@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 +24 -27
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1181
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1151
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
- `<header>` and `role="banner"`
|
|
81
|
-
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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; //
|
|
130
|
-
toggleSnow: () => void; //
|
|
131
|
-
physicsConfig: PhysicsConfig; // Current
|
|
132
|
-
updatePhysicsConfig: (config: Partial<PhysicsConfig>) => void; //
|
|
133
|
-
resetPhysics: () => void; //
|
|
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
|
-
-
|
|
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
|
-
- **
|
|
148
|
-
- **Adaptive Spawn Rate**: Automatically reduces snowflake
|
|
149
|
-
- **
|
|
150
|
-
- **
|
|
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
|
-
**
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|