@oim-media/core 1.27.9 → 1.27.10

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 +2 -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 +162 -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 +258 -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,132 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { toCanvasUnits } from "./box.js";
7
+ import { asObject } from "./context.js";
8
+ /**
9
+ * A length with per-language exceptions (`fontSizes`, `maxWidths`). The main
10
+ * language is the value; the others that differ from it are the exceptions.
11
+ */
12
+ function sized(ctx, style, key, perLanguageKey) {
13
+ const W = ctx.canvas.width;
14
+ const base = toCanvasUnits(ctx.take(style, key), W);
15
+ const perLanguage = asObject(ctx.take(style, perLanguageKey)) ?? {};
16
+ const value = toCanvasUnits(perLanguage[ctx.language], W) ?? base;
17
+ if (value === undefined)
18
+ return undefined;
19
+ const modes = {};
20
+ for (const [language, raw] of Object.entries(perLanguage)) {
21
+ const converted = toCanvasUnits(raw, W);
22
+ if (language !== ctx.language && converted !== undefined && converted !== value)
23
+ modes[language] = converted;
24
+ }
25
+ return Object.keys(modes).length > 0 ? { value, modes } : value;
26
+ }
27
+ const TYPOGRAPHY_KEYS = [
28
+ "fontFamily", "fontSize", "fontSizes", "fontWeight", "fontStyle", "bold", "italic", "underline", "textAlign",
29
+ "lineHeight", "letterSpacing", "textTransform", "textDecoration", "maxWidth", "maxWidths", "marks", "textRuns",
30
+ "textHighlight", "dropCap", "artisticPreset", "curveType", "curveAmount", "extrusionDepth", "extrusionAngle",
31
+ "extrusionColor", "extrusionShading",
32
+ ];
33
+ export function convertText(ctx, slot, layer) {
34
+ const { raw, style } = slot;
35
+ const align = ctx.take(style, "textAlign") ?? ctx.take(raw, "align");
36
+ ctx.take(raw, "align");
37
+ if (layer.type !== "text") {
38
+ for (const key of TYPOGRAPHY_KEYS)
39
+ ctx.take(style, key);
40
+ return;
41
+ }
42
+ const content = ctx.take(raw, "content");
43
+ const text = { content: {} };
44
+ if (typeof content === "string")
45
+ text.content[ctx.language] = content;
46
+ else
47
+ for (const [language, value] of Object.entries(asObject(content) ?? {}))
48
+ if (typeof value === "string")
49
+ text.content[language] = value;
50
+ const font = {};
51
+ const family = ctx.take(style, "fontFamily");
52
+ if (typeof family === "string" && family)
53
+ font.family = family;
54
+ const size = sized(ctx, style, "fontSize", "fontSizes");
55
+ if (size !== undefined)
56
+ font.size = size;
57
+ const weight = ctx.take(style, "fontWeight");
58
+ // bold, italic and underline were retired in 1.5.0 and the player ignores them.
59
+ ctx.take(style, "bold");
60
+ if (typeof weight === "number" || (typeof weight === "string" && weight)) {
61
+ if (Number(weight) !== 400)
62
+ font.weight = Number.isFinite(Number(weight)) ? Number(weight) : weight;
63
+ }
64
+ const fontStyle = ctx.take(style, "fontStyle");
65
+ if (fontStyle === "italic" || fontStyle === "oblique")
66
+ font.italic = true;
67
+ ctx.take(style, "italic");
68
+ if (Object.keys(font).length > 0)
69
+ text.font = font;
70
+ if (align === "center" || align === "right" || align === "justify")
71
+ text.align = align;
72
+ const lineHeight = ctx.take(style, "lineHeight");
73
+ if (typeof lineHeight === "number" || (typeof lineHeight === "string" && lineHeight))
74
+ text.lineHeight = lineHeight;
75
+ // 1.x passed letterSpacing to CSS as it came: a bare number was invalid CSS and
76
+ // painted nothing (golden background-pattern-order); a length with its unit did.
77
+ // Artistic text drew its own SVG, where a bare number was a length.
78
+ const rawSpacing = ctx.take(style, "letterSpacing");
79
+ const spacing = typeof rawSpacing === "string" ? toCanvasUnits(rawSpacing, ctx.canvas.width)
80
+ : typeof rawSpacing === "number" && slot.type === "artistic-text" ? rawSpacing : undefined;
81
+ if (spacing !== undefined && spacing !== 0)
82
+ text.letterSpacing = spacing;
83
+ const transform = ctx.take(style, "textTransform");
84
+ if (transform === "uppercase" || transform === "lowercase" || transform === "capitalize")
85
+ text.transform = transform;
86
+ const decoration = ctx.take(style, "textDecoration");
87
+ ctx.take(style, "underline");
88
+ if (typeof decoration === "string" && decoration && decoration !== "none")
89
+ text.decoration = decoration;
90
+ const maxWidth = sized(ctx, style, "maxWidth", "maxWidths");
91
+ if (maxWidth !== undefined)
92
+ text.maxWidth = maxWidth;
93
+ const marks = asObject(ctx.take(style, "marks"));
94
+ if (marks && Object.keys(marks).length > 0)
95
+ text.marks = marks;
96
+ const runs = asObject(ctx.take(style, "textRuns"));
97
+ if (runs && Object.keys(runs).length > 0)
98
+ text.runs = runs;
99
+ const highlight = asObject(ctx.take(style, "textHighlight"));
100
+ if (highlight && highlight.enabled !== false)
101
+ text.highlight = highlight;
102
+ const dropCap = asObject(ctx.take(style, "dropCap"));
103
+ if (dropCap && dropCap.enabled !== false)
104
+ text.dropCap = dropCap;
105
+ const artistic = {};
106
+ const preset = ctx.take(style, "artisticPreset");
107
+ if (typeof preset === "string" && preset)
108
+ artistic.preset = preset;
109
+ const curveType = ctx.take(style, "curveType");
110
+ const curveAmount = ctx.take(style, "curveAmount");
111
+ // 1.x drew an arc when the type was missing.
112
+ const curve = curveType ?? "arc";
113
+ if ((curve === "arc" || curve === "wave" || curve === "arch") && typeof curveAmount === "number" && curveAmount !== 0) {
114
+ artistic.curve = { type: curve, amount: curveAmount };
115
+ }
116
+ const depth = ctx.take(style, "extrusionDepth");
117
+ const angle = ctx.take(style, "extrusionAngle");
118
+ const extrusionColor = ctx.take(style, "extrusionColor");
119
+ const shading = ctx.take(style, "extrusionShading");
120
+ if (typeof depth === "number" && depth > 0) {
121
+ artistic.extrusion = { depth };
122
+ if (typeof angle === "number")
123
+ artistic.extrusion.angle = angle;
124
+ if (typeof extrusionColor === "string" && extrusionColor)
125
+ artistic.extrusion.color = extrusionColor;
126
+ if (typeof shading === "boolean")
127
+ artistic.extrusion.shading = shading;
128
+ }
129
+ if (slot.type === "artistic-text" || Object.keys(artistic).length > 0)
130
+ text.artistic = artistic;
131
+ layer.text = text;
132
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { LayerType } from "../layer-blocks.js";
7
+ import type { DraftLayer, UpgradeContext, V1Slot } from "./context.js";
8
+ /** The fifteen layer types of 1.x and the five they become. */
9
+ export declare const TYPE_OF: Record<string, LayerType>;
10
+ /**
11
+ * Moves each child inside its group. Membership is the core's own rule
12
+ * (`childrenByGroup`, read from the child's `groupId`), so the 2.0 tree nests
13
+ * exactly what every 1.x player nests. `childIds` only repeats it.
14
+ */
15
+ export declare function buildTree(ctx: UpgradeContext, slots: V1Slot[], layers: DraftLayer[]): DraftLayer[];
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { childrenByGroup } from "../../groups.js";
7
+ /** The fifteen layer types of 1.x and the five they become. */
8
+ export const TYPE_OF = {
9
+ text: "text",
10
+ "artistic-text": "text",
11
+ geo: "shape",
12
+ shape: "shape",
13
+ draw: "shape",
14
+ svg: "shape",
15
+ pattern: "shape",
16
+ container: "shape",
17
+ filter: "shape",
18
+ mask: "shape",
19
+ image: "image",
20
+ lottie: "lottie",
21
+ group: "group",
22
+ component: "group",
23
+ zone: "group",
24
+ };
25
+ /**
26
+ * Moves each child inside its group. Membership is the core's own rule
27
+ * (`childrenByGroup`, read from the child's `groupId`), so the 2.0 tree nests
28
+ * exactly what every 1.x player nests. `childIds` only repeats it.
29
+ */
30
+ export function buildTree(ctx, slots, layers) {
31
+ const members = childrenByGroup(slots.map((s) => ({ ...s.raw, style: s.style })));
32
+ const parentOf = new Map();
33
+ for (const [group, children] of members)
34
+ for (const child of children)
35
+ parentOf.set(child, group);
36
+ const byId = new Map(layers.map((layer) => [layer.id, layer]));
37
+ const top = [];
38
+ slots.forEach((slot, index) => {
39
+ ctx.take(slot.style, "groupId");
40
+ ctx.take(slot.style, "childIds");
41
+ const layer = layers[index];
42
+ const parent = byId.get(parentOf.get(layer.id) ?? "");
43
+ if (parent && parent !== layer && parent.type === "group")
44
+ (parent.children ??= []).push(layer);
45
+ else
46
+ top.push(layer);
47
+ });
48
+ return top;
49
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Variables } from "../schema.js";
7
+ import { type UpgradeContext, type V1Object } from "./context.js";
8
+ export declare function convertVariables(ctx: UpgradeContext, meta: V1Object, languages: string[]): Variables | undefined;
@@ -0,0 +1,24 @@
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
+ export function convertVariables(ctx, meta, languages) {
8
+ const palettes = asObject(ctx.take(meta, "palettes")) ?? {};
9
+ const preferred = ctx.take(meta, "defaultPalette");
10
+ const names = Object.keys(palettes).filter((name) => asObject(palettes[name]));
11
+ if (names.length === 0)
12
+ return undefined;
13
+ const values = {};
14
+ for (const name of names) {
15
+ for (const [role, color] of Object.entries(asObject(palettes[name]) ?? {})) {
16
+ if (typeof color === "string" && color)
17
+ (values[role] ??= {})[name] = color;
18
+ }
19
+ }
20
+ const variables = { modes: { palette: names, language: languages }, values };
21
+ if (typeof preferred === "string" && names.includes(preferred))
22
+ variables.defaults = { palette: preferred };
23
+ return variables;
24
+ }
@@ -0,0 +1,12 @@
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 V1Object } from "./context.js";
7
+ export declare const FLOW_KEYS: string[];
8
+ /**
9
+ * The root `zones` as groups, at the bottom of the stack (1.x put them before
10
+ * every layer), each holding the layers whose `zone_id` names it, in their order.
11
+ */
12
+ export declare function convertZones(ctx: UpgradeContext, meta: V1Object, layers: DraftLayer[], zoneOf: Map<DraftLayer, string>): DraftLayer[];
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // Decision (14 Nov): a 1.x zone becomes a 2.0 group WITHOUT its flow. A zone was a
7
+ // flex box that laid its layers out and ignored their x/y; 2.0 groups have no
8
+ // layout, so the zone keeps its box and paint and each layer stays at its own x/y.
9
+ // A file that relied on the flow paints differently. No editor creates zones and
10
+ // no conformance vector uses them; if zones come back, groups get a layout block.
11
+ import { toCanvasUnits } from "./box.js";
12
+ import { asObject } from "./context.js";
13
+ import { isColor } from "./paints.js";
14
+ export const FLOW_KEYS = ["display", "flexDirection", "justifyContent", "alignItems", "gap", "padding"];
15
+ const percent = (value, of) => (typeof value === "number" && Number.isFinite(value) ? (value / 100) * of : 0);
16
+ function zoneGroup(ctx, value, index) {
17
+ const zone = { ...(asObject(value) ?? {}) };
18
+ const style = { ...(asObject(zone.style) ?? {}) };
19
+ ctx.register(zone, `zones[${index}]`);
20
+ ctx.register(style, `zones[${index}].style`);
21
+ ctx.take(zone, "style");
22
+ const id = String(ctx.take(zone, "id") ?? `zone-${index + 1}`);
23
+ const pos = Array.isArray(zone.position) ? zone.position : [0, 0];
24
+ const size = Array.isArray(zone.size) ? zone.size : [100, 100];
25
+ ctx.take(zone, "position");
26
+ ctx.take(zone, "size");
27
+ for (const key of FLOW_KEYS)
28
+ ctx.retire(style, key);
29
+ const { width: W, height: H } = ctx.canvas;
30
+ const box = { x: percent(pos[0], W), y: percent(pos[1], H), width: percent(size[0], W), height: percent(size[1], H) };
31
+ const group = { id, type: "group", box, children: [] };
32
+ const blur = /^blur\((\d+(?:\.\d+)?)px\)$/.exec(String(ctx.take(style, "backdropFilter") ?? "").trim());
33
+ if (blur)
34
+ group.effects = [{ kind: "backdrop", blur: Number(blur[1]) }];
35
+ // A group paints nothing of its own: the zone's background is a shape at its bottom.
36
+ const background = ctx.take(style, "background");
37
+ const corners = toCanvasUnits(ctx.take(style, "borderRadius"), W);
38
+ if (isColor(background)) {
39
+ const plate = { id: `${id}__background`, type: "shape", box: { ...box }, geometry: { kind: "rect" }, fills: [{ kind: "color", value: background }] };
40
+ if (corners)
41
+ plate.corners = corners;
42
+ group.children.push(plate);
43
+ }
44
+ return group;
45
+ }
46
+ /**
47
+ * The root `zones` as groups, at the bottom of the stack (1.x put them before
48
+ * every layer), each holding the layers whose `zone_id` names it, in their order.
49
+ */
50
+ export function convertZones(ctx, meta, layers, zoneOf) {
51
+ const list = ctx.take(meta, "zones");
52
+ if (!Array.isArray(list) || list.length === 0)
53
+ return layers;
54
+ const groups = list.map((value, index) => zoneGroup(ctx, value, index));
55
+ const byId = new Map(groups.map((g) => [g.id, g]));
56
+ const rest = layers.filter((layer) => {
57
+ const group = byId.get(zoneOf.get(layer) ?? "");
58
+ if (group)
59
+ group.children.push(layer);
60
+ return !group;
61
+ });
62
+ return [...groups, ...rest];
63
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { OimDocument } from "./schema.js";
7
+ import { type DraftLayer, type UpgradeContext, type V1Slot } from "./upgrade/context.js";
8
+ export type UpgradeResult = {
9
+ document: OimDocument;
10
+ /** 1.x keys dropped on purpose, such as `root.signature`. */
11
+ retired: string[];
12
+ /** 1.x keys nobody converted. A complete upgrade leaves this empty. */
13
+ unhandled: string[];
14
+ };
15
+ export type Converter = (ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer) => void;
16
+ export declare function isV2(input: unknown): boolean;
17
+ export declare function upgrade(input: unknown): UpgradeResult;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // Reads a 1.x document as a 2.0 one. Pure: the input is never modified and
7
+ // nothing is signed. A 1.x file is verified with its own bytes first; this
8
+ // runs afterwards, in memory.
9
+ import { normalizeLegacyKeys } from "../legacyKeys.js";
10
+ import { convertAnimations } from "./upgrade/animations.js";
11
+ import { convertBox } from "./upgrade/box.js";
12
+ import { canvasEffects, convertEffects } from "./upgrade/effects.js";
13
+ import { convertGeometry } from "./upgrade/geometry.js";
14
+ import { RETIRED_STYLE_KEYS } from "./upgrade/keys.js";
15
+ import { convertMask } from "./upgrade/mask.js";
16
+ import { canvasFills, convertPaints } from "./upgrade/paints.js";
17
+ import { asObject, createContext } from "./upgrade/context.js";
18
+ import { canvasOf, convertRoot, languagesOf, rolesOf } from "./upgrade/root.js";
19
+ import { convertText } from "./upgrade/text.js";
20
+ import { buildTree, TYPE_OF } from "./upgrade/tree.js";
21
+ import { convertZones } from "./upgrade/zones.js";
22
+ import { convertVariables } from "./upgrade/variables.js";
23
+ /** One converter per block, in the order they run. */
24
+ // Order matters twice: the image block must exist before the effects decide
25
+ // where the colour filters go, and the mask runs last because it replaces the
26
+ // geometry, fill and stroke of the layer that takes that role.
27
+ const CONVERTERS = [
28
+ convertBox,
29
+ convertText,
30
+ convertPaints,
31
+ convertGeometry,
32
+ convertEffects,
33
+ convertAnimations,
34
+ convertMask,
35
+ ];
36
+ export function isV2(input) {
37
+ const version = asObject(input)?.oim;
38
+ return typeof version === "string" && /^2\./.test(version);
39
+ }
40
+ // Short aliases retired in 1.12.0. The player has not read them since, so a
41
+ // file that still carries them was painted without them: they are retired here too.
42
+ const SLOT_ALIASES = ["p", "st", "c", "t"];
43
+ function readSlot(ctx, value, index) {
44
+ const raw = { ...(asObject(value) ?? {}) };
45
+ const style = { ...(asObject(raw.style) ?? {}) };
46
+ ctx.register(raw, "slot");
47
+ for (const alias of SLOT_ALIASES)
48
+ if (alias in raw)
49
+ ctx.retire(raw, alias);
50
+ ctx.register(style, "style");
51
+ ctx.take(raw, "style");
52
+ // `s` was a size nobody wrote.
53
+ ctx.retire(raw, "s");
54
+ for (const key of RETIRED_STYLE_KEYS)
55
+ ctx.retire(style, key);
56
+ if (raw.id === undefined)
57
+ raw.id = `layer-${index + 1}`;
58
+ const type = typeof raw.type === "string" ? raw.type : "text";
59
+ return { raw, style, type };
60
+ }
61
+ function startLayer(ctx, slot) {
62
+ const { raw } = slot;
63
+ const layer = {
64
+ id: String(ctx.take(raw, "id")),
65
+ type: TYPE_OF[slot.type] ?? "shape",
66
+ box: { x: 0, y: 0, width: 0, height: 0 },
67
+ };
68
+ ctx.take(raw, "type");
69
+ if (!(slot.type in TYPE_OF))
70
+ ctx.note(`slot.type: unknown layer type "${slot.type}"`);
71
+ const name = ctx.take(raw, "name");
72
+ if (typeof name === "string" && name)
73
+ layer.name = name;
74
+ // Shown only in some languages; "*" (or no list) is every language, and an
75
+ // empty list hid the layer in all of them, as the 1.x player did.
76
+ const languages = ctx.take(raw, "languages");
77
+ if (Array.isArray(languages) && !languages.includes("*")) {
78
+ const own = languages.filter((l) => typeof l === "string" && l.length > 0);
79
+ if (own.length > 0)
80
+ layer.languages = [...new Set(own)];
81
+ else
82
+ layer.visible = false;
83
+ }
84
+ const pending = ctx.take(raw, "pendingTranslation");
85
+ if (Array.isArray(pending) && pending.length > 0) {
86
+ layer.extensions = { ...layer.extensions, studio: { pendingTranslation: pending } };
87
+ }
88
+ return layer;
89
+ }
90
+ /** What a layer type cannot exist without, when no converter supplied it. */
91
+ function completeLayer(layer) {
92
+ if (layer.type === "shape")
93
+ layer.geometry ??= { kind: "rect" };
94
+ if (layer.type === "text")
95
+ layer.text ??= { content: {} };
96
+ if (layer.type === "image")
97
+ layer.image ??= { src: "oim:base" };
98
+ if (layer.type === "group")
99
+ layer.children ??= [];
100
+ layer.children?.forEach(completeLayer);
101
+ }
102
+ export function upgrade(input) {
103
+ if (isV2(input))
104
+ return { document: input, retired: [], unhandled: [] };
105
+ const meta = normalizeLegacyKeys(asObject(input) ?? {});
106
+ const ctx = createContext(canvasOf(meta), languagesOf(meta)[0], rolesOf(meta));
107
+ ctx.register(meta, "root");
108
+ const { document, slots: rawSlots } = convertRoot(ctx, meta);
109
+ const slots = rawSlots.map((value, index) => readSlot(ctx, value, index));
110
+ const layers = slots.map((slot) => {
111
+ const layer = startLayer(ctx, slot);
112
+ for (const convert of CONVERTERS)
113
+ convert(ctx, slot, layer);
114
+ return layer;
115
+ });
116
+ // The zone a layer sits in: only a top-level layer, as 1.x attached only those.
117
+ const zoneOf = new Map();
118
+ slots.forEach((slot, i) => {
119
+ const zone = ctx.take(slot.raw, "zone_id");
120
+ if (typeof zone === "string" && zone)
121
+ zoneOf.set(layers[i], zone);
122
+ });
123
+ document.layers = convertZones(ctx, meta, buildTree(ctx, slots, layers), zoneOf);
124
+ const variables = convertVariables(ctx, meta, document.languages);
125
+ if (variables)
126
+ document.variables = variables;
127
+ const background = canvasFills(ctx, meta);
128
+ if (background.length > 0)
129
+ document.canvas = { ...document.canvas, fills: background };
130
+ // Effects over the whole canvas become one last layer that covers it.
131
+ const overall = canvasEffects(ctx, meta);
132
+ if (overall.length > 0) {
133
+ document.layers.push({
134
+ id: "__canvas-effects",
135
+ type: "shape",
136
+ box: { x: 0, y: 0, width: ctx.canvas.width, height: ctx.canvas.height },
137
+ geometry: { kind: "rect" },
138
+ effects: overall,
139
+ });
140
+ }
141
+ document.layers.forEach(completeLayer);
142
+ return { document, ...ctx.finish() };
143
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare const DOCUMENT_VERSION = "2.0.0-draft.1";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // Apart from the schema so the upgrade path can name it without loading zod.
7
+ export const DOCUMENT_VERSION = "2.0.0-draft.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oim-media/core",
3
- "version": "1.27.9",
3
+ "version": "1.27.10",
4
4
  "description": "Core of the OIM format: the contract schema, binary extraction from PNG and the shared rendering logic used by every OIM player.",
5
5
  "keywords": [
6
6
  "oim",
@@ -25,6 +25,10 @@
25
25
  "types": "./dist/api.d.ts",
26
26
  "default": "./dist/api.js"
27
27
  },
28
+ "./v2": {
29
+ "types": "./dist/v2/index.d.ts",
30
+ "default": "./dist/v2/index.js"
31
+ },
28
32
  "./generative": {
29
33
  "types": "./dist/generative/index.d.ts",
30
34
  "default": "./dist/generative/index.js"