@konfetti-js/solid 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 +21 -0
- package/README.md +31 -0
- package/dist/index.cjs +84 -0
- package/dist/index.d.cts +71 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +67 -0
- package/package.json +66 -0
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,31 @@
|
|
|
1
|
+
# @konfetti-js/solid
|
|
2
|
+
|
|
3
|
+
Solid hook and component for [konfetti.js](https://andreabettich.github.io/konfetti.js/). Installs `@konfetti-js/core` for you.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @konfetti-js/solid
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { createSignal } from 'solid-js';
|
|
11
|
+
import { useKonfetti, Konfetti } from '@konfetti-js/solid';
|
|
12
|
+
|
|
13
|
+
function SaveButton() {
|
|
14
|
+
const { cannon } = useKonfetti();
|
|
15
|
+
return <button onClick={() => cannon()}>Save</button>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function Celebration() {
|
|
19
|
+
const [done, setDone] = createSignal(false);
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
<button onClick={() => setDone(true)}>Finish</button>
|
|
23
|
+
<Konfetti fire={done()} preset="fireworks" onFired={() => setDone(false)} />
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
See the [full documentation](https://github.com/andreabettich/konfetti.js#readme).
|
|
30
|
+
|
|
31
|
+
MIT licensed.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
Konfetti: () => Konfetti,
|
|
24
|
+
useKonfetti: () => useKonfetti
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/Konfetti.tsx
|
|
29
|
+
var import_core = require("@konfetti-js/core");
|
|
30
|
+
var import_solid_js = require("solid-js");
|
|
31
|
+
function Konfetti(props) {
|
|
32
|
+
(0, import_solid_js.createEffect)(
|
|
33
|
+
(0, import_solid_js.on)(
|
|
34
|
+
() => props.fire,
|
|
35
|
+
(shouldFire) => {
|
|
36
|
+
if (!shouldFire) return;
|
|
37
|
+
const { fire: _fire, preset, onFired, ...options } = props;
|
|
38
|
+
if (preset) {
|
|
39
|
+
(0, import_core.firePreset)(preset, options);
|
|
40
|
+
} else {
|
|
41
|
+
(0, import_core.fire)(options);
|
|
42
|
+
}
|
|
43
|
+
onFired?.();
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/useKonfetti.ts
|
|
51
|
+
var import_core2 = require("@konfetti-js/core");
|
|
52
|
+
var import_solid_js2 = require("solid-js");
|
|
53
|
+
function useKonfetti() {
|
|
54
|
+
let stop = null;
|
|
55
|
+
const stopStream = () => {
|
|
56
|
+
stop?.();
|
|
57
|
+
stop = null;
|
|
58
|
+
};
|
|
59
|
+
if ((0, import_solid_js2.getOwner)()) (0, import_solid_js2.onCleanup)(stopStream);
|
|
60
|
+
return {
|
|
61
|
+
fire: import_core2.fire,
|
|
62
|
+
cannon: import_core2.cannon,
|
|
63
|
+
explosion: import_core2.explosion,
|
|
64
|
+
fireworks: import_core2.fireworks,
|
|
65
|
+
rain: import_core2.rain,
|
|
66
|
+
snow: import_core2.snow,
|
|
67
|
+
sideCannons: import_core2.sideCannons,
|
|
68
|
+
pride: import_core2.pride,
|
|
69
|
+
continuous: (options, interval) => {
|
|
70
|
+
stopStream();
|
|
71
|
+
stop = (0, import_core2.continuous)(options, interval);
|
|
72
|
+
return stop;
|
|
73
|
+
},
|
|
74
|
+
reset: () => {
|
|
75
|
+
stopStream();
|
|
76
|
+
(0, import_core2.reset)();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
Konfetti,
|
|
83
|
+
useKonfetti
|
|
84
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { KonfettiOptions, PresetName } from '@konfetti-js/core';
|
|
2
|
+
|
|
3
|
+
interface KonfettiProps extends KonfettiOptions {
|
|
4
|
+
/** Fire when this turns true */
|
|
5
|
+
fire?: boolean;
|
|
6
|
+
/** Preset to fire; other props override the preset's values */
|
|
7
|
+
preset?: PresetName;
|
|
8
|
+
/** Called right after firing, for example to set your `fire` signal back to false */
|
|
9
|
+
onFired?: () => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Declarative Konfetti component for Solid.js. Fires once each time `fire` turns true.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function App() {
|
|
17
|
+
* const [celebrate, setCelebrate] = createSignal(false);
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <>
|
|
21
|
+
* <button onClick={() => setCelebrate(true)}>Celebrate!</button>
|
|
22
|
+
* <Konfetti fire={celebrate()} preset="fireworks" onFired={() => setCelebrate(false)} />
|
|
23
|
+
* </>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function Konfetti(props: KonfettiProps): null;
|
|
29
|
+
|
|
30
|
+
type FireFn = (options?: KonfettiOptions) => void;
|
|
31
|
+
interface UseKonfettiReturn {
|
|
32
|
+
/** Fire konfetti with optional options */
|
|
33
|
+
fire: FireFn;
|
|
34
|
+
/** Fire cannon preset */
|
|
35
|
+
cannon: FireFn;
|
|
36
|
+
/** Fire explosion preset */
|
|
37
|
+
explosion: FireFn;
|
|
38
|
+
/** Fire fireworks preset */
|
|
39
|
+
fireworks: FireFn;
|
|
40
|
+
/** Fire rain preset */
|
|
41
|
+
rain: FireFn;
|
|
42
|
+
/** Fire snow preset */
|
|
43
|
+
snow: FireFn;
|
|
44
|
+
/** Fire side cannons preset */
|
|
45
|
+
sideCannons: FireFn;
|
|
46
|
+
/** Fire pride preset */
|
|
47
|
+
pride: FireFn;
|
|
48
|
+
/** Start a stream (stopped automatically on cleanup); returns a stop function */
|
|
49
|
+
continuous: (options?: KonfettiOptions, interval?: number) => () => void;
|
|
50
|
+
/** Clear all konfetti and stop streams */
|
|
51
|
+
reset: () => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Solid.js hook for konfetti.js
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* function App() {
|
|
59
|
+
* const { fire, cannon } = useKonfetti();
|
|
60
|
+
*
|
|
61
|
+
* return (
|
|
62
|
+
* <button onClick={() => fire({ particleCount: 100 })}>
|
|
63
|
+
* Celebrate!
|
|
64
|
+
* </button>
|
|
65
|
+
* );
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function useKonfetti(): UseKonfettiReturn;
|
|
70
|
+
|
|
71
|
+
export { Konfetti, type KonfettiProps, type UseKonfettiReturn, useKonfetti };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { KonfettiOptions, PresetName } from '@konfetti-js/core';
|
|
2
|
+
|
|
3
|
+
interface KonfettiProps extends KonfettiOptions {
|
|
4
|
+
/** Fire when this turns true */
|
|
5
|
+
fire?: boolean;
|
|
6
|
+
/** Preset to fire; other props override the preset's values */
|
|
7
|
+
preset?: PresetName;
|
|
8
|
+
/** Called right after firing, for example to set your `fire` signal back to false */
|
|
9
|
+
onFired?: () => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Declarative Konfetti component for Solid.js. Fires once each time `fire` turns true.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* function App() {
|
|
17
|
+
* const [celebrate, setCelebrate] = createSignal(false);
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <>
|
|
21
|
+
* <button onClick={() => setCelebrate(true)}>Celebrate!</button>
|
|
22
|
+
* <Konfetti fire={celebrate()} preset="fireworks" onFired={() => setCelebrate(false)} />
|
|
23
|
+
* </>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function Konfetti(props: KonfettiProps): null;
|
|
29
|
+
|
|
30
|
+
type FireFn = (options?: KonfettiOptions) => void;
|
|
31
|
+
interface UseKonfettiReturn {
|
|
32
|
+
/** Fire konfetti with optional options */
|
|
33
|
+
fire: FireFn;
|
|
34
|
+
/** Fire cannon preset */
|
|
35
|
+
cannon: FireFn;
|
|
36
|
+
/** Fire explosion preset */
|
|
37
|
+
explosion: FireFn;
|
|
38
|
+
/** Fire fireworks preset */
|
|
39
|
+
fireworks: FireFn;
|
|
40
|
+
/** Fire rain preset */
|
|
41
|
+
rain: FireFn;
|
|
42
|
+
/** Fire snow preset */
|
|
43
|
+
snow: FireFn;
|
|
44
|
+
/** Fire side cannons preset */
|
|
45
|
+
sideCannons: FireFn;
|
|
46
|
+
/** Fire pride preset */
|
|
47
|
+
pride: FireFn;
|
|
48
|
+
/** Start a stream (stopped automatically on cleanup); returns a stop function */
|
|
49
|
+
continuous: (options?: KonfettiOptions, interval?: number) => () => void;
|
|
50
|
+
/** Clear all konfetti and stop streams */
|
|
51
|
+
reset: () => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Solid.js hook for konfetti.js
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* function App() {
|
|
59
|
+
* const { fire, cannon } = useKonfetti();
|
|
60
|
+
*
|
|
61
|
+
* return (
|
|
62
|
+
* <button onClick={() => fire({ particleCount: 100 })}>
|
|
63
|
+
* Celebrate!
|
|
64
|
+
* </button>
|
|
65
|
+
* );
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function useKonfetti(): UseKonfettiReturn;
|
|
70
|
+
|
|
71
|
+
export { Konfetti, type KonfettiProps, type UseKonfettiReturn, useKonfetti };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/Konfetti.tsx
|
|
2
|
+
import { fire, firePreset } from "@konfetti-js/core";
|
|
3
|
+
import { createEffect, on } from "solid-js";
|
|
4
|
+
function Konfetti(props) {
|
|
5
|
+
createEffect(
|
|
6
|
+
on(
|
|
7
|
+
() => props.fire,
|
|
8
|
+
(shouldFire) => {
|
|
9
|
+
if (!shouldFire) return;
|
|
10
|
+
const { fire: _fire, preset, onFired, ...options } = props;
|
|
11
|
+
if (preset) {
|
|
12
|
+
firePreset(preset, options);
|
|
13
|
+
} else {
|
|
14
|
+
fire(options);
|
|
15
|
+
}
|
|
16
|
+
onFired?.();
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/useKonfetti.ts
|
|
24
|
+
import {
|
|
25
|
+
cannon,
|
|
26
|
+
continuous as coreContinuous,
|
|
27
|
+
reset as coreReset,
|
|
28
|
+
explosion,
|
|
29
|
+
fire as fire2,
|
|
30
|
+
fireworks,
|
|
31
|
+
pride,
|
|
32
|
+
rain,
|
|
33
|
+
sideCannons,
|
|
34
|
+
snow
|
|
35
|
+
} from "@konfetti-js/core";
|
|
36
|
+
import { getOwner, onCleanup } from "solid-js";
|
|
37
|
+
function useKonfetti() {
|
|
38
|
+
let stop = null;
|
|
39
|
+
const stopStream = () => {
|
|
40
|
+
stop?.();
|
|
41
|
+
stop = null;
|
|
42
|
+
};
|
|
43
|
+
if (getOwner()) onCleanup(stopStream);
|
|
44
|
+
return {
|
|
45
|
+
fire: fire2,
|
|
46
|
+
cannon,
|
|
47
|
+
explosion,
|
|
48
|
+
fireworks,
|
|
49
|
+
rain,
|
|
50
|
+
snow,
|
|
51
|
+
sideCannons,
|
|
52
|
+
pride,
|
|
53
|
+
continuous: (options, interval) => {
|
|
54
|
+
stopStream();
|
|
55
|
+
stop = coreContinuous(options, interval);
|
|
56
|
+
return stop;
|
|
57
|
+
},
|
|
58
|
+
reset: () => {
|
|
59
|
+
stopStream();
|
|
60
|
+
coreReset();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
Konfetti,
|
|
66
|
+
useKonfetti
|
|
67
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@konfetti-js/solid",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Solid.js 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
|
+
"solid",
|
|
34
|
+
"solidjs",
|
|
35
|
+
"animation"
|
|
36
|
+
],
|
|
37
|
+
"author": "Andrea Bettich",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/andreabettich/konfetti.js.git",
|
|
42
|
+
"directory": "packages/solid"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://andreabettich.github.io/konfetti.js/",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/andreabettich/konfetti.js/issues"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@konfetti-js/core": "^0.3.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"solid-js": ">=1.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"solid-js": "^1.9.11",
|
|
56
|
+
"tsup": "^8.3.0",
|
|
57
|
+
"typescript": "^5.9.3"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"lint": "biome lint src",
|
|
64
|
+
"check": "biome check src --write"
|
|
65
|
+
}
|
|
66
|
+
}
|