@hdcodedev/snowfall 1.0.13 → 1.0.15

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
@@ -5,8 +5,7 @@
5
5
 
6
6
  A realistic snowfall effect for React with physics-based accumulation on surfaces. Features melting, wind, and smart surface detection.
7
7
 
8
- ![ScreenRecording2025-12-23at00 07 30-ezgif com-optimize](https://github.com/user-attachments/assets/49c4a537-7f04-4043-806e-21478f419dd7)
9
-
8
+ <img width="1391" height="843" alt="Screenshot 2026-03-29 at 19 18 18" src="https://github.com/user-attachments/assets/b7a420c6-0fb2-4255-afec-29e60444d198" />
10
9
 
11
10
 
12
11
  ## Features
@@ -34,7 +33,7 @@ yarn add @hdcodedev/snowfall
34
33
 
35
34
  ## Quick Start
36
35
 
37
- Snowfall automatically detects semantic tags (like `<header>`) and styled elements. You can also force accumulation manually.
36
+ Snowfall automatically detects HTML elements like `<header>` and `<footer>` and accumulates snow on their edges. You can also mark any element manually.
38
37
 
39
38
  ### Basic Usage
40
39
 
@@ -72,17 +71,15 @@ export default function App() {
72
71
 
73
72
  ### Surface Types
74
73
 
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
74
+ Use the `data-snowfall` attribute to control where snow accumulates on an element:
78
75
 
79
- By default:
80
- - `<header>` and `role="banner"` → Bottom accumulation
81
- - `<footer>` and other elements Top accumulation (natural piling)
76
+ - **`data-snowfall="top"`** — Snow piles up on the top edge (default for `<footer>` and most elements)
77
+ - **`data-snowfall="bottom"`** — Snow hangs from the bottom edge (default for `<header>` and `role="banner"`)
78
+ - **`data-snowfall="ignore"`** No snow accumulates on this element
82
79
 
83
80
  ## Customization
84
81
 
85
- You can customize physics via the `SnowfallProvider`:
82
+ You can customize how snow behaves via the `SnowfallProvider`:
86
83
 
87
84
  ```tsx
88
85
  import { SnowfallProvider, DEFAULT_PHYSICS } from '@hdcodedev/snowfall';
@@ -113,30 +110,30 @@ const customPhysics = {
113
110
 
114
111
  ### `<SnowfallProvider>`
115
112
 
116
- Wraps your app to provide snowfall context.
113
+ Wraps your app to manage snowfall state. Place it at the root of your component tree.
117
114
 
118
115
  ### `<Snowfall />`
119
116
 
120
- The main snowfall canvas component. Must be used within `SnowfallProvider`.
117
+ Renders the snowfall canvas. Must be placed inside `SnowfallProvider`. Snow accumulates on detected elements automatically.
121
118
 
122
119
  ### `useSnowfall()`
123
120
 
124
- Hook to access snowfall controls. Must be used within `SnowfallProvider`.
121
+ Hook to control snowfall at runtime. Must be used inside `SnowfallProvider`.
125
122
 
126
123
  **Returns:**
127
124
  ```typescript
128
125
  {
129
- isEnabled: boolean; // Current enabled state
130
- toggleSnow: () => void; // Function to toggle snow on/off
131
- physicsConfig: PhysicsConfig; // Current physics configuration
132
- updatePhysicsConfig: (config: Partial<PhysicsConfig>) => void; // Update physics
133
- resetPhysics: () => void; // Reset to default physics
126
+ isEnabled: boolean; // Whether snow is currently falling
127
+ toggleSnow: () => void; // Start or stop the snowfall
128
+ physicsConfig: PhysicsConfig; // Current snow behavior settings
129
+ updatePhysicsConfig: (config: Partial<PhysicsConfig>) => void; // Change settings at runtime
130
+ resetPhysics: () => void; // Restore default settings
134
131
  }
135
132
  ```
136
133
 
137
134
  ## Tips
138
135
 
139
- - The snowfall canvas has `pointer-events: none`, so it won't interfere with user interactions
136
+ - Snow is drawn on a transparent layer that doesn't block clicks, scrolling, or other interactions
140
137
  - Snow accumulation works best on static or slowly-changing layouts
141
138
  - The component uses `'use client'` directive for Next.js 13+ App Router compatibility
142
139
 
@@ -144,18 +141,18 @@ Hook to access snowfall controls. Must be used within `SnowfallProvider`.
144
141
 
145
142
  Key optimizations for smooth 60 FPS performance:
146
143
 
147
- - **Probabilistic Collision Detection**: Only 30% of snowflakes check collisions per frame (configurable via `COLLISION_CHECK_RATE`), significantly reducing CPU load while maintaining visual quality
148
- - **Adaptive Spawn Rate**: Automatically reduces snowflake spawning when FPS drops below 40 to prevent performance degradation
149
- - **Viewport Culling**: Only renders accumulation for visible elements
150
- - **Zero-allocation FPS Tracking**: Uses a second-bucket approach to eliminate per-frame memory allocations
144
+ - **Smart Collision Checks**: Only 30% of snowflakes check for collisions each frame (configurable via `COLLISION_CHECK_RATE`), reducing CPU load while maintaining visual quality
145
+ - **Adaptive Spawn Rate**: Automatically reduces snowflake count when FPS drops below 40
146
+ - **Offscreen Skipping**: Only processes accumulation for elements visible in the viewport
147
+ - **Efficient FPS Tracking**: Uses a second-bucket approach to avoid per-frame memory allocations
151
148
 
152
- **Tuning for lower-end devices:**
149
+ **For slower devices, reduce the load:**
153
150
  ```tsx
154
151
  const customPhysics = {
155
152
  ...DEFAULT_PHYSICS,
156
- MAX_FLAKES: 200,
157
- COLLISION_CHECK_RATE: 0.1,
158
- MAX_SURFACES: 15,
153
+ MAX_FLAKES: 200, // Fewer snowflakes
154
+ COLLISION_CHECK_RATE: 0.1, // Check fewer flakes per frame
155
+ MAX_SURFACES: 15, // Fewer surfaces to track
159
156
  };
160
157
  ```
161
158
 
package/dist/index.d.mts CHANGED
@@ -23,6 +23,10 @@ interface PhysicsConfig {
23
23
  };
24
24
  MAX_SURFACES: number;
25
25
  COLLISION_CHECK_RATE: number;
26
+ /**
27
+ * Optional cap for render DPR. Lower values reduce GPU load on high-DPI displays.
28
+ */
29
+ MAX_RENDER_DPR?: number;
26
30
  }
27
31
  declare const DEFAULT_PHYSICS: PhysicsConfig;
28
32
  interface PerformanceMetrics {
@@ -56,8 +60,4 @@ declare function SnowfallProvider({ children, initialDebug, initialEnabled }: {
56
60
  }): react_jsx_runtime.JSX.Element;
57
61
  declare function useSnowfall(): SnowfallContextType;
58
62
 
59
- declare function DebugPanel({ defaultOpen }: {
60
- defaultOpen?: boolean;
61
- }): react_jsx_runtime.JSX.Element | null;
62
-
63
- export { DEFAULT_PHYSICS, DebugPanel, type PerformanceMetrics, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };
63
+ export { DEFAULT_PHYSICS, type PerformanceMetrics, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };
package/dist/index.d.ts CHANGED
@@ -23,6 +23,10 @@ interface PhysicsConfig {
23
23
  };
24
24
  MAX_SURFACES: number;
25
25
  COLLISION_CHECK_RATE: number;
26
+ /**
27
+ * Optional cap for render DPR. Lower values reduce GPU load on high-DPI displays.
28
+ */
29
+ MAX_RENDER_DPR?: number;
26
30
  }
27
31
  declare const DEFAULT_PHYSICS: PhysicsConfig;
28
32
  interface PerformanceMetrics {
@@ -56,8 +60,4 @@ declare function SnowfallProvider({ children, initialDebug, initialEnabled }: {
56
60
  }): react_jsx_runtime.JSX.Element;
57
61
  declare function useSnowfall(): SnowfallContextType;
58
62
 
59
- declare function DebugPanel({ defaultOpen }: {
60
- defaultOpen?: boolean;
61
- }): react_jsx_runtime.JSX.Element | null;
62
-
63
- export { DEFAULT_PHYSICS, DebugPanel, type PerformanceMetrics, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };
63
+ export { DEFAULT_PHYSICS, type PerformanceMetrics, type PhysicsConfig, Snowfall, SnowfallProvider, useSnowfall };