@energy8platform/shell 0.6.6 → 0.7.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.
Files changed (43) hide show
  1. package/dist/html.cjs.js +669 -105
  2. package/dist/html.cjs.js.map +1 -1
  3. package/dist/html.d.ts +204 -27
  4. package/dist/html.esm.js +662 -106
  5. package/dist/html.esm.js.map +1 -1
  6. package/dist/index.cjs.js +370 -18
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.d.ts +196 -26
  9. package/dist/index.esm.js +363 -19
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/pixi.cjs.js +944 -278
  12. package/dist/pixi.cjs.js.map +1 -1
  13. package/dist/pixi.d.ts +199 -28
  14. package/dist/pixi.esm.js +937 -279
  15. package/dist/pixi.esm.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/core/ShellController.ts +68 -16
  18. package/src/core/icon-names.ts +30 -0
  19. package/src/core/index.ts +4 -0
  20. package/src/core/menu.ts +301 -0
  21. package/src/core/popover.ts +81 -0
  22. package/src/core/renderer.ts +13 -10
  23. package/src/core/state.ts +2 -1
  24. package/src/core/types.ts +12 -6
  25. package/src/core/version.ts +1 -1
  26. package/src/ui/html/HtmlRenderer.ts +31 -8
  27. package/src/ui/html/components/GameInfo.ts +1 -1
  28. package/src/ui/html/components/Menu.ts +153 -0
  29. package/src/ui/html/icons.ts +16 -15
  30. package/src/ui/html/primitives.ts +142 -0
  31. package/src/ui/html/shell.css.ts +21 -1
  32. package/src/ui/pixi/PixiRenderer.ts +32 -14
  33. package/src/ui/pixi/components/BottomBar.ts +80 -9
  34. package/src/ui/pixi/components/GameInfo.ts +1 -1
  35. package/src/ui/pixi/components/Menu.ts +167 -0
  36. package/src/ui/pixi/context.ts +3 -2
  37. package/src/ui/pixi/icons.ts +16 -15
  38. package/src/ui/pixi/pixi-icon.ts +15 -3
  39. package/src/ui/pixi/primitives/controls.ts +46 -0
  40. package/src/ui/pixi/primitives/popover.ts +163 -0
  41. package/src/ui/pixi/primitives/scroll.ts +9 -5
  42. package/src/ui/html/components/Settings.ts +0 -68
  43. package/src/ui/pixi/components/Settings.ts +0 -132
package/dist/html.d.ts CHANGED
@@ -16,13 +16,117 @@ declare class EventEmitter<TEvents extends {}> {
16
16
  removeAllListeners(event?: keyof TEvents): this;
17
17
  }
18
18
 
19
+ declare const ICON_NAMES: readonly ["spin", "turbo1", "autoplay", "stop", "menu", "minus", "plus", "gift", "info", "soundOn", "soundOff", "close", "back", "chevronRight", "ticket", "turbo2", "turboOff", "chevronUp", "chevronDown"];
20
+ type IconName = (typeof ICON_NAMES)[number];
21
+
22
+ /** Built-in presets: the id alone is enough — the shell knows the label, icon and behaviour. */
23
+ type MenuPresetId = 'sound' | 'music' | 'sfx' | 'gameInfo';
24
+ declare function isPresetId(id: string): id is MenuPresetId;
25
+ interface MenuItemBase {
26
+ id: string;
27
+ /** Overrides the preset/default label. Run through the shell translator. */
28
+ label?: string;
29
+ icon?: IconName;
30
+ disabled?: boolean;
31
+ }
32
+ type MenuPresetItem = {
33
+ id: MenuPresetId;
34
+ } & Omit<MenuItemBase, 'id'>;
35
+ type MenuToggleItem = {
36
+ type: 'toggle';
37
+ value?: boolean;
38
+ onChange?(v: boolean): void;
39
+ } & MenuItemBase;
40
+ type MenuRangeItem = {
41
+ type: 'range';
42
+ min?: number;
43
+ max?: number;
44
+ step?: number;
45
+ value?: number;
46
+ /** Right-hand readout. Defaults to percent for a 0..1 range, else the raw number. */
47
+ format?(v: number): string;
48
+ onChange?(v: number): void;
49
+ } & MenuItemBase;
50
+ type MenuButtonItem = {
51
+ type: 'button';
52
+ chevron?: boolean;
53
+ onSelect?(): void;
54
+ } & MenuItemBase;
55
+ type MenuSeparatorItem = {
56
+ type: 'separator';
57
+ };
58
+ type MenuItem = MenuPresetItem | MenuToggleItem | MenuRangeItem | MenuButtonItem | MenuSeparatorItem;
59
+ /** The rows shown when `ShellConfig.menu` is omitted — today's Settings content, minus master. */
60
+ declare const DEFAULT_MENU: MenuItem[];
61
+ /** What `resolveMenu` reads. `ShellController` satisfies it; tests can supply a small literal. */
62
+ interface MenuHost {
63
+ readonly menu: MenuItem[];
64
+ t(text: string): string;
65
+ getMenuValue(id: string): boolean | number | undefined;
66
+ setMenuValue(id: string, value: boolean | number): void;
67
+ readonly actions: {
68
+ openInfo(): void;
69
+ };
70
+ }
71
+ /** A row, ready to draw: no preset knowledge left, no config shapes, just kind + accessors. */
72
+ type MenuRow = {
73
+ kind: 'separator';
74
+ } | {
75
+ kind: 'toggle';
76
+ id: string;
77
+ label: string;
78
+ disabled: boolean;
79
+ /** Glyph for the current value (the sound preset swaps speaker on/off). */
80
+ icon(value: boolean): IconName | undefined;
81
+ get(): boolean;
82
+ set(value: boolean): void;
83
+ } | {
84
+ kind: 'range';
85
+ id: string;
86
+ label: string;
87
+ icon?: IconName;
88
+ disabled: boolean;
89
+ min: number;
90
+ max: number;
91
+ step: number;
92
+ get(): number;
93
+ set(value: number): void;
94
+ format(value: number): string;
95
+ } | {
96
+ kind: 'button';
97
+ id: string;
98
+ label: string;
99
+ icon?: IconName;
100
+ disabled: boolean;
101
+ chevron: boolean;
102
+ select(): void;
103
+ };
104
+ /** Range bounds with defaults: 0..1 like a volume slider, step = a twentieth of the span. */
105
+ declare function rangeBounds(item: {
106
+ min?: number;
107
+ max?: number;
108
+ step?: number;
109
+ }): {
110
+ min: number;
111
+ max: number;
112
+ step: number;
113
+ };
114
+ /** Initial values for CUSTOM items (presets keep their own homes). Values already in `prev` win, so
115
+ * a later `setMenu()` with the same ids does not reset what the player has changed. */
116
+ declare function seedMenuValues(items: MenuItem[], prev?: Record<string, boolean | number>): Record<string, boolean | number>;
117
+ /** Expand the configured list into render-ready rows. A config mistake — an unknown preset id, an
118
+ * unrecognized custom `type`, or an invalid range span — is dropped with one warning rather than
119
+ * silently misbehaving: a typo must be visible, not silently invisible. A custom id that collides
120
+ * with a reserved preset id also warns, but keeps its row (see `custom()`). */
121
+ declare function resolveMenu(host: MenuHost): MenuRow[];
122
+
19
123
  /** `freeSpins` and `bonus` are the SAME bar layout (host-driven hero + Total Win); `freeSpins` is
20
124
  * kept as a back-compat alias for the common case (its readout is derived current/total), while
21
125
  * `bonus` pairs with `setBonus()` to show a game-supplied label + value (adventure, hold-and-spin,
22
126
  * respins — anything that isn't a plain free-spins counter). */
23
127
  type ShellMode = 'base' | 'bonus' | 'freeSpins' | 'replay';
24
- /** The three independent volume sliders shown in the Settings overlay. */
25
- type VolumeKey = 'master' | 'music' | 'sfx';
128
+ /** The two independent volume sliders shown in the bar menu. */
129
+ type VolumeKey = 'music' | 'sfx';
26
130
  type VolumeLevels = Record<VolumeKey, number>;
27
131
  interface CurrencyConfig {
28
132
  symbol: string;
@@ -287,11 +391,13 @@ interface ShellConfig {
287
391
  onBonusBuy?: () => void;
288
392
  /** Initial Settings-overlay volume slider positions (each 0..1, defaults to 1 = 100%). The shell
289
393
  * keeps them stateful across opens; read/update at runtime via `shell.getVolume()` /
290
- * `shell.setVolume()`, and listen to `settingChange` ({ key: 'master'|'music'|'sfx' }) to apply. */
394
+ * `shell.setVolume()`, and listen to `settingChange` ({ key: 'music'|'sfx' }) to apply. */
291
395
  volumes?: Partial<VolumeLevels>;
396
+ /** Bar-menu items, in order. Omit for the default list (sound, music, sfx, ─, game info). */
397
+ menu?: MenuItem[];
292
398
  }
293
399
  /** ShellConfig after the controller applies defaults (version, isSocial, replay, theme). No mount. */
294
- type ResolvedShellConfig = Required<Pick<ShellConfig, 'language' | 'currency' | 'availableBets' | 'defaultBet' | 'balance' | 'win' | 'mode' | 'features' | 'gameInfo' | 'version' | 'isSocial' | 'replay'>> & Pick<ShellConfig, 'currentBet' | 'theme' | 'onBonusBuy' | 'volumes'>;
400
+ type ResolvedShellConfig = Required<Pick<ShellConfig, 'language' | 'currency' | 'availableBets' | 'defaultBet' | 'balance' | 'win' | 'mode' | 'features' | 'gameInfo' | 'version' | 'isSocial' | 'replay'>> & Pick<ShellConfig, 'currentBet' | 'theme' | 'onBonusBuy' | 'volumes' | 'menu'>;
295
401
  interface ShellState {
296
402
  mode: ShellMode;
297
403
  /** Sticky replay marker — true for a historical-round replay, regardless of the current
@@ -316,9 +422,11 @@ interface ShellState {
316
422
  /** The currently activated `feature` option (e.g. Ante), or null. Drives the
317
423
  * effective-bet readout tint and the BUY BONUS → DISABLE toggle on the bar. */
318
424
  activeFeature: BonusOption | null;
319
- /** Volume slider positions (0..1) surfaced in the Settings overlay. Stateful across opens so a
320
- * reopened overlay reflects the last-set positions instead of resetting to 100%. */
425
+ /** Volume slider positions (0..1) for the two sliders in the menu. */
321
426
  volumes: VolumeLevels;
427
+ /** Values of CUSTOM menu items, keyed by id. Seeded from the item list; preset values live in
428
+ * their own homes (`soundOn`, `volumes`) and are reached through `getMenuValue`. */
429
+ menu: Record<string, boolean | number>;
322
430
  }
323
431
  interface ShellEvents {
324
432
  spin: void;
@@ -399,8 +507,6 @@ interface ShellRenderer {
399
507
  openOverlay(req: OverlayRequest): OverlayHandle | void;
400
508
  /** Tear down any open overlay. */
401
509
  closeOverlay(): void;
402
- /** If the open overlay registered a sound-icon refresher, the controller calls this to refresh it. */
403
- refreshSoundIcon?(on: boolean): void;
404
510
  /** Fade out + remove all nodes; resolve when gone. */
405
511
  destroy(): Promise<void> | void;
406
512
  /** Insets a scene should avoid (only the bottom bar is reserved; the rest is full-bleed). */
@@ -439,17 +545,21 @@ interface ShellHost {
439
545
  emit: EventEmitter<ShellEvents>['emit'];
440
546
  /** Renderer reports its surface size; the controller recomputes layout + re-renders. */
441
547
  notifyResize(w: number, h: number): void;
442
- /** Flip shared sound state (emits settingChange + refreshes an open Settings icon). */
548
+ /** Flip shared sound state (emits settingChange + refreshes an open menu's sound icon). */
443
549
  setSound(on: boolean): void;
444
- /** An open Settings overlay registers an icon updater here (null clears it on close). */
445
- setSoundRefresh(fn: ((on: boolean) => void) | null): void;
446
- /** Current volume slider position (0..1) for master/music/sfx. */
550
+ /** Current volume slider position (0..1) for music/sfx. */
447
551
  getVolume(key: VolumeKey): number;
448
552
  /** Set a volume slider (0..1): clamps, stores, emits `settingChange`, and live-updates an open
449
- * Settings overlay. Called by the slider control on drag AND by game code as the public API. */
553
+ * menu. Called by the slider control on drag AND by game code as the public API. */
450
554
  setVolume(key: VolumeKey, value: number): void;
451
- /** An open Settings overlay registers a slider updater here (null clears it on close). */
452
- setVolumeRefresh(fn: ((key: VolumeKey, value: number) => void) | null): void;
555
+ /** The configured menu items (see core/menu.ts). */
556
+ readonly menu: MenuItem[];
557
+ /** Current value of a menu item — presets included (sound → soundOn, music/sfx → volumes). */
558
+ getMenuValue(id: string): boolean | number | undefined;
559
+ /** Set a menu value: clamps ranges, stores, emits `settingChange`, refreshes an open menu. */
560
+ setMenuValue(id: string, value: boolean | number): void;
561
+ /** An open menu registers a row updater here (null clears it on close). */
562
+ setMenuRefresh(fn: ((id: string, value: boolean | number) => void) | null): void;
453
563
  /** Logic-bearing actions invoked by renderer controls. */
454
564
  readonly actions: ShellActions;
455
565
  /** Re-show the replay summary modal through the controller (keeps its OverlayHandle in sync).
@@ -487,7 +597,7 @@ interface OverlayHandle {
487
597
  close(): void;
488
598
  }
489
599
  type OverlayRequest = {
490
- kind: 'settings';
600
+ kind: 'menu';
491
601
  } | {
492
602
  kind: 'gameInfo';
493
603
  } | {
@@ -518,14 +628,15 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
518
628
  tokens: ShellTokens;
519
629
  layout: ShellLayoutMode;
520
630
  soundOn: boolean;
521
- readonly engineVersion = "0.6.6";
631
+ readonly engineVersion = "0.7.0";
522
632
  readonly actions: ShellActions;
523
633
  private renderer;
524
634
  private i18n;
525
635
  private kbd?;
526
636
  private overlay;
527
- private soundRefresh;
528
- private volumeRefresh;
637
+ private menuItems;
638
+ private menuRefresh;
639
+ private overlayKind;
529
640
  private prevBalance;
530
641
  private prevWin;
531
642
  private destroyed;
@@ -538,7 +649,9 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
538
649
  private attachKeyboard;
539
650
  private pullFocus;
540
651
  private show;
652
+ /** Open the bar menu. Called again while it is open, it closes it — the burger toggles. */
541
653
  openMenu(): void;
654
+ /** @deprecated The Settings overlay is gone — this opens the bar menu. */
542
655
  openSettings(): void;
543
656
  openInfo(): void;
544
657
  openBuyBonus(): void;
@@ -549,13 +662,20 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
549
662
  /** Programmatically dismiss whatever overlay/modal is open. No-op when nothing is shown. */
550
663
  closeModal(): void;
551
664
  setSound(on: boolean): void;
552
- setSoundRefresh(fn: ((on: boolean) => void) | null): void;
553
665
  getVolume(key: VolumeKey): number;
554
666
  /** Set a volume slider (0..1). Shared by the slider control (drag) and game code (public API):
555
- * clamps, stores so a reopened Settings overlay reflects it, emits `settingChange`, and
556
- * live-updates the slider if the overlay is currently open. */
667
+ * clamps, stores so a reopened menu popover reflects it, emits `settingChange`, and
668
+ * live-updates the slider if the menu is currently open. */
557
669
  setVolume(key: VolumeKey, value: number): void;
558
- setVolumeRefresh(fn: ((key: VolumeKey, value: number) => void) | null): void;
670
+ get menu(): MenuItem[];
671
+ /** Replace the item list. Values of ids already in state are kept; new ids are seeded. */
672
+ setMenu(items: MenuItem[]): void;
673
+ getMenuValue(id: string): boolean | number | undefined;
674
+ /** Set a menu value. Presets route to their own homes so there is never a second copy. */
675
+ setMenuValue(id: string, value: boolean | number): void;
676
+ setMenuRefresh(fn: ((id: string, value: boolean | number) => void) | null): void;
677
+ /** Clamp to the declared bounds of a custom `range` item (a non-range id passes through). */
678
+ private clampRange;
559
679
  activateFeature(bonus: BonusOption): void;
560
680
  deactivateFeature(): void;
561
681
  private money;
@@ -587,6 +707,56 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
587
707
  destroy(): Promise<void>;
588
708
  }
589
709
 
710
+ /** Geometry for the bar-menu popover. Pure math over rectangles so the DOM and Pixi renderers
711
+ * place it identically — the renderers only supply measured sizes and apply the result. */
712
+ interface Rect {
713
+ x: number;
714
+ y: number;
715
+ w: number;
716
+ h: number;
717
+ }
718
+ interface Surface {
719
+ w: number;
720
+ h: number;
721
+ }
722
+ interface PopoverPlacement {
723
+ /** Top-left of the popover card, in surface coordinates. */
724
+ x: number;
725
+ y: number;
726
+ /** True space on the chosen side, in surface coordinates; may be less than minH on a very short surface. The row list scrolls inside it. */
727
+ maxH: number;
728
+ /** Arrow centre, relative to the card's left edge. `-1` when there is no anchor to point at. */
729
+ arrowX: number;
730
+ /** True when the card opens below the anchor (arrow flips to the top edge). */
731
+ below: boolean;
732
+ }
733
+ declare const POPOVER: {
734
+ /** Keep-out from the surface edges. */
735
+ readonly margin: 8;
736
+ /** Space between the anchor and the card. */
737
+ readonly gap: 8;
738
+ /** Minimum distance from the arrow tip to either rounded corner. */
739
+ readonly arrowInset: 14;
740
+ /** A card shorter than this does not fit — flip to the other side instead. */
741
+ readonly minH: 120;
742
+ readonly minW: 220;
743
+ readonly maxW: 320;
744
+ };
745
+ /** Card width: content width clamped to [minW, maxW] and never wider than the surface. */
746
+ declare function popoverWidth(surfaceW: number, contentW: number): number;
747
+ /** Place the card above the `anchor` (below if it does not fit), left-aligned to it and clamped
748
+ * inside the surface. `anchor === null` (no bar / hidden shell) centres it, arrow off.
749
+ *
750
+ * `anchor` drives PLACEMENT (x, y, maxH, below) — normally the bar's whole plaque ("plate"), so the
751
+ * card sits flush with the bar as a whole rather than with whichever control opened it. `pointer` is
752
+ * the (optional) rect the ARROW points at — normally the burger button, which can sit anywhere
753
+ * inside the plate. Defaults to `anchor` when omitted, so every caller that only ever had one rect
754
+ * (i.e. every caller before `pointer` existed) keeps behaving exactly as it did before. */
755
+ declare function placePopover(anchor: Rect | null, surface: Surface, size: {
756
+ w: number;
757
+ h: number;
758
+ }, pointer?: Rect | null): PopoverPlacement;
759
+
590
760
  /** Rewrite restricted gambling terms in `text` to social-safe phrasing, preserving case. */
591
761
  declare function socialize(text: string): string;
592
762
  type Lang = 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hi' | 'id' | 'ja' | 'ko' | 'pl' | 'pt' | 'ru' | 'tr' | 'vi' | 'zh' | 'da';
@@ -603,7 +773,7 @@ interface I18n {
603
773
  declare function createI18n(opts: I18nOptions): I18n;
604
774
 
605
775
  /** The @energy8platform/shell package version, stamped into the game-info footer. */
606
- declare const PACKAGE_VERSION = "0.6.6";
776
+ declare const PACKAGE_VERSION = "0.7.0";
607
777
 
608
778
  /** A shell: the renderer-agnostic controller plus the surface facade (safeArea/barHeight/setVisible)
609
779
  * an embedding host reads. `createShell`, `createGameShell` and `createPixiShell` all return this. */
@@ -629,7 +799,11 @@ declare class HtmlRenderer implements ShellRenderer {
629
799
  private ro;
630
800
  private moneyAnims;
631
801
  private modalOnKey;
802
+ private popoverPosition;
632
803
  private destroyed;
804
+ /** The scale factor last applied to the bar by applyFitScale() — exposed so the menu popover can
805
+ * match it exactly (see getBarScale) rather than re-derive its own, possibly-disagreeing, value. */
806
+ private barScale;
633
807
  /** MutationObserver for buy-bonus confirm fit — fires fitModals() when nodes are added
634
808
  * inside the modalHost (e.g. the confirm dialog appended after the grid is open). */
635
809
  private mutObs;
@@ -644,10 +818,13 @@ declare class HtmlRenderer implements ShellRenderer {
644
818
  animateMoney(field: 'balance' | 'win', from: number, to: number, durationMs?: number): void;
645
819
  openOverlay(req: OverlayRequest): OverlayHandle | void;
646
820
  closeOverlay(): void;
647
- refreshSoundIcon?(_on: boolean): void;
648
821
  destroy(): Promise<void>;
649
822
  /** Trigger a bar fit-scale pass (used by tests that stub geometry after the initial render). */
650
823
  fitBar(): void;
824
+ /** The scale factor applyFitScale() last applied to the bar — the menu popover multiplies its own
825
+ * card by this SAME number so its typography/padding/row-heights carry the same visual weight
826
+ * relationship the bar has, instead of ignoring the viewport like a fixed-px card would. */
827
+ getBarScale(): number;
651
828
  private cancelMoneyAnims;
652
829
  private buildOverlay;
653
830
  private showModal;
@@ -676,5 +853,5 @@ declare function createGameShell(config: HtmlShellConfig): ShellController;
676
853
  /** Tear down the active shell (no argument — singleton). Resolves immediately when nothing is active. */
677
854
  declare function removeGameShell(): Promise<void>;
678
855
 
679
- export { DEFAULT_ACCENT, ShellController as GameShell, HtmlRenderer, PACKAGE_VERSION, SCHEMES, ShellController, createGameShell, createI18n, createShell, normalizeLang, removeGameShell, resolveConfig, resolveTheme, socialize };
680
- export type { AutoplayConfig, AutoplayOptions, BonusCardContext, BonusOption, BonusReadout, CellRef, CreateShellOptions, CurrencyConfig, FreeSpinsState, GameInfoContent, GameInfoSection, GameMode, HtmlShellConfig, I18n, I18nOptions, Lang, ModalAction, ModalOptions, OverlayHandle, OverlayRequest, PaylineDef, PaytableRow, ReplayModalOptions, ResolvedShellConfig, SafeArea, ShapeDef, Shell, ShellActions, HtmlShellConfig as ShellConfig, ShellEvents, ShellFeatures, ShellHost, ShellLayoutMode, ShellMode, ShellRenderer, ShellState, ShellSurface, ShellTokens, ThemeConfig, VolumeKey, VolumeLevels, WinSection };
856
+ export { DEFAULT_ACCENT, DEFAULT_MENU, ShellController as GameShell, HtmlRenderer, PACKAGE_VERSION, POPOVER, SCHEMES, ShellController, createGameShell, createI18n, createShell, isPresetId, normalizeLang, placePopover, popoverWidth, rangeBounds, removeGameShell, resolveConfig, resolveMenu, resolveTheme, seedMenuValues, socialize };
857
+ export type { AutoplayConfig, AutoplayOptions, BonusCardContext, BonusOption, BonusReadout, CellRef, CreateShellOptions, CurrencyConfig, FreeSpinsState, GameInfoContent, GameInfoSection, GameMode, HtmlShellConfig, I18n, I18nOptions, Lang, MenuHost, MenuItem, MenuPresetId, MenuRow, ModalAction, ModalOptions, OverlayHandle, OverlayRequest, PaylineDef, PaytableRow, PopoverPlacement, Rect as PopoverRect, ReplayModalOptions, ResolvedShellConfig, SafeArea, ShapeDef, Shell, ShellActions, HtmlShellConfig as ShellConfig, ShellEvents, ShellFeatures, ShellHost, ShellLayoutMode, ShellMode, ShellRenderer, ShellState, ShellSurface, ShellTokens, ThemeConfig, VolumeKey, VolumeLevels, WinSection };