@tastic/hud 0.25.0 → 0.26.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,7 @@
1
+ export { M as MenuOption, P as PlayerSetupPanel, c as PlayerSetupPanelProps, R as ReadyButton, S as SharedActionBand, g as getColorPopoverId, d as getCpuDifficultyPopoverId, f as getProfilePopoverId, u as useZoneClampedAlign } from '../index-DW0PsGCE.js';
2
+ import 'react';
3
+ import '@rific/auto-paper';
4
+ import '@tastic/profile';
5
+ import '../usePopoverHost-T8QWb2_A.js';
6
+ import '@tastic/core';
7
+ import 'react-native';
@@ -0,0 +1,511 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lobby/index.ts
21
+ var lobby_exports = {};
22
+ __export(lobby_exports, {
23
+ PlayerSetupPanel: () => PlayerSetupPanel,
24
+ ReadyButton: () => ReadyButton,
25
+ SharedActionBand: () => SharedActionBand,
26
+ getColorPopoverId: () => getColorPopoverId,
27
+ getCpuDifficultyPopoverId: () => getCpuDifficultyPopoverId,
28
+ getProfilePopoverId: () => getProfilePopoverId,
29
+ useZoneClampedAlign: () => useZoneClampedAlign
30
+ });
31
+ module.exports = __toCommonJS(lobby_exports);
32
+
33
+ // src/PlayerSetupPanel.tsx
34
+ var import_profile = require("@tastic/profile");
35
+ var import_react_native7 = require("react-native");
36
+ var import_react_native_paper3 = require("react-native-paper");
37
+
38
+ // src/InlineColorPicker.tsx
39
+ var import_auto_paper = require("@rific/auto-paper");
40
+ var import_feedback_press = require("@rific/feedback-press");
41
+ var import_core = require("@tastic/core");
42
+ var import_react_native4 = require("react-native");
43
+ var import_react_native_paper = require("react-native-paper");
44
+
45
+ // src/fonts.ts
46
+ var import_react_native = require("react-native");
47
+ var MONO_FONT = import_react_native.Platform.select({ ios: "Menlo", android: "monospace", default: "monospace" });
48
+
49
+ // src/PopoverBody.tsx
50
+ var import_react_native2 = require("react-native");
51
+ var import_jsx_runtime = require("react/jsx-runtime");
52
+ var CARET_SIZE = 7;
53
+ var CARET_RING_OFFSET = 2;
54
+ var CARET_DIP = 1;
55
+ function PopoverBody({ visible, children, align = "center", verticalAlign = "below", caretColor, caretBorderColor, caretBorderWidth = 1, triggerSize = 0 }) {
56
+ if (!visible) return null;
57
+ const above = verticalAlign === "above";
58
+ const alignStyle = align === "left" ? styles.contentLeft : align === "right" ? styles.contentRight : styles.contentCenter;
59
+ const verticalStyle = above ? styles.contentAbove : styles.contentBelow;
60
+ const ringSize = CARET_SIZE + caretBorderWidth;
61
+ const caretOffset = (halfFootprint) => align === "right" ? { right: triggerSize / 2 - halfFootprint } : { left: triggerSize / 2 - halfFootprint };
62
+ const caretFill = above ? "borderTopColor" : "borderBottomColor";
63
+ const caretWidthProp = above ? "borderTopWidth" : "borderBottomWidth";
64
+ const caretEdge = (size) => above ? { bottom: -size + CARET_DIP } : { top: -size + CARET_DIP };
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: [styles.content, alignStyle, verticalStyle], children: [
66
+ children,
67
+ caretColor && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
68
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.caret, caretOffset(ringSize), caretEdge(ringSize), { [caretFill]: caretBorderColor ?? caretColor, [caretWidthProp]: ringSize, borderLeftWidth: ringSize, borderRightWidth: ringSize }] }),
69
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.caret, caretOffset(CARET_SIZE), caretEdge(CARET_SIZE - CARET_RING_OFFSET), { [caretFill]: caretColor, [caretWidthProp]: CARET_SIZE, borderLeftWidth: CARET_SIZE, borderRightWidth: CARET_SIZE }] })
70
+ ] })
71
+ ] });
72
+ }
73
+ var styles = import_react_native2.StyleSheet.create({
74
+ caret: {
75
+ borderLeftColor: "transparent",
76
+ borderRightColor: "transparent",
77
+ height: 0,
78
+ position: "absolute",
79
+ width: 0,
80
+ // Explicit, not left to DOM order - the box it dips into is itself a position:'relative' view,
81
+ // which React Native Web always gives an implicit zIndex:0 (see PopoverBody's stacking-context
82
+ // notes elsewhere in this codebase), so painting on top needs a real zIndex to beat that
83
+ // reliably rather than relying on being the later sibling.
84
+ zIndex: 1
85
+ },
86
+ content: {
87
+ position: "absolute",
88
+ zIndex: 50
89
+ },
90
+ contentAbove: {
91
+ bottom: "100%",
92
+ marginBottom: 8
93
+ },
94
+ contentBelow: {
95
+ marginTop: 8,
96
+ top: "100%"
97
+ },
98
+ // Stretched to the anchor's own (trigger) width, with alignItems centering the actual (usually
99
+ // much wider) popover box inside via plain flexbox - not `left:'50%'` plus a percentage
100
+ // `transform`, which depends on native resolving the box's own auto width before applying the
101
+ // transform and has proven unreliable there, visibly shifting the box off-center.
102
+ contentCenter: {
103
+ alignItems: "center",
104
+ left: 0,
105
+ right: 0
106
+ },
107
+ contentLeft: {
108
+ left: 0
109
+ },
110
+ contentRight: {
111
+ right: 0
112
+ }
113
+ });
114
+
115
+ // src/useAutoAlign.ts
116
+ var import_react = require("react");
117
+ var import_react_native3 = require("react-native");
118
+ var EDGE_MARGIN = 12;
119
+ function rotateRect(x, y, width, height, rotation, windowWidth, windowHeight) {
120
+ if (rotation === 0) return { x, y, width, height };
121
+ const cx = windowWidth / 2;
122
+ const cy = windowHeight / 2;
123
+ const dx = x + width / 2 - cx;
124
+ const dy = y + height / 2 - cy;
125
+ const [newDx, newDy, newWidth, newHeight] = rotation === 180 ? [-dx, -dy, width, height] : rotation === 90 ? [-dy, dx, height, width] : [dy, -dx, height, width];
126
+ return { x: cx + newDx - newWidth / 2, y: cy + newDy - newHeight / 2, width: newWidth, height: newHeight };
127
+ }
128
+ function useAutoAlign(open, contentWidth, contentHeight, rotation = 0, bounds) {
129
+ const triggerRef = (0, import_react.useRef)(null);
130
+ const { width: windowWidth, height: windowHeight } = (0, import_react_native3.useWindowDimensions)();
131
+ const [align, setAlign] = (0, import_react.useState)("center");
132
+ const [verticalAlign, setVerticalAlign] = (0, import_react.useState)("below");
133
+ const [maxHeight, setMaxHeight] = (0, import_react.useState)(contentHeight);
134
+ const [measured, setMeasured] = (0, import_react.useState)(false);
135
+ const [prevOpen, setPrevOpen] = (0, import_react.useState)(open);
136
+ if (open !== prevOpen) {
137
+ setPrevOpen(open);
138
+ if (open) setMeasured(false);
139
+ }
140
+ (0, import_react.useEffect)(() => {
141
+ if (!open) return;
142
+ const place = (limits) => (rawX, rawY, rawWidth, rawHeight) => {
143
+ const { x, y, width: triggerWidth, height: triggerHeight } = rotateRect(rawX, rawY, rawWidth, rawHeight, rotation, windowWidth, windowHeight);
144
+ const centerX = x + triggerWidth / 2;
145
+ const overflowsRight = centerX + contentWidth / 2 > limits.right - EDGE_MARGIN;
146
+ const overflowsLeft = centerX - contentWidth / 2 < limits.left + EDGE_MARGIN;
147
+ if (overflowsRight && !overflowsLeft) setAlign("right");
148
+ else if (overflowsLeft && !overflowsRight) setAlign("left");
149
+ else setAlign("center");
150
+ const roomBelow = limits.bottom - (y + triggerHeight) - EDGE_MARGIN;
151
+ const roomAbove = y - limits.top - EDGE_MARGIN;
152
+ const above = contentHeight > roomBelow && roomAbove > roomBelow;
153
+ setVerticalAlign(above ? "above" : "below");
154
+ setMaxHeight(Math.max(above ? roomAbove : roomBelow, 0));
155
+ setMeasured(true);
156
+ };
157
+ const screen = { left: 0, top: 0, right: windowWidth, bottom: windowHeight };
158
+ const boundsView = bounds?.current;
159
+ if (!boundsView) {
160
+ triggerRef.current?.measureInWindow(place(screen));
161
+ return;
162
+ }
163
+ boundsView.measureInWindow((rawX, rawY, rawWidth, rawHeight) => {
164
+ const b = rotateRect(rawX, rawY, rawWidth, rawHeight, rotation, windowWidth, windowHeight);
165
+ triggerRef.current?.measureInWindow(place({ left: Math.max(b.x, 0), top: Math.max(b.y, 0), right: Math.min(b.x + b.width, windowWidth), bottom: Math.min(b.y + b.height, windowHeight) }));
166
+ });
167
+ }, [open, contentWidth, contentHeight, windowWidth, windowHeight, rotation, bounds]);
168
+ return { align, maxHeight, measured, triggerRef, verticalAlign };
169
+ }
170
+
171
+ // src/InlineColorPicker.tsx
172
+ var import_jsx_runtime2 = require("react/jsx-runtime");
173
+ var EMOJI_PATTERN = /\p{Extended_Pictographic}/u;
174
+ var DEFAULT_SIZE = 48;
175
+ var SWATCH_SIZE = 28;
176
+ var SWATCH_RING_WIDTH = 2;
177
+ var SWATCHES_PADDING = 8;
178
+ var SWATCHES_GAP = 6;
179
+ var SWATCHES_BORDER_WIDTH = 2;
180
+ var MIN_COLUMNS = 4;
181
+ var MAX_COLUMNS = 5;
182
+ var SCREEN_MARGIN = 40;
183
+ function widthForColumns(columns) {
184
+ return SWATCHES_BORDER_WIDTH * 2 + SWATCHES_PADDING * 2 + SWATCH_SIZE * columns + SWATCHES_GAP * (columns - 1);
185
+ }
186
+ function getInlineColorPickerContentSize(swatchCount, windowWidth, columns) {
187
+ const autoColumns = (0, import_core.clamp)(Math.floor((windowWidth - 2 * SCREEN_MARGIN + SWATCHES_GAP) / (SWATCH_SIZE + SWATCHES_GAP)), MIN_COLUMNS, MAX_COLUMNS);
188
+ const resolvedColumns = columns ?? autoColumns;
189
+ const width = widthForColumns(resolvedColumns);
190
+ const rows = Math.ceil(swatchCount / resolvedColumns);
191
+ const height = SWATCHES_BORDER_WIDTH * 2 + SWATCHES_PADDING * 2 + SWATCH_SIZE * rows + SWATCHES_GAP * (rows - 1);
192
+ return { width, height };
193
+ }
194
+ function SwatchDrawing({ size, children }) {
195
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native4.View, { style: [styles2.drawing, { borderRadius: size / 2, height: size, width: size }], children });
196
+ }
197
+ function InlineColorPicker({ id, host, value, onChange, previewValue, swatches = import_auto_paper.defaultColors, takenValue, allowSwapTaken, dark, align: forcedAlign, alignOverride, rotation: rotationOverride, icon = "palette", tag, labelFontFamily = MONO_FONT, autoDismiss = true, columns, size = DEFAULT_SIZE, renderSwatch, bounds }) {
198
+ const ambientRotation = (0, import_core.useRotation)();
199
+ const rotation = rotationOverride ?? ambientRotation;
200
+ const menuBg = dark ? "#000000" : "#FFFFFF";
201
+ const { width: windowWidth } = (0, import_react_native4.useWindowDimensions)();
202
+ const { width: swatchesWidth, height: swatchesHeight } = getInlineColorPickerContentSize(swatches.length, windowWidth, columns);
203
+ const open = host.openId === id;
204
+ const auto = useAutoAlign(open, swatchesWidth, swatchesHeight, rotation, bounds);
205
+ const placement = alignOverride ?? auto;
206
+ const { maxHeight, measured, triggerRef, verticalAlign } = placement;
207
+ const align = forcedAlign ?? placement.align;
208
+ const displayFor = previewValue ?? ((hex) => hex);
209
+ const displayValue = displayFor(value);
210
+ const contrastColor = (0, import_auto_paper.getContrastColor)(displayValue);
211
+ const tagFontSize = size * (tag && EMOJI_PATTERN.test(tag) ? 0.6 : 0.4);
212
+ const triggerDrawing = renderSwatch?.(displayValue, size, "trigger") ?? null;
213
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native4.View, { style: [styles2.anchor, open && styles2.anchorOpen], children: [
214
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_feedback_press.TouchableRipple, { onPress: () => host.toggle(id), borderless: true, style: [styles2.trigger, triggerDrawing === null && { backgroundColor: displayValue }, { borderRadius: size / 2, height: size, width: size }], children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native4.View, { ref: triggerRef, collapsable: false, style: styles2.triggerMeasure, children: [
215
+ triggerDrawing !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SwatchDrawing, { size, children: triggerDrawing }),
216
+ tag ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_paper.Text, { style: [styles2.tagLabel, { color: contrastColor, fontFamily: labelFontFamily, fontSize: tagFontSize }], numberOfLines: 1, adjustsFontSizeToFit: true, children: tag }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_paper.Icon, { source: icon, size: size * 0.6, color: contrastColor })
217
+ ] }) }),
218
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PopoverBody, { visible: open && measured, align, verticalAlign, caretColor: menuBg, caretBorderColor: displayValue, caretBorderWidth: SWATCHES_BORDER_WIDTH, triggerSize: size, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native4.ScrollView, { style: [styles2.swatches, { backgroundColor: menuBg, borderColor: displayValue, width: swatchesWidth, maxHeight }], contentContainerStyle: styles2.swatchesContent, showsVerticalScrollIndicator: false, children: swatches.map((swatch) => {
219
+ const selected = swatch.value.toLowerCase() === value.toLowerCase();
220
+ const taken = !selected && !!takenValue && swatch.value.toLowerCase() === takenValue.toLowerCase();
221
+ const swappable = taken && allowSwapTaken;
222
+ const swatchDisplay = displayFor(swatch.value);
223
+ const contrast = (0, import_auto_paper.getContrastColor)(swatchDisplay);
224
+ const drawnSize = selected ? SWATCH_SIZE - 2 * SWATCH_RING_WIDTH : SWATCH_SIZE;
225
+ const drawing = renderSwatch?.(swatchDisplay, drawnSize, "swatch") ?? null;
226
+ const mark = selected ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_paper.Icon, { source: "check", size: 16, color: contrast }) : swappable ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_paper.Icon, { source: "swap-horizontal", size: 16, color: contrast }) : taken ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_paper.Icon, { source: "close", size: 16, color: contrast }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native4.View, {});
227
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
228
+ import_feedback_press.TouchableRipple,
229
+ {
230
+ disabled: taken && !swappable,
231
+ onPress: () => {
232
+ onChange(swatch.value);
233
+ if (autoDismiss) host.close();
234
+ },
235
+ borderless: true,
236
+ style: [styles2.swatch, drawing === null && { backgroundColor: swatchDisplay }, selected && styles2.swatchSelected, taken && !swappable && styles2.swatchTaken],
237
+ children: drawing !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native4.View, { style: styles2.swatchFace, children: [
238
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SwatchDrawing, { size: drawnSize, children: drawing }),
239
+ mark
240
+ ] }) : mark
241
+ },
242
+ swatch.value
243
+ );
244
+ }) }) })
245
+ ] });
246
+ }
247
+ var styles2 = import_react_native4.StyleSheet.create({
248
+ anchor: {
249
+ position: "relative"
250
+ },
251
+ // See SectionedDropdown's identical comment - React Native Web gives every position:'relative' view
252
+ // its own stacking context, so the elevation has to live on the anchor itself, not just the
253
+ // popover content nested inside it, to correctly paint above this anchor's own later siblings.
254
+ anchorOpen: {
255
+ zIndex: 100
256
+ },
257
+ // A renderSwatch drawing (see SwatchDrawing).
258
+ drawing: {
259
+ left: 0,
260
+ overflow: "hidden",
261
+ pointerEvents: "none",
262
+ position: "absolute",
263
+ top: 0
264
+ },
265
+ swatch: {
266
+ alignItems: "center",
267
+ borderRadius: SWATCH_SIZE / 2,
268
+ height: SWATCH_SIZE,
269
+ justifyContent: "center",
270
+ width: SWATCH_SIZE
271
+ },
272
+ // A drawn swatch (see SwatchDrawing) and its mark: the whole circle inside the selected one's ring.
273
+ swatchFace: {
274
+ alignItems: "center",
275
+ bottom: 0,
276
+ justifyContent: "center",
277
+ left: 0,
278
+ position: "absolute",
279
+ right: 0,
280
+ top: 0
281
+ },
282
+ swatchSelected: {
283
+ borderColor: "#ffffff",
284
+ borderWidth: SWATCH_RING_WIDTH
285
+ },
286
+ swatchTaken: {
287
+ opacity: 0.35
288
+ },
289
+ swatches: {
290
+ borderRadius: 12,
291
+ borderWidth: SWATCHES_BORDER_WIDTH,
292
+ elevation: 8,
293
+ shadowColor: "#000000",
294
+ shadowOffset: { height: 2, width: 0 },
295
+ shadowOpacity: 0.3,
296
+ shadowRadius: 8
297
+ // width is set inline above - border-box sizing means it has to include the border too
298
+ // (2*SWATCHES_BORDER_WIDTH), not just padding+content, or exactly enough room goes missing that
299
+ // the last column silently wraps to a new row. Anything wider than the exact sum just shows as
300
+ // dead space on the right edge of each row instead.
301
+ },
302
+ // Separate from `swatches` itself - see SectionedDropdown's identical menu/menuContent split.
303
+ // The scroll frame's own bounds (including maxHeight) live on the ScrollView; the actual grid
304
+ // wrapping belongs to its contentContainerStyle, which sizes to the unclamped content instead.
305
+ swatchesContent: {
306
+ flexDirection: "row",
307
+ flexWrap: "wrap",
308
+ gap: SWATCHES_GAP,
309
+ padding: SWATCHES_PADDING
310
+ },
311
+ tagLabel: {
312
+ fontWeight: "700",
313
+ letterSpacing: 0.5
314
+ },
315
+ // borderRadius/height/width come from the `size` prop instead (see render-site override) - no
316
+ // fixed default here, since this style object is shared by every caller regardless of size.
317
+ trigger: {
318
+ alignItems: "center",
319
+ alignSelf: "flex-start",
320
+ justifyContent: "center"
321
+ },
322
+ // Wraps just the icon/tag, inside the TouchableRipple, purely so useAutoAlign has a plain View
323
+ // to attach its measurement ref to - TouchableRipple itself doesn't forward a ref to a
324
+ // measurable native node. Padded horizontally so a multi-character tag doesn't butt right up
325
+ // against the trigger's own circular edge (an icon alone doesn't need it, but this style is
326
+ // shared by both).
327
+ triggerMeasure: {
328
+ alignItems: "center",
329
+ height: "100%",
330
+ justifyContent: "center",
331
+ paddingHorizontal: 4,
332
+ width: "100%"
333
+ }
334
+ });
335
+
336
+ // src/ReadyButton.tsx
337
+ var import_feedback_press2 = require("@rific/feedback-press");
338
+ var import_react_native5 = require("react-native");
339
+ var import_react_native_paper2 = require("react-native-paper");
340
+ var import_jsx_runtime3 = require("react/jsx-runtime");
341
+ function ReadyButton({ color, ready, onToggleReady, style, labelFontFamily = MONO_FONT }) {
342
+ const readyButtonStyle = [styles3.readyButton, { borderColor: color }, ready && { backgroundColor: color }, style];
343
+ const labelTextStyle = { fontFamily: labelFontFamily, fontWeight: "bold" };
344
+ const labelColorStyle = { color: ready ? "#000000" : color };
345
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_feedback_press2.TouchableRipple, { onPress: onToggleReady, borderless: true, style: readyButtonStyle, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_paper2.Text, { variant: "labelLarge", style: [labelTextStyle, labelColorStyle], children: ready ? "READY \u2713" : "READY?" }) });
346
+ }
347
+ var styles3 = import_react_native5.StyleSheet.create({
348
+ readyButton: {
349
+ alignItems: "center",
350
+ borderRadius: 12,
351
+ borderWidth: 1,
352
+ justifyContent: "center",
353
+ minWidth: 120,
354
+ paddingHorizontal: 16,
355
+ paddingVertical: 10
356
+ }
357
+ });
358
+
359
+ // src/usePopoverHost.ts
360
+ var import_react2 = require("react");
361
+ function usePopoverHost() {
362
+ const [openId, setOpenId] = (0, import_react2.useState)(null);
363
+ const toggle = (0, import_react2.useCallback)((id) => {
364
+ setOpenId((prev) => prev === id ? null : id);
365
+ }, []);
366
+ const close = (0, import_react2.useCallback)(() => setOpenId(null), []);
367
+ return { openId, toggle, close };
368
+ }
369
+
370
+ // src/useZoneClampedAlign.ts
371
+ var import_split_screen = require("@tastic/split-screen");
372
+ var import_react3 = require("react");
373
+ var import_react_native6 = require("react-native");
374
+ var import_react_native_safe_area_context = require("react-native-safe-area-context");
375
+ var EDGE_MARGIN2 = 12;
376
+ function useZoneClampedAlign(open, contentWidth, contentHeight, rotation = 0) {
377
+ const auto = useAutoAlign(open, contentWidth, contentHeight, rotation);
378
+ const zone = (0, import_split_screen.useZoneBounds)();
379
+ const { height: windowHeight } = (0, import_react_native6.useWindowDimensions)();
380
+ const insets = (0, import_react_native_safe_area_context.useSafeAreaInsets)();
381
+ const shouldMeasure = open && auto.measured && zone !== null;
382
+ const [ownBounds, setOwnBounds] = (0, import_react3.useState)(null);
383
+ const [prevShouldMeasure, setPrevShouldMeasure] = (0, import_react3.useState)(shouldMeasure);
384
+ if (shouldMeasure !== prevShouldMeasure) {
385
+ setPrevShouldMeasure(shouldMeasure);
386
+ setOwnBounds(null);
387
+ }
388
+ (0, import_react3.useEffect)(() => {
389
+ if (!shouldMeasure) return;
390
+ auto.triggerRef.current?.measureInWindow((_x, y, _width, height) => {
391
+ const belowShared = zone.zoneSide === "belowShared";
392
+ const awayRoom = belowShared ? windowHeight - insets.bottom - (y + height) - EDGE_MARGIN2 : y - insets.top - EDGE_MARGIN2;
393
+ const towardRoom = belowShared ? y - zone.sharedEdgeY - EDGE_MARGIN2 : zone.sharedEdgeY - (y + height) - EDGE_MARGIN2;
394
+ const useToward = contentHeight > awayRoom && towardRoom > awayRoom;
395
+ let awaySide = belowShared ? "below" : "above";
396
+ let towardSide = belowShared ? "above" : "below";
397
+ if (zone.rotated) {
398
+ awaySide = awaySide === "above" ? "below" : "above";
399
+ towardSide = towardSide === "above" ? "below" : "above";
400
+ }
401
+ setOwnBounds({ maxHeight: Math.max(useToward ? towardRoom : awayRoom, 0), verticalAlign: useToward ? towardSide : awaySide });
402
+ });
403
+ }, [shouldMeasure, zone, auto.triggerRef, contentHeight, windowHeight, insets.top, insets.bottom]);
404
+ if (!zone) return auto;
405
+ if (!ownBounds) return { ...auto, measured: false };
406
+ return { ...auto, maxHeight: ownBounds.maxHeight, measured: auto.measured, verticalAlign: ownBounds.verticalAlign };
407
+ }
408
+
409
+ // src/PlayerSetupPanel.tsx
410
+ var import_jsx_runtime4 = require("react/jsx-runtime");
411
+ function getColorPopoverId(idPrefix) {
412
+ return `${idPrefix}-color`;
413
+ }
414
+ function getProfilePopoverId(idPrefix) {
415
+ return `${idPrefix}-profile`;
416
+ }
417
+ function getCpuDifficultyPopoverId(idPrefix) {
418
+ return `${idPrefix}-difficulty`;
419
+ }
420
+ function PlayerSetupPanel({ idPrefix, host, label, labelFontFamily, color, onColorChange, swatches, takenColor, allowSwapTaken, colorCaption, showColor = true, colorAlignOverride, colorRotation, isHuman, secondPicker, secondPickerId, ready, onToggleReady, dark, showReadyButton = true, profiles, selectedProfileId, takenProfileId, guestLabel, onProfileSelect, onManageProfiles, cpuDifficulty, cpuDifficultyOptions, onCpuDifficultyChange, humanIcon = "face-man", cpuIcon = "robot" }) {
421
+ const ownHost = usePopoverHost();
422
+ const popover = host ?? ownHost;
423
+ const ownPopoverOpen = popover.openId?.startsWith(`${idPrefix}-`) ?? false;
424
+ const pickerRowPopoverOpen = popover.openId === getColorPopoverId(idPrefix) || secondPickerId !== void 0 && popover.openId === secondPickerId;
425
+ const showProfilePicker = isHuman && profiles !== void 0 && !!onProfileSelect;
426
+ const showCpuDifficulty = !isHuman && cpuDifficulty !== void 0 && cpuDifficultyOptions !== void 0 && !!onCpuDifficultyChange;
427
+ const seatButton = showProfilePicker || showCpuDifficulty;
428
+ const selectedProfile = profiles?.find((p) => p.id === selectedProfileId) ?? null;
429
+ const colorSection = showColor ? { value: color, onChange: onColorChange, swatches, takenValue: takenColor, allowSwapTaken, caption: showProfilePicker && selectedProfile ? colorCaption : void 0 } : void 0;
430
+ const seatPickerId = showProfilePicker ? getProfilePopoverId(idPrefix) : getCpuDifficultyPopoverId(idPrefix);
431
+ const seatPickerSize = showProfilePicker ? (0, import_profile.getProfilePickerContentSize)(profiles.length, !!onManageProfiles, colorSection) : (0, import_profile.getOptionPickerContentSize)(cpuDifficultyOptions?.length ?? 0, colorSection);
432
+ const seatPickerAlign = useZoneClampedAlign(seatButton && popover.openId === seatPickerId, seatPickerSize.width, seatPickerSize.height);
433
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native7.View, { style: [styles4.panel, ownPopoverOpen && styles4.panelOpen], children: [
434
+ showProfilePicker ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_profile.ProfilePicker, { idPrefix, host: popover, profiles, selectedId: selectedProfileId ?? null, takenId: takenProfileId, color, dark, guestLabel: guestLabel ?? "GUEST", onSelect: (profile) => onProfileSelect?.(profile), onManage: onManageProfiles, colorSection, alignOverride: seatPickerAlign }) : showCpuDifficulty ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_profile.OptionPicker, { id: getCpuDifficultyPopoverId(idPrefix), host: popover, options: cpuDifficultyOptions, value: cpuDifficulty, onChange: onCpuDifficultyChange, color, dark, icon: cpuIcon, colorSection, alignOverride: seatPickerAlign }) : label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native_paper3.Text, { variant: "labelSmall", style: { color, fontFamily: labelFontFamily }, children: label }),
435
+ (!seatButton || secondPicker) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native7.View, { style: [styles4.pickerRow, pickerRowPopoverOpen && styles4.pickerRowOpen], children: [
436
+ !seatButton && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(InlineColorPicker, { id: getColorPopoverId(idPrefix), host: popover, value: color, onChange: onColorChange, swatches, takenValue: takenColor, allowSwapTaken, alignOverride: colorAlignOverride, rotation: colorRotation, dark, tag: isHuman ? selectedProfile?.tag : void 0, icon: isHuman ? humanIcon : cpuIcon }),
437
+ secondPicker
438
+ ] }),
439
+ isHuman && showReadyButton && onToggleReady && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ReadyButton, { color, ready: ready ?? false, onToggleReady })
440
+ ] });
441
+ }
442
+ var styles4 = import_react_native7.StyleSheet.create({
443
+ panel: {
444
+ alignItems: "center",
445
+ gap: 12
446
+ },
447
+ // See SectionedDropdown's anchorOpen comment - this panel is typically a sibling of another
448
+ // panel (and/or a shared-controls row), so a popover escaping this panel's bounds needs the panel
449
+ // itself elevated, not just the popover content, to paint above a later sibling.
450
+ panelOpen: {
451
+ zIndex: 100
452
+ },
453
+ // Same gap as `panel`'s own vertical rhythm, reused horizontally - the fallback color swatch and
454
+ // (when present) secondPicker sit side by side within this row instead of stacked in the panel's
455
+ // own column.
456
+ pickerRow: {
457
+ alignItems: "center",
458
+ flexDirection: "row",
459
+ gap: 12
460
+ },
461
+ // A popover is an absolutely-positioned sibling of its own trigger - so a tall one (the color
462
+ // swatch grid) can extend down far enough to overlap the ReadyButton below, which paints on top of
463
+ // it by default DOM order since it's a later sibling within `panel`. `panel`'s own panelOpen
464
+ // elevation only helps this panel paint above OTHER panels (see its own comment) - it does nothing
465
+ // for stacking *within* this panel, since React Native Web gives each View its own stacking
466
+ // context. This is what actually fixes that: elevate pickerRow itself above its own later sibling
467
+ // whenever one of its own popovers is open.
468
+ pickerRowOpen: {
469
+ zIndex: 100
470
+ }
471
+ });
472
+
473
+ // src/SharedActionBand.tsx
474
+ var import_feedback_press3 = require("@rific/feedback-press");
475
+ var import_react_native8 = require("react-native");
476
+ var import_jsx_runtime5 = require("react/jsx-runtime");
477
+ function SharedActionBand({ onBack, onSettings, onRandomize, onReset, fg, popoverOpen, children }) {
478
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native8.View, { style: [styles5.column, popoverOpen && styles5.columnOpen], children: [
479
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react_native8.View, { style: styles5.actionsRow, children: [
480
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_feedback_press3.IconButton, { icon: "arrow-left", iconColor: fg, size: 20, onPress: onBack, accessibilityLabel: "Back" }),
481
+ onRandomize && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_feedback_press3.IconButton, { icon: "dice-multiple", iconColor: fg, size: 18, onPress: onRandomize, accessibilityLabel: "Randomize match settings" }),
482
+ onReset && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_feedback_press3.IconButton, { icon: "restore", iconColor: fg, size: 18, onPress: onReset, accessibilityLabel: "Reset match settings to defaults" }),
483
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_feedback_press3.IconButton, { icon: "cog", iconColor: fg, size: 20, onPress: onSettings, accessibilityLabel: "Settings" })
484
+ ] }),
485
+ children
486
+ ] });
487
+ }
488
+ var styles5 = import_react_native8.StyleSheet.create({
489
+ actionsRow: {
490
+ alignItems: "center",
491
+ flexDirection: "row",
492
+ gap: 16
493
+ },
494
+ column: {
495
+ alignItems: "center",
496
+ gap: 8
497
+ },
498
+ columnOpen: {
499
+ zIndex: 100
500
+ }
501
+ });
502
+ // Annotate the CommonJS export names for ESM import in node:
503
+ 0 && (module.exports = {
504
+ PlayerSetupPanel,
505
+ ReadyButton,
506
+ SharedActionBand,
507
+ getColorPopoverId,
508
+ getCpuDifficultyPopoverId,
509
+ getProfilePopoverId,
510
+ useZoneClampedAlign
511
+ });
@@ -0,0 +1,19 @@
1
+ import {
2
+ PlayerSetupPanel,
3
+ ReadyButton,
4
+ SharedActionBand,
5
+ getColorPopoverId,
6
+ getCpuDifficultyPopoverId,
7
+ getProfilePopoverId,
8
+ useZoneClampedAlign
9
+ } from "../chunk-UO2V5C2U.mjs";
10
+ import "../chunk-FOJLQMKA.mjs";
11
+ export {
12
+ PlayerSetupPanel,
13
+ ReadyButton,
14
+ SharedActionBand,
15
+ getColorPopoverId,
16
+ getCpuDifficultyPopoverId,
17
+ getProfilePopoverId,
18
+ useZoneClampedAlign
19
+ };
@@ -0,0 +1,25 @@
1
+ import { ViewRotation } from '@tastic/core';
2
+ import { RefObject, ComponentRef } from 'react';
3
+ import { View } from 'react-native';
4
+
5
+ type PopoverAlign = 'left' | 'right' | 'center';
6
+ type PopoverVerticalAlign = 'below' | 'above';
7
+ type PopoverRotation = ViewRotation;
8
+ interface AlignResult {
9
+ align: PopoverAlign;
10
+ verticalAlign: PopoverVerticalAlign;
11
+ maxHeight: number;
12
+ measured: boolean;
13
+ triggerRef: RefObject<ViewInstance | null>;
14
+ }
15
+ type ViewInstance = ComponentRef<typeof View>;
16
+ declare function useAutoAlign(open: boolean, contentWidth: number, contentHeight: number, rotation?: PopoverRotation, bounds?: RefObject<ViewInstance | null>): AlignResult;
17
+
18
+ interface PopoverHost {
19
+ openId: string | null;
20
+ toggle: (id: string) => void;
21
+ close: () => void;
22
+ }
23
+ declare function usePopoverHost(): PopoverHost;
24
+
25
+ export { type AlignResult as A, type PopoverHost as P, type ViewInstance as V, type PopoverRotation as a, type PopoverAlign as b, type PopoverVerticalAlign as c, usePopoverHost as d, useAutoAlign as u };
@@ -0,0 +1,25 @@
1
+ import { ViewRotation } from '@tastic/core';
2
+ import { RefObject, ComponentRef } from 'react';
3
+ import { View } from 'react-native';
4
+
5
+ type PopoverAlign = 'left' | 'right' | 'center';
6
+ type PopoverVerticalAlign = 'below' | 'above';
7
+ type PopoverRotation = ViewRotation;
8
+ interface AlignResult {
9
+ align: PopoverAlign;
10
+ verticalAlign: PopoverVerticalAlign;
11
+ maxHeight: number;
12
+ measured: boolean;
13
+ triggerRef: RefObject<ViewInstance | null>;
14
+ }
15
+ type ViewInstance = ComponentRef<typeof View>;
16
+ declare function useAutoAlign(open: boolean, contentWidth: number, contentHeight: number, rotation?: PopoverRotation, bounds?: RefObject<ViewInstance | null>): AlignResult;
17
+
18
+ interface PopoverHost {
19
+ openId: string | null;
20
+ toggle: (id: string) => void;
21
+ close: () => void;
22
+ }
23
+ declare function usePopoverHost(): PopoverHost;
24
+
25
+ export { type AlignResult as A, type PopoverHost as P, type ViewInstance as V, type PopoverRotation as a, type PopoverAlign as b, type PopoverVerticalAlign as c, usePopoverHost as d, useAutoAlign as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tastic/hud",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Visual component kit for local-multiplayer React Native games: inline (non-modal) popovers, dropdowns, color pickers, gauges, ready buttons, and dialogs, built to stay scoped to one player's own zone on a shared screen",
5
5
  "keywords": [
6
6
  "react-native",
@@ -48,6 +48,13 @@
48
48
  "import": "./dist/guide/index.mjs",
49
49
  "require": "./dist/guide/index.js"
50
50
  },
51
+ "./lobby": {
52
+ "react-native": "./src/lobby/index.ts",
53
+ "browser": "./src/lobby/index.ts",
54
+ "types": "./dist/lobby/index.d.ts",
55
+ "import": "./dist/lobby/index.mjs",
56
+ "require": "./dist/lobby/index.js"
57
+ },
51
58
  "./skia": {
52
59
  "react-native": "./src/skia/index.ts",
53
60
  "browser": "./src/skia/index.ts",
@@ -87,15 +94,15 @@
87
94
  "@infinitetoken/eslint-config": "^0.2.1",
88
95
  "@infinitetoken/jest-config": "^0.5.2",
89
96
  "@infinitetoken/tsconfig": "^0.6.0",
90
- "@rific/auto-paper": "^0.13.3",
97
+ "@rific/auto-paper": "^0.13.4",
91
98
  "@rific/core": "^0.5.0",
92
99
  "@rific/feedback-press": "^0.13.1",
93
100
  "@rific/updater": "^0.7.1",
94
101
  "@shopify/react-native-skia": "^2.14.0",
95
102
  "@tastic/achievements": "^0.6.0",
96
103
  "@tastic/core": "^0.14.0",
97
- "@tastic/profile": "^0.16.2",
98
- "@tastic/split-screen": "^0.5.4",
104
+ "@tastic/profile": "^0.17.0",
105
+ "@tastic/split-screen": "^0.5.5",
99
106
  "@testing-library/dom": "^10.4.1",
100
107
  "@testing-library/react": "^16.3.2",
101
108
  "@types/jest": "^30.0.0",
@@ -5,6 +5,7 @@ import { ScrollView, StyleSheet, TextStyle, View } from 'react-native'
5
5
  import { Icon, Text } from 'react-native-paper'
6
6
 
7
7
  import { MONO_FONT } from './fonts'
8
+ import type { MenuOption } from './menuOption'
8
9
  import { PopoverBody } from './PopoverBody'
9
10
  import TriggerGaugeHost from './TriggerGaugeHost'
10
11
  import { AlignResult, PopoverRotation, useAutoAlign } from './useAutoAlign'
@@ -34,17 +35,9 @@ const MENU_ITEM_HEIGHT_WITH_DESCRIPTION = 58
34
35
  const MENU_DIVIDER_HEIGHT = 9
35
36
  const MENU_VERTICAL_PADDING = 12
36
37
 
37
- export interface MenuOption<T extends string | number> {
38
- value: T
39
- label: string
40
- description?: string
41
- // Optional per-option icon - when every option in a single-select section has one, the trigger
42
- // shows the currently selected option's icon instead of the static fallback, so the value is
43
- // readable at a glance without opening the dropdown. Unused by multi-select sections (there's no
44
- // single "the" selected option to show on the trigger).
45
- icon?: string
46
- iconSize?: number
47
- }
38
+ // In a module of its own (menuOption.ts) so `@tastic/hud/lobby` can export the type without
39
+ // reaching this file, which imports TriggerGaugeHost and so Skia.
40
+ export type { MenuOption } from './menuOption'
48
41
 
49
42
  // Exactly one of these can be true at a time - radio-style. Tapping a row selects it; whether that
50
43
  // also closes the popover is controlled by the dropdown's own `autoDismiss` prop.