Skip to content

Commit f75edb4

Browse files
jonathantnealromainmenke
authored andcommitted
7.0.4
1 parent c500635 commit f75edb4

13 files changed

+77
-5
lines changed

plugins/postcss-custom-media/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Custom Media
22

3+
### 7.0.4 (September 23, 2018)
4+
5+
- Added: `importFromPlugins` option to process imports
6+
37
### 7.0.3 (September 20, 2018)
48

59
- Fixed: Do not break on an empty `importFrom` object

plugins/postcss-custom-media/lib/export-to.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function exportCustomMediaToDestinations(customMedia, destination
8080
const to = String(opts.to || '');
8181

8282
// type of file being written to
83-
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase();
83+
const type = (opts.type || path.extname(to).slice(1)).toLowerCase();
8484

8585
// transformed custom media
8686
const customMediaJSON = toJSON(customMedia);

plugins/postcss-custom-media/lib/media-ast-from-string.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MediaQuery {
6565
constructor(string) {
6666
const [, before, media, after ] = string.match(spaceWrapRegExp);
6767
const [, modifier = '', afterModifier = ' ', type = '', beforeAnd = '', and = '', beforeExpression = '', expression1 = '', expression2 = ''] = media.match(mediaRegExp) || [];
68-
const raws = { before, after, afterModifier, originalModifier: modifier || 'not', beforeAnd, and, beforeExpression };
68+
const raws = { before, after, afterModifier, originalModifier: modifier || '', beforeAnd, and, beforeExpression };
6969
const nodes = parse(expression1 || expression2, true);
7070

7171
Object.assign(this, {

plugins/postcss-custom-media/lib/transform-media-list.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ function transformMedia(media, customMedias) {
3535
raws: !modifier || media.modifier
3636
? { ...media.raws }
3737
: { ...replacementMedia.raws },
38-
type: media.type || replacementMedia.type
38+
type: media.type || replacementMedia.type,
3939
});
4040

41+
// conditionally include more replacement raws when the type is present
42+
if (mediaClone.type === replacementMedia.type) {
43+
Object.assign(mediaClone.raws, {
44+
and: replacementMedia.raws.and,
45+
beforeAnd: replacementMedia.raws.beforeAnd,
46+
beforeExpression: replacementMedia.raws.beforeExpression
47+
});
48+
}
49+
4150
mediaClone.nodes.splice(index, 1, ...replacementMedia.clone().nodes.map(node => {
4251
// use spacing from the current usage
4352
node.spaces = { ...media.nodes[index].spaces };

plugins/postcss-custom-media/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-custom-media",
3-
"version": "7.0.3",
3+
"version": "7.0.4",
44
"description": "Use Custom Media Queries in CSS",
55
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
66
"contributors": [
@@ -38,7 +38,7 @@
3838
"eslint-config-dev": "^2.0.0",
3939
"postcss-tape": "^2.2.0",
4040
"pre-commit": "^1.2.2",
41-
"rollup": "^0.66.1",
41+
"rollup": "^0.66.2",
4242
"rollup-plugin-babel": "^4.0.3"
4343
},
4444
"eslintConfig": {

plugins/postcss-custom-media/test/basic.css

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@custom-media --mq-a (max-width: 30em), (max-height: 30em);
2+
@custom-media --mq-b screen and (max-width: 30em);
23
@custom-media --not-mq-a not all and (--mq-a);
34

45
@media (--mq-a) {
@@ -7,6 +8,12 @@
78
}
89
}
910

11+
@media (--mq-b) {
12+
body {
13+
order: 1;
14+
}
15+
}
16+
1017
@media (--mq-a), (--mq-a) {
1118
body {
1219
order: 1;

plugins/postcss-custom-media/test/basic.expect.css

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
}
55
}
66

7+
@media screen and (max-width: 30em) {
8+
body {
9+
order: 1;
10+
}
11+
}
12+
713
@media (max-width: 30em),(max-height: 30em), (max-width: 30em), (max-height: 30em) {
814
body {
915
order: 1;

plugins/postcss-custom-media/test/basic.preserve.expect.css

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@custom-media --mq-a (max-width: 30em), (max-height: 30em);
2+
@custom-media --mq-b screen and (max-width: 30em);
23
@custom-media --not-mq-a not all and (--mq-a);
34

45
@media (max-width: 30em),(max-height: 30em) {
@@ -13,6 +14,18 @@
1314
}
1415
}
1516

17+
@media screen and (max-width: 30em) {
18+
body {
19+
order: 1;
20+
}
21+
}
22+
23+
@media (--mq-b) {
24+
body {
25+
order: 1;
26+
}
27+
}
28+
1629
@media (max-width: 30em),(max-height: 30em), (max-width: 30em), (max-height: 30em) {
1730
body {
1831
order: 1;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@custom-media --mq-a (max-width: 30em), (max-height: 30em);
2+
@custom-media --mq-b screen and (max-width: 30em);
23
@custom-media --not-mq-a not all and (--mq-a);
34
@custom-media --circular-mq-a (--circular-mq-b);
45
@custom-media --circular-mq-b (--circular-mq-a);

plugins/postcss-custom-media/test/export-media.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
customMedia: {
33
'--mq-a': '(max-width: 30em), (max-height: 30em)',
4+
'--mq-b': 'screen and (max-width: 30em)',
45
'--not-mq-a': 'not all and (--mq-a)',
56
'--circular-mq-a': '(--circular-mq-b)',
67
'--circular-mq-b': '(--circular-mq-a)'

plugins/postcss-custom-media/test/export-media.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"custom-media": {
33
"--mq-a": "(max-width: 30em), (max-height: 30em)",
4+
"--mq-b": "screen and (max-width: 30em)",
45
"--not-mq-a": "not all and (--mq-a)",
56
"--circular-mq-a": "(--circular-mq-b)",
67
"--circular-mq-b": "(--circular-mq-a)"

plugins/postcss-custom-media/test/export-media.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const customMedia = {
22
'--mq-a': '(max-width: 30em), (max-height: 30em)',
3+
'--mq-b': 'screen and (max-width: 30em)',
34
'--not-mq-a': 'not all and (--mq-a)',
45
'--circular-mq-a': '(--circular-mq-b)',
56
'--circular-mq-b': '(--circular-mq-a)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@media (max-width: 30em),(max-height: 30em) {
2+
body {
3+
order: 1;
4+
}
5+
}
6+
7+
@media (max-width: 30em),(max-height: 30em), (max-width: 30em), (max-height: 30em) {
8+
body {
9+
order: 1;
10+
}
11+
}
12+
13+
@media not all and (max-width: 30em),not all and (max-height: 30em) {
14+
body {
15+
order: 2;
16+
}
17+
}
18+
19+
@media not all and (max-width: 30em),not all and (max-height: 30em) {
20+
body {
21+
order: 1;
22+
}
23+
}
24+
25+
@media all and (max-width: 30em),all and (max-height: 30em) {
26+
body {
27+
order: 2;
28+
}
29+
}

0 commit comments

Comments
 (0)