@wojcieh/snow-drift 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +184 -2
- package/dist/snow-drift.cjs +1611 -0
- package/dist/snow-drift.d.ts +58 -0
- package/dist/snow-drift.js +1590 -0
- package/dist/snow-drift.min.js +2 -0
- package/package.json +74 -4
- package/src/physics.js +358 -0
- package/src/snow-drift.d.ts +58 -0
- package/src/snow-drift.js +1574 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wojciech Marusiak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,185 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `<snow-drift>`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@wojcieh/snow-drift"><img src="https://img.shields.io/npm/v/%40wojcieh%2Fsnow-drift?style=for-the-badge&logo=npm&color=cb3837" alt="npm version" /></a>
|
|
5
|
+
<a href="https://wojciehm.github.io/snow-drift/"><img src="https://img.shields.io/badge/Live_Playground-Demo-38bdf8?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Live Playground" /></a>
|
|
6
|
+
<a href="https://github.com/wojciehm/snow-drift/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/wojciehm/snow-drift/ci.yml?branch=main&style=for-the-badge&logo=github&label=Tests" alt="CI Tests" /></a>
|
|
7
|
+
<a href="https://github.com/wojciehm/snow-drift/releases"><img src="https://img.shields.io/github/v/release/wojciehm/snow-drift?style=for-the-badge&logo=github" alt="GitHub Release" /></a>
|
|
8
|
+
<img src="https://img.shields.io/badge/Size-9.3_KB_brotli-0284c7?style=for-the-badge" alt="9.3 KB brotli" />
|
|
9
|
+
<img src="https://img.shields.io/badge/Dependencies-0-16a34a?style=for-the-badge" alt="Zero Dependencies" />
|
|
10
|
+
<a href="LICENSE"><img src="https://img.shields.io/github/license/wojciehm/snow-drift?style=for-the-badge" alt="MIT License" /></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
Zero-dependency **`<snow-drift>` Web Component** (`9.3 KB` brotli / `10.4 KB` gzip) that brings physical winter snowfall and 1D heightmap snowbanks to real DOM elements. Drop a single HTML tag into Hugo, Astro, WordPress, Ghost, React, Vue, Next.js, or plain HTML.
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://wojciehm.github.io/snow-drift/">
|
|
17
|
+
<img src="assets/snow-drift-preview.webp" alt="snow-drift interactive playground showing circular avatar snow cap, glyph-contour headline drifts, and staggered card snowbanks" width="100%" />
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<strong><a href="https://wojciehm.github.io/snow-drift/">Try the Interactive Playground</a></strong> · Live in production on <a href="https://www.wojcieh.net">wojcieh.net</a> & <a href="https://www.marusiak.pl">marusiak.pl</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## What Makes `<snow-drift>` Different
|
|
28
|
+
|
|
29
|
+
1. **Automatic CSS `border-radius` Geometry:** Reads `getComputedStyle(el)` automatically. Flat cards get smooth snowbanks, pill buttons get rounded corner tapers, and circular avatars (`border-radius: 50%` or `9999px`) receive a true circular `sqrt(R² - x²)` snow cap that sheds snow along steep flanks.
|
|
30
|
+
2. **Glyph-Contour Typography (`text-surfaces`):** Scans real character bounding boxes and Canvas `measureText()` ascender metrics so snow settles along individual word contours, resting higher on capitals and ascenders than lowercase x-height.
|
|
31
|
+
3. **Wind Gusts & Chain-Reaction Avalanches:** Snowfall arrives in organic density waves with periodic directional wind gusts. When a snowbank exceeds its slope stability threshold (or gets pushed by a gust), a slab shears off, slumps naturally, and tumbles down onto lower DOM cards.
|
|
32
|
+
4. **Tactile Pointer Snow-Clearing:** Sweeping a mouse or finger repels airborne flakes and brushes settled snow off cards, circular badges, headlines, and the viewport floor with subtle snow spray.
|
|
33
|
+
5. **100/100 Lighthouse & SSR Safe:** Boots inside `requestIdleCallback`, renders on a single `pointer-events: none` Shadow DOM `<canvas>` (`0 CLS`), tracks `position: sticky` without scroll layout thrashing, pauses when `document.hidden` is `true` (`0%` background CPU), respects `prefers-reduced-motion`, and imports cleanly in Node.js SSR.
|
|
34
|
+
|
|
35
|
+
| Package | License | Framework | DOM Drifts | Circular `border-radius` Arcs | Headline Glyph Contours | Chain Avalanches |
|
|
36
|
+
| :--- | :--- | :--- | :---: | :---: | :---: | :---: |
|
|
37
|
+
| **`@wojcieh/snow-drift`** | **MIT** | **Any (Web Component)** | ✅ | ✅ | ✅ | ✅ |
|
|
38
|
+
| `@zachleat/snow-fall` | MIT | Any (Web Component) | ➖ | ➖ | ➖ | ➖ |
|
|
39
|
+
| `@hdcodedev/snowfall` | MIT | React only | ✅ | ➖ | ➖ | ➖ |
|
|
40
|
+
| `@elementalfx/weather` | MIT | Vanilla JS (multi-FX) | ✅ | ➖ | ➖ | ➖ |
|
|
41
|
+
| `@fluritheme/fluri` | Proprietary | Commercial script | ✅ | ➖ | ➖ | ➖ |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quickstart
|
|
46
|
+
|
|
47
|
+
### 1. CDN / Static Sites (Hugo, Astro, WordPress, Ghost, Plain HTML)
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script type="module" src="https://unpkg.com/@wojcieh/snow-drift"></script>
|
|
51
|
+
|
|
52
|
+
<snow-drift
|
|
53
|
+
surfaces="article, .card, .avatar"
|
|
54
|
+
text-surfaces="h1"
|
|
55
|
+
mode="normal"
|
|
56
|
+
controls
|
|
57
|
+
></snow-drift>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Prefer a classic `<script defer>` tag via jsDelivr?
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<script defer src="https://cdn.jsdelivr.net/npm/@wojcieh/snow-drift@1/dist/snow-drift.min.js"></script>
|
|
64
|
+
<snow-drift surfaces=".card, .avatar" controls></snow-drift>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. npm / Bundlers (Vite, Next.js, Astro, SvelteKit, Nuxt, React, Vue)
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install @wojcieh/snow-drift
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import "@wojcieh/snow-drift";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Then render `<snow-drift>` anywhere in your layout:
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<snow-drift surfaces=".card, .bento-tile, .avatar" text-surfaces=".hero-title"></snow-drift>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. Binding Your Own Navbar or Sidebar Toggle Button
|
|
84
|
+
|
|
85
|
+
Omit `controls` if you want to use your own site button instead of the built-in floating pill. Add `data-snow-drift-toggle` to any button or link (and `data-snow-drift-label` to update the text automatically as the user cycles `Normal -> Blizzard -> Light -> Off`):
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<button type="button" data-snow-drift-toggle>
|
|
89
|
+
❄️ <span data-snow-drift-label>Snow: Normal</span>
|
|
90
|
+
</button>
|
|
91
|
+
|
|
92
|
+
<snow-drift surfaces="article, .widget, .site-logo"></snow-drift>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`<snow-drift>` automatically sets `aria-pressed="true|false"`, `data-snow-active="true|false"`, and `data-snow-mode="normal|blizzard|light|off"` on bound toggle elements so you can style active states (for example spinning your snowflake icon in `blizzard` mode).
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## HTML Attributes
|
|
100
|
+
|
|
101
|
+
| Attribute | Default | Description |
|
|
102
|
+
| :--- | :--- | :--- |
|
|
103
|
+
| `mode` | `"normal"` | Initial weather preset: `"normal"`, `"blizzard"`, `"light"`, or `"off"`. Overridden by saved `localStorage` preference when `storage-key` is enabled. |
|
|
104
|
+
| `surfaces` | `""` | CSS selector for cards, containers, pills, and avatars where snowdrifts accumulate. |
|
|
105
|
+
| `text-surfaces` | `""` | CSS selector for headings or badges where snow settles along per-word glyph contours. |
|
|
106
|
+
| `floor` | `"true"` | Accumulate a snowbank along the bottom edge of the viewport (`"true"` or `"false"`). |
|
|
107
|
+
| `bury` | `"blizzard"` | Allow the floor snowbank to grow uncapped and bury the viewport: `"blizzard"` (only during Blizzard mode), `"true"` (always), or `"false"` (capped at ~68px). |
|
|
108
|
+
| `avalanches` | `"true"` | Enable automatic wind and overload slab avalanches (`"true"` or `"false"`). |
|
|
109
|
+
| `interactive` | `"true"` | Enable pointer flake repulsion and cursor snowbank brushing (`"true"` or `"false"`). |
|
|
110
|
+
| `controls` | *unset* | Boolean attribute. Renders the built-in floating toggle pill inside Shadow DOM. |
|
|
111
|
+
| `controls-position` | `"bottom-right"` | Corner for the built-in pill: `"bottom-right"`, `"bottom-left"`, `"top-right"`, or `"top-left"`. |
|
|
112
|
+
| `toggle-selector` | `""` | Additional CSS selector for custom toggle buttons in your page DOM (`[data-snow-drift-toggle]` is bound automatically). |
|
|
113
|
+
| `theme` | `"auto"` | `"auto"`, `"dark"`, or `"light"`. In `"auto"` mode, observes root theme attributes/classes (`data-theme`, `data-scheme`, `.dark`, `.light`), background luminance, and `prefers-color-scheme`. |
|
|
114
|
+
| `density` | `"1"` | Multiplier (`0.15` to `4`) applied to viewport-scaled snowflake count. |
|
|
115
|
+
| `wind` | `"1"` | Multiplier (`0` to `4`) applied to wind gust intensity. |
|
|
116
|
+
| `preseed` | *unset* | Optional fraction (`0.05` to `1`, e.g. `preseed="0.5"`) to pre-populate snowdrifts immediately on load. |
|
|
117
|
+
| `z-index` | `"9990"` | CSS `z-index` for the fixed canvas overlay. |
|
|
118
|
+
| `storage-key` | `"snow-drift-mode"` | `localStorage` key used to persist user mode selection. Pass `"none"` to disable persistence. |
|
|
119
|
+
| `respect-reduced-motion` | `"true"` | Defaults to `"off"` when `prefers-reduced-motion: reduce` matches (unless the user explicitly selects an active mode). |
|
|
120
|
+
|
|
121
|
+
### Per-Element HTML Overrides
|
|
122
|
+
|
|
123
|
+
You can fine-tune individual matched elements in your markup:
|
|
124
|
+
|
|
125
|
+
- `data-snow-shape="circle | pill | flat"`: Override automatic `border-radius` shape classification.
|
|
126
|
+
- `data-snow-max-height="16"`: Cap maximum snowdrift height (in CSS pixels) on a specific element.
|
|
127
|
+
- `data-snow-ignore`: Exclude a matched element from snow accumulation.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## JavaScript API & Events
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
const snow = document.querySelector("snow-drift");
|
|
135
|
+
|
|
136
|
+
// Switch mode programmatically ("normal" | "blizzard" | "light" | "off")
|
|
137
|
+
snow.mode = "blizzard";
|
|
138
|
+
|
|
139
|
+
// Cycle to the next mode in sequence
|
|
140
|
+
snow.cycleMode();
|
|
141
|
+
|
|
142
|
+
// Pre-pack snowdrifts across visible surfaces (0..1)
|
|
143
|
+
snow.seedDrifts(0.75);
|
|
144
|
+
|
|
145
|
+
// Trigger an avalanche on the fullest surface, a specific element, or "all"
|
|
146
|
+
snow.triggerAvalanche();
|
|
147
|
+
snow.triggerAvalanche(document.querySelector(".avatar"));
|
|
148
|
+
snow.triggerAvalanche("all");
|
|
149
|
+
|
|
150
|
+
// Clear all accumulated drifts immediately
|
|
151
|
+
snow.clearDrifts();
|
|
152
|
+
|
|
153
|
+
// Re-scan DOM surfaces after dynamic SPA route or layout changes
|
|
154
|
+
snow.refresh();
|
|
155
|
+
|
|
156
|
+
// Listen for mode changes and avalanches
|
|
157
|
+
snow.addEventListener("snow-drift:change", (e) => {
|
|
158
|
+
console.log("Mode:", e.detail.mode, "Active:", e.detail.active);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
snow.addEventListener("snow-drift:avalanche", (e) => {
|
|
162
|
+
console.log("Avalanche sheared off:", e.detail.element, e.detail.shape);
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
TypeScript declarations (`dist/snow-drift.d.ts`) are bundled out of the box, including `HTMLElementTagNameMap` and typed `CustomEvent` definitions.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Development & Tests
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
git clone https://github.com/wojciehm/snow-drift.git
|
|
174
|
+
cd snow-drift
|
|
175
|
+
npm install
|
|
176
|
+
npm test
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Open `demo/index.html` over any local static server (for example `npx serve demo` or `python3 -m http.server --directory demo 8080`) to experiment with the interactive physics bench.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT License. Copyright (c) 2026 [Wojciech Marusiak](https://www.wojcieh.net).
|