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

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