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

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,688 @@
1
+ import {
2
+ deriveTint,
3
+ useXAUITheme
4
+ } from "./chunk-X2K2FX3W.js";
5
+
6
+ // src/system/portal/portal.tsx
7
+ import { useContext, useId, useLayoutEffect } from "react";
8
+
9
+ // src/system/portal/portal-context.ts
10
+ import { createContext } from "react";
11
+ var PortalContext = createContext(null);
12
+
13
+ // src/system/portal/portal.tsx
14
+ function Portal({ children }) {
15
+ const context = useContext(PortalContext);
16
+ const key = useId();
17
+ useLayoutEffect(() => {
18
+ context?.addPortal(key, children);
19
+ }, [children, context, key]);
20
+ useLayoutEffect(() => {
21
+ return () => context?.removePortal(key);
22
+ }, [context, key]);
23
+ return null;
24
+ }
25
+ Portal.displayName = "XAUI.Portal";
26
+
27
+ // src/system/portal/portal-host.tsx
28
+ import { Fragment, useCallback, useMemo, useState } from "react";
29
+ import { StyleSheet, View } from "react-native";
30
+ var styles = StyleSheet.create({
31
+ container: { flex: 1 }
32
+ });
33
+ function PortalHost({ children }) {
34
+ const [portals, setPortals] = useState(/* @__PURE__ */ new Map());
35
+ const addPortal = useCallback((key, element) => {
36
+ setPortals((current) => new Map(current).set(key, element));
37
+ }, []);
38
+ const removePortal = useCallback((key) => {
39
+ setPortals((current) => {
40
+ if (!current.has(key)) return current;
41
+ const next = new Map(current);
42
+ next.delete(key);
43
+ return next;
44
+ });
45
+ }, []);
46
+ const methods = useMemo(
47
+ () => ({ addPortal, removePortal }),
48
+ [addPortal, removePortal]
49
+ );
50
+ return /* @__PURE__ */ React.createElement(PortalContext.Provider, { value: methods }, /* @__PURE__ */ React.createElement(View, { style: styles.container }, children, Array.from(portals, ([key, element]) => /* @__PURE__ */ React.createElement(Fragment, { key }, element))));
51
+ }
52
+ PortalHost.displayName = "XAUI.PortalHost";
53
+
54
+ // src/system/pressable-feedback/pressable-feedback.tsx
55
+ import { forwardRef as forwardRef2, useContext as useContext3, useEffect as useEffect2, useMemo as useMemo2 } from "react";
56
+ import { Pressable } from "react-native";
57
+ import Animated3, {
58
+ useAnimatedStyle as useAnimatedStyle3,
59
+ useSharedValue as useSharedValue3,
60
+ withTiming as withTiming3
61
+ } from "react-native-reanimated";
62
+
63
+ // src/system/pressable-feedback/pressable-feedback-context.ts
64
+ import { createContext as createContext3 } from "react";
65
+
66
+ // src/system/slot/create-slot-context.ts
67
+ import { createContext as createContext2, useContext as useContext2 } from "react";
68
+ function createSlotContext(name) {
69
+ const Context = createContext2(null);
70
+ Context.displayName = `XAUI.${name}.Context`;
71
+ function useSlotContext() {
72
+ const value = useContext2(Context);
73
+ if (value === null) {
74
+ const error = new Error(
75
+ `XAUI: use${name} must be called inside <${name}>. A slot reads the values its root resolved, so it can only be rendered as a child of one.`
76
+ );
77
+ Error.captureStackTrace?.(
78
+ error,
79
+ useSlotContext
80
+ );
81
+ throw error;
82
+ }
83
+ return value;
84
+ }
85
+ return [Context.Provider, useSlotContext];
86
+ }
87
+
88
+ // src/system/pressable-feedback/pressable-feedback-context.ts
89
+ var [FeedbackProvider, useFeedback] = createSlotContext("PressableFeedback");
90
+ var DisableAllContext = createContext3(false);
91
+
92
+ // src/system/pressable-feedback/pressable-feedback-highlight.tsx
93
+ import { useEffect } from "react";
94
+ import { StyleSheet as StyleSheet2, View as View2 } from "react-native";
95
+ import Animated, {
96
+ useAnimatedStyle,
97
+ useSharedValue,
98
+ withTiming
99
+ } from "react-native-reanimated";
100
+
101
+ // src/system/pressable-feedback/pressable-feedback.animation.ts
102
+ var PRESS_SCALE = 0.975;
103
+ var PRESS_DURATION = 100;
104
+ var RELEASE_DURATION = 150;
105
+ var HIGHLIGHT_OPACITY = 0.08;
106
+ var RIPPLE_OPACITY = 0.12;
107
+ var RIPPLE_DURATION = 350;
108
+ var RIPPLE_COVERAGE = 1.25;
109
+ var ALL_OFF = {
110
+ scale: false,
111
+ highlight: false,
112
+ ripple: false,
113
+ none: true
114
+ };
115
+ var ALL_ON = {
116
+ scale: true,
117
+ highlight: true,
118
+ ripple: true,
119
+ none: false
120
+ };
121
+ function resolveAnimation(animation, inheritedDisableAll = false) {
122
+ if (inheritedDisableAll) return { ...ALL_OFF, disableAll: true };
123
+ if (animation === false || animation === "disabled") {
124
+ return { ...ALL_OFF, disableAll: false };
125
+ }
126
+ if (animation === "disable-all") return { ...ALL_OFF, disableAll: true };
127
+ if (animation === void 0 || animation === true) {
128
+ return { ...ALL_ON, disableAll: false };
129
+ }
130
+ const scale = animation.scale ?? true;
131
+ const highlight = animation.highlight ?? true;
132
+ const ripple = animation.ripple ?? true;
133
+ return {
134
+ scale,
135
+ highlight,
136
+ ripple,
137
+ none: !scale && !highlight && !ripple,
138
+ disableAll: false
139
+ };
140
+ }
141
+ function resolveSlotAnimation(override, enabledByRoot, defaultOpacity, defaultDuration = PRESS_DURATION) {
142
+ const fallback = {
143
+ enabled: enabledByRoot,
144
+ duration: defaultDuration,
145
+ opacity: defaultOpacity
146
+ };
147
+ if (override === void 0 || override === true) return fallback;
148
+ if (override === false) return { ...fallback, enabled: false };
149
+ return {
150
+ enabled: enabledByRoot,
151
+ duration: override.duration ?? defaultDuration,
152
+ opacity: override.opacity ?? defaultOpacity
153
+ };
154
+ }
155
+
156
+ // src/system/pressable-feedback/pressable-feedback-highlight.tsx
157
+ function PressableFeedbackHighlight({
158
+ style,
159
+ animation: override
160
+ }) {
161
+ const { isPressed, animation, progress } = useFeedback();
162
+ const theme = useXAUITheme();
163
+ const settings = resolveSlotAnimation(
164
+ override,
165
+ animation.highlight,
166
+ HIGHLIGHT_OPACITY
167
+ );
168
+ const base = [
169
+ StyleSheet2.absoluteFillObject,
170
+ { backgroundColor: theme.colors.foreground },
171
+ style
172
+ ];
173
+ if (!progress || !settings.enabled) {
174
+ return /* @__PURE__ */ React.createElement(
175
+ View2,
176
+ {
177
+ pointerEvents: "none",
178
+ style: [base, { opacity: isPressed ? settings.opacity : 0 }]
179
+ }
180
+ );
181
+ }
182
+ return /* @__PURE__ */ React.createElement(
183
+ AnimatedHighlight,
184
+ {
185
+ base,
186
+ duration: settings.duration,
187
+ opacity: settings.opacity
188
+ }
189
+ );
190
+ }
191
+ PressableFeedbackHighlight.displayName = "XAUI.PressableFeedback.Highlight";
192
+ function AnimatedHighlight({
193
+ base,
194
+ duration,
195
+ opacity
196
+ }) {
197
+ const { isPressed } = useFeedback();
198
+ const shown = useSharedValue(0);
199
+ useEffect(() => {
200
+ shown.value = withTiming(isPressed ? 1 : 0, { duration });
201
+ }, [isPressed, shown, duration]);
202
+ const animatedStyle = useAnimatedStyle(() => ({
203
+ opacity: shown.value * opacity
204
+ }));
205
+ return /* @__PURE__ */ React.createElement(Animated.View, { pointerEvents: "none", style: [base, animatedStyle] });
206
+ }
207
+
208
+ // src/system/pressable-feedback/pressable-feedback-ripple.tsx
209
+ import Animated2, {
210
+ interpolate,
211
+ useAnimatedReaction,
212
+ useAnimatedStyle as useAnimatedStyle2,
213
+ useSharedValue as useSharedValue2,
214
+ withTiming as withTiming2
215
+ } from "react-native-reanimated";
216
+ function PressableFeedbackRipple({
217
+ style,
218
+ animation: override
219
+ }) {
220
+ const { animation, progress, pressCount, origin, size } = useFeedback();
221
+ const theme = useXAUITheme();
222
+ const settings = resolveSlotAnimation(
223
+ override,
224
+ animation.ripple,
225
+ RIPPLE_OPACITY,
226
+ RIPPLE_DURATION
227
+ );
228
+ if (!progress || !pressCount || !origin || !size || !settings.enabled) return null;
229
+ return /* @__PURE__ */ React.createElement(
230
+ AnimatedRipple,
231
+ {
232
+ color: theme.colors.foreground,
233
+ duration: settings.duration,
234
+ opacity: settings.opacity,
235
+ style
236
+ }
237
+ );
238
+ }
239
+ PressableFeedbackRipple.displayName = "XAUI.PressableFeedback.Ripple";
240
+ function AnimatedRipple({
241
+ color,
242
+ duration,
243
+ opacity,
244
+ style
245
+ }) {
246
+ const { pressCount, origin, size } = useFeedback();
247
+ const waveA = useSharedValue2(0);
248
+ const waveB = useSharedValue2(0);
249
+ const fromA = useSharedValue2({ x: 0, y: 0 });
250
+ const fromB = useSharedValue2({ x: 0, y: 0 });
251
+ const useA = useSharedValue2(true);
252
+ useAnimatedReaction(
253
+ () => pressCount?.value ?? 0,
254
+ (count, previous) => {
255
+ if (previous === null || count === previous) return;
256
+ const wave = useA.value ? waveA : waveB;
257
+ const from = useA.value ? fromA : fromB;
258
+ from.value = origin?.value ?? { x: 0, y: 0 };
259
+ wave.value = 0;
260
+ wave.value = withTiming2(2, { duration: duration * 2 });
261
+ useA.value = !useA.value;
262
+ }
263
+ );
264
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
265
+ RippleWave,
266
+ {
267
+ wave: waveA,
268
+ from: fromA,
269
+ size,
270
+ color,
271
+ opacity,
272
+ style
273
+ }
274
+ ), /* @__PURE__ */ React.createElement(
275
+ RippleWave,
276
+ {
277
+ wave: waveB,
278
+ from: fromB,
279
+ size,
280
+ color,
281
+ opacity,
282
+ style
283
+ }
284
+ ));
285
+ }
286
+ function RippleWave({
287
+ wave,
288
+ from,
289
+ size,
290
+ color,
291
+ opacity,
292
+ style
293
+ }) {
294
+ const animatedStyle = useAnimatedStyle2(() => {
295
+ const within = size?.value ?? { width: 0, height: 0 };
296
+ const radius = Math.sqrt(within.width * within.width + within.height * within.height) * RIPPLE_COVERAGE;
297
+ const at = from.value;
298
+ return {
299
+ width: radius * 2,
300
+ height: radius * 2,
301
+ borderRadius: radius,
302
+ // Rises as the circle opens and drains once it is open — so the wave is at its
303
+ // strongest when it covers the control, not when it is a dot under the finger.
304
+ opacity: interpolate(wave.value, [0, 1, 2], [0, opacity, 0]),
305
+ transform: [
306
+ { translateX: at.x - radius },
307
+ { translateY: at.y - radius },
308
+ { scale: interpolate(wave.value, [0, 1, 2], [0, 1, 1]) }
309
+ ]
310
+ };
311
+ });
312
+ return /* @__PURE__ */ React.createElement(
313
+ Animated2.View,
314
+ {
315
+ pointerEvents: "none",
316
+ style: [
317
+ { position: "absolute", backgroundColor: color },
318
+ animatedStyle,
319
+ style
320
+ ]
321
+ }
322
+ );
323
+ }
324
+
325
+ // src/system/slot/slot.tsx
326
+ import { cloneElement, forwardRef, isValidElement } from "react";
327
+
328
+ // src/system/slot/merge-refs.ts
329
+ function mergeRefs(...refs) {
330
+ return (value) => {
331
+ for (const ref of refs) {
332
+ if (typeof ref === "function") ref(value);
333
+ else if (ref) ref.current = value;
334
+ }
335
+ };
336
+ }
337
+
338
+ // src/system/slot/merge-props.ts
339
+ var EVENT_HANDLER = /^on[A-Z]/;
340
+ function mergeProps(ours, theirs) {
341
+ const merged = { ...ours };
342
+ for (const key of Object.keys(theirs)) {
343
+ const ourValue = ours[key];
344
+ const theirValue = theirs[key];
345
+ if (EVENT_HANDLER.test(key)) {
346
+ merged[key] = composeHandlers(ourValue, theirValue);
347
+ } else if (key === "style") {
348
+ merged[key] = mergeStyles(ourValue, theirValue);
349
+ } else if (key === "ref") {
350
+ merged[key] = mergeRefs(
351
+ ourValue,
352
+ theirValue
353
+ );
354
+ } else {
355
+ merged[key] = theirValue;
356
+ }
357
+ }
358
+ return merged;
359
+ }
360
+ function composeHandlers(ours, theirs) {
361
+ if (typeof ours !== "function") return theirs;
362
+ if (typeof theirs !== "function") return ours;
363
+ return (...args) => {
364
+ ;
365
+ ours(...args);
366
+ return theirs(...args);
367
+ };
368
+ }
369
+ function mergeStyles(ours, theirs) {
370
+ if (typeof ours === "function" || typeof theirs === "function") {
371
+ return (state) => [
372
+ resolveStyle(ours, state),
373
+ resolveStyle(theirs, state)
374
+ ];
375
+ }
376
+ return [ours, theirs];
377
+ }
378
+ function resolveStyle(style, state) {
379
+ return typeof style === "function" ? style(state) : style;
380
+ }
381
+
382
+ // src/system/slot/slot.tsx
383
+ var Slot = forwardRef(function Slot2({ children, ...ours }, ref) {
384
+ if (!isValidElement(children)) {
385
+ throw new Error(
386
+ "XAUI: asChild expects exactly one React element as its child, and merges the component's props into it. Text, a fragment, several children or none give it nothing to merge into \u2014 drop `asChild` to render the component itself."
387
+ );
388
+ }
389
+ const child = children;
390
+ const merged = mergeProps(ours, child.props);
391
+ merged.ref = mergeRefs(ref, refOf(child));
392
+ return cloneElement(child, merged);
393
+ });
394
+ Slot.displayName = "XAUI.Slot";
395
+ function refOf(element) {
396
+ const fromProps = element.props.ref;
397
+ const fromElement = element.ref;
398
+ return fromProps ?? fromElement;
399
+ }
400
+
401
+ // src/system/pressable-feedback/pressable-feedback.tsx
402
+ var AnimatedPressable = Animated3.createAnimatedComponent(Pressable);
403
+ var AnimatedSlot = Animated3.createAnimatedComponent(Slot);
404
+ var PressableFeedback = forwardRef2(
405
+ function PressableFeedback2({ animation, feedbackVariant = "scale-highlight", ...rest }, ref) {
406
+ const inheritedDisableAll = useContext3(DisableAllContext);
407
+ const resolved = resolveAnimation(animation, inheritedDisableAll);
408
+ const Feedback = resolved.none || feedbackVariant === "none" ? StaticFeedback : AnimatedFeedback;
409
+ const body = /* @__PURE__ */ React.createElement(
410
+ Feedback,
411
+ {
412
+ ref,
413
+ animation: resolved,
414
+ feedbackVariant,
415
+ ...rest
416
+ }
417
+ );
418
+ return resolved.disableAll ? /* @__PURE__ */ React.createElement(DisableAllContext.Provider, { value: true }, body) : body;
419
+ }
420
+ );
421
+ var StaticFeedback = forwardRef2(function StaticFeedback2({
422
+ isPressed = false,
423
+ isDisabled,
424
+ asChild = false,
425
+ animation,
426
+ feedbackVariant,
427
+ children,
428
+ style,
429
+ ...rest
430
+ }, ref) {
431
+ const context = useMemo2(() => ({ isPressed, animation }), [isPressed, animation]);
432
+ const Root = asChild ? Slot : Pressable;
433
+ return /* @__PURE__ */ React.createElement(Root, { ref, style, disabled: isDisabled, ...rest }, /* @__PURE__ */ React.createElement(FeedbackProvider, { value: context }, /* @__PURE__ */ React.createElement(DefaultOverlay, { variant: feedbackVariant }), children));
434
+ });
435
+ var AnimatedFeedback = forwardRef2(function AnimatedFeedback2({
436
+ isPressed = false,
437
+ isDisabled,
438
+ asChild = false,
439
+ animation,
440
+ feedbackVariant,
441
+ children,
442
+ style,
443
+ onPressIn,
444
+ onLayout,
445
+ ...rest
446
+ }, ref) {
447
+ const progress = useSharedValue3(0);
448
+ const pressCount = useSharedValue3(0);
449
+ const origin = useSharedValue3({ x: 0, y: 0 });
450
+ const size = useSharedValue3({ width: 0, height: 0 });
451
+ useEffect2(() => {
452
+ progress.value = withTiming3(isPressed ? 1 : 0, {
453
+ duration: isPressed ? PRESS_DURATION : RELEASE_DURATION
454
+ });
455
+ }, [isPressed, progress]);
456
+ const animatedStyle = useAnimatedStyle3(
457
+ () => animation.scale ? { transform: [{ scale: 1 - (1 - PRESS_SCALE) * progress.value }] } : {}
458
+ );
459
+ const context = useMemo2(
460
+ () => ({ isPressed, animation, progress, pressCount, origin, size }),
461
+ [isPressed, animation, progress, pressCount, origin, size]
462
+ );
463
+ const handlePressIn = (event) => {
464
+ const { locationX, locationY } = event.nativeEvent;
465
+ origin.value = { x: locationX, y: locationY };
466
+ pressCount.value += 1;
467
+ onPressIn?.(event);
468
+ };
469
+ const handleLayout = (event) => {
470
+ const { width, height } = event.nativeEvent.layout;
471
+ size.value = { width, height };
472
+ onLayout?.(event);
473
+ };
474
+ const clip = feedbackVariant === "scale-ripple" ? { overflow: "hidden" } : null;
475
+ const Root = asChild ? AnimatedSlot : AnimatedPressable;
476
+ return /* @__PURE__ */ React.createElement(
477
+ Root,
478
+ {
479
+ ref,
480
+ style: [clip, style, animatedStyle],
481
+ disabled: isDisabled,
482
+ onPressIn: handlePressIn,
483
+ onLayout: handleLayout,
484
+ ...rest
485
+ },
486
+ /* @__PURE__ */ React.createElement(FeedbackProvider, { value: context }, /* @__PURE__ */ React.createElement(DefaultOverlay, { variant: feedbackVariant }), children)
487
+ );
488
+ });
489
+ function DefaultOverlay({ variant }) {
490
+ if (variant === "scale-highlight") return /* @__PURE__ */ React.createElement(PressableFeedbackHighlight, null);
491
+ if (variant === "scale-ripple") return /* @__PURE__ */ React.createElement(PressableFeedbackRipple, null);
492
+ return null;
493
+ }
494
+
495
+ // src/system/pressable-feedback/index.ts
496
+ var PressableFeedback3 = Object.assign(PressableFeedback, {
497
+ Highlight: PressableFeedbackHighlight,
498
+ Ripple: PressableFeedbackRipple
499
+ });
500
+
501
+ // src/system/recipe/resolve-tint.ts
502
+ var TINT_SLICE_BY_SUFFIX = [
503
+ [/SoftForeground$/, "softForeground"],
504
+ [/SoftPressed$/, "softPressed"],
505
+ [/Soft$/, "soft"],
506
+ [/Foreground$/, "foreground"],
507
+ [/Pressed$/, "pressed"]
508
+ ];
509
+ function tintSliceFor(token) {
510
+ for (const [suffix, slice] of TINT_SLICE_BY_SUFFIX) {
511
+ if (suffix.test(token)) return slice;
512
+ }
513
+ return "base";
514
+ }
515
+ function resolveTint(tokens, color, theme) {
516
+ const tint = deriveTint(color, theme);
517
+ const colors = {};
518
+ for (const [role, token] of Object.entries(tokens ?? {})) {
519
+ colors[role] = tint[tintSliceFor(token)];
520
+ }
521
+ return colors;
522
+ }
523
+
524
+ // src/system/recipe/style-cache.ts
525
+ import { StyleSheet as StyleSheet3 } from "react-native";
526
+
527
+ // src/system/recipe/variant-map.ts
528
+ var STATE_ORDER = ["focused", "pressed", "disabled"];
529
+ function resolveSelection(defaultVariants, selection) {
530
+ const resolved = { ...defaultVariants };
531
+ for (const [axis, value] of Object.entries(selection ?? {})) {
532
+ if (value !== void 0) resolved[axis] = value;
533
+ }
534
+ return resolved;
535
+ }
536
+ function resolveVariantColors(tokens, theme) {
537
+ const colors = {};
538
+ for (const [role, token] of entriesOf(tokens)) {
539
+ const value = theme.colors[token];
540
+ if (value === void 0) {
541
+ throw new Error(
542
+ `XAUI: the recipe names "${token}" for its "${role}" role, but the theme has no such colour token. Check the spelling against XAUIColors.`
543
+ );
544
+ }
545
+ colors[role] = value;
546
+ }
547
+ return colors;
548
+ }
549
+ function activeStateFns(states, active) {
550
+ const fns = [];
551
+ for (const state of STATE_ORDER) {
552
+ const fn = active[state] ? states?.[state] : void 0;
553
+ if (fn) fns.push(fn);
554
+ }
555
+ return fns;
556
+ }
557
+ function collectStyleFns(config, selection, states) {
558
+ const fns = [];
559
+ if (config.base) fns.push(config.base);
560
+ if (config.paint) fns.push(config.paint);
561
+ for (const [axis, values] of Object.entries(config.variants ?? {})) {
562
+ const value = selection[axis];
563
+ const fn = value === void 0 ? void 0 : values[value];
564
+ if (fn) fns.push(fn);
565
+ }
566
+ for (const compound of config.compoundVariants ?? []) {
567
+ if (appliesTo(compound.when, selection)) fns.push(compound.style);
568
+ }
569
+ return [...fns, ...activeStateFns(config.states, states)];
570
+ }
571
+ function appliesTo(when, selection) {
572
+ return Object.entries(when).every(([axis, value]) => selection[axis] === value);
573
+ }
574
+ function entriesOf(tokens) {
575
+ return Object.entries(tokens ?? {});
576
+ }
577
+
578
+ // src/system/recipe/style-cache.ts
579
+ function createStyleCache(slots) {
580
+ const entries = /* @__PURE__ */ new Map();
581
+ return {
582
+ read(key, build) {
583
+ const hit = entries.get(key);
584
+ if (hit) return hit;
585
+ const built = build();
586
+ const complete = {};
587
+ for (const slot of slots) complete[slot] = built[slot] ?? {};
588
+ const created = StyleSheet3.create(complete);
589
+ entries.set(key, created);
590
+ return created;
591
+ },
592
+ get size() {
593
+ return entries.size;
594
+ },
595
+ clear() {
596
+ entries.clear();
597
+ }
598
+ };
599
+ }
600
+ function cacheKey(theme, selection, states) {
601
+ const axes = Object.keys(selection).sort().map((axis) => `${axis}:${selection[axis] ?? "-"}`).join("|");
602
+ const active = STATE_ORDER.filter((state) => states[state]).join(",");
603
+ return `${theme.id}|${theme.mode}|${axes}|${active}`;
604
+ }
605
+
606
+ // src/system/recipe/create-recipe.ts
607
+ function createRecipe(config) {
608
+ const cache = createStyleCache(config.slots);
609
+ const tokensFor = (variant) => variant === void 0 ? void 0 : config.variantTokens?.[variant];
610
+ return {
611
+ slots: config.slots,
612
+ resolve({ theme, selection, states = {} }) {
613
+ const resolved = resolveSelection(config.defaultVariants, selection);
614
+ return cache.read(cacheKey(theme, resolved, states), () => {
615
+ const colors = resolveVariantColors(tokensFor(resolved.variant), theme);
616
+ return apply(collectStyleFns(config, resolved, states), theme, colors);
617
+ });
618
+ },
619
+ tint({ theme, color, selection, states = {} }) {
620
+ if (!config.paint) return {};
621
+ const resolved = resolveSelection(config.defaultVariants, selection);
622
+ const tokens = tokensFor(resolved.variant);
623
+ if (!tokens) return {};
624
+ const colors = resolveTint(tokens, color, theme);
625
+ const fns = [config.paint, ...activeStateFns(config.states, states)];
626
+ return apply(fns, theme, colors);
627
+ }
628
+ };
629
+ }
630
+ function apply(fns, theme, colors) {
631
+ const merged = {};
632
+ for (const fn of fns) {
633
+ const produced = fn(theme, colors);
634
+ for (const slot of Object.keys(produced)) {
635
+ const style = produced[slot];
636
+ if (!style) continue;
637
+ const previous = merged[slot];
638
+ merged[slot] = previous ? { ...previous, ...style } : style;
639
+ }
640
+ }
641
+ return merged;
642
+ }
643
+
644
+ // src/system/slot/children-to-string.ts
645
+ import { isValidElement as isValidElement2 } from "react";
646
+ function childrenToString(children) {
647
+ const text = stringify(children);
648
+ return text === null || text === "" ? null : text;
649
+ }
650
+ function stringify(node) {
651
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
652
+ if (typeof node === "string") return node;
653
+ if (typeof node === "number") return String(node);
654
+ if (isValidElement2(node)) return null;
655
+ if (Array.isArray(node)) {
656
+ let text = "";
657
+ for (const child of node) {
658
+ const part = stringify(child);
659
+ if (part === null) return null;
660
+ text += part;
661
+ }
662
+ return text;
663
+ }
664
+ return null;
665
+ }
666
+
667
+ export {
668
+ PortalContext,
669
+ Portal,
670
+ PortalHost,
671
+ createSlotContext,
672
+ useFeedback,
673
+ PRESS_SCALE,
674
+ PRESS_DURATION,
675
+ RELEASE_DURATION,
676
+ HIGHLIGHT_OPACITY,
677
+ RIPPLE_OPACITY,
678
+ RIPPLE_DURATION,
679
+ RIPPLE_COVERAGE,
680
+ resolveAnimation,
681
+ resolveSlotAnimation,
682
+ mergeRefs,
683
+ mergeProps,
684
+ Slot,
685
+ PressableFeedback3 as PressableFeedback,
686
+ createRecipe,
687
+ childrenToString
688
+ };