@oim-media/player-oim 1.34.5 → 1.35.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/dist/esm/index.js CHANGED
@@ -430,7 +430,7 @@ function ensureParallaxKeyframes(root) {
430
430
  * Copyright (c) 2026 Xue Studios LLC
431
431
  * SPDX-License-Identifier: Apache-2.0
432
432
  */
433
- var IDENTITY$1 = [
433
+ var IDENTITY = [
434
434
  1,
435
435
  0,
436
436
  0,
@@ -551,7 +551,7 @@ function then(first, next) {
551
551
  }
552
552
  return out;
553
553
  }
554
- var chain = (...steps) => steps.reduce(then, IDENTITY$1);
554
+ var chain = (...steps) => steps.reduce(then, IDENTITY);
555
555
  /** The presets, each a chain of primitives applied left to right (spec 2026-11-17). */
556
556
  var PRESETS = {
557
557
  "warm-vintage": chain(sepia(.35), contrast(.9), brightness(1.05), saturate(1.1)),
@@ -584,7 +584,7 @@ Object.keys(PRESETS);
584
584
  function colorGradeMatrix(preset, intensity = 100) {
585
585
  if (!Object.hasOwn(PRESETS, preset)) return void 0;
586
586
  const t = Math.min(100, Math.max(0, intensity)) / 100;
587
- return PRESETS[preset].map((v, i) => +(IDENTITY$1[i] + (v - IDENTITY$1[i]) * t).toFixed(6));
587
+ return PRESETS[preset].map((v, i) => +(IDENTITY[i] + (v - IDENTITY[i]) * t).toFixed(6));
588
588
  }
589
589
  // ../core/src/dynamic-colors.ts
590
590
  /**
@@ -1176,15 +1176,15 @@ var PATTERN_MOVES = [
1176
1176
  var TILE = "var(--oim-bg-tile, 160px)";
1177
1177
  var BIG = `calc(${TILE} * 1.15)`;
1178
1178
  var at = (pos) => `background-position: ${pos}`;
1179
- var sized$1 = (size) => `background-size: ${size} ${size}`;
1179
+ var sized = (size) => `background-size: ${size} ${size}`;
1180
1180
  /** The keyframes a moving pattern runs, one tile per lap: the 1.x player's, which the 2.0 scene lost with the old renderer. */
1181
1181
  var PATTERN_KEYFRAMES = [
1182
1182
  `@keyframes background-animation-right { from { ${at("0 0")} } to { ${at(`${TILE} 0`)} } }`,
1183
1183
  `@keyframes background-animation-left { from { ${at("0 0")} } to { ${at(`calc(-1 * ${TILE}) 0`)} } }`,
1184
1184
  `@keyframes background-animation-up { from { ${at("0 0")} } to { ${at(`0 calc(-1 * ${TILE})`)} } }`,
1185
1185
  `@keyframes background-animation-down { from { ${at("0 0")} } to { ${at(`0 ${TILE}`)} } }`,
1186
- `@keyframes background-animation-zoom-in { 0%, 100% { ${sized$1(TILE)} } 50% { ${sized$1(BIG)} } }`,
1187
- `@keyframes background-animation-zoom-out { 0%, 100% { ${sized$1(BIG)} } 50% { ${sized$1(TILE)} } }`,
1186
+ `@keyframes background-animation-zoom-in { 0%, 100% { ${sized(TILE)} } 50% { ${sized(BIG)} } }`,
1187
+ `@keyframes background-animation-zoom-out { 0%, 100% { ${sized(BIG)} } 50% { ${sized(TILE)} } }`,
1188
1188
  "@keyframes background-animation-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.65; } }"
1189
1189
  ].join(" ");
1190
1190
  function ensurePatternKeyframes(doc) {
@@ -1448,1735 +1448,16 @@ function normalizeLegacyKeys(meta) {
1448
1448
  delete out.reedicion;
1449
1449
  return out;
1450
1450
  }
1451
- // ../core/src/v2/layer-blocks.ts
1452
- /**
1453
- * @license
1454
- * Copyright (c) 2026 Xue Studios LLC
1455
- * SPDX-License-Identifier: Apache-2.0
1456
- */
1457
- var LAYER_BLOCKS = {
1458
- text: [
1459
- "fills",
1460
- "strokes",
1461
- "effects",
1462
- "animations",
1463
- "motion",
1464
- "mask",
1465
- "text",
1466
- "interactions"
1467
- ],
1468
- shape: [
1469
- "fills",
1470
- "strokes",
1471
- "effects",
1472
- "animations",
1473
- "motion",
1474
- "mask",
1475
- "geometry",
1476
- "corners",
1477
- "a11y",
1478
- "interactions"
1479
- ],
1480
- image: [
1481
- "strokes",
1482
- "effects",
1483
- "animations",
1484
- "motion",
1485
- "mask",
1486
- "corners",
1487
- "image",
1488
- "a11y",
1489
- "interactions"
1490
- ],
1491
- lottie: [
1492
- "effects",
1493
- "animations",
1494
- "motion"
1495
- ],
1496
- group: [
1497
- "effects",
1498
- "animations",
1499
- "motion",
1500
- "interactions",
1501
- "children"
1502
- ]
1503
- };
1504
- function admits(type, block) {
1505
- return LAYER_BLOCKS[type].includes(block);
1506
- }
1507
1451
  // ../core/src/v2/upgrade/context.ts
1508
1452
  /**
1509
1453
  * @license
1510
1454
  * Copyright (c) 2026 Xue Studios LLC
1511
1455
  * SPDX-License-Identifier: Apache-2.0
1512
1456
  */
1513
- function createContext(canvas, language, roles = /* @__PURE__ */ new Set()) {
1514
- const labels = /* @__PURE__ */ new Map();
1515
- const taken = /* @__PURE__ */ new Map();
1516
- const retired = /* @__PURE__ */ new Set();
1517
- const notes = /* @__PURE__ */ new Set();
1518
- const mark = (owner, key) => {
1519
- let keys = taken.get(owner);
1520
- if (!keys) taken.set(owner, keys = /* @__PURE__ */ new Set());
1521
- keys.add(key);
1522
- };
1523
- return {
1524
- canvas,
1525
- language,
1526
- hasRole: (role) => roles.has(role) || isValidDynamicColorRole(role),
1527
- register(owner, label) {
1528
- labels.set(owner, label);
1529
- },
1530
- take(owner, key) {
1531
- mark(owner, key);
1532
- return owner[key];
1533
- },
1534
- retire(owner, key) {
1535
- mark(owner, key);
1536
- if (owner[key] !== void 0) retired.add(`${labels.get(owner) ?? "?"}.${key}`);
1537
- },
1538
- note(path) {
1539
- notes.add(path);
1540
- },
1541
- finish() {
1542
- const unhandled = new Set(notes);
1543
- for (const [owner, label] of labels) {
1544
- const keys = taken.get(owner);
1545
- for (const key of Object.keys(owner)) if (owner[key] !== void 0 && !keys?.has(key)) unhandled.add(`${label}.${key}`);
1546
- }
1547
- return {
1548
- retired: [...retired].sort(),
1549
- unhandled: [...unhandled].sort()
1550
- };
1551
- }
1552
- };
1553
- }
1554
1457
  /** A plain object, or nothing. */
1555
1458
  function asObject(value) {
1556
1459
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
1557
1460
  }
1558
- // ../core/src/v2/upgrade/animations.ts
1559
- /**
1560
- * @license
1561
- * Copyright (c) 2026 Xue Studios LLC
1562
- * SPDX-License-Identifier: Apache-2.0
1563
- */
1564
- var finite$2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
1565
- /** The letter each property has in a 1.x keyframe, and its value at rest. */
1566
- var KEYFRAME_PROPERTIES = [
1567
- [
1568
- "o",
1569
- "opacity",
1570
- 1
1571
- ],
1572
- [
1573
- "s",
1574
- "scale",
1575
- 1
1576
- ],
1577
- [
1578
- "r",
1579
- "rotation",
1580
- 0
1581
- ],
1582
- [
1583
- "x",
1584
- "x",
1585
- 0
1586
- ],
1587
- [
1588
- "y",
1589
- "y",
1590
- 0
1591
- ],
1592
- [
1593
- "b",
1594
- "blur",
1595
- 0
1596
- ]
1597
- ];
1598
- /** What 1.x wrote into one `transform`: a frame that left one out drew it at rest. */
1599
- var IN_TRANSFORM = /* @__PURE__ */ new Set([
1600
- "x",
1601
- "y",
1602
- "scale",
1603
- "rotation"
1604
- ]);
1605
- /**
1606
- * 1.x keyframes carry every property at once, in seconds. Each property that
1607
- * ever leaves its rest value becomes a track, with time from 0 to 1. Position,
1608
- * scale and rotation take every frame (at rest where the frame is silent, as
1609
- * 1.x drew it); opacity and blur take only the frames that name them.
1610
- */
1611
- function tracksOf(keyframes, duration) {
1612
- const frames = keyframes.map(asObject).filter((f) => !!f && finite$2(f.t) !== void 0);
1613
- if (frames.length < 2) return [];
1614
- const tracks = [];
1615
- for (const [letter, property, rest] of KEYFRAME_PROPERTIES) {
1616
- const named = frames.filter((f) => finite$2(f[letter]) !== void 0);
1617
- if (!named.some((f) => f[letter] !== rest)) continue;
1618
- const points = (IN_TRANSFORM.has(property) ? frames : named).map((f) => {
1619
- const point = {
1620
- t: Math.min(1, Math.max(0, f.t / duration)),
1621
- v: finite$2(f[letter]) ?? rest
1622
- };
1623
- if (f.e !== void 0) point.e = f.e;
1624
- return point;
1625
- });
1626
- if (points.length === 1) {
1627
- const at = points[0].t;
1628
- if (at > 0) points.unshift({
1629
- t: 0,
1630
- v: rest
1631
- });
1632
- if (at < 1) points.push({
1633
- t: 1,
1634
- v: rest
1635
- });
1636
- }
1637
- tracks.push({
1638
- property,
1639
- keyframes: points
1640
- });
1641
- }
1642
- return tracks;
1643
- }
1644
- var TEXT_TARGET = {
1645
- "rise-words": "words",
1646
- "reveal-mask": "lines"
1647
- };
1648
- /**
1649
- * The look a layer takes under the pointer. Each track runs from the layer's
1650
- * own value to the state's, which 1.x set outright (it did not add to it).
1651
- * Only hover: 1.x never drew the look of `active`.
1652
- */
1653
- function hoverLook(ctx, state, layer) {
1654
- const tracks = [];
1655
- const to = (property, own, target) => {
1656
- if (target !== own) tracks.push({
1657
- property,
1658
- keyframes: [{
1659
- t: 0,
1660
- v: own
1661
- }, {
1662
- t: 1,
1663
- v: target
1664
- }]
1665
- });
1666
- };
1667
- const scale = finite$2(state.scale);
1668
- if (scale !== void 0) to("scale", 1, scale > 10 ? scale / 100 : scale);
1669
- const rotation = finite$2(state.rotation);
1670
- if (rotation !== void 0) to("rotation", layer.box.rotation ?? 0, rotation);
1671
- const opacity = finite$2(state.opacity);
1672
- if (opacity !== void 0) to("opacity", layer.opacity ?? 1, opacity / 100);
1673
- if (state.color) ctx.note("style.states.hover.color: a hover colour is not carried to 2.0");
1674
- if (tracks.length === 0) return void 0;
1675
- return {
1676
- on: "hover",
1677
- tracks,
1678
- duration: Math.max(0, finite$2(state.transitionDuration) ?? 0)
1679
- };
1680
- }
1681
- var ACTIONS = /* @__PURE__ */ new Set([
1682
- "show",
1683
- "hide",
1684
- "toggle",
1685
- "setText",
1686
- "play"
1687
- ]);
1688
- function stateInteraction(state, on) {
1689
- const actions = (Array.isArray(state.actions) ? state.actions : []).map(asObject).filter((a) => !!a && typeof a.target === "string" && typeof a.type === "string" && ACTIONS.has(a.type)).map((a) => ({
1690
- type: a.type,
1691
- target: a.target,
1692
- ...typeof a.value === "string" ? { value: a.value } : {}
1693
- }));
1694
- return actions.length > 0 ? {
1695
- on,
1696
- actions
1697
- } : void 0;
1698
- }
1699
- function convertAnimations(ctx, slot, layer) {
1700
- const { raw, style } = slot;
1701
- const animations = [];
1702
- const interactions = [];
1703
- const animation = asObject(ctx.take(style, "animation"));
1704
- if (animation) {
1705
- const said = finite$2(animation.duration);
1706
- const delay = finite$2(animation.delay);
1707
- const seconds = said || 8;
1708
- const tracks = Array.isArray(animation.keyframes) && seconds > 0 ? tracksOf(animation.keyframes, seconds) : [];
1709
- if (tracks.length > 0) animations.push({
1710
- on: animation.trigger === "action" ? "action" : "loop",
1711
- tracks,
1712
- duration: seconds * 1e3
1713
- });
1714
- if (typeof animation.loop === "string" && animation.loop !== "none" && animation.loop !== "custom") animations.push({
1715
- on: "loop",
1716
- preset: animation.loop,
1717
- duration: said && said > 0 ? said * 1e3 : 0,
1718
- ...delay && delay > 0 ? { delay: delay * 1e3 } : {}
1719
- });
1720
- if (typeof animation.hover === "string" && animation.hover !== "none" && animation.hover !== "custom") animations.push({
1721
- on: "hover",
1722
- preset: animation.hover,
1723
- duration: 200
1724
- });
1725
- for (const key of [
1726
- "custom_loop_css",
1727
- "custom_keyframes",
1728
- "custom_hover_css"
1729
- ]) if (animation[key]) ctx.note(`style.animation.${key}: raw CSS is not carried to 2.0`);
1730
- }
1731
- const textType = ctx.take(style, "textAnimationType");
1732
- const speed = finite$2(ctx.take(style, "textAnimationSpeed"));
1733
- const textDelay = finite$2(ctx.take(style, "textAnimationDelay"));
1734
- const intensity = finite$2(ctx.take(style, "textAnimationIntensity"));
1735
- const cursor = ctx.take(style, "typewriterCursor");
1736
- if (layer.type === "text" && typeof textType === "string" && textType && textType !== "none") {
1737
- const params = {};
1738
- if (speed !== void 0) params.speed = speed;
1739
- if (intensity !== void 0) params.intensity = intensity;
1740
- if (typeof cursor === "boolean") params.cursor = cursor;
1741
- animations.push({
1742
- on: "load",
1743
- target: TEXT_TARGET[textType] ?? "chars",
1744
- preset: textType,
1745
- ...Object.keys(params).length > 0 ? { params } : {},
1746
- duration: 0,
1747
- ...textDelay ? { delay: textDelay * 1e3 } : {}
1748
- });
1749
- }
1750
- const reveal = asObject(ctx.take(style, "reveal"));
1751
- if (reveal && typeof reveal.effect === "string") animations.push({
1752
- on: "enter",
1753
- preset: reveal.effect,
1754
- duration: finite$2(reveal.duration) ?? 300,
1755
- ...reveal.easing !== void 0 ? { easing: reveal.easing } : {}
1756
- });
1757
- const trimStart = finite$2(ctx.take(style, "trimStart"));
1758
- const trimEnd = finite$2(ctx.take(style, "trimEnd"));
1759
- const trimDuration = finite$2(ctx.take(style, "trimDuration"));
1760
- const share = (percent) => Math.min(1, Math.max(0, percent / 100));
1761
- const start = share(trimStart ?? 0);
1762
- const end = share(trimEnd ?? 100);
1763
- const seconds = Math.max(0, trimDuration ?? 0);
1764
- const content = raw.content;
1765
- const texts = typeof content === "string" ? [content] : Object.values(asObject(content) ?? {});
1766
- const drawn = slot.type !== "image" && texts.some((t) => typeof t === "string" && /(<|&lt;)svg|<span|<div|<a|<img/i.test(t));
1767
- if (layer.type === "shape" && layer.geometry && drawn && style.strokeWidth) {
1768
- if (start > 0 || end < 1) layer.geometry.trim = {
1769
- ...start > 0 ? { start } : {},
1770
- ...end < 1 ? { end } : {}
1771
- };
1772
- if (seconds > 0) animations.push({
1773
- on: "load",
1774
- duration: seconds * 1e3,
1775
- tracks: [{
1776
- property: "trimEnd",
1777
- keyframes: [{
1778
- t: 0,
1779
- v: start
1780
- }, {
1781
- t: 1,
1782
- v: end
1783
- }]
1784
- }]
1785
- });
1786
- }
1787
- const states = asObject(ctx.take(raw, "states")) ?? asObject(ctx.take(style, "states")) ?? {};
1788
- const interactive = raw.isInteractive === true || style.isInteractive === true;
1789
- ctx.take(raw, "isInteractive");
1790
- for (const [name, on] of [["hover", "hover"], ["active", "press"]]) {
1791
- const state = asObject(states[name]);
1792
- if (!state) continue;
1793
- const look = interactive && on === "hover" ? hoverLook(ctx, state, layer) : void 0;
1794
- if (look) animations.push(look);
1795
- const acts = interactive ? stateInteraction(state, on) : void 0;
1796
- if (acts) interactions.push(acts);
1797
- }
1798
- const interaction = asObject(ctx.take(raw, "interaction"));
1799
- const target = asObject(interaction?.target);
1800
- if (interaction?.action_type === "toggle_elements" && target) {
1801
- const ids = (list) => Array.isArray(list) ? list.filter((id) => typeof id === "string") : [];
1802
- const actions = [...ids(target.show_slots).map((id) => ({
1803
- type: "show",
1804
- target: id
1805
- })), ...ids(target.hide_slots).map((id) => ({
1806
- type: "hide",
1807
- target: id
1808
- }))];
1809
- if (actions.length > 0) interactions.push({
1810
- on: "press",
1811
- actions
1812
- });
1813
- }
1814
- ctx.take(style, "isInteractive");
1815
- const parallax = asObject(ctx.take(raw, "parallax")) ?? asObject(ctx.take(style, "parallax"));
1816
- ctx.take(style, "parallax");
1817
- if (parallax && parallax.enabled !== false) {
1818
- const inf = asObject(parallax.infinite) ?? {};
1819
- const speed = inf.enabled === false ? 0 : finite$2(parallax.speedPxSec) ?? finite$2(inf.speedPxSec) ?? finite$2(inf.speed_px_sec) ?? (parallax.mode === "infinite_horizontal" ? finite$2(parallax.speed) ?? 20 : 0);
1820
- const pick = (...values) => values.find((v) => v !== void 0);
1821
- const direction = pick(parallax.direction, inf.direction);
1822
- const mirror = pick(parallax.mirror, parallax.seamlessTile, inf.mirror, inf.seamlessTile, inf.seamless_tile);
1823
- const pauseOnHover = pick(parallax.pauseOnHover, inf.pauseOnHover, inf.pause_on_hover);
1824
- if (speed !== 0) layer.motion = { loop: {
1825
- speedPxSec: Math.min(500, Math.max(-500, speed)),
1826
- ...direction === "left_to_right" || direction === "right_to_left" ? { direction } : {},
1827
- ...mirror !== void 0 ? { mirror: !!mirror } : {},
1828
- ...pauseOnHover !== void 0 ? { pauseOnHover: !!pauseOnHover } : {}
1829
- } };
1830
- else if (parallax.mode !== "infinite_horizontal") ctx.retire(raw.parallax !== void 0 ? raw : style, "parallax");
1831
- }
1832
- ctx.retire(style, "sceneLoop");
1833
- ctx.retire(raw, "isParallaxGroup");
1834
- ctx.retire(style, "isParallaxGroup");
1835
- ctx.retire(raw, "is_parallax_group");
1836
- ctx.retire(style, "loopDepth");
1837
- ctx.retire(raw, "tracking_data");
1838
- const css = ctx.take(style, "cssAnimation");
1839
- if (typeof css === "string" && css && !/^background-animation-/.test(css)) ctx.note("style.cssAnimation: raw CSS is not carried to 2.0");
1840
- if (animations.length > 0) layer.animations = animations;
1841
- if (interactions.length > 0 && admits(layer.type, "interactions")) layer.interactions = interactions;
1842
- }
1843
- // ../core/src/dimensions.ts
1844
- /**
1845
- * @license
1846
- * Copyright (c) 2026 Xue Studios LLC
1847
- * SPDX-License-Identifier: Apache-2.0
1848
- */
1849
- /**
1850
- * Extracts the pure numeric value of a dimension given in user units.
1851
- * If it comes as '25cqw' or '25%' and baseDimension is known, it computes its numeric equivalent.
1852
- */
1853
- function resolveNumericDimension(val, baseDimension = 800) {
1854
- if (val === void 0 || val === null || val === "") return null;
1855
- if (typeof val === "number") return Number.isFinite(val) ? val : null;
1856
- const str = String(val).trim();
1857
- if (str.endsWith("cqw") || str.endsWith("%")) {
1858
- const num = parseFloat(str);
1859
- if (!Number.isFinite(num)) return null;
1860
- return num / 100 * baseDimension;
1861
- }
1862
- if (str.endsWith("px")) {
1863
- const num = parseFloat(str);
1864
- return Number.isFinite(num) ? num : null;
1865
- }
1866
- const parsed = parseFloat(str);
1867
- return Number.isFinite(parsed) ? parsed : null;
1868
- }
1869
- // ../core/src/v2/upgrade/box.ts
1870
- /**
1871
- * @license
1872
- * Copyright (c) 2026 Xue Studios LLC
1873
- * SPDX-License-Identifier: Apache-2.0
1874
- */
1875
- var BLEND_MODES = /* @__PURE__ */ new Set([
1876
- "multiply",
1877
- "screen",
1878
- "overlay",
1879
- "darken",
1880
- "lighten",
1881
- "color-dodge",
1882
- "color-burn",
1883
- "difference"
1884
- ]);
1885
- /** A 1.x length (number, "92.5cqw", "120px", "50%") in canvas units; undefined when it says nothing. */
1886
- function toCanvasUnits(value, canvasWidth) {
1887
- if (typeof value !== "number" && typeof value !== "string") return void 0;
1888
- const resolved = resolveNumericDimension(value, canvasWidth);
1889
- return resolved !== null && Number.isFinite(resolved) ? resolved : void 0;
1890
- }
1891
- var finite$1 = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
1892
- var SHAPE_TYPES = /* @__PURE__ */ new Set([
1893
- "geo",
1894
- "shape",
1895
- "draw",
1896
- "filter",
1897
- "container",
1898
- "mask",
1899
- "artistic-text"
1900
- ]);
1901
- var DEFAULT_SIDE = .1;
1902
- /**
1903
- * A 1.x style length as the player painted it, in canvas units. Every length is
1904
- * painted against the canvas width (cqw) except a percentage, which CSS takes
1905
- * from the container's own axis. Undefined for what the player does not size.
1906
- */
1907
- function paintedLength(value, axis, W) {
1908
- if (value === void 0 || value === null || value === "") return void 0;
1909
- if (typeof value === "number") return Number.isFinite(value) && axis > 0 ? value / axis * W : void 0;
1910
- const text = String(value).trim();
1911
- const n = parseFloat(text);
1912
- if (!Number.isFinite(n)) return void 0;
1913
- if (text.endsWith("cqw")) return n / 100 * W;
1914
- if (text.endsWith("%")) return n / 100 * axis;
1915
- if (text.endsWith("px")) return n;
1916
- return /^-?[\d.]+$/.test(text) && axis > 0 ? n / axis * W : void 0;
1917
- }
1918
- var hasContent = (content) => typeof content === "string" ? content !== "" : !!content && typeof content === "object" && Object.values(content).some((v) => typeof v === "string" && v !== "");
1919
- /** Position, size, rotation, opacity, visibility and blend. Defaults are not written. */
1920
- function convertBox(ctx, slot, layer) {
1921
- const { raw, style } = slot;
1922
- const { width: W, height: H } = ctx.canvas;
1923
- const position = ctx.take(raw, "position");
1924
- const [px, py] = Array.isArray(position) ? position : [];
1925
- let fx = finite$1(px) ?? 0;
1926
- let fy = finite$1(py) ?? 0;
1927
- if (fx > 1 || fy > 1) {
1928
- fx /= 100;
1929
- fy /= 100;
1930
- }
1931
- const widthPx = finite$1(ctx.take(raw, "width_px"));
1932
- const heightPx = finite$1(ctx.take(raw, "height_px"));
1933
- const widthPercent = finite$1(ctx.take(raw, "widthPercent"));
1934
- const heightPercent = finite$1(ctx.take(raw, "heightPercent"));
1935
- const styleWidth = ctx.take(style, "width");
1936
- const styleHeight = ctx.take(style, "height");
1937
- const ref = (px, percent, value, axis) => px ?? (percent !== void 0 ? percent / 100 * axis : toCanvasUnits(value, axis) ?? 0);
1938
- const wRef = ref(widthPx, widthPercent, styleWidth, W);
1939
- const hRef = ref(heightPx, heightPercent, styleHeight, H);
1940
- const type = String(raw.type ?? "text");
1941
- const isShape = SHAPE_TYPES.has(type) && !(type === "mask" && style.maskMode === "cutout");
1942
- const isBackground = raw.is_background_pattern === true || raw.id === "background-pattern-slot";
1943
- const content = hasContent(raw.content);
1944
- const fromStyle = [paintedLength(styleWidth, W, W), paintedLength(styleHeight, H, W)];
1945
- const fromFields = [widthPx ?? (widthPercent !== void 0 ? widthPercent / 100 * W : void 0), heightPx !== void 0 ? heightPx / W * W : heightPercent !== void 0 ? heightPercent / 100 * W : void 0];
1946
- let size;
1947
- if (fromStyle[0] !== void 0 && fromStyle[1] !== void 0) size = fromStyle;
1948
- else if (fromFields[0] !== void 0 && fromFields[1] !== void 0 && (isShape || type === "image" || !content)) size = fromFields;
1949
- else if (type === "image" || isShape && !content || isBackground || type === "pattern") size = [0, 1].map((i) => fromFields[i] ?? fromStyle[i] ?? DEFAULT_SIDE * W);
1950
- else size = [void 0, void 0];
1951
- const align = style.textAlign ?? raw.align ?? "left";
1952
- const pull = (span) => align === "center" ? span / 2 : align === "right" ? span : 0;
1953
- const anchorX = fx * W + pull(wRef);
1954
- const anchorY = fy * H + hRef / 2;
1955
- const [width, height] = size;
1956
- if (width === void 0 || height === void 0) {
1957
- if (type !== "text" && !content) layer.box = {
1958
- x: fx * W,
1959
- y: fy * H,
1960
- width: Math.max(0, wRef),
1961
- height: Math.max(0, hRef)
1962
- };
1963
- else {
1964
- layer.box = {
1965
- x: anchorX,
1966
- y: anchorY,
1967
- anchor: align === "center" ? "center" : align === "right" ? "right" : "left"
1968
- };
1969
- if (wRef > 0) layer.box.width = wRef;
1970
- }
1971
- } else layer.box = {
1972
- x: anchorX - pull(width),
1973
- y: anchorY - height / 2,
1974
- width: Math.max(0, width),
1975
- height: Math.max(0, height)
1976
- };
1977
- const rotation = finite$1(ctx.take(style, "rotation"));
1978
- if (rotation) layer.box.rotation = rotation;
1979
- const opacity = finite$1(ctx.take(style, "opacity"));
1980
- if (opacity !== void 0 && opacity < 100) layer.opacity = Math.max(0, opacity) / 100;
1981
- const hiddenSlot = ctx.take(raw, "isVisible") === false;
1982
- if (ctx.take(style, "isVisible") === false || hiddenSlot) layer.visible = false;
1983
- const blend = ctx.take(style, "blendMode");
1984
- if (typeof blend === "string" && BLEND_MODES.has(blend)) layer.blend = blend;
1985
- }
1986
- // ../core/src/v2/upgrade/gradient.ts
1987
- /**
1988
- * @license
1989
- * Copyright (c) 2026 Xue Studios LLC
1990
- * SPDX-License-Identifier: Apache-2.0
1991
- */
1992
- var SIDES = {
1993
- "to top": 0,
1994
- "to right": 90,
1995
- "to bottom": 180,
1996
- "to left": 270,
1997
- "to top right": 45,
1998
- "to bottom right": 135,
1999
- "to bottom left": 225,
2000
- "to top left": 315
2001
- };
2002
- var COLOR = /^(#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla)\([^()]*\)|[a-z]+)$/i;
2003
- /** Splits on the commas that are not inside parentheses. */
2004
- function splitTopLevel(text) {
2005
- const parts = [];
2006
- let depth = 0;
2007
- let start = 0;
2008
- for (let i = 0; i < text.length; i++) {
2009
- const c = text[i];
2010
- if (c === "(") depth++;
2011
- else if (c === ")") depth--;
2012
- else if (c === "," && depth === 0) {
2013
- parts.push(text.slice(start, i).trim());
2014
- start = i + 1;
2015
- }
2016
- }
2017
- parts.push(text.slice(start).trim());
2018
- return parts;
2019
- }
2020
- function parseStop(text) {
2021
- const match = /^(.*?)(?:\s+(-?[\d.]+)%)?$/.exec(text);
2022
- if (!match) return null;
2023
- const color = match[1].trim();
2024
- if (!COLOR.test(color)) return null;
2025
- if (match[2] === void 0) return { color };
2026
- const at = Number(match[2]) / 100;
2027
- return Number.isFinite(at) ? {
2028
- color,
2029
- at: Math.min(1, Math.max(0, at))
2030
- } : null;
2031
- }
2032
- function parseCssGradient(css) {
2033
- if (typeof css !== "string") return null;
2034
- const match = /^\s*(linear|radial|conic)-gradient\((.*)\)\s*$/is.exec(css);
2035
- if (!match) return null;
2036
- const type = match[1].toLowerCase();
2037
- const parts = splitTopLevel(match[2]);
2038
- if (!parts || parts.some((p) => p === "")) return null;
2039
- let angle;
2040
- const head = parts[0].toLowerCase();
2041
- const degrees = /^(?:from\s+)?(-?[\d.]+)deg$/.exec(head);
2042
- if (degrees) {
2043
- angle = Number(degrees[1]);
2044
- parts.shift();
2045
- } else if (head in SIDES) {
2046
- angle = SIDES[head];
2047
- parts.shift();
2048
- } else if (type === "radial" && /^(circle|ellipse)\b/.test(head)) parts.shift();
2049
- const stops = parts.map(parseStop);
2050
- if (stops.length < 2 || stops.some((s) => s === null)) return null;
2051
- const gradient = {
2052
- type,
2053
- stops
2054
- };
2055
- if (angle !== void 0 && Number.isFinite(angle)) gradient.angle = angle;
2056
- return gradient;
2057
- }
2058
- // ../core/src/v2/upgrade/svg-paths.ts
2059
- /**
2060
- * @license
2061
- * Copyright (c) 2026 Xue Studios LLC
2062
- * SPDX-License-Identifier: Apache-2.0
2063
- */
2064
- var IDENTITY = [
2065
- 1,
2066
- 0,
2067
- 0,
2068
- 1,
2069
- 0,
2070
- 0
2071
- ];
2072
- var SHAPES$1 = /* @__PURE__ */ new Set([
2073
- "path",
2074
- "rect",
2075
- "circle",
2076
- "ellipse",
2077
- "line",
2078
- "polyline",
2079
- "polygon"
2080
- ]);
2081
- var CONTAINERS = /* @__PURE__ */ new Set(["svg", "g"]);
2082
- /** Text for people, with nothing to draw. Its content is skipped. */
2083
- var SILENT = /* @__PURE__ */ new Set([
2084
- "title",
2085
- "desc",
2086
- "metadata"
2087
- ]);
2088
- function multiply(a, b) {
2089
- return [
2090
- a[0] * b[0] + a[2] * b[1],
2091
- a[1] * b[0] + a[3] * b[1],
2092
- a[0] * b[2] + a[2] * b[3],
2093
- a[1] * b[2] + a[3] * b[3],
2094
- a[0] * b[4] + a[2] * b[5] + a[4],
2095
- a[1] * b[4] + a[3] * b[5] + a[5]
2096
- ];
2097
- }
2098
- var numbersIn = (text) => (text.match(/-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi) ?? []).map(Number);
2099
- function parseTransform(text) {
2100
- let matrix = IDENTITY;
2101
- const calls = [...text.matchAll(/([a-zA-Z]+)\s*\(([^)]*)\)/g)];
2102
- if (calls.length === 0 && text.trim() !== "") return null;
2103
- for (const [, name, args] of calls) {
2104
- const n = numbersIn(args);
2105
- let next;
2106
- if (name === "matrix" && n.length === 6) next = n;
2107
- else if (name === "translate" && n.length >= 1) next = [
2108
- 1,
2109
- 0,
2110
- 0,
2111
- 1,
2112
- n[0],
2113
- n[1] ?? 0
2114
- ];
2115
- else if (name === "scale" && n.length >= 1) next = [
2116
- n[0],
2117
- 0,
2118
- 0,
2119
- n[1] ?? n[0],
2120
- 0,
2121
- 0
2122
- ];
2123
- else if (name === "rotate" && n.length >= 1) {
2124
- const r = n[0] * Math.PI / 180;
2125
- const turn = [
2126
- Math.cos(r),
2127
- Math.sin(r),
2128
- -Math.sin(r),
2129
- Math.cos(r),
2130
- 0,
2131
- 0
2132
- ];
2133
- next = n.length >= 3 ? multiply(multiply([
2134
- 1,
2135
- 0,
2136
- 0,
2137
- 1,
2138
- n[1],
2139
- n[2]
2140
- ], turn), [
2141
- 1,
2142
- 0,
2143
- 0,
2144
- 1,
2145
- -n[1],
2146
- -n[2]
2147
- ]) : turn;
2148
- } else if (name === "skewX" && n.length === 1) next = [
2149
- 1,
2150
- 0,
2151
- Math.tan(n[0] * Math.PI / 180),
2152
- 1,
2153
- 0,
2154
- 0
2155
- ];
2156
- else if (name === "skewY" && n.length === 1) next = [
2157
- 1,
2158
- Math.tan(n[0] * Math.PI / 180),
2159
- 0,
2160
- 1,
2161
- 0,
2162
- 0
2163
- ];
2164
- else return null;
2165
- matrix = multiply(matrix, next);
2166
- }
2167
- return matrix;
2168
- }
2169
- function attributesOf(text) {
2170
- const attrs = {};
2171
- for (const [, name, , double, single] of text.matchAll(/([a-zA-Z_:][\w:.-]*)\s*=\s*("([^"]*)"|'([^']*)')/g)) attrs[name] = double ?? single ?? "";
2172
- return attrs;
2173
- }
2174
- var HORIZONTAL = /* @__PURE__ */ new Set([
2175
- "x",
2176
- "width",
2177
- "cx",
2178
- "rx",
2179
- "x1",
2180
- "x2"
2181
- ]);
2182
- var VERTICAL = /* @__PURE__ */ new Set([
2183
- "y",
2184
- "height",
2185
- "cy",
2186
- "ry",
2187
- "y1",
2188
- "y2"
2189
- ]);
2190
- /** A length; a percentage is of the viewBox, as SVG resolves it (r: of its normalised diagonal). */
2191
- var numIn = (attrs, name, viewBox) => {
2192
- const raw = attrs[name] ?? "0";
2193
- const value = Number.parseFloat(raw);
2194
- if (!Number.isFinite(value)) return 0;
2195
- if (!raw.trim().endsWith("%") || !viewBox) return value;
2196
- const [w, h] = [viewBox[2], viewBox[3]];
2197
- const ref = HORIZONTAL.has(name) ? w : VERTICAL.has(name) ? h : Math.sqrt((w * w + h * h) / 2);
2198
- return value / 100 * ref;
2199
- };
2200
- /**
2201
- * A layer 1.x drew from SVG markup: the `svg` type, or an old library icon created
2202
- * as `geo` with the SVG in its content. Its strokeColor tints the drawing.
2203
- */
2204
- function drawsMarkup(slot) {
2205
- if (slot.type === "svg") return true;
2206
- const content = slot.raw.content;
2207
- return (typeof content === "string" ? [content] : content && typeof content === "object" ? Object.values(content) : []).some((v) => typeof v === "string" && /<svg/i.test(v));
2208
- }
2209
- /** The path data of a basic shape. */
2210
- function shapeToPath(tag, a, vb) {
2211
- const num = (attrs, name) => numIn(attrs, name, vb);
2212
- if (tag === "path") return a.d?.trim() || null;
2213
- if (tag === "rect") {
2214
- const [x, y, w, h] = [
2215
- num(a, "x"),
2216
- num(a, "y"),
2217
- num(a, "width"),
2218
- num(a, "height")
2219
- ];
2220
- if (!(w > 0) || !(h > 0)) return null;
2221
- let rx = a.rx !== void 0 ? num(a, "rx") : a.ry !== void 0 ? num(a, "ry") : 0;
2222
- let ry = a.ry !== void 0 ? num(a, "ry") : rx;
2223
- rx = Math.min(rx, w / 2);
2224
- ry = Math.min(ry, h / 2);
2225
- if (!(rx > 0) || !(ry > 0)) return `M${x} ${y}H${x + w}V${y + h}H${x}Z`;
2226
- return `M${x + rx} ${y}H${x + w - rx}A${rx} ${ry} 0 0 1 ${x + w} ${y + ry}V${y + h - ry}A${rx} ${ry} 0 0 1 ${x + w - rx} ${y + h}H${x + rx}A${rx} ${ry} 0 0 1 ${x} ${y + h - ry}V${y + ry}A${rx} ${ry} 0 0 1 ${x + rx} ${y}Z`;
2227
- }
2228
- if (tag === "circle" || tag === "ellipse") {
2229
- const [cx, cy] = [num(a, "cx"), num(a, "cy")];
2230
- const rx = tag === "circle" ? num(a, "r") : num(a, "rx");
2231
- const ry = tag === "circle" ? rx : num(a, "ry");
2232
- if (!(rx > 0) || !(ry > 0)) return null;
2233
- return `M${cx - rx} ${cy}A${rx} ${ry} 0 1 0 ${cx + rx} ${cy}A${rx} ${ry} 0 1 0 ${cx - rx} ${cy}Z`;
2234
- }
2235
- if (tag === "line") return `M${num(a, "x1")} ${num(a, "y1")}L${num(a, "x2")} ${num(a, "y2")}`;
2236
- const points = numbersIn(a.points ?? "");
2237
- if (points.length < 4 || points.length % 2 !== 0) return null;
2238
- let d = `M${points[0]} ${points[1]}`;
2239
- for (let i = 2; i < points.length; i += 2) d += `L${points[i]} ${points[i + 1]}`;
2240
- return tag === "polygon" ? `${d}Z` : d;
2241
- }
2242
- var INHERITED = [
2243
- "fill",
2244
- "stroke",
2245
- "stroke-width",
2246
- "stroke-linecap",
2247
- "stroke-linejoin",
2248
- "fill-rule"
2249
- ];
2250
- function refusal(name, attrs) {
2251
- for (const key of Object.keys(attrs)) {
2252
- const lower = key.toLowerCase();
2253
- if (lower === "style") return `<${name}> carries a style attribute`;
2254
- if (lower.startsWith("on")) return `<${name}> carries an event handler (${key})`;
2255
- if (lower === "href" || lower.endsWith(":href")) return `<${name}> carries a reference (${key})`;
2256
- }
2257
- for (const key of ["fill", "stroke"]) if (/url\s*\(/i.test(attrs[key] ?? "")) return `<${name}> paints with a reference (${key})`;
2258
- return null;
2259
- }
2260
- function svgToPaths(xml) {
2261
- if (typeof xml !== "string" || xml.trim() === "") return {
2262
- ok: false,
2263
- reason: "not an SVG string"
2264
- };
2265
- const source = xml.replace(/<!--[\s\S]*?-->/g, "").replace(/<\?[\s\S]*?\?>/g, "").replace(/<!DOCTYPE[^>]*>/gi, "");
2266
- const paths = [];
2267
- const stack = [];
2268
- let viewBox;
2269
- let silent = 0;
2270
- let sawSvg = false;
2271
- for (const [, closing, name, rest, selfClosing] of source.matchAll(/<(\/?)([a-zA-Z][\w:-]*)([^>]*?)(\/?)>/g)) {
2272
- if (SILENT.has(name)) {
2273
- if (closing) silent--;
2274
- else if (!selfClosing) silent++;
2275
- continue;
2276
- }
2277
- if (silent > 0) continue;
2278
- if (closing) {
2279
- stack.pop();
2280
- continue;
2281
- }
2282
- if (!CONTAINERS.has(name) && !SHAPES$1.has(name)) return {
2283
- ok: false,
2284
- reason: `<${name}> is outside the static profile`
2285
- };
2286
- const attrs = attributesOf(rest);
2287
- const refused = refusal(name, attrs);
2288
- if (refused) return {
2289
- ok: false,
2290
- reason: refused
2291
- };
2292
- const parent = stack[stack.length - 1];
2293
- const own = attrs.transform === void 0 ? IDENTITY : parseTransform(attrs.transform);
2294
- if (!own) return {
2295
- ok: false,
2296
- reason: `<${name}> has a transform that cannot be read`
2297
- };
2298
- const matrix = parent ? multiply(parent.matrix, own) : own;
2299
- const inherited = { ...parent?.attrs ?? {} };
2300
- for (const key of INHERITED) if (attrs[key] !== void 0) inherited[key] = attrs[key];
2301
- if (name === "svg" && !sawSvg) {
2302
- sawSvg = true;
2303
- const box = numbersIn(attrs.viewBox ?? "");
2304
- const [w, h] = [Number.parseFloat(attrs.width ?? ""), Number.parseFloat(attrs.height ?? "")];
2305
- if (box.length === 4) viewBox = box;
2306
- else if (w > 0 && h > 0 && !/%/.test(`${attrs.width}${attrs.height}`)) viewBox = [
2307
- 0,
2308
- 0,
2309
- w,
2310
- h
2311
- ];
2312
- }
2313
- if (SHAPES$1.has(name)) {
2314
- const d = shapeToPath(name, attrs, viewBox);
2315
- if (!d) continue;
2316
- const entry = { d };
2317
- const fill = inherited.fill ?? "black";
2318
- if (fill !== "none") entry.fill = fill;
2319
- const stroke = inherited.stroke;
2320
- if (stroke && stroke !== "none") {
2321
- entry.stroke = stroke;
2322
- const width = Number.parseFloat(inherited["stroke-width"] ?? "1");
2323
- entry.strokeWidth = Number.isFinite(width) ? width : 1;
2324
- const cap = inherited["stroke-linecap"];
2325
- const join = inherited["stroke-linejoin"];
2326
- if (cap === "round" || cap === "square") entry.cap = cap;
2327
- if (join === "round" || join === "bevel") entry.join = join;
2328
- }
2329
- if (inherited["fill-rule"] === "evenodd") entry.fillRule = "evenodd";
2330
- const opacity = Number.parseFloat(attrs.opacity ?? "");
2331
- if (Number.isFinite(opacity) && opacity < 1) entry.opacity = Math.max(0, opacity);
2332
- if (matrix.some((v, i) => Math.abs(v - IDENTITY[i]) > 1e-9)) entry.transform = matrix.map((v) => Number(v.toFixed(6)));
2333
- paths.push(entry);
2334
- }
2335
- if (CONTAINERS.has(name) && !selfClosing) stack.push({
2336
- name,
2337
- matrix,
2338
- attrs: inherited
2339
- });
2340
- }
2341
- if (!sawSvg) return {
2342
- ok: false,
2343
- reason: "no <svg> element"
2344
- };
2345
- if (!viewBox) return {
2346
- ok: false,
2347
- reason: "the <svg> declares no viewBox nor a size in units"
2348
- };
2349
- if (paths.length === 0) return {
2350
- ok: false,
2351
- reason: "nothing to draw"
2352
- };
2353
- return {
2354
- ok: true,
2355
- value: {
2356
- viewBox,
2357
- paths
2358
- }
2359
- };
2360
- }
2361
- // ../core/src/v2/upgrade/paints.ts
2362
- /**
2363
- * @license
2364
- * Copyright (c) 2026 Xue Studios LLC
2365
- * SPDX-License-Identifier: Apache-2.0
2366
- */
2367
- var isColor = (value) => typeof value === "string" && value !== "" && value !== "transparent" && value !== "none";
2368
- /**
2369
- * A colour and its role. A known role (a palette's, or one of the dynamic roles
2370
- * a host page can set) becomes a binding that keeps the literal as its fallback,
2371
- * which is what 1.x painted: `var(--oim-color-<role>, <literal>)`.
2372
- */
2373
- function colorOf(ctx, owner, key, roleKey) {
2374
- const literal = ctx.take(owner, key);
2375
- const role = roleKey ? ctx.take(owner, roleKey) : void 0;
2376
- if (typeof role === "string" && ctx.hasRole(role)) return isColor(literal) ? {
2377
- var: role,
2378
- fallback: literal
2379
- } : { var: role };
2380
- return isColor(literal) ? literal : void 0;
2381
- }
2382
- var numbers = (value) => Array.isArray(value) && value.length > 0 && value.every((n) => typeof n === "number") ? value : void 0;
2383
- /** The pattern fields that share a prefix: `fillPattern*` on a layer, `backgroundPattern*` on a layer or the canvas. */
2384
- function patternOf(ctx, owner, prefix, cssAnimation, canvasBackground = false) {
2385
- const preset = ctx.take(owner, `${prefix}Type`);
2386
- const single = colorOf(ctx, owner, `${prefix}Color`, `${prefix}ColorRole`);
2387
- const bg = colorOf(ctx, owner, `${prefix}BgColor`, `${prefix}BgColorRole`);
2388
- const list = ctx.take(owner, `${prefix}Colors`);
2389
- const scale = ctx.take(owner, `${prefix}Scale`);
2390
- const speed = ctx.take(owner, `${prefix}Speed`);
2391
- const direction = ctx.take(owner, `${prefix}Direction`);
2392
- const svgs = ctx.take(owner, `${prefix}Svgs`);
2393
- const sizes = numbers(ctx.take(owner, `${prefix}Sizes`));
2394
- const counts = numbers(ctx.take(owner, `${prefix}Counts`)) ?? numbers(ctx.take(owner, `${prefix}Count`));
2395
- const dispersions = numbers(ctx.take(owner, `${prefix}Dispersions`)) ?? numbers(ctx.take(owner, `${prefix}Dispersion`));
2396
- const colors = Array.isArray(list) ? list.filter(isColor) : [];
2397
- const tile = canvasBackground && prefix === "backgroundPattern" && typeof owner.svgRawXml === "string" && owner.svgRawXml !== "";
2398
- if ((typeof preset !== "string" || !preset) && !tile && single === void 0 && bg === void 0 && colors.length === 0) return void 0;
2399
- const pattern = typeof preset === "string" && preset ? { preset } : {};
2400
- if (colors.length > 0 && single !== void 0 && typeof single === "object") colors[0] = single;
2401
- if (colors.length > 0) pattern.colors = colors;
2402
- else if (single !== void 0) pattern.colors = [single];
2403
- if (bg !== void 0) pattern.bg = bg;
2404
- if (typeof scale === "number" && scale !== 1) pattern.scale = scale;
2405
- if (sizes) pattern.sizes = sizes;
2406
- if (counts) pattern.counts = counts;
2407
- if (dispersions) pattern.dispersions = dispersions;
2408
- if (Array.isArray(svgs) && svgs.length > 0) pattern.svgs = svgs.filter((s) => typeof s === "string");
2409
- const css = typeof cssAnimation === "string" ? /^background-animation-([a-z-]+)\s+([\d.]+)s\b/.exec(cssAnimation) : null;
2410
- const way = typeof direction === "string" && direction !== "none" ? direction : css?.[1];
2411
- const period = typeof speed === "number" && speed > 0 ? speed : css ? Number(css[2]) : prefix === "backgroundPattern" && way ? 8 : void 0;
2412
- if (way && MOTION.has(way) && period) pattern.motion = {
2413
- direction: way,
2414
- period
2415
- };
2416
- return {
2417
- kind: "pattern",
2418
- pattern
2419
- };
2420
- }
2421
- var MOTION = /* @__PURE__ */ new Set([
2422
- "right",
2423
- "left",
2424
- "up",
2425
- "down",
2426
- "zoom-in",
2427
- "zoom-out",
2428
- "pulse"
2429
- ]);
2430
- function gradientOf(ctx, owner, key, label) {
2431
- const css = ctx.take(owner, key);
2432
- if (css === void 0 || css === null || css === "") return void 0;
2433
- const gradient = parseCssGradient(css);
2434
- if (!gradient) {
2435
- ctx.note(`${label}.${key}: gradient not understood`);
2436
- return;
2437
- }
2438
- return {
2439
- kind: "gradient",
2440
- gradient
2441
- };
2442
- }
2443
- function imageOf(ctx, style) {
2444
- const src = ctx.take(style, "fillImage");
2445
- const crop = asObject(ctx.take(style, "fillImageCrop"));
2446
- const flipX = ctx.take(style, "fillImageFlipX");
2447
- const flipY = ctx.take(style, "fillImageFlipY");
2448
- if (typeof src !== "string" || !src) return void 0;
2449
- const paint = {
2450
- kind: "image",
2451
- src
2452
- };
2453
- if (crop) paint.crop = crop;
2454
- if (flipX === true) paint.flipX = true;
2455
- if (flipY === true) paint.flipY = true;
2456
- return paint;
2457
- }
2458
- var TEXT_GRADIENT_PRESETS = /* @__PURE__ */ new Set([
2459
- "metallic-chrome",
2460
- "sunset-gold",
2461
- "neon-glow",
2462
- "linear"
2463
- ]);
2464
- function fillOf(ctx, slot) {
2465
- const { style } = slot;
2466
- const fillType = ctx.take(style, "fillType");
2467
- const backgroundType = ctx.take(style, "backgroundType");
2468
- const color = colorOf(ctx, style, "fillColor", typeof style.fillColorRole === "string" && style.fillColorRole ? "fillColorRole" : "colorRole");
2469
- ctx.take(style, "fillColorRole");
2470
- ctx.take(style, "colorRole");
2471
- ctx.take(style, "color");
2472
- const gradient = gradientOf(ctx, style, "fillGradient", "style");
2473
- const image = imageOf(ctx, style);
2474
- const cssAnimation = style.cssAnimation;
2475
- const fillPattern = patternOf(ctx, style, "fillPattern", cssAnimation);
2476
- const backgroundPattern = patternOf(ctx, style, "backgroundPattern", cssAnimation, slot.raw.is_background_pattern === true || slot.raw.id === "background-pattern-slot");
2477
- const generative = asObject(ctx.take(style, "fillGenerative")) ?? asObject(ctx.take(style, "backgroundGenerative"));
2478
- const backgroundFit = ctx.take(style, "backgroundFit");
2479
- const textGradient = ctx.take(style, "textGradientType");
2480
- if (backgroundPattern && backgroundFit === "cover" && "pattern" in backgroundPattern) backgroundPattern.pattern.fit = "cover";
2481
- const pattern = fillPattern ?? backgroundPattern;
2482
- if (pattern && typeof cssAnimation === "string" && /^background-animation-/.test(cssAnimation)) ctx.take(style, "cssAnimation");
2483
- const solid = () => {
2484
- return color === void 0 ? void 0 : {
2485
- kind: "color",
2486
- value: color
2487
- };
2488
- };
2489
- const kind = typeof fillType === "string" ? fillType : typeof backgroundType === "string" ? backgroundType : slot.type === "pattern" || backgroundPattern ? "pattern" : "color";
2490
- if (kind === "none" || kind === "transparent") return void 0;
2491
- if (kind === "gradient") return gradient ?? solid();
2492
- if (kind === "image") return image ? color === void 0 ? image : [image, solid()] : solid();
2493
- if (kind === "pattern") return pattern ?? solid();
2494
- if (kind === "generative") return generative ? {
2495
- kind: "generative",
2496
- generative
2497
- } : solid();
2498
- if ((slot.type === "text" || slot.type === "artistic-text") && typeof textGradient === "string" && TEXT_GRADIENT_PRESETS.has(textGradient) && textGradient !== "linear") return {
2499
- kind: "gradient",
2500
- preset: textGradient
2501
- };
2502
- return solid();
2503
- }
2504
- function strokeOf(ctx, style, colorKey, widthKey, extra = {}, roleKey) {
2505
- const color = colorOf(ctx, style, colorKey, roleKey);
2506
- const width = ctx.take(style, widthKey);
2507
- if (typeof width !== "number" || !(width > 0) || color === void 0) return void 0;
2508
- return {
2509
- paint: {
2510
- kind: "color",
2511
- value: color
2512
- },
2513
- width,
2514
- ...extra
2515
- };
2516
- }
2517
- /** 1.x painted a text stroke black when it had no colour, under `textStrokeColorRole || strokeColorRole`. */
2518
- function textStrokeOf(ctx, style) {
2519
- const roleKey = typeof style.textStrokeColorRole === "string" && style.textStrokeColorRole ? "textStrokeColorRole" : "strokeColorRole";
2520
- const width = style.textStrokeWidth;
2521
- const color = colorOf(ctx, style, "textStrokeColor", roleKey);
2522
- ctx.take(style, "textStrokeColorRole");
2523
- ctx.take(style, "textStrokeWidth");
2524
- if (typeof width !== "number" || !(width > 0)) return void 0;
2525
- return {
2526
- paint: {
2527
- kind: "color",
2528
- value: color ?? "#000000"
2529
- },
2530
- width
2531
- };
2532
- }
2533
- function convertPaints(ctx, slot, layer) {
2534
- const { style } = slot;
2535
- const hollowText = layer.type === "text" && style.fillColor === "transparent" && (style.fillType === void 0 || style.fillType === "solid" || style.fillType === "color");
2536
- const fills = fillOf(ctx, slot);
2537
- const fill = Array.isArray(fills) ? fills[0] : fills;
2538
- const shape = style.geoShape;
2539
- const customPath = typeof style.svgPath === "string" && style.svgPath !== "" && (shape === void 0 || shape === "custom");
2540
- const colourless = slot.type === "geo" && (customPath || shape === "scribble") && !!fill && "kind" in fill && fill.kind === "color";
2541
- if (fill && !colourless && admits(layer.type, "fills")) layer.fills = Array.isArray(fills) ? fills : [fill];
2542
- else if (hollowText) layer.fills = [{
2543
- kind: "color",
2544
- value: "transparent"
2545
- }];
2546
- const strokeStyle = ctx.take(style, "strokeStyle");
2547
- const dashed = strokeStyle === "dashed" || strokeStyle === "dotted" ? { style: strokeStyle } : {};
2548
- const borderStyle = ctx.take(style, "borderStyle");
2549
- const border = strokeOf(ctx, style, "borderColor", "borderWidth", borderStyle === "dashed" || borderStyle === "dotted" ? { style: borderStyle } : {});
2550
- const markup = drawsMarkup(slot);
2551
- const tint = markup ? colorOf(ctx, style, "strokeColor", "strokeColorRole") : void 0;
2552
- if (markup) ctx.take(style, "strokeWidth");
2553
- const gradientStroke = markup && ctx.take(style, "strokePaint") === "gradient" ? gradientOf(ctx, style, "strokeGradient", "style") : void 0;
2554
- if (markup) ctx.take(style, "strokeGradient");
2555
- let outline = gradientStroke ? {
2556
- paint: gradientStroke,
2557
- width: 0
2558
- } : tint !== void 0 ? {
2559
- paint: {
2560
- kind: "color",
2561
- value: tint
2562
- },
2563
- width: 0
2564
- } : strokeOf(ctx, style, "strokeColor", "strokeWidth", dashed, "strokeColorRole");
2565
- if (!outline && style.geoShape === "scribble") {
2566
- const width = typeof style.strokeWidth === "number" && style.strokeWidth > 0 ? style.strokeWidth : 2;
2567
- outline = {
2568
- paint: {
2569
- kind: "color",
2570
- value: colorOf(ctx, style, "strokeColor", "strokeColorRole") ?? colorOf(ctx, style, "fillColor", "fillColorRole") ?? "#2563EB"
2571
- },
2572
- width,
2573
- ...dashed
2574
- };
2575
- }
2576
- const glyphs = textStrokeOf(ctx, style);
2577
- const outer = strokeOf(ctx, style, "outerStrokeColor", "outerStrokeWidth", { align: "outside" });
2578
- const inner = strokeOf(ctx, style, "innerStrokeColor", "innerStrokeWidth", { align: "inside" });
2579
- const strokes = (layer.type === "text" ? [
2580
- glyphs,
2581
- outer,
2582
- inner
2583
- ] : [
2584
- outline,
2585
- borderStyle === "solid" || borderStyle === "dashed" || borderStyle === "dotted" ? border : void 0,
2586
- glyphs,
2587
- outer,
2588
- inner
2589
- ]).filter((s) => s !== void 0);
2590
- if (strokes.length > 0 && admits(layer.type, "strokes")) layer.strokes = strokes;
2591
- }
2592
- var TEXTURE_KEYS = [
2593
- ["tipo", "type"],
2594
- ["color", "color"],
2595
- ["angulo", "angle"],
2596
- ["cruzada", "crossed"],
2597
- ["grosor", "thickness"],
2598
- ["tamano", "size"]
2599
- ];
2600
- /** The background of the canvas, which 1.x kept in some twenty undeclared root keys. */
2601
- function canvasFills(ctx, meta) {
2602
- const type = ctx.take(meta, "backgroundType");
2603
- const color = colorOf(ctx, meta, "backgroundColor");
2604
- const gradient = gradientOf(ctx, meta, "backgroundGradient", "root");
2605
- for (const key of [
2606
- "backgroundGradientAngle",
2607
- "backgroundGradientStart",
2608
- "backgroundGradientEnd",
2609
- "backgroundGradientType"
2610
- ]) ctx.take(meta, key);
2611
- const pattern = patternOf(ctx, meta, "backgroundPattern");
2612
- const generative = asObject(ctx.take(meta, "backgroundGenerative"));
2613
- const texture = asObject(ctx.take(meta, "backgroundTexture"));
2614
- const fills = [];
2615
- const solid = color === void 0 ? void 0 : {
2616
- kind: "color",
2617
- value: color
2618
- };
2619
- if (type === "gradient") fills.push(...[gradient ?? solid].filter((p) => !!p));
2620
- else if (type === "pattern") fills.push(...[pattern ?? solid].filter((p) => !!p));
2621
- else if (type === "generative" && generative) fills.push({
2622
- kind: "generative",
2623
- generative
2624
- });
2625
- else if (type !== "transparent" && type !== "image" && solid) fills.push(solid);
2626
- if (texture && typeof texture.tipo === "string") {
2627
- const drawn = {};
2628
- for (const [spanish, english] of TEXTURE_KEYS) if (texture[spanish] !== void 0) drawn[english] = texture[spanish];
2629
- const paint = {
2630
- kind: "texture",
2631
- texture: drawn
2632
- };
2633
- if (typeof texture.opacidad === "number") paint.opacity = Math.min(1, Math.max(0, texture.opacidad));
2634
- fills.push(paint);
2635
- }
2636
- return fills;
2637
- }
2638
- // ../core/src/media-filters.ts
2639
- /**
2640
- * @license
2641
- * Copyright (c) 2026 Xue Studios LLC
2642
- * SPDX-License-Identifier: Apache-2.0
2643
- */
2644
- /**
2645
- * CSS for media filters (image and image fill).
2646
- *
2647
- * A single function serves all three renderers (editor, player and export):
2648
- * if each one composed the filter on its own, they would diverge. Neutral
2649
- * values (blur 0, hue 0, brightness/contrast/saturation 100, preset `none`)
2650
- * produce no CSS, so an image with no adjustments carries no `filter` in the DOM.
2651
- */
2652
- /** Single table of filter presets: the player and the other renderers use it through this function. */
2653
- var FILTER_PRESET_CSS = {
2654
- grayscale: "grayscale(1)",
2655
- sepia: "sepia(0.8)",
2656
- "high-contrast": "contrast(1.5) saturate(1.2)",
2657
- vintage: "sepia(0.35) contrast(1.1) saturate(0.85) brightness(1.05)",
2658
- cool: "saturate(1.1) hue-rotate(15deg) brightness(1.02)",
2659
- warm: "saturate(1.15) hue-rotate(-12deg) brightness(1.03)",
2660
- faded: "contrast(0.85) brightness(1.1) saturate(0.8)",
2661
- cinema: "contrast(1.25) saturate(1.1) hue-rotate(-8deg) brightness(0.95)",
2662
- nordic: "saturate(0.7) hue-rotate(20deg) brightness(1.05) contrast(1.1)",
2663
- sunset: "sepia(0.4) saturate(1.4) hue-rotate(-20deg) brightness(1.05)",
2664
- noir: "grayscale(1) contrast(1.6) brightness(0.9)",
2665
- dramatic: "contrast(1.6) saturate(1.3) brightness(0.95)",
2666
- cyberpunk: "contrast(1.3) saturate(1.8) hue-rotate(140deg)",
2667
- pastel: "brightness(1.15) saturate(1.3) contrast(0.9) hue-rotate(-5deg)",
2668
- vhs: "sepia(0.2) contrast(1.2) saturate(1.5) hue-rotate(30deg) brightness(1.05)"
2669
- };
2670
- // ../core/src/v2/upgrade/effects.ts
2671
- /**
2672
- * @license
2673
- * Copyright (c) 2026 Xue Studios LLC
2674
- * SPDX-License-Identifier: Apache-2.0
2675
- */
2676
- var finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
2677
- /**
2678
- * The colour-filter fields, shared by the filter layer (a backdrop effect),
2679
- * the image layer and the image fill. 1.x percentages become factors; a value
2680
- * that changes nothing is not written.
2681
- */
2682
- function takeFilters(ctx, style, backdrop = false) {
2683
- const named = ctx.take(style, "filterPreset");
2684
- const short = ctx.take(style, "fp");
2685
- const preset = backdrop ? named || short : named;
2686
- const blur = finite(ctx.take(style, "filterBlur"));
2687
- const brightness = finite(ctx.take(style, "filterBrightness"));
2688
- const contrast = finite(ctx.take(style, "filterContrast"));
2689
- const saturate = finite(ctx.take(style, "filterSaturate"));
2690
- const hueRotate = finite(ctx.take(style, "filterHueRotate"));
2691
- const filters = {};
2692
- if (typeof preset === "string" && (Object.hasOwn(FILTER_PRESET_CSS, preset) || backdrop && preset === "duotone")) filters.preset = preset;
2693
- if (blur) filters.blur = blur;
2694
- if (brightness !== void 0 && brightness !== 100) filters.brightness = brightness / 100;
2695
- if (contrast !== void 0 && contrast !== 100) filters.contrast = contrast / 100;
2696
- if (saturate !== void 0 && saturate !== 100) filters.saturate = saturate / 100;
2697
- if (hueRotate) filters.hueRotate = hueRotate;
2698
- return Object.keys(filters).length > 0 ? filters : void 0;
2699
- }
2700
- function listedEffect(ctx, value, defaults = {}) {
2701
- const fx = asObject(value);
2702
- if (!fx || fx.enabled === false) return void 0;
2703
- const tintOf = (fallbackColor, fallbackRole) => {
2704
- const role = fx.colorRole || fallbackRole;
2705
- const literal = typeof fx.color === "string" && fx.color ? fx.color : fallbackColor;
2706
- const color = typeof role === "string" && ctx.hasRole(role) ? literal ? {
2707
- var: role,
2708
- fallback: literal
2709
- } : { var: role } : literal;
2710
- return color === void 0 ? {} : { color };
2711
- };
2712
- const tint = tintOf(void 0, void 0);
2713
- switch (fx.type) {
2714
- case "drop-shadow": {
2715
- if (defaults.glyphsInSvg) return void 0;
2716
- const shadow = {
2717
- kind: "shadow",
2718
- y: 4,
2719
- blur: 12,
2720
- ...tintOf("rgba(0, 0, 0, 0.35)", defaults.shadowRole)
2721
- };
2722
- for (const key of [
2723
- "x",
2724
- "y",
2725
- "blur",
2726
- "spread"
2727
- ]) {
2728
- const n = finite(fx[key]);
2729
- if (n !== void 0) shadow[key] = key === "blur" ? Math.max(0, n) : n;
2730
- }
2731
- if (!shadow.x) delete shadow.x;
2732
- return shadow;
2733
- }
2734
- case "glow": {
2735
- if (defaults.glyphsInSvg) return void 0;
2736
- const glow = {
2737
- kind: "glow",
2738
- radius: finite(fx.radius) || 16,
2739
- ...tintOf("#f59e0b", defaults.glowRole)
2740
- };
2741
- const intensity = finite(fx.intensity);
2742
- if (intensity !== void 0) glow.intensity = intensity;
2743
- return glow;
2744
- }
2745
- case "blur": return {
2746
- kind: "blur",
2747
- radius: finite(fx.radius) ?? 8
2748
- };
2749
- case "color-grade": {
2750
- if (typeof fx.preset !== "string") return void 0;
2751
- const intensity = finite(fx.intensity);
2752
- return {
2753
- kind: "color-grade",
2754
- preset: fx.preset,
2755
- ...intensity === void 0 ? {} : { intensity }
2756
- };
2757
- }
2758
- case "texture": {
2759
- if (typeof fx.preset !== "string") return void 0;
2760
- const texture = {
2761
- kind: "texture",
2762
- preset: fx.preset,
2763
- ...tint
2764
- };
2765
- const intensity = finite(fx.intensity);
2766
- const scale = finite(fx.scale);
2767
- if (intensity !== void 0) texture.intensity = intensity;
2768
- if (typeof fx.blend === "string") texture.blend = fx.blend;
2769
- if (scale !== void 0 && scale !== 1) texture.scale = scale;
2770
- return texture;
2771
- }
2772
- default:
2773
- ctx.note(`style.effects: unknown effect type "${String(fx.type)}"`);
2774
- return;
2775
- }
2776
- }
2777
- function listedEffects(ctx, value, defaults) {
2778
- return Array.isArray(value) ? value.map((fx) => listedEffect(ctx, fx, defaults)).filter((fx) => !!fx) : [];
2779
- }
2780
- function convertEffects(ctx, slot, layer) {
2781
- const { style } = slot;
2782
- const effects = [];
2783
- const named = ctx.take(style, "effect");
2784
- const namedColor = colorOf(ctx, style, "effectColor", "effectColorRole");
2785
- const namedRadius = finite(ctx.take(style, "effectRadius"));
2786
- if (named === "neon") effects.push({
2787
- kind: "glow",
2788
- radius: namedRadius ?? 16,
2789
- color: namedColor ?? "#f59e0b"
2790
- });
2791
- const list = ctx.take(style, "effects");
2792
- const hasList = Array.isArray(list) && list.length > 0;
2793
- const enabled = ctx.take(style, "shadowEnabled") === true && !hasList;
2794
- let enabledShadow;
2795
- const shadowColor = colorOf(ctx, style, "shadowColor", "shadowColorRole");
2796
- const blur = finite(ctx.take(style, "shadowBlur"));
2797
- const x = finite(ctx.take(style, "shadowOffsetX"));
2798
- const y = finite(ctx.take(style, "shadowOffsetY"));
2799
- const opacity = finite(ctx.take(style, "shadowOpacity"));
2800
- if (enabled) {
2801
- const shadow = { kind: "shadow" };
2802
- if (x) shadow.x = x;
2803
- if (y) shadow.y = y;
2804
- if (blur) shadow.blur = blur;
2805
- if (shadowColor !== void 0) shadow.color = shadowColor;
2806
- if (opacity !== void 0 && opacity < 100) shadow.opacity = Math.max(0, opacity) / 100;
2807
- enabledShadow = shadow;
2808
- }
2809
- const legacyBlur = finite(ctx.take(style, "layerBlur")) ?? finite(ctx.take(style, "blur"));
2810
- ctx.take(style, "blur");
2811
- if (hasList) effects.push(...listedEffects(ctx, list, {
2812
- shadowRole: style.shadowColorRole,
2813
- glowRole: style.effectColorRole,
2814
- glyphsInSvg: slot.type === "artistic-text"
2815
- }));
2816
- else if (legacyBlur && legacyBlur > 0) effects.push({
2817
- kind: "blur",
2818
- radius: legacyBlur
2819
- });
2820
- const filters = takeFilters(ctx, style, slot.type === "filter");
2821
- if (slot.type === "filter") effects.push({
2822
- kind: "backdrop",
2823
- ...filters
2824
- });
2825
- else if (filters) {
2826
- const paint = layer.fills?.find((p) => "kind" in p && p.kind === "image");
2827
- if (layer.image) layer.image.filters = filters;
2828
- else if (paint && "kind" in paint && paint.kind === "image") paint.filters = filters;
2829
- }
2830
- const grain = ctx.take(style, "grain") === true;
2831
- const intensity = finite(ctx.take(style, "grainIntensity"));
2832
- const size = finite(ctx.take(style, "grainSize"));
2833
- const blend = ctx.take(style, "grainBlend");
2834
- if (grain && !hasList) {
2835
- const fx = { kind: "grain" };
2836
- if (intensity !== void 0) fx.intensity = intensity;
2837
- if (size !== void 0) fx.size = size;
2838
- if (typeof blend === "string") fx.blend = blend;
2839
- effects.push(fx);
2840
- }
2841
- if (enabledShadow) effects.push(enabledShadow);
2842
- if (effects.length > 0) layer.effects = effects;
2843
- }
2844
- /** Grain and effects declared for the whole canvas. */
2845
- function canvasEffects(ctx, meta) {
2846
- const effects = listedEffects(ctx, ctx.take(meta, "effects"));
2847
- const grain = asObject(ctx.take(meta, "grain"));
2848
- if (grain && grain.enabled !== false) {
2849
- const fx = { kind: "grain" };
2850
- const intensity = finite(grain.intensity);
2851
- const frequency = finite(grain.baseFrequency);
2852
- if (intensity !== void 0) fx.intensity = intensity;
2853
- if (frequency !== void 0) fx.size = frequency;
2854
- if (typeof grain.blendMode === "string") fx.blend = grain.blendMode;
2855
- if (typeof grain.color === "string") fx.color = grain.color;
2856
- effects.push(fx);
2857
- }
2858
- return effects;
2859
- }
2860
- // ../core/src/v2/upgrade/geometry.ts
2861
- /**
2862
- * @license
2863
- * Copyright (c) 2026 Xue Studios LLC
2864
- * SPDX-License-Identifier: Apache-2.0
2865
- */
2866
- /** The 1.x name of a figure and the 2.0 geometry that has its own kind. */
2867
- var BASIC = {
2868
- rectangle: { kind: "rect" },
2869
- circle: { kind: "ellipse" },
2870
- line: { kind: "line" }
2871
- };
2872
- var viewBoxOf = (value) => {
2873
- const numbers = typeof value === "string" ? value.trim().split(/[\s,]+/).map(Number) : [];
2874
- return numbers.length === 4 && numbers.every(Number.isFinite) ? numbers : [
2875
- 0,
2876
- 0,
2877
- 24,
2878
- 24
2879
- ];
2880
- };
2881
- /** `content` of a layer that is not a text: one value for every language, under "*" or the main one. */
2882
- function mediaOf(ctx, slot) {
2883
- const content = ctx.take(slot.raw, "content");
2884
- if (typeof content === "string") return content || void 0;
2885
- const map = asObject(content) ?? {};
2886
- const value = map["*"] ?? map[ctx.language] ?? Object.values(map).find((v) => typeof v === "string" && v !== "");
2887
- return typeof value === "string" && value !== "" ? value : void 0;
2888
- }
2889
- /**
2890
- * A picture with per-language exceptions. 1.x kept the principal under "*" and
2891
- * gave a language its own key, final even when empty.
2892
- */
2893
- function imageSource(slot, value) {
2894
- const map = asObject(slot.raw.content);
2895
- if (!map || typeof map["*"] !== "string" || value === "oim:base") return value;
2896
- const modes = {};
2897
- for (const [language, own] of Object.entries(map)) if (language !== "*" && typeof own === "string" && own !== value) modes[language] = own;
2898
- return Object.keys(modes).length > 0 ? {
2899
- value,
2900
- modes
2901
- } : value;
2902
- }
2903
- function pathsFromLayers(ctx, layers, viewBox, original = []) {
2904
- const paths = [];
2905
- for (const item of layers) {
2906
- const part = asObject(item);
2907
- if (!part || typeof part.d !== "string" || !part.d) continue;
2908
- const entry = { d: part.d };
2909
- if (part.fill === void 0 && part.stroke === void 0) {
2910
- const { d: _, ...inherited } = original.find((path) => path.d === part.d) ?? { d: "" };
2911
- Object.assign(entry, inherited);
2912
- }
2913
- if (typeof part.fill === "string" && part.fill !== "none") entry.fill = part.fill;
2914
- if (typeof part.stroke === "string" && part.stroke !== "none") {
2915
- entry.stroke = part.stroke;
2916
- entry.strokeWidth = typeof part.strokeWidth === "number" ? part.strokeWidth : 1;
2917
- }
2918
- if (typeof part.animationType === "string" && part.animationType !== "none") ctx.note(`style.svgLayers: per-path animation "${part.animationType}"`);
2919
- paths.push(entry);
2920
- }
2921
- return paths.length > 0 ? {
2922
- kind: "paths",
2923
- viewBox,
2924
- paths
2925
- } : void 0;
2926
- }
2927
- function shapeGeometry(ctx, slot, media) {
2928
- const { style } = slot;
2929
- const name = ctx.take(style, "geoShape");
2930
- ctx.take(style, "geoType");
2931
- const path = ctx.take(style, "svgPath");
2932
- const blob = ctx.take(style, "customBlobPath");
2933
- const viewBox = viewBoxOf(ctx.take(style, "svgViewBox"));
2934
- const rawXml = ctx.take(style, "svgRawXml");
2935
- const layers = ctx.take(style, "svgLayers");
2936
- const content = drawsMarkup(slot) && typeof media === "string" && /<svg/i.test(media) ? media : void 0;
2937
- if (content) {
2938
- const parsed = svgToPaths(content);
2939
- if (parsed.ok) return {
2940
- kind: "paths",
2941
- ...parsed.value
2942
- };
2943
- }
2944
- if (Array.isArray(layers) && layers.length > 0) {
2945
- const original = typeof rawXml === "string" && rawXml ? svgToPaths(rawXml) : void 0;
2946
- const fromLayers = pathsFromLayers(ctx, layers, viewBox, original?.ok ? original.value.paths : []);
2947
- if (fromLayers) return fromLayers;
2948
- }
2949
- const xml = content ?? (typeof rawXml === "string" && rawXml ? rawXml : drawsMarkup(slot) ? media : void 0);
2950
- if (xml) {
2951
- const parsed = svgToPaths(xml);
2952
- if (parsed.ok) return {
2953
- kind: "paths",
2954
- ...parsed.value
2955
- };
2956
- const original = xml !== rawXml && typeof rawXml === "string" && rawXml ? svgToPaths(rawXml) : void 0;
2957
- if (original?.ok) return {
2958
- kind: "paths",
2959
- ...original.value
2960
- };
2961
- ctx.note(`style.svgRawXml: ${parsed.reason}`);
2962
- return { kind: "rect" };
2963
- }
2964
- const d = typeof path === "string" && path ? path : typeof blob === "string" && blob ? blob : void 0;
2965
- if (name === "scribble" && typeof blob === "string" && blob) return {
2966
- kind: "paths",
2967
- viewBox: [
2968
- 0,
2969
- 0,
2970
- 100,
2971
- 100
2972
- ],
2973
- paths: [{ d: blob }]
2974
- };
2975
- if (name === "blob" && typeof blob === "string" && blob) return {
2976
- kind: "paths",
2977
- viewBox: [
2978
- 0,
2979
- 0,
2980
- 100,
2981
- 100
2982
- ],
2983
- paths: [{ d: blob }]
2984
- };
2985
- if (d && (name === void 0 || name === "custom" || name === "blob")) return {
2986
- kind: "paths",
2987
- viewBox: name === "blob" ? [
2988
- 0,
2989
- 0,
2990
- 100,
2991
- 100
2992
- ] : viewBox,
2993
- paths: [{ d }]
2994
- };
2995
- if (typeof name === "string" && name) return BASIC[name] ?? {
2996
- kind: "preset",
2997
- name
2998
- };
2999
- return { kind: "rect" };
3000
- }
3001
- var CORNER_KEYS = [
3002
- ["borderRadiusTL", "borderTopLeftRadius"],
3003
- ["borderRadiusTR", "borderTopRightRadius"],
3004
- ["borderRadiusBR", "borderBottomRightRadius"],
3005
- ["borderRadiusBL", "borderBottomLeftRadius"]
3006
- ];
3007
- var SHORTHAND = [
3008
- [
3009
- 0,
3010
- 0,
3011
- 0,
3012
- 0
3013
- ],
3014
- [
3015
- 0,
3016
- 1,
3017
- 0,
3018
- 1
3019
- ],
3020
- [
3021
- 0,
3022
- 1,
3023
- 2,
3024
- 1
3025
- ],
3026
- [
3027
- 0,
3028
- 1,
3029
- 2,
3030
- 3
3031
- ]
3032
- ];
3033
- function cornersOf(ctx, style) {
3034
- const W = ctx.canvas.width;
3035
- const raw = ctx.take(style, "borderRadius");
3036
- const tokens = typeof raw === "string" ? raw.trim().split(/\s+/) : [];
3037
- const shorthand = tokens.length > 1 && tokens.length <= 4 ? SHORTHAND[tokens.length - 1].map((i) => toCanvasUnits(tokens[i], W)) : [];
3038
- const all = tokens.length > 1 ? 0 : toCanvasUnits(raw, W) ?? 0;
3039
- const each = CORNER_KEYS.map((keys, corner) => {
3040
- return keys.map((key) => toCanvasUnits(ctx.take(style, key), W)).find((v) => v !== void 0) ?? shorthand[corner];
3041
- });
3042
- if (each.some((v) => v !== void 0)) {
3043
- const four = each.map((v) => Math.max(0, v ?? all));
3044
- return four.every((v) => v === four[0]) ? four[0] || void 0 : four;
3045
- }
3046
- return all > 0 ? all : void 0;
3047
- }
3048
- function convertGeometry(ctx, slot, layer) {
3049
- const { style } = slot;
3050
- const media = layer.type === "text" ? void 0 : mediaOf(ctx, slot);
3051
- if (layer.type === "shape") layer.geometry = shapeGeometry(ctx, slot, media);
3052
- const first = layer.fills?.[0];
3053
- if (drawsMarkup(slot) && layer.geometry?.kind === "paths" && first && "kind" in first && first.kind === "color") for (const path of layer.geometry.paths) path.fill = "currentColor";
3054
- else for (const key of [
3055
- "geoShape",
3056
- "geoType",
3057
- "svgPath",
3058
- "customBlobPath",
3059
- "svgViewBox",
3060
- "svgRawXml",
3061
- "svgLayers"
3062
- ]) ctx.take(style, key);
3063
- if ((slot.raw.is_background_pattern === true || slot.raw.id === "background-pattern-slot") && layer.geometry?.kind === "paths" && first && "kind" in first && first.kind === "pattern") {
3064
- first.pattern.tile = {
3065
- viewBox: layer.geometry.viewBox,
3066
- paths: layer.geometry.paths.slice(0, 64)
3067
- };
3068
- layer.geometry = { kind: "rect" };
3069
- }
3070
- const corners = cornersOf(ctx, style);
3071
- if (corners !== void 0 && admits(layer.type, "corners")) layer.corners = corners;
3072
- const fit = ctx.take(style, "objectFit");
3073
- const crop = asObject(ctx.take(style, "imageCrop"));
3074
- if (layer.type === "image") {
3075
- layer.image = { src: imageSource(slot, media ?? "oim:base") };
3076
- if (typeof fit === "string" && fit !== "cover") layer.image.fit = fit;
3077
- if (crop) layer.image.crop = crop;
3078
- }
3079
- if (layer.type === "lottie" && media) layer.lottie = { src: media };
3080
- if (ctx.take(style, "flipX") === true) layer.box.flipX = true;
3081
- if (ctx.take(style, "flipY") === true) layer.box.flipY = true;
3082
- const alt = asObject(ctx.take(style, "alt"));
3083
- const decorative = ctx.take(style, "decorative") === true;
3084
- if (admits(layer.type, "a11y") && (alt && Object.keys(alt).length > 0 || decorative)) {
3085
- layer.a11y = {};
3086
- if (alt && Object.keys(alt).length > 0) layer.a11y.alt = alt;
3087
- if (decorative) layer.a11y.decorative = true;
3088
- }
3089
- }
3090
- // ../core/src/v2/upgrade/keys.ts
3091
- /**
3092
- * @license
3093
- * Copyright (c) 2026 Xue Studios LLC
3094
- * SPDX-License-Identifier: Apache-2.0
3095
- */
3096
- /** Declared in 1.x and dropped in 2.0: nobody wrote them, or they were CSS inside the file. */
3097
- var RETIRED_STYLE_KEYS = [
3098
- "shader_fx",
3099
- "outline",
3100
- "verticalAlign"
3101
- ];
3102
- // ../core/src/v2/upgrade/mask.ts
3103
- /**
3104
- * @license
3105
- * Copyright (c) 2026 Xue Studios LLC
3106
- * SPDX-License-Identifier: Apache-2.0
3107
- */
3108
- var SHAPES = {
3109
- rectangle: { kind: "rect" },
3110
- circle: { kind: "ellipse" },
3111
- line: { kind: "line" }
3112
- };
3113
- function convertMask(ctx, slot, layer) {
3114
- const { style } = slot;
3115
- const mode = ctx.take(style, "maskMode");
3116
- const feather = ctx.take(style, "maskFeather");
3117
- const coverage = ctx.take(style, "maskCoverage");
3118
- const shape = ctx.take(style, "maskShape");
3119
- const path = ctx.take(style, "maskSvgPath");
3120
- const cuts = ctx.take(style, "cuts");
3121
- const bgLiteral = ctx.take(style, "maskBgColor");
3122
- const bgRole = ctx.take(style, "maskBgColorRole");
3123
- const strokeLiteral = ctx.take(style, "maskStrokeColor");
3124
- const strokeRole = ctx.take(style, "maskStrokeColorRole");
3125
- const strokeWidth = ctx.take(style, "maskStrokeWidth");
3126
- ctx.take(style, "maskInvert");
3127
- if (slot.type !== "mask") return;
3128
- const mask = {};
3129
- const cutout = mode === "cutout";
3130
- if (cutout) mask.mode = "cutout";
3131
- if (typeof feather === "number" && feather > 0) mask.feather = feather;
3132
- if (coverage === "container") mask.scope = "group";
3133
- layer.mask = mask;
3134
- const name = typeof shape === "string" && shape ? shape : typeof style.geoShape === "string" ? style.geoShape : void 0;
3135
- const d = typeof path === "string" && path ? path : typeof style.svgPath === "string" && style.svgPath ? style.svgPath : void 0;
3136
- if (d && (!name || name === "custom")) layer.geometry = {
3137
- kind: "paths",
3138
- viewBox: [
3139
- 0,
3140
- 0,
3141
- 100,
3142
- 100
3143
- ],
3144
- paths: [{ d }]
3145
- };
3146
- else if (name && name !== "custom") layer.geometry = SHAPES[name] ?? {
3147
- kind: "preset",
3148
- name
3149
- };
3150
- else layer.geometry = { kind: "ellipse" };
3151
- if (Array.isArray(cuts) && cuts.length > 0) layer.extensions = {
3152
- ...layer.extensions,
3153
- studio: {
3154
- ...asObject(layer.extensions?.studio),
3155
- maskCuts: cuts
3156
- }
3157
- };
3158
- if (cutout) return;
3159
- const color = (role, literal, fallback) => {
3160
- const value = isColor(literal) ? literal : fallback;
3161
- return typeof role === "string" && ctx.hasRole(role) ? {
3162
- var: role,
3163
- fallback: value
3164
- } : value;
3165
- };
3166
- const own = layer.fills?.[0];
3167
- if (!(own !== void 0 && "kind" in own && own.kind !== "color")) layer.fills = [{
3168
- kind: "color",
3169
- value: color(bgRole || style.fillColorRole, bgLiteral, "#38BDF8")
3170
- }];
3171
- delete layer.strokes;
3172
- if (typeof strokeWidth === "number" && strokeWidth > 0) layer.strokes = [{
3173
- paint: {
3174
- kind: "color",
3175
- value: color(strokeRole || style.strokeColorRole, strokeLiteral, "#FFFFFF")
3176
- },
3177
- width: strokeWidth
3178
- }];
3179
- }
3180
1461
  // ../core/src/reeditPermission.ts
3181
1462
  /**
3182
1463
  * @license
@@ -3229,614 +1510,16 @@ function permissionOf(metadata) {
3229
1510
  function signatureStamp(permission) {
3230
1511
  return permission === "public" ? "verified_authorless" : "verified";
3231
1512
  }
3232
- // ../core/src/v2/version.ts
3233
- /**
3234
- * @license
3235
- * Copyright (c) 2026 Xue Studios LLC
3236
- * SPDX-License-Identifier: Apache-2.0
3237
- */
3238
- var DOCUMENT_VERSION = "2.0.0-draft.1";
3239
- // ../core/src/v2/upgrade/root.ts
3240
- /**
3241
- * @license
3242
- * Copyright (c) 2026 Xue Studios LLC
3243
- * SPDX-License-Identifier: Apache-2.0
3244
- */
3245
- /** Fallback when a 1.x file declares no canvas: the base the core has always assumed. */
3246
- var DEFAULT_CANVAS = 800;
3247
- var TRANSPORT_KEYS = [
3248
- "signature",
3249
- "key_version",
3250
- "signed_at",
3251
- "timestamp",
3252
- "image_hash",
3253
- "image_hash_alg"
3254
- ];
3255
- var RETIRED_ROOT_KEYS = [
3256
- "version",
3257
- "min_player",
3258
- "image",
3259
- "media_type",
3260
- "allowed_domains",
3261
- "terms_accepted",
3262
- "redirect_membership_verified",
3263
- "capabilities",
3264
- "capabilities_required"
3265
- ];
3266
- function canvasOf(meta) {
3267
- const canvas = asObject(meta.canvas) ?? {};
3268
- const positive = (value) => typeof value === "number" && value > 0 ? value : void 0;
3269
- const width = positive(meta.artboardWidth) ?? positive(meta.canvasWidth) ?? positive(meta.canvas_width) ?? positive(canvas.natural_width) ?? positive(canvas.width) ?? DEFAULT_CANVAS;
3270
- return {
3271
- width,
3272
- height: positive(meta.artboardHeight) ?? positive(meta.canvasHeight) ?? positive(meta.canvas_height) ?? positive(canvas.natural_height) ?? positive(canvas.height) ?? width
3273
- };
3274
- }
3275
- function languagesOf(meta) {
3276
- for (const key of ["languages", "lang"]) {
3277
- const list = meta[key];
3278
- if (Array.isArray(list)) {
3279
- const clean = list.filter((l) => typeof l === "string" && l.length > 0);
3280
- if (clean.length > 0) return [...new Set(clean)];
3281
- }
3282
- }
3283
- const found = /* @__PURE__ */ new Set();
3284
- for (const slot of Array.isArray(meta.slots) ? meta.slots : []) {
3285
- const content = asObject(asObject(slot)?.content);
3286
- for (const key of Object.keys(content ?? {})) if (key !== "*") found.add(key);
3287
- }
3288
- return found.size > 0 ? [...found] : ["es"];
3289
- }
3290
- /** Every colour role some palette of the document defines. */
3291
- function rolesOf(meta) {
3292
- const roles = /* @__PURE__ */ new Set();
3293
- for (const palette of Object.values(asObject(meta.palettes) ?? {})) for (const role of Object.keys(asObject(palette) ?? {})) roles.add(role);
3294
- return roles;
3295
- }
3296
- /** The 2.0 document without its layers, and the 1.x list the layers come from. */
3297
- function convertRoot(ctx, meta) {
3298
- const document = {
3299
- oim: DOCUMENT_VERSION,
3300
- canvas: ctx.canvas,
3301
- languages: languagesOf(meta),
3302
- layers: []
3303
- };
3304
- for (const key of [
3305
- "oim",
3306
- "canvas",
3307
- "languages",
3308
- "lang"
3309
- ]) ctx.take(meta, key);
3310
- const id = ctx.take(meta, "oim_id");
3311
- if (typeof id === "string" && id) document.id = id;
3312
- const name = ctx.take(meta, "name");
3313
- if (typeof name === "string" && name) document.name = name;
3314
- if (meta.reedit !== void 0 || meta.immutable_lock !== void 0) document.reedit = permissionOf(meta);
3315
- ctx.take(meta, "reedit");
3316
- ctx.take(meta, "immutable_lock");
3317
- const description = asObject(ctx.take(meta, "description"));
3318
- if (description && Object.keys(description).length > 0) document.description = description;
3319
- const fonts = ctx.take(meta, "fonts");
3320
- if (Array.isArray(fonts) && fonts.length > 0) document.fonts = fonts;
3321
- for (const key of TRANSPORT_KEYS) ctx.retire(meta, key);
3322
- for (const key of RETIRED_ROOT_KEYS) ctx.retire(meta, key);
3323
- let slots = [];
3324
- for (const key of [
3325
- "slots",
3326
- "elements",
3327
- "layers"
3328
- ]) {
3329
- const list = ctx.take(meta, key);
3330
- if (slots.length === 0 && Array.isArray(list)) slots = list;
3331
- }
3332
- return {
3333
- document,
3334
- slots
3335
- };
3336
- }
3337
- // ../core/src/v2/upgrade/text.ts
3338
- /**
3339
- * @license
3340
- * Copyright (c) 2026 Xue Studios LLC
3341
- * SPDX-License-Identifier: Apache-2.0
3342
- */
3343
- /**
3344
- * A length with per-language exceptions (`fontSizes`, `maxWidths`). The main
3345
- * language is the value; the others that differ from it are the exceptions.
3346
- */
3347
- function sized(ctx, style, key, perLanguageKey) {
3348
- const W = ctx.canvas.width;
3349
- const base = toCanvasUnits(ctx.take(style, key), W);
3350
- const perLanguage = asObject(ctx.take(style, perLanguageKey)) ?? {};
3351
- const value = toCanvasUnits(perLanguage[ctx.language], W) ?? base;
3352
- if (value === void 0) return void 0;
3353
- const modes = {};
3354
- for (const [language, raw] of Object.entries(perLanguage)) {
3355
- const converted = toCanvasUnits(raw, W);
3356
- if (language !== ctx.language && converted !== void 0 && converted !== value) modes[language] = converted;
3357
- }
3358
- return Object.keys(modes).length > 0 ? {
3359
- value,
3360
- modes
3361
- } : value;
3362
- }
3363
- var TYPOGRAPHY_KEYS = [
3364
- "fontFamily",
3365
- "fontSize",
3366
- "fontSizes",
3367
- "fontWeight",
3368
- "fontStyle",
3369
- "bold",
3370
- "italic",
3371
- "underline",
3372
- "textAlign",
3373
- "lineHeight",
3374
- "letterSpacing",
3375
- "textTransform",
3376
- "textDecoration",
3377
- "maxWidth",
3378
- "maxWidths",
3379
- "marks",
3380
- "textRuns",
3381
- "textHighlight",
3382
- "dropCap",
3383
- "artisticPreset",
3384
- "curveType",
3385
- "curveAmount",
3386
- "extrusionDepth",
3387
- "extrusionAngle",
3388
- "extrusionColor",
3389
- "extrusionShading"
3390
- ];
3391
- function convertText(ctx, slot, layer) {
3392
- const { raw, style } = slot;
3393
- ctx.retire(style, "textRole");
3394
- const align = ctx.take(style, "textAlign") ?? ctx.take(raw, "align");
3395
- ctx.take(raw, "align");
3396
- if (layer.type !== "text") {
3397
- for (const key of TYPOGRAPHY_KEYS) ctx.take(style, key);
3398
- return;
3399
- }
3400
- const content = ctx.take(raw, "content");
3401
- const text = { content: {} };
3402
- if (typeof content === "string") text.content[ctx.language] = content;
3403
- else for (const [language, value] of Object.entries(asObject(content) ?? {})) if (typeof value === "string") text.content[language] = value;
3404
- const font = {};
3405
- const family = ctx.take(style, "fontFamily");
3406
- if (typeof family === "string" && family) font.family = family;
3407
- const size = sized(ctx, style, "fontSize", "fontSizes");
3408
- if (size !== void 0) font.size = size;
3409
- const weight = ctx.take(style, "fontWeight");
3410
- ctx.take(style, "bold");
3411
- if (typeof weight === "number" || typeof weight === "string" && weight) {
3412
- if (Number(weight) !== 400) font.weight = Number.isFinite(Number(weight)) ? Number(weight) : weight;
3413
- }
3414
- const fontStyle = ctx.take(style, "fontStyle");
3415
- if (fontStyle === "italic" || fontStyle === "oblique") font.italic = true;
3416
- ctx.take(style, "italic");
3417
- if (Object.keys(font).length > 0) text.font = font;
3418
- if (align === "center" || align === "right" || align === "justify") text.align = align;
3419
- const lineHeight = ctx.take(style, "lineHeight");
3420
- if (typeof lineHeight === "number" || typeof lineHeight === "string" && lineHeight) text.lineHeight = lineHeight;
3421
- const rawSpacing = ctx.take(style, "letterSpacing");
3422
- const spacing = typeof rawSpacing === "string" ? toCanvasUnits(rawSpacing, ctx.canvas.width) : typeof rawSpacing === "number" && slot.type === "artistic-text" ? rawSpacing : void 0;
3423
- if (spacing !== void 0 && spacing !== 0) text.letterSpacing = spacing;
3424
- const transform = ctx.take(style, "textTransform");
3425
- if (transform === "uppercase" || transform === "lowercase" || transform === "capitalize") text.transform = transform;
3426
- const decoration = ctx.take(style, "textDecoration");
3427
- ctx.take(style, "underline");
3428
- if (typeof decoration === "string" && decoration && decoration !== "none") text.decoration = decoration;
3429
- const maxWidth = sized(ctx, style, "maxWidth", "maxWidths");
3430
- if (maxWidth !== void 0) text.maxWidth = maxWidth;
3431
- const marks = asObject(ctx.take(style, "marks"));
3432
- if (marks && Object.keys(marks).length > 0) text.marks = marks;
3433
- const runs = asObject(ctx.take(style, "textRuns"));
3434
- if (runs && Object.keys(runs).length > 0) text.runs = runs;
3435
- const highlight = asObject(ctx.take(style, "textHighlight"));
3436
- if (highlight && highlight.enabled !== false) text.highlight = highlight;
3437
- const dropCap = asObject(ctx.take(style, "dropCap"));
3438
- if (dropCap && dropCap.enabled !== false) text.dropCap = dropCap;
3439
- const artistic = {};
3440
- const preset = ctx.take(style, "artisticPreset");
3441
- if (typeof preset === "string" && preset) artistic.preset = preset;
3442
- const curveType = ctx.take(style, "curveType");
3443
- const curveAmount = ctx.take(style, "curveAmount");
3444
- const curve = curveType ?? "arc";
3445
- if ((curve === "arc" || curve === "wave" || curve === "arch") && typeof curveAmount === "number" && curveAmount !== 0) artistic.curve = {
3446
- type: curve,
3447
- amount: curveAmount
3448
- };
3449
- const depth = ctx.take(style, "extrusionDepth");
3450
- const angle = ctx.take(style, "extrusionAngle");
3451
- const extrusionColor = ctx.take(style, "extrusionColor");
3452
- const shading = ctx.take(style, "extrusionShading");
3453
- if (typeof depth === "number" && depth > 0) {
3454
- artistic.extrusion = { depth };
3455
- if (typeof angle === "number") artistic.extrusion.angle = angle;
3456
- if (typeof extrusionColor === "string" && extrusionColor) artistic.extrusion.color = extrusionColor;
3457
- if (typeof shading === "boolean") artistic.extrusion.shading = shading;
3458
- }
3459
- if (slot.type === "artistic-text" || Object.keys(artistic).length > 0) text.artistic = artistic;
3460
- layer.text = text;
3461
- }
3462
- // ../core/src/groups.ts
3463
- /**
3464
- * @license
3465
- * Copyright (c) 2026 Xue Studios LLC
3466
- * SPDX-License-Identifier: Apache-2.0
3467
- */
3468
- /**
3469
- * Who is a child of whom. This is the rule where the editor and the player
3470
- * HAVE to agree.
3471
- *
3472
- * It lives here, and not on each side, because it is the only part of the
3473
- * groups whose disagreement shows: if both do not answer the same to "which
3474
- * layers go inside this group", the same file is painted differently depending
3475
- * on who opens it, and its author has no way of knowing which of the two is right.
3476
- *
3477
- * What is NOT here is deliberate. The editor has editing operations -dissolve,
3478
- * extract, duplicate, select- that the player never runs, and each one computes
3479
- * its wrapper's style from different data: the player receives the box already
3480
- * resolved in pixels, while the editor carries opacity, blend, filter and
3481
- * preview state. They are two different functions that shared a name, not a
3482
- * copy that drifted. Merging them would force one to pretend to be what the
3483
- * other needs.
3484
- *
3485
- * ## Why the parent lives in `style`
3486
- *
3487
- * `RawSlot`, in the backend, is a Pydantic model with `extra='ignore'`: a new
3488
- * field at the ROOT of the slot is silently discarded when signing. That is how
3489
- * the parallax was lost in every published `.oim`. So it is read from one single
3490
- * place, and that place is `style`.
3491
- *
3492
- * ## Why it travels in one direction only
3493
- *
3494
- * The editor keeps two representations -the group carries `childIds` and each
3495
- * child carries `groupId`- because it needs to walk the hierarchy in both
3496
- * directions. Only the second one travels in the file: two copies of the same
3497
- * truth inside a signed file is how the duplicated group broke in the past.
3498
- * On opening, the editor derives `childIds` from the `groupId`s.
3499
- *
3500
- * ## Degrades in both directions
3501
- *
3502
- * An old file carries no `style.groupId` in any slot: the map comes out empty,
3503
- * nothing is nested, and the viewer paints things as always. An old player with
3504
- * a new file ignores the field and paints the children loose, with their canvas
3505
- * coordinates. In no case does a layer disappear.
3506
- */
3507
- /** Is this slot a group? */
3508
- function isGroup(slot) {
3509
- return !!slot && slot.type === "group";
3510
- }
3511
- /**
3512
- * A slot's parent, as the editor writes it.
3513
- *
3514
- * It is read from ONE place only -`style.groupId`- for the reason explained
3515
- * above about `extra='ignore'`.
3516
- */
3517
- function slotParent(slot) {
3518
- const id = (slot && slot.style || {}).groupId;
3519
- return typeof id === "string" && id ? id : null;
3520
- }
3521
- /**
3522
- * Which slots go inside which group.
3523
- *
3524
- * It is walked by the child's `groupId`, the only direction that travels to the
3525
- * file. A `groupId` that points to something that does not exist, or that is not
3526
- * a group, nests nothing: the child stays loose where it was, which is the usual
3527
- * behavior, and never a layer that disappears.
3528
- *
3529
- * A group cannot be a child of itself or of another group -the editor enforces
3530
- * that rule-, but this cannot trust a file that may come from anywhere: without
3531
- * this cut, two groups that point at each other would hang the nesting.
3532
- */
3533
- function childrenByGroup(slots) {
3534
- const groupIds = /* @__PURE__ */ new Set();
3535
- for (const s of slots || []) if (isGroup(s) && s.id) groupIds.add(String(s.id));
3536
- const byParent = /* @__PURE__ */ new Map();
3537
- for (const s of slots || []) {
3538
- if (!s || !s.id || isGroup(s)) continue;
3539
- const parent = slotParent(s);
3540
- if (!parent || !groupIds.has(parent)) continue;
3541
- const list = byParent.get(parent);
3542
- if (list) list.push(String(s.id));
3543
- else byParent.set(parent, [String(s.id)]);
3544
- }
3545
- return byParent;
3546
- }
3547
- // ../core/src/v2/upgrade/tree.ts
3548
- /**
3549
- * @license
3550
- * Copyright (c) 2026 Xue Studios LLC
3551
- * SPDX-License-Identifier: Apache-2.0
3552
- */
3553
- /** The fifteen layer types of 1.x and the five they become. */
3554
- var TYPE_OF = {
3555
- text: "text",
3556
- "artistic-text": "text",
3557
- geo: "shape",
3558
- shape: "shape",
3559
- draw: "shape",
3560
- svg: "shape",
3561
- pattern: "shape",
3562
- container: "shape",
3563
- filter: "shape",
3564
- mask: "shape",
3565
- image: "image",
3566
- lottie: "lottie",
3567
- group: "group",
3568
- component: "group",
3569
- zone: "group"
3570
- };
3571
- /**
3572
- * Moves each child inside its group. Membership is the core's own rule
3573
- * (`childrenByGroup`, read from the child's `groupId`), so the 2.0 tree nests
3574
- * exactly what every 1.x player nests. `childIds` only repeats it.
3575
- */
3576
- function buildTree(ctx, slots, layers) {
3577
- const members = childrenByGroup(slots.map((s) => ({
3578
- ...s.raw,
3579
- style: s.style
3580
- })));
3581
- const parentOf = /* @__PURE__ */ new Map();
3582
- for (const [group, children] of members) for (const child of children) parentOf.set(child, group);
3583
- const byId = new Map(layers.map((layer) => [layer.id, layer]));
3584
- const top = [];
3585
- slots.forEach((slot, index) => {
3586
- ctx.take(slot.style, "groupId");
3587
- ctx.take(slot.style, "childIds");
3588
- const layer = layers[index];
3589
- const parent = byId.get(parentOf.get(layer.id) ?? "");
3590
- if (parent && parent !== layer && parent.type === "group") (parent.children ??= []).push(layer);
3591
- else top.push(layer);
3592
- });
3593
- return top;
3594
- }
3595
- // ../core/src/v2/upgrade/zones.ts
3596
- /**
3597
- * @license
3598
- * Copyright (c) 2026 Xue Studios LLC
3599
- * SPDX-License-Identifier: Apache-2.0
3600
- */
3601
- var FLOW_KEYS = [
3602
- "display",
3603
- "flexDirection",
3604
- "justifyContent",
3605
- "alignItems",
3606
- "gap",
3607
- "padding"
3608
- ];
3609
- var percent$1 = (value, of) => typeof value === "number" && Number.isFinite(value) ? value / 100 * of : 0;
3610
- function zoneGroup(ctx, value, index) {
3611
- const zone = { ...asObject(value) ?? {} };
3612
- const style = { ...asObject(zone.style) ?? {} };
3613
- ctx.register(zone, `zones[${index}]`);
3614
- ctx.register(style, `zones[${index}].style`);
3615
- ctx.take(zone, "style");
3616
- const id = String(ctx.take(zone, "id") ?? `zone-${index + 1}`);
3617
- const pos = Array.isArray(zone.position) ? zone.position : [0, 0];
3618
- const size = Array.isArray(zone.size) ? zone.size : [100, 100];
3619
- ctx.take(zone, "position");
3620
- ctx.take(zone, "size");
3621
- for (const key of FLOW_KEYS) ctx.retire(style, key);
3622
- const { width: W, height: H } = ctx.canvas;
3623
- const box = {
3624
- x: percent$1(pos[0], W),
3625
- y: percent$1(pos[1], H),
3626
- width: percent$1(size[0], W),
3627
- height: percent$1(size[1], H)
3628
- };
3629
- const group = {
3630
- id,
3631
- type: "group",
3632
- box,
3633
- children: []
3634
- };
3635
- const blur = /^blur\((\d+(?:\.\d+)?)px\)$/.exec(String(ctx.take(style, "backdropFilter") ?? "").trim());
3636
- if (blur) group.effects = [{
3637
- kind: "backdrop",
3638
- blur: Number(blur[1])
3639
- }];
3640
- const background = ctx.take(style, "background");
3641
- const corners = toCanvasUnits(ctx.take(style, "borderRadius"), W);
3642
- if (isColor(background)) {
3643
- const plate = {
3644
- id: `${id}__background`,
3645
- type: "shape",
3646
- box: { ...box },
3647
- geometry: { kind: "rect" },
3648
- fills: [{
3649
- kind: "color",
3650
- value: background
3651
- }]
3652
- };
3653
- if (corners) plate.corners = corners;
3654
- group.children.push(plate);
3655
- }
3656
- return group;
3657
- }
3658
- /**
3659
- * The root `zones` as groups, at the bottom of the stack (1.x put them before
3660
- * every layer), each holding the layers whose `zone_id` names it, in their order.
3661
- */
3662
- function convertZones(ctx, meta, layers, zoneOf) {
3663
- const list = ctx.take(meta, "zones");
3664
- if (!Array.isArray(list) || list.length === 0) return layers;
3665
- const groups = list.map((value, index) => zoneGroup(ctx, value, index));
3666
- const byId = new Map(groups.map((g) => [g.id, g]));
3667
- const rest = layers.filter((layer) => {
3668
- const group = byId.get(zoneOf.get(layer) ?? "");
3669
- if (group) group.children.push(layer);
3670
- return !group;
3671
- });
3672
- return [...groups, ...rest];
3673
- }
3674
- // ../core/src/v2/upgrade/variables.ts
3675
- /**
3676
- * @license
3677
- * Copyright (c) 2026 Xue Studios LLC
3678
- * SPDX-License-Identifier: Apache-2.0
3679
- */
3680
- function convertVariables(ctx, meta, languages) {
3681
- const palettes = asObject(ctx.take(meta, "palettes")) ?? {};
3682
- const preferred = ctx.take(meta, "defaultPalette");
3683
- const names = Object.keys(palettes).filter((name) => asObject(palettes[name]));
3684
- if (names.length === 0) return void 0;
3685
- const values = {};
3686
- for (const name of names) for (const [role, color] of Object.entries(asObject(palettes[name]) ?? {})) if (typeof color === "string" && color) (values[role] ??= {})[name] = color;
3687
- const variables = {
3688
- modes: {
3689
- palette: names,
3690
- language: languages
3691
- },
3692
- values
3693
- };
3694
- if (typeof preferred === "string" && names.includes(preferred)) variables.defaults = { palette: preferred };
3695
- return variables;
3696
- }
3697
1513
  // ../core/src/v2/upgrade.ts
3698
1514
  /**
3699
1515
  * @license
3700
1516
  * Copyright (c) 2026 Xue Studios LLC
3701
1517
  * SPDX-License-Identifier: Apache-2.0
3702
1518
  */
3703
- /** One converter per block, in the order they run. */
3704
- var CONVERTERS = [
3705
- convertBox,
3706
- convertText,
3707
- convertPaints,
3708
- convertGeometry,
3709
- convertEffects,
3710
- convertAnimations,
3711
- convertMask
3712
- ];
3713
1519
  function isV2(input) {
3714
1520
  const version = asObject(input)?.oim;
3715
1521
  return typeof version === "string" && /^2\./.test(version);
3716
1522
  }
3717
- var SLOT_ALIASES = [
3718
- "p",
3719
- "st",
3720
- "c",
3721
- "t"
3722
- ];
3723
- function readSlot(ctx, value, index) {
3724
- const raw = { ...asObject(value) ?? {} };
3725
- const style = { ...asObject(raw.style) ?? {} };
3726
- ctx.register(raw, "slot");
3727
- for (const alias of SLOT_ALIASES) if (alias in raw) ctx.retire(raw, alias);
3728
- ctx.register(style, "style");
3729
- ctx.take(raw, "style");
3730
- ctx.retire(raw, "s");
3731
- for (const key of RETIRED_STYLE_KEYS) ctx.retire(style, key);
3732
- if (raw.id === void 0) raw.id = `layer-${index + 1}`;
3733
- return {
3734
- raw,
3735
- style,
3736
- type: typeof raw.type === "string" ? raw.type : "text"
3737
- };
3738
- }
3739
- function startLayer(ctx, slot) {
3740
- const { raw } = slot;
3741
- const layer = {
3742
- id: String(ctx.take(raw, "id")),
3743
- type: TYPE_OF[slot.type] ?? "shape",
3744
- box: {
3745
- x: 0,
3746
- y: 0,
3747
- width: 0,
3748
- height: 0
3749
- }
3750
- };
3751
- ctx.take(raw, "type");
3752
- if (!(slot.type in TYPE_OF)) ctx.note(`slot.type: unknown layer type "${slot.type}"`);
3753
- const name = ctx.take(raw, "name");
3754
- if (typeof name === "string" && name) layer.name = name;
3755
- const languages = ctx.take(raw, "languages");
3756
- if (Array.isArray(languages) && !languages.includes("*")) {
3757
- const own = languages.filter((l) => typeof l === "string" && l.length > 0);
3758
- if (own.length > 0) layer.languages = [...new Set(own)];
3759
- else layer.visible = false;
3760
- }
3761
- const pending = ctx.take(raw, "pendingTranslation");
3762
- if (Array.isArray(pending) && pending.length > 0) layer.extensions = {
3763
- ...layer.extensions,
3764
- studio: { pendingTranslation: pending }
3765
- };
3766
- return layer;
3767
- }
3768
- /** What a layer type cannot exist without, when no converter supplied it. */
3769
- function completeLayer(layer) {
3770
- if (layer.type === "shape") layer.geometry ??= { kind: "rect" };
3771
- if (layer.type === "text") layer.text ??= { content: {} };
3772
- if (layer.type === "image") layer.image ??= { src: "oim:base" };
3773
- if (layer.type === "group") layer.children ??= [];
3774
- layer.children?.forEach(completeLayer);
3775
- }
3776
- function upgrade$1(input) {
3777
- if (isV2(input)) return {
3778
- document: input,
3779
- retired: [],
3780
- unhandled: []
3781
- };
3782
- const meta = normalizeLegacyKeys(asObject(input) ?? {});
3783
- const ctx = createContext(canvasOf(meta), languagesOf(meta)[0], rolesOf(meta));
3784
- ctx.register(meta, "root");
3785
- const { document, slots: rawSlots } = convertRoot(ctx, meta);
3786
- const slots = rawSlots.map((value, index) => readSlot(ctx, value, index));
3787
- const layers = slots.map((slot) => {
3788
- const layer = startLayer(ctx, slot);
3789
- for (const convert of CONVERTERS) convert(ctx, slot, layer);
3790
- return layer;
3791
- });
3792
- const zoneOf = /* @__PURE__ */ new Map();
3793
- slots.forEach((slot, i) => {
3794
- const zone = ctx.take(slot.raw, "zone_id");
3795
- if (typeof zone === "string" && zone) zoneOf.set(layers[i], zone);
3796
- });
3797
- document.layers = convertZones(ctx, meta, buildTree(ctx, slots, layers), zoneOf);
3798
- const backgroundIds = new Set(slots.filter((slot) => slot.raw.is_background_pattern === true || slot.raw.id === "background-pattern-slot").map((slot) => String(slot.raw.id)));
3799
- if (backgroundIds.size) {
3800
- const rank = (layer) => layer.id === "oim-base" ? 0 : backgroundIds.has(layer.id) ? 1 : 2;
3801
- document.layers = [...document.layers].sort((a, b) => rank(a) - rank(b));
3802
- }
3803
- const variables = convertVariables(ctx, meta, document.languages);
3804
- if (variables) document.variables = variables;
3805
- const background = canvasFills(ctx, meta);
3806
- if (background.length > 0) document.canvas = {
3807
- ...document.canvas,
3808
- fills: background
3809
- };
3810
- const overall = canvasEffects(ctx, meta);
3811
- if (overall.length > 0) document.layers.push({
3812
- id: "__canvas-effects",
3813
- type: "shape",
3814
- box: {
3815
- x: 0,
3816
- y: 0,
3817
- width: ctx.canvas.width,
3818
- height: ctx.canvas.height
3819
- },
3820
- geometry: { kind: "rect" },
3821
- effects: overall
3822
- });
3823
- document.layers.forEach(completeLayer);
3824
- document.layers.unshift({
3825
- id: "oim-base",
3826
- type: "image",
3827
- box: {
3828
- x: 0,
3829
- y: 0,
3830
- width: ctx.canvas.width,
3831
- height: ctx.canvas.height
3832
- },
3833
- image: { src: "oim:base" }
3834
- });
3835
- return {
3836
- document,
3837
- ...ctx.finish()
3838
- };
3839
- }
3840
1523
  // ../core/src/v2/base-layer.ts
3841
1524
  /**
3842
1525
  * @license
@@ -4795,7 +2478,7 @@ function nextWheelZoom(zoom, deltaY, deltaMode, pinch) {
4795
2478
  * the format can change without the player being touched. Tying both numbers
4796
2479
  * together would make an internal fix look like a format break.
4797
2480
  */
4798
- var CONTRACT_VERSION = "1.34.5";
2481
+ var CONTRACT_VERSION = "1.35.0";
4799
2482
  /**
4800
2483
  * What the player implements TODAY, measured and not assumed.
4801
2484
  *
@@ -10223,17 +7906,6 @@ function sceneColors(variables, palette, prefersDark) {
10223
7906
  active
10224
7907
  };
10225
7908
  }
10226
- // ../scene/src/runtime/upgrade-entry.ts
10227
- /**
10228
- * @license
10229
- * Copyright (c) 2026 Xue Studios LLC
10230
- * SPDX-License-Identifier: Apache-2.0
10231
- */
10232
- var upgrade = upgrade$1;
10233
- /** Resolves when `upgrade` can be called. Here it already can. */
10234
- function ensureUpgrade() {
10235
- return Promise.resolve();
10236
- }
10237
7909
  // ../scene/src/runtime/features-entry.ts
10238
7910
  /**
10239
7911
  * @license
@@ -10536,7 +8208,6 @@ var EngineShell = class {
10536
8208
  */
10537
8209
  /** The 2.0 document the scene paints: a 2.0 file with its references resolved, a 1.x file upgraded. */
10538
8210
  function sceneDocument(metadata) {
10539
- if (!isV2(metadata)) return upgrade(structuredClone(metadata)).document;
10540
8211
  const resolved = resolveRefs(structuredClone(metadata));
10541
8212
  resolved.missing.forEach((id) => console.warn(`[OimPlayer] resource "${id}" is not in the document`));
10542
8213
  return resolved.document;
@@ -10576,10 +8247,13 @@ var ImageEngine = class extends EngineShell {
10576
8247
  } }));
10577
8248
  };
10578
8249
  if (paints) {
10579
- if (!isV2(file)) await ensureUpgrade().catch((err) => {
8250
+ if (!isV2(file)) {
10580
8251
  paints = false;
10581
- report(err);
10582
- });
8252
+ this.host.dispatchEvent(new CustomEvent("oim:error", { detail: {
8253
+ code: "unsupported-version",
8254
+ message: "OIM 1.x files are no longer painted; upgrade the file with the CLI or re-export it."
8255
+ } }));
8256
+ }
10583
8257
  if (ticket !== this._renderTicket) return;
10584
8258
  }
10585
8259
  if (paints) {
@@ -11170,6 +8844,11 @@ var ImageEngine = class extends EngineShell {
11170
8844
  * Copyright (c) 2026 Xue Studios LLC
11171
8845
  * SPDX-License-Identifier: Apache-2.0
11172
8846
  */
8847
+ /** The 2.0 document's languages (`languages`), lowercased and sorted; [] before a file loads. */
8848
+ function documentLanguages(engine) {
8849
+ const langs = (engine ? engine.fileMetadata ?? engine.metadata : null)?.languages;
8850
+ return Array.isArray(langs) ? [...new Set(langs.map((l) => String(l).toLowerCase()))].sort() : [];
8851
+ }
11173
8852
  function detectMediaType(src, firstBytes) {
11174
8853
  let ext = "";
11175
8854
  if (typeof src === "string") {
@@ -11364,17 +9043,7 @@ OimPlayerElement._startAutoRotateLang = function() {
11364
9043
  if (isNaN(intervalMs) || intervalMs <= 0) intervalMs = 3e3;
11365
9044
  const self = this;
11366
9045
  this._autoRotateIntervalId = setInterval(() => {
11367
- const metadata = self._engine ? self._engine.metadata : null;
11368
- if (!metadata) return;
11369
- const slots = metadata.slots || metadata.elements || [];
11370
- const allLangs = {};
11371
- for (let i = 0; i < slots.length; i++) {
11372
- const content = slots[i].content || {};
11373
- Object.keys(content).forEach((lang) => {
11374
- allLangs[lang.toLowerCase()] = true;
11375
- });
11376
- }
11377
- const langs = Object.keys(allLangs).sort();
9046
+ const langs = documentLanguages(self._engine);
11378
9047
  if (langs.length <= 1) return;
11379
9048
  const currentLang = (self.getAttribute("lang") || self._engine && self._engine.lang || "en").toLowerCase();
11380
9049
  const nextLang = langs[(langs.indexOf(currentLang) + 1) % langs.length];
@@ -11649,16 +9318,7 @@ if (typeof customElements !== "undefined" && !customElements.get("oim-player"))
11649
9318
  }
11650
9319
  });
11651
9320
  Object.defineProperty(OimPlayerClass.prototype, "languages", { get: function() {
11652
- if (!this._engine || !this._engine.metadata) return [];
11653
- const slots = this._engine.metadata.slots || this._engine.metadata.elements || [];
11654
- const allLangs = {};
11655
- for (let i = 0; i < slots.length; i++) {
11656
- const content = slots[i].content || {};
11657
- Object.keys(content).forEach((lang) => {
11658
- allLangs[lang.toLowerCase()] = true;
11659
- });
11660
- }
11661
- return Object.keys(allLangs).sort();
9321
+ return documentLanguages(this._engine);
11662
9322
  } });
11663
9323
  Object.defineProperty(OimPlayerClass.prototype, "currentLang", { get: function() {
11664
9324
  return this._engine ? this._engine.lang : this.getAttribute("lang") || "en";