@open-slot-ui/core 0.8.3 → 0.9.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/index.cjs CHANGED
@@ -437,12 +437,136 @@ function valueFitMaxWidth(digits, columnWidth) {
437
437
  return clampDigits(digits) * columnWidth + 64;
438
438
  }
439
439
 
440
+ // src/format/currency.ts
441
+ var CURRENCY_TABLE = Object.freeze({
442
+ // ── fiat — symbol BEFORE the amount ──────────────────────────────────────────
443
+ USD: { symbol: "$", decimals: 2 },
444
+ CAD: { symbol: "CA$", decimals: 2 },
445
+ JPY: { symbol: "\xA5", decimals: 0 },
446
+ EUR: { symbol: "\u20AC", decimals: 2 },
447
+ RUB: { symbol: "\u20BD", decimals: 2 },
448
+ CNY: { symbol: "CN\xA5", decimals: 2 },
449
+ PHP: { symbol: "\u20B1", decimals: 2 },
450
+ INR: { symbol: "\u20B9", decimals: 2 },
451
+ IDR: { symbol: "Rp", decimals: 0 },
452
+ KRW: { symbol: "\u20A9", decimals: 0 },
453
+ BRL: { symbol: "R$", decimals: 2 },
454
+ MXN: { symbol: "MX$", decimals: 2 },
455
+ TRY: { symbol: "\u20BA", decimals: 2 },
456
+ GBP: { symbol: "\xA3", decimals: 2 },
457
+ NGN: { symbol: "\u20A6", decimals: 2 },
458
+ TWD: { symbol: "NT$", decimals: 2 },
459
+ SGD: { symbol: "SG$", decimals: 2 },
460
+ MYR: { symbol: "RM", decimals: 2 },
461
+ CRC: { symbol: "\u20A1", decimals: 2 },
462
+ // three-decimal dinars/rials (1 unit = 1000 fils) — the >2-decimal path must format these
463
+ KWD: { symbol: "KD", decimals: 3 },
464
+ JOD: { symbol: "JD", decimals: 3 },
465
+ BHD: { symbol: "BD", decimals: 3 },
466
+ OMR: { symbol: "OMR", decimals: 3 },
467
+ TND: { symbol: "DT", decimals: 3 },
468
+ LYD: { symbol: "LD", decimals: 3 },
469
+ IQD: { symbol: "IQD", decimals: 3 },
470
+ // ── fiat — symbol AFTER the amount ───────────────────────────────────────────
471
+ DKK: { symbol: "kr", decimals: 2, symbolAfter: true },
472
+ NOK: { symbol: "kr", decimals: 2, symbolAfter: true },
473
+ PLN: { symbol: "z\u0142", decimals: 2, symbolAfter: true },
474
+ VND: { symbol: "\u20AB", decimals: 0, symbolAfter: true },
475
+ CLP: { symbol: "CLP", decimals: 0, symbolAfter: true },
476
+ ARS: { symbol: "ARS", decimals: 2, symbolAfter: true },
477
+ PEN: { symbol: "S/", decimals: 2, symbolAfter: true },
478
+ // ── crypto (8-dp, so sub-cent + high precision format correctly) ─────────────
479
+ BTC: { symbol: "\u20BF", decimals: 8 },
480
+ ETH: { symbol: "\u039E", decimals: 8 },
481
+ LTC: { symbol: "\u0141", decimals: 8 },
482
+ BCH: { symbol: "BCH", decimals: 8 },
483
+ DOGE: { symbol: "\xD0", decimals: 8 },
484
+ USDT: { symbol: "\u20AE", decimals: 2 },
485
+ USDC: { symbol: "USDC", decimals: 2 },
486
+ // ── Stake social coins — Gold Coins / Stake Cash (shown as GC / SC) ───────────
487
+ XGC: { symbol: "GC", decimals: 2, social: true },
488
+ XSC: { symbol: "SC", decimals: 2, social: true },
489
+ GC: { symbol: "GC", decimals: 2, social: true },
490
+ SC: { symbol: "SC", decimals: 2, social: true }
491
+ });
492
+ var upper = (code) => typeof code === "string" ? code.toUpperCase() : "";
493
+ function isSocialCurrency(code) {
494
+ return CURRENCY_TABLE[upper(code)]?.social === true;
495
+ }
496
+ function resolveCurrency(code, overrides = {}) {
497
+ const info = CURRENCY_TABLE[upper(code)];
498
+ if (!info) {
499
+ return {
500
+ code: overrides.code ?? code,
501
+ decimals: clampDecimals(overrides.decimals ?? 2),
502
+ position: overrides.position ?? "suffix",
503
+ separator: overrides.separator ?? ",",
504
+ decimalChar: overrides.decimalChar ?? ".",
505
+ ...overrides.symbol ? { symbol: overrides.symbol, display: overrides.display ?? "symbol" } : {}
506
+ };
507
+ }
508
+ return {
509
+ // Social coins carry their DISPLAY code (XGC → "GC", XSC → "SC"); fiat/crypto keep
510
+ // their ISO code (the symbol is what's actually rendered under `display:'symbol'`).
511
+ code: overrides.code ?? (info.social ? info.symbol : code),
512
+ symbol: overrides.symbol ?? info.symbol,
513
+ display: overrides.display ?? "symbol",
514
+ position: overrides.position ?? (info.symbolAfter ? "suffix" : "prefix"),
515
+ decimals: clampDecimals(overrides.decimals ?? info.decimals),
516
+ separator: overrides.separator ?? ",",
517
+ decimalChar: overrides.decimalChar ?? "."
518
+ };
519
+ }
520
+ function neededDecimals(value, base) {
521
+ const b = clampDecimals(base);
522
+ if (!Number.isFinite(value) || value === 0) return b;
523
+ let scaled = Math.round(Math.abs(value) * 1e8);
524
+ let d = 8;
525
+ while (d > b && scaled % 10 === 0) {
526
+ scaled /= 10;
527
+ d--;
528
+ }
529
+ return d;
530
+ }
531
+ function formatAmountPrecise(value, spec, opts = {}) {
532
+ const base = clampDecimals(spec.decimals ?? 2);
533
+ const d = neededDecimals(value, base);
534
+ return d === base ? formatAmount(value, spec, opts) : formatAmount(value, { ...spec, decimals: d }, opts);
535
+ }
536
+ function formatAmount(value, spec, opts = {}) {
537
+ const decimals = clampDecimals(spec.decimals);
538
+ const sep = spec.separator ?? ",";
539
+ const dot = spec.decimalChar ?? ".";
540
+ const n = Number.isFinite(value) ? value : 0;
541
+ const fixed = Math.abs(n).toFixed(decimals);
542
+ const [int = "0", frac] = fixed.split(".");
543
+ const grouped = int.replace(/\B(?=(\d{3})+(?!\d))/g, sep);
544
+ const body = frac ? `${grouped}${dot}${frac}` : grouped;
545
+ const sign = n < 0 ? "-" : opts.signed ? "+" : "";
546
+ const number = `${sign}${body}`;
547
+ const symbolMode = spec.display === "symbol" && !!spec.symbol;
548
+ const affix = symbolMode ? spec.symbol : spec.code;
549
+ const prefix = (spec.position ?? "suffix") === "prefix";
550
+ const gap = symbolMode && prefix ? "" : " ";
551
+ return prefix ? `${affix}${gap}${number}` : `${number}${gap}${affix}`;
552
+ }
553
+
440
554
  // src/controls/ValueDisplay.ts
441
555
  var ValueDisplay = class extends Control {
442
556
  states = { idle: { interactable: false } };
443
557
  value = new Signal(0);
444
558
  currency;
445
559
  label;
560
+ /**
561
+ * Show a value at the precision it ACTUALLY carries (default on): when the value has
562
+ * more fraction digits than the currency's native precision — a sub-unit win like a
563
+ * USD 0.01 bet × a ×0.2 face = 0.002, or the 999.982 balance it leaves behind — the
564
+ * display decimals bump just enough to reveal them ($0.002), and drop back to the
565
+ * native look (5.00) once the value is clean again. Set `false` for hard-fixed decimals.
566
+ */
567
+ autoPrecision = true;
568
+ /** The currency's NATIVE precision — what `autoPrecision` returns to on clean values. */
569
+ baseDecimals;
446
570
  /** Minimum odometer column width (0 = auto: sized tightly to the value, grows as it
447
571
  * does). Read by the renderer at build time, so set it before mount (or declaratively
448
572
  * via `controls.{id}.digits`). */
@@ -453,9 +577,11 @@ var ValueDisplay = class extends Control {
453
577
  this.currency = new Signal(
454
578
  c && typeof c.code === "string" ? { ...c, decimals: clampDecimals(c.decimals) } : { code: "USD", decimals: 2 }
455
579
  );
580
+ this.baseDecimals = this.currency.get().decimals;
456
581
  this.label = opts.label;
457
582
  this.digits = clampMinDigits(opts.digits ?? 0);
458
583
  if (opts.initial != null) this.value.set(opts.initial);
584
+ this.applyPrecision();
459
585
  }
460
586
  /** Set the minimum odometer column width (clamped 0..18; 0 = auto). Read by the
461
587
  * renderer at build time, so set it before mount (or via `controls.{id}.digits`). */
@@ -466,14 +592,27 @@ var ValueDisplay = class extends Control {
466
592
  * good value — malformed host data never throws into the render loop (P11). */
467
593
  set(amount) {
468
594
  this.value.set(safeAmount(amount, this.value.get()));
595
+ this.applyPrecision();
469
596
  }
470
597
  get() {
471
598
  return this.value.get();
472
599
  }
473
- /** Keep the prior spec on malformed input; clamp decimals to 0..8 (P11). */
600
+ /** Keep the prior spec on malformed input; clamp decimals to 0..8 (P11). The given
601
+ * decimals become the NATIVE precision (`autoPrecision` bumps above it as needed). */
474
602
  setCurrency(spec) {
475
603
  if (!spec || typeof spec.code !== "string") return;
476
- this.currency.set({ ...spec, decimals: clampDecimals(spec.decimals) });
604
+ this.baseDecimals = clampDecimals(spec.decimals);
605
+ this.currency.set({ ...spec, decimals: this.baseDecimals });
606
+ this.applyPrecision();
607
+ }
608
+ /** Bump the display decimals to what the current value needs — never below the
609
+ * currency's native precision — and drop back once the value is clean again.
610
+ * No-op (and no signal churn) when the shown precision is already right. */
611
+ applyPrecision() {
612
+ if (!this.autoPrecision) return;
613
+ const want = neededDecimals(this.value.get(), this.baseDecimals);
614
+ const cur = this.currency.get();
615
+ if (cur.decimals !== want) this.currency.set({ ...cur, decimals: want });
477
616
  }
478
617
  /** Accent emphasis: the renderer tints the value in the theme accent while on.
479
618
  * For "this number is modified" moments — e.g. a bet display showing the
@@ -1132,6 +1271,7 @@ var BLOCK_KINDS = [
1132
1271
  "subheading",
1133
1272
  "callout",
1134
1273
  "stat-grid",
1274
+ "mode-stats",
1135
1275
  "steps",
1136
1276
  "table",
1137
1277
  "paytable",
@@ -1284,6 +1424,9 @@ function validateSpec(spec) {
1284
1424
  if (b.kind === "stat-grid" && (!b.items || b.items.length === 0)) {
1285
1425
  add("warn", `${p}.items`, "empty-grid", "a stat-grid block has no items");
1286
1426
  }
1427
+ if (b.kind === "mode-stats" && !spec.facts?.modes?.length) {
1428
+ add("warn", `${p}`, "mode-stats-no-facts", "a mode-stats block renders from spec.facts.modes, but no modes are declared");
1429
+ }
1287
1430
  if (b.kind === "steps" && (!b.items || b.items.length === 0)) {
1288
1431
  add("warn", `${p}.items`, "empty-steps", "a steps block has no items");
1289
1432
  }
@@ -1479,6 +1622,10 @@ var openuiDefaults = {
1479
1622
  // reality check (RTS 13) — {{minutes}} is interpolated by open-ui's scheduler
1480
1623
  "openui.realityCheck.title": "Reality check",
1481
1624
  "openui.realityCheck.message": "You've been playing for {{minutes}} minutes. Take a moment before continuing.",
1625
+ // Rules-completeness audit (the info menu's "forgotten declarations" card)
1626
+ "openui.rulesAudit.title": "Rules incomplete",
1627
+ "openui.rulesAudit.required": "Missing required information:",
1628
+ "openui.rulesAudit.recommended": "Highly recommended:",
1482
1629
  // RGS error defaults (override via your messages dict or per-call)
1483
1630
  "openui.err.generic.title": "Something went wrong",
1484
1631
  "openui.err.generic.message": "Sorry, something went wrong. Please try again.",
@@ -1517,11 +1664,13 @@ var openuiSocialDefaults = {
1517
1664
  "openui.replay.costMultiplier": "Feature Multiplier",
1518
1665
  "openui.replay.payoutMultiplier": "Final Multiplier",
1519
1666
  "openui.err.insufficient.message": "You don't have enough balance for this play.",
1520
- "openui.err.limit.message": "A play limit has been reached. Please try again later."
1667
+ "openui.err.limit.message": "A play limit has been reached. Please try again later.",
1668
+ // The auto mode-stats grid's label words (used as their own keys at render time).
1669
+ "Max win": "Max prize"
1521
1670
  };
1522
1671
  function interpolate(template, vars) {
1523
1672
  if (!vars) return template;
1524
- return template.replace(/\{\{(\w+)\}\}/g, (_m, k) => String(vars[k] ?? `{{${k}}}`));
1673
+ return template.replace(/\{\{([\w.-]+)\}\}/g, (_m, k) => String(vars[k] ?? `{{${k}}}`));
1525
1674
  }
1526
1675
  var DictionaryTranslator = class {
1527
1676
  constructor(messages, locale, socialMessages = {}) {
@@ -1561,98 +1710,207 @@ function dictionary(messages, locale, socialMessages) {
1561
1710
  return new DictionaryTranslator(messages, locale, socialMessages);
1562
1711
  }
1563
1712
 
1564
- // src/format/currency.ts
1565
- var CURRENCY_TABLE = Object.freeze({
1566
- // ── fiat symbol BEFORE the amount ──────────────────────────────────────────
1567
- USD: { symbol: "$", decimals: 2 },
1568
- CAD: { symbol: "CA$", decimals: 2 },
1569
- JPY: { symbol: "\xA5", decimals: 0 },
1570
- EUR: { symbol: "\u20AC", decimals: 2 },
1571
- RUB: { symbol: "\u20BD", decimals: 2 },
1572
- CNY: { symbol: "CN\xA5", decimals: 2 },
1573
- PHP: { symbol: "\u20B1", decimals: 2 },
1574
- INR: { symbol: "\u20B9", decimals: 2 },
1575
- IDR: { symbol: "Rp", decimals: 0 },
1576
- KRW: { symbol: "\u20A9", decimals: 0 },
1577
- BRL: { symbol: "R$", decimals: 2 },
1578
- MXN: { symbol: "MX$", decimals: 2 },
1579
- TRY: { symbol: "\u20BA", decimals: 2 },
1580
- GBP: { symbol: "\xA3", decimals: 2 },
1581
- NGN: { symbol: "\u20A6", decimals: 2 },
1582
- TWD: { symbol: "NT$", decimals: 2 },
1583
- SGD: { symbol: "SG$", decimals: 2 },
1584
- MYR: { symbol: "RM", decimals: 2 },
1585
- CRC: { symbol: "\u20A1", decimals: 2 },
1586
- // three-decimal dinars (1 unit = 1000 fils) — the >2-decimal path must format these
1587
- KWD: { symbol: "KD", decimals: 3 },
1588
- JOD: { symbol: "JD", decimals: 3 },
1589
- BHD: { symbol: "BD", decimals: 3 },
1590
- // ── fiat — symbol AFTER the amount ───────────────────────────────────────────
1591
- DKK: { symbol: "kr", decimals: 2, symbolAfter: true },
1592
- NOK: { symbol: "kr", decimals: 2, symbolAfter: true },
1593
- PLN: { symbol: "z\u0142", decimals: 2, symbolAfter: true },
1594
- VND: { symbol: "\u20AB", decimals: 0, symbolAfter: true },
1595
- CLP: { symbol: "CLP", decimals: 0, symbolAfter: true },
1596
- ARS: { symbol: "ARS", decimals: 2, symbolAfter: true },
1597
- PEN: { symbol: "S/", decimals: 2, symbolAfter: true },
1598
- // ── crypto (8-dp, so sub-cent + high precision format correctly) ─────────────
1599
- BTC: { symbol: "\u20BF", decimals: 8 },
1600
- ETH: { symbol: "\u039E", decimals: 8 },
1601
- LTC: { symbol: "\u0141", decimals: 8 },
1602
- BCH: { symbol: "BCH", decimals: 8 },
1603
- DOGE: { symbol: "\xD0", decimals: 8 },
1604
- USDT: { symbol: "\u20AE", decimals: 2 },
1605
- USDC: { symbol: "USDC", decimals: 2 },
1606
- // ── Stake social coins — Gold Coins / Stake Cash (shown as GC / SC) ───────────
1607
- XGC: { symbol: "GC", decimals: 2, social: true },
1608
- XSC: { symbol: "SC", decimals: 2, social: true },
1609
- GC: { symbol: "GC", decimals: 2, social: true },
1610
- SC: { symbol: "SC", decimals: 2, social: true }
1611
- });
1612
- var upper = (code) => typeof code === "string" ? code.toUpperCase() : "";
1613
- function isSocialCurrency(code) {
1614
- return CURRENCY_TABLE[upper(code)]?.social === true;
1615
- }
1616
- function resolveCurrency(code, overrides = {}) {
1617
- const info = CURRENCY_TABLE[upper(code)];
1618
- if (!info) {
1619
- return {
1620
- code: overrides.code ?? code,
1621
- decimals: clampDecimals(overrides.decimals ?? 2),
1622
- position: overrides.position ?? "suffix",
1623
- separator: overrides.separator ?? ",",
1624
- decimalChar: overrides.decimalChar ?? ".",
1625
- ...overrides.symbol ? { symbol: overrides.symbol, display: overrides.display ?? "symbol" } : {}
1626
- };
1713
+ // src/spec/facts.ts
1714
+ function mergeFacts(base, add) {
1715
+ const modes = [...base.modes ?? []];
1716
+ for (const m of add.modes ?? []) {
1717
+ const i = modes.findIndex((x) => x.id === m.id);
1718
+ if (i < 0) modes.push({ ...m });
1719
+ else {
1720
+ const merged = { ...modes[i] };
1721
+ for (const [k, v] of Object.entries(m)) if (v !== void 0) merged[k] = v;
1722
+ modes[i] = merged;
1723
+ }
1627
1724
  }
1628
1725
  return {
1629
- // Social coins carry their DISPLAY code (XGC → "GC", XSC → "SC"); fiat/crypto keep
1630
- // their ISO code (the symbol is what's actually rendered under `display:'symbol'`).
1631
- code: overrides.code ?? (info.social ? info.symbol : code),
1632
- symbol: overrides.symbol ?? info.symbol,
1633
- display: overrides.display ?? "symbol",
1634
- position: overrides.position ?? (info.symbolAfter ? "suffix" : "prefix"),
1635
- decimals: clampDecimals(overrides.decimals ?? info.decimals),
1636
- separator: overrides.separator ?? ",",
1637
- decimalChar: overrides.decimalChar ?? "."
1726
+ ...modes.length ? { modes } : {},
1727
+ freeSpins: add.freeSpins !== void 0 ? add.freeSpins : base.freeSpins,
1728
+ volatility: add.volatility ?? base.volatility,
1729
+ maxWinCapX: add.maxWinCapX ?? base.maxWinCapX
1638
1730
  };
1639
1731
  }
1640
- function formatAmount(value, spec, opts = {}) {
1641
- const decimals = clampDecimals(spec.decimals);
1642
- const sep = spec.separator ?? ",";
1643
- const dot = spec.decimalChar ?? ".";
1644
- const n = Number.isFinite(value) ? value : 0;
1645
- const fixed = Math.abs(n).toFixed(decimals);
1646
- const [int = "0", frac] = fixed.split(".");
1647
- const grouped = int.replace(/\B(?=(\d{3})+(?!\d))/g, sep);
1648
- const body = frac ? `${grouped}${dot}${frac}` : grouped;
1649
- const sign = n < 0 ? "-" : opts.signed ? "+" : "";
1650
- const number = `${sign}${body}`;
1651
- const symbolMode = spec.display === "symbol" && !!spec.symbol;
1652
- const affix = symbolMode ? spec.symbol : spec.code;
1653
- const prefix = (spec.position ?? "suffix") === "prefix";
1654
- const gap = symbolMode && prefix ? "" : " ";
1655
- return prefix ? `${affix}${gap}${number}` : `${number}${gap}${affix}`;
1732
+ function formatRtp(rtp) {
1733
+ return `${rtp.toFixed(2)}%`;
1734
+ }
1735
+ function formatTimes(x) {
1736
+ return `${x.toLocaleString("en-US", { maximumFractionDigits: 2 })}\xD7`;
1737
+ }
1738
+ function modeStatsItems(facts, tr = (s) => s) {
1739
+ const out = [];
1740
+ for (const m of facts?.modes ?? []) {
1741
+ if (m.rtp != null) out.push({ label: `${tr("RTP")} \xB7 ${tr(m.name)}`, value: formatRtp(m.rtp) });
1742
+ if (m.maxWinX != null) out.push({ label: `${tr("Max win")} \xB7 ${tr(m.name)}`, value: formatTimes(m.maxWinX) });
1743
+ }
1744
+ if (facts?.volatility) out.push({ label: tr("Volatility"), value: tr(facts.volatility) });
1745
+ if (facts?.maxWinCapX != null) out.push({ label: tr("Round cap"), value: formatTimes(facts.maxWinCapX) });
1746
+ return out;
1747
+ }
1748
+ function factsVars(facts, extra) {
1749
+ const vars = {};
1750
+ for (const m of facts?.modes ?? []) {
1751
+ if (!m.id) continue;
1752
+ vars[`name.${m.id}`] = m.name;
1753
+ if (m.rtp != null) vars[`rtp.${m.id}`] = formatRtp(m.rtp);
1754
+ if (m.maxWinX != null) vars[`maxWin.${m.id}`] = formatTimes(m.maxWinX);
1755
+ if (m.cost != null) vars[`cost.${m.id}`] = formatTimes(m.cost);
1756
+ }
1757
+ const fs = facts?.freeSpins;
1758
+ if (fs) {
1759
+ if (fs.count != null) vars["freeSpins.count"] = fs.count;
1760
+ if (fs.retrigger != null) vars["freeSpins.retrigger"] = fs.retrigger ? "can" : "cannot";
1761
+ }
1762
+ if (facts?.volatility) vars["volatility"] = facts.volatility;
1763
+ if (facts?.maxWinCapX != null) vars["maxWinCap"] = formatTimes(facts.maxWinCapX);
1764
+ return extra ? { ...vars, ...extra } : vars;
1765
+ }
1766
+ function scanBlocks(blocks, resolve = (s) => s) {
1767
+ const scan = { text: "", headings: "", covers: /* @__PURE__ */ new Set(), hasModeStats: false, hasLegal: false };
1768
+ const addText = (t) => {
1769
+ if (typeof t === "string" && t) scan.text += `
1770
+ ${resolve(t)}`;
1771
+ };
1772
+ const walk = (list) => {
1773
+ for (const b of list ?? []) {
1774
+ for (const c of b.covers ?? []) scan.covers.add(c);
1775
+ const anyB = b;
1776
+ switch (b.kind) {
1777
+ case "mode-stats":
1778
+ scan.hasModeStats = true;
1779
+ (b.extras ?? []).forEach((it) => {
1780
+ addText(it.label);
1781
+ addText(it.value);
1782
+ });
1783
+ break;
1784
+ case "legal":
1785
+ scan.hasLegal = true;
1786
+ addText(b.text);
1787
+ break;
1788
+ case "heading":
1789
+ case "subheading":
1790
+ scan.headings += `
1791
+ ${resolve(b.text)}`;
1792
+ addText(b.text);
1793
+ break;
1794
+ case "text":
1795
+ addText(b.text);
1796
+ break;
1797
+ case "callout":
1798
+ addText(b.title);
1799
+ addText(b.text);
1800
+ break;
1801
+ case "media":
1802
+ addText(b.title);
1803
+ addText(b.text);
1804
+ break;
1805
+ case "steps":
1806
+ b.items.forEach(addText);
1807
+ break;
1808
+ case "table":
1809
+ (b.columns ?? []).forEach(addText);
1810
+ b.rows.forEach((r) => r.forEach(addText));
1811
+ break;
1812
+ case "paytable":
1813
+ b.rows.forEach((r) => {
1814
+ addText(r.symbol);
1815
+ addText(r.payouts);
1816
+ });
1817
+ break;
1818
+ case "cards":
1819
+ b.items.forEach((it) => {
1820
+ addText(it.title);
1821
+ addText(it.text);
1822
+ });
1823
+ break;
1824
+ case "stat-grid":
1825
+ b.items.forEach((it) => {
1826
+ addText(it.label);
1827
+ addText(it.value);
1828
+ });
1829
+ break;
1830
+ case "group":
1831
+ addText(b.title);
1832
+ walk(b.children);
1833
+ break;
1834
+ default:
1835
+ addText(anyB.label);
1836
+ addText(anyB.hint);
1837
+ break;
1838
+ }
1839
+ }
1840
+ };
1841
+ walk(blocks);
1842
+ return scan;
1843
+ }
1844
+ var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1845
+ function mentionsRtp(text, rtp) {
1846
+ const s = String(rtp);
1847
+ const [int = "", frac = ""] = s.split(".");
1848
+ const body = frac ? `${escapeRe(int)}[.,]${escapeRe(frac)}0*` : `${escapeRe(int)}(?:[.,]0{1,2})?`;
1849
+ return new RegExp(`\\b${body}\\s*%`).test(text);
1850
+ }
1851
+ function mentionsTimes(text, x) {
1852
+ const digits = String(Math.trunc(Math.abs(x)));
1853
+ let grouped = "";
1854
+ for (let i = 0; i < digits.length; i++) {
1855
+ if (i > 0 && (digits.length - i) % 3 === 0) grouped += "[,.\\s\\u00a0]?";
1856
+ grouped += digits[i];
1857
+ }
1858
+ const frac = Math.abs(x) % 1 !== 0 ? `[.,]\\d+` : `(?:[.,]\\d+)?`;
1859
+ return new RegExp(`\\b${grouped}${frac}\\s*[x\xD7]`, "i").test(text);
1860
+ }
1861
+ var mentionsName = (text, name) => text.toLowerCase().includes(name.toLowerCase());
1862
+ function auditRules(facts, rules, opts = {}) {
1863
+ const out = [];
1864
+ try {
1865
+ const scan = scanBlocks(rules, opts.resolve);
1866
+ const add = (level, code, topic, message) => {
1867
+ out.push({ level, code, topic, message });
1868
+ };
1869
+ const covered = (topic) => scan.covers.has(topic);
1870
+ for (const m of facts?.modes ?? []) {
1871
+ const nameIn = mentionsName(scan.text, m.name);
1872
+ if (m.rtp == null) {
1873
+ add("required", "facts-missing-rtp", `rtp:${m.id}`, `\u201C${m.name}\u201D declares no RTP \u2014 set facts.modes[].rtp so the rules can state it.`);
1874
+ } else if (!(scan.hasModeStats || covered(`rtp:${m.id}`) || nameIn && mentionsRtp(scan.text, m.rtp))) {
1875
+ add("required", "rules-missing-rtp", `rtp:${m.id}`, `The RTP of \u201C${m.name}\u201D (${formatRtp(m.rtp)}) is not stated in the rules.`);
1876
+ }
1877
+ if (m.maxWinX == null) {
1878
+ add("required", "facts-missing-maxwin", `maxwin:${m.id}`, `\u201C${m.name}\u201D declares no max win \u2014 set facts.modes[].maxWinX so the rules can state it.`);
1879
+ } else if (!(scan.hasModeStats || covered(`maxwin:${m.id}`) || nameIn && mentionsTimes(scan.text, m.maxWinX))) {
1880
+ add("required", "rules-missing-maxwin", `maxwin:${m.id}`, `The max win of \u201C${m.name}\u201D (${formatTimes(m.maxWinX)}) is not stated in the rules.`);
1881
+ }
1882
+ if (m.kind && m.kind !== "base" && !(covered(`feature:${m.id}`) || nameIn)) {
1883
+ add("required", "rules-missing-feature", `feature:${m.id}`, `The configured feature \u201C${m.name}\u201D is not described in the rules.`);
1884
+ }
1885
+ }
1886
+ const fs = facts?.freeSpins;
1887
+ if (fs === void 0) {
1888
+ if (facts?.modes?.length) {
1889
+ add("recommended", "facts-missing-freespins", "freespins", "Free-spins info is highly recommended: declare facts.freeSpins { count, retrigger } \u2014 or freeSpins: false if the game has none.");
1890
+ }
1891
+ } else if (fs !== false) {
1892
+ const fsIn = covered("freespins") || /free\s*spins?/i.test(scan.text);
1893
+ if (!fsIn) {
1894
+ add("recommended", "rules-missing-freespins", "freespins", "The rules never mention the free spins this game declares.");
1895
+ } else {
1896
+ if (fs.count != null && !covered("freespins:count") && !new RegExp(`\\b${fs.count}\\b[\\s\\S]{0,60}?spins?|spins?[\\s\\S]{0,60}?\\b${fs.count}\\b`, "i").test(scan.text)) {
1897
+ add("recommended", "rules-missing-fs-count", "freespins:count", `State that the bonus awards exactly ${fs.count} free spins.`);
1898
+ }
1899
+ if (fs.retrigger != null && !covered("freespins:retrigger") && !/re-?trigger/i.test(scan.text)) {
1900
+ add("recommended", "rules-missing-fs-retrigger", "freespins:retrigger", `State that free spins ${fs.retrigger ? "CAN" : "CANNOT"} be retriggered.`);
1901
+ }
1902
+ }
1903
+ }
1904
+ if (rules?.length && !scan.hasLegal && !/malfunction/i.test(scan.text)) {
1905
+ add("recommended", "rules-missing-legal", "legal", "Add the platform legal disclaimer (a `legal` block).");
1906
+ }
1907
+ if (rules?.length && !covered("controls") && !/\bcontrols?\b/i.test(scan.headings)) {
1908
+ add("recommended", "rules-missing-controls", "controls", 'Describe every interactive control (a \u201CControls\u201D section or covers: ["controls"]).');
1909
+ }
1910
+ out.sort((a, b) => a.level === b.level ? 0 : a.level === "required" ? -1 : 1);
1911
+ } catch {
1912
+ }
1913
+ return out;
1656
1914
  }
1657
1915
 
1658
1916
  // src/OpenUI.ts
@@ -1704,6 +1962,11 @@ var OpenUI = class {
1704
1962
  replay = new Signal(false);
1705
1963
  /** Game name + version (shown in the menu footer; for support / certification). */
1706
1964
  gameInfo = {};
1965
+ /** Declared GAME FACTS (modes + RTP/max win, free spins, volatility, cap) — seeded
1966
+ * from `spec.facts`, extended at runtime via {@link declareFacts} (the buy-feature
1967
+ * modal declares its configured features automatically). Drives the `mode-stats`
1968
+ * rules block + the rules-completeness audit in the info menu. */
1969
+ facts = new Signal({});
1707
1970
  /** Minimum round duration (ms) from jurisdiction — stored for the GAME to enforce. */
1708
1971
  minimumRoundDuration = 0;
1709
1972
  /** Buy-feature confirm threshold, as a multiple of the base bet. A play (buy or
@@ -1711,6 +1974,13 @@ var OpenUI = class {
1711
1974
  * — Stake requires that bet modes above 2× never activate on a single click. `0`
1712
1975
  * (the default) = off. Set via `spec.buyFeature.confirmAboveCost` or a jurisdiction. */
1713
1976
  confirmBuyAboveCost = 0;
1977
+ /** When autoplay stops while the balance can no longer cover the next round —
1978
+ * whether the built-in RG enforcement stopped it, the game's own pre-check did, or
1979
+ * the player pressed Stop already broke — pop the SAME insufficient-funds modal a
1980
+ * manual spin shows (ERR_IPB) instead of ending silently. A normal stop with funds
1981
+ * in hand shows nothing. Default on; `spec.autoplay.insufficientFundsNotice: false`
1982
+ * opts out. */
1983
+ autoplayInsufficientNotice = true;
1714
1984
  sessionNet = 0;
1715
1985
  prevVolumes = null;
1716
1986
  /** The frozen UISpec `createUI` built this from, if any — authored = run = tested. */
@@ -1850,6 +2120,13 @@ var OpenUI = class {
1850
2120
  this.disposers.push(this.betStepper.index.subscribe(syncStepperButtons));
1851
2121
  this.bet.set(this.betStepper.value);
1852
2122
  syncStepperButtons();
2123
+ this.disposers.push(
2124
+ this.bus.on("autoplayStopped", () => {
2125
+ if (!this.autoplayInsufficientNotice || this.replay.get()) return;
2126
+ if (this.noticePanel.isOpen) return;
2127
+ if (this.balance.get() < this.bet.get()) this.showRgsError("ERR_IPB");
2128
+ })
2129
+ );
1853
2130
  this.disposers.push(
1854
2131
  this.noticePanel.state.subscribe(() => {
1855
2132
  if (this.noticePanel.isOpen) return;
@@ -1940,6 +2217,12 @@ var OpenUI = class {
1940
2217
  if (this.autoplay.isActive && this.balance.get() < this.bet.get()) this.autoplay.stop();
1941
2218
  }
1942
2219
  }
2220
+ /** Merge more game facts into {@link facts} (modes merge by id; defined incoming
2221
+ * fields win). The info menu re-audits + re-renders its rules automatically. */
2222
+ declareFacts(add) {
2223
+ if (!add || typeof add !== "object") return;
2224
+ this.facts.set(mergeFacts(this.facts.get(), add));
2225
+ }
1943
2226
  /** Reset the running session net + aggregates + timer (e.g. on a fresh session). */
1944
2227
  resetSession() {
1945
2228
  this.sessionNet = 0;
@@ -2273,6 +2556,12 @@ function walkBlock(b, src, out) {
2273
2556
  add(it.value);
2274
2557
  });
2275
2558
  break;
2559
+ case "mode-stats":
2560
+ (b.extras ?? []).forEach((it) => {
2561
+ add(it.label);
2562
+ add(it.value);
2563
+ });
2564
+ break;
2276
2565
  case "group":
2277
2566
  add(b.title);
2278
2567
  b.children.forEach((c, i) => walkBlock(c, `${src}.children[${i}]`, out));
@@ -2366,6 +2655,7 @@ function createUI(spec = {}, hooks = {}) {
2366
2655
  }
2367
2656
  if (typeof spec.rtp === "number") ui.rtp.set(spec.rtp);
2368
2657
  if (spec.game) ui.gameInfo = { name: spec.game.name, version: spec.game.version };
2658
+ if (spec.facts) ui.declareFacts(spec.facts);
2369
2659
  if (spec.betLadder?.levels?.length) {
2370
2660
  ui.betStepper.setLevels(spec.betLadder.levels, spec.betLadder.index ?? 0);
2371
2661
  ui.bet.set(ui.betStepper.value);
@@ -2378,6 +2668,7 @@ function createUI(spec = {}, hooks = {}) {
2378
2668
  }
2379
2669
  if (spec.autoplay?.lossLimits) ui.autoplay.setLossLimitOptions(spec.autoplay.lossLimits);
2380
2670
  if (spec.autoplay?.winLimits) ui.autoplay.setWinLimitOptions(spec.autoplay.winLimits);
2671
+ if (spec.autoplay?.insufficientFundsNotice === false) ui.autoplayInsufficientNotice = false;
2381
2672
  if (spec.turbo) {
2382
2673
  ui.turbo.setModes(resolveTurboModes(spec.turbo.modes));
2383
2674
  if (spec.turbo.index != null) ui.turbo.setIndex(spec.turbo.index);
@@ -2493,6 +2784,43 @@ function composeMenu(menu, opts = {}) {
2493
2784
  return out;
2494
2785
  }
2495
2786
 
2787
+ // src/spec/rulesDoc.ts
2788
+ function isRulesDoc(doc) {
2789
+ if (!doc || typeof doc !== "object") return false;
2790
+ const d = doc;
2791
+ return d.version === 1 && Array.isArray(d.blocks);
2792
+ }
2793
+ var mergeLocaleMaps = (under, over) => {
2794
+ const out = {};
2795
+ for (const src of [under, over]) {
2796
+ for (const [loc, map] of Object.entries(src ?? {})) out[loc] = { ...out[loc], ...map };
2797
+ }
2798
+ return out;
2799
+ };
2800
+ function applyRulesDoc(spec, doc) {
2801
+ if (!isRulesDoc(doc)) return spec;
2802
+ const messages = mergeLocaleMaps(doc.messages, spec.locale?.messages);
2803
+ const socialMessages = mergeLocaleMaps(doc.socialMessages, spec.locale?.socialMessages);
2804
+ return {
2805
+ ...spec,
2806
+ menu: { ...spec.menu, rules: doc.blocks },
2807
+ locale: {
2808
+ locale: spec.locale?.locale ?? "en",
2809
+ messages: Object.keys(messages).length ? messages : { en: {} },
2810
+ ...Object.keys(socialMessages).length ? { socialMessages } : {}
2811
+ },
2812
+ ...doc.facts ? { facts: mergeFacts(doc.facts, spec.facts ?? {}) } : {}
2813
+ };
2814
+ }
2815
+ function auditRulesDoc(doc, opts = {}) {
2816
+ if (!isRulesDoc(doc)) return [];
2817
+ const facts = opts.facts ? mergeFacts(doc.facts ?? {}, opts.facts) : doc.facts;
2818
+ const dict = doc.messages?.[opts.locale ?? "en"] ?? {};
2819
+ const vars = factsVars(facts);
2820
+ const resolve = (s) => (dict[s] ?? s).replace(/\{\{([\w.-]+)\}\}/g, (_m, k) => String(vars[k] ?? `{{${k}}}`));
2821
+ return auditRules(facts, doc.blocks, { resolve });
2822
+ }
2823
+
2496
2824
  // src/spec/defaultHudSpec.ts
2497
2825
  var defaultHudSpec = Object.freeze({
2498
2826
  meta: { id: "open-ui-reference-hud", version: 1 },
@@ -2582,6 +2910,12 @@ function buildBetLadder(cfg, divisor = API_AMOUNT_DIVISOR) {
2582
2910
  const found = levels.findIndex((v) => v >= want);
2583
2911
  return { levels, index: found < 0 ? 0 : found };
2584
2912
  }
2913
+ function resolveBetLadder(availableBets, defaultBet, fallback = [0.2, 0.5, 1, 2, 5, 10]) {
2914
+ const levels = availableBets?.length ? availableBets.slice() : fallback.slice();
2915
+ const exact = levels.indexOf(defaultBet);
2916
+ const index = exact >= 0 ? exact : Math.max(0, levels.findIndex((b) => b >= defaultBet));
2917
+ return { levels, index };
2918
+ }
2585
2919
  function clampBet(amount, cfg, divisor = API_AMOUNT_DIVISOR) {
2586
2920
  const min = (cfg.minBet ?? 0) / divisor;
2587
2921
  const max = (cfg.maxBet ?? Infinity) / divisor;
@@ -2624,6 +2958,9 @@ exports.TurboControl = TurboControl;
2624
2958
  exports.Turn = Turn;
2625
2959
  exports.ValueDisplay = ValueDisplay;
2626
2960
  exports.applyJurisdiction = applyJurisdiction;
2961
+ exports.applyRulesDoc = applyRulesDoc;
2962
+ exports.auditRules = auditRules;
2963
+ exports.auditRulesDoc = auditRulesDoc;
2627
2964
  exports.breakpointFor = breakpointFor;
2628
2965
  exports.buildBetLadder = buildBetLadder;
2629
2966
  exports.buildBlocks = buildBlocks;
@@ -2648,16 +2985,25 @@ exports.displayDigits = displayDigits;
2648
2985
  exports.effect = effect;
2649
2986
  exports.errorBlocks = errorBlocks;
2650
2987
  exports.extendTheme = extendTheme;
2988
+ exports.factsVars = factsVars;
2651
2989
  exports.findForbiddenPhrases = findForbiddenPhrases;
2652
2990
  exports.formatAmount = formatAmount;
2991
+ exports.formatAmountPrecise = formatAmountPrecise;
2992
+ exports.formatRtp = formatRtp;
2993
+ exports.formatTimes = formatTimes;
2653
2994
  exports.installResponsive = installResponsive;
2654
2995
  exports.integerDigits = integerDigits;
2996
+ exports.isRulesDoc = isRulesDoc;
2655
2997
  exports.isSafeColor = isSafeColor;
2656
2998
  exports.isSocialCurrency = isSocialCurrency;
2657
2999
  exports.landscapeDefaultLayouts = landscapeDefaultLayouts;
3000
+ exports.mergeFacts = mergeFacts;
3001
+ exports.modeStatsItems = modeStatsItems;
3002
+ exports.neededDecimals = neededDecimals;
2658
3003
  exports.openuiDefaults = openuiDefaults;
2659
3004
  exports.openuiSocialDefaults = openuiSocialDefaults;
2660
3005
  exports.portraitDefaultLayouts = portraitDefaultLayouts;
3006
+ exports.resolveBetLadder = resolveBetLadder;
2661
3007
  exports.resolveCurrency = resolveCurrency;
2662
3008
  exports.resolvePlacement = resolvePlacement;
2663
3009
  exports.resolveTheme = resolveTheme;