Skip to content

Commit 91e5e73

Browse files
authored
Revamp system for generating and mixing in property descriptors
Previously the workflow for installing property descriptors on CSSStyleDeclaration was complex: * The `download` task would download a subset of property names from https://www.w3.org/Style/CSS/all-properties.en.json, which would get written to the checked-in file `lib/generated/allProperties.js`. * Those properties, plus those in the checked-in file `lib/utils/allExtraProperties.js`, would be used to generate `lib/generated/propertyDefinitions.js` at prepare time, by using the data in `@webref/css`. (If a property did not exist in `@webref/css`, no property definition would be generated.) * The property handlers in `lib/properties/*.js` would be used both in code like `normalize.js`, and also to generate `lib/generated/properties.js` at prepare time by copying most of the body of those handlers into `properties.js`. `lib/generated/properties.js` would then be used to install the actual property descriptors. This was overly complex and confusing. The new flow is: * `@webref/css` becomes the single source of truth for which CSS properties we support. The w3.org JSON file and checked-in `allProperties.js` and `allExtraProperties.js` are deleted. * One prepare-time script generates all relevant property definitions in `lib/generated/propertyDefinitions.js`. * One prepare-time script then uses those property definitions to generate an object of property descriptors, which either delegate directly to the existing handler files, or use the generic property descriptor code. There is no longer any complicated AST-munging to move code from `lib/properties/*.js` into a generated file. And the generated object of property descriptors can be simply and easily mixed in to `CSSStyleDeclaration`. As part of standardizing on `@webref/css` as our source of truth, this makes some changes to the supported list of CSS properties: * Many new ones are added with generic processing. * The following are added with fully-implemented processing: border-block-end-color, border-block-start-color, border-inline-end-color, border-inline-start-color, text-emphasis-color. * The following nonstandard properties are deleted: -webkit-background-composite, -webkit-border-after, -webkit-border-after-color, -webkit-border-after-style, -webkit-border-after-width, -webkit-border-before, -webkit-border-before-color, -webkit-border-before-style, -webkit-border-before-width, -webkit-border-end, -webkit-border-end-color, -webkit-border-end-style, -webkit-border-end-width, -webkit-border-fit, -webkit-border-horizontal-spacing, -webkit-border-start, -webkit-border-start-color, -webkit-border-start-style, -webkit-border-start-width, -webkit-border-vertical-spacing, -webkit-color-correction, -webkit-column-axis, -webkit-column-break-after, -webkit-column-break-before, -webkit-column-break-inside, -webkit-column-rule-color, -webkit-flex-align, -webkit-flex-item-align, -webkit-flex-line-pack, -webkit-flex-order, -webkit-flex-pack, -webkit-font-size-delta, -webkit-font-smoothing, -webkit-highlight, -webkit-hyphenate-limit-after, -webkit-hyphenate-limit-before, -webkit-locale, -webkit-logical-height, -webkit-logical-width, -webkit-margin-after, -webkit-margin-after-collapse, -webkit-margin-before, -webkit-margin-before-collapse, -webkit-margin-bottom-collapse, -webkit-margin-collapse, -webkit-margin-end, -webkit-margin-start, -webkit-margin-top-collapse, -webkit-marquee, -webkit-marquee-direction, -webkit-marquee-increment, -webkit-marquee-repetition, -webkit-marquee-speed, -webkit-marquee-style, -webkit-mask-attachment, -webkit-mask-position-x, -webkit-mask-position-y, -webkit-mask-repeat-x, -webkit-mask-repeat-y, -webkit-match-nearest-mail-blockquote-color, -webkit-max-logical-height, -webkit-max-logical-width, -webkit-min-logical-height, -webkit-min-logical-width, -webkit-nbsp-mode, -webkit-overflow-scrolling, -webkit-padding-after, -webkit-padding-before, -webkit-padding-end, -webkit-padding-start, -webkit-perspective-origin-x, -webkit-perspective-origin-y, -webkit-region-break-after, -webkit-region-break-before, -webkit-region-break-inside, -webkit-region-overflow, -webkit-rtl-ordering, -webkit-svg-shadow, -webkit-tap-highlight-color, -webkit-text-decorations-in-effect, -webkit-text-emphasis-color, -webkit-text-security, -webkit-transform-origin-x, -webkit-transform-origin-y, -webkit-transform-origin-z, -webkit-user-drag, -webkit-user-modify, -webkit-wrap, -webkit-wrap-margin, -webkit-wrap-padding, -webkit-wrap-shape-inside, -webkit-wrap-shape-outside, -webkit-zoom, color-profile, color-rendering, enable-background, glyph-orientation-horizontal, kerning, marker-offset, marks, size, src, text-line-through, text-line-through-color, text-line-through-mode, text-line-through-style, text-line-through-width, text-overline, text-overline-color, text-overline-mode, text-overline-style, text-overline-width, text-underline, text-underline-color, text-underline-mode, text-underline-style, text-underline-width, unicode-range. This additionally deletes the `propertyList` export from the package's main module, as that was an artifact of our previous over-complicated pipeline.
1 parent 8b4cd29 commit 91e5e73

23 files changed

Lines changed: 162 additions & 1737 deletions

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
22
npm-debug.log
3-
lib/generated/implementedProperties.js
4-
lib/generated/properties.js
53
lib/generated/propertyDefinitions.js
4+
lib/generated/propertyDescriptors.js

lib/CSSStyleDeclaration.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
*/
55
"use strict";
66

7-
const allProperties = require("./generated/allProperties");
8-
const implementedProperties = require("./generated/implementedProperties");
9-
const generatedProperties = require("./generated/properties");
7+
const propertyDescriptors = require("./generated/propertyDescriptors");
108
const {
119
borderProperties,
1210
getPositionValue,
@@ -22,9 +20,6 @@ const {
2220
parsePropertyValue,
2321
prepareValue
2422
} = require("./parsers");
25-
const allExtraProperties = require("./utils/allExtraProperties");
26-
const { dashedToCamelCase } = require("./utils/camelize");
27-
const { getPropertyDescriptor } = require("./utils/propertyDescriptors");
2823
const { asciiLowercase } = require("./utils/strings");
2924

3025
/**
@@ -363,7 +358,7 @@ class CSSStyleDeclaration {
363358
return;
364359
}
365360
const property = asciiLowercase(prop);
366-
if (!allProperties.has(property) && !allExtraProperties.has(property)) {
361+
if (!Object.hasOwn(propertyDescriptors, property)) {
367362
return;
368363
}
369364
if (priority) {
@@ -626,24 +621,10 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
626621
}
627622
});
628623

629-
// Properties
630-
Object.defineProperties(CSSStyleDeclaration.prototype, generatedProperties);
631-
632-
// Additional properties
633-
[...allProperties, ...allExtraProperties].forEach((property) => {
634-
if (!implementedProperties.has(property)) {
635-
const declaration = getPropertyDescriptor(property);
636-
Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
637-
const camel = dashedToCamelCase(property);
638-
Object.defineProperty(CSSStyleDeclaration.prototype, camel, declaration);
639-
if (/^webkit[A-Z]/.test(camel)) {
640-
const pascal = camel.replace(/^webkit/, "Webkit");
641-
Object.defineProperty(CSSStyleDeclaration.prototype, pascal, declaration);
642-
}
643-
}
644-
});
624+
// TODO: Remove once the CSSStyleDeclaration is fully spec-compliant.
625+
// @see https://github.com/jsdom/cssstyle/issues/255#issuecomment-3630183207
626+
Object.defineProperties(CSSStyleDeclaration.prototype, propertyDescriptors);
645627

646628
module.exports = {
647-
CSSStyleDeclaration,
648-
propertyList: Object.fromEntries(implementedProperties)
629+
CSSStyleDeclaration
649630
};

lib/generated/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)