@xaui/native 0.9.1-alpha.0 → 0.9.1-alpha.10

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