@xaui/native 0.0.2
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/README.md +105 -0
- package/dist/button/index.cjs +672 -0
- package/dist/button/index.d.cts +90 -0
- package/dist/button/index.d.ts +90 -0
- package/dist/button/index.js +264 -0
- package/dist/chunk-6ITFLLAM.js +375 -0
- package/dist/chunk-SHT66VET.js +60 -0
- package/dist/core/index.cjs +99 -0
- package/dist/core/index.d.cts +19 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.js +12 -0
- package/dist/index.cjs +417 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/indicator/index.cjs +417 -0
- package/dist/indicator/index.d.cts +47 -0
- package/dist/indicator/index.d.ts +47 -0
- package/dist/indicator/index.js +7 -0
- package/dist/progress/index.cjs +266 -0
- package/dist/progress/index.d.cts +47 -0
- package/dist/progress/index.d.ts +47 -0
- package/dist/progress/index.js +216 -0
- package/dist/theme-qvIXI4kF.d.cts +3 -0
- package/dist/theme-qvIXI4kF.d.ts +3 -0
- package/package.json +80 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useXUITheme
|
|
3
|
+
} from "./chunk-SHT66VET.js";
|
|
4
|
+
|
|
5
|
+
// src/components/indicator/indicator.tsx
|
|
6
|
+
import React3 from "react";
|
|
7
|
+
import { View as View3 } from "react-native";
|
|
8
|
+
|
|
9
|
+
// src/components/indicator/circular-activity-indicator.tsx
|
|
10
|
+
import React, { useEffect, useRef } from "react";
|
|
11
|
+
import { Animated, Easing, Platform, View } from "react-native";
|
|
12
|
+
|
|
13
|
+
// src/components/indicator/indicator.style.ts
|
|
14
|
+
import { StyleSheet } from "react-native";
|
|
15
|
+
var styles = StyleSheet.create({
|
|
16
|
+
container: {
|
|
17
|
+
width: "100%",
|
|
18
|
+
justifyContent: "center"
|
|
19
|
+
},
|
|
20
|
+
layer: {
|
|
21
|
+
...StyleSheet.absoluteFillObject,
|
|
22
|
+
justifyContent: "center",
|
|
23
|
+
alignItems: "center"
|
|
24
|
+
},
|
|
25
|
+
track: {
|
|
26
|
+
width: "100%",
|
|
27
|
+
overflow: "hidden"
|
|
28
|
+
},
|
|
29
|
+
progress: {
|
|
30
|
+
height: "100%"
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// src/components/indicator/circular-activity-indicator.tsx
|
|
35
|
+
import { getSafeThemeColor } from "@xaui/core";
|
|
36
|
+
var DURATION = 1800;
|
|
37
|
+
var CircularActivityIndicator = ({
|
|
38
|
+
size = 40,
|
|
39
|
+
themeColor = "primary",
|
|
40
|
+
color,
|
|
41
|
+
backgroundColor,
|
|
42
|
+
disableAnimation = false,
|
|
43
|
+
showTrack = true
|
|
44
|
+
}) => {
|
|
45
|
+
const theme = useXUITheme();
|
|
46
|
+
const { current: timer } = useRef(new Animated.Value(0));
|
|
47
|
+
const rotation = useRef(void 0);
|
|
48
|
+
const startRotation = React.useCallback(() => {
|
|
49
|
+
if (rotation.current) {
|
|
50
|
+
timer.setValue(0);
|
|
51
|
+
Animated.loop(rotation.current).start();
|
|
52
|
+
}
|
|
53
|
+
}, [timer]);
|
|
54
|
+
const stopRotation = () => {
|
|
55
|
+
if (rotation.current) rotation.current.stop();
|
|
56
|
+
};
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (rotation.current === void 0) {
|
|
59
|
+
rotation.current = Animated.timing(timer, {
|
|
60
|
+
duration: DURATION,
|
|
61
|
+
easing: Easing.linear,
|
|
62
|
+
useNativeDriver: Platform.OS !== "web",
|
|
63
|
+
toValue: 1
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!disableAnimation) startRotation();
|
|
67
|
+
else stopRotation();
|
|
68
|
+
}, [disableAnimation, startRotation, timer]);
|
|
69
|
+
const safeThemeColor = getSafeThemeColor(themeColor);
|
|
70
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
71
|
+
const mainColor = color || colorScheme.main;
|
|
72
|
+
const trackColor = showTrack ? backgroundColor ?? colorScheme.background : "transparent";
|
|
73
|
+
const strokeWidth = size * 0.1;
|
|
74
|
+
const frames = 60 * DURATION / 1e3;
|
|
75
|
+
const easing = Easing.bezier(0.4, 0, 0.7, 1);
|
|
76
|
+
const containerStyle = {
|
|
77
|
+
width: size,
|
|
78
|
+
height: size / 2,
|
|
79
|
+
overflow: "hidden"
|
|
80
|
+
};
|
|
81
|
+
return /* @__PURE__ */ React.createElement(View, { style: [styles.container, { width: size, height: size }] }, /* @__PURE__ */ React.createElement(
|
|
82
|
+
View,
|
|
83
|
+
{
|
|
84
|
+
style: {
|
|
85
|
+
width: size,
|
|
86
|
+
height: size,
|
|
87
|
+
borderRadius: size / 2,
|
|
88
|
+
borderWidth: strokeWidth,
|
|
89
|
+
borderColor: trackColor
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
), /* @__PURE__ */ React.createElement(
|
|
93
|
+
View,
|
|
94
|
+
{
|
|
95
|
+
style: {
|
|
96
|
+
width: size,
|
|
97
|
+
height: size,
|
|
98
|
+
position: "absolute"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[0, 1].map((index) => {
|
|
102
|
+
const inputRange = Array.from(
|
|
103
|
+
new Array(frames),
|
|
104
|
+
(_, frameIndex) => frameIndex / (frames - 1)
|
|
105
|
+
);
|
|
106
|
+
const outputRange = Array.from(new Array(frames), (_, frameIndex) => {
|
|
107
|
+
let progress = 2 * frameIndex / (frames - 1);
|
|
108
|
+
const rotationValue = index ? +(360 - 15) : -(180 - 15);
|
|
109
|
+
if (progress > 1) {
|
|
110
|
+
progress = 2 - progress;
|
|
111
|
+
}
|
|
112
|
+
const direction = index ? -1 : 1;
|
|
113
|
+
return `${direction * (180 - 30) * easing(progress) + rotationValue}deg`;
|
|
114
|
+
});
|
|
115
|
+
const layerStyle = {
|
|
116
|
+
width: size,
|
|
117
|
+
height: size,
|
|
118
|
+
transform: [
|
|
119
|
+
{
|
|
120
|
+
rotate: timer.interpolate({
|
|
121
|
+
inputRange: [0, 1],
|
|
122
|
+
outputRange: [`${0 + 30 + 15}deg`, `${2 * 360 + 30 + 15}deg`]
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
};
|
|
127
|
+
const viewportStyle = {
|
|
128
|
+
width: size,
|
|
129
|
+
height: size,
|
|
130
|
+
transform: [
|
|
131
|
+
{ translateY: index ? -size / 2 : 0 },
|
|
132
|
+
{
|
|
133
|
+
rotate: timer.interpolate({ inputRange, outputRange })
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
const offsetStyle = index ? { top: size / 2 } : null;
|
|
138
|
+
const lineStyle = {
|
|
139
|
+
width: size,
|
|
140
|
+
height: size,
|
|
141
|
+
borderColor: mainColor,
|
|
142
|
+
borderWidth: strokeWidth,
|
|
143
|
+
borderRadius: size / 2
|
|
144
|
+
};
|
|
145
|
+
return /* @__PURE__ */ React.createElement(Animated.View, { key: index, style: [styles.layer] }, /* @__PURE__ */ React.createElement(Animated.View, { style: layerStyle }, /* @__PURE__ */ React.createElement(Animated.View, { style: [containerStyle, offsetStyle], collapsable: false }, /* @__PURE__ */ React.createElement(Animated.View, { style: viewportStyle }, /* @__PURE__ */ React.createElement(Animated.View, { style: containerStyle, collapsable: false }, /* @__PURE__ */ React.createElement(Animated.View, { style: lineStyle }))))));
|
|
146
|
+
})
|
|
147
|
+
));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/components/indicator/linear-activity-indicator.tsx
|
|
151
|
+
import React2 from "react";
|
|
152
|
+
import { StyleSheet as StyleSheet2, View as View2 } from "react-native";
|
|
153
|
+
import Animated2, { useAnimatedStyle } from "react-native-reanimated";
|
|
154
|
+
|
|
155
|
+
// src/components/indicator/indicator.hook.ts
|
|
156
|
+
import { useEffect as useEffect2 } from "react";
|
|
157
|
+
import {
|
|
158
|
+
Easing as Easing2,
|
|
159
|
+
cancelAnimation,
|
|
160
|
+
useSharedValue,
|
|
161
|
+
withRepeat,
|
|
162
|
+
withSequence,
|
|
163
|
+
withTiming
|
|
164
|
+
} from "react-native-reanimated";
|
|
165
|
+
var useLinearActivityIndicatorAnimation = (disableAnimation) => {
|
|
166
|
+
const primaryTranslateX = useSharedValue(0);
|
|
167
|
+
const primaryScaleX = useSharedValue(0.08);
|
|
168
|
+
const secondaryTranslateX = useSharedValue(0);
|
|
169
|
+
const secondaryScaleX = useSharedValue(0.08);
|
|
170
|
+
useEffect2(() => {
|
|
171
|
+
if (disableAnimation) {
|
|
172
|
+
cancelAnimation(primaryTranslateX);
|
|
173
|
+
cancelAnimation(primaryScaleX);
|
|
174
|
+
cancelAnimation(secondaryTranslateX);
|
|
175
|
+
cancelAnimation(secondaryScaleX);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
primaryTranslateX.value = withRepeat(
|
|
179
|
+
withSequence(
|
|
180
|
+
withTiming(0, { duration: 0 }),
|
|
181
|
+
withTiming(0, { duration: 400, easing: Easing2.linear }),
|
|
182
|
+
withTiming(0.836714, {
|
|
183
|
+
duration: 783,
|
|
184
|
+
easing: Easing2.bezier(0.5, 0, 0.701732, 0.495819)
|
|
185
|
+
}),
|
|
186
|
+
withTiming(2.00611, {
|
|
187
|
+
duration: 817,
|
|
188
|
+
easing: Easing2.bezier(0.302435, 0.381352, 0.55, 0.956352)
|
|
189
|
+
})
|
|
190
|
+
),
|
|
191
|
+
-1,
|
|
192
|
+
false
|
|
193
|
+
);
|
|
194
|
+
primaryScaleX.value = withRepeat(
|
|
195
|
+
withSequence(
|
|
196
|
+
withTiming(0.08, { duration: 0 }),
|
|
197
|
+
withTiming(0.08, { duration: 733, easing: Easing2.linear }),
|
|
198
|
+
withTiming(0.661479, {
|
|
199
|
+
duration: 650,
|
|
200
|
+
easing: Easing2.bezier(0.334731, 0.12482, 0.785844, 1)
|
|
201
|
+
}),
|
|
202
|
+
withTiming(0.08, {
|
|
203
|
+
duration: 617,
|
|
204
|
+
easing: Easing2.bezier(0.06, 0.11, 0.6, 1)
|
|
205
|
+
})
|
|
206
|
+
),
|
|
207
|
+
-1,
|
|
208
|
+
false
|
|
209
|
+
);
|
|
210
|
+
secondaryTranslateX.value = withRepeat(
|
|
211
|
+
withSequence(
|
|
212
|
+
withTiming(0, { duration: 0 }),
|
|
213
|
+
withTiming(0.376519, {
|
|
214
|
+
duration: 500,
|
|
215
|
+
easing: Easing2.bezier(0.15, 0, 0.515058, 0.409685)
|
|
216
|
+
}),
|
|
217
|
+
withTiming(0.843862, {
|
|
218
|
+
duration: 467,
|
|
219
|
+
easing: Easing2.bezier(0.31033, 0.284058, 0.8, 0.733712)
|
|
220
|
+
}),
|
|
221
|
+
withTiming(1.60278, {
|
|
222
|
+
duration: 1033,
|
|
223
|
+
easing: Easing2.bezier(0.4, 0.627035, 0.6, 0.902026)
|
|
224
|
+
})
|
|
225
|
+
),
|
|
226
|
+
-1,
|
|
227
|
+
false
|
|
228
|
+
);
|
|
229
|
+
secondaryScaleX.value = withRepeat(
|
|
230
|
+
withSequence(
|
|
231
|
+
withTiming(0.08, { duration: 0 }),
|
|
232
|
+
withTiming(0.457104, {
|
|
233
|
+
duration: 383,
|
|
234
|
+
easing: Easing2.bezier(0.205028, 0.057051, 0.57661, 0.453971)
|
|
235
|
+
}),
|
|
236
|
+
withTiming(0.72796, {
|
|
237
|
+
duration: 500,
|
|
238
|
+
easing: Easing2.bezier(0.152313, 0.196432, 0.648374, 1.00432)
|
|
239
|
+
}),
|
|
240
|
+
withTiming(0.08, {
|
|
241
|
+
duration: 1117,
|
|
242
|
+
easing: Easing2.bezier(0.257759, -3163e-6, 0.211762, 1.38179)
|
|
243
|
+
})
|
|
244
|
+
),
|
|
245
|
+
-1,
|
|
246
|
+
false
|
|
247
|
+
);
|
|
248
|
+
return () => {
|
|
249
|
+
cancelAnimation(primaryTranslateX);
|
|
250
|
+
cancelAnimation(primaryScaleX);
|
|
251
|
+
cancelAnimation(secondaryTranslateX);
|
|
252
|
+
cancelAnimation(secondaryScaleX);
|
|
253
|
+
};
|
|
254
|
+
}, [disableAnimation]);
|
|
255
|
+
return {
|
|
256
|
+
primaryTranslateX,
|
|
257
|
+
primaryScaleX,
|
|
258
|
+
secondaryTranslateX,
|
|
259
|
+
secondaryScaleX
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/components/indicator/linear-activity-indicator.tsx
|
|
264
|
+
var LinearActivityIndicator = ({
|
|
265
|
+
size = 4,
|
|
266
|
+
themeColor = "primary",
|
|
267
|
+
color,
|
|
268
|
+
backgroundColor,
|
|
269
|
+
disableAnimation = false,
|
|
270
|
+
borderRadius = 0,
|
|
271
|
+
showTrack = true
|
|
272
|
+
}) => {
|
|
273
|
+
const theme = useXUITheme();
|
|
274
|
+
const { primaryTranslateX, primaryScaleX, secondaryTranslateX, secondaryScaleX } = useLinearActivityIndicatorAnimation(disableAnimation);
|
|
275
|
+
const colorScheme = theme.colors[themeColor];
|
|
276
|
+
const mainColor = color || colorScheme.main;
|
|
277
|
+
const trackColor = showTrack ? backgroundColor ?? colorScheme.background : "transparent";
|
|
278
|
+
const barStyle = {
|
|
279
|
+
...StyleSheet2.absoluteFillObject,
|
|
280
|
+
backgroundColor: mainColor,
|
|
281
|
+
borderRadius
|
|
282
|
+
};
|
|
283
|
+
const primaryStyle = useAnimatedStyle(() => ({
|
|
284
|
+
transform: [
|
|
285
|
+
{ translateX: `${(primaryTranslateX.value - 1.45167) * 100}%` },
|
|
286
|
+
{ scaleX: primaryScaleX.value }
|
|
287
|
+
]
|
|
288
|
+
}));
|
|
289
|
+
const secondaryStyle = useAnimatedStyle(() => ({
|
|
290
|
+
transform: [
|
|
291
|
+
{ translateX: `${(secondaryTranslateX.value - 0.548889) * 100}%` },
|
|
292
|
+
{ scaleX: secondaryScaleX.value }
|
|
293
|
+
]
|
|
294
|
+
}));
|
|
295
|
+
return /* @__PURE__ */ React2.createElement(
|
|
296
|
+
View2,
|
|
297
|
+
{
|
|
298
|
+
style: {
|
|
299
|
+
height: size,
|
|
300
|
+
width: "100%",
|
|
301
|
+
borderRadius,
|
|
302
|
+
backgroundColor: trackColor,
|
|
303
|
+
overflow: "hidden"
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
/* @__PURE__ */ React2.createElement(Animated2.View, { style: [barStyle, primaryStyle] }),
|
|
307
|
+
/* @__PURE__ */ React2.createElement(Animated2.View, { style: [barStyle, secondaryStyle] })
|
|
308
|
+
);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/components/indicator/indicator.tsx
|
|
312
|
+
var ActivityIndicator = (props) => {
|
|
313
|
+
const {
|
|
314
|
+
variant = "circular",
|
|
315
|
+
themeColor = "primary",
|
|
316
|
+
color,
|
|
317
|
+
backgroundColor,
|
|
318
|
+
size,
|
|
319
|
+
disableAnimation = false,
|
|
320
|
+
borderRadius,
|
|
321
|
+
showTrack
|
|
322
|
+
} = props;
|
|
323
|
+
const theme = useXUITheme();
|
|
324
|
+
const colorScheme = theme.colors[themeColor];
|
|
325
|
+
const mainColor = color ?? colorScheme.main;
|
|
326
|
+
const trackColor = backgroundColor ?? (showTrack ? colorScheme.background : "transparent");
|
|
327
|
+
if (variant === "circular") {
|
|
328
|
+
const circleSize = size ?? 40;
|
|
329
|
+
return /* @__PURE__ */ React3.createElement(
|
|
330
|
+
View3,
|
|
331
|
+
{
|
|
332
|
+
style: [styles.container, { width: circleSize, height: circleSize }],
|
|
333
|
+
accessible: true,
|
|
334
|
+
accessibilityRole: "progressbar",
|
|
335
|
+
accessibilityLabel: "Loading"
|
|
336
|
+
},
|
|
337
|
+
/* @__PURE__ */ React3.createElement(
|
|
338
|
+
CircularActivityIndicator,
|
|
339
|
+
{
|
|
340
|
+
size: circleSize,
|
|
341
|
+
themeColor,
|
|
342
|
+
color: mainColor,
|
|
343
|
+
backgroundColor: trackColor,
|
|
344
|
+
disableAnimation
|
|
345
|
+
}
|
|
346
|
+
)
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
const linearSize = size ?? 4;
|
|
350
|
+
return /* @__PURE__ */ React3.createElement(
|
|
351
|
+
View3,
|
|
352
|
+
{
|
|
353
|
+
style: styles.container,
|
|
354
|
+
accessible: true,
|
|
355
|
+
accessibilityRole: "progressbar",
|
|
356
|
+
accessibilityLabel: "Loading"
|
|
357
|
+
},
|
|
358
|
+
/* @__PURE__ */ React3.createElement(
|
|
359
|
+
LinearActivityIndicator,
|
|
360
|
+
{
|
|
361
|
+
size: linearSize,
|
|
362
|
+
themeColor,
|
|
363
|
+
color: mainColor,
|
|
364
|
+
backgroundColor: trackColor,
|
|
365
|
+
disableAnimation,
|
|
366
|
+
borderRadius,
|
|
367
|
+
showTrack
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export {
|
|
374
|
+
ActivityIndicator
|
|
375
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/core/theme-context.tsx
|
|
2
|
+
import React, { createContext } from "react";
|
|
3
|
+
import { useColorScheme } from "react-native";
|
|
4
|
+
import { defaultTheme } from "@xaui/core/theme";
|
|
5
|
+
var XUIThemeContext = createContext(null);
|
|
6
|
+
function XUIProvider({
|
|
7
|
+
children,
|
|
8
|
+
theme: lightTheme,
|
|
9
|
+
darkTheme
|
|
10
|
+
}) {
|
|
11
|
+
const colorScheme = useColorScheme() ?? "light";
|
|
12
|
+
const theme = React.useMemo(() => {
|
|
13
|
+
if (!darkTheme && !lightTheme) return defaultTheme;
|
|
14
|
+
const activeTheme = colorScheme === "dark" && darkTheme ? darkTheme : lightTheme;
|
|
15
|
+
if (!activeTheme) return defaultTheme;
|
|
16
|
+
return {
|
|
17
|
+
...defaultTheme,
|
|
18
|
+
...activeTheme,
|
|
19
|
+
colors: {
|
|
20
|
+
...defaultTheme.colors,
|
|
21
|
+
...activeTheme.colors
|
|
22
|
+
},
|
|
23
|
+
fontFamilies: {
|
|
24
|
+
...defaultTheme.fontFamilies,
|
|
25
|
+
...activeTheme.fontFamilies
|
|
26
|
+
},
|
|
27
|
+
fontSizes: {
|
|
28
|
+
...defaultTheme.fontSizes,
|
|
29
|
+
...activeTheme.fontSizes
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}, [lightTheme, darkTheme, colorScheme]);
|
|
33
|
+
return /* @__PURE__ */ React.createElement(XUIThemeContext.Provider, { value: theme }, children);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/core/theme-hooks.ts
|
|
37
|
+
import { useContext } from "react";
|
|
38
|
+
import { useColorScheme as useColorScheme2 } from "react-native";
|
|
39
|
+
function useColorMode() {
|
|
40
|
+
const nativeScheme = useColorScheme2();
|
|
41
|
+
return nativeScheme ?? "light";
|
|
42
|
+
}
|
|
43
|
+
function useXUITheme() {
|
|
44
|
+
const theme = useContext(XUIThemeContext);
|
|
45
|
+
if (!theme) {
|
|
46
|
+
throw new Error("useXUITheme must be used within XUIProvider");
|
|
47
|
+
}
|
|
48
|
+
return theme;
|
|
49
|
+
}
|
|
50
|
+
function useXUIColors() {
|
|
51
|
+
const theme = useXUITheme();
|
|
52
|
+
return theme.colors;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
XUIProvider,
|
|
57
|
+
useColorMode,
|
|
58
|
+
useXUITheme,
|
|
59
|
+
useXUIColors
|
|
60
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/core/index.ts
|
|
31
|
+
var core_exports = {};
|
|
32
|
+
__export(core_exports, {
|
|
33
|
+
XUIProvider: () => XUIProvider,
|
|
34
|
+
useColorMode: () => useColorMode,
|
|
35
|
+
useXUIColors: () => useXUIColors,
|
|
36
|
+
useXUITheme: () => useXUITheme
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(core_exports);
|
|
39
|
+
|
|
40
|
+
// src/core/theme-context.tsx
|
|
41
|
+
var import_react = __toESM(require("react"), 1);
|
|
42
|
+
var import_react_native = require("react-native");
|
|
43
|
+
var import_theme = require("@xaui/core/theme");
|
|
44
|
+
var XUIThemeContext = (0, import_react.createContext)(null);
|
|
45
|
+
function XUIProvider({
|
|
46
|
+
children,
|
|
47
|
+
theme: lightTheme,
|
|
48
|
+
darkTheme
|
|
49
|
+
}) {
|
|
50
|
+
const colorScheme = (0, import_react_native.useColorScheme)() ?? "light";
|
|
51
|
+
const theme = import_react.default.useMemo(() => {
|
|
52
|
+
if (!darkTheme && !lightTheme) return import_theme.defaultTheme;
|
|
53
|
+
const activeTheme = colorScheme === "dark" && darkTheme ? darkTheme : lightTheme;
|
|
54
|
+
if (!activeTheme) return import_theme.defaultTheme;
|
|
55
|
+
return {
|
|
56
|
+
...import_theme.defaultTheme,
|
|
57
|
+
...activeTheme,
|
|
58
|
+
colors: {
|
|
59
|
+
...import_theme.defaultTheme.colors,
|
|
60
|
+
...activeTheme.colors
|
|
61
|
+
},
|
|
62
|
+
fontFamilies: {
|
|
63
|
+
...import_theme.defaultTheme.fontFamilies,
|
|
64
|
+
...activeTheme.fontFamilies
|
|
65
|
+
},
|
|
66
|
+
fontSizes: {
|
|
67
|
+
...import_theme.defaultTheme.fontSizes,
|
|
68
|
+
...activeTheme.fontSizes
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}, [lightTheme, darkTheme, colorScheme]);
|
|
72
|
+
return /* @__PURE__ */ import_react.default.createElement(XUIThemeContext.Provider, { value: theme }, children);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/core/theme-hooks.ts
|
|
76
|
+
var import_react2 = require("react");
|
|
77
|
+
var import_react_native2 = require("react-native");
|
|
78
|
+
function useColorMode() {
|
|
79
|
+
const nativeScheme = (0, import_react_native2.useColorScheme)();
|
|
80
|
+
return nativeScheme ?? "light";
|
|
81
|
+
}
|
|
82
|
+
function useXUITheme() {
|
|
83
|
+
const theme = (0, import_react2.useContext)(XUIThemeContext);
|
|
84
|
+
if (!theme) {
|
|
85
|
+
throw new Error("useXUITheme must be used within XUIProvider");
|
|
86
|
+
}
|
|
87
|
+
return theme;
|
|
88
|
+
}
|
|
89
|
+
function useXUIColors() {
|
|
90
|
+
const theme = useXUITheme();
|
|
91
|
+
return theme.colors;
|
|
92
|
+
}
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
XUIProvider,
|
|
96
|
+
useColorMode,
|
|
97
|
+
useXUIColors,
|
|
98
|
+
useXUITheme
|
|
99
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { XUITheme } from '@xaui/core/theme';
|
|
3
|
+
|
|
4
|
+
type DeepPartial<T> = {
|
|
5
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
6
|
+
};
|
|
7
|
+
interface XUIProviderProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
theme?: DeepPartial<XUITheme>;
|
|
10
|
+
darkTheme?: DeepPartial<XUITheme>;
|
|
11
|
+
}
|
|
12
|
+
declare function XUIProvider({ children, theme: lightTheme, darkTheme, }: XUIProviderProps): React.JSX.Element;
|
|
13
|
+
|
|
14
|
+
type ColorMode = 'light' | 'dark';
|
|
15
|
+
declare function useColorMode(): ColorMode;
|
|
16
|
+
declare function useXUITheme(): XUITheme;
|
|
17
|
+
declare function useXUIColors(): XUITheme['colors'];
|
|
18
|
+
|
|
19
|
+
export { XUIProvider, useColorMode, useXUIColors, useXUITheme };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { XUITheme } from '@xaui/core/theme';
|
|
3
|
+
|
|
4
|
+
type DeepPartial<T> = {
|
|
5
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
6
|
+
};
|
|
7
|
+
interface XUIProviderProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
theme?: DeepPartial<XUITheme>;
|
|
10
|
+
darkTheme?: DeepPartial<XUITheme>;
|
|
11
|
+
}
|
|
12
|
+
declare function XUIProvider({ children, theme: lightTheme, darkTheme, }: XUIProviderProps): React.JSX.Element;
|
|
13
|
+
|
|
14
|
+
type ColorMode = 'light' | 'dark';
|
|
15
|
+
declare function useColorMode(): ColorMode;
|
|
16
|
+
declare function useXUITheme(): XUITheme;
|
|
17
|
+
declare function useXUIColors(): XUITheme['colors'];
|
|
18
|
+
|
|
19
|
+
export { XUIProvider, useColorMode, useXUIColors, useXUITheme };
|