Skip to content

Commit b737ff6

Browse files
committed
Support unitless zeros in shadows and borders
1 parent 4f3eb02 commit b737ff6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/css-variables.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,13 @@ describe("parseCssVariables", () => {
807807
});
808808
});
809809

810+
test("parses shadow with unitless zeros", () => {
811+
const result = parseCssVariables(
812+
"--shadow: inset 0 0 0 1px hsl(220 3% 15% / 10%);",
813+
);
814+
expect(result.shadow?.$value).toHaveProperty("inset", true);
815+
});
816+
810817
test("parses inset shadow", () => {
811818
const result = parseCssVariables(
812819
"--shadow: inset 0px 2px 4px 0px rgba(0, 0, 0, 0.1);",

src/css-variables.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,17 @@ const parseColorToken = (value: string): undefined | Token => {
359359
}
360360
};
361361

362-
const parseDimensionValue = (value: string): undefined | DimensionValue => {
363-
const match = value.match(/^([\d.-]+)(px|rem)$/);
362+
const parseDimensionValue = (
363+
value: string,
364+
unitlessZero?: boolean,
365+
): undefined | DimensionValue => {
366+
if (unitlessZero && value === "0") {
367+
return {
368+
value: 0,
369+
unit: "px",
370+
};
371+
}
372+
let match = value.match(/^([\d.-]+)(px|rem)$/);
364373
if (!match) {
365374
return;
366375
}
@@ -456,7 +465,7 @@ const parseShadowItem = (value: string): undefined | ShadowObject => {
456465
.filter((item) => item !== undefined)
457466
.at(0);
458467
const dimensions = parts
459-
.map(parseDimensionValue)
468+
.map((item) => parseDimensionValue(item, true))
460469
.filter((item) => item !== undefined);
461470
const offsetX = dimensions.at(0);
462471
const offsetY = dimensions.at(1);
@@ -520,7 +529,7 @@ const parseBorderToken = (value: string): undefined | Token => {
520529
const aliases = parts
521530
.map(parseAliasValue)
522531
.filter((item) => item !== undefined);
523-
const width = parts.map(parseDimensionValue).at(0);
532+
const width = parts.map((item) => parseDimensionValue(item, true)).at(0);
524533
const color = parts.map(parseColorValue).at(0);
525534
return {
526535
$type: "border",

0 commit comments

Comments
 (0)