@xaui/hybrid 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.
@@ -0,0 +1,440 @@
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/components/indicator/index.ts
31
+ var indicator_exports = {};
32
+ __export(indicator_exports, {
33
+ ActivityIndicator: () => ActivityIndicator
34
+ });
35
+ module.exports = __toCommonJS(indicator_exports);
36
+
37
+ // src/components/indicator/circular-activity-indicator.tsx
38
+ var import_react3 = require("react");
39
+ var import_framer_motion = require("framer-motion");
40
+
41
+ // src/core/theme-context.tsx
42
+ var import_react2 = __toESM(require("react"), 1);
43
+
44
+ // src/core/theme-hooks.ts
45
+ var import_react = require("react");
46
+ function useXUITheme() {
47
+ const theme = (0, import_react.useContext)(XUIThemeContext);
48
+ if (!theme) {
49
+ throw new Error("useXUITheme must be used within XUIProvider");
50
+ }
51
+ return theme;
52
+ }
53
+
54
+ // src/core/theme-context.tsx
55
+ var import_theme = require("@xaui/core/theme");
56
+ var import_jsx_runtime = require("react/jsx-runtime");
57
+ var XUIThemeContext = (0, import_react2.createContext)(null);
58
+
59
+ // src/components/indicator/indicator.style.ts
60
+ var import_tailwind_variants = require("tailwind-variants");
61
+ var indicatorStyles = (0, import_tailwind_variants.tv)({
62
+ slots: {
63
+ base: "relative flex items-center justify-center overflow-hidden",
64
+ track: "overflow-hidden",
65
+ indicator: ""
66
+ },
67
+ variants: {
68
+ variant: {
69
+ linear: {
70
+ base: "w-full block",
71
+ track: "relative w-full h-full overflow-hidden",
72
+ indicator: "absolute top-0 bottom-0 left-0 transition-all"
73
+ },
74
+ circular: {
75
+ base: "inline-flex shrink-0",
76
+ track: "fill-none w-auto h-auto",
77
+ indicator: "fill-none w-auto h-auto"
78
+ }
79
+ }
80
+ },
81
+ defaultVariants: {
82
+ variant: "linear"
83
+ }
84
+ });
85
+
86
+ // src/components/indicator/circular-activity-indicator.tsx
87
+ var import_core2 = require("@xaui/core");
88
+ var import_jsx_runtime2 = require("react/jsx-runtime");
89
+ var DURATION = 1.5;
90
+ var EASING = [0.4, 0, 0.7, 1];
91
+ var bezierEasing = (t) => {
92
+ const [x1, y1, x2, y2] = EASING;
93
+ const cx = 3 * x1;
94
+ const bx = 3 * (x2 - x1) - cx;
95
+ const ax = 1 - cx - bx;
96
+ const cy = 3 * y1;
97
+ const by = 3 * (y2 - y1) - cy;
98
+ const ay = 1 - cy - by;
99
+ const sampleCurveX = (u2) => ((ax * u2 + bx) * u2 + cx) * u2;
100
+ const sampleCurveY = (u2) => ((ay * u2 + by) * u2 + cy) * u2;
101
+ let u = t;
102
+ for (let i = 0; i < 8; i++) {
103
+ const x = sampleCurveX(u) - t;
104
+ if (Math.abs(x) < 1e-3) break;
105
+ const slope = 3 * ax * u * u + 2 * bx * u + cx;
106
+ if (Math.abs(slope) < 1e-6) break;
107
+ u -= x / slope;
108
+ }
109
+ return sampleCurveY(u);
110
+ };
111
+ var generateKeyframes = (index, frames) => {
112
+ const rotationValue = index ? 360 - 15 : -(180 - 15);
113
+ const direction = index ? -1 : 1;
114
+ return Array.from({ length: frames }, (_, frameIndex) => {
115
+ let progress = 2 * frameIndex / (frames - 1);
116
+ if (progress > 1) progress = 2 - progress;
117
+ return direction * (180 - 30) * bezierEasing(progress) + rotationValue;
118
+ });
119
+ };
120
+ var CircularActivityIndicator = ({
121
+ size = 40,
122
+ themeColor = "primary",
123
+ color,
124
+ backgroundColor,
125
+ disableAnimation = false,
126
+ showTrack = true,
127
+ className
128
+ }) => {
129
+ const { base } = indicatorStyles({ variant: "circular" });
130
+ const theme = useXUITheme();
131
+ const safeThemeColor = (0, import_core2.getSafeThemeColor)(themeColor);
132
+ const colorScheme = theme.colors[safeThemeColor];
133
+ const resolvedColor = color ?? colorScheme.main;
134
+ const resolvedBackground = showTrack ? backgroundColor ?? colorScheme.background : "transparent";
135
+ const strokeWidth = size * 0.1;
136
+ const frames = Math.round(60 * DURATION);
137
+ const times = (0, import_react3.useMemo)(
138
+ () => Array.from({ length: frames }, (_, i) => i / (frames - 1)),
139
+ [frames]
140
+ );
141
+ const outerStart = 0 + 30 + 15;
142
+ const outerEnd = 2 * 360 + 30 + 15;
143
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
144
+ "div",
145
+ {
146
+ className: base({ className }),
147
+ style: { width: size, height: size, position: "relative" },
148
+ children: [
149
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
150
+ "div",
151
+ {
152
+ style: {
153
+ width: size,
154
+ height: size,
155
+ borderRadius: size / 2,
156
+ borderWidth: strokeWidth,
157
+ borderStyle: "solid",
158
+ borderColor: resolvedBackground,
159
+ boxSizing: "border-box"
160
+ }
161
+ }
162
+ ),
163
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
164
+ "div",
165
+ {
166
+ style: {
167
+ width: size,
168
+ height: size,
169
+ position: "absolute",
170
+ top: 0,
171
+ left: 0
172
+ },
173
+ children: [0, 1].map((index) => {
174
+ const keyframes = generateKeyframes(index, frames);
175
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
176
+ "div",
177
+ {
178
+ style: {
179
+ position: "absolute",
180
+ width: size,
181
+ height: size
182
+ },
183
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
184
+ import_framer_motion.motion.div,
185
+ {
186
+ style: {
187
+ width: size,
188
+ height: size,
189
+ transformOrigin: "50% 50%"
190
+ },
191
+ initial: { rotate: outerStart },
192
+ animate: disableAnimation ? { rotate: outerStart } : { rotate: outerEnd },
193
+ transition: disableAnimation ? { duration: 0 } : {
194
+ type: "tween",
195
+ duration: DURATION,
196
+ ease: "linear",
197
+ repeat: Infinity,
198
+ repeatType: "loop",
199
+ repeatDelay: 0
200
+ },
201
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
202
+ "div",
203
+ {
204
+ style: {
205
+ width: size,
206
+ height: size / 2,
207
+ overflow: "hidden",
208
+ position: "absolute",
209
+ ...index ? { top: size / 2 } : {}
210
+ },
211
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
212
+ import_framer_motion.motion.div,
213
+ {
214
+ style: {
215
+ width: size,
216
+ height: size,
217
+ transformOrigin: "50% 50%"
218
+ },
219
+ initial: {
220
+ y: index ? -size / 2 : 0,
221
+ rotate: keyframes[0]
222
+ },
223
+ animate: disableAnimation ? { y: index ? -size / 2 : 0, rotate: keyframes[0] } : { y: index ? -size / 2 : 0, rotate: keyframes },
224
+ transition: disableAnimation ? { duration: 0 } : {
225
+ type: "tween",
226
+ duration: DURATION,
227
+ ease: "linear",
228
+ repeat: Infinity,
229
+ repeatType: "loop",
230
+ repeatDelay: 0,
231
+ times
232
+ },
233
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
234
+ "div",
235
+ {
236
+ style: {
237
+ width: size,
238
+ height: size / 2,
239
+ overflow: "hidden"
240
+ },
241
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
242
+ "div",
243
+ {
244
+ style: {
245
+ width: size,
246
+ height: size,
247
+ borderColor: resolvedColor,
248
+ borderWidth: strokeWidth,
249
+ borderStyle: "solid",
250
+ borderRadius: size / 2,
251
+ boxSizing: "border-box"
252
+ }
253
+ }
254
+ )
255
+ }
256
+ )
257
+ }
258
+ )
259
+ }
260
+ )
261
+ }
262
+ )
263
+ },
264
+ index
265
+ );
266
+ })
267
+ }
268
+ )
269
+ ]
270
+ }
271
+ );
272
+ };
273
+
274
+ // src/components/indicator/linear-activity-indicator.tsx
275
+ var import_framer_motion2 = require("framer-motion");
276
+ var import_core4 = require("@xaui/core");
277
+ var import_jsx_runtime3 = require("react/jsx-runtime");
278
+ var DURATION_SECONDS = 2;
279
+ var PRIMARY_TRANSLATE_OFFSET = 1.45167;
280
+ var SECONDARY_TRANSLATE_OFFSET = 0.548889;
281
+ var toPercent = (value, offset) => `${(value - offset) * 100}%`;
282
+ var buildTimes = (durations) => {
283
+ const total = durations.reduce((sum, duration) => sum + duration, 0);
284
+ let acc = 0;
285
+ const intermediateTimes = durations.slice(0, -1).map((duration) => {
286
+ acc += duration;
287
+ return acc / total;
288
+ });
289
+ return [0, ...intermediateTimes, 1];
290
+ };
291
+ var primaryTranslateKeyframes = [0, 0, 0.836714, 2.00611].map(
292
+ (value) => toPercent(value, PRIMARY_TRANSLATE_OFFSET)
293
+ );
294
+ var primaryTranslateTimes = buildTimes([400, 783, 817]);
295
+ var primaryTranslateEase = [
296
+ "linear",
297
+ [0.5, 0, 0.701732, 0.495819],
298
+ [0.302435, 0.381352, 0.55, 0.956352]
299
+ ];
300
+ var primaryScaleKeyframes = [0.08, 0.08, 0.661479, 0.08];
301
+ var primaryScaleTimes = buildTimes([733, 650, 617]);
302
+ var primaryScaleEase = [
303
+ "linear",
304
+ [0.334731, 0.12482, 0.785844, 1],
305
+ [0.06, 0.11, 0.6, 1]
306
+ ];
307
+ var secondaryTranslateKeyframes = [0, 0.376519, 0.843862, 1.60278].map(
308
+ (value) => toPercent(value, SECONDARY_TRANSLATE_OFFSET)
309
+ );
310
+ var secondaryTranslateTimes = buildTimes([500, 467, 1033]);
311
+ var secondaryTranslateEase = [
312
+ [0.15, 0, 0.515058, 0.409685],
313
+ [0.31033, 0.284058, 0.8, 0.733712],
314
+ [0.4, 0.627035, 0.6, 0.902026]
315
+ ];
316
+ var secondaryScaleKeyframes = [0.08, 0.457104, 0.72796, 0.08];
317
+ var secondaryScaleTimes = buildTimes([383, 500, 1117]);
318
+ var secondaryScaleEase = [
319
+ [0.205028, 0.057051, 0.57661, 0.453971],
320
+ [0.152313, 0.196432, 0.648374, 1.00432],
321
+ [0.257759, -3163e-6, 0.211762, 1.38179]
322
+ ];
323
+ var LinearActivityIndicator = ({
324
+ size = 4,
325
+ themeColor = "primary",
326
+ color,
327
+ backgroundColor,
328
+ disableAnimation = false,
329
+ borderRadius = 0,
330
+ showTrack = true,
331
+ className
332
+ }) => {
333
+ const { base, track } = indicatorStyles({ variant: "linear" });
334
+ const theme = useXUITheme();
335
+ const safeThemeColor = (0, import_core4.getSafeThemeColor)(themeColor);
336
+ const colorScheme = theme.colors[safeThemeColor];
337
+ const mainColor = color ?? colorScheme.main;
338
+ const trackColor = showTrack ? backgroundColor ?? colorScheme.background : "transparent";
339
+ const radius = Math.max(0, borderRadius);
340
+ const primaryAnimate = disableAnimation ? { x: primaryTranslateKeyframes[0], scaleX: primaryScaleKeyframes[0] } : { x: primaryTranslateKeyframes, scaleX: primaryScaleKeyframes };
341
+ const secondaryAnimate = disableAnimation ? { x: secondaryTranslateKeyframes[0], scaleX: secondaryScaleKeyframes[0] } : { x: secondaryTranslateKeyframes, scaleX: secondaryScaleKeyframes };
342
+ const primaryTransition = disableAnimation ? { x: { duration: 0 }, scaleX: { duration: 0 } } : {
343
+ x: {
344
+ duration: DURATION_SECONDS,
345
+ ease: primaryTranslateEase,
346
+ times: primaryTranslateTimes,
347
+ repeat: Infinity,
348
+ repeatType: "loop"
349
+ },
350
+ scaleX: {
351
+ duration: DURATION_SECONDS,
352
+ ease: primaryScaleEase,
353
+ times: primaryScaleTimes,
354
+ repeat: Infinity,
355
+ repeatType: "loop"
356
+ }
357
+ };
358
+ const secondaryTransition = disableAnimation ? { x: { duration: 0 }, scaleX: { duration: 0 } } : {
359
+ x: {
360
+ duration: DURATION_SECONDS,
361
+ ease: secondaryTranslateEase,
362
+ times: secondaryTranslateTimes,
363
+ repeat: Infinity,
364
+ repeatType: "loop"
365
+ },
366
+ scaleX: {
367
+ duration: DURATION_SECONDS,
368
+ ease: secondaryScaleEase,
369
+ times: secondaryScaleTimes,
370
+ repeat: Infinity,
371
+ repeatType: "loop"
372
+ }
373
+ };
374
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: base({ className }), style: { height: size }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
375
+ "div",
376
+ {
377
+ className: track(),
378
+ style: {
379
+ position: "relative",
380
+ height: size,
381
+ backgroundColor: trackColor,
382
+ borderRadius: radius,
383
+ overflow: "hidden"
384
+ },
385
+ children: [
386
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
387
+ import_framer_motion2.motion.div,
388
+ {
389
+ initial: { x: primaryTranslateKeyframes[0], scaleX: primaryScaleKeyframes[0] },
390
+ animate: primaryAnimate,
391
+ transition: primaryTransition,
392
+ style: {
393
+ position: "absolute",
394
+ inset: 0,
395
+ width: "100%",
396
+ height: size,
397
+ backgroundColor: mainColor,
398
+ borderRadius: radius,
399
+ transformOrigin: "50% 50%"
400
+ }
401
+ }
402
+ ),
403
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
404
+ import_framer_motion2.motion.div,
405
+ {
406
+ initial: {
407
+ x: secondaryTranslateKeyframes[0],
408
+ scaleX: secondaryScaleKeyframes[0]
409
+ },
410
+ animate: secondaryAnimate,
411
+ transition: secondaryTransition,
412
+ style: {
413
+ position: "absolute",
414
+ inset: 0,
415
+ width: "100%",
416
+ height: size,
417
+ backgroundColor: mainColor,
418
+ borderRadius: radius,
419
+ transformOrigin: "50% 50%"
420
+ }
421
+ }
422
+ )
423
+ ]
424
+ }
425
+ ) });
426
+ };
427
+
428
+ // src/components/indicator/indicator.tsx
429
+ var import_jsx_runtime4 = require("react/jsx-runtime");
430
+ var ActivityIndicator = (props) => {
431
+ const { variant = "circular", ...rest } = props;
432
+ if (variant === "circular") {
433
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { role: "progressbar", "aria-label": "Loading", className: "inline-flex", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CircularActivityIndicator, { ...rest }) });
434
+ }
435
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { role: "progressbar", "aria-label": "Loading", className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LinearActivityIndicator, { ...rest }) });
436
+ };
437
+ // Annotate the CommonJS export names for ESM import in node:
438
+ 0 && (module.exports = {
439
+ ActivityIndicator
440
+ });
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { T as ThemeColor } from '../theme-qvIXI4kF.cjs';
3
+
4
+ type ActivityIndicatorVariant = 'linear' | 'circular';
5
+ type ActivityIndicatorProps = {
6
+ /**
7
+ * The variant of activity indicator.
8
+ * @default 'circular'
9
+ */
10
+ variant?: ActivityIndicatorVariant;
11
+ /**
12
+ * The size of the activity indicator (height for linear, diameter for circular).
13
+ * @default 4 for linear, 40 for circular
14
+ */
15
+ size?: number;
16
+ /**
17
+ * The theme color of the activity indicator.
18
+ * @default 'primary'
19
+ */
20
+ themeColor?: ThemeColor;
21
+ /**
22
+ * The custom color of the activity indicator.
23
+ * Overrides themeColor.
24
+ */
25
+ color?: string;
26
+ /**
27
+ * The background color of the track.
28
+ */
29
+ backgroundColor?: string;
30
+ /**
31
+ * Whether to disable the animation.
32
+ * @default false
33
+ */
34
+ disableAnimation?: boolean;
35
+ /**
36
+ * The border radius of the indicator and track.
37
+ */
38
+ borderRadius?: number;
39
+ /**
40
+ * Show track for the activity indicator.
41
+ */
42
+ showTrack?: boolean;
43
+ /**
44
+ * Custom class name to be applied to the activity indicator.
45
+ */
46
+ className?: string;
47
+ };
48
+
49
+ declare const ActivityIndicator: React.FC<ActivityIndicatorProps>;
50
+
51
+ export { ActivityIndicator, type ActivityIndicatorProps };
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { T as ThemeColor } from '../theme-qvIXI4kF.js';
3
+
4
+ type ActivityIndicatorVariant = 'linear' | 'circular';
5
+ type ActivityIndicatorProps = {
6
+ /**
7
+ * The variant of activity indicator.
8
+ * @default 'circular'
9
+ */
10
+ variant?: ActivityIndicatorVariant;
11
+ /**
12
+ * The size of the activity indicator (height for linear, diameter for circular).
13
+ * @default 4 for linear, 40 for circular
14
+ */
15
+ size?: number;
16
+ /**
17
+ * The theme color of the activity indicator.
18
+ * @default 'primary'
19
+ */
20
+ themeColor?: ThemeColor;
21
+ /**
22
+ * The custom color of the activity indicator.
23
+ * Overrides themeColor.
24
+ */
25
+ color?: string;
26
+ /**
27
+ * The background color of the track.
28
+ */
29
+ backgroundColor?: string;
30
+ /**
31
+ * Whether to disable the animation.
32
+ * @default false
33
+ */
34
+ disableAnimation?: boolean;
35
+ /**
36
+ * The border radius of the indicator and track.
37
+ */
38
+ borderRadius?: number;
39
+ /**
40
+ * Show track for the activity indicator.
41
+ */
42
+ showTrack?: boolean;
43
+ /**
44
+ * Custom class name to be applied to the activity indicator.
45
+ */
46
+ className?: string;
47
+ };
48
+
49
+ declare const ActivityIndicator: React.FC<ActivityIndicatorProps>;
50
+
51
+ export { ActivityIndicator, type ActivityIndicatorProps };
@@ -0,0 +1,7 @@
1
+ import {
2
+ ActivityIndicator
3
+ } from "../chunk-57VNE2OC.js";
4
+ import "../chunk-4GTYR4N2.js";
5
+ export {
6
+ ActivityIndicator
7
+ };