@hdcodedev/snowfall 1.0.10 → 1.0.12
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 +27 -21
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +353 -206
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +342 -195
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,13 +12,13 @@ A realistic snowfall effect for React with physics-based accumulation on surface
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
14
|
- **Realistic Physics** - Wind, wobble, and varied snowflake speeds
|
|
15
|
-
- **Surface Accumulation** - Snow naturally
|
|
16
|
-
- **Melting Effect** -
|
|
15
|
+
- **Surface Accumulation** - Snow naturally piles up on elements
|
|
16
|
+
- **Melting Effect** - Gradual melting over time
|
|
17
17
|
- **Border-Radius Aware** - Respects rounded corners
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **Toggleable** -
|
|
21
|
-
- **Responsive** - Adapts to viewport and element
|
|
18
|
+
- **Auto-Detection** - Automatically finds and accumulates on semantic elements
|
|
19
|
+
- **High Performance** - Smooth 60 FPS with adaptive optimizations
|
|
20
|
+
- **Toggleable** - Enable/disable on demand
|
|
21
|
+
- **Responsive** - Adapts to viewport and element changes
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
|
@@ -107,8 +107,6 @@ const customPhysics = {
|
|
|
107
107
|
MAX: 1.6, // Maximum flake radius
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
|
-
|
|
111
|
-
// Then use it in your provider - see API section below
|
|
112
110
|
```
|
|
113
111
|
|
|
114
112
|
## API
|
|
@@ -117,14 +115,10 @@ const customPhysics = {
|
|
|
117
115
|
|
|
118
116
|
Wraps your app to provide snowfall context.
|
|
119
117
|
|
|
120
|
-
**Props:** None
|
|
121
|
-
|
|
122
118
|
### `<Snowfall />`
|
|
123
119
|
|
|
124
120
|
The main snowfall canvas component. Must be used within `SnowfallProvider`.
|
|
125
121
|
|
|
126
|
-
**Props:** None
|
|
127
|
-
|
|
128
122
|
### `useSnowfall()`
|
|
129
123
|
|
|
130
124
|
Hook to access snowfall controls. Must be used within `SnowfallProvider`.
|
|
@@ -145,7 +139,25 @@ Hook to access snowfall controls. Must be used within `SnowfallProvider`.
|
|
|
145
139
|
- The snowfall canvas has `pointer-events: none`, so it won't interfere with user interactions
|
|
146
140
|
- Snow accumulation works best on static or slowly-changing layouts
|
|
147
141
|
- The component uses `'use client'` directive for Next.js 13+ App Router compatibility
|
|
148
|
-
|
|
142
|
+
|
|
143
|
+
## Performance Optimizations
|
|
144
|
+
|
|
145
|
+
Key optimizations for smooth 60 FPS performance:
|
|
146
|
+
|
|
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
|
|
151
|
+
|
|
152
|
+
**Tuning for lower-end devices:**
|
|
153
|
+
```tsx
|
|
154
|
+
const customPhysics = {
|
|
155
|
+
...DEFAULT_PHYSICS,
|
|
156
|
+
MAX_FLAKES: 200,
|
|
157
|
+
COLLISION_CHECK_RATE: 0.1,
|
|
158
|
+
MAX_SURFACES: 15,
|
|
159
|
+
};
|
|
160
|
+
```
|
|
149
161
|
|
|
150
162
|
## Development
|
|
151
163
|
|
|
@@ -171,12 +183,6 @@ Licensed under the [Apache 2.0 License](LICENSE).
|
|
|
171
183
|
|
|
172
184
|
## Contributing
|
|
173
185
|
|
|
174
|
-
Contributions are welcome!
|
|
175
|
-
|
|
176
|
-
## Show Your Support
|
|
177
|
-
|
|
178
|
-
If you like this project, please consider giving it a star on GitHub!
|
|
179
|
-
|
|
180
|
-
## Issues
|
|
186
|
+
Contributions are welcome! If you like this project, please give it a star ⭐
|
|
181
187
|
|
|
182
|
-
Found a bug?
|
|
188
|
+
Found a bug or have a feature request? [Open an issue](https://github.com/hdcodedev/snowfall/issues) on GitHub.
|
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,7 @@ interface PhysicsConfig {
|
|
|
22
22
|
MAX: number;
|
|
23
23
|
};
|
|
24
24
|
MAX_SURFACES: number;
|
|
25
|
+
COLLISION_CHECK_RATE: number;
|
|
25
26
|
}
|
|
26
27
|
declare const DEFAULT_PHYSICS: PhysicsConfig;
|
|
27
28
|
interface PerformanceMetrics {
|
|
@@ -48,9 +49,10 @@ interface SnowfallContextType {
|
|
|
48
49
|
metrics: PerformanceMetrics | null;
|
|
49
50
|
setMetrics: (metrics: PerformanceMetrics) => void;
|
|
50
51
|
}
|
|
51
|
-
declare function SnowfallProvider({ children, initialDebug }: {
|
|
52
|
+
declare function SnowfallProvider({ children, initialDebug, initialEnabled }: {
|
|
52
53
|
children: ReactNode;
|
|
53
54
|
initialDebug?: boolean;
|
|
55
|
+
initialEnabled?: boolean;
|
|
54
56
|
}): react_jsx_runtime.JSX.Element;
|
|
55
57
|
declare function useSnowfall(): SnowfallContextType;
|
|
56
58
|
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ interface PhysicsConfig {
|
|
|
22
22
|
MAX: number;
|
|
23
23
|
};
|
|
24
24
|
MAX_SURFACES: number;
|
|
25
|
+
COLLISION_CHECK_RATE: number;
|
|
25
26
|
}
|
|
26
27
|
declare const DEFAULT_PHYSICS: PhysicsConfig;
|
|
27
28
|
interface PerformanceMetrics {
|
|
@@ -48,9 +49,10 @@ interface SnowfallContextType {
|
|
|
48
49
|
metrics: PerformanceMetrics | null;
|
|
49
50
|
setMetrics: (metrics: PerformanceMetrics) => void;
|
|
50
51
|
}
|
|
51
|
-
declare function SnowfallProvider({ children, initialDebug }: {
|
|
52
|
+
declare function SnowfallProvider({ children, initialDebug, initialEnabled }: {
|
|
52
53
|
children: ReactNode;
|
|
53
54
|
initialDebug?: boolean;
|
|
55
|
+
initialEnabled?: boolean;
|
|
54
56
|
}): react_jsx_runtime.JSX.Element;
|
|
55
57
|
declare function useSnowfall(): SnowfallContextType;
|
|
56
58
|
|