Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Correct transition timing function for Webflow paste (#3652)

Ivan Starkov737aa3434d9c
diff --git a/packages/css-data/src/property-parsers/transition-property-extractor.ts b/packages/css-data/src/property-parsers/transition-property-extractor.ts
index 4a4c2c067d..e1ecd784f5 100644
--- a/packages/css-data/src/property-parsers/transition-property-extractor.ts
+++ b/packages/css-data/src/property-parsers/transition-property-extractor.ts
@@ -8,10 +8,17 @@ import {
} from "@webstudio-is/css-engine";
import { isAnimatableProperty } from "..";
-export const isTimingFunction = (timing: string) => {
- const regex =
- /^(ease(-in-out|-in|-out)?|linear|cubic-bezier\((-?\d+(\.\d+)?(, ?)?){3}-?\d+(\.\d+)?\)|steps\(\d+(,(start|end|jump-start|jump-end|jump-none|jump-both))?\))$/gm;
- return regex.test(timing);
+export const isTimingFunction = (name: string) => {
+ const allowedNames = [
+ "ease-in",
+ "ease-out",
+ "ease-in-out",
+ "linear",
+ "cubic-bezier",
+ "steps",
+ ];
+
+ return allowedNames.includes(name);
};
export type ExtractedTransitionProperties = {
diff --git a/packages/css-data/src/property-parsers/transition.test.ts b/packages/css-data/src/property-parsers/transition.test.ts
index 4708d2755c..8afa0f4192 100644
--- a/packages/css-data/src/property-parsers/transition.test.ts
+++ b/packages/css-data/src/property-parsers/transition.test.ts
@@ -34,6 +34,70 @@ test("parses an in-valid transitionDuration longhand property", () => {
`);
});
+test("parses a vaild transitionTimingFunction longhand property with 0 omitted", () => {
+ const parsedValue = parseTransitionLonghandProperty(
+ "transitionTimingFunction",
+ "ease, ease-in, cubic-bezier(.68,-0.6,0.32,1.6), steps(4, jump-start)"
+ );
+ expect(parsedValue).toMatchInlineSnapshot(`
+{
+ "type": "layers",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "ease",
+ },
+ {
+ "type": "keyword",
+ "value": "ease-in",
+ },
+ {
+ "args": {
+ "type": "layers",
+ "value": [
+ {
+ "type": "keyword",
+ "value": ".68",
+ },
+ {
+ "type": "keyword",
+ "value": "-0.6",
+ },
+ {
+ "type": "keyword",
+ "value": "0.32",
+ },
+ {
+ "type": "keyword",
+ "value": "1.6",
+ },
+ ],
+ },
+ "name": "cubic-bezier",
+ "type": "function",
+ },
+ {
+ "args": {
+ "type": "layers",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "4",
+ },
+ {
+ "type": "keyword",
+ "value": "jump-start",
+ },
+ ],
+ },
+ "name": "steps",
+ "type": "function",
+ },
+ ],
+}
+`);
+});
+
test("parses a vaild transitionTimingFunction longhand property", () => {
const parsedValue = parseTransitionLonghandProperty(
"transitionTimingFunction",
diff --git a/packages/css-data/src/property-parsers/transition.ts b/packages/css-data/src/property-parsers/transition.ts
index d80af46368..1efe7ac6e6 100644
--- a/packages/css-data/src/property-parsers/transition.ts
+++ b/packages/css-data/src/property-parsers/transition.ts
@@ -95,17 +95,11 @@ export const parseTransitionLonghandProperty = (
switch (property) {
case "transitionTimingFunction": {
if (child.type === "Identifier") {
- if (isTimingFunction(csstree.generate(child)) === false) {
- throw new Error(
- `Invalid timing function, received ${csstree.generate(child)}`
- );
- }
-
layers.value.push({ type: "keyword", value: child.name });
}
if (child.type === "Function") {
- if (isTimingFunction(csstree.generate(child)) === false) {
+ if (isTimingFunction(child.name) === false) {
throw new Error(
`Invalid timing function, received ${csstree.generate(child)}`
);