Skip to content

Commit

Permalink
refactor: parse complex aspect ratio as unparsed value (#3740)
Browse files Browse the repository at this point in the history
Fixes the issue with pasting images from webflow.
  • Loading branch information
TrySound authored Jul 16, 2024
1 parent 308acbb commit cfde2f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
29 changes: 22 additions & 7 deletions packages/css-data/src/parse-css-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ describe("Parse CSS value", () => {
type: "invalid",
value: "10",
});

// This will return number unit, as number is valid for aspectRatio.
expect(parseCssValue("aspectRatio", "10")).toEqual({
type: "unit",
unit: "number",
value: 10,
});
});
});

Expand Down Expand Up @@ -870,3 +863,25 @@ describe("parse filters", () => {
});
});
});

describe("aspect-ratio", () => {
test("support single numeric value", () => {
expect(parseCssValue("aspectRatio", "10")).toEqual({
type: "unit",
unit: "number",
value: 10,
});
});
test("support keyword", () => {
expect(parseCssValue("aspectRatio", "auto")).toEqual({
type: "keyword",
value: "auto",
});
});
test("support two values", () => {
expect(parseCssValue("aspectRatio", "16 / 9")).toEqual({
type: "unparsed",
value: "16 / 9",
});
});
});
6 changes: 5 additions & 1 deletion packages/css-data/src/parse-css-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,17 @@ export const parseCssValue = (
// Probably a tuple like background-size or box-shadow
if (
ast.type === "Value" &&
(ast.children.size > 1 || tupleProps.has(property))
(ast.children.size === 2 || tupleProps.has(property))
) {
const tuple: TupleValue = {
type: "tuple",
value: [],
};
for (const node of ast.children) {
// output any values with unhandled operators like slash or comma as unparsed
if (node.type === "Operator") {
return { type: "unparsed", value: input };
}
const matchedValue = parseLiteral(node, keywordValues[property as never]);
if (matchedValue) {
tuple.value.push(matchedValue as never);
Expand Down

0 comments on commit cfde2f3

Please sign in to comment.