Skip to content

Commit

Permalink
feat(animations) : rightspeed animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutesa-Cedric committed Sep 26, 2023
1 parent cc4cf01 commit 3ec50bf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
61 changes: 61 additions & 0 deletions src/animations/complex/RightSpeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable no-prototype-builtins */
import wrapper from '@/HOC/wrapper'
import { animation, defaults } from '@/lib/defaultConfigs'

const lookup = {}

function make(reverse, { left, right, mirror, opposite }) {
const checksum = (left ? 1 : 0) | (right ? 2 : 0) | (mirror ? 16 : 0) | (opposite ? 32 : 0) | (reverse ? 64 : 0)

Check failure on line 8 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
if (lookup.hasOwnProperty(checksum))

Check failure on line 9 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
return lookup[checksum]

Check failure on line 10 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 8
if (!mirror !== !(reverse && opposite)) // Boolean XOR

Check failure on line 11 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
[left, right] = [right, left]

Check failure on line 12 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 8
const dist = '100%'

Check failure on line 13 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
const x = left ? `-${dist}` : (right ? dist : '0')

Check failure on line 14 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
const rule = !reverse

Check failure on line 15 in src/animations/complex/RightSpeed.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
? `from {
transform: translate3d(${x}, 0, 0) skewX(-30deg);
opacity: 0;
}
60% {
transform: skewX(20deg);
opacity: 1;
}
80% {
transform: skewX(-5deg);
opacity: 1;
}
to {
transform: none;
opacity: 1;
}`
: `from {
opacity: 1;
}
to {
transform: translate3d(${x}, 0, 0) skewX(30deg);
opacity: 0;
}
`
lookup[checksum] = animation(rule)
return lookup[checksum]
}

function LightSpeed({
children, _out, forever,
timeout, duration = defaults.duration, delay = defaults.delay, count = defaults.count, ...props
} = defaults) {
const effect = {
make,
duration: timeout === undefined ? duration : timeout,
delay,
forever,
count,
style: { animationFillMode: 'both' },
}
const _checksum = 0 + (props.left ? 1 : 0) + (props.right ? 10 : 0) + (props.mirror ? 10000 : 0) + (props.opposite ? 100000 : 0);
// @ts-expect-error(some props are not allowed, this will be fixed later)
return wrapper(props, effect, effect, children)
}

export default LightSpeed
7 changes: 6 additions & 1 deletion src/animations/complex/Rotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import wrapper from '@/HOC/wrapper'
import { animation, defaults } from '@/lib/defaultConfigs'

// lookup table
const lookup = {}
function make(reverse, { left, right, up, down, top, bottom, mirror, opposite }) {

// checksum for lookup table
const checksum = (left ? 1 : 0) | (right ? 2 : 0) | (top || down ? 4 : 0) | (bottom || up ? 8 : 0) | (mirror ? 16 : 0) | (opposite ? 32 : 0) | (reverse ? 64 : 0);
if (lookup.hasOwnProperty(checksum))
return lookup[checksum]
Expand All @@ -28,7 +31,9 @@ function make(reverse, { left, right, up, down, top, bottom, mirror, opposite })

function Rotate({
children, _out, forever,
timeout, duration = defaults.duration, delay = defaults.delay, count = defaults.count, ...props
timeout, duration = defaults.duration,
delay = defaults.delay,
count = defaults.count, ...props
} = defaults) {
const effect = {
make,
Expand Down
1 change: 1 addition & 0 deletions src/animations/complex/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Rotate";
export * from "./RightSpeed";

0 comments on commit 3ec50bf

Please sign in to comment.