@flare-engine/ui 0.2.1 → 0.3.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.
package/dist/index.mjs CHANGED
@@ -1,715 +1,790 @@
1
- // src/theme.ts
2
- import { createContext, createElement, useContext } from "react";
3
- var darkTheme = {
4
- name: "dark",
5
- colors: {
6
- bg: "#0b0d10",
7
- surface: "#14181d",
8
- surfaceAlt: "#1d232b",
9
- border: "#2a323c",
10
- text: "#e7ecf1",
11
- textMuted: "#8c96a3",
12
- accent: "#4aa3ff",
13
- accentText: "#0b0d10",
14
- danger: "#ff5c5c",
15
- success: "#5dd39e",
16
- warning: "#f1c40f",
17
- focus: "#ffd166"
18
- },
19
- spacing: { xs: 4, sm: 8, md: 12, lg: 20, xl: 32 },
20
- typography: {
21
- sizeXs: 10,
22
- sizeSm: 12,
23
- sizeMd: 14,
24
- sizeLg: 18,
25
- sizeXl: 24
26
- },
27
- radii: { none: 0, sm: 4, md: 8, lg: 16, pill: 9999 }
1
+ import { Fragment, createContext, createElement, useContext, useEffect, useId, useMemo, useState } from "react";
2
+ import { Pressable, StyleSheet, Text, View } from "react-native";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/focus-context.ts
5
+ const FocusContext = createContext(null);
6
+ function useFocusManager() {
7
+ const ctx = useContext(FocusContext);
8
+ return ctx ? ctx.manager : null;
9
+ }
10
+ function useFocusedId() {
11
+ const ctx = useContext(FocusContext);
12
+ return ctx ? ctx.focusedId : null;
13
+ }
14
+ //#endregion
15
+ //#region src/theme.ts
16
+ const darkTheme = {
17
+ name: "dark",
18
+ colors: {
19
+ bg: "#0b0d10",
20
+ surface: "#14181d",
21
+ surfaceAlt: "#1d232b",
22
+ border: "#2a323c",
23
+ text: "#e7ecf1",
24
+ textMuted: "#8c96a3",
25
+ accent: "#4aa3ff",
26
+ accentText: "#0b0d10",
27
+ danger: "#ff5c5c",
28
+ success: "#5dd39e",
29
+ warning: "#f1c40f",
30
+ focus: "#ffd166"
31
+ },
32
+ spacing: {
33
+ xs: 4,
34
+ sm: 8,
35
+ md: 12,
36
+ lg: 20,
37
+ xl: 32
38
+ },
39
+ typography: {
40
+ sizeXs: 10,
41
+ sizeSm: 12,
42
+ sizeMd: 14,
43
+ sizeLg: 18,
44
+ sizeXl: 24
45
+ },
46
+ radii: {
47
+ none: 0,
48
+ sm: 4,
49
+ md: 8,
50
+ lg: 16,
51
+ pill: 9999
52
+ }
28
53
  };
29
- var lightTheme = {
30
- name: "light",
31
- colors: {
32
- bg: "#f6f8fa",
33
- surface: "#ffffff",
34
- surfaceAlt: "#eef1f4",
35
- border: "#d4dae0",
36
- text: "#13181d",
37
- textMuted: "#5b6670",
38
- accent: "#0a66d0",
39
- accentText: "#ffffff",
40
- danger: "#d12e2e",
41
- success: "#2f9d69",
42
- warning: "#c79600",
43
- focus: "#ff9500"
44
- },
45
- spacing: { xs: 4, sm: 8, md: 12, lg: 20, xl: 32 },
46
- typography: {
47
- sizeXs: 10,
48
- sizeSm: 12,
49
- sizeMd: 14,
50
- sizeLg: 18,
51
- sizeXl: 24
52
- },
53
- radii: { none: 0, sm: 4, md: 8, lg: 16, pill: 9999 }
54
+ const lightTheme = {
55
+ name: "light",
56
+ colors: {
57
+ bg: "#f6f8fa",
58
+ surface: "#ffffff",
59
+ surfaceAlt: "#eef1f4",
60
+ border: "#d4dae0",
61
+ text: "#13181d",
62
+ textMuted: "#5b6670",
63
+ accent: "#0a66d0",
64
+ accentText: "#ffffff",
65
+ danger: "#d12e2e",
66
+ success: "#2f9d69",
67
+ warning: "#c79600",
68
+ focus: "#ff9500"
69
+ },
70
+ spacing: {
71
+ xs: 4,
72
+ sm: 8,
73
+ md: 12,
74
+ lg: 20,
75
+ xl: 32
76
+ },
77
+ typography: {
78
+ sizeXs: 10,
79
+ sizeSm: 12,
80
+ sizeMd: 14,
81
+ sizeLg: 18,
82
+ sizeXl: 24
83
+ },
84
+ radii: {
85
+ none: 0,
86
+ sm: 4,
87
+ md: 8,
88
+ lg: 16,
89
+ pill: 9999
90
+ }
54
91
  };
55
- var ThemeContext = createContext(darkTheme);
92
+ const ThemeContext = createContext(darkTheme);
56
93
  function ThemeProvider({ theme = darkTheme, children }) {
57
- return createElement(ThemeContext.Provider, { value: theme }, children);
94
+ return createElement(ThemeContext.Provider, { value: theme }, children);
58
95
  }
59
96
  function useTheme() {
60
- return useContext(ThemeContext);
97
+ return useContext(ThemeContext);
61
98
  }
62
-
63
- // src/focus.ts
64
- function createFocusManager() {
65
- const nodes = /* @__PURE__ */ new Map();
66
- let seqCounter = 0;
67
- let focusedId = null;
68
- const listeners = /* @__PURE__ */ new Set();
69
- function notify() {
70
- for (const l of listeners) l(focusedId);
71
- }
72
- function orderedIds() {
73
- const entries = Array.from(nodes.values()).filter((e) => !e.disabled);
74
- entries.sort((a, b) => {
75
- if (a.tabIndex !== b.tabIndex) return a.tabIndex - b.tabIndex;
76
- return a.seq - b.seq;
77
- });
78
- return entries.map((e) => e.id);
79
- }
80
- function setFocused(next) {
81
- if (next === focusedId) return;
82
- const prev = focusedId;
83
- focusedId = next;
84
- if (prev !== null) nodes.get(prev)?.onBlur?.();
85
- if (next !== null) nodes.get(next)?.onFocus?.();
86
- notify();
87
- }
88
- function move(delta) {
89
- const order = orderedIds();
90
- if (order.length === 0) {
91
- setFocused(null);
92
- return;
93
- }
94
- if (focusedId === null) {
95
- setFocused(delta === 1 ? order[0] ?? null : order[order.length - 1] ?? null);
96
- return;
97
- }
98
- const idx = order.indexOf(focusedId);
99
- if (idx === -1) {
100
- setFocused(order[0] ?? null);
101
- return;
102
- }
103
- const nextIdx = (idx + delta + order.length) % order.length;
104
- setFocused(order[nextIdx] ?? null);
105
- }
106
- return {
107
- register(node) {
108
- const entry = { ...node, seq: seqCounter++ };
109
- nodes.set(node.id, entry);
110
- if (focusedId === null && !node.disabled) {
111
- setFocused(node.id);
112
- }
113
- return () => {
114
- this.unregister(node.id);
115
- };
116
- },
117
- unregister(id) {
118
- if (!nodes.has(id)) return;
119
- nodes.delete(id);
120
- if (focusedId === id) {
121
- const order = orderedIds();
122
- setFocused(order[0] ?? null);
123
- }
124
- },
125
- focus(id) {
126
- const entry = nodes.get(id);
127
- if (!entry || entry.disabled) return;
128
- setFocused(id);
129
- },
130
- blur() {
131
- setFocused(null);
132
- },
133
- next() {
134
- move(1);
135
- },
136
- prev() {
137
- move(-1);
138
- },
139
- activate() {
140
- if (focusedId === null) return;
141
- nodes.get(focusedId)?.onActivate?.();
142
- },
143
- getFocused() {
144
- return focusedId;
145
- },
146
- getOrder() {
147
- return orderedIds();
148
- },
149
- subscribe(listener) {
150
- listeners.add(listener);
151
- return () => {
152
- listeners.delete(listener);
153
- };
154
- }
155
- };
99
+ //#endregion
100
+ //#region src/button.tsx
101
+ function Button({ label, onPress, variant = "primary", disabled = false, tabIndex = 0, focusId, style }) {
102
+ const theme = useTheme();
103
+ const manager = useFocusManager();
104
+ const focusedId = useFocusedId();
105
+ const generated = useId();
106
+ const id = focusId ?? generated;
107
+ useEffect(() => {
108
+ if (!manager) return;
109
+ return manager.register({
110
+ id,
111
+ tabIndex,
112
+ disabled,
113
+ onActivate: () => {
114
+ if (!disabled) onPress?.();
115
+ }
116
+ });
117
+ }, [
118
+ manager,
119
+ id,
120
+ tabIndex,
121
+ disabled,
122
+ onPress
123
+ ]);
124
+ const focused = focusedId === id;
125
+ let bg = theme.colors.surface;
126
+ let fg = theme.colors.text;
127
+ let border = theme.colors.border;
128
+ switch (variant) {
129
+ case "primary":
130
+ bg = theme.colors.accent;
131
+ fg = theme.colors.accentText;
132
+ border = theme.colors.accent;
133
+ break;
134
+ case "secondary":
135
+ bg = theme.colors.surfaceAlt;
136
+ fg = theme.colors.text;
137
+ border = theme.colors.border;
138
+ break;
139
+ case "ghost":
140
+ bg = "transparent";
141
+ fg = theme.colors.text;
142
+ border = "transparent";
143
+ break;
144
+ case "danger":
145
+ bg = theme.colors.danger;
146
+ fg = theme.colors.accentText;
147
+ border = theme.colors.danger;
148
+ break;
149
+ }
150
+ const container = {
151
+ backgroundColor: bg,
152
+ borderColor: focused ? theme.colors.focus : border,
153
+ borderWidth: focused ? 2 : 1,
154
+ borderRadius: theme.radii.md,
155
+ paddingHorizontal: theme.spacing.md,
156
+ paddingVertical: theme.spacing.sm,
157
+ opacity: disabled ? .5 : 1
158
+ };
159
+ return /* @__PURE__ */ jsx(Pressable, {
160
+ onPress: () => {
161
+ if (disabled) return;
162
+ manager?.focus(id);
163
+ onPress?.();
164
+ },
165
+ disabled,
166
+ accessibilityRole: "button",
167
+ accessibilityLabel: label,
168
+ accessibilityState: {
169
+ disabled,
170
+ selected: focused
171
+ },
172
+ style: [
173
+ styles.wrap,
174
+ container,
175
+ style
176
+ ],
177
+ children: /* @__PURE__ */ jsx(View, { children: /* @__PURE__ */ jsx(Text, {
178
+ style: {
179
+ color: fg,
180
+ fontSize: theme.typography.sizeMd,
181
+ textAlign: "center"
182
+ },
183
+ children: label
184
+ }) })
185
+ });
156
186
  }
157
-
158
- // src/focus-context.ts
159
- import { createContext as createContext2, useContext as useContext2 } from "react";
160
- var FocusContext = createContext2(null);
161
- function useFocusManager() {
162
- return useContext2(FocusContext);
187
+ const styles = StyleSheet.create({ wrap: {
188
+ alignSelf: "stretch",
189
+ alignItems: "center",
190
+ justifyContent: "center"
191
+ } });
192
+ //#endregion
193
+ //#region src/label.tsx
194
+ function Label({ children, variant = "md", tone = "default", mono = false, style, numberOfLines, ellipsizeMode, adjustsFontSizeToFit, minimumFontScale }) {
195
+ const theme = useTheme();
196
+ const sizeMap = {
197
+ xs: theme.typography.sizeXs,
198
+ sm: theme.typography.sizeSm,
199
+ md: theme.typography.sizeMd,
200
+ lg: theme.typography.sizeLg,
201
+ xl: theme.typography.sizeXl
202
+ };
203
+ return /* @__PURE__ */ jsx(Text, {
204
+ numberOfLines,
205
+ ellipsizeMode,
206
+ adjustsFontSizeToFit,
207
+ minimumFontScale,
208
+ style: [{
209
+ color: {
210
+ default: theme.colors.text,
211
+ muted: theme.colors.textMuted,
212
+ accent: theme.colors.accent,
213
+ danger: theme.colors.danger,
214
+ success: theme.colors.success,
215
+ warning: theme.colors.warning
216
+ }[tone],
217
+ fontSize: sizeMap[variant],
218
+ fontFamily: mono ? theme.typography.fontFamilyMono : theme.typography.fontFamily
219
+ }, style],
220
+ children
221
+ });
163
222
  }
164
-
165
- // src/focus-provider.tsx
166
- import { createElement as createElement2, useEffect, useState } from "react";
167
- function FocusProvider({ manager, children }) {
168
- const [mgr] = useState(() => manager ?? createFocusManager());
169
- const [, force] = useState(0);
170
- useEffect(() => {
171
- return mgr.subscribe(() => {
172
- force((n) => n + 1);
173
- });
174
- }, [mgr]);
175
- return createElement2(FocusContext.Provider, { value: mgr }, children);
223
+ //#endregion
224
+ //#region src/panel.tsx
225
+ function Panel({ children, variant = "surface", padding = "md", radius = "md", style }) {
226
+ const theme = useTheme();
227
+ return /* @__PURE__ */ jsx(View, {
228
+ style: [{
229
+ backgroundColor: variant === "elevated" ? theme.colors.surfaceAlt : theme.colors.surface,
230
+ padding: padding === "none" ? 0 : theme.spacing[padding],
231
+ borderRadius: theme.radii[radius],
232
+ borderWidth: variant === "elevated" ? 1 : 0,
233
+ borderColor: theme.colors.border
234
+ }, style],
235
+ children
236
+ });
176
237
  }
177
-
178
- // src/layout.ts
179
- var ZERO_PAD = { top: 0, right: 0, bottom: 0, left: 0 };
180
- function resolvePadding(p) {
181
- if (!p) return ZERO_PAD;
182
- return {
183
- top: p.top ?? 0,
184
- right: p.right ?? 0,
185
- bottom: p.bottom ?? 0,
186
- left: p.left ?? 0
187
- };
238
+ //#endregion
239
+ //#region src/dialogue-panel.tsx
240
+ /**
241
+ * Dialogue panel with a portrait slot. Pairs with `@flare-engine/dialogue`
242
+ * — subscribe to `runner.onLine` and pass `speakerPortraitKey` → your
243
+ * portrait resolver → `portrait` here.
244
+ *
245
+ * Portrait resolution is caller-owned so the UI kit stays asset-agnostic.
246
+ */
247
+ function DialoguePanel({ speaker, text, portrait, choices, onAdvance, style }) {
248
+ const theme = useTheme();
249
+ const body = /* @__PURE__ */ jsxs(View, {
250
+ style: {
251
+ flexDirection: "row",
252
+ alignItems: "flex-start"
253
+ },
254
+ children: [portrait !== void 0 ? /* @__PURE__ */ jsx(View, {
255
+ style: { marginRight: theme.spacing.md },
256
+ children: portrait
257
+ }) : null, /* @__PURE__ */ jsxs(View, {
258
+ style: { flex: 1 },
259
+ children: [
260
+ /* @__PURE__ */ jsx(Label, {
261
+ variant: "sm",
262
+ tone: "accent",
263
+ style: { marginBottom: theme.spacing.xs },
264
+ children: speaker
265
+ }),
266
+ /* @__PURE__ */ jsx(Label, {
267
+ variant: "md",
268
+ children: text
269
+ }),
270
+ choices && choices.length > 0 ? /* @__PURE__ */ jsx(View, {
271
+ style: { marginTop: theme.spacing.md },
272
+ children: choices.map((c, i) => /* @__PURE__ */ jsx(View, {
273
+ style: { marginTop: i === 0 ? 0 : theme.spacing.xs },
274
+ children: /* @__PURE__ */ jsx(Button, {
275
+ label: c.label,
276
+ onPress: c.onPress,
277
+ disabled: c.disabled,
278
+ variant: "secondary"
279
+ })
280
+ }, `${c.label}-${i}`))
281
+ }) : null
282
+ ]
283
+ })]
284
+ });
285
+ if (choices && choices.length > 0) return /* @__PURE__ */ jsx(Panel, {
286
+ variant: "elevated",
287
+ padding: "md",
288
+ style,
289
+ children: body
290
+ });
291
+ return /* @__PURE__ */ jsx(Pressable, {
292
+ onPress: onAdvance,
293
+ children: /* @__PURE__ */ jsx(Panel, {
294
+ variant: "elevated",
295
+ padding: "md",
296
+ style,
297
+ children: body
298
+ })
299
+ });
188
300
  }
189
- function resolveLayout(container, children) {
190
- const n = children.length;
191
- if (n === 0) return [];
192
- const pad = resolvePadding(container.padding);
193
- const gap = container.gap ?? 0;
194
- const isRow = container.direction === "row";
195
- const mainSize = (isRow ? container.width : container.height) - (isRow ? pad.left + pad.right : pad.top + pad.bottom);
196
- const crossSize = (isRow ? container.height : container.width) - (isRow ? pad.top + pad.bottom : pad.left + pad.right);
197
- const mainStart = isRow ? pad.left : pad.top;
198
- const crossStart = isRow ? pad.top : pad.left;
199
- const justify = container.justifyContent ?? "start";
200
- const align = container.alignItems ?? "stretch";
201
- const totalGap = gap * Math.max(0, n - 1);
202
- let totalBasis = 0;
203
- let totalGrow = 0;
204
- for (const c of children) {
205
- totalBasis += c.basis ?? 0;
206
- totalGrow += c.grow ?? 0;
207
- }
208
- const leftover = mainSize - totalBasis - totalGap;
209
- const sizes = new Array(n);
210
- for (let i = 0; i < n; i++) {
211
- const c = children[i];
212
- const base = c.basis ?? 0;
213
- const growShare = totalGrow > 0 ? (c.grow ?? 0) / totalGrow * Math.max(0, leftover) : 0;
214
- sizes[i] = Math.max(0, base + growShare);
215
- }
216
- const used = sizes.reduce((acc, s) => acc + s, 0) + totalGap;
217
- const free = Math.max(0, mainSize - used);
218
- let cursor = mainStart;
219
- let spacing = gap;
220
- switch (justify) {
221
- case "start":
222
- break;
223
- case "end":
224
- cursor = mainStart + free;
225
- break;
226
- case "center":
227
- cursor = mainStart + free / 2;
228
- break;
229
- case "space-between":
230
- if (n > 1) spacing = gap + free / (n - 1);
231
- break;
232
- case "space-around":
233
- if (n > 0) {
234
- const s = free / n;
235
- cursor = mainStart + s / 2;
236
- spacing = gap + s;
237
- }
238
- break;
239
- case "space-evenly":
240
- if (n >= 0) {
241
- const s = free / (n + 1);
242
- cursor = mainStart + s;
243
- spacing = gap + s;
244
- }
245
- break;
246
- }
247
- const out = new Array(n);
248
- for (let i = 0; i < n; i++) {
249
- const c = children[i];
250
- const mainLen = sizes[i];
251
- const crossLen = c.crossSize !== void 0 ? c.crossSize : align === "stretch" ? crossSize : 0;
252
- let crossOffset;
253
- switch (align) {
254
- case "start":
255
- crossOffset = 0;
256
- break;
257
- case "end":
258
- crossOffset = crossSize - crossLen;
259
- break;
260
- case "center":
261
- crossOffset = (crossSize - crossLen) / 2;
262
- break;
263
- case "stretch":
264
- crossOffset = 0;
265
- break;
266
- }
267
- const x = isRow ? cursor : crossStart + crossOffset;
268
- const y = isRow ? crossStart + crossOffset : cursor;
269
- const w = isRow ? mainLen : crossLen;
270
- const h = isRow ? crossLen : mainLen;
271
- out[i] = { x, y, width: w, height: h };
272
- cursor += mainLen + spacing;
273
- }
274
- return out;
301
+ //#endregion
302
+ //#region src/focus.ts
303
+ function createFocusManager() {
304
+ const nodes = /* @__PURE__ */ new Map();
305
+ let seqCounter = 0;
306
+ let focusedId = null;
307
+ const listeners = /* @__PURE__ */ new Set();
308
+ function notify() {
309
+ for (const l of listeners) l(focusedId);
310
+ }
311
+ function orderedIds() {
312
+ const entries = Array.from(nodes.values()).filter((e) => !e.disabled);
313
+ entries.sort((a, b) => {
314
+ if (a.tabIndex !== b.tabIndex) return a.tabIndex - b.tabIndex;
315
+ return a.seq - b.seq;
316
+ });
317
+ return entries.map((e) => e.id);
318
+ }
319
+ function setFocused(next) {
320
+ if (next === focusedId) return;
321
+ const prev = focusedId;
322
+ focusedId = next;
323
+ if (prev !== null) nodes.get(prev)?.onBlur?.();
324
+ if (next !== null) nodes.get(next)?.onFocus?.();
325
+ notify();
326
+ }
327
+ function move(delta) {
328
+ const order = orderedIds();
329
+ if (order.length === 0) {
330
+ setFocused(null);
331
+ return;
332
+ }
333
+ if (focusedId === null) {
334
+ setFocused(delta === 1 ? order[0] ?? null : order[order.length - 1] ?? null);
335
+ return;
336
+ }
337
+ const idx = order.indexOf(focusedId);
338
+ if (idx === -1) {
339
+ setFocused(order[0] ?? null);
340
+ return;
341
+ }
342
+ setFocused(order[(idx + delta + order.length) % order.length] ?? null);
343
+ }
344
+ return {
345
+ register(node) {
346
+ const entry = {
347
+ ...node,
348
+ seq: seqCounter++
349
+ };
350
+ nodes.set(node.id, entry);
351
+ return () => {
352
+ this.unregister(node.id);
353
+ };
354
+ },
355
+ unregister(id) {
356
+ if (!nodes.has(id)) return;
357
+ nodes.delete(id);
358
+ if (focusedId === id) setFocused(orderedIds()[0] ?? null);
359
+ },
360
+ focus(id) {
361
+ const entry = nodes.get(id);
362
+ if (!entry || entry.disabled) return;
363
+ setFocused(id);
364
+ },
365
+ focusFirst() {
366
+ setFocused(orderedIds()[0] ?? null);
367
+ },
368
+ blur() {
369
+ setFocused(null);
370
+ },
371
+ next() {
372
+ move(1);
373
+ },
374
+ prev() {
375
+ move(-1);
376
+ },
377
+ activate() {
378
+ if (focusedId === null) return;
379
+ nodes.get(focusedId)?.onActivate?.();
380
+ },
381
+ getFocused() {
382
+ return focusedId;
383
+ },
384
+ getOrder() {
385
+ return orderedIds();
386
+ },
387
+ subscribe(listener) {
388
+ listeners.add(listener);
389
+ return () => {
390
+ listeners.delete(listener);
391
+ };
392
+ }
393
+ };
275
394
  }
276
-
277
- // src/panel.tsx
278
- import { View } from "react-native";
279
- import { jsx } from "react/jsx-runtime";
280
- function Panel({
281
- children,
282
- variant = "surface",
283
- padding = "md",
284
- radius = "md",
285
- style
286
- }) {
287
- const theme = useTheme();
288
- const bg = variant === "elevated" ? theme.colors.surfaceAlt : theme.colors.surface;
289
- const pad = padding === "none" ? 0 : theme.spacing[padding];
290
- const r = theme.radii[radius];
291
- const base = {
292
- backgroundColor: bg,
293
- padding: pad,
294
- borderRadius: r,
295
- borderWidth: variant === "elevated" ? 1 : 0,
296
- borderColor: theme.colors.border
297
- };
298
- return /* @__PURE__ */ jsx(View, { style: [base, style], children });
395
+ //#endregion
396
+ //#region src/focus-keyboard-driver.ts
397
+ const DEFAULT_NEXT = [
398
+ "ArrowDown",
399
+ "ArrowRight",
400
+ "Tab"
401
+ ];
402
+ const DEFAULT_PREV = ["ArrowUp", "ArrowLeft"];
403
+ const DEFAULT_ACTIVATE = ["Enter", "Space"];
404
+ function createFocusKeyboardDriver(manager, keys, options) {
405
+ const nextCodes = options?.next ?? DEFAULT_NEXT;
406
+ const prevCodes = options?.prev ?? DEFAULT_PREV;
407
+ const activateCodes = options?.activate ?? DEFAULT_ACTIVATE;
408
+ return { update() {
409
+ for (let i = 0; i < nextCodes.length; i++) if (keys.wasPressed(nextCodes[i])) {
410
+ manager.next();
411
+ return;
412
+ }
413
+ for (let i = 0; i < prevCodes.length; i++) if (keys.wasPressed(prevCodes[i])) {
414
+ manager.prev();
415
+ return;
416
+ }
417
+ for (let i = 0; i < activateCodes.length; i++) if (keys.wasPressed(activateCodes[i])) {
418
+ manager.activate();
419
+ return;
420
+ }
421
+ } };
299
422
  }
300
-
301
- // src/label.tsx
302
- import { Text } from "react-native";
303
- import { jsx as jsx2 } from "react/jsx-runtime";
304
- function Label({
305
- children,
306
- variant = "md",
307
- tone = "default",
308
- mono = false,
309
- style
310
- }) {
311
- const theme = useTheme();
312
- const sizeMap = {
313
- xs: theme.typography.sizeXs,
314
- sm: theme.typography.sizeSm,
315
- md: theme.typography.sizeMd,
316
- lg: theme.typography.sizeLg,
317
- xl: theme.typography.sizeXl
318
- };
319
- const toneMap = {
320
- default: theme.colors.text,
321
- muted: theme.colors.textMuted,
322
- accent: theme.colors.accent,
323
- danger: theme.colors.danger,
324
- success: theme.colors.success,
325
- warning: theme.colors.warning
326
- };
327
- const base = {
328
- color: toneMap[tone],
329
- fontSize: sizeMap[variant],
330
- fontFamily: mono ? theme.typography.fontFamilyMono : theme.typography.fontFamily
331
- };
332
- return /* @__PURE__ */ jsx2(Text, { style: [base, style], children });
423
+ //#endregion
424
+ //#region src/focus-provider.tsx
425
+ /**
426
+ * Instantiates a FocusManager (or uses the one provided) and publishes
427
+ * { manager, focusedId } as context state so consumers re-render on focus
428
+ * moves.
429
+ */
430
+ function FocusProvider({ manager, autoFocus, children }) {
431
+ const [mgr] = useState(() => manager ?? createFocusManager());
432
+ const [focusedId, setFocusedId] = useState(() => mgr.getFocused());
433
+ useEffect(() => {
434
+ setFocusedId(mgr.getFocused());
435
+ return mgr.subscribe((id) => {
436
+ setFocusedId(id);
437
+ });
438
+ }, [mgr]);
439
+ useEffect(() => {
440
+ if (autoFocus && mgr.getFocused() === null) mgr.focusFirst();
441
+ }, [autoFocus, mgr]);
442
+ const value = useMemo(() => ({
443
+ manager: mgr,
444
+ focusedId
445
+ }), [mgr, focusedId]);
446
+ return createElement(FocusContext.Provider, { value }, children);
333
447
  }
334
-
335
- // src/button.tsx
336
- import { useEffect as useEffect2, useId } from "react";
337
- import { Pressable, StyleSheet, Text as Text2, View as View2 } from "react-native";
338
- import { jsx as jsx3 } from "react/jsx-runtime";
339
- function Button({
340
- label,
341
- onPress,
342
- variant = "primary",
343
- disabled = false,
344
- tabIndex = 0,
345
- focusId,
346
- style
347
- }) {
348
- const theme = useTheme();
349
- const manager = useFocusManager();
350
- const generated = useId();
351
- const id = focusId ?? generated;
352
- useEffect2(() => {
353
- if (!manager) return;
354
- return manager.register({
355
- id,
356
- tabIndex,
357
- disabled,
358
- onActivate: () => {
359
- if (!disabled) onPress?.();
360
- }
361
- });
362
- }, [manager, id, tabIndex, disabled, onPress]);
363
- const focused = manager?.getFocused() === id;
364
- let bg = theme.colors.surface;
365
- let fg = theme.colors.text;
366
- let border = theme.colors.border;
367
- switch (variant) {
368
- case "primary":
369
- bg = theme.colors.accent;
370
- fg = theme.colors.accentText;
371
- border = theme.colors.accent;
372
- break;
373
- case "secondary":
374
- bg = theme.colors.surfaceAlt;
375
- fg = theme.colors.text;
376
- border = theme.colors.border;
377
- break;
378
- case "ghost":
379
- bg = "transparent";
380
- fg = theme.colors.text;
381
- border = "transparent";
382
- break;
383
- case "danger":
384
- bg = theme.colors.danger;
385
- fg = theme.colors.accentText;
386
- border = theme.colors.danger;
387
- break;
388
- }
389
- const container = {
390
- backgroundColor: bg,
391
- borderColor: focused ? theme.colors.focus : border,
392
- borderWidth: focused ? 2 : 1,
393
- borderRadius: theme.radii.md,
394
- paddingHorizontal: theme.spacing.md,
395
- paddingVertical: theme.spacing.sm,
396
- opacity: disabled ? 0.5 : 1
397
- };
398
- return /* @__PURE__ */ jsx3(
399
- Pressable,
400
- {
401
- onPress: () => {
402
- if (disabled) return;
403
- manager?.focus(id);
404
- onPress?.();
405
- },
406
- disabled,
407
- accessibilityRole: "button",
408
- accessibilityLabel: label,
409
- accessibilityState: { disabled, selected: focused },
410
- style: [styles.wrap, container, style],
411
- children: /* @__PURE__ */ jsx3(View2, { children: /* @__PURE__ */ jsx3(Text2, { style: { color: fg, fontSize: theme.typography.sizeMd, textAlign: "center" }, children: label }) })
412
- }
413
- );
448
+ //#endregion
449
+ //#region src/progress-bar.tsx
450
+ function ProgressBar({ value, height = 8, trackColor, fillColor, style }) {
451
+ const theme = useTheme();
452
+ const clamped = Number.isNaN(value) ? 0 : Math.max(0, Math.min(1, value));
453
+ const r = theme.radii.sm;
454
+ return /* @__PURE__ */ jsx(View, {
455
+ style: [{
456
+ height,
457
+ borderRadius: r,
458
+ backgroundColor: trackColor ?? theme.colors.surfaceAlt,
459
+ overflow: "hidden"
460
+ }, style],
461
+ children: /* @__PURE__ */ jsx(View, { style: {
462
+ width: `${clamped * 100}%`,
463
+ height: "100%",
464
+ backgroundColor: fillColor ?? theme.colors.accent
465
+ } })
466
+ });
414
467
  }
415
- var styles = StyleSheet.create({
416
- wrap: {
417
- alignSelf: "stretch",
418
- alignItems: "center",
419
- justifyContent: "center"
420
- }
421
- });
422
-
423
- // src/progress-bar.tsx
424
- import { View as View3 } from "react-native";
425
- import { jsx as jsx4 } from "react/jsx-runtime";
426
- function ProgressBar({
427
- value,
428
- height = 8,
429
- trackColor,
430
- fillColor,
431
- style
432
- }) {
433
- const theme = useTheme();
434
- const clamped = Number.isNaN(value) ? 0 : Math.max(0, Math.min(1, value));
435
- const r = theme.radii.sm;
436
- return /* @__PURE__ */ jsx4(
437
- View3,
438
- {
439
- style: [
440
- {
441
- height,
442
- borderRadius: r,
443
- backgroundColor: trackColor ?? theme.colors.surfaceAlt,
444
- overflow: "hidden"
445
- },
446
- style
447
- ],
448
- children: /* @__PURE__ */ jsx4(
449
- View3,
450
- {
451
- style: {
452
- width: `${clamped * 100}%`,
453
- height: "100%",
454
- backgroundColor: fillColor ?? theme.colors.accent
455
- }
456
- }
457
- )
458
- }
459
- );
468
+ //#endregion
469
+ //#region src/hud-bar.tsx
470
+ function HUDBar({ label, value, max, kind = "custom", showNumbers = true, fillColor }) {
471
+ const theme = useTheme();
472
+ const ratio = max <= 0 ? 0 : value / max;
473
+ let color = fillColor;
474
+ if (!color) switch (kind) {
475
+ case "hp":
476
+ color = theme.colors.danger;
477
+ break;
478
+ case "mp":
479
+ color = theme.colors.accent;
480
+ break;
481
+ case "xp":
482
+ color = theme.colors.success;
483
+ break;
484
+ default: color = theme.colors.accent;
485
+ }
486
+ return /* @__PURE__ */ jsxs(View, { children: [/* @__PURE__ */ jsxs(View, {
487
+ style: {
488
+ flexDirection: "row",
489
+ justifyContent: "space-between",
490
+ marginBottom: theme.spacing.xs
491
+ },
492
+ children: [/* @__PURE__ */ jsx(Label, {
493
+ variant: "sm",
494
+ tone: "muted",
495
+ children: label
496
+ }), showNumbers && /* @__PURE__ */ jsx(Label, {
497
+ variant: "sm",
498
+ tone: "muted",
499
+ mono: true,
500
+ children: `${Math.max(0, Math.floor(value))} / ${Math.max(0, Math.floor(max))}`
501
+ })]
502
+ }), /* @__PURE__ */ jsx(ProgressBar, {
503
+ value: ratio,
504
+ fillColor: color
505
+ })] });
460
506
  }
461
-
462
- // src/hud-bar.tsx
463
- import { View as View4 } from "react-native";
464
- import { jsx as jsx5, jsxs } from "react/jsx-runtime";
465
- function HUDBar({
466
- label,
467
- value,
468
- max,
469
- kind = "custom",
470
- showNumbers = true,
471
- fillColor
472
- }) {
473
- const theme = useTheme();
474
- const ratio = max <= 0 ? 0 : value / max;
475
- let color = fillColor;
476
- if (!color) {
477
- switch (kind) {
478
- case "hp":
479
- color = theme.colors.danger;
480
- break;
481
- case "mp":
482
- color = theme.colors.accent;
483
- break;
484
- case "xp":
485
- color = theme.colors.success;
486
- break;
487
- default:
488
- color = theme.colors.accent;
489
- }
490
- }
491
- return /* @__PURE__ */ jsxs(View4, { children: [
492
- /* @__PURE__ */ jsxs(
493
- View4,
494
- {
495
- style: {
496
- flexDirection: "row",
497
- justifyContent: "space-between",
498
- marginBottom: theme.spacing.xs
499
- },
500
- children: [
501
- /* @__PURE__ */ jsx5(Label, { variant: "sm", tone: "muted", children: label }),
502
- showNumbers && /* @__PURE__ */ jsx5(Label, { variant: "sm", tone: "muted", mono: true, children: `${Math.max(0, Math.floor(value))} / ${Math.max(0, Math.floor(max))}` })
503
- ]
504
- }
505
- ),
506
- /* @__PURE__ */ jsx5(ProgressBar, { value: ratio, fillColor: color })
507
- ] });
507
+ //#endregion
508
+ //#region src/layout.ts
509
+ const ZERO_PAD = {
510
+ top: 0,
511
+ right: 0,
512
+ bottom: 0,
513
+ left: 0
514
+ };
515
+ function resolvePadding(p) {
516
+ if (!p) return ZERO_PAD;
517
+ return {
518
+ top: p.top ?? 0,
519
+ right: p.right ?? 0,
520
+ bottom: p.bottom ?? 0,
521
+ left: p.left ?? 0
522
+ };
508
523
  }
509
-
510
- // src/list.tsx
511
- import { Fragment } from "react";
512
- import { View as View5 } from "react-native";
513
- import { jsx as jsx6 } from "react/jsx-runtime";
524
+ function resolveLayout(container, children) {
525
+ const n = children.length;
526
+ if (n === 0) return [];
527
+ const pad = resolvePadding(container.padding);
528
+ const gap = container.gap ?? 0;
529
+ const isRow = container.direction === "row";
530
+ const mainSize = (isRow ? container.width : container.height) - (isRow ? pad.left + pad.right : pad.top + pad.bottom);
531
+ const crossSize = (isRow ? container.height : container.width) - (isRow ? pad.top + pad.bottom : pad.left + pad.right);
532
+ const mainStart = isRow ? pad.left : pad.top;
533
+ const crossStart = isRow ? pad.top : pad.left;
534
+ const justify = container.justifyContent ?? "start";
535
+ const align = container.alignItems ?? "stretch";
536
+ const totalGap = gap * Math.max(0, n - 1);
537
+ let totalBasis = 0;
538
+ let totalGrow = 0;
539
+ for (const c of children) {
540
+ totalBasis += c.basis ?? 0;
541
+ totalGrow += c.grow ?? 0;
542
+ }
543
+ const leftover = mainSize - totalBasis - totalGap;
544
+ const sizes = new Array(n);
545
+ for (let i = 0; i < n; i++) {
546
+ const c = children[i];
547
+ const base = c.basis ?? 0;
548
+ const growShare = totalGrow > 0 ? (c.grow ?? 0) / totalGrow * Math.max(0, leftover) : 0;
549
+ sizes[i] = Math.max(0, base + growShare);
550
+ }
551
+ const used = sizes.reduce((acc, s) => acc + s, 0) + totalGap;
552
+ const free = Math.max(0, mainSize - used);
553
+ let cursor = mainStart;
554
+ let spacing = gap;
555
+ switch (justify) {
556
+ case "start": break;
557
+ case "end":
558
+ cursor = mainStart + free;
559
+ break;
560
+ case "center":
561
+ cursor = mainStart + free / 2;
562
+ break;
563
+ case "space-between":
564
+ if (n > 1) spacing = gap + free / (n - 1);
565
+ break;
566
+ case "space-around":
567
+ if (n > 0) {
568
+ const s = free / n;
569
+ cursor = mainStart + s / 2;
570
+ spacing = gap + s;
571
+ }
572
+ break;
573
+ case "space-evenly":
574
+ if (n >= 0) {
575
+ const s = free / (n + 1);
576
+ cursor = mainStart + s;
577
+ spacing = gap + s;
578
+ }
579
+ break;
580
+ }
581
+ const out = new Array(n);
582
+ for (let i = 0; i < n; i++) {
583
+ const c = children[i];
584
+ const mainLen = sizes[i];
585
+ const crossLen = c.crossSize !== void 0 ? c.crossSize : align === "stretch" ? crossSize : 0;
586
+ let crossOffset;
587
+ switch (align) {
588
+ case "start":
589
+ crossOffset = 0;
590
+ break;
591
+ case "end":
592
+ crossOffset = crossSize - crossLen;
593
+ break;
594
+ case "center":
595
+ crossOffset = (crossSize - crossLen) / 2;
596
+ break;
597
+ case "stretch":
598
+ crossOffset = 0;
599
+ break;
600
+ }
601
+ out[i] = {
602
+ x: isRow ? cursor : crossStart + crossOffset,
603
+ y: isRow ? crossStart + crossOffset : cursor,
604
+ width: isRow ? mainLen : crossLen,
605
+ height: isRow ? crossLen : mainLen
606
+ };
607
+ cursor += mainLen + spacing;
608
+ }
609
+ return out;
610
+ }
611
+ //#endregion
612
+ //#region src/list.tsx
613
+ /**
614
+ * Vertical (or horizontal) stack with consistent gap. Thin container; the
615
+ * focus manager handles navigation between interactive children.
616
+ */
514
617
  function List({ children, gap, direction = "column", style }) {
515
- const theme = useTheme();
516
- const g = gap ?? theme.spacing.sm;
517
- const items = [];
518
- let i = 0;
519
- const flat = Array.isArray(children) ? children : [children];
520
- for (const child of flat) {
521
- if (child === null || child === void 0 || child === false) continue;
522
- if (i > 0) {
523
- const spacerStyle = direction === "row" ? { width: g } : { height: g };
524
- items.push(/* @__PURE__ */ jsx6(View5, { style: spacerStyle }, `s-${i}`));
525
- }
526
- items.push(/* @__PURE__ */ jsx6(Fragment, { children: child }, `i-${i}`));
527
- i++;
528
- }
529
- return /* @__PURE__ */ jsx6(View5, { style: [{ flexDirection: direction }, style], children: items });
618
+ const theme = useTheme();
619
+ const g = gap ?? theme.spacing.sm;
620
+ const items = [];
621
+ let i = 0;
622
+ const flat = Array.isArray(children) ? children : [children];
623
+ for (const child of flat) {
624
+ if (child === null || child === void 0 || child === false) continue;
625
+ if (i > 0) {
626
+ const spacerStyle = direction === "row" ? { width: g } : { height: g };
627
+ items.push(/* @__PURE__ */ jsx(View, { style: spacerStyle }, `s-${i}`));
628
+ }
629
+ items.push(/* @__PURE__ */ jsx(Fragment, { children: child }, `i-${i}`));
630
+ i++;
631
+ }
632
+ return /* @__PURE__ */ jsx(View, {
633
+ style: [{ flexDirection: direction }, style],
634
+ children: items
635
+ });
530
636
  }
531
-
532
- // src/modal.tsx
533
- import { Pressable as Pressable2, View as View6 } from "react-native";
534
- import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
535
- function Modal({
536
- visible,
537
- children,
538
- onBackdropPress,
539
- backdropOpacity = 0.6
540
- }) {
541
- if (!visible) return null;
542
- return /* @__PURE__ */ jsxs2(
543
- View6,
544
- {
545
- style: {
546
- position: "absolute",
547
- top: 0,
548
- left: 0,
549
- right: 0,
550
- bottom: 0,
551
- alignItems: "center",
552
- justifyContent: "center"
553
- },
554
- pointerEvents: "box-none",
555
- children: [
556
- /* @__PURE__ */ jsx7(
557
- Pressable2,
558
- {
559
- onPress: onBackdropPress,
560
- style: {
561
- position: "absolute",
562
- top: 0,
563
- left: 0,
564
- right: 0,
565
- bottom: 0,
566
- backgroundColor: `rgba(0,0,0,${backdropOpacity})`
567
- }
568
- }
569
- ),
570
- /* @__PURE__ */ jsx7(Panel, { variant: "elevated", padding: "lg", style: { minWidth: 240, maxWidth: "80%" }, children })
571
- ]
572
- }
573
- );
637
+ //#endregion
638
+ //#region src/main-menu-kit.tsx
639
+ /**
640
+ * Title-screen kit: headline, optional subtitle, vertical button list,
641
+ * optional footer slot. All strings are caller-supplied (localized upstream).
642
+ *
643
+ * Save-slot / settings / credits panels are built on top of this kit by the
644
+ * consumer; the kit itself is a pure title-menu primitive.
645
+ */
646
+ function MainMenuKit({ title, subtitle, items, footer, style }) {
647
+ const theme = useTheme();
648
+ return /* @__PURE__ */ jsxs(View, {
649
+ style: [{
650
+ flex: 1,
651
+ alignItems: "center",
652
+ justifyContent: "center",
653
+ padding: theme.spacing.lg
654
+ }, style],
655
+ children: [
656
+ /* @__PURE__ */ jsx(Label, {
657
+ variant: "xl",
658
+ tone: "accent",
659
+ style: { marginBottom: theme.spacing.xs },
660
+ children: title
661
+ }),
662
+ subtitle !== void 0 ? /* @__PURE__ */ jsx(Label, {
663
+ variant: "sm",
664
+ tone: "muted",
665
+ style: { marginBottom: theme.spacing.lg },
666
+ children: subtitle
667
+ }) : /* @__PURE__ */ jsx(View, { style: { height: theme.spacing.lg } }),
668
+ /* @__PURE__ */ jsx(View, {
669
+ style: {
670
+ alignSelf: "stretch",
671
+ maxWidth: 320,
672
+ width: "100%"
673
+ },
674
+ children: items.map((item, i) => /* @__PURE__ */ jsx(View, {
675
+ style: { marginTop: i === 0 ? 0 : theme.spacing.sm },
676
+ children: /* @__PURE__ */ jsx(Button, {
677
+ label: item.label,
678
+ onPress: item.onPress,
679
+ variant: item.variant ?? "primary",
680
+ disabled: item.disabled,
681
+ focusId: item.id,
682
+ tabIndex: i
683
+ })
684
+ }, item.id))
685
+ }),
686
+ footer !== void 0 ? /* @__PURE__ */ jsx(View, {
687
+ style: { marginTop: theme.spacing.lg },
688
+ children: footer
689
+ }) : null
690
+ ]
691
+ });
574
692
  }
575
-
576
- // src/dialogue-panel.tsx
577
- import { Pressable as Pressable3, View as View7 } from "react-native";
578
- import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
579
- function DialoguePanel({
580
- speaker,
581
- text,
582
- portrait,
583
- choices,
584
- onAdvance,
585
- style
586
- }) {
587
- const theme = useTheme();
588
- const body = /* @__PURE__ */ jsxs3(View7, { style: { flexDirection: "row", alignItems: "flex-start" }, children: [
589
- portrait !== void 0 ? /* @__PURE__ */ jsx8(View7, { style: { marginRight: theme.spacing.md }, children: portrait }) : null,
590
- /* @__PURE__ */ jsxs3(View7, { style: { flex: 1 }, children: [
591
- /* @__PURE__ */ jsx8(Label, { variant: "sm", tone: "accent", style: { marginBottom: theme.spacing.xs }, children: speaker }),
592
- /* @__PURE__ */ jsx8(Label, { variant: "md", children: text }),
593
- choices && choices.length > 0 ? /* @__PURE__ */ jsx8(View7, { style: { marginTop: theme.spacing.md }, children: choices.map((c, i) => /* @__PURE__ */ jsx8(View7, { style: { marginTop: i === 0 ? 0 : theme.spacing.xs }, children: /* @__PURE__ */ jsx8(
594
- Button,
595
- {
596
- label: c.label,
597
- onPress: c.onPress,
598
- disabled: c.disabled,
599
- variant: "secondary"
600
- }
601
- ) }, `${c.label}-${i}`)) }) : null
602
- ] })
603
- ] });
604
- if (choices && choices.length > 0) {
605
- return /* @__PURE__ */ jsx8(Panel, { variant: "elevated", padding: "md", style, children: body });
606
- }
607
- return /* @__PURE__ */ jsx8(Pressable3, { onPress: onAdvance, children: /* @__PURE__ */ jsx8(Panel, { variant: "elevated", padding: "md", style, children: body }) });
693
+ //#endregion
694
+ //#region src/modal.tsx
695
+ /**
696
+ * Overlay modal that renders a centered `Panel` with its children. Parent is
697
+ * responsible for controlling visibility and (if desired) focus trapping via
698
+ * the shared FocusManager.
699
+ */
700
+ function Modal({ visible, children, onBackdropPress, backdropOpacity = .6 }) {
701
+ if (!visible) return null;
702
+ return /* @__PURE__ */ jsxs(View, {
703
+ style: {
704
+ position: "absolute",
705
+ top: 0,
706
+ left: 0,
707
+ right: 0,
708
+ bottom: 0,
709
+ alignItems: "center",
710
+ justifyContent: "center"
711
+ },
712
+ pointerEvents: "box-none",
713
+ children: [/* @__PURE__ */ jsx(Pressable, {
714
+ onPress: onBackdropPress,
715
+ style: {
716
+ position: "absolute",
717
+ top: 0,
718
+ left: 0,
719
+ right: 0,
720
+ bottom: 0,
721
+ backgroundColor: `rgba(0,0,0,${backdropOpacity})`
722
+ }
723
+ }), /* @__PURE__ */ jsx(Panel, {
724
+ variant: "elevated",
725
+ padding: "lg",
726
+ style: {
727
+ minWidth: 240,
728
+ maxWidth: "80%"
729
+ },
730
+ children
731
+ })]
732
+ });
608
733
  }
609
-
610
- // src/shop-panel.tsx
611
- import { View as View8 } from "react-native";
612
- import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
613
- function ShopPanel({
614
- items,
615
- isEntitled,
616
- onPurchase,
617
- ownedLabel = "Owned",
618
- purchaseLabelFor,
619
- style
620
- }) {
621
- const theme = useTheme();
622
- return /* @__PURE__ */ jsx9(Panel, { variant: "elevated", padding: "md", style, children: items.map((item, i) => {
623
- const owned = item.ownedKeys?.some((k) => isEntitled(k)) ?? false;
624
- return /* @__PURE__ */ jsxs4(
625
- View8,
626
- {
627
- style: {
628
- marginTop: i === 0 ? 0 : theme.spacing.md,
629
- paddingTop: i === 0 ? 0 : theme.spacing.md,
630
- borderTopWidth: i === 0 ? 0 : 1,
631
- borderTopColor: theme.colors.border
632
- },
633
- children: [
634
- /* @__PURE__ */ jsx9(Label, { variant: "md", children: item.title }),
635
- item.description !== void 0 ? /* @__PURE__ */ jsx9(Label, { variant: "sm", tone: "muted", style: { marginTop: theme.spacing.xs }, children: item.description }) : null,
636
- /* @__PURE__ */ jsx9(View8, { style: { marginTop: theme.spacing.sm }, children: owned ? /* @__PURE__ */ jsx9(Button, { label: ownedLabel, variant: "ghost", disabled: true }) : /* @__PURE__ */ jsx9(
637
- Button,
638
- {
639
- label: purchaseLabelFor ? purchaseLabelFor(item) : item.priceDisplay,
640
- variant: "primary",
641
- disabled: item.disabled,
642
- onPress: () => onPurchase(item.productId)
643
- }
644
- ) })
645
- ]
646
- },
647
- item.productId
648
- );
649
- }) });
734
+ //#endregion
735
+ //#region src/shop-panel.tsx
736
+ /**
737
+ * List-style shop panel. Caller builds the `items` array by joining a
738
+ * `ProductCatalog` with the `Product[]` returned by `IAPProvider.getProducts`.
739
+ *
740
+ * Price strings and ownership copy are caller-provided so the UI kit stays
741
+ * localization-free.
742
+ */
743
+ function ShopPanel({ items, isEntitled, onPurchase, ownedLabel = "Owned", purchaseLabelFor, style }) {
744
+ const theme = useTheme();
745
+ return /* @__PURE__ */ jsx(Panel, {
746
+ variant: "elevated",
747
+ padding: "md",
748
+ style,
749
+ children: items.map((item, i) => {
750
+ const owned = item.ownedKeys?.some((k) => isEntitled(k)) ?? false;
751
+ return /* @__PURE__ */ jsxs(View, {
752
+ style: {
753
+ marginTop: i === 0 ? 0 : theme.spacing.md,
754
+ paddingTop: i === 0 ? 0 : theme.spacing.md,
755
+ borderTopWidth: i === 0 ? 0 : 1,
756
+ borderTopColor: theme.colors.border
757
+ },
758
+ children: [
759
+ /* @__PURE__ */ jsx(Label, {
760
+ variant: "md",
761
+ children: item.title
762
+ }),
763
+ item.description !== void 0 ? /* @__PURE__ */ jsx(Label, {
764
+ variant: "sm",
765
+ tone: "muted",
766
+ style: { marginTop: theme.spacing.xs },
767
+ children: item.description
768
+ }) : null,
769
+ /* @__PURE__ */ jsx(View, {
770
+ style: { marginTop: theme.spacing.sm },
771
+ children: owned ? /* @__PURE__ */ jsx(Button, {
772
+ label: ownedLabel,
773
+ variant: "ghost",
774
+ disabled: true
775
+ }) : /* @__PURE__ */ jsx(Button, {
776
+ label: purchaseLabelFor ? purchaseLabelFor(item) : item.priceDisplay,
777
+ variant: "primary",
778
+ disabled: item.disabled,
779
+ onPress: () => onPurchase(item.productId)
780
+ })
781
+ })
782
+ ]
783
+ }, item.productId);
784
+ })
785
+ });
650
786
  }
787
+ //#endregion
788
+ export { Button, DialoguePanel, FocusContext, FocusProvider, HUDBar, Label, List, MainMenuKit, Modal, Panel, ProgressBar, ShopPanel, ThemeProvider, createFocusKeyboardDriver, createFocusManager, darkTheme, lightTheme, resolveLayout, useFocusManager, useFocusedId, useTheme };
651
789
 
652
- // src/main-menu-kit.tsx
653
- import { View as View9 } from "react-native";
654
- import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
655
- function MainMenuKit({
656
- title,
657
- subtitle,
658
- items,
659
- footer,
660
- style
661
- }) {
662
- const theme = useTheme();
663
- return /* @__PURE__ */ jsxs5(
664
- View9,
665
- {
666
- style: [
667
- {
668
- flex: 1,
669
- alignItems: "center",
670
- justifyContent: "center",
671
- padding: theme.spacing.lg
672
- },
673
- style
674
- ],
675
- children: [
676
- /* @__PURE__ */ jsx10(Label, { variant: "xl", tone: "accent", style: { marginBottom: theme.spacing.xs }, children: title }),
677
- subtitle !== void 0 ? /* @__PURE__ */ jsx10(Label, { variant: "sm", tone: "muted", style: { marginBottom: theme.spacing.lg }, children: subtitle }) : /* @__PURE__ */ jsx10(View9, { style: { height: theme.spacing.lg } }),
678
- /* @__PURE__ */ jsx10(View9, { style: { alignSelf: "stretch", maxWidth: 320, width: "100%" }, children: items.map((item, i) => /* @__PURE__ */ jsx10(View9, { style: { marginTop: i === 0 ? 0 : theme.spacing.sm }, children: /* @__PURE__ */ jsx10(
679
- Button,
680
- {
681
- label: item.label,
682
- onPress: item.onPress,
683
- variant: item.variant ?? "primary",
684
- disabled: item.disabled,
685
- focusId: item.id,
686
- tabIndex: i
687
- }
688
- ) }, item.id)) }),
689
- footer !== void 0 ? /* @__PURE__ */ jsx10(View9, { style: { marginTop: theme.spacing.lg }, children: footer }) : null
690
- ]
691
- }
692
- );
693
- }
694
- export {
695
- Button,
696
- DialoguePanel,
697
- FocusContext,
698
- FocusProvider,
699
- HUDBar,
700
- Label,
701
- List,
702
- MainMenuKit,
703
- Modal,
704
- Panel,
705
- ProgressBar,
706
- ShopPanel,
707
- ThemeProvider,
708
- createFocusManager,
709
- darkTheme,
710
- lightTheme,
711
- resolveLayout,
712
- useFocusManager,
713
- useTheme
714
- };
715
790
  //# sourceMappingURL=index.mjs.map