svelte-confetti-explosion 0.0.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,7 +57,7 @@ const isUndefined = (value) => typeof value === 'undefined';
57
57
  const error = (message) => {
58
58
  console.error(message);
59
59
  };
60
- function validate(particleCount, duration, colors, particleSize, force, floorHeight, floorWidth) {
60
+ function validate(particleCount, duration, colors, particleSize, force, stageHeight, stageWidth, particlesShape) {
61
61
  const isSafeInteger = Number.isSafeInteger;
62
62
  if (!isUndefined(particleCount) && isSafeInteger(particleCount) && particleCount < 0) {
63
63
  error('particleCount must be a positive integer');
@@ -67,6 +67,11 @@ function validate(particleCount, duration, colors, particleSize, force, floorHei
67
67
  error('duration must be a positive integer');
68
68
  return false;
69
69
  }
70
+ if (!isUndefined(particlesShape) &&
71
+ !['mix', 'circles', 'rectangles'].includes(particlesShape)) {
72
+ error('particlesShape should be either "mix" or "circles" or "rectangle"');
73
+ return false;
74
+ }
70
75
  if (!isUndefined(colors) && !Array.isArray(colors)) {
71
76
  error('colors must be an array of strings');
72
77
  return false;
@@ -79,17 +84,17 @@ function validate(particleCount, duration, colors, particleSize, force, floorHei
79
84
  error('force must be a positive integer and should be within 0 and 1');
80
85
  return false;
81
86
  }
82
- if (!isUndefined(floorHeight) &&
83
- typeof floorHeight === 'number' &&
84
- isSafeInteger(floorHeight) &&
85
- floorHeight < 0) {
87
+ if (!isUndefined(stageHeight) &&
88
+ typeof stageHeight === 'number' &&
89
+ isSafeInteger(stageHeight) &&
90
+ stageHeight < 0) {
86
91
  error('floorHeight must be a positive integer');
87
92
  return false;
88
93
  }
89
- if (!isUndefined(floorWidth) &&
90
- typeof floorWidth === 'number' &&
91
- isSafeInteger(floorWidth) &&
92
- floorWidth < 0) {
94
+ if (!isUndefined(stageWidth) &&
95
+ typeof stageWidth === 'number' &&
96
+ isSafeInteger(stageWidth) &&
97
+ stageWidth < 0) {
93
98
  error('floorWidth must be a positive integer');
94
99
  return false;
95
100
  }
@@ -134,6 +139,28 @@ export let particleSize = SIZE;
134
139
  * ```
135
140
  */
136
141
  export let duration = DURATION;
142
+ /**
143
+ * Shape of particles to use. Can be `mix`, `circles` or `rectangles`
144
+ *
145
+ * `mix` will use both circles and rectangles
146
+ * `circles` will use only circles
147
+ * `rectangles` will use only rectangles
148
+ *
149
+ * @default 'mix'
150
+ *
151
+ * @example
152
+ *
153
+ * ```svelte
154
+ * <ConfettiExplosion particlesShape='circles' />
155
+ * ```
156
+ *
157
+ * @example
158
+ *
159
+ * ```svelte
160
+ * <ConfettiExplosion particlesShape='rectangles' />
161
+ * ```
162
+ */
163
+ export let particlesShape = 'mix';
137
164
  /**
138
165
  * Colors to use for the confetti particles. Pass string array of colors. Can use hex colors, named colors,
139
166
  * CSS Variables, literally anything valid in plain CSS.
@@ -201,7 +228,7 @@ $: particles = createParticles(particleCount, colors);
201
228
  $: particleCount > 300 &&
202
229
  console.log("[SVELTE-CONFETTI-EXPLOSION] That's a lot of confetti, you sure about that? A lesser number" +
203
230
  ' like 200 will still give off the party vibes while still not bricking the device 😉');
204
- $: isValid = validate(particleCount, duration, colors, particleSize, force, stageHeight, stageWidth);
231
+ $: isValid = validate(particleCount, duration, colors, particleSize, force, stageHeight, stageWidth, particlesShape);
205
232
  onMount(async () => {
206
233
  await waitFor(duration);
207
234
  if (shouldDestroyAfterDone) {
@@ -216,7 +243,8 @@ function confettiStyles(node, { degree }) {
216
243
  const rotationIndex = Math.round(Math.random() * (rotationTransforms.length - 1));
217
244
  const durationChaos = duration - Math.round(Math.random() * 1000);
218
245
  const shouldBeCrazy = Math.random() < CRAZY_PARTICLES_FREQUENCY;
219
- const isCircle = shouldBeCircle(rotationIndex);
246
+ const isCircle = particlesShape !== 'rectangles' &&
247
+ (particlesShape === 'circles' || shouldBeCircle(rotationIndex));
220
248
  // x-axis disturbance, roughly the distance the particle will initially deviate from its target
221
249
  const x1 = shouldBeCrazy ? round(Math.random() * CRAZY_PARTICLE_CRAZINESS, 2) : 0;
222
250
  const x2 = x1 * -1;
@@ -281,6 +309,7 @@ function confettiStyles(node, { degree }) {
281
309
  height: 0;
282
310
  overflow: visible;
283
311
  position: relative;
312
+ transform: translate3d(var(--x, 0), var(--y, 0), 0);
284
313
  z-index: 1200;
285
314
  }
286
315
 
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ declare type ParticleShape = 'mix' | 'circles' | 'rectangles';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  /**
@@ -34,6 +35,27 @@ declare const __propDef: {
34
35
  * <ConfettiExplosion duration={5000} />
35
36
  * ```
36
37
  */ duration?: number;
38
+ /**
39
+ * Shape of particles to use. Can be `mix`, `circles` or `rectangles`
40
+ *
41
+ * `mix` will use both circles and rectangles
42
+ * `circles` will use only circles
43
+ * `rectangles` will use only rectangles
44
+ *
45
+ * @default 'mix'
46
+ *
47
+ * @example
48
+ *
49
+ * ```svelte
50
+ * <ConfettiExplosion particlesShape='circles' />
51
+ * ```
52
+ *
53
+ * @example
54
+ *
55
+ * ```svelte
56
+ * <ConfettiExplosion particlesShape='rectangles' />
57
+ * ```
58
+ */ particlesShape?: ParticleShape;
37
59
  /**
38
60
  * Colors to use for the confetti particles. Pass string array of colors. Can use hex colors, named colors,
39
61
  * CSS Variables, literally anything valid in plain CSS.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Puru Vijay
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 CHANGED
@@ -14,7 +14,7 @@ Let's party 🎊🎊 with Svelte! svelte-confetti-explosion allows you to show a
14
14
 
15
15
  [Try it in Svelte REPL](https://svelte.dev/repl/4e41a080739a4427a1f2c98b7f5d4b24?version=3.44.2)
16
16
 
17
- # Installing
17
+ ## Installing
18
18
 
19
19
  ```bash
20
20
  # pnpm
@@ -27,7 +27,7 @@ npm install svelte-confetti-explosion
27
27
  yarn add svelte-confetti-explosion
28
28
  ```
29
29
 
30
- # Usage
30
+ ## Usage
31
31
 
32
32
  Basic usage:
33
33
 
@@ -45,11 +45,11 @@ Customizing behavior with options:
45
45
  <ConfettiExplosion particleCount={200} force={0.3} />
46
46
  ```
47
47
 
48
- # Options
48
+ ## Props
49
49
 
50
50
  There's tons of options available for this package. All of them are already documented within the code itself, so you'll never have to leave the code editor.
51
51
 
52
- ## particleCount
52
+ ### particleCount
53
53
 
54
54
  Number of confetti particles to create.
55
55
 
@@ -63,7 +63,7 @@ Number of confetti particles to create.
63
63
  <ConfettiExplosion particleCount={200} />
64
64
  ```
65
65
 
66
- ## particleSize
66
+ ### particleSize
67
67
 
68
68
  Size of the confetti particles in pixels
69
69
 
@@ -77,7 +77,7 @@ Size of the confetti particles in pixels
77
77
  <ConfettiExplosion particleSize={20} />
78
78
  ```
79
79
 
80
- ## duration
80
+ ### duration
81
81
 
82
82
  Duration of the animation in milliseconds
83
83
 
@@ -91,7 +91,7 @@ Duration of the animation in milliseconds
91
91
  <ConfettiExplosion duration={5000} />
92
92
  ```
93
93
 
94
- ## colors
94
+ ### colors
95
95
 
96
96
  Colors to use for the confetti particles. Pass string array of colors. Can use hex colors, named colors, CSS Variables, literally anything valid in plain CSS.
97
97
 
@@ -105,7 +105,25 @@ Colors to use for the confetti particles. Pass string array of colors. Can use h
105
105
  <ConfettiExplosion colors={['var(--yellow)', 'var(--red)', '#2E3191', '#41BBC7']} />
106
106
  ```
107
107
 
108
- ## force
108
+ ### particlesShape
109
+
110
+ Shape of particles to use. Can be `mix`, `circles` or `rectangles`
111
+
112
+ `mix` will use both circles and rectangles
113
+ `circles` will use only circles
114
+ `rectangles` will use only rectangles
115
+
116
+ **type:** `'mix' | 'circles' | 'rectangles'`
117
+
118
+ **Default value:** `'mix'`
119
+
120
+ **Example:**
121
+
122
+ ```svelte
123
+ <ConfettiExplosion particlesShape="circles" />
124
+ ```
125
+
126
+ ### force
109
127
 
110
128
  Force of the confetti particles. Between 0 and 1. 0 is no force, 1 is maximum force. Will error out if you pass a value outside of this range.
111
129
 
@@ -119,7 +137,7 @@ Force of the confetti particles. Between 0 and 1. 0 is no force, 1 is maximum fo
119
137
  <ConfettiExplosion force={0.3} />
120
138
  ```
121
139
 
122
- ## stageHeight
140
+ ### stageHeight
123
141
 
124
142
  Height of the stage in pixels. Confetti will only fall within this height.
125
143
 
@@ -133,7 +151,7 @@ Height of the stage in pixels. Confetti will only fall within this height.
133
151
  <ConfettiExplosion stageHeight={500} />
134
152
  ```
135
153
 
136
- ## stageWidth
154
+ ### stageWidth
137
155
 
138
156
  Width of the stage in pixels. Confetti will only fall within this width.
139
157
 
@@ -147,7 +165,7 @@ Width of the stage in pixels. Confetti will only fall within this width.
147
165
  <ConfettiExplosion stageWidth={500} />
148
166
  ```
149
167
 
150
- ## shouldDestroyAfterDone
168
+ ### shouldDestroyAfterDone
151
169
 
152
170
  Whether or not destroy all confetti nodes after the `duration` period has passed. By default it destroys all nodes, to free up memory.
153
171
 
@@ -161,12 +179,33 @@ Whether or not destroy all confetti nodes after the `duration` period has passed
161
179
  <ConfettiExplosion shouldDestroyAfterDone={false} />
162
180
  ```
163
181
 
164
- # Performance
182
+ ## Style Props
183
+
184
+ You can specify two style props on the component: `--x` and `--y`. These will shift the confetti particles on the x and y axis. by how much you specify, These can be in `px`, `em`, `rem`, `vh`, `vw`, literally any valid CSS unit.
185
+
186
+ **USAGE:**
187
+
188
+ ```svelte
189
+ <ConfettiExplosion --x="10px" --y="10px" />
190
+ ```
191
+
192
+ ## Examples
193
+
194
+ [Basic Example](https://svelte.dev/repl/4e41a080739a4427a1f2c98b7f5d4b24?version=3.44.2)
195
+
196
+ [Confetti where mouse click](https://svelte.dev/repl/dbe0ab06c34f4f25aa6f948fdd1982c7?version=3.44.2)
197
+
198
+ ## Performance
165
199
 
166
200
  This library functions by creating 2 DOM nodes for every single confetti. By default, if the `particlesCount` is set to 150, it will create 300 nodes. This is a lot of nodes. For most devices, these many nodes are not a big issue, but I recommend checking your target devices' performance if you choose to go with a higher number, like 400 or 500.
167
201
 
168
202
  Also, after the specified `duration`, all the confetti DOM nodes will be destroyed. This is to free up memory. If you wish to keep them around, set `shouldDestroyAfterDone` to `false`.
169
203
 
170
- # License
204
+ ## License
171
205
 
172
206
  MIT License
207
+ © [Puru Vijay](https://twitter.com/puruvjdev)
208
+
209
+ ```
210
+
211
+ ```
package/package.json CHANGED
@@ -1,23 +1,31 @@
1
1
  {
2
2
  "name": "svelte-confetti-explosion",
3
- "version": "0.0.6",
4
- "svelte": "index.js",
5
- "devDependencies": {
6
- "@sveltejs/kit": "^1.0.0-next.197",
7
- "prettier": "^2.4.1",
8
- "prettier-plugin-svelte": "^2.5.0",
9
- "sass": "^1.43.4",
10
- "svelte": "^3.44.2",
11
- "svelte-check": "^2.2.10",
12
- "svelte-preprocess": "^4.9.8",
13
- "svelte2tsx": "^0.4.10",
14
- "tslib": "^2.3.1",
15
- "typescript": "^4.5.2"
3
+ "version": "0.2.0",
4
+ "description": "Confetti explosion in Svelte 🎉🎊",
5
+ "author": "Puru Vijay",
6
+ "license": "MIT",
7
+ "bugs": {
8
+ "url": "https://github.com/PuruVJ/svelte-confetti-explosion/issues"
16
9
  },
17
- "type": "module",
18
- "dependencies": {
19
- "svelte-confetti-explosion": "0.0.5"
10
+ "sideEffects": false,
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/PuruVJ/svelte-confetti-explosion.git"
20
14
  },
15
+ "svelte": "index.js",
16
+ "keywords": [
17
+ "confetti",
18
+ "party",
19
+ "fun",
20
+ "badass",
21
+ "badassery",
22
+ "svelte",
23
+ "sveltekit",
24
+ "small",
25
+ "tiny",
26
+ "performant"
27
+ ],
28
+ "type": "module",
21
29
  "exports": {
22
30
  "./package.json": "./package.json",
23
31
  "./ConfettiExplosion.svelte": "./ConfettiExplosion.svelte",