@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/index.esm.js CHANGED
@@ -50,6 +50,240 @@ class EventEmitter {
50
50
  }
51
51
  }
52
52
 
53
+ // AUTO-GENERATED from ../../icons.svg by scripts/gen-icons-from-svg.mjs — do not edit by hand.
54
+ // Sharp monochrome icon set: each glyph is a 24×24 viewBox fragment using currentColor
55
+ // (hollow shapes use fill-rule="evenodd"). Coordinates are baked into the 24×24 space (no
56
+ // <g transform>), so the same fragment renders identically in the DOM <svg> and in Pixi's
57
+ // GraphicsContext.svg. To change an icon: edit icons.svg, then run
58
+ // `node scripts/gen-icons-from-svg.mjs`.
59
+ // The single glyph-name union, shared by core (menu items) and both renderers.
60
+ const ICON_NAMES = [
61
+ 'spin',
62
+ 'turbo1',
63
+ 'autoplay',
64
+ 'stop',
65
+ 'menu',
66
+ 'minus',
67
+ 'plus',
68
+ 'gift',
69
+ 'info',
70
+ 'soundOn',
71
+ 'soundOff',
72
+ 'close',
73
+ 'back',
74
+ 'chevronRight',
75
+ 'ticket',
76
+ 'turbo2',
77
+ 'turboOff',
78
+ 'chevronUp',
79
+ 'chevronDown',
80
+ ];
81
+
82
+ const PRESET_IDS = ['sound', 'music', 'sfx', 'gameInfo'];
83
+ function isPresetId(id) {
84
+ return PRESET_IDS.includes(id);
85
+ }
86
+ /** The rows shown when `ShellConfig.menu` is omitted — today's Settings content, minus master. */
87
+ const DEFAULT_MENU = [
88
+ { id: 'sound' },
89
+ { id: 'music' },
90
+ { id: 'sfx' },
91
+ { type: 'separator' },
92
+ { id: 'gameInfo' },
93
+ ];
94
+ const isSeparator = (i) => i.type === 'separator';
95
+ /** Range bounds with defaults: 0..1 like a volume slider, step = a twentieth of the span. */
96
+ function rangeBounds(item) {
97
+ const min = item.min ?? 0;
98
+ const max = item.max ?? 1;
99
+ const derivedStep = (max - min) / 20;
100
+ // A declared `step` must be a genuinely positive number. `??` alone doesn't catch this: an
101
+ // explicit 0 (or a negative value) is not null/undefined, so it would sail through unchanged —
102
+ // and a renderer's position math divides by it (Pixi's fromUnit: `(raw-min)/step`), turning the
103
+ // slider's value into NaN, which then reaches `state.menu` and the `settingChange` payload.
104
+ const step = item.step != null && item.step > 0 ? item.step : derivedStep;
105
+ return { min, max, step };
106
+ }
107
+ /** Initial values for CUSTOM items (presets keep their own homes). Values already in `prev` win, so
108
+ * a later `setMenu()` with the same ids does not reset what the player has changed. */
109
+ function seedMenuValues(items, prev = {}) {
110
+ const out = {};
111
+ for (const item of items) {
112
+ if (isSeparator(item))
113
+ continue;
114
+ const type = item.type;
115
+ if (!type || isPresetId(item.id))
116
+ continue;
117
+ // A previous value only carries over when its runtime type still matches this item's kind.
118
+ // Without this guard, reconfiguring the same id from a toggle to a range (or back) would seed
119
+ // a boolean into a slider's position math (or a stale number into a checkbox) — a legitimate
120
+ // reconfiguration, not a config error, so it falls through to the item's own default instead
121
+ // of warning.
122
+ const prevValue = prev[item.id];
123
+ if (type === 'toggle') {
124
+ out[item.id] = typeof prevValue === 'boolean' ? prevValue : (item.value ?? false);
125
+ }
126
+ else if (type === 'range') {
127
+ const r = item;
128
+ out[item.id] = typeof prevValue === 'number' ? prevValue : (r.value ?? rangeBounds(r).min);
129
+ }
130
+ }
131
+ return out;
132
+ }
133
+ const percent = (v) => `${Math.round(v * 100)}%`;
134
+ function safeIcon(name) {
135
+ return name && ICON_NAMES.includes(name) ? name : undefined;
136
+ }
137
+ /** Every drop/collision warning goes through here so the message style stays uniform. */
138
+ function warn(message) {
139
+ console.warn(`[shell] ${message}`);
140
+ }
141
+ /** Expand the configured list into render-ready rows. A config mistake — an unknown preset id, an
142
+ * unrecognized custom `type`, or an invalid range span — is dropped with one warning rather than
143
+ * silently misbehaving: a typo must be visible, not silently invisible. A custom id that collides
144
+ * with a reserved preset id also warns, but keeps its row (see `custom()`). */
145
+ function resolveMenu(host) {
146
+ const rows = [];
147
+ for (const item of host.menu) {
148
+ if (isSeparator(item)) {
149
+ rows.push({ kind: 'separator' });
150
+ continue;
151
+ }
152
+ const type = item.type;
153
+ if (!type) {
154
+ const row = preset(host, item);
155
+ if (row)
156
+ rows.push(row);
157
+ else
158
+ warn(`unknown menu preset id "${item.id}" — item skipped`);
159
+ continue;
160
+ }
161
+ const row = custom(host, item, type);
162
+ if (row)
163
+ rows.push(row);
164
+ }
165
+ return rows;
166
+ }
167
+ function preset(host, item) {
168
+ const disabled = item.disabled ?? false;
169
+ const label = host.t(item.label ?? DEFAULT_LABELS[item.id] ?? item.id);
170
+ switch (item.id) {
171
+ case 'sound':
172
+ return {
173
+ kind: 'toggle',
174
+ id: 'sound',
175
+ label,
176
+ disabled,
177
+ icon: (v) => safeIcon(item.icon) ?? (v ? 'soundOn' : 'soundOff'),
178
+ get: () => host.getMenuValue('sound') !== false,
179
+ set: (v) => host.setMenuValue('sound', v),
180
+ };
181
+ case 'music':
182
+ case 'sfx': {
183
+ const id = item.id;
184
+ return {
185
+ kind: 'range',
186
+ id,
187
+ label,
188
+ icon: safeIcon(item.icon),
189
+ disabled,
190
+ min: 0,
191
+ max: 1,
192
+ step: 0.05,
193
+ get: () => Number(host.getMenuValue(id) ?? 1),
194
+ set: (v) => host.setMenuValue(id, v),
195
+ format: percent,
196
+ };
197
+ }
198
+ case 'gameInfo':
199
+ return {
200
+ kind: 'button',
201
+ id: 'gameInfo',
202
+ label,
203
+ icon: safeIcon(item.icon) ?? 'info',
204
+ disabled,
205
+ chevron: true,
206
+ select: () => host.actions.openInfo(),
207
+ };
208
+ default:
209
+ return null;
210
+ }
211
+ }
212
+ const DEFAULT_LABELS = {
213
+ sound: 'Sound',
214
+ music: 'Music',
215
+ sfx: 'SFX',
216
+ gameInfo: 'Game info',
217
+ };
218
+ function custom(host, item, type) {
219
+ // Same store, different semantics: the real preset's get() and a custom row's get() disagree
220
+ // (see the preset cases below vs. the toggle case here). Routing does not change — Task 4's
221
+ // ShellHost is what actually owns the value — this warning just makes the clash visible.
222
+ if (isPresetId(item.id)) {
223
+ warn(`menu item id "${item.id}" collides with a built-in preset id — preset ids are reserved`);
224
+ }
225
+ const disabled = item.disabled ?? false;
226
+ const label = host.t(item.label ?? item.id);
227
+ const icon = safeIcon(item.icon);
228
+ if (type === 'toggle') {
229
+ const it = item;
230
+ return {
231
+ kind: 'toggle',
232
+ id: it.id,
233
+ label,
234
+ disabled,
235
+ icon: () => icon,
236
+ get: () => host.getMenuValue(it.id) === true,
237
+ set: (v) => {
238
+ host.setMenuValue(it.id, v);
239
+ it.onChange?.(v);
240
+ },
241
+ };
242
+ }
243
+ if (type === 'range') {
244
+ const it = item;
245
+ const { min, max, step } = rangeBounds(it);
246
+ if (max <= min) {
247
+ // A renderer's position math ((value - min) / (max - min)) turns this into Infinity/NaN —
248
+ // drop the row instead, exactly like an unknown preset id.
249
+ warn(`menu item "${it.id}" has invalid range bounds (min ${min}, max ${max}) — item skipped`);
250
+ return null;
251
+ }
252
+ return {
253
+ kind: 'range',
254
+ id: it.id,
255
+ label,
256
+ icon,
257
+ disabled,
258
+ min,
259
+ max,
260
+ step,
261
+ get: () => Number(host.getMenuValue(it.id) ?? min),
262
+ set: (v) => {
263
+ host.setMenuValue(it.id, v);
264
+ it.onChange?.(v);
265
+ },
266
+ format: it.format ?? (min === 0 && max === 1 ? percent : (v) => String(v)),
267
+ };
268
+ }
269
+ if (type === 'button') {
270
+ const it = item;
271
+ return {
272
+ kind: 'button',
273
+ id: it.id,
274
+ label,
275
+ icon,
276
+ disabled,
277
+ chevron: it.chevron ?? false,
278
+ select: () => it.onSelect?.(),
279
+ };
280
+ }
281
+ // Neither toggle, range, nor button — a typo'd `type` used to fall through to an unconditional
282
+ // button row with no onSelect. Drop it visibly instead.
283
+ warn(`menu item "${item.id}" has unknown type "${type}" — item skipped`);
284
+ return null;
285
+ }
286
+
53
287
  function createInitialState(config) {
54
288
  return {
55
289
  mode: config.mode,
@@ -66,10 +300,10 @@ function createInitialState(config) {
66
300
  bonus: null,
67
301
  activeFeature: null,
68
302
  volumes: {
69
- master: clampVolume(config.volumes?.master),
70
303
  music: clampVolume(config.volumes?.music),
71
304
  sfx: clampVolume(config.volumes?.sfx),
72
305
  },
306
+ menu: seedMenuValues(config.menu ?? DEFAULT_MENU),
73
307
  };
74
308
  }
75
309
  /** Clamp a configured volume to 0..1, defaulting to full (1) when unset/invalid. */
@@ -141,15 +375,19 @@ function resolveTheme(theme = {}) {
141
375
  * trailing zeros are trimmed down to (but never past) `minDecimals`, so small wins keep their
142
376
  * significant digits. Balance / bet / prices stay fixed at `minDecimals`.
143
377
  *
378
+ * Separators default to the platform convention — `.` decimal, `,` thousands (`€1,234.50`).
379
+ * A comma decimal is NOT safe as a default: players read "2,50" as 250 and believe they were
380
+ * paid far more than they were. Games that need another convention pass `currency.separator`.
381
+ *
144
382
  * Example with `maxDecimals: 4, minDecimals: 2`:
145
- * fixed → 0.0673 → 0,07 0.3 → 0,30
146
- * variable → 0.0673 → 0,0673 0.067 → 0,067 0.3 → 0,30 0 → 0,00
383
+ * fixed → 0.0673 → 0.07 0.3 → 0.30
384
+ * variable → 0.0673 → 0.0673 0.067 → 0.067 0.3 → 0.30 0 → 0.00
147
385
  */
148
386
  function formatCurrency(value, currency, variableDecimals = false) {
149
387
  const maxDecimals = currency.maxDecimals ?? 2;
150
388
  const minDecimals = Math.max(0, Math.min(maxDecimals, currency.minDecimals ?? maxDecimals));
151
- const thousands = currency.separator?.thousands ?? '.';
152
- const decimal = currency.separator?.decimal ?? ',';
389
+ const thousands = currency.separator?.thousands ?? ',';
390
+ const decimal = currency.separator?.decimal ?? '.';
153
391
  const safe = Number.isFinite(value) ? value : 0;
154
392
  // fixed callers round at minDecimals; variable callers round at maxDecimals then trim back down.
155
393
  const places = variableDecimals ? maxDecimals : minDecimals;
@@ -1427,7 +1665,7 @@ class KeyboardController {
1427
1665
 
1428
1666
  // AUTO-GENERATED by scripts/gen-version.mjs — do not edit. Mirrors package.json "version".
1429
1667
  /** The @energy8platform/shell package version, stamped into the game-info footer. */
1430
- const PACKAGE_VERSION = '0.6.6';
1668
+ const PACKAGE_VERSION = '0.7.1';
1431
1669
 
1432
1670
  /** Apply defaults to the raw config (the mount target lives on the renderer, not here). */
1433
1671
  function resolveConfig(config) {
@@ -1445,6 +1683,7 @@ function resolveConfig(config) {
1445
1683
  theme: config.theme,
1446
1684
  onBonusBuy: config.onBonusBuy,
1447
1685
  volumes: config.volumes,
1686
+ menu: config.menu,
1448
1687
  version: config.version ?? '1.0.0',
1449
1688
  isSocial: config.isSocial ?? false,
1450
1689
  replay: config.replay ?? config.mode === 'replay',
@@ -1465,8 +1704,9 @@ class ShellController extends EventEmitter {
1465
1704
  i18n;
1466
1705
  kbd;
1467
1706
  overlay = null;
1468
- soundRefresh = null;
1469
- volumeRefresh = null;
1707
+ menuItems;
1708
+ menuRefresh = null;
1709
+ overlayKind = null;
1470
1710
  prevBalance;
1471
1711
  prevWin;
1472
1712
  destroyed = false;
@@ -1477,6 +1717,7 @@ class ShellController extends EventEmitter {
1477
1717
  this.config = resolveConfig(config);
1478
1718
  this.i18n = createI18n({ language: this.config.language, isSocial: this.config.isSocial });
1479
1719
  this.state = createInitialState(this.config);
1720
+ this.menuItems = this.config.menu ?? DEFAULT_MENU;
1480
1721
  this.tokens = resolveTheme(this.config.theme);
1481
1722
  this.prevBalance = this.state.balance;
1482
1723
  this.prevWin = this.state.win;
@@ -1610,14 +1851,21 @@ class ShellController extends EventEmitter {
1610
1851
  show(req) {
1611
1852
  this.closeModal();
1612
1853
  this.overlay = this.renderer.openOverlay(req) ?? null;
1854
+ this.overlayKind = this.overlay ? req.kind : null;
1613
1855
  }
1856
+ /** Open the bar menu. Called again while it is open, it closes it — the burger toggles. */
1614
1857
  openMenu() {
1858
+ if (this.overlayKind === 'menu') {
1859
+ this.closeModal();
1860
+ return;
1861
+ }
1615
1862
  this.emit('menuOpen');
1616
- this.openSettings();
1863
+ this.show({ kind: 'menu' });
1617
1864
  }
1865
+ /** @deprecated The Settings overlay is gone — this opens the bar menu. */
1618
1866
  openSettings() {
1619
1867
  this.emit('settingsOpen');
1620
- this.show({ kind: 'settings' });
1868
+ this.openMenu();
1621
1869
  }
1622
1870
  openInfo() {
1623
1871
  this.emit('infoOpen');
@@ -1649,35 +1897,72 @@ class ShellController extends EventEmitter {
1649
1897
  if (!this.overlay)
1650
1898
  return;
1651
1899
  this.overlay = null;
1652
- this.soundRefresh = null;
1653
- this.volumeRefresh = null;
1900
+ this.overlayKind = null;
1901
+ this.menuRefresh = null;
1654
1902
  this.renderer.closeOverlay();
1655
1903
  }
1656
1904
  // ── sound ──────────────────────────────────────────────────────────────────
1657
1905
  setSound(on) {
1658
1906
  this.soundOn = on;
1659
1907
  this.emit('settingChange', { key: 'sound', value: on });
1660
- this.soundRefresh?.(on);
1661
- this.renderer.refreshSoundIcon?.(on);
1662
- }
1663
- setSoundRefresh(fn) {
1664
- this.soundRefresh = fn;
1908
+ this.menuRefresh?.('sound', on);
1665
1909
  }
1666
1910
  // ── volume ─────────────────────────────────────────────────────────────────
1667
1911
  getVolume(key) {
1668
1912
  return this.state.volumes[key];
1669
1913
  }
1670
1914
  /** Set a volume slider (0..1). Shared by the slider control (drag) and game code (public API):
1671
- * clamps, stores so a reopened Settings overlay reflects it, emits `settingChange`, and
1672
- * live-updates the slider if the overlay is currently open. */
1915
+ * clamps, stores so a reopened menu popover reflects it, emits `settingChange`, and
1916
+ * live-updates the slider if the menu is currently open. */
1673
1917
  setVolume(key, value) {
1674
1918
  const v = Math.max(0, Math.min(1, value));
1675
1919
  this.state.volumes[key] = v;
1676
1920
  this.emit('settingChange', { key, value: v });
1677
- this.volumeRefresh?.(key, v);
1921
+ this.menuRefresh?.(key, v);
1922
+ }
1923
+ // ── menu ───────────────────────────────────────────────────────────────────
1924
+ get menu() {
1925
+ return this.menuItems;
1926
+ }
1927
+ /** Replace the item list. Values of ids already in state are kept; new ids are seeded. */
1928
+ setMenu(items) {
1929
+ this.menuItems = items;
1930
+ this.state.menu = seedMenuValues(items, this.state.menu);
1931
+ if (this.overlayKind === 'menu')
1932
+ this.show({ kind: 'menu' });
1678
1933
  }
1679
- setVolumeRefresh(fn) {
1680
- this.volumeRefresh = fn;
1934
+ getMenuValue(id) {
1935
+ if (id === 'sound')
1936
+ return this.soundOn;
1937
+ if (id === 'music' || id === 'sfx')
1938
+ return this.state.volumes[id];
1939
+ return this.state.menu[id];
1940
+ }
1941
+ /** Set a menu value. Presets route to their own homes so there is never a second copy. */
1942
+ setMenuValue(id, value) {
1943
+ if (id === 'sound') {
1944
+ this.setSound(value !== false);
1945
+ return;
1946
+ }
1947
+ if (id === 'music' || id === 'sfx') {
1948
+ this.setVolume(id, Number(value));
1949
+ return;
1950
+ }
1951
+ const next = typeof value === 'number' ? this.clampRange(id, value) : value;
1952
+ this.state.menu[id] = next;
1953
+ this.emit('settingChange', { key: id, value: next });
1954
+ this.menuRefresh?.(id, next);
1955
+ }
1956
+ setMenuRefresh(fn) {
1957
+ this.menuRefresh = fn;
1958
+ }
1959
+ /** Clamp to the declared bounds of a custom `range` item (a non-range id passes through). */
1960
+ clampRange(id, value) {
1961
+ const item = this.menuItems.find((i) => i.id === id);
1962
+ if (!item || item.type !== 'range')
1963
+ return value;
1964
+ const { min, max } = rangeBounds(item);
1965
+ return Math.max(min, Math.min(max, value));
1681
1966
  }
1682
1967
  // ── features ─────────────────────────────────────────────────────────────────
1683
1968
  activateFeature(bonus) {
@@ -1787,6 +2072,11 @@ class ShellController extends EventEmitter {
1787
2072
  if (this.destroyed)
1788
2073
  return Promise.resolve();
1789
2074
  this.destroyed = true;
2075
+ // With the menu (or any overlay) open at teardown, `menuRefresh` / `overlay` / `overlayKind`
2076
+ // would otherwise survive the renderer's destroy — so a later setVolume()/setSound() call
2077
+ // invokes a stale row updater against already-destroyed Pixi Graphics (or a detached DOM node)
2078
+ // and throws. Run BEFORE the renderer teardown below, while it can still close cleanly.
2079
+ this.closeModal();
1790
2080
  if (typeof document !== 'undefined') {
1791
2081
  this.kbd?.detach();
1792
2082
  document.removeEventListener('pointerdown', this.pullFocus, true);
@@ -1796,6 +2086,64 @@ class ShellController extends EventEmitter {
1796
2086
  }
1797
2087
  }
1798
2088
 
2089
+ /** Geometry for the bar-menu popover. Pure math over rectangles so the DOM and Pixi renderers
2090
+ * place it identically — the renderers only supply measured sizes and apply the result. */
2091
+ const POPOVER = {
2092
+ /** Keep-out from the surface edges. */
2093
+ margin: 8,
2094
+ /** Space between the anchor and the card. */
2095
+ gap: 8,
2096
+ /** Minimum distance from the arrow tip to either rounded corner. */
2097
+ arrowInset: 14,
2098
+ /** A card shorter than this does not fit — flip to the other side instead. */
2099
+ minH: 120,
2100
+ minW: 220,
2101
+ maxW: 320,
2102
+ };
2103
+ const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
2104
+ /** Card width: content width clamped to [minW, maxW] and never wider than the surface. */
2105
+ function popoverWidth(surfaceW, contentW) {
2106
+ const hi = Math.min(POPOVER.maxW, surfaceW - POPOVER.margin * 2);
2107
+ return Math.max(0, clamp(contentW, Math.min(POPOVER.minW, hi), hi));
2108
+ }
2109
+ /** Place the card above the `anchor` (below if it does not fit), left-aligned to it and clamped
2110
+ * inside the surface. `anchor === null` (no bar / hidden shell) centres it, arrow off.
2111
+ *
2112
+ * `anchor` drives PLACEMENT (x, y, maxH, below) — normally the bar's whole plaque ("plate"), so the
2113
+ * card sits flush with the bar as a whole rather than with whichever control opened it. `pointer` is
2114
+ * the (optional) rect the ARROW points at — normally the burger button, which can sit anywhere
2115
+ * inside the plate. Defaults to `anchor` when omitted, so every caller that only ever had one rect
2116
+ * (i.e. every caller before `pointer` existed) keeps behaving exactly as it did before. */
2117
+ function placePopover(anchor, surface, size, pointer = null) {
2118
+ const { margin, gap, arrowInset, minH } = POPOVER;
2119
+ if (!anchor) {
2120
+ const maxH = Math.max(0, surface.h - margin * 2);
2121
+ const h = Math.min(size.h, maxH);
2122
+ const rawY = (surface.h - h) / 2;
2123
+ const y = clamp(rawY, margin, Math.max(margin, surface.h - h - margin));
2124
+ return {
2125
+ x: Math.max(margin, (surface.w - size.w) / 2),
2126
+ y,
2127
+ maxH,
2128
+ arrowX: -1,
2129
+ below: false,
2130
+ };
2131
+ }
2132
+ const spaceAbove = anchor.y - gap - margin;
2133
+ const spaceBelow = surface.h - (anchor.y + anchor.h) - gap - margin;
2134
+ // Prefer above; flip only when the card would be squeezed below its usable minimum AND there is
2135
+ // genuinely more room on the other side.
2136
+ const below = spaceAbove < Math.min(size.h, minH) && spaceBelow > spaceAbove;
2137
+ const maxH = Math.max(0, below ? spaceBelow : spaceAbove);
2138
+ const h = Math.min(size.h, maxH);
2139
+ const x = clamp(anchor.x, margin, Math.max(margin, surface.w - size.w - margin));
2140
+ const rawY = below ? anchor.y + anchor.h + gap : anchor.y - gap - h;
2141
+ const y = clamp(rawY, margin, Math.max(margin, surface.h - h - margin));
2142
+ const arrowAnchor = pointer ?? anchor;
2143
+ const arrowX = clamp(arrowAnchor.x + arrowAnchor.w / 2 - x, arrowInset, Math.max(arrowInset, size.w - arrowInset));
2144
+ return { x, y, maxH, arrowX, below };
2145
+ }
2146
+
1799
2147
  const NO_INSET = { top: 0, right: 0, bottom: 0, left: 0 };
1800
2148
  /** Create a shell with an explicit renderer instance (custom or a built-in HtmlRenderer/PixiRenderer).
1801
2149
  * Built-in renderers also have the createGameShell/createPixiShell sugar in /html and /pixi.
@@ -1814,5 +2162,5 @@ function createShell(opts) {
1814
2162
  return controller;
1815
2163
  }
1816
2164
 
1817
- export { DEFAULT_ACCENT, PACKAGE_VERSION, SCHEMES, ShellController, createI18n, createShell, normalizeLang, resolveConfig, resolveTheme, socialize };
2165
+ export { DEFAULT_ACCENT, DEFAULT_MENU, PACKAGE_VERSION, POPOVER, SCHEMES, ShellController, createI18n, createShell, isPresetId, normalizeLang, placePopover, popoverWidth, rangeBounds, resolveConfig, resolveMenu, resolveTheme, seedMenuValues, socialize };
1818
2166
  //# sourceMappingURL=index.esm.js.map