postcss-color-functional-notation 4.2.2 → 4.2.3
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 +16 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +78 -71
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changes to PostCSS Color Functional Notation
|
|
2
2
|
|
|
3
|
+
### 4.2.3 (May 19, 2022)
|
|
4
|
+
|
|
5
|
+
- Handle modern channel values in legacy notation (comma separated)
|
|
6
|
+
|
|
7
|
+
```css
|
|
8
|
+
.color {
|
|
9
|
+
color: rgba(0, 255, 0, 50%);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* becomes */
|
|
13
|
+
|
|
14
|
+
.color {
|
|
15
|
+
color: rgba(0, 255, 0, 0.5);
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
3
19
|
### 4.2.2 (February 5, 2022)
|
|
4
20
|
|
|
5
21
|
- Improved `es module` and `commonjs` compatibility
|
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 r=e(require("postcss-value-parser"));function
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=e(require("postcss-value-parser"));function t(e){const t=e.value;if(!function(e,r){let t=!1,n=!1,u=!1;const a=r.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));for(let l=0;l<a.length;l++){const o=a[l];if("word"===o.type&&"from"===o.value)return!1;"div"!==o.type||","!==o.value?e&&"word"===o.type&&o.value.endsWith("%")?u=!0:l===r.length-1&&"word"===o.type&&o.value.endsWith("%")&&(n=!0):t=!0}if(t&&(n||u))return!0;if(t)return!1;return!0}("rgb"===t||"rgba"===t,e.nodes))return;const i=function(e){let r=0;for(let t=0;t<e.length;t++){const n=e[t];if("div"===n.type&&","===n.value){if(r<2&&(n.value=" ",n.type="space"),2===r&&(n.value="/"),r>2)return;r++}}return e}(e.nodes),s=i.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let f=null;if("hsl"===t||"hsla"===t?f=function(e){if(!function(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const t=r.default.unit(e.value);if(!t)return!1;return!!t.number&&("deg"===t.unit||"grad"===t.unit||"rad"===t.unit||"turn"===t.unit||""===t.unit)}(e[0]))return null;if(!n(e[1]))return null;if(!n(e[2]))return null;const t={h:r.default.unit(e[0].value),hNode:e[0],s:r.default.unit(e[1].value),sNode:e[1],l:r.default.unit(e[2].value),lNode:e[2]};if(function(e){switch(e.unit){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=Math.round(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=Math.round(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=Math.round(360*parseFloat(e.number)).toString()}}(t.h),""!==t.h.unit)return null;t.hNode.value=t.h.number,l(e[3])&&(t.slash=e[3]);(n(e[4])||u(e[4])||a(e[4]))&&(t.alpha=e[4]);return t}(s):"rgb"!==t&&"rgba"!==t||(f=function(e){if(!n(e[0]))return null;if(!n(e[1]))return null;if(!n(e[2]))return null;const t={r:r.default.unit(e[0].value),rNode:e[0],g:r.default.unit(e[1].value),gNode:e[1],b:r.default.unit(e[2].value),bNode:e[2]};"%"===t.r.unit&&(t.r.number=String(Math.floor(Number(t.r.number)/100*255)),t.rNode.value=t.r.number);"%"===t.g.unit&&(t.g.number=String(Math.floor(Number(t.g.number)/100*255)),t.gNode.value=t.g.number);"%"===t.b.unit&&(t.b.number=String(Math.floor(Number(t.b.number)/100*255)),t.bNode.value=t.b.number);l(e[3])&&(t.slash=e[3]);(n(e[4])||u(e[4])||a(e[4]))&&(t.alpha=e[4]);return t}(s)),!f)return;if(s.length>3&&(!f.slash||!f.alpha))return;!function(e,t,n){"hsl"===e.value||"hsla"===e.value?e.value="hsl":"rgb"!==e.value&&"rgba"!==e.value||(e.value="rgb");if(!t||!n)return;"hsl"===e.value?e.value="hsla":e.value="rgba";if(t.value=",",t.before="",!function(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const t=r.default.unit(e.value);if(!t)return!1;return!!t.number}(n))return;const u=r.default.unit(n.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),n.value=String(u.number))}(e,f.slash,f.alpha);const[c,d]=function(e){if(function(e){if(void 0!==e.r)return!0;return!1}(e))return[e.rNode,e.gNode,e.bNode];return[e.hNode,e.sNode,e.lNode]}(f);e.nodes.splice(e.nodes.indexOf(c)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),e.nodes.splice(e.nodes.indexOf(d)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""})}function n(e){if(!e||"word"!==e.type)return!1;if(!o(e))return!1;const t=r.default.unit(e.value);return!!t&&("%"===t.unit||""===t.unit)}function u(e){return e&&"function"===e.type&&"calc"===e.value}function a(e){return e&&"function"===e.type&&"var"===e.value}function l(e){return e&&"div"===e.type&&"/"===e.value}function o(e){if(!e||!e.value)return!1;try{return!1!==r.default.unit(e.value)}catch(e){return!1}}const i=e=>{const n="preserve"in Object(e)&&Boolean(e.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(e,{result:u,postcss:a})=>{if(n&&function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))"))return!0;r=r.parent}else r=r.parent;return!1}(e))return;const l=e.value;if(!/(^|[^\w-])(hsla?|rgba?)\(/i.test(l))return;let o;try{o=r.default(l)}catch(r){e.warn(u,`Failed to parse value '${l}' as a hsl or rgb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&("hsl"!==e.value&&"hsla"!==e.value&&"rgb"!==e.value&&"rgba"!==e.value||t(e))}));const i=String(o);if(i!==l)if(n&&e.variable){const r=e.parent,t="(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))",n=a.atRule({name:"supports",params:t,source:e.source}),u=r.clone();u.removeAll(),u.append(e.clone()),n.append(u);let l=r,o=r.next();for(;l&&o&&"atrule"===o.type&&"supports"===o.name&&o.params===t;)l=o,o=o.next();l.after(n),e.value=i}else n?e.cloneBefore({value:i}):e.value=i}}};i.postcss=!0,module.exports=i;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"postcss-value-parser";function r(r){const o=r.value;let
|
|
1
|
+
import e from"postcss-value-parser";function r(r){const o=r.value;if(!function(e,r){let n=!1,t=!1,u=!1;const a=r.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));for(let l=0;l<a.length;l++){const o=a[l];if("word"===o.type&&"from"===o.value)return!1;"div"!==o.type||","!==o.value?e&&"word"===o.type&&o.value.endsWith("%")?u=!0:l===r.length-1&&"word"===o.type&&o.value.endsWith("%")&&(t=!0):n=!0}if(n&&(t||u))return!0;if(n)return!1;return!0}("rgb"===o||"rgba"===o,r.nodes))return;const i=function(e){let r=0;for(let n=0;n<e.length;n++){const t=e[n];if("div"===t.type&&","===t.value){if(r<2&&(t.value=" ",t.type="space"),2===r&&(t.value="/"),r>2)return;r++}}return e}(r.nodes),s=i.slice().filter((e=>"comment"!==e.type&&"space"!==e.type));let c=null;if("hsl"===o||"hsla"===o?c=function(r){if(!function(r){if(!r||"word"!==r.type)return!1;if(!l(r))return!1;const n=e.unit(r.value);if(!n)return!1;return!!n.number&&("deg"===n.unit||"grad"===n.unit||"rad"===n.unit||"turn"===n.unit||""===n.unit)}(r[0]))return null;if(!n(r[1]))return null;if(!n(r[2]))return null;const o={h:e.unit(r[0].value),hNode:r[0],s:e.unit(r[1].value),sNode:r[1],l:e.unit(r[2].value),lNode:r[2]};if(function(e){switch(e.unit){case"deg":return void(e.unit="");case"rad":return e.unit="",void(e.number=Math.round(180*parseFloat(e.number)/Math.PI).toString());case"grad":return e.unit="",void(e.number=Math.round(.9*parseFloat(e.number)).toString());case"turn":e.unit="",e.number=Math.round(360*parseFloat(e.number)).toString()}}(o.h),""!==o.h.unit)return null;o.hNode.value=o.h.number,a(r[3])&&(o.slash=r[3]);(n(r[4])||t(r[4])||u(r[4]))&&(o.alpha=r[4]);return o}(s):"rgb"!==o&&"rgba"!==o||(c=function(r){if(!n(r[0]))return null;if(!n(r[1]))return null;if(!n(r[2]))return null;const l={r:e.unit(r[0].value),rNode:r[0],g:e.unit(r[1].value),gNode:r[1],b:e.unit(r[2].value),bNode:r[2]};"%"===l.r.unit&&(l.r.number=String(Math.floor(Number(l.r.number)/100*255)),l.rNode.value=l.r.number);"%"===l.g.unit&&(l.g.number=String(Math.floor(Number(l.g.number)/100*255)),l.gNode.value=l.g.number);"%"===l.b.unit&&(l.b.number=String(Math.floor(Number(l.b.number)/100*255)),l.bNode.value=l.b.number);a(r[3])&&(l.slash=r[3]);(n(r[4])||t(r[4])||u(r[4]))&&(l.alpha=r[4]);return l}(s)),!c)return;if(s.length>3&&(!c.slash||!c.alpha))return;!function(r,n,t){"hsl"===r.value||"hsla"===r.value?r.value="hsl":"rgb"!==r.value&&"rgba"!==r.value||(r.value="rgb");if(!n||!t)return;"hsl"===r.value?r.value="hsla":r.value="rgba";if(n.value=",",n.before="",!function(r){if(!r||"word"!==r.type)return!1;if(!l(r))return!1;const n=e.unit(r.value);if(!n)return!1;return!!n.number}(t))return;const u=e.unit(t.value);if(!u)return;"%"===u.unit&&(u.number=String(parseFloat(u.number)/100),t.value=String(u.number))}(r,c.slash,c.alpha);const[f,v]=function(e){if(function(e){if(void 0!==e.r)return!0;return!1}(e))return[e.rNode,e.gNode,e.bNode];return[e.hNode,e.sNode,e.lNode]}(c);r.nodes.splice(r.nodes.indexOf(f)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""}),r.nodes.splice(r.nodes.indexOf(v)+1,0,{sourceIndex:0,sourceEndIndex:1,value:",",type:"div",before:"",after:""})}function n(r){if(!r||"word"!==r.type)return!1;if(!l(r))return!1;const n=e.unit(r.value);return!!n&&("%"===n.unit||""===n.unit)}function t(e){return e&&"function"===e.type&&"calc"===e.value}function u(e){return e&&"function"===e.type&&"var"===e.value}function a(e){return e&&"div"===e.type&&"/"===e.value}function l(r){if(!r||!r.value)return!1;try{return!1!==e.unit(r.value)}catch(e){return!1}}const o=n=>{const t="preserve"in Object(n)&&Boolean(n.preserve);return{postcssPlugin:"postcss-color-functional-notation",Declaration:(n,{result:u,postcss:a})=>{if(t&&function(e){let r=e.parent;for(;r;)if("atrule"===r.type){if("supports"===r.name&&-1!==r.params.indexOf("(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))"))return!0;r=r.parent}else r=r.parent;return!1}(n))return;const l=n.value;if(!/(^|[^\w-])(hsla?|rgba?)\(/i.test(l))return;let o;try{o=e(l)}catch(e){n.warn(u,`Failed to parse value '${l}' as a hsl or rgb function. Leaving the original value intact.`)}if(void 0===o)return;o.walk((e=>{e.type&&"function"===e.type&&("hsl"!==e.value&&"hsla"!==e.value&&"rgb"!==e.value&&"rgba"!==e.value||r(e))}));const i=String(o);if(i!==l)if(t&&n.variable){const e=n.parent,r="(color: rgb(0 0 0 / 0.5)) and (color: hsl(0 0% 0% / 0.5))",t=a.atRule({name:"supports",params:r,source:n.source}),u=e.clone();u.removeAll(),u.append(n.clone()),t.append(u);let l=e,o=e.next();for(;l&&o&&"atrule"===o.type&&"supports"===o.name&&o.params===r;)l=o,o=o.next();l.after(t),n.value=i}else t?n.cloneBefore({value:i}):n.value=i}}};o.postcss=!0;export{o as default};
|
package/package.json
CHANGED
|
@@ -1,73 +1,80 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
2
|
+
"name": "postcss-color-functional-notation",
|
|
3
|
+
"description": "Use space and slash separated color notation in CSS",
|
|
4
|
+
"version": "4.2.3",
|
|
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
|
+
"postcss-value-parser": "^4.2.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"postcss": "^8.4"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "rollup -c ../../rollup/default.js",
|
|
38
|
+
"clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
|
|
39
|
+
"docs": "node ../../.github/bin/generate-docs/install.mjs",
|
|
40
|
+
"lint": "npm run lint:eslint && npm run lint:package-json",
|
|
41
|
+
"lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
|
|
42
|
+
"lint:package-json": "node ../../.github/bin/format-package-json.mjs",
|
|
43
|
+
"prepublishOnly": "npm run clean && npm run build && npm run test",
|
|
44
|
+
"test": "node .tape.mjs && npm run test:exports",
|
|
45
|
+
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs",
|
|
46
|
+
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-functional-notation#readme",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
52
|
+
"directory": "plugins/postcss-color-functional-notation"
|
|
53
|
+
},
|
|
54
|
+
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|
|
55
|
+
"keywords": [
|
|
56
|
+
"color",
|
|
57
|
+
"colors",
|
|
58
|
+
"comma",
|
|
59
|
+
"css",
|
|
60
|
+
"design",
|
|
61
|
+
"functional",
|
|
62
|
+
"hsl",
|
|
63
|
+
"hsla",
|
|
64
|
+
"hwb",
|
|
65
|
+
"notation",
|
|
66
|
+
"postcss",
|
|
67
|
+
"postcss-plugin",
|
|
68
|
+
"rgb",
|
|
69
|
+
"rgba",
|
|
70
|
+
"space",
|
|
71
|
+
"syntax"
|
|
72
|
+
],
|
|
73
|
+
"csstools": {
|
|
74
|
+
"exportName": "postcssColorFunctionalNotation",
|
|
75
|
+
"humanReadableName": "PostCSS Color Functional Notation"
|
|
76
|
+
},
|
|
77
|
+
"volta": {
|
|
78
|
+
"extends": "../../package.json"
|
|
79
|
+
}
|
|
73
80
|
}
|