@xaui/native 0.9.1-alpha.1 → 0.9.1-alpha.11

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