@oim-media/player-oim 1.35.2 → 1.36.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 CHANGED
@@ -26,7 +26,7 @@ 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 **53 KB gzip** and includes the verifier. Lottie, generative fills and pattern tiles are not
29
+ The single file is about **54 KB gzip** and includes the verifier. Lottie, generative fills and pattern tiles are not
30
30
  in it: each is loaded from `dist/vendor/`, next to the player, only when a file uses it. A test keeps the
31
31
  file under a 55 KB budget.
32
32
 
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DYNAMIC_COLOR_ROLES, GRAIN_LAYER_TYPES, cropCss, filterClipPath, flipScale, mediaFilterCss, resolveLineHeight, resolvePalette } from "@oim-media/core";
2
- import { geometryOutline, paintColors, paintCss, palettesOf, patternStyle, typographyCss } from "@oim-media/core/v2";
2
+ import { geometryOutline, paintColors, paintCss, palettesOf, patternStyle, trimDash, typographyCss } from "@oim-media/core/v2";
3
3
  // ../scene/src/runtime/modes.ts
4
4
  /**
5
5
  * @license
@@ -1520,6 +1520,16 @@ function isV2(input) {
1520
1520
  const version = asObject(input)?.oim;
1521
1521
  return typeof version === "string" && /^2\./.test(version);
1522
1522
  }
1523
+ // ../core/src/v2/extensions.ts
1524
+ /**
1525
+ * @license
1526
+ * Copyright (c) 2026 Xue Studios LLC
1527
+ * SPDX-License-Identifier: Apache-2.0
1528
+ */
1529
+ var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set();
1530
+ function unsupportedRequired(document) {
1531
+ return (document.extensionsRequired ?? []).filter((name) => !SUPPORTED_EXTENSIONS.has(name));
1532
+ }
1523
1533
  // ../core/src/v2/base-layer.ts
1524
1534
  /**
1525
1535
  * @license
@@ -2478,7 +2488,7 @@ function nextWheelZoom(zoom, deltaY, deltaMode, pinch) {
2478
2488
  * the format can change without the player being touched. Tying both numbers
2479
2489
  * together would make an internal fix look like a format break.
2480
2490
  */
2481
- var CONTRACT_VERSION = "1.35.2";
2491
+ var CONTRACT_VERSION = "1.36.1";
2482
2492
  /**
2483
2493
  * What the player implements TODAY, measured and not assumed.
2484
2494
  *
@@ -2697,8 +2707,8 @@ function applyCorners(el, layer, round) {
2697
2707
  */
2698
2708
  var SVG_NS = "http://www.w3.org/2000/svg";
2699
2709
  var sequence = 0;
2700
- /** Path data for a silhouette given as polygon points or as a path. */
2701
- var silhouettePath = (figure) => figure.d ?? "M " + figure.points.split(" ").join(" L ") + " Z";
2710
+ /** Path data of a silhouette: every figure is a path now, a polygon preset included. */
2711
+ var silhouettePath = (figure) => figure.d;
2702
2712
  /**
2703
2713
  * A zero-size <svg> holding a clipPath in objectBoundingBox units, so the silhouette
2704
2714
  * maps onto whatever box references it, at any size. Returns the svg and the
@@ -2807,7 +2817,7 @@ function applyGeometry(el, layer, ctx) {
2807
2817
  el.querySelectorAll(":scope > svg[data-oim-figure]").forEach((node) => node.remove());
2808
2818
  el.querySelectorAll(":scope > [data-oim-figure-clip]").forEach((box) => box.replaceWith(...box.querySelectorAll(":scope > img")));
2809
2819
  setMask(el, void 0);
2810
- const outline = geometryOutline(layer.geometry);
2820
+ const outline = geometryOutline(layer.geometry, layer.box);
2811
2821
  const rich = paintedByFillLayer(layer) && !layer.mask;
2812
2822
  if (outline.round && !outline.silhouette) el.style.borderRadius = "50%";
2813
2823
  const figure = outline.silhouette;
@@ -2852,9 +2862,8 @@ function applyGeometry(el, layer, ctx) {
2852
2862
  display: "block",
2853
2863
  overflow: "visible"
2854
2864
  });
2855
- const shape = el.ownerDocument.createElementNS(SVG$3, figure.points ? "polygon" : "path");
2856
- if (figure.points) shape.setAttribute("points", figure.points);
2857
- else shape.setAttribute("d", figure.d);
2865
+ const shape = el.ownerDocument.createElementNS(SVG$3, "path");
2866
+ shape.setAttribute("d", figure.d);
2858
2867
  shape.setAttribute("fill", fill ?? "none");
2859
2868
  if (stroke) {
2860
2869
  shape.setAttribute("stroke", stroke.color);
@@ -2864,6 +2873,20 @@ function applyGeometry(el, layer, ctx) {
2864
2873
  shape.setAttribute("stroke-linecap", "round");
2865
2874
  if (stroke.style === "dashed") shape.setAttribute("stroke-dasharray", "6,4");
2866
2875
  else if (stroke.style === "dotted") shape.setAttribute("stroke-dasharray", "2,3");
2876
+ const tracksTrim = layer.animations?.some((a) => a.tracks?.some((t) => t.property === "trimStart" || t.property === "trimEnd"));
2877
+ const dash = trimDash(layer.geometry?.trim) ?? (tracksTrim ? {
2878
+ dasharray: "1 2",
2879
+ dashoffset: 0
2880
+ } : void 0);
2881
+ if (dash) {
2882
+ shape.removeAttribute("vector-effect");
2883
+ const [, , vbW, vbH] = figure.viewBox.trim().split(" ").map(Number);
2884
+ const scale = (vbW / (layer.box.width || vbW) + vbH / (layer.box.height || vbH)) / 2;
2885
+ shape.setAttribute("stroke-width", String(+(Number(stroke.width) * scale).toFixed(4)));
2886
+ shape.setAttribute("pathLength", "1");
2887
+ shape.setAttribute("stroke-dasharray", dash.dasharray);
2888
+ shape.setAttribute("stroke-dashoffset", String(dash.dashoffset));
2889
+ }
2867
2890
  }
2868
2891
  svg.appendChild(shape);
2869
2892
  el.appendChild(svg);
@@ -7027,7 +7050,8 @@ var valueAt = (track, t) => {
7027
7050
  * only independent properties (`translate`, `scale`, `rotate`), so the box keeps
7028
7051
  * its own `transform`. `len` turns canvas pixels into the scene's length.
7029
7052
  */
7030
- function trackFrames(tracks, len) {
7053
+ function trackFrames(allTracks, len) {
7054
+ const tracks = allTracks.filter((tr) => !isTrim(tr));
7031
7055
  return [...new Set(tracks.flatMap((tr) => tr.keyframes.map((k) => k.t)))].sort((a, b) => a - b).map((t) => {
7032
7056
  const frame = { offset: t };
7033
7057
  let x;
@@ -7047,6 +7071,37 @@ function trackFrames(tracks, len) {
7047
7071
  return frame;
7048
7072
  });
7049
7073
  }
7074
+ var isTrim = (tr) => tr.property === "trimStart" || tr.property === "trimEnd";
7075
+ /**
7076
+ * The frames of the `trimStart` and `trimEnd` tracks, for the outline's own path: the dash of
7077
+ * the trim at each keyframe time (a track the animation lacks keeps the rest value). Empty when
7078
+ * there is no trim track.
7079
+ */
7080
+ function trimFrames(tracks, rest) {
7081
+ const own = tracks.filter(isTrim);
7082
+ const times = [...new Set(own.flatMap((tr) => tr.keyframes.map((k) => k.t)))].sort((a, b) => a - b);
7083
+ const of = (property, t) => {
7084
+ const tr = own.find((x) => x.property === property);
7085
+ return tr ? valueAt(tr, t) : void 0;
7086
+ };
7087
+ return times.map((t) => {
7088
+ const dash = trimDash({
7089
+ start: of("trimStart", t) ?? rest?.start,
7090
+ end: of("trimEnd", t) ?? rest?.end
7091
+ }) ?? {
7092
+ dasharray: "1 2",
7093
+ dashoffset: 0
7094
+ };
7095
+ const frame = {
7096
+ offset: t,
7097
+ strokeDasharray: dash.dasharray,
7098
+ strokeDashoffset: String(dash.dashoffset)
7099
+ };
7100
+ const e = own.flatMap((tr) => tr.keyframes.filter((k) => k.t === t)).find((k) => k.e !== void 0)?.e;
7101
+ if (e !== void 0) frame.easing = easingToCss(e, "linear");
7102
+ return frame;
7103
+ });
7104
+ }
7050
7105
  /** An animation's frames: its tracks, or the reveal its preset names. */
7051
7106
  function animationFrames(a, len) {
7052
7107
  if (a.tracks) return trackFrames(a.tracks, len);
@@ -7446,12 +7501,11 @@ function applyLoop(el, layer, canvasWidth, len) {
7446
7501
  * Copyright (c) 2026 Xue Studios LLC
7447
7502
  * SPDX-License-Identifier: Apache-2.0
7448
7503
  */
7449
- var layerUses = (layer, nested = false) => {
7504
+ var layerUses = (layer) => {
7450
7505
  const uses = [];
7451
7506
  if (layer.animations?.some((a) => !canAnimate(a))) uses.push("animation:preset");
7452
7507
  if (layer.geometry?.kind === "paths" && (layer.fills ?? []).some((p) => "kind" in p && p.kind === "pattern")) uses.push("paint:pattern-tile");
7453
- if (nested && layer.mask?.mode === "cutout") uses.push("mask");
7454
- for (const child of layer.children ?? []) uses.push(...layerUses(child, true));
7508
+ for (const child of layer.children ?? []) uses.push(...layerUses(child));
7455
7509
  return uses;
7456
7510
  };
7457
7511
  /** The out-of-scope blocks a document uses, each once, sorted. Run it on a document whose references are resolved. */
@@ -7469,8 +7523,10 @@ var notYet = (name) => () => {
7469
7523
  throw new Error(`scene.${name} is not implemented yet`);
7470
7524
  };
7471
7525
  /** The file's language that the reader's own matches (exactly, then by its main tag), else the file's first. */
7526
+ var main = (tag) => tag.toLowerCase().split("-")[0];
7527
+ /** The one rule for matching two language tags: the same tag, or the same primary subtag (en-US ~ en). */
7528
+ var sameLanguage = (a, b) => a.toLowerCase() === b.toLowerCase() || main(a) === main(b);
7472
7529
  function languageOf(languages, reader) {
7473
- const main = (tag) => tag.toLowerCase().split("-")[0];
7474
7530
  return languages.find((l) => reader !== void 0 && l.toLowerCase() === reader.toLowerCase()) ?? languages.find((l) => reader !== void 0 && main(l) === main(reader)) ?? languages[0];
7475
7531
  }
7476
7532
  function mount$1(container, document, _options = {}) {
@@ -7534,6 +7590,8 @@ function mount$1(container, document, _options = {}) {
7534
7590
  len: canvasLen
7535
7591
  });
7536
7592
  let lang = languageOf(document.languages, _options.language ?? (typeof navigator === "undefined" ? void 0 : navigator.language));
7593
+ /** A layer with its own `languages` shows only in those; absent means every language. */
7594
+ const inLanguage = (layer) => !layer.languages || layer.languages.some((l) => sameLanguage(l, lang));
7537
7595
  /** The effects the scene paints (blur, shadow, glow, backdrop); grain, texture and duotone wait for their own painter (see coverage). */
7538
7596
  const applyEffects = (el, layer) => {
7539
7597
  const style = effectsToStyle(layer.effects, {
@@ -7619,13 +7677,14 @@ function mount$1(container, document, _options = {}) {
7619
7677
  fonts
7620
7678
  });
7621
7679
  }
7622
- if (has("visible", "text")) {
7623
- el.toggleAttribute("data-oim-hidden", layer.visible === false);
7624
- if (layer.visible === false) hide(el);
7680
+ if (has("visible", "text", "languages")) {
7681
+ const hidden = layer.visible === false || !inLanguage(layer);
7682
+ el.toggleAttribute("data-oim-hidden", hidden);
7683
+ if (hidden) hide(el);
7625
7684
  else show(el);
7626
7685
  }
7627
7686
  const figure = has("fills", "geometry", "strokes");
7628
- const outline = layer.type === "shape" ? figure ? applyGeometry(el, layer, { colors }) : geometryOutline(layer.geometry) : geometryOutline(void 0);
7687
+ const outline = layer.type === "shape" ? figure ? applyGeometry(el, layer, { colors }) : geometryOutline(layer.geometry, layer.box) : geometryOutline(void 0);
7629
7688
  if (has("effects", "geometry")) el.style.clipPath = filterClip(layer, outline);
7630
7689
  if (has("corners", "geometry")) applyCorners(el, layer, !!outline.round);
7631
7690
  if (has("strokes", "geometry", "fills")) applyStrokes(el, layer, {
@@ -7672,6 +7731,18 @@ function mount$1(container, document, _options = {}) {
7672
7731
  if (paused) timing.iterations === Infinity ? run.cancel() : run.finish?.();
7673
7732
  return run;
7674
7733
  };
7734
+ /** Runs an animation on a layer's box, and its trim tracks on the figure's own outline. */
7735
+ const animateLayer = (el, layer, a, timing) => {
7736
+ const runs = [];
7737
+ const frames = animationFrames(a, len);
7738
+ const box = frames.length ? animate(el, frames, timing) : void 0;
7739
+ if (box) runs.push(box);
7740
+ const trim = a.tracks ? trimFrames(a.tracks, layer.geometry?.trim) : [];
7741
+ const outline = trim.length ? el.querySelector(":scope > svg[data-oim-figure] > *") : null;
7742
+ const own = outline && animate(outline, trim, timing);
7743
+ if (own) runs.push(own);
7744
+ return runs;
7745
+ };
7675
7746
  const animationsOf = (layer, on) => (layer.animations ?? []).filter((a) => a.on === on && canAnimate(a));
7676
7747
  const bindAnimations = (el, layer) => {
7677
7748
  for (const a of [...animationsOf(layer, "load"), ...animationsOf(layer, "loop")]) {
@@ -7704,7 +7775,7 @@ function mount$1(container, document, _options = {}) {
7704
7775
  const words = el.textContent ?? "";
7705
7776
  el.replaceChildren(body);
7706
7777
  const frames = entranceFrames(a.preset);
7707
- const stagger = typeof a.params?.speed === "number" ? a.params.speed : void 0;
7778
+ const stagger = typeof a.stagger === "number" ? a.stagger / 1e3 : typeof a.params?.speed === "number" ? a.params.speed : void 0;
7708
7779
  applyEntrance(body, words, a.preset, stagger, (a.delay ?? 0) / 1e3, (span, start) => void animate(span, frames, {
7709
7780
  duration: ENTRANCE_MS,
7710
7781
  delay: start * 1e3,
@@ -7713,7 +7784,18 @@ function mount$1(container, document, _options = {}) {
7713
7784
  }));
7714
7785
  continue;
7715
7786
  }
7716
- animate(el, animationFrames(a, len), animationTiming(a));
7787
+ animateLayer(el, layer, a, animationTiming(a));
7788
+ }
7789
+ for (const a of animationsOf(layer, "press")) {
7790
+ let last = [];
7791
+ el.addEventListener("pointerdown", () => {
7792
+ if (paused) return;
7793
+ for (const run of last) run.cancel();
7794
+ last = animateLayer(el, layer, a, {
7795
+ ...animationTiming(a),
7796
+ fill: "none"
7797
+ });
7798
+ });
7717
7799
  }
7718
7800
  const hover = animationsOf(layer, "hover");
7719
7801
  if (!hover.length) return;
@@ -7724,13 +7806,10 @@ function mount$1(container, document, _options = {}) {
7724
7806
  r.playbackRate = 1;
7725
7807
  r.play();
7726
7808
  }
7727
- else for (const a of hover) {
7728
- const r = animate(el, animationFrames(a, len), {
7729
- ...animationTiming(a),
7730
- duration: a.duration || 200
7731
- });
7732
- if (r) runs.push(r);
7733
- }
7809
+ else for (const a of hover) runs.push(...animateLayer(el, layer, a, {
7810
+ ...animationTiming(a),
7811
+ duration: a.duration || 200
7812
+ }));
7734
7813
  });
7735
7814
  el.addEventListener("pointerleave", () => {
7736
7815
  for (const r of runs) r.reverse();
@@ -7745,7 +7824,7 @@ function mount$1(container, document, _options = {}) {
7745
7824
  visible
7746
7825
  };
7747
7826
  const { el } = entry;
7748
- el.toggleAttribute("data-oim-hidden", !visible);
7827
+ el.toggleAttribute("data-oim-hidden", !visible || !inLanguage(entry.layer));
7749
7828
  const enter = animationsOf(entry.layer, "enter")[0];
7750
7829
  const frames = enter ? animationFrames(enter, len) : revealFrames(REVEAL_DEFAULT.effect, true);
7751
7830
  const timing = enter ? {
@@ -7756,8 +7835,10 @@ function mount$1(container, document, _options = {}) {
7756
7835
  easing: REVEAL_DEFAULT.easing
7757
7836
  };
7758
7837
  if (visible) {
7759
- show(el);
7760
- if (!paused) animate(el, frames, timing);
7838
+ if (inLanguage(entry.layer)) {
7839
+ show(el);
7840
+ if (!paused) animate(el, frames, timing);
7841
+ }
7761
7842
  return;
7762
7843
  }
7763
7844
  const run = paused ? void 0 : animate(el, [...frames].reverse(), timing);
@@ -7791,7 +7872,7 @@ function mount$1(container, document, _options = {}) {
7791
7872
  continue;
7792
7873
  }
7793
7874
  if (action.type === "play") {
7794
- for (const a of animationsOf(entry.layer, "action")) if (!paused) animate(entry.el, animationFrames(a, len), {
7875
+ for (const a of animationsOf(entry.layer, "action")) if (!paused) animateLayer(entry.el, entry.layer, a, {
7795
7876
  ...animationTiming(a),
7796
7877
  fill: "none"
7797
7878
  });
@@ -7826,14 +7907,21 @@ function mount$1(container, document, _options = {}) {
7826
7907
  applyLoop(el, layer, width, len);
7827
7908
  if (!_options.disableActions) bindInteractions(el, layer.interactions, runActions(layer.id));
7828
7909
  bindAnimations(el, layer);
7829
- for (const child of layer.children ?? []) paint(child, el, layer.box);
7910
+ for (const child of layer.children ?? []) place(child, el, layer.box);
7830
7911
  parent.appendChild(el);
7831
7912
  };
7832
- for (const layer of document.layers) if (layer.mask?.mode === "cutout") applyCutoutMask(root, layer, {
7833
- width,
7834
- height
7835
- });
7836
- else paint(layer, root, canvas);
7913
+ const place = (layer, parent, frame) => {
7914
+ if (layer.mask?.mode === "cutout") applyCutoutMask(parent, {
7915
+ ...layer,
7916
+ box: {
7917
+ ...layer.box,
7918
+ x: (layer.box.x ?? 0) - frame.x,
7919
+ y: (layer.box.y ?? 0) - frame.y
7920
+ }
7921
+ }, frame);
7922
+ else paint(layer, parent, frame);
7923
+ };
7924
+ for (const layer of document.layers) place(layer, root, canvas);
7837
7925
  container.appendChild(letterbox);
7838
7926
  let frame;
7839
7927
  const pendingMoves = /* @__PURE__ */ new Map();
@@ -7874,7 +7962,10 @@ function mount$1(container, document, _options = {}) {
7874
7962
  setMode({ language }) {
7875
7963
  if (language === void 0) return;
7876
7964
  lang = languageOf(document.languages, language);
7877
- for (const { el, layer } of entries.values()) if (layer.type === "text" || layer.type === "image") paintBlocks(el, layer, /* @__PURE__ */ new Set(["text", "image"]));
7965
+ for (const { el, layer } of entries.values()) {
7966
+ const keys = [...layer.type === "text" || layer.type === "image" ? ["text", "image"] : [], ...layer.languages ? ["languages"] : []];
7967
+ if (keys.length) paintBlocks(el, layer, new Set(keys));
7968
+ }
7878
7969
  },
7879
7970
  play() {
7880
7971
  if (still) return;
@@ -8273,6 +8364,16 @@ var ImageEngine = class extends EngineShell {
8273
8364
  code: "unsupported-version",
8274
8365
  message: "OIM 1.x files are no longer painted; upgrade the file with the CLI or re-export it."
8275
8366
  } }));
8367
+ } else {
8368
+ const extensions = unsupportedRequired(file);
8369
+ if (extensions.length) {
8370
+ paints = false;
8371
+ this.host.dispatchEvent(new CustomEvent("oim:error", { detail: {
8372
+ code: "unsupported-extension",
8373
+ extensions,
8374
+ message: "The file requires extensions this player does not implement: " + extensions.join(", ")
8375
+ } }));
8376
+ }
8276
8377
  }
8277
8378
  if (ticket !== this._renderTicket) return;
8278
8379
  }