From 91bbadcf4e07c3615a05b4d8e99f99f905de44db Mon Sep 17 00:00:00 2001 From: MurakamiShinyu Date: Fri, 10 Jan 2025 13:25:18 +0900 Subject: [PATCH] fix: fix calc() not working for unitless values - fix #1442 --- packages/core/src/vivliostyle/css-cascade.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/src/vivliostyle/css-cascade.ts b/packages/core/src/vivliostyle/css-cascade.ts index 506321733..c9570f77c 100644 --- a/packages/core/src/vivliostyle/css-cascade.ts +++ b/packages/core/src/vivliostyle/css-cascade.ts @@ -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);