@xaui/native 0.9.1-alpha.7 → 0.9.1-alpha.9

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.
@@ -387,6 +387,7 @@ function createTheme(config = {}) {
387
387
  var defaultTheme = createTheme();
388
388
 
389
389
  // src/provider/xaui-provider.tsx
390
+ var _jsxruntime = require('react/jsx-runtime');
390
391
  function XAUIProvider({
391
392
  children,
392
393
  theme = defaultTheme,
@@ -394,7 +395,7 @@ function XAUIProvider({
394
395
  }) {
395
396
  const scheme = _reactnative.useColorScheme.call(void 0, );
396
397
  const resolved = colorMode === "system" ? scheme === "dark" ? "dark" : "light" : colorMode;
397
- return /* @__PURE__ */ React.createElement(_chunk3QBT3Q65cjs.ThemeContext.Provider, { value: theme[resolved] }, children);
398
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk3QBT3Q65cjs.ThemeContext.Provider, { value: theme[resolved], children });
398
399
  }
399
400
 
400
401
  // src/theme/palette.ts
@@ -0,0 +1,57 @@
1
+ // src/system/portal/portal.tsx
2
+ import { useContext, useId, useLayoutEffect } from "react";
3
+
4
+ // src/system/portal/portal-context.ts
5
+ import { createContext } from "react";
6
+ var PortalContext = createContext(null);
7
+
8
+ // src/system/portal/portal.tsx
9
+ function Portal({ children }) {
10
+ const context = useContext(PortalContext);
11
+ const key = useId();
12
+ useLayoutEffect(() => {
13
+ context?.addPortal(key, children);
14
+ }, [children, context, key]);
15
+ useLayoutEffect(() => {
16
+ return () => context?.removePortal(key);
17
+ }, [context, key]);
18
+ return null;
19
+ }
20
+ Portal.displayName = "XAUI.Portal";
21
+
22
+ // src/system/portal/portal-host.tsx
23
+ import { Fragment, useCallback, useMemo, useState } from "react";
24
+ import { StyleSheet, View } from "react-native";
25
+ import { jsx, jsxs } from "react/jsx-runtime";
26
+ var styles = StyleSheet.create({
27
+ container: { flex: 1 }
28
+ });
29
+ function PortalHost({ children }) {
30
+ const [portals, setPortals] = useState(/* @__PURE__ */ new Map());
31
+ const addPortal = useCallback((key, element) => {
32
+ setPortals((current) => new Map(current).set(key, element));
33
+ }, []);
34
+ const removePortal = useCallback((key) => {
35
+ setPortals((current) => {
36
+ if (!current.has(key)) return current;
37
+ const next = new Map(current);
38
+ next.delete(key);
39
+ return next;
40
+ });
41
+ }, []);
42
+ const methods = useMemo(
43
+ () => ({ addPortal, removePortal }),
44
+ [addPortal, removePortal]
45
+ );
46
+ return /* @__PURE__ */ jsx(PortalContext.Provider, { value: methods, children: /* @__PURE__ */ jsxs(View, { style: styles.container, children: [
47
+ children,
48
+ Array.from(portals, ([key, element]) => /* @__PURE__ */ jsx(Fragment, { children: element }, key))
49
+ ] }) });
50
+ }
51
+ PortalHost.displayName = "XAUI.PortalHost";
52
+
53
+ export {
54
+ PortalContext,
55
+ Portal,
56
+ PortalHost
57
+ };
@@ -387,6 +387,7 @@ function createTheme(config = {}) {
387
387
  var defaultTheme = createTheme();
388
388
 
389
389
  // src/provider/xaui-provider.tsx
390
+ import { jsx } from "react/jsx-runtime";
390
391
  function XAUIProvider({
391
392
  children,
392
393
  theme = defaultTheme,
@@ -394,7 +395,7 @@ function XAUIProvider({
394
395
  }) {
395
396
  const scheme = useColorScheme();
396
397
  const resolved = colorMode === "system" ? scheme === "dark" ? "dark" : "light" : colorMode;
397
- return /* @__PURE__ */ React.createElement(ThemeContext.Provider, { value: theme[resolved] }, children);
398
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: theme[resolved], children });
398
399
  }
399
400
 
400
401
  // src/theme/palette.ts
@@ -0,0 +1,57 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/system/portal/portal.tsx
2
+ var _react = require('react');
3
+
4
+ // src/system/portal/portal-context.ts
5
+
6
+ var PortalContext = _react.createContext.call(void 0, null);
7
+
8
+ // src/system/portal/portal.tsx
9
+ function Portal({ children }) {
10
+ const context = _react.useContext.call(void 0, PortalContext);
11
+ const key = _react.useId.call(void 0, );
12
+ _react.useLayoutEffect.call(void 0, () => {
13
+ _optionalChain([context, 'optionalAccess', _ => _.addPortal, 'call', _2 => _2(key, children)]);
14
+ }, [children, context, key]);
15
+ _react.useLayoutEffect.call(void 0, () => {
16
+ return () => _optionalChain([context, 'optionalAccess', _3 => _3.removePortal, 'call', _4 => _4(key)]);
17
+ }, [context, key]);
18
+ return null;
19
+ }
20
+ Portal.displayName = "XAUI.Portal";
21
+
22
+ // src/system/portal/portal-host.tsx
23
+
24
+ var _reactnative = require('react-native');
25
+ var _jsxruntime = require('react/jsx-runtime');
26
+ var styles = _reactnative.StyleSheet.create({
27
+ container: { flex: 1 }
28
+ });
29
+ function PortalHost({ children }) {
30
+ const [portals, setPortals] = _react.useState.call(void 0, /* @__PURE__ */ new Map());
31
+ const addPortal = _react.useCallback.call(void 0, (key, element) => {
32
+ setPortals((current) => new Map(current).set(key, element));
33
+ }, []);
34
+ const removePortal = _react.useCallback.call(void 0, (key) => {
35
+ setPortals((current) => {
36
+ if (!current.has(key)) return current;
37
+ const next = new Map(current);
38
+ next.delete(key);
39
+ return next;
40
+ });
41
+ }, []);
42
+ const methods = _react.useMemo.call(void 0,
43
+ () => ({ addPortal, removePortal }),
44
+ [addPortal, removePortal]
45
+ );
46
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PortalContext.Provider, { value: methods, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactnative.View, { style: styles.container, children: [
47
+ children,
48
+ Array.from(portals, ([key, element]) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: element }, key))
49
+ ] }) });
50
+ }
51
+ PortalHost.displayName = "XAUI.PortalHost";
52
+
53
+
54
+
55
+
56
+
57
+ exports.PortalContext = PortalContext; exports.Portal = Portal; exports.PortalHost = PortalHost;
@@ -0,0 +1,350 @@
1
+ import {
2
+ Icon,
3
+ PressableFeedback,
4
+ childrenToString,
5
+ createRecipe,
6
+ createSlotContext
7
+ } from "./chunk-U3C6VN4X.js";
8
+ import {
9
+ useXAUITheme
10
+ } from "./chunk-X2K2FX3W.js";
11
+
12
+ // src/components/button/button.context.ts
13
+ var [ButtonProvider, useButton] = createSlotContext("Button");
14
+
15
+ // src/components/button/button-icon.tsx
16
+ import { jsx } from "react/jsx-runtime";
17
+ function ButtonIcon({ size, color, ...rest }) {
18
+ const { icon } = useButton();
19
+ return /* @__PURE__ */ jsx(Icon, { size: size ?? icon.size, color: color ?? icon.color, ...rest });
20
+ }
21
+ ButtonIcon.displayName = "XAUI.Button.Icon";
22
+
23
+ // src/components/button/button-label.tsx
24
+ import { forwardRef } from "react";
25
+ import { Text } from "react-native";
26
+ import { jsx as jsx2 } from "react/jsx-runtime";
27
+ var ButtonLabel = forwardRef(function ButtonLabel2({ children, style, numberOfLines = 1, ...rest }, ref) {
28
+ const { labelStyle } = useButton();
29
+ return /* @__PURE__ */ jsx2(
30
+ Text,
31
+ {
32
+ ref,
33
+ numberOfLines,
34
+ style: [labelStyle, style],
35
+ ...rest,
36
+ children
37
+ }
38
+ );
39
+ });
40
+ ButtonLabel.displayName = "XAUI.Button.Label";
41
+
42
+ // src/components/button/button-spinner.tsx
43
+ import { useEffect } from "react";
44
+ import { View } from "react-native";
45
+ import Animated, {
46
+ Easing,
47
+ cancelAnimation,
48
+ useAnimatedStyle,
49
+ useSharedValue,
50
+ withRepeat,
51
+ withTiming
52
+ } from "react-native-reanimated";
53
+ import { jsx as jsx3 } from "react/jsx-runtime";
54
+ var ROTATION_DURATION = 800;
55
+ function ButtonSpinner({ style, animation = true }) {
56
+ const { spinnerStyle } = useButton();
57
+ if (!animation) return /* @__PURE__ */ jsx3(View, { style: [spinnerStyle, style] });
58
+ return /* @__PURE__ */ jsx3(SpinningRing, { style: [spinnerStyle, style] });
59
+ }
60
+ ButtonSpinner.displayName = "XAUI.Button.Spinner";
61
+ function SpinningRing({ style }) {
62
+ const angle = useSharedValue(0);
63
+ useEffect(() => {
64
+ angle.value = withRepeat(
65
+ withTiming(360, { duration: ROTATION_DURATION, easing: Easing.linear }),
66
+ -1,
67
+ false
68
+ );
69
+ return () => cancelAnimation(angle);
70
+ }, [angle]);
71
+ const animatedStyle = useAnimatedStyle(
72
+ () => ({ transform: [{ rotate: `${angle.value}deg` }] }),
73
+ [angle]
74
+ );
75
+ return /* @__PURE__ */ jsx3(Animated.View, { style: [style, animatedStyle] });
76
+ }
77
+
78
+ // src/components/button/button.tsx
79
+ import { forwardRef as forwardRef2, useMemo } from "react";
80
+ import { StyleSheet } from "react-native";
81
+
82
+ // src/hooks/use-press-state.ts
83
+ import { useCallback, useRef, useState } from "react";
84
+ function usePressState(handlers = {}) {
85
+ const [isPressed, setIsPressed] = useState(false);
86
+ const latest = useRef(handlers);
87
+ latest.current = handlers;
88
+ const onPressIn = useCallback((event) => {
89
+ setIsPressed(true);
90
+ latest.current.onPressIn?.(event);
91
+ }, []);
92
+ const onPressOut = useCallback((event) => {
93
+ setIsPressed(false);
94
+ latest.current.onPressOut?.(event);
95
+ }, []);
96
+ const press = useRef({ onPressIn, onPressOut }).current;
97
+ return [isPressed, press];
98
+ }
99
+
100
+ // src/utils/warn-dev.ts
101
+ function warnDev(message) {
102
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
103
+ console.warn(`XAUI: ${message}`);
104
+ }
105
+
106
+ // src/components/button/button.recipe.ts
107
+ var SLOTS = ["root", "label", "icon", "spinner"];
108
+ var VARIANT_TOKENS = {
109
+ primary: { bg: "accent", bgPressed: "accentPressed", fg: "accentForeground" },
110
+ secondary: { bg: "default", bgPressed: "defaultPressed", fg: "defaultForeground" },
111
+ tertiary: {
112
+ border: "border",
113
+ bgPressed: "defaultSoftPressed",
114
+ fg: "foreground"
115
+ },
116
+ ghost: { bgPressed: "defaultSoftPressed", fg: "foreground" },
117
+ success: { bg: "success", bgPressed: "successPressed", fg: "successForeground" },
118
+ "success-soft": {
119
+ bg: "successSoft",
120
+ bgPressed: "successSoftPressed",
121
+ fg: "successSoftForeground"
122
+ },
123
+ warning: { bg: "warning", bgPressed: "warningPressed", fg: "warningForeground" },
124
+ "warning-soft": {
125
+ bg: "warningSoft",
126
+ bgPressed: "warningSoftPressed",
127
+ fg: "warningSoftForeground"
128
+ },
129
+ danger: { bg: "danger", bgPressed: "dangerPressed", fg: "dangerForeground" },
130
+ "danger-soft": {
131
+ bg: "dangerSoft",
132
+ bgPressed: "dangerSoftPressed",
133
+ fg: "dangerSoftForeground"
134
+ }
135
+ };
136
+ function ring(theme, size) {
137
+ return {
138
+ width: size,
139
+ height: size,
140
+ borderRadius: size / 2,
141
+ borderWidth: theme.borderWidth.default * 2,
142
+ borderTopColor: "transparent"
143
+ };
144
+ }
145
+ function sizeAxis(step) {
146
+ const { size, padding, gap, glyph, radius } = step;
147
+ return (theme) => ({
148
+ root: {
149
+ height: theme.controlHeights[size],
150
+ paddingHorizontal: theme.spacing(padding),
151
+ gap: theme.spacing(gap),
152
+ borderRadius: theme.radius[radius]
153
+ },
154
+ label: {
155
+ fontSize: theme.fontSizes[size],
156
+ lineHeight: theme.lineHeights[size]
157
+ },
158
+ icon: { fontSize: theme.fontSizes[glyph] },
159
+ spinner: ring(theme, theme.fontSizes[glyph])
160
+ });
161
+ }
162
+ var buttonRecipe = createRecipe({
163
+ slots: SLOTS,
164
+ base: (theme) => ({
165
+ root: {
166
+ flexDirection: "row",
167
+ alignItems: "center",
168
+ justifyContent: "center",
169
+ borderWidth: 0,
170
+ // iOS's squircle. Free on Android, and it is what makes a large radius read as a
171
+ // shape rather than as two arcs meeting a straight edge.
172
+ borderCurve: "continuous"
173
+ },
174
+ label: {
175
+ fontFamily: theme.fontFamilies.body,
176
+ fontWeight: theme.fontWeights.medium
177
+ }
178
+ }),
179
+ variantTokens: VARIANT_TOKENS,
180
+ /**
181
+ * Where the variant's colours land, for every variant at once. The border width follows
182
+ * the *presence* of the border role rather than a per-variant flag — `tertiary` is the
183
+ * only variant that names one, and that fact is already in the table above.
184
+ */
185
+ paint: (theme, colors) => ({
186
+ root: {
187
+ backgroundColor: colors.bg,
188
+ borderColor: colors.border,
189
+ borderWidth: colors.border ? theme.borderWidth.default : 0
190
+ },
191
+ label: { color: colors.fg },
192
+ icon: { color: colors.fg },
193
+ spinner: { borderColor: colors.fg }
194
+ }),
195
+ /**
196
+ * Declaration order is application order: `radius` overrides the radius `size` set, and
197
+ * `isIconOnly` overrides its padding. Both are axes rather than a static sheet merged
198
+ * at the call site, so they stay inside the cache key and a press still allocates
199
+ * nothing.
200
+ */
201
+ variants: {
202
+ size: {
203
+ xs: sizeAxis({ size: "xs", padding: 3, gap: 1, glyph: "sm", radius: "3xl" }),
204
+ sm: sizeAxis({
205
+ size: "sm",
206
+ padding: 3.5,
207
+ gap: 1.5,
208
+ glyph: "md",
209
+ radius: "3xl"
210
+ }),
211
+ md: sizeAxis({ size: "md", padding: 4, gap: 2, glyph: "lg", radius: "3xl" }),
212
+ lg: sizeAxis({ size: "lg", padding: 5, gap: 2.5, glyph: "xl", radius: "4xl" })
213
+ },
214
+ radius: {
215
+ xs: (t) => ({ root: { borderRadius: t.radius.xs } }),
216
+ sm: (t) => ({ root: { borderRadius: t.radius.sm } }),
217
+ md: (t) => ({ root: { borderRadius: t.radius.md } }),
218
+ lg: (t) => ({ root: { borderRadius: t.radius.lg } }),
219
+ xl: (t) => ({ root: { borderRadius: t.radius.xl } }),
220
+ "2xl": (t) => ({ root: { borderRadius: t.radius["2xl"] } }),
221
+ "3xl": (t) => ({ root: { borderRadius: t.radius["3xl"] } }),
222
+ "4xl": (t) => ({ root: { borderRadius: t.radius["4xl"] } }),
223
+ field: (t) => ({ root: { borderRadius: t.radius.field } }),
224
+ full: (t) => ({ root: { borderRadius: t.radius.full } })
225
+ },
226
+ // A square on a fixed height. No width is computed, and none needs to be.
227
+ isIconOnly: {
228
+ true: () => ({ root: { paddingHorizontal: 0, aspectRatio: 1 } })
229
+ }
230
+ },
231
+ /**
232
+ * The pressed colour lives here rather than in a `PressableFeedback.Highlight`, because
233
+ * a control picks one treatment or the other — both, and a pressed button darkens
234
+ * twice. This one is the variant's own `…Pressed` token, so the press reads as the
235
+ * button's colour going down rather than as a neutral film over it, and a tinted button
236
+ * presses through the same OKLab formula as a token one.
237
+ */
238
+ states: {
239
+ pressed: (_theme, colors) => ({ root: { backgroundColor: colors.bgPressed } }),
240
+ disabled: (theme) => ({ root: { opacity: theme.opacity.disabled } })
241
+ },
242
+ // Annotated, or inference reads the whole `Variant` parameter off this one literal and
243
+ // narrows the recipe to the single variant named here.
244
+ defaultVariants: { variant: "primary", size: "md" }
245
+ });
246
+
247
+ // src/components/button/button.utils.ts
248
+ import { Children, isValidElement } from "react";
249
+ function containsElementOfType(children, type) {
250
+ return Children.toArray(children).some(
251
+ (child) => isValidElement(child) && child.type === type
252
+ );
253
+ }
254
+
255
+ // src/components/button/button.tsx
256
+ import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
257
+ var ButtonRoot = forwardRef2(function Button({
258
+ children,
259
+ variant,
260
+ size,
261
+ radius,
262
+ color,
263
+ isDisabled = false,
264
+ isLoading = false,
265
+ isIconOnly = false,
266
+ asChild = false,
267
+ // `scale` and not `scale-highlight`: the recipe's `pressed` state already paints the
268
+ // variant's own pressed colour, and a neutral wash on top would darken it twice.
269
+ feedbackVariant = "scale",
270
+ accessibilityRole = "button",
271
+ style,
272
+ onPressIn,
273
+ onPressOut,
274
+ ...rest
275
+ }, ref) {
276
+ const theme = useXAUITheme();
277
+ const [isPressed, press] = usePressState({ onPressIn, onPressOut });
278
+ const selection = {
279
+ variant,
280
+ size,
281
+ radius,
282
+ isIconOnly: isIconOnly ? "true" : void 0
283
+ };
284
+ const states = { pressed: isPressed, disabled: isDisabled || isLoading };
285
+ const styles = buttonRecipe.resolve({ theme, selection, states });
286
+ const tint = color ? buttonRecipe.tint({ theme, color, selection, states }) : void 0;
287
+ const context = useMemo(() => {
288
+ const icon = StyleSheet.flatten([styles.icon, tint?.icon]);
289
+ return {
290
+ labelStyle: tint ? [styles.label, tint.label] : styles.label,
291
+ spinnerStyle: tint ? [styles.spinner, tint.spinner] : styles.spinner,
292
+ icon: {
293
+ size: icon.fontSize,
294
+ // `ColorValue` also covers the platform's opaque colours, which `Icon` cannot
295
+ // hand to a third-party component expecting a string.
296
+ color: typeof icon.color === "string" ? icon.color : void 0
297
+ },
298
+ isDisabled,
299
+ isLoading
300
+ };
301
+ }, [styles, tint, isDisabled, isLoading]);
302
+ const rootStyle = [
303
+ styles.root,
304
+ tint?.root,
305
+ typeof style === "function" ? style({ pressed: isPressed }) : style
306
+ ];
307
+ const text = childrenToString(children);
308
+ const showSpinner = isLoading && !containsElementOfType(children, ButtonSpinner);
309
+ if (isIconOnly && !rest.accessibilityLabel && !rest["aria-label"]) {
310
+ warnDev(
311
+ "Button: an icon-only button needs an `accessibilityLabel` \u2014 there is no text for a screen reader to read, so it announces as an unlabelled button."
312
+ );
313
+ }
314
+ return /* @__PURE__ */ jsx4(ButtonProvider, { value: context, children: /* @__PURE__ */ jsx4(
315
+ PressableFeedback,
316
+ {
317
+ ref,
318
+ isPressed,
319
+ isDisabled: isDisabled || isLoading,
320
+ asChild,
321
+ feedbackVariant,
322
+ accessibilityRole,
323
+ accessibilityState: { disabled: isDisabled, busy: isLoading },
324
+ ...rest,
325
+ style: rootStyle,
326
+ onPressIn: press.onPressIn,
327
+ onPressOut: press.onPressOut,
328
+ children: asChild ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
329
+ showSpinner ? /* @__PURE__ */ jsx4(ButtonSpinner, {}) : null,
330
+ text !== null ? /* @__PURE__ */ jsx4(ButtonLabel, { children: text }) : children
331
+ ] })
332
+ }
333
+ ) });
334
+ });
335
+ ButtonRoot.displayName = "XAUI.Button.Root";
336
+
337
+ // src/components/button/index.ts
338
+ var Button2 = Object.assign(ButtonRoot, {
339
+ Label: ButtonLabel,
340
+ Icon: ButtonIcon,
341
+ Spinner: ButtonSpinner
342
+ });
343
+
344
+ export {
345
+ useButton,
346
+ usePressState,
347
+ warnDev,
348
+ buttonRecipe,
349
+ Button2 as Button
350
+ };