@yamatozhen/design_system 1.0.0

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 (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +101 -0
  3. package/package.json +49 -0
  4. package/scripts/postinstall.js +105 -0
  5. package/template/app/ClientNav.tsx +310 -0
  6. package/template/app/globals.css +167 -0
  7. package/template/app/layout.tsx +128 -0
  8. package/template/app/themes/dark-mc.css +51 -0
  9. package/template/app/themes/dark.css +51 -0
  10. package/template/app/themes/light-mc.css +51 -0
  11. package/template/app/themes/light.css +51 -0
  12. package/template/app/themes/theme.css +82 -0
  13. package/template/components/layout/Lightbox/LightboxCard.tsx +100 -0
  14. package/template/components/layout/Lightbox/LightboxGallery.module.css +249 -0
  15. package/template/components/layout/Lightbox/LightboxGallery.tsx +72 -0
  16. package/template/components/layout/Lightbox/LightboxGrid.tsx +186 -0
  17. package/template/components/layout/Lightbox/LightboxModal.module.css +395 -0
  18. package/template/components/layout/Lightbox/LightboxModal.tsx +500 -0
  19. package/template/components/layout/Lightbox/demo.tsx +412 -0
  20. package/template/components/layout/Lightbox/index.ts +30 -0
  21. package/template/components/layout/Lightbox/types.ts +113 -0
  22. package/template/components/layout/Lightbox/useLightboxFilters.ts +140 -0
  23. package/template/components/layout/accordion/Accordion.module.css +149 -0
  24. package/template/components/layout/accordion/Accordion.tsx +114 -0
  25. package/template/components/layout/button/Button.module.css +305 -0
  26. package/template/components/layout/button/ButtonGroup.tsx +503 -0
  27. package/template/components/layout/button/FAB.tsx +118 -0
  28. package/template/components/layout/button/button.tsx +128 -0
  29. package/template/components/layout/button/drop.module.css +229 -0
  30. package/template/components/layout/button/drop.tsx +516 -0
  31. package/template/components/layout/hero/v1/heroSlideshow.module.css +107 -0
  32. package/template/components/layout/hero/v1/heroSlideshow.tsx +233 -0
  33. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +126 -0
  34. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +290 -0
  35. package/template/components/layout/modals/alert/Alert.tsx +188 -0
  36. package/template/components/layout/navigation/MioCard.module.css +88 -0
  37. package/template/components/layout/navigation/MioCard.tsx +266 -0
  38. package/template/components/layout/navigation/Wrap.tsx +41 -0
  39. package/template/components/layout/navigation/nav/Nav.module.css +508 -0
  40. package/template/components/layout/navigation/nav/Nav.tsx +167 -0
  41. package/template/components/layout/navigation/nav/NavBar.tsx +419 -0
  42. package/template/components/layout/navigation/nav/NavContext.tsx +259 -0
  43. package/template/components/layout/navigation/nav/NavItem.tsx +173 -0
  44. package/template/components/layout/navigation/nav/NavNew.module.css +373 -0
  45. package/template/components/layout/navigation/nav/NavRail.tsx +315 -0
  46. package/template/components/layout/navigation/nav/NavSection.tsx +102 -0
  47. package/template/components/layout/navigation/nav/NavTab.tsx +25 -0
  48. package/template/components/layout/navigation/nav/navftb/NavFTB.module.css +252 -0
  49. package/template/components/layout/navigation/nav/navftb/NavFTB.tsx +399 -0
  50. package/template/components/layout/navigation/nav/navftb/useTabIndicator.ts +484 -0
  51. package/template/components/layout/navigation/nav/navheader/NavHeader.module.css +59 -0
  52. package/template/components/layout/navigation/nav/navheader/NavHeader.tsx +478 -0
  53. package/template/components/layout/pages/loadingScreen.tsx +102 -0
  54. package/template/components/layout/pages/maintenance/Maintenance.tsx +53 -0
  55. package/template/components/layout/pages/maintenance/maintenance.module.css +163 -0
  56. package/template/components/layout/switch/Switch.module.css +102 -0
  57. package/template/components/layout/switch/Switch.tsx +48 -0
  58. package/template/components/tools/Divider.tsx +11 -0
  59. package/template/components/tools/ProgressiveBlur.tsx +73 -0
  60. package/template/components/tools/ReduceMotionContext.tsx +5 -0
  61. package/template/components/tools/Sinewave.tsx +199 -0
  62. package/template/components/tools/SinewaveProgress.tsx +135 -0
  63. package/template/components/tools/badge/Badge.tsx +28 -0
  64. package/template/components/tools/flubber.d.ts +7 -0
  65. package/template/components/tools/icon/SocialIcons.tsx +88 -0
  66. package/template/components/tools/icon/icon.module.css +0 -0
  67. package/template/components/tools/icon/icon.tsx +125 -0
  68. package/template/components/tools/mobileViewProvider.tsx +58 -0
  69. package/template/components/tools/react-bits/ClickSpark.tsx +177 -0
  70. package/template/components/tools/react-bits/FadeContent.tsx +90 -0
  71. package/template/components/tools/react-bits/GlareHover.tsx +73 -0
  72. package/template/components/tools/react-bits/GradientText/GradientText.css +70 -0
  73. package/template/components/tools/react-bits/GradientText/GradientText.tsx +44 -0
  74. package/template/components/tools/react-bits/Magnet.tsx +118 -0
  75. package/template/components/tools/react-bits/Stepper/Stepper.css +134 -0
  76. package/template/components/tools/react-bits/Stepper/Stepper.tsx +412 -0
  77. package/template/components/tools/ripple/ripple.css +41 -0
  78. package/template/components/tools/ripple/ripple.tsx +53 -0
  79. package/template/components/tools/shape/ShapeLoader.tsx +101 -0
  80. package/template/components/tools/shape/ShapeMorph.tsx +190 -0
  81. package/template/components/tools/shape/ShapePaths.ts +116 -0
  82. package/template/components/tools/switch/Switch.module.css +102 -0
  83. package/template/components/tools/switch/Switch.tsx +48 -0
  84. package/template/components/tools/useBodyScrollLock.tsx +27 -0
  85. package/template/components/tools/useImageColor.ts +47 -0
  86. package/template/components/tools/useNavSheetDrag.tsx +196 -0
  87. package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght.woff2 +0 -0
@@ -0,0 +1,135 @@
1
+ "use client";
2
+ import React from "react";
3
+ import Sinewave from "@/components/tools/Sinewave";
4
+
5
+ type SinewaveProgressProps = {
6
+ /** 0-100 task progress. The wave covers the loaded portion, the line covers the rest. */
7
+ progress: number;
8
+ width?: number;
9
+ height?: number;
10
+ /** Frequency at full width. Wavelength is held constant as the wave grows. */
11
+ frequency?: number;
12
+ amplitude?: number;
13
+ strokeWidth?: number;
14
+ accentColor?: string;
15
+ trackColor?: string;
16
+ duration?: number;
17
+ progressDuration?: number;
18
+ progressEasing?: string;
19
+ /** Seconds to hold at 100% before the whole bar collapses (thickness → 0). */
20
+ onCollapsed?: () => void;
21
+ shrinkDelay?: number;
22
+ className?: string;
23
+ style?: React.CSSProperties;
24
+ };
25
+
26
+ const SinewaveProgress: React.FC<SinewaveProgressProps> = ({
27
+ progress,
28
+ width = 400,
29
+ height = 20,
30
+ frequency = width * 0.04,
31
+ amplitude = 2,
32
+ strokeWidth = 4,
33
+ accentColor = "var(--md-sys-color-primary, #d9ff1f)",
34
+ trackColor = "var(--md-sys-color-secondary-container, #2e4a3d)",
35
+ duration = 1,
36
+ progressDuration = 1,
37
+ progressEasing = "cubic-bezier(0.5,0,0.5,1)",
38
+ shrinkDelay = 1,
39
+ onCollapsed,
40
+ className,
41
+ style,
42
+ }) => {
43
+ const clamped = Math.min(100, Math.max(0, progress));
44
+ const loadedWidth = (clamped / 100) * width;
45
+ const computedWidth = width - loadedWidth;
46
+ const remainingWidth = Math.max(0, computedWidth);
47
+ const freqPerPx = frequency / width; // 12 / 400 = 0.03 — constant wavelength
48
+ const progressTransition = `${progressDuration}s ${progressEasing}`;
49
+
50
+ const complete = clamped >= 100;
51
+
52
+ // Reach 100% → hold shrinkDelay seconds → collapse everything at once.
53
+ const [collapsed, setCollapsed] = React.useState(false);
54
+ React.useEffect(() => {
55
+ if (!complete) {
56
+ setCollapsed(false);
57
+ return;
58
+ }
59
+ const t = setTimeout(() => setCollapsed(true), shrinkDelay * 1000);
60
+ return () => clearTimeout(t);
61
+ }, [complete, shrinkDelay]);
62
+
63
+ // One thickness drives the wave stroke, the track height and the dot, so all
64
+ // three thin to nothing together when `collapsed` flips. amplitude goes with them.
65
+ const thickness = collapsed ? 0 : strokeWidth;
66
+ const waveAmplitude = collapsed ? 0 : amplitude;
67
+ const sizeTween = "var(--transition-expressive-color)"; // shared → all shrink in sync
68
+
69
+ return (
70
+ <div
71
+ className={className}
72
+ style={{
73
+ display: "flex",
74
+ alignItems: "center",
75
+ width,
76
+ height,
77
+ ...style,
78
+ }}
79
+ >
80
+ <div
81
+ style={{
82
+ width: loadedWidth,
83
+ marginRight: !complete ? 8 : 0,
84
+ height,
85
+ flexShrink: 0,
86
+ transition: `width ${progressTransition}, margin ${progressTransition}`,
87
+ }}
88
+ >
89
+ <Sinewave
90
+ fluid
91
+ freqPerPx={freqPerPx}
92
+ height={height}
93
+ amplitude={waveAmplitude}
94
+ strokeWidth={thickness}
95
+ stroke={accentColor}
96
+ animate={true}
97
+ duration={duration}
98
+ style={{ margin: 0, minHeight: height, width: "100%" }}
99
+ />
100
+ </div>
101
+ <div
102
+ onTransitionEnd={(e) => {
103
+ if (collapsed && e.propertyName === "height") onCollapsed?.();
104
+ }}
105
+ style={{
106
+ flexGrow: 0,
107
+ flexShrink: 0,
108
+ flexBasis: remainingWidth,
109
+ opacity: !complete ? 1 : 0,
110
+ minWidth: 0,
111
+ height: thickness,
112
+ background: trackColor,
113
+ borderRadius: thickness,
114
+ transition: `flex-basis ${progressTransition}, height ${sizeTween}, border-radius ${sizeTween}, background ${sizeTween}, opacity 2s ${sizeTween}`,
115
+ }}
116
+ />
117
+ <span
118
+ aria-hidden
119
+ style={{
120
+ flexShrink: 0,
121
+ width: thickness,
122
+ height: thickness,
123
+ borderRadius: "50%",
124
+ position: "absolute",
125
+ opacity: !complete ? 1 : 0,
126
+ marginLeft: width - thickness + 8,
127
+ background: accentColor,
128
+ transition: `width ${sizeTween}, height ${sizeTween}, margin 2s ${sizeTween}, background ${sizeTween}, opacity 2s ${sizeTween}`,
129
+ }}
130
+ />
131
+ </div>
132
+ );
133
+ };
134
+
135
+ export default SinewaveProgress;
@@ -0,0 +1,28 @@
1
+ function Badge({
2
+ children,
3
+ badgeVariant = "error",
4
+ }: {
5
+ badgeVariant?: "error" | "primary" | "secondary" | "tertiary";
6
+ children?: React.ReactNode;
7
+ }) {
8
+ return (
9
+ <span
10
+ style={{
11
+ display: "inline-block",
12
+ backgroundColor: `var(--md-sys-color-on-${badgeVariant}-container)`,
13
+ color: `var(--md-sys-color-${badgeVariant}-container)`,
14
+ borderRadius: 56,
15
+ padding: "8px 14px",
16
+ scale: 0.6,
17
+ fontWeight: 600,
18
+ margin: "-6px -12px",
19
+ textTransform: "uppercase",
20
+ transition: "all var(--transition-expressive-color)",
21
+ }}
22
+ >
23
+ {children}
24
+ </span>
25
+ );
26
+ }
27
+
28
+ export { Badge };
@@ -0,0 +1,7 @@
1
+ declare module "flubber" {
2
+ export function interpolate(
3
+ from: string,
4
+ to: string,
5
+ options?: { maxSegmentLength?: number },
6
+ ): (t: number) => string;
7
+ }
@@ -0,0 +1,88 @@
1
+ export function ArtStationIcon({ size = 24 }: { size?: number }) {
2
+ return (
3
+ <svg
4
+ width={size}
5
+ height={size}
6
+ viewBox="0 0 32 32"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ fill="currentColor"
9
+ aria-hidden="true"
10
+ >
11
+ <path d="M 13.730469 5 L 26 27 L 27.994141 22.488281 C 28.457141 21.562281 28.410094 20.463078 27.871094 19.580078 L 20.095703 6.4355469 C 19.550703 5.5445469 18.580156 5 17.535156 5 L 13.730469 5 z M 11.511719 7.1777344 L 5.6308594 18 L 17.546875 18 L 11.511719 7.1777344 z M 4 21 L 6.171875 25.341797 C 6.679875 26.357797 7.7175156 27 8.8535156 27 L 22.566406 27 L 19.220703 21 L 4 21 z" />
12
+ </svg>
13
+ );
14
+ }
15
+
16
+ export function InstagramIcon({ size = 24 }: { size?: number }) {
17
+ return (
18
+ <svg
19
+ width={size}
20
+ height={size}
21
+ viewBox="3 2.5 19 19"
22
+ fill="none"
23
+ xmlns="http://www.w3.org/2000/svg"
24
+ aria-hidden="true"
25
+ >
26
+ <path
27
+ fillRule="evenodd"
28
+ clipRule="evenodd"
29
+ d="M15.5 5H9.5C7.29086 5 5.5 6.79086 5.5 9V15C5.5 17.2091 7.29086 19 9.5 19H15.5C17.7091 19 19.5 17.2091 19.5 15V9C19.5 6.79086 17.7091 5 15.5 5Z"
30
+ stroke="currentColor"
31
+ strokeWidth="1.3"
32
+ strokeLinecap="round"
33
+ strokeLinejoin="round"
34
+ />
35
+ <path
36
+ fillRule="evenodd"
37
+ clipRule="evenodd"
38
+ d="M12.5 15C10.8431 15 9.5 13.6569 9.5 12C9.5 10.3431 10.8431 9 12.5 9C14.1569 9 15.5 10.3431 15.5 12C15.5 12.7956 15.1839 13.5587 14.6213 14.1213C14.0587 14.6839 13.2956 15 12.5 15Z"
39
+ stroke="currentColor"
40
+ strokeWidth="1.3"
41
+ strokeLinecap="round"
42
+ strokeLinejoin="round"
43
+ />
44
+ <rect
45
+ x="15.5"
46
+ y="9"
47
+ width="2"
48
+ height="2"
49
+ rx="1"
50
+ transform="rotate(-90 15.5 9)"
51
+ fill="currentColor"
52
+ />
53
+ <rect
54
+ x="16"
55
+ y="8.5"
56
+ width="1"
57
+ height="1"
58
+ rx="0.5"
59
+ transform="rotate(-90 16 8.5)"
60
+ stroke="currentColor"
61
+ strokeLinecap="round"
62
+ />
63
+ </svg>
64
+ );
65
+ }
66
+
67
+ export function DiscordIcon({ size = 24 }: { size?: number }) {
68
+ return (
69
+ <svg
70
+ width={size}
71
+ height={size}
72
+ viewBox="9.7 9.6 174.6 172.8"
73
+ xmlns="http://www.w3.org/2000/svg"
74
+ fill="none"
75
+ aria-hidden="true"
76
+ >
77
+ <path
78
+ stroke="currentColor"
79
+ strokeLinecap="round"
80
+ strokeLinejoin="round"
81
+ strokeWidth="11"
82
+ d="m68 138-8 16c-10.19-4.246-20.742-8.492-31.96-15.8-3.912-2.549-6.284-6.88-6.378-11.548-.488-23.964 5.134-48.056 19.369-73.528 1.863-3.334 4.967-5.778 8.567-7.056C58.186 43.02 64.016 40.664 74 39l6 11s6-2 16-2 16 2 16 2l6-11c9.984 1.664 15.814 4.02 24.402 7.068 3.6 1.278 6.704 3.722 8.567 7.056 14.235 25.472 19.857 49.564 19.37 73.528-.095 4.668-2.467 8.999-6.379 11.548-11.218 7.308-21.769 11.554-31.96 15.8l-8-16m-68-8s20 10 40 10 40-10 40-10"
83
+ />
84
+ <ellipse cx="71" cy="101" fill="currentColor" rx="13" ry="15" />
85
+ <ellipse cx="121" cy="101" fill="currentColor" rx="13" ry="15" />
86
+ </svg>
87
+ );
88
+ }
File without changes
@@ -0,0 +1,125 @@
1
+ "use client";
2
+ import React, { useEffect, useState } from "react";
3
+ import styles from "./icon.module.css";
4
+
5
+ interface IconProps {
6
+ id?: string;
7
+ label?: string;
8
+ systemName?: string;
9
+ className?: string;
10
+ direction?: "row" | "column";
11
+ reverse?: boolean;
12
+ iconStyle?: React.CSSProperties;
13
+ labelStyle?: React.CSSProperties;
14
+ iconBodyStyle?: React.CSSProperties;
15
+ }
16
+
17
+ export default function Icon({
18
+ id,
19
+ label,
20
+ systemName,
21
+ className,
22
+ reverse,
23
+ direction,
24
+ iconStyle,
25
+ labelStyle,
26
+ iconBodyStyle,
27
+ }: IconProps) {
28
+ // Keep the last non-empty label mounted so it can animate out
29
+ const [cachedLabel, setCachedLabel] = useState(label);
30
+ useEffect(() => {
31
+ if (label) setCachedLabel(label);
32
+ }, [label]);
33
+
34
+ const hasLabel = !!label;
35
+
36
+ return (
37
+ <div
38
+ className={
39
+ className ? `${className} ${styles.iconBody}` : styles.iconBody
40
+ }
41
+ style={{
42
+ flexDirection:
43
+ direction === "column" ? "column" : reverse ? "row-reverse" : "row",
44
+ display: "inline-flex",
45
+ alignItems: "center",
46
+ justifyContent: "center",
47
+ minWidth: 0,
48
+
49
+ height: "auto",
50
+ padding:
51
+ direction === "column"
52
+ ? 0
53
+ : reverse
54
+ ? "0 2px 0 8px"
55
+ : hasLabel && systemName
56
+ ? "0 8px 0 2px"
57
+ : hasLabel
58
+ ? "0 8px"
59
+ : !hasLabel
60
+ ? 0
61
+ : 0,
62
+ width: "auto",
63
+ gap: direction === "column" ? 0 : !hasLabel || !systemName ? 0 : 4,
64
+ transition: `padding var(--transition-expressive-slow) ${hasLabel ? "0ms" : "0ms"}, gap var(--transition-expressive-slow) ${hasLabel ? "0ms" : "0ms"}`,
65
+ ...iconBodyStyle,
66
+ }}
67
+ >
68
+ {systemName && (
69
+ <span
70
+ id={id}
71
+ className={`${styles.iconStyle} material-symbols-rounded`}
72
+ style={{
73
+ userSelect: "none",
74
+ display: "inline-flex",
75
+ alignItems: "center",
76
+ justifyContent: "center",
77
+ lineHeight: "1",
78
+ verticalAlign: "middle",
79
+ margin: 0,
80
+ padding: 0,
81
+ height: "24px",
82
+ width: "24px",
83
+ ...iconStyle,
84
+ }}
85
+ aria-label={label}
86
+ >
87
+ {systemName}
88
+ </span>
89
+ )}
90
+
91
+ {/* Grid wrapper animates 0fr ↔ 1fr */}
92
+ <div
93
+ style={{
94
+ display: "inline-grid",
95
+ gridTemplateColumns: hasLabel ? "1fr" : "0fr",
96
+ transition: `grid-template-columns var(--transition-expressive-slow) ${hasLabel ? "0ms" : "0ms"}`,
97
+ }}
98
+ >
99
+ <label
100
+ className={`${styles.iconLabel} md-label`}
101
+ style={{
102
+ display: "inline-flex",
103
+ alignItems: "center",
104
+ height: "28px",
105
+ justifyContent: "center",
106
+ cursor: "pointer",
107
+ userSelect: "none",
108
+ whiteSpace: "nowrap",
109
+ paddingBottom: "0.1em",
110
+ overflow: "hidden",
111
+ opacity: hasLabel ? 1 : 0,
112
+ transition: "opacity 0.3s ease",
113
+ ...labelStyle,
114
+ ...(direction === "column"
115
+ ? { fontSize: 12, fontWeight: 400 }
116
+ : {}),
117
+ }}
118
+ htmlFor={id}
119
+ >
120
+ {cachedLabel}
121
+ </label>
122
+ </div>
123
+ </div>
124
+ );
125
+ }
@@ -0,0 +1,58 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+
5
+ export function useMediaQuery(query: string): boolean {
6
+ // Always start with `false` so the server render and the initial client
7
+ // render agree. The real value is synced in useEffect (after hydration),
8
+ // which avoids the server/client HTML mismatch that triggers React's
9
+ // hydration error when the viewport is mobile-sized on first load.
10
+ const [matches, setMatches] = useState(false);
11
+
12
+ useEffect(() => {
13
+ const media = window.matchMedia(query);
14
+ // Sync immediately on mount so the UI snaps to the correct layout
15
+ // after hydration without waiting for a resize event.
16
+ setMatches(media.matches);
17
+
18
+ const update = () => setMatches(media.matches);
19
+
20
+ media.addEventListener("change", update);
21
+ return () => media.removeEventListener("change", update);
22
+ }, [query]);
23
+
24
+ return matches;
25
+ }
26
+
27
+ export function MobileViewProvider({
28
+ children,
29
+ }: {
30
+ children: React.ReactNode;
31
+ }) {
32
+ const isMobile = useMediaQuery("(max-width: 767px)");
33
+
34
+ useEffect(() => {
35
+ const root = document.documentElement;
36
+
37
+ if (isMobile) {
38
+ root.setAttribute("data-mobile-view", "");
39
+ } else {
40
+ root.removeAttribute("data-mobile-view");
41
+ }
42
+ }, [isMobile]);
43
+
44
+ return <>{children}</>;
45
+ }
46
+
47
+ // mobileViewProvider.tsx
48
+ export const BREAKPOINTS = {
49
+ mobile: "(max-width: 767px)",
50
+ tablet: "(max-width: 1024px)",
51
+ } as const;
52
+
53
+ // convenience hook so components do one call instead of two
54
+ export function useBreakpoints() {
55
+ const isMobile = useMediaQuery(BREAKPOINTS.mobile);
56
+ const isTablet = useMediaQuery(BREAKPOINTS.tablet);
57
+ return { isMobile, isTablet };
58
+ }
@@ -0,0 +1,177 @@
1
+ import React, { useRef, useEffect, useCallback } from "react";
2
+
3
+ interface ClickSparkProps {
4
+ sparkColor?: string;
5
+ sparkSize?: number;
6
+ sparkRadius?: number;
7
+ sparkCount?: number;
8
+ duration?: number;
9
+ easing?: "linear" | "ease-in" | "ease-out" | "ease-in-out";
10
+ extraScale?: number;
11
+ children?: React.ReactNode;
12
+ }
13
+
14
+ interface Spark {
15
+ x: number;
16
+ y: number;
17
+ angle: number;
18
+ startTime: number;
19
+ }
20
+
21
+ const ClickSpark: React.FC<ClickSparkProps> = ({
22
+ sparkColor = "#fff",
23
+ sparkSize = 10,
24
+ sparkRadius = 15,
25
+ sparkCount = 8,
26
+ duration = 400,
27
+ easing = "ease-out",
28
+ extraScale = 1.0,
29
+ children
30
+ }) => {
31
+ const canvasRef = useRef<HTMLCanvasElement>(null);
32
+ const sparksRef = useRef<Spark[]>([]);
33
+ const startTimeRef = useRef<number | null>(null);
34
+
35
+ useEffect(() => {
36
+ const canvas = canvasRef.current;
37
+ if (!canvas) return;
38
+
39
+ const parent = canvas.parentElement;
40
+ if (!parent) return;
41
+
42
+ let resizeTimeout: ReturnType<typeof setTimeout>;
43
+
44
+ const resizeCanvas = () => {
45
+ const { width, height } = parent.getBoundingClientRect();
46
+ if (canvas.width !== width || canvas.height !== height) {
47
+ canvas.width = width;
48
+ canvas.height = height;
49
+ }
50
+ };
51
+
52
+ const handleResize = () => {
53
+ clearTimeout(resizeTimeout);
54
+ resizeTimeout = setTimeout(resizeCanvas, 100);
55
+ };
56
+
57
+ const ro = new ResizeObserver(handleResize);
58
+ ro.observe(parent);
59
+
60
+ resizeCanvas();
61
+
62
+ return () => {
63
+ ro.disconnect();
64
+ clearTimeout(resizeTimeout);
65
+ };
66
+ }, []);
67
+
68
+
69
+ const easeFunc = useCallback(
70
+ (t: number) => {
71
+ switch (easing) {
72
+ case "linear":
73
+ return t;
74
+ case "ease-in":
75
+ return t * t;
76
+ case "ease-in-out":
77
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
78
+ default:
79
+ return t * (2 - t);
80
+ }
81
+ },
82
+ [easing]
83
+ );
84
+
85
+ useEffect(() => {
86
+ const canvas = canvasRef.current;
87
+ if (!canvas) return;
88
+ const ctx = canvas.getContext("2d");
89
+ if (!ctx) return;
90
+
91
+ let animationId: number;
92
+
93
+ const draw = (timestamp: number) => {
94
+ if (!startTimeRef.current) {
95
+ startTimeRef.current = timestamp;
96
+ }
97
+ ctx?.clearRect(0, 0, canvas.width, canvas.height);
98
+
99
+ sparksRef.current = sparksRef.current.filter((spark: Spark) => {
100
+ const elapsed = timestamp - spark.startTime;
101
+ if (elapsed >= duration) {
102
+ return false;
103
+ }
104
+
105
+ const progress = elapsed / duration;
106
+ const eased = easeFunc(progress);
107
+
108
+ const distance = eased * sparkRadius * extraScale;
109
+ const lineLength = sparkSize * (1 - eased);
110
+
111
+ const x1 = spark.x + distance * Math.cos(spark.angle);
112
+ const y1 = spark.y + distance * Math.sin(spark.angle);
113
+ const x2 = spark.x + (distance + lineLength) * Math.cos(spark.angle);
114
+ const y2 = spark.y + (distance + lineLength) * Math.sin(spark.angle);
115
+
116
+ ctx.strokeStyle = sparkColor;
117
+ ctx.lineWidth = 2;
118
+ ctx.beginPath();
119
+ ctx.moveTo(x1, y1);
120
+ ctx.lineTo(x2, y2);
121
+ ctx.stroke();
122
+
123
+ return true;
124
+ });
125
+
126
+ animationId = requestAnimationFrame(draw);
127
+ };
128
+
129
+ animationId = requestAnimationFrame(draw);
130
+
131
+ return () => {
132
+ cancelAnimationFrame(animationId);
133
+ };
134
+ }, [sparkColor, sparkSize, sparkRadius, sparkCount, duration, easeFunc, extraScale]);
135
+
136
+ const handleClick = (e: React.MouseEvent<HTMLDivElement>): void => {
137
+ const canvas = canvasRef.current;
138
+ if (!canvas) return;
139
+ const rect = canvas.getBoundingClientRect();
140
+ const x = e.clientX - rect.left;
141
+ const y = e.clientY - rect.top;
142
+
143
+ const now = performance.now();
144
+ const newSparks: Spark[] = Array.from({length: sparkCount}, (_, i) => ({
145
+ x,
146
+ y,
147
+ angle: (2 * Math.PI * i) / sparkCount,
148
+ startTime: now,
149
+ }));
150
+
151
+ sparksRef.current.push(...newSparks);
152
+ };
153
+
154
+ return (
155
+ <div style={{
156
+ width:"100%",
157
+ height:"100%",
158
+ position:"relative"
159
+ }}
160
+ onClick={handleClick}
161
+ >
162
+ <canvas
163
+ ref={canvasRef}
164
+ style={{
165
+ position:"absolute",
166
+ inset:0,
167
+ pointerEvents:"none",
168
+ zIndex: "9999999999",
169
+ mixBlendMode: "difference"
170
+ }}
171
+ />
172
+ {children}
173
+ </div>
174
+ );
175
+ };
176
+
177
+ export default ClickSpark;