winter-fx 0.0.0-stage → 0.2.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 yers
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,140 @@
1
- # Temporary Holding Version
1
+ # winter-fx
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Falling snow, a twinkling garland and frost on the screen edges, for any web page. Each effect is one function call, works with any framework, and is 1.5 to 3 kB minified and compressed. No dependencies.
4
+
5
+ Try every setting on the [demo page](https://y3rsss.github.io/winter-fx/).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install winter-fx
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```js
16
+ import { snow, garland, frost } from "winter-fx";
17
+
18
+ const stopSnow = snow();
19
+ const stopGarland = garland();
20
+ const stopFrost = frost();
21
+
22
+ // later, to remove the snow and everything it added
23
+ stopSnow();
24
+ ```
25
+
26
+ Every effect returns a function that removes it. Calling that function again does nothing. Calling an effect twice adds two separate layers, each with its own stop function.
27
+
28
+ The effects sit over the page in a fixed layer. Clicks go through to the page underneath, and screen readers skip them.
29
+
30
+ ## Effects
31
+
32
+ All settings are optional. Every effect also takes `zIndex`, any integer, which defaults to `9999`.
33
+
34
+ ### snow
35
+
36
+ Snowflakes falling over the page, in three depth layers.
37
+
38
+ ```js
39
+ snow({ color: "#ffffff", amount: 2, speed: 0.5, shape: "crystal", size: 2 });
40
+ ```
41
+
42
+ | Setting | Default | Valid values |
43
+ | -------- | -------------------------------- | ---------------------------------------------------------------------- |
44
+ | `color` | `"light-dark(#7f9cc0, #ffffff)"` | any CSS color |
45
+ | `amount` | `1` | a number greater than 0 and at most 3. Multiplies the number of flakes |
46
+ | `speed` | `1` | a number greater than 0 and at most 5. Multiplies the falling speed |
47
+ | `shape` | `"dot"` | `"dot"` or `"crystal"` |
48
+ | `size` | `1` | a number greater than 0 and at most 3. Multiplies how big flakes are |
49
+
50
+ With `shape: "crystal"`, each flake is a thin six-armed crystal or a small clump, as wide as the dot it replaces, that sways and turns as it falls. Bigger crystals sway wider. Crystals take 2 to 3 times as long to draw as dots, and about 4 times at size 3, where more of them are big enough to show their details.
51
+
52
+ ### garland
53
+
54
+ A string of lights across the top of the page. Each bulb twinkles on its own timing.
55
+
56
+ ```js
57
+ garland({ colors: ["#ff4d4d", "#ffcc33"] });
58
+ ```
59
+
60
+ | Setting | Default | Valid values |
61
+ | -------- | ---------------------------------------------- | -------------------------------------------------------- |
62
+ | `colors` | `["#ff4d4d", "#ffcc33", "#4cd964", "#4da6ff"]` | a list of at least one CSS color. Bulbs cycle through it |
63
+
64
+ ### frost
65
+
66
+ Ice crystals that grow in from the edges of the screen and leave the middle clear.
67
+
68
+ ```js
69
+ frost({ size: 1.5 });
70
+ ```
71
+
72
+ | Setting | Default | Valid values |
73
+ | ------- | -------------------------------- | ------------------------------------------------------------------------------- |
74
+ | `color` | `"light-dark(#6f93bd, #e4efff)"` | any CSS color |
75
+ | `size` | `1` | a number greater than 0 and at most 2. Multiplies how far the crystals reach in |
76
+
77
+ ### Colors
78
+
79
+ Colors can be any CSS color, including variables like `"var(--brand)"`. The effects follow changes to them right away.
80
+
81
+ The default colors use `light-dark()`, which picks the light or dark value from the page's `color-scheme`. A dark site that doesn't set `color-scheme: dark` gets the light values, so set it or pass your own color.
82
+
83
+ ## Wrong settings
84
+
85
+ A bad setting throws as soon as the effect is called, with a message that names the effect, the setting and the value it got:
86
+
87
+ ```text
88
+ winter-fx: snow() setting "amount" must be a number greater than 0 and at most 3, got -1
89
+ ```
90
+
91
+ A setting of the wrong type, or one the effect doesn't know, throws a `TypeError`. A value out of range throws a `RangeError`. A setting left out, `undefined` or `null` gets its default.
92
+
93
+ ## Frameworks and server rendering
94
+
95
+ Importing winter-fx never touches the page, so it's safe in server-rendered apps like Next.js, Nuxt and Astro. Call the effects only in the browser, after the page has loaded. Called on the server, they throw.
96
+
97
+ Start an effect when your component mounts, and call its stop function when it unmounts. In React, the stop function is the effect's cleanup:
98
+
99
+ ```jsx
100
+ import { useEffect } from "react";
101
+ import { snow } from "winter-fx";
102
+
103
+ export function Snow() {
104
+ useEffect(() => snow(), []);
105
+ return null;
106
+ }
107
+ ```
108
+
109
+ Sites that replace the page's `<body>` without a reload, like Turbo, remove the effects with it. Call the stop function before the swap and start the effect again after it.
110
+
111
+ ## Script tag
112
+
113
+ Sites without a build step can load winter-fx from a CDN:
114
+
115
+ ```html
116
+ <script type="module">
117
+ import { snow } from "https://cdn.jsdelivr.net/npm/winter-fx@0.2/+esm";
118
+ snow();
119
+ </script>
120
+ ```
121
+
122
+ ## Reduced motion
123
+
124
+ Visitors can ask their system for less motion. The effects follow that setting, and change while the page is open if it changes. No setting can turn this off.
125
+
126
+ | Effect | With reduced motion on |
127
+ | ------- | -------------------------------------------------------- |
128
+ | snow | Shows nothing, and comes back when the setting turns off |
129
+ | garland | Bulbs stay lit without twinkling |
130
+ | frost | Appears at once, without growing in |
131
+
132
+ ## Browser support
133
+
134
+ Chrome and Edge 123, Firefox 120 and Safari 17.5, and later versions. These are the first with `light-dark()`, which lets the default colors follow dark mode.
135
+
136
+ Older versions also worked when this release was checked, back to Chromium 112, Firefox 111 and WebKit 16.4, the engine inside Safari. There the default colors stay light on dark pages, so pass your own color if that matters.
137
+
138
+ ## License
139
+
140
+ MIT
@@ -0,0 +1,17 @@
1
+ import { type Random } from "../shared/random.ts";
2
+ export interface Point {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export interface Line {
7
+ from: Point;
8
+ to: Point;
9
+ level: number;
10
+ }
11
+ export type Side = "top" | "bottom" | "left" | "right";
12
+ export declare const LEVELS = 2;
13
+ export declare function seededRandom(seed: number): Random;
14
+ export declare function growCrystal(start: Point, angle: number, length: number, level: number, random: Random): Line[];
15
+ export declare function waveOf(random: Random): (share: number) => number;
16
+ export declare function frostLines(width: number, height: number, size: number, seed: number): Record<Side, Line[]>;
17
+ export declare function pathData(lines: Line[]): string;
@@ -0,0 +1,145 @@
1
+ import { between } from "../shared/random.js";
2
+ export const LEVELS = 2;
3
+ const BRANCH_SPOTS = 4;
4
+ const BRANCH_CHANCE = 0.6;
5
+ const BRANCH_ANGLE = Math.PI / 3;
6
+ const ANGLE_SPREAD = 0.15;
7
+ const BRANCH_SHARE = 0.42;
8
+ const TAPER = 0.7;
9
+ const MIN_FACTOR = 0.7;
10
+ const MAX_FACTOR = 1.3;
11
+ const WAVES = [
12
+ { cycles: 3, height: 0.35 },
13
+ { cycles: 7, height: 0.21 },
14
+ { cycles: 17, height: 0.14 },
15
+ ];
16
+ const MIN_LENGTH = 4;
17
+ const MAX_LENGTH = 10;
18
+ const MIN_SPACING = 5;
19
+ const MAX_SPACING = 11;
20
+ const TILT = 0.5;
21
+ const CORNER_BOOST = 0.8;
22
+ const TOP_WEIGHT = 0.7;
23
+ const BOTTOM_WEIGHT = 1.5;
24
+ export function seededRandom(seed) {
25
+ let state = seed;
26
+ return () => {
27
+ state = (state + 0x6d2b79f5) | 0;
28
+ let mixed = Math.imul(state ^ (state >>> 15), 1 | state);
29
+ mixed = (mixed + Math.imul(mixed ^ (mixed >>> 7), 61 | mixed)) ^ mixed;
30
+ return ((mixed ^ (mixed >>> 14)) >>> 0) / 4294967296;
31
+ };
32
+ }
33
+ function sideWeight(share) {
34
+ return TOP_WEIGHT + (BOTTOM_WEIGHT - TOP_WEIGHT) * share;
35
+ }
36
+ function edgesOf(width, height) {
37
+ return [
38
+ {
39
+ side: "top",
40
+ length: width,
41
+ inward: Math.PI / 2,
42
+ start: (d) => ({ x: d, y: 0 }),
43
+ weight: () => TOP_WEIGHT,
44
+ },
45
+ {
46
+ side: "bottom",
47
+ length: width,
48
+ inward: -Math.PI / 2,
49
+ start: (d) => ({ x: d, y: height }),
50
+ weight: () => BOTTOM_WEIGHT,
51
+ },
52
+ {
53
+ side: "left",
54
+ length: height,
55
+ inward: 0,
56
+ start: (d) => ({ x: 0, y: d }),
57
+ weight: sideWeight,
58
+ },
59
+ {
60
+ side: "right",
61
+ length: height,
62
+ inward: Math.PI,
63
+ start: (d) => ({ x: width, y: d }),
64
+ weight: sideWeight,
65
+ },
66
+ ];
67
+ }
68
+ function pointAt(start, angle, distance) {
69
+ const x = start.x + Math.cos(angle) * distance;
70
+ const y = start.y + Math.sin(angle) * distance;
71
+ return { x, y };
72
+ }
73
+ export function growCrystal(start, angle, length, level, random) {
74
+ const lines = [
75
+ { from: start, to: pointAt(start, angle, length), level },
76
+ ];
77
+ if (level === LEVELS - 1) {
78
+ return lines;
79
+ }
80
+ for (let spot = 1; spot <= BRANCH_SPOTS; spot++) {
81
+ const share = spot / (BRANCH_SPOTS + 1);
82
+ const at = pointAt(start, angle, length * share);
83
+ for (const side of [1, -1]) {
84
+ const coin = random();
85
+ if (coin >= BRANCH_CHANCE) {
86
+ continue;
87
+ }
88
+ const turn = BRANCH_ANGLE + between(random, -ANGLE_SPREAD, ANGLE_SPREAD);
89
+ const branchLength = length *
90
+ BRANCH_SHARE *
91
+ (1 - share * TAPER) *
92
+ between(random, MIN_FACTOR, MAX_FACTOR);
93
+ lines.push(...growCrystal(at, angle + side * turn, branchLength, level + 1, random));
94
+ }
95
+ }
96
+ return lines;
97
+ }
98
+ export function waveOf(random) {
99
+ const waves = [];
100
+ for (const wave of WAVES) {
101
+ waves.push({ cycles: wave.cycles, height: wave.height, phase: random() });
102
+ }
103
+ return (share) => {
104
+ let total = 1;
105
+ for (const wave of waves) {
106
+ total +=
107
+ wave.height *
108
+ Math.sin((share * wave.cycles + wave.phase) * 2 * Math.PI);
109
+ }
110
+ return total;
111
+ };
112
+ }
113
+ export function frostLines(width, height, size, seed) {
114
+ const edges = {
115
+ top: [],
116
+ bottom: [],
117
+ left: [],
118
+ right: [],
119
+ };
120
+ for (const [index, edge] of edgesOf(width, height).entries()) {
121
+ const random = seededRandom(seed + index);
122
+ const wave = waveOf(random);
123
+ const lines = edges[edge.side];
124
+ for (let d = between(random, 0, MAX_SPACING); d < edge.length; d += between(random, MIN_SPACING, MAX_SPACING)) {
125
+ const share = d / edge.length;
126
+ const fromMiddle = Math.abs(share - 0.5) * 2;
127
+ const length = size *
128
+ between(random, MIN_LENGTH, MAX_LENGTH) *
129
+ edge.weight(share) *
130
+ wave(share) *
131
+ (1 + CORNER_BOOST * fromMiddle ** 4);
132
+ const angle = edge.inward + between(random, -TILT, TILT);
133
+ lines.push(...growCrystal(edge.start(d), angle, length, 0, random));
134
+ }
135
+ }
136
+ return edges;
137
+ }
138
+ export function pathData(lines) {
139
+ let data = "";
140
+ for (const { from, to } of lines) {
141
+ data += `M${from.x.toFixed(1)} ${from.y.toFixed(1)}`;
142
+ data += `L${to.x.toFixed(1)} ${to.y.toFixed(1)}`;
143
+ }
144
+ return data;
145
+ }
@@ -0,0 +1,7 @@
1
+ import { type CommonOptions } from "../shared/options.ts";
2
+ import type { Stop } from "../shared/stop.ts";
3
+ export interface FrostOptions extends CommonOptions {
4
+ color?: string;
5
+ size?: number;
6
+ }
7
+ export declare function frost(options?: FrostOptions): Stop;
@@ -0,0 +1,233 @@
1
+ import { watchReducedMotion } from "../shared/motion.js";
2
+ import { checkColor, checkInteger, checkPositive, readOptions, themeColor, } from "../shared/options.js";
3
+ import { assertBrowser, createOverlay } from "../shared/overlay.js";
4
+ import { svgElement, uniqueId } from "../shared/svg.js";
5
+ import { frostLines, LEVELS, pathData, } from "./crystals.js";
6
+ const DEFAULT_LIGHT_COLOR = "#6f93bd";
7
+ const DEFAULT_DARK_COLOR = "#e4efff";
8
+ const MAX_SIZE = 2;
9
+ const STROKE_WIDTHS = [0.8, 0.5];
10
+ const OPACITIES = [0.8, 0.6];
11
+ const CRUST_WIDTH = 7;
12
+ const CRUST_BLUR = 3.6;
13
+ const CRUST_OPACITY = 0.11;
14
+ const GRAIN_OPACITY = 0.6;
15
+ const GRAIN_TILE = 128;
16
+ const GLOW_SHARE = 30;
17
+ const GLOW_SPILL = 300;
18
+ const GROW_MS = 5000;
19
+ const GROW_EASING = "ease-out";
20
+ const REACH = 70;
21
+ const BOTTOM_REACH = 1.4;
22
+ const FADE = 20;
23
+ const PLACEMENTS = {
24
+ top: { pinned: ["top", "left"], outward: [0, -1], inward: "to bottom" },
25
+ bottom: { pinned: ["bottom", "left"], outward: [0, 1], inward: "to top" },
26
+ left: { pinned: ["bottom", "left"], outward: [-1, 0], inward: "to right" },
27
+ right: { pinned: ["bottom", "right"], outward: [1, 0], inward: "to left" },
28
+ };
29
+ const SIDES = ["top", "bottom", "left", "right"];
30
+ function createStroke(paint, width, opacity) {
31
+ const path = svgElement("path", {});
32
+ path.style.fill = "none";
33
+ path.style.stroke = paint;
34
+ path.style.strokeWidth = String(width);
35
+ path.style.strokeLinecap = "round";
36
+ path.style.strokeDasharray = "none";
37
+ path.style.strokeOpacity = "1";
38
+ path.style.opacity = String(opacity);
39
+ path.style.pointerEvents = "none";
40
+ return path;
41
+ }
42
+ function createGrain(color, grainId) {
43
+ const noise = svgElement("filter", {
44
+ id: `${grainId}-noise`,
45
+ x: 0,
46
+ y: 0,
47
+ width: "100%",
48
+ height: "100%",
49
+ });
50
+ noise.append(svgElement("feTurbulence", {
51
+ type: "fractalNoise",
52
+ baseFrequency: 0.9,
53
+ numOctaves: 2,
54
+ seed: 4,
55
+ stitchTiles: "stitch",
56
+ }), svgElement("feColorMatrix", {
57
+ type: "matrix",
58
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 -4.6",
59
+ }), svgElement("feComposite", { in: "SourceGraphic", operator: "in" }));
60
+ const specks = svgElement("rect", { width: GRAIN_TILE, height: GRAIN_TILE });
61
+ specks.style.fill = color;
62
+ specks.style.stroke = "none";
63
+ specks.style.filter = `url(#${grainId}-noise)`;
64
+ const grain = svgElement("pattern", {
65
+ id: grainId,
66
+ width: GRAIN_TILE,
67
+ height: GRAIN_TILE,
68
+ patternUnits: "userSpaceOnUse",
69
+ });
70
+ grain.append(specks);
71
+ return [noise, grain];
72
+ }
73
+ function createBlock() {
74
+ const block = document.createElement("div");
75
+ block.style.position = "absolute";
76
+ block.style.width = "auto";
77
+ block.style.height = "auto";
78
+ block.style.pointerEvents = "none";
79
+ return block;
80
+ }
81
+ function createGlow(side, color) {
82
+ const glow = createBlock();
83
+ glow.style.inset = `-${GLOW_SPILL}px`;
84
+ glow.style[side] = "0";
85
+ glow.style.boxShadow = `inset 0 -12px 44px color-mix(in srgb, ${color} ${GLOW_SHARE}%, transparent)`;
86
+ return glow;
87
+ }
88
+ function createPiece(side, color) {
89
+ const blurId = uniqueId("frost-blur");
90
+ const grainId = uniqueId("frost-grain");
91
+ const blur = svgElement("filter", {
92
+ id: blurId,
93
+ filterUnits: "userSpaceOnUse",
94
+ });
95
+ blur.append(svgElement("feGaussianBlur", { stdDeviation: CRUST_BLUR }));
96
+ const defs = svgElement("defs", {});
97
+ defs.append(blur, ...createGrain(color, grainId));
98
+ const blurred = createStroke(color, CRUST_WIDTH, CRUST_OPACITY);
99
+ blurred.style.filter = `url(#${blurId})`;
100
+ const grainy = createStroke(`url(#${grainId})`, CRUST_WIDTH, GRAIN_OPACITY);
101
+ const levels = Array.from({ length: LEVELS }, (_, level) => createStroke(color, STROKE_WIDTHS[level] ?? 0.5, OPACITIES[level] ?? 0.6));
102
+ const svg = svgElement("svg", {});
103
+ svg.style.position = "absolute";
104
+ svg.style.top = "0";
105
+ svg.style.left = "0";
106
+ svg.style.display = "block";
107
+ svg.style.pointerEvents = "none";
108
+ svg.append(defs, blurred, grainy, ...levels);
109
+ const inner = createBlock();
110
+ inner.style.inset = "0";
111
+ inner.append(createGlow(side, color), svg);
112
+ const { pinned, inward } = PLACEMENTS[side];
113
+ const box = document.createElement("div");
114
+ box.style.position = "fixed";
115
+ box.style[pinned[0]] = "0";
116
+ box.style[pinned[1]] = "0";
117
+ box.style.overflow = "hidden";
118
+ box.style.pointerEvents = "none";
119
+ box.style.maskImage = `linear-gradient(${inward}, black calc(100% - ${FADE}px), transparent)`;
120
+ box.style.willChange = "transform";
121
+ box.append(inner);
122
+ return { side, box, inner, svg, blur, crust: [blurred, grainy], levels };
123
+ }
124
+ function thickness(side, size) {
125
+ const reach = REACH * Math.max(size, 1);
126
+ return (side === "bottom" ? reach * BOTTOM_REACH : reach) + FADE;
127
+ }
128
+ function pieceArea(side, bounds, size) {
129
+ const band = thickness(side, size);
130
+ const { width, height } = bounds;
131
+ if (side === "top") {
132
+ return { x: 0, y: 0, width, height: band };
133
+ }
134
+ if (side === "bottom") {
135
+ return { x: 0, y: height - band, width, height: band };
136
+ }
137
+ if (side === "left") {
138
+ return { x: 0, y: 0, width: band, height };
139
+ }
140
+ return { x: width - band, y: 0, width: band, height };
141
+ }
142
+ function drawPiece(piece, lines, area) {
143
+ const { x, y, width, height } = area;
144
+ piece.box.style.width = `${width}px`;
145
+ piece.box.style.height = `${height}px`;
146
+ piece.svg.style.width = `${width}px`;
147
+ piece.svg.style.height = `${height}px`;
148
+ piece.svg.setAttribute("viewBox", `${x} ${y} ${width} ${height}`);
149
+ piece.blur.setAttribute("x", String(x));
150
+ piece.blur.setAttribute("y", String(y));
151
+ piece.blur.setAttribute("width", String(width));
152
+ piece.blur.setAttribute("height", String(height));
153
+ const all = pathData(lines);
154
+ for (const path of piece.crust) {
155
+ path.setAttribute("d", all);
156
+ }
157
+ for (const [level, path] of piece.levels.entries()) {
158
+ const own = lines.filter((line) => line.level === level);
159
+ path.setAttribute("d", pathData(own));
160
+ }
161
+ }
162
+ function screenBounds() {
163
+ const { width, height } = screen;
164
+ if (width < height && matchMedia("(orientation: landscape)").matches) {
165
+ return { width: height, height: width };
166
+ }
167
+ return { width, height };
168
+ }
169
+ function drawingBounds(layer) {
170
+ const whole = screenBounds();
171
+ return {
172
+ width: Math.max(whole.width, layer.clientWidth),
173
+ height: Math.max(whole.height, layer.clientHeight),
174
+ };
175
+ }
176
+ function slide(element, x, y) {
177
+ const hidden = `translate(${x * 100}%, ${y * 100}%)`;
178
+ return element.animate([{ transform: hidden }, { transform: "none" }], {
179
+ duration: GROW_MS,
180
+ easing: GROW_EASING,
181
+ });
182
+ }
183
+ function startGrowth(piece) {
184
+ const [x, y] = PLACEMENTS[piece.side].outward;
185
+ return [slide(piece.box, x, y), slide(piece.inner, -x, -y)];
186
+ }
187
+ export function frost(options) {
188
+ assertBrowser("frost");
189
+ const settings = readOptions("frost", options, ["color", "size", "zIndex"]);
190
+ const color = checkColor("frost", "color", settings.color ?? themeColor(DEFAULT_LIGHT_COLOR, DEFAULT_DARK_COLOR));
191
+ const size = checkPositive("frost", "size", settings.size ?? 1, MAX_SIZE);
192
+ const zIndex = checkInteger("frost", "zIndex", settings.zIndex ?? 9999);
193
+ const layer = createOverlay(zIndex);
194
+ const pieces = SIDES.map((side) => createPiece(side, color));
195
+ layer.append(...pieces.map((piece) => piece.box));
196
+ const seed = Math.floor(Math.random() * 2 ** 32);
197
+ function draw(bounds) {
198
+ const edges = frostLines(bounds.width, bounds.height, size, seed);
199
+ for (const piece of pieces) {
200
+ const area = pieceArea(piece.side, bounds, size);
201
+ drawPiece(piece, edges[piece.side], area);
202
+ }
203
+ }
204
+ let drawn = drawingBounds(layer);
205
+ draw(drawn);
206
+ const controller = new AbortController();
207
+ const growths = pieces.flatMap(startGrowth);
208
+ watchReducedMotion((reduced) => {
209
+ if (!reduced) {
210
+ return;
211
+ }
212
+ for (const growth of growths) {
213
+ growth.finish();
214
+ }
215
+ }, controller.signal);
216
+ const observer = new ResizeObserver(() => {
217
+ const bounds = drawingBounds(layer);
218
+ if (bounds.width === drawn.width && bounds.height === drawn.height) {
219
+ return;
220
+ }
221
+ drawn = bounds;
222
+ draw(drawn);
223
+ });
224
+ observer.observe(layer);
225
+ return () => {
226
+ controller.abort();
227
+ observer.disconnect();
228
+ for (const growth of growths) {
229
+ growth.cancel();
230
+ }
231
+ layer.remove();
232
+ };
233
+ }
@@ -0,0 +1,6 @@
1
+ import { type CommonOptions } from "../shared/options.ts";
2
+ import type { Stop } from "../shared/stop.ts";
3
+ export interface GarlandOptions extends CommonOptions {
4
+ colors?: readonly string[];
5
+ }
6
+ export declare function garland(options?: GarlandOptions): Stop;