- From: Sam Atkins via GitHub <sysbot+gh@w3.org>
- Date: Tue, 28 Jan 2025 15:59:48 +0000
- To: public-css-archive@w3.org
AtkinsSJ has just created a new issue for https://github.com/w3c/csswg-drafts: == [css-values-4] Calc-simplification mishandles unresolved percentages in product nodes == For this CSS: ``` div { background-position-y: calc(2% * 2); } ``` The first time that the [calc simplification algorithm](https://drafts.csswg.org/css-values-4/#calc-simplification) is run for this, (at the end of [parse a calculation](https://drafts.csswg.org/css-values-4/#parse-a-calculation),) we end up in step 9.4: > If root contains only numeric values and/or Invert nodes containing numeric values, and [multiplying the types](https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-multiply-two-types) of all the children (noting that the type of an Invert node is the [inverse](https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-invert-a-type) of its child’s type) results in a type that [matches](https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-match) any of the types that a [math function](https://drafts.csswg.org/css-values-4/#math-function) can resolve to, return the result of multiplying all the values of the children (noting that the value of an Invert node is the reciprocal of its child’s value), expressed in the result’s [canonical unit](https://drafts.csswg.org/css-values-4/#canonical-unit). The `2%` numeric node has a type of `«[ "length" → 1 ]», with a percent hint of "length"` in [determine the type of a calculation](https://drafts.csswg.org/css-values-4/#ref-for-percentage-value%E2%91%A2%E2%91%A1). Step 3 before this is unable to convert it to an actual number of pixels. However, the instructions in step 9.4 multiply its type and value with the `2` node anyway, producing a result with an apparent value of `4px`. It's possible that the note under step 4, "If a percentage is left at this point, it will usually block simplification of the node..." is intended to apply here and my example should not have reached step 9.4. If this is the case then it'd be helpful if that was clarified. However, the other steps explicitly handle percentages, so that doesn't seem to be the case. Adding my own ad-hoc check in 9.4 to skip to step 9.5 for such percentages solves the issue, but does leave the result as `calc(2% * 2)` instead of `4%`. Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11588 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Tuesday, 28 January 2025 15:59:49 UTC