Skip to content

Commit cbdfc45

Browse files
authored
fix: rollup minify selectors should retain spaces (#3524)
# Description Reduce complexity for CSS tagged template compression. Also spotted some invalid commas in the `progress` stylesheets. ## Motivation & context The CSS tagged template minifier was combining `:host() .child` selectors, causing styles to not get rendered properly. ## Issue type checklist <!--- What type of change are you submitting? Put an x in the box that applies: --> - [ ] **Chore**: A change that does not impact distributed packages. - [x] **Bug fix**: A change that fixes an issue, link to the issue above. - [ ] **New feature**: A change that adds functionality. **Is this a breaking change?** - [ ] This change causes current functionality to break. <!--- If yes, describe the impact. --> **Adding or modifying component(s) in `@microsoft/fast-components` checklist** <!-- Do your changes add or modify components in the @microsoft/fast-components package? Put an x in the box that applies: --> - [ ] I have added a new component - [ ] I have modified an existing component - [ ] I have updated the [definition file](https://github.com/Microsoft/fast/blob/master/packages/web-components/fast-components/CONTRIBUTING.md#definition) - [ ] I have updated the [configuration file](https://github.com/Microsoft/fast/blob/master/packages/web-components/fast-components/CONTRIBUTING.md#configuration) ## Process & policy checklist <!--- Review the list and check the boxes that apply. --> - [ ] I have added tests for my changes. - [x] I have tested my changes. - [ ] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/Microsoft/fast/blob/master/CONTRIBUTING.md) documentation and followed the [standards](https://www.fast.design/docs/en/contributing/standards) for this project. <!--- Formatting guidelines: Accepted peer review title format: <type>: <description> Example titles: chore: add unit tests for all components feat: add a border radius to button fix: update design system to use 3px border radius <type> is required to be one of the following: - chore: A change that does not impact distributed packages. - fix: A change which fixes an issue. - feat: A that adds functionality. <description> is required for the CHANGELOG and speaks to what the user gets from this PR: - Be concise. - Use all lowercase characters. - Use imperative, present tense (e.g. `add` not `adds`.) - Do not end your description with a period. - Avoid redundant words. For additional information regarding working on FAST, check out our documentation site: https://www.fast.design/docs/en/contributing/working -->
1 parent ea84cbd commit cbdfc45

File tree

14 files changed

+109
-51
lines changed

14 files changed

+109
-51
lines changed

build/transform-html-fragment.js renamed to build/transform-fragments.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const spaceBetweenTags = /(>)\s+(<)/g;
44
const spaceBetweenAttrs = /(["'\w])(?!\s*>)\s+/g;
55
const openEnded = /(?:[^="'\w])?(["'\w])\s*$/g;
66

7-
export default function transformHTMLFragment(data) {
7+
export function transformHTMLFragment(data) {
88
// if the chunk is only space, collapse and return it
99
if (data.match(onlySpace)) {
1010
return data.replace(onlySpace, " ");
@@ -25,3 +25,25 @@ export default function transformHTMLFragment(data) {
2525

2626
return data.trim();
2727
}
28+
29+
const newlines = /\n/g;
30+
const separators = /\s*([\{\};])\s*/g;
31+
const lastProp = /;\s*(\})/g;
32+
const extraSpaces = /\s\s+/g;
33+
const endingSpaces = / ?\s+$/g;
34+
35+
export function transformCSSFragment(data) {
36+
// newlines
37+
data = data.replace(newlines, "");
38+
39+
// Remove extra space, but not too much
40+
data = data.replace(separators, "$1");
41+
42+
// Remove semicolons followed by property list end
43+
data = data.replace(lastProp, "$1");
44+
45+
// space might be between property values or between selectors
46+
data = data.replace(endingSpaces, " ");
47+
48+
return data.replace(extraSpaces, " ");
49+
}

packages/web-components/fast-components-msft/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"rollup": "^2.7.6",
7878
"rollup-plugin-commonjs": "^10.1.0",
7979
"rollup-plugin-filesize": "^8.0.2",
80-
"rollup-plugin-minify-tagged-css-template": "^0.0.2",
8180
"rollup-plugin-node-resolve": "^5.2.0",
8281
"rollup-plugin-terser": "^5.3.0",
8382
"rollup-plugin-transform-tagged-template": "^0.0.3",

packages/web-components/fast-components-msft/rollup.config.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import commonJS from "rollup-plugin-commonjs";
22
import filesize from "rollup-plugin-filesize";
3-
import minifyTaggedCSSTemplate from "rollup-plugin-minify-tagged-css-template";
4-
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
53
import resolve from "rollup-plugin-node-resolve";
64
import { terser } from "rollup-plugin-terser";
5+
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
76
import typescript from "rollup-plugin-typescript2";
8-
import transformHTMLFragment from "../../../build/transform-html-fragment";
7+
import {
8+
transformCSSFragment,
9+
transformHTMLFragment,
10+
} from "../../../build/transform-fragments";
911

10-
const parserOptions = { sourceType: "module" };
12+
const parserOptions = {
13+
sourceType: "module",
14+
};
1115

1216
export default [
1317
{
@@ -33,14 +37,19 @@ export default [
3337
},
3438
},
3539
}),
36-
minifyTaggedCSSTemplate({ parserOptions }),
40+
transformTaggedTemplate({
41+
tagsToProcess: ["css"],
42+
transformer: transformCSSFragment,
43+
parserOptions,
44+
}),
3745
transformTaggedTemplate({
3846
tagsToProcess: ["html"],
3947
transformer: transformHTMLFragment,
4048
parserOptions,
4149
}),
4250
filesize({
4351
showMinifiedSize: false,
52+
showBrotliSize: true,
4453
}),
4554
],
4655
},

packages/web-components/fast-components-msft/src/progress/progress/progress.styles.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const ProgressStyles = css`
4848
height: 100%;
4949
background-color: ${accentForegroundRestBehavior.var};
5050
border-radius: calc(var(--design-unit) * 1px);
51-
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
51+
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
5252
width: 40%;
5353
animation: indeterminate-1 2s infinite;
5454
}
@@ -59,12 +59,13 @@ export const ProgressStyles = css`
5959
height: 100%;
6060
background-color: ${accentForegroundRestBehavior.var};
6161
border-radius: calc(var(--design-unit) * 1px);
62-
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
62+
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
6363
width: 60%;
6464
animation: indeterminate-2 2s infinite;
6565
}
6666
67-
:host(.paused) .indeterminate-indicator-1, :host(.paused) .indeterminate-indicator-2 {
67+
:host(.paused) .indeterminate-indicator-1,
68+
:host(.paused) .indeterminate-indicator-2 {
6869
animation-play-state: paused;
6970
background-color: ${neutralFillRestBehavior.var};
7071
}
@@ -88,7 +89,7 @@ export const ProgressStyles = css`
8889
100% {
8990
opacity: 0;
9091
transform: translateX(300%);
91-
},
92+
}
9293
}
9394
9495
@keyframes indeterminate-2 {
@@ -106,8 +107,8 @@ export const ProgressStyles = css`
106107
100% {
107108
transform: translateX(166.66%);
108109
opacity: 1;
109-
},
110-
},
110+
}
111+
}
111112
`.withBehaviors(
112113
accentForegroundRestBehavior,
113114
neutralFillRestBehavior,

packages/web-components/fast-components-msft/src/slider/slider.styles.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import {
1717
} from "../styles";
1818

1919
export const SliderStyles = css`
20-
:host([hidden]) {
21-
display: none;
22-
}
23-
2420
${display("inline-grid")} :host {
2521
--thumb-size: calc(${heightNumber} * 0.5);
2622
--thumb-translate: calc(var(--thumb-size) * 0.5);
@@ -57,7 +53,7 @@ export const SliderStyles = css`
5753
position: absolute;
5854
height: calc(var(--thumb-size) * 1px);
5955
width: calc(var(--thumb-size) * 1px);
60-
transition: "all 0.2s ease";
56+
transition: all 0.2s ease;
6157
}
6258
.thumb-cursor {
6359
border: none;

packages/web-components/fast-components-msft/src/styles/patterns/button.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ export const BaseButtonStyles = css`
8888
.start,
8989
.end,
9090
::slotted(svg) {
91-
/* Glyph size and margin-left is temporary -
92-
replace when adaptive typography is figured out */
93-
width: 16px;
91+
${
92+
/* Glyph size and margin-left is temporary -
93+
replace when adaptive typography is figured out */ ""
94+
} width: 16px;
9495
height: 16px;
9596
}
9697

packages/web-components/fast-components/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"rollup": "^2.7.6",
8282
"rollup-plugin-commonjs": "^10.1.0",
8383
"rollup-plugin-filesize": "^8.0.2",
84-
"rollup-plugin-minify-tagged-css-template": "^0.0.2",
8584
"rollup-plugin-node-resolve": "^5.2.0",
8685
"rollup-plugin-terser": "^5.3.0",
8786
"rollup-plugin-transform-tagged-template": "^0.0.3",

packages/web-components/fast-components/rollup.config.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import commonJS from "rollup-plugin-commonjs";
22
import filesize from "rollup-plugin-filesize";
3-
import minifyTaggedCSSTemplate from "rollup-plugin-minify-tagged-css-template";
43
import resolve from "rollup-plugin-node-resolve";
54
import { terser } from "rollup-plugin-terser";
65
import transformTaggedTemplate from "rollup-plugin-transform-tagged-template";
76
import typescript from "rollup-plugin-typescript2";
8-
import transformHTMLFragment from "../../../build/transform-html-fragment";
7+
import {
8+
transformCSSFragment,
9+
transformHTMLFragment,
10+
} from "../../../build/transform-fragments";
911

10-
const parserOptions = { sourceType: "module" };
12+
const parserOptions = {
13+
sourceType: "module",
14+
};
1115

1216
export default [
1317
{
@@ -33,13 +37,20 @@ export default [
3337
},
3438
},
3539
}),
36-
minifyTaggedCSSTemplate({ parserOptions }),
40+
transformTaggedTemplate({
41+
tagsToProcess: ["css"],
42+
transformer: transformCSSFragment,
43+
parserOptions,
44+
}),
3745
transformTaggedTemplate({
3846
tagsToProcess: ["html"],
3947
transformer: transformHTMLFragment,
4048
parserOptions,
4149
}),
42-
filesize({ showMinifiedSize: false }),
50+
filesize({
51+
showMinifiedSize: false,
52+
showBrotliSize: true,
53+
}),
4354
],
4455
},
4556
];

packages/web-components/fast-components/src/progress/progress/progress.styles.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const ProgressStyles = css`
4848
height: 100%;
4949
background-color: ${accentForegroundRestBehavior.var};
5050
border-radius: calc(var(--design-unit) * 1px);
51-
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
51+
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
5252
width: 40%;
5353
animation: indeterminate-1 2s infinite;
5454
}
@@ -59,12 +59,13 @@ export const ProgressStyles = css`
5959
height: 100%;
6060
background-color: ${accentForegroundRestBehavior.var};
6161
border-radius: calc(var(--design-unit) * 1px);
62-
animation-timing-function: cubic-bezier(0.4, 0.0, 0.6, 1.0);
62+
animation-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
6363
width: 60%;
6464
animation: indeterminate-2 2s infinite;
6565
}
6666
67-
:host(.paused) .indeterminate-indicator-1, :host(.paused) .indeterminate-indicator-2 {
67+
:host(.paused) .indeterminate-indicator-1,
68+
:host(.paused) .indeterminate-indicator-2 {
6869
animation-play-state: paused;
6970
background-color: ${neutralFillRestBehavior.var};
7071
}
@@ -88,7 +89,7 @@ export const ProgressStyles = css`
8889
100% {
8990
opacity: 0;
9091
transform: translateX(300%);
91-
},
92+
}
9293
}
9394
9495
@keyframes indeterminate-2 {
@@ -106,8 +107,8 @@ export const ProgressStyles = css`
106107
100% {
107108
transform: translateX(166.66%);
108109
opacity: 1;
109-
},
110-
},
110+
}
111+
}
111112
`.withBehaviors(
112113
accentForegroundRestBehavior,
113114
neutralFillRestBehavior,

packages/web-components/fast-element/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
"prettier": "2.0.2",
7070
"rollup": "^2.7.6",
7171
"rollup-plugin-filesize": "^8.0.2",
72-
"rollup-plugin-minify-tagged-css-template": "^0.0.2",
7372
"rollup-plugin-terser": "^5.3.0",
73+
"rollup-plugin-transform-tagged-template": "^0.0.3",
7474
"rollup-plugin-typescript2": "^0.27.0",
7575
"source-map": "^0.7.3",
7676
"source-map-loader": "^0.2.4",

0 commit comments

Comments
 (0)