@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/dist/index.cjs ADDED
@@ -0,0 +1,417 @@
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/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ActivityIndicator: () => ActivityIndicator
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // src/components/indicator/indicator.tsx
38
+ var import_react6 = __toESM(require("react"), 1);
39
+ var import_react_native6 = require("react-native");
40
+
41
+ // src/core/theme-context.tsx
42
+ var import_react = __toESM(require("react"), 1);
43
+ var import_react_native = require("react-native");
44
+ var import_theme = require("@xaui/core/theme");
45
+ var XUIThemeContext = (0, import_react.createContext)(null);
46
+
47
+ // src/core/theme-hooks.ts
48
+ var import_react2 = require("react");
49
+ var import_react_native2 = require("react-native");
50
+ function useXUITheme() {
51
+ const theme = (0, import_react2.useContext)(XUIThemeContext);
52
+ if (!theme) {
53
+ throw new Error("useXUITheme must be used within XUIProvider");
54
+ }
55
+ return theme;
56
+ }
57
+
58
+ // src/components/indicator/circular-activity-indicator.tsx
59
+ var import_react3 = __toESM(require("react"), 1);
60
+ var import_react_native4 = require("react-native");
61
+
62
+ // src/components/indicator/indicator.style.ts
63
+ var import_react_native3 = require("react-native");
64
+ var styles = import_react_native3.StyleSheet.create({
65
+ container: {
66
+ width: "100%",
67
+ justifyContent: "center"
68
+ },
69
+ layer: {
70
+ ...import_react_native3.StyleSheet.absoluteFillObject,
71
+ justifyContent: "center",
72
+ alignItems: "center"
73
+ },
74
+ track: {
75
+ width: "100%",
76
+ overflow: "hidden"
77
+ },
78
+ progress: {
79
+ height: "100%"
80
+ }
81
+ });
82
+
83
+ // src/components/indicator/circular-activity-indicator.tsx
84
+ var import_core2 = require("@xaui/core");
85
+ var DURATION = 1800;
86
+ var CircularActivityIndicator = ({
87
+ size = 40,
88
+ themeColor = "primary",
89
+ color,
90
+ backgroundColor,
91
+ disableAnimation = false,
92
+ showTrack = true
93
+ }) => {
94
+ const theme = useXUITheme();
95
+ const { current: timer } = (0, import_react3.useRef)(new import_react_native4.Animated.Value(0));
96
+ const rotation = (0, import_react3.useRef)(void 0);
97
+ const startRotation = import_react3.default.useCallback(() => {
98
+ if (rotation.current) {
99
+ timer.setValue(0);
100
+ import_react_native4.Animated.loop(rotation.current).start();
101
+ }
102
+ }, [timer]);
103
+ const stopRotation = () => {
104
+ if (rotation.current) rotation.current.stop();
105
+ };
106
+ (0, import_react3.useEffect)(() => {
107
+ if (rotation.current === void 0) {
108
+ rotation.current = import_react_native4.Animated.timing(timer, {
109
+ duration: DURATION,
110
+ easing: import_react_native4.Easing.linear,
111
+ useNativeDriver: import_react_native4.Platform.OS !== "web",
112
+ toValue: 1
113
+ });
114
+ }
115
+ if (!disableAnimation) startRotation();
116
+ else stopRotation();
117
+ }, [disableAnimation, startRotation, timer]);
118
+ const safeThemeColor = (0, import_core2.getSafeThemeColor)(themeColor);
119
+ const colorScheme = theme.colors[safeThemeColor];
120
+ const mainColor = color || colorScheme.main;
121
+ const trackColor = showTrack ? backgroundColor ?? colorScheme.background : "transparent";
122
+ const strokeWidth = size * 0.1;
123
+ const frames = 60 * DURATION / 1e3;
124
+ const easing = import_react_native4.Easing.bezier(0.4, 0, 0.7, 1);
125
+ const containerStyle = {
126
+ width: size,
127
+ height: size / 2,
128
+ overflow: "hidden"
129
+ };
130
+ return /* @__PURE__ */ import_react3.default.createElement(import_react_native4.View, { style: [styles.container, { width: size, height: size }] }, /* @__PURE__ */ import_react3.default.createElement(
131
+ import_react_native4.View,
132
+ {
133
+ style: {
134
+ width: size,
135
+ height: size,
136
+ borderRadius: size / 2,
137
+ borderWidth: strokeWidth,
138
+ borderColor: trackColor
139
+ }
140
+ }
141
+ ), /* @__PURE__ */ import_react3.default.createElement(
142
+ import_react_native4.View,
143
+ {
144
+ style: {
145
+ width: size,
146
+ height: size,
147
+ position: "absolute"
148
+ }
149
+ },
150
+ [0, 1].map((index) => {
151
+ const inputRange = Array.from(
152
+ new Array(frames),
153
+ (_, frameIndex) => frameIndex / (frames - 1)
154
+ );
155
+ const outputRange = Array.from(new Array(frames), (_, frameIndex) => {
156
+ let progress = 2 * frameIndex / (frames - 1);
157
+ const rotationValue = index ? +(360 - 15) : -(180 - 15);
158
+ if (progress > 1) {
159
+ progress = 2 - progress;
160
+ }
161
+ const direction = index ? -1 : 1;
162
+ return `${direction * (180 - 30) * easing(progress) + rotationValue}deg`;
163
+ });
164
+ const layerStyle = {
165
+ width: size,
166
+ height: size,
167
+ transform: [
168
+ {
169
+ rotate: timer.interpolate({
170
+ inputRange: [0, 1],
171
+ outputRange: [`${0 + 30 + 15}deg`, `${2 * 360 + 30 + 15}deg`]
172
+ })
173
+ }
174
+ ]
175
+ };
176
+ const viewportStyle = {
177
+ width: size,
178
+ height: size,
179
+ transform: [
180
+ { translateY: index ? -size / 2 : 0 },
181
+ {
182
+ rotate: timer.interpolate({ inputRange, outputRange })
183
+ }
184
+ ]
185
+ };
186
+ const offsetStyle = index ? { top: size / 2 } : null;
187
+ const lineStyle = {
188
+ width: size,
189
+ height: size,
190
+ borderColor: mainColor,
191
+ borderWidth: strokeWidth,
192
+ borderRadius: size / 2
193
+ };
194
+ return /* @__PURE__ */ import_react3.default.createElement(import_react_native4.Animated.View, { key: index, style: [styles.layer] }, /* @__PURE__ */ import_react3.default.createElement(import_react_native4.Animated.View, { style: layerStyle }, /* @__PURE__ */ import_react3.default.createElement(import_react_native4.Animated.View, { style: [containerStyle, offsetStyle], collapsable: false }, /* @__PURE__ */ import_react3.default.createElement(import_react_native4.Animated.View, { style: viewportStyle }, /* @__PURE__ */ import_react3.default.createElement(import_react_native4.Animated.View, { style: containerStyle, collapsable: false }, /* @__PURE__ */ import_react3.default.createElement(import_react_native4.Animated.View, { style: lineStyle }))))));
195
+ })
196
+ ));
197
+ };
198
+
199
+ // src/components/indicator/linear-activity-indicator.tsx
200
+ var import_react5 = __toESM(require("react"), 1);
201
+ var import_react_native5 = require("react-native");
202
+ var import_react_native_reanimated2 = __toESM(require("react-native-reanimated"), 1);
203
+
204
+ // src/components/indicator/indicator.hook.ts
205
+ var import_react4 = require("react");
206
+ var import_react_native_reanimated = require("react-native-reanimated");
207
+ var useLinearActivityIndicatorAnimation = (disableAnimation) => {
208
+ const primaryTranslateX = (0, import_react_native_reanimated.useSharedValue)(0);
209
+ const primaryScaleX = (0, import_react_native_reanimated.useSharedValue)(0.08);
210
+ const secondaryTranslateX = (0, import_react_native_reanimated.useSharedValue)(0);
211
+ const secondaryScaleX = (0, import_react_native_reanimated.useSharedValue)(0.08);
212
+ (0, import_react4.useEffect)(() => {
213
+ if (disableAnimation) {
214
+ (0, import_react_native_reanimated.cancelAnimation)(primaryTranslateX);
215
+ (0, import_react_native_reanimated.cancelAnimation)(primaryScaleX);
216
+ (0, import_react_native_reanimated.cancelAnimation)(secondaryTranslateX);
217
+ (0, import_react_native_reanimated.cancelAnimation)(secondaryScaleX);
218
+ return;
219
+ }
220
+ primaryTranslateX.value = (0, import_react_native_reanimated.withRepeat)(
221
+ (0, import_react_native_reanimated.withSequence)(
222
+ (0, import_react_native_reanimated.withTiming)(0, { duration: 0 }),
223
+ (0, import_react_native_reanimated.withTiming)(0, { duration: 400, easing: import_react_native_reanimated.Easing.linear }),
224
+ (0, import_react_native_reanimated.withTiming)(0.836714, {
225
+ duration: 783,
226
+ easing: import_react_native_reanimated.Easing.bezier(0.5, 0, 0.701732, 0.495819)
227
+ }),
228
+ (0, import_react_native_reanimated.withTiming)(2.00611, {
229
+ duration: 817,
230
+ easing: import_react_native_reanimated.Easing.bezier(0.302435, 0.381352, 0.55, 0.956352)
231
+ })
232
+ ),
233
+ -1,
234
+ false
235
+ );
236
+ primaryScaleX.value = (0, import_react_native_reanimated.withRepeat)(
237
+ (0, import_react_native_reanimated.withSequence)(
238
+ (0, import_react_native_reanimated.withTiming)(0.08, { duration: 0 }),
239
+ (0, import_react_native_reanimated.withTiming)(0.08, { duration: 733, easing: import_react_native_reanimated.Easing.linear }),
240
+ (0, import_react_native_reanimated.withTiming)(0.661479, {
241
+ duration: 650,
242
+ easing: import_react_native_reanimated.Easing.bezier(0.334731, 0.12482, 0.785844, 1)
243
+ }),
244
+ (0, import_react_native_reanimated.withTiming)(0.08, {
245
+ duration: 617,
246
+ easing: import_react_native_reanimated.Easing.bezier(0.06, 0.11, 0.6, 1)
247
+ })
248
+ ),
249
+ -1,
250
+ false
251
+ );
252
+ secondaryTranslateX.value = (0, import_react_native_reanimated.withRepeat)(
253
+ (0, import_react_native_reanimated.withSequence)(
254
+ (0, import_react_native_reanimated.withTiming)(0, { duration: 0 }),
255
+ (0, import_react_native_reanimated.withTiming)(0.376519, {
256
+ duration: 500,
257
+ easing: import_react_native_reanimated.Easing.bezier(0.15, 0, 0.515058, 0.409685)
258
+ }),
259
+ (0, import_react_native_reanimated.withTiming)(0.843862, {
260
+ duration: 467,
261
+ easing: import_react_native_reanimated.Easing.bezier(0.31033, 0.284058, 0.8, 0.733712)
262
+ }),
263
+ (0, import_react_native_reanimated.withTiming)(1.60278, {
264
+ duration: 1033,
265
+ easing: import_react_native_reanimated.Easing.bezier(0.4, 0.627035, 0.6, 0.902026)
266
+ })
267
+ ),
268
+ -1,
269
+ false
270
+ );
271
+ secondaryScaleX.value = (0, import_react_native_reanimated.withRepeat)(
272
+ (0, import_react_native_reanimated.withSequence)(
273
+ (0, import_react_native_reanimated.withTiming)(0.08, { duration: 0 }),
274
+ (0, import_react_native_reanimated.withTiming)(0.457104, {
275
+ duration: 383,
276
+ easing: import_react_native_reanimated.Easing.bezier(0.205028, 0.057051, 0.57661, 0.453971)
277
+ }),
278
+ (0, import_react_native_reanimated.withTiming)(0.72796, {
279
+ duration: 500,
280
+ easing: import_react_native_reanimated.Easing.bezier(0.152313, 0.196432, 0.648374, 1.00432)
281
+ }),
282
+ (0, import_react_native_reanimated.withTiming)(0.08, {
283
+ duration: 1117,
284
+ easing: import_react_native_reanimated.Easing.bezier(0.257759, -3163e-6, 0.211762, 1.38179)
285
+ })
286
+ ),
287
+ -1,
288
+ false
289
+ );
290
+ return () => {
291
+ (0, import_react_native_reanimated.cancelAnimation)(primaryTranslateX);
292
+ (0, import_react_native_reanimated.cancelAnimation)(primaryScaleX);
293
+ (0, import_react_native_reanimated.cancelAnimation)(secondaryTranslateX);
294
+ (0, import_react_native_reanimated.cancelAnimation)(secondaryScaleX);
295
+ };
296
+ }, [disableAnimation]);
297
+ return {
298
+ primaryTranslateX,
299
+ primaryScaleX,
300
+ secondaryTranslateX,
301
+ secondaryScaleX
302
+ };
303
+ };
304
+
305
+ // src/components/indicator/linear-activity-indicator.tsx
306
+ var LinearActivityIndicator = ({
307
+ size = 4,
308
+ themeColor = "primary",
309
+ color,
310
+ backgroundColor,
311
+ disableAnimation = false,
312
+ borderRadius = 0,
313
+ showTrack = true
314
+ }) => {
315
+ const theme = useXUITheme();
316
+ const { primaryTranslateX, primaryScaleX, secondaryTranslateX, secondaryScaleX } = useLinearActivityIndicatorAnimation(disableAnimation);
317
+ const colorScheme = theme.colors[themeColor];
318
+ const mainColor = color || colorScheme.main;
319
+ const trackColor = showTrack ? backgroundColor ?? colorScheme.background : "transparent";
320
+ const barStyle = {
321
+ ...import_react_native5.StyleSheet.absoluteFillObject,
322
+ backgroundColor: mainColor,
323
+ borderRadius
324
+ };
325
+ const primaryStyle = (0, import_react_native_reanimated2.useAnimatedStyle)(() => ({
326
+ transform: [
327
+ { translateX: `${(primaryTranslateX.value - 1.45167) * 100}%` },
328
+ { scaleX: primaryScaleX.value }
329
+ ]
330
+ }));
331
+ const secondaryStyle = (0, import_react_native_reanimated2.useAnimatedStyle)(() => ({
332
+ transform: [
333
+ { translateX: `${(secondaryTranslateX.value - 0.548889) * 100}%` },
334
+ { scaleX: secondaryScaleX.value }
335
+ ]
336
+ }));
337
+ return /* @__PURE__ */ import_react5.default.createElement(
338
+ import_react_native5.View,
339
+ {
340
+ style: {
341
+ height: size,
342
+ width: "100%",
343
+ borderRadius,
344
+ backgroundColor: trackColor,
345
+ overflow: "hidden"
346
+ }
347
+ },
348
+ /* @__PURE__ */ import_react5.default.createElement(import_react_native_reanimated2.default.View, { style: [barStyle, primaryStyle] }),
349
+ /* @__PURE__ */ import_react5.default.createElement(import_react_native_reanimated2.default.View, { style: [barStyle, secondaryStyle] })
350
+ );
351
+ };
352
+
353
+ // src/components/indicator/indicator.tsx
354
+ var ActivityIndicator = (props) => {
355
+ const {
356
+ variant = "circular",
357
+ themeColor = "primary",
358
+ color,
359
+ backgroundColor,
360
+ size,
361
+ disableAnimation = false,
362
+ borderRadius,
363
+ showTrack
364
+ } = props;
365
+ const theme = useXUITheme();
366
+ const colorScheme = theme.colors[themeColor];
367
+ const mainColor = color ?? colorScheme.main;
368
+ const trackColor = backgroundColor ?? (showTrack ? colorScheme.background : "transparent");
369
+ if (variant === "circular") {
370
+ const circleSize = size ?? 40;
371
+ return /* @__PURE__ */ import_react6.default.createElement(
372
+ import_react_native6.View,
373
+ {
374
+ style: [styles.container, { width: circleSize, height: circleSize }],
375
+ accessible: true,
376
+ accessibilityRole: "progressbar",
377
+ accessibilityLabel: "Loading"
378
+ },
379
+ /* @__PURE__ */ import_react6.default.createElement(
380
+ CircularActivityIndicator,
381
+ {
382
+ size: circleSize,
383
+ themeColor,
384
+ color: mainColor,
385
+ backgroundColor: trackColor,
386
+ disableAnimation
387
+ }
388
+ )
389
+ );
390
+ }
391
+ const linearSize = size ?? 4;
392
+ return /* @__PURE__ */ import_react6.default.createElement(
393
+ import_react_native6.View,
394
+ {
395
+ style: styles.container,
396
+ accessible: true,
397
+ accessibilityRole: "progressbar",
398
+ accessibilityLabel: "Loading"
399
+ },
400
+ /* @__PURE__ */ import_react6.default.createElement(
401
+ LinearActivityIndicator,
402
+ {
403
+ size: linearSize,
404
+ themeColor,
405
+ color: mainColor,
406
+ backgroundColor: trackColor,
407
+ disableAnimation,
408
+ borderRadius,
409
+ showTrack
410
+ }
411
+ )
412
+ );
413
+ };
414
+ // Annotate the CommonJS export names for ESM import in node:
415
+ 0 && (module.exports = {
416
+ ActivityIndicator
417
+ });
@@ -0,0 +1,3 @@
1
+ export { ActivityIndicator } from './indicator/index.cjs';
2
+ import 'react';
3
+ import './theme-qvIXI4kF.cjs';
@@ -0,0 +1,3 @@
1
+ export { ActivityIndicator } from './indicator/index.js';
2
+ import 'react';
3
+ import './theme-qvIXI4kF.js';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ ActivityIndicator
3
+ } from "./chunk-6ITFLLAM.js";
4
+ import "./chunk-SHT66VET.js";
5
+ export {
6
+ ActivityIndicator
7
+ };