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