@hdcodedev/snowfall 1.0.3 → 1.0.5

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 CHANGED
@@ -1,7 +1,14 @@
1
- # @hdcodedev/snowfall
1
+ # [@hdcodedev/snowfall](https://next-snowfall.vercel.app)
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@hdcodedev/snowfall.svg)](https://www.npmjs.com/package/@hdcodedev/snowfall)
4
+
2
5
 
3
6
  A realistic snowfall effect for React with physics-based accumulation on surfaces. Features melting, wind, and smart surface detection.
4
7
 
8
+ ![ScreenRecording2025-12-23at00 07 30-ezgif com-optimize](https://github.com/user-attachments/assets/49c4a537-7f04-4043-806e-21478f419dd7)
9
+
10
+
11
+
5
12
  ## Features
6
13
 
7
14
  - **Realistic Physics** - Wind, wobble, and varied snowflake speeds
@@ -39,39 +46,69 @@ export default function App() {
39
46
  <SnowfallProvider>
40
47
  <Snowfall />
41
48
 
42
- {/* Auto-detected: Semantic tags */}
49
+ {/* Auto-detected: Headers accumulate snow on BOTTOM */}
43
50
  <header>
44
51
  <h1>My Site</h1>
45
52
  </header>
46
53
 
54
+ {/* Auto-detected: Footers accumulate snow on TOP (natural piling) */}
55
+ <footer>
56
+ <p>© 2025</p>
57
+ </footer>
58
+
47
59
  {/* Manual: Force accumulation on any element */}
48
60
  <div data-snowfall="top">
49
61
  <h2>Custom Element</h2>
50
62
  </div>
63
+
64
+ {/* Disable accumulation on specific elements */}
65
+ <div data-snowfall="ignore">
66
+ <p>No snow here</p>
67
+ </div>
51
68
  </SnowfallProvider>
52
69
  );
53
70
  }
54
71
  ```
55
72
 
73
+ ### Surface Types
74
+
75
+ - **`data-snowfall="top"`** (default for most elements): Snow accumulates on the top edge, piling downward
76
+ - **`data-snowfall="bottom"`** (default for `<header>` tags): Snow accumulates on the bottom edge
77
+ - **`data-snowfall="ignore"`**: Prevents snow accumulation on the element
78
+
79
+ By default:
80
+ - `<header>` and `role="banner"` → Bottom accumulation
81
+ - `<footer>` and other elements → Top accumulation (natural piling)
82
+
56
83
  ## Customization
57
84
 
58
- The snowfall physics can be customized by modifying the `SNOW_PHYSICS` constant:
85
+ You can customize physics via the `SnowfallProvider`:
59
86
 
60
- ```typescript
61
- const SNOW_PHYSICS = {
87
+ ```tsx
88
+ import { SnowfallProvider, DEFAULT_PHYSICS } from '@hdcodedev/snowfall';
89
+
90
+ const customPhysics = {
91
+ ...DEFAULT_PHYSICS,
62
92
  MAX_FLAKES: 500, // Maximum number of snowflakes
63
93
  MELT_SPEED: 0.00005, // How fast snow melts (lower = lasts longer)
94
+ WIND_STRENGTH: 1.5, // Wind intensity
64
95
  ACCUMULATION: {
65
- SIDE_RATE: 1.2, // Accumulation rate on sides
66
- TOP_CARD_RATE: 1.9, // Accumulation rate on card tops
67
- TOP_HEADER_RATE: 1.2, // Accumulation rate on header tops
96
+ SIDE_RATE: 1.0, // Accumulation rate on sides
97
+ TOP_RATE: 5.0, // Accumulation rate on top surfaces
98
+ BOTTOM_RATE: 5.0, // Accumulation rate on bottom surfaces (headers)
68
99
  },
69
100
  MAX_DEPTH: {
70
- CARD_TOP: 50, // Max snow height on cards (px)
71
- HEADER_TOP: 25, // Max snow height on headers (px)
72
- CARD_SIDE: 8, // Max snow width on card sides (px)
101
+ TOP: 100, // Max snow height on top surfaces (px)
102
+ BOTTOM: 50, // Max snow height on bottom surfaces (px)
103
+ SIDE: 20, // Max snow width on sides (px)
104
+ },
105
+ FLAKE_SIZE: {
106
+ MIN: 0.5, // Minimum flake radius
107
+ MAX: 1.6, // Maximum flake radius
73
108
  }
74
109
  };
110
+
111
+ // Then use it in your provider - see API section below
75
112
  ```
76
113
 
77
114
  ## API
@@ -95,15 +132,14 @@ Hook to access snowfall controls. Must be used within `SnowfallProvider`.
95
132
  **Returns:**
96
133
  ```typescript
97
134
  {
98
- isEnabled: boolean; // Current enabled state
99
- toggleSnow: () => void; // Function to toggle snow on/off
135
+ isEnabled: boolean; // Current enabled state
136
+ toggleSnow: () => void; // Function to toggle snow on/off
137
+ physicsConfig: PhysicsConfig; // Current physics configuration
138
+ updatePhysicsConfig: (config: Partial<PhysicsConfig>) => void; // Update physics
139
+ resetPhysics: () => void; // Reset to default physics
100
140
  }
101
141
  ```
102
142
 
103
- ## Demo
104
-
105
- Check out the [live demo](https://snowfall-2026.vercel.app)
106
-
107
143
  ## Tips
108
144
 
109
145
  - The snowfall canvas has `pointer-events: none`, so it won't interfere with user interactions
package/dist/index.d.mts CHANGED
@@ -23,16 +23,35 @@ interface PhysicsConfig {
23
23
  };
24
24
  }
25
25
  declare const DEFAULT_PHYSICS: PhysicsConfig;
26
+ interface PerformanceMetrics {
27
+ fps: number;
28
+ frameTime: number;
29
+ scanTime: number;
30
+ rectUpdateTime: number;
31
+ surfaceCount: number;
32
+ flakeCount: number;
33
+ maxFlakes: number;
34
+ rafGap: number;
35
+ clearTime: number;
36
+ physicsTime: number;
37
+ drawTime: number;
38
+ }
26
39
  interface SnowfallContextType {
27
40
  isEnabled: boolean;
28
41
  toggleSnow: () => void;
29
42
  physicsConfig: PhysicsConfig;
30
43
  updatePhysicsConfig: (config: Partial<PhysicsConfig>) => void;
31
44
  resetPhysics: () => void;
45
+ debugMode: boolean;
46
+ toggleDebug: () => void;
47
+ metrics: PerformanceMetrics | null;
48
+ setMetrics: (metrics: PerformanceMetrics) => void;
32
49
  }
33
50
  declare function SnowfallProvider({ children }: {
34
51
  children: ReactNode;
35
52
  }): react_jsx_runtime.JSX.Element;
36
53
  declare function useSnowfall(): SnowfallContextType;
37
54
 
38
- export { DEFAULT_PHYSICS, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };
55
+ declare function DebugPanel(): react_jsx_runtime.JSX.Element | null;
56
+
57
+ export { DEFAULT_PHYSICS, DebugPanel, type PerformanceMetrics, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };
package/dist/index.d.ts CHANGED
@@ -23,16 +23,35 @@ interface PhysicsConfig {
23
23
  };
24
24
  }
25
25
  declare const DEFAULT_PHYSICS: PhysicsConfig;
26
+ interface PerformanceMetrics {
27
+ fps: number;
28
+ frameTime: number;
29
+ scanTime: number;
30
+ rectUpdateTime: number;
31
+ surfaceCount: number;
32
+ flakeCount: number;
33
+ maxFlakes: number;
34
+ rafGap: number;
35
+ clearTime: number;
36
+ physicsTime: number;
37
+ drawTime: number;
38
+ }
26
39
  interface SnowfallContextType {
27
40
  isEnabled: boolean;
28
41
  toggleSnow: () => void;
29
42
  physicsConfig: PhysicsConfig;
30
43
  updatePhysicsConfig: (config: Partial<PhysicsConfig>) => void;
31
44
  resetPhysics: () => void;
45
+ debugMode: boolean;
46
+ toggleDebug: () => void;
47
+ metrics: PerformanceMetrics | null;
48
+ setMetrics: (metrics: PerformanceMetrics) => void;
32
49
  }
33
50
  declare function SnowfallProvider({ children }: {
34
51
  children: ReactNode;
35
52
  }): react_jsx_runtime.JSX.Element;
36
53
  declare function useSnowfall(): SnowfallContextType;
37
54
 
38
- export { DEFAULT_PHYSICS, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };
55
+ declare function DebugPanel(): react_jsx_runtime.JSX.Element | null;
56
+
57
+ export { DEFAULT_PHYSICS, DebugPanel, type PerformanceMetrics, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };