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