@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.
@@ -1,7 +1,53 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkKFCORXWWcjs = require('../chunk-KFCORXWW.cjs');
4
- require('../chunk-M7P46XKI.cjs');
5
3
 
6
4
 
7
- exports.createRecipe = _chunkKFCORXWWcjs.createRecipe;
5
+ var _chunkLMUPNKPHcjs = require('../chunk-LMUPNKPH.cjs');
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ var _chunkE2UGZJBTcjs = require('../chunk-E2UGZJBT.cjs');
28
+ require('../chunk-3QBT3Q65.cjs');
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ exports.HIGHLIGHT_OPACITY = _chunkE2UGZJBTcjs.HIGHLIGHT_OPACITY; exports.Icon = _chunkE2UGZJBTcjs.Icon; exports.IconContext = _chunkE2UGZJBTcjs.IconContext; exports.PRESS_DURATION = _chunkE2UGZJBTcjs.PRESS_DURATION; exports.PRESS_SCALE = _chunkE2UGZJBTcjs.PRESS_SCALE; exports.Portal = _chunkLMUPNKPHcjs.Portal; exports.PortalContext = _chunkLMUPNKPHcjs.PortalContext; exports.PortalHost = _chunkLMUPNKPHcjs.PortalHost; exports.PressableFeedback = _chunkE2UGZJBTcjs.PressableFeedback; exports.RELEASE_DURATION = _chunkE2UGZJBTcjs.RELEASE_DURATION; exports.RIPPLE_COVERAGE = _chunkE2UGZJBTcjs.RIPPLE_COVERAGE; exports.RIPPLE_DURATION = _chunkE2UGZJBTcjs.RIPPLE_DURATION; exports.RIPPLE_OPACITY = _chunkE2UGZJBTcjs.RIPPLE_OPACITY; exports.Slot = _chunkE2UGZJBTcjs.Slot; exports.childrenToString = _chunkE2UGZJBTcjs.childrenToString; exports.createRecipe = _chunkE2UGZJBTcjs.createRecipe; exports.createSlotContext = _chunkE2UGZJBTcjs.createSlotContext; exports.mergeProps = _chunkE2UGZJBTcjs.mergeProps; exports.mergeRefs = _chunkE2UGZJBTcjs.mergeRefs; exports.resolveAnimation = _chunkE2UGZJBTcjs.resolveAnimation; exports.resolveSlotAnimation = _chunkE2UGZJBTcjs.resolveSlotAnimation; exports.useFeedback = _chunkE2UGZJBTcjs.useFeedback; exports.useIconContext = _chunkE2UGZJBTcjs.useIconContext;
@@ -1,83 +1,265 @@
1
- import { g as XAUITheme, X as XAUIColors } from '../theme.type-B3ODSLbB.cjs';
2
- import { ViewStyle, TextStyle } from 'react-native';
3
-
4
- /**
5
- * A slot is a view or a text node, and a recipe writes one object per slot, so the two
6
- * RN style shapes are merged rather than discriminated per slot.
7
- */
8
- type SlotStyle = ViewStyle & TextStyle;
9
- type SlotStyles<Slot extends string> = Partial<Record<Slot, SlotStyle>>;
10
- /** The roles a variant consumes. The variant names tokens; `paint` says where they land. */
11
- type VariantRole = 'bg' | 'bgPressed' | 'fg' | 'border';
12
- /** Token names per role no colour value ever appears in a recipe. */
13
- type VariantTokens = Partial<Record<VariantRole, keyof XAUIColors>>;
14
- /** The same roles resolved: theme colours, or the slices of a raw `color`. */
15
- type VariantColors = Partial<Record<VariantRole, string>>;
16
- /**
17
- * `disabled` is applied last of the three: a control that is both pressed and disabled
18
- * has to read disabled.
19
- */
20
- type StateName = 'focused' | 'pressed' | 'disabled';
21
- type States = Partial<Record<StateName, boolean>>;
22
- /** Reads the theme and the variant's resolved colours; returns one style per slot. */
23
- type StyleFn<Slot extends string> = (theme: XAUITheme, colors: VariantColors) => SlotStyles<Slot>;
24
- /** Named axes of finite token values — `{ size: { sm: fn, md: fn } }`. */
25
- type Axes<Slot extends string> = Record<string, Record<string, StyleFn<Slot>>>;
26
- /** One value per axis, plus the variant. Missing keys fall back to `defaultVariants`. */
27
- type Selection<Variant extends string, A extends Axes<string>> = {
28
- variant?: Variant;
29
- } & {
30
- [Axis in keyof A]?: Extract<keyof A[Axis], string>;
31
- };
32
- type CompoundVariant<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
33
- when: Selection<Variant, A>;
34
- style: StyleFn<Slot>;
1
+ import * as react from 'react';
2
+ import { Ref, ReactNode, Provider, RefCallback } from 'react';
3
+ import { b as IconProps, a as IconContextValue, S as SlotAnimation, F as FeedbackContext, c as AnimationProp, R as ResolvedAnimation, d as FeedbackVariant } from '../create-recipe-BjSP0zL_.cjs';
4
+ export { A as AnimationConfig, h as Axes, C as CompoundVariant, I as IconComponentProps, P as PressableFeedbackProps, f as Recipe, i as RecipeConfig, g as ResolveArgs, j as ResolvedSelection, k as ResolvedStyles, l as Selection, m as SlotStyle, n as SlotStyles, o as StateName, p as States, q as StyleFn, T as TintArgs, V as VariantColors, r as VariantRole, s as VariantTokens, e as createRecipe } from '../create-recipe-BjSP0zL_.cjs';
5
+ import * as react_native from 'react-native';
6
+ import { StyleProp, ViewStyle } from 'react-native';
7
+ import 'react-native-reanimated';
8
+ import '../theme.type-C9bFJKFm.cjs';
9
+
10
+ /**
11
+ * The gap nobody else closes: an icon is a third-party component, so a slot context does
12
+ * not reach it and every call site ends up computing the colour by hand.
13
+ *
14
+ * ```tsx
15
+ * <Button variant="danger">
16
+ * <Button.Icon as={TrashIcon} /> {/* colour and size inherited, nothing to pass *\/}
17
+ * <Button.Label>Supprimer</Button.Label>
18
+ * </Button>
19
+ * ```
20
+ *
21
+ * Three accepted forms — a component through `as`, a raw SVG as children, or an image
22
+ * through `source` and the resolution is the same for all three: an explicit prop, else
23
+ * what the surrounding slot published, else the theme.
24
+ */
25
+ declare function Icon({ as: Component, children, source, size, color, style, }: IconProps): react.JSX.Element;
26
+ declare namespace Icon {
27
+ var displayName: string;
28
+ }
29
+
30
+ /**
31
+ * Not a `createSlotContext`: that one throws outside its parent, and an `Icon` has to
32
+ * work on its own as much as inside a `Button`. An empty context is the honest default —
33
+ * nothing inherited, so the theme decides.
34
+ */
35
+ declare const IconContext: react.Context<IconContextValue>;
36
+ declare function useIconContext(): IconContextValue;
37
+
38
+ type PressableFeedbackHighlightProps = {
39
+ style?: StyleProp<ViewStyle>;
40
+ /** Overrides the blanket `animation` on the root, for this overlay only. */
41
+ animation?: SlotAnimation;
35
42
  };
36
- type RecipeConfig<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
37
- /** Every slot the component publishes. Slots a recipe never styles resolve to `{}`. */
38
- slots: readonly Slot[];
39
- base?: StyleFn<Slot>;
40
- variantTokens?: Record<Variant, VariantTokens>;
41
- /** Where the variant's colours land written once, and it holds for every variant. */
42
- paint?: StyleFn<Slot>;
43
- variants?: A;
44
- compoundVariants?: ReadonlyArray<CompoundVariant<Slot, Variant, A>>;
45
- states?: Partial<Record<StateName, StyleFn<Slot>>>;
46
- defaultVariants?: Selection<Variant, A>;
43
+ /**
44
+ * The press wash: one flat overlay fading in under the finger.
45
+ *
46
+ * It is a **neutral** wash, not the variant's pressed colour. A component picks one or
47
+ * the other — this overlay, or a `pressed` state in its recipe swapping `bg` for
48
+ * `bgPressed`never both, or a pressed button darkens twice.
49
+ */
50
+ declare function PressableFeedbackHighlight({ style, animation: override, }: PressableFeedbackHighlightProps): react.JSX.Element;
51
+ declare namespace PressableFeedbackHighlight {
52
+ var displayName: string;
53
+ }
54
+
55
+ type PressableFeedbackRippleProps = {
56
+ style?: StyleProp<ViewStyle>;
57
+ /** Overrides the blanket `animation` on the root, for this overlay only. */
58
+ animation?: SlotAnimation;
47
59
  };
48
- /** Stable references: the same object for the same tokens, for the app's lifetime. */
49
- type ResolvedStyles<Slot extends string> = Readonly<Record<Slot, SlotStyle>>;
50
- /** A selection with `defaultVariants` already folded in, keyed by axis name. */
51
- type ResolvedSelection = Readonly<Record<string, string | undefined>>;
52
-
53
- type ResolveArgs<Variant extends string, A extends Axes<string>> = {
54
- theme: XAUITheme;
55
- selection?: Selection<Variant, A>;
56
- states?: States;
60
+ /**
61
+ * A circle washing outwards from where the finger landed.
62
+ *
63
+ * **Two animations, not one, and that is the whole shape of it.** The circle *expands*
64
+ * once per touch, from the point of contact to past the far corner. Its *opacity* follows
65
+ * the finger — up on press, held while the press lasts, out on release. Driving both from
66
+ * one curve is what makes a ripple read wrong: tie opacity to the expansion and the wave
67
+ * is invisible under the finger and brightest once it covers everything, which is a flash
68
+ * of the whole control rather than a wave leaving the touch point.
69
+ *
70
+ * It needs the root to clip — `PressableFeedback` sets `overflow: 'hidden'` when it
71
+ * mounts one — and it renders nothing on the static branch: a ripple that cannot expand
72
+ * is a coloured disc sitting on the control, which reads as a defect rather than as
73
+ * reduced motion.
74
+ */
75
+ declare function PressableFeedbackRipple({ style, animation: override, }: PressableFeedbackRippleProps): react.JSX.Element | null;
76
+ declare namespace PressableFeedbackRipple {
77
+ var displayName: string;
78
+ }
79
+
80
+ declare const useFeedback: () => FeedbackContext;
81
+
82
+ /**
83
+ * The values the v0 tree shipped with (`Animated.spring` to `0.975`, `bounciness: 0`,
84
+ * over roughly 100ms). Kept identical on purpose: the touch feedback is the part of a
85
+ * library users feel rather than read, and changing its timing in a rewrite would be a
86
+ * regression nobody asked for. `bounciness: 0` is why a duration replaces the spring —
87
+ * a spring with no bounce is a curve.
88
+ */
89
+ declare const PRESS_SCALE = 0.975;
90
+ declare const PRESS_DURATION = 100;
91
+ declare const RELEASE_DURATION = 150;
92
+ /** How far the wash and the ripple go at full press. */
93
+ declare const HIGHLIGHT_OPACITY = 0.08;
94
+ declare const RIPPLE_OPACITY = 0.12;
95
+ declare const RIPPLE_DURATION = 350;
96
+ /**
97
+ * The circle's radius as a multiple of the control's diagonal. Above 1 it covers from
98
+ * any point on the control, so where the finger landed never enters the calculation.
99
+ */
100
+ declare const RIPPLE_COVERAGE = 1.25;
101
+ /**
102
+ * One shape out of four accepted ones, so the components read a record instead of
103
+ * re-deciding what `'disable-all'` meant.
104
+ *
105
+ * `inheritedDisableAll` comes from an ancestor that asked for it, and it wins: a list
106
+ * that switched its rows' animations off cannot be overridden by a row.
107
+ */
108
+ declare function resolveAnimation(animation: AnimationProp | undefined, inheritedDisableAll?: boolean): ResolvedAnimation;
109
+ type ResolvedSlotAnimation = {
110
+ enabled: boolean;
111
+ duration: number;
112
+ opacity: number;
57
113
  };
58
- type TintArgs<Variant extends string, A extends Axes<string>> = ResolveArgs<Variant, A> & {
59
- color: string;
114
+ /**
115
+ * A slot's own `animation` over the root's blanket one, with the root winning when it
116
+ * switched everything off — `animation="disable-all"` on an ancestor cannot be undone by
117
+ * an overlay that asks nicely.
118
+ */
119
+ declare function resolveSlotAnimation(override: SlotAnimation | undefined, enabledByRoot: boolean, defaultOpacity: number, defaultDuration?: number): ResolvedSlotAnimation;
120
+
121
+ declare const PressableFeedback: react.ForwardRefExoticComponent<Omit<react_native.PressableProps, "style" | "children" | "disabled"> & {
122
+ isPressed?: boolean;
123
+ isDisabled?: boolean;
124
+ asChild?: boolean;
125
+ feedbackVariant?: FeedbackVariant;
126
+ animation?: AnimationProp;
127
+ style?: react_native.StyleProp<react_native.ViewStyle>;
128
+ children?: react.ReactNode;
129
+ } & react.RefAttributes<react_native.View>> & {
130
+ Highlight: typeof PressableFeedbackHighlight;
131
+ Ripple: typeof PressableFeedbackRipple;
60
132
  };
61
- type Recipe<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
62
- readonly slots: readonly Slot[];
63
- /** The cached pass: stable `StyleSheet` references, keyed by tokens alone. */
64
- resolve(args: ResolveArgs<Variant, A>): ResolvedStyles<Slot>;
133
+
134
+ /** Anything React accepts as a ref, plus the absence of one. */
135
+ type PossibleRef<T> = Ref<T> | undefined;
136
+ /**
137
+ * The props `mergeProps` knows how to combine. Deliberately loose: it merges whatever a
138
+ * root hands to whatever child it was given, and neither side is knowable from here.
139
+ */
140
+ type MergeableProps = Record<string, unknown>;
141
+ type AsChildProps = {
65
142
  /**
66
- * The tint pass: the same functions run again with `color`'s slices in place of the
67
- * theme's tokens. Uncached and allocating, and only ever called when `color` is set.
143
+ * Merge this component's props into its single child instead of rendering an element
144
+ * of its own a navigation `Link` as a `Button`, a bespoke trigger as a `Select`.
68
145
  */
69
- tint(args: TintArgs<Variant, A>): SlotStyles<Slot>;
146
+ asChild?: boolean;
147
+ };
148
+
149
+ type PortalProps = {
150
+ children: ReactNode;
70
151
  };
71
152
  /**
72
- * A component's style, declared once. Resolution splits in two because the two halves
73
- * have different lifetimes: everything keyed by a finite token is cached forever, and
74
- * an arbitrary `color` is recomputed per render which is what keeps the cache bounded
75
- * by the number of token combinations rather than by the palette users invent.
153
+ * Renders its children into the nearest `PortalHost` instead of where it sits. What
154
+ * `Dialog`, `Sheet`, `Drawer` and `Snackbar` are built on: an overlay has to escape the
155
+ * clipping and stacking of whatever container happened to hold the trigger.
156
+ *
157
+ * Both halves run in layout effects rather than effects, which is deliberate: the content
158
+ * lands in the same commit as the trigger's, so an overlay neither shows one frame late
159
+ * nor survives one frame past the unmount that closed it. The unpublish sits in its own
160
+ * effect so that it does not depend on `children` — a re-publish then keeps the portal's
161
+ * place in the host's order instead of dropping it and re-adding it at the end.
162
+ */
163
+ declare function Portal({ children }: PortalProps): null;
164
+ declare namespace Portal {
165
+ var displayName: string;
166
+ }
167
+
168
+ type PortalMethods = {
169
+ addPortal: (key: string, element: ReactNode) => void;
170
+ removePortal: (key: string) => void;
171
+ };
172
+ /**
173
+ * `null` outside a host, and `Portal` treats that as "render nothing" rather than
174
+ * throwing: an app that forgot `PortalHost` should lose its overlays, not crash on the
175
+ * first `Dialog`.
176
+ */
177
+ declare const PortalContext: react.Context<PortalMethods | null>;
178
+
179
+ type PortalHostProps = {
180
+ children: ReactNode;
181
+ };
182
+ /**
183
+ * Where every `Portal` in the tree below renders. Mounted once, at the root of the app,
184
+ * above navigation — an overlay that renders inside a screen is clipped by it.
185
+ */
186
+ declare function PortalHost({ children }: PortalHostProps): react.JSX.Element;
187
+ declare namespace PortalHost {
188
+ var displayName: string;
189
+ }
190
+
191
+ /**
192
+ * R3: the string a root should wrap in its default text slot, or `null` when it should
193
+ * render its children as they are.
194
+ *
195
+ * The whole tree is stringified recursively rather than the first child inspected. That
196
+ * is what makes `<Button>{count} items</Button>` work — children there are the array
197
+ * `[3, ' items']`, and an `isValidElement` check on the first entry would call it an
198
+ * element-free tree only by accident, while a check for "is the first child a string"
199
+ * would miss it outright.
200
+ *
201
+ * `null` for an empty result as much as for a tree containing an element: in both cases
202
+ * there is nothing to wrap, and a root's fallback — render the children — is right for
203
+ * both. It also keeps `<Button>{false}</Button>` from mounting an empty text node.
204
+ */
205
+ declare function childrenToString(children: ReactNode): string | null;
206
+
207
+ /**
208
+ * A context a slot cannot read by accident. Every compound gets one, and it carries
209
+ * **resolved** values — style references the root already computed, not tokens for the
210
+ * slot to resolve again (R5).
211
+ *
212
+ * ```ts
213
+ * const [ButtonProvider, useButton] = createSlotContext<ButtonContext>('Button')
214
+ * ```
215
+ *
216
+ * The tuple is what lets each compound name its own hook, which R10 requires it to
217
+ * export. `name` gives both halves of the error, so there is one place to spell it.
218
+ */
219
+ declare function createSlotContext<T>(name: string): readonly [Provider<T | null>, () => T];
220
+
221
+ /**
222
+ * Merges a root's own props into the child it renders through `asChild` (R12). Four
223
+ * rules, and the child wins wherever they do not apply — it is the more specific intent:
224
+ *
225
+ * - **Event handlers compose.** Both run, ours first: the component's own behaviour (the
226
+ * press state that drives its styles) happens before the child's side effect (the
227
+ * navigation). Replacing one with the other is the bug this exists to prevent.
228
+ * - **Styles stack**, ours under the child's, so the child can override.
229
+ * - **`ref`s merge** through `mergeRefs`. React 19 passes `ref` as an ordinary prop, so
230
+ * it arrives here rather than beside the props, and dropping it would sever the root's
231
+ * handle on the node.
232
+ * - **Everything else: the child's value wins**, and ours fills in what it left unset.
233
+ */
234
+ declare function mergeProps(ours: MergeableProps, theirs: MergeableProps): MergeableProps;
235
+
236
+ /**
237
+ * One callback that feeds several refs — what lets a root keep its own handle on a node
238
+ * while still honouring the ref its caller passed (R9), and what `asChild` needs to
239
+ * forward a ref into the child it merges into (R12).
240
+ *
241
+ * It returns nothing on purpose. React 19 reads a ref callback's return value as a
242
+ * cleanup function while React 18 ignores it, and this package supports both; letting
243
+ * a merged cleanup through would behave differently on each. React calls every ref with
244
+ * `null` on unmount anyway, which this forwards.
245
+ */
246
+ declare function mergeRefs<T>(...refs: Array<PossibleRef<T>>): RefCallback<T>;
247
+
248
+ type SlotProps = MergeableProps & {
249
+ children?: ReactNode;
250
+ };
251
+ /**
252
+ * The render branch behind `asChild` (R12). A root picks it instead of its own element:
253
+ *
254
+ * ```tsx
255
+ * const Root = asChild ? Slot : Pressable
256
+ * return <Root ref={ref} {...rootProps}>{children}</Root>
257
+ * ```
76
258
  *
77
- * const styles = buttonRecipe.resolve({ theme, selection: { variant, size }, states })
78
- * const tint = color ? buttonRecipe.tint({ theme, color, selection, states }) : undefined
79
- * <View style={[styles.root, tint?.root, style]} />
259
+ * One line per root, which is the point forty-seven roots each hand-rolling a
260
+ * `cloneElement` and a ref merge would drift, and R12 has to hold uniformly from the
261
+ * first component or the ref signature of the whole core changes later.
80
262
  */
81
- declare function createRecipe<Slot extends string, Variant extends string, const A extends Axes<Slot>>(config: RecipeConfig<Slot, Variant, A>): Recipe<Slot, Variant, A>;
263
+ declare const Slot: react.ForwardRefExoticComponent<Omit<SlotProps, "ref"> & react.RefAttributes<unknown>>;
82
264
 
83
- export { type Axes, type CompoundVariant, type Recipe, type RecipeConfig, type ResolveArgs, type ResolvedSelection, type ResolvedStyles, type Selection, type SlotStyle, type SlotStyles, type StateName, type States, type StyleFn, type TintArgs, type VariantColors, type VariantRole, type VariantTokens, createRecipe };
265
+ export { AnimationProp, type AsChildProps, FeedbackContext, FeedbackVariant, HIGHLIGHT_OPACITY, Icon, IconContext, IconContextValue, IconProps, type MergeableProps, PRESS_DURATION, PRESS_SCALE, Portal, PortalContext, PortalHost, type PortalHostProps, type PortalMethods, type PortalProps, type PossibleRef, PressableFeedback, type PressableFeedbackHighlightProps, type PressableFeedbackRippleProps, RELEASE_DURATION, RIPPLE_COVERAGE, RIPPLE_DURATION, RIPPLE_OPACITY, ResolvedAnimation, Slot, SlotAnimation, type SlotProps, childrenToString, createSlotContext, mergeProps, mergeRefs, resolveAnimation, resolveSlotAnimation, useFeedback, useIconContext };