Skip to content

Commit

Permalink
Format all files
Browse files Browse the repository at this point in the history
  • Loading branch information
woofers committed Jul 23, 2024
1 parent 33c61fd commit 45c4fb9
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 81 deletions.
6 changes: 6 additions & 0 deletions packages/react-wavify/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"singleQuote": true,
"semi": false,
"trailingComma" : "none"
}
34 changes: 17 additions & 17 deletions packages/react-wavify/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import React from "react";
import React from 'react'

type WaveOptions = {
height?: number;
amplitude?: number;
speed?: number;
points?: number;
};
height?: number
amplitude?: number
speed?: number
points?: number
}

type BaseProps = Omit<
React.SVGProps<SVGPathElement>,
"ref" | "height" | "width" | "points"
>;
'ref' | 'height' | 'width' | 'points'
>

type WaveProps = BaseProps &
WaveOptions & {
paused?: boolean;
fill?: string;
options?: WaveOptions;
ref?: string;
svgId?: string;
svgPathId?: string;
};
paused?: boolean
fill?: string
options?: WaveOptions
ref?: string
svgId?: string
svgPathId?: string
}

declare const Wave: React.FC<WaveProps>;
declare const Wave: React.FC<WaveProps>

export = Wave;
export = Wave
16 changes: 8 additions & 8 deletions packages/react-wavify/src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from "react";
import WaveBase from "./wave";
import React from 'react'
import WaveBase from './wave'

const defaults = {
fill: "#fff",
fill: '#fff',
paused: false,
height: 20,
amplitude: 20,
speed: 0.15,
points: 3,
};
points: 3
}

const Wave = ({ options, ...rest }) => (
<WaveBase {...Object.assign({}, defaults, options, rest)} />
);
)

if (__isDev__) {
Wave.displayName = "Wave";
Wave.displayName = 'Wave'
}

export default Wave;
export default Wave
100 changes: 50 additions & 50 deletions packages/react-wavify/src/wave.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
import React, { Component } from "react";
import React, { Component } from 'react'

class Wave extends Component {
constructor(props) {
super(props);
this._container = React.createRef();
this.state = { path: "" };
this._lastUpdate = 0;
this._elapsed = 0;
this._step = 0;
this._update = this._update.bind(this);
super(props)
this._container = React.createRef()
this.state = { path: '' }
this._lastUpdate = 0
this._elapsed = 0
this._step = 0
this._update = this._update.bind(this)
}

_calculateWavePoints() {
const points = [];
const points = []
for (let i = 0; i <= Math.max(this.props.points, 1); i++) {
const scale = 100;
const x = (i / this.props.points) * this._width();
const scale = 100
const x = (i / this.props.points) * this._width()
const seed =
(this._step + (i + (i % this.props.points))) * this.props.speed * scale;
const height = Math.sin(seed / scale) * this.props.amplitude;
const y = Math.sin(seed / scale) * height + this.props.height;
points.push({ x, y });
(this._step + (i + (i % this.props.points))) * this.props.speed * scale
const height = Math.sin(seed / scale) * this.props.amplitude
const y = Math.sin(seed / scale) * height + this.props.height
points.push({ x, y })
}
return points;
return points
}

_buildPath(points) {
let svg = `M ${points[0].x} ${points[0].y}`;
let svg = `M ${points[0].x} ${points[0].y}`
const initial = {
x: (points[1].x - points[0].x) / 2,
y: points[1].y - points[0].y + points[0].y + (points[1].y - points[0].y),
};
const cubic = (a, b) => ` C ${a.x} ${a.y} ${a.x} ${a.y} ${b.x} ${b.y}`;
svg += cubic(initial, points[1]);
let point = initial;
y: points[1].y - points[0].y + points[0].y + (points[1].y - points[0].y)
}
const cubic = (a, b) => ` C ${a.x} ${a.y} ${a.x} ${a.y} ${b.x} ${b.y}`
svg += cubic(initial, points[1])
let point = initial
for (let i = 1; i < points.length - 1; i++) {
point = {
x: points[i].x - point.x + points[i].x,
y: points[i].y - point.y + points[i].y,
};
svg += cubic(point, points[i + 1]);
y: points[i].y - point.y + points[i].y
}
svg += cubic(point, points[i + 1])
}
svg += ` L ${this._width()} ${this._height()}`;
svg += ` L 0 ${this._height()} Z`;
return svg;
svg += ` L ${this._width()} ${this._height()}`
svg += ` L 0 ${this._height()} Z`
return svg
}

_width = () => this._container.current.offsetWidth;
_height = () => this._container.current.offsetHeight;
_width = () => this._container.current.offsetWidth
_height = () => this._container.current.offsetHeight

_redraw() {
this.setState({
path: this._buildPath(this._calculateWavePoints()),
});
path: this._buildPath(this._calculateWavePoints())
})
}

_draw() {
if (!this.props.paused) {
const now = new Date();
this._elapsed += now - this._lastUpdate;
this._lastUpdate = now;
const now = new Date()
this._elapsed += now - this._lastUpdate
this._lastUpdate = now
}
const scale = 1000;
this._step = (this._elapsed * Math.PI) / scale;
this._redraw();
const scale = 1000
this._step = (this._elapsed * Math.PI) / scale
this._redraw()
}

_update() {
this._draw();
this._draw()
if (this._frameId) {
this._resume();
this._resume()
}
}

_resume() {
this._frameId = window.requestAnimationFrame(this._update);
this._lastUpdate = new Date();
this._frameId = window.requestAnimationFrame(this._update)
this._lastUpdate = new Date()
}

componentDidMount() {
if (!this._frameId) {
this._resume();
this._resume()
}
}

componentWillUnmount() {
window.cancelAnimationFrame(this._frameId);
this._frameId = 0;
window.cancelAnimationFrame(this._frameId)
this._frameId = 0
}

render() {
Expand All @@ -106,10 +106,10 @@ class Wave extends Component {
speed,
points,
...rest
} = this.props;
} = this.props
return (
<div
style={{ width: "100%", display: "inline-block", ...style }}
style={{ width: '100%', display: 'inline-block', ...style }}
className={className}
id={id}
ref={this._container}
Expand All @@ -126,13 +126,13 @@ class Wave extends Component {
{...Object.assign(
{},
{ d: this.state.path, fill, id: svgPathId },
rest,
rest
)}
/>
</svg>
</div>
);
)
}
}

export default Wave;
export default Wave
1 change: 0 additions & 1 deletion packages/website/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './global.css'
import { Quicksand } from 'next/font/google'


const quicksand = Quicksand({
subsets: ['latin'],
weight: ['700'],
Expand Down
19 changes: 15 additions & 4 deletions packages/website/src/components/pause.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ type PauseProps = {
className?: string
}

const Pause: React.FC<PauseProps> = ({ paused, onClick, className, ...rest }) => {
const Pause: React.FC<PauseProps> = ({
paused,
onClick,
className,
...rest
}) => {
const handleClick = () => {
onClick()
}
Expand All @@ -26,13 +31,19 @@ const Pause: React.FC<PauseProps> = ({ paused, onClick, className, ...rest }) =>
onMouseUp={handleClick}
title={label}
aria-label={label}
className={clsx("text-[75px] border-0 text-[var(--color-primary)] bg-transparent [-webkit-tap-highlight-color:rgba(0,0,0,0)] hover:text-[var(--color-primaryHover)]", className)}
className={clsx(
'text-[75px] border-0 text-[var(--color-primary)] bg-transparent [-webkit-tap-highlight-color:rgba(0,0,0,0)] hover:text-[var(--color-primaryHover)]',
className
)}
{...rest}
>
{paused ? <PlayIcon className="w-[66px]" /> : <PauseIcon className="w-[66px]" />}
{paused ? (
<PlayIcon className="w-[66px]" />
) : (
<PauseIcon className="w-[66px]" />
)}
</button>
)
}

export default Pause

1 change: 0 additions & 1 deletion packages/website/src/components/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import Wave from 'components/wave'
import clsx from 'clsx'


const Center: React.FC<React.ComponentProps<'div'>> = ({
className,
...rest
Expand Down

0 comments on commit 45c4fb9

Please sign in to comment.