@energy8platform/shell 0.6.6 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/html.cjs.js +677 -109
  2. package/dist/html.cjs.js.map +1 -1
  3. package/dist/html.d.ts +207 -27
  4. package/dist/html.esm.js +670 -110
  5. package/dist/html.esm.js.map +1 -1
  6. package/dist/index.cjs.js +378 -22
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.d.ts +199 -26
  9. package/dist/index.esm.js +371 -23
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/pixi.cjs.js +952 -282
  12. package/dist/pixi.cjs.js.map +1 -1
  13. package/dist/pixi.d.ts +202 -28
  14. package/dist/pixi.esm.js +945 -283
  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/format.ts +8 -4
  19. package/src/core/icon-names.ts +30 -0
  20. package/src/core/index.ts +4 -0
  21. package/src/core/menu.ts +301 -0
  22. package/src/core/popover.ts +81 -0
  23. package/src/core/renderer.ts +13 -10
  24. package/src/core/state.ts +2 -1
  25. package/src/core/types.ts +15 -6
  26. package/src/core/version.ts +1 -1
  27. package/src/ui/html/HtmlRenderer.ts +31 -8
  28. package/src/ui/html/components/GameInfo.ts +1 -1
  29. package/src/ui/html/components/Menu.ts +153 -0
  30. package/src/ui/html/icons.ts +16 -15
  31. package/src/ui/html/primitives.ts +142 -0
  32. package/src/ui/html/shell.css.ts +21 -1
  33. package/src/ui/pixi/PixiRenderer.ts +32 -14
  34. package/src/ui/pixi/components/BottomBar.ts +80 -9
  35. package/src/ui/pixi/components/GameInfo.ts +1 -1
  36. package/src/ui/pixi/components/Menu.ts +167 -0
  37. package/src/ui/pixi/context.ts +3 -2
  38. package/src/ui/pixi/icons.ts +16 -15
  39. package/src/ui/pixi/pixi-icon.ts +15 -3
  40. package/src/ui/pixi/primitives/controls.ts +46 -0
  41. package/src/ui/pixi/primitives/popover.ts +163 -0
  42. package/src/ui/pixi/primitives/scroll.ts +9 -5
  43. package/src/ui/html/components/Settings.ts +0 -68
  44. 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;
@@ -36,6 +140,9 @@ interface CurrencyConfig {
36
140
  * trimmed down to this many places so small wins keep their significant digits (e.g. 0.0673)
37
141
  * while round amounts stay compact (e.g. 0.30). Everything else is shown at exactly this many. */
38
142
  minDecimals?: number;
143
+ /** Defaults to the platform convention: `{ thousands: ',', decimal: '.' }` → `€1,234.50`.
144
+ * Override only for a jurisdiction that requires another convention — a comma decimal reads
145
+ * as a thousands group to most players and inflates the perceived payout. */
39
146
  separator?: {
40
147
  thousands?: string;
41
148
  decimal?: string;
@@ -289,11 +396,13 @@ interface ShellConfig {
289
396
  onBonusBuy?: () => void;
290
397
  /** Initial Settings-overlay volume slider positions (each 0..1, defaults to 1 = 100%). The shell
291
398
  * 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. */
399
+ * `shell.setVolume()`, and listen to `settingChange` ({ key: 'music'|'sfx' }) to apply. */
293
400
  volumes?: Partial<VolumeLevels>;
401
+ /** Bar-menu items, in order. Omit for the default list (sound, music, sfx, ─, game info). */
402
+ menu?: MenuItem[];
294
403
  }
295
404
  /** 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'>;
405
+ 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
406
  interface ShellState {
298
407
  mode: ShellMode;
299
408
  /** Sticky replay marker — true for a historical-round replay, regardless of the current
@@ -318,9 +427,11 @@ interface ShellState {
318
427
  /** The currently activated `feature` option (e.g. Ante), or null. Drives the
319
428
  * effective-bet readout tint and the BUY BONUS → DISABLE toggle on the bar. */
320
429
  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%. */
430
+ /** Volume slider positions (0..1) for the two sliders in the menu. */
323
431
  volumes: VolumeLevels;
432
+ /** Values of CUSTOM menu items, keyed by id. Seeded from the item list; preset values live in
433
+ * their own homes (`soundOn`, `volumes`) and are reached through `getMenuValue`. */
434
+ menu: Record<string, boolean | number>;
324
435
  }
325
436
  interface ShellEvents {
326
437
  spin: void;
@@ -401,8 +512,6 @@ interface ShellRenderer {
401
512
  openOverlay(req: OverlayRequest): OverlayHandle | void;
402
513
  /** Tear down any open overlay. */
403
514
  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
515
  /** Fade out + remove all nodes; resolve when gone. */
407
516
  destroy(): Promise<void> | void;
408
517
  /** Insets a scene should avoid (only the bottom bar is reserved; the rest is full-bleed). */
@@ -441,17 +550,21 @@ interface ShellHost {
441
550
  emit: EventEmitter<ShellEvents>['emit'];
442
551
  /** Renderer reports its surface size; the controller recomputes layout + re-renders. */
443
552
  notifyResize(w: number, h: number): void;
444
- /** Flip shared sound state (emits settingChange + refreshes an open Settings icon). */
553
+ /** Flip shared sound state (emits settingChange + refreshes an open menu's sound icon). */
445
554
  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. */
555
+ /** Current volume slider position (0..1) for music/sfx. */
449
556
  getVolume(key: VolumeKey): number;
450
557
  /** 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. */
558
+ * menu. Called by the slider control on drag AND by game code as the public API. */
452
559
  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;
560
+ /** The configured menu items (see core/menu.ts). */
561
+ readonly menu: MenuItem[];
562
+ /** Current value of a menu item — presets included (sound → soundOn, music/sfx → volumes). */
563
+ getMenuValue(id: string): boolean | number | undefined;
564
+ /** Set a menu value: clamps ranges, stores, emits `settingChange`, refreshes an open menu. */
565
+ setMenuValue(id: string, value: boolean | number): void;
566
+ /** An open menu registers a row updater here (null clears it on close). */
567
+ setMenuRefresh(fn: ((id: string, value: boolean | number) => void) | null): void;
455
568
  /** Logic-bearing actions invoked by renderer controls. */
456
569
  readonly actions: ShellActions;
457
570
  /** Re-show the replay summary modal through the controller (keeps its OverlayHandle in sync).
@@ -489,7 +602,7 @@ interface OverlayHandle {
489
602
  close(): void;
490
603
  }
491
604
  type OverlayRequest = {
492
- kind: 'settings';
605
+ kind: 'menu';
493
606
  } | {
494
607
  kind: 'gameInfo';
495
608
  } | {
@@ -520,14 +633,15 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
520
633
  tokens: ShellTokens;
521
634
  layout: ShellLayoutMode;
522
635
  soundOn: boolean;
523
- readonly engineVersion = "0.6.6";
636
+ readonly engineVersion = "0.7.1";
524
637
  readonly actions: ShellActions;
525
638
  private renderer;
526
639
  private i18n;
527
640
  private kbd?;
528
641
  private overlay;
529
- private soundRefresh;
530
- private volumeRefresh;
642
+ private menuItems;
643
+ private menuRefresh;
644
+ private overlayKind;
531
645
  private prevBalance;
532
646
  private prevWin;
533
647
  private destroyed;
@@ -540,7 +654,9 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
540
654
  private attachKeyboard;
541
655
  private pullFocus;
542
656
  private show;
657
+ /** Open the bar menu. Called again while it is open, it closes it — the burger toggles. */
543
658
  openMenu(): void;
659
+ /** @deprecated The Settings overlay is gone — this opens the bar menu. */
544
660
  openSettings(): void;
545
661
  openInfo(): void;
546
662
  openBuyBonus(): void;
@@ -551,13 +667,20 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
551
667
  /** Programmatically dismiss whatever overlay/modal is open. No-op when nothing is shown. */
552
668
  closeModal(): void;
553
669
  setSound(on: boolean): void;
554
- setSoundRefresh(fn: ((on: boolean) => void) | null): void;
555
670
  getVolume(key: VolumeKey): number;
556
671
  /** 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. */
672
+ * clamps, stores so a reopened menu popover reflects it, emits `settingChange`, and
673
+ * live-updates the slider if the menu is currently open. */
559
674
  setVolume(key: VolumeKey, value: number): void;
560
- setVolumeRefresh(fn: ((key: VolumeKey, value: number) => void) | null): void;
675
+ get menu(): MenuItem[];
676
+ /** Replace the item list. Values of ids already in state are kept; new ids are seeded. */
677
+ setMenu(items: MenuItem[]): void;
678
+ getMenuValue(id: string): boolean | number | undefined;
679
+ /** Set a menu value. Presets route to their own homes so there is never a second copy. */
680
+ setMenuValue(id: string, value: boolean | number): void;
681
+ setMenuRefresh(fn: ((id: string, value: boolean | number) => void) | null): void;
682
+ /** Clamp to the declared bounds of a custom `range` item (a non-range id passes through). */
683
+ private clampRange;
561
684
  activateFeature(bonus: BonusOption$1): void;
562
685
  deactivateFeature(): void;
563
686
  private money;
@@ -589,6 +712,56 @@ declare class ShellController extends EventEmitter<ShellEvents> implements Shell
589
712
  destroy(): Promise<void>;
590
713
  }
591
714
 
715
+ /** Geometry for the bar-menu popover. Pure math over rectangles so the DOM and Pixi renderers
716
+ * place it identically — the renderers only supply measured sizes and apply the result. */
717
+ interface Rect {
718
+ x: number;
719
+ y: number;
720
+ w: number;
721
+ h: number;
722
+ }
723
+ interface Surface {
724
+ w: number;
725
+ h: number;
726
+ }
727
+ interface PopoverPlacement {
728
+ /** Top-left of the popover card, in surface coordinates. */
729
+ x: number;
730
+ y: number;
731
+ /** 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. */
732
+ maxH: number;
733
+ /** Arrow centre, relative to the card's left edge. `-1` when there is no anchor to point at. */
734
+ arrowX: number;
735
+ /** True when the card opens below the anchor (arrow flips to the top edge). */
736
+ below: boolean;
737
+ }
738
+ declare const POPOVER: {
739
+ /** Keep-out from the surface edges. */
740
+ readonly margin: 8;
741
+ /** Space between the anchor and the card. */
742
+ readonly gap: 8;
743
+ /** Minimum distance from the arrow tip to either rounded corner. */
744
+ readonly arrowInset: 14;
745
+ /** A card shorter than this does not fit — flip to the other side instead. */
746
+ readonly minH: 120;
747
+ readonly minW: 220;
748
+ readonly maxW: 320;
749
+ };
750
+ /** Card width: content width clamped to [minW, maxW] and never wider than the surface. */
751
+ declare function popoverWidth(surfaceW: number, contentW: number): number;
752
+ /** Place the card above the `anchor` (below if it does not fit), left-aligned to it and clamped
753
+ * inside the surface. `anchor === null` (no bar / hidden shell) centres it, arrow off.
754
+ *
755
+ * `anchor` drives PLACEMENT (x, y, maxH, below) — normally the bar's whole plaque ("plate"), so the
756
+ * card sits flush with the bar as a whole rather than with whichever control opened it. `pointer` is
757
+ * the (optional) rect the ARROW points at — normally the burger button, which can sit anywhere
758
+ * inside the plate. Defaults to `anchor` when omitted, so every caller that only ever had one rect
759
+ * (i.e. every caller before `pointer` existed) keeps behaving exactly as it did before. */
760
+ declare function placePopover(anchor: Rect | null, surface: Surface, size: {
761
+ w: number;
762
+ h: number;
763
+ }, pointer?: Rect | null): PopoverPlacement;
764
+
592
765
  /** Rewrite restricted gambling terms in `text` to social-safe phrasing, preserving case. */
593
766
  declare function socialize(text: string): string;
594
767
  type Lang = 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hi' | 'id' | 'ja' | 'ko' | 'pl' | 'pt' | 'ru' | 'tr' | 'vi' | 'zh' | 'da';
@@ -605,7 +778,7 @@ interface I18n {
605
778
  declare function createI18n(opts: I18nOptions): I18n;
606
779
 
607
780
  /** The @energy8platform/shell package version, stamped into the game-info footer. */
608
- declare const PACKAGE_VERSION = "0.6.6";
781
+ declare const PACKAGE_VERSION = "0.7.1";
609
782
 
610
783
  /** A shell: the renderer-agnostic controller plus the surface facade (safeArea/barHeight/setVisible)
611
784
  * an embedding host reads. `createShell`, `createGameShell` and `createPixiShell` all return this. */
@@ -675,10 +848,11 @@ declare class PixiRenderer implements ShellRenderer {
675
848
  private cancelMoneyAnims;
676
849
  openOverlay(req: OverlayRequest): OverlayHandle | void;
677
850
  closeOverlay(): void;
678
- refreshSoundIcon(_on: boolean): void;
679
851
  /** Fade out (≈250ms, like GameShell's REMOVE_FADE_MS) then tear down; resolves when removed. */
680
852
  destroy(): Promise<void>;
681
- pushLayer(node: ShellLayer): LayerHandle;
853
+ pushLayer(node: ShellLayer, opts?: {
854
+ backdrop?: boolean;
855
+ }): LayerHandle;
682
856
  closeLayer(): void;
683
857
  private clearLayer;
684
858
  fitModals(): void;
@@ -740,5 +914,5 @@ declare function createPixiShell(config: PixiShellConfig): PixiGameShell;
740
914
  * Resolves when removed — mirrors `removePixiShell` in the legacy package. */
741
915
  declare function removePixiShell(): Promise<void>;
742
916
 
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 };
917
+ 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 };
918
+ 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 };