Skip to content

Commit 74cfcca

Browse files
committed
Ignore offset, easing and composite in getKeyframeKeys
1 parent ad00be0 commit 74cfcca

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

src/hooks/core.spec.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { describe, it, expect } from "@jest/globals";
2+
import { getKeyframeKeys } from "./core";
3+
4+
describe("getKeyframeKeys", () => {
5+
it("normal", () => {
6+
expect(
7+
getKeyframeKeys([
8+
{ transform: "rotate(-720deg) translateX(0px)" },
9+
{ transform: "rotate(-360deg) translateX(-250px)", offset: 0.25 },
10+
{
11+
transform: "rotate(0deg) translateX(0px)",
12+
fill: "red",
13+
fontSize: "48px",
14+
fontWeight: "bold",
15+
offset: 0.75,
16+
},
17+
{ transform: "rotate(360deg) translateX(0px)", fill: "lightskyblue" },
18+
])
19+
).toEqual(["transform", "fill", "fontSize", "fontWeight"]);
20+
});
21+
22+
it("ignore offset, easing and composite", () => {
23+
expect(
24+
getKeyframeKeys([
25+
{ transform: "rotate(-720deg) translateX(0px)", easing: "ease" },
26+
{
27+
transform: "rotate(0deg) translateX(0px)",
28+
offset: 0.75,
29+
composite: "accumulate",
30+
},
31+
{ transform: "rotate(360deg) translateX(0px)" },
32+
])
33+
).toEqual(["transform"]);
34+
});
35+
36+
it("map cssFloat and cssOffset", () => {
37+
expect(getKeyframeKeys([{ cssFloat: "left", cssOffset: 10 }])).toEqual([
38+
"float",
39+
"offset",
40+
]);
41+
});
42+
});

src/hooks/core.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ export interface AnimationOptions
2626
}
2727

2828
export const getKeyframeKeys = (keyframes: TypedKeyframe[]): string[] =>
29-
uniqBy(keyframes.flatMap(getKeys)).map((k) => {
30-
if (k === "cssFloat") {
31-
return "float";
29+
uniqBy(keyframes.flatMap(getKeys)).reduce((acc, k) => {
30+
if (["offset", "easing", "composite"].includes(k)) {
31+
// Ignore
32+
} else if (k === "cssFloat") {
33+
acc.push("float");
3234
} else if (k === "cssOffset") {
33-
return "offset";
35+
acc.push("offset");
3436
} else {
35-
return k;
37+
acc.push(k);
3638
}
37-
});
39+
return acc;
40+
}, [] as string[]);
3841

3942
export const createAnimation = (
4043
el: HTMLElement | null,

0 commit comments

Comments
 (0)