@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.
- package/README.md +38 -11
- package/dist/chrome/index.d.mts +5 -29
- package/dist/chrome/index.d.ts +5 -29
- package/dist/chrome/index.mjs +9 -7
- package/dist/{chunk-AJD4FMG5.mjs → chunk-33MWHPPH.mjs} +26 -336
- package/dist/chunk-FOJLQMKA.mjs +315 -0
- package/dist/chunk-UO2V5C2U.mjs +175 -0
- package/dist/index-Bz4j509X.d.mts +96 -0
- package/dist/index-DW0PsGCE.d.ts +96 -0
- package/dist/index.d.mts +12 -97
- package/dist/index.d.ts +12 -97
- package/dist/index.mjs +26 -176
- package/dist/lobby/index.d.mts +7 -0
- package/dist/lobby/index.d.ts +7 -0
- package/dist/lobby/index.js +511 -0
- package/dist/lobby/index.mjs +19 -0
- package/dist/usePopoverHost-T8QWb2_A.d.mts +25 -0
- package/dist/usePopoverHost-T8QWb2_A.d.ts +25 -0
- package/package.json +11 -4
- package/src/SectionedDropdown.tsx +4 -11
- package/src/lobby/index.ts +13 -0
- package/src/menuOption.ts +14 -0
- package/src/useAutoAlign.ts +4 -1
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// src/fonts.ts
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
var MONO_FONT = Platform.select({ ios: "Menlo", android: "monospace", default: "monospace" });
|
|
4
|
+
|
|
5
|
+
// src/PopoverBody.tsx
|
|
6
|
+
import { StyleSheet, View } from "react-native";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
var CARET_SIZE = 7;
|
|
9
|
+
var CARET_RING_OFFSET = 2;
|
|
10
|
+
var CARET_DIP = 1;
|
|
11
|
+
function PopoverBody({ visible, children, align = "center", verticalAlign = "below", caretColor, caretBorderColor, caretBorderWidth = 1, triggerSize = 0 }) {
|
|
12
|
+
if (!visible) return null;
|
|
13
|
+
const above = verticalAlign === "above";
|
|
14
|
+
const alignStyle = align === "left" ? styles.contentLeft : align === "right" ? styles.contentRight : styles.contentCenter;
|
|
15
|
+
const verticalStyle = above ? styles.contentAbove : styles.contentBelow;
|
|
16
|
+
const ringSize = CARET_SIZE + caretBorderWidth;
|
|
17
|
+
const caretOffset = (halfFootprint) => align === "right" ? { right: triggerSize / 2 - halfFootprint } : { left: triggerSize / 2 - halfFootprint };
|
|
18
|
+
const caretFill = above ? "borderTopColor" : "borderBottomColor";
|
|
19
|
+
const caretWidthProp = above ? "borderTopWidth" : "borderBottomWidth";
|
|
20
|
+
const caretEdge = (size) => above ? { bottom: -size + CARET_DIP } : { top: -size + CARET_DIP };
|
|
21
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles.content, alignStyle, verticalStyle], children: [
|
|
22
|
+
children,
|
|
23
|
+
caretColor && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24
|
+
/* @__PURE__ */ jsx(View, { style: [styles.caret, caretOffset(ringSize), caretEdge(ringSize), { [caretFill]: caretBorderColor ?? caretColor, [caretWidthProp]: ringSize, borderLeftWidth: ringSize, borderRightWidth: ringSize }] }),
|
|
25
|
+
/* @__PURE__ */ jsx(View, { style: [styles.caret, caretOffset(CARET_SIZE), caretEdge(CARET_SIZE - CARET_RING_OFFSET), { [caretFill]: caretColor, [caretWidthProp]: CARET_SIZE, borderLeftWidth: CARET_SIZE, borderRightWidth: CARET_SIZE }] })
|
|
26
|
+
] })
|
|
27
|
+
] });
|
|
28
|
+
}
|
|
29
|
+
var styles = StyleSheet.create({
|
|
30
|
+
caret: {
|
|
31
|
+
borderLeftColor: "transparent",
|
|
32
|
+
borderRightColor: "transparent",
|
|
33
|
+
height: 0,
|
|
34
|
+
position: "absolute",
|
|
35
|
+
width: 0,
|
|
36
|
+
// Explicit, not left to DOM order - the box it dips into is itself a position:'relative' view,
|
|
37
|
+
// which React Native Web always gives an implicit zIndex:0 (see PopoverBody's stacking-context
|
|
38
|
+
// notes elsewhere in this codebase), so painting on top needs a real zIndex to beat that
|
|
39
|
+
// reliably rather than relying on being the later sibling.
|
|
40
|
+
zIndex: 1
|
|
41
|
+
},
|
|
42
|
+
content: {
|
|
43
|
+
position: "absolute",
|
|
44
|
+
zIndex: 50
|
|
45
|
+
},
|
|
46
|
+
contentAbove: {
|
|
47
|
+
bottom: "100%",
|
|
48
|
+
marginBottom: 8
|
|
49
|
+
},
|
|
50
|
+
contentBelow: {
|
|
51
|
+
marginTop: 8,
|
|
52
|
+
top: "100%"
|
|
53
|
+
},
|
|
54
|
+
// Stretched to the anchor's own (trigger) width, with alignItems centering the actual (usually
|
|
55
|
+
// much wider) popover box inside via plain flexbox - not `left:'50%'` plus a percentage
|
|
56
|
+
// `transform`, which depends on native resolving the box's own auto width before applying the
|
|
57
|
+
// transform and has proven unreliable there, visibly shifting the box off-center.
|
|
58
|
+
contentCenter: {
|
|
59
|
+
alignItems: "center",
|
|
60
|
+
left: 0,
|
|
61
|
+
right: 0
|
|
62
|
+
},
|
|
63
|
+
contentLeft: {
|
|
64
|
+
left: 0
|
|
65
|
+
},
|
|
66
|
+
contentRight: {
|
|
67
|
+
right: 0
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// src/useAutoAlign.ts
|
|
72
|
+
import { useEffect, useRef, useState } from "react";
|
|
73
|
+
import { useWindowDimensions } from "react-native";
|
|
74
|
+
var EDGE_MARGIN = 12;
|
|
75
|
+
function rotateRect(x, y, width, height, rotation, windowWidth, windowHeight) {
|
|
76
|
+
if (rotation === 0) return { x, y, width, height };
|
|
77
|
+
const cx = windowWidth / 2;
|
|
78
|
+
const cy = windowHeight / 2;
|
|
79
|
+
const dx = x + width / 2 - cx;
|
|
80
|
+
const dy = y + height / 2 - cy;
|
|
81
|
+
const [newDx, newDy, newWidth, newHeight] = rotation === 180 ? [-dx, -dy, width, height] : rotation === 90 ? [-dy, dx, height, width] : [dy, -dx, height, width];
|
|
82
|
+
return { x: cx + newDx - newWidth / 2, y: cy + newDy - newHeight / 2, width: newWidth, height: newHeight };
|
|
83
|
+
}
|
|
84
|
+
function useAutoAlign(open, contentWidth, contentHeight, rotation = 0, bounds) {
|
|
85
|
+
const triggerRef = useRef(null);
|
|
86
|
+
const { width: windowWidth, height: windowHeight } = useWindowDimensions();
|
|
87
|
+
const [align, setAlign] = useState("center");
|
|
88
|
+
const [verticalAlign, setVerticalAlign] = useState("below");
|
|
89
|
+
const [maxHeight, setMaxHeight] = useState(contentHeight);
|
|
90
|
+
const [measured, setMeasured] = useState(false);
|
|
91
|
+
const [prevOpen, setPrevOpen] = useState(open);
|
|
92
|
+
if (open !== prevOpen) {
|
|
93
|
+
setPrevOpen(open);
|
|
94
|
+
if (open) setMeasured(false);
|
|
95
|
+
}
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!open) return;
|
|
98
|
+
const place = (limits) => (rawX, rawY, rawWidth, rawHeight) => {
|
|
99
|
+
const { x, y, width: triggerWidth, height: triggerHeight } = rotateRect(rawX, rawY, rawWidth, rawHeight, rotation, windowWidth, windowHeight);
|
|
100
|
+
const centerX = x + triggerWidth / 2;
|
|
101
|
+
const overflowsRight = centerX + contentWidth / 2 > limits.right - EDGE_MARGIN;
|
|
102
|
+
const overflowsLeft = centerX - contentWidth / 2 < limits.left + EDGE_MARGIN;
|
|
103
|
+
if (overflowsRight && !overflowsLeft) setAlign("right");
|
|
104
|
+
else if (overflowsLeft && !overflowsRight) setAlign("left");
|
|
105
|
+
else setAlign("center");
|
|
106
|
+
const roomBelow = limits.bottom - (y + triggerHeight) - EDGE_MARGIN;
|
|
107
|
+
const roomAbove = y - limits.top - EDGE_MARGIN;
|
|
108
|
+
const above = contentHeight > roomBelow && roomAbove > roomBelow;
|
|
109
|
+
setVerticalAlign(above ? "above" : "below");
|
|
110
|
+
setMaxHeight(Math.max(above ? roomAbove : roomBelow, 0));
|
|
111
|
+
setMeasured(true);
|
|
112
|
+
};
|
|
113
|
+
const screen = { left: 0, top: 0, right: windowWidth, bottom: windowHeight };
|
|
114
|
+
const boundsView = bounds?.current;
|
|
115
|
+
if (!boundsView) {
|
|
116
|
+
triggerRef.current?.measureInWindow(place(screen));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
boundsView.measureInWindow((rawX, rawY, rawWidth, rawHeight) => {
|
|
120
|
+
const b = rotateRect(rawX, rawY, rawWidth, rawHeight, rotation, windowWidth, windowHeight);
|
|
121
|
+
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) }));
|
|
122
|
+
});
|
|
123
|
+
}, [open, contentWidth, contentHeight, windowWidth, windowHeight, rotation, bounds]);
|
|
124
|
+
return { align, maxHeight, measured, triggerRef, verticalAlign };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/InlineColorPicker.tsx
|
|
128
|
+
import { defaultColors, getContrastColor } from "@rific/auto-paper";
|
|
129
|
+
import { TouchableRipple } from "@rific/feedback-press";
|
|
130
|
+
import { clamp, useRotation } from "@tastic/core";
|
|
131
|
+
import { ScrollView, StyleSheet as StyleSheet2, useWindowDimensions as useWindowDimensions2, View as View3 } from "react-native";
|
|
132
|
+
import { Icon, Text } from "react-native-paper";
|
|
133
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
134
|
+
var EMOJI_PATTERN = /\p{Extended_Pictographic}/u;
|
|
135
|
+
var DEFAULT_SIZE = 48;
|
|
136
|
+
var SWATCH_SIZE = 28;
|
|
137
|
+
var SWATCH_RING_WIDTH = 2;
|
|
138
|
+
var SWATCHES_PADDING = 8;
|
|
139
|
+
var SWATCHES_GAP = 6;
|
|
140
|
+
var SWATCHES_BORDER_WIDTH = 2;
|
|
141
|
+
var MIN_COLUMNS = 4;
|
|
142
|
+
var MAX_COLUMNS = 5;
|
|
143
|
+
var SCREEN_MARGIN = 40;
|
|
144
|
+
function widthForColumns(columns) {
|
|
145
|
+
return SWATCHES_BORDER_WIDTH * 2 + SWATCHES_PADDING * 2 + SWATCH_SIZE * columns + SWATCHES_GAP * (columns - 1);
|
|
146
|
+
}
|
|
147
|
+
function getInlineColorPickerContentSize(swatchCount, windowWidth, columns) {
|
|
148
|
+
const autoColumns = clamp(Math.floor((windowWidth - 2 * SCREEN_MARGIN + SWATCHES_GAP) / (SWATCH_SIZE + SWATCHES_GAP)), MIN_COLUMNS, MAX_COLUMNS);
|
|
149
|
+
const resolvedColumns = columns ?? autoColumns;
|
|
150
|
+
const width = widthForColumns(resolvedColumns);
|
|
151
|
+
const rows = Math.ceil(swatchCount / resolvedColumns);
|
|
152
|
+
const height = SWATCHES_BORDER_WIDTH * 2 + SWATCHES_PADDING * 2 + SWATCH_SIZE * rows + SWATCHES_GAP * (rows - 1);
|
|
153
|
+
return { width, height };
|
|
154
|
+
}
|
|
155
|
+
function SwatchDrawing({ size, children }) {
|
|
156
|
+
return /* @__PURE__ */ jsx2(View3, { style: [styles2.drawing, { borderRadius: size / 2, height: size, width: size }], children });
|
|
157
|
+
}
|
|
158
|
+
function InlineColorPicker({ id, host, value, onChange, previewValue, swatches = defaultColors, takenValue, allowSwapTaken, dark, align: forcedAlign, alignOverride, rotation: rotationOverride, icon = "palette", tag, labelFontFamily = MONO_FONT, autoDismiss = true, columns, size = DEFAULT_SIZE, renderSwatch, bounds }) {
|
|
159
|
+
const ambientRotation = useRotation();
|
|
160
|
+
const rotation = rotationOverride ?? ambientRotation;
|
|
161
|
+
const menuBg = dark ? "#000000" : "#FFFFFF";
|
|
162
|
+
const { width: windowWidth } = useWindowDimensions2();
|
|
163
|
+
const { width: swatchesWidth, height: swatchesHeight } = getInlineColorPickerContentSize(swatches.length, windowWidth, columns);
|
|
164
|
+
const open = host.openId === id;
|
|
165
|
+
const auto = useAutoAlign(open, swatchesWidth, swatchesHeight, rotation, bounds);
|
|
166
|
+
const placement = alignOverride ?? auto;
|
|
167
|
+
const { maxHeight, measured, triggerRef, verticalAlign } = placement;
|
|
168
|
+
const align = forcedAlign ?? placement.align;
|
|
169
|
+
const displayFor = previewValue ?? ((hex) => hex);
|
|
170
|
+
const displayValue = displayFor(value);
|
|
171
|
+
const contrastColor = getContrastColor(displayValue);
|
|
172
|
+
const tagFontSize = size * (tag && EMOJI_PATTERN.test(tag) ? 0.6 : 0.4);
|
|
173
|
+
const triggerDrawing = renderSwatch?.(displayValue, size, "trigger") ?? null;
|
|
174
|
+
return /* @__PURE__ */ jsxs2(View3, { style: [styles2.anchor, open && styles2.anchorOpen], children: [
|
|
175
|
+
/* @__PURE__ */ jsx2(TouchableRipple, { onPress: () => host.toggle(id), borderless: true, style: [styles2.trigger, triggerDrawing === null && { backgroundColor: displayValue }, { borderRadius: size / 2, height: size, width: size }], children: /* @__PURE__ */ jsxs2(View3, { ref: triggerRef, collapsable: false, style: styles2.triggerMeasure, children: [
|
|
176
|
+
triggerDrawing !== null && /* @__PURE__ */ jsx2(SwatchDrawing, { size, children: triggerDrawing }),
|
|
177
|
+
tag ? /* @__PURE__ */ jsx2(Text, { style: [styles2.tagLabel, { color: contrastColor, fontFamily: labelFontFamily, fontSize: tagFontSize }], numberOfLines: 1, adjustsFontSizeToFit: true, children: tag }) : /* @__PURE__ */ jsx2(Icon, { source: icon, size: size * 0.6, color: contrastColor })
|
|
178
|
+
] }) }),
|
|
179
|
+
/* @__PURE__ */ jsx2(PopoverBody, { visible: open && measured, align, verticalAlign, caretColor: menuBg, caretBorderColor: displayValue, caretBorderWidth: SWATCHES_BORDER_WIDTH, triggerSize: size, children: /* @__PURE__ */ jsx2(ScrollView, { style: [styles2.swatches, { backgroundColor: menuBg, borderColor: displayValue, width: swatchesWidth, maxHeight }], contentContainerStyle: styles2.swatchesContent, showsVerticalScrollIndicator: false, children: swatches.map((swatch) => {
|
|
180
|
+
const selected = swatch.value.toLowerCase() === value.toLowerCase();
|
|
181
|
+
const taken = !selected && !!takenValue && swatch.value.toLowerCase() === takenValue.toLowerCase();
|
|
182
|
+
const swappable = taken && allowSwapTaken;
|
|
183
|
+
const swatchDisplay = displayFor(swatch.value);
|
|
184
|
+
const contrast = getContrastColor(swatchDisplay);
|
|
185
|
+
const drawnSize = selected ? SWATCH_SIZE - 2 * SWATCH_RING_WIDTH : SWATCH_SIZE;
|
|
186
|
+
const drawing = renderSwatch?.(swatchDisplay, drawnSize, "swatch") ?? null;
|
|
187
|
+
const mark = selected ? /* @__PURE__ */ jsx2(Icon, { source: "check", size: 16, color: contrast }) : swappable ? /* @__PURE__ */ jsx2(Icon, { source: "swap-horizontal", size: 16, color: contrast }) : taken ? /* @__PURE__ */ jsx2(Icon, { source: "close", size: 16, color: contrast }) : /* @__PURE__ */ jsx2(View3, {});
|
|
188
|
+
return /* @__PURE__ */ jsx2(
|
|
189
|
+
TouchableRipple,
|
|
190
|
+
{
|
|
191
|
+
disabled: taken && !swappable,
|
|
192
|
+
onPress: () => {
|
|
193
|
+
onChange(swatch.value);
|
|
194
|
+
if (autoDismiss) host.close();
|
|
195
|
+
},
|
|
196
|
+
borderless: true,
|
|
197
|
+
style: [styles2.swatch, drawing === null && { backgroundColor: swatchDisplay }, selected && styles2.swatchSelected, taken && !swappable && styles2.swatchTaken],
|
|
198
|
+
children: drawing !== null ? /* @__PURE__ */ jsxs2(View3, { style: styles2.swatchFace, children: [
|
|
199
|
+
/* @__PURE__ */ jsx2(SwatchDrawing, { size: drawnSize, children: drawing }),
|
|
200
|
+
mark
|
|
201
|
+
] }) : mark
|
|
202
|
+
},
|
|
203
|
+
swatch.value
|
|
204
|
+
);
|
|
205
|
+
}) }) })
|
|
206
|
+
] });
|
|
207
|
+
}
|
|
208
|
+
var styles2 = StyleSheet2.create({
|
|
209
|
+
anchor: {
|
|
210
|
+
position: "relative"
|
|
211
|
+
},
|
|
212
|
+
// See SectionedDropdown's identical comment - React Native Web gives every position:'relative' view
|
|
213
|
+
// its own stacking context, so the elevation has to live on the anchor itself, not just the
|
|
214
|
+
// popover content nested inside it, to correctly paint above this anchor's own later siblings.
|
|
215
|
+
anchorOpen: {
|
|
216
|
+
zIndex: 100
|
|
217
|
+
},
|
|
218
|
+
// A renderSwatch drawing (see SwatchDrawing).
|
|
219
|
+
drawing: {
|
|
220
|
+
left: 0,
|
|
221
|
+
overflow: "hidden",
|
|
222
|
+
pointerEvents: "none",
|
|
223
|
+
position: "absolute",
|
|
224
|
+
top: 0
|
|
225
|
+
},
|
|
226
|
+
swatch: {
|
|
227
|
+
alignItems: "center",
|
|
228
|
+
borderRadius: SWATCH_SIZE / 2,
|
|
229
|
+
height: SWATCH_SIZE,
|
|
230
|
+
justifyContent: "center",
|
|
231
|
+
width: SWATCH_SIZE
|
|
232
|
+
},
|
|
233
|
+
// A drawn swatch (see SwatchDrawing) and its mark: the whole circle inside the selected one's ring.
|
|
234
|
+
swatchFace: {
|
|
235
|
+
alignItems: "center",
|
|
236
|
+
bottom: 0,
|
|
237
|
+
justifyContent: "center",
|
|
238
|
+
left: 0,
|
|
239
|
+
position: "absolute",
|
|
240
|
+
right: 0,
|
|
241
|
+
top: 0
|
|
242
|
+
},
|
|
243
|
+
swatchSelected: {
|
|
244
|
+
borderColor: "#ffffff",
|
|
245
|
+
borderWidth: SWATCH_RING_WIDTH
|
|
246
|
+
},
|
|
247
|
+
swatchTaken: {
|
|
248
|
+
opacity: 0.35
|
|
249
|
+
},
|
|
250
|
+
swatches: {
|
|
251
|
+
borderRadius: 12,
|
|
252
|
+
borderWidth: SWATCHES_BORDER_WIDTH,
|
|
253
|
+
elevation: 8,
|
|
254
|
+
shadowColor: "#000000",
|
|
255
|
+
shadowOffset: { height: 2, width: 0 },
|
|
256
|
+
shadowOpacity: 0.3,
|
|
257
|
+
shadowRadius: 8
|
|
258
|
+
// width is set inline above - border-box sizing means it has to include the border too
|
|
259
|
+
// (2*SWATCHES_BORDER_WIDTH), not just padding+content, or exactly enough room goes missing that
|
|
260
|
+
// the last column silently wraps to a new row. Anything wider than the exact sum just shows as
|
|
261
|
+
// dead space on the right edge of each row instead.
|
|
262
|
+
},
|
|
263
|
+
// Separate from `swatches` itself - see SectionedDropdown's identical menu/menuContent split.
|
|
264
|
+
// The scroll frame's own bounds (including maxHeight) live on the ScrollView; the actual grid
|
|
265
|
+
// wrapping belongs to its contentContainerStyle, which sizes to the unclamped content instead.
|
|
266
|
+
swatchesContent: {
|
|
267
|
+
flexDirection: "row",
|
|
268
|
+
flexWrap: "wrap",
|
|
269
|
+
gap: SWATCHES_GAP,
|
|
270
|
+
padding: SWATCHES_PADDING
|
|
271
|
+
},
|
|
272
|
+
tagLabel: {
|
|
273
|
+
fontWeight: "700",
|
|
274
|
+
letterSpacing: 0.5
|
|
275
|
+
},
|
|
276
|
+
// borderRadius/height/width come from the `size` prop instead (see render-site override) - no
|
|
277
|
+
// fixed default here, since this style object is shared by every caller regardless of size.
|
|
278
|
+
trigger: {
|
|
279
|
+
alignItems: "center",
|
|
280
|
+
alignSelf: "flex-start",
|
|
281
|
+
justifyContent: "center"
|
|
282
|
+
},
|
|
283
|
+
// Wraps just the icon/tag, inside the TouchableRipple, purely so useAutoAlign has a plain View
|
|
284
|
+
// to attach its measurement ref to - TouchableRipple itself doesn't forward a ref to a
|
|
285
|
+
// measurable native node. Padded horizontally so a multi-character tag doesn't butt right up
|
|
286
|
+
// against the trigger's own circular edge (an icon alone doesn't need it, but this style is
|
|
287
|
+
// shared by both).
|
|
288
|
+
triggerMeasure: {
|
|
289
|
+
alignItems: "center",
|
|
290
|
+
height: "100%",
|
|
291
|
+
justifyContent: "center",
|
|
292
|
+
paddingHorizontal: 4,
|
|
293
|
+
width: "100%"
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// src/usePopoverHost.ts
|
|
298
|
+
import { useCallback, useState as useState2 } from "react";
|
|
299
|
+
function usePopoverHost() {
|
|
300
|
+
const [openId, setOpenId] = useState2(null);
|
|
301
|
+
const toggle = useCallback((id) => {
|
|
302
|
+
setOpenId((prev) => prev === id ? null : id);
|
|
303
|
+
}, []);
|
|
304
|
+
const close = useCallback(() => setOpenId(null), []);
|
|
305
|
+
return { openId, toggle, close };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export {
|
|
309
|
+
MONO_FONT,
|
|
310
|
+
PopoverBody,
|
|
311
|
+
useAutoAlign,
|
|
312
|
+
getInlineColorPickerContentSize,
|
|
313
|
+
InlineColorPicker,
|
|
314
|
+
usePopoverHost
|
|
315
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InlineColorPicker,
|
|
3
|
+
MONO_FONT,
|
|
4
|
+
useAutoAlign,
|
|
5
|
+
usePopoverHost
|
|
6
|
+
} from "./chunk-FOJLQMKA.mjs";
|
|
7
|
+
|
|
8
|
+
// src/ReadyButton.tsx
|
|
9
|
+
import { TouchableRipple } from "@rific/feedback-press";
|
|
10
|
+
import { StyleSheet } from "react-native";
|
|
11
|
+
import { Text } from "react-native-paper";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
function ReadyButton({ color, ready, onToggleReady, style, labelFontFamily = MONO_FONT }) {
|
|
14
|
+
const readyButtonStyle = [styles.readyButton, { borderColor: color }, ready && { backgroundColor: color }, style];
|
|
15
|
+
const labelTextStyle = { fontFamily: labelFontFamily, fontWeight: "bold" };
|
|
16
|
+
const labelColorStyle = { color: ready ? "#000000" : color };
|
|
17
|
+
return /* @__PURE__ */ jsx(TouchableRipple, { onPress: onToggleReady, borderless: true, style: readyButtonStyle, children: /* @__PURE__ */ jsx(Text, { variant: "labelLarge", style: [labelTextStyle, labelColorStyle], children: ready ? "READY \u2713" : "READY?" }) });
|
|
18
|
+
}
|
|
19
|
+
var styles = StyleSheet.create({
|
|
20
|
+
readyButton: {
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
borderRadius: 12,
|
|
23
|
+
borderWidth: 1,
|
|
24
|
+
justifyContent: "center",
|
|
25
|
+
minWidth: 120,
|
|
26
|
+
paddingHorizontal: 16,
|
|
27
|
+
paddingVertical: 10
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// src/useZoneClampedAlign.ts
|
|
32
|
+
import { useZoneBounds } from "@tastic/split-screen";
|
|
33
|
+
import { useEffect, useState } from "react";
|
|
34
|
+
import { useWindowDimensions } from "react-native";
|
|
35
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
36
|
+
var EDGE_MARGIN = 12;
|
|
37
|
+
function useZoneClampedAlign(open, contentWidth, contentHeight, rotation = 0) {
|
|
38
|
+
const auto = useAutoAlign(open, contentWidth, contentHeight, rotation);
|
|
39
|
+
const zone = useZoneBounds();
|
|
40
|
+
const { height: windowHeight } = useWindowDimensions();
|
|
41
|
+
const insets = useSafeAreaInsets();
|
|
42
|
+
const shouldMeasure = open && auto.measured && zone !== null;
|
|
43
|
+
const [ownBounds, setOwnBounds] = useState(null);
|
|
44
|
+
const [prevShouldMeasure, setPrevShouldMeasure] = useState(shouldMeasure);
|
|
45
|
+
if (shouldMeasure !== prevShouldMeasure) {
|
|
46
|
+
setPrevShouldMeasure(shouldMeasure);
|
|
47
|
+
setOwnBounds(null);
|
|
48
|
+
}
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!shouldMeasure) return;
|
|
51
|
+
auto.triggerRef.current?.measureInWindow((_x, y, _width, height) => {
|
|
52
|
+
const belowShared = zone.zoneSide === "belowShared";
|
|
53
|
+
const awayRoom = belowShared ? windowHeight - insets.bottom - (y + height) - EDGE_MARGIN : y - insets.top - EDGE_MARGIN;
|
|
54
|
+
const towardRoom = belowShared ? y - zone.sharedEdgeY - EDGE_MARGIN : zone.sharedEdgeY - (y + height) - EDGE_MARGIN;
|
|
55
|
+
const useToward = contentHeight > awayRoom && towardRoom > awayRoom;
|
|
56
|
+
let awaySide = belowShared ? "below" : "above";
|
|
57
|
+
let towardSide = belowShared ? "above" : "below";
|
|
58
|
+
if (zone.rotated) {
|
|
59
|
+
awaySide = awaySide === "above" ? "below" : "above";
|
|
60
|
+
towardSide = towardSide === "above" ? "below" : "above";
|
|
61
|
+
}
|
|
62
|
+
setOwnBounds({ maxHeight: Math.max(useToward ? towardRoom : awayRoom, 0), verticalAlign: useToward ? towardSide : awaySide });
|
|
63
|
+
});
|
|
64
|
+
}, [shouldMeasure, zone, auto.triggerRef, contentHeight, windowHeight, insets.top, insets.bottom]);
|
|
65
|
+
if (!zone) return auto;
|
|
66
|
+
if (!ownBounds) return { ...auto, measured: false };
|
|
67
|
+
return { ...auto, maxHeight: ownBounds.maxHeight, measured: auto.measured, verticalAlign: ownBounds.verticalAlign };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/PlayerSetupPanel.tsx
|
|
71
|
+
import { getOptionPickerContentSize, getProfilePickerContentSize, OptionPicker, ProfilePicker } from "@tastic/profile";
|
|
72
|
+
import { StyleSheet as StyleSheet2, View } from "react-native";
|
|
73
|
+
import { Text as Text2 } from "react-native-paper";
|
|
74
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
75
|
+
function getColorPopoverId(idPrefix) {
|
|
76
|
+
return `${idPrefix}-color`;
|
|
77
|
+
}
|
|
78
|
+
function getProfilePopoverId(idPrefix) {
|
|
79
|
+
return `${idPrefix}-profile`;
|
|
80
|
+
}
|
|
81
|
+
function getCpuDifficultyPopoverId(idPrefix) {
|
|
82
|
+
return `${idPrefix}-difficulty`;
|
|
83
|
+
}
|
|
84
|
+
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" }) {
|
|
85
|
+
const ownHost = usePopoverHost();
|
|
86
|
+
const popover = host ?? ownHost;
|
|
87
|
+
const ownPopoverOpen = popover.openId?.startsWith(`${idPrefix}-`) ?? false;
|
|
88
|
+
const pickerRowPopoverOpen = popover.openId === getColorPopoverId(idPrefix) || secondPickerId !== void 0 && popover.openId === secondPickerId;
|
|
89
|
+
const showProfilePicker = isHuman && profiles !== void 0 && !!onProfileSelect;
|
|
90
|
+
const showCpuDifficulty = !isHuman && cpuDifficulty !== void 0 && cpuDifficultyOptions !== void 0 && !!onCpuDifficultyChange;
|
|
91
|
+
const seatButton = showProfilePicker || showCpuDifficulty;
|
|
92
|
+
const selectedProfile = profiles?.find((p) => p.id === selectedProfileId) ?? null;
|
|
93
|
+
const colorSection = showColor ? { value: color, onChange: onColorChange, swatches, takenValue: takenColor, allowSwapTaken, caption: showProfilePicker && selectedProfile ? colorCaption : void 0 } : void 0;
|
|
94
|
+
const seatPickerId = showProfilePicker ? getProfilePopoverId(idPrefix) : getCpuDifficultyPopoverId(idPrefix);
|
|
95
|
+
const seatPickerSize = showProfilePicker ? getProfilePickerContentSize(profiles.length, !!onManageProfiles, colorSection) : getOptionPickerContentSize(cpuDifficultyOptions?.length ?? 0, colorSection);
|
|
96
|
+
const seatPickerAlign = useZoneClampedAlign(seatButton && popover.openId === seatPickerId, seatPickerSize.width, seatPickerSize.height);
|
|
97
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles2.panel, ownPopoverOpen && styles2.panelOpen], children: [
|
|
98
|
+
showProfilePicker ? /* @__PURE__ */ jsx2(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__ */ jsx2(OptionPicker, { id: getCpuDifficultyPopoverId(idPrefix), host: popover, options: cpuDifficultyOptions, value: cpuDifficulty, onChange: onCpuDifficultyChange, color, dark, icon: cpuIcon, colorSection, alignOverride: seatPickerAlign }) : label && /* @__PURE__ */ jsx2(Text2, { variant: "labelSmall", style: { color, fontFamily: labelFontFamily }, children: label }),
|
|
99
|
+
(!seatButton || secondPicker) && /* @__PURE__ */ jsxs(View, { style: [styles2.pickerRow, pickerRowPopoverOpen && styles2.pickerRowOpen], children: [
|
|
100
|
+
!seatButton && /* @__PURE__ */ jsx2(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 }),
|
|
101
|
+
secondPicker
|
|
102
|
+
] }),
|
|
103
|
+
isHuman && showReadyButton && onToggleReady && /* @__PURE__ */ jsx2(ReadyButton, { color, ready: ready ?? false, onToggleReady })
|
|
104
|
+
] });
|
|
105
|
+
}
|
|
106
|
+
var styles2 = StyleSheet2.create({
|
|
107
|
+
panel: {
|
|
108
|
+
alignItems: "center",
|
|
109
|
+
gap: 12
|
|
110
|
+
},
|
|
111
|
+
// See SectionedDropdown's anchorOpen comment - this panel is typically a sibling of another
|
|
112
|
+
// panel (and/or a shared-controls row), so a popover escaping this panel's bounds needs the panel
|
|
113
|
+
// itself elevated, not just the popover content, to paint above a later sibling.
|
|
114
|
+
panelOpen: {
|
|
115
|
+
zIndex: 100
|
|
116
|
+
},
|
|
117
|
+
// Same gap as `panel`'s own vertical rhythm, reused horizontally - the fallback color swatch and
|
|
118
|
+
// (when present) secondPicker sit side by side within this row instead of stacked in the panel's
|
|
119
|
+
// own column.
|
|
120
|
+
pickerRow: {
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
flexDirection: "row",
|
|
123
|
+
gap: 12
|
|
124
|
+
},
|
|
125
|
+
// A popover is an absolutely-positioned sibling of its own trigger - so a tall one (the color
|
|
126
|
+
// swatch grid) can extend down far enough to overlap the ReadyButton below, which paints on top of
|
|
127
|
+
// it by default DOM order since it's a later sibling within `panel`. `panel`'s own panelOpen
|
|
128
|
+
// elevation only helps this panel paint above OTHER panels (see its own comment) - it does nothing
|
|
129
|
+
// for stacking *within* this panel, since React Native Web gives each View its own stacking
|
|
130
|
+
// context. This is what actually fixes that: elevate pickerRow itself above its own later sibling
|
|
131
|
+
// whenever one of its own popovers is open.
|
|
132
|
+
pickerRowOpen: {
|
|
133
|
+
zIndex: 100
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// src/SharedActionBand.tsx
|
|
138
|
+
import { IconButton } from "@rific/feedback-press";
|
|
139
|
+
import { StyleSheet as StyleSheet3, View as View2 } from "react-native";
|
|
140
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
141
|
+
function SharedActionBand({ onBack, onSettings, onRandomize, onReset, fg, popoverOpen, children }) {
|
|
142
|
+
return /* @__PURE__ */ jsxs2(View2, { style: [styles3.column, popoverOpen && styles3.columnOpen], children: [
|
|
143
|
+
/* @__PURE__ */ jsxs2(View2, { style: styles3.actionsRow, children: [
|
|
144
|
+
/* @__PURE__ */ jsx3(IconButton, { icon: "arrow-left", iconColor: fg, size: 20, onPress: onBack, accessibilityLabel: "Back" }),
|
|
145
|
+
onRandomize && /* @__PURE__ */ jsx3(IconButton, { icon: "dice-multiple", iconColor: fg, size: 18, onPress: onRandomize, accessibilityLabel: "Randomize match settings" }),
|
|
146
|
+
onReset && /* @__PURE__ */ jsx3(IconButton, { icon: "restore", iconColor: fg, size: 18, onPress: onReset, accessibilityLabel: "Reset match settings to defaults" }),
|
|
147
|
+
/* @__PURE__ */ jsx3(IconButton, { icon: "cog", iconColor: fg, size: 20, onPress: onSettings, accessibilityLabel: "Settings" })
|
|
148
|
+
] }),
|
|
149
|
+
children
|
|
150
|
+
] });
|
|
151
|
+
}
|
|
152
|
+
var styles3 = StyleSheet3.create({
|
|
153
|
+
actionsRow: {
|
|
154
|
+
alignItems: "center",
|
|
155
|
+
flexDirection: "row",
|
|
156
|
+
gap: 16
|
|
157
|
+
},
|
|
158
|
+
column: {
|
|
159
|
+
alignItems: "center",
|
|
160
|
+
gap: 8
|
|
161
|
+
},
|
|
162
|
+
columnOpen: {
|
|
163
|
+
zIndex: 100
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export {
|
|
168
|
+
ReadyButton,
|
|
169
|
+
useZoneClampedAlign,
|
|
170
|
+
getColorPopoverId,
|
|
171
|
+
getProfilePopoverId,
|
|
172
|
+
getCpuDifficultyPopoverId,
|
|
173
|
+
PlayerSetupPanel,
|
|
174
|
+
SharedActionBand
|
|
175
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { SeedColor } from '@rific/auto-paper';
|
|
4
|
+
import { Profile } from '@tastic/profile';
|
|
5
|
+
import { P as PopoverHost, A as AlignResult, a as PopoverRotation, u as useAutoAlign } from './usePopoverHost-T8QWb2_A.mjs';
|
|
6
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
7
|
+
|
|
8
|
+
interface MenuOption<T extends string | number> {
|
|
9
|
+
value: T;
|
|
10
|
+
label: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
iconSize?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const LABELED_DROPDOWN_POPOVER_WIDTH = 180;
|
|
17
|
+
declare function getLabeledDropdownContentHeight(optionCount: number): number;
|
|
18
|
+
interface LabeledDropdownOption<T extends string> {
|
|
19
|
+
value: T;
|
|
20
|
+
label: string;
|
|
21
|
+
icon?: string;
|
|
22
|
+
}
|
|
23
|
+
interface Props$2<T extends string> {
|
|
24
|
+
id: string;
|
|
25
|
+
host: PopoverHost;
|
|
26
|
+
options: LabeledDropdownOption<T>[];
|
|
27
|
+
value: T;
|
|
28
|
+
onChange: (value: T) => void;
|
|
29
|
+
color: string;
|
|
30
|
+
dark: boolean;
|
|
31
|
+
align?: 'left' | 'right' | 'center';
|
|
32
|
+
alignOverride?: AlignResult;
|
|
33
|
+
}
|
|
34
|
+
declare function LabeledDropdown<T extends string>({ id, host, options, value, onChange, color, dark, align: forcedAlign, alignOverride }: Props$2<T>): react.JSX.Element;
|
|
35
|
+
|
|
36
|
+
declare function getColorPopoverId(idPrefix: string): string;
|
|
37
|
+
declare function getProfilePopoverId(idPrefix: string): string;
|
|
38
|
+
declare function getCpuDifficultyPopoverId(idPrefix: string): string;
|
|
39
|
+
interface PlayerSetupPanelProps<C extends string = string> {
|
|
40
|
+
idPrefix: string;
|
|
41
|
+
host?: PopoverHost;
|
|
42
|
+
label?: string;
|
|
43
|
+
labelFontFamily?: string;
|
|
44
|
+
color: string;
|
|
45
|
+
onColorChange: (hex: string) => void;
|
|
46
|
+
swatches: SeedColor[];
|
|
47
|
+
takenColor?: string;
|
|
48
|
+
allowSwapTaken?: boolean;
|
|
49
|
+
colorCaption?: string;
|
|
50
|
+
showColor?: boolean;
|
|
51
|
+
colorAlignOverride?: AlignResult;
|
|
52
|
+
colorRotation?: PopoverRotation;
|
|
53
|
+
isHuman: boolean;
|
|
54
|
+
secondPicker?: ReactNode;
|
|
55
|
+
secondPickerId?: string;
|
|
56
|
+
ready?: boolean;
|
|
57
|
+
onToggleReady?: () => void;
|
|
58
|
+
dark: boolean;
|
|
59
|
+
showReadyButton?: boolean;
|
|
60
|
+
profiles?: Profile[];
|
|
61
|
+
selectedProfileId?: string | null;
|
|
62
|
+
takenProfileId?: string | null;
|
|
63
|
+
guestLabel?: string;
|
|
64
|
+
onProfileSelect?: (profile: Profile | null) => void;
|
|
65
|
+
onManageProfiles?: () => void;
|
|
66
|
+
cpuDifficulty?: C;
|
|
67
|
+
cpuDifficultyOptions?: LabeledDropdownOption<C>[];
|
|
68
|
+
onCpuDifficultyChange?: (value: C) => void;
|
|
69
|
+
humanIcon?: string;
|
|
70
|
+
cpuIcon?: string;
|
|
71
|
+
}
|
|
72
|
+
declare function PlayerSetupPanel<C extends string = string>({ idPrefix, host, label, labelFontFamily, color, onColorChange, swatches, takenColor, allowSwapTaken, colorCaption, showColor, colorAlignOverride, colorRotation, isHuman, secondPicker, secondPickerId, ready, onToggleReady, dark, showReadyButton, profiles, selectedProfileId, takenProfileId, guestLabel, onProfileSelect, onManageProfiles, cpuDifficulty, cpuDifficultyOptions, onCpuDifficultyChange, humanIcon, cpuIcon }: PlayerSetupPanelProps<C>): react.JSX.Element;
|
|
73
|
+
|
|
74
|
+
interface Props$1 {
|
|
75
|
+
color: string;
|
|
76
|
+
ready: boolean;
|
|
77
|
+
onToggleReady: () => void;
|
|
78
|
+
style?: StyleProp<ViewStyle>;
|
|
79
|
+
labelFontFamily?: string;
|
|
80
|
+
}
|
|
81
|
+
declare function ReadyButton({ color, ready, onToggleReady, style, labelFontFamily }: Props$1): react.JSX.Element;
|
|
82
|
+
|
|
83
|
+
interface Props {
|
|
84
|
+
onBack: () => void;
|
|
85
|
+
onSettings: () => void;
|
|
86
|
+
onRandomize?: () => void;
|
|
87
|
+
onReset?: () => void;
|
|
88
|
+
fg: string;
|
|
89
|
+
popoverOpen: boolean;
|
|
90
|
+
children: ReactNode;
|
|
91
|
+
}
|
|
92
|
+
declare function SharedActionBand({ onBack, onSettings, onRandomize, onReset, fg, popoverOpen, children }: Props): react.JSX.Element;
|
|
93
|
+
|
|
94
|
+
declare function useZoneClampedAlign(open: boolean, contentWidth: number, contentHeight: number, rotation?: PopoverRotation): ReturnType<typeof useAutoAlign>;
|
|
95
|
+
|
|
96
|
+
export { LABELED_DROPDOWN_POPOVER_WIDTH as L, type MenuOption as M, PlayerSetupPanel as P, ReadyButton as R, SharedActionBand as S, LabeledDropdown as a, type LabeledDropdownOption as b, type PlayerSetupPanelProps as c, getCpuDifficultyPopoverId as d, getLabeledDropdownContentHeight as e, getProfilePopoverId as f, getColorPopoverId as g, useZoneClampedAlign as u };
|