@oim-media/core 1.28.0 → 1.29.1
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 +1 -1
- package/dist/compatibility.d.ts +1 -1
- package/dist/compatibility.js +5 -3
- package/dist/v2/base-layer.d.ts +2 -1
- package/dist/v2/base-layer.js +10 -1
- package/dist/v2/colors.d.ts +19 -0
- package/dist/v2/colors.js +37 -0
- package/dist/v2/index.d.ts +4 -0
- package/dist/v2/index.js +5 -0
- package/dist/v2/resources.js +13 -0
- package/dist/v2/schema.d.ts +2 -0
- package/dist/v2/schema.js +7 -2
- package/dist/v2/typography.d.ts +12 -0
- package/dist/v2/typography.js +46 -0
- package/dist/v2/upgrade/text.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ URLs only) and `@oim-media/core/generative` and `@oim-media/core/generative/cata
|
|
|
26
26
|
|
|
27
27
|
- `OimMetadataSchema`, `OvmMetadataSchema`, `OIMOrOVMMetadata`: Zod schemas of the
|
|
28
28
|
metadata. Types `OIMMetadata`, `OVMMetadata`, `Slot`, `TextMark`, `Reveal`, ...
|
|
29
|
-
- `CONTRACT_VERSION`: the contract version this build implements (`"1.
|
|
29
|
+
- `CONTRACT_VERSION`: the contract version this build implements (`"1.29.1"`).
|
|
30
30
|
- `BASE_CONTRACT_VERSION`, `PLAYER_CAPABILITIES`, `VERSION_BY_CAPABILITY`, `minVersionFor`.
|
|
31
31
|
- `MAX_SLOTS`, `MAX_MARKS`, `MARK_NAME`, `PALETTE_NAME_PATTERN`, `CSS_GRADIENT_PATTERN`.
|
|
32
32
|
|
package/dist/compatibility.d.ts
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
* the format can change without the player being touched. Tying both numbers
|
|
42
42
|
* together would make an internal fix look like a format break.
|
|
43
43
|
*/
|
|
44
|
-
export declare const CONTRACT_VERSION = "1.
|
|
44
|
+
export declare const CONTRACT_VERSION = "1.29.1";
|
|
45
45
|
/**
|
|
46
46
|
* The first version of the format. Whatever requires nothing more requires this.
|
|
47
47
|
*
|
package/dist/compatibility.js
CHANGED
|
@@ -41,9 +41,11 @@
|
|
|
41
41
|
* the format can change without the player being touched. Tying both numbers
|
|
42
42
|
* together would make an internal fix look like a format break.
|
|
43
43
|
*/
|
|
44
|
-
export const CONTRACT_VERSION = "1.
|
|
45
|
-
// 1.
|
|
46
|
-
// 1.
|
|
44
|
+
export const CONTRACT_VERSION = "1.29.1";
|
|
45
|
+
// 1.29.1: the 1.x to 2.0 upgrade retires the editor-only textRole field; no format change.
|
|
46
|
+
// 1.29.0: a 2.0 image src can be { ref } to a resources entry of kind image.
|
|
47
|
+
// 1.29.0: the player reads 2.0 files and has a poster attribute; 2.0 conformance vectors ship in @oim-media/spec.
|
|
48
|
+
// 1.29.0: an SVG layer upgrades from its content, not svgRawXml; no format change.
|
|
47
49
|
// 1.27.11: fixes to the 2.0 upgrade (corner shorthand, hollow text, SVG icons, colour under a photo); no format change.
|
|
48
50
|
// 1.27.10: no format change; the player paints from 2.0 and a zone is a group without its flow.
|
|
49
51
|
// 1.27.9: numbers beyond +/-(2^53 - 1) have no canonical form; the Rust crate parses decimals exactly.
|
package/dist/v2/base-layer.d.ts
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* Copyright (c) 2026 Xue Studios LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import type { Layer } from "./schema.js";
|
|
6
|
+
import type { Layer, Paint } from "./schema.js";
|
|
7
7
|
/**
|
|
8
8
|
* True when some image layer, nested ones included, shows the file's own picture (`oim:base`),
|
|
9
9
|
* in its principal picture or in any language. Such a document's PNG is its base, not a poster.
|
|
10
10
|
*/
|
|
11
11
|
export declare function hasBaseLayer(document: {
|
|
12
12
|
layers: Layer[];
|
|
13
|
+
resources?: Record<string, Paint>;
|
|
13
14
|
}): boolean;
|
package/dist/v2/base-layer.js
CHANGED
|
@@ -10,7 +10,16 @@ const BASE = "oim:base";
|
|
|
10
10
|
* in its principal picture or in any language. Such a document's PNG is its base, not a poster.
|
|
11
11
|
*/
|
|
12
12
|
export function hasBaseLayer(document) {
|
|
13
|
-
|
|
13
|
+
// A `{ ref }` is read through the resource it names, as resolveRefs would read it.
|
|
14
|
+
const shows = (src) => {
|
|
15
|
+
if (typeof src === "string")
|
|
16
|
+
return src === BASE;
|
|
17
|
+
if ("ref" in src) {
|
|
18
|
+
const paint = document.resources?.[src.ref];
|
|
19
|
+
return paint !== undefined && "kind" in paint && paint.kind === "image" && paint.src === BASE;
|
|
20
|
+
}
|
|
21
|
+
return src.value === BASE || Object.values(src.modes ?? {}).includes(BASE);
|
|
22
|
+
};
|
|
14
23
|
const walk = (layers) => layers.some((layer) => (layer.image !== undefined && shows(layer.image.src)) || walk(layer.children ?? []));
|
|
15
24
|
return walk(document.layers);
|
|
16
25
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { PaintColors } from "./paint-css.js";
|
|
7
|
+
import type { Variables } from "./schema.js";
|
|
8
|
+
export type PaletteMetadata = {
|
|
9
|
+
palettes?: Record<string, Record<string, string>>;
|
|
10
|
+
defaultPalette?: string;
|
|
11
|
+
};
|
|
12
|
+
/** The named palettes of a document, read back from its variables: one role → colour map per palette name. */
|
|
13
|
+
export declare function palettesOf(variables: Variables | undefined): Record<string, Record<string, string>> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* How a renderer paints a 2.0 colour: a palette binding stays a `var()` so a
|
|
16
|
+
* mode change needs no repaint; drawn-in paints (patterns) take the default
|
|
17
|
+
* palette's value, since an image cannot hold a `var()`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function paintColors(metadata: PaletteMetadata): PaintColors;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
// How a 2.0 colour becomes paint: the palette a document's variables name, and
|
|
7
|
+
// the CSS a renderer writes for a colour. One copy, read by the scene and by the
|
|
8
|
+
// 1.x renderer's bridge, so both pick the same colour for the same palette.
|
|
9
|
+
import { resolveCssColor, resolvePalette } from "../dynamic-colors.js";
|
|
10
|
+
/** The named palettes of a document, read back from its variables: one role → colour map per palette name. */
|
|
11
|
+
export function palettesOf(variables) {
|
|
12
|
+
const names = variables?.modes?.palette;
|
|
13
|
+
if (!variables || !names)
|
|
14
|
+
return undefined;
|
|
15
|
+
const palettes = Object.fromEntries(names.map((name) => [name, {}]));
|
|
16
|
+
for (const [role, byPalette] of Object.entries(variables.values ?? {})) {
|
|
17
|
+
for (const [name, color] of Object.entries(byPalette)) {
|
|
18
|
+
if (palettes[name] && typeof color === "string")
|
|
19
|
+
palettes[name][role] = color;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return palettes;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* How a renderer paints a 2.0 colour: a palette binding stays a `var()` so a
|
|
26
|
+
* mode change needs no repaint; drawn-in paints (patterns) take the default
|
|
27
|
+
* palette's value, since an image cannot hold a `var()`.
|
|
28
|
+
*/
|
|
29
|
+
export function paintColors(metadata) {
|
|
30
|
+
const isVar = (v) => !!v && typeof v === "object" && typeof v.var === "string";
|
|
31
|
+
return {
|
|
32
|
+
css: (v) => (isVar(v) ? resolveCssColor(v.var, v.fallback) : typeof v === "string" ? resolveCssColor(null, v) : "") || undefined,
|
|
33
|
+
literal: (v) => (isVar(v)
|
|
34
|
+
? resolvePalette(metadata)?.colors?.[v.var] ?? resolveCssColor(null, v.fallback)
|
|
35
|
+
: typeof v === "string" ? resolveCssColor(null, v) : "") || undefined,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/dist/v2/index.d.ts
CHANGED
|
@@ -9,3 +9,7 @@ export * from "./upgrade.js";
|
|
|
9
9
|
export type { UpgradeContext } from "./upgrade/context.js";
|
|
10
10
|
export * from "./paint-css.js";
|
|
11
11
|
export * from "./resources.js";
|
|
12
|
+
export * from "./geometry-outline.js";
|
|
13
|
+
export * from "./base-layer.js";
|
|
14
|
+
export * from "./colors.js";
|
|
15
|
+
export * from "./typography.js";
|
package/dist/v2/index.js
CHANGED
|
@@ -10,3 +10,8 @@ export * from "./schema.js";
|
|
|
10
10
|
export * from "./upgrade.js";
|
|
11
11
|
export * from "./paint-css.js";
|
|
12
12
|
export * from "./resources.js";
|
|
13
|
+
// The shared outline of a shape and the test for a document that shows its base picture.
|
|
14
|
+
export * from "./geometry-outline.js";
|
|
15
|
+
export * from "./base-layer.js";
|
|
16
|
+
export * from "./colors.js";
|
|
17
|
+
export * from "./typography.js";
|
package/dist/v2/resources.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// Paints live in three places: `canvas.fills`, each layer's `fills`, and each
|
|
7
7
|
// stroke's `paint`. A `{ ref }` in any of them points at `document.resources`.
|
|
8
8
|
// A stroke whose ref is missing is dropped, since a stroke has no paint without it.
|
|
9
|
+
// An image layer's `src` may be a `{ ref }` to an image paint; if that is missing or
|
|
10
|
+
// not an image, the layer loses its `image` block rather than keeping a dead source.
|
|
9
11
|
/** A copy of the document with every `{ ref }` paint replaced by its resource. */
|
|
10
12
|
export function resolveRefs(document) {
|
|
11
13
|
const out = structuredClone(document);
|
|
@@ -31,6 +33,17 @@ export function resolveRefs(document) {
|
|
|
31
33
|
return paint ? [{ ...stroke, paint }] : [];
|
|
32
34
|
});
|
|
33
35
|
}
|
|
36
|
+
if (layer.image && typeof layer.image.src === "object" && "ref" in layer.image.src) {
|
|
37
|
+
const src = layer.image.src;
|
|
38
|
+
const resource = Object.prototype.hasOwnProperty.call(resources, src.ref) ? resources[src.ref] : undefined;
|
|
39
|
+
if (resource && "kind" in resource && resource.kind === "image")
|
|
40
|
+
layer.image = { ...layer.image, src: resource.src };
|
|
41
|
+
else {
|
|
42
|
+
delete layer.image;
|
|
43
|
+
if (!missing.includes(src.ref))
|
|
44
|
+
missing.push(src.ref);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
34
47
|
if (layer.children)
|
|
35
48
|
walk(layer.children);
|
|
36
49
|
}
|
package/dist/v2/schema.d.ts
CHANGED
|
@@ -670,6 +670,8 @@ export declare const imageSchema: z.ZodObject<{
|
|
|
670
670
|
src: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
671
671
|
value: z.ZodString;
|
|
672
672
|
modes: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
673
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
674
|
+
ref: z.ZodString;
|
|
673
675
|
}, z.core.$strict>]>;
|
|
674
676
|
fit: z.ZodOptional<z.ZodEnum<{
|
|
675
677
|
cover: "cover";
|
package/dist/v2/schema.js
CHANGED
|
@@ -232,8 +232,13 @@ const corners = z.union([z.number().min(0), z.array(z.number().min(0)).length(4)
|
|
|
232
232
|
export const imageSchema = z
|
|
233
233
|
.object({
|
|
234
234
|
// "oim:base" is the PNG of the file itself. A language can have its own
|
|
235
|
-
// picture; an empty one means that language shows none.
|
|
236
|
-
|
|
235
|
+
// picture; an empty one means that language shows none. A `{ ref }` names an
|
|
236
|
+
// image paint in `document.resources` (resolved by resolveRefs).
|
|
237
|
+
src: z.union([
|
|
238
|
+
z.string().min(1),
|
|
239
|
+
z.object({ value: z.string().min(1), modes: z.record(z.string(), z.string()) }).strict(),
|
|
240
|
+
z.object({ ref: id }).strict(),
|
|
241
|
+
]),
|
|
237
242
|
fit: fit.optional(),
|
|
238
243
|
crop: crop.optional(),
|
|
239
244
|
filters: imageFiltersSchema.optional(),
|
|
@@ -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 { Layer } from "./schema.js";
|
|
7
|
+
/**
|
|
8
|
+
* The CSS typography of a 2.0 text, for one language. Lengths are canvas units,
|
|
9
|
+
* which the overlay paints 1:1 as px. Absent fields are absent: the caller
|
|
10
|
+
* keeps its defaults.
|
|
11
|
+
*/
|
|
12
|
+
export declare function typographyCss(layer: Pick<Layer, "text"> | undefined, lang: string): Record<string, string> | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/** A 2.0 scalar resolved for one language: its exception for that mode, else its value. */
|
|
7
|
+
function forLanguage(value, lang) {
|
|
8
|
+
if (typeof value === 'number')
|
|
9
|
+
return value;
|
|
10
|
+
if (value && typeof value === 'object' && 'value' in value) {
|
|
11
|
+
const { value: base, modes } = value;
|
|
12
|
+
const own = modes?.[lang];
|
|
13
|
+
return typeof own === 'number' ? own : typeof base === 'number' ? base : undefined;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The CSS typography of a 2.0 text, for one language. Lengths are canvas units,
|
|
19
|
+
* which the overlay paints 1:1 as px. Absent fields are absent: the caller
|
|
20
|
+
* keeps its defaults.
|
|
21
|
+
*/
|
|
22
|
+
export function typographyCss(layer, lang) {
|
|
23
|
+
const text = layer?.text;
|
|
24
|
+
if (!text)
|
|
25
|
+
return undefined;
|
|
26
|
+
const css = {};
|
|
27
|
+
const size = forLanguage(text.font?.size, lang);
|
|
28
|
+
if (size !== undefined)
|
|
29
|
+
css.fontSize = `${+size.toFixed(4)}px`;
|
|
30
|
+
const maxWidth = forLanguage(text.maxWidth, lang);
|
|
31
|
+
if (maxWidth !== undefined)
|
|
32
|
+
css.maxWidth = `${+maxWidth.toFixed(4)}px`;
|
|
33
|
+
if (text.font?.family)
|
|
34
|
+
css.fontFamily = text.font.family;
|
|
35
|
+
if (text.font?.weight !== undefined)
|
|
36
|
+
css.fontWeight = String(text.font.weight);
|
|
37
|
+
if (text.font?.italic)
|
|
38
|
+
css.fontStyle = 'italic';
|
|
39
|
+
if (text.letterSpacing !== undefined)
|
|
40
|
+
css.letterSpacing = `${text.letterSpacing}px`;
|
|
41
|
+
if (text.transform)
|
|
42
|
+
css.textTransform = text.transform;
|
|
43
|
+
if (text.decoration)
|
|
44
|
+
css.textDecoration = text.decoration;
|
|
45
|
+
return css;
|
|
46
|
+
}
|
package/dist/v2/upgrade/text.js
CHANGED
|
@@ -32,6 +32,8 @@ const TYPOGRAPHY_KEYS = [
|
|
|
32
32
|
];
|
|
33
33
|
export function convertText(ctx, slot, layer) {
|
|
34
34
|
const { raw, style } = slot;
|
|
35
|
+
// The editor's hierarchy buttons; no player read it, on any layer type.
|
|
36
|
+
ctx.retire(style, "textRole");
|
|
35
37
|
const align = ctx.take(style, "textAlign") ?? ctx.take(raw, "align");
|
|
36
38
|
ctx.take(raw, "align");
|
|
37
39
|
if (layer.type !== "text") {
|
package/package.json
CHANGED