Skip to content

Commit

Permalink
fix(postcss-reduce-initial): regenerate data (#1242)
Browse files Browse the repository at this point in the history
* fix(postcss-reduce-initial): regenerate data

* Extract script out of published `src` directory
* Run script to update initial value data from MDN

* fix(postcss-reduce-initial): fix bad data

* correct mask-repeat initial value from no-repeat to repeat and move
  to fromInitial since repeat.length = 6 < initial.length = 7
* add transform-box to default ignore list
  • Loading branch information
ludofischer committed Nov 26, 2021
1 parent 9ecc907 commit c6e9f00
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 11 deletions.
27 changes: 25 additions & 2 deletions packages/postcss-reduce-initial/data/fromInitial.json
@@ -1,7 +1,10 @@
{
"-webkit-line-clamp": "none",
"accent-color": "auto",
"align-content": "normal",
"align-items": "normal",
"align-self": "auto",
"align-tracks": "normal",
"animation-delay": "0s",
"animation-direction": "normal",
"animation-duration": "0s",
Expand All @@ -10,6 +13,7 @@
"animation-name": "none",
"animation-timing-function": "ease",
"appearance": "auto",
"aspect-ratio": "auto",
"azimuth": "center",
"backdrop-filter": "none",
"background-attachment": "scroll",
Expand Down Expand Up @@ -65,6 +69,7 @@
"clear": "none",
"clip": "auto",
"clip-path": "none",
"color-scheme": "normal",
"column-count": "auto",
"column-gap": "normal",
"column-rule-style": "none",
Expand All @@ -75,6 +80,7 @@
"content": "normal",
"counter-increment": "none",
"counter-reset": "none",
"counter-set": "none",
"cursor": "auto",
"direction": "ltr",
"empty-cells": "show",
Expand Down Expand Up @@ -102,6 +108,7 @@
"font-variant-numeric": "normal",
"font-variant-position": "normal",
"font-weight": "normal",
"forced-color-adjust": "auto",
"grid-auto-columns": "auto",
"grid-auto-flow": "row",
"grid-auto-rows": "auto",
Expand All @@ -117,7 +124,6 @@
"hanging-punctuation": "none",
"height": "auto",
"hyphens": "manual",
"image-orientation": "0deg",
"image-rendering": "auto",
"image-resolution": "1dppx",
"ime-mode": "auto",
Expand All @@ -135,11 +141,13 @@
"justify-content": "normal",
"justify-items": "legacy",
"justify-self": "auto",
"justify-tracks": "normal",
"left": "auto",
"letter-spacing": "normal",
"line-break": "auto",
"line-clamp": "none",
"line-height": "normal",
"line-height-step": "0",
"list-style-image": "none",
"list-style-type": "disc",
"margin-block": "0",
Expand All @@ -152,6 +160,7 @@
"margin-left": "0",
"margin-right": "0",
"margin-top": "0",
"margin-trim": "none",
"mask-border-mode": "alpha",
"mask-border-outset": "0",
"mask-border-slice": "0",
Expand All @@ -160,7 +169,10 @@
"mask-composite": "add",
"mask-image": "none",
"mask-position": "center",
"mask-repeat": "repeat",
"mask-size": "auto",
"masonry-auto-flow": "pack",
"math-style": "normal",
"max-block-size": "0",
"max-height": "none",
"max-inline-size": "0",
Expand All @@ -185,8 +197,14 @@
"outline-width": "medium",
"overflow-anchor": "auto",
"overflow-block": "auto",
"overflow-clip-margin": "0px",
"overflow-inline": "auto",
"overflow-wrap": "normal",
"overscroll-behavior": "auto",
"overscroll-behavior-block": "auto",
"overscroll-behavior-inline": "auto",
"overscroll-behavior-x": "auto",
"overscroll-behavior-y": "auto",
"padding-block": "0",
"padding-block-end": "0",
"padding-block-start": "0",
Expand All @@ -209,9 +227,9 @@
"right": "auto",
"rotate": "none",
"row-gap": "normal",
"ruby-position": "over",
"scale": "none",
"scrollbar-color": "auto",
"scrollbar-gutter": "auto",
"scrollbar-width": "auto",
"scroll-behavior": "auto",
"scroll-margin": "0",
Expand Down Expand Up @@ -242,6 +260,8 @@
"scroll-snap-points-y": "none",
"scroll-snap-stop": "normal",
"scroll-snap-type": "none",
"scroll-snap-type-x": "none",
"scroll-snap-type-y": "none",
"shape-image-threshold": "0.0",
"shape-margin": "0",
"shape-outside": "none",
Expand All @@ -252,6 +272,7 @@
"text-decoration-line": "none",
"text-decoration-skip-ink": "auto",
"text-decoration-style": "solid",
"text-decoration-thickness": "auto",
"text-emphasis-style": "none",
"text-indent": "0",
"text-justify": "auto",
Expand All @@ -260,6 +281,7 @@
"text-rendering": "auto",
"text-shadow": "none",
"text-transform": "none",
"text-underline-offset": "auto",
"text-underline-position": "auto",
"top": "auto",
"touch-action": "auto",
Expand All @@ -271,6 +293,7 @@
"transition-timing-function": "ease",
"translate": "none",
"unicode-bidi": "normal",
"user-select": "auto",
"white-space": "normal",
"widows": "2",
"width": "auto",
Expand Down
5 changes: 3 additions & 2 deletions packages/postcss-reduce-initial/data/toInitial.json
Expand Up @@ -17,17 +17,18 @@
"box-sizing": "content-box",
"column-rule-color": "currentcolor",
"font-synthesis": "weight style",
"image-orientation": "from-image",
"mask-clip": "border-box",
"mask-mode": "match-source",
"mask-origin": "border-box",
"mask-repeat": "repeat",
"mask-type": "luminance",
"ruby-align": "space-around",
"ruby-merge": "separate",
"ruby-position": "alternate",
"text-decoration-color": "currentcolor",
"text-emphasis-color": "currentcolor",
"text-emphasis-position": "over right",
"transform-box": "border-box",
"transform-box": "view-box",
"transform-origin": "50% 50% 0",
"vertical-align": "baseline",
"writing-mode": "horizontal-tb"
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-reduce-initial/package.json
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"acquire": "node ./src/script/acquire.mjs",
"prebuild": "rimraf dist",
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore '**/__tests__/,src/script'",
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__\"",
"prepare": "yarn build"
},
"keywords": [
Expand Down
Expand Up @@ -5,8 +5,8 @@ const url =
'https://raw.githubusercontent.com/mdn/data/master/css/properties.json';

const paths = {
fromInitial: new URL('../../data/fromInitial.json', import.meta.url),
toInitial: new URL('../../data/toInitial.json', import.meta.url),
fromInitial: new URL('../data/fromInitial.json', import.meta.url),
toInitial: new URL('../data/toInitial.json', import.meta.url),
};

generate(writeFile, paths, url).catch((error) => {
Expand Down
15 changes: 15 additions & 0 deletions packages/postcss-reduce-initial/src/__tests__/index.js
Expand Up @@ -97,6 +97,21 @@ test(
processCSS('h1{min-height:initial}', 'h1{min-height:auto}')
);

/* The correct initial value is `repeat`,
but MDN has the wrong data so */
test(
'preserve no-repeat mask-repeat',
passthroughCSS('div{mask-repeat:no-repeat}')
);

test(
'transform initial mask-repeat to repeat',
processCSS('div{mask-repeat:initial}', 'div{mask-repeat:repeat}')
);

/* Skip transform-box for browser compatibility */
test('preserve transform-box', passthroughCSS('div{transform-box:view-box}'));

test(
'should ignore the data present in the ignore options',
passthroughCSS('h1{min-height:initial}', { ignore: ['min-height'] })
Expand Down
8 changes: 4 additions & 4 deletions packages/postcss-reduce-initial/src/index.js
Expand Up @@ -6,7 +6,7 @@ import toInitial from '../data/toInitial.json';
const initial = 'initial';

// In most of the browser including chrome the initial for `writing-mode` is not `horizontal-tb`. Ref https://github.com/cssnano/cssnano/pull/905
const defaultIgnoreProps = ['writing-mode'];
const defaultIgnoreProps = ['writing-mode', 'transform-box'];

function pluginCreator() {
return {
Expand All @@ -25,11 +25,11 @@ function pluginCreator() {
OnceExit(css) {
css.walkDecls((decl) => {
const lowerCasedProp = decl.prop.toLowerCase();
const ignoreProp = defaultIgnoreProps.concat(
resultOpts.ignore || []
const ignoreProp = new Set(
defaultIgnoreProps.concat(resultOpts.ignore || [])
);

if (ignoreProp.includes(lowerCasedProp)) {
if (ignoreProp.has(lowerCasedProp)) {
return;
}

Expand Down

0 comments on commit c6e9f00

Please sign in to comment.