@oim-media/player-oim 1.30.1 → 1.31.0

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,9 +26,9 @@ import "@oim-media/player-oim";
26
26
  ```
27
27
 
28
28
  The second form is also reachable as the subpath `@oim-media/player-oim/cdn`.
29
- The single file is about **59 KB gzip** and includes the verifier. Lottie is not
30
- in it: it is loaded from `dist/vendor/` only when a file uses it. A test keeps the
31
- file under a 59 KB budget.
29
+ The single file is about **53 KB gzip** and includes the verifier. Lottie, generative fills and pattern tiles are not
30
+ in it: each is loaded from `dist/vendor/`, next to the player, only when a file uses it. A test keeps the
31
+ file under a 55 KB budget.
32
32
 
33
33
  ## Usage
34
34
 
@@ -211,8 +211,8 @@ from `https://api.oim.media/v1/media/keys`. A page can point that at its own
211
211
  backend with `window.OIM_PLAYER_CONFIG = { keysUrl: "..." }`, set before the
212
212
  player loads. The player never holds a private key.
213
213
 
214
- Network use: the `.oim` file itself, the key endpoint when needed, and the Lottie
215
- library from the package's `dist/vendor/` when a file uses Lottie. The player makes
214
+ Network use: the `.oim` file itself, the key endpoint when needed, and the optional parts (Lottie, generative fills, pattern tiles)
215
+ from the package's `dist/vendor/` when a file uses them. The player makes
216
216
  no analytics requests.
217
217
 
218
218
  A valid signature proves the file has not changed since it was signed. It does not
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { mediaFilterCss } from "@oim-media/core";
1
2
  // ../scene/src/legacy/modes.ts
2
3
  /**
3
4
  * @license
@@ -2000,7 +2001,7 @@ function normalize(style) {
2000
2001
  };
2001
2002
  }
2002
2003
  /** Fixed order: preset, blur, brightness, contrast, saturation, hue-rotate. `undefined` if everything is neutral. */
2003
- function mediaFilterCss(style) {
2004
+ function mediaFilterCss$1(style) {
2004
2005
  const a = normalize(style);
2005
2006
  const parts = [];
2006
2007
  if (a.preset !== void 0) parts.push(FILTER_PRESET_CSS[a.preset]);
@@ -2244,12 +2245,16 @@ function imageSource(slot, value) {
2244
2245
  modes
2245
2246
  } : value;
2246
2247
  }
2247
- function pathsFromLayers(ctx, layers, viewBox) {
2248
+ function pathsFromLayers(ctx, layers, viewBox, original = []) {
2248
2249
  const paths = [];
2249
2250
  for (const item of layers) {
2250
2251
  const part = asObject(item);
2251
2252
  if (!part || typeof part.d !== "string" || !part.d) continue;
2252
2253
  const entry = { d: part.d };
2254
+ if (part.fill === void 0 && part.stroke === void 0) {
2255
+ const { d: _, ...inherited } = original.find((path) => path.d === part.d) ?? { d: "" };
2256
+ Object.assign(entry, inherited);
2257
+ }
2253
2258
  if (typeof part.fill === "string" && part.fill !== "none") entry.fill = part.fill;
2254
2259
  if (typeof part.stroke === "string" && part.stroke !== "none") {
2255
2260
  entry.stroke = part.stroke;
@@ -2273,11 +2278,20 @@ function shapeGeometry(ctx, slot, media) {
2273
2278
  const viewBox = viewBoxOf(ctx.take(style, "svgViewBox"));
2274
2279
  const rawXml = ctx.take(style, "svgRawXml");
2275
2280
  const layers = ctx.take(style, "svgLayers");
2281
+ const content = drawsMarkup(slot) && typeof media === "string" && /<svg/i.test(media) ? media : void 0;
2282
+ if (content) {
2283
+ const parsed = svgToPaths(content);
2284
+ if (parsed.ok) return {
2285
+ kind: "paths",
2286
+ ...parsed.value
2287
+ };
2288
+ }
2276
2289
  if (Array.isArray(layers) && layers.length > 0) {
2277
- const fromLayers = pathsFromLayers(ctx, layers, viewBox);
2290
+ const original = typeof rawXml === "string" && rawXml ? svgToPaths(rawXml) : void 0;
2291
+ const fromLayers = pathsFromLayers(ctx, layers, viewBox, original?.ok ? original.value.paths : []);
2278
2292
  if (fromLayers) return fromLayers;
2279
2293
  }
2280
- const xml = (drawsMarkup(slot) && typeof media === "string" && /<svg/i.test(media) ? media : void 0) ?? (typeof rawXml === "string" && rawXml ? rawXml : drawsMarkup(slot) ? media : void 0);
2294
+ const xml = content ?? (typeof rawXml === "string" && rawXml ? rawXml : drawsMarkup(slot) ? media : void 0);
2281
2295
  if (xml) {
2282
2296
  const parsed = svgToPaths(xml);
2283
2297
  if (parsed.ok) return {
@@ -3368,6 +3382,90 @@ function compareLangs(slot, before, after) {
3368
3382
  if (a.size !== b.size || a.maxWidthValue !== b.maxWidthValue) return "style-only";
3369
3383
  return "none";
3370
3384
  }
3385
+ // ../scene/src/legacy/shadow.ts
3386
+ /**
3387
+ * @license
3388
+ * Copyright (c) 2026 Xue Studios LLC
3389
+ * SPDX-License-Identifier: Apache-2.0
3390
+ */
3391
+ /** The shadow colour with its opacity, for drop-shadow and text-shadow alike. */
3392
+ function shadowColorCss(style) {
3393
+ const alpha = style.shadowOpacity !== void 0 ? Math.max(0, Math.min(100, style.shadowOpacity)) / 100 : 1;
3394
+ const sanitized = (style.shadowColor || "#000000").replace("#", "");
3395
+ const complete = sanitized.length === 3 ? sanitized.split("").map(function(c) {
3396
+ return c + c;
3397
+ }).join("") : sanitized;
3398
+ const r = parseInt(complete.substring(0, 2), 16) || 0;
3399
+ const g = parseInt(complete.substring(2, 4), 16) || 0;
3400
+ const b = parseInt(complete.substring(4, 6), 16) || 0;
3401
+ const baseColor = "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
3402
+ return style.shadowColorRole ? alpha < 1 ? "color-mix(in srgb, " + resolveCssColor(style.shadowColorRole, baseColor) + " " + Math.round(alpha * 100) + "%, transparent)" : resolveCssColor(style.shadowColorRole, baseColor) : baseColor;
3403
+ }
3404
+ // ../scene/src/blocks/effects.ts
3405
+ /**
3406
+ * @license
3407
+ * Copyright (c) 2026 Xue Studios LLC
3408
+ * SPDX-License-Identifier: Apache-2.0
3409
+ */
3410
+ /** The image filters of a backdrop or a filter, as the media-filter CSS reads them. */
3411
+ function filterStyle(filters) {
3412
+ const f = filters ?? {};
3413
+ const percent = (v) => typeof v === "number" ? +(v * 100).toFixed(6) : void 0;
3414
+ return {
3415
+ filterPreset: f.preset,
3416
+ filterBlur: f.blur,
3417
+ filterBrightness: percent(f.brightness),
3418
+ filterContrast: percent(f.contrast),
3419
+ filterSaturate: percent(f.saturate),
3420
+ filterHueRotate: f.hueRotate
3421
+ };
3422
+ }
3423
+ /** A glow with no colour, or one the document cannot resolve, is this amber. */
3424
+ var GLOW_FALLBACK = "#f59e0b";
3425
+ function effectsToStyle(effects, ctx) {
3426
+ const filter = [];
3427
+ const textShadow = [];
3428
+ const defs = [];
3429
+ for (const fx of effects ?? []) if (fx.kind === "blur") filter.push(`blur(${fx.radius}px)`);
3430
+ else if (fx.kind === "glow") {
3431
+ const c = ctx.colorCss(fx.color) || GLOW_FALLBACK;
3432
+ const r = fx.radius;
3433
+ if (ctx.isText) textShadow.push(`0px 0px ${r * .4}px ${c}`, `0px 0px ${r}px ${c}`);
3434
+ else filter.push(`drop-shadow(0px 0px ${r * .4}px ${c}) drop-shadow(0px 0px ${r}px ${c})`);
3435
+ } else if (fx.kind === "shadow") {
3436
+ const bound = fx.color && typeof fx.color === "object" ? fx.color : void 0;
3437
+ const c = fx.opacity !== void 0 ? shadowColorCss({
3438
+ shadowColor: bound ? bound.fallback : fx.color,
3439
+ shadowOpacity: fx.opacity * 100,
3440
+ shadowColorRole: bound?.var
3441
+ }) : ctx.colorCss(fx.color ?? "#000000") || "#000000";
3442
+ const part = `${fx.x || 0}px ${fx.y || 0}px ${fx.blur || 0}px ${c}`;
3443
+ if (ctx.isText) textShadow.push(part);
3444
+ else filter.push(`drop-shadow(${part})`);
3445
+ } else if (fx.kind === "grain") {
3446
+ if (!ctx.grainable) continue;
3447
+ const id = "oim-grain-" + ctx.layerId.replace(/[^A-Za-z0-9_-]/g, "_");
3448
+ defs.push({
3449
+ kind: "grain",
3450
+ id,
3451
+ effect: fx
3452
+ });
3453
+ filter.push(`url(#${id})`);
3454
+ } else if (fx.kind === "texture") defs.push({
3455
+ kind: "texture",
3456
+ effect: fx
3457
+ });
3458
+ const backdrop = effects?.find((fx) => fx.kind === "backdrop");
3459
+ let backdropFilter;
3460
+ if (backdrop?.preset === "duotone") defs.push({ kind: "duotone" });
3461
+ else backdropFilter = mediaFilterCss(filterStyle(backdrop));
3462
+ return {
3463
+ filter: filter.join(" "),
3464
+ textShadow: textShadow.join(", "),
3465
+ backdropFilter,
3466
+ defs
3467
+ };
3468
+ }
3371
3469
  // ../scene/src/legacy/v2-layers.ts
3372
3470
  /**
3373
3471
  * @license
@@ -3410,23 +3508,6 @@ function anchorShift(box) {
3410
3508
  return [/left/.test(anchor) ? "0%" : /right/.test(anchor) ? "-100%" : "-50%", /^top/.test(anchor) ? "0%" : /^bottom/.test(anchor) ? "-100%" : "-50%"];
3411
3509
  }
3412
3510
  /**
3413
- * A 2.0 filter set as the 1.x style fields, so the one function all three
3414
- * renderers share (`mediaFilterCss`) still writes the CSS. Every key is
3415
- * present, so spreading it over a 1.x style replaces that style's filters.
3416
- */
3417
- function filterStyle(filters) {
3418
- const f = filters ?? {};
3419
- const percent = (v) => typeof v === "number" ? +(v * 100).toFixed(6) : void 0;
3420
- return {
3421
- filterPreset: f.preset,
3422
- filterBlur: f.blur,
3423
- filterBrightness: percent(f.brightness),
3424
- filterContrast: percent(f.contrast),
3425
- filterSaturate: percent(f.saturate),
3426
- filterHueRotate: f.hueRotate
3427
- };
3428
- }
3429
- /**
3430
3511
  * The 1.x mask fields of a 2.0 mask layer, so the mask helpers keep one input.
3431
3512
  * Every field is written, absent ones as `undefined`, so nothing of 1.x shows through.
3432
3513
  */
@@ -3580,6 +3661,7 @@ function legacyView(document) {
3580
3661
  languages: document.languages,
3581
3662
  slots
3582
3663
  };
3664
+ if (document.canvas.fills?.length) view.canvasFills = document.canvas.fills;
3583
3665
  if (document.fonts) view.fonts = document.fonts;
3584
3666
  const palettes = palettesOf(document.variables);
3585
3667
  if (palettes) view.palettes = palettes;
@@ -4723,7 +4805,7 @@ function nextWheelZoom(zoom, deltaY, deltaMode, pinch) {
4723
4805
  * the format can change without the player being touched. Tying both numbers
4724
4806
  * together would make an internal fix look like a format break.
4725
4807
  */
4726
- var CONTRACT_VERSION = "1.30.1";
4808
+ var CONTRACT_VERSION = "1.31.0";
4727
4809
  /**
4728
4810
  * What the player implements TODAY, measured and not assumed.
4729
4811
  *
@@ -8669,25 +8751,6 @@ function artworkLabel(meta, nodes, lang, principal = lang) {
8669
8751
  if (t && t.type === "text") return t.text;
8670
8752
  return playerString("image", lang);
8671
8753
  }
8672
- // ../scene/src/legacy/shadow.ts
8673
- /**
8674
- * @license
8675
- * Copyright (c) 2026 Xue Studios LLC
8676
- * SPDX-License-Identifier: Apache-2.0
8677
- */
8678
- /** The shadow colour with its opacity, for drop-shadow and text-shadow alike. */
8679
- function shadowColorCss(style) {
8680
- const alpha = style.shadowOpacity !== void 0 ? Math.max(0, Math.min(100, style.shadowOpacity)) / 100 : 1;
8681
- const sanitized = (style.shadowColor || "#000000").replace("#", "");
8682
- const complete = sanitized.length === 3 ? sanitized.split("").map(function(c) {
8683
- return c + c;
8684
- }).join("") : sanitized;
8685
- const r = parseInt(complete.substring(0, 2), 16) || 0;
8686
- const g = parseInt(complete.substring(2, 4), 16) || 0;
8687
- const b = parseInt(complete.substring(4, 6), 16) || 0;
8688
- const baseColor = "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
8689
- return style.shadowColorRole ? alpha < 1 ? "color-mix(in srgb, " + resolveCssColor(style.shadowColorRole, baseColor) + " " + Math.round(alpha * 100) + "%, transparent)" : resolveCssColor(style.shadowColorRole, baseColor) : baseColor;
8690
- }
8691
8754
  // ../core/src/crop.ts
8692
8755
  /**
8693
8756
  * @license
@@ -8786,7 +8849,7 @@ function mountImageFill(slotEl, paint, silhouette, resolvedUrl, fallbackColor) {
8786
8849
  const flip = flipScale(paint.flipX, paint.flipY);
8787
8850
  img.style.transform = flip ? `${crop.transform} scale(${flip[0]}, ${flip[1]})`.trim() : crop.transform;
8788
8851
  img.style.transformOrigin = crop.transformOrigin;
8789
- img.style.filter = mediaFilterCss(filterStyle(paint.filters)) ?? "";
8852
+ img.style.filter = mediaFilterCss$1(filterStyle(paint.filters)) ?? "";
8790
8853
  img.addEventListener("error", () => {
8791
8854
  box.remove();
8792
8855
  if (!fallbackColor) return;
@@ -9883,6 +9946,15 @@ var LegacyRenderer = class {
9883
9946
  const groupChildren = childrenByGroup(slots);
9884
9947
  const v2Layers = v2LayersOf(self.metadata);
9885
9948
  const v2Colors = paintColors(self.metadata);
9949
+ const canvasFill = self.metadata.canvasFills?.[0];
9950
+ if (canvasFill && self._overlay && !onlyIds) {
9951
+ const css = paintCss(canvasFill, {
9952
+ colors: v2Colors,
9953
+ width: self.metadata.canvas_width,
9954
+ height: self.metadata.canvas_height
9955
+ });
9956
+ for (const [prop, value] of Object.entries(css)) self._overlay.style[prop] = value;
9957
+ }
9886
9958
  const v2Literal = (v) => v && typeof v === "object" && typeof v.fallback === "string" ? v2Colors.literal(v.fallback) : v2Colors.literal(v);
9887
9959
  const slotPromises = slots.map(async (slot) => {
9888
9960
  const slotType = slot.type;
@@ -10028,7 +10100,7 @@ var LegacyRenderer = class {
10028
10100
  }
10029
10101
  imgEl.style.display = "block";
10030
10102
  imgEl.style.pointerEvents = "none";
10031
- imgEl.style.filter = slot.type === "image" ? mediaFilterCss(filterStyle(v2Own.image?.filters)) ?? "" : "";
10103
+ imgEl.style.filter = slot.type === "image" ? mediaFilterCss$1(filterStyle(v2Own.image?.filters)) ?? "" : "";
10032
10104
  loopWrap.style.width = "100%";
10033
10105
  loopWrap.style.height = "100%";
10034
10106
  hoverWrap.style.width = "100%";
@@ -10285,7 +10357,8 @@ var LegacyRenderer = class {
10285
10357
  const underFill = v2Own.fills?.[1];
10286
10358
  const underColor = fillKind === "image" && underFill?.kind === "color" ? v2Colors.css(underFill.value) : void 0;
10287
10359
  const resolvedBgColor = fillKind === "color" ? v2Colors.css(v2Fill.value) : imageSrcSafe ? void 0 : underColor;
10288
- if (resolvedBgColor && isGeoLike && !isWindowMask && slotType !== "text" && !isArtisticText && !hasComplexFill) slotEl.style.setProperty("background-color", resolvedBgColor);
10360
+ const isDrawing = v2Own?.type === "shape" && v2Own.geometry?.kind === "paths";
10361
+ if (resolvedBgColor && isGeoLike && !isWindowMask && slotType !== "text" && !isArtisticText && !hasComplexFill && !isDrawing) slotEl.style.setProperty("background-color", resolvedBgColor);
10289
10362
  const hasVector = slotType === "svg" || isSvg || v2Own.geometry?.kind === "paths" || isGeoLike && !!shapeOutline.silhouette;
10290
10363
  const v2Layer = v2Layers.get(String(slot.id));
10291
10364
  const v2Stroke = v2Layer?.strokes?.find((s) => !s.align && "kind" in s.paint && s.paint.kind === "color" && typeof s.width === "number");
@@ -10407,6 +10480,7 @@ var LegacyRenderer = class {
10407
10480
  transformX = duplicatedForInfinite || textAlign === "left" ? "0%" : textAlign === "right" ? "-100%" : "-50%";
10408
10481
  const share = transformX === "0%" ? 0 : transformX === "-100%" ? 1 : .5;
10409
10482
  slotEl.style.left = (box.x + box.width * share).toFixed(2) + "px";
10483
+ if (share > 0 && paintsText && !isArtisticText) slotEl.style.left = `calc(${slotEl.style.left} + ${.25 * share}em)`;
10410
10484
  slotEl.style.top = (box.y + box.height / 2).toFixed(2) + "px";
10411
10485
  } else {
10412
10486
  [transformX, transformY] = anchorShift(box);
@@ -10523,31 +10597,18 @@ var LegacyRenderer = class {
10523
10597
  const addTextShadow = (part) => {
10524
10598
  slotEl.style.textShadow = slotEl.style.textShadow ? slotEl.style.textShadow + ", " + part : part;
10525
10599
  };
10526
- const v2Effects = v2Own.effects;
10527
- for (const fx of v2Effects ?? []) if (fx.kind === "blur") addFilter("blur(" + fx.radius + "px)");
10528
- else if (fx.kind === "glow") {
10529
- const c = v2Colors.css(fx.color) || "#f59e0b";
10530
- const r = fx.radius;
10531
- if (slotType === "text") addTextShadow("0px 0px " + r * .4 + "px " + c + ", 0px 0px " + r + "px " + c);
10532
- else addFilter("drop-shadow(0px 0px " + r * .4 + "px " + c + ") drop-shadow(0px 0px " + r + "px " + c + ")");
10533
- } else if (fx.kind === "shadow") {
10534
- const bound = fx.color && typeof fx.color === "object" ? fx.color : void 0;
10535
- const c = fx.opacity !== void 0 ? shadowColorCss({
10536
- shadowColor: bound ? bound.fallback : fx.color,
10537
- shadowOpacity: fx.opacity * 100,
10538
- shadowColorRole: bound?.var
10539
- }) : v2Colors.css(fx.color ?? "#000000") || "#000000";
10540
- const part = (fx.x || 0) + "px " + (fx.y || 0) + "px " + (fx.blur || 0) + "px " + c;
10541
- if (slotType === "text") addTextShadow(part);
10542
- else addFilter("drop-shadow(" + part + ")");
10543
- } else if (fx.kind === "grain") {
10544
- if (!GRAIN_LAYER_TYPES.includes(slotType)) continue;
10545
- const grainId = "oim-grain-" + String(slot.id).replace(/[^A-Za-z0-9_-]/g, "_");
10546
- self._defineLayerGrain(grainId, fx);
10547
- addFilter("url(#" + grainId + ")");
10548
- } else if (fx.kind === "texture") applyTexture({
10549
- ...fx,
10550
- color: fx.color === void 0 ? void 0 : v2Literal(fx.color)
10600
+ const fxStyle = effectsToStyle(v2Own.effects, {
10601
+ isText: slotType === "text",
10602
+ grainable: GRAIN_LAYER_TYPES.includes(slotType),
10603
+ layerId: String(slot.id),
10604
+ colorCss: (color) => v2Colors.css(color)
10605
+ });
10606
+ if (fxStyle.filter) addFilter(fxStyle.filter);
10607
+ if (fxStyle.textShadow) addTextShadow(fxStyle.textShadow);
10608
+ for (const def of fxStyle.defs) if (def.kind === "grain") self._defineLayerGrain(def.id, def.effect);
10609
+ else if (def.kind === "texture") applyTexture({
10610
+ ...def.effect,
10611
+ color: def.effect.color === void 0 ? void 0 : v2Literal(def.effect.color)
10551
10612
  });
10552
10613
  const targetOpacity = v2Own.opacity ?? 1;
10553
10614
  slotEl.dataset.oimOpacity = String(targetOpacity);
@@ -10558,9 +10619,7 @@ var LegacyRenderer = class {
10558
10619
  slotEl.style.pointerEvents = "none";
10559
10620
  }
10560
10621
  if (slotType === "filter") {
10561
- const backdrop = v2Own.effects?.find((fx) => fx.kind === "backdrop");
10562
- const filterCss = mediaFilterCss(filterStyle(backdrop));
10563
- const filterValue = backdrop?.preset === "duotone" ? "url(#" + getDuotoneFilterId(slot) + ")" : filterCss;
10622
+ const filterValue = fxStyle.defs.some((def) => def.kind === "duotone") ? "url(#" + getDuotoneFilterId(slot) + ")" : fxStyle.backdropFilter;
10564
10623
  if (filterValue) {
10565
10624
  slotEl.style.backdropFilter = filterValue;
10566
10625
  slotEl.style.webkitBackdropFilter = filterValue;