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