@oim-media/core 1.27.10 → 1.27.12

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 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.27.10"`).
29
+ - `CONTRACT_VERSION`: the contract version this build implements (`"1.27.12"`).
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
 
@@ -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.27.10";
44
+ export declare const CONTRACT_VERSION = "1.27.12";
45
45
  /**
46
46
  * The first version of the format. Whatever requires nothing more requires this.
47
47
  *
@@ -41,7 +41,9 @@
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.27.10";
44
+ export const CONTRACT_VERSION = "1.27.12";
45
+ // 1.27.12: an SVG layer upgrades from its content, not svgRawXml; no format change.
46
+ // 1.27.11: fixes to the 2.0 upgrade (corner shorthand, hollow text, SVG icons, colour under a photo); no format change.
45
47
  // 1.27.10: no format change; the player paints from 2.0 and a zone is a group without its flow.
46
48
  // 1.27.9: numbers beyond +/-(2^53 - 1) have no canonical form; the Rust crate parses decimals exactly.
47
49
  // 1.27.8: Flutter stroke and effects scale with the canvas; packages on npm, pub.dev and crates.io.
@@ -78,7 +78,9 @@ function shapeGeometry(ctx, slot, media) {
78
78
  if (fromLayers)
79
79
  return fromLayers;
80
80
  }
81
- const xml = typeof rawXml === "string" && rawXml ? rawXml : drawsMarkup(slot) ? media : undefined;
81
+ // 1.x painted the content of a markup layer; svgRawXml is the untouched original it was edited from.
82
+ const content = drawsMarkup(slot) && typeof media === "string" && /<svg/i.test(media) ? media : undefined;
83
+ const xml = content ?? (typeof rawXml === "string" && rawXml ? rawXml : drawsMarkup(slot) ? media : undefined);
82
84
  if (xml) {
83
85
  const parsed = svgToPaths(xml);
84
86
  if (parsed.ok)
@@ -104,11 +106,17 @@ const CORNER_KEYS = [
104
106
  ["borderRadiusBR", "borderBottomRightRadius"],
105
107
  ["borderRadiusBL", "borderBottomLeftRadius"],
106
108
  ];
109
+ // The CSS shorthand order: one value for all, two for TL/BR and TR/BL, three for TL, TR/BL, BR.
110
+ const SHORTHAND = [[0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 2, 1], [0, 1, 2, 3]];
107
111
  function cornersOf(ctx, style) {
108
- const all = toCanvasUnits(ctx.take(style, "borderRadius"), ctx.canvas.width) ?? 0;
109
- const each = CORNER_KEYS.map((keys) => {
110
- const values = keys.map((key) => toCanvasUnits(ctx.take(style, key), ctx.canvas.width));
111
- return values.find((v) => v !== undefined);
112
+ const W = ctx.canvas.width;
113
+ const raw = ctx.take(style, "borderRadius");
114
+ const tokens = typeof raw === "string" ? raw.trim().split(/\s+/) : [];
115
+ const shorthand = tokens.length > 1 && tokens.length <= 4 ? SHORTHAND[tokens.length - 1].map((i) => toCanvasUnits(tokens[i], W)) : [];
116
+ const all = tokens.length > 1 ? 0 : (toCanvasUnits(raw, W) ?? 0);
117
+ const each = CORNER_KEYS.map((keys, corner) => {
118
+ const values = keys.map((key) => toCanvasUnits(ctx.take(style, key), W));
119
+ return values.find((v) => v !== undefined) ?? shorthand[corner];
112
120
  });
113
121
  if (each.some((v) => v !== undefined)) {
114
122
  const four = each.map((v) => Math.max(0, v ?? all));
@@ -24,7 +24,7 @@ export function colorOf(ctx, owner, key, roleKey) {
24
24
  }
25
25
  const numbers = (value) => Array.isArray(value) && value.length > 0 && value.every((n) => typeof n === "number") ? value : undefined;
26
26
  /** The pattern fields that share a prefix: `fillPattern*` on a layer, `backgroundPattern*` on a layer or the canvas. */
27
- function patternOf(ctx, owner, prefix, cssAnimation) {
27
+ function patternOf(ctx, owner, prefix, cssAnimation, canvasBackground = false) {
28
28
  const preset = ctx.take(owner, `${prefix}Type`);
29
29
  const single = colorOf(ctx, owner, `${prefix}Color`, `${prefix}ColorRole`);
30
30
  const bg = colorOf(ctx, owner, `${prefix}BgColor`, `${prefix}BgColorRole`);
@@ -39,7 +39,8 @@ function patternOf(ctx, owner, prefix, cssAnimation) {
39
39
  const dispersions = numbers(ctx.take(owner, `${prefix}Dispersions`)) ?? numbers(ctx.take(owner, `${prefix}Dispersion`));
40
40
  const colors = Array.isArray(list) ? list.filter(isColor) : [];
41
41
  // A raw SVG tile carries no preset: only the colours it is recoloured with, its fit and its motion.
42
- const tile = prefix === "backgroundPattern" && typeof owner.svgRawXml === "string" && owner.svgRawXml !== "";
42
+ // Only the canvas background tiles its raw SVG; any other SVG layer is a drawing.
43
+ const tile = canvasBackground && prefix === "backgroundPattern" && typeof owner.svgRawXml === "string" && owner.svgRawXml !== "";
43
44
  if ((typeof preset !== "string" || !preset) && !tile && single === undefined && bg === undefined && colors.length === 0)
44
45
  return undefined;
45
46
  const pattern = typeof preset === "string" && preset ? { preset } : {};
@@ -118,7 +119,8 @@ function fillOf(ctx, slot) {
118
119
  const image = imageOf(ctx, style);
119
120
  const cssAnimation = style.cssAnimation;
120
121
  const fillPattern = patternOf(ctx, style, "fillPattern", cssAnimation);
121
- const backgroundPattern = patternOf(ctx, style, "backgroundPattern", cssAnimation);
122
+ const canvasBackground = slot.raw.is_background_pattern === true || slot.raw.id === "background-pattern-slot";
123
+ const backgroundPattern = patternOf(ctx, style, "backgroundPattern", cssAnimation, canvasBackground);
122
124
  const generative = asObject(ctx.take(style, "fillGenerative")) ?? asObject(ctx.take(style, "backgroundGenerative"));
123
125
  const backgroundFit = ctx.take(style, "backgroundFit");
124
126
  const textGradient = ctx.take(style, "textGradientType");
@@ -169,6 +171,8 @@ function textStrokeOf(ctx, style) {
169
171
  }
170
172
  export function convertPaints(ctx, slot, layer) {
171
173
  const { style } = slot;
174
+ // A text whose letter 1.x left transparent (only its stroke shows): no fill would paint it black.
175
+ const hollowText = layer.type === "text" && style.fillColor === "transparent" && (style.fillType === undefined || style.fillType === "solid" || style.fillType === "color");
172
176
  const fills = fillOf(ctx, slot);
173
177
  const fill = Array.isArray(fills) ? fills[0] : fills;
174
178
  // 1.x painted no colour inside a custom path (only a photo, a gradient or a
@@ -178,6 +182,8 @@ export function convertPaints(ctx, slot, layer) {
178
182
  const colourless = slot.type === "geo" && (customPath || shape === "scribble") && !!fill && "kind" in fill && fill.kind === "color";
179
183
  if (fill && !colourless && admits(layer.type, "fills"))
180
184
  layer.fills = Array.isArray(fills) ? fills : [fill];
185
+ else if (hollowText)
186
+ layer.fills = [{ kind: "color", value: "transparent" }];
181
187
  const strokeStyle = ctx.take(style, "strokeStyle");
182
188
  const dashed = strokeStyle === "dashed" || strokeStyle === "dotted" ? { style: strokeStyle } : {};
183
189
  // 1.x passed borderColor and borderWidth to CSS without a border-style, so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oim-media/core",
3
- "version": "1.27.10",
3
+ "version": "1.27.12",
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",