Skip to content

Commit

Permalink
🔧 add eslint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
almond-bongbong committed Apr 17, 2023
1 parent f223e31 commit a8c8974
Show file tree
Hide file tree
Showing 11 changed files with 1,354 additions and 79 deletions.
3 changes: 2 additions & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Props {
effectInterval?: number;
effectCount?: number;
colors?: string[];
launchSpeed?: number;
}
declare function Confetti({ x, y, particleCount, deg, shapeSize, spreadDeg, effectInterval, effectCount, colors, }: Props): JSX.Element;
declare function Confetti({ x, y, particleCount, deg, shapeSize, spreadDeg, effectInterval, effectCount, colors, launchSpeed, }: Props): JSX.Element;
export default Confetti;
23 changes: 13 additions & 10 deletions lib/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.esm.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/js/Particle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare class Particle {
swingOffset: number;
swingSpeed: number;
swingAmplitude: number;
constructor(x: number, y: number, deg: number | undefined, colors: string[], shapes?: readonly ["circle", "square"], shapeSize?: number, spread?: number);
constructor(x: number, y: number, deg: number | undefined, colors: string[], shapes?: readonly ["circle", "square"], shapeSize?: number, spread?: number, launchSpeed?: number);
update(): void;
drawSquare(ctx: CanvasRenderingContext2D): void;
drawCircle(ctx: CanvasRenderingContext2D): void;
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
"@babel/core": "^7.21.3",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-eslint": "^9.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/react": "^18.0.28",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"eslint": "^8.38.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"postcss": "^8.4.21",
"prettier": "^2.8.4",
"react": "^18.2.0",
Expand Down
4 changes: 4 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import typescript from 'rollup-plugin-typescript2';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import babel from '@rollup/plugin-babel';
import eslint from '@rollup/plugin-eslint';

import packageJson from './package.json' assert { type: 'json' };

Expand All @@ -24,6 +25,9 @@ export default {
},
],
plugins: [
eslint({
include: ['src/**/*.ts', 'src/**/*.tsx'],
}),
peerDepsExternal(),
nodeResolve({ extensions }),
commonjs(),
Expand Down
69 changes: 20 additions & 49 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {
effectInterval?: number;
effectCount?: number;
colors?: string[];
launchSpeed?: number;
}

function Confetti({
Expand All @@ -27,6 +28,7 @@ function Confetti({
effectInterval = 3000,
effectCount = 1,
colors = ['#ff577f', '#ff884b', '#ffd384', '#fff9b0'],
launchSpeed = 1,
}: Props) {
const canvasRef = useRef<HTMLCanvasElement>(null);
const ctxRef = useRef<CanvasRenderingContext2D>();
Expand All @@ -51,33 +53,22 @@ function Confetti({
ctx.scale(DPR, DPR);
}, []);

const createConfetti = useCallback(
(options: {
x: number;
y: number;
particleCount: number;
deg: number;
shapeSize: number;
spreadDeg: number;
colors: string[];
shapes?: readonly ['circle', 'square'];
}) => {
for (let i = 0; i < options.particleCount; i += 1) {
particlesRef.current.push(
new Particle(
options.x,
options.y,
options.deg,
options.colors,
options.shapes,
options.shapeSize,
options.spreadDeg,
),
);
}
},
[],
);
const createConfetti = useCallback(() => {
for (let i = 0; i < particleCount; i += 1) {
particlesRef.current.push(
new Particle(
x,
y,
deg,
colors,
['circle', 'square'],
shapeSize,
spreadDeg,
launchSpeed,
),
);
}
}, [x, y, deg, colors, shapeSize, spreadDeg, launchSpeed, particleCount]);

const render = useCallback(() => {
if (!ctxRef.current) return;
Expand Down Expand Up @@ -105,15 +96,7 @@ function Confetti({
effectDelta > effectInterval &&
effectCountRef.current < effectCount
) {
createConfetti({
x,
y,
particleCount,
deg,
shapeSize,
spreadDeg,
colors,
});
createConfetti();
effectThen = now - (effectDelta % effectInterval);
effectCountRef.current += 1;
}
Expand All @@ -137,18 +120,7 @@ function Confetti({
};

animationFrameRef.current = requestAnimationFrame(frame);
}, [
x,
y,
particleCount,
deg,
effectInterval,
shapeSize,
effectCount,
spreadDeg,
colors,
createConfetti,
]);
}, [effectInterval, effectCount, createConfetti]);

useEffect(() => {
init();
Expand All @@ -163,7 +135,6 @@ function Confetti({

useEffect(() => {
effectCountRef.current = 0;
// render();
}, [effectCount]);

return <canvas className={styles.canvas} ref={canvasRef} />;
Expand Down
3 changes: 3 additions & 0 deletions src/js/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Particle {
shapes = ['circle', 'square'] as const,
shapeSize = 12,
spread = 30,
launchSpeed = 1,
) {
const DPR = window.devicePixelRatio > 1 ? 2 : 1;
this.x = x * window.innerWidth * DPR;
Expand All @@ -58,6 +59,8 @@ class Particle {
this.swingOffset = randomNumBetween(0, Math.PI * 2);
this.swingSpeed = Math.random() * 0.05 + 0.01;
this.swingAmplitude = randomNumBetween(0, 0.4);

console.log(launchSpeed);
}

update() {
Expand Down
Loading

0 comments on commit a8c8974

Please sign in to comment.