postcss-double-position-gradients 3.0.5 → 3.1.2

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changes to PostCSS Double Position Gradients
2
2
 
3
+ ### 3.1.2 (July 8, 2022)
4
+
5
+ - Fix case insensitive matching.
6
+
7
+ ### 3.1.1 (March 7, 2022)
8
+
9
+ - Add typescript support
10
+ - Fix color functions.
11
+ - Fix `at` keyword with `at 20px 20px` being interpreted as a double position color stop.
12
+
13
+ ### 3.1.0 (February 15, 2022)
14
+
15
+ - Ignore values in relevant `@supports` rules.
16
+ - Support double position gradients in Custom Properties.
17
+
18
+ ```css
19
+ @supports (order: linear-gradient(90deg, black 25% 50%, blue 50% 75%)) {
20
+ .support {
21
+ /* is not processed */
22
+ order: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
23
+ }
24
+ }
25
+ ```
26
+
3
27
  ### 3.0.5 (February 5, 2022)
4
28
 
5
29
  - Improved `es module` and `commonjs` compatibility
package/README.md CHANGED
@@ -92,6 +92,30 @@ postcssDoublePositionGradients({ preserve: false })
92
92
  }
93
93
  ```
94
94
 
95
+ ### enableProgressiveCustomProperties
96
+
97
+ The `enableProgressiveCustomProperties` option determines whether the original notation
98
+ is wrapped with `@supports` when used in Custom Properties. By default, it is enabled.
99
+
100
+ ⚠️ We only recommend disabling this when you set `preserve` to `false` or if you bring your own fix for Custom Properties. See what the plugin does in its [README](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-progressive-custom-properties#readme).
101
+
102
+ ```js
103
+ postcssDoublePositionGradients({ enableProgressiveCustomProperties: false })
104
+ ```
105
+
106
+ ```pcss
107
+ :root {
108
+ --a-gradient: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
109
+ }
110
+
111
+ /* becomes */
112
+
113
+ :root {
114
+ --a-gradient: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%); /* will never be used, not even in older browser */
115
+ --a-gradient: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
116
+ }
117
+ ```
118
+
95
119
  [css-url]: https://cssdb.org/#double-position-gradients
96
120
  [discord]: https://discord.gg/bUadyRwkJS
97
121
  [npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
@@ -0,0 +1,2 @@
1
+ import type { Node } from 'postcss';
2
+ export declare function hasSupportsAtRuleAncestor(node: Node): boolean;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("postcss-value-parser"));const r=/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i,n=/^(repeating-)?(conic|linear|radial)-gradient$/i,a=e=>"div"===e.type&&","===e.value;function i(e){try{return!1!==t.default.unit(null==e?void 0:e.value)}catch(e){return!1}}function o(e){const o=!("preserve"in Object(e))||Boolean(e.preserve);return{postcssPlugin:"postcss-double-position-gradients",Declaration(e,{result:l}){if(!r.test(e.value))return;let u;try{u=t.default(e.value)}catch(t){e.warn(l,`Failed to parse value '${e.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===u)return;u.walk((e=>{if("function"!==e.type||!n.test(e.value))return;return e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type)).forEach(((t,r,n)=>{const o=Object(n[r-1]),l=Object(n[r-2]),u=Object(n[r+1]);if(l.type&&i(o)&&i(t)){const r={type:l.type,value:l.value},n={type:"div",value:",",before:a(u)?u.before:"",after:a(u)?"":" "};!function(e,t,...r){const n=e.findIndex((e=>e===t));e.splice.apply(e,[n-1,0].concat(Array.prototype.slice.call(...r,0)))}(e.nodes,t,[n,r])}})),!1}));const c=u.toString();if(c!==e.value){if(o)return void e.cloneBefore({value:c});e.value=c}}}}o.postcss=!0,module.exports=o;
1
+ "use strict";var e=require("@csstools/postcss-progressive-custom-properties"),t=require("postcss-value-parser");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e),s=r(t);function i(e){return e.includes("conic-gradient(")||e.includes("linear-gradient(")||e.includes("radial-gradient(")||e.includes("repeating-conic-gradient(")||e.includes("repeating-linear-gradient(")||e.includes("repeating-radial-gradient(")}const a=["at","bottom","center","circle","closest-corner","closest-side","ellipse","farthest-corner","farthest-side","from","in","left","right","to","top"],o=e=>"div"===e.type&&","===e.value;function l(e){try{return!1!==s.default.unit(null==e?void 0:e.value)}catch(e){return!1}}const c=e=>({postcssPlugin:"postcss-double-position-gradients",Declaration(t,{result:r}){if(!i(t.value.toLowerCase()))return;if(function(e){let t=e.parent;for(;t;)if("atrule"===t.type){if("supports"===t.name.toLowerCase()&&i(t.params.toLowerCase()))return!0;t=t.parent}else t=t.parent;return!1}(t))return;let n;try{n=s.default(t.value)}catch(e){t.warn(r,`Failed to parse value '${t.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===n)return;n.walk((e=>{if("function"!==e.type||"conic-gradient"!==(t=e.value.toLowerCase())&&"linear-gradient"!==t&&"radial-gradient"!==t&&"repeating-conic-gradient"!==t&&"repeating-linear-gradient"!==t&&"repeating-radial-gradient"!==t)return;var t;const r=e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));let n=!1;r.forEach(((t,r,s)=>{if("word"===t.type&&a.includes(t.value.toLowerCase())&&(n=!0),"div"===t.type&&","===t.value&&(n=!1),n)return;const i=Object(s[r-1]),c=Object(s[r-2]),u=Object(s[r+1]);if(c.type&&l(i)&&l(t)){const r=c,n={type:"div",value:",",before:o(u)?u.before:"",after:o(u)?"":" "};e.nodes.splice(e.nodes.indexOf(t)-1,0,n,r)}}))}));const c=n.toString();c!==t.value&&(t.cloneBefore({value:c}),e.preserve||t.remove())}});c.postcss=!0;const u=e=>{const t=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},e);return t.enableProgressiveCustomProperties&&t.preserve?{postcssPlugin:"postcss-double-position-gradients",plugins:[n.default(),c(t)]}:c(t)};u.postcss=!0,module.exports=u;
@@ -0,0 +1,7 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ declare type pluginOptions = {
3
+ preserve?: boolean;
4
+ enableProgressiveCustomProperties?: boolean;
5
+ };
6
+ declare const postcssPlugin: PluginCreator<pluginOptions>;
7
+ export default postcssPlugin;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import e from"postcss-value-parser";const t=/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i,r=/^(repeating-)?(conic|linear|radial)-gradient$/i,a=e=>"div"===e.type&&","===e.value;function n(t){try{return!1!==e.unit(null==t?void 0:t.value)}catch(e){return!1}}function i(i){const o=!("preserve"in Object(i))||Boolean(i.preserve);return{postcssPlugin:"postcss-double-position-gradients",Declaration(i,{result:l}){if(!t.test(i.value))return;let c;try{c=e(i.value)}catch(e){i.warn(l,`Failed to parse value '${i.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===c)return;c.walk((e=>{if("function"!==e.type||!r.test(e.value))return;return e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type)).forEach(((t,r,i)=>{const o=Object(i[r-1]),l=Object(i[r-2]),c=Object(i[r+1]);if(l.type&&n(o)&&n(t)){const r={type:l.type,value:l.value},n={type:"div",value:",",before:a(c)?c.before:"",after:a(c)?"":" "};!function(e,t,...r){const a=e.findIndex((e=>e===t));e.splice.apply(e,[a-1,0].concat(Array.prototype.slice.call(...r,0)))}(e.nodes,t,[n,r])}})),!1}));const s=c.toString();if(s!==i.value){if(o)return void i.cloneBefore({value:s});i.value=s}}}}i.postcss=!0;export{i as default};
1
+ import e from"@csstools/postcss-progressive-custom-properties";import t from"postcss-value-parser";function r(e){return e.includes("conic-gradient(")||e.includes("linear-gradient(")||e.includes("radial-gradient(")||e.includes("repeating-conic-gradient(")||e.includes("repeating-linear-gradient(")||e.includes("repeating-radial-gradient(")}const n=["at","bottom","center","circle","closest-corner","closest-side","ellipse","farthest-corner","farthest-side","from","in","left","right","to","top"],s=e=>"div"===e.type&&","===e.value;function i(e){try{return!1!==t.unit(null==e?void 0:e.value)}catch(e){return!1}}const a=e=>({postcssPlugin:"postcss-double-position-gradients",Declaration(a,{result:o}){if(!r(a.value.toLowerCase()))return;if(function(e){let t=e.parent;for(;t;)if("atrule"===t.type){if("supports"===t.name.toLowerCase()&&r(t.params.toLowerCase()))return!0;t=t.parent}else t=t.parent;return!1}(a))return;let c;try{c=t(a.value)}catch(e){a.warn(o,`Failed to parse value '${a.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===c)return;c.walk((e=>{if("function"!==e.type||"conic-gradient"!==(t=e.value.toLowerCase())&&"linear-gradient"!==t&&"radial-gradient"!==t&&"repeating-conic-gradient"!==t&&"repeating-linear-gradient"!==t&&"repeating-radial-gradient"!==t)return;var t;const r=e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));let a=!1;r.forEach(((t,r,o)=>{if("word"===t.type&&n.includes(t.value.toLowerCase())&&(a=!0),"div"===t.type&&","===t.value&&(a=!1),a)return;const c=Object(o[r-1]),l=Object(o[r-2]),u=Object(o[r+1]);if(l.type&&i(c)&&i(t)){const r=l,n={type:"div",value:",",before:s(u)?u.before:"",after:s(u)?"":" "};e.nodes.splice(e.nodes.indexOf(t)-1,0,n,r)}}))}));const l=c.toString();l!==a.value&&(a.cloneBefore({value:l}),e.preserve||a.remove())}});a.postcss=!0;const o=t=>{const r=Object.assign({enableProgressiveCustomProperties:!0,preserve:!0},t);return r.enableProgressiveCustomProperties&&r.preserve?{postcssPlugin:"postcss-double-position-gradients",plugins:[e(),a(r)]}:a(r)};o.postcss=!0;export{o as default};
@@ -0,0 +1,2 @@
1
+ export declare function includesGradientsFunction(str: string): boolean;
2
+ export declare function isGradientsFunctions(str: string): boolean;
package/package.json CHANGED
@@ -1,69 +1,78 @@
1
1
  {
2
- "name": "postcss-double-position-gradients",
3
- "version": "3.0.5",
4
- "description": "Use double-position gradients in CSS",
5
- "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
- "license": "CC0-1.0",
7
- "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients#readme",
8
- "bugs": "https://github.com/csstools/postcss-plugins/issues",
9
- "main": "dist/index.cjs",
10
- "module": "dist/index.mjs",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.cjs",
15
- "default": "./dist/index.mjs"
16
- }
17
- },
18
- "files": [
19
- "CHANGELOG.md",
20
- "LICENSE.md",
21
- "README.md",
22
- "dist"
23
- ],
24
- "scripts": {
25
- "build": "rollup -c ../../rollup/default.js",
26
- "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
27
- "lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
28
- "prepublishOnly": "npm run clean && npm run build && npm run test",
29
- "stryker": "stryker run --logLevel error",
30
- "test": "postcss-tape --ci && npm run test:exports",
31
- "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
32
- },
33
- "engines": {
34
- "node": "^12 || ^14 || >=16"
35
- },
36
- "dependencies": {
37
- "postcss-value-parser": "^4.2.0"
38
- },
39
- "devDependencies": {
40
- "postcss": "^8.3.6",
41
- "postcss-tape": "^6.0.1"
42
- },
43
- "peerDependencies": {
44
- "postcss": "^8.4"
45
- },
46
- "keywords": [
47
- "postcss",
48
- "css",
49
- "postcss-plugin",
50
- "double",
51
- "position",
52
- "gradients",
53
- "linear",
54
- "radial",
55
- "conic",
56
- "color",
57
- "stop",
58
- "syntax",
59
- "repeating"
60
- ],
61
- "repository": {
62
- "type": "git",
63
- "url": "https://github.com/csstools/postcss-plugins.git",
64
- "directory": "plugins/postcss-double-position-gradients"
65
- },
66
- "volta": {
67
- "extends": "../../package.json"
68
- }
2
+ "name": "postcss-double-position-gradients",
3
+ "description": "Use double-position gradients in CSS",
4
+ "version": "3.1.2",
5
+ "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
+ "license": "CC0-1.0",
7
+ "funding": {
8
+ "type": "opencollective",
9
+ "url": "https://opencollective.com/csstools"
10
+ },
11
+ "engines": {
12
+ "node": "^12 || ^14 || >=16"
13
+ },
14
+ "main": "dist/index.cjs",
15
+ "module": "dist/index.mjs",
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs",
21
+ "default": "./dist/index.mjs"
22
+ }
23
+ },
24
+ "files": [
25
+ "CHANGELOG.md",
26
+ "LICENSE.md",
27
+ "README.md",
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "@csstools/postcss-progressive-custom-properties": "^1.1.0",
32
+ "postcss-value-parser": "^4.2.0"
33
+ },
34
+ "peerDependencies": {
35
+ "postcss": "^8.2"
36
+ },
37
+ "scripts": {
38
+ "build": "rollup -c ../../rollup/default.js",
39
+ "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
40
+ "docs": "node ../../.github/bin/generate-docs/install.mjs",
41
+ "lint": "npm run lint:eslint && npm run lint:package-json",
42
+ "lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
43
+ "lint:package-json": "node ../../.github/bin/format-package-json.mjs",
44
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
45
+ "test": "node .tape.mjs && npm run test:exports",
46
+ "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs",
47
+ "test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
48
+ },
49
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients#readme",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/csstools/postcss-plugins.git",
53
+ "directory": "plugins/postcss-double-position-gradients"
54
+ },
55
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
56
+ "keywords": [
57
+ "color",
58
+ "conic",
59
+ "css",
60
+ "double",
61
+ "gradients",
62
+ "linear",
63
+ "position",
64
+ "postcss",
65
+ "postcss-plugin",
66
+ "radial",
67
+ "repeating",
68
+ "stop",
69
+ "syntax"
70
+ ],
71
+ "csstools": {
72
+ "exportName": "postcssDoublePositionGradients",
73
+ "humanReadableName": "PostCSS Double Position Gradients"
74
+ },
75
+ "volta": {
76
+ "extends": "../../package.json"
77
+ }
69
78
  }