-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test of shorthand as well as clean up and minor fixes
- Loading branch information
1 parent
f6ac94f
commit 071c468
Showing
23 changed files
with
633 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@siteimprove/alfa-style": minor | ||
--- | ||
|
||
**Added:** CSS shorthand property `mask` and corresponding longhand properties is now supported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { List, type Value } from "@siteimprove/alfa-css"; | ||
|
||
import type { Style } from "../../style.js"; | ||
|
||
/** | ||
* {@link https://drafts.fxtf.org/css-masking/#layering}. | ||
* | ||
* @remarks | ||
* The computed value depends on the number of layers. | ||
* A layer is created for each of the comma separated values for `mask-image`. | ||
* | ||
* If there are more values than layers, the excess values are discarded. | ||
* Otherwise, the values must be repeated | ||
* until the number of values matches the number of layers. | ||
*/ | ||
export function matchLayers<V extends Value>( | ||
value: List<V>, | ||
style: Style, | ||
): List<V> { | ||
const numberOfLayers = Math.max( | ||
style.computed("mask-image").value.values.length, | ||
1, | ||
); | ||
|
||
const numberOfValues = value.values.length; | ||
if (numberOfValues === numberOfLayers) { | ||
return value; | ||
} | ||
|
||
return List.of( | ||
(numberOfLayers < numberOfValues | ||
? value.values | ||
: Array(Math.ceil(numberOfLayers / numberOfValues)) | ||
.fill(value.values) | ||
.flat() | ||
).slice(0, numberOfLayers), | ||
", ", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import { Box, Keyword, List } from "@siteimprove/alfa-css"; | ||
|
||
import { Longhand } from "../longhand.js"; | ||
import { matchLayers } from "./mask.js"; | ||
|
||
import { matchLayers } from "./helpers/match-layers.js"; | ||
|
||
type Specified = List<Box.CoordBox>; | ||
type Computed = Specified; | ||
|
||
export const initialItem = Keyword.of("border-box"); | ||
export namespace MaskOrigin { | ||
export const initialItem = Keyword.of("border-box"); | ||
} | ||
|
||
/** | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/mask-origin} | ||
* | ||
* @internal | ||
*/ | ||
export default Longhand.of<Specified, Computed>( | ||
List.of([initialItem], ", "), | ||
List.of([MaskOrigin.initialItem], ", "), | ||
List.parseCommaSeparated(Box.parseCoordBox), | ||
(value, style) => value.map((value) => matchLayers(value, style)), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.