Skip to content

Commit

Permalink
Introduce calculatable numeric types (#1432)
Browse files Browse the repository at this point in the history
* Add calculalted Numeric abstraction

* Add calculated Number type

* Add some Number tests

* Typo

* Scaffold for calculated interger

* Accept broader refinements in Selective.if()

* Replace CSS Number by (fixed) calculatable ones

* Clean up parser

* Use (fixed) calculated Integers

* Remove and infer redundant second parameter of dimensions

* Make calculatable length inherits from calculatable dimensions

* Add some angle parsing tests

* Build calculatable Angle abstraction

* Spread usage of calculatable Angles

* Streamline expressions reducing

* Introduce calculatable percentage abstraction

* Remove NumberPercentage

* Use calculatable percentages

* Streamline percentage resolusion

* Clean up

* Extract API

* Clean up

* Clean up

* Extract API

* Strip down base numerics used in calculations

* Remove Math inheritance from Value

* Move value.ts back in the value directory

* Mark temporary helpers as internal

* Extract API

* Introduce Foo.Canonical abstraction

* Extract API

* Typo

Co-authored-by: Rolf Christian Jørgensen <114920418+rcj-siteimprove@users.noreply.github.com>

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rolf Christian Jørgensen <114920418+rcj-siteimprove@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 21, 2023
1 parent dc70915 commit f4cda0e
Show file tree
Hide file tree
Showing 115 changed files with 2,656 additions and 1,279 deletions.
10 changes: 10 additions & 0 deletions .changeset/brown-countries-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@siteimprove/alfa-style": minor
"@siteimprove/alfa-css": minor
---

**Breaking:** New abstractions for calculatable numeric values (numbers, percentages, dimensions) are introduced and used in style properties. Currently, style properties only accept non-calculated numeric (except for some properties that already accepted calculated lengths or length-percentages and keep doing so).

These abstractions are now exported from `@siteimprove/alfa-css` instead of the old abstractions which didn't accept calculations. In order to keep the functionalities of the old abstractions, replace `Foo` (`Number`, `Length`, …) with `Foo.Fixed`.

The new abstractions come with a `#resolve()` method which resolve any remaining calculation and returns a `Fixed` value. These methods need various resolvers argument depending on the precise abstraction (e.g. `Length#resolve` needs to know how to resolve relative lengths into `px`).
5 changes: 5 additions & 0 deletions .changeset/cold-tables-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-css": minor
---

**Breaking:** Math expression converters (`.toLength`, …) now return a `Result<T, string>` instead of an `option<T>`.
5 changes: 5 additions & 0 deletions .changeset/fair-needles-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-css": minor
---

**Breaking:** The redundant second type parameter (Unit category) of Dimensions has been removed and is now automatically inferred from the first parameter (type string representation).
7 changes: 2 additions & 5 deletions .changeset/gold-pens-shave.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"@siteimprove/alfa-css": minor
---

**Breaking:** `Math.resolve` has been renamed `Math.resolve2`.
This is a temporary change to accommodate for the new `resolve` method on parent class `Value`.

**Breaking:** `Math.resolve2` now returns a `Result<Numeric, string>` instead of an `Option`.
**Breaking:** `Math.resolve` now returns a `Result<Numeric, string>` instead of an `Option`.
Invalid expressions return an error message.

**Breaking:** No resolver is needed for `Math.resolve2` on `Number` expressions.
**Breaking:** No resolver is needed for `Math.resolve` on `Number` expressions.
5 changes: 5 additions & 0 deletions .changeset/hip-baboons-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-css": minor
---

**Added:** Most CSS value types now export a `Foo.Canonical` type which is the canonical representation of the type with calculation resolved, relative values absolutized, and dimensions converted to their canonical units. The `Canonical` type is normally the one used to represent conputed values of style propreties.
7 changes: 7 additions & 0 deletions .changeset/odd-dancers-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@siteimprove/alfa-selective": minor
---

**Added:** `Selective.if()` now accepts any refinement and will refine to the intersection of its result and the value in the associated right side.

This allows use cases like `Selective.of<A | B>(foo).if(isBOrC, bar => …)` to correctly refine `bar` to a `B` instead of defaulting to the `Predicate` overload that wouldn't refine anything.
5 changes: 5 additions & 0 deletions .changeset/rotten-birds-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-style": minor
---

**Breaking:** the `NumberPercentage` abstraction, which doesn't exist in CSS, has been removed.
5 changes: 5 additions & 0 deletions .changeset/serious-snails-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-style": minor
---

**Breaking:** The `Resolver.percentage` helper has been removed. Instead, the `Percentage#resolve(base)` method (from `@siteimprove/alfa-css`) provides the same functionality.
Loading

0 comments on commit f4cda0e

Please sign in to comment.