@konfetti-js/vue 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,26 @@
1
+ # @konfetti-js/vue
2
+
3
+ Vue composable and directive for [konfetti.js](https://andreabettich.github.io/konfetti.js/). Installs `@konfetti-js/core` for you.
4
+
5
+ ```bash
6
+ npm install @konfetti-js/vue
7
+ ```
8
+
9
+ ```vue
10
+ <script setup>
11
+ import { useKonfetti, vKonfetti } from '@konfetti-js/vue';
12
+
13
+ const { fire } = useKonfetti();
14
+ </script>
15
+
16
+ <template>
17
+ <button @click="fire({ particleCount: 100 })">Celebrate!</button>
18
+
19
+ <!-- Fires from the element on click; reacts to changes in the bound options -->
20
+ <button v-konfetti="{ preset: 'fireworks' }">Fireworks!</button>
21
+ </template>
22
+ ```
23
+
24
+ The directive also accepts `trigger` (default `'click'`) and every core option. See the [full documentation](https://github.com/andreabettich/konfetti.js#readme).
25
+
26
+ MIT licensed.
package/dist/index.cjs ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ useKonfetti: () => useKonfetti,
24
+ vKonfetti: () => vKonfetti
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/directive.ts
29
+ var import_core = require("@konfetti-js/core");
30
+ var states = /* @__PURE__ */ new WeakMap();
31
+ function bindTrigger(el, state) {
32
+ const trigger = state.options.trigger ?? "click";
33
+ if (trigger === state.trigger) return;
34
+ el.removeEventListener(state.trigger, state.handler);
35
+ el.addEventListener(trigger, state.handler);
36
+ state.trigger = trigger;
37
+ }
38
+ var vKonfetti = {
39
+ mounted(el, binding) {
40
+ const state = {
41
+ options: binding.value ?? {},
42
+ trigger: binding.value?.trigger ?? "click",
43
+ handler: () => {
44
+ const { trigger: _trigger, ...options } = state.options;
45
+ (0, import_core.fireFromElement)(el, options);
46
+ }
47
+ };
48
+ el.addEventListener(state.trigger, state.handler);
49
+ states.set(el, state);
50
+ },
51
+ updated(el, binding) {
52
+ const state = states.get(el);
53
+ if (!state) return;
54
+ state.options = binding.value ?? {};
55
+ bindTrigger(el, state);
56
+ },
57
+ unmounted(el) {
58
+ const state = states.get(el);
59
+ if (!state) return;
60
+ el.removeEventListener(state.trigger, state.handler);
61
+ states.delete(el);
62
+ }
63
+ };
64
+
65
+ // src/useKonfetti.ts
66
+ var import_core2 = require("@konfetti-js/core");
67
+ var import_vue = require("vue");
68
+ function useKonfetti() {
69
+ let stop = null;
70
+ const stopStream = () => {
71
+ stop?.();
72
+ stop = null;
73
+ };
74
+ if ((0, import_vue.getCurrentScope)()) (0, import_vue.onScopeDispose)(stopStream);
75
+ return {
76
+ fire: import_core2.fire,
77
+ cannon: import_core2.cannon,
78
+ explosion: import_core2.explosion,
79
+ fireworks: import_core2.fireworks,
80
+ rain: import_core2.rain,
81
+ snow: import_core2.snow,
82
+ sideCannons: import_core2.sideCannons,
83
+ pride: import_core2.pride,
84
+ continuous: (options, interval) => {
85
+ stopStream();
86
+ stop = (0, import_core2.continuous)(options, interval);
87
+ return stop;
88
+ },
89
+ reset: () => {
90
+ stopStream();
91
+ (0, import_core2.reset)();
92
+ }
93
+ };
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ useKonfetti,
98
+ vKonfetti
99
+ });
@@ -0,0 +1,73 @@
1
+ import { FireFromElementOptions, KonfettiOptions } from '@konfetti-js/core';
2
+ import { Directive } from 'vue';
3
+
4
+ interface KonfettiDirectiveOptions extends FireFromElementOptions {
5
+ /** Event to trigger konfetti (default: 'click') */
6
+ trigger?: string;
7
+ }
8
+ /**
9
+ * Vue directive for konfetti.js. Fires from the element on click (or `trigger`),
10
+ * and picks up changes to the bound options.
11
+ *
12
+ * @example
13
+ * ```vue
14
+ * <template>
15
+ * <!-- Basic usage -->
16
+ * <button v-konfetti>Click me!</button>
17
+ *
18
+ * <!-- With options -->
19
+ * <button v-konfetti="{ particleCount: 100, spread: 70 }">
20
+ * Celebrate!
21
+ * </button>
22
+ *
23
+ * <!-- With preset -->
24
+ * <button v-konfetti="{ preset: 'fireworks' }">
25
+ * Fireworks!
26
+ * </button>
27
+ * </template>
28
+ * ```
29
+ */
30
+ declare const vKonfetti: Directive<HTMLElement, KonfettiDirectiveOptions | undefined>;
31
+
32
+ type FireFn = (options?: KonfettiOptions) => void;
33
+ interface UseKonfettiReturn {
34
+ /** Fire konfetti with optional options */
35
+ fire: FireFn;
36
+ /** Fire cannon preset */
37
+ cannon: FireFn;
38
+ /** Fire explosion preset */
39
+ explosion: FireFn;
40
+ /** Fire fireworks preset */
41
+ fireworks: FireFn;
42
+ /** Fire rain preset */
43
+ rain: FireFn;
44
+ /** Fire snow preset */
45
+ snow: FireFn;
46
+ /** Fire side cannons preset */
47
+ sideCannons: FireFn;
48
+ /** Fire pride preset */
49
+ pride: FireFn;
50
+ /** Start a stream (stopped automatically on unmount); returns a stop function */
51
+ continuous: (options?: KonfettiOptions, interval?: number) => () => void;
52
+ /** Clear all konfetti and stop streams */
53
+ reset: () => void;
54
+ }
55
+ /**
56
+ * Vue composable for konfetti.js
57
+ *
58
+ * @example
59
+ * ```vue
60
+ * <script setup>
61
+ * import { useKonfetti } from '@konfetti-js/vue';
62
+ *
63
+ * const { fire, cannon } = useKonfetti();
64
+ * </script>
65
+ *
66
+ * <template>
67
+ * <button @click="fire({ particleCount: 100 })">Celebrate!</button>
68
+ * </template>
69
+ * ```
70
+ */
71
+ declare function useKonfetti(): UseKonfettiReturn;
72
+
73
+ export { type UseKonfettiReturn, useKonfetti, vKonfetti };
@@ -0,0 +1,73 @@
1
+ import { FireFromElementOptions, KonfettiOptions } from '@konfetti-js/core';
2
+ import { Directive } from 'vue';
3
+
4
+ interface KonfettiDirectiveOptions extends FireFromElementOptions {
5
+ /** Event to trigger konfetti (default: 'click') */
6
+ trigger?: string;
7
+ }
8
+ /**
9
+ * Vue directive for konfetti.js. Fires from the element on click (or `trigger`),
10
+ * and picks up changes to the bound options.
11
+ *
12
+ * @example
13
+ * ```vue
14
+ * <template>
15
+ * <!-- Basic usage -->
16
+ * <button v-konfetti>Click me!</button>
17
+ *
18
+ * <!-- With options -->
19
+ * <button v-konfetti="{ particleCount: 100, spread: 70 }">
20
+ * Celebrate!
21
+ * </button>
22
+ *
23
+ * <!-- With preset -->
24
+ * <button v-konfetti="{ preset: 'fireworks' }">
25
+ * Fireworks!
26
+ * </button>
27
+ * </template>
28
+ * ```
29
+ */
30
+ declare const vKonfetti: Directive<HTMLElement, KonfettiDirectiveOptions | undefined>;
31
+
32
+ type FireFn = (options?: KonfettiOptions) => void;
33
+ interface UseKonfettiReturn {
34
+ /** Fire konfetti with optional options */
35
+ fire: FireFn;
36
+ /** Fire cannon preset */
37
+ cannon: FireFn;
38
+ /** Fire explosion preset */
39
+ explosion: FireFn;
40
+ /** Fire fireworks preset */
41
+ fireworks: FireFn;
42
+ /** Fire rain preset */
43
+ rain: FireFn;
44
+ /** Fire snow preset */
45
+ snow: FireFn;
46
+ /** Fire side cannons preset */
47
+ sideCannons: FireFn;
48
+ /** Fire pride preset */
49
+ pride: FireFn;
50
+ /** Start a stream (stopped automatically on unmount); returns a stop function */
51
+ continuous: (options?: KonfettiOptions, interval?: number) => () => void;
52
+ /** Clear all konfetti and stop streams */
53
+ reset: () => void;
54
+ }
55
+ /**
56
+ * Vue composable for konfetti.js
57
+ *
58
+ * @example
59
+ * ```vue
60
+ * <script setup>
61
+ * import { useKonfetti } from '@konfetti-js/vue';
62
+ *
63
+ * const { fire, cannon } = useKonfetti();
64
+ * </script>
65
+ *
66
+ * <template>
67
+ * <button @click="fire({ particleCount: 100 })">Celebrate!</button>
68
+ * </template>
69
+ * ```
70
+ */
71
+ declare function useKonfetti(): UseKonfettiReturn;
72
+
73
+ export { type UseKonfettiReturn, useKonfetti, vKonfetti };
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ // src/directive.ts
2
+ import { fireFromElement } from "@konfetti-js/core";
3
+ var states = /* @__PURE__ */ new WeakMap();
4
+ function bindTrigger(el, state) {
5
+ const trigger = state.options.trigger ?? "click";
6
+ if (trigger === state.trigger) return;
7
+ el.removeEventListener(state.trigger, state.handler);
8
+ el.addEventListener(trigger, state.handler);
9
+ state.trigger = trigger;
10
+ }
11
+ var vKonfetti = {
12
+ mounted(el, binding) {
13
+ const state = {
14
+ options: binding.value ?? {},
15
+ trigger: binding.value?.trigger ?? "click",
16
+ handler: () => {
17
+ const { trigger: _trigger, ...options } = state.options;
18
+ fireFromElement(el, options);
19
+ }
20
+ };
21
+ el.addEventListener(state.trigger, state.handler);
22
+ states.set(el, state);
23
+ },
24
+ updated(el, binding) {
25
+ const state = states.get(el);
26
+ if (!state) return;
27
+ state.options = binding.value ?? {};
28
+ bindTrigger(el, state);
29
+ },
30
+ unmounted(el) {
31
+ const state = states.get(el);
32
+ if (!state) return;
33
+ el.removeEventListener(state.trigger, state.handler);
34
+ states.delete(el);
35
+ }
36
+ };
37
+
38
+ // src/useKonfetti.ts
39
+ import {
40
+ cannon,
41
+ continuous as coreContinuous,
42
+ reset as coreReset,
43
+ explosion,
44
+ fire,
45
+ fireworks,
46
+ pride,
47
+ rain,
48
+ sideCannons,
49
+ snow
50
+ } from "@konfetti-js/core";
51
+ import { getCurrentScope, onScopeDispose } from "vue";
52
+ function useKonfetti() {
53
+ let stop = null;
54
+ const stopStream = () => {
55
+ stop?.();
56
+ stop = null;
57
+ };
58
+ if (getCurrentScope()) onScopeDispose(stopStream);
59
+ return {
60
+ fire,
61
+ cannon,
62
+ explosion,
63
+ fireworks,
64
+ rain,
65
+ snow,
66
+ sideCannons,
67
+ pride,
68
+ continuous: (options, interval) => {
69
+ stopStream();
70
+ stop = coreContinuous(options, interval);
71
+ return stop;
72
+ },
73
+ reset: () => {
74
+ stopStream();
75
+ coreReset();
76
+ }
77
+ };
78
+ }
79
+ export {
80
+ useKonfetti,
81
+ vKonfetti
82
+ };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@konfetti-js/vue",
3
+ "version": "0.3.0",
4
+ "description": "Vue wrapper for konfetti.js",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "sideEffects": false,
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "provenance": true
29
+ },
30
+ "keywords": [
31
+ "konfetti",
32
+ "confetti",
33
+ "vue",
34
+ "animation"
35
+ ],
36
+ "author": "Andrea Bettich",
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/andreabettich/konfetti.js.git",
41
+ "directory": "packages/vue"
42
+ },
43
+ "homepage": "https://andreabettich.github.io/konfetti.js/",
44
+ "bugs": {
45
+ "url": "https://github.com/andreabettich/konfetti.js/issues"
46
+ },
47
+ "dependencies": {
48
+ "@konfetti-js/core": "^0.3.0"
49
+ },
50
+ "peerDependencies": {
51
+ "vue": ">=3.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "tsup": "^8.3.0",
55
+ "typescript": "^5.9.3",
56
+ "vue": "^3.5.27"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "dev": "tsup --watch",
61
+ "typecheck": "tsc --noEmit",
62
+ "lint": "biome lint src",
63
+ "check": "biome check src --write"
64
+ }
65
+ }