@flare-engine/ui 0.2.0 → 0.3.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.
package/dist/index.mjs CHANGED
@@ -1,715 +1,786 @@
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 }) {
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
+ style: [{
205
+ color: {
206
+ default: theme.colors.text,
207
+ muted: theme.colors.textMuted,
208
+ accent: theme.colors.accent,
209
+ danger: theme.colors.danger,
210
+ success: theme.colors.success,
211
+ warning: theme.colors.warning
212
+ }[tone],
213
+ fontSize: sizeMap[variant],
214
+ fontFamily: mono ? theme.typography.fontFamilyMono : theme.typography.fontFamily
215
+ }, style],
216
+ children
217
+ });
163
218
  }
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);
219
+ //#endregion
220
+ //#region src/panel.tsx
221
+ function Panel({ children, variant = "surface", padding = "md", radius = "md", style }) {
222
+ const theme = useTheme();
223
+ return /* @__PURE__ */ jsx(View, {
224
+ style: [{
225
+ backgroundColor: variant === "elevated" ? theme.colors.surfaceAlt : theme.colors.surface,
226
+ padding: padding === "none" ? 0 : theme.spacing[padding],
227
+ borderRadius: theme.radii[radius],
228
+ borderWidth: variant === "elevated" ? 1 : 0,
229
+ borderColor: theme.colors.border
230
+ }, style],
231
+ children
232
+ });
176
233
  }
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
- };
234
+ //#endregion
235
+ //#region src/dialogue-panel.tsx
236
+ /**
237
+ * Dialogue panel with a portrait slot. Pairs with `@flare-engine/dialogue`
238
+ * — subscribe to `runner.onLine` and pass `speakerPortraitKey` → your
239
+ * portrait resolver → `portrait` here.
240
+ *
241
+ * Portrait resolution is caller-owned so the UI kit stays asset-agnostic.
242
+ */
243
+ function DialoguePanel({ speaker, text, portrait, choices, onAdvance, style }) {
244
+ const theme = useTheme();
245
+ const body = /* @__PURE__ */ jsxs(View, {
246
+ style: {
247
+ flexDirection: "row",
248
+ alignItems: "flex-start"
249
+ },
250
+ children: [portrait !== void 0 ? /* @__PURE__ */ jsx(View, {
251
+ style: { marginRight: theme.spacing.md },
252
+ children: portrait
253
+ }) : null, /* @__PURE__ */ jsxs(View, {
254
+ style: { flex: 1 },
255
+ children: [
256
+ /* @__PURE__ */ jsx(Label, {
257
+ variant: "sm",
258
+ tone: "accent",
259
+ style: { marginBottom: theme.spacing.xs },
260
+ children: speaker
261
+ }),
262
+ /* @__PURE__ */ jsx(Label, {
263
+ variant: "md",
264
+ children: text
265
+ }),
266
+ choices && choices.length > 0 ? /* @__PURE__ */ jsx(View, {
267
+ style: { marginTop: theme.spacing.md },
268
+ children: choices.map((c, i) => /* @__PURE__ */ jsx(View, {
269
+ style: { marginTop: i === 0 ? 0 : theme.spacing.xs },
270
+ children: /* @__PURE__ */ jsx(Button, {
271
+ label: c.label,
272
+ onPress: c.onPress,
273
+ disabled: c.disabled,
274
+ variant: "secondary"
275
+ })
276
+ }, `${c.label}-${i}`))
277
+ }) : null
278
+ ]
279
+ })]
280
+ });
281
+ if (choices && choices.length > 0) return /* @__PURE__ */ jsx(Panel, {
282
+ variant: "elevated",
283
+ padding: "md",
284
+ style,
285
+ children: body
286
+ });
287
+ return /* @__PURE__ */ jsx(Pressable, {
288
+ onPress: onAdvance,
289
+ children: /* @__PURE__ */ jsx(Panel, {
290
+ variant: "elevated",
291
+ padding: "md",
292
+ style,
293
+ children: body
294
+ })
295
+ });
188
296
  }
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;
297
+ //#endregion
298
+ //#region src/focus.ts
299
+ function createFocusManager() {
300
+ const nodes = /* @__PURE__ */ new Map();
301
+ let seqCounter = 0;
302
+ let focusedId = null;
303
+ const listeners = /* @__PURE__ */ new Set();
304
+ function notify() {
305
+ for (const l of listeners) l(focusedId);
306
+ }
307
+ function orderedIds() {
308
+ const entries = Array.from(nodes.values()).filter((e) => !e.disabled);
309
+ entries.sort((a, b) => {
310
+ if (a.tabIndex !== b.tabIndex) return a.tabIndex - b.tabIndex;
311
+ return a.seq - b.seq;
312
+ });
313
+ return entries.map((e) => e.id);
314
+ }
315
+ function setFocused(next) {
316
+ if (next === focusedId) return;
317
+ const prev = focusedId;
318
+ focusedId = next;
319
+ if (prev !== null) nodes.get(prev)?.onBlur?.();
320
+ if (next !== null) nodes.get(next)?.onFocus?.();
321
+ notify();
322
+ }
323
+ function move(delta) {
324
+ const order = orderedIds();
325
+ if (order.length === 0) {
326
+ setFocused(null);
327
+ return;
328
+ }
329
+ if (focusedId === null) {
330
+ setFocused(delta === 1 ? order[0] ?? null : order[order.length - 1] ?? null);
331
+ return;
332
+ }
333
+ const idx = order.indexOf(focusedId);
334
+ if (idx === -1) {
335
+ setFocused(order[0] ?? null);
336
+ return;
337
+ }
338
+ setFocused(order[(idx + delta + order.length) % order.length] ?? null);
339
+ }
340
+ return {
341
+ register(node) {
342
+ const entry = {
343
+ ...node,
344
+ seq: seqCounter++
345
+ };
346
+ nodes.set(node.id, entry);
347
+ return () => {
348
+ this.unregister(node.id);
349
+ };
350
+ },
351
+ unregister(id) {
352
+ if (!nodes.has(id)) return;
353
+ nodes.delete(id);
354
+ if (focusedId === id) setFocused(orderedIds()[0] ?? null);
355
+ },
356
+ focus(id) {
357
+ const entry = nodes.get(id);
358
+ if (!entry || entry.disabled) return;
359
+ setFocused(id);
360
+ },
361
+ focusFirst() {
362
+ setFocused(orderedIds()[0] ?? null);
363
+ },
364
+ blur() {
365
+ setFocused(null);
366
+ },
367
+ next() {
368
+ move(1);
369
+ },
370
+ prev() {
371
+ move(-1);
372
+ },
373
+ activate() {
374
+ if (focusedId === null) return;
375
+ nodes.get(focusedId)?.onActivate?.();
376
+ },
377
+ getFocused() {
378
+ return focusedId;
379
+ },
380
+ getOrder() {
381
+ return orderedIds();
382
+ },
383
+ subscribe(listener) {
384
+ listeners.add(listener);
385
+ return () => {
386
+ listeners.delete(listener);
387
+ };
388
+ }
389
+ };
275
390
  }
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 });
391
+ //#endregion
392
+ //#region src/focus-keyboard-driver.ts
393
+ const DEFAULT_NEXT = [
394
+ "ArrowDown",
395
+ "ArrowRight",
396
+ "Tab"
397
+ ];
398
+ const DEFAULT_PREV = ["ArrowUp", "ArrowLeft"];
399
+ const DEFAULT_ACTIVATE = ["Enter", "Space"];
400
+ function createFocusKeyboardDriver(manager, keys, options) {
401
+ const nextCodes = options?.next ?? DEFAULT_NEXT;
402
+ const prevCodes = options?.prev ?? DEFAULT_PREV;
403
+ const activateCodes = options?.activate ?? DEFAULT_ACTIVATE;
404
+ return { update() {
405
+ for (let i = 0; i < nextCodes.length; i++) if (keys.wasPressed(nextCodes[i])) {
406
+ manager.next();
407
+ return;
408
+ }
409
+ for (let i = 0; i < prevCodes.length; i++) if (keys.wasPressed(prevCodes[i])) {
410
+ manager.prev();
411
+ return;
412
+ }
413
+ for (let i = 0; i < activateCodes.length; i++) if (keys.wasPressed(activateCodes[i])) {
414
+ manager.activate();
415
+ return;
416
+ }
417
+ } };
299
418
  }
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 });
419
+ //#endregion
420
+ //#region src/focus-provider.tsx
421
+ /**
422
+ * Instantiates a FocusManager (or uses the one provided) and publishes
423
+ * { manager, focusedId } as context state so consumers re-render on focus
424
+ * moves.
425
+ */
426
+ function FocusProvider({ manager, autoFocus, children }) {
427
+ const [mgr] = useState(() => manager ?? createFocusManager());
428
+ const [focusedId, setFocusedId] = useState(() => mgr.getFocused());
429
+ useEffect(() => {
430
+ setFocusedId(mgr.getFocused());
431
+ return mgr.subscribe((id) => {
432
+ setFocusedId(id);
433
+ });
434
+ }, [mgr]);
435
+ useEffect(() => {
436
+ if (autoFocus && mgr.getFocused() === null) mgr.focusFirst();
437
+ }, [autoFocus, mgr]);
438
+ const value = useMemo(() => ({
439
+ manager: mgr,
440
+ focusedId
441
+ }), [mgr, focusedId]);
442
+ return createElement(FocusContext.Provider, { value }, children);
333
443
  }
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
- );
444
+ //#endregion
445
+ //#region src/progress-bar.tsx
446
+ function ProgressBar({ value, height = 8, trackColor, fillColor, style }) {
447
+ const theme = useTheme();
448
+ const clamped = Number.isNaN(value) ? 0 : Math.max(0, Math.min(1, value));
449
+ const r = theme.radii.sm;
450
+ return /* @__PURE__ */ jsx(View, {
451
+ style: [{
452
+ height,
453
+ borderRadius: r,
454
+ backgroundColor: trackColor ?? theme.colors.surfaceAlt,
455
+ overflow: "hidden"
456
+ }, style],
457
+ children: /* @__PURE__ */ jsx(View, { style: {
458
+ width: `${clamped * 100}%`,
459
+ height: "100%",
460
+ backgroundColor: fillColor ?? theme.colors.accent
461
+ } })
462
+ });
414
463
  }
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
- );
464
+ //#endregion
465
+ //#region src/hud-bar.tsx
466
+ function HUDBar({ label, value, max, kind = "custom", showNumbers = true, fillColor }) {
467
+ const theme = useTheme();
468
+ const ratio = max <= 0 ? 0 : value / max;
469
+ let color = fillColor;
470
+ if (!color) switch (kind) {
471
+ case "hp":
472
+ color = theme.colors.danger;
473
+ break;
474
+ case "mp":
475
+ color = theme.colors.accent;
476
+ break;
477
+ case "xp":
478
+ color = theme.colors.success;
479
+ break;
480
+ default: color = theme.colors.accent;
481
+ }
482
+ return /* @__PURE__ */ jsxs(View, { children: [/* @__PURE__ */ jsxs(View, {
483
+ style: {
484
+ flexDirection: "row",
485
+ justifyContent: "space-between",
486
+ marginBottom: theme.spacing.xs
487
+ },
488
+ children: [/* @__PURE__ */ jsx(Label, {
489
+ variant: "sm",
490
+ tone: "muted",
491
+ children: label
492
+ }), showNumbers && /* @__PURE__ */ jsx(Label, {
493
+ variant: "sm",
494
+ tone: "muted",
495
+ mono: true,
496
+ children: `${Math.max(0, Math.floor(value))} / ${Math.max(0, Math.floor(max))}`
497
+ })]
498
+ }), /* @__PURE__ */ jsx(ProgressBar, {
499
+ value: ratio,
500
+ fillColor: color
501
+ })] });
460
502
  }
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
- ] });
503
+ //#endregion
504
+ //#region src/layout.ts
505
+ const ZERO_PAD = {
506
+ top: 0,
507
+ right: 0,
508
+ bottom: 0,
509
+ left: 0
510
+ };
511
+ function resolvePadding(p) {
512
+ if (!p) return ZERO_PAD;
513
+ return {
514
+ top: p.top ?? 0,
515
+ right: p.right ?? 0,
516
+ bottom: p.bottom ?? 0,
517
+ left: p.left ?? 0
518
+ };
508
519
  }
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";
520
+ function resolveLayout(container, children) {
521
+ const n = children.length;
522
+ if (n === 0) return [];
523
+ const pad = resolvePadding(container.padding);
524
+ const gap = container.gap ?? 0;
525
+ const isRow = container.direction === "row";
526
+ const mainSize = (isRow ? container.width : container.height) - (isRow ? pad.left + pad.right : pad.top + pad.bottom);
527
+ const crossSize = (isRow ? container.height : container.width) - (isRow ? pad.top + pad.bottom : pad.left + pad.right);
528
+ const mainStart = isRow ? pad.left : pad.top;
529
+ const crossStart = isRow ? pad.top : pad.left;
530
+ const justify = container.justifyContent ?? "start";
531
+ const align = container.alignItems ?? "stretch";
532
+ const totalGap = gap * Math.max(0, n - 1);
533
+ let totalBasis = 0;
534
+ let totalGrow = 0;
535
+ for (const c of children) {
536
+ totalBasis += c.basis ?? 0;
537
+ totalGrow += c.grow ?? 0;
538
+ }
539
+ const leftover = mainSize - totalBasis - totalGap;
540
+ const sizes = new Array(n);
541
+ for (let i = 0; i < n; i++) {
542
+ const c = children[i];
543
+ const base = c.basis ?? 0;
544
+ const growShare = totalGrow > 0 ? (c.grow ?? 0) / totalGrow * Math.max(0, leftover) : 0;
545
+ sizes[i] = Math.max(0, base + growShare);
546
+ }
547
+ const used = sizes.reduce((acc, s) => acc + s, 0) + totalGap;
548
+ const free = Math.max(0, mainSize - used);
549
+ let cursor = mainStart;
550
+ let spacing = gap;
551
+ switch (justify) {
552
+ case "start": break;
553
+ case "end":
554
+ cursor = mainStart + free;
555
+ break;
556
+ case "center":
557
+ cursor = mainStart + free / 2;
558
+ break;
559
+ case "space-between":
560
+ if (n > 1) spacing = gap + free / (n - 1);
561
+ break;
562
+ case "space-around":
563
+ if (n > 0) {
564
+ const s = free / n;
565
+ cursor = mainStart + s / 2;
566
+ spacing = gap + s;
567
+ }
568
+ break;
569
+ case "space-evenly":
570
+ if (n >= 0) {
571
+ const s = free / (n + 1);
572
+ cursor = mainStart + s;
573
+ spacing = gap + s;
574
+ }
575
+ break;
576
+ }
577
+ const out = new Array(n);
578
+ for (let i = 0; i < n; i++) {
579
+ const c = children[i];
580
+ const mainLen = sizes[i];
581
+ const crossLen = c.crossSize !== void 0 ? c.crossSize : align === "stretch" ? crossSize : 0;
582
+ let crossOffset;
583
+ switch (align) {
584
+ case "start":
585
+ crossOffset = 0;
586
+ break;
587
+ case "end":
588
+ crossOffset = crossSize - crossLen;
589
+ break;
590
+ case "center":
591
+ crossOffset = (crossSize - crossLen) / 2;
592
+ break;
593
+ case "stretch":
594
+ crossOffset = 0;
595
+ break;
596
+ }
597
+ out[i] = {
598
+ x: isRow ? cursor : crossStart + crossOffset,
599
+ y: isRow ? crossStart + crossOffset : cursor,
600
+ width: isRow ? mainLen : crossLen,
601
+ height: isRow ? crossLen : mainLen
602
+ };
603
+ cursor += mainLen + spacing;
604
+ }
605
+ return out;
606
+ }
607
+ //#endregion
608
+ //#region src/list.tsx
609
+ /**
610
+ * Vertical (or horizontal) stack with consistent gap. Thin container; the
611
+ * focus manager handles navigation between interactive children.
612
+ */
514
613
  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 });
614
+ const theme = useTheme();
615
+ const g = gap ?? theme.spacing.sm;
616
+ const items = [];
617
+ let i = 0;
618
+ const flat = Array.isArray(children) ? children : [children];
619
+ for (const child of flat) {
620
+ if (child === null || child === void 0 || child === false) continue;
621
+ if (i > 0) {
622
+ const spacerStyle = direction === "row" ? { width: g } : { height: g };
623
+ items.push(/* @__PURE__ */ jsx(View, { style: spacerStyle }, `s-${i}`));
624
+ }
625
+ items.push(/* @__PURE__ */ jsx(Fragment, { children: child }, `i-${i}`));
626
+ i++;
627
+ }
628
+ return /* @__PURE__ */ jsx(View, {
629
+ style: [{ flexDirection: direction }, style],
630
+ children: items
631
+ });
530
632
  }
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
- );
633
+ //#endregion
634
+ //#region src/main-menu-kit.tsx
635
+ /**
636
+ * Title-screen kit: headline, optional subtitle, vertical button list,
637
+ * optional footer slot. All strings are caller-supplied (localized upstream).
638
+ *
639
+ * Save-slot / settings / credits panels are built on top of this kit by the
640
+ * consumer; the kit itself is a pure title-menu primitive.
641
+ */
642
+ function MainMenuKit({ title, subtitle, items, footer, style }) {
643
+ const theme = useTheme();
644
+ return /* @__PURE__ */ jsxs(View, {
645
+ style: [{
646
+ flex: 1,
647
+ alignItems: "center",
648
+ justifyContent: "center",
649
+ padding: theme.spacing.lg
650
+ }, style],
651
+ children: [
652
+ /* @__PURE__ */ jsx(Label, {
653
+ variant: "xl",
654
+ tone: "accent",
655
+ style: { marginBottom: theme.spacing.xs },
656
+ children: title
657
+ }),
658
+ subtitle !== void 0 ? /* @__PURE__ */ jsx(Label, {
659
+ variant: "sm",
660
+ tone: "muted",
661
+ style: { marginBottom: theme.spacing.lg },
662
+ children: subtitle
663
+ }) : /* @__PURE__ */ jsx(View, { style: { height: theme.spacing.lg } }),
664
+ /* @__PURE__ */ jsx(View, {
665
+ style: {
666
+ alignSelf: "stretch",
667
+ maxWidth: 320,
668
+ width: "100%"
669
+ },
670
+ children: items.map((item, i) => /* @__PURE__ */ jsx(View, {
671
+ style: { marginTop: i === 0 ? 0 : theme.spacing.sm },
672
+ children: /* @__PURE__ */ jsx(Button, {
673
+ label: item.label,
674
+ onPress: item.onPress,
675
+ variant: item.variant ?? "primary",
676
+ disabled: item.disabled,
677
+ focusId: item.id,
678
+ tabIndex: i
679
+ })
680
+ }, item.id))
681
+ }),
682
+ footer !== void 0 ? /* @__PURE__ */ jsx(View, {
683
+ style: { marginTop: theme.spacing.lg },
684
+ children: footer
685
+ }) : null
686
+ ]
687
+ });
574
688
  }
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 }) });
689
+ //#endregion
690
+ //#region src/modal.tsx
691
+ /**
692
+ * Overlay modal that renders a centered `Panel` with its children. Parent is
693
+ * responsible for controlling visibility and (if desired) focus trapping via
694
+ * the shared FocusManager.
695
+ */
696
+ function Modal({ visible, children, onBackdropPress, backdropOpacity = .6 }) {
697
+ if (!visible) return null;
698
+ return /* @__PURE__ */ jsxs(View, {
699
+ style: {
700
+ position: "absolute",
701
+ top: 0,
702
+ left: 0,
703
+ right: 0,
704
+ bottom: 0,
705
+ alignItems: "center",
706
+ justifyContent: "center"
707
+ },
708
+ pointerEvents: "box-none",
709
+ children: [/* @__PURE__ */ jsx(Pressable, {
710
+ onPress: onBackdropPress,
711
+ style: {
712
+ position: "absolute",
713
+ top: 0,
714
+ left: 0,
715
+ right: 0,
716
+ bottom: 0,
717
+ backgroundColor: `rgba(0,0,0,${backdropOpacity})`
718
+ }
719
+ }), /* @__PURE__ */ jsx(Panel, {
720
+ variant: "elevated",
721
+ padding: "lg",
722
+ style: {
723
+ minWidth: 240,
724
+ maxWidth: "80%"
725
+ },
726
+ children
727
+ })]
728
+ });
608
729
  }
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
- }) });
730
+ //#endregion
731
+ //#region src/shop-panel.tsx
732
+ /**
733
+ * List-style shop panel. Caller builds the `items` array by joining a
734
+ * `ProductCatalog` with the `Product[]` returned by `IAPProvider.getProducts`.
735
+ *
736
+ * Price strings and ownership copy are caller-provided so the UI kit stays
737
+ * localization-free.
738
+ */
739
+ function ShopPanel({ items, isEntitled, onPurchase, ownedLabel = "Owned", purchaseLabelFor, style }) {
740
+ const theme = useTheme();
741
+ return /* @__PURE__ */ jsx(Panel, {
742
+ variant: "elevated",
743
+ padding: "md",
744
+ style,
745
+ children: items.map((item, i) => {
746
+ const owned = item.ownedKeys?.some((k) => isEntitled(k)) ?? false;
747
+ return /* @__PURE__ */ jsxs(View, {
748
+ style: {
749
+ marginTop: i === 0 ? 0 : theme.spacing.md,
750
+ paddingTop: i === 0 ? 0 : theme.spacing.md,
751
+ borderTopWidth: i === 0 ? 0 : 1,
752
+ borderTopColor: theme.colors.border
753
+ },
754
+ children: [
755
+ /* @__PURE__ */ jsx(Label, {
756
+ variant: "md",
757
+ children: item.title
758
+ }),
759
+ item.description !== void 0 ? /* @__PURE__ */ jsx(Label, {
760
+ variant: "sm",
761
+ tone: "muted",
762
+ style: { marginTop: theme.spacing.xs },
763
+ children: item.description
764
+ }) : null,
765
+ /* @__PURE__ */ jsx(View, {
766
+ style: { marginTop: theme.spacing.sm },
767
+ children: owned ? /* @__PURE__ */ jsx(Button, {
768
+ label: ownedLabel,
769
+ variant: "ghost",
770
+ disabled: true
771
+ }) : /* @__PURE__ */ jsx(Button, {
772
+ label: purchaseLabelFor ? purchaseLabelFor(item) : item.priceDisplay,
773
+ variant: "primary",
774
+ disabled: item.disabled,
775
+ onPress: () => onPurchase(item.productId)
776
+ })
777
+ })
778
+ ]
779
+ }, item.productId);
780
+ })
781
+ });
650
782
  }
783
+ //#endregion
784
+ export { Button, DialoguePanel, FocusContext, FocusProvider, HUDBar, Label, List, MainMenuKit, Modal, Panel, ProgressBar, ShopPanel, ThemeProvider, createFocusKeyboardDriver, createFocusManager, darkTheme, lightTheme, resolveLayout, useFocusManager, useFocusedId, useTheme };
651
785
 
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
786
  //# sourceMappingURL=index.mjs.map