@xaui/native 0.9.1-alpha.2 → 0.9.1-alpha.20

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.
Files changed (53) hide show
  1. package/dist/chunk-2WMVDMFV.cjs +62 -0
  2. package/dist/chunk-33QILJJH.cjs +143 -0
  3. package/dist/chunk-4EPS7UBO.js +496 -0
  4. package/dist/{chunk-M7P46XKI.cjs → chunk-57SJ4LJF.cjs} +33 -3
  5. package/dist/chunk-6ARON3XT.cjs +534 -0
  6. package/dist/{chunk-RBNCR5KB.js → chunk-A3EGFI6T.js} +31 -1
  7. package/dist/chunk-A4VD4MHK.cjs +757 -0
  8. package/dist/{chunk-NHPQQQ7P.cjs → chunk-BHTFIZTQ.cjs} +55 -88
  9. package/dist/chunk-EVXZGNPA.cjs +303 -0
  10. package/dist/chunk-EXX6ATAS.js +303 -0
  11. package/dist/chunk-GGW42MY4.js +20 -0
  12. package/dist/chunk-JXLRHKCQ.js +143 -0
  13. package/dist/chunk-MC7SY2QH.cjs +20 -0
  14. package/dist/{chunk-PBVPOX7D.js → chunk-MWXE7D4L.js} +29 -62
  15. package/dist/{chunk-RCP3SD26.js → chunk-N7C4UNUL.js} +2 -126
  16. package/dist/chunk-RMLFMRWL.js +102 -0
  17. package/dist/chunk-UBA6AEY6.cjs +102 -0
  18. package/dist/{chunk-B755PRVJ.cjs → chunk-UVO4GFSW.cjs} +3 -127
  19. package/dist/chunk-WXAME7KB.js +728 -0
  20. package/dist/chunk-XHZBXYVU.js +62 -0
  21. package/dist/components/button/index.cjs +15 -0
  22. package/dist/components/button/index.d.cts +658 -0
  23. package/dist/components/button/index.d.ts +658 -0
  24. package/dist/components/button/index.js +15 -0
  25. package/dist/components/typography/index.cjs +14 -0
  26. package/dist/components/typography/index.d.cts +116 -0
  27. package/dist/components/typography/index.d.ts +116 -0
  28. package/dist/components/typography/index.js +14 -0
  29. package/dist/components/view/index.cjs +16 -0
  30. package/dist/components/view/index.d.cts +152 -0
  31. package/dist/components/view/index.d.ts +152 -0
  32. package/dist/components/view/index.js +16 -0
  33. package/dist/create-recipe-C0XXjuow.d.cts +89 -0
  34. package/dist/create-recipe-CPXFo2rk.d.ts +89 -0
  35. package/dist/index.cjs +151 -5
  36. package/dist/index.d.cts +77 -4
  37. package/dist/index.d.ts +77 -4
  38. package/dist/index.js +155 -9
  39. package/dist/pressable-feedback.type-1K8YEOb8.d.cts +195 -0
  40. package/dist/pressable-feedback.type-BwkKLQlX.d.ts +195 -0
  41. package/dist/style-props.type-B1BG5TCm.d.cts +31 -0
  42. package/dist/style-props.type-B1BG5TCm.d.ts +31 -0
  43. package/dist/system/index.cjs +64 -3
  44. package/dist/system/index.d.cts +299 -75
  45. package/dist/system/index.d.ts +299 -75
  46. package/dist/system/index.js +66 -5
  47. package/dist/theme/index.cjs +4 -3
  48. package/dist/theme/index.d.cts +26 -14
  49. package/dist/theme/index.d.ts +26 -14
  50. package/dist/theme/index.js +7 -6
  51. package/dist/{theme.type-B3ODSLbB.d.cts → theme.type-C2gNHpEx.d.cts} +8 -2
  52. package/dist/{theme.type-B3ODSLbB.d.ts → theme.type-C2gNHpEx.d.ts} +8 -2
  53. package/package.json +64 -18
@@ -0,0 +1,62 @@
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; }
2
+
3
+ var _chunkEVXZGNPAcjs = require('./chunk-EVXZGNPA.cjs');
4
+
5
+ // src/system/portal/portal.tsx
6
+ var _react = require('react');
7
+
8
+ // src/system/portal/portal-context.ts
9
+
10
+ var PortalContext = _react.createContext.call(void 0, null);
11
+
12
+ // src/system/portal/portal.tsx
13
+ function Portal({ children }) {
14
+ const context = _react.useContext.call(void 0, PortalContext);
15
+ const key = _react.useId.call(void 0, );
16
+ _react.useLayoutEffect.call(void 0, () => {
17
+ _optionalChain([context, 'optionalAccess', _ => _.addPortal, 'call', _2 => _2(key, children)]);
18
+ }, [children, context, key]);
19
+ _react.useLayoutEffect.call(void 0, () => {
20
+ return () => _optionalChain([context, 'optionalAccess', _3 => _3.removePortal, 'call', _4 => _4(key)]);
21
+ }, [context, key]);
22
+ return null;
23
+ }
24
+ Portal.displayName = "XAUI.Portal";
25
+
26
+ // src/system/portal/portal-host.tsx
27
+
28
+ var _reactnative = require('react-native');
29
+ var _jsxruntime = require('react/jsx-runtime');
30
+ var styles = _reactnative.StyleSheet.create({
31
+ container: { flex: 1 }
32
+ });
33
+ function PortalHost({ children, ...props }) {
34
+ const [styleProps] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
35
+ const [portals, setPortals] = _react.useState.call(void 0, /* @__PURE__ */ new Map());
36
+ const addPortal = _react.useCallback.call(void 0, (key, element) => {
37
+ setPortals((current) => new Map(current).set(key, element));
38
+ }, []);
39
+ const removePortal = _react.useCallback.call(void 0, (key) => {
40
+ setPortals((current) => {
41
+ if (!current.has(key)) return current;
42
+ const next = new Map(current);
43
+ next.delete(key);
44
+ return next;
45
+ });
46
+ }, []);
47
+ const methods = _react.useMemo.call(void 0,
48
+ () => ({ addPortal, removePortal }),
49
+ [addPortal, removePortal]
50
+ );
51
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PortalContext.Provider, { value: methods, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _reactnative.View, { style: [styles.container, styleProps], children: [
52
+ children,
53
+ Array.from(portals, ([key, element]) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Fragment, { children: element }, key))
54
+ ] }) });
55
+ }
56
+ PortalHost.displayName = "XAUI.PortalHost";
57
+
58
+
59
+
60
+
61
+
62
+ exports.PortalContext = PortalContext; exports.Portal = Portal; exports.PortalHost = PortalHost;
@@ -0,0 +1,143 @@
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; }
2
+
3
+
4
+ var _chunkEVXZGNPAcjs = require('./chunk-EVXZGNPA.cjs');
5
+
6
+ // src/components/view/grid.tsx
7
+ var _react = require('react');
8
+ var _reactnative = require('react-native');
9
+
10
+ // src/components/view/grid.context.ts
11
+
12
+ var GridContext = _react.createContext.call(void 0, null);
13
+ var GridProvider = GridContext.Provider;
14
+ function useGrid() {
15
+ const value = _react.useContext.call(void 0, GridContext);
16
+ if (value === null) {
17
+ throw new Error(
18
+ "XAUI: Grid.Item must be rendered inside a Grid \u2014 it spans that grid\u2019s columns, and outside one there is nothing to span."
19
+ );
20
+ }
21
+ return value;
22
+ }
23
+ function spanWidth({ cellWidth, columns, gap }, span) {
24
+ const clamped = Math.min(Math.max(Math.floor(span), 1), columns);
25
+ if (cellWidth === void 0) return `${100 / columns * clamped}%`;
26
+ return cellWidth * clamped + gap * (clamped - 1);
27
+ }
28
+
29
+ // src/components/view/grid.tsx
30
+ var _jsxruntime = require('react/jsx-runtime');
31
+ var GridRoot = _react.forwardRef.call(void 0, function Grid({ children, columns = 2, gap = 0, style, onLayout, ...props }, ref) {
32
+ const [width, setWidth] = _react.useState.call(void 0, );
33
+ const [styleProps, rest] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
34
+ const safeColumns = Math.max(Math.floor(columns), 1);
35
+ const cellWidth = width === void 0 ? void 0 : (width - gap * (safeColumns - 1)) / safeColumns;
36
+ const context = _react.useMemo.call(void 0,
37
+ () => ({ cellWidth, columns: safeColumns, gap }),
38
+ [cellWidth, safeColumns, gap]
39
+ );
40
+ const handleLayout = (event) => {
41
+ const next = event.nativeEvent.layout.width;
42
+ if (next > 0 && next !== width) setWidth(next);
43
+ _optionalChain([onLayout, 'optionalCall', _ => _(event)]);
44
+ };
45
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, GridProvider, { value: context, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
46
+ _reactnative.View,
47
+ {
48
+ ref,
49
+ onLayout: handleLayout,
50
+ style: [
51
+ { flexDirection: "row", flexWrap: "wrap", rowGap: gap, columnGap: gap },
52
+ styleProps,
53
+ style
54
+ ],
55
+ ...rest,
56
+ children: _react.Children.map(
57
+ children,
58
+ (child) => isGridItem(child) ? child : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactnative.View, { style: { width: spanWidth(context, 1) }, children: child })
59
+ )
60
+ }
61
+ ) });
62
+ });
63
+ GridRoot.displayName = "XAUI.Grid";
64
+ function isGridItem(child) {
65
+ if (child === null || typeof child !== "object") return false;
66
+ const type = child.type;
67
+ return _optionalChain([type, 'optionalAccess', _2 => _2.displayName]) === "XAUI.Grid.Item";
68
+ }
69
+
70
+ // src/components/view/grid-item.tsx
71
+
72
+
73
+
74
+ var GridItem = _react.forwardRef.call(void 0, function GridItem2({ children, span = 1, style, ...props }, ref) {
75
+ const grid = useGrid();
76
+ const [styleProps, rest] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
77
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
78
+ _reactnative.View,
79
+ {
80
+ ref,
81
+ style: [{ width: spanWidth(grid, span) }, styleProps, style],
82
+ ...rest,
83
+ children
84
+ }
85
+ );
86
+ });
87
+ GridItem.displayName = "XAUI.Grid.Item";
88
+
89
+ // src/components/view/stack.tsx
90
+
91
+
92
+
93
+ var StackRoot = _react.forwardRef.call(void 0, function Stack({ children, asChild = false, style, ...props }, ref) {
94
+ const [styleProps, rest] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
95
+ const Root = asChild ? _chunkEVXZGNPAcjs.Slot : _reactnative.View;
96
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Root, { ref, style: [{ position: "relative" }, styleProps, style], ...rest, children });
97
+ });
98
+ StackRoot.displayName = "XAUI.Stack";
99
+
100
+ // src/components/view/stack-item.tsx
101
+
102
+
103
+
104
+ var StackItem = _react.forwardRef.call(void 0, function StackItem2({ children, asChild = false, style, ...props }, ref) {
105
+ const [styleProps, rest] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
106
+ const Root = asChild ? _chunkEVXZGNPAcjs.Slot : _reactnative.View;
107
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Root, { ref, style: [{ position: "absolute" }, styleProps, style], ...rest, children });
108
+ });
109
+ StackItem.displayName = "XAUI.Stack.Item";
110
+
111
+ // src/components/view/row.tsx
112
+
113
+
114
+
115
+ var Row = _react.forwardRef.call(void 0, function Row2({ children, asChild = false, style, ...props }, ref) {
116
+ const [styleProps, rest] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
117
+ const Root = asChild ? _chunkEVXZGNPAcjs.Slot : _reactnative.View;
118
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Root, { ref, style: [{ flexDirection: "row" }, styleProps, style], ...rest, children });
119
+ });
120
+ Row.displayName = "XAUI.Row";
121
+
122
+ // src/components/view/column.tsx
123
+
124
+
125
+
126
+ var Column = _react.forwardRef.call(void 0, function Column2({ children, asChild = false, style, ...props }, ref) {
127
+ const [styleProps, rest] = _chunkEVXZGNPAcjs.useStyleProps.call(void 0, props);
128
+ const Root = asChild ? _chunkEVXZGNPAcjs.Slot : _reactnative.View;
129
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Root, { ref, style: [{ flexDirection: "column" }, styleProps, style], ...rest, children });
130
+ });
131
+ Column.displayName = "XAUI.Column";
132
+
133
+ // src/components/view/index.ts
134
+ var Stack2 = Object.assign(StackRoot, { Item: StackItem });
135
+ var Grid2 = Object.assign(GridRoot, { Item: GridItem });
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+ exports.useGrid = useGrid; exports.Row = Row; exports.Column = Column; exports.Stack = Stack2; exports.Grid = Grid2;
@@ -0,0 +1,496 @@
1
+ import { Icon, PressableFeedback } from "./chunk-WXAME7KB.js";
2
+ import { createRecipe } from "./chunk-N7C4UNUL.js";
3
+ import { childrenToString, createSlotContext, useStyleProps } from "./chunk-EXX6ATAS.js";
4
+ import { useXAUITheme } from "./chunk-A3EGFI6T.js";
5
+
6
+ // src/components/button/button.context.ts
7
+ var [ButtonProvider, useButton] = createSlotContext("Button");
8
+
9
+ // src/components/button/button-icon.tsx
10
+ import { jsx } from "react/jsx-runtime";
11
+ function ButtonIcon({
12
+ size,
13
+ color,
14
+ ...rest
15
+ }) {
16
+ const {
17
+ icon
18
+ } = useButton();
19
+ return /* @__PURE__ */jsx(Icon, {
20
+ size: size ?? icon.size,
21
+ color: color ?? icon.color,
22
+ ...rest
23
+ });
24
+ }
25
+ ButtonIcon.displayName = "XAUI.Button.Icon";
26
+
27
+ // src/components/button/button-label.tsx
28
+ import { forwardRef } from "react";
29
+ import { Text } from "react-native";
30
+ import { jsx as jsx2 } from "react/jsx-runtime";
31
+ var ButtonLabel = forwardRef(function ButtonLabel2({
32
+ children,
33
+ style,
34
+ numberOfLines = 1,
35
+ ...props
36
+ }, ref) {
37
+ const {
38
+ labelStyle
39
+ } = useButton();
40
+ const [styleProps, rest] = useStyleProps(props);
41
+ return /* @__PURE__ */jsx2(Text, {
42
+ ref,
43
+ numberOfLines,
44
+ style: [labelStyle, styleProps, style],
45
+ ...rest,
46
+ children
47
+ });
48
+ });
49
+ ButtonLabel.displayName = "XAUI.Button.Label";
50
+
51
+ // src/components/button/button-spinner.tsx
52
+ import { useEffect } from "react";
53
+ import { View } from "react-native";
54
+ import Animated, { Easing, cancelAnimation, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from "react-native-reanimated";
55
+ import { jsx as jsx3 } from "react/jsx-runtime";
56
+ var ROTATION_DURATION = 800;
57
+ function ButtonSpinner({
58
+ style,
59
+ animation = true,
60
+ ...props
61
+ }) {
62
+ const {
63
+ spinnerStyle
64
+ } = useButton();
65
+ const [styleProps] = useStyleProps(props);
66
+ const ringStyle = [spinnerStyle, styleProps, style];
67
+ if (!animation) return /* @__PURE__ */jsx3(View, {
68
+ style: ringStyle
69
+ });
70
+ return /* @__PURE__ */jsx3(SpinningRing, {
71
+ style: ringStyle
72
+ });
73
+ }
74
+ ButtonSpinner.displayName = "XAUI.Button.Spinner";
75
+ const _worklet_8562276324058_init_data = {
76
+ code: "function chunk4EPS7UBOJs1(){const{angle}=this.__closure;return{transform:[{rotate:angle.value+\"deg\"}]};}",
77
+ location: "/home/runner/work/xaui/xaui/packages/native/dist/chunk-4EPS7UBO.js",
78
+ sourceMap: "{\"version\":3,\"names\":[\"chunk4EPS7UBOJs1\",\"angle\",\"__closure\",\"transform\",\"rotate\",\"value\"],\"sources\":[\"/home/runner/work/xaui/xaui/packages/native/dist/chunk-4EPS7UBO.js\"],\"mappings\":\"AA8EyC,SAAAA,gBAAMA,CAAA,QAAAC,KAAA,OAAAC,SAAA,CAE3C,MAAO,CAAEC,SAAS,CAAE,CAAC,CAAEC,MAAM,CAAKH,KAAK,CAACI,KAAK,MAAM,CAAC,CAAE,CAAC,CACzD\",\"ignoreList\":[]}"
79
+ };
80
+ function SpinningRing({
81
+ style
82
+ }) {
83
+ const angle = useSharedValue(0);
84
+ useEffect(() => {
85
+ angle.value = withRepeat(withTiming(360, {
86
+ duration: ROTATION_DURATION,
87
+ easing: Easing.linear
88
+ }), -1, false);
89
+ return () => cancelAnimation(angle);
90
+ }, [angle]);
91
+ const animatedStyle = useAnimatedStyle(function chunk4EPS7UBOJs1Factory({
92
+ _worklet_8562276324058_init_data,
93
+ angle
94
+ }) {
95
+ const _e = [new global.Error(), -2, -27];
96
+ const chunk4EPS7UBOJs1 = function () {
97
+ return {
98
+ transform: [{
99
+ rotate: `${angle.value}deg`
100
+ }]
101
+ };
102
+ };
103
+ chunk4EPS7UBOJs1.__closure = {
104
+ angle
105
+ };
106
+ chunk4EPS7UBOJs1.__workletHash = 8562276324058;
107
+ chunk4EPS7UBOJs1.__pluginVersion = "0.7.4";
108
+ chunk4EPS7UBOJs1.__initData = _worklet_8562276324058_init_data;
109
+ chunk4EPS7UBOJs1.__stackDetails = _e;
110
+ return chunk4EPS7UBOJs1;
111
+ }({
112
+ _worklet_8562276324058_init_data,
113
+ angle
114
+ }), [angle]);
115
+ return /* @__PURE__ */jsx3(Animated.View, {
116
+ style: [style, animatedStyle]
117
+ });
118
+ }
119
+
120
+ // src/components/button/button.tsx
121
+ import { forwardRef as forwardRef2, useMemo } from "react";
122
+ import { StyleSheet } from "react-native";
123
+
124
+ // src/hooks/use-press-state.ts
125
+ import { useCallback, useRef, useState } from "react";
126
+ function usePressState(handlers = {}) {
127
+ const [isPressed, setIsPressed] = useState(false);
128
+ const latest = useRef(handlers);
129
+ latest.current = handlers;
130
+ const onPressIn = useCallback(event => {
131
+ setIsPressed(true);
132
+ latest.current.onPressIn?.(event);
133
+ }, []);
134
+ const onPressOut = useCallback(event => {
135
+ setIsPressed(false);
136
+ latest.current.onPressOut?.(event);
137
+ }, []);
138
+ const press = useRef({
139
+ onPressIn,
140
+ onPressOut
141
+ }).current;
142
+ return [isPressed, press];
143
+ }
144
+
145
+ // src/utils/warn-dev.ts
146
+ function warnDev(message) {
147
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
148
+ console.warn(`XAUI: ${message}`);
149
+ }
150
+
151
+ // src/components/button/button.recipe.ts
152
+ var SLOTS = ["root", "label", "icon", "spinner"];
153
+ var VARIANT_TOKENS = {
154
+ primary: {
155
+ bg: "accent",
156
+ bgPressed: "accentPressed",
157
+ fg: "accentForeground"
158
+ },
159
+ // The accent's soft slice, not a second neutral: `secondary` is to `primary` what
160
+ // `danger-soft` is to `danger`, and it reads as the same family at lower emphasis.
161
+ secondary: {
162
+ bg: "accentSoft",
163
+ bgPressed: "accentSoftPressed",
164
+ fg: "accentSoftForeground"
165
+ },
166
+ default: {
167
+ bg: "default",
168
+ bgPressed: "defaultPressed",
169
+ fg: "defaultForeground"
170
+ },
171
+ tertiary: {
172
+ border: "border",
173
+ bgPressed: "defaultSoftPressed",
174
+ fg: "foreground"
175
+ },
176
+ ghost: {
177
+ bgPressed: "defaultSoftPressed",
178
+ fg: "foreground"
179
+ },
180
+ danger: {
181
+ bg: "danger",
182
+ bgPressed: "dangerPressed",
183
+ fg: "dangerForeground"
184
+ },
185
+ "danger-soft": {
186
+ bg: "dangerSoft",
187
+ bgPressed: "dangerSoftPressed",
188
+ fg: "dangerSoftForeground"
189
+ }
190
+ };
191
+ function ring(theme, size) {
192
+ return {
193
+ width: size,
194
+ height: size,
195
+ borderRadius: size / 2,
196
+ borderWidth: theme.borderWidth.default * 2,
197
+ borderTopColor: "transparent"
198
+ };
199
+ }
200
+ function sizeAxis(step) {
201
+ const {
202
+ size,
203
+ padding,
204
+ gap,
205
+ glyph,
206
+ radius
207
+ } = step;
208
+ return theme => ({
209
+ root: {
210
+ height: theme.controlHeights[size],
211
+ paddingHorizontal: theme.spacing(padding),
212
+ gap: theme.spacing(gap),
213
+ borderRadius: theme.radius[radius]
214
+ },
215
+ label: {
216
+ fontSize: theme.fontSizes[size],
217
+ lineHeight: theme.lineHeights[size]
218
+ },
219
+ icon: {
220
+ fontSize: theme.fontSizes[glyph]
221
+ },
222
+ spinner: ring(theme, theme.fontSizes[glyph])
223
+ });
224
+ }
225
+ var buttonRecipe = createRecipe({
226
+ slots: SLOTS,
227
+ base: theme => ({
228
+ root: {
229
+ flexDirection: "row",
230
+ alignItems: "center",
231
+ justifyContent: "center",
232
+ borderWidth: 0,
233
+ // iOS's squircle. Free on Android, and it is what makes a large radius read as a
234
+ // shape rather than as two arcs meeting a straight edge.
235
+ borderCurve: "continuous"
236
+ },
237
+ label: {
238
+ fontFamily: theme.fontFamilies.body,
239
+ fontWeight: theme.fontWeights.medium
240
+ }
241
+ }),
242
+ variantTokens: VARIANT_TOKENS,
243
+ /**
244
+ * Where the variant's colours land, for every variant at once. The border width follows
245
+ * the *presence* of the border role rather than a per-variant flag — `tertiary` is the
246
+ * only variant that names one, and that fact is already in the table above.
247
+ */
248
+ paint: (theme, colors) => ({
249
+ root: {
250
+ backgroundColor: colors.bg,
251
+ borderColor: colors.border,
252
+ borderWidth: colors.border ? theme.borderWidth.default : 0
253
+ },
254
+ label: {
255
+ color: colors.fg
256
+ },
257
+ icon: {
258
+ color: colors.fg
259
+ },
260
+ spinner: {
261
+ borderColor: colors.fg
262
+ }
263
+ }),
264
+ /**
265
+ * Declaration order is application order: `radius` overrides the radius `size` set, and
266
+ * `isIconOnly` overrides its padding. Both are axes rather than a static sheet merged
267
+ * at the call site, so they stay inside the cache key and a press still allocates
268
+ * nothing.
269
+ */
270
+ variants: {
271
+ size: {
272
+ xs: sizeAxis({
273
+ size: "xs",
274
+ padding: 3,
275
+ gap: 1,
276
+ glyph: "sm",
277
+ radius: "3xl"
278
+ }),
279
+ sm: sizeAxis({
280
+ size: "sm",
281
+ padding: 3.5,
282
+ gap: 1.5,
283
+ glyph: "md",
284
+ radius: "3xl"
285
+ }),
286
+ md: sizeAxis({
287
+ size: "md",
288
+ padding: 4,
289
+ gap: 2,
290
+ glyph: "lg",
291
+ radius: "3xl"
292
+ }),
293
+ lg: sizeAxis({
294
+ size: "lg",
295
+ padding: 5,
296
+ gap: 2.5,
297
+ glyph: "xl",
298
+ radius: "4xl"
299
+ })
300
+ },
301
+ radius: {
302
+ xs: t => ({
303
+ root: {
304
+ borderRadius: t.radius.xs
305
+ }
306
+ }),
307
+ sm: t => ({
308
+ root: {
309
+ borderRadius: t.radius.sm
310
+ }
311
+ }),
312
+ md: t => ({
313
+ root: {
314
+ borderRadius: t.radius.md
315
+ }
316
+ }),
317
+ lg: t => ({
318
+ root: {
319
+ borderRadius: t.radius.lg
320
+ }
321
+ }),
322
+ xl: t => ({
323
+ root: {
324
+ borderRadius: t.radius.xl
325
+ }
326
+ }),
327
+ "2xl": t => ({
328
+ root: {
329
+ borderRadius: t.radius["2xl"]
330
+ }
331
+ }),
332
+ "3xl": t => ({
333
+ root: {
334
+ borderRadius: t.radius["3xl"]
335
+ }
336
+ }),
337
+ "4xl": t => ({
338
+ root: {
339
+ borderRadius: t.radius["4xl"]
340
+ }
341
+ }),
342
+ field: t => ({
343
+ root: {
344
+ borderRadius: t.radius.field
345
+ }
346
+ }),
347
+ full: t => ({
348
+ root: {
349
+ borderRadius: t.radius.full
350
+ }
351
+ })
352
+ },
353
+ // A square on a fixed height. No width is computed, and none needs to be.
354
+ isIconOnly: {
355
+ true: () => ({
356
+ root: {
357
+ paddingHorizontal: 0,
358
+ aspectRatio: 1
359
+ }
360
+ })
361
+ }
362
+ },
363
+ /**
364
+ * The pressed colour lives here rather than in a `PressableFeedback.Highlight`, because
365
+ * a control picks one treatment or the other — both, and a pressed button darkens
366
+ * twice. This one is the variant's own `…Pressed` token, so the press reads as the
367
+ * button's colour going down rather than as a neutral film over it, and a tinted button
368
+ * presses through the same OKLab formula as a token one.
369
+ */
370
+ states: {
371
+ pressed: (_theme, colors) => ({
372
+ root: {
373
+ backgroundColor: colors.bgPressed
374
+ }
375
+ }),
376
+ disabled: theme => ({
377
+ root: {
378
+ opacity: theme.opacity.disabled
379
+ }
380
+ })
381
+ },
382
+ defaultVariants: {
383
+ variant: "primary",
384
+ size: "md"
385
+ }
386
+ });
387
+
388
+ // src/components/button/button.utils.ts
389
+ import { Children, isValidElement } from "react";
390
+ function containsElementOfType(children, type) {
391
+ return Children.toArray(children).some(child => isValidElement(child) && child.type === type);
392
+ }
393
+
394
+ // src/components/button/button.tsx
395
+ import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
396
+ var ButtonRoot = forwardRef2(function Button({
397
+ children,
398
+ variant,
399
+ size,
400
+ radius,
401
+ color,
402
+ isDisabled = false,
403
+ isLoading = false,
404
+ isIconOnly = false,
405
+ asChild = false,
406
+ accessibilityRole = "button",
407
+ accessibilityState,
408
+ style,
409
+ onPressIn,
410
+ onPressOut,
411
+ ...props
412
+ }, ref) {
413
+ const theme = useXAUITheme();
414
+ const [styleProps, rest] = useStyleProps(props);
415
+ const [isPressed, press] = usePressState({
416
+ onPressIn,
417
+ onPressOut
418
+ });
419
+ const selection = {
420
+ variant,
421
+ size,
422
+ radius,
423
+ isIconOnly: isIconOnly ? "true" : void 0
424
+ };
425
+ const states = {
426
+ pressed: isPressed,
427
+ disabled: isDisabled || isLoading
428
+ };
429
+ const styles = buttonRecipe.resolve({
430
+ theme,
431
+ selection,
432
+ states
433
+ });
434
+ const tint = color ? buttonRecipe.tint({
435
+ theme,
436
+ color,
437
+ selection,
438
+ states
439
+ }) : void 0;
440
+ const context = useMemo(() => {
441
+ const icon = StyleSheet.flatten([styles.icon, tint?.icon]);
442
+ return {
443
+ labelStyle: tint ? [styles.label, tint.label] : styles.label,
444
+ spinnerStyle: tint ? [styles.spinner, tint.spinner] : styles.spinner,
445
+ icon: {
446
+ size: icon.fontSize,
447
+ // `ColorValue` also covers the platform's opaque colours, which `Icon` cannot
448
+ // hand to a third-party component expecting a string.
449
+ color: typeof icon.color === "string" ? icon.color : void 0
450
+ },
451
+ isDisabled,
452
+ isLoading
453
+ };
454
+ }, [styles, tint, isDisabled, isLoading]);
455
+ const rootStyle = [styles.root, tint?.root, styleProps, typeof style === "function" ? style({
456
+ pressed: isPressed
457
+ }) : style];
458
+ const text = childrenToString(children);
459
+ const showSpinner = isLoading && !containsElementOfType(children, ButtonSpinner);
460
+ if (isIconOnly && !rest.accessibilityLabel && !rest["aria-label"]) {
461
+ warnDev("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.");
462
+ }
463
+ return /* @__PURE__ */jsx4(ButtonProvider, {
464
+ value: context,
465
+ children: /* @__PURE__ */jsx4(PressableFeedback, {
466
+ ref,
467
+ isPressed,
468
+ isDisabled: isDisabled || isLoading,
469
+ asChild,
470
+ accessibilityRole,
471
+ accessibilityState: {
472
+ disabled: isDisabled,
473
+ busy: isLoading,
474
+ ...accessibilityState
475
+ },
476
+ ...rest,
477
+ style: rootStyle,
478
+ onPressIn: press.onPressIn,
479
+ onPressOut: press.onPressOut,
480
+ children: asChild ? children : /* @__PURE__ */jsxs(Fragment, {
481
+ children: [showSpinner ? /* @__PURE__ */jsx4(ButtonSpinner, {}) : null, text !== null ? /* @__PURE__ */jsx4(ButtonLabel, {
482
+ children: text
483
+ }) : children]
484
+ })
485
+ })
486
+ });
487
+ });
488
+ ButtonRoot.displayName = "XAUI.Button.Root";
489
+
490
+ // src/components/button/index.ts
491
+ var Button2 = Object.assign(ButtonRoot, {
492
+ Label: ButtonLabel,
493
+ Icon: ButtonIcon,
494
+ Spinner: ButtonSpinner
495
+ });
496
+ export { useButton, usePressState, warnDev, buttonRecipe, Button2 as Button };