@konfetti-js/svelte 0.3.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) 2025 Andrea Bettich
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,24 @@
1
+ # @konfetti-js/svelte
2
+
3
+ Svelte action and helpers for [konfetti.js](https://andreabettich.github.io/konfetti.js/). Works with Svelte 4 and 5, and installs `@konfetti-js/core` for you.
4
+
5
+ ```bash
6
+ npm install @konfetti-js/svelte
7
+ ```
8
+
9
+ ```svelte
10
+ <script>
11
+ import { konfettiAction, createKonfetti } from '@konfetti-js/svelte';
12
+
13
+ const { fire } = createKonfetti();
14
+ </script>
15
+
16
+ <!-- Fires from the element on click -->
17
+ <button use:konfettiAction={{ preset: 'fireworks' }}>Fireworks!</button>
18
+
19
+ <button onclick={() => fire({ particleCount: 100 })}>Celebrate!</button>
20
+ ```
21
+
22
+ When `createKonfetti()` is called during component setup, its `continuous()` stream stops when the component is destroyed. See the [full documentation](https://github.com/andreabettich/konfetti.js#readme).
23
+
24
+ MIT licensed.
@@ -0,0 +1,75 @@
1
+ import { FireFromElementOptions, KonfettiOptions } from '@konfetti-js/core';
2
+ import { Action } from 'svelte/action';
3
+
4
+ interface KonfettiActionOptions extends FireFromElementOptions {
5
+ /** Event to trigger konfetti (default: 'click') */
6
+ trigger?: string;
7
+ }
8
+ /**
9
+ * Svelte action for konfetti.js. Fires from the element on click (or `trigger`).
10
+ *
11
+ * @example
12
+ * ```svelte
13
+ * <script>
14
+ * import { konfettiAction } from '@konfetti-js/svelte';
15
+ * </script>
16
+ *
17
+ * <!-- Basic usage -->
18
+ * <button use:konfettiAction>Click me!</button>
19
+ *
20
+ * <!-- With options -->
21
+ * <button use:konfettiAction={{ particleCount: 100, spread: 70 }}>
22
+ * Celebrate!
23
+ * </button>
24
+ *
25
+ * <!-- With preset -->
26
+ * <button use:konfettiAction={{ preset: 'fireworks' }}>
27
+ * Fireworks!
28
+ * </button>
29
+ * ```
30
+ */
31
+ declare const konfettiAction: Action<HTMLElement, KonfettiActionOptions | undefined>;
32
+
33
+ type FireFn = (options?: KonfettiOptions) => void;
34
+ interface KonfettiStore {
35
+ /** Fire konfetti with optional options */
36
+ fire: FireFn;
37
+ /** Fire cannon preset */
38
+ cannon: FireFn;
39
+ /** Fire explosion preset */
40
+ explosion: FireFn;
41
+ /** Fire fireworks preset */
42
+ fireworks: FireFn;
43
+ /** Fire rain preset */
44
+ rain: FireFn;
45
+ /** Fire snow preset */
46
+ snow: FireFn;
47
+ /** Fire side cannons preset */
48
+ sideCannons: FireFn;
49
+ /** Fire pride preset */
50
+ pride: FireFn;
51
+ /** Start a stream (stopped automatically on destroy); returns a stop function */
52
+ continuous: (options?: KonfettiOptions, interval?: number) => () => void;
53
+ /** Clear all konfetti and stop streams */
54
+ reset: () => void;
55
+ }
56
+ /**
57
+ * Create konfetti controls for Svelte. When called while a component
58
+ * initializes, its stream stops automatically when the component is destroyed.
59
+ *
60
+ * @example
61
+ * ```svelte
62
+ * <script>
63
+ * import { createKonfetti } from '@konfetti-js/svelte';
64
+ *
65
+ * const konfetti = createKonfetti();
66
+ * </script>
67
+ *
68
+ * <button onclick={() => konfetti.fire({ particleCount: 100 })}>
69
+ * Celebrate!
70
+ * </button>
71
+ * ```
72
+ */
73
+ declare function createKonfetti(): KonfettiStore;
74
+
75
+ export { type KonfettiActionOptions, type KonfettiStore, createKonfetti, konfettiAction };
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ // src/action.ts
2
+ import { fireFromElement } from "@konfetti-js/core";
3
+ var konfettiAction = (node, initialOptions = {}) => {
4
+ let current = initialOptions;
5
+ let trigger = current.trigger ?? "click";
6
+ const handler = () => {
7
+ const { trigger: _trigger, ...options } = current;
8
+ fireFromElement(node, options);
9
+ };
10
+ node.addEventListener(trigger, handler);
11
+ return {
12
+ update(nextOptions = {}) {
13
+ current = nextOptions;
14
+ const nextTrigger = nextOptions.trigger ?? "click";
15
+ if (nextTrigger !== trigger) {
16
+ node.removeEventListener(trigger, handler);
17
+ node.addEventListener(nextTrigger, handler);
18
+ trigger = nextTrigger;
19
+ }
20
+ },
21
+ destroy() {
22
+ node.removeEventListener(trigger, handler);
23
+ }
24
+ };
25
+ };
26
+
27
+ // src/createKonfetti.ts
28
+ import {
29
+ cannon,
30
+ continuous as coreContinuous,
31
+ reset as coreReset,
32
+ explosion,
33
+ fire,
34
+ fireworks,
35
+ pride,
36
+ rain,
37
+ sideCannons,
38
+ snow
39
+ } from "@konfetti-js/core";
40
+ import { onDestroy } from "svelte";
41
+ function createKonfetti() {
42
+ let stop = null;
43
+ const stopStream = () => {
44
+ stop?.();
45
+ stop = null;
46
+ };
47
+ try {
48
+ onDestroy(stopStream);
49
+ } catch {
50
+ }
51
+ return {
52
+ fire,
53
+ cannon,
54
+ explosion,
55
+ fireworks,
56
+ rain,
57
+ snow,
58
+ sideCannons,
59
+ pride,
60
+ continuous: (options, interval) => {
61
+ stopStream();
62
+ stop = coreContinuous(options, interval);
63
+ return stop;
64
+ },
65
+ reset: () => {
66
+ stopStream();
67
+ coreReset();
68
+ }
69
+ };
70
+ }
71
+ export {
72
+ createKonfetti,
73
+ konfettiAction
74
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@konfetti-js/svelte",
3
+ "version": "0.3.0",
4
+ "description": "Svelte wrapper for konfetti.js",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "provenance": true
23
+ },
24
+ "keywords": [
25
+ "konfetti",
26
+ "confetti",
27
+ "svelte",
28
+ "animation"
29
+ ],
30
+ "author": "Andrea Bettich",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/andreabettich/konfetti.js.git",
35
+ "directory": "packages/svelte"
36
+ },
37
+ "homepage": "https://andreabettich.github.io/konfetti.js/",
38
+ "bugs": {
39
+ "url": "https://github.com/andreabettich/konfetti.js/issues"
40
+ },
41
+ "dependencies": {
42
+ "@konfetti-js/core": "^0.3.0"
43
+ },
44
+ "peerDependencies": {
45
+ "svelte": ">=4.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "svelte": "^5.55.7",
49
+ "tsup": "^8.3.0",
50
+ "typescript": "^5.9.3"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup",
54
+ "dev": "tsup --watch",
55
+ "typecheck": "tsc --noEmit",
56
+ "lint": "biome lint src",
57
+ "check": "biome check src --write"
58
+ }
59
+ }