@basmilius/sparkle 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2024 Bas Milius
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 ADDED
@@ -0,0 +1,49 @@
1
+ <a href="https://bas.dev" target="_blank" rel="noopener">
2
+ <img src="https://bmcdn.nl/assets/branding/logo.svg" alt="Bas Milius Logo" height="60" width="60" />
3
+ </a>
4
+
5
+ ---
6
+
7
+ # Sparkle
8
+
9
+ Canvas-based visual effects library for the web. Includes fireworks, confetti and snow simulations.
10
+
11
+ ### Install
12
+
13
+ ```bash
14
+ bun add @basmilius/sparkle
15
+ ```
16
+ ```bash
17
+ npm install @basmilius/sparkle
18
+ ```
19
+ ```bash
20
+ pnpm add @basmilius/sparkle
21
+ ```
22
+
23
+ ### Quick Start
24
+
25
+ ```typescript
26
+ import { FireworkSimulation, ConfettiSimulation, SnowSimulation } from '@basmilius/sparkle';
27
+
28
+ const canvas = document.getElementById('canvas') as HTMLCanvasElement;
29
+
30
+ // Fireworks
31
+ const fireworks = new FireworkSimulation(canvas);
32
+ fireworks.start();
33
+
34
+ // Confetti
35
+ const confetti = new ConfettiSimulation(canvas);
36
+ confetti.fire({ angle: 90, spread: 60, particles: 150, startVelocity: 45, x: 0.5, y: 0.5 });
37
+
38
+ // Snow
39
+ const snow = new SnowSimulation(canvas);
40
+ snow.start();
41
+ ```
42
+
43
+ ### Documentation
44
+
45
+ Visit the [documentation site](https://sparkle.graphics) for guides, examples and the full API reference.
46
+
47
+ ### License
48
+
49
+ MIT
@@ -0,0 +1,98 @@
1
+ //#region src/canvas.d.ts
2
+ declare class LimitedFrameRateCanvas {
3
+ #private;
4
+ get canvas(): HTMLCanvasElement;
5
+ get context(): CanvasRenderingContext2D;
6
+ get delta(): number;
7
+ get deltaFactor(): number;
8
+ get frameRate(): number;
9
+ get isSmall(): boolean;
10
+ get isTicking(): boolean;
11
+ get ticks(): number;
12
+ get height(): number;
13
+ get width(): number;
14
+ constructor(canvas: HTMLCanvasElement, frameRate: number, options?: CanvasRenderingContext2DSettings);
15
+ loop(): void;
16
+ start(): void;
17
+ stop(): void;
18
+ draw(): void;
19
+ tick(): void;
20
+ destroy(): void;
21
+ onResize(): void;
22
+ onVisibilityChange(): void;
23
+ }
24
+ //#endregion
25
+ //#region src/confetti/types.d.ts
26
+ type Config = {
27
+ readonly angle: number;
28
+ readonly colors: string[];
29
+ readonly decay: number;
30
+ readonly gravity: number;
31
+ readonly particles: number;
32
+ readonly shapes: Shape[];
33
+ readonly spread: number;
34
+ readonly ticks: number;
35
+ readonly startVelocity: number;
36
+ readonly x: number;
37
+ readonly y: number;
38
+ };
39
+ type Shape = "circle" | "diamond" | "ribbon" | "square" | "star" | "triangle";
40
+ //#endregion
41
+ //#region src/confetti/simulation.d.ts
42
+ interface ConfettiSimulationConfig {
43
+ readonly scale?: number;
44
+ readonly canvasOptions?: CanvasRenderingContext2DSettings;
45
+ }
46
+ declare class ConfettiSimulation extends LimitedFrameRateCanvas {
47
+ #private;
48
+ constructor(canvas: HTMLCanvasElement, config?: ConfettiSimulationConfig);
49
+ fire(config: Partial<Config>): void;
50
+ draw(): void;
51
+ tick(): void;
52
+ onResize(): void;
53
+ }
54
+ //#endregion
55
+ //#region src/point.d.ts
56
+ type Point = {
57
+ x: number;
58
+ y: number;
59
+ };
60
+ //#endregion
61
+ //#region src/fireworks/types.d.ts
62
+ type ExplosionType = "peony" | "chrysanthemum" | "willow" | "ring" | "palm" | "crackle" | "crossette" | "dahlia" | "brocade" | "horsetail" | "strobe" | "heart" | "spiral" | "flower";
63
+ type FireworkVariant = ExplosionType | "saturn" | "concentric";
64
+ type ParticleShape = "line" | "circle" | "star" | "diamond";
65
+ interface FireworkSimulationConfig {
66
+ readonly scale?: number;
67
+ readonly autoSpawn?: boolean;
68
+ readonly canvasOptions?: CanvasRenderingContext2DSettings;
69
+ }
70
+ declare const FIREWORK_VARIANTS: FireworkVariant[];
71
+ //#endregion
72
+ //#region src/fireworks/simulation.d.ts
73
+ declare class FireworkSimulation extends LimitedFrameRateCanvas {
74
+ #private;
75
+ constructor(canvas: HTMLCanvasElement, config?: FireworkSimulationConfig);
76
+ draw(): void;
77
+ fireExplosion(variant: FireworkVariant, position?: Point): void;
78
+ tick(): void;
79
+ }
80
+ //#endregion
81
+ //#region src/snow/simulation.d.ts
82
+ interface SnowSimulationConfig {
83
+ readonly fillStyle?: string;
84
+ readonly particles?: number;
85
+ readonly scale?: number;
86
+ readonly size?: number;
87
+ readonly speed?: number;
88
+ readonly canvasOptions?: CanvasRenderingContext2DSettings;
89
+ }
90
+ declare class SnowSimulation extends LimitedFrameRateCanvas {
91
+ #private;
92
+ constructor(canvas: HTMLCanvasElement, config?: SnowSimulationConfig);
93
+ draw(): void;
94
+ tick(): void;
95
+ }
96
+ //#endregion
97
+ export { ConfettiSimulation, ConfettiSimulationConfig, ExplosionType, FIREWORK_VARIANTS, FireworkSimulation, FireworkSimulationConfig, FireworkVariant, LimitedFrameRateCanvas, ParticleShape, SnowSimulation, SnowSimulationConfig };
98
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/canvas.ts","../src/confetti/types.ts","../src/confetti/simulation.ts","../src/point.ts","../src/fireworks/types.ts","../src/fireworks/simulation.ts","../src/snow/simulation.ts"],"mappings":";cAAa,sBAAA;EAAA;MAeL,MAAA,CAAA,GAAU,iBAAA;EAAA,IAIV,OAAA,CAAA,GAAW,wBAAA;EAAA,IAIX,KAAA,CAAA;EAAA,IAIA,WAAA,CAAA;EAAA,IAIA,SAAA,CAAA;EAAA,IAIA,OAAA,CAAA;EAAA,IAIA,SAAA,CAAA;EAAA,IAIA,KAAA,CAAA;EAAA,IAIA,MAAA,CAAA;EAAA,IAIA,KAAA,CAAA;EAIJ,WAAA,CAAY,MAAA,EAAQ,iBAAA,EAAmB,SAAA,UAAmB,OAAA,GAAS,gCAAA;EAanE,IAAA,CAAA;EAuBA,KAAA,CAAA;EAOA,IAAA,CAAA;EAKA,IAAA,CAAA;EAIA,IAAA,CAAA;EAIA,OAAA,CAAA;EAMA,QAAA,CAAA;EAMA,kBAAA,CAAA;AAAA;;;KC3HQ,MAAA;EAAA,SACC,KAAA;EAAA,SACA,MAAA;EAAA,SACA,KAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA;EAAA,SACA,MAAA,EAAQ,KAAA;EAAA,SACR,MAAA;EAAA,SACA,KAAA;EAAA,SACA,aAAA;EAAA,SACA,CAAA;EAAA,SACA,CAAA;AAAA;AAAA,KAyCD,KAAA;;;UCKK,wBAAA;EAAA,SACJ,KAAA;EAAA,SACA,aAAA,GAAgB,gCAAA;AAAA;AAAA,cAGhB,kBAAA,SAA2B,sBAAA;EAAA;EAKpC,WAAA,CAAY,MAAA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