Skip to content

Commit

Permalink
Merge pull request #1443 from vivliostyle/fix/issue1442
Browse files Browse the repository at this point in the history
fix: fix calc() not working for unitless values
  • Loading branch information
MurakamiShinyu authored Jan 10, 2025
2 parents a090f43 + 91bbadc commit 5d59967
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/vivliostyle/css-cascade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4825,8 +4825,15 @@ export class CalcFilterVisitor extends Css.FilterVisitor {
if (exprVal instanceof Css.Expr) {
try {
const exprResult = exprVal.expr.evaluate(this.context);
if (typeof exprResult === "number") {
value = new Css.Numeric(exprResult, "px");
if (typeof exprResult === "number" && !isNaN(exprResult)) {
if (/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(exprText)) {
// length value
value = new Css.Numeric(exprResult, "px");
} else if (!/\d[a-z]/i.test(exprText)) {
// unitless number
value = new Css.Num(exprResult);
}
// otherwise, keep the original calc() expression
}
} catch (err) {
Logging.logger.warn(err);
Expand Down

0 comments on commit 5d59967

Please sign in to comment.