let-it-blossom 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +91 -2
- package/dist/cherryblossom-DWzs_qT1.d.mts +163 -0
- package/dist/cherryblossom-DWzs_qT1.d.ts +163 -0
- package/dist/cherryblossom.global.cjs +2 -0
- package/dist/cherryblossom.global.cjs.map +1 -0
- package/dist/cherryblossom.global.d.mts +5 -0
- package/dist/cherryblossom.global.d.ts +5 -0
- package/dist/cherryblossom.global.global.js +2 -0
- package/dist/cherryblossom.global.global.js.map +1 -0
- package/dist/cherryblossom.global.mjs +2 -0
- package/dist/cherryblossom.global.mjs.map +1 -0
- package/dist/chunk-RDJ3OPGN.mjs +2 -0
- package/dist/chunk-RDJ3OPGN.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.global.js +2 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Austin Mirando
|
|
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,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Let It Blossom (🌸 `let-it-blossom`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An ultra-lightweight, zero-dependency canvas library that adds realistic, floating cherry blossom petals (sakura) to any web page. Features realistic 3D fluttering, ambient wind variations, interactive mouse breeze swirl/repulsion, and retina display support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Realistic Sakura Petals:** Bezier-curved petal geometry with natural notched tips and multi-tone pastel pink gradients.
|
|
8
|
+
- **3D Flutter Dynamics:** Simulates yaw, pitch, roll, and air-resistance tumbling.
|
|
9
|
+
- **Interactive Mouse Breeze:** Hovering or moving your cursor creates dynamic breeze waves that disperse nearby petals.
|
|
10
|
+
- **High-DPI / Retina Ready:** Automatically scales to match `devicePixelRatio` with crisp rendering.
|
|
11
|
+
- **Accessible:** Respects `prefers-reduced-motion` preferences automatically.
|
|
12
|
+
- **Zero Dependencies:** Pure vanilla TypeScript, lightweight footprint.
|
|
13
|
+
- **Universal:** Compatible with modern bundlers (ESM, CommonJS, and IIFE browser builds). SSR-safe.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install let-it-blossom
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### ES Module / TypeScript
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { CherryBlossom } from "let-it-blossom";
|
|
27
|
+
|
|
28
|
+
// Start cherry blossoms falling across the page
|
|
29
|
+
const blossom = new CherryBlossom();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Vanilla HTML / CDN
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/cherryblossom/dist/cherryblossom.global.global.js"></script>
|
|
36
|
+
<script>
|
|
37
|
+
const blossom = new CherryBlossom();
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration & Options
|
|
42
|
+
|
|
43
|
+
You can pass an optional configuration object to customize petals, wind, and behavior:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const blossom = new CherryBlossom({
|
|
47
|
+
// Number of petals on screen (default: 45)
|
|
48
|
+
number: 50,
|
|
49
|
+
|
|
50
|
+
// Target container (default: document.body)
|
|
51
|
+
root: document.body,
|
|
52
|
+
|
|
53
|
+
// Wind and gust options
|
|
54
|
+
wind: {
|
|
55
|
+
speed: 1.5, // Base horizontal drift
|
|
56
|
+
gust: 1.5, // Periodic wind gust variance
|
|
57
|
+
enableMouseBreeze: true,// Petals react to mouse movement
|
|
58
|
+
mouseRadius: 140, // Cursor influence radius in px
|
|
59
|
+
mouseForce: 1.8 // Repulsion strength
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// Petal visuals
|
|
63
|
+
petalStyle: {
|
|
64
|
+
colors: ["#ffb7c5", "#ff8da1", "#fca3b7", "#ffe4e9"],
|
|
65
|
+
opacityRange: [0.75, 0.95],
|
|
66
|
+
sizeRange: [12, 22]
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// Accessibility
|
|
70
|
+
respectReducedMotion: true
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Methods & API
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// Stop / pause animation
|
|
78
|
+
blossom.stop();
|
|
79
|
+
|
|
80
|
+
// Resume animation
|
|
81
|
+
blossom.start();
|
|
82
|
+
|
|
83
|
+
// Dynamically change petal count
|
|
84
|
+
blossom.number = 80;
|
|
85
|
+
|
|
86
|
+
// Permanently tear down canvas and listeners
|
|
87
|
+
blossom.clear();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
interface PetalStyle {
|
|
2
|
+
/**
|
|
3
|
+
* Primary fill color or gradient stop colors for petal.
|
|
4
|
+
* Can be hex, rgba, or array of strings for gradient.
|
|
5
|
+
* Defaults to gentle pastel sakura pinks: ['#ffb7c5', '#ff94aa']
|
|
6
|
+
*/
|
|
7
|
+
colors?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Opacity of petal, default [0.7, 0.95]
|
|
10
|
+
*/
|
|
11
|
+
opacityRange?: [number, number];
|
|
12
|
+
/**
|
|
13
|
+
* Base petal size in pixels (length), default [12, 22]
|
|
14
|
+
*/
|
|
15
|
+
sizeRange?: [number, number];
|
|
16
|
+
}
|
|
17
|
+
interface WindOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Base horizontal wind speed, defaults to 1.5
|
|
20
|
+
*/
|
|
21
|
+
speed?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Max random gust variation added to wind, defaults to 2.0
|
|
24
|
+
*/
|
|
25
|
+
gust?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether mouse cursor repels/swirls petals, defaults to true
|
|
28
|
+
*/
|
|
29
|
+
enableMouseBreeze?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Radius of mouse breeze influence in pixels, defaults to 140
|
|
32
|
+
*/
|
|
33
|
+
mouseRadius?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Force multiplier for mouse breeze, defaults to 1.8
|
|
36
|
+
*/
|
|
37
|
+
mouseForce?: number;
|
|
38
|
+
}
|
|
39
|
+
interface CherryBlossomOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Container element to mount canvas into, defaults to document.body
|
|
42
|
+
*/
|
|
43
|
+
root?: HTMLElement | null;
|
|
44
|
+
/**
|
|
45
|
+
* Total number of petals, defaults to 40 (or window.innerWidth / 30)
|
|
46
|
+
*/
|
|
47
|
+
number?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Gravity downward acceleration / speed range [min, max], defaults to [1.2, 2.8]
|
|
50
|
+
*/
|
|
51
|
+
gravityRange?: [number, number];
|
|
52
|
+
/**
|
|
53
|
+
* Wind and gust configuration
|
|
54
|
+
*/
|
|
55
|
+
wind?: WindOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Petal appearance options
|
|
58
|
+
*/
|
|
59
|
+
petalStyle?: PetalStyle;
|
|
60
|
+
/**
|
|
61
|
+
* Canvas CSS styles override, defaults to { zIndex: '999999', pointerEvents: 'none', position: 'fixed' }
|
|
62
|
+
*/
|
|
63
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
64
|
+
/**
|
|
65
|
+
* Respect system prefers-reduced-motion media query, defaults to true
|
|
66
|
+
*/
|
|
67
|
+
respectReducedMotion?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Maximum devicePixelRatio to use for Retina rendering (defaults to 2)
|
|
70
|
+
*/
|
|
71
|
+
maxPixelRatio?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* CherryBlossom manages the canvas lifecycle, particle physics simulation loop,
|
|
76
|
+
* dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.
|
|
77
|
+
*/
|
|
78
|
+
declare class CherryBlossom {
|
|
79
|
+
/**
|
|
80
|
+
* Static default options
|
|
81
|
+
*/
|
|
82
|
+
static readonly DEFAULT_OPTIONS: {
|
|
83
|
+
root: HTMLElement | null;
|
|
84
|
+
number: number;
|
|
85
|
+
gravityRange: [number, number];
|
|
86
|
+
wind: {
|
|
87
|
+
speed: number;
|
|
88
|
+
gust: number;
|
|
89
|
+
enableMouseBreeze: boolean;
|
|
90
|
+
mouseRadius: number;
|
|
91
|
+
mouseForce: number;
|
|
92
|
+
};
|
|
93
|
+
petalStyle: {
|
|
94
|
+
colors: string[];
|
|
95
|
+
opacityRange: [number, number];
|
|
96
|
+
sizeRange: [number, number];
|
|
97
|
+
};
|
|
98
|
+
style: Partial<CSSStyleDeclaration>;
|
|
99
|
+
respectReducedMotion: boolean;
|
|
100
|
+
maxPixelRatio: number;
|
|
101
|
+
};
|
|
102
|
+
readonly canvas: HTMLCanvasElement | null;
|
|
103
|
+
private readonly ctx;
|
|
104
|
+
private readonly root;
|
|
105
|
+
private readonly respectReducedMotion;
|
|
106
|
+
private readonly maxPixelRatio;
|
|
107
|
+
private petals;
|
|
108
|
+
private _number;
|
|
109
|
+
private _wind;
|
|
110
|
+
private _petalStyle;
|
|
111
|
+
private _gravityRange;
|
|
112
|
+
private animationFrameId;
|
|
113
|
+
private isRunning;
|
|
114
|
+
private isDestroyed;
|
|
115
|
+
private width;
|
|
116
|
+
private height;
|
|
117
|
+
private pixelRatio;
|
|
118
|
+
private resizeObserver;
|
|
119
|
+
private mediaQueryList;
|
|
120
|
+
private windTime;
|
|
121
|
+
private currentWind;
|
|
122
|
+
private mouseX;
|
|
123
|
+
private mouseY;
|
|
124
|
+
private boundOnPointerMove;
|
|
125
|
+
private boundOnPointerLeave;
|
|
126
|
+
private boundOnMotionChange;
|
|
127
|
+
constructor(options?: CherryBlossomOptions);
|
|
128
|
+
get number(): number;
|
|
129
|
+
set number(value: number);
|
|
130
|
+
get wind(): Required<WindOptions>;
|
|
131
|
+
set wind(options: Partial<WindOptions>);
|
|
132
|
+
get petalStyle(): PetalStyle;
|
|
133
|
+
set petalStyle(style: PetalStyle);
|
|
134
|
+
/**
|
|
135
|
+
* Starts or resumes the animation loop.
|
|
136
|
+
*/
|
|
137
|
+
start(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Pauses the animation loop.
|
|
140
|
+
*/
|
|
141
|
+
stop(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Alias for start()
|
|
144
|
+
*/
|
|
145
|
+
resume(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Alias for stop()
|
|
148
|
+
*/
|
|
149
|
+
pause(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Cleans up canvas, event listeners, observers and removes the element permanently.
|
|
152
|
+
*/
|
|
153
|
+
clear(): void;
|
|
154
|
+
private updateDimensions;
|
|
155
|
+
private initPetals;
|
|
156
|
+
private adjustPetalCount;
|
|
157
|
+
private attachMouseListeners;
|
|
158
|
+
private removeMouseListeners;
|
|
159
|
+
private renderFrame;
|
|
160
|
+
private loop;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { CherryBlossom as C, type PetalStyle as P, type WindOptions as W, type CherryBlossomOptions as a };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
interface PetalStyle {
|
|
2
|
+
/**
|
|
3
|
+
* Primary fill color or gradient stop colors for petal.
|
|
4
|
+
* Can be hex, rgba, or array of strings for gradient.
|
|
5
|
+
* Defaults to gentle pastel sakura pinks: ['#ffb7c5', '#ff94aa']
|
|
6
|
+
*/
|
|
7
|
+
colors?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Opacity of petal, default [0.7, 0.95]
|
|
10
|
+
*/
|
|
11
|
+
opacityRange?: [number, number];
|
|
12
|
+
/**
|
|
13
|
+
* Base petal size in pixels (length), default [12, 22]
|
|
14
|
+
*/
|
|
15
|
+
sizeRange?: [number, number];
|
|
16
|
+
}
|
|
17
|
+
interface WindOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Base horizontal wind speed, defaults to 1.5
|
|
20
|
+
*/
|
|
21
|
+
speed?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Max random gust variation added to wind, defaults to 2.0
|
|
24
|
+
*/
|
|
25
|
+
gust?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether mouse cursor repels/swirls petals, defaults to true
|
|
28
|
+
*/
|
|
29
|
+
enableMouseBreeze?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Radius of mouse breeze influence in pixels, defaults to 140
|
|
32
|
+
*/
|
|
33
|
+
mouseRadius?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Force multiplier for mouse breeze, defaults to 1.8
|
|
36
|
+
*/
|
|
37
|
+
mouseForce?: number;
|
|
38
|
+
}
|
|
39
|
+
interface CherryBlossomOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Container element to mount canvas into, defaults to document.body
|
|
42
|
+
*/
|
|
43
|
+
root?: HTMLElement | null;
|
|
44
|
+
/**
|
|
45
|
+
* Total number of petals, defaults to 40 (or window.innerWidth / 30)
|
|
46
|
+
*/
|
|
47
|
+
number?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Gravity downward acceleration / speed range [min, max], defaults to [1.2, 2.8]
|
|
50
|
+
*/
|
|
51
|
+
gravityRange?: [number, number];
|
|
52
|
+
/**
|
|
53
|
+
* Wind and gust configuration
|
|
54
|
+
*/
|
|
55
|
+
wind?: WindOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Petal appearance options
|
|
58
|
+
*/
|
|
59
|
+
petalStyle?: PetalStyle;
|
|
60
|
+
/**
|
|
61
|
+
* Canvas CSS styles override, defaults to { zIndex: '999999', pointerEvents: 'none', position: 'fixed' }
|
|
62
|
+
*/
|
|
63
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
64
|
+
/**
|
|
65
|
+
* Respect system prefers-reduced-motion media query, defaults to true
|
|
66
|
+
*/
|
|
67
|
+
respectReducedMotion?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Maximum devicePixelRatio to use for Retina rendering (defaults to 2)
|
|
70
|
+
*/
|
|
71
|
+
maxPixelRatio?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* CherryBlossom manages the canvas lifecycle, particle physics simulation loop,
|
|
76
|
+
* dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.
|
|
77
|
+
*/
|
|
78
|
+
declare class CherryBlossom {
|
|
79
|
+
/**
|
|
80
|
+
* Static default options
|
|
81
|
+
*/
|
|
82
|
+
static readonly DEFAULT_OPTIONS: {
|
|
83
|
+
root: HTMLElement | null;
|
|
84
|
+
number: number;
|
|
85
|
+
gravityRange: [number, number];
|
|
86
|
+
wind: {
|
|
87
|
+
speed: number;
|
|
88
|
+
gust: number;
|
|
89
|
+
enableMouseBreeze: boolean;
|
|
90
|
+
mouseRadius: number;
|
|
91
|
+
mouseForce: number;
|
|
92
|
+
};
|
|
93
|
+
petalStyle: {
|
|
94
|
+
colors: string[];
|
|
95
|
+
opacityRange: [number, number];
|
|
96
|
+
sizeRange: [number, number];
|
|
97
|
+
};
|
|
98
|
+
style: Partial<CSSStyleDeclaration>;
|
|
99
|
+
respectReducedMotion: boolean;
|
|
100
|
+
maxPixelRatio: number;
|
|
101
|
+
};
|
|
102
|
+
readonly canvas: HTMLCanvasElement | null;
|
|
103
|
+
private readonly ctx;
|
|
104
|
+
private readonly root;
|
|
105
|
+
private readonly respectReducedMotion;
|
|
106
|
+
private readonly maxPixelRatio;
|
|
107
|
+
private petals;
|
|
108
|
+
private _number;
|
|
109
|
+
private _wind;
|
|
110
|
+
private _petalStyle;
|
|
111
|
+
private _gravityRange;
|
|
112
|
+
private animationFrameId;
|
|
113
|
+
private isRunning;
|
|
114
|
+
private isDestroyed;
|
|
115
|
+
private width;
|
|
116
|
+
private height;
|
|
117
|
+
private pixelRatio;
|
|
118
|
+
private resizeObserver;
|
|
119
|
+
private mediaQueryList;
|
|
120
|
+
private windTime;
|
|
121
|
+
private currentWind;
|
|
122
|
+
private mouseX;
|
|
123
|
+
private mouseY;
|
|
124
|
+
private boundOnPointerMove;
|
|
125
|
+
private boundOnPointerLeave;
|
|
126
|
+
private boundOnMotionChange;
|
|
127
|
+
constructor(options?: CherryBlossomOptions);
|
|
128
|
+
get number(): number;
|
|
129
|
+
set number(value: number);
|
|
130
|
+
get wind(): Required<WindOptions>;
|
|
131
|
+
set wind(options: Partial<WindOptions>);
|
|
132
|
+
get petalStyle(): PetalStyle;
|
|
133
|
+
set petalStyle(style: PetalStyle);
|
|
134
|
+
/**
|
|
135
|
+
* Starts or resumes the animation loop.
|
|
136
|
+
*/
|
|
137
|
+
start(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Pauses the animation loop.
|
|
140
|
+
*/
|
|
141
|
+
stop(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Alias for start()
|
|
144
|
+
*/
|
|
145
|
+
resume(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Alias for stop()
|
|
148
|
+
*/
|
|
149
|
+
pause(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Cleans up canvas, event listeners, observers and removes the element permanently.
|
|
152
|
+
*/
|
|
153
|
+
clear(): void;
|
|
154
|
+
private updateDimensions;
|
|
155
|
+
private initPetals;
|
|
156
|
+
private adjustPetalCount;
|
|
157
|
+
private attachMouseListeners;
|
|
158
|
+
private removeMouseListeners;
|
|
159
|
+
private renderFrame;
|
|
160
|
+
private loop;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { CherryBlossom as C, type PetalStyle as P, type WindOptions as W, type CherryBlossomOptions as a };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var v=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!g.call(r,i)&&i!==t&&v(r,i,{get:()=>e[i],enumerable:!(n=w(e,i))||n.enumerable});return r};var x=r=>P(v({},"__esModule",{value:!0}),r);var L={};R(L,{CherryBlossom:()=>l,default:()=>O});module.exports=x(L);function s(r,e){return r+Math.random()*(e-r)}var u=class{x=0;y=0;z=0;size=15;aspectRatio=1.25;vx=0;vy=0;vz=0;pitch=0;yaw=0;roll=0;dPitch=0;dYaw=0;dRoll=0;oscillationPhase=0;oscillationSpeed=0;swayAmplitude=0;color1="#ffb7c5";color2="#ff94aa";opacity=.85;mouseVx=0;mouseVy=0;constructor(e,t,n){this.reset(e,t,!0,n)}reset(e,t,n=!1,i){let o=i?.sizeRange??[12,22],a=i?.opacityRange??[.75,.95],h=i?.colors??["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"];this.size=s(o[0],o[1]),this.aspectRatio=s(1.15,1.35),this.opacity=s(a[0],a[1]),this.color1=h[Math.floor(Math.random()*h.length)],this.color2=h[Math.floor(Math.random()*h.length)],this.x=s(-50,e+50),this.y=n?s(-t,t):s(-60,-20),this.z=s(.7,1.25),this.vy=s(1.2,2.6)*this.z,this.vx=s(-.5,.8),this.pitch=s(0,Math.PI*2),this.yaw=s(0,Math.PI*2),this.roll=s(0,Math.PI*2),this.dPitch=s(.015,.045),this.dYaw=s(.02,.06),this.dRoll=s(.01,.03),this.oscillationPhase=s(0,Math.PI*2),this.oscillationSpeed=s(.02,.05),this.swayAmplitude=s(.8,2.2),this.mouseVx=0,this.mouseVy=0}update(e,t,n,i,o,a=140,h=1.8){this.pitch+=this.dPitch,this.yaw+=this.dYaw,this.roll+=this.dRoll,this.oscillationPhase+=this.oscillationSpeed;let f=Math.sin(this.oscillationPhase)*this.swayAmplitude;if(i!==null&&o!==null){let d=this.x-i,m=this.y-o,p=d*d+m*m,y=a*a;if(p<y&&p>0){let c=Math.sqrt(p),b=(1-c/a)*h;this.mouseVx+=d/c*b*2.5,this.mouseVy+=(m/c*b-.5)*1.5}}this.mouseVx*=.92,this.mouseVy*=.92,this.x+=(this.vx+n+f+this.mouseVx)*this.z,this.y+=(this.vy+this.mouseVy)*this.z,(this.y>t+40||this.x>e+80||this.x<-80)&&(n>0&&Math.random()<.3?(this.x=-30,this.y=s(-20,t*.7)):(this.y=-30,this.x=s(-40,e+40)),this.mouseVx=0,this.mouseVy=0)}draw(e){e.save(),e.translate(this.x,this.y),e.rotate(this.roll);let t=Math.cos(this.yaw)*this.z,n=Math.cos(this.pitch)*this.z;e.scale(t,n),e.globalAlpha=Math.max(0,Math.min(1,this.opacity));let i=this.size/this.aspectRatio*.5,o=this.size*.5,a=e.createLinearGradient(0,o,0,-o);a.addColorStop(0,this.color1),a.addColorStop(1,this.color2),e.fillStyle=a,e.beginPath(),e.moveTo(0,o),e.bezierCurveTo(-i*1.3,o*.4,-i*1.2,-o*.6,-i*.35,-o),e.quadraticCurveTo(0,-o*.75,i*.35,-o),e.bezierCurveTo(i*1.2,-o*.6,i*1.3,o*.4,0,o),e.closePath(),e.fill(),e.restore()}};var l=class r{static DEFAULT_OPTIONS={root:null,number:45,gravityRange:[1.2,2.6],wind:{speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8},petalStyle:{colors:["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"],opacityRange:[.75,.95],sizeRange:[12,22]},style:{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"999999"},respectReducedMotion:!0,maxPixelRatio:2};canvas=null;ctx=null;root=null;respectReducedMotion=!0;maxPixelRatio=2;petals=[];_number=45;_wind={speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8};_petalStyle={};_gravityRange=[1.2,2.6];animationFrameId=null;isRunning=!1;isDestroyed=!1;width=0;height=0;pixelRatio=1;resizeObserver=null;mediaQueryList=null;windTime=0;currentWind=1.5;mouseX=null;mouseY=null;boundOnPointerMove=null;boundOnPointerLeave=null;boundOnMotionChange=null;constructor(e){let t={...r.DEFAULT_OPTIONS,...e};this._number=Math.max(0,Math.min(1e4,t.number??45));let n=r.DEFAULT_OPTIONS.wind;if(this._wind={speed:t.wind?.speed??n.speed,gust:t.wind?.gust??n.gust,enableMouseBreeze:t.wind?.enableMouseBreeze??n.enableMouseBreeze,mouseRadius:t.wind?.mouseRadius??n.mouseRadius,mouseForce:t.wind?.mouseForce??n.mouseForce},this._petalStyle={...r.DEFAULT_OPTIONS.petalStyle,...t.petalStyle||{}},this._gravityRange=t.gravityRange||[1.2,2.6],this.respectReducedMotion=t.respectReducedMotion??!0,this.maxPixelRatio=t.maxPixelRatio??2,typeof window>"u"||typeof document>"u"||(this.root=t.root??document.body,!this.root))return;this.canvas=document.createElement("canvas"),this.canvas.setAttribute("aria-hidden","true"),this.ctx=this.canvas.getContext("2d");let i={...r.DEFAULT_OPTIONS.style,...t.style||{}};Object.assign(this.canvas.style,i),this.root.appendChild(this.canvas),this.updateDimensions(),typeof ResizeObserver<"u"&&this.root?(this.resizeObserver=new ResizeObserver(()=>this.updateDimensions()),this.resizeObserver.observe(this.root===document.body?document.documentElement:this.root)):window.addEventListener("resize",this.updateDimensions),this._wind.enableMouseBreeze&&this.attachMouseListeners(),this.respectReducedMotion&&typeof window.matchMedia=="function"&&(this.mediaQueryList=window.matchMedia("(prefers-reduced-motion: reduce)"),this.boundOnMotionChange=a=>{a.matches?this.pause():!this.isDestroyed&&this.isRunning&&this.resume()},this.mediaQueryList.addEventListener&&this.mediaQueryList.addEventListener("change",this.boundOnMotionChange)),this.initPetals(),this.respectReducedMotion&&this.mediaQueryList?.matches?this.renderFrame():this.start()}get number(){return this._number}set number(e){this.isDestroyed||(this._number=Math.max(0,Math.min(1e4,Math.floor(e))),this.adjustPetalCount())}get wind(){return{...this._wind}}set wind(e){this.isDestroyed||(this._wind={...this._wind,...e},e.enableMouseBreeze===!1?this.removeMouseListeners():e.enableMouseBreeze===!0&&this.attachMouseListeners())}get petalStyle(){return{...this._petalStyle}}set petalStyle(e){if(!this.isDestroyed){this._petalStyle={...this._petalStyle,...e};for(let t of this.petals)t.reset(this.width,this.height,!1,this._petalStyle)}}start(){this.isDestroyed||this.isRunning||(this.isRunning=!0,this.resume())}stop(){this.isRunning=!1,this.pause()}resume(){this.animationFrameId===null&&!this.isDestroyed&&(this.animationFrameId=requestAnimationFrame(this.loop))}pause(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}clear(){this.isDestroyed=!0,this.stop(),this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):typeof window<"u"&&window.removeEventListener("resize",this.updateDimensions),this.mediaQueryList&&this.boundOnMotionChange&&this.mediaQueryList.removeEventListener&&this.mediaQueryList.removeEventListener("change",this.boundOnMotionChange),this.removeMouseListeners(),this.canvas&&this.canvas.parentElement&&this.canvas.parentElement.removeChild(this.canvas),this.petals=[]}updateDimensions=()=>{if(!this.canvas||!this.root)return;let e=this.root===document.body,t=e?window.innerWidth:this.root.clientWidth,n=e?window.innerHeight:this.root.clientHeight;this.width=t,this.height=n;let i=typeof window<"u"&&window.devicePixelRatio||1;this.pixelRatio=Math.min(i,this.maxPixelRatio),this.canvas.width=Math.round(this.width*this.pixelRatio),this.canvas.height=Math.round(this.height*this.pixelRatio),this.ctx&&this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)};initPetals(){this.petals=[];for(let e=0;e<this._number;e++)this.petals.push(new u(this.width,this.height,this._petalStyle))}adjustPetalCount(){let e=this.petals.length;if(this._number>e)for(let t=e;t<this._number;t++)this.petals.push(new u(this.width,this.height,this._petalStyle));else this._number<e&&this.petals.splice(this._number)}attachMouseListeners(){typeof window>"u"||this.boundOnPointerMove||(this.boundOnPointerMove=e=>{this.mouseX=e.clientX,this.mouseY=e.clientY},this.boundOnPointerLeave=()=>{this.mouseX=null,this.mouseY=null},window.addEventListener("pointermove",this.boundOnPointerMove,{passive:!0}),window.addEventListener("pointerleave",this.boundOnPointerLeave,{passive:!0}))}removeMouseListeners(){typeof window>"u"||(this.boundOnPointerMove&&(window.removeEventListener("pointermove",this.boundOnPointerMove),this.boundOnPointerMove=null),this.boundOnPointerLeave&&(window.removeEventListener("pointerleave",this.boundOnPointerLeave),this.boundOnPointerLeave=null),this.mouseX=null,this.mouseY=null)}renderFrame(){if(!(!this.ctx||!this.canvas)){this.ctx.clearRect(0,0,this.width,this.height);for(let e of this.petals)e.draw(this.ctx)}}loop=()=>{if(!this.isRunning||this.isDestroyed)return;this.windTime+=.015;let e=Math.sin(this.windTime)*this._wind.gust+Math.cos(this.windTime*.4)*.5;this.currentWind=this._wind.speed+e;for(let t=0;t<this.petals.length;t++)this.petals[t].update(this.width,this.height,this.currentWind,this.mouseX,this.mouseY,this._wind.mouseRadius,this._wind.mouseForce);this.renderFrame(),this.animationFrameId=requestAnimationFrame(this.loop)}};typeof window<"u"&&(window.CherryBlossom=l);var O=l;0&&(module.exports={CherryBlossom});
|
|
2
|
+
//# sourceMappingURL=cherryblossom.global.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/global.ts","../src/math.ts","../src/petal.ts","../src/cherryblossom.ts"],"sourcesContent":["import { CherryBlossom } from \"./cherryblossom\";\n\n// Mount directly to window for vanilla CDN <script> tags\nif (typeof window !== \"undefined\") {\n (window as unknown as { CherryBlossom: typeof CherryBlossom }).CherryBlossom = CherryBlossom;\n}\n\nexport { CherryBlossom };\nexport default CherryBlossom;\n","/**\n * Random float in range [min, max)\n */\nexport function randomRange(min: number, max: number): number {\n return min + Math.random() * (max - min);\n}\n\n/**\n * Random integer in range [min, max]\n */\nexport function randomInt(min: number, max: number): number {\n return Math.floor(min + Math.random() * (max - min + 1));\n}\n\n/**\n * Clamp a number between min and max\n */\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, val));\n}\n","import { randomRange } from \"./math\";\nimport type { PetalStyle } from \"./types\";\n\n/**\n * Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),\n * physics velocities, realistic bezier geometry, and wind responsiveness.\n */\nexport class Petal {\n // Coordinates\n x = 0;\n y = 0;\n z = 0; // Simulated depth for scale & parallax\n\n // Dimensions\n size = 15;\n aspectRatio = 1.25; // Length to width ratio\n\n // Velocities\n vx = 0;\n vy = 0;\n vz = 0;\n\n // 3D rotation angles & angular velocities\n pitch = 0; // Tumbling end-over-end\n yaw = 0; // Spinning around horizontal axis\n roll = 0; // Twisting clockwise/counterclockwise\n dPitch = 0;\n dYaw = 0;\n dRoll = 0;\n\n // Flutter & sway oscillation parameters\n oscillationPhase = 0;\n oscillationSpeed = 0;\n swayAmplitude = 0;\n\n // Color & appearance\n color1 = \"#ffb7c5\";\n color2 = \"#ff94aa\";\n opacity = 0.85;\n\n // Mouse wind displacement\n mouseVx = 0;\n mouseVy = 0;\n\n constructor(width: number, height: number, style?: PetalStyle) {\n this.reset(width, height, true, style);\n }\n\n /**\n * Re-initializes petal position, velocities, and 3D rotations.\n * If initial is true, petals are scattered vertically across the whole screen.\n */\n reset(width: number, height: number, initial = false, style?: PetalStyle): void {\n const sizeRange = style?.sizeRange ?? [12, 22];\n const opacityRange = style?.opacityRange ?? [0.75, 0.95];\n const colors = style?.colors ?? [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"];\n\n this.size = randomRange(sizeRange[0], sizeRange[1]);\n this.aspectRatio = randomRange(1.15, 1.35);\n this.opacity = randomRange(opacityRange[0], opacityRange[1]);\n\n // Pick random gradient colors for realistic petal shading\n this.color1 = colors[Math.floor(Math.random() * colors.length)];\n this.color2 = colors[Math.floor(Math.random() * colors.length)];\n\n // Position\n this.x = randomRange(-50, width + 50);\n this.y = initial ? randomRange(-height, height) : randomRange(-60, -20);\n this.z = randomRange(0.7, 1.25); // Parallax depth\n\n // Falling velocity (scaled slightly by depth)\n this.vy = randomRange(1.2, 2.6) * this.z;\n this.vx = randomRange(-0.5, 0.8);\n\n // 3D angles (in radians)\n this.pitch = randomRange(0, Math.PI * 2);\n this.yaw = randomRange(0, Math.PI * 2);\n this.roll = randomRange(0, Math.PI * 2);\n\n // Rotational velocities (flutter speed)\n this.dPitch = randomRange(0.015, 0.045);\n this.dYaw = randomRange(0.02, 0.06);\n this.dRoll = randomRange(0.01, 0.03);\n\n // Sway oscillation\n this.oscillationPhase = randomRange(0, Math.PI * 2);\n this.oscillationSpeed = randomRange(0.02, 0.05);\n this.swayAmplitude = randomRange(0.8, 2.2);\n\n // Reset mouse influence\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n\n /**\n * Update particle physics step\n */\n update(\n width: number,\n height: number,\n ambientWind: number,\n mouseX: number | null,\n mouseY: number | null,\n mouseRadius = 140,\n mouseForce = 1.8\n ): void {\n // 3D rotation update\n this.pitch += this.dPitch;\n this.yaw += this.dYaw;\n this.roll += this.dRoll;\n\n // Organic swaying wave\n this.oscillationPhase += this.oscillationSpeed;\n const sway = Math.sin(this.oscillationPhase) * this.swayAmplitude;\n\n // Mouse breeze interaction\n if (mouseX !== null && mouseY !== null) {\n const dx = this.x - mouseX;\n const dy = this.y - mouseY;\n const distSq = dx * dx + dy * dy;\n const radSq = mouseRadius * mouseRadius;\n\n if (distSq < radSq && distSq > 0) {\n const dist = Math.sqrt(distSq);\n const factor = (1 - dist / mouseRadius) * mouseForce;\n // Direction away from mouse with a slight upward and swirling drift\n this.mouseVx += (dx / dist) * factor * 2.5;\n this.mouseVy += ((dy / dist) * factor - 0.5) * 1.5;\n }\n }\n\n // Dampen mouse breeze impulse\n this.mouseVx *= 0.92;\n this.mouseVy *= 0.92;\n\n // Update positions\n this.x += (this.vx + ambientWind + sway + this.mouseVx) * this.z;\n this.y += (this.vy + this.mouseVy) * this.z;\n\n // Reset when moving off-screen\n if (this.y > height + 40 || this.x > width + 80 || this.x < -80) {\n // Loop from top or left depending on wind\n if (ambientWind > 0 && Math.random() < 0.3) {\n // Wrap around from left\n this.x = -30;\n this.y = randomRange(-20, height * 0.7);\n } else {\n this.y = -30;\n this.x = randomRange(-40, width + 40);\n }\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n }\n\n /**\n * Draw the petal using Canvas2D bezier curves, transformed into 3D view\n */\n draw(ctx: CanvasRenderingContext2D): void {\n ctx.save();\n\n // Move to petal center\n ctx.translate(this.x, this.y);\n\n // Apply 3D rotation using 2D projection matrix\n // Roll rotates in 2D plane; Pitch and Yaw squish width/height to simulate 3D rotation\n ctx.rotate(this.roll);\n const scaleX = Math.cos(this.yaw) * this.z;\n const scaleY = Math.cos(this.pitch) * this.z;\n ctx.scale(scaleX, scaleY);\n\n ctx.globalAlpha = Math.max(0, Math.min(1, this.opacity));\n\n // Draw realistic sakura petal shape with notch at tip\n // The petal is drawn centered around (0, 0), with base at (0, length/2) and notched tip at (0, -length/2)\n const w = (this.size / this.aspectRatio) * 0.5;\n const h = this.size * 0.5;\n\n // Gradient shading across the petal\n const grad = ctx.createLinearGradient(0, h, 0, -h);\n grad.addColorStop(0, this.color1);\n grad.addColorStop(1, this.color2);\n ctx.fillStyle = grad;\n\n ctx.beginPath();\n // Start at bottom base of petal\n ctx.moveTo(0, h);\n\n // Left curved side up to the left lobe of notch\n ctx.bezierCurveTo(-w * 1.3, h * 0.4, -w * 1.2, -h * 0.6, -w * 0.35, -h);\n\n // The iconic sakura notch at petal tip\n ctx.quadraticCurveTo(0, -h * 0.75, w * 0.35, -h);\n\n // Right curved side down back to base\n ctx.bezierCurveTo(w * 1.2, -h * 0.6, w * 1.3, h * 0.4, 0, h);\n\n ctx.closePath();\n ctx.fill();\n\n ctx.restore();\n }\n}\n","import { Petal } from \"./petal\";\nimport { randomRange } from \"./math\";\nimport type { CherryBlossomOptions, WindOptions, PetalStyle } from \"./types\";\n\n/**\n * CherryBlossom manages the canvas lifecycle, particle physics simulation loop,\n * dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.\n */\nexport class CherryBlossom {\n /**\n * Static default options\n */\n public static readonly DEFAULT_OPTIONS = {\n root: null as HTMLElement | null,\n number: 45,\n gravityRange: [1.2, 2.6] as [number, number],\n wind: {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n },\n petalStyle: {\n colors: [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"],\n opacityRange: [0.75, 0.95] as [number, number],\n sizeRange: [12, 22] as [number, number]\n },\n style: {\n position: \"fixed\",\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n zIndex: \"999999\"\n } as Partial<CSSStyleDeclaration>,\n respectReducedMotion: true,\n maxPixelRatio: 2\n };\n\n public readonly canvas: HTMLCanvasElement | null = null;\n private readonly ctx: CanvasRenderingContext2D | null = null;\n private readonly root: HTMLElement | null = null;\n private readonly respectReducedMotion: boolean = true;\n private readonly maxPixelRatio: number = 2;\n\n // State\n private petals: Petal[] = [];\n private _number: number = 45;\n private _wind: Required<WindOptions> = {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n };\n private _petalStyle: PetalStyle = {};\n private _gravityRange: [number, number] = [1.2, 2.6];\n \n private animationFrameId: number | null = null;\n private isRunning: boolean = false;\n private isDestroyed: boolean = false;\n\n // Environment & metrics\n private width: number = 0;\n private height: number = 0;\n private pixelRatio: number = 1;\n private resizeObserver: ResizeObserver | null = null;\n private mediaQueryList: MediaQueryList | null = null;\n\n // Wind calculation state\n private windTime: number = 0;\n private currentWind: number = 1.5;\n\n // Mouse tracking\n private mouseX: number | null = null;\n private mouseY: number | null = null;\n private boundOnPointerMove: ((e: PointerEvent | MouseEvent) => void) | null = null;\n private boundOnPointerLeave: (() => void) | null = null;\n private boundOnMotionChange: ((e: MediaQueryListEvent) => void) | null = null;\n\n constructor(options?: CherryBlossomOptions) {\n const opts = { ...CherryBlossom.DEFAULT_OPTIONS, ...options };\n\n this._number = Math.max(0, Math.min(10000, opts.number ?? 45));\n const defaultWind = CherryBlossom.DEFAULT_OPTIONS.wind;\n this._wind = {\n speed: opts.wind?.speed ?? defaultWind.speed,\n gust: opts.wind?.gust ?? defaultWind.gust,\n enableMouseBreeze: opts.wind?.enableMouseBreeze ?? defaultWind.enableMouseBreeze,\n mouseRadius: opts.wind?.mouseRadius ?? defaultWind.mouseRadius,\n mouseForce: opts.wind?.mouseForce ?? defaultWind.mouseForce\n };\n this._petalStyle = {\n ...CherryBlossom.DEFAULT_OPTIONS.petalStyle,\n ...(opts.petalStyle || {})\n };\n this._gravityRange = opts.gravityRange || [1.2, 2.6];\n this.respectReducedMotion = opts.respectReducedMotion ?? true;\n this.maxPixelRatio = opts.maxPixelRatio ?? 2;\n\n // Guard for SSR environments where document/window are undefined\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return;\n }\n\n this.root = opts.root ?? document.body;\n if (!this.root) return;\n\n // Create and attach canvas element\n this.canvas = document.createElement(\"canvas\");\n this.canvas.setAttribute(\"aria-hidden\", \"true\");\n this.ctx = this.canvas.getContext(\"2d\");\n\n // Apply styles\n const styles = { ...CherryBlossom.DEFAULT_OPTIONS.style, ...(opts.style || {}) };\n Object.assign(this.canvas.style, styles);\n\n this.root.appendChild(this.canvas);\n\n // Initial resize and high-DPI setup\n this.updateDimensions();\n\n // Listen to resize\n if (typeof ResizeObserver !== \"undefined\" && this.root) {\n this.resizeObserver = new ResizeObserver(() => this.updateDimensions());\n this.resizeObserver.observe(this.root === document.body ? document.documentElement : this.root);\n } else {\n window.addEventListener(\"resize\", this.updateDimensions);\n }\n\n // Mouse breeze listeners\n if (this._wind.enableMouseBreeze) {\n this.attachMouseListeners();\n }\n\n // Prefers-reduced-motion listener\n if (this.respectReducedMotion && typeof window.matchMedia === \"function\") {\n this.mediaQueryList = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n this.boundOnMotionChange = (e: MediaQueryListEvent) => {\n if (e.matches) {\n this.pause();\n } else if (!this.isDestroyed && this.isRunning) {\n this.resume();\n }\n };\n if (this.mediaQueryList.addEventListener) {\n this.mediaQueryList.addEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n // Spawn petals\n this.initPetals();\n\n // Check reduced motion setting before starting\n const prefersReduced = this.respectReducedMotion && this.mediaQueryList?.matches;\n if (!prefersReduced) {\n this.start();\n } else {\n // Draw static frame once\n this.renderFrame();\n }\n }\n\n // --- Public Getters and Setters ---\n\n public get number(): number {\n return this._number;\n }\n\n public set number(value: number) {\n if (this.isDestroyed) return;\n this._number = Math.max(0, Math.min(10000, Math.floor(value)));\n this.adjustPetalCount();\n }\n\n public get wind(): Required<WindOptions> {\n return { ...this._wind };\n }\n\n public set wind(options: Partial<WindOptions>) {\n if (this.isDestroyed) return;\n this._wind = { ...this._wind, ...options };\n if (options.enableMouseBreeze === false) {\n this.removeMouseListeners();\n } else if (options.enableMouseBreeze === true) {\n this.attachMouseListeners();\n }\n }\n\n public get petalStyle(): PetalStyle {\n return { ...this._petalStyle };\n }\n\n public set petalStyle(style: PetalStyle) {\n if (this.isDestroyed) return;\n this._petalStyle = { ...this._petalStyle, ...style };\n // Re-apply to all petals\n for (const petal of this.petals) {\n petal.reset(this.width, this.height, false, this._petalStyle);\n }\n }\n\n // --- Lifecycle Control Methods ---\n\n /**\n * Starts or resumes the animation loop.\n */\n public start(): void {\n if (this.isDestroyed || this.isRunning) return;\n this.isRunning = true;\n this.resume();\n }\n\n /**\n * Pauses the animation loop.\n */\n public stop(): void {\n this.isRunning = false;\n this.pause();\n }\n\n /**\n * Alias for start()\n */\n public resume(): void {\n if (this.animationFrameId === null && !this.isDestroyed) {\n this.animationFrameId = requestAnimationFrame(this.loop);\n }\n }\n\n /**\n * Alias for stop()\n */\n public pause(): void {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n /**\n * Cleans up canvas, event listeners, observers and removes the element permanently.\n */\n public clear(): void {\n this.isDestroyed = true;\n this.stop();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n } else if (typeof window !== \"undefined\") {\n window.removeEventListener(\"resize\", this.updateDimensions);\n }\n\n if (this.mediaQueryList && this.boundOnMotionChange) {\n if (this.mediaQueryList.removeEventListener) {\n this.mediaQueryList.removeEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n this.removeMouseListeners();\n\n if (this.canvas && this.canvas.parentElement) {\n this.canvas.parentElement.removeChild(this.canvas);\n }\n\n this.petals = [];\n }\n\n // --- Private Implementations ---\n\n private updateDimensions = (): void => {\n if (!this.canvas || !this.root) return;\n\n const isBody = this.root === document.body;\n const clientWidth = isBody ? window.innerWidth : this.root.clientWidth;\n const clientHeight = isBody ? window.innerHeight : this.root.clientHeight;\n\n this.width = clientWidth;\n this.height = clientHeight;\n\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1;\n this.pixelRatio = Math.min(dpr, this.maxPixelRatio);\n\n // Canvas physical buffer resolution\n this.canvas.width = Math.round(this.width * this.pixelRatio);\n this.canvas.height = Math.round(this.height * this.pixelRatio);\n\n // Scale context to match retina pixels\n if (this.ctx) {\n this.ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);\n }\n };\n\n private initPetals(): void {\n this.petals = [];\n for (let i = 0; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n }\n\n private adjustPetalCount(): void {\n const current = this.petals.length;\n if (this._number > current) {\n for (let i = current; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n } else if (this._number < current) {\n this.petals.splice(this._number);\n }\n }\n\n private attachMouseListeners(): void {\n if (typeof window === \"undefined\" || this.boundOnPointerMove) return;\n\n this.boundOnPointerMove = (e: MouseEvent | PointerEvent) => {\n this.mouseX = e.clientX;\n this.mouseY = e.clientY;\n };\n\n this.boundOnPointerLeave = () => {\n this.mouseX = null;\n this.mouseY = null;\n };\n\n window.addEventListener(\"pointermove\", this.boundOnPointerMove, { passive: true });\n window.addEventListener(\"pointerleave\", this.boundOnPointerLeave, { passive: true });\n }\n\n private removeMouseListeners(): void {\n if (typeof window === \"undefined\") return;\n\n if (this.boundOnPointerMove) {\n window.removeEventListener(\"pointermove\", this.boundOnPointerMove);\n this.boundOnPointerMove = null;\n }\n if (this.boundOnPointerLeave) {\n window.removeEventListener(\"pointerleave\", this.boundOnPointerLeave);\n this.boundOnPointerLeave = null;\n }\n this.mouseX = null;\n this.mouseY = null;\n }\n\n private renderFrame(): void {\n if (!this.ctx || !this.canvas) return;\n\n this.ctx.clearRect(0, 0, this.width, this.height);\n\n for (const petal of this.petals) {\n petal.draw(this.ctx);\n }\n }\n\n private loop = (): void => {\n if (!this.isRunning || this.isDestroyed) return;\n\n // Organic wind oscillation over time\n this.windTime += 0.015;\n const gust = Math.sin(this.windTime) * this._wind.gust + Math.cos(this.windTime * 0.4) * 0.5;\n this.currentWind = this._wind.speed + gust;\n\n // Update each petal\n for (let i = 0; i < this.petals.length; i++) {\n this.petals[i].update(\n this.width,\n this.height,\n this.currentWind,\n this.mouseX,\n this.mouseY,\n this._wind.mouseRadius,\n this._wind.mouseForce\n );\n }\n\n this.renderFrame();\n\n this.animationFrameId = requestAnimationFrame(this.loop);\n };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GCGO,SAASK,EAAYC,EAAaC,EAAqB,CAC5D,OAAOD,EAAM,KAAK,OAAO,GAAKC,EAAMD,EACtC,CCEO,IAAME,EAAN,KAAY,CAEjB,EAAI,EACJ,EAAI,EACJ,EAAI,EAGJ,KAAO,GACP,YAAc,KAGd,GAAK,EACL,GAAK,EACL,GAAK,EAGL,MAAQ,EACR,IAAM,EACN,KAAO,EACP,OAAS,EACT,KAAO,EACP,MAAQ,EAGR,iBAAmB,EACnB,iBAAmB,EACnB,cAAgB,EAGhB,OAAS,UACT,OAAS,UACT,QAAU,IAGV,QAAU,EACV,QAAU,EAEV,YAAYC,EAAeC,EAAgBC,EAAoB,CAC7D,KAAK,MAAMF,EAAOC,EAAQ,GAAMC,CAAK,CACvC,CAMA,MAAMF,EAAeC,EAAgBE,EAAU,GAAOD,EAA0B,CAC9E,IAAME,EAAYF,GAAO,WAAa,CAAC,G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K,QAEvB,MAAK,IAAI,UAAU,EAAG,EAAG,KAAK,MAAO,KAAK,MAAM,EAEhD,QAAWP,KAAS,KAAK,OACvBA,EAAM,KAAK,KAAK,GAAG,EAEvB,CAEQ,KAAO,IAAY,CACzB,GAAI,CAAC,KAAK,WAAa,KAAK,YAAa,OAGzC,KAAK,UAAY,KACjB,IAAMQ,EAAO,KAAK,IAAI,KAAK,QAAQ,EAAI,KAAK,MAAM,KAAO,KAAK,IAAI,KAAK,SAAW,EAAG,EAAI,GACzF,KAAK,YAAc,KAAK,MAAM,MAAQA,EAGtC,QAASH,EAAI,EAAGA,EAAI,KAAK,OAAO,OAAQA,IACtC,KAAK,OAAOA,CAAC,EAAE,OACb,KAAK,MACL,KAAK,OACL,KAAK,YACL,KAAK,OACL,KAAK,OACL,KAAK,MAAM,YACX,KAAK,MAAM,UACb,EAGF,KAAK,YAAY,EAEjB,KAAK,iBAAmB,sBAAsB,KAAK,IAAI,CACzD,CACF,EH1XI,OAAO,OAAW,MACnB,OAA8D,cAAgBI,GAIjF,IAAOC,EAAQC","names":["global_exports","__export","CherryBlossom","global_default","__toCommonJS","randomRange","min","max","Petal","width","height","style","initial","sizeRange","opacityRange","colors","randomRange","ambientWind","mouseX","mouseY","mouseRadius","mouseForce","sway","dx","dy","distSq","radSq","dist","factor","ctx","scaleX","scaleY","w","h","grad","CherryBlossom","_CherryBlossom","options","opts","defaultWind","styles","e","value","style","petal","isBody","clientWidth","clientHeight","dpr","i","Petal","current","gust","CherryBlossom","global_default","CherryBlossom"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var CherryBlossomPkg=(()=>{var v=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!g.call(r,i)&&i!==t&&v(r,i,{get:()=>e[i],enumerable:!(n=w(e,i))||n.enumerable});return r};var x=r=>P(v({},"__esModule",{value:!0}),r);var L={};R(L,{CherryBlossom:()=>l,default:()=>O});function s(r,e){return r+Math.random()*(e-r)}var u=class{x=0;y=0;z=0;size=15;aspectRatio=1.25;vx=0;vy=0;vz=0;pitch=0;yaw=0;roll=0;dPitch=0;dYaw=0;dRoll=0;oscillationPhase=0;oscillationSpeed=0;swayAmplitude=0;color1="#ffb7c5";color2="#ff94aa";opacity=.85;mouseVx=0;mouseVy=0;constructor(e,t,n){this.reset(e,t,!0,n)}reset(e,t,n=!1,i){let o=i?.sizeRange??[12,22],a=i?.opacityRange??[.75,.95],h=i?.colors??["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"];this.size=s(o[0],o[1]),this.aspectRatio=s(1.15,1.35),this.opacity=s(a[0],a[1]),this.color1=h[Math.floor(Math.random()*h.length)],this.color2=h[Math.floor(Math.random()*h.length)],this.x=s(-50,e+50),this.y=n?s(-t,t):s(-60,-20),this.z=s(.7,1.25),this.vy=s(1.2,2.6)*this.z,this.vx=s(-.5,.8),this.pitch=s(0,Math.PI*2),this.yaw=s(0,Math.PI*2),this.roll=s(0,Math.PI*2),this.dPitch=s(.015,.045),this.dYaw=s(.02,.06),this.dRoll=s(.01,.03),this.oscillationPhase=s(0,Math.PI*2),this.oscillationSpeed=s(.02,.05),this.swayAmplitude=s(.8,2.2),this.mouseVx=0,this.mouseVy=0}update(e,t,n,i,o,a=140,h=1.8){this.pitch+=this.dPitch,this.yaw+=this.dYaw,this.roll+=this.dRoll,this.oscillationPhase+=this.oscillationSpeed;let f=Math.sin(this.oscillationPhase)*this.swayAmplitude;if(i!==null&&o!==null){let d=this.x-i,m=this.y-o,p=d*d+m*m,y=a*a;if(p<y&&p>0){let c=Math.sqrt(p),b=(1-c/a)*h;this.mouseVx+=d/c*b*2.5,this.mouseVy+=(m/c*b-.5)*1.5}}this.mouseVx*=.92,this.mouseVy*=.92,this.x+=(this.vx+n+f+this.mouseVx)*this.z,this.y+=(this.vy+this.mouseVy)*this.z,(this.y>t+40||this.x>e+80||this.x<-80)&&(n>0&&Math.random()<.3?(this.x=-30,this.y=s(-20,t*.7)):(this.y=-30,this.x=s(-40,e+40)),this.mouseVx=0,this.mouseVy=0)}draw(e){e.save(),e.translate(this.x,this.y),e.rotate(this.roll);let t=Math.cos(this.yaw)*this.z,n=Math.cos(this.pitch)*this.z;e.scale(t,n),e.globalAlpha=Math.max(0,Math.min(1,this.opacity));let i=this.size/this.aspectRatio*.5,o=this.size*.5,a=e.createLinearGradient(0,o,0,-o);a.addColorStop(0,this.color1),a.addColorStop(1,this.color2),e.fillStyle=a,e.beginPath(),e.moveTo(0,o),e.bezierCurveTo(-i*1.3,o*.4,-i*1.2,-o*.6,-i*.35,-o),e.quadraticCurveTo(0,-o*.75,i*.35,-o),e.bezierCurveTo(i*1.2,-o*.6,i*1.3,o*.4,0,o),e.closePath(),e.fill(),e.restore()}};var l=class r{static DEFAULT_OPTIONS={root:null,number:45,gravityRange:[1.2,2.6],wind:{speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8},petalStyle:{colors:["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"],opacityRange:[.75,.95],sizeRange:[12,22]},style:{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"999999"},respectReducedMotion:!0,maxPixelRatio:2};canvas=null;ctx=null;root=null;respectReducedMotion=!0;maxPixelRatio=2;petals=[];_number=45;_wind={speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8};_petalStyle={};_gravityRange=[1.2,2.6];animationFrameId=null;isRunning=!1;isDestroyed=!1;width=0;height=0;pixelRatio=1;resizeObserver=null;mediaQueryList=null;windTime=0;currentWind=1.5;mouseX=null;mouseY=null;boundOnPointerMove=null;boundOnPointerLeave=null;boundOnMotionChange=null;constructor(e){let t={...r.DEFAULT_OPTIONS,...e};this._number=Math.max(0,Math.min(1e4,t.number??45));let n=r.DEFAULT_OPTIONS.wind;if(this._wind={speed:t.wind?.speed??n.speed,gust:t.wind?.gust??n.gust,enableMouseBreeze:t.wind?.enableMouseBreeze??n.enableMouseBreeze,mouseRadius:t.wind?.mouseRadius??n.mouseRadius,mouseForce:t.wind?.mouseForce??n.mouseForce},this._petalStyle={...r.DEFAULT_OPTIONS.petalStyle,...t.petalStyle||{}},this._gravityRange=t.gravityRange||[1.2,2.6],this.respectReducedMotion=t.respectReducedMotion??!0,this.maxPixelRatio=t.maxPixelRatio??2,typeof window>"u"||typeof document>"u"||(this.root=t.root??document.body,!this.root))return;this.canvas=document.createElement("canvas"),this.canvas.setAttribute("aria-hidden","true"),this.ctx=this.canvas.getContext("2d");let i={...r.DEFAULT_OPTIONS.style,...t.style||{}};Object.assign(this.canvas.style,i),this.root.appendChild(this.canvas),this.updateDimensions(),typeof ResizeObserver<"u"&&this.root?(this.resizeObserver=new ResizeObserver(()=>this.updateDimensions()),this.resizeObserver.observe(this.root===document.body?document.documentElement:this.root)):window.addEventListener("resize",this.updateDimensions),this._wind.enableMouseBreeze&&this.attachMouseListeners(),this.respectReducedMotion&&typeof window.matchMedia=="function"&&(this.mediaQueryList=window.matchMedia("(prefers-reduced-motion: reduce)"),this.boundOnMotionChange=a=>{a.matches?this.pause():!this.isDestroyed&&this.isRunning&&this.resume()},this.mediaQueryList.addEventListener&&this.mediaQueryList.addEventListener("change",this.boundOnMotionChange)),this.initPetals(),this.respectReducedMotion&&this.mediaQueryList?.matches?this.renderFrame():this.start()}get number(){return this._number}set number(e){this.isDestroyed||(this._number=Math.max(0,Math.min(1e4,Math.floor(e))),this.adjustPetalCount())}get wind(){return{...this._wind}}set wind(e){this.isDestroyed||(this._wind={...this._wind,...e},e.enableMouseBreeze===!1?this.removeMouseListeners():e.enableMouseBreeze===!0&&this.attachMouseListeners())}get petalStyle(){return{...this._petalStyle}}set petalStyle(e){if(!this.isDestroyed){this._petalStyle={...this._petalStyle,...e};for(let t of this.petals)t.reset(this.width,this.height,!1,this._petalStyle)}}start(){this.isDestroyed||this.isRunning||(this.isRunning=!0,this.resume())}stop(){this.isRunning=!1,this.pause()}resume(){this.animationFrameId===null&&!this.isDestroyed&&(this.animationFrameId=requestAnimationFrame(this.loop))}pause(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}clear(){this.isDestroyed=!0,this.stop(),this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):typeof window<"u"&&window.removeEventListener("resize",this.updateDimensions),this.mediaQueryList&&this.boundOnMotionChange&&this.mediaQueryList.removeEventListener&&this.mediaQueryList.removeEventListener("change",this.boundOnMotionChange),this.removeMouseListeners(),this.canvas&&this.canvas.parentElement&&this.canvas.parentElement.removeChild(this.canvas),this.petals=[]}updateDimensions=()=>{if(!this.canvas||!this.root)return;let e=this.root===document.body,t=e?window.innerWidth:this.root.clientWidth,n=e?window.innerHeight:this.root.clientHeight;this.width=t,this.height=n;let i=typeof window<"u"&&window.devicePixelRatio||1;this.pixelRatio=Math.min(i,this.maxPixelRatio),this.canvas.width=Math.round(this.width*this.pixelRatio),this.canvas.height=Math.round(this.height*this.pixelRatio),this.ctx&&this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)};initPetals(){this.petals=[];for(let e=0;e<this._number;e++)this.petals.push(new u(this.width,this.height,this._petalStyle))}adjustPetalCount(){let e=this.petals.length;if(this._number>e)for(let t=e;t<this._number;t++)this.petals.push(new u(this.width,this.height,this._petalStyle));else this._number<e&&this.petals.splice(this._number)}attachMouseListeners(){typeof window>"u"||this.boundOnPointerMove||(this.boundOnPointerMove=e=>{this.mouseX=e.clientX,this.mouseY=e.clientY},this.boundOnPointerLeave=()=>{this.mouseX=null,this.mouseY=null},window.addEventListener("pointermove",this.boundOnPointerMove,{passive:!0}),window.addEventListener("pointerleave",this.boundOnPointerLeave,{passive:!0}))}removeMouseListeners(){typeof window>"u"||(this.boundOnPointerMove&&(window.removeEventListener("pointermove",this.boundOnPointerMove),this.boundOnPointerMove=null),this.boundOnPointerLeave&&(window.removeEventListener("pointerleave",this.boundOnPointerLeave),this.boundOnPointerLeave=null),this.mouseX=null,this.mouseY=null)}renderFrame(){if(!(!this.ctx||!this.canvas)){this.ctx.clearRect(0,0,this.width,this.height);for(let e of this.petals)e.draw(this.ctx)}}loop=()=>{if(!this.isRunning||this.isDestroyed)return;this.windTime+=.015;let e=Math.sin(this.windTime)*this._wind.gust+Math.cos(this.windTime*.4)*.5;this.currentWind=this._wind.speed+e;for(let t=0;t<this.petals.length;t++)this.petals[t].update(this.width,this.height,this.currentWind,this.mouseX,this.mouseY,this._wind.mouseRadius,this._wind.mouseForce);this.renderFrame(),this.animationFrameId=requestAnimationFrame(this.loop)}};typeof window<"u"&&(window.CherryBlossom=l);var O=l;return x(L);})();
|
|
2
|
+
//# sourceMappingURL=cherryblossom.global.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/global.ts","../src/math.ts","../src/petal.ts","../src/cherryblossom.ts"],"sourcesContent":["import { CherryBlossom } from \"./cherryblossom\";\n\n// Mount directly to window for vanilla CDN <script> tags\nif (typeof window !== \"undefined\") {\n (window as unknown as { CherryBlossom: typeof CherryBlossom }).CherryBlossom = CherryBlossom;\n}\n\nexport { CherryBlossom };\nexport default CherryBlossom;\n","/**\n * Random float in range [min, max)\n */\nexport function randomRange(min: number, max: number): number {\n return min + Math.random() * (max - min);\n}\n\n/**\n * Random integer in range [min, max]\n */\nexport function randomInt(min: number, max: number): number {\n return Math.floor(min + Math.random() * (max - min + 1));\n}\n\n/**\n * Clamp a number between min and max\n */\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, val));\n}\n","import { randomRange } from \"./math\";\nimport type { PetalStyle } from \"./types\";\n\n/**\n * Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),\n * physics velocities, realistic bezier geometry, and wind responsiveness.\n */\nexport class Petal {\n // Coordinates\n x = 0;\n y = 0;\n z = 0; // Simulated depth for scale & parallax\n\n // Dimensions\n size = 15;\n aspectRatio = 1.25; // Length to width ratio\n\n // Velocities\n vx = 0;\n vy = 0;\n vz = 0;\n\n // 3D rotation angles & angular velocities\n pitch = 0; // Tumbling end-over-end\n yaw = 0; // Spinning around horizontal axis\n roll = 0; // Twisting clockwise/counterclockwise\n dPitch = 0;\n dYaw = 0;\n dRoll = 0;\n\n // Flutter & sway oscillation parameters\n oscillationPhase = 0;\n oscillationSpeed = 0;\n swayAmplitude = 0;\n\n // Color & appearance\n color1 = \"#ffb7c5\";\n color2 = \"#ff94aa\";\n opacity = 0.85;\n\n // Mouse wind displacement\n mouseVx = 0;\n mouseVy = 0;\n\n constructor(width: number, height: number, style?: PetalStyle) {\n this.reset(width, height, true, style);\n }\n\n /**\n * Re-initializes petal position, velocities, and 3D rotations.\n * If initial is true, petals are scattered vertically across the whole screen.\n */\n reset(width: number, height: number, initial = false, style?: PetalStyle): void {\n const sizeRange = style?.sizeRange ?? [12, 22];\n const opacityRange = style?.opacityRange ?? [0.75, 0.95];\n const colors = style?.colors ?? [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"];\n\n this.size = randomRange(sizeRange[0], sizeRange[1]);\n this.aspectRatio = randomRange(1.15, 1.35);\n this.opacity = randomRange(opacityRange[0], opacityRange[1]);\n\n // Pick random gradient colors for realistic petal shading\n this.color1 = colors[Math.floor(Math.random() * colors.length)];\n this.color2 = colors[Math.floor(Math.random() * colors.length)];\n\n // Position\n this.x = randomRange(-50, width + 50);\n this.y = initial ? randomRange(-height, height) : randomRange(-60, -20);\n this.z = randomRange(0.7, 1.25); // Parallax depth\n\n // Falling velocity (scaled slightly by depth)\n this.vy = randomRange(1.2, 2.6) * this.z;\n this.vx = randomRange(-0.5, 0.8);\n\n // 3D angles (in radians)\n this.pitch = randomRange(0, Math.PI * 2);\n this.yaw = randomRange(0, Math.PI * 2);\n this.roll = randomRange(0, Math.PI * 2);\n\n // Rotational velocities (flutter speed)\n this.dPitch = randomRange(0.015, 0.045);\n this.dYaw = randomRange(0.02, 0.06);\n this.dRoll = randomRange(0.01, 0.03);\n\n // Sway oscillation\n this.oscillationPhase = randomRange(0, Math.PI * 2);\n this.oscillationSpeed = randomRange(0.02, 0.05);\n this.swayAmplitude = randomRange(0.8, 2.2);\n\n // Reset mouse influence\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n\n /**\n * Update particle physics step\n */\n update(\n width: number,\n height: number,\n ambientWind: number,\n mouseX: number | null,\n mouseY: number | null,\n mouseRadius = 140,\n mouseForce = 1.8\n ): void {\n // 3D rotation update\n this.pitch += this.dPitch;\n this.yaw += this.dYaw;\n this.roll += this.dRoll;\n\n // Organic swaying wave\n this.oscillationPhase += this.oscillationSpeed;\n const sway = Math.sin(this.oscillationPhase) * this.swayAmplitude;\n\n // Mouse breeze interaction\n if (mouseX !== null && mouseY !== null) {\n const dx = this.x - mouseX;\n const dy = this.y - mouseY;\n const distSq = dx * dx + dy * dy;\n const radSq = mouseRadius * mouseRadius;\n\n if (distSq < radSq && distSq > 0) {\n const dist = Math.sqrt(distSq);\n const factor = (1 - dist / mouseRadius) * mouseForce;\n // Direction away from mouse with a slight upward and swirling drift\n this.mouseVx += (dx / dist) * factor * 2.5;\n this.mouseVy += ((dy / dist) * factor - 0.5) * 1.5;\n }\n }\n\n // Dampen mouse breeze impulse\n this.mouseVx *= 0.92;\n this.mouseVy *= 0.92;\n\n // Update positions\n this.x += (this.vx + ambientWind + sway + this.mouseVx) * this.z;\n this.y += (this.vy + this.mouseVy) * this.z;\n\n // Reset when moving off-screen\n if (this.y > height + 40 || this.x > width + 80 || this.x < -80) {\n // Loop from top or left depending on wind\n if (ambientWind > 0 && Math.random() < 0.3) {\n // Wrap around from left\n this.x = -30;\n this.y = randomRange(-20, height * 0.7);\n } else {\n this.y = -30;\n this.x = randomRange(-40, width + 40);\n }\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n }\n\n /**\n * Draw the petal using Canvas2D bezier curves, transformed into 3D view\n */\n draw(ctx: CanvasRenderingContext2D): void {\n ctx.save();\n\n // Move to petal center\n ctx.translate(this.x, this.y);\n\n // Apply 3D rotation using 2D projection matrix\n // Roll rotates in 2D plane; Pitch and Yaw squish width/height to simulate 3D rotation\n ctx.rotate(this.roll);\n const scaleX = Math.cos(this.yaw) * this.z;\n const scaleY = Math.cos(this.pitch) * this.z;\n ctx.scale(scaleX, scaleY);\n\n ctx.globalAlpha = Math.max(0, Math.min(1, this.opacity));\n\n // Draw realistic sakura petal shape with notch at tip\n // The petal is drawn centered around (0, 0), with base at (0, length/2) and notched tip at (0, -length/2)\n const w = (this.size / this.aspectRatio) * 0.5;\n const h = this.size * 0.5;\n\n // Gradient shading across the petal\n const grad = ctx.createLinearGradient(0, h, 0, -h);\n grad.addColorStop(0, this.color1);\n grad.addColorStop(1, this.color2);\n ctx.fillStyle = grad;\n\n ctx.beginPath();\n // Start at bottom base of petal\n ctx.moveTo(0, h);\n\n // Left curved side up to the left lobe of notch\n ctx.bezierCurveTo(-w * 1.3, h * 0.4, -w * 1.2, -h * 0.6, -w * 0.35, -h);\n\n // The iconic sakura notch at petal tip\n ctx.quadraticCurveTo(0, -h * 0.75, w * 0.35, -h);\n\n // Right curved side down back to base\n ctx.bezierCurveTo(w * 1.2, -h * 0.6, w * 1.3, h * 0.4, 0, h);\n\n ctx.closePath();\n ctx.fill();\n\n ctx.restore();\n }\n}\n","import { Petal } from \"./petal\";\nimport { randomRange } from \"./math\";\nimport type { CherryBlossomOptions, WindOptions, PetalStyle } from \"./types\";\n\n/**\n * CherryBlossom manages the canvas lifecycle, particle physics simulation loop,\n * dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.\n */\nexport class CherryBlossom {\n /**\n * Static default options\n */\n public static readonly DEFAULT_OPTIONS = {\n root: null as HTMLElement | null,\n number: 45,\n gravityRange: [1.2, 2.6] as [number, number],\n wind: {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n },\n petalStyle: {\n colors: [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"],\n opacityRange: [0.75, 0.95] as [number, number],\n sizeRange: [12, 22] as [number, number]\n },\n style: {\n position: \"fixed\",\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n zIndex: \"999999\"\n } as Partial<CSSStyleDeclaration>,\n respectReducedMotion: true,\n maxPixelRatio: 2\n };\n\n public readonly canvas: HTMLCanvasElement | null = null;\n private readonly ctx: CanvasRenderingContext2D | null = null;\n private readonly root: HTMLElement | null = null;\n private readonly respectReducedMotion: boolean = true;\n private readonly maxPixelRatio: number = 2;\n\n // State\n private petals: Petal[] = [];\n private _number: number = 45;\n private _wind: Required<WindOptions> = {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n };\n private _petalStyle: PetalStyle = {};\n private _gravityRange: [number, number] = [1.2, 2.6];\n \n private animationFrameId: number | null = null;\n private isRunning: boolean = false;\n private isDestroyed: boolean = false;\n\n // Environment & metrics\n private width: number = 0;\n private height: number = 0;\n private pixelRatio: number = 1;\n private resizeObserver: ResizeObserver | null = null;\n private mediaQueryList: MediaQueryList | null = null;\n\n // Wind calculation state\n private windTime: number = 0;\n private currentWind: number = 1.5;\n\n // Mouse tracking\n private mouseX: number | null = null;\n private mouseY: number | null = null;\n private boundOnPointerMove: ((e: PointerEvent | MouseEvent) => void) | null = null;\n private boundOnPointerLeave: (() => void) | null = null;\n private boundOnMotionChange: ((e: MediaQueryListEvent) => void) | null = null;\n\n constructor(options?: CherryBlossomOptions) {\n const opts = { ...CherryBlossom.DEFAULT_OPTIONS, ...options };\n\n this._number = Math.max(0, Math.min(10000, opts.number ?? 45));\n const defaultWind = CherryBlossom.DEFAULT_OPTIONS.wind;\n this._wind = {\n speed: opts.wind?.speed ?? defaultWind.speed,\n gust: opts.wind?.gust ?? defaultWind.gust,\n enableMouseBreeze: opts.wind?.enableMouseBreeze ?? defaultWind.enableMouseBreeze,\n mouseRadius: opts.wind?.mouseRadius ?? defaultWind.mouseRadius,\n mouseForce: opts.wind?.mouseForce ?? defaultWind.mouseForce\n };\n this._petalStyle = {\n ...CherryBlossom.DEFAULT_OPTIONS.petalStyle,\n ...(opts.petalStyle || {})\n };\n this._gravityRange = opts.gravityRange || [1.2, 2.6];\n this.respectReducedMotion = opts.respectReducedMotion ?? true;\n this.maxPixelRatio = opts.maxPixelRatio ?? 2;\n\n // Guard for SSR environments where document/window are undefined\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return;\n }\n\n this.root = opts.root ?? document.body;\n if (!this.root) return;\n\n // Create and attach canvas element\n this.canvas = document.createElement(\"canvas\");\n this.canvas.setAttribute(\"aria-hidden\", \"true\");\n this.ctx = this.canvas.getContext(\"2d\");\n\n // Apply styles\n const styles = { ...CherryBlossom.DEFAULT_OPTIONS.style, ...(opts.style || {}) };\n Object.assign(this.canvas.style, styles);\n\n this.root.appendChild(this.canvas);\n\n // Initial resize and high-DPI setup\n this.updateDimensions();\n\n // Listen to resize\n if (typeof ResizeObserver !== \"undefined\" && this.root) {\n this.resizeObserver = new ResizeObserver(() => this.updateDimensions());\n this.resizeObserver.observe(this.root === document.body ? document.documentElement : this.root);\n } else {\n window.addEventListener(\"resize\", this.updateDimensions);\n }\n\n // Mouse breeze listeners\n if (this._wind.enableMouseBreeze) {\n this.attachMouseListeners();\n }\n\n // Prefers-reduced-motion listener\n if (this.respectReducedMotion && typeof window.matchMedia === \"function\") {\n this.mediaQueryList = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n this.boundOnMotionChange = (e: MediaQueryListEvent) => {\n if (e.matches) {\n this.pause();\n } else if (!this.isDestroyed && this.isRunning) {\n this.resume();\n }\n };\n if (this.mediaQueryList.addEventListener) {\n this.mediaQueryList.addEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n // Spawn petals\n this.initPetals();\n\n // Check reduced motion setting before starting\n const prefersReduced = this.respectReducedMotion && this.mediaQueryList?.matches;\n if (!prefersReduced) {\n this.start();\n } else {\n // Draw static frame once\n this.renderFrame();\n }\n }\n\n // --- Public Getters and Setters ---\n\n public get number(): number {\n return this._number;\n }\n\n public set number(value: number) {\n if (this.isDestroyed) return;\n this._number = Math.max(0, Math.min(10000, Math.floor(value)));\n this.adjustPetalCount();\n }\n\n public get wind(): Required<WindOptions> {\n return { ...this._wind };\n }\n\n public set wind(options: Partial<WindOptions>) {\n if (this.isDestroyed) return;\n this._wind = { ...this._wind, ...options };\n if (options.enableMouseBreeze === false) {\n this.removeMouseListeners();\n } else if (options.enableMouseBreeze === true) {\n this.attachMouseListeners();\n }\n }\n\n public get petalStyle(): PetalStyle {\n return { ...this._petalStyle };\n }\n\n public set petalStyle(style: PetalStyle) {\n if (this.isDestroyed) return;\n this._petalStyle = { ...this._petalStyle, ...style };\n // Re-apply to all petals\n for (const petal of this.petals) {\n petal.reset(this.width, this.height, false, this._petalStyle);\n }\n }\n\n // --- Lifecycle Control Methods ---\n\n /**\n * Starts or resumes the animation loop.\n */\n public start(): void {\n if (this.isDestroyed || this.isRunning) return;\n this.isRunning = true;\n this.resume();\n }\n\n /**\n * Pauses the animation loop.\n */\n public stop(): void {\n this.isRunning = false;\n this.pause();\n }\n\n /**\n * Alias for start()\n */\n public resume(): void {\n if (this.animationFrameId === null && !this.isDestroyed) {\n this.animationFrameId = requestAnimationFrame(this.loop);\n }\n }\n\n /**\n * Alias for stop()\n */\n public pause(): void {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n /**\n * Cleans up canvas, event listeners, observers and removes the element permanently.\n */\n public clear(): void {\n this.isDestroyed = true;\n this.stop();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n } else if (typeof window !== \"undefined\") {\n window.removeEventListener(\"resize\", this.updateDimensions);\n }\n\n if (this.mediaQueryList && this.boundOnMotionChange) {\n if (this.mediaQueryList.removeEventListener) {\n this.mediaQueryList.removeEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n this.removeMouseListeners();\n\n if (this.canvas && this.canvas.parentElement) {\n this.canvas.parentElement.removeChild(this.canvas);\n }\n\n this.petals = [];\n }\n\n // --- Private Implementations ---\n\n private updateDimensions = (): void => {\n if (!this.canvas || !this.root) return;\n\n const isBody = this.root === document.body;\n const clientWidth = isBody ? window.innerWidth : this.root.clientWidth;\n const clientHeight = isBody ? window.innerHeight : this.root.clientHeight;\n\n this.width = clientWidth;\n this.height = clientHeight;\n\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1;\n this.pixelRatio = Math.min(dpr, this.maxPixelRatio);\n\n // Canvas physical buffer resolution\n this.canvas.width = Math.round(this.width * this.pixelRatio);\n this.canvas.height = Math.round(this.height * this.pixelRatio);\n\n // Scale context to match retina pixels\n if (this.ctx) {\n this.ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);\n }\n };\n\n private initPetals(): void {\n this.petals = [];\n for (let i = 0; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n }\n\n private adjustPetalCount(): void {\n const current = this.petals.length;\n if (this._number > current) {\n for (let i = current; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n } else if (this._number < current) {\n this.petals.splice(this._number);\n }\n }\n\n private attachMouseListeners(): void {\n if (typeof window === \"undefined\" || this.boundOnPointerMove) return;\n\n this.boundOnPointerMove = (e: MouseEvent | PointerEvent) => {\n this.mouseX = e.clientX;\n this.mouseY = e.clientY;\n };\n\n this.boundOnPointerLeave = () => {\n this.mouseX = null;\n this.mouseY = null;\n };\n\n window.addEventListener(\"pointermove\", this.boundOnPointerMove, { passive: true });\n window.addEventListener(\"pointerleave\", this.boundOnPointerLeave, { passive: true });\n }\n\n private removeMouseListeners(): void {\n if (typeof window === \"undefined\") return;\n\n if (this.boundOnPointerMove) {\n window.removeEventListener(\"pointermove\", this.boundOnPointerMove);\n this.boundOnPointerMove = null;\n }\n if (this.boundOnPointerLeave) {\n window.removeEventListener(\"pointerleave\", this.boundOnPointerLeave);\n this.boundOnPointerLeave = null;\n }\n this.mouseX = null;\n this.mouseY = null;\n }\n\n private renderFrame(): void {\n if (!this.ctx || !this.canvas) return;\n\n this.ctx.clearRect(0, 0, this.width, this.height);\n\n for (const petal of this.petals) {\n petal.draw(this.ctx);\n }\n }\n\n private loop = (): void => {\n if (!this.isRunning || this.isDestroyed) return;\n\n // Organic wind oscillation over time\n this.windTime += 0.015;\n const gust = Math.sin(this.windTime) * this._wind.gust + Math.cos(this.windTime * 0.4) * 0.5;\n this.currentWind = this._wind.speed + gust;\n\n // Update each petal\n for (let i = 0; i < this.petals.length; i++) {\n this.petals[i].update(\n this.width,\n this.height,\n this.currentWind,\n this.mouseX,\n this.mouseY,\n this._wind.mouseRadius,\n this._wind.mouseForce\n );\n }\n\n this.renderFrame();\n\n this.animationFrameId = requestAnimationFrame(this.loop);\n };\n}\n"],"mappings":"ocAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,YAAAC,ICGO,SAASC,EAAYC,EAAaC,EAAqB,CAC5D,OAAOD,EAAM,KAAK,OAAO,GAAKC,EAAMD,EACtC,CCEO,IAAME,EAAN,KAAY,CAEjB,EAAI,EACJ,EAAI,EACJ,EAAI,EAGJ,KAAO,GACP,YAAc,KAGd,GAAK,EACL,GAAK,EACL,GAAK,EAGL,MAAQ,EACR,IAAM,EACN,KAAO,EACP,OAAS,EACT,KAAO,EACP,MAAQ,EAGR,iBAAmB,EACnB,iBAAmB,EACnB,cAAgB,EAGhB,OAAS,UACT,OAAS,UACT,QAAU,IAGV,QAAU,EACV,QAAU,EAEV,YAAYC,EAAeC,EAAgBC,EAAoB,CAC7D,KAAK,MAAMF,EAAOC,EAAQ,GAAMC,CAAK,CACvC,CAMA,MAAMF,E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,KAAK,OAAS,KAChB,CAEQ,aAAoB,CAC1B,GAAI,GAAC,KAAK,KAAO,CAAC,KAAK,QAEvB,MAAK,IAAI,UAAU,EAAG,EAAG,KAAK,MAAO,KAAK,MAAM,EAEhD,QAAWP,KAAS,KAAK,OACvBA,EAAM,KAAK,KAAK,GAAG,EAEvB,CAEQ,KAAO,IAAY,CACzB,GAAI,CAAC,KAAK,WAAa,KAAK,YAAa,OAGzC,KAAK,UAAY,KACjB,IAAMQ,EAAO,KAAK,IAAI,KAAK,QAAQ,EAAI,KAAK,MAAM,KAAO,KAAK,IAAI,KAAK,SAAW,EAAG,EAAI,GACzF,KAAK,YAAc,KAAK,MAAM,MAAQA,EAGtC,QAASH,EAAI,EAAGA,EAAI,KAAK,OAAO,OAAQA,IACtC,KAAK,OAAOA,CAAC,EAAE,OACb,KAAK,MACL,KAAK,OACL,KAAK,YACL,KAAK,OACL,KAAK,OACL,KAAK,MAAM,YACX,KAAK,MAAM,UACb,EAGF,KAAK,YAAY,EAEjB,KAAK,iBAAmB,sBAAsB,KAAK,IAAI,CACzD,CACF,EH1XI,OAAO,OAAW,MACnB,OAA8D,cAAgBI,GAIjF,IAAOC,EAAQC","names":["global_exports","__export","CherryBlossom","global_default","randomRange","min","max","Petal","width","height","style","initial","sizeRange","opacityRange","colors","randomRange","ambientWind","mouseX","mouseY","mouseRadius","mouseForce","sway","dx","dy","distSq","radSq","dist","factor","ctx","scaleX","scaleY","w","h","grad","CherryBlossom","_CherryBlossom","options","opts","defaultWind","styles","e","value","style","petal","isBody","clientWidth","clientHeight","dpr","i","Petal","current","gust","CherryBlossom","global_default","CherryBlossom"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/global.ts"],"sourcesContent":["import { CherryBlossom } from \"./cherryblossom\";\n\n// Mount directly to window for vanilla CDN <script> tags\nif (typeof window !== \"undefined\") {\n (window as unknown as { CherryBlossom: typeof CherryBlossom }).CherryBlossom = CherryBlossom;\n}\n\nexport { CherryBlossom };\nexport default CherryBlossom;\n"],"mappings":"yCAGI,OAAO,OAAW,MACnB,OAA8D,cAAgBA,GAIjF,IAAOC,EAAQC","names":["CherryBlossom","global_default","CherryBlossom"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function i(a,e){return a+Math.random()*(e-a)}var l=class{x=0;y=0;z=0;size=15;aspectRatio=1.25;vx=0;vy=0;vz=0;pitch=0;yaw=0;roll=0;dPitch=0;dYaw=0;dRoll=0;oscillationPhase=0;oscillationSpeed=0;swayAmplitude=0;color1="#ffb7c5";color2="#ff94aa";opacity=.85;mouseVx=0;mouseVy=0;constructor(e,t,o){this.reset(e,t,!0,o)}reset(e,t,o=!1,n){let s=n?.sizeRange??[12,22],r=n?.opacityRange??[.75,.95],h=n?.colors??["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"];this.size=i(s[0],s[1]),this.aspectRatio=i(1.15,1.35),this.opacity=i(r[0],r[1]),this.color1=h[Math.floor(Math.random()*h.length)],this.color2=h[Math.floor(Math.random()*h.length)],this.x=i(-50,e+50),this.y=o?i(-t,t):i(-60,-20),this.z=i(.7,1.25),this.vy=i(1.2,2.6)*this.z,this.vx=i(-.5,.8),this.pitch=i(0,Math.PI*2),this.yaw=i(0,Math.PI*2),this.roll=i(0,Math.PI*2),this.dPitch=i(.015,.045),this.dYaw=i(.02,.06),this.dRoll=i(.01,.03),this.oscillationPhase=i(0,Math.PI*2),this.oscillationSpeed=i(.02,.05),this.swayAmplitude=i(.8,2.2),this.mouseVx=0,this.mouseVy=0}update(e,t,o,n,s,r=140,h=1.8){this.pitch+=this.dPitch,this.yaw+=this.dYaw,this.roll+=this.dRoll,this.oscillationPhase+=this.oscillationSpeed;let b=Math.sin(this.oscillationPhase)*this.swayAmplitude;if(n!==null&&s!==null){let u=this.x-n,d=this.y-s,m=u*u+d*d,f=r*r;if(m<f&&m>0){let p=Math.sqrt(m),c=(1-p/r)*h;this.mouseVx+=u/p*c*2.5,this.mouseVy+=(d/p*c-.5)*1.5}}this.mouseVx*=.92,this.mouseVy*=.92,this.x+=(this.vx+o+b+this.mouseVx)*this.z,this.y+=(this.vy+this.mouseVy)*this.z,(this.y>t+40||this.x>e+80||this.x<-80)&&(o>0&&Math.random()<.3?(this.x=-30,this.y=i(-20,t*.7)):(this.y=-30,this.x=i(-40,e+40)),this.mouseVx=0,this.mouseVy=0)}draw(e){e.save(),e.translate(this.x,this.y),e.rotate(this.roll);let t=Math.cos(this.yaw)*this.z,o=Math.cos(this.pitch)*this.z;e.scale(t,o),e.globalAlpha=Math.max(0,Math.min(1,this.opacity));let n=this.size/this.aspectRatio*.5,s=this.size*.5,r=e.createLinearGradient(0,s,0,-s);r.addColorStop(0,this.color1),r.addColorStop(1,this.color2),e.fillStyle=r,e.beginPath(),e.moveTo(0,s),e.bezierCurveTo(-n*1.3,s*.4,-n*1.2,-s*.6,-n*.35,-s),e.quadraticCurveTo(0,-s*.75,n*.35,-s),e.bezierCurveTo(n*1.2,-s*.6,n*1.3,s*.4,0,s),e.closePath(),e.fill(),e.restore()}};var v=class a{static DEFAULT_OPTIONS={root:null,number:45,gravityRange:[1.2,2.6],wind:{speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8},petalStyle:{colors:["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"],opacityRange:[.75,.95],sizeRange:[12,22]},style:{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"999999"},respectReducedMotion:!0,maxPixelRatio:2};canvas=null;ctx=null;root=null;respectReducedMotion=!0;maxPixelRatio=2;petals=[];_number=45;_wind={speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8};_petalStyle={};_gravityRange=[1.2,2.6];animationFrameId=null;isRunning=!1;isDestroyed=!1;width=0;height=0;pixelRatio=1;resizeObserver=null;mediaQueryList=null;windTime=0;currentWind=1.5;mouseX=null;mouseY=null;boundOnPointerMove=null;boundOnPointerLeave=null;boundOnMotionChange=null;constructor(e){let t={...a.DEFAULT_OPTIONS,...e};this._number=Math.max(0,Math.min(1e4,t.number??45));let o=a.DEFAULT_OPTIONS.wind;if(this._wind={speed:t.wind?.speed??o.speed,gust:t.wind?.gust??o.gust,enableMouseBreeze:t.wind?.enableMouseBreeze??o.enableMouseBreeze,mouseRadius:t.wind?.mouseRadius??o.mouseRadius,mouseForce:t.wind?.mouseForce??o.mouseForce},this._petalStyle={...a.DEFAULT_OPTIONS.petalStyle,...t.petalStyle||{}},this._gravityRange=t.gravityRange||[1.2,2.6],this.respectReducedMotion=t.respectReducedMotion??!0,this.maxPixelRatio=t.maxPixelRatio??2,typeof window>"u"||typeof document>"u"||(this.root=t.root??document.body,!this.root))return;this.canvas=document.createElement("canvas"),this.canvas.setAttribute("aria-hidden","true"),this.ctx=this.canvas.getContext("2d");let n={...a.DEFAULT_OPTIONS.style,...t.style||{}};Object.assign(this.canvas.style,n),this.root.appendChild(this.canvas),this.updateDimensions(),typeof ResizeObserver<"u"&&this.root?(this.resizeObserver=new ResizeObserver(()=>this.updateDimensions()),this.resizeObserver.observe(this.root===document.body?document.documentElement:this.root)):window.addEventListener("resize",this.updateDimensions),this._wind.enableMouseBreeze&&this.attachMouseListeners(),this.respectReducedMotion&&typeof window.matchMedia=="function"&&(this.mediaQueryList=window.matchMedia("(prefers-reduced-motion: reduce)"),this.boundOnMotionChange=r=>{r.matches?this.pause():!this.isDestroyed&&this.isRunning&&this.resume()},this.mediaQueryList.addEventListener&&this.mediaQueryList.addEventListener("change",this.boundOnMotionChange)),this.initPetals(),this.respectReducedMotion&&this.mediaQueryList?.matches?this.renderFrame():this.start()}get number(){return this._number}set number(e){this.isDestroyed||(this._number=Math.max(0,Math.min(1e4,Math.floor(e))),this.adjustPetalCount())}get wind(){return{...this._wind}}set wind(e){this.isDestroyed||(this._wind={...this._wind,...e},e.enableMouseBreeze===!1?this.removeMouseListeners():e.enableMouseBreeze===!0&&this.attachMouseListeners())}get petalStyle(){return{...this._petalStyle}}set petalStyle(e){if(!this.isDestroyed){this._petalStyle={...this._petalStyle,...e};for(let t of this.petals)t.reset(this.width,this.height,!1,this._petalStyle)}}start(){this.isDestroyed||this.isRunning||(this.isRunning=!0,this.resume())}stop(){this.isRunning=!1,this.pause()}resume(){this.animationFrameId===null&&!this.isDestroyed&&(this.animationFrameId=requestAnimationFrame(this.loop))}pause(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}clear(){this.isDestroyed=!0,this.stop(),this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):typeof window<"u"&&window.removeEventListener("resize",this.updateDimensions),this.mediaQueryList&&this.boundOnMotionChange&&this.mediaQueryList.removeEventListener&&this.mediaQueryList.removeEventListener("change",this.boundOnMotionChange),this.removeMouseListeners(),this.canvas&&this.canvas.parentElement&&this.canvas.parentElement.removeChild(this.canvas),this.petals=[]}updateDimensions=()=>{if(!this.canvas||!this.root)return;let e=this.root===document.body,t=e?window.innerWidth:this.root.clientWidth,o=e?window.innerHeight:this.root.clientHeight;this.width=t,this.height=o;let n=typeof window<"u"&&window.devicePixelRatio||1;this.pixelRatio=Math.min(n,this.maxPixelRatio),this.canvas.width=Math.round(this.width*this.pixelRatio),this.canvas.height=Math.round(this.height*this.pixelRatio),this.ctx&&this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)};initPetals(){this.petals=[];for(let e=0;e<this._number;e++)this.petals.push(new l(this.width,this.height,this._petalStyle))}adjustPetalCount(){let e=this.petals.length;if(this._number>e)for(let t=e;t<this._number;t++)this.petals.push(new l(this.width,this.height,this._petalStyle));else this._number<e&&this.petals.splice(this._number)}attachMouseListeners(){typeof window>"u"||this.boundOnPointerMove||(this.boundOnPointerMove=e=>{this.mouseX=e.clientX,this.mouseY=e.clientY},this.boundOnPointerLeave=()=>{this.mouseX=null,this.mouseY=null},window.addEventListener("pointermove",this.boundOnPointerMove,{passive:!0}),window.addEventListener("pointerleave",this.boundOnPointerLeave,{passive:!0}))}removeMouseListeners(){typeof window>"u"||(this.boundOnPointerMove&&(window.removeEventListener("pointermove",this.boundOnPointerMove),this.boundOnPointerMove=null),this.boundOnPointerLeave&&(window.removeEventListener("pointerleave",this.boundOnPointerLeave),this.boundOnPointerLeave=null),this.mouseX=null,this.mouseY=null)}renderFrame(){if(!(!this.ctx||!this.canvas)){this.ctx.clearRect(0,0,this.width,this.height);for(let e of this.petals)e.draw(this.ctx)}}loop=()=>{if(!this.isRunning||this.isDestroyed)return;this.windTime+=.015;let e=Math.sin(this.windTime)*this._wind.gust+Math.cos(this.windTime*.4)*.5;this.currentWind=this._wind.speed+e;for(let t=0;t<this.petals.length;t++)this.petals[t].update(this.width,this.height,this.currentWind,this.mouseX,this.mouseY,this._wind.mouseRadius,this._wind.mouseForce);this.renderFrame(),this.animationFrameId=requestAnimationFrame(this.loop)}};export{l as a,v as b};
|
|
2
|
+
//# sourceMappingURL=chunk-RDJ3OPGN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/math.ts","../src/petal.ts","../src/cherryblossom.ts"],"sourcesContent":["/**\n * Random float in range [min, max)\n */\nexport function randomRange(min: number, max: number): number {\n return min + Math.random() * (max - min);\n}\n\n/**\n * Random integer in range [min, max]\n */\nexport function randomInt(min: number, max: number): number {\n return Math.floor(min + Math.random() * (max - min + 1));\n}\n\n/**\n * Clamp a number between min and max\n */\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, val));\n}\n","import { randomRange } from \"./math\";\nimport type { PetalStyle } from \"./types\";\n\n/**\n * Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),\n * physics velocities, realistic bezier geometry, and wind responsiveness.\n */\nexport class Petal {\n // Coordinates\n x = 0;\n y = 0;\n z = 0; // Simulated depth for scale & parallax\n\n // Dimensions\n size = 15;\n aspectRatio = 1.25; // Length to width ratio\n\n // Velocities\n vx = 0;\n vy = 0;\n vz = 0;\n\n // 3D rotation angles & angular velocities\n pitch = 0; // Tumbling end-over-end\n yaw = 0; // Spinning around horizontal axis\n roll = 0; // Twisting clockwise/counterclockwise\n dPitch = 0;\n dYaw = 0;\n dRoll = 0;\n\n // Flutter & sway oscillation parameters\n oscillationPhase = 0;\n oscillationSpeed = 0;\n swayAmplitude = 0;\n\n // Color & appearance\n color1 = \"#ffb7c5\";\n color2 = \"#ff94aa\";\n opacity = 0.85;\n\n // Mouse wind displacement\n mouseVx = 0;\n mouseVy = 0;\n\n constructor(width: number, height: number, style?: PetalStyle) {\n this.reset(width, height, true, style);\n }\n\n /**\n * Re-initializes petal position, velocities, and 3D rotations.\n * If initial is true, petals are scattered vertically across the whole screen.\n */\n reset(width: number, height: number, initial = false, style?: PetalStyle): void {\n const sizeRange = style?.sizeRange ?? [12, 22];\n const opacityRange = style?.opacityRange ?? [0.75, 0.95];\n const colors = style?.colors ?? [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"];\n\n this.size = randomRange(sizeRange[0], sizeRange[1]);\n this.aspectRatio = randomRange(1.15, 1.35);\n this.opacity = randomRange(opacityRange[0], opacityRange[1]);\n\n // Pick random gradient colors for realistic petal shading\n this.color1 = colors[Math.floor(Math.random() * colors.length)];\n this.color2 = colors[Math.floor(Math.random() * colors.length)];\n\n // Position\n this.x = randomRange(-50, width + 50);\n this.y = initial ? randomRange(-height, height) : randomRange(-60, -20);\n this.z = randomRange(0.7, 1.25); // Parallax depth\n\n // Falling velocity (scaled slightly by depth)\n this.vy = randomRange(1.2, 2.6) * this.z;\n this.vx = randomRange(-0.5, 0.8);\n\n // 3D angles (in radians)\n this.pitch = randomRange(0, Math.PI * 2);\n this.yaw = randomRange(0, Math.PI * 2);\n this.roll = randomRange(0, Math.PI * 2);\n\n // Rotational velocities (flutter speed)\n this.dPitch = randomRange(0.015, 0.045);\n this.dYaw = randomRange(0.02, 0.06);\n this.dRoll = randomRange(0.01, 0.03);\n\n // Sway oscillation\n this.oscillationPhase = randomRange(0, Math.PI * 2);\n this.oscillationSpeed = randomRange(0.02, 0.05);\n this.swayAmplitude = randomRange(0.8, 2.2);\n\n // Reset mouse influence\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n\n /**\n * Update particle physics step\n */\n update(\n width: number,\n height: number,\n ambientWind: number,\n mouseX: number | null,\n mouseY: number | null,\n mouseRadius = 140,\n mouseForce = 1.8\n ): void {\n // 3D rotation update\n this.pitch += this.dPitch;\n this.yaw += this.dYaw;\n this.roll += this.dRoll;\n\n // Organic swaying wave\n this.oscillationPhase += this.oscillationSpeed;\n const sway = Math.sin(this.oscillationPhase) * this.swayAmplitude;\n\n // Mouse breeze interaction\n if (mouseX !== null && mouseY !== null) {\n const dx = this.x - mouseX;\n const dy = this.y - mouseY;\n const distSq = dx * dx + dy * dy;\n const radSq = mouseRadius * mouseRadius;\n\n if (distSq < radSq && distSq > 0) {\n const dist = Math.sqrt(distSq);\n const factor = (1 - dist / mouseRadius) * mouseForce;\n // Direction away from mouse with a slight upward and swirling drift\n this.mouseVx += (dx / dist) * factor * 2.5;\n this.mouseVy += ((dy / dist) * factor - 0.5) * 1.5;\n }\n }\n\n // Dampen mouse breeze impulse\n this.mouseVx *= 0.92;\n this.mouseVy *= 0.92;\n\n // Update positions\n this.x += (this.vx + ambientWind + sway + this.mouseVx) * this.z;\n this.y += (this.vy + this.mouseVy) * this.z;\n\n // Reset when moving off-screen\n if (this.y > height + 40 || this.x > width + 80 || this.x < -80) {\n // Loop from top or left depending on wind\n if (ambientWind > 0 && Math.random() < 0.3) {\n // Wrap around from left\n this.x = -30;\n this.y = randomRange(-20, height * 0.7);\n } else {\n this.y = -30;\n this.x = randomRange(-40, width + 40);\n }\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n }\n\n /**\n * Draw the petal using Canvas2D bezier curves, transformed into 3D view\n */\n draw(ctx: CanvasRenderingContext2D): void {\n ctx.save();\n\n // Move to petal center\n ctx.translate(this.x, this.y);\n\n // Apply 3D rotation using 2D projection matrix\n // Roll rotates in 2D plane; Pitch and Yaw squish width/height to simulate 3D rotation\n ctx.rotate(this.roll);\n const scaleX = Math.cos(this.yaw) * this.z;\n const scaleY = Math.cos(this.pitch) * this.z;\n ctx.scale(scaleX, scaleY);\n\n ctx.globalAlpha = Math.max(0, Math.min(1, this.opacity));\n\n // Draw realistic sakura petal shape with notch at tip\n // The petal is drawn centered around (0, 0), with base at (0, length/2) and notched tip at (0, -length/2)\n const w = (this.size / this.aspectRatio) * 0.5;\n const h = this.size * 0.5;\n\n // Gradient shading across the petal\n const grad = ctx.createLinearGradient(0, h, 0, -h);\n grad.addColorStop(0, this.color1);\n grad.addColorStop(1, this.color2);\n ctx.fillStyle = grad;\n\n ctx.beginPath();\n // Start at bottom base of petal\n ctx.moveTo(0, h);\n\n // Left curved side up to the left lobe of notch\n ctx.bezierCurveTo(-w * 1.3, h * 0.4, -w * 1.2, -h * 0.6, -w * 0.35, -h);\n\n // The iconic sakura notch at petal tip\n ctx.quadraticCurveTo(0, -h * 0.75, w * 0.35, -h);\n\n // Right curved side down back to base\n ctx.bezierCurveTo(w * 1.2, -h * 0.6, w * 1.3, h * 0.4, 0, h);\n\n ctx.closePath();\n ctx.fill();\n\n ctx.restore();\n }\n}\n","import { Petal } from \"./petal\";\nimport { randomRange } from \"./math\";\nimport type { CherryBlossomOptions, WindOptions, PetalStyle } from \"./types\";\n\n/**\n * CherryBlossom manages the canvas lifecycle, particle physics simulation loop,\n * dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.\n */\nexport class CherryBlossom {\n /**\n * Static default options\n */\n public static readonly DEFAULT_OPTIONS = {\n root: null as HTMLElement | null,\n number: 45,\n gravityRange: [1.2, 2.6] as [number, number],\n wind: {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n },\n petalStyle: {\n colors: [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"],\n opacityRange: [0.75, 0.95] as [number, number],\n sizeRange: [12, 22] as [number, number]\n },\n style: {\n position: \"fixed\",\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n zIndex: \"999999\"\n } as Partial<CSSStyleDeclaration>,\n respectReducedMotion: true,\n maxPixelRatio: 2\n };\n\n public readonly canvas: HTMLCanvasElement | null = null;\n private readonly ctx: CanvasRenderingContext2D | null = null;\n private readonly root: HTMLElement | null = null;\n private readonly respectReducedMotion: boolean = true;\n private readonly maxPixelRatio: number = 2;\n\n // State\n private petals: Petal[] = [];\n private _number: number = 45;\n private _wind: Required<WindOptions> = {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n };\n private _petalStyle: PetalStyle = {};\n private _gravityRange: [number, number] = [1.2, 2.6];\n \n private animationFrameId: number | null = null;\n private isRunning: boolean = false;\n private isDestroyed: boolean = false;\n\n // Environment & metrics\n private width: number = 0;\n private height: number = 0;\n private pixelRatio: number = 1;\n private resizeObserver: ResizeObserver | null = null;\n private mediaQueryList: MediaQueryList | null = null;\n\n // Wind calculation state\n private windTime: number = 0;\n private currentWind: number = 1.5;\n\n // Mouse tracking\n private mouseX: number | null = null;\n private mouseY: number | null = null;\n private boundOnPointerMove: ((e: PointerEvent | MouseEvent) => void) | null = null;\n private boundOnPointerLeave: (() => void) | null = null;\n private boundOnMotionChange: ((e: MediaQueryListEvent) => void) | null = null;\n\n constructor(options?: CherryBlossomOptions) {\n const opts = { ...CherryBlossom.DEFAULT_OPTIONS, ...options };\n\n this._number = Math.max(0, Math.min(10000, opts.number ?? 45));\n const defaultWind = CherryBlossom.DEFAULT_OPTIONS.wind;\n this._wind = {\n speed: opts.wind?.speed ?? defaultWind.speed,\n gust: opts.wind?.gust ?? defaultWind.gust,\n enableMouseBreeze: opts.wind?.enableMouseBreeze ?? defaultWind.enableMouseBreeze,\n mouseRadius: opts.wind?.mouseRadius ?? defaultWind.mouseRadius,\n mouseForce: opts.wind?.mouseForce ?? defaultWind.mouseForce\n };\n this._petalStyle = {\n ...CherryBlossom.DEFAULT_OPTIONS.petalStyle,\n ...(opts.petalStyle || {})\n };\n this._gravityRange = opts.gravityRange || [1.2, 2.6];\n this.respectReducedMotion = opts.respectReducedMotion ?? true;\n this.maxPixelRatio = opts.maxPixelRatio ?? 2;\n\n // Guard for SSR environments where document/window are undefined\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return;\n }\n\n this.root = opts.root ?? document.body;\n if (!this.root) return;\n\n // Create and attach canvas element\n this.canvas = document.createElement(\"canvas\");\n this.canvas.setAttribute(\"aria-hidden\", \"true\");\n this.ctx = this.canvas.getContext(\"2d\");\n\n // Apply styles\n const styles = { ...CherryBlossom.DEFAULT_OPTIONS.style, ...(opts.style || {}) };\n Object.assign(this.canvas.style, styles);\n\n this.root.appendChild(this.canvas);\n\n // Initial resize and high-DPI setup\n this.updateDimensions();\n\n // Listen to resize\n if (typeof ResizeObserver !== \"undefined\" && this.root) {\n this.resizeObserver = new ResizeObserver(() => this.updateDimensions());\n this.resizeObserver.observe(this.root === document.body ? document.documentElement : this.root);\n } else {\n window.addEventListener(\"resize\", this.updateDimensions);\n }\n\n // Mouse breeze listeners\n if (this._wind.enableMouseBreeze) {\n this.attachMouseListeners();\n }\n\n // Prefers-reduced-motion listener\n if (this.respectReducedMotion && typeof window.matchMedia === \"function\") {\n this.mediaQueryList = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n this.boundOnMotionChange = (e: MediaQueryListEvent) => {\n if (e.matches) {\n this.pause();\n } else if (!this.isDestroyed && this.isRunning) {\n this.resume();\n }\n };\n if (this.mediaQueryList.addEventListener) {\n this.mediaQueryList.addEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n // Spawn petals\n this.initPetals();\n\n // Check reduced motion setting before starting\n const prefersReduced = this.respectReducedMotion && this.mediaQueryList?.matches;\n if (!prefersReduced) {\n this.start();\n } else {\n // Draw static frame once\n this.renderFrame();\n }\n }\n\n // --- Public Getters and Setters ---\n\n public get number(): number {\n return this._number;\n }\n\n public set number(value: number) {\n if (this.isDestroyed) return;\n this._number = Math.max(0, Math.min(10000, Math.floor(value)));\n this.adjustPetalCount();\n }\n\n public get wind(): Required<WindOptions> {\n return { ...this._wind };\n }\n\n public set wind(options: Partial<WindOptions>) {\n if (this.isDestroyed) return;\n this._wind = { ...this._wind, ...options };\n if (options.enableMouseBreeze === false) {\n this.removeMouseListeners();\n } else if (options.enableMouseBreeze === true) {\n this.attachMouseListeners();\n }\n }\n\n public get petalStyle(): PetalStyle {\n return { ...this._petalStyle };\n }\n\n public set petalStyle(style: PetalStyle) {\n if (this.isDestroyed) return;\n this._petalStyle = { ...this._petalStyle, ...style };\n // Re-apply to all petals\n for (const petal of this.petals) {\n petal.reset(this.width, this.height, false, this._petalStyle);\n }\n }\n\n // --- Lifecycle Control Methods ---\n\n /**\n * Starts or resumes the animation loop.\n */\n public start(): void {\n if (this.isDestroyed || this.isRunning) return;\n this.isRunning = true;\n this.resume();\n }\n\n /**\n * Pauses the animation loop.\n */\n public stop(): void {\n this.isRunning = false;\n this.pause();\n }\n\n /**\n * Alias for start()\n */\n public resume(): void {\n if (this.animationFrameId === null && !this.isDestroyed) {\n this.animationFrameId = requestAnimationFrame(this.loop);\n }\n }\n\n /**\n * Alias for stop()\n */\n public pause(): void {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n /**\n * Cleans up canvas, event listeners, observers and removes the element permanently.\n */\n public clear(): void {\n this.isDestroyed = true;\n this.stop();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n } else if (typeof window !== \"undefined\") {\n window.removeEventListener(\"resize\", this.updateDimensions);\n }\n\n if (this.mediaQueryList && this.boundOnMotionChange) {\n if (this.mediaQueryList.removeEventListener) {\n this.mediaQueryList.removeEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n this.removeMouseListeners();\n\n if (this.canvas && this.canvas.parentElement) {\n this.canvas.parentElement.removeChild(this.canvas);\n }\n\n this.petals = [];\n }\n\n // --- Private Implementations ---\n\n private updateDimensions = (): void => {\n if (!this.canvas || !this.root) return;\n\n const isBody = this.root === document.body;\n const clientWidth = isBody ? window.innerWidth : this.root.clientWidth;\n const clientHeight = isBody ? window.innerHeight : this.root.clientHeight;\n\n this.width = clientWidth;\n this.height = clientHeight;\n\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1;\n this.pixelRatio = Math.min(dpr, this.maxPixelRatio);\n\n // Canvas physical buffer resolution\n this.canvas.width = Math.round(this.width * this.pixelRatio);\n this.canvas.height = Math.round(this.height * this.pixelRatio);\n\n // Scale context to match retina pixels\n if (this.ctx) {\n this.ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);\n }\n };\n\n private initPetals(): void {\n this.petals = [];\n for (let i = 0; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n }\n\n private adjustPetalCount(): void {\n const current = this.petals.length;\n if (this._number > current) {\n for (let i = current; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n } else if (this._number < current) {\n this.petals.splice(this._number);\n }\n }\n\n private attachMouseListeners(): void {\n if (typeof window === \"undefined\" || this.boundOnPointerMove) return;\n\n this.boundOnPointerMove = (e: MouseEvent | PointerEvent) => {\n this.mouseX = e.clientX;\n this.mouseY = e.clientY;\n };\n\n this.boundOnPointerLeave = () => {\n this.mouseX = null;\n this.mouseY = null;\n };\n\n window.addEventListener(\"pointermove\", this.boundOnPointerMove, { passive: true });\n window.addEventListener(\"pointerleave\", this.boundOnPointerLeave, { passive: true });\n }\n\n private removeMouseListeners(): void {\n if (typeof window === \"undefined\") return;\n\n if (this.boundOnPointerMove) {\n window.removeEventListener(\"pointermove\", this.boundOnPointerMove);\n this.boundOnPointerMove = null;\n }\n if (this.boundOnPointerLeave) {\n window.removeEventListener(\"pointerleave\", this.boundOnPointerLeave);\n this.boundOnPointerLeave = null;\n }\n this.mouseX = null;\n this.mouseY = null;\n }\n\n private renderFrame(): void {\n if (!this.ctx || !this.canvas) return;\n\n this.ctx.clearRect(0, 0, this.width, this.height);\n\n for (const petal of this.petals) {\n petal.draw(this.ctx);\n }\n }\n\n private loop = (): void => {\n if (!this.isRunning || this.isDestroyed) return;\n\n // Organic wind oscillation over time\n this.windTime += 0.015;\n const gust = Math.sin(this.windTime) * this._wind.gust + Math.cos(this.windTime * 0.4) * 0.5;\n this.currentWind = this._wind.speed + gust;\n\n // Update each petal\n for (let i = 0; i < this.petals.length; i++) {\n this.petals[i].update(\n this.width,\n this.height,\n this.currentWind,\n this.mouseX,\n this.mouseY,\n this._wind.mouseRadius,\n this._wind.mouseForce\n );\n }\n\n this.renderFrame();\n\n this.animationFrameId = requestAnimationFrame(this.loop);\n };\n}\n"],"mappings":"AAGO,SAASA,EAAYC,EAAaC,EAAqB,CAC5D,OAAOD,EAAM,KAAK,OAAO,GAAKC,EAAMD,EACtC,CCEO,IAAME,EAAN,KAAY,CAEjB,EAAI,EACJ,EAAI,EACJ,EAAI,EAGJ,KAAO,GACP,YAAc,KAGd,GAAK,EACL,GAAK,EACL,GAAK,EAGL,MAAQ,EACR,IAAM,EACN,KAAO,EACP,OAAS,EACT,KAAO,EACP,MAAQ,EAGR,iBAAmB,EACnB,iBAAmB,EACnB,cAAgB,EAGhB,OAAS,UACT,OAAS,UACT,QAAU,IAGV,QAAU,EACV,QAAU,EAEV,YAAYC,EAAeC,EAAgBC,EAAoB,CAC7D,KAAK,MAAMF,EAAOC,EAAQ,GAAMC,CAAK,CACvC,CAMA,MAAMF,EAAeC,EAAgBE,EAAU,GAAOD,EAA0B,CAC9E,IAAME,EAAYF,GAAO,WAAa,CAAC,GAAI,EAAE,EACvCG,EAAeH,GAAO,cAAgB,CAAC,IAAM,GAAI,EACjDI,EAASJ,GAAO,QAAU,CAAC,UAAW,UAAW,UAAW,SAAS,EAE3E,KAAK,KAAO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EQ,KAAO,IAAY,CACzB,GAAI,CAAC,KAAK,WAAa,KAAK,YAAa,OAGzC,KAAK,UAAY,KACjB,IAAMQ,EAAO,KAAK,IAAI,KAAK,QAAQ,EAAI,KAAK,MAAM,KAAO,KAAK,IAAI,KAAK,SAAW,EAAG,EAAI,GACzF,KAAK,YAAc,KAAK,MAAM,MAAQA,EAGtC,QAASH,EAAI,EAAGA,EAAI,KAAK,OAAO,OAAQA,IACtC,KAAK,OAAOA,CAAC,EAAE,OACb,KAAK,MACL,KAAK,OACL,KAAK,YACL,KAAK,OACL,KAAK,OACL,KAAK,MAAM,YACX,KAAK,MAAM,UACb,EAGF,KAAK,YAAY,EAEjB,KAAK,iBAAmB,sBAAsB,KAAK,IAAI,CACzD,CACF","names":["randomRange","min","max","Petal","width","height","style","initial","sizeRange","opacityRange","colors","randomRange","ambientWind","mouseX","mouseY","mouseRadius","mouseForce","sway","dx","dy","distSq","radSq","dist","factor","ctx","scaleX","scaleY","w","h","grad","CherryBlossom","_CherryBlossom","options","opts","defaultWind","styles","e","value","style","petal","isBody","clientWidth","clientHeight","dpr","i","Petal","current","gust"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var v=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!g.call(r,i)&&i!==t&&v(r,i,{get:()=>e[i],enumerable:!(n=w(e,i))||n.enumerable});return r};var x=r=>P(v({},"__esModule",{value:!0}),r);var L={};R(L,{CherryBlossom:()=>u,Petal:()=>h,default:()=>O});module.exports=x(L);function s(r,e){return r+Math.random()*(e-r)}var h=class{x=0;y=0;z=0;size=15;aspectRatio=1.25;vx=0;vy=0;vz=0;pitch=0;yaw=0;roll=0;dPitch=0;dYaw=0;dRoll=0;oscillationPhase=0;oscillationSpeed=0;swayAmplitude=0;color1="#ffb7c5";color2="#ff94aa";opacity=.85;mouseVx=0;mouseVy=0;constructor(e,t,n){this.reset(e,t,!0,n)}reset(e,t,n=!1,i){let o=i?.sizeRange??[12,22],a=i?.opacityRange??[.75,.95],l=i?.colors??["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"];this.size=s(o[0],o[1]),this.aspectRatio=s(1.15,1.35),this.opacity=s(a[0],a[1]),this.color1=l[Math.floor(Math.random()*l.length)],this.color2=l[Math.floor(Math.random()*l.length)],this.x=s(-50,e+50),this.y=n?s(-t,t):s(-60,-20),this.z=s(.7,1.25),this.vy=s(1.2,2.6)*this.z,this.vx=s(-.5,.8),this.pitch=s(0,Math.PI*2),this.yaw=s(0,Math.PI*2),this.roll=s(0,Math.PI*2),this.dPitch=s(.015,.045),this.dYaw=s(.02,.06),this.dRoll=s(.01,.03),this.oscillationPhase=s(0,Math.PI*2),this.oscillationSpeed=s(.02,.05),this.swayAmplitude=s(.8,2.2),this.mouseVx=0,this.mouseVy=0}update(e,t,n,i,o,a=140,l=1.8){this.pitch+=this.dPitch,this.yaw+=this.dYaw,this.roll+=this.dRoll,this.oscillationPhase+=this.oscillationSpeed;let f=Math.sin(this.oscillationPhase)*this.swayAmplitude;if(i!==null&&o!==null){let d=this.x-i,m=this.y-o,p=d*d+m*m,y=a*a;if(p<y&&p>0){let c=Math.sqrt(p),b=(1-c/a)*l;this.mouseVx+=d/c*b*2.5,this.mouseVy+=(m/c*b-.5)*1.5}}this.mouseVx*=.92,this.mouseVy*=.92,this.x+=(this.vx+n+f+this.mouseVx)*this.z,this.y+=(this.vy+this.mouseVy)*this.z,(this.y>t+40||this.x>e+80||this.x<-80)&&(n>0&&Math.random()<.3?(this.x=-30,this.y=s(-20,t*.7)):(this.y=-30,this.x=s(-40,e+40)),this.mouseVx=0,this.mouseVy=0)}draw(e){e.save(),e.translate(this.x,this.y),e.rotate(this.roll);let t=Math.cos(this.yaw)*this.z,n=Math.cos(this.pitch)*this.z;e.scale(t,n),e.globalAlpha=Math.max(0,Math.min(1,this.opacity));let i=this.size/this.aspectRatio*.5,o=this.size*.5,a=e.createLinearGradient(0,o,0,-o);a.addColorStop(0,this.color1),a.addColorStop(1,this.color2),e.fillStyle=a,e.beginPath(),e.moveTo(0,o),e.bezierCurveTo(-i*1.3,o*.4,-i*1.2,-o*.6,-i*.35,-o),e.quadraticCurveTo(0,-o*.75,i*.35,-o),e.bezierCurveTo(i*1.2,-o*.6,i*1.3,o*.4,0,o),e.closePath(),e.fill(),e.restore()}};var u=class r{static DEFAULT_OPTIONS={root:null,number:45,gravityRange:[1.2,2.6],wind:{speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8},petalStyle:{colors:["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"],opacityRange:[.75,.95],sizeRange:[12,22]},style:{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"999999"},respectReducedMotion:!0,maxPixelRatio:2};canvas=null;ctx=null;root=null;respectReducedMotion=!0;maxPixelRatio=2;petals=[];_number=45;_wind={speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8};_petalStyle={};_gravityRange=[1.2,2.6];animationFrameId=null;isRunning=!1;isDestroyed=!1;width=0;height=0;pixelRatio=1;resizeObserver=null;mediaQueryList=null;windTime=0;currentWind=1.5;mouseX=null;mouseY=null;boundOnPointerMove=null;boundOnPointerLeave=null;boundOnMotionChange=null;constructor(e){let t={...r.DEFAULT_OPTIONS,...e};this._number=Math.max(0,Math.min(1e4,t.number??45));let n=r.DEFAULT_OPTIONS.wind;if(this._wind={speed:t.wind?.speed??n.speed,gust:t.wind?.gust??n.gust,enableMouseBreeze:t.wind?.enableMouseBreeze??n.enableMouseBreeze,mouseRadius:t.wind?.mouseRadius??n.mouseRadius,mouseForce:t.wind?.mouseForce??n.mouseForce},this._petalStyle={...r.DEFAULT_OPTIONS.petalStyle,...t.petalStyle||{}},this._gravityRange=t.gravityRange||[1.2,2.6],this.respectReducedMotion=t.respectReducedMotion??!0,this.maxPixelRatio=t.maxPixelRatio??2,typeof window>"u"||typeof document>"u"||(this.root=t.root??document.body,!this.root))return;this.canvas=document.createElement("canvas"),this.canvas.setAttribute("aria-hidden","true"),this.ctx=this.canvas.getContext("2d");let i={...r.DEFAULT_OPTIONS.style,...t.style||{}};Object.assign(this.canvas.style,i),this.root.appendChild(this.canvas),this.updateDimensions(),typeof ResizeObserver<"u"&&this.root?(this.resizeObserver=new ResizeObserver(()=>this.updateDimensions()),this.resizeObserver.observe(this.root===document.body?document.documentElement:this.root)):window.addEventListener("resize",this.updateDimensions),this._wind.enableMouseBreeze&&this.attachMouseListeners(),this.respectReducedMotion&&typeof window.matchMedia=="function"&&(this.mediaQueryList=window.matchMedia("(prefers-reduced-motion: reduce)"),this.boundOnMotionChange=a=>{a.matches?this.pause():!this.isDestroyed&&this.isRunning&&this.resume()},this.mediaQueryList.addEventListener&&this.mediaQueryList.addEventListener("change",this.boundOnMotionChange)),this.initPetals(),this.respectReducedMotion&&this.mediaQueryList?.matches?this.renderFrame():this.start()}get number(){return this._number}set number(e){this.isDestroyed||(this._number=Math.max(0,Math.min(1e4,Math.floor(e))),this.adjustPetalCount())}get wind(){return{...this._wind}}set wind(e){this.isDestroyed||(this._wind={...this._wind,...e},e.enableMouseBreeze===!1?this.removeMouseListeners():e.enableMouseBreeze===!0&&this.attachMouseListeners())}get petalStyle(){return{...this._petalStyle}}set petalStyle(e){if(!this.isDestroyed){this._petalStyle={...this._petalStyle,...e};for(let t of this.petals)t.reset(this.width,this.height,!1,this._petalStyle)}}start(){this.isDestroyed||this.isRunning||(this.isRunning=!0,this.resume())}stop(){this.isRunning=!1,this.pause()}resume(){this.animationFrameId===null&&!this.isDestroyed&&(this.animationFrameId=requestAnimationFrame(this.loop))}pause(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}clear(){this.isDestroyed=!0,this.stop(),this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):typeof window<"u"&&window.removeEventListener("resize",this.updateDimensions),this.mediaQueryList&&this.boundOnMotionChange&&this.mediaQueryList.removeEventListener&&this.mediaQueryList.removeEventListener("change",this.boundOnMotionChange),this.removeMouseListeners(),this.canvas&&this.canvas.parentElement&&this.canvas.parentElement.removeChild(this.canvas),this.petals=[]}updateDimensions=()=>{if(!this.canvas||!this.root)return;let e=this.root===document.body,t=e?window.innerWidth:this.root.clientWidth,n=e?window.innerHeight:this.root.clientHeight;this.width=t,this.height=n;let i=typeof window<"u"&&window.devicePixelRatio||1;this.pixelRatio=Math.min(i,this.maxPixelRatio),this.canvas.width=Math.round(this.width*this.pixelRatio),this.canvas.height=Math.round(this.height*this.pixelRatio),this.ctx&&this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)};initPetals(){this.petals=[];for(let e=0;e<this._number;e++)this.petals.push(new h(this.width,this.height,this._petalStyle))}adjustPetalCount(){let e=this.petals.length;if(this._number>e)for(let t=e;t<this._number;t++)this.petals.push(new h(this.width,this.height,this._petalStyle));else this._number<e&&this.petals.splice(this._number)}attachMouseListeners(){typeof window>"u"||this.boundOnPointerMove||(this.boundOnPointerMove=e=>{this.mouseX=e.clientX,this.mouseY=e.clientY},this.boundOnPointerLeave=()=>{this.mouseX=null,this.mouseY=null},window.addEventListener("pointermove",this.boundOnPointerMove,{passive:!0}),window.addEventListener("pointerleave",this.boundOnPointerLeave,{passive:!0}))}removeMouseListeners(){typeof window>"u"||(this.boundOnPointerMove&&(window.removeEventListener("pointermove",this.boundOnPointerMove),this.boundOnPointerMove=null),this.boundOnPointerLeave&&(window.removeEventListener("pointerleave",this.boundOnPointerLeave),this.boundOnPointerLeave=null),this.mouseX=null,this.mouseY=null)}renderFrame(){if(!(!this.ctx||!this.canvas)){this.ctx.clearRect(0,0,this.width,this.height);for(let e of this.petals)e.draw(this.ctx)}}loop=()=>{if(!this.isRunning||this.isDestroyed)return;this.windTime+=.015;let e=Math.sin(this.windTime)*this._wind.gust+Math.cos(this.windTime*.4)*.5;this.currentWind=this._wind.speed+e;for(let t=0;t<this.petals.length;t++)this.petals[t].update(this.width,this.height,this.currentWind,this.mouseX,this.mouseY,this._wind.mouseRadius,this._wind.mouseForce);this.renderFrame(),this.animationFrameId=requestAnimationFrame(this.loop)}};var O=u;0&&(module.exports={CherryBlossom,Petal});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/math.ts","../src/petal.ts","../src/cherryblossom.ts"],"sourcesContent":["export { CherryBlossom } from \"./cherryblossom\";\nexport { Petal } from \"./petal\";\nexport type {\n CherryBlossomOptions,\n WindOptions,\n PetalStyle\n} from \"./types\";\n\nimport { CherryBlossom } from \"./cherryblossom\";\nexport default CherryBlossom;\n","/**\n * Random float in range [min, max)\n */\nexport function randomRange(min: number, max: number): number {\n return min + Math.random() * (max - min);\n}\n\n/**\n * Random integer in range [min, max]\n */\nexport function randomInt(min: number, max: number): number {\n return Math.floor(min + Math.random() * (max - min + 1));\n}\n\n/**\n * Clamp a number between min and max\n */\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, val));\n}\n","import { randomRange } from \"./math\";\nimport type { PetalStyle } from \"./types\";\n\n/**\n * Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),\n * physics velocities, realistic bezier geometry, and wind responsiveness.\n */\nexport class Petal {\n // Coordinates\n x = 0;\n y = 0;\n z = 0; // Simulated depth for scale & parallax\n\n // Dimensions\n size = 15;\n aspectRatio = 1.25; // Length to width ratio\n\n // Velocities\n vx = 0;\n vy = 0;\n vz = 0;\n\n // 3D rotation angles & angular velocities\n pitch = 0; // Tumbling end-over-end\n yaw = 0; // Spinning around horizontal axis\n roll = 0; // Twisting clockwise/counterclockwise\n dPitch = 0;\n dYaw = 0;\n dRoll = 0;\n\n // Flutter & sway oscillation parameters\n oscillationPhase = 0;\n oscillationSpeed = 0;\n swayAmplitude = 0;\n\n // Color & appearance\n color1 = \"#ffb7c5\";\n color2 = \"#ff94aa\";\n opacity = 0.85;\n\n // Mouse wind displacement\n mouseVx = 0;\n mouseVy = 0;\n\n constructor(width: number, height: number, style?: PetalStyle) {\n this.reset(width, height, true, style);\n }\n\n /**\n * Re-initializes petal position, velocities, and 3D rotations.\n * If initial is true, petals are scattered vertically across the whole screen.\n */\n reset(width: number, height: number, initial = false, style?: PetalStyle): void {\n const sizeRange = style?.sizeRange ?? [12, 22];\n const opacityRange = style?.opacityRange ?? [0.75, 0.95];\n const colors = style?.colors ?? [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"];\n\n this.size = randomRange(sizeRange[0], sizeRange[1]);\n this.aspectRatio = randomRange(1.15, 1.35);\n this.opacity = randomRange(opacityRange[0], opacityRange[1]);\n\n // Pick random gradient colors for realistic petal shading\n this.color1 = colors[Math.floor(Math.random() * colors.length)];\n this.color2 = colors[Math.floor(Math.random() * colors.length)];\n\n // Position\n this.x = randomRange(-50, width + 50);\n this.y = initial ? randomRange(-height, height) : randomRange(-60, -20);\n this.z = randomRange(0.7, 1.25); // Parallax depth\n\n // Falling velocity (scaled slightly by depth)\n this.vy = randomRange(1.2, 2.6) * this.z;\n this.vx = randomRange(-0.5, 0.8);\n\n // 3D angles (in radians)\n this.pitch = randomRange(0, Math.PI * 2);\n this.yaw = randomRange(0, Math.PI * 2);\n this.roll = randomRange(0, Math.PI * 2);\n\n // Rotational velocities (flutter speed)\n this.dPitch = randomRange(0.015, 0.045);\n this.dYaw = randomRange(0.02, 0.06);\n this.dRoll = randomRange(0.01, 0.03);\n\n // Sway oscillation\n this.oscillationPhase = randomRange(0, Math.PI * 2);\n this.oscillationSpeed = randomRange(0.02, 0.05);\n this.swayAmplitude = randomRange(0.8, 2.2);\n\n // Reset mouse influence\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n\n /**\n * Update particle physics step\n */\n update(\n width: number,\n height: number,\n ambientWind: number,\n mouseX: number | null,\n mouseY: number | null,\n mouseRadius = 140,\n mouseForce = 1.8\n ): void {\n // 3D rotation update\n this.pitch += this.dPitch;\n this.yaw += this.dYaw;\n this.roll += this.dRoll;\n\n // Organic swaying wave\n this.oscillationPhase += this.oscillationSpeed;\n const sway = Math.sin(this.oscillationPhase) * this.swayAmplitude;\n\n // Mouse breeze interaction\n if (mouseX !== null && mouseY !== null) {\n const dx = this.x - mouseX;\n const dy = this.y - mouseY;\n const distSq = dx * dx + dy * dy;\n const radSq = mouseRadius * mouseRadius;\n\n if (distSq < radSq && distSq > 0) {\n const dist = Math.sqrt(distSq);\n const factor = (1 - dist / mouseRadius) * mouseForce;\n // Direction away from mouse with a slight upward and swirling drift\n this.mouseVx += (dx / dist) * factor * 2.5;\n this.mouseVy += ((dy / dist) * factor - 0.5) * 1.5;\n }\n }\n\n // Dampen mouse breeze impulse\n this.mouseVx *= 0.92;\n this.mouseVy *= 0.92;\n\n // Update positions\n this.x += (this.vx + ambientWind + sway + this.mouseVx) * this.z;\n this.y += (this.vy + this.mouseVy) * this.z;\n\n // Reset when moving off-screen\n if (this.y > height + 40 || this.x > width + 80 || this.x < -80) {\n // Loop from top or left depending on wind\n if (ambientWind > 0 && Math.random() < 0.3) {\n // Wrap around from left\n this.x = -30;\n this.y = randomRange(-20, height * 0.7);\n } else {\n this.y = -30;\n this.x = randomRange(-40, width + 40);\n }\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n }\n\n /**\n * Draw the petal using Canvas2D bezier curves, transformed into 3D view\n */\n draw(ctx: CanvasRenderingContext2D): void {\n ctx.save();\n\n // Move to petal center\n ctx.translate(this.x, this.y);\n\n // Apply 3D rotation using 2D projection matrix\n // Roll rotates in 2D plane; Pitch and Yaw squish width/height to simulate 3D rotation\n ctx.rotate(this.roll);\n const scaleX = Math.cos(this.yaw) * this.z;\n const scaleY = Math.cos(this.pitch) * this.z;\n ctx.scale(scaleX, scaleY);\n\n ctx.globalAlpha = Math.max(0, Math.min(1, this.opacity));\n\n // Draw realistic sakura petal shape with notch at tip\n // The petal is drawn centered around (0, 0), with base at (0, length/2) and notched tip at (0, -length/2)\n const w = (this.size / this.aspectRatio) * 0.5;\n const h = this.size * 0.5;\n\n // Gradient shading across the petal\n const grad = ctx.createLinearGradient(0, h, 0, -h);\n grad.addColorStop(0, this.color1);\n grad.addColorStop(1, this.color2);\n ctx.fillStyle = grad;\n\n ctx.beginPath();\n // Start at bottom base of petal\n ctx.moveTo(0, h);\n\n // Left curved side up to the left lobe of notch\n ctx.bezierCurveTo(-w * 1.3, h * 0.4, -w * 1.2, -h * 0.6, -w * 0.35, -h);\n\n // The iconic sakura notch at petal tip\n ctx.quadraticCurveTo(0, -h * 0.75, w * 0.35, -h);\n\n // Right curved side down back to base\n ctx.bezierCurveTo(w * 1.2, -h * 0.6, w * 1.3, h * 0.4, 0, h);\n\n ctx.closePath();\n ctx.fill();\n\n ctx.restore();\n }\n}\n","import { Petal } from \"./petal\";\nimport { randomRange } from \"./math\";\nimport type { CherryBlossomOptions, WindOptions, PetalStyle } from \"./types\";\n\n/**\n * CherryBlossom manages the canvas lifecycle, particle physics simulation loop,\n * dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.\n */\nexport class CherryBlossom {\n /**\n * Static default options\n */\n public static readonly DEFAULT_OPTIONS = {\n root: null as HTMLElement | null,\n number: 45,\n gravityRange: [1.2, 2.6] as [number, number],\n wind: {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n },\n petalStyle: {\n colors: [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"],\n opacityRange: [0.75, 0.95] as [number, number],\n sizeRange: [12, 22] as [number, number]\n },\n style: {\n position: \"fixed\",\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n zIndex: \"999999\"\n } as Partial<CSSStyleDeclaration>,\n respectReducedMotion: true,\n maxPixelRatio: 2\n };\n\n public readonly canvas: HTMLCanvasElement | null = null;\n private readonly ctx: CanvasRenderingContext2D | null = null;\n private readonly root: HTMLElement | null = null;\n private readonly respectReducedMotion: boolean = true;\n private readonly maxPixelRatio: number = 2;\n\n // State\n private petals: Petal[] = [];\n private _number: number = 45;\n private _wind: Required<WindOptions> = {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n };\n private _petalStyle: PetalStyle = {};\n private _gravityRange: [number, number] = [1.2, 2.6];\n \n private animationFrameId: number | null = null;\n private isRunning: boolean = false;\n private isDestroyed: boolean = false;\n\n // Environment & metrics\n private width: number = 0;\n private height: number = 0;\n private pixelRatio: number = 1;\n private resizeObserver: ResizeObserver | null = null;\n private mediaQueryList: MediaQueryList | null = null;\n\n // Wind calculation state\n private windTime: number = 0;\n private currentWind: number = 1.5;\n\n // Mouse tracking\n private mouseX: number | null = null;\n private mouseY: number | null = null;\n private boundOnPointerMove: ((e: PointerEvent | MouseEvent) => void) | null = null;\n private boundOnPointerLeave: (() => void) | null = null;\n private boundOnMotionChange: ((e: MediaQueryListEvent) => void) | null = null;\n\n constructor(options?: CherryBlossomOptions) {\n const opts = { ...CherryBlossom.DEFAULT_OPTIONS, ...options };\n\n this._number = Math.max(0, Math.min(10000, opts.number ?? 45));\n const defaultWind = CherryBlossom.DEFAULT_OPTIONS.wind;\n this._wind = {\n speed: opts.wind?.speed ?? defaultWind.speed,\n gust: opts.wind?.gust ?? defaultWind.gust,\n enableMouseBreeze: opts.wind?.enableMouseBreeze ?? defaultWind.enableMouseBreeze,\n mouseRadius: opts.wind?.mouseRadius ?? defaultWind.mouseRadius,\n mouseForce: opts.wind?.mouseForce ?? defaultWind.mouseForce\n };\n this._petalStyle = {\n ...CherryBlossom.DEFAULT_OPTIONS.petalStyle,\n ...(opts.petalStyle || {})\n };\n this._gravityRange = opts.gravityRange || [1.2, 2.6];\n this.respectReducedMotion = opts.respectReducedMotion ?? true;\n this.maxPixelRatio = opts.maxPixelRatio ?? 2;\n\n // Guard for SSR environments where document/window are undefined\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return;\n }\n\n this.root = opts.root ?? document.body;\n if (!this.root) return;\n\n // Create and attach canvas element\n this.canvas = document.createElement(\"canvas\");\n this.canvas.setAttribute(\"aria-hidden\", \"true\");\n this.ctx = this.canvas.getContext(\"2d\");\n\n // Apply styles\n const styles = { ...CherryBlossom.DEFAULT_OPTIONS.style, ...(opts.style || {}) };\n Object.assign(this.canvas.style, styles);\n\n this.root.appendChild(this.canvas);\n\n // Initial resize and high-DPI setup\n this.updateDimensions();\n\n // Listen to resize\n if (typeof ResizeObserver !== \"undefined\" && this.root) {\n this.resizeObserver = new ResizeObserver(() => this.updateDimensions());\n this.resizeObserver.observe(this.root === document.body ? document.documentElement : this.root);\n } else {\n window.addEventListener(\"resize\", this.updateDimensions);\n }\n\n // Mouse breeze listeners\n if (this._wind.enableMouseBreeze) {\n this.attachMouseListeners();\n }\n\n // Prefers-reduced-motion listener\n if (this.respectReducedMotion && typeof window.matchMedia === \"function\") {\n this.mediaQueryList = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n this.boundOnMotionChange = (e: MediaQueryListEvent) => {\n if (e.matches) {\n this.pause();\n } else if (!this.isDestroyed && this.isRunning) {\n this.resume();\n }\n };\n if (this.mediaQueryList.addEventListener) {\n this.mediaQueryList.addEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n // Spawn petals\n this.initPetals();\n\n // Check reduced motion setting before starting\n const prefersReduced = this.respectReducedMotion && this.mediaQueryList?.matches;\n if (!prefersReduced) {\n this.start();\n } else {\n // Draw static frame once\n this.renderFrame();\n }\n }\n\n // --- Public Getters and Setters ---\n\n public get number(): number {\n return this._number;\n }\n\n public set number(value: number) {\n if (this.isDestroyed) return;\n this._number = Math.max(0, Math.min(10000, Math.floor(value)));\n this.adjustPetalCount();\n }\n\n public get wind(): Required<WindOptions> {\n return { ...this._wind };\n }\n\n public set wind(options: Partial<WindOptions>) {\n if (this.isDestroyed) return;\n this._wind = { ...this._wind, ...options };\n if (options.enableMouseBreeze === false) {\n this.removeMouseListeners();\n } else if (options.enableMouseBreeze === true) {\n this.attachMouseListeners();\n }\n }\n\n public get petalStyle(): PetalStyle {\n return { ...this._petalStyle };\n }\n\n public set petalStyle(style: PetalStyle) {\n if (this.isDestroyed) return;\n this._petalStyle = { ...this._petalStyle, ...style };\n // Re-apply to all petals\n for (const petal of this.petals) {\n petal.reset(this.width, this.height, false, this._petalStyle);\n }\n }\n\n // --- Lifecycle Control Methods ---\n\n /**\n * Starts or resumes the animation loop.\n */\n public start(): void {\n if (this.isDestroyed || this.isRunning) return;\n this.isRunning = true;\n this.resume();\n }\n\n /**\n * Pauses the animation loop.\n */\n public stop(): void {\n this.isRunning = false;\n this.pause();\n }\n\n /**\n * Alias for start()\n */\n public resume(): void {\n if (this.animationFrameId === null && !this.isDestroyed) {\n this.animationFrameId = requestAnimationFrame(this.loop);\n }\n }\n\n /**\n * Alias for stop()\n */\n public pause(): void {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n /**\n * Cleans up canvas, event listeners, observers and removes the element permanently.\n */\n public clear(): void {\n this.isDestroyed = true;\n this.stop();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n } else if (typeof window !== \"undefined\") {\n window.removeEventListener(\"resize\", this.updateDimensions);\n }\n\n if (this.mediaQueryList && this.boundOnMotionChange) {\n if (this.mediaQueryList.removeEventListener) {\n this.mediaQueryList.removeEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n this.removeMouseListeners();\n\n if (this.canvas && this.canvas.parentElement) {\n this.canvas.parentElement.removeChild(this.canvas);\n }\n\n this.petals = [];\n }\n\n // --- Private Implementations ---\n\n private updateDimensions = (): void => {\n if (!this.canvas || !this.root) return;\n\n const isBody = this.root === document.body;\n const clientWidth = isBody ? window.innerWidth : this.root.clientWidth;\n const clientHeight = isBody ? window.innerHeight : this.root.clientHeight;\n\n this.width = clientWidth;\n this.height = clientHeight;\n\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1;\n this.pixelRatio = Math.min(dpr, this.maxPixelRatio);\n\n // Canvas physical buffer resolution\n this.canvas.width = Math.round(this.width * this.pixelRatio);\n this.canvas.height = Math.round(this.height * this.pixelRatio);\n\n // Scale context to match retina pixels\n if (this.ctx) {\n this.ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);\n }\n };\n\n private initPetals(): void {\n this.petals = [];\n for (let i = 0; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n }\n\n private adjustPetalCount(): void {\n const current = this.petals.length;\n if (this._number > current) {\n for (let i = current; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n } else if (this._number < current) {\n this.petals.splice(this._number);\n }\n }\n\n private attachMouseListeners(): void {\n if (typeof window === \"undefined\" || this.boundOnPointerMove) return;\n\n this.boundOnPointerMove = (e: MouseEvent | PointerEvent) => {\n this.mouseX = e.clientX;\n this.mouseY = e.clientY;\n };\n\n this.boundOnPointerLeave = () => {\n this.mouseX = null;\n this.mouseY = null;\n };\n\n window.addEventListener(\"pointermove\", this.boundOnPointerMove, { passive: true });\n window.addEventListener(\"pointerleave\", this.boundOnPointerLeave, { passive: true });\n }\n\n private removeMouseListeners(): void {\n if (typeof window === \"undefined\") return;\n\n if (this.boundOnPointerMove) {\n window.removeEventListener(\"pointermove\", this.boundOnPointerMove);\n this.boundOnPointerMove = null;\n }\n if (this.boundOnPointerLeave) {\n window.removeEventListener(\"pointerleave\", this.boundOnPointerLeave);\n this.boundOnPointerLeave = null;\n }\n this.mouseX = null;\n this.mouseY = null;\n }\n\n private renderFrame(): void {\n if (!this.ctx || !this.canvas) return;\n\n this.ctx.clearRect(0, 0, this.width, this.height);\n\n for (const petal of this.petals) {\n petal.draw(this.ctx);\n }\n }\n\n private loop = (): void => {\n if (!this.isRunning || this.isDestroyed) return;\n\n // Organic wind oscillation over time\n this.windTime += 0.015;\n const gust = Math.sin(this.windTime) * this._wind.gust + Math.cos(this.windTime * 0.4) * 0.5;\n this.currentWind = this._wind.speed + gust;\n\n // Update each petal\n for (let i = 0; i < this.petals.length; i++) {\n this.petals[i].update(\n this.width,\n this.height,\n this.currentWind,\n this.mouseX,\n this.mouseY,\n this._wind.mouseRadius,\n this._wind.mouseForce\n );\n }\n\n this.renderFrame();\n\n this.animationFrameId = requestAnimationFrame(this.loop);\n };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,UAAAC,EAAA,YAAAC,IAAA,eAAAC,EAAAL,GCGO,SAASM,EAAYC,EAAaC,EAAqB,CAC5D,OAAOD,EAAM,KAAK,OAAO,GAAKC,EAAMD,EACtC,CCEO,IAAME,EAAN,KAAY,CAEjB,EAAI,EACJ,EAAI,EACJ,EAAI,EAGJ,KAAO,GACP,YAAc,KAGd,GAAK,EACL,GAAK,EACL,GAAK,EAGL,MAAQ,EACR,IAAM,EACN,KAAO,EACP,OAAS,EACT,KAAO,EACP,MAAQ,EAGR,iBAAmB,EACnB,iBAAmB,EACnB,cAAgB,EAGhB,OAAS,UACT,OAAS,UACT,QAAU,IAGV,QAAU,EACV,QAAU,EAEV,YAAYC,EAAeC,EAAgBC,EAAoB,CAC7D,KAAK,MAAMF,EAAOC,EAAQ,GAAMC,CAAK,CACvC,CAMA,MAAMF,EAAeC,EAAgBE,EAAU,GAAOD,EAA0B,CAC9E,IAAME,EAAYF,GAAO,WAAa,CAAC,GAAI,EAAE,EACvCG,EAAeH,GAAO,cAAgB,CAAC,IAAM,GAAI,EACjDI,EAASJ,GAAO,QAAU,CAAC,UAAW,UAAW,UAAW,SAAS,EAE3E,KAAK,KAAOK,EAAYH,EAAU,CAAC,EAAGA,EAA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C,KAAK,WAAa,KAAK,YAAa,OAGzC,KAAK,UAAY,KACjB,IAAMQ,EAAO,KAAK,IAAI,KAAK,QAAQ,EAAI,KAAK,MAAM,KAAO,KAAK,IAAI,KAAK,SAAW,EAAG,EAAI,GACzF,KAAK,YAAc,KAAK,MAAM,MAAQA,EAGtC,QAASH,EAAI,EAAGA,EAAI,KAAK,OAAO,OAAQA,IACtC,KAAK,OAAOA,CAAC,EAAE,OACb,KAAK,MACL,KAAK,OACL,KAAK,YACL,KAAK,OACL,KAAK,OACL,KAAK,MAAM,YACX,KAAK,MAAM,UACb,EAGF,KAAK,YAAY,EAEjB,KAAK,iBAAmB,sBAAsB,KAAK,IAAI,CACzD,CACF,EHpXA,IAAOI,EAAQC","names":["src_exports","__export","CherryBlossom","Petal","src_default","__toCommonJS","randomRange","min","max","Petal","width","height","style","initial","sizeRange","opacityRange","colors","randomRange","ambientWind","mouseX","mouseY","mouseRadius","mouseForce","sway","dx","dy","distSq","radSq","dist","factor","ctx","scaleX","scaleY","w","h","grad","CherryBlossom","_CherryBlossom","options","opts","defaultWind","styles","e","value","style","petal","isBody","clientWidth","clientHeight","dpr","i","Petal","current","gust","src_default","CherryBlossom"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { P as PetalStyle, C as CherryBlossom } from './cherryblossom-DWzs_qT1.mjs';
|
|
2
|
+
export { a as CherryBlossomOptions, W as WindOptions } from './cherryblossom-DWzs_qT1.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),
|
|
6
|
+
* physics velocities, realistic bezier geometry, and wind responsiveness.
|
|
7
|
+
*/
|
|
8
|
+
declare class Petal {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
z: number;
|
|
12
|
+
size: number;
|
|
13
|
+
aspectRatio: number;
|
|
14
|
+
vx: number;
|
|
15
|
+
vy: number;
|
|
16
|
+
vz: number;
|
|
17
|
+
pitch: number;
|
|
18
|
+
yaw: number;
|
|
19
|
+
roll: number;
|
|
20
|
+
dPitch: number;
|
|
21
|
+
dYaw: number;
|
|
22
|
+
dRoll: number;
|
|
23
|
+
oscillationPhase: number;
|
|
24
|
+
oscillationSpeed: number;
|
|
25
|
+
swayAmplitude: number;
|
|
26
|
+
color1: string;
|
|
27
|
+
color2: string;
|
|
28
|
+
opacity: number;
|
|
29
|
+
mouseVx: number;
|
|
30
|
+
mouseVy: number;
|
|
31
|
+
constructor(width: number, height: number, style?: PetalStyle);
|
|
32
|
+
/**
|
|
33
|
+
* Re-initializes petal position, velocities, and 3D rotations.
|
|
34
|
+
* If initial is true, petals are scattered vertically across the whole screen.
|
|
35
|
+
*/
|
|
36
|
+
reset(width: number, height: number, initial?: boolean, style?: PetalStyle): void;
|
|
37
|
+
/**
|
|
38
|
+
* Update particle physics step
|
|
39
|
+
*/
|
|
40
|
+
update(width: number, height: number, ambientWind: number, mouseX: number | null, mouseY: number | null, mouseRadius?: number, mouseForce?: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Draw the petal using Canvas2D bezier curves, transformed into 3D view
|
|
43
|
+
*/
|
|
44
|
+
draw(ctx: CanvasRenderingContext2D): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { CherryBlossom, Petal, PetalStyle, CherryBlossom as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { P as PetalStyle, C as CherryBlossom } from './cherryblossom-DWzs_qT1.js';
|
|
2
|
+
export { a as CherryBlossomOptions, W as WindOptions } from './cherryblossom-DWzs_qT1.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),
|
|
6
|
+
* physics velocities, realistic bezier geometry, and wind responsiveness.
|
|
7
|
+
*/
|
|
8
|
+
declare class Petal {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
z: number;
|
|
12
|
+
size: number;
|
|
13
|
+
aspectRatio: number;
|
|
14
|
+
vx: number;
|
|
15
|
+
vy: number;
|
|
16
|
+
vz: number;
|
|
17
|
+
pitch: number;
|
|
18
|
+
yaw: number;
|
|
19
|
+
roll: number;
|
|
20
|
+
dPitch: number;
|
|
21
|
+
dYaw: number;
|
|
22
|
+
dRoll: number;
|
|
23
|
+
oscillationPhase: number;
|
|
24
|
+
oscillationSpeed: number;
|
|
25
|
+
swayAmplitude: number;
|
|
26
|
+
color1: string;
|
|
27
|
+
color2: string;
|
|
28
|
+
opacity: number;
|
|
29
|
+
mouseVx: number;
|
|
30
|
+
mouseVy: number;
|
|
31
|
+
constructor(width: number, height: number, style?: PetalStyle);
|
|
32
|
+
/**
|
|
33
|
+
* Re-initializes petal position, velocities, and 3D rotations.
|
|
34
|
+
* If initial is true, petals are scattered vertically across the whole screen.
|
|
35
|
+
*/
|
|
36
|
+
reset(width: number, height: number, initial?: boolean, style?: PetalStyle): void;
|
|
37
|
+
/**
|
|
38
|
+
* Update particle physics step
|
|
39
|
+
*/
|
|
40
|
+
update(width: number, height: number, ambientWind: number, mouseX: number | null, mouseY: number | null, mouseRadius?: number, mouseForce?: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Draw the petal using Canvas2D bezier curves, transformed into 3D view
|
|
43
|
+
*/
|
|
44
|
+
draw(ctx: CanvasRenderingContext2D): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { CherryBlossom, Petal, PetalStyle, CherryBlossom as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var CherryBlossomPkg=(()=>{var v=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var R=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!g.call(r,i)&&i!==t&&v(r,i,{get:()=>e[i],enumerable:!(n=w(e,i))||n.enumerable});return r};var x=r=>P(v({},"__esModule",{value:!0}),r);var L={};R(L,{CherryBlossom:()=>u,Petal:()=>h,default:()=>O});function s(r,e){return r+Math.random()*(e-r)}var h=class{x=0;y=0;z=0;size=15;aspectRatio=1.25;vx=0;vy=0;vz=0;pitch=0;yaw=0;roll=0;dPitch=0;dYaw=0;dRoll=0;oscillationPhase=0;oscillationSpeed=0;swayAmplitude=0;color1="#ffb7c5";color2="#ff94aa";opacity=.85;mouseVx=0;mouseVy=0;constructor(e,t,n){this.reset(e,t,!0,n)}reset(e,t,n=!1,i){let o=i?.sizeRange??[12,22],a=i?.opacityRange??[.75,.95],l=i?.colors??["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"];this.size=s(o[0],o[1]),this.aspectRatio=s(1.15,1.35),this.opacity=s(a[0],a[1]),this.color1=l[Math.floor(Math.random()*l.length)],this.color2=l[Math.floor(Math.random()*l.length)],this.x=s(-50,e+50),this.y=n?s(-t,t):s(-60,-20),this.z=s(.7,1.25),this.vy=s(1.2,2.6)*this.z,this.vx=s(-.5,.8),this.pitch=s(0,Math.PI*2),this.yaw=s(0,Math.PI*2),this.roll=s(0,Math.PI*2),this.dPitch=s(.015,.045),this.dYaw=s(.02,.06),this.dRoll=s(.01,.03),this.oscillationPhase=s(0,Math.PI*2),this.oscillationSpeed=s(.02,.05),this.swayAmplitude=s(.8,2.2),this.mouseVx=0,this.mouseVy=0}update(e,t,n,i,o,a=140,l=1.8){this.pitch+=this.dPitch,this.yaw+=this.dYaw,this.roll+=this.dRoll,this.oscillationPhase+=this.oscillationSpeed;let f=Math.sin(this.oscillationPhase)*this.swayAmplitude;if(i!==null&&o!==null){let d=this.x-i,m=this.y-o,p=d*d+m*m,y=a*a;if(p<y&&p>0){let c=Math.sqrt(p),b=(1-c/a)*l;this.mouseVx+=d/c*b*2.5,this.mouseVy+=(m/c*b-.5)*1.5}}this.mouseVx*=.92,this.mouseVy*=.92,this.x+=(this.vx+n+f+this.mouseVx)*this.z,this.y+=(this.vy+this.mouseVy)*this.z,(this.y>t+40||this.x>e+80||this.x<-80)&&(n>0&&Math.random()<.3?(this.x=-30,this.y=s(-20,t*.7)):(this.y=-30,this.x=s(-40,e+40)),this.mouseVx=0,this.mouseVy=0)}draw(e){e.save(),e.translate(this.x,this.y),e.rotate(this.roll);let t=Math.cos(this.yaw)*this.z,n=Math.cos(this.pitch)*this.z;e.scale(t,n),e.globalAlpha=Math.max(0,Math.min(1,this.opacity));let i=this.size/this.aspectRatio*.5,o=this.size*.5,a=e.createLinearGradient(0,o,0,-o);a.addColorStop(0,this.color1),a.addColorStop(1,this.color2),e.fillStyle=a,e.beginPath(),e.moveTo(0,o),e.bezierCurveTo(-i*1.3,o*.4,-i*1.2,-o*.6,-i*.35,-o),e.quadraticCurveTo(0,-o*.75,i*.35,-o),e.bezierCurveTo(i*1.2,-o*.6,i*1.3,o*.4,0,o),e.closePath(),e.fill(),e.restore()}};var u=class r{static DEFAULT_OPTIONS={root:null,number:45,gravityRange:[1.2,2.6],wind:{speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8},petalStyle:{colors:["#ffb7c5","#ff8da1","#fca3b7","#ffe4e9"],opacityRange:[.75,.95],sizeRange:[12,22]},style:{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"999999"},respectReducedMotion:!0,maxPixelRatio:2};canvas=null;ctx=null;root=null;respectReducedMotion=!0;maxPixelRatio=2;petals=[];_number=45;_wind={speed:1.5,gust:1.5,enableMouseBreeze:!0,mouseRadius:140,mouseForce:1.8};_petalStyle={};_gravityRange=[1.2,2.6];animationFrameId=null;isRunning=!1;isDestroyed=!1;width=0;height=0;pixelRatio=1;resizeObserver=null;mediaQueryList=null;windTime=0;currentWind=1.5;mouseX=null;mouseY=null;boundOnPointerMove=null;boundOnPointerLeave=null;boundOnMotionChange=null;constructor(e){let t={...r.DEFAULT_OPTIONS,...e};this._number=Math.max(0,Math.min(1e4,t.number??45));let n=r.DEFAULT_OPTIONS.wind;if(this._wind={speed:t.wind?.speed??n.speed,gust:t.wind?.gust??n.gust,enableMouseBreeze:t.wind?.enableMouseBreeze??n.enableMouseBreeze,mouseRadius:t.wind?.mouseRadius??n.mouseRadius,mouseForce:t.wind?.mouseForce??n.mouseForce},this._petalStyle={...r.DEFAULT_OPTIONS.petalStyle,...t.petalStyle||{}},this._gravityRange=t.gravityRange||[1.2,2.6],this.respectReducedMotion=t.respectReducedMotion??!0,this.maxPixelRatio=t.maxPixelRatio??2,typeof window>"u"||typeof document>"u"||(this.root=t.root??document.body,!this.root))return;this.canvas=document.createElement("canvas"),this.canvas.setAttribute("aria-hidden","true"),this.ctx=this.canvas.getContext("2d");let i={...r.DEFAULT_OPTIONS.style,...t.style||{}};Object.assign(this.canvas.style,i),this.root.appendChild(this.canvas),this.updateDimensions(),typeof ResizeObserver<"u"&&this.root?(this.resizeObserver=new ResizeObserver(()=>this.updateDimensions()),this.resizeObserver.observe(this.root===document.body?document.documentElement:this.root)):window.addEventListener("resize",this.updateDimensions),this._wind.enableMouseBreeze&&this.attachMouseListeners(),this.respectReducedMotion&&typeof window.matchMedia=="function"&&(this.mediaQueryList=window.matchMedia("(prefers-reduced-motion: reduce)"),this.boundOnMotionChange=a=>{a.matches?this.pause():!this.isDestroyed&&this.isRunning&&this.resume()},this.mediaQueryList.addEventListener&&this.mediaQueryList.addEventListener("change",this.boundOnMotionChange)),this.initPetals(),this.respectReducedMotion&&this.mediaQueryList?.matches?this.renderFrame():this.start()}get number(){return this._number}set number(e){this.isDestroyed||(this._number=Math.max(0,Math.min(1e4,Math.floor(e))),this.adjustPetalCount())}get wind(){return{...this._wind}}set wind(e){this.isDestroyed||(this._wind={...this._wind,...e},e.enableMouseBreeze===!1?this.removeMouseListeners():e.enableMouseBreeze===!0&&this.attachMouseListeners())}get petalStyle(){return{...this._petalStyle}}set petalStyle(e){if(!this.isDestroyed){this._petalStyle={...this._petalStyle,...e};for(let t of this.petals)t.reset(this.width,this.height,!1,this._petalStyle)}}start(){this.isDestroyed||this.isRunning||(this.isRunning=!0,this.resume())}stop(){this.isRunning=!1,this.pause()}resume(){this.animationFrameId===null&&!this.isDestroyed&&(this.animationFrameId=requestAnimationFrame(this.loop))}pause(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}clear(){this.isDestroyed=!0,this.stop(),this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):typeof window<"u"&&window.removeEventListener("resize",this.updateDimensions),this.mediaQueryList&&this.boundOnMotionChange&&this.mediaQueryList.removeEventListener&&this.mediaQueryList.removeEventListener("change",this.boundOnMotionChange),this.removeMouseListeners(),this.canvas&&this.canvas.parentElement&&this.canvas.parentElement.removeChild(this.canvas),this.petals=[]}updateDimensions=()=>{if(!this.canvas||!this.root)return;let e=this.root===document.body,t=e?window.innerWidth:this.root.clientWidth,n=e?window.innerHeight:this.root.clientHeight;this.width=t,this.height=n;let i=typeof window<"u"&&window.devicePixelRatio||1;this.pixelRatio=Math.min(i,this.maxPixelRatio),this.canvas.width=Math.round(this.width*this.pixelRatio),this.canvas.height=Math.round(this.height*this.pixelRatio),this.ctx&&this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)};initPetals(){this.petals=[];for(let e=0;e<this._number;e++)this.petals.push(new h(this.width,this.height,this._petalStyle))}adjustPetalCount(){let e=this.petals.length;if(this._number>e)for(let t=e;t<this._number;t++)this.petals.push(new h(this.width,this.height,this._petalStyle));else this._number<e&&this.petals.splice(this._number)}attachMouseListeners(){typeof window>"u"||this.boundOnPointerMove||(this.boundOnPointerMove=e=>{this.mouseX=e.clientX,this.mouseY=e.clientY},this.boundOnPointerLeave=()=>{this.mouseX=null,this.mouseY=null},window.addEventListener("pointermove",this.boundOnPointerMove,{passive:!0}),window.addEventListener("pointerleave",this.boundOnPointerLeave,{passive:!0}))}removeMouseListeners(){typeof window>"u"||(this.boundOnPointerMove&&(window.removeEventListener("pointermove",this.boundOnPointerMove),this.boundOnPointerMove=null),this.boundOnPointerLeave&&(window.removeEventListener("pointerleave",this.boundOnPointerLeave),this.boundOnPointerLeave=null),this.mouseX=null,this.mouseY=null)}renderFrame(){if(!(!this.ctx||!this.canvas)){this.ctx.clearRect(0,0,this.width,this.height);for(let e of this.petals)e.draw(this.ctx)}}loop=()=>{if(!this.isRunning||this.isDestroyed)return;this.windTime+=.015;let e=Math.sin(this.windTime)*this._wind.gust+Math.cos(this.windTime*.4)*.5;this.currentWind=this._wind.speed+e;for(let t=0;t<this.petals.length;t++)this.petals[t].update(this.width,this.height,this.currentWind,this.mouseX,this.mouseY,this._wind.mouseRadius,this._wind.mouseForce);this.renderFrame(),this.animationFrameId=requestAnimationFrame(this.loop)}};var O=u;return x(L);})();
|
|
2
|
+
//# sourceMappingURL=index.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/math.ts","../src/petal.ts","../src/cherryblossom.ts"],"sourcesContent":["export { CherryBlossom } from \"./cherryblossom\";\nexport { Petal } from \"./petal\";\nexport type {\n CherryBlossomOptions,\n WindOptions,\n PetalStyle\n} from \"./types\";\n\nimport { CherryBlossom } from \"./cherryblossom\";\nexport default CherryBlossom;\n","/**\n * Random float in range [min, max)\n */\nexport function randomRange(min: number, max: number): number {\n return min + Math.random() * (max - min);\n}\n\n/**\n * Random integer in range [min, max]\n */\nexport function randomInt(min: number, max: number): number {\n return Math.floor(min + Math.random() * (max - min + 1));\n}\n\n/**\n * Clamp a number between min and max\n */\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, val));\n}\n","import { randomRange } from \"./math\";\nimport type { PetalStyle } from \"./types\";\n\n/**\n * Represents a single cherry blossom petal with 3D orientation (yaw, pitch, roll),\n * physics velocities, realistic bezier geometry, and wind responsiveness.\n */\nexport class Petal {\n // Coordinates\n x = 0;\n y = 0;\n z = 0; // Simulated depth for scale & parallax\n\n // Dimensions\n size = 15;\n aspectRatio = 1.25; // Length to width ratio\n\n // Velocities\n vx = 0;\n vy = 0;\n vz = 0;\n\n // 3D rotation angles & angular velocities\n pitch = 0; // Tumbling end-over-end\n yaw = 0; // Spinning around horizontal axis\n roll = 0; // Twisting clockwise/counterclockwise\n dPitch = 0;\n dYaw = 0;\n dRoll = 0;\n\n // Flutter & sway oscillation parameters\n oscillationPhase = 0;\n oscillationSpeed = 0;\n swayAmplitude = 0;\n\n // Color & appearance\n color1 = \"#ffb7c5\";\n color2 = \"#ff94aa\";\n opacity = 0.85;\n\n // Mouse wind displacement\n mouseVx = 0;\n mouseVy = 0;\n\n constructor(width: number, height: number, style?: PetalStyle) {\n this.reset(width, height, true, style);\n }\n\n /**\n * Re-initializes petal position, velocities, and 3D rotations.\n * If initial is true, petals are scattered vertically across the whole screen.\n */\n reset(width: number, height: number, initial = false, style?: PetalStyle): void {\n const sizeRange = style?.sizeRange ?? [12, 22];\n const opacityRange = style?.opacityRange ?? [0.75, 0.95];\n const colors = style?.colors ?? [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"];\n\n this.size = randomRange(sizeRange[0], sizeRange[1]);\n this.aspectRatio = randomRange(1.15, 1.35);\n this.opacity = randomRange(opacityRange[0], opacityRange[1]);\n\n // Pick random gradient colors for realistic petal shading\n this.color1 = colors[Math.floor(Math.random() * colors.length)];\n this.color2 = colors[Math.floor(Math.random() * colors.length)];\n\n // Position\n this.x = randomRange(-50, width + 50);\n this.y = initial ? randomRange(-height, height) : randomRange(-60, -20);\n this.z = randomRange(0.7, 1.25); // Parallax depth\n\n // Falling velocity (scaled slightly by depth)\n this.vy = randomRange(1.2, 2.6) * this.z;\n this.vx = randomRange(-0.5, 0.8);\n\n // 3D angles (in radians)\n this.pitch = randomRange(0, Math.PI * 2);\n this.yaw = randomRange(0, Math.PI * 2);\n this.roll = randomRange(0, Math.PI * 2);\n\n // Rotational velocities (flutter speed)\n this.dPitch = randomRange(0.015, 0.045);\n this.dYaw = randomRange(0.02, 0.06);\n this.dRoll = randomRange(0.01, 0.03);\n\n // Sway oscillation\n this.oscillationPhase = randomRange(0, Math.PI * 2);\n this.oscillationSpeed = randomRange(0.02, 0.05);\n this.swayAmplitude = randomRange(0.8, 2.2);\n\n // Reset mouse influence\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n\n /**\n * Update particle physics step\n */\n update(\n width: number,\n height: number,\n ambientWind: number,\n mouseX: number | null,\n mouseY: number | null,\n mouseRadius = 140,\n mouseForce = 1.8\n ): void {\n // 3D rotation update\n this.pitch += this.dPitch;\n this.yaw += this.dYaw;\n this.roll += this.dRoll;\n\n // Organic swaying wave\n this.oscillationPhase += this.oscillationSpeed;\n const sway = Math.sin(this.oscillationPhase) * this.swayAmplitude;\n\n // Mouse breeze interaction\n if (mouseX !== null && mouseY !== null) {\n const dx = this.x - mouseX;\n const dy = this.y - mouseY;\n const distSq = dx * dx + dy * dy;\n const radSq = mouseRadius * mouseRadius;\n\n if (distSq < radSq && distSq > 0) {\n const dist = Math.sqrt(distSq);\n const factor = (1 - dist / mouseRadius) * mouseForce;\n // Direction away from mouse with a slight upward and swirling drift\n this.mouseVx += (dx / dist) * factor * 2.5;\n this.mouseVy += ((dy / dist) * factor - 0.5) * 1.5;\n }\n }\n\n // Dampen mouse breeze impulse\n this.mouseVx *= 0.92;\n this.mouseVy *= 0.92;\n\n // Update positions\n this.x += (this.vx + ambientWind + sway + this.mouseVx) * this.z;\n this.y += (this.vy + this.mouseVy) * this.z;\n\n // Reset when moving off-screen\n if (this.y > height + 40 || this.x > width + 80 || this.x < -80) {\n // Loop from top or left depending on wind\n if (ambientWind > 0 && Math.random() < 0.3) {\n // Wrap around from left\n this.x = -30;\n this.y = randomRange(-20, height * 0.7);\n } else {\n this.y = -30;\n this.x = randomRange(-40, width + 40);\n }\n this.mouseVx = 0;\n this.mouseVy = 0;\n }\n }\n\n /**\n * Draw the petal using Canvas2D bezier curves, transformed into 3D view\n */\n draw(ctx: CanvasRenderingContext2D): void {\n ctx.save();\n\n // Move to petal center\n ctx.translate(this.x, this.y);\n\n // Apply 3D rotation using 2D projection matrix\n // Roll rotates in 2D plane; Pitch and Yaw squish width/height to simulate 3D rotation\n ctx.rotate(this.roll);\n const scaleX = Math.cos(this.yaw) * this.z;\n const scaleY = Math.cos(this.pitch) * this.z;\n ctx.scale(scaleX, scaleY);\n\n ctx.globalAlpha = Math.max(0, Math.min(1, this.opacity));\n\n // Draw realistic sakura petal shape with notch at tip\n // The petal is drawn centered around (0, 0), with base at (0, length/2) and notched tip at (0, -length/2)\n const w = (this.size / this.aspectRatio) * 0.5;\n const h = this.size * 0.5;\n\n // Gradient shading across the petal\n const grad = ctx.createLinearGradient(0, h, 0, -h);\n grad.addColorStop(0, this.color1);\n grad.addColorStop(1, this.color2);\n ctx.fillStyle = grad;\n\n ctx.beginPath();\n // Start at bottom base of petal\n ctx.moveTo(0, h);\n\n // Left curved side up to the left lobe of notch\n ctx.bezierCurveTo(-w * 1.3, h * 0.4, -w * 1.2, -h * 0.6, -w * 0.35, -h);\n\n // The iconic sakura notch at petal tip\n ctx.quadraticCurveTo(0, -h * 0.75, w * 0.35, -h);\n\n // Right curved side down back to base\n ctx.bezierCurveTo(w * 1.2, -h * 0.6, w * 1.3, h * 0.4, 0, h);\n\n ctx.closePath();\n ctx.fill();\n\n ctx.restore();\n }\n}\n","import { Petal } from \"./petal\";\nimport { randomRange } from \"./math\";\nimport type { CherryBlossomOptions, WindOptions, PetalStyle } from \"./types\";\n\n/**\n * CherryBlossom manages the canvas lifecycle, particle physics simulation loop,\n * dynamic wind fluctuations, mouse interaction breeze, and high-DPI responsive rendering.\n */\nexport class CherryBlossom {\n /**\n * Static default options\n */\n public static readonly DEFAULT_OPTIONS = {\n root: null as HTMLElement | null,\n number: 45,\n gravityRange: [1.2, 2.6] as [number, number],\n wind: {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n },\n petalStyle: {\n colors: [\"#ffb7c5\", \"#ff8da1\", \"#fca3b7\", \"#ffe4e9\"],\n opacityRange: [0.75, 0.95] as [number, number],\n sizeRange: [12, 22] as [number, number]\n },\n style: {\n position: \"fixed\",\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n zIndex: \"999999\"\n } as Partial<CSSStyleDeclaration>,\n respectReducedMotion: true,\n maxPixelRatio: 2\n };\n\n public readonly canvas: HTMLCanvasElement | null = null;\n private readonly ctx: CanvasRenderingContext2D | null = null;\n private readonly root: HTMLElement | null = null;\n private readonly respectReducedMotion: boolean = true;\n private readonly maxPixelRatio: number = 2;\n\n // State\n private petals: Petal[] = [];\n private _number: number = 45;\n private _wind: Required<WindOptions> = {\n speed: 1.5,\n gust: 1.5,\n enableMouseBreeze: true,\n mouseRadius: 140,\n mouseForce: 1.8\n };\n private _petalStyle: PetalStyle = {};\n private _gravityRange: [number, number] = [1.2, 2.6];\n \n private animationFrameId: number | null = null;\n private isRunning: boolean = false;\n private isDestroyed: boolean = false;\n\n // Environment & metrics\n private width: number = 0;\n private height: number = 0;\n private pixelRatio: number = 1;\n private resizeObserver: ResizeObserver | null = null;\n private mediaQueryList: MediaQueryList | null = null;\n\n // Wind calculation state\n private windTime: number = 0;\n private currentWind: number = 1.5;\n\n // Mouse tracking\n private mouseX: number | null = null;\n private mouseY: number | null = null;\n private boundOnPointerMove: ((e: PointerEvent | MouseEvent) => void) | null = null;\n private boundOnPointerLeave: (() => void) | null = null;\n private boundOnMotionChange: ((e: MediaQueryListEvent) => void) | null = null;\n\n constructor(options?: CherryBlossomOptions) {\n const opts = { ...CherryBlossom.DEFAULT_OPTIONS, ...options };\n\n this._number = Math.max(0, Math.min(10000, opts.number ?? 45));\n const defaultWind = CherryBlossom.DEFAULT_OPTIONS.wind;\n this._wind = {\n speed: opts.wind?.speed ?? defaultWind.speed,\n gust: opts.wind?.gust ?? defaultWind.gust,\n enableMouseBreeze: opts.wind?.enableMouseBreeze ?? defaultWind.enableMouseBreeze,\n mouseRadius: opts.wind?.mouseRadius ?? defaultWind.mouseRadius,\n mouseForce: opts.wind?.mouseForce ?? defaultWind.mouseForce\n };\n this._petalStyle = {\n ...CherryBlossom.DEFAULT_OPTIONS.petalStyle,\n ...(opts.petalStyle || {})\n };\n this._gravityRange = opts.gravityRange || [1.2, 2.6];\n this.respectReducedMotion = opts.respectReducedMotion ?? true;\n this.maxPixelRatio = opts.maxPixelRatio ?? 2;\n\n // Guard for SSR environments where document/window are undefined\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return;\n }\n\n this.root = opts.root ?? document.body;\n if (!this.root) return;\n\n // Create and attach canvas element\n this.canvas = document.createElement(\"canvas\");\n this.canvas.setAttribute(\"aria-hidden\", \"true\");\n this.ctx = this.canvas.getContext(\"2d\");\n\n // Apply styles\n const styles = { ...CherryBlossom.DEFAULT_OPTIONS.style, ...(opts.style || {}) };\n Object.assign(this.canvas.style, styles);\n\n this.root.appendChild(this.canvas);\n\n // Initial resize and high-DPI setup\n this.updateDimensions();\n\n // Listen to resize\n if (typeof ResizeObserver !== \"undefined\" && this.root) {\n this.resizeObserver = new ResizeObserver(() => this.updateDimensions());\n this.resizeObserver.observe(this.root === document.body ? document.documentElement : this.root);\n } else {\n window.addEventListener(\"resize\", this.updateDimensions);\n }\n\n // Mouse breeze listeners\n if (this._wind.enableMouseBreeze) {\n this.attachMouseListeners();\n }\n\n // Prefers-reduced-motion listener\n if (this.respectReducedMotion && typeof window.matchMedia === \"function\") {\n this.mediaQueryList = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n this.boundOnMotionChange = (e: MediaQueryListEvent) => {\n if (e.matches) {\n this.pause();\n } else if (!this.isDestroyed && this.isRunning) {\n this.resume();\n }\n };\n if (this.mediaQueryList.addEventListener) {\n this.mediaQueryList.addEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n // Spawn petals\n this.initPetals();\n\n // Check reduced motion setting before starting\n const prefersReduced = this.respectReducedMotion && this.mediaQueryList?.matches;\n if (!prefersReduced) {\n this.start();\n } else {\n // Draw static frame once\n this.renderFrame();\n }\n }\n\n // --- Public Getters and Setters ---\n\n public get number(): number {\n return this._number;\n }\n\n public set number(value: number) {\n if (this.isDestroyed) return;\n this._number = Math.max(0, Math.min(10000, Math.floor(value)));\n this.adjustPetalCount();\n }\n\n public get wind(): Required<WindOptions> {\n return { ...this._wind };\n }\n\n public set wind(options: Partial<WindOptions>) {\n if (this.isDestroyed) return;\n this._wind = { ...this._wind, ...options };\n if (options.enableMouseBreeze === false) {\n this.removeMouseListeners();\n } else if (options.enableMouseBreeze === true) {\n this.attachMouseListeners();\n }\n }\n\n public get petalStyle(): PetalStyle {\n return { ...this._petalStyle };\n }\n\n public set petalStyle(style: PetalStyle) {\n if (this.isDestroyed) return;\n this._petalStyle = { ...this._petalStyle, ...style };\n // Re-apply to all petals\n for (const petal of this.petals) {\n petal.reset(this.width, this.height, false, this._petalStyle);\n }\n }\n\n // --- Lifecycle Control Methods ---\n\n /**\n * Starts or resumes the animation loop.\n */\n public start(): void {\n if (this.isDestroyed || this.isRunning) return;\n this.isRunning = true;\n this.resume();\n }\n\n /**\n * Pauses the animation loop.\n */\n public stop(): void {\n this.isRunning = false;\n this.pause();\n }\n\n /**\n * Alias for start()\n */\n public resume(): void {\n if (this.animationFrameId === null && !this.isDestroyed) {\n this.animationFrameId = requestAnimationFrame(this.loop);\n }\n }\n\n /**\n * Alias for stop()\n */\n public pause(): void {\n if (this.animationFrameId !== null) {\n cancelAnimationFrame(this.animationFrameId);\n this.animationFrameId = null;\n }\n }\n\n /**\n * Cleans up canvas, event listeners, observers and removes the element permanently.\n */\n public clear(): void {\n this.isDestroyed = true;\n this.stop();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n } else if (typeof window !== \"undefined\") {\n window.removeEventListener(\"resize\", this.updateDimensions);\n }\n\n if (this.mediaQueryList && this.boundOnMotionChange) {\n if (this.mediaQueryList.removeEventListener) {\n this.mediaQueryList.removeEventListener(\"change\", this.boundOnMotionChange);\n }\n }\n\n this.removeMouseListeners();\n\n if (this.canvas && this.canvas.parentElement) {\n this.canvas.parentElement.removeChild(this.canvas);\n }\n\n this.petals = [];\n }\n\n // --- Private Implementations ---\n\n private updateDimensions = (): void => {\n if (!this.canvas || !this.root) return;\n\n const isBody = this.root === document.body;\n const clientWidth = isBody ? window.innerWidth : this.root.clientWidth;\n const clientHeight = isBody ? window.innerHeight : this.root.clientHeight;\n\n this.width = clientWidth;\n this.height = clientHeight;\n\n const dpr = typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1;\n this.pixelRatio = Math.min(dpr, this.maxPixelRatio);\n\n // Canvas physical buffer resolution\n this.canvas.width = Math.round(this.width * this.pixelRatio);\n this.canvas.height = Math.round(this.height * this.pixelRatio);\n\n // Scale context to match retina pixels\n if (this.ctx) {\n this.ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);\n }\n };\n\n private initPetals(): void {\n this.petals = [];\n for (let i = 0; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n }\n\n private adjustPetalCount(): void {\n const current = this.petals.length;\n if (this._number > current) {\n for (let i = current; i < this._number; i++) {\n this.petals.push(new Petal(this.width, this.height, this._petalStyle));\n }\n } else if (this._number < current) {\n this.petals.splice(this._number);\n }\n }\n\n private attachMouseListeners(): void {\n if (typeof window === \"undefined\" || this.boundOnPointerMove) return;\n\n this.boundOnPointerMove = (e: MouseEvent | PointerEvent) => {\n this.mouseX = e.clientX;\n this.mouseY = e.clientY;\n };\n\n this.boundOnPointerLeave = () => {\n this.mouseX = null;\n this.mouseY = null;\n };\n\n window.addEventListener(\"pointermove\", this.boundOnPointerMove, { passive: true });\n window.addEventListener(\"pointerleave\", this.boundOnPointerLeave, { passive: true });\n }\n\n private removeMouseListeners(): void {\n if (typeof window === \"undefined\") return;\n\n if (this.boundOnPointerMove) {\n window.removeEventListener(\"pointermove\", this.boundOnPointerMove);\n this.boundOnPointerMove = null;\n }\n if (this.boundOnPointerLeave) {\n window.removeEventListener(\"pointerleave\", this.boundOnPointerLeave);\n this.boundOnPointerLeave = null;\n }\n this.mouseX = null;\n this.mouseY = null;\n }\n\n private renderFrame(): void {\n if (!this.ctx || !this.canvas) return;\n\n this.ctx.clearRect(0, 0, this.width, this.height);\n\n for (const petal of this.petals) {\n petal.draw(this.ctx);\n }\n }\n\n private loop = (): void => {\n if (!this.isRunning || this.isDestroyed) return;\n\n // Organic wind oscillation over time\n this.windTime += 0.015;\n const gust = Math.sin(this.windTime) * this._wind.gust + Math.cos(this.windTime * 0.4) * 0.5;\n this.currentWind = this._wind.speed + gust;\n\n // Update each petal\n for (let i = 0; i < this.petals.length; i++) {\n this.petals[i].update(\n this.width,\n this.height,\n this.currentWind,\n this.mouseX,\n this.mouseY,\n this._wind.mouseRadius,\n this._wind.mouseForce\n );\n }\n\n this.renderFrame();\n\n this.animationFrameId = requestAnimationFrame(this.loop);\n };\n}\n"],"mappings":"ocAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,UAAAC,EAAA,YAAAC,ICGO,SAASC,EAAYC,EAAaC,EAAqB,CAC5D,OAAOD,EAAM,KAAK,OAAO,GAAKC,EAAMD,EACtC,CCEO,IAAME,EAAN,KAAY,CAEjB,EAAI,EACJ,EAAI,EACJ,EAAI,EAGJ,KAAO,GACP,YAAc,KAGd,GAAK,EACL,GAAK,EACL,GAAK,EAGL,MAAQ,EACR,IAAM,EACN,KAAO,EACP,OAAS,EACT,KAAO,EACP,MAAQ,EAGR,iBAAmB,EACnB,iBAAmB,EACnB,cAAgB,EAGhB,OAAS,UACT,OAAS,UACT,QAAU,IAGV,QAAU,EACV,QAAU,EAEV,YAAYC,EAAeC,EAAgBC,EAAoB,CAC7D,KAAK,MAAMF,EAAOC,EAAQ,GAAMC,CAAK,CACvC,CAMA,MAAMF,EAAeC,EAAgBE,EAAU,GAAOD,EAA0B,CAC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B,GAAI,GAAC,KAAK,KAAO,CAAC,KAAK,QAEvB,MAAK,IAAI,UAAU,EAAG,EAAG,KAAK,MAAO,KAAK,MAAM,EAEhD,QAAWP,KAAS,KAAK,OACvBA,EAAM,KAAK,KAAK,GAAG,EAEvB,CAEQ,KAAO,IAAY,CACzB,GAAI,CAAC,KAAK,WAAa,KAAK,YAAa,OAGzC,KAAK,UAAY,KACjB,IAAMQ,EAAO,KAAK,IAAI,KAAK,QAAQ,EAAI,KAAK,MAAM,KAAO,KAAK,IAAI,KAAK,SAAW,EAAG,EAAI,GACzF,KAAK,YAAc,KAAK,MAAM,MAAQA,EAGtC,QAASH,EAAI,EAAGA,EAAI,KAAK,OAAO,OAAQA,IACtC,KAAK,OAAOA,CAAC,EAAE,OACb,KAAK,MACL,KAAK,OACL,KAAK,YACL,KAAK,OACL,KAAK,OACL,KAAK,MAAM,YACX,KAAK,MAAM,UACb,EAGF,KAAK,YAAY,EAEjB,KAAK,iBAAmB,sBAAsB,KAAK,IAAI,CACzD,CACF,EHpXA,IAAOI,EAAQC","names":["src_exports","__export","CherryBlossom","Petal","src_default","randomRange","min","max","Petal","width","height","style","initial","sizeRange","opacityRange","colors","randomRange","ambientWind","mouseX","mouseY","mouseRadius","mouseForce","sway","dx","dy","distSq","radSq","dist","factor","ctx","scaleX","scaleY","w","h","grad","CherryBlossom","_CherryBlossom","options","opts","defaultWind","styles","e","value","style","petal","isBody","clientWidth","clientHeight","dpr","i","Petal","current","gust","src_default","CherryBlossom"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { CherryBlossom } from \"./cherryblossom\";\nexport { Petal } from \"./petal\";\nexport type {\n CherryBlossomOptions,\n WindOptions,\n PetalStyle\n} from \"./types\";\n\nimport { CherryBlossom } from \"./cherryblossom\";\nexport default CherryBlossom;\n"],"mappings":"gDASA,IAAOA,EAAQC","names":["src_default","CherryBlossom"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "let-it-blossom",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "🌸 Let your website bloom instantly. Realistic floating cherry blossom petals with 3D flutter, wind dynamics, and mouse interaction. Zero dependencies.",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"browser": "./dist/cherryblossom.global.global.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/austinhttps/npm-package-cherry-blossom.git"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"cherry-blossom",
|
|
33
|
+
"sakura",
|
|
34
|
+
"petals",
|
|
35
|
+
"canvas",
|
|
36
|
+
"animation",
|
|
37
|
+
"effects",
|
|
38
|
+
"particles",
|
|
39
|
+
"let-it-go",
|
|
40
|
+
"spring"
|
|
41
|
+
],
|
|
42
|
+
"author": "Austin",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/austinhttps/npm-package-cherry-blossom/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/austinhttps/npm-package-cherry-blossom#readme",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.0.0",
|
|
50
|
+
"tsup": "^8.3.5",
|
|
51
|
+
"typescript": "^5.6.3",
|
|
52
|
+
"vitest": "^2.1.8"
|
|
53
|
+
}
|
|
54
|
+
}
|