postcss-convert-values 6.0.4 → 6.1.0
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/package.json +1 -1
- package/src/index.js +26 -9
- package/types/index.d.ts +18 -7
- package/types/index.d.ts.map +1 -0
- package/types/lib/convert.d.ts +1 -0
- package/types/lib/convert.d.ts.map +1 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
const { dirname } = require('path');
|
|
2
3
|
const valueParser = require('postcss-value-parser');
|
|
3
4
|
const browserslist = require('browserslist');
|
|
4
5
|
const convert = require('./lib/convert.js');
|
|
@@ -114,6 +115,7 @@ function clampOpacity(node) {
|
|
|
114
115
|
function shouldKeepZeroUnit(decl, browsers) {
|
|
115
116
|
const { parent } = decl;
|
|
116
117
|
const lowerCasedProp = decl.prop.toLowerCase();
|
|
118
|
+
|
|
117
119
|
return (
|
|
118
120
|
(decl.value.includes('%') &&
|
|
119
121
|
keepZeroPercent.has(lowerCasedProp) &&
|
|
@@ -194,24 +196,39 @@ function transform(opts, browsers, decl) {
|
|
|
194
196
|
}
|
|
195
197
|
|
|
196
198
|
const plugin = 'postcss-convert-values';
|
|
199
|
+
|
|
197
200
|
/**
|
|
198
|
-
* @typedef {
|
|
201
|
+
* @typedef {Parameters<typeof convert>[2]} ConvertOptions
|
|
202
|
+
* @typedef {{ overrideBrowserslist?: string | string[] }} AutoprefixerOptions
|
|
203
|
+
* @typedef {Pick<browserslist.Options, 'stats' | 'path' | 'env'>} BrowserslistOptions
|
|
204
|
+
* @typedef {{precision?: false | number} & ConvertOptions & AutoprefixerOptions & BrowserslistOptions} Options
|
|
205
|
+
*/
|
|
206
|
+
|
|
199
207
|
/**
|
|
200
208
|
* @type {import('postcss').PluginCreator<Options>}
|
|
201
209
|
* @param {Options} opts
|
|
202
210
|
* @return {import('postcss').Plugin}
|
|
203
211
|
*/
|
|
204
212
|
function pluginCreator(opts = { precision: false }) {
|
|
205
|
-
const browsers = browserslist(null, {
|
|
206
|
-
stats: opts.stats,
|
|
207
|
-
path: __dirname,
|
|
208
|
-
env: opts.env,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
213
|
return {
|
|
212
214
|
postcssPlugin: plugin,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @param {import('postcss').Result & {opts: BrowserslistOptions & {file?: string}}} result
|
|
218
|
+
*/
|
|
219
|
+
prepare(result) {
|
|
220
|
+
const { stats, env, from, file } = result.opts || {};
|
|
221
|
+
const browsers = browserslist(opts.overrideBrowserslist, {
|
|
222
|
+
stats: opts.stats || stats,
|
|
223
|
+
path: opts.path || dirname(from || file || __filename),
|
|
224
|
+
env: opts.env || env,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
OnceExit(css) {
|
|
229
|
+
css.walkDecls((decl) => transform(opts, browsers, decl));
|
|
230
|
+
},
|
|
231
|
+
};
|
|
215
232
|
},
|
|
216
233
|
};
|
|
217
234
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export = pluginCreator;
|
|
2
2
|
/**
|
|
3
|
-
* @typedef {
|
|
3
|
+
* @typedef {Parameters<typeof convert>[2]} ConvertOptions
|
|
4
|
+
* @typedef {{ overrideBrowserslist?: string | string[] }} AutoprefixerOptions
|
|
5
|
+
* @typedef {Pick<browserslist.Options, 'stats' | 'path' | 'env'>} BrowserslistOptions
|
|
6
|
+
* @typedef {{precision?: false | number} & ConvertOptions & AutoprefixerOptions & BrowserslistOptions} Options
|
|
7
|
+
*/
|
|
4
8
|
/**
|
|
5
9
|
* @type {import('postcss').PluginCreator<Options>}
|
|
6
10
|
* @param {Options} opts
|
|
@@ -8,13 +12,20 @@ export = pluginCreator;
|
|
|
8
12
|
*/
|
|
9
13
|
declare function pluginCreator(opts?: Options): import('postcss').Plugin;
|
|
10
14
|
declare namespace pluginCreator {
|
|
11
|
-
export { postcss, Options };
|
|
15
|
+
export { postcss, ConvertOptions, AutoprefixerOptions, BrowserslistOptions, Options };
|
|
12
16
|
}
|
|
13
17
|
type Options = {
|
|
14
|
-
precision
|
|
15
|
-
|
|
16
|
-
time?: boolean;
|
|
17
|
-
length?: boolean;
|
|
18
|
-
} & browserslist.Options;
|
|
18
|
+
precision?: false | number;
|
|
19
|
+
} & ConvertOptions & AutoprefixerOptions & BrowserslistOptions;
|
|
19
20
|
declare var postcss: true;
|
|
21
|
+
type ConvertOptions = [number: number, unit: string, {
|
|
22
|
+
time?: boolean | undefined;
|
|
23
|
+
length?: boolean | undefined;
|
|
24
|
+
angle?: boolean | undefined;
|
|
25
|
+
}][2];
|
|
26
|
+
type AutoprefixerOptions = {
|
|
27
|
+
overrideBrowserslist?: string | string[];
|
|
28
|
+
};
|
|
29
|
+
type BrowserslistOptions = Pick<browserslist.Options, 'stats' | 'path' | 'env'>;
|
|
20
30
|
import browserslist = require("browserslist");
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAuMA;;;;;GAKG;AAEH;;;;GAIG;AACH,sCAHW,OAAO,GACN,OAAO,SAAS,EAAE,MAAM,CAwBnC;;;;eA9BY;IAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;CAAC,GAAG,cAAc,GAAG,mBAAmB,GAAG,mBAAmB;;sBAHzF;;;;GAA2B,CAAC,CAAC;2BAC7B;IAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE;2BAC5C,KAAK,oBAAoB,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC"}
|
package/types/lib/convert.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/lib/convert.js"],"names":[],"mappings":"AA+DiB,kCALN,MAAM,QACN,MAAM,2BACN;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAC,GAClD,MAAM,CAuBjB"}
|