@flare-engine/ui 0.1.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.
@@ -0,0 +1,350 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { ViewStyle, TextStyle } from 'react-native';
4
+
5
+ interface ThemeColors {
6
+ bg: string;
7
+ surface: string;
8
+ surfaceAlt: string;
9
+ border: string;
10
+ text: string;
11
+ textMuted: string;
12
+ accent: string;
13
+ accentText: string;
14
+ danger: string;
15
+ success: string;
16
+ warning: string;
17
+ focus: string;
18
+ }
19
+ interface ThemeSpacing {
20
+ xs: number;
21
+ sm: number;
22
+ md: number;
23
+ lg: number;
24
+ xl: number;
25
+ }
26
+ interface ThemeTypography {
27
+ sizeXs: number;
28
+ sizeSm: number;
29
+ sizeMd: number;
30
+ sizeLg: number;
31
+ sizeXl: number;
32
+ fontFamily?: string;
33
+ fontFamilyMono?: string;
34
+ }
35
+ interface ThemeRadii {
36
+ none: number;
37
+ sm: number;
38
+ md: number;
39
+ lg: number;
40
+ pill: number;
41
+ }
42
+ interface Theme {
43
+ name: string;
44
+ colors: ThemeColors;
45
+ spacing: ThemeSpacing;
46
+ typography: ThemeTypography;
47
+ radii: ThemeRadii;
48
+ }
49
+ declare const darkTheme: Theme;
50
+ declare const lightTheme: Theme;
51
+ interface ThemeProviderProps {
52
+ theme?: Theme;
53
+ children: ReactNode;
54
+ }
55
+ declare function ThemeProvider({ theme, children }: ThemeProviderProps): ReactNode;
56
+ declare function useTheme(): Theme;
57
+
58
+ /**
59
+ * Keyboard + (future) gamepad focus navigation.
60
+ *
61
+ * Primitives register themselves with the focus manager by id + tab order.
62
+ * The manager owns which id is currently focused and exposes `next` / `prev`
63
+ * / `activate` actions for a driver (keyboard key handler, gamepad dpad)
64
+ * to call. Components read `focusedId` to render a focus ring.
65
+ */
66
+ interface FocusNode {
67
+ id: string;
68
+ /** Lower tabIndex is focused first. Nodes with equal tabIndex fall back to registration order. */
69
+ tabIndex: number;
70
+ /** Called when this node is activated (Enter / A button). */
71
+ onActivate?: () => void;
72
+ /** Called when this node receives focus. */
73
+ onFocus?: () => void;
74
+ /** Called when this node loses focus. */
75
+ onBlur?: () => void;
76
+ /** If true, the node is skipped during navigation. */
77
+ disabled?: boolean;
78
+ }
79
+ interface FocusManager {
80
+ register(node: FocusNode): () => void;
81
+ unregister(id: string): void;
82
+ focus(id: string): void;
83
+ blur(): void;
84
+ next(): void;
85
+ prev(): void;
86
+ activate(): void;
87
+ getFocused(): string | null;
88
+ getOrder(): readonly string[];
89
+ subscribe(listener: (focusedId: string | null) => void): () => void;
90
+ }
91
+ declare function createFocusManager(): FocusManager;
92
+
93
+ declare const FocusContext: react.Context<FocusManager | null>;
94
+ declare function useFocusManager(): FocusManager | null;
95
+
96
+ interface FocusProviderProps {
97
+ manager?: FocusManager;
98
+ children: ReactNode;
99
+ }
100
+ /**
101
+ * Instantiates a FocusManager (or uses the one provided) and exposes it
102
+ * through `FocusContext`. Also triggers a re-render whenever focus moves,
103
+ * so primitives that read `focusedId` update their focus ring.
104
+ */
105
+ declare function FocusProvider({ manager, children }: FocusProviderProps): ReactNode;
106
+
107
+ /**
108
+ * Minimal flex-like layout resolver.
109
+ *
110
+ * Computes positions + sizes for a single container + its direct children.
111
+ * Supports row/column direction, gap, padding, main-axis `justifyContent`,
112
+ * cross-axis `alignItems`, and per-child `grow` / `basis` / fixed size.
113
+ *
114
+ * Pure function — callers use it to drive their own renderer. React Native
115
+ * already does its own flex, so this is primarily for Skia-rendered HUD /
116
+ * menu layouts that need deterministic pixel positions.
117
+ */
118
+ type FlexDirection = 'row' | 'column';
119
+ type JustifyContent = 'start' | 'end' | 'center' | 'space-between' | 'space-around' | 'space-evenly';
120
+ type AlignItems = 'start' | 'end' | 'center' | 'stretch';
121
+ interface Padding {
122
+ top: number;
123
+ right: number;
124
+ bottom: number;
125
+ left: number;
126
+ }
127
+ interface LayoutChild {
128
+ /** Fixed main-axis size. Ignored when `grow > 0`. */
129
+ basis?: number;
130
+ /** Fractional share of leftover main-axis space. */
131
+ grow?: number;
132
+ /** Fixed cross-axis size. Overrides stretch. */
133
+ crossSize?: number;
134
+ }
135
+ interface LayoutContainer {
136
+ width: number;
137
+ height: number;
138
+ direction: FlexDirection;
139
+ gap?: number;
140
+ padding?: Partial<Padding>;
141
+ justifyContent?: JustifyContent;
142
+ alignItems?: AlignItems;
143
+ }
144
+ interface LayoutRect {
145
+ x: number;
146
+ y: number;
147
+ width: number;
148
+ height: number;
149
+ }
150
+ declare function resolveLayout(container: LayoutContainer, children: readonly LayoutChild[]): LayoutRect[];
151
+
152
+ interface PanelProps {
153
+ children?: ReactNode;
154
+ /** Visual style: surface (default) or elevated (surfaceAlt + border). */
155
+ variant?: 'surface' | 'elevated';
156
+ /** Padding size token. Defaults to 'md'. */
157
+ padding?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
158
+ /** Corner radius token. Defaults to 'md'. */
159
+ radius?: 'none' | 'sm' | 'md' | 'lg' | 'pill';
160
+ style?: ViewStyle;
161
+ }
162
+ declare function Panel({ children, variant, padding, radius, style, }: PanelProps): ReactNode;
163
+
164
+ type LabelVariant = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
165
+ type LabelTone = 'default' | 'muted' | 'accent' | 'danger' | 'success' | 'warning';
166
+ interface LabelProps {
167
+ children?: ReactNode;
168
+ variant?: LabelVariant;
169
+ tone?: LabelTone;
170
+ mono?: boolean;
171
+ style?: TextStyle;
172
+ }
173
+ declare function Label({ children, variant, tone, mono, style, }: LabelProps): ReactNode;
174
+
175
+ type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
176
+ interface ButtonProps {
177
+ label: string;
178
+ onPress?: () => void;
179
+ variant?: ButtonVariant;
180
+ disabled?: boolean;
181
+ /** Focus-navigation tab order. Lower is earlier. Defaults to 0. */
182
+ tabIndex?: number;
183
+ /** Stable focus id. If omitted, a generated id is used. */
184
+ focusId?: string;
185
+ style?: ViewStyle;
186
+ }
187
+ declare function Button({ label, onPress, variant, disabled, tabIndex, focusId, style, }: ButtonProps): ReactNode;
188
+
189
+ interface ProgressBarProps {
190
+ /** Progress in [0, 1]. Values outside are clamped. */
191
+ value: number;
192
+ /** Height of the bar in pixels. */
193
+ height?: number;
194
+ /** Track color override. Defaults to theme.colors.surfaceAlt. */
195
+ trackColor?: string;
196
+ /** Fill color override. Defaults to theme.colors.accent. */
197
+ fillColor?: string;
198
+ style?: ViewStyle;
199
+ }
200
+ declare function ProgressBar({ value, height, trackColor, fillColor, style, }: ProgressBarProps): ReactNode;
201
+
202
+ type HUDBarKind = 'hp' | 'mp' | 'xp' | 'custom';
203
+ interface HUDBarProps {
204
+ label: string;
205
+ value: number;
206
+ max: number;
207
+ kind?: HUDBarKind;
208
+ /** When true, shows "value / max" next to the label. */
209
+ showNumbers?: boolean;
210
+ /** Override bar fill color. */
211
+ fillColor?: string;
212
+ }
213
+ declare function HUDBar({ label, value, max, kind, showNumbers, fillColor, }: HUDBarProps): ReactNode;
214
+
215
+ interface ListProps {
216
+ children?: ReactNode;
217
+ /** Gap between items in pixels. Defaults to theme.spacing.sm. */
218
+ gap?: number;
219
+ direction?: 'column' | 'row';
220
+ style?: ViewStyle;
221
+ }
222
+ /**
223
+ * Vertical (or horizontal) stack with consistent gap. Thin container; the
224
+ * focus manager handles navigation between interactive children.
225
+ */
226
+ declare function List({ children, gap, direction, style }: ListProps): ReactNode;
227
+
228
+ interface ModalProps {
229
+ visible: boolean;
230
+ children?: ReactNode;
231
+ /** Called when the backdrop is pressed. Return nothing to close, or do nothing to make it non-dismissable. */
232
+ onBackdropPress?: () => void;
233
+ /** Backdrop opacity 0..1. Defaults to 0.6. */
234
+ backdropOpacity?: number;
235
+ }
236
+ /**
237
+ * Overlay modal that renders a centered `Panel` with its children. Parent is
238
+ * responsible for controlling visibility and (if desired) focus trapping via
239
+ * the shared FocusManager.
240
+ */
241
+ declare function Modal({ visible, children, onBackdropPress, backdropOpacity, }: ModalProps): ReactNode;
242
+
243
+ interface DialogueChoice {
244
+ /** Display label (already localized by the caller). */
245
+ readonly label: string;
246
+ /** Called when the player selects this choice. */
247
+ readonly onPress: () => void;
248
+ readonly disabled?: boolean;
249
+ }
250
+ interface DialoguePanelProps {
251
+ /** Speaker name — rendered above the text. */
252
+ readonly speaker: string;
253
+ /** Line text — rendered in the body. */
254
+ readonly text: string;
255
+ /**
256
+ * Portrait node. Typically an `<Image>` or a Skia/shape avatar keyed by
257
+ * `LineNode.speakerPortraitKey`. When omitted, the portrait slot collapses.
258
+ */
259
+ readonly portrait?: ReactNode;
260
+ /**
261
+ * Optional choices. When present, renders a `Button` per option; when
262
+ * absent, the panel tap-advances via `onAdvance`.
263
+ */
264
+ readonly choices?: readonly DialogueChoice[];
265
+ /** Advance callback — used only when `choices` is empty / omitted. */
266
+ readonly onAdvance?: () => void;
267
+ readonly style?: ViewStyle;
268
+ }
269
+ /**
270
+ * Dialogue panel with a portrait slot. Pairs with `@flare-engine/dialogue`
271
+ * — subscribe to `runner.onLine` and pass `speakerPortraitKey` → your
272
+ * portrait resolver → `portrait` here.
273
+ *
274
+ * Extracted from Pan Tvardowski per Phase 11.14 (M9.4). Portrait resolution
275
+ * is caller-owned so the UI kit stays asset-agnostic.
276
+ */
277
+ declare function DialoguePanel({ speaker, text, portrait, choices, onAdvance, style, }: DialoguePanelProps): ReactNode;
278
+
279
+ interface ShopItem {
280
+ /** Store product id — forwarded verbatim to `onPurchase`. */
281
+ readonly productId: string;
282
+ /** Localized display title. */
283
+ readonly title: string;
284
+ /** Localized price string (from `Product.priceDisplay`). */
285
+ readonly priceDisplay: string;
286
+ /** Optional localized description. */
287
+ readonly description?: string;
288
+ /**
289
+ * Entitlement key(s) that mark this product as already owned. When the
290
+ * store reports any of these as entitled, the purchase button is replaced
291
+ * with an "owned" label.
292
+ */
293
+ readonly ownedKeys?: readonly string[];
294
+ readonly disabled?: boolean;
295
+ }
296
+ interface ShopPanelProps {
297
+ readonly items: readonly ShopItem[];
298
+ /** Returns `true` when the given entitlement key is already owned. */
299
+ readonly isEntitled: (key: string) => boolean;
300
+ /** Called when a not-owned item's purchase button is pressed. */
301
+ readonly onPurchase: (productId: string) => void;
302
+ /** Localized label for already-owned items. Defaults to "Owned". */
303
+ readonly ownedLabel?: string;
304
+ /** Localized label for the purchase action. Defaults to the item's price. */
305
+ readonly purchaseLabelFor?: (item: ShopItem) => string;
306
+ readonly style?: ViewStyle;
307
+ }
308
+ /**
309
+ * List-style shop panel. Caller builds the `items` array by joining a
310
+ * `ProductCatalog` with the `Product[]` returned by `IAPProvider.getProducts`.
311
+ *
312
+ * Extracted from Pan Tvardowski per Phase 11.14 (M9.3). Price strings and
313
+ * ownership copy are caller-provided so the UI kit stays localization-free.
314
+ */
315
+ declare function ShopPanel({ items, isEntitled, onPurchase, ownedLabel, purchaseLabelFor, style, }: ShopPanelProps): ReactNode;
316
+
317
+ interface MainMenuItem {
318
+ /** Stable id — used as focus id + React key. */
319
+ readonly id: string;
320
+ /** Localized label. */
321
+ readonly label: string;
322
+ readonly onPress: () => void;
323
+ readonly variant?: ButtonVariant;
324
+ readonly disabled?: boolean;
325
+ }
326
+ interface MainMenuKitProps {
327
+ /** Localized title. */
328
+ readonly title: string;
329
+ /** Optional localized subtitle — tagline, version, locale flag, etc. */
330
+ readonly subtitle?: string;
331
+ /** Button list. Rendered top-to-bottom in order. */
332
+ readonly items: readonly MainMenuItem[];
333
+ /**
334
+ * Optional footer slot — typically a row of ghost buttons (credits, links)
335
+ * or a version/build string.
336
+ */
337
+ readonly footer?: ReactNode;
338
+ readonly style?: ViewStyle;
339
+ }
340
+ /**
341
+ * Title-screen kit: headline, optional subtitle, vertical button list,
342
+ * optional footer slot. All strings are caller-supplied (localized upstream).
343
+ *
344
+ * Extracted from Pan Tvardowski per Phase 11.14 (M9.1). Save-slot / settings
345
+ * / credits panels are built on top of this kit by the consumer; the kit
346
+ * itself is a pure title-menu primitive.
347
+ */
348
+ declare function MainMenuKit({ title, subtitle, items, footer, style, }: MainMenuKitProps): ReactNode;
349
+
350
+ export { type AlignItems, Button, type ButtonProps, type ButtonVariant, type DialogueChoice, DialoguePanel, type DialoguePanelProps, type FlexDirection, FocusContext, type FocusManager, type FocusNode, FocusProvider, type FocusProviderProps, HUDBar, type HUDBarKind, type HUDBarProps, type JustifyContent, Label, type LabelProps, type LabelTone, type LabelVariant, type LayoutChild, type LayoutContainer, type LayoutRect, List, type ListProps, type MainMenuItem, MainMenuKit, type MainMenuKitProps, Modal, type ModalProps, type Padding, Panel, type PanelProps, ProgressBar, type ProgressBarProps, type ShopItem, ShopPanel, type ShopPanelProps, type Theme, type ThemeColors, ThemeProvider, type ThemeProviderProps, type ThemeRadii, type ThemeSpacing, type ThemeTypography, createFocusManager, darkTheme, lightTheme, resolveLayout, useFocusManager, useTheme };