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

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