Skip to content

Commit

Permalink
Add initial support for background shorthand property (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager authored Jun 25, 2020
1 parent eb78e06 commit ae2b659
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/alfa-style/src/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export namespace Property {

type Registered = typeof Registered;
const Registered = {
background: Background.Shorthand,
overflow: Overflow.Shorthand,
};

Expand Down
20 changes: 20 additions & 0 deletions packages/alfa-style/src/property/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@siteimprove/alfa-css";
import { Iterable } from "@siteimprove/alfa-iterable";
import { Parser } from "@siteimprove/alfa-parser";
import { Record } from "@siteimprove/alfa-record";

import * as css from "@siteimprove/alfa-css";

Expand All @@ -33,6 +34,9 @@ export namespace Background {
export type Computed = RGB<Percentage, Percentage> | Current | System;
}

/**
* @see https://drafts.csswg.org/css-backgrounds/#background-color
*/
export const Color: Property<
Color.Specified,
Color.Computed
Expand Down Expand Up @@ -66,6 +70,9 @@ export namespace Background {
>;
}

/**
* @see https://drafts.csswg.org/css-backgrounds/#background-image
*/
export const Image: Property<Image.Specified, Image.Computed> = Property.of(
List.of([Keyword.of("none")], ", "),
map(
Expand All @@ -91,6 +98,19 @@ export namespace Background {
)
)
);

/**
* @see https://drafts.csswg.org/css-backgrounds/#background
*/
export const Shorthand = Property.Shorthand.of(
["background-image", "background-color"],
map(Color.parse, (color) => {
return Record.of({
"background-color": color,
"background-image": Image.initial as Image.Specified,
});
})
);
}

function resolveImage(image: Image, style: Style) {
Expand Down
8 changes: 0 additions & 8 deletions packages/alfa-style/src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export class Style implements Serializable {
const { name, value } = declaration;

if (Property.isName(name)) {
if (this._cascaded.has(name)) {
continue;
}

const property = Property.get(name);

for (const result of parse(property, value)) {
Expand All @@ -72,10 +68,6 @@ export class Style implements Serializable {

for (const result of parseShorthand(shorthand, value)) {
for (const [name, value] of result) {
if (this._cascaded.has(name)) {
continue;
}

this._cascaded.set(name, Value.of(value, Option.of(declaration)));
}
}
Expand Down

0 comments on commit ae2b659

Please sign in to comment.