@xaui/native 0.9.1-alpha.1 → 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.
- package/dist/{chunk-NHPQQQ7P.cjs → chunk-2FEDC7U5.cjs} +34 -57
- package/dist/{chunk-M7P46XKI.cjs → chunk-3QBT3Q65.cjs} +27 -2
- package/dist/chunk-3TIDEII6.js +57 -0
- package/dist/chunk-66OVPWF4.js +716 -0
- package/dist/chunk-7D262JCJ.cjs +716 -0
- package/dist/{chunk-PBVPOX7D.js → chunk-7XGOXTGT.js} +5 -28
- package/dist/chunk-EQGTD5F6.js +353 -0
- package/dist/chunk-ERCOAOO6.cjs +353 -0
- package/dist/chunk-LMUPNKPH.cjs +57 -0
- package/dist/{chunk-RBNCR5KB.js → chunk-X2K2FX3W.js} +25 -0
- package/dist/components/button/index.cjs +12 -0
- package/dist/components/button/index.d.cts +192 -0
- package/dist/components/button/index.d.ts +192 -0
- package/dist/components/button/index.js +12 -0
- package/dist/create-recipe-BjSP0zL_.d.cts +210 -0
- package/dist/create-recipe-Dn9kj5Rs.d.ts +210 -0
- package/dist/index.cjs +116 -5
- package/dist/index.d.cts +73 -4
- package/dist/index.d.ts +73 -4
- package/dist/index.js +119 -8
- package/dist/system/index.cjs +49 -3
- package/dist/system/index.d.cts +251 -72
- package/dist/system/index.d.ts +251 -72
- package/dist/system/index.js +50 -4
- package/dist/theme/index.cjs +3 -3
- package/dist/theme/index.d.cts +3 -2
- package/dist/theme/index.d.ts +3 -2
- package/dist/theme/index.js +6 -6
- package/dist/{theme.type-B3ODSLbB.d.cts → theme.type-C9bFJKFm.d.cts} +7 -1
- package/dist/{theme.type-B3ODSLbB.d.ts → theme.type-C9bFJKFm.d.ts} +7 -1
- package/package.json +37 -11
- package/dist/chunk-KFCORXWW.cjs +0 -150
- package/dist/chunk-N357EQCZ.js +0 -150
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deriveTint,
|
|
3
|
+
useXAUITheme
|
|
4
|
+
} from "./chunk-X2K2FX3W.js";
|
|
5
|
+
|
|
6
|
+
// src/system/icon/icon-context.ts
|
|
7
|
+
import { createContext, useContext } from "react";
|
|
8
|
+
var IconContext = createContext({});
|
|
9
|
+
IconContext.displayName = "XAUI.Icon.Context";
|
|
10
|
+
function useIconContext() {
|
|
11
|
+
return useContext(IconContext);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/system/icon/icon.tsx
|
|
15
|
+
import { cloneElement, isValidElement } from "react";
|
|
16
|
+
import { Image } from "react-native";
|
|
17
|
+
import { jsx } from "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 = useXAUITheme();
|
|
28
|
+
const resolvedSize = size ?? inherited.size ?? theme.fontSizes.md;
|
|
29
|
+
const resolvedColor = color ?? inherited.color ?? theme.colors.foreground;
|
|
30
|
+
if (Component) {
|
|
31
|
+
return /* @__PURE__ */ jsx(Component, { size: resolvedSize, color: resolvedColor });
|
|
32
|
+
}
|
|
33
|
+
if (isValidElement(children)) {
|
|
34
|
+
return cloneElement(children, {
|
|
35
|
+
width: resolvedSize,
|
|
36
|
+
height: resolvedSize,
|
|
37
|
+
color: resolvedColor
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (source) {
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
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
|
+
import { isValidElement as isValidElement2 } from "react";
|
|
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 (isValidElement2(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
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
83
|
+
function createSlotContext(name) {
|
|
84
|
+
const Context = createContext2(null);
|
|
85
|
+
Context.displayName = `XAUI.${name}.Context`;
|
|
86
|
+
function useSlotContext() {
|
|
87
|
+
const value = useContext2(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
|
+
Error.captureStackTrace?.(
|
|
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
|
+
import { cloneElement as cloneElement2, forwardRef, isValidElement as isValidElement3 } from "react";
|
|
159
|
+
var Slot = forwardRef(function Slot2({ children, ...ours }, ref) {
|
|
160
|
+
if (!isValidElement3(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 cloneElement2(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 fromProps ?? fromElement;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/system/pressable-feedback/pressable-feedback-context.ts
|
|
178
|
+
import { createContext as createContext3 } from "react";
|
|
179
|
+
var [FeedbackProvider, useFeedback] = createSlotContext("PressableFeedback");
|
|
180
|
+
var DisableAllContext = createContext3(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 = animation.scale ?? true;
|
|
212
|
+
const highlight = animation.highlight ?? true;
|
|
213
|
+
const ripple = 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: override.duration ?? defaultDuration,
|
|
233
|
+
opacity: override.opacity ?? defaultOpacity
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/system/pressable-feedback/pressable-feedback.tsx
|
|
238
|
+
import { forwardRef as forwardRef2, useContext as useContext3, useEffect as useEffect2, useMemo } from "react";
|
|
239
|
+
import { Pressable } from "react-native";
|
|
240
|
+
import Animated3, {
|
|
241
|
+
useAnimatedStyle as useAnimatedStyle3,
|
|
242
|
+
useSharedValue as useSharedValue3,
|
|
243
|
+
withTiming as withTiming3
|
|
244
|
+
} from "react-native-reanimated";
|
|
245
|
+
|
|
246
|
+
// src/system/pressable-feedback/pressable-feedback-highlight.tsx
|
|
247
|
+
import { useEffect } from "react";
|
|
248
|
+
import { StyleSheet, View } from "react-native";
|
|
249
|
+
import Animated, {
|
|
250
|
+
useAnimatedStyle,
|
|
251
|
+
useSharedValue,
|
|
252
|
+
withTiming
|
|
253
|
+
} from "react-native-reanimated";
|
|
254
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
255
|
+
function PressableFeedbackHighlight({
|
|
256
|
+
style,
|
|
257
|
+
animation: override
|
|
258
|
+
}) {
|
|
259
|
+
const { isPressed, animation, progress } = useFeedback();
|
|
260
|
+
const theme = useXAUITheme();
|
|
261
|
+
const settings = resolveSlotAnimation(
|
|
262
|
+
override,
|
|
263
|
+
animation.highlight,
|
|
264
|
+
HIGHLIGHT_OPACITY
|
|
265
|
+
);
|
|
266
|
+
const base = [
|
|
267
|
+
StyleSheet.absoluteFillObject,
|
|
268
|
+
{ backgroundColor: theme.colors.foreground },
|
|
269
|
+
style
|
|
270
|
+
];
|
|
271
|
+
if (!progress || !settings.enabled) {
|
|
272
|
+
return /* @__PURE__ */ jsx2(
|
|
273
|
+
View,
|
|
274
|
+
{
|
|
275
|
+
pointerEvents: "none",
|
|
276
|
+
style: [base, { opacity: isPressed ? settings.opacity : 0 }]
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return /* @__PURE__ */ jsx2(
|
|
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 = useSharedValue(0);
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
shown.value = withTiming(isPressed ? 1 : 0, { duration });
|
|
299
|
+
}, [isPressed, shown, duration]);
|
|
300
|
+
const animatedStyle = useAnimatedStyle(
|
|
301
|
+
() => ({ opacity: shown.value * opacity }),
|
|
302
|
+
[shown, opacity]
|
|
303
|
+
);
|
|
304
|
+
return /* @__PURE__ */ jsx2(Animated.View, { pointerEvents: "none", style: [base, animatedStyle] });
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/system/pressable-feedback/pressable-feedback-ripple.tsx
|
|
308
|
+
import Animated2, {
|
|
309
|
+
interpolate,
|
|
310
|
+
useAnimatedReaction,
|
|
311
|
+
useAnimatedStyle as useAnimatedStyle2,
|
|
312
|
+
useSharedValue as useSharedValue2,
|
|
313
|
+
withTiming as withTiming2
|
|
314
|
+
} from "react-native-reanimated";
|
|
315
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
316
|
+
function PressableFeedbackRipple({
|
|
317
|
+
style,
|
|
318
|
+
animation: override
|
|
319
|
+
}) {
|
|
320
|
+
const { animation, progress, pressCount, origin, size } = useFeedback();
|
|
321
|
+
const theme = useXAUITheme();
|
|
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__ */ jsx3(
|
|
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 = useSharedValue2(0);
|
|
348
|
+
const waveB = useSharedValue2(0);
|
|
349
|
+
const fromA = useSharedValue2({ x: 0, y: 0 });
|
|
350
|
+
const fromB = useSharedValue2({ x: 0, y: 0 });
|
|
351
|
+
const useA = useSharedValue2(true);
|
|
352
|
+
useAnimatedReaction(
|
|
353
|
+
() => pressCount?.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 = origin?.value ?? { x: 0, y: 0 };
|
|
359
|
+
wave.value = 0;
|
|
360
|
+
wave.value = withTiming2(2, { duration: duration * 2 });
|
|
361
|
+
useA.value = !useA.value;
|
|
362
|
+
},
|
|
363
|
+
[pressCount, origin, duration, waveA, waveB, fromA, fromB, useA]
|
|
364
|
+
);
|
|
365
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
366
|
+
/* @__PURE__ */ jsx3(
|
|
367
|
+
RippleWave,
|
|
368
|
+
{
|
|
369
|
+
wave: waveA,
|
|
370
|
+
from: fromA,
|
|
371
|
+
size,
|
|
372
|
+
color,
|
|
373
|
+
opacity,
|
|
374
|
+
style
|
|
375
|
+
}
|
|
376
|
+
),
|
|
377
|
+
/* @__PURE__ */ jsx3(
|
|
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 = useAnimatedStyle2(() => {
|
|
399
|
+
const within = size?.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: interpolate(wave.value, [0, 1, 2], [0, opacity, 0]),
|
|
409
|
+
transform: [
|
|
410
|
+
{ translateX: at.x - radius },
|
|
411
|
+
{ translateY: at.y - radius },
|
|
412
|
+
{ scale: interpolate(wave.value, [0, 1, 2], [0, 1, 1]) }
|
|
413
|
+
]
|
|
414
|
+
};
|
|
415
|
+
}, [wave, from, size, opacity]);
|
|
416
|
+
return /* @__PURE__ */ jsx3(
|
|
417
|
+
Animated2.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
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
431
|
+
var AnimatedPressable = Animated3.createAnimatedComponent(Pressable);
|
|
432
|
+
var AnimatedSlot = Animated3.createAnimatedComponent(Slot);
|
|
433
|
+
var PressableFeedback = forwardRef2(
|
|
434
|
+
function PressableFeedback2({ animation, feedbackVariant = "scale-highlight", ...rest }, ref) {
|
|
435
|
+
const inheritedDisableAll = useContext3(DisableAllContext);
|
|
436
|
+
const resolved = resolveAnimation(animation, inheritedDisableAll);
|
|
437
|
+
const Feedback = resolved.none || feedbackVariant === "none" ? StaticFeedback : AnimatedFeedback;
|
|
438
|
+
const body2 = /* @__PURE__ */ jsx4(
|
|
439
|
+
Feedback,
|
|
440
|
+
{
|
|
441
|
+
ref,
|
|
442
|
+
animation: resolved,
|
|
443
|
+
feedbackVariant,
|
|
444
|
+
...rest
|
|
445
|
+
}
|
|
446
|
+
);
|
|
447
|
+
return resolved.disableAll ? /* @__PURE__ */ jsx4(DisableAllContext.Provider, { value: true, children: body2 }) : body2;
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
var StaticFeedback = forwardRef2(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 = useMemo(() => ({ isPressed, animation }), [isPressed, animation]);
|
|
461
|
+
const Root = asChild ? Slot : Pressable;
|
|
462
|
+
return /* @__PURE__ */ jsx4(FeedbackProvider, { value: context, children: /* @__PURE__ */ jsx4(
|
|
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 = forwardRef2(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 = useSharedValue3(0);
|
|
486
|
+
const pressCount = useSharedValue3(0);
|
|
487
|
+
const origin = useSharedValue3({ x: 0, y: 0 });
|
|
488
|
+
const size = useSharedValue3({ width: 0, height: 0 });
|
|
489
|
+
useEffect2(() => {
|
|
490
|
+
progress.value = withTiming3(isPressed ? 1 : 0, {
|
|
491
|
+
duration: isPressed ? PRESS_DURATION : RELEASE_DURATION
|
|
492
|
+
});
|
|
493
|
+
}, [isPressed, progress]);
|
|
494
|
+
const animatedStyle = useAnimatedStyle3(
|
|
495
|
+
() => animation.scale ? { transform: [{ scale: 1 - (1 - PRESS_SCALE) * progress.value }] } : {},
|
|
496
|
+
[animation.scale, progress]
|
|
497
|
+
);
|
|
498
|
+
const context = useMemo(
|
|
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
|
+
onPressIn?.(event);
|
|
507
|
+
};
|
|
508
|
+
const handleLayout = (event) => {
|
|
509
|
+
const { width, height } = event.nativeEvent.layout;
|
|
510
|
+
size.value = { width, height };
|
|
511
|
+
onLayout?.(event);
|
|
512
|
+
};
|
|
513
|
+
const Root = asChild ? AnimatedSlot : AnimatedPressable;
|
|
514
|
+
return /* @__PURE__ */ jsx4(FeedbackProvider, { value: context, children: /* @__PURE__ */ jsx4(
|
|
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__ */ jsxs2(Fragment2, { children: [
|
|
530
|
+
/* @__PURE__ */ jsx4(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__ */ jsx4(PressableFeedbackHighlight, {});
|
|
542
|
+
if (variant === "scale-ripple") return /* @__PURE__ */ jsx4(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 = deriveTint(color, theme);
|
|
568
|
+
const colors = {};
|
|
569
|
+
for (const [role, token] of Object.entries(tokens ?? {})) {
|
|
570
|
+
colors[role] = tint[tintSliceFor(token)];
|
|
571
|
+
}
|
|
572
|
+
return colors;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/system/recipe/style-cache.ts
|
|
576
|
+
import { StyleSheet as StyleSheet2 } from "react-native";
|
|
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(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] ? states?.[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(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 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(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] = built[slot] ?? {};
|
|
639
|
+
const created = StyleSheet2.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}:${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 : config.variantTokens?.[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
|
+
export {
|
|
696
|
+
IconContext,
|
|
697
|
+
useIconContext,
|
|
698
|
+
Icon,
|
|
699
|
+
childrenToString,
|
|
700
|
+
createSlotContext,
|
|
701
|
+
mergeRefs,
|
|
702
|
+
mergeProps,
|
|
703
|
+
Slot,
|
|
704
|
+
useFeedback,
|
|
705
|
+
PRESS_SCALE,
|
|
706
|
+
PRESS_DURATION,
|
|
707
|
+
RELEASE_DURATION,
|
|
708
|
+
HIGHLIGHT_OPACITY,
|
|
709
|
+
RIPPLE_OPACITY,
|
|
710
|
+
RIPPLE_DURATION,
|
|
711
|
+
RIPPLE_COVERAGE,
|
|
712
|
+
resolveAnimation,
|
|
713
|
+
resolveSlotAnimation,
|
|
714
|
+
PressableFeedback3 as PressableFeedback,
|
|
715
|
+
createRecipe
|
|
716
|
+
};
|