@alpic-ai/ui 0.0.0-dev.g05467b7 → 0.0.0-dev.g05c89ce

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.
Files changed (47) hide show
  1. package/dist/components/area-chart.d.mts +2 -0
  2. package/dist/components/area-chart.mjs +9 -3
  3. package/dist/components/bar-chart.d.mts +2 -0
  4. package/dist/components/bar-chart.mjs +9 -3
  5. package/dist/components/bar-list.d.mts +3 -0
  6. package/dist/components/bar-list.mjs +25 -12
  7. package/dist/components/chart-card.d.mts +1 -1
  8. package/dist/components/chart-card.mjs +1 -1
  9. package/dist/components/chart-container.d.mts +1 -1
  10. package/dist/components/chart-legend.d.mts +5 -0
  11. package/dist/components/chart-legend.mjs +11 -2
  12. package/dist/components/donut-chart.mjs +9 -5
  13. package/dist/components/form.mjs +1 -1
  14. package/dist/components/heatmap-chart.d.mts +8 -0
  15. package/dist/components/heatmap-chart.mjs +39 -8
  16. package/dist/components/line-chart.d.mts +2 -0
  17. package/dist/components/line-chart.mjs +10 -3
  18. package/dist/components/stat.d.mts +3 -1
  19. package/dist/components/stat.mjs +14 -4
  20. package/dist/components/wizard.d.mts +1 -19
  21. package/dist/components/wizard.mjs +1 -19
  22. package/dist/lib/chart.mjs +16 -1
  23. package/package.json +23 -23
  24. package/src/components/area-chart.tsx +12 -4
  25. package/src/components/bar-chart.tsx +12 -4
  26. package/src/components/bar-list.tsx +26 -10
  27. package/src/components/chart-card.tsx +8 -6
  28. package/src/components/chart-container.tsx +2 -0
  29. package/src/components/chart-legend.tsx +10 -2
  30. package/src/components/donut-chart.tsx +6 -6
  31. package/src/components/form.tsx +1 -1
  32. package/src/components/heatmap-chart.tsx +62 -18
  33. package/src/components/line-chart.tsx +18 -5
  34. package/src/components/stat.tsx +10 -6
  35. package/src/components/wizard.tsx +1 -35
  36. package/src/lib/chart.ts +34 -0
  37. package/src/stories/area-chart.stories.tsx +1 -3
  38. package/src/stories/bar-chart.stories.tsx +1 -3
  39. package/src/stories/bar-list.stories.tsx +1 -3
  40. package/src/stories/donut-chart.stories.tsx +1 -3
  41. package/src/stories/heatmap-chart.stories.tsx +1 -3
  42. package/src/stories/line-chart.stories.tsx +1 -3
  43. package/src/stories/wizard.stories.tsx +23 -5
  44. package/src/styles/tokens.css +0 -45
  45. package/dist/components/grid-fx.d.mts +0 -13
  46. package/dist/components/grid-fx.mjs +0 -188
  47. package/src/components/grid-fx.tsx +0 -238
@@ -1,238 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
-
5
- import { useReducedMotion } from "../hooks/use-reduced-motion";
6
- import { cn } from "../lib/cn";
7
-
8
- const CELL_SIZE = 46;
9
- const TTL_MIN = 42;
10
- const TTL_MAX = 78;
11
- const SPAWN_MIN = 180;
12
- const SPAWN_MAX = 480;
13
-
14
- interface GlitchLine {
15
- horiz: boolean;
16
- at: number;
17
- life: number;
18
- ttl: number;
19
- color: string;
20
- colorHi: string;
21
- }
22
-
23
- const rand = (min: number, max: number) => min + Math.random() * (max - min);
24
-
25
- function resolveColors(element: HTMLElement) {
26
- const styles = getComputedStyle(element);
27
- return {
28
- color: styles.getPropertyValue("--color-primary").trim() || "#e90060" /* --color-primary */,
29
- colorHi: styles.getPropertyValue("--color-primary-hover").trim() || "#f22b79" /* --color-primary-hover */,
30
- };
31
- }
32
-
33
- function strokeFull(ctx: CanvasRenderingContext2D, horiz: boolean, at: number, width: number, height: number) {
34
- ctx.beginPath();
35
- if (horiz) {
36
- ctx.moveTo(0, at);
37
- ctx.lineTo(width, at);
38
- } else {
39
- ctx.moveTo(at, 0);
40
- ctx.lineTo(at, height);
41
- }
42
- ctx.stroke();
43
- }
44
-
45
- function drawGlitchLine(ctx: CanvasRenderingContext2D, line: GlitchLine, width: number, height: number) {
46
- const { horiz, at, color, colorHi } = line;
47
- const span = horiz ? width : height;
48
- const progress = line.life / line.ttl;
49
- const envelope = progress < 0.08 ? progress / 0.08 : 1 - (progress - 0.08) / 0.92;
50
- const base = Math.max(0, envelope);
51
-
52
- ctx.lineCap = "round";
53
-
54
- const ghosts = [
55
- { offset: 0, alpha: 0.85, blur: 12 },
56
- { offset: rand(-3, 3), alpha: 0.35, blur: 0 },
57
- { offset: rand(-7, 7), alpha: 0.2, blur: 0 },
58
- ];
59
- for (const ghost of ghosts) {
60
- ctx.globalAlpha = base * ghost.alpha * (Math.random() < 0.1 ? 0.3 : 1);
61
- ctx.strokeStyle = color;
62
- ctx.lineWidth = 1.5;
63
- ctx.shadowBlur = ghost.blur;
64
- ctx.shadowColor = color;
65
- strokeFull(ctx, horiz, at + ghost.offset, width, height);
66
- }
67
-
68
- if (Math.random() < 0.5) {
69
- ctx.globalAlpha = base * 0.6;
70
- ctx.lineWidth = 2;
71
- ctx.shadowBlur = 0;
72
- ctx.strokeStyle = colorHi;
73
- for (let segment = 0; segment < 3; segment++) {
74
- const start = rand(0, span * 0.85);
75
- const end = start + rand(20, 80);
76
- const jitter = rand(-4, 4);
77
- ctx.beginPath();
78
- if (horiz) {
79
- ctx.moveTo(start, at + jitter);
80
- ctx.lineTo(end, at + jitter);
81
- } else {
82
- ctx.moveTo(at + jitter, start);
83
- ctx.lineTo(at + jitter, end);
84
- }
85
- ctx.stroke();
86
- }
87
- }
88
- }
89
-
90
- function GridFx({
91
- className,
92
- cellSize = CELL_SIZE,
93
- style,
94
- ...props
95
- }: React.ComponentProps<"canvas"> & { cellSize?: number }) {
96
- const reduced = useReducedMotion();
97
- const canvasRef = React.useRef<HTMLCanvasElement>(null);
98
-
99
- React.useEffect(() => {
100
- if (reduced) {
101
- return;
102
- }
103
- const canvas = canvasRef.current;
104
- const parent = canvas?.parentElement;
105
- const ctx = canvas?.getContext("2d");
106
- if (!canvas || !parent || !ctx) {
107
- return;
108
- }
109
-
110
- let width = 0;
111
- let height = 0;
112
- let dpr = 1;
113
- let frame = 0;
114
- let nextIn = rand(SPAWN_MIN, SPAWN_MAX);
115
- let onScreen = true;
116
- const lines: GlitchLine[] = [];
117
-
118
- const resize = () => {
119
- dpr = Math.min(window.devicePixelRatio || 1, 2);
120
- width = parent.clientWidth;
121
- height = parent.clientHeight;
122
- canvas.width = width * dpr;
123
- canvas.height = height * dpr;
124
- ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
125
- };
126
-
127
- const spawn = () => {
128
- const horiz = Math.random() < 0.5;
129
- const tracks = Math.ceil((horiz ? height : width) / cellSize);
130
- const { color, colorHi } = resolveColors(canvas);
131
- lines.push({
132
- horiz,
133
- at: Math.floor(Math.random() * tracks) * cellSize + 0.5,
134
- life: 0,
135
- ttl: rand(TTL_MIN, TTL_MAX),
136
- color,
137
- colorHi,
138
- });
139
- };
140
-
141
- const tick = () => {
142
- ctx.globalAlpha = 1;
143
- ctx.shadowBlur = 0;
144
- ctx.clearRect(0, 0, width, height);
145
-
146
- if (--nextIn <= 0) {
147
- spawn();
148
- nextIn = rand(SPAWN_MIN, SPAWN_MAX);
149
- }
150
- for (let index = lines.length - 1; index >= 0; index--) {
151
- const line = lines[index];
152
- if (!line) {
153
- continue;
154
- }
155
- line.life++;
156
- drawGlitchLine(ctx, line, width, height);
157
- if (line.life >= line.ttl) {
158
- lines.splice(index, 1);
159
- }
160
- }
161
-
162
- ctx.globalAlpha = 1;
163
- ctx.shadowBlur = 0;
164
- frame = requestAnimationFrame(tick);
165
- };
166
-
167
- const running = () => onScreen && document.visibilityState === "visible";
168
- const start = () => {
169
- if (!frame && running()) {
170
- frame = requestAnimationFrame(tick);
171
- }
172
- };
173
- const stop = () => {
174
- if (frame) {
175
- cancelAnimationFrame(frame);
176
- }
177
- frame = 0;
178
- ctx.clearRect(0, 0, width, height);
179
- };
180
-
181
- resize();
182
- start();
183
-
184
- const resizeObserver = new ResizeObserver(() => resize());
185
- resizeObserver.observe(parent);
186
-
187
- const intersectionObserver = new IntersectionObserver(([entry]) => {
188
- if (!entry) {
189
- return;
190
- }
191
- onScreen = entry.isIntersecting;
192
- if (onScreen) {
193
- start();
194
- } else {
195
- stop();
196
- }
197
- });
198
- intersectionObserver.observe(canvas);
199
-
200
- const onVisibility = () => {
201
- if (running()) {
202
- start();
203
- } else {
204
- stop();
205
- }
206
- };
207
- document.addEventListener("visibilitychange", onVisibility);
208
-
209
- return () => {
210
- stop();
211
- resizeObserver.disconnect();
212
- intersectionObserver.disconnect();
213
- document.removeEventListener("visibilitychange", onVisibility);
214
- };
215
- }, [reduced, cellSize]);
216
-
217
- if (reduced) {
218
- return null;
219
- }
220
-
221
- return (
222
- <canvas
223
- ref={canvasRef}
224
- aria-hidden
225
- data-slot="grid-fx"
226
- className={cn("pointer-events-none absolute inset-0 h-full w-full", className)}
227
- style={{
228
- zIndex: -1,
229
- WebkitMaskImage: "radial-gradient(120% 95% at 50% 0%, #000 30%, transparent 100%)",
230
- maskImage: "radial-gradient(120% 95% at 50% 0%, #000 30%, transparent 100%)",
231
- ...style,
232
- }}
233
- {...props}
234
- />
235
- );
236
- }
237
-
238
- export { GridFx };