@sarthak03dot/romantic-animations 1.2.9 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/index.d.ts +102 -0
- package/package.json +4 -5
- package/dist/index.d.ts +0 -1
- package/src/animations/butterfly.js +0 -92
- package/src/animations/confetti.js +0 -92
- package/src/animations/fireworks.js +0 -112
- package/src/animations/floatingHearts.js +0 -89
- package/src/animations/floatingOrbs.js +0 -76
- package/src/animations/heartBurst.js +0 -113
- package/src/animations/heartTrail.js +0 -85
- package/src/animations/loveRain.js +0 -71
- package/src/animations/magicDust.js +0 -87
- package/src/animations/shootingStars.js +0 -82
- package/src/animations/sparkles.js +0 -93
- package/src/animations/starField.js +0 -100
- package/src/core/engine.js +0 -77
- package/src/index.d.ts +0 -26
- package/src/index.js +0 -224
package/src/core/engine.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* romantic-animations — core engine
|
|
3
|
-
* Handles canvas creation, sizing, resize observation, and cleanup.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const DEFAULT_OPTIONS = {
|
|
7
|
-
zIndex: 0,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Initialises a canvas inside the given container element.
|
|
12
|
-
*
|
|
13
|
-
* @param {string|HTMLElement} containerIdOrEl – element id OR element reference
|
|
14
|
-
* @param {object} userOptions – optional overrides
|
|
15
|
-
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D,
|
|
16
|
-
* options: object, destroy: Function }}
|
|
17
|
-
*/
|
|
18
|
-
export function initCanvas(containerIdOrEl, userOptions = {}) {
|
|
19
|
-
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
|
|
20
|
-
|
|
21
|
-
const container =
|
|
22
|
-
typeof containerIdOrEl === 'string'
|
|
23
|
-
? document.getElementById(containerIdOrEl)
|
|
24
|
-
: containerIdOrEl;
|
|
25
|
-
|
|
26
|
-
if (!container) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`[romantic-animations] Container "${containerIdOrEl}" not found in the DOM.`
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Remove any pre-existing canvas we created (clean slate when re-triggering)
|
|
33
|
-
const old = container.querySelector('canvas[data-ra]');
|
|
34
|
-
if (old) old.remove();
|
|
35
|
-
|
|
36
|
-
const canvas = document.createElement('canvas');
|
|
37
|
-
canvas.setAttribute('data-ra', '1');
|
|
38
|
-
canvas.style.cssText = `
|
|
39
|
-
position: fixed;
|
|
40
|
-
top: 0;
|
|
41
|
-
left: 0;
|
|
42
|
-
width: 100vw;
|
|
43
|
-
height: 100vh;
|
|
44
|
-
pointer-events: none;
|
|
45
|
-
z-index: ${options.zIndex};
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
const resize = () => {
|
|
49
|
-
canvas.width = window.innerWidth;
|
|
50
|
-
canvas.height = window.innerHeight;
|
|
51
|
-
};
|
|
52
|
-
resize();
|
|
53
|
-
|
|
54
|
-
container.style.position = container.style.position || 'relative';
|
|
55
|
-
container.appendChild(canvas);
|
|
56
|
-
|
|
57
|
-
// Keep canvas sized to container
|
|
58
|
-
const ro = new ResizeObserver(resize);
|
|
59
|
-
ro.observe(container);
|
|
60
|
-
|
|
61
|
-
const ctx = canvas.getContext('2d');
|
|
62
|
-
|
|
63
|
-
/** Tear-down helper – call the returned destroy() to stop & clean up */
|
|
64
|
-
function destroy() {
|
|
65
|
-
ro.disconnect();
|
|
66
|
-
canvas.remove();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return { canvas, ctx, options, destroy };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Merge user options with animation-specific defaults.
|
|
74
|
-
*/
|
|
75
|
-
export function mergeOptions(defaults, userOptions = {}) {
|
|
76
|
-
return Object.assign({}, defaults, userOptions);
|
|
77
|
-
}
|
package/src/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export interface AnimationOptions {
|
|
2
|
-
density?: number;
|
|
3
|
-
minSize?: number;
|
|
4
|
-
maxSize?: number;
|
|
5
|
-
speed?: number;
|
|
6
|
-
colors?: string[];
|
|
7
|
-
zIndex?: number;
|
|
8
|
-
pointerEvents?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export declare function startFloatingHearts(
|
|
12
|
-
container?: HTMLElement,
|
|
13
|
-
options?: AnimationOptions
|
|
14
|
-
): number;
|
|
15
|
-
|
|
16
|
-
export declare function startConfetti(
|
|
17
|
-
container?: HTMLElement,
|
|
18
|
-
options?: AnimationOptions
|
|
19
|
-
): number;
|
|
20
|
-
|
|
21
|
-
export declare function startFireworks(
|
|
22
|
-
container?: HTMLElement,
|
|
23
|
-
options?: AnimationOptions
|
|
24
|
-
): number;
|
|
25
|
-
|
|
26
|
-
export declare function stopAnimation(id: number): void;
|
package/src/index.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* romantic-animations v2.0.0
|
|
3
|
-
* ───────────────────────────────────────────────────────
|
|
4
|
-
* A rich collection of canvas-based romantic & celebratory
|
|
5
|
-
* animations for the web.
|
|
6
|
-
*
|
|
7
|
-
* Usage (ESM):
|
|
8
|
-
* import { startFloatingHearts, stopAll } from '@sarthak03dot/romantic-animations';
|
|
9
|
-
* startFloatingHearts('my-container');
|
|
10
|
-
*
|
|
11
|
-
* Usage (UMD / CDN):
|
|
12
|
-
* <script src="...romantic-animations.umd.js"></script>
|
|
13
|
-
* <script>
|
|
14
|
-
* RomanticAnimations.startFloatingHearts('my-container');
|
|
15
|
-
* </script>
|
|
16
|
-
* ───────────────────────────────────────────────────────
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { initCanvas } from './core/engine.js';
|
|
20
|
-
import { floatingHearts } from './animations/floatingHearts.js';
|
|
21
|
-
import { heartTrail } from './animations/heartTrail.js';
|
|
22
|
-
import { heartBurst } from './animations/heartBurst.js';
|
|
23
|
-
import { sparkles } from './animations/sparkles.js';
|
|
24
|
-
import { loveRain } from './animations/loveRain.js';
|
|
25
|
-
import { confetti } from './animations/confetti.js';
|
|
26
|
-
import { fireworks } from './animations/fireworks.js';
|
|
27
|
-
import { starField } from './animations/starField.js';
|
|
28
|
-
import { butterflies } from './animations/butterfly.js';
|
|
29
|
-
import { magicDust } from './animations/magicDust.js';
|
|
30
|
-
import { floatingOrbs } from './animations/floatingOrbs.js';
|
|
31
|
-
import { shootingStars } from './animations/shootingStars.js';
|
|
32
|
-
|
|
33
|
-
// Track active sessions so stopAll() can clean up everything
|
|
34
|
-
const _sessions = new Map(); // containerId → { destroy, stop }
|
|
35
|
-
let _sessionId = 0;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Internal helper — boots a canvas and starts an animation fn.
|
|
39
|
-
* Returns a numeric session id that can be passed to stopAnimation().
|
|
40
|
-
*
|
|
41
|
-
* @param {string|HTMLElement} containerId
|
|
42
|
-
* @param {Function} animFn – the animation factory
|
|
43
|
-
* @param {object} options – user options forwarded to the animation
|
|
44
|
-
* @returns {number} session id
|
|
45
|
-
*/
|
|
46
|
-
function _run(containerId, animFn, options = {}) {
|
|
47
|
-
const { canvas, destroy } = initCanvas(containerId, options);
|
|
48
|
-
const stop = animFn(canvas, options);
|
|
49
|
-
const id = ++_sessionId;
|
|
50
|
-
_sessions.set(id, { destroy, stop });
|
|
51
|
-
return id;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Stop a single animation by its session id.
|
|
56
|
-
* @param {number} id – returned by a start* call
|
|
57
|
-
*/
|
|
58
|
-
export function stopAnimation(id) {
|
|
59
|
-
if (_sessions.has(id)) {
|
|
60
|
-
const s = _sessions.get(id);
|
|
61
|
-
if (typeof s.stop === 'function') s.stop();
|
|
62
|
-
s.destroy();
|
|
63
|
-
_sessions.delete(id);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Stop every running animation and clean up all canvases.
|
|
69
|
-
*/
|
|
70
|
-
export function stopAll() {
|
|
71
|
-
_sessions.forEach((s) => {
|
|
72
|
-
if (typeof s.stop === 'function') s.stop();
|
|
73
|
-
s.destroy();
|
|
74
|
-
});
|
|
75
|
-
_sessions.clear();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Floating hearts rising from the bottom.
|
|
82
|
-
* @param {string|HTMLElement} containerId
|
|
83
|
-
* @param {object} [options]
|
|
84
|
-
* @param {number} [options.count=0.12] – spawn probability per frame (0–1)
|
|
85
|
-
* @param {number} [options.minSize=14]
|
|
86
|
-
* @param {number} [options.maxSize=32]
|
|
87
|
-
* @param {number} [options.minSpeed=0.8]
|
|
88
|
-
* @param {number} [options.maxSpeed=2.4]
|
|
89
|
-
* @param {string[]} [options.colors]
|
|
90
|
-
* @param {boolean} [options.wobble=true] – sine-wave horizontal drift
|
|
91
|
-
* @param {boolean} [options.glow=true]
|
|
92
|
-
* @returns {number} session id
|
|
93
|
-
*/
|
|
94
|
-
export function startFloatingHearts(containerId, options = {}) {
|
|
95
|
-
return _run(containerId, floatingHearts, options);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Heart trail that follows the cursor / touch.
|
|
100
|
-
* @param {string|HTMLElement} containerId
|
|
101
|
-
* @param {object} [options]
|
|
102
|
-
* @param {number} [options.minSize=6]
|
|
103
|
-
* @param {number} [options.maxSize=16]
|
|
104
|
-
* @param {number} [options.decay=0.025]
|
|
105
|
-
* @param {string[]} [options.colors]
|
|
106
|
-
* @param {boolean} [options.glow=true]
|
|
107
|
-
* @returns {number} session id
|
|
108
|
-
*/
|
|
109
|
-
export function startHeartTrail(containerId, options = {}) {
|
|
110
|
-
return _run(containerId, heartTrail, options);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Heart burst on click / tap.
|
|
115
|
-
* @param {string|HTMLElement} containerId
|
|
116
|
-
* @param {object} [options]
|
|
117
|
-
* @param {number} [options.count=20] – particles per burst
|
|
118
|
-
* @param {string[]} [options.symbols] – 'heart' | 'star' | 'sparkle'
|
|
119
|
-
* @param {boolean} [options.glow=true]
|
|
120
|
-
* @returns {number} session id
|
|
121
|
-
*/
|
|
122
|
-
export function startHeartBurst(containerId, options = {}) {
|
|
123
|
-
return _run(containerId, heartBurst, options);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Twinkling sparkle stars.
|
|
128
|
-
* @param {string|HTMLElement} containerId
|
|
129
|
-
* @param {object} [options]
|
|
130
|
-
* @param {number} [options.count=80]
|
|
131
|
-
* @param {number} [options.speed=0.5]
|
|
132
|
-
* @param {boolean} [options.glow=true]
|
|
133
|
-
* @returns {number} session id
|
|
134
|
-
*/
|
|
135
|
-
export function startSparkles(containerId, options = {}) {
|
|
136
|
-
return _run(containerId, sparkles, options);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Rain of love emojis / symbols drifting downward.
|
|
141
|
-
* @param {string|HTMLElement} containerId
|
|
142
|
-
* @param {object} [options]
|
|
143
|
-
* @param {number} [options.density=0.15]
|
|
144
|
-
* @param {string[]} [options.symbols] – array of strings / emoji
|
|
145
|
-
* @param {boolean} [options.glow=true]
|
|
146
|
-
* @returns {number} session id
|
|
147
|
-
*/
|
|
148
|
-
export function startLoveRain(containerId, options = {}) {
|
|
149
|
-
return _run(containerId, loveRain, options);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Colourful confetti raining down.
|
|
154
|
-
* @param {string|HTMLElement} containerId
|
|
155
|
-
* @param {object} [options]
|
|
156
|
-
* @param {number} [options.density=0.18]
|
|
157
|
-
* @param {string[]} [options.colors]
|
|
158
|
-
* @param {string[]} [options.shapes] – 'rect' | 'circle' | 'ribbon'
|
|
159
|
-
* @returns {number} session id
|
|
160
|
-
*/
|
|
161
|
-
export function startConfetti(containerId, options = {}) {
|
|
162
|
-
return _run(containerId, confetti, options);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Fireworks that auto-launch on an interval.
|
|
167
|
-
* @param {string|HTMLElement} containerId
|
|
168
|
-
* @param {object} [options]
|
|
169
|
-
* @param {number} [options.interval=1200] – ms between launches
|
|
170
|
-
* @param {number} [options.particleCount=80]
|
|
171
|
-
* @param {boolean} [options.glow=true]
|
|
172
|
-
* @returns {number} session id
|
|
173
|
-
*/
|
|
174
|
-
export function startFireworks(containerId, options = {}) {
|
|
175
|
-
return _run(containerId, fireworks, options);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Drifting star field with optional constellation lines.
|
|
180
|
-
* @param {string|HTMLElement} containerId
|
|
181
|
-
* @param {object} [options]
|
|
182
|
-
* @param {number} [options.starCount=120]
|
|
183
|
-
* @param {number} [options.speed=0.4]
|
|
184
|
-
* @param {boolean} [options.twinkle=true]
|
|
185
|
-
* @param {number} [options.connectDist=100] – set to 0 to disable lines
|
|
186
|
-
* @returns {number} session id
|
|
187
|
-
*/
|
|
188
|
-
export function startStarField(containerId, options = {}) {
|
|
189
|
-
return _run(containerId, starField, options);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function startButterflies(containerId, options = {}) {
|
|
193
|
-
return _run(containerId, butterflies, options);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function startMagicDust(containerId, options = {}) {
|
|
197
|
-
return _run(containerId, magicDust, options);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function startFloatingOrbs(containerId, options = {}) {
|
|
201
|
-
return _run(containerId, floatingOrbs, options);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export function startShootingStars(containerId, options = {}) {
|
|
205
|
-
return _run(containerId, shootingStars, options);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ─── Default export (convenient for UMD / CDN namespace) ──────────────────────
|
|
209
|
-
export default {
|
|
210
|
-
startFloatingHearts,
|
|
211
|
-
startHeartTrail,
|
|
212
|
-
startHeartBurst,
|
|
213
|
-
startSparkles,
|
|
214
|
-
startLoveRain,
|
|
215
|
-
startConfetti,
|
|
216
|
-
startFireworks,
|
|
217
|
-
startStarField,
|
|
218
|
-
startButterflies,
|
|
219
|
-
startMagicDust,
|
|
220
|
-
startFloatingOrbs,
|
|
221
|
-
startShootingStars,
|
|
222
|
-
stopAnimation,
|
|
223
|
-
stopAll,
|
|
224
|
-
};
|