postcss-double-position-gradients 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changes to PostCSS Double Position Gradients
2
+
3
+ ### 1.0.0 (October 28, 2018)
4
+
5
+ - Initial version
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 ADDED
@@ -0,0 +1,104 @@
1
+ # PostCSS Double Position Gradients [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
2
+
3
+ [![NPM Version][npm-img]][npm-url]
4
+ [![Build Status][cli-img]][cli-url]
5
+ [![Support Chat][git-img]][git-url]
6
+
7
+ [PostCSS Double Position Gradients] lets you use double-position gradients in
8
+ CSS, following the [CSS Image Values and Replaced Content] specification.
9
+
10
+ ```pcss
11
+ .linear-gradient {
12
+ background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
13
+ }
14
+
15
+ .conic-gradient {
16
+ background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
17
+ }
18
+
19
+ /* becomes */
20
+
21
+ .linear-gradient {
22
+ background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
23
+ background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
24
+ }
25
+
26
+ .conic-gradient {
27
+ background-image: conic-gradient(yellowgreen 40%, gold 0deg, gold 75%, #f06 0deg);
28
+ background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
29
+ }
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Add [PostCSS Double Position Gradients] to your project:
35
+
36
+ ```bash
37
+ npm install postcss-double-position-gradients --save-dev
38
+ ```
39
+
40
+ Use [PostCSS Double Position Gradients] to process your CSS:
41
+
42
+ ```js
43
+ const postcssDoublePositionGradients = require('postcss-double-position-gradients');
44
+
45
+ postcssDoublePositionGradients.process(YOUR_CSS /*, processOptions, pluginOptions */);
46
+ ```
47
+
48
+ Or use it as a [PostCSS] plugin:
49
+
50
+ ```js
51
+ const postcss = require('postcss');
52
+ const postcssDoublePositionGradients = require('postcss-double-position-gradients');
53
+
54
+ postcss([
55
+ postcssDoublePositionGradients(/* pluginOptions */)
56
+ ]).process(YOUR_CSS /*, processOptions */);
57
+ ```
58
+
59
+ [PostCSS Double Position Gradients] runs in all Node environments, with special instructions for:
60
+
61
+ | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
62
+ | --- | --- | --- | --- | --- | --- |
63
+
64
+ ## Options
65
+
66
+ ### preserve
67
+
68
+ The `preserve` option determines whether the original double-position gradients
69
+ should be preserved. By default, double-position gradients are preserved.
70
+
71
+ ```js
72
+ postcssDoublePositionGradients({ preserve: false })
73
+ ```
74
+
75
+ ```css
76
+ .linear-gradient {
77
+ background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
78
+ }
79
+
80
+ .conic-gradient {
81
+ background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
82
+ }
83
+
84
+ /* becomes */
85
+
86
+ .linear-gradient {
87
+ background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
88
+ }
89
+
90
+ .conic-gradient {
91
+ background-image: conic-gradient(yellowgreen 40%, gold 0deg, gold 75%, #f06 0deg);
92
+ }
93
+ ```
94
+
95
+ [cli-img]: https://img.shields.io/travis/jonathantneal/postcss-double-position-gradients/master.svg
96
+ [cli-url]: https://travis-ci.org/jonathantneal/postcss-double-position-gradients
97
+ [git-img]: https://img.shields.io/badge/support-chat-blue.svg
98
+ [git-url]: https://gitter.im/postcss/postcss
99
+ [npm-img]: https://img.shields.io/npm/v/postcss-double-position-gradients.svg
100
+ [npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
101
+
102
+ [CSS Image Values and Replaced Content]: https://www.w3.org/TR/css-images-4/#color-stop-syntax
103
+ [PostCSS]: https://github.com/postcss/postcss
104
+ [PostCSS Double Position Gradients]: https://github.com/jonathantneal/postcss-double-position-gradients
package/index.cjs.js ADDED
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
+
5
+ var postcss = _interopDefault(require('postcss'));
6
+ var valueParser = _interopDefault(require('postcss-values-parser'));
7
+
8
+ var index = postcss.plugin('postcss-double-position-gradients', opts => {
9
+ const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;
10
+ return root => {
11
+ // walk every declaration
12
+ root.walkDecls(decl => {
13
+ const originalValue = decl.value; // if the declaration value contains a gradient
14
+
15
+ if (gradientFunctionRegExp.test(originalValue)) {
16
+ const ast = valueParser(originalValue).parse(); // walk every function in the declaration value
17
+
18
+ ast.walkFunctionNodes(fn => {
19
+ // if the function is a gradient
20
+ if (gradientFunctionNameRegExp.test(fn.value)) {
21
+ const nodes = fn.nodes.slice(1, -1); // walk every argument to the function
22
+
23
+ nodes.forEach((node, index) => {
24
+ const node1back = Object(nodes[index - 1]);
25
+ const node2back = Object(nodes[index - 2]);
26
+ const isDoublePositionLength = node2back.type && node1back.type === 'number' && node.type === 'number'; // if the argument concludes a double-position gradient
27
+
28
+ if (isDoublePositionLength) {
29
+ // insert the fallback colors
30
+ const color = node2back.clone();
31
+ const comma = valueParser.comma({
32
+ value: ',',
33
+ raws: {
34
+ after: ' '
35
+ }
36
+ });
37
+ fn.insertBefore(node, comma);
38
+ fn.insertBefore(node, color);
39
+ }
40
+ });
41
+ }
42
+ });
43
+ const modifiedValue = ast.toString(); // if the value has changed due to double-position gradients
44
+
45
+ if (originalValue !== modifiedValue) {
46
+ // add the fallback value
47
+ decl.cloneBefore({
48
+ value: modifiedValue
49
+ }); // conditionally remove the double-position gradient
50
+
51
+ if (!preserve) {
52
+ decl.remove();
53
+ }
54
+ }
55
+ }
56
+ });
57
+ };
58
+ });
59
+ const gradientFunctionRegExp = /(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i;
60
+ const gradientFunctionNameRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;
61
+
62
+ module.exports = index;
63
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["index.js"],"sourcesContent":["import postcss from 'postcss';\nimport valueParser from 'postcss-values-parser';\n\nexport default postcss.plugin('postcss-double-position-gradients', opts => {\n\tconst preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;\n\n\treturn root => {\n\t\t// walk every declaration\n\t\troot.walkDecls(decl => {\n\t\t\tconst { value: originalValue } = decl;\n\n\t\t\t// if the declaration value contains a gradient\n\t\t\tif (gradientFunctionRegExp.test(originalValue)) {\n\t\t\t\tconst ast = valueParser(originalValue).parse();\n\n\t\t\t\t// walk every function in the declaration value\n\t\t\t\tast.walkFunctionNodes(fn => {\n\t\t\t\t\t// if the function is a gradient\n\t\t\t\t\tif (gradientFunctionNameRegExp.test(fn.value)) {\n\t\t\t\t\t\tconst nodes = fn.nodes.slice(1, -1);\n\n\t\t\t\t\t\t// walk every argument to the function\n\t\t\t\t\t\tnodes.forEach((node, index) => {\n\t\t\t\t\t\t\tconst node1back = Object(nodes[index - 1]);\n\t\t\t\t\t\t\tconst node2back = Object(nodes[index - 2]);\n\n\t\t\t\t\t\t\tconst isDoublePositionLength = node2back.type && node1back.type === 'number' && node.type === 'number';\n\n\t\t\t\t\t\t\t// if the argument concludes a double-position gradient\n\t\t\t\t\t\t\tif (isDoublePositionLength) {\n\t\t\t\t\t\t\t\t// insert the fallback colors\n\t\t\t\t\t\t\t\tconst color = node2back.clone();\n\t\t\t\t\t\t\t\tconst comma = valueParser.comma({ value: ',', raws: { after: ' ' } });\n\n\t\t\t\t\t\t\t\tfn.insertBefore(node, comma);\n\t\t\t\t\t\t\t\tfn.insertBefore(node, color);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tconst modifiedValue = ast.toString();\n\n\t\t\t\t// if the value has changed due to double-position gradients\n\t\t\t\tif (originalValue !== modifiedValue) {\n\t\t\t\t\t// add the fallback value\n\t\t\t\t\tdecl.cloneBefore({ value: modifiedValue });\n\n\t\t\t\t\t// conditionally remove the double-position gradient\n\t\t\t\t\tif (!preserve) {\n\t\t\t\t\t\tdecl.remove();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n});\n\nconst gradientFunctionRegExp = /(repeating-)?(conic|linear|radial)-gradient\\([\\W\\w]*\\)/i;\nconst gradientFunctionNameRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;\n"],"names":["postcss","plugin","opts","preserve","Object","Boolean","root","walkDecls","decl","originalValue","value","gradientFunctionRegExp","test","ast","valueParser","parse","walkFunctionNodes","fn","gradientFunctionNameRegExp","nodes","slice","forEach","node","index","node1back","node2back","isDoublePositionLength","type","color","clone","comma","raws","after","insertBefore","modifiedValue","toString","cloneBefore","remove"],"mappings":";;;;;;;AAGA,YAAeA,OAAO,CAACC,MAAR,CAAe,mCAAf,EAAoDC,IAAI,IAAI;QACpEC,QAAQ,GAAG,cAAcC,MAAM,CAACF,IAAD,CAApB,GAA6BG,OAAO,CAACH,IAAI,CAACC,QAAN,CAApC,GAAsD,IAAvE;SAEOG,IAAI,IAAI;;IAEdA,IAAI,CAACC,SAAL,CAAeC,IAAI,IAAI;YACPC,aADO,GACWD,IADX,CACdE,KADc;;UAIlBC,sBAAsB,CAACC,IAAvB,CAA4BH,aAA5B,CAAJ,EAAgD;cACzCI,GAAG,GAAGC,WAAW,CAACL,aAAD,CAAX,CAA2BM,KAA3B,EAAZ,CAD+C;;QAI/CF,GAAG,CAACG,iBAAJ,CAAsBC,EAAE,IAAI;;cAEvBC,0BAA0B,CAACN,IAA3B,CAAgCK,EAAE,CAACP,KAAnC,CAAJ,EAA+C;kBACxCS,KAAK,GAAGF,EAAE,CAACE,KAAH,CAASC,KAAT,CAAe,CAAf,EAAkB,CAAC,CAAnB,CAAd,CAD8C;;YAI9CD,KAAK,CAACE,OAAN,CAAc,CAACC,IAAD,EAAOC,KAAP,KAAiB;oBACxBC,SAAS,GAAGpB,MAAM,CAACe,KAAK,CAACI,KAAK,GAAG,CAAT,CAAN,CAAxB;oBACME,SAAS,GAAGrB,MAAM,CAACe,KAAK,CAACI,KAAK,GAAG,CAAT,CAAN,CAAxB;oBAEMG,sBAAsB,GAAGD,SAAS,CAACE,IAAV,IAAkBH,SAAS,CAACG,IAAV,KAAmB,QAArC,IAAiDL,IAAI,CAACK,IAAL,KAAc,QAA9F,CAJ8B;;kBAO1BD,sBAAJ,EAA4B;;sBAErBE,KAAK,GAAGH,SAAS,CAACI,KAAV,EAAd;sBACMC,KAAK,GAAGhB,WAAW,CAACgB,KAAZ,CAAkB;kBAAEpB,KAAK,EAAE,GAAT;kBAAcqB,IAAI,EAAE;oBAAEC,KAAK,EAAE;;iBAA/C,CAAd;gBAEAf,EAAE,CAACgB,YAAH,CAAgBX,IAAhB,EAAsBQ,KAAtB;gBACAb,EAAE,CAACgB,YAAH,CAAgBX,IAAhB,EAAsBM,KAAtB;;aAbF;;SANF;cAyBMM,aAAa,GAAGrB,GAAG,CAACsB,QAAJ,EAAtB,CA7B+C;;YAgC3C1B,aAAa,KAAKyB,aAAtB,EAAqC;;UAEpC1B,IAAI,CAAC4B,WAAL,CAAiB;YAAE1B,KAAK,EAAEwB;WAA1B,EAFoC;;cAKhC,CAAC/B,QAAL,EAAe;YACdK,IAAI,CAAC6B,MAAL;;;;KA1CJ;GAFD;CAHc,CAAf;AAuDA,MAAM1B,sBAAsB,GAAG,yDAA/B;AACA,MAAMO,0BAA0B,GAAG,gDAAnC;;;;"}
package/index.es.mjs ADDED
@@ -0,0 +1,59 @@
1
+ import postcss from 'postcss';
2
+ import valueParser from 'postcss-values-parser';
3
+
4
+ var index = postcss.plugin('postcss-double-position-gradients', opts => {
5
+ const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;
6
+ return root => {
7
+ // walk every declaration
8
+ root.walkDecls(decl => {
9
+ const originalValue = decl.value; // if the declaration value contains a gradient
10
+
11
+ if (gradientFunctionRegExp.test(originalValue)) {
12
+ const ast = valueParser(originalValue).parse(); // walk every function in the declaration value
13
+
14
+ ast.walkFunctionNodes(fn => {
15
+ // if the function is a gradient
16
+ if (gradientFunctionNameRegExp.test(fn.value)) {
17
+ const nodes = fn.nodes.slice(1, -1); // walk every argument to the function
18
+
19
+ nodes.forEach((node, index) => {
20
+ const node1back = Object(nodes[index - 1]);
21
+ const node2back = Object(nodes[index - 2]);
22
+ const isDoublePositionLength = node2back.type && node1back.type === 'number' && node.type === 'number'; // if the argument concludes a double-position gradient
23
+
24
+ if (isDoublePositionLength) {
25
+ // insert the fallback colors
26
+ const color = node2back.clone();
27
+ const comma = valueParser.comma({
28
+ value: ',',
29
+ raws: {
30
+ after: ' '
31
+ }
32
+ });
33
+ fn.insertBefore(node, comma);
34
+ fn.insertBefore(node, color);
35
+ }
36
+ });
37
+ }
38
+ });
39
+ const modifiedValue = ast.toString(); // if the value has changed due to double-position gradients
40
+
41
+ if (originalValue !== modifiedValue) {
42
+ // add the fallback value
43
+ decl.cloneBefore({
44
+ value: modifiedValue
45
+ }); // conditionally remove the double-position gradient
46
+
47
+ if (!preserve) {
48
+ decl.remove();
49
+ }
50
+ }
51
+ }
52
+ });
53
+ };
54
+ });
55
+ const gradientFunctionRegExp = /(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i;
56
+ const gradientFunctionNameRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;
57
+
58
+ export default index;
59
+ //# sourceMappingURL=index.es.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.mjs","sources":["index.js"],"sourcesContent":["import postcss from 'postcss';\nimport valueParser from 'postcss-values-parser';\n\nexport default postcss.plugin('postcss-double-position-gradients', opts => {\n\tconst preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;\n\n\treturn root => {\n\t\t// walk every declaration\n\t\troot.walkDecls(decl => {\n\t\t\tconst { value: originalValue } = decl;\n\n\t\t\t// if the declaration value contains a gradient\n\t\t\tif (gradientFunctionRegExp.test(originalValue)) {\n\t\t\t\tconst ast = valueParser(originalValue).parse();\n\n\t\t\t\t// walk every function in the declaration value\n\t\t\t\tast.walkFunctionNodes(fn => {\n\t\t\t\t\t// if the function is a gradient\n\t\t\t\t\tif (gradientFunctionNameRegExp.test(fn.value)) {\n\t\t\t\t\t\tconst nodes = fn.nodes.slice(1, -1);\n\n\t\t\t\t\t\t// walk every argument to the function\n\t\t\t\t\t\tnodes.forEach((node, index) => {\n\t\t\t\t\t\t\tconst node1back = Object(nodes[index - 1]);\n\t\t\t\t\t\t\tconst node2back = Object(nodes[index - 2]);\n\n\t\t\t\t\t\t\tconst isDoublePositionLength = node2back.type && node1back.type === 'number' && node.type === 'number';\n\n\t\t\t\t\t\t\t// if the argument concludes a double-position gradient\n\t\t\t\t\t\t\tif (isDoublePositionLength) {\n\t\t\t\t\t\t\t\t// insert the fallback colors\n\t\t\t\t\t\t\t\tconst color = node2back.clone();\n\t\t\t\t\t\t\t\tconst comma = valueParser.comma({ value: ',', raws: { after: ' ' } });\n\n\t\t\t\t\t\t\t\tfn.insertBefore(node, comma);\n\t\t\t\t\t\t\t\tfn.insertBefore(node, color);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tconst modifiedValue = ast.toString();\n\n\t\t\t\t// if the value has changed due to double-position gradients\n\t\t\t\tif (originalValue !== modifiedValue) {\n\t\t\t\t\t// add the fallback value\n\t\t\t\t\tdecl.cloneBefore({ value: modifiedValue });\n\n\t\t\t\t\t// conditionally remove the double-position gradient\n\t\t\t\t\tif (!preserve) {\n\t\t\t\t\t\tdecl.remove();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n});\n\nconst gradientFunctionRegExp = /(repeating-)?(conic|linear|radial)-gradient\\([\\W\\w]*\\)/i;\nconst gradientFunctionNameRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;\n"],"names":["postcss","plugin","opts","preserve","Object","Boolean","root","walkDecls","decl","originalValue","value","gradientFunctionRegExp","test","ast","valueParser","parse","walkFunctionNodes","fn","gradientFunctionNameRegExp","nodes","slice","forEach","node","index","node1back","node2back","isDoublePositionLength","type","color","clone","comma","raws","after","insertBefore","modifiedValue","toString","cloneBefore","remove"],"mappings":";;;AAGA,YAAeA,OAAO,CAACC,MAAR,CAAe,mCAAf,EAAoDC,IAAI,IAAI;QACpEC,QAAQ,GAAG,cAAcC,MAAM,CAACF,IAAD,CAApB,GAA6BG,OAAO,CAACH,IAAI,CAACC,QAAN,CAApC,GAAsD,IAAvE;SAEOG,IAAI,IAAI;;IAEdA,IAAI,CAACC,SAAL,CAAeC,IAAI,IAAI;YACPC,aADO,GACWD,IADX,CACdE,KADc;;UAIlBC,sBAAsB,CAACC,IAAvB,CAA4BH,aAA5B,CAAJ,EAAgD;cACzCI,GAAG,GAAGC,WAAW,CAACL,aAAD,CAAX,CAA2BM,KAA3B,EAAZ,CAD+C;;QAI/CF,GAAG,CAACG,iBAAJ,CAAsBC,EAAE,IAAI;;cAEvBC,0BAA0B,CAACN,IAA3B,CAAgCK,EAAE,CAACP,KAAnC,CAAJ,EAA+C;kBACxCS,KAAK,GAAGF,EAAE,CAACE,KAAH,CAASC,KAAT,CAAe,CAAf,EAAkB,CAAC,CAAnB,CAAd,CAD8C;;YAI9CD,KAAK,CAACE,OAAN,CAAc,CAACC,IAAD,EAAOC,KAAP,KAAiB;oBACxBC,SAAS,GAAGpB,MAAM,CAACe,KAAK,CAACI,KAAK,GAAG,CAAT,CAAN,CAAxB;oBACME,SAAS,GAAGrB,MAAM,CAACe,KAAK,CAACI,KAAK,GAAG,CAAT,CAAN,CAAxB;oBAEMG,sBAAsB,GAAGD,SAAS,CAACE,IAAV,IAAkBH,SAAS,CAACG,IAAV,KAAmB,QAArC,IAAiDL,IAAI,CAACK,IAAL,KAAc,QAA9F,CAJ8B;;kBAO1BD,sBAAJ,EAA4B;;sBAErBE,KAAK,GAAGH,SAAS,CAACI,KAAV,EAAd;sBACMC,KAAK,GAAGhB,WAAW,CAACgB,KAAZ,CAAkB;kBAAEpB,KAAK,EAAE,GAAT;kBAAcqB,IAAI,EAAE;oBAAEC,KAAK,EAAE;;iBAA/C,CAAd;gBAEAf,EAAE,CAACgB,YAAH,CAAgBX,IAAhB,EAAsBQ,KAAtB;gBACAb,EAAE,CAACgB,YAAH,CAAgBX,IAAhB,EAAsBM,KAAtB;;aAbF;;SANF;cAyBMM,aAAa,GAAGrB,GAAG,CAACsB,QAAJ,EAAtB,CA7B+C;;YAgC3C1B,aAAa,KAAKyB,aAAtB,EAAqC;;UAEpC1B,IAAI,CAAC4B,WAAL,CAAiB;YAAE1B,KAAK,EAAEwB;WAA1B,EAFoC;;cAKhC,CAAC/B,QAAL,EAAe;YACdK,IAAI,CAAC6B,MAAL;;;;KA1CJ;GAFD;CAHc,CAAf;AAuDA,MAAM1B,sBAAsB,GAAG,yDAA/B;AACA,MAAMO,0BAA0B,GAAG,gDAAnC;;;;"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "postcss-double-position-gradients",
3
+ "version": "1.0.0",
4
+ "description": "Use double-position gradients in CSS",
5
+ "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
+ "license": "CC0-1.0",
7
+ "repository": "jonathantneal/postcss-double-position-gradients",
8
+ "homepage": "https://github.com/jonathantneal/postcss-double-position-gradients#readme",
9
+ "bugs": "https://github.com/jonathantneal/postcss-double-position-gradients/issues",
10
+ "main": "index.cjs.js",
11
+ "module": "index.es.mjs",
12
+ "files": [
13
+ "index.cjs.js",
14
+ "index.cjs.js.map",
15
+ "index.es.mjs",
16
+ "index.es.mjs.map"
17
+ ],
18
+ "scripts": {
19
+ "prepublishOnly": "npm test",
20
+ "pretest": "rollup -c .rollup.js --silent",
21
+ "test": "npm run test:js && npm run test:tape",
22
+ "test:js": "eslint *.js --cache --ignore-path .gitignore --quiet",
23
+ "test:tape": "postcss-tape"
24
+ },
25
+ "engines": {
26
+ "node": ">=6.0.0"
27
+ },
28
+ "dependencies": {
29
+ "postcss": "^7.0.5",
30
+ "postcss-values-parser": "^2.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/core": "^7.1.2",
34
+ "@babel/plugin-syntax-dynamic-import": "^7.0.0",
35
+ "@babel/preset-env": "^7.1.0",
36
+ "babel-eslint": "^10.0.1",
37
+ "eslint": "^5.8.0",
38
+ "eslint-config-dev": "^2.0.0",
39
+ "postcss-tape": "^2.2.0",
40
+ "pre-commit": "^1.2.2",
41
+ "rollup": "^0.66.6",
42
+ "rollup-plugin-babel": "^4.0.3"
43
+ },
44
+ "eslintConfig": {
45
+ "extends": "dev",
46
+ "parser": "babel-eslint"
47
+ },
48
+ "keywords": [
49
+ "postcss",
50
+ "css",
51
+ "postcss-plugin",
52
+ "double",
53
+ "position",
54
+ "gradients",
55
+ "linear",
56
+ "radial",
57
+ "conic",
58
+ "color",
59
+ "stop",
60
+ "syntax",
61
+ "repeating"
62
+ ]
63
+ }