-
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.
- Loading branch information
1 parent
fb39e55
commit e5af28b
Showing
6 changed files
with
169 additions
and
0 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
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,45 @@ | ||
import { | ||
Image, | ||
Keyword, | ||
URL, | ||
type Parser as CSSParser, | ||
} from "@siteimprove/alfa-css"; | ||
import { Parser } from "@siteimprove/alfa-parser"; | ||
import { Selective } from "@siteimprove/alfa-selective"; | ||
|
||
import { Longhand } from "../longhand.js"; | ||
import { Resolver } from "../resolver.js"; | ||
|
||
const { either } = Parser; | ||
|
||
export type MaskBorderSource = Keyword<"none"> | Image | URL; | ||
|
||
export namespace MaskBorderSource { | ||
export const parse: CSSParser<MaskBorderSource> = either( | ||
Keyword.parse("none"), | ||
either(Image.parse, URL.parse), | ||
); | ||
|
||
export const initialItem = Keyword.of("none"); | ||
} | ||
|
||
type Specified = MaskBorderSource; | ||
type Computed = Specified; | ||
|
||
/** | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/mask-border-source} | ||
* | ||
* @internal | ||
*/ | ||
export default Longhand.of<Specified, Computed>( | ||
MaskBorderSource.initialItem, | ||
MaskBorderSource.parse, | ||
(value, style) => | ||
value.map((image) => | ||
Selective.of(image) | ||
.if(Image.isImage, (image) => | ||
image.partiallyResolve(Resolver.length(style)), | ||
) | ||
.get(), | ||
), | ||
); |
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
109 changes: 109 additions & 0 deletions
109
packages/alfa-style/test/property/mask-border-source.spec.tsx
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,109 @@ | ||
import { test } from "@siteimprove/alfa-test"; | ||
import { h } from "@siteimprove/alfa-dom"; | ||
|
||
import { computed } from "../common.js"; | ||
|
||
test("initial value is none", (t) => { | ||
t.deepEqual(computed(<div></div>, "mask-border-source"), { | ||
value: { | ||
type: "keyword", | ||
value: "none", | ||
}, | ||
source: null, | ||
}); | ||
}); | ||
|
||
test("#computed parses url value", (t) => { | ||
t.deepEqual( | ||
computed( | ||
<div style={{ maskBorderSource: "url(foo.svg)" }}></div>, | ||
"mask-border-source", | ||
), | ||
{ | ||
value: { | ||
type: "image", | ||
image: { | ||
type: "url", | ||
url: "foo.svg", | ||
}, | ||
}, | ||
source: h.declaration("mask-border-source", "url(foo.svg)").toJSON(), | ||
}, | ||
); | ||
}); | ||
|
||
test("#computed parses linear-gradient value", (t) => { | ||
t.deepEqual( | ||
computed( | ||
<div style={{ maskBorderSource: "linear-gradient(red, blue)" }}></div>, | ||
"mask-border-source", | ||
), | ||
{ | ||
value: { | ||
type: "image", | ||
image: { | ||
type: "gradient", | ||
kind: "linear", | ||
direction: { | ||
type: "side", | ||
side: "bottom", | ||
}, | ||
items: [ | ||
{ | ||
color: { | ||
type: "color", | ||
format: "rgb", | ||
alpha: { | ||
type: "percentage", | ||
value: 1, | ||
}, | ||
red: { | ||
type: "percentage", | ||
value: 1, | ||
}, | ||
green: { | ||
type: "percentage", | ||
value: 0, | ||
}, | ||
blue: { | ||
type: "percentage", | ||
value: 0, | ||
}, | ||
}, | ||
position: null, | ||
type: "stop", | ||
}, | ||
{ | ||
color: { | ||
type: "color", | ||
format: "rgb", | ||
alpha: { | ||
type: "percentage", | ||
value: 1, | ||
}, | ||
red: { | ||
type: "percentage", | ||
value: 0, | ||
}, | ||
green: { | ||
type: "percentage", | ||
value: 0, | ||
}, | ||
blue: { | ||
type: "percentage", | ||
value: 1, | ||
}, | ||
}, | ||
position: null, | ||
type: "stop", | ||
}, | ||
], | ||
repeats: false, | ||
}, | ||
}, | ||
source: h | ||
.declaration("mask-border-source", "linear-gradient(red, blue)") | ||
.toJSON(), | ||
}, | ||
); | ||
}); |
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