micro-canvas-confetti-native 0.1.0 → 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.
Files changed (63) hide show
  1. package/README.md +158 -142
  2. package/lib/commonjs/api.js +3 -3
  3. package/lib/commonjs/api.js.map +1 -1
  4. package/lib/commonjs/coins.js.map +1 -1
  5. package/lib/commonjs/constants.js +6 -6
  6. package/lib/commonjs/constants.js.map +1 -1
  7. package/lib/commonjs/core.js.map +1 -1
  8. package/lib/commonjs/engine.js +3 -3
  9. package/lib/commonjs/engine.js.map +1 -1
  10. package/lib/commonjs/hooks/useReducedMotion.js +3 -3
  11. package/lib/commonjs/hooks/useReducedMotion.js.map +1 -1
  12. package/lib/commonjs/host/ParticleHost.js +3 -3
  13. package/lib/commonjs/host/ParticleHost.js.map +1 -1
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/physics/collect.js.map +1 -1
  16. package/lib/commonjs/physics/drag.js.map +1 -1
  17. package/lib/commonjs/physics/spawn.js.map +1 -1
  18. package/lib/commonjs/physics/wobble.js.map +1 -1
  19. package/lib/commonjs/sequence.js.map +1 -1
  20. package/lib/commonjs/types.js.map +1 -1
  21. package/lib/commonjs/utils/math.js.map +1 -1
  22. package/lib/commonjs/utils/validation.js +3 -3
  23. package/lib/commonjs/utils/validation.js.map +1 -1
  24. package/lib/module/api.js +3 -3
  25. package/lib/module/api.js.map +1 -1
  26. package/lib/module/coins.js.map +1 -1
  27. package/lib/module/constants.js +6 -6
  28. package/lib/module/constants.js.map +1 -1
  29. package/lib/module/core.js +3 -3
  30. package/lib/module/core.js.map +1 -1
  31. package/lib/module/engine.js +3 -3
  32. package/lib/module/engine.js.map +1 -1
  33. package/lib/module/hooks/useReducedMotion.js +3 -3
  34. package/lib/module/hooks/useReducedMotion.js.map +1 -1
  35. package/lib/module/host/ParticleHost.js +3 -3
  36. package/lib/module/host/ParticleHost.js.map +1 -1
  37. package/lib/module/index.js.map +1 -1
  38. package/lib/module/physics/collect.js.map +1 -1
  39. package/lib/module/physics/drag.js.map +1 -1
  40. package/lib/module/physics/spawn.js.map +1 -1
  41. package/lib/module/physics/wobble.js.map +1 -1
  42. package/lib/module/sequence.js.map +1 -1
  43. package/lib/module/types.js.map +1 -1
  44. package/lib/module/utils/math.js.map +1 -1
  45. package/lib/module/utils/validation.js +3 -3
  46. package/lib/module/utils/validation.js.map +1 -1
  47. package/package.json +118 -118
  48. package/src/api.ts +78 -78
  49. package/src/coins.ts +8 -8
  50. package/src/constants.ts +187 -187
  51. package/src/core.ts +18 -18
  52. package/src/engine.ts +354 -354
  53. package/src/hooks/useReducedMotion.ts +26 -26
  54. package/src/host/ParticleHost.tsx +181 -181
  55. package/src/index.ts +33 -33
  56. package/src/physics/collect.ts +100 -100
  57. package/src/physics/drag.ts +15 -15
  58. package/src/physics/spawn.ts +139 -139
  59. package/src/physics/wobble.ts +11 -11
  60. package/src/sequence.ts +39 -39
  61. package/src/types.ts +243 -243
  62. package/src/utils/math.ts +49 -49
  63. package/src/utils/validation.ts +203 -203
package/src/constants.ts CHANGED
@@ -1,187 +1,187 @@
1
- import type {
2
- CoinType,
3
- ConfettiDuration,
4
- ConfettiOptions,
5
- ConfettiPreset,
6
- ParticleShape,
7
- PhysicsConfig,
8
- } from "./types";
9
-
10
- export const DEFAULT_PARTICLE_COUNT = 60;
11
- export const DEFAULT_COIN_COUNT = 12;
12
- export const MIN_PARTICLE_COUNT = 1;
13
- /**
14
- * Safety ceilings. The caller chooses `particleCount`; each piece is a view,
15
- * so a high count costs more. Requests above these are clamped and warned.
16
- */
17
- export const MAX_CONFETTI_PIECES = 300;
18
- export const MAX_COIN_PIECES = 150;
19
-
20
- export const DEFAULT_ANGLE = 270;
21
- export const DEFAULT_SPREAD = 45;
22
- export const DEFAULT_START_VELOCITY = 45;
23
- export const DEFAULT_GRAVITY = 1.2;
24
- export const DEFAULT_DRAG = 0.08;
25
- export const DEFAULT_DECAY = 0;
26
- export const DEFAULT_SCALAR = 1;
27
- export const MIN_SCALAR = 0.2;
28
- export const MAX_SCALAR = 3;
29
-
30
- export const ROTATION_DRAG = 0.12;
31
- export const WOBBLE_DRAG = 0.1;
32
- export const MIN_FLATNESS = 0.15;
33
- export const SKEW_FACTOR = 0.3;
34
-
35
- export const CULL_MARGIN = 50;
36
- export const SETTLE_VELOCITY_THRESHOLD = 0.05;
37
- export const SETTLE_Y_OFFSET = 50;
38
-
39
- /**
40
- * The shared physics constants are tuned in small units; the host advances
41
- * the simulation this many seconds per real second so bursts read at phone scale.
42
- */
43
- export const SIMULATION_TIME_SCALE = 12;
44
- /** Longest frame step in seconds, so a dropped frame does not teleport pieces. */
45
- export const MAX_FRAME_SECONDS = 0.05;
46
- export const DEFAULT_FRAME_SECONDS = 1 / 60;
47
-
48
- /** No limit — pieces can travel anywhere on screen. */
49
- export const DEFAULT_BURST_RADIUS = 0;
50
- export const MAX_BURST_RADIUS = 5000;
51
-
52
- /** Lifespan in ticks when duration is set and ticks are not explicit. */
53
- export const DURATION_TICKS: Record<ConfettiDuration, number> = {
54
- short: 45,
55
- normal: 0,
56
- long: 220,
57
- };
58
-
59
- /** Default drag per duration preset. */
60
- export const DURATION_DRAG: Record<ConfettiDuration, number> = {
61
- short: 0.16,
62
- normal: DEFAULT_DRAG,
63
- long: 0.05,
64
- };
65
-
66
- /** Default size multiplier per duration preset. */
67
- export const DURATION_SCALAR: Record<ConfettiDuration, number> = {
68
- short: 0.55,
69
- normal: 1,
70
- long: 1.15,
71
- };
72
-
73
- export const DEFAULT_COLORS: readonly string[] = [
74
- "#FF2D55",
75
- "#FFCC00",
76
- "#34C759",
77
- "#007AFF",
78
- "#AF52DE",
79
- "#FF9500",
80
- "#5AC8FA",
81
- "#FF6B9D",
82
- ];
83
-
84
- export const CELEBRATION_COLORS = [
85
- "#FFD700",
86
- "#FF2D55",
87
- "#FF1493",
88
- "#00E5FF",
89
- "#39FF14",
90
- "#FF9500",
91
- "#BF5AF2",
92
- ] as const;
93
- export const SUBTLE_COLORS = ["#B8C5D6", "#D4A5A5", "#A8D8EA", "#C9B1FF"] as const;
94
- export const CANNON_COLORS = ["#FF4500", "#FFA500", "#FFFF00", "#FF2D55", "#FF6347"] as const;
95
- export const SPARK_COLORS = ["#FFFFFF", "#FFFACD", "#FFE4E1", "#E0FFFF"] as const;
96
-
97
- export const DEFAULT_SHAPES: readonly ParticleShape[] = ["rect", "circle"];
98
-
99
- /** Confetti piece size range in dp before `scalar`. */
100
- export const CONFETTI_WIDTH_RANGE = [6, 12] as const;
101
- export const CONFETTI_HEIGHT_RANGE = [4, 10] as const;
102
-
103
- export const COIN_TYPES: readonly CoinType[] = ["h-keystone"];
104
- export const DEFAULT_COIN_TYPE: CoinType = "h-keystone";
105
- /** Coin edge length in dp before `scalar`. */
106
- export const COIN_SIZE = 40;
107
- /** Coins spin in-plane slower than paper confetti. */
108
- export const COIN_ROTATION_FACTOR = 0.25;
109
-
110
- /** Collect flight: average ms per piece and the random spread around it. */
111
- export const DEFAULT_COLLECT_FLIGHT_MS = 900;
112
- export const COLLECT_FLIGHT_JITTER_MS = 200;
113
- export const DEFAULT_COLLECT_STAGGER_MS = 60;
114
- export const COLLECT_STAGGER_JITTER_MS = 20;
115
- export const MAX_COLLECT_FLIGHT_MS = 5000;
116
- export const MAX_COLLECT_STAGGER_MS = 1000;
117
- /** Scale at launch and at the target, relative to the piece size. */
118
- export const COLLECT_START_SCALE = 2.4;
119
- export const COLLECT_END_SCALE = 0.2;
120
- /** Fraction of the flight after which pieces fade out. */
121
- export const COLLECT_FADE_START = 0.85;
122
- /** Pieces start scattered this far (dp) around the origin. */
123
- export const COLLECT_ORIGIN_SCATTER = 24;
124
- /** How far the arc bows sideways, as a fraction of the flight distance. */
125
- export const COLLECT_ARC_BEND = 0.35;
126
- /** Coin spin speed in radians per second during a collect flight. */
127
- export const COLLECT_SPIN_RANGE = [6, 10] as const;
128
-
129
- /** Baseline simulation values used when options are resolved. */
130
- export const DEFAULT_PHYSICS: PhysicsConfig = {
131
- gravity: DEFAULT_GRAVITY,
132
- drag: DEFAULT_DRAG,
133
- rotationDrag: ROTATION_DRAG,
134
- wobbleDrag: WOBBLE_DRAG,
135
- minFlatness: MIN_FLATNESS,
136
- skewFactor: SKEW_FACTOR,
137
- decay: DEFAULT_DECAY,
138
- };
139
-
140
- /** Default option overrides for each named preset. */
141
- export const PRESET_OPTIONS: Record<ConfettiPreset, Partial<ConfettiOptions>> = {
142
- celebration: {
143
- particleCount: 150,
144
- startVelocity: 62,
145
- spread: 85,
146
- gravity: 0.9,
147
- duration: "normal",
148
- scalar: 1.15,
149
- colors: CELEBRATION_COLORS,
150
- shapes: ["rect", "circle"],
151
- },
152
- subtle: {
153
- particleCount: 14,
154
- startVelocity: 16,
155
- spread: 22,
156
- gravity: 0.55,
157
- duration: "short",
158
- scalar: 0.6,
159
- drag: 0.14,
160
- colors: SUBTLE_COLORS,
161
- shapes: ["circle"],
162
- },
163
- cannon: {
164
- particleCount: 55,
165
- startVelocity: 88,
166
- spread: 14,
167
- gravity: 2.2,
168
- duration: "short",
169
- scalar: 1,
170
- angle: 270,
171
- colors: CANNON_COLORS,
172
- shapes: ["rect"],
173
- },
174
- spark: {
175
- particleCount: 8,
176
- startVelocity: 22,
177
- spread: 360,
178
- gravity: 0.4,
179
- duration: "short",
180
- scalar: 0.45,
181
- drag: 0.2,
182
- decay: 0.08,
183
- burstRadius: 80,
184
- colors: SPARK_COLORS,
185
- shapes: ["circle"],
186
- },
187
- };
1
+ import type {
2
+ CoinType,
3
+ ConfettiDuration,
4
+ ConfettiOptions,
5
+ ConfettiPreset,
6
+ ParticleShape,
7
+ PhysicsConfig,
8
+ } from "./types";
9
+
10
+ export const DEFAULT_PARTICLE_COUNT = 60;
11
+ export const DEFAULT_COIN_COUNT = 12;
12
+ export const MIN_PARTICLE_COUNT = 1;
13
+ /**
14
+ * Safety ceilings. The caller chooses `particleCount`; each piece is a view,
15
+ * so a high count costs more. Requests above these are clamped and warned.
16
+ */
17
+ export const MAX_CONFETTI_PIECES = 300;
18
+ export const MAX_COIN_PIECES = 150;
19
+
20
+ export const DEFAULT_ANGLE = 270;
21
+ export const DEFAULT_SPREAD = 45;
22
+ export const DEFAULT_START_VELOCITY = 45;
23
+ export const DEFAULT_GRAVITY = 1.2;
24
+ export const DEFAULT_DRAG = 0.08;
25
+ export const DEFAULT_DECAY = 0;
26
+ export const DEFAULT_SCALAR = 1;
27
+ export const MIN_SCALAR = 0.2;
28
+ export const MAX_SCALAR = 3;
29
+
30
+ export const ROTATION_DRAG = 0.12;
31
+ export const WOBBLE_DRAG = 0.1;
32
+ export const MIN_FLATNESS = 0.15;
33
+ export const SKEW_FACTOR = 0.3;
34
+
35
+ export const CULL_MARGIN = 50;
36
+ export const SETTLE_VELOCITY_THRESHOLD = 0.05;
37
+ export const SETTLE_Y_OFFSET = 50;
38
+
39
+ /**
40
+ * The shared physics constants are tuned in small units; the host advances
41
+ * the simulation this many seconds per real second so bursts read at phone scale.
42
+ */
43
+ export const SIMULATION_TIME_SCALE = 12;
44
+ /** Longest frame step in seconds, so a dropped frame does not teleport pieces. */
45
+ export const MAX_FRAME_SECONDS = 0.05;
46
+ export const DEFAULT_FRAME_SECONDS = 1 / 60;
47
+
48
+ /** No limit — pieces can travel anywhere on screen. */
49
+ export const DEFAULT_BURST_RADIUS = 0;
50
+ export const MAX_BURST_RADIUS = 5000;
51
+
52
+ /** Lifespan in ticks when duration is set and ticks are not explicit. */
53
+ export const DURATION_TICKS: Record<ConfettiDuration, number> = {
54
+ short: 45,
55
+ normal: 0,
56
+ long: 220,
57
+ };
58
+
59
+ /** Default drag per duration preset. */
60
+ export const DURATION_DRAG: Record<ConfettiDuration, number> = {
61
+ short: 0.16,
62
+ normal: DEFAULT_DRAG,
63
+ long: 0.05,
64
+ };
65
+
66
+ /** Default size multiplier per duration preset. */
67
+ export const DURATION_SCALAR: Record<ConfettiDuration, number> = {
68
+ short: 0.55,
69
+ normal: 1,
70
+ long: 1.15,
71
+ };
72
+
73
+ export const DEFAULT_COLORS: readonly string[] = [
74
+ "#FF2D55",
75
+ "#FFCC00",
76
+ "#34C759",
77
+ "#007AFF",
78
+ "#AF52DE",
79
+ "#FF9500",
80
+ "#5AC8FA",
81
+ "#FF6B9D",
82
+ ];
83
+
84
+ export const CELEBRATION_COLORS = [
85
+ "#FFD700",
86
+ "#FF2D55",
87
+ "#FF1493",
88
+ "#00E5FF",
89
+ "#39FF14",
90
+ "#FF9500",
91
+ "#BF5AF2",
92
+ ] as const;
93
+ export const SUBTLE_COLORS = ["#B8C5D6", "#D4A5A5", "#A8D8EA", "#C9B1FF"] as const;
94
+ export const CANNON_COLORS = ["#FF4500", "#FFA500", "#FFFF00", "#FF2D55", "#FF6347"] as const;
95
+ export const SPARK_COLORS = ["#FFFFFF", "#FFFACD", "#FFE4E1", "#E0FFFF"] as const;
96
+
97
+ export const DEFAULT_SHAPES: readonly ParticleShape[] = ["rect", "circle"];
98
+
99
+ /** Confetti piece size range in dp before `scalar`. */
100
+ export const CONFETTI_WIDTH_RANGE = [6, 12] as const;
101
+ export const CONFETTI_HEIGHT_RANGE = [4, 10] as const;
102
+
103
+ export const COIN_TYPES: readonly CoinType[] = ["h-keystone"];
104
+ export const DEFAULT_COIN_TYPE: CoinType = "h-keystone";
105
+ /** Coin edge length in dp before `scalar`. */
106
+ export const COIN_SIZE = 40;
107
+ /** Coins spin in-plane slower than paper confetti. */
108
+ export const COIN_ROTATION_FACTOR = 0.25;
109
+
110
+ /** Collect flight: average ms per piece and the random spread around it. */
111
+ export const DEFAULT_COLLECT_FLIGHT_MS = 900;
112
+ export const COLLECT_FLIGHT_JITTER_MS = 200;
113
+ export const DEFAULT_COLLECT_STAGGER_MS = 60;
114
+ export const COLLECT_STAGGER_JITTER_MS = 20;
115
+ export const MAX_COLLECT_FLIGHT_MS = 5000;
116
+ export const MAX_COLLECT_STAGGER_MS = 1000;
117
+ /** Scale at launch and at the target, relative to the piece size. */
118
+ export const COLLECT_START_SCALE = 2.4;
119
+ export const COLLECT_END_SCALE = 0.2;
120
+ /** Fraction of the flight after which pieces fade out. */
121
+ export const COLLECT_FADE_START = 0.85;
122
+ /** Pieces start scattered this far (dp) around the origin. */
123
+ export const COLLECT_ORIGIN_SCATTER = 24;
124
+ /** How far the arc bows sideways, as a fraction of the flight distance. */
125
+ export const COLLECT_ARC_BEND = 0.35;
126
+ /** Coin spin speed in radians per second during a collect flight. */
127
+ export const COLLECT_SPIN_RANGE = [6, 10] as const;
128
+
129
+ /** Baseline simulation values used when options are resolved. */
130
+ export const DEFAULT_PHYSICS: PhysicsConfig = {
131
+ gravity: DEFAULT_GRAVITY,
132
+ drag: DEFAULT_DRAG,
133
+ rotationDrag: ROTATION_DRAG,
134
+ wobbleDrag: WOBBLE_DRAG,
135
+ minFlatness: MIN_FLATNESS,
136
+ skewFactor: SKEW_FACTOR,
137
+ decay: DEFAULT_DECAY,
138
+ };
139
+
140
+ /** Default option overrides for each named preset. */
141
+ export const PRESET_OPTIONS: Record<ConfettiPreset, Partial<ConfettiOptions>> = {
142
+ celebration: {
143
+ particleCount: 150,
144
+ startVelocity: 62,
145
+ spread: 85,
146
+ gravity: 0.9,
147
+ duration: "normal",
148
+ scalar: 1.15,
149
+ colors: CELEBRATION_COLORS,
150
+ shapes: ["rect", "circle"],
151
+ },
152
+ subtle: {
153
+ particleCount: 14,
154
+ startVelocity: 16,
155
+ spread: 22,
156
+ gravity: 0.55,
157
+ duration: "short",
158
+ scalar: 0.6,
159
+ drag: 0.14,
160
+ colors: SUBTLE_COLORS,
161
+ shapes: ["circle"],
162
+ },
163
+ cannon: {
164
+ particleCount: 55,
165
+ startVelocity: 88,
166
+ spread: 14,
167
+ gravity: 2.2,
168
+ duration: "short",
169
+ scalar: 1,
170
+ angle: 270,
171
+ colors: CANNON_COLORS,
172
+ shapes: ["rect"],
173
+ },
174
+ spark: {
175
+ particleCount: 8,
176
+ startVelocity: 22,
177
+ spread: 360,
178
+ gravity: 0.4,
179
+ duration: "short",
180
+ scalar: 0.45,
181
+ drag: 0.2,
182
+ decay: 0.08,
183
+ burstRadius: 80,
184
+ colors: SPARK_COLORS,
185
+ shapes: ["circle"],
186
+ },
187
+ };
package/src/core.ts CHANGED
@@ -1,18 +1,18 @@
1
- /**
2
- * React-Native-free subpath: spawn, integrate, collect, and validation.
3
- * Safe to import in tests, workers, or a custom renderer.
4
- */
5
- export {
6
- COIN_TYPES,
7
- DEFAULT_COIN_TYPE,
8
- DEFAULT_COLORS,
9
- DEFAULT_PHYSICS,
10
- PRESET_OPTIONS,
11
- SIMULATION_TIME_SCALE,
12
- } from "./constants";
13
- export { sampleCollectPiece,spawnCollectPieces } from "./physics/collect";
14
- export { applyDrag, applyDrag2D } from "./physics/drag";
15
- export { integrateParticle, isParticleDead, spawnParticles } from "./physics/spawn";
16
- export { computeSkewX, computeWobbleScale } from "./physics/wobble";
17
- export type * from "./types";
18
- export { parseCollectOptions, parseConfettiOptions, resolveCoinType } from "./utils/validation";
1
+ /**
2
+ * React-Native-free subpath: spawn, integrate, collect, and validation.
3
+ * Safe to import in tests, workers, or a custom renderer.
4
+ */
5
+ export {
6
+ COIN_TYPES,
7
+ DEFAULT_COIN_TYPE,
8
+ DEFAULT_COLORS,
9
+ DEFAULT_PHYSICS,
10
+ PRESET_OPTIONS,
11
+ SIMULATION_TIME_SCALE,
12
+ } from "./constants";
13
+ export { sampleCollectPiece,spawnCollectPieces } from "./physics/collect";
14
+ export { applyDrag, applyDrag2D } from "./physics/drag";
15
+ export { integrateParticle, isParticleDead, spawnParticles } from "./physics/spawn";
16
+ export { computeSkewX, computeWobbleScale } from "./physics/wobble";
17
+ export type * from "./types";
18
+ export { parseCollectOptions, parseConfettiOptions, resolveCoinType } from "./utils/validation";