From 3293a99180866bfd6a0c20b27f06b3305b93beb7 Mon Sep 17 00:00:00 2001 From: Kasper Isager Date: Thu, 25 Jun 2020 12:42:36 +0200 Subject: [PATCH 1/3] Add initial support for `background` shorthand property --- packages/alfa-style/src/property.ts | 1 + packages/alfa-style/src/property/background.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/alfa-style/src/property.ts b/packages/alfa-style/src/property.ts index 80c2fe4403..0933844ac6 100644 --- a/packages/alfa-style/src/property.ts +++ b/packages/alfa-style/src/property.ts @@ -198,6 +198,7 @@ export namespace Property { type Registered = typeof Registered; const Registered = { + background: Background.Shorthand, overflow: Overflow.Shorthand, }; diff --git a/packages/alfa-style/src/property/background.ts b/packages/alfa-style/src/property/background.ts index cb0bde37e8..db4cd9c884 100644 --- a/packages/alfa-style/src/property/background.ts +++ b/packages/alfa-style/src/property/background.ts @@ -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"; @@ -91,6 +92,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) { From c7debbd3da3cdb5e0a1353381c78ed7ac6d6b057 Mon Sep 17 00:00:00 2001 From: Kasper Isager Date: Thu, 25 Jun 2020 12:48:48 +0200 Subject: [PATCH 2/3] Later properties should overwrite earlier properties --- packages/alfa-style/src/style.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/alfa-style/src/style.ts b/packages/alfa-style/src/style.ts index 4e66d76228..5dc8cabad5 100644 --- a/packages/alfa-style/src/style.ts +++ b/packages/alfa-style/src/style.ts @@ -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)) { @@ -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))); } } From 84eaaa5cff7285a766c3e6021b479c7ff9fe067c Mon Sep 17 00:00:00 2001 From: Kasper Isager Date: Thu, 25 Jun 2020 12:52:39 +0200 Subject: [PATCH 3/3] Add links to spec for other background properties --- packages/alfa-style/src/property/background.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/alfa-style/src/property/background.ts b/packages/alfa-style/src/property/background.ts index db4cd9c884..afa5bbb330 100644 --- a/packages/alfa-style/src/property/background.ts +++ b/packages/alfa-style/src/property/background.ts @@ -34,6 +34,9 @@ export namespace Background { export type Computed = RGB | Current | System; } + /** + * @see https://drafts.csswg.org/css-backgrounds/#background-color + */ export const Color: Property< Color.Specified, Color.Computed @@ -67,6 +70,9 @@ export namespace Background { >; } + /** + * @see https://drafts.csswg.org/css-backgrounds/#background-image + */ export const Image: Property = Property.of( List.of([Keyword.of("none")], ", "), map(