cssnano-preset-default 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cssnano-preset-default",
3
- "version": "6.0.4",
3
+ "version": "6.1.0",
4
4
  "main": "src/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "description": "Safe defaults for cssnano which require minimal configuration.",
@@ -11,35 +11,36 @@
11
11
  ],
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
+ "browserslist": "^4.23.0",
14
15
  "css-declaration-sorter": "^7.1.1",
15
16
  "postcss-calc": "^9.0.1",
16
- "cssnano-utils": "^4.0.1",
17
- "postcss-colormin": "^6.0.2",
18
- "postcss-convert-values": "^6.0.3",
19
- "postcss-discard-comments": "^6.0.1",
20
- "postcss-discard-duplicates": "^6.0.2",
21
- "postcss-discard-empty": "^6.0.2",
22
- "postcss-discard-overridden": "^6.0.1",
23
- "postcss-merge-longhand": "^6.0.2",
24
- "postcss-merge-rules": "^6.0.3",
25
- "postcss-minify-font-values": "^6.0.1",
26
- "postcss-minify-gradients": "^6.0.1",
27
- "postcss-minify-params": "^6.0.2",
28
- "postcss-minify-selectors": "^6.0.2",
29
- "postcss-normalize-charset": "^6.0.1",
30
- "postcss-normalize-display-values": "^6.0.1",
31
- "postcss-normalize-positions": "^6.0.1",
32
- "postcss-normalize-repeat-style": "^6.0.1",
33
- "postcss-normalize-string": "^6.0.1",
34
- "postcss-normalize-timing-functions": "^6.0.1",
35
- "postcss-normalize-unicode": "^6.0.2",
36
- "postcss-normalize-url": "^6.0.1",
37
- "postcss-normalize-whitespace": "^6.0.1",
38
- "postcss-ordered-values": "^6.0.1",
39
- "postcss-reduce-initial": "^6.0.2",
40
- "postcss-reduce-transforms": "^6.0.1",
41
- "postcss-svgo": "^6.0.2",
42
- "postcss-unique-selectors": "^6.0.2"
17
+ "cssnano-utils": "^4.0.2",
18
+ "postcss-colormin": "^6.1.0",
19
+ "postcss-convert-values": "^6.1.0",
20
+ "postcss-discard-comments": "^6.0.2",
21
+ "postcss-discard-duplicates": "^6.0.3",
22
+ "postcss-discard-empty": "^6.0.3",
23
+ "postcss-discard-overridden": "^6.0.2",
24
+ "postcss-merge-longhand": "^6.0.4",
25
+ "postcss-merge-rules": "^6.1.0",
26
+ "postcss-minify-font-values": "^6.0.3",
27
+ "postcss-minify-gradients": "^6.0.3",
28
+ "postcss-minify-params": "^6.1.0",
29
+ "postcss-minify-selectors": "^6.0.3",
30
+ "postcss-normalize-charset": "^6.0.2",
31
+ "postcss-normalize-display-values": "^6.0.2",
32
+ "postcss-normalize-positions": "^6.0.2",
33
+ "postcss-normalize-repeat-style": "^6.0.2",
34
+ "postcss-normalize-string": "^6.0.2",
35
+ "postcss-normalize-timing-functions": "^6.0.2",
36
+ "postcss-normalize-unicode": "^6.1.0",
37
+ "postcss-normalize-url": "^6.0.2",
38
+ "postcss-normalize-whitespace": "^6.0.2",
39
+ "postcss-ordered-values": "^6.0.2",
40
+ "postcss-reduce-initial": "^6.1.0",
41
+ "postcss-reduce-transforms": "^6.0.2",
42
+ "postcss-svgo": "^6.0.3",
43
+ "postcss-unique-selectors": "^6.0.3"
43
44
  },
44
45
  "author": {
45
46
  "name": "Ben Briggs",
package/src/index.js CHANGED
@@ -43,89 +43,153 @@ const postcssNormalizeDisplayValues = require('postcss-normalize-display-values'
43
43
  const postcssNormalizeTimingFunctions = require('postcss-normalize-timing-functions');
44
44
  const { rawCache } = require('cssnano-utils');
45
45
 
46
- /** @typedef {{
47
- discardComments?: false | import('postcss-discard-comments').Options & { exclude?: true},
48
- reduceInitial?: false | { exclude?: true}
49
- minifyGradients?: false | { exclude?: true}
50
- svgo?: false | import('postcss-svgo').Options & { exclude?: true},
51
- reduceTransforms?: false | { exclude?: true}
52
- convertValues?: false | import('postcss-convert-values').Options & { exclude?: true},
53
- calc?: false | import('postcss-calc').PostCssCalcOptions & { exclude?: true},
54
- colormin?: false | Record<string, any> & { exclude?: true},
55
- orderedValues?: false | { exclude?: true},
56
- minifySelectors?: false | { exclude?: true},
57
- minifyParams?: false | { exclude?: true},
58
- normalizeCharset?: false | import('postcss-normalize-charset').Options & { exclude?: true},
59
- minifyFontValues?: false | import('postcss-minify-font-values').Options & { exclude?: true},
60
- normalizeUrl?: false | { exclude?: true},
61
- mergeLonghand?: false | { exclude?: true},
62
- discardDuplicates?: false | { exclude?: true},
63
- discardOverridden?: false | { exclude?: true},
64
- normalizeRepeatStyle?: false | { exclude?: true},
65
- mergeRules?: false | { exclude?: true},
66
- discardEmpty?: false | { exclude?: true},
67
- uniqueSelectors?: false | { exclude?: true},
68
- normalizeString?: false | import('postcss-normalize-string').Options & { exclude?: true},
69
- normalizePositions?: false | { exclude?: true},
70
- normalizeWhitespace?: false| { exclude?: true},
71
- normalizeUnicode?: false | { exclude?: true},
72
- normalizeDisplayValues?: false | { exclude?: true},
73
- normalizeTimingFunctions?: false | { exclude?: true},
74
- rawCache?: false | { exclude?: true}}} Options */
46
+ /**
47
+ * @template {object | void} [OptionsExtends=void]
48
+ * @typedef {false | OptionsExtends & {exclude?: true}} SimpleOptions
49
+ */
50
+
51
+ /**
52
+ * @typedef {object} Options
53
+ * @property {SimpleOptions<Parameters<typeof cssDeclarationSorter>[0]>} [cssDeclarationSorter]
54
+ * @property {SimpleOptions<import('postcss-discard-comments').Options>} [discardComments]
55
+ * @property {SimpleOptions<import('postcss-reduce-initial').Options>} [reduceInitial]
56
+ * @property {SimpleOptions} [minifyGradients]
57
+ * @property {SimpleOptions<import('postcss-svgo').Options>} [svgo]
58
+ * @property {SimpleOptions} [reduceTransforms]
59
+ * @property {SimpleOptions<import('postcss-convert-values').Options>} [convertValues]
60
+ * @property {SimpleOptions<import('postcss-calc').PostCssCalcOptions>} [calc]
61
+ * @property {SimpleOptions<import('postcss-colormin').Options>} [colormin]
62
+ * @property {SimpleOptions} [orderedValues]
63
+ * @property {SimpleOptions} [minifySelectors]
64
+ * @property {SimpleOptions<import('postcss-minify-params').Options>} [minifyParams]
65
+ * @property {SimpleOptions<import('postcss-normalize-charset').Options>} [normalizeCharset]
66
+ * @property {SimpleOptions<import('postcss-minify-font-values').Options>} [minifyFontValues]
67
+ * @property {SimpleOptions} [normalizeUrl]
68
+ * @property {SimpleOptions} [mergeLonghand]
69
+ * @property {SimpleOptions} [discardDuplicates]
70
+ * @property {SimpleOptions} [discardOverridden]
71
+ * @property {SimpleOptions} [normalizeRepeatStyle]
72
+ * @property {SimpleOptions<import('postcss-merge-rules').Options>} [mergeRules]
73
+ * @property {SimpleOptions} [discardEmpty]
74
+ * @property {SimpleOptions} [uniqueSelectors]
75
+ * @property {SimpleOptions<import('postcss-normalize-string').Options>} [normalizeString]
76
+ * @property {SimpleOptions} [normalizePositions]
77
+ * @property {SimpleOptions} [normalizeWhitespace]
78
+ * @property {SimpleOptions<import('postcss-normalize-unicode').Options>} [normalizeUnicode]
79
+ * @property {SimpleOptions} [normalizeDisplayValues]
80
+ * @property {SimpleOptions} [normalizeTimingFunctions]
81
+ * @property {SimpleOptions} [rawCache]
82
+ */
75
83
 
76
- const defaultOpts = {
77
- convertValues: {
78
- length: false,
79
- },
80
- normalizeCharset: {
81
- add: false,
82
- },
83
- cssDeclarationSorter: {
84
- keepOverrides: true,
85
- },
86
- };
84
+ /**
85
+ * @typedef {{ overrideBrowserslist?: string | string[] }} AutoprefixerOptions
86
+ * @typedef {Pick<import('browserslist').Options, 'stats' | 'path' | 'env'>} BrowserslistOptions
87
+ */
87
88
 
88
89
  /**
89
- * @param {Options} opts
90
- * @return {{plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
90
+ * @param {[import('postcss').PluginCreator<any>, keyof Options][]} plugins
91
+ * @param {Parameters<typeof defaultPreset>[0]} opts
92
+ * @returns {ReturnType<typeof defaultPreset>["plugins"]}
91
93
  */
92
- function defaultPreset(opts = {}) {
93
- const options = Object.assign({}, defaultOpts, opts);
94
+ function configurePlugins(plugins, opts = {}) {
95
+ const { overrideBrowserslist, stats, env, path } = opts;
94
96
 
95
- /** @type {[import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]} **/
96
- const plugins = [
97
- [postcssDiscardComments, options.discardComments],
98
- [postcssMinifyGradients, options.minifyGradients],
99
- [postcssReduceInitial, options.reduceInitial],
100
- [postcssSvgo, options.svgo],
101
- [postcssNormalizeDisplayValues, options.normalizeDisplayValues],
102
- [postcssReduceTransforms, options.reduceTransforms],
103
- [postcssColormin, options.colormin],
104
- [postcssNormalizeTimingFunctions, options.normalizeTimingFunctions],
105
- [postcssCalc, options.calc],
106
- [postcssConvertValues, options.convertValues],
107
- [postcssOrderedValues, options.orderedValues],
108
- [postcssMinifySelectors, options.minifySelectors],
109
- [postcssMinifyParams, options.minifyParams],
110
- [postcssNormalizeCharset, options.normalizeCharset],
111
- [postcssDiscardOverridden, options.discardOverridden],
112
- [postcssNormalizeString, options.normalizeString],
113
- [postcssNormalizeUnicode, options.normalizeUnicode],
114
- [postcssMinifyFontValues, options.minifyFontValues],
115
- [postcssNormalizeUrl, options.normalizeUrl],
116
- [postcssNormalizeRepeatStyle, options.normalizeRepeatStyle],
117
- [postcssNormalizePositions, options.normalizePositions],
118
- [postcssNormalizeWhitespace, options.normalizeWhitespace],
119
- [postcssMergeLonghand, options.mergeLonghand],
120
- [postcssDiscardDuplicates, options.discardDuplicates],
121
- [postcssMergeRules, options.mergeRules],
122
- [postcssDiscardEmpty, options.discardEmpty],
123
- [postcssUniqueSelectors, options.uniqueSelectors],
124
- [cssDeclarationSorter, options.cssDeclarationSorter],
125
- [rawCache, options.rawCache],
126
- ];
97
+ // Shared Autoprefixer + Browserslist options
98
+ const sharedProps = {
99
+ overrideBrowserslist,
100
+ stats,
101
+ env,
102
+ path,
103
+ };
127
104
 
128
- return { plugins };
105
+ /**
106
+ * @type {Options}
107
+ */
108
+ const defaults = {
109
+ colormin: {
110
+ ...sharedProps,
111
+ },
112
+ convertValues: {
113
+ length: false,
114
+ ...sharedProps,
115
+ },
116
+ mergeRules: {
117
+ ...sharedProps,
118
+ },
119
+ minifyParams: {
120
+ ...sharedProps,
121
+ },
122
+ normalizeCharset: {
123
+ add: false,
124
+ },
125
+ normalizeUnicode: {
126
+ ...sharedProps,
127
+ },
128
+ reduceInitial: {
129
+ ...sharedProps,
130
+ },
131
+ cssDeclarationSorter: {
132
+ keepOverrides: true,
133
+ },
134
+ };
135
+
136
+ // Merge option properties for each plugin
137
+ return plugins.map(([plugin, opt]) => {
138
+ const defaultProps = defaults[opt] ?? {};
139
+ const presetProps = opts[opt] ?? {};
140
+
141
+ return [
142
+ plugin,
143
+ presetProps !== false
144
+ ? { ...defaultProps, ...presetProps }
145
+ : { exclude: true },
146
+ ];
147
+ });
148
+ }
149
+
150
+ /**
151
+ * Safe defaults for cssnano which require minimal configuration
152
+ *
153
+ * @param {Options & AutoprefixerOptions & BrowserslistOptions} opts
154
+ * @returns {{ plugins: [import('postcss').PluginCreator<any>, Options[keyof Options]][] }}
155
+ */
156
+ function defaultPreset(opts = {}) {
157
+ return {
158
+ plugins: configurePlugins(
159
+ [
160
+ [postcssDiscardComments, 'discardComments'],
161
+ [postcssMinifyGradients, 'minifyGradients'],
162
+ [postcssReduceInitial, 'reduceInitial'],
163
+ [postcssSvgo, 'svgo'],
164
+ [postcssNormalizeDisplayValues, 'normalizeDisplayValues'],
165
+ [postcssReduceTransforms, 'reduceTransforms'],
166
+ [postcssColormin, 'colormin'],
167
+ [postcssNormalizeTimingFunctions, 'normalizeTimingFunctions'],
168
+ [postcssCalc, 'calc'],
169
+ [postcssConvertValues, 'convertValues'],
170
+ [postcssOrderedValues, 'orderedValues'],
171
+ [postcssMinifySelectors, 'minifySelectors'],
172
+ [postcssMinifyParams, 'minifyParams'],
173
+ [postcssNormalizeCharset, 'normalizeCharset'],
174
+ [postcssDiscardOverridden, 'discardOverridden'],
175
+ [postcssNormalizeString, 'normalizeString'],
176
+ [postcssNormalizeUnicode, 'normalizeUnicode'],
177
+ [postcssMinifyFontValues, 'minifyFontValues'],
178
+ [postcssNormalizeUrl, 'normalizeUrl'],
179
+ [postcssNormalizeRepeatStyle, 'normalizeRepeatStyle'],
180
+ [postcssNormalizePositions, 'normalizePositions'],
181
+ [postcssNormalizeWhitespace, 'normalizeWhitespace'],
182
+ [postcssMergeLonghand, 'mergeLonghand'],
183
+ [postcssDiscardDuplicates, 'discardDuplicates'],
184
+ [postcssMergeRules, 'mergeRules'],
185
+ [postcssDiscardEmpty, 'discardEmpty'],
186
+ [postcssUniqueSelectors, 'uniqueSelectors'],
187
+ [cssDeclarationSorter, 'cssDeclarationSorter'],
188
+ [rawCache, 'rawCache'],
189
+ ],
190
+ opts
191
+ ),
192
+ };
129
193
  }
130
194
 
131
195
  module.exports = defaultPreset;
package/types/index.d.ts CHANGED
@@ -1,98 +1,67 @@
1
1
  export = defaultPreset;
2
2
  /**
3
- * @param {Options} opts
4
- * @return {{plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
3
+ * Safe defaults for cssnano which require minimal configuration
4
+ *
5
+ * @param {Options & AutoprefixerOptions & BrowserslistOptions} opts
6
+ * @returns {{ plugins: [import('postcss').PluginCreator<any>, Options[keyof Options]][] }}
5
7
  */
6
- declare function defaultPreset(opts?: Options): {
7
- plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][];
8
+ declare function defaultPreset(opts?: Options & AutoprefixerOptions & BrowserslistOptions): {
9
+ plugins: [import('postcss').PluginCreator<any>, Options[keyof Options]][];
8
10
  };
9
11
  declare namespace defaultPreset {
10
- export { Options };
12
+ export { SimpleOptions, Options, AutoprefixerOptions, BrowserslistOptions };
11
13
  }
12
14
  type Options = {
13
- discardComments?: false | import('postcss-discard-comments').Options & {
14
- exclude?: true;
15
- };
16
- reduceInitial?: false | {
17
- exclude?: true;
18
- };
19
- minifyGradients?: false | {
20
- exclude?: true;
21
- };
22
- svgo?: false | import('postcss-svgo').Options & {
23
- exclude?: true;
24
- };
25
- reduceTransforms?: false | {
26
- exclude?: true;
27
- };
28
- convertValues?: false | import('postcss-convert-values').Options & {
29
- exclude?: true;
30
- };
31
- calc?: false | import('postcss-calc').PostCssCalcOptions & {
32
- exclude?: true;
33
- };
34
- colormin?: false | (Record<string, any> & {
35
- exclude?: true;
36
- });
37
- orderedValues?: false | {
38
- exclude?: true;
39
- };
40
- minifySelectors?: false | {
41
- exclude?: true;
42
- };
43
- minifyParams?: false | {
44
- exclude?: true;
45
- };
46
- normalizeCharset?: false | import('postcss-normalize-charset').Options & {
47
- exclude?: true;
48
- };
49
- minifyFontValues?: false | import('postcss-minify-font-values').Options & {
50
- exclude?: true;
51
- };
52
- normalizeUrl?: false | {
53
- exclude?: true;
54
- };
55
- mergeLonghand?: false | {
56
- exclude?: true;
57
- };
58
- discardDuplicates?: false | {
59
- exclude?: true;
60
- };
61
- discardOverridden?: false | {
62
- exclude?: true;
63
- };
64
- normalizeRepeatStyle?: false | {
65
- exclude?: true;
66
- };
67
- mergeRules?: false | {
68
- exclude?: true;
69
- };
70
- discardEmpty?: false | {
71
- exclude?: true;
72
- };
73
- uniqueSelectors?: false | {
74
- exclude?: true;
75
- };
76
- normalizeString?: false | import('postcss-normalize-string').Options & {
77
- exclude?: true;
78
- };
79
- normalizePositions?: false | {
80
- exclude?: true;
81
- };
82
- normalizeWhitespace?: false | {
83
- exclude?: true;
84
- };
85
- normalizeUnicode?: false | {
86
- exclude?: true;
87
- };
88
- normalizeDisplayValues?: false | {
89
- exclude?: true;
90
- };
91
- normalizeTimingFunctions?: false | {
92
- exclude?: true;
93
- };
94
- rawCache?: false | {
95
- exclude?: true;
96
- };
15
+ cssDeclarationSorter?: SimpleOptions<{
16
+ order?: ("alphabetical" | "concentric-css" | "smacss") | ((propertyNameA: string, propertyNameB: string) => 0 | 1 | -1) | undefined;
17
+ keepOverrides?: boolean | undefined;
18
+ } | undefined> | undefined;
19
+ discardComments?: SimpleOptions<postcssDiscardComments.Options> | undefined;
20
+ reduceInitial?: SimpleOptions<postcssReduceInitial.Options> | undefined;
21
+ minifyGradients?: SimpleOptions<void> | undefined;
22
+ svgo?: SimpleOptions<postcssSvgo.Options> | undefined;
23
+ reduceTransforms?: SimpleOptions<void> | undefined;
24
+ convertValues?: SimpleOptions<postcssConvertValues.Options> | undefined;
25
+ calc?: SimpleOptions<postcssCalc.PostCssCalcOptions> | undefined;
26
+ colormin?: SimpleOptions<postcssColormin.Options> | undefined;
27
+ orderedValues?: SimpleOptions<void> | undefined;
28
+ minifySelectors?: SimpleOptions<void> | undefined;
29
+ minifyParams?: SimpleOptions<postcssMinifyParams.Options> | undefined;
30
+ normalizeCharset?: SimpleOptions<postcssNormalizeCharset.Options> | undefined;
31
+ minifyFontValues?: SimpleOptions<postcssMinifyFontValues.Options> | undefined;
32
+ normalizeUrl?: SimpleOptions<void> | undefined;
33
+ mergeLonghand?: SimpleOptions<void> | undefined;
34
+ discardDuplicates?: SimpleOptions<void> | undefined;
35
+ discardOverridden?: SimpleOptions<void> | undefined;
36
+ normalizeRepeatStyle?: SimpleOptions<void> | undefined;
37
+ mergeRules?: SimpleOptions<postcssMergeRules.Options> | undefined;
38
+ discardEmpty?: SimpleOptions<void> | undefined;
39
+ uniqueSelectors?: SimpleOptions<void> | undefined;
40
+ normalizeString?: SimpleOptions<postcssNormalizeString.Options> | undefined;
41
+ normalizePositions?: SimpleOptions<void> | undefined;
42
+ normalizeWhitespace?: SimpleOptions<void> | undefined;
43
+ normalizeUnicode?: SimpleOptions<postcssNormalizeUnicode.Options> | undefined;
44
+ normalizeDisplayValues?: SimpleOptions<void> | undefined;
45
+ normalizeTimingFunctions?: SimpleOptions<void> | undefined;
46
+ rawCache?: SimpleOptions<void> | undefined;
97
47
  };
98
- import { rawCache } from "cssnano-utils";
48
+ type AutoprefixerOptions = {
49
+ overrideBrowserslist?: string | string[];
50
+ };
51
+ type BrowserslistOptions = Pick<import('browserslist').Options, 'stats' | 'path' | 'env'>;
52
+ type SimpleOptions<OptionsExtends extends void | object = void> = false | (OptionsExtends & {
53
+ exclude?: true;
54
+ });
55
+ import postcssDiscardComments = require("postcss-discard-comments");
56
+ import postcssReduceInitial = require("postcss-reduce-initial");
57
+ import postcssSvgo = require("postcss-svgo");
58
+ import postcssConvertValues = require("postcss-convert-values");
59
+ import postcssCalc = require("postcss-calc");
60
+ import postcssColormin = require("postcss-colormin");
61
+ import postcssMinifyParams = require("postcss-minify-params");
62
+ import postcssNormalizeCharset = require("postcss-normalize-charset");
63
+ import postcssMinifyFontValues = require("postcss-minify-font-values");
64
+ import postcssMergeRules = require("postcss-merge-rules");
65
+ import postcssNormalizeString = require("postcss-normalize-string");
66
+ import postcssNormalizeUnicode = require("postcss-normalize-unicode");
67
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAqJA;;;;;GAKG;AACH,sCAHW,OAAO,GAAG,mBAAmB,GAAG,mBAAmB,GACjD;IAAE,OAAO,EAAE,CAAC,OAAO,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,EAAE,CAAA;CAAE,CAuCzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA5GY;IAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE;2BAC5C,KAAK,OAAO,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;kEAtC9D,KAAK,IAAG,cAAc,GAAG;IAAC,OAAO,CAAC,EAAE,IAAI,CAAA;CAAC,CAAA"}