@oim-media/core 1.27.8 → 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 (57) hide show
  1. package/LICENSE +55 -55
  2. package/NOTICE +6 -6
  3. package/README.md +158 -134
  4. package/dist/canonical.d.ts +25 -0
  5. package/dist/canonical.js +18 -1
  6. package/dist/compatibility.d.ts +1 -1
  7. package/dist/compatibility.js +3 -1
  8. package/dist/generative/primitives/blob.js +4 -4
  9. package/dist/generative/primitives/iso-grid.js +7 -7
  10. package/dist/generative/primitives/mesh.js +3 -3
  11. package/dist/parallaxCss.js +8 -8
  12. package/dist/patterns.js +9 -9
  13. package/dist/v2/geometry-outline.d.ts +23 -0
  14. package/dist/v2/geometry-outline.js +35 -0
  15. package/dist/v2/index.d.ts +10 -0
  16. package/dist/v2/index.js +11 -0
  17. package/dist/v2/layer-blocks.d.ts +11 -0
  18. package/dist/v2/layer-blocks.js +34 -0
  19. package/dist/v2/paint-css.d.ts +46 -0
  20. package/dist/v2/paint-css.js +109 -0
  21. package/dist/v2/schema.d.ts +1180 -0
  22. package/dist/v2/schema.js +433 -0
  23. package/dist/v2/upgrade/animations.d.ts +7 -0
  24. package/dist/v2/upgrade/animations.js +255 -0
  25. package/dist/v2/upgrade/box.d.ts +10 -0
  26. package/dist/v2/upgrade/box.js +119 -0
  27. package/dist/v2/upgrade/context.d.ts +42 -0
  28. package/dist/v2/upgrade/context.js +54 -0
  29. package/dist/v2/upgrade/effects.d.ts +25 -0
  30. package/dist/v2/upgrade/effects.js +204 -0
  31. package/dist/v2/upgrade/geometry.d.ts +9 -0
  32. package/dist/v2/upgrade/geometry.js +162 -0
  33. package/dist/v2/upgrade/gradient.d.ts +14 -0
  34. package/dist/v2/upgrade/gradient.js +79 -0
  35. package/dist/v2/upgrade/keys.d.ts +9 -0
  36. package/dist/v2/upgrade/keys.js +31 -0
  37. package/dist/v2/upgrade/mask.d.ts +7 -0
  38. package/dist/v2/upgrade/mask.js +64 -0
  39. package/dist/v2/upgrade/paints.d.ts +21 -0
  40. package/dist/v2/upgrade/paints.js +258 -0
  41. package/dist/v2/upgrade/root.d.ts +21 -0
  42. package/dist/v2/upgrade/root.js +94 -0
  43. package/dist/v2/upgrade/svg-paths.d.ts +38 -0
  44. package/dist/v2/upgrade/svg-paths.js +225 -0
  45. package/dist/v2/upgrade/text.d.ts +7 -0
  46. package/dist/v2/upgrade/text.js +132 -0
  47. package/dist/v2/upgrade/tree.d.ts +15 -0
  48. package/dist/v2/upgrade/tree.js +49 -0
  49. package/dist/v2/upgrade/variables.d.ts +8 -0
  50. package/dist/v2/upgrade/variables.js +24 -0
  51. package/dist/v2/upgrade/zones.d.ts +12 -0
  52. package/dist/v2/upgrade/zones.js +63 -0
  53. package/dist/v2/upgrade.d.ts +17 -0
  54. package/dist/v2/upgrade.js +143 -0
  55. package/dist/v2/version.d.ts +6 -0
  56. package/dist/v2/version.js +7 -0
  57. package/package.json +6 -2
package/dist/patterns.js CHANGED
@@ -134,20 +134,20 @@ export function generatePatternSVG(options) {
134
134
  const fillAttr = isStrokeOnly ? 'none' : color;
135
135
  const strokeAttr = isStrokeOnly ? color : 'none';
136
136
  const strokeWidthAttr = isStrokeOnly ? '1.5' : '0';
137
- patternContent += `
138
- <g transform="translate(${x}, ${y}) scale(${scaleVar}) rotate(${rotVar}) translate(-12, -12)" fill="${fillAttr}" stroke="${strokeAttr}" stroke-width="${strokeWidthAttr}" stroke-linecap="round" stroke-linejoin="round">
139
- ${contentSvg}
140
- </g>
137
+ patternContent += `
138
+ <g transform="translate(${x}, ${y}) scale(${scaleVar}) rotate(${rotVar}) translate(-12, -12)" fill="${fillAttr}" stroke="${strokeAttr}" stroke-width="${strokeWidthAttr}" stroke-linecap="round" stroke-linejoin="round">
139
+ ${contentSvg}
140
+ </g>
141
141
  `;
142
142
  }
143
143
  }
144
144
  }
145
145
  }
146
- const svgString = `
147
- <svg xmlns="http://www.w3.org/2000/svg" width="${baseSize}" height="${baseSize}" viewBox="0 0 ${baseSize} ${baseSize}">
148
- <rect width="100%" height="100%" fill="${bgColor}" />
149
- ${patternContent}
150
- </svg>
146
+ const svgString = `
147
+ <svg xmlns="http://www.w3.org/2000/svg" width="${baseSize}" height="${baseSize}" viewBox="0 0 ${baseSize} ${baseSize}">
148
+ <rect width="100%" height="100%" fill="${bgColor}" />
149
+ ${patternContent}
150
+ </svg>
151
151
  `;
152
152
  return `data:image/svg+xml;utf8,${encodeURIComponent(svgString.replace(/\s+/g, ' ').trim())}`;
153
153
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type FrameSilhouette } from "../frame-silhouette.js";
7
+ import type { Geometry } from "./schema.js";
8
+ export type Outline = {
9
+ /** The figure to draw, or null for a box (a rectangle, or an ellipse drawn round). */
10
+ silhouette: FrameSilhouette | null;
11
+ /** A colour fill paints inside the figure; an open stroke does not take one. */
12
+ fillable: boolean;
13
+ /** An ellipse: the box with fully rounded corners. */
14
+ round: boolean;
15
+ /** The catalogue name, for the mask of a non-flat fill. */
16
+ preset?: string;
17
+ /** A single custom path (the frame of a photo or a blob), with its viewBox. */
18
+ path?: {
19
+ d: string;
20
+ viewBox: string;
21
+ };
22
+ };
23
+ export declare function geometryOutline(geometry: Geometry | undefined): Outline;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // The outline of a 2.0 shape: what clips its fill and carries its stroke. One
7
+ // function for every renderer that draws a shape in the DOM.
8
+ import { frameSilhouette } from "../frame-silhouette.js";
9
+ import { shapeDrawing } from "../geoShapes.js";
10
+ const BOX = { silhouette: null, fillable: true, round: false };
11
+ export function geometryOutline(geometry) {
12
+ if (!geometry || geometry.kind === "rect")
13
+ return BOX;
14
+ if (geometry.kind === "line" || geometry.kind === "preset" || geometry.kind === "ellipse") {
15
+ // 1.x drew its circle as the catalogue's `circle` path; the box is also rounded.
16
+ const preset = geometry.kind === "line" ? "line" : geometry.kind === "ellipse" ? "circle" : geometry.name;
17
+ const drawing = shapeDrawing(preset);
18
+ if (!drawing)
19
+ return BOX;
20
+ return {
21
+ silhouette: frameSilhouette({ geoShape: preset }),
22
+ fillable: drawing.kind === "polygon" || !!drawing.fillable,
23
+ round: geometry.kind === "ellipse",
24
+ preset,
25
+ };
26
+ }
27
+ if (geometry.kind === "paths" && geometry.paths.length === 1 && !geometry.paths[0].fill && !geometry.paths[0].stroke) {
28
+ const viewBox = geometry.viewBox.join(" ");
29
+ const silhouette = frameSilhouette({ svgPath: geometry.paths[0].d, svgViewBox: viewBox });
30
+ // upgrade leaves out the colour 1.x did not paint inside a custom path, so whatever fill remains is drawn.
31
+ return silhouette ? { silhouette, fillable: true, round: false, path: { d: silhouette.d, viewBox: silhouette.viewBox } } : BOX;
32
+ }
33
+ // A drawing of several paths (an SVG) paints itself; polygon and star are not written by upgrade yet.
34
+ return BOX;
35
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export * from "./layer-blocks.js";
7
+ export * from "./schema.js";
8
+ export * from "./upgrade.js";
9
+ export type { UpgradeContext } from "./upgrade/context.js";
10
+ export * from "./paint-css.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // The 2.0 document, still a draft. Nothing here is read by a player yet; the
7
+ // published format is the one the package root describes.
8
+ export * from "./layer-blocks.js";
9
+ export * from "./schema.js";
10
+ export * from "./upgrade.js";
11
+ export * from "./paint-css.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export declare const LAYER_TYPES: readonly ["text", "shape", "image", "lottie", "group"];
7
+ export type LayerType = (typeof LAYER_TYPES)[number];
8
+ export declare const BLOCKS: readonly ["fills", "strokes", "effects", "animations", "motion", "mask", "geometry", "corners", "text", "image", "a11y", "interactions", "children"];
9
+ export type Block = (typeof BLOCKS)[number];
10
+ export declare const LAYER_BLOCKS: Record<LayerType, readonly Block[]>;
11
+ export declare function admits(type: LayerType, block: Block): boolean;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // Which block each layer type admits. The single source of truth for the 2.0
7
+ // document: the schema builds each layer object from this table, so a block on
8
+ // a type that does not admit it is a validation error rather than ignored data.
9
+ export const LAYER_TYPES = ["text", "shape", "image", "lottie", "group"];
10
+ export const BLOCKS = [
11
+ "fills",
12
+ "strokes",
13
+ "effects",
14
+ "animations",
15
+ "motion",
16
+ "mask",
17
+ "geometry",
18
+ "corners",
19
+ "text",
20
+ "image",
21
+ "a11y",
22
+ "interactions",
23
+ "children",
24
+ ];
25
+ export const LAYER_BLOCKS = {
26
+ text: ["fills", "strokes", "effects", "animations", "motion", "mask", "text", "interactions"],
27
+ shape: ["fills", "strokes", "effects", "animations", "motion", "mask", "geometry", "corners", "a11y", "interactions"],
28
+ image: ["strokes", "effects", "animations", "motion", "mask", "corners", "image", "a11y", "interactions"],
29
+ lottie: ["effects", "animations", "motion"],
30
+ group: ["effects", "animations", "motion", "interactions", "children"],
31
+ };
32
+ export function admits(type, block) {
33
+ return LAYER_BLOCKS[type].includes(block);
34
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type CSSProperties } from "../fill.js";
7
+ import type { Paint } from "./schema.js";
8
+ import type { Gradient } from "./upgrade/gradient.js";
9
+ /** How a renderer turns a 2.0 colour value into something it can paint. */
10
+ export type PaintColors = {
11
+ /** A colour as CSS; may be a `var()` so a mode change needs no repaint. */
12
+ css(value: unknown): string | undefined;
13
+ /** A concrete colour, for paints drawn into an image (patterns, generative). */
14
+ literal(value: unknown): string | undefined;
15
+ };
16
+ export type PaintTarget = {
17
+ /** Text is painted through its glyphs: a non-flat fill clips to the text. */
18
+ isText?: boolean;
19
+ width?: number;
20
+ height?: number;
21
+ colors: PaintColors;
22
+ /** Shared paints of the document, for `{ ref }`. */
23
+ resources?: Record<string, Paint>;
24
+ };
25
+ type PatternPaint = Extract<Paint, {
26
+ kind: "pattern";
27
+ }>["pattern"];
28
+ /**
29
+ * A 2.0 pattern in the `fillPattern*` fields the 1.x tile painters read, with
30
+ * each colour's role kept beside its literal so the tint can stay a live CSS variable.
31
+ */
32
+ export declare function patternStyle(p: PatternPaint, colors: PaintColors): Record<string, unknown>;
33
+ export declare function gradientCss(gradient: Gradient | {
34
+ type: Gradient["type"];
35
+ angle?: number;
36
+ stops: {
37
+ color: unknown;
38
+ at?: number;
39
+ }[];
40
+ }, colors: PaintColors): string | undefined;
41
+ /**
42
+ * The CSS of one paint. Opacity is returned as `opacity` and is the caller's
43
+ * to place: on its own node when the layer stacks several fills.
44
+ */
45
+ export declare function paintCss(paint: Paint, target: PaintTarget, depth?: number): CSSProperties;
46
+ export {};
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // A 2.0 paint as CSS. One function for every renderer that paints in the DOM
7
+ // (the scene, and through it the player and the editor's canvas). The CSS for
8
+ // patterns and generative fills is still the 1.x one, called through its
9
+ // fields, so both versions paint the same pixels while 1.x files exist.
10
+ import { getFillCss } from "../fill.js";
11
+ const roleOf = (c) => (c && typeof c === "object" && typeof c.var === "string" ? c.var : undefined);
12
+ const rawOf = (c, colors) => (roleOf(c) ? colors.literal(c.fallback) : colors.literal(c));
13
+ /**
14
+ * A 2.0 pattern in the `fillPattern*` fields the 1.x tile painters read, with
15
+ * each colour's role kept beside its literal so the tint can stay a live CSS variable.
16
+ */
17
+ export function patternStyle(p, colors) {
18
+ const list = (p.colors ?? []).map((c) => rawOf(c, colors)).filter((c) => !!c);
19
+ return {
20
+ fillPatternType: p.preset,
21
+ fillPatternColor: list[0],
22
+ fillPatternColorRole: roleOf(p.colors?.[0]),
23
+ fillPatternColors: list.length > 1 ? list : undefined,
24
+ fillPatternBgColor: rawOf(p.bg, colors),
25
+ fillPatternBgColorRole: roleOf(p.bg),
26
+ fillPatternScale: p.scale,
27
+ fillPatternSizes: p.sizes,
28
+ fillPatternCounts: p.counts,
29
+ fillPatternDispersions: p.dispersions,
30
+ fillPatternSvgs: p.svgs,
31
+ fillPatternDirection: p.motion?.direction,
32
+ fillPatternSpeed: p.motion?.period,
33
+ };
34
+ }
35
+ const pct = (at) => `${+(at * 100).toFixed(4)}%`;
36
+ export function gradientCss(gradient, colors) {
37
+ const stops = [];
38
+ for (const stop of gradient.stops) {
39
+ const color = colors.css(stop.color);
40
+ if (!color)
41
+ return undefined;
42
+ stops.push(stop.at === undefined ? color : `${color} ${pct(stop.at)}`);
43
+ }
44
+ const head = gradient.type === "linear"
45
+ ? gradient.angle === undefined ? "" : `${gradient.angle}deg, `
46
+ : gradient.type === "conic"
47
+ ? gradient.angle === undefined ? "" : `from ${gradient.angle}deg, `
48
+ : "";
49
+ return `${gradient.type}-gradient(${head}${stops.join(", ")})`;
50
+ }
51
+ const clipToText = (css) => ({
52
+ ...css,
53
+ backgroundClip: "text",
54
+ WebkitBackgroundClip: "text",
55
+ color: "transparent",
56
+ });
57
+ const withOpacity = (css, opacity) => opacity === undefined || opacity === 1 ? css : { ...css, opacity: String(opacity) };
58
+ /**
59
+ * The CSS of one paint. Opacity is returned as `opacity` and is the caller's
60
+ * to place: on its own node when the layer stacks several fills.
61
+ */
62
+ export function paintCss(paint, target, depth = 0) {
63
+ const { colors, isText } = target;
64
+ if ("ref" in paint) {
65
+ const shared = target.resources?.[paint.ref];
66
+ // A resource pointing at another resource is followed once; a loop paints nothing.
67
+ return shared && depth < 4 ? paintCss(shared, target, depth + 1) : {};
68
+ }
69
+ const flat = (color) => color ? (isText ? { color } : { backgroundColor: color }) : {};
70
+ switch (paint.kind) {
71
+ case "color":
72
+ return withOpacity(flat(colors.css(paint.value)), paint.opacity);
73
+ case "gradient": {
74
+ const css = paint.gradient ? gradientCss(paint.gradient, colors) : undefined;
75
+ if (!css)
76
+ return {};
77
+ const out = { backgroundImage: css };
78
+ return withOpacity(isText ? clipToText(out) : out, paint.opacity);
79
+ }
80
+ case "pattern": {
81
+ const p = paint.pattern;
82
+ // Baked into an image: every colour is the one the active palette gives.
83
+ const list = (p.colors ?? []).map((c) => colors.literal(c)).filter((c) => !!c);
84
+ const css = getFillCss({
85
+ ...patternStyle(p, colors),
86
+ type: isText ? "text" : "shape",
87
+ fillType: "pattern",
88
+ fillPatternType: p.preset ?? "clouds",
89
+ fillPatternColor: list[0],
90
+ fillPatternColors: list.length > 1 ? list : undefined,
91
+ fillPatternBgColor: colors.literal(p.bg),
92
+ });
93
+ return withOpacity(css, paint.opacity);
94
+ }
95
+ case "generative": {
96
+ const css = getFillCss({
97
+ type: isText ? "text" : "shape",
98
+ width: target.width,
99
+ height: target.height,
100
+ fillType: "generative",
101
+ fillGenerative: paint.generative,
102
+ });
103
+ return withOpacity(css, paint.opacity);
104
+ }
105
+ default:
106
+ // image and texture are drawn as their own nodes by the renderer.
107
+ return {};
108
+ }
109
+ }