@forumone/postcss-advanced-variables 0.0.0-stage → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +108 -0
- package/README.md +575 -2
- package/index.js +730 -0
- package/index.mjs +728 -0
- package/package.json +55 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
## Statement of Purpose
|
|
4
|
+
|
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
6
|
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
|
7
|
+
subsequent owner(s) (each and all, an “owner”) of an original work of
|
|
8
|
+
authorship and/or a database (each, a “Work”).
|
|
9
|
+
|
|
10
|
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
|
11
|
+
purpose of contributing to a commons of creative, cultural and scientific works
|
|
12
|
+
(“Commons”) that the public can reliably and without fear of later claims of
|
|
13
|
+
infringement build upon, modify, incorporate in other works, reuse and
|
|
14
|
+
redistribute as freely as possible in any form whatsoever and for any purposes,
|
|
15
|
+
including without limitation commercial purposes. These owners may contribute
|
|
16
|
+
to the Commons to promote the ideal of a free culture and the further
|
|
17
|
+
production of creative, cultural and scientific works, or to gain reputation or
|
|
18
|
+
greater distribution for their Work in part through the use and efforts of
|
|
19
|
+
others.
|
|
20
|
+
|
|
21
|
+
For these and/or other purposes and motivations, and without any expectation of
|
|
22
|
+
additional consideration or compensation, the person associating CC0 with a
|
|
23
|
+
Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
|
|
24
|
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
|
|
25
|
+
publicly distribute the Work under its terms, with knowledge of his or her
|
|
26
|
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
|
27
|
+
effect of CC0 on those rights.
|
|
28
|
+
|
|
29
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
30
|
+
protected by copyright and related or neighboring rights (“Copyright and
|
|
31
|
+
Related Rights”). Copyright and Related Rights include, but are not limited
|
|
32
|
+
to, the following:
|
|
33
|
+
1. the right to reproduce, adapt, distribute, perform, display, communicate,
|
|
34
|
+
and translate a Work;
|
|
35
|
+
2. moral rights retained by the original author(s) and/or performer(s);
|
|
36
|
+
3. publicity and privacy rights pertaining to a person’s image or likeness
|
|
37
|
+
depicted in a Work;
|
|
38
|
+
4. rights protecting against unfair competition in regards to a Work,
|
|
39
|
+
subject to the limitations in paragraph 4(i), below;
|
|
40
|
+
5. rights protecting the extraction, dissemination, use and reuse of data in
|
|
41
|
+
a Work;
|
|
42
|
+
6. database rights (such as those arising under Directive 96/9/EC of the
|
|
43
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
44
|
+
protection of databases, and under any national implementation thereof,
|
|
45
|
+
including any amended or successor version of such directive); and
|
|
46
|
+
7. other similar, equivalent or corresponding rights throughout the world
|
|
47
|
+
based on applicable law or treaty, and any national implementations
|
|
48
|
+
thereof.
|
|
49
|
+
|
|
50
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
|
51
|
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
|
52
|
+
unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
|
|
53
|
+
and Related Rights and associated claims and causes of action, whether now
|
|
54
|
+
known or unknown (including existing as well as future claims and causes of
|
|
55
|
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
|
56
|
+
duration provided by applicable law or treaty (including future time
|
|
57
|
+
extensions), (iii) in any current or future medium and for any number of
|
|
58
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
|
59
|
+
commercial, advertising or promotional purposes (the “Waiver”). Affirmer
|
|
60
|
+
makes the Waiver for the benefit of each member of the public at large and
|
|
61
|
+
to the detriment of Affirmer’s heirs and successors, fully intending that
|
|
62
|
+
such Waiver shall not be subject to revocation, rescission, cancellation,
|
|
63
|
+
termination, or any other legal or equitable action to disrupt the quiet
|
|
64
|
+
enjoyment of the Work by the public as contemplated by Affirmer’s express
|
|
65
|
+
Statement of Purpose.
|
|
66
|
+
|
|
67
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
|
68
|
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
|
69
|
+
shall be preserved to the maximum extent permitted taking into account
|
|
70
|
+
Affirmer’s express Statement of Purpose. In addition, to the extent the
|
|
71
|
+
Waiver is so judged Affirmer hereby grants to each affected person a
|
|
72
|
+
royalty-free, non transferable, non sublicensable, non exclusive,
|
|
73
|
+
irrevocable and unconditional license to exercise Affirmer’s Copyright and
|
|
74
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
75
|
+
maximum duration provided by applicable law or treaty (including future time
|
|
76
|
+
extensions), (iii) in any current or future medium and for any number of
|
|
77
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
|
78
|
+
commercial, advertising or promotional purposes (the “License”). The License
|
|
79
|
+
shall be deemed effective as of the date CC0 was applied by Affirmer to the
|
|
80
|
+
Work. Should any part of the License for any reason be judged legally
|
|
81
|
+
invalid or ineffective under applicable law, such partial invalidity or
|
|
82
|
+
ineffectiveness shall not invalidate the remainder of the License, and in
|
|
83
|
+
such case Affirmer hereby affirms that he or she will not (i) exercise any
|
|
84
|
+
of his or her remaining Copyright and Related Rights in the Work or (ii)
|
|
85
|
+
assert any associated claims and causes of action with respect to the Work,
|
|
86
|
+
in either case contrary to Affirmer’s express Statement of Purpose.
|
|
87
|
+
|
|
88
|
+
4. Limitations and Disclaimers.
|
|
89
|
+
1. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
90
|
+
surrendered, licensed or otherwise affected by this document.
|
|
91
|
+
2. Affirmer offers the Work as-is and makes no representations or warranties
|
|
92
|
+
of any kind concerning the Work, express, implied, statutory or
|
|
93
|
+
otherwise, including without limitation warranties of title,
|
|
94
|
+
merchantability, fitness for a particular purpose, non infringement, or
|
|
95
|
+
the absence of latent or other defects, accuracy, or the present or
|
|
96
|
+
absence of errors, whether or not discoverable, all to the greatest
|
|
97
|
+
extent permissible under applicable law.
|
|
98
|
+
3. Affirmer disclaims responsibility for clearing rights of other persons
|
|
99
|
+
that may apply to the Work or any use thereof, including without
|
|
100
|
+
limitation any person’s Copyright and Related Rights in the Work.
|
|
101
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
102
|
+
consents, permissions or other rights required for any use of the Work.
|
|
103
|
+
4. Affirmer understands and acknowledges that Creative Commons is not a
|
|
104
|
+
party to this document and has no duty or obligation with respect to this
|
|
105
|
+
CC0 or use of the Work.
|
|
106
|
+
|
|
107
|
+
For more information, please see
|
|
108
|
+
http://creativecommons.org/publicdomain/zero/1.0/.
|
package/README.md
CHANGED
|
@@ -1,3 +1,576 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PostCSS Advanced Variables
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Forked from https://github.com/csstools/postcss-advanced-variables
|
|
4
|
+
|
|
5
|
+
[PostCSS Advanced Variables] lets you use Sass-like variables, conditionals,
|
|
6
|
+
and iterators in CSS.
|
|
7
|
+
|
|
8
|
+
```scss
|
|
9
|
+
$dir: assets/icons;
|
|
10
|
+
|
|
11
|
+
@each $icon in (foo, bar, baz) {
|
|
12
|
+
.icon-$icon {
|
|
13
|
+
background: url('$dir/$icon.png');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@for $count from 1 to 5 by 2 {
|
|
18
|
+
@if $count > 2 {
|
|
19
|
+
.col-$count {
|
|
20
|
+
width: #{$count}0%;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@import "path/to/some-file";
|
|
26
|
+
|
|
27
|
+
/* after */
|
|
28
|
+
|
|
29
|
+
.icon-foo {
|
|
30
|
+
background: url('assets/icons/foo.png');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.icon-bar {
|
|
34
|
+
background: url('assets/icons/bar.png');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.icon-baz {
|
|
38
|
+
background: url('assets/icons/baz.png');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.col-3 {
|
|
42
|
+
width: 30%;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.col-5 {
|
|
46
|
+
width: 50%;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// the contents of "path/to/_some-file.scss"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
Add [PostCSS Advanced Variables] to your build tool:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install postcss-advanced-variables --save-dev
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Node
|
|
61
|
+
|
|
62
|
+
Use [PostCSS Advanced Variables] to process your CSS:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
require('postcss-advanced-variables').process(YOUR_CSS);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### PostCSS
|
|
69
|
+
|
|
70
|
+
Add [PostCSS] to your build tool:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm install postcss --save-dev
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Use [PostCSS Advanced Variables] as a plugin:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
postcss([
|
|
80
|
+
require('postcss-advanced-variables')(/* options */)
|
|
81
|
+
]).process(YOUR_CSS);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Gulp
|
|
85
|
+
|
|
86
|
+
Add [Gulp PostCSS] to your build tool:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm install gulp-postcss --save-dev
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Use [PostCSS Advanced Variables] in your Gulpfile:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
var postcss = require('gulp-postcss');
|
|
96
|
+
|
|
97
|
+
gulp.task('css', function () {
|
|
98
|
+
return gulp.src('./src/*.css').pipe(
|
|
99
|
+
postcss([
|
|
100
|
+
require('postcss-advanced-variables')(/* options */)
|
|
101
|
+
])
|
|
102
|
+
).pipe(
|
|
103
|
+
gulp.dest('.')
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Grunt
|
|
109
|
+
|
|
110
|
+
Add [Grunt PostCSS] to your build tool:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm install grunt-postcss --save-dev
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use [PostCSS Advanced Variables] in your Gruntfile:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
grunt.loadNpmTasks('grunt-postcss');
|
|
120
|
+
|
|
121
|
+
grunt.initConfig({
|
|
122
|
+
postcss: {
|
|
123
|
+
options: {
|
|
124
|
+
use: [
|
|
125
|
+
require('postcss-advanced-variables')(/* options */)
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
dist: {
|
|
129
|
+
src: '*.css'
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Features
|
|
138
|
+
|
|
139
|
+
### $variables
|
|
140
|
+
|
|
141
|
+
Variables let you store information to be reused anywhere in a stylesheet.
|
|
142
|
+
|
|
143
|
+
Variables are set just like CSS properties, placing a `$` symbol before the
|
|
144
|
+
name of the variable (`$var-name`). They may also be set placing a `$` symbol
|
|
145
|
+
before two parentheses wrapping the name of the variable (`$(var-name)`), or by
|
|
146
|
+
wrapping the `$` symbol and variable name in curly braces preceeded by a hash
|
|
147
|
+
(`#{$var-name}`).
|
|
148
|
+
|
|
149
|
+
```scss
|
|
150
|
+
$font-size: 1.25em;
|
|
151
|
+
$font-stack: "Helvetica Neue", sans-serif;
|
|
152
|
+
$primary-color: #333;
|
|
153
|
+
|
|
154
|
+
body {
|
|
155
|
+
font: $font-size $(font-stack);
|
|
156
|
+
color: #{$primary-color};
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
*Note: To use `#{$var-name}` without issues, you will need to include the
|
|
161
|
+
[PostCSS SCSS Syntax].
|
|
162
|
+
|
|
163
|
+
In that example, `$font-size`, `$font-stack`, and `$primary-color` are replaced
|
|
164
|
+
with their values.
|
|
165
|
+
|
|
166
|
+
```css
|
|
167
|
+
body {
|
|
168
|
+
font: 1.25em "Helvetica Neue", sans-serif;
|
|
169
|
+
color: #333;
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### @if and @else Rules
|
|
174
|
+
|
|
175
|
+
Conditionals like `@if` and `@else` let you use rules in a stylesheet if they
|
|
176
|
+
evaluate true or false.
|
|
177
|
+
|
|
178
|
+
Conditionals are set by writing `@if` before the expression you want to
|
|
179
|
+
evaluate. If the expression is true, then its contents are included in the
|
|
180
|
+
stylesheet. If the expression is false, then its contents are not included, but
|
|
181
|
+
the contents of an `@else` that follows it are included.
|
|
182
|
+
|
|
183
|
+
```scss
|
|
184
|
+
$type: monster;
|
|
185
|
+
|
|
186
|
+
p {
|
|
187
|
+
@if $type == ocean {
|
|
188
|
+
color: blue;
|
|
189
|
+
} @else {
|
|
190
|
+
color: black;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
In that example, `$type === ocean` is false, so the `@if` contents are ignored
|
|
196
|
+
and the `@else` contents are used.
|
|
197
|
+
|
|
198
|
+
```css
|
|
199
|
+
p {
|
|
200
|
+
color: black;
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### @for and @each Rules
|
|
205
|
+
|
|
206
|
+
Iterators like `@for` and `@each` let you repeat content in a stylesheet.
|
|
207
|
+
|
|
208
|
+
A `@for` statement repeats by a numerical counter defined as a variable.
|
|
209
|
+
|
|
210
|
+
It can be written as `@for $counter from <start> through <end>` where
|
|
211
|
+
`$counter` is the name of the iterating variable, `<start>` is the number to
|
|
212
|
+
start with, and `<end>` is the number to finish with.
|
|
213
|
+
|
|
214
|
+
It can also be written as `@for $counter from <start> to <end>` where
|
|
215
|
+
`$counter` is still the name of the counter variable, `<start>` is still the
|
|
216
|
+
number to start with, but `<end>` is now the number to finish
|
|
217
|
+
*before, but not include*.
|
|
218
|
+
|
|
219
|
+
When `<start>` is greater than `<end>`, the counter will decrement instead of
|
|
220
|
+
increment.
|
|
221
|
+
|
|
222
|
+
Either form of `@for` can be written as
|
|
223
|
+
`@for $var from <start> to <end> by <increment>` or
|
|
224
|
+
`@for $var from <start> through <end> by <increment>`
|
|
225
|
+
where `<incremement>` is the amount the counter variable will advance.
|
|
226
|
+
|
|
227
|
+
```scss
|
|
228
|
+
@for $i from 1 through 5 by 2 {
|
|
229
|
+
.width-#{$i} {
|
|
230
|
+
width: #{$i}0em;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@for $j from 1 to 5 by 2 {
|
|
235
|
+
.height-#{$j} {
|
|
236
|
+
height: #{$j}0em;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
In that example, `$i` is repeated from 1 through 5 by 2, which means it is
|
|
242
|
+
repeated 3 times (1, 3, and 5). Meanwhile, `$j` is repeated from 1 to 5 by 2,
|
|
243
|
+
which means it is repeated 2 times (1 and 3).
|
|
244
|
+
|
|
245
|
+
```css
|
|
246
|
+
.width-1 {
|
|
247
|
+
width: 10em;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.width-3 {
|
|
251
|
+
width: 30em;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.width-5 {
|
|
255
|
+
width: 50em;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.height-1 {
|
|
259
|
+
height: 10em;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.height-3 {
|
|
263
|
+
height: 30em;
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
An `@each` statement statement repeats through a list of values.
|
|
268
|
+
|
|
269
|
+
It can be written as `@each $item in $list` where `$item` is the
|
|
270
|
+
name of the iterating variable and `$list` is the list of values being looped
|
|
271
|
+
over.
|
|
272
|
+
|
|
273
|
+
```scss
|
|
274
|
+
@each $animal in (puma, sea-slug, egret, salamander) {
|
|
275
|
+
.#{$animal}-icon {
|
|
276
|
+
background-image: url("images/icon-#{$animal}.svg");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
In that example, a list of 4 animals is looped over to create 4 unique
|
|
282
|
+
classnames.
|
|
283
|
+
|
|
284
|
+
```css
|
|
285
|
+
.puma-icon {
|
|
286
|
+
background-image: url("images/icon-puma.svg");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.sea-slug-icon {
|
|
290
|
+
background-image: url("images/icon-sea-slug.svg");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.egret-icon {
|
|
294
|
+
background-image: url("images/icon-egret.svg");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.salamander-icon {
|
|
298
|
+
background-image: url("images/icon-salamander.svg");
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
It can also be written as `@each $item $counter in $list` where `$item` is
|
|
303
|
+
still the name of the iterating variable and `$list` is still the list of values
|
|
304
|
+
being looped over, but now `$counter` is the numerical counter.
|
|
305
|
+
|
|
306
|
+
```scss
|
|
307
|
+
@each $animal $i in (puma, sea-slug, egret, salamander) {
|
|
308
|
+
.#{$animal}-icon {
|
|
309
|
+
background-image: url("images/icon-#{$i}.svg");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
```css
|
|
315
|
+
.puma-icon {
|
|
316
|
+
background-image: url("images/icon-1.svg");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.sea-slug-icon {
|
|
320
|
+
background-image: url("images/icon-2.svg");
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.egret-icon {
|
|
324
|
+
background-image: url("images/icon-3.svg");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.salamander-icon {
|
|
328
|
+
background-image: url("images/icon-4.svg");
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
In that example, a list of 4 animals is looped over to create 4 unique
|
|
333
|
+
classnames.
|
|
334
|
+
|
|
335
|
+
### @mixin, @include, and @content rules
|
|
336
|
+
|
|
337
|
+
Mixins let you reuse rule in a stylesheet. A `@mixin` defines the content you
|
|
338
|
+
want to reuse, while an `@include` rule includes it anywhere in your stylesheet.
|
|
339
|
+
|
|
340
|
+
Mixins are set by writing `@mixin` before the name of the mixin you define.
|
|
341
|
+
This can be (optionally) followed by comma-separated variables you
|
|
342
|
+
want to use inside of it. Mixins are then used anywhere by writing `@include`
|
|
343
|
+
before the name of the mixin you are using. This is (again, optionally)
|
|
344
|
+
followed by some comma-separated arguments you want to pass into the mixin as
|
|
345
|
+
the (aforementioned) variables.
|
|
346
|
+
|
|
347
|
+
```scss
|
|
348
|
+
@mixin heading-text {
|
|
349
|
+
color: #242424;
|
|
350
|
+
font-size: 4em;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
h1, h2, h3 {
|
|
354
|
+
@include heading-text;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.some-heading-component > :first-child {
|
|
358
|
+
@include heading-text;
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
In that example, `@include heading-text` is replaced with its contents.
|
|
363
|
+
|
|
364
|
+
```css
|
|
365
|
+
h1, h2, h3 {
|
|
366
|
+
color: #242424;
|
|
367
|
+
font-size: 4em;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.some-heading-component > :first-child {
|
|
371
|
+
color: #242424;
|
|
372
|
+
font-size: 4em;
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Remember, mixins can be followed by comma-separated variables you
|
|
377
|
+
want to pass into the mixin as variables.
|
|
378
|
+
|
|
379
|
+
```scss
|
|
380
|
+
@mixin heading-text($color: #242424, $font-size: 4em) {
|
|
381
|
+
color: $color;
|
|
382
|
+
font-size: $font-size;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
h1, h2, h3 {
|
|
386
|
+
@include heading-text;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.some-heading-component > :first-child {
|
|
390
|
+
@include heading-text(#111111, 6em);
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
In that example, `@include heading-text` is replaced with its contents, but
|
|
395
|
+
this time some of their contents are customized with variables.
|
|
396
|
+
|
|
397
|
+
```css
|
|
398
|
+
h1, h2, h3 {
|
|
399
|
+
color: #242424;
|
|
400
|
+
font-size: 4em;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.some-heading-component > :first-child {
|
|
404
|
+
color: #111111;
|
|
405
|
+
font-size: 6em;
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## Options
|
|
412
|
+
|
|
413
|
+
### variables
|
|
414
|
+
|
|
415
|
+
The `variables` option defines global variables used when they cannot be
|
|
416
|
+
resolved automatically.
|
|
417
|
+
|
|
418
|
+
```js
|
|
419
|
+
require('postcss-advanced-variables')({
|
|
420
|
+
variables: {
|
|
421
|
+
'site-width': '960px'
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
The `variables` option also accepts a function, which is given 2 arguments; the
|
|
427
|
+
name of the unresolved variable, and the PostCSS node that used it.
|
|
428
|
+
|
|
429
|
+
```js
|
|
430
|
+
require('postcss-advanced-variables')({
|
|
431
|
+
variables(name, node) {
|
|
432
|
+
if (name === 'site-width') {
|
|
433
|
+
return '960px';
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
```scss
|
|
442
|
+
.hero {
|
|
443
|
+
max-width: $site-width;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/* after */
|
|
447
|
+
|
|
448
|
+
.hero {
|
|
449
|
+
max-width: 960px;
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### unresolved
|
|
454
|
+
|
|
455
|
+
The `unresolved` option defines how unresolved variables, mixins, and imports
|
|
456
|
+
should be handled. The available options are `throw`, `warn`, and `ignore`. The
|
|
457
|
+
default option is to `throw`.
|
|
458
|
+
|
|
459
|
+
```js
|
|
460
|
+
require('postcss-advanced-variables')({
|
|
461
|
+
unresolved: 'ignore' // ignore unresolved variables
|
|
462
|
+
});
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### disable
|
|
466
|
+
|
|
467
|
+
The `disable` option defines which features should be disabled in
|
|
468
|
+
[PostCSS Advanced Variables].
|
|
469
|
+
|
|
470
|
+
The `disable` option can be a string or an array, and the features that can be
|
|
471
|
+
disabled are `@content`, `@each`, `@else`, `@if`, `@include`, `@import`, `@for`,
|
|
472
|
+
and `@mixin`.
|
|
473
|
+
|
|
474
|
+
```js
|
|
475
|
+
require('postcss-advanced-variables')({
|
|
476
|
+
disable: '@mixin, @include, @content' // ignore @mixin, @include, and @content at-rules
|
|
477
|
+
});
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### Import Options
|
|
481
|
+
|
|
482
|
+
These options only apply to the `@import` at-rule.
|
|
483
|
+
|
|
484
|
+
#### importPaths
|
|
485
|
+
|
|
486
|
+
The `importPaths` option defines a path or multiple paths used to lookup
|
|
487
|
+
files when they cannot be found automatically.
|
|
488
|
+
|
|
489
|
+
The `importPaths` option can be a string or an array.
|
|
490
|
+
|
|
491
|
+
By default, imports are resolved using the [Sass Import Resolve Specification].
|
|
492
|
+
|
|
493
|
+
```js
|
|
494
|
+
require('postcss-advanced-variables')({
|
|
495
|
+
importPaths: ['path/to/files', 'another/path/to/files']
|
|
496
|
+
});
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
#### importResolve
|
|
500
|
+
|
|
501
|
+
The `importResolve` option defines the file resolver used by imports. It is a
|
|
502
|
+
function given 3 arguments; the url id, the current working directory, and the
|
|
503
|
+
options processed by [PostCSS Advanced Variables].
|
|
504
|
+
|
|
505
|
+
The `importResolve` function should return a Promise with an object containing
|
|
506
|
+
the full path (`file`) and the contents of the file (`contents`).
|
|
507
|
+
|
|
508
|
+
```js
|
|
509
|
+
const resolve = require('custom-resolver');
|
|
510
|
+
|
|
511
|
+
require('postcss-advanced-variables')({
|
|
512
|
+
// a resolver may work many ways, and this is just an example
|
|
513
|
+
importResolve: (id, cwd, opts) => resolve({ id, cwd });
|
|
514
|
+
});
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
#### importFilter
|
|
518
|
+
|
|
519
|
+
The `importFilter` option determines whether an import will be inlined.
|
|
520
|
+
|
|
521
|
+
The value can be a function or an regular expression. When
|
|
522
|
+
providing a function, it is called with a single string argument `id`
|
|
523
|
+
and returns true when the import should be inlined. When providing a
|
|
524
|
+
regular expression, if the `id` matches the expression, the import will
|
|
525
|
+
be inlined.
|
|
526
|
+
|
|
527
|
+
By default, imports are ignored if they begin with a protocol or
|
|
528
|
+
protocol-relative slashes (`//`).
|
|
529
|
+
|
|
530
|
+
```js
|
|
531
|
+
require('postcss-advanced-variables')({
|
|
532
|
+
importFilter: (id) => {
|
|
533
|
+
return ['ignore', 'these', 'imports'].contains(id);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
#### importRoot
|
|
539
|
+
|
|
540
|
+
The `importRoot` option defines the root directory used by imports when the
|
|
541
|
+
current directory cannot be detected. Its default value is `process.cwd()`.
|
|
542
|
+
|
|
543
|
+
```js
|
|
544
|
+
require('postcss-advanced-variables')({
|
|
545
|
+
importRoot: 'path/to/root'
|
|
546
|
+
});
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
#### importCache
|
|
550
|
+
|
|
551
|
+
The `importCache` option defines a cache made available to the options object
|
|
552
|
+
that may be used by the [file resolver](#importResolve).
|
|
553
|
+
|
|
554
|
+
```js
|
|
555
|
+
const sharedCache = {};
|
|
556
|
+
|
|
557
|
+
require('postcss-advanced-variables')({
|
|
558
|
+
importCache: sharedCache
|
|
559
|
+
});
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-advanced-variables.svg
|
|
563
|
+
[cli-url]: https://travis-ci.org/jonathantneal/postcss-advanced-variables
|
|
564
|
+
[test-img]: https://github.com/csstools/postcss-advanced-variables/actions/workflows/test.yml/badge.svg
|
|
565
|
+
[test-url]: https://github.com/csstools/postcss-advanced-variables/actions/workflows/test.yml
|
|
566
|
+
[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg
|
|
567
|
+
[git-url]: https://gitter.im/postcss/postcss
|
|
568
|
+
[npm-img]: https://img.shields.io/npm/v/postcss-advanced-variables.svg
|
|
569
|
+
[npm-url]: https://www.npmjs.com/package/postcss-advanced-variables
|
|
570
|
+
|
|
571
|
+
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|
572
|
+
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|
573
|
+
[PostCSS]: https://github.com/postcss/postcss
|
|
574
|
+
[PostCSS Advanced Variables]: https://github.com/jonathantneal/postcss-advanced-variables
|
|
575
|
+
[PostCSS SCSS Syntax]: https://github.com/postcss/postcss-scss
|
|
576
|
+
[Sass Import Resolve Specification]: https://jonathantneal.github.io/sass-import-resolve/
|