postcss-lab-function 3.1.0 → 4.0.1
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/README.md +4 -12
- package/dist/index.cjs.js +35 -21
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +36 -20
- package/dist/index.esm.js.map +1 -0
- package/package.json +19 -30
- package/CHANGELOG.md +0 -37
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[<img alt="npm version" src="https://img.shields.io/npm/v/postcss-lab-function.svg" height="20">][npm-url]
|
|
4
4
|
[<img alt="CSS Standard Status" src="https://cssdb.org/badge/lab-function.svg" height="20">][css-url]
|
|
5
|
-
[<img alt="
|
|
5
|
+
[<img alt="Build Status" src="https://github.com/csstools/postcss-lab-function/workflows/test/badge.svg" height="20">][cli-url]
|
|
6
6
|
[<img alt="support chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
|
|
7
7
|
|
|
8
8
|
|
|
@@ -28,18 +28,10 @@
|
|
|
28
28
|
Add [PostCSS Lab Function] to your project:
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
npm install postcss-lab-function --save-dev
|
|
31
|
+
npm install postcss postcss-lab-function --save-dev
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Use [PostCSS
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
const postcssLabFunction = require('postcss-lab-function');
|
|
38
|
-
|
|
39
|
-
postcssLabFunction.process(YOUR_CSS /*, processOptions, pluginOptions */);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Or use it as a [PostCSS] plugin:
|
|
34
|
+
Use it as a [PostCSS] plugin:
|
|
43
35
|
|
|
44
36
|
```js
|
|
45
37
|
const postcss = require('postcss');
|
|
@@ -83,7 +75,7 @@ postcssLabFunction({ preserve: true })
|
|
|
83
75
|
}
|
|
84
76
|
```
|
|
85
77
|
|
|
86
|
-
[cli-url]: https://
|
|
78
|
+
[cli-url]: https://github.com/csstools/postcss-lab-function/actions/workflows/test.yml?query=workflow/test
|
|
87
79
|
[css-url]: https://cssdb.org/#lab-function
|
|
88
80
|
[git-url]: https://gitter.im/postcss/postcss
|
|
89
81
|
[npm-url]: https://www.npmjs.com/package/postcss-lab-function
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
-
|
|
5
|
-
var postcss = _interopDefault(require('postcss'));
|
|
6
3
|
var postcssValuesParser = require('postcss-values-parser');
|
|
7
4
|
var convertColors = require('@csstools/convert-colors');
|
|
8
5
|
|
|
@@ -80,22 +77,22 @@ const onCSSFunction = node => {
|
|
|
80
77
|
const commaNode = postcssValuesParser.parse(',').first;
|
|
81
78
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
82
79
|
|
|
83
|
-
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
80
|
+
const createRegExpTest$1 = Function.bind.bind(RegExp.prototype.test);
|
|
84
81
|
/** Return whether the function name is `lab` or `lch`. */
|
|
85
82
|
|
|
86
|
-
const isColorFunctionName = createRegExpTest(/^(lab|lch)$/i);
|
|
83
|
+
const isColorFunctionName = createRegExpTest$1(/^(lab|lch)$/i);
|
|
87
84
|
/** Return whether the function name is `calc`. */
|
|
88
85
|
|
|
89
|
-
const isCalcFunctionName = createRegExpTest(/^calc$/i);
|
|
86
|
+
const isCalcFunctionName = createRegExpTest$1(/^calc$/i);
|
|
90
87
|
/** Return whether the function name is `lab`. */
|
|
91
88
|
|
|
92
|
-
const isLabColorFunctionName = createRegExpTest(/^lab$/i);
|
|
89
|
+
const isLabColorFunctionName = createRegExpTest$1(/^lab$/i);
|
|
93
90
|
/** Return whether the unit is alpha-like. */
|
|
94
91
|
|
|
95
|
-
const isAlphaLikeUnit = createRegExpTest(/^%?$/i);
|
|
92
|
+
const isAlphaLikeUnit = createRegExpTest$1(/^%?$/i);
|
|
96
93
|
/** Return whether the unit is hue-like. */
|
|
97
94
|
|
|
98
|
-
const isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i);
|
|
95
|
+
const isHueLikeUnit = createRegExpTest$1(/^(deg|grad|rad|turn)?$/i);
|
|
99
96
|
/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */
|
|
100
97
|
|
|
101
98
|
const isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit);
|
|
@@ -151,14 +148,29 @@ var options = {
|
|
|
151
148
|
|
|
152
149
|
/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */
|
|
153
150
|
|
|
154
|
-
const onCSSDeclaration = decl
|
|
151
|
+
const onCSSDeclaration = (decl, {
|
|
152
|
+
result
|
|
153
|
+
}) => {
|
|
155
154
|
const {
|
|
156
155
|
value: originalValue
|
|
157
156
|
} = decl;
|
|
158
157
|
|
|
159
158
|
if (hasAnyColorFunction(originalValue)) {
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
let valueAST;
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
valueAST = postcssValuesParser.parse(originalValue, {
|
|
163
|
+
ignoreUnknownWords: true
|
|
164
|
+
});
|
|
165
|
+
} catch (error) {
|
|
166
|
+
decl.warn(result, `Failed to parse value '${originalValue}' as a lab or hcl function. Leaving the original value intact.`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (typeof valueAST === 'undefined') {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
valueAST.walkType('func', onCSSFunction);
|
|
162
174
|
const modifiedValue = String(valueAST);
|
|
163
175
|
|
|
164
176
|
if (modifiedValue !== originalValue) {
|
|
@@ -170,26 +182,28 @@ const onCSSDeclaration = decl => {
|
|
|
170
182
|
};
|
|
171
183
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
172
184
|
|
|
173
|
-
const createRegExpTest
|
|
185
|
+
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
174
186
|
/** Return whether the value has a lab() or lch() function. */
|
|
175
187
|
|
|
176
|
-
const hasAnyColorFunction = createRegExpTest
|
|
188
|
+
const hasAnyColorFunction = createRegExpTest(/(^|[^\w-])(lab|lch)\(/i);
|
|
177
189
|
/** @typedef {import('postcss').Declaration} CSSDeclaration */
|
|
178
190
|
|
|
179
191
|
/** Transform lab() and lch() functions in CSS. */
|
|
180
192
|
|
|
181
|
-
const postcssPlugin =
|
|
193
|
+
const postcssPlugin =
|
|
182
194
|
/** @type {PostCSSPluginInitializer} */
|
|
183
195
|
opts => {
|
|
184
196
|
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
|
|
185
|
-
return
|
|
186
|
-
|
|
197
|
+
return {
|
|
198
|
+
postcssPlugin: 'postcss-lab-function',
|
|
199
|
+
Declaration: onCSSDeclaration
|
|
187
200
|
};
|
|
188
|
-
}
|
|
189
|
-
/** @typedef {import('postcss').Root} CSSRoot */
|
|
201
|
+
};
|
|
190
202
|
|
|
191
|
-
|
|
203
|
+
postcssPlugin.postcss = true;
|
|
204
|
+
/** @typedef {import('postcss').Plugin} PostCSSPlugin */
|
|
192
205
|
|
|
193
|
-
/** @typedef {(opts: options) =>
|
|
206
|
+
/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */
|
|
194
207
|
|
|
195
208
|
module.exports = postcssPlugin;
|
|
209
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/onCSSFunction.js","../src/options.js","../src/onCSSDeclaration.js","../src/index.js"],"sourcesContent":["import { lab2rgb, lch2rgb } from '@csstools/convert-colors'\nimport { parse } from 'postcss-values-parser'\n\n/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */\nconst onCSSFunction = node => {\n\t/** @type {{ name: string, nodes: CSSNode[] }} */\n\tconst { name, nodes } = node\n\n\tif (isColorFunctionName(name)) {\n\t\tif (isLabFunctionContents(nodes) || isLchFunctionContents(nodes)) {\n\t\t\t// rename the Color function to `rgb`\n\t\t\tObject.assign(node, { name: 'rgb' })\n\n\t\t\t/** @type {CSSPunctuation} Slash punctuation before the Alpha channel. */\n\t\t\tconst slashNode = nodes[3]\n\n\t\t\t/** @type {CSSNumber} Alpha channel. */\n\t\t\tconst alphaNode = nodes[4]\n\n\t\t\tif (alphaNode) {\n\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t// transform the Alpha channel from a Percentage to (0-1) Number\n\t\t\t\t\tObject.assign(alphaNode, { value: String(alphaNode.value / 100), unit: '' })\n\t\t\t\t}\n\n\t\t\t\t// if the color is fully opaque (i.e. the Alpha channel is `1`)\n\t\t\t\tif (alphaNode.value === '1') {\n\t\t\t\t\t// remove the Slash and Alpha channel\n\t\t\t\t\tslashNode.remove()\n\t\t\t\t\talphaNode.remove()\n\t\t\t\t} else {\n\t\t\t\t\t// otherwise, rename the Color function to `rgba`\n\t\t\t\t\tObject.assign(node, { name: 'rgba' })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// replace a remaining Slash with a Comma\n\t\t\tif (slashNode && isSlash(slashNode)) {\n\t\t\t\tslashNode.replaceWith(commaNode.clone())\n\t\t\t}\n\n\t\t\t/** Extracted Color channels. */\n\t\t\tconst [channelNode1, channelNode2, channelNode3] = nodes\n\n\t\t\t/** Corresponding Color transformer. */\n\t\t\tconst toRGB = isLabColorFunctionName(name) ? lab2rgb : lch2rgb\n\n\t\t\t/** RGB channels from the source color. */\n\t\t\tconst rgbValues = toRGB(\n\t\t\t\t...[\n\t\t\t\t\tchannelNode1.value,\n\t\t\t\t\tchannelNode2.value,\n\t\t\t\t\tchannelNode3.value\n\t\t\t\t].map(\n\t\t\t\t\tchannelNumber => parseFloat(channelNumber)\n\t\t\t\t)\n\t\t\t).map(\n\t\t\t\tchannelValue => Math.max(Math.min(parseInt(channelValue * 2.55), 255), 0)\n\t\t\t)\n\n\t\t\tchannelNode3.replaceWith(\n\t\t\t\tchannelNode3.clone({ value: String(rgbValues[2]) })\n\t\t\t)\n\n\t\t\tchannelNode2.replaceWith(\n\t\t\t\tchannelNode2.clone({ value: String(rgbValues[1]) }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\n\t\t\tchannelNode1.replaceWith(\n\t\t\t\tchannelNode1.clone({ value: String(rgbValues[0]), unit: '' }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\t\t}\n\t}\n}\n\nexport default onCSSFunction\n\nconst commaNode = parse(',').first\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the function name is `lab` or `lch`. */\nconst isColorFunctionName = createRegExpTest(/^(lab|lch)$/i)\n\n/** Return whether the function name is `calc`. */\nconst isCalcFunctionName = createRegExpTest(/^calc$/i)\n\n/** Return whether the function name is `lab`. */\nconst isLabColorFunctionName = createRegExpTest(/^lab$/i)\n\n/** Return whether the unit is alpha-like. */\nconst isAlphaLikeUnit = createRegExpTest(/^%?$/i)\n\n/** Return whether the unit is hue-like. */\nconst isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */\nconst isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is a calc() function. */\nconst isCalc = node => node.type === 'func' && isCalcFunctionName(node.name)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Hue-like unit. */\nconst isHue = node => isCalc(node) || node.type === 'numeric' && isHueLikeUnit(node.unit)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Number unit. */\nconst isNumber = node => isCalc(node) || node.type === 'numeric' && node.unit === ''\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Percentage unit. */\nconst isPercentage = node => isCalc(node) || node.type === 'numeric' && node.unit === '%'\n\n/** @type {(node: CSSOperator) => boolean} Return whether the node is a Slash delimiter. */\nconst isSlash = node => node.type === 'operator' && node.value === '/'\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lab() function. */\nconst isLabFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof labFunctionContents[index] === 'function' && labFunctionContents[index](node)\n)\n\n/** Set of nodes in a lab() function. */\nconst labFunctionContents = [isPercentage, isNumber, isNumber, isSlash, isAlphaValue]\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lch() function. */\nconst isLchFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof lchFunctionContents[index] === 'function' && lchFunctionContents[index](node)\n)\n\n/** Set of nodes in a lch() function. */\nconst lchFunctionContents = [isPercentage, isNumber, isHue, isSlash, isAlphaValue]\n\n/** @typedef {import('postcss-values-parser').Func} CSSFunction */\n/** @typedef {import('postcss-values-parser').Node} CSSNode */\n/** @typedef {import('postcss-values-parser').Numeric} CSSNumber */\n/** @typedef {import('postcss-values-parser').Operator} CSSOperator */\n/** @typedef {import('postcss-values-parser').Punctuation} CSSPunctuation */\n","export default {\n\t/** Whether to preserve the original functional color declaration. */\n\tpreserve: false\n}\n","import { parse } from 'postcss-values-parser'\nimport onCSSFunction from './onCSSFunction'\nimport options from './options'\n\n/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */\nconst onCSSDeclaration = (decl, { result }) => {\n\tconst { value: originalValue } = decl\n\n\tif (hasAnyColorFunction(originalValue)) {\n\t\tlet valueAST\n\n\t\ttry {\n\t\t\tvalueAST = parse(originalValue, { ignoreUnknownWords: true })\n\t\t} catch (error) {\n\t\t\tdecl.warn(\n\t\t\t\tresult,\n\t\t\t\t`Failed to parse value '${originalValue}' as a lab or hcl function. Leaving the original value intact.`\n\t\t\t)\n\t\t}\n\n\t\tif (typeof valueAST === 'undefined') {\n\t\t\treturn\n\t\t}\n\n\t\tvalueAST.walkType('func', onCSSFunction)\n\n\t\tconst modifiedValue = String(valueAST)\n\n\t\tif (modifiedValue !== originalValue) {\n\t\t\tif (options.preserve) decl.cloneBefore({ value: modifiedValue })\n\t\t\telse decl.value = modifiedValue\n\t\t}\n\t}\n}\n\nexport default onCSSDeclaration\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the value has a lab() or lch() function. */\nconst hasAnyColorFunction = createRegExpTest(/(^|[^\\w-])(lab|lch)\\(/i)\n\n/** @typedef {import('postcss').Declaration} CSSDeclaration */\n","import onCSSDeclaration from './onCSSDeclaration'\nimport options from './options'\n\n/** Transform lab() and lch() functions in CSS. */\nconst postcssPlugin = /** @type {PostCSSPluginInitializer} */ opts => {\n\toptions.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false\n\n\treturn {\n\t\tpostcssPlugin: 'postcss-lab-function',\n\t\tDeclaration: onCSSDeclaration,\n\t}\n}\n\npostcssPlugin.postcss = true\n\nexport default postcssPlugin\n\n/** @typedef {import('postcss').Plugin} PostCSSPlugin */\n/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */\n"],"names":["onCSSFunction","node","name","nodes","isColorFunctionName","isLabFunctionContents","isLchFunctionContents","Object","assign","slashNode","alphaNode","isPercentage","isCalc","value","String","unit","remove","isSlash","replaceWith","commaNode","clone","channelNode1","channelNode2","channelNode3","toRGB","isLabColorFunctionName","lab2rgb","lch2rgb","rgbValues","map","channelNumber","parseFloat","channelValue","Math","max","min","parseInt","parse","first","createRegExpTest","Function","bind","RegExp","prototype","test","isCalcFunctionName","isAlphaLikeUnit","isHueLikeUnit","isAlphaValue","type","isHue","isNumber","every","index","labFunctionContents","lchFunctionContents","preserve","onCSSDeclaration","decl","result","originalValue","hasAnyColorFunction","valueAST","ignoreUnknownWords","error","warn","walkType","modifiedValue","options","cloneBefore","postcssPlugin","opts","Boolean","Declaration","postcss"],"mappings":";;;;;AAGA;;AACA,MAAMA,aAAa,GAAGC,IAAI,IAAI;AAC7B;AACA,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBF,IAAxB;;AAEA,MAAIG,mBAAmB,CAACF,IAAD,CAAvB,EAA+B;AAC9B,QAAIG,qBAAqB,CAACF,KAAD,CAArB,IAAgCG,qBAAqB,CAACH,KAAD,CAAzD,EAAkE;AACjE;AACAI,MAAAA,MAAM,CAACC,MAAP,CAAcP,IAAd,EAAoB;AAAEC,QAAAA,IAAI,EAAE;AAAR,OAApB;AAEA;;AACA,YAAMO,SAAS,GAAGN,KAAK,CAAC,CAAD,CAAvB;AAEA;;AACA,YAAMO,SAAS,GAAGP,KAAK,CAAC,CAAD,CAAvB;;AAEA,UAAIO,SAAJ,EAAe;AACd,YAAIC,YAAY,CAACD,SAAD,CAAZ,IAA2B,CAACE,MAAM,CAACF,SAAD,CAAtC,EAAmD;AAClD;AACAH,UAAAA,MAAM,CAACC,MAAP,CAAcE,SAAd,EAAyB;AAAEG,YAAAA,KAAK,EAAEC,MAAM,CAACJ,SAAS,CAACG,KAAV,GAAkB,GAAnB,CAAf;AAAwCE,YAAAA,IAAI,EAAE;AAA9C,WAAzB;AACA,SAJa;;;AAOd,YAAIL,SAAS,CAACG,KAAV,KAAoB,GAAxB,EAA6B;AAC5B;AACAJ,UAAAA,SAAS,CAACO,MAAV;AACAN,UAAAA,SAAS,CAACM,MAAV;AACA,SAJD,MAIO;AACN;AACAT,UAAAA,MAAM,CAACC,MAAP,CAAcP,IAAd,EAAoB;AAAEC,YAAAA,IAAI,EAAE;AAAR,WAApB;AACA;AACD,OAzBgE;;;AA4BjE,UAAIO,SAAS,IAAIQ,OAAO,CAACR,SAAD,CAAxB,EA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,EAAc;AACfN,MAAAA,IAAI,CAACO,IAAL,CACCN,MADD,EAEE,0BAAyBC,aAAc,gEAFzC;AAIA;;AAED,QAAI,OAAOE,QAAP,KAAoB,WAAxB,EAAqC;AACpC;AACA;;AAEDA,IAAAA,QAAQ,CAACI,QAAT,CAAkB,MAAlB,EAA0BlE,aAA1B;AAEA,UAAMmE,aAAa,GAAGrD,MAAM,CAACgD,QAAD,CAA5B;;AAEA,QAAIK,aAAa,KAAKP,aAAtB,EAAqC;AACpC,UAAIQ,OAAO,CAACZ,QAAZ,EAAsBE,IAAI,CAACW,WAAL,CAAiB;AAAExD,QAAAA,KAAK,EAAEsD;AAAT,OAAjB,EAAtB,KACKT,IAAI,CAAC7C,KAAL,GAAasD,aAAb;AACL;AACD;AACD,CA5BD;AAgCA;;AACA,MAAM5B,gBAAgB,GAAGC,QAAQ,CAACC,IAAT,CAAcA,IAAd,CAAmBC,MAAM,CAACC,SAAP,CAAiBC,IAApC,CAAzB;AAEA;;AACA,MAAMiB,mBAAmB,GAAGtB,gBAAgB,CAAC,wBAAD,CAA5C;AAEA;;ACxCA;;MACM+B,aAAa;AAAG;AAAwCC,IAAI,IAAI;AACrEH,EAAAA,OAAO,CAACZ,QAAR,GAAmB,cAAcjD,MAAM,CAACgE,IAAD,CAApB,GAA6BC,OAAO,CAACD,IAAI,CAACf,QAAN,CAApC,GAAsD,KAAzE;AAEA,SAAO;AACNc,IAAAA,aAAa,EAAE,sBADT;AAENG,IAAAA,WAAW,EAAEhB;AAFP,GAAP;AAIA;;AAEDa,aAAa,CAACI,OAAd,GAAwB,IAAxB;AAIA;;AACA;;;;"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import postcss from 'postcss';
|
|
2
1
|
import { parse } from 'postcss-values-parser';
|
|
3
2
|
import { lab2rgb, lch2rgb } from '@csstools/convert-colors';
|
|
4
3
|
|
|
@@ -76,22 +75,22 @@ const onCSSFunction = node => {
|
|
|
76
75
|
const commaNode = parse(',').first;
|
|
77
76
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
78
77
|
|
|
79
|
-
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
78
|
+
const createRegExpTest$1 = Function.bind.bind(RegExp.prototype.test);
|
|
80
79
|
/** Return whether the function name is `lab` or `lch`. */
|
|
81
80
|
|
|
82
|
-
const isColorFunctionName = createRegExpTest(/^(lab|lch)$/i);
|
|
81
|
+
const isColorFunctionName = createRegExpTest$1(/^(lab|lch)$/i);
|
|
83
82
|
/** Return whether the function name is `calc`. */
|
|
84
83
|
|
|
85
|
-
const isCalcFunctionName = createRegExpTest(/^calc$/i);
|
|
84
|
+
const isCalcFunctionName = createRegExpTest$1(/^calc$/i);
|
|
86
85
|
/** Return whether the function name is `lab`. */
|
|
87
86
|
|
|
88
|
-
const isLabColorFunctionName = createRegExpTest(/^lab$/i);
|
|
87
|
+
const isLabColorFunctionName = createRegExpTest$1(/^lab$/i);
|
|
89
88
|
/** Return whether the unit is alpha-like. */
|
|
90
89
|
|
|
91
|
-
const isAlphaLikeUnit = createRegExpTest(/^%?$/i);
|
|
90
|
+
const isAlphaLikeUnit = createRegExpTest$1(/^%?$/i);
|
|
92
91
|
/** Return whether the unit is hue-like. */
|
|
93
92
|
|
|
94
|
-
const isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i);
|
|
93
|
+
const isHueLikeUnit = createRegExpTest$1(/^(deg|grad|rad|turn)?$/i);
|
|
95
94
|
/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */
|
|
96
95
|
|
|
97
96
|
const isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit);
|
|
@@ -147,14 +146,29 @@ var options = {
|
|
|
147
146
|
|
|
148
147
|
/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */
|
|
149
148
|
|
|
150
|
-
const onCSSDeclaration = decl
|
|
149
|
+
const onCSSDeclaration = (decl, {
|
|
150
|
+
result
|
|
151
|
+
}) => {
|
|
151
152
|
const {
|
|
152
153
|
value: originalValue
|
|
153
154
|
} = decl;
|
|
154
155
|
|
|
155
156
|
if (hasAnyColorFunction(originalValue)) {
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
let valueAST;
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
valueAST = parse(originalValue, {
|
|
161
|
+
ignoreUnknownWords: true
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
decl.warn(result, `Failed to parse value '${originalValue}' as a lab or hcl function. Leaving the original value intact.`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (typeof valueAST === 'undefined') {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
valueAST.walkType('func', onCSSFunction);
|
|
158
172
|
const modifiedValue = String(valueAST);
|
|
159
173
|
|
|
160
174
|
if (modifiedValue !== originalValue) {
|
|
@@ -166,26 +180,28 @@ const onCSSDeclaration = decl => {
|
|
|
166
180
|
};
|
|
167
181
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
168
182
|
|
|
169
|
-
const createRegExpTest
|
|
183
|
+
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
170
184
|
/** Return whether the value has a lab() or lch() function. */
|
|
171
185
|
|
|
172
|
-
const hasAnyColorFunction = createRegExpTest
|
|
186
|
+
const hasAnyColorFunction = createRegExpTest(/(^|[^\w-])(lab|lch)\(/i);
|
|
173
187
|
/** @typedef {import('postcss').Declaration} CSSDeclaration */
|
|
174
188
|
|
|
175
189
|
/** Transform lab() and lch() functions in CSS. */
|
|
176
190
|
|
|
177
|
-
const postcssPlugin =
|
|
191
|
+
const postcssPlugin =
|
|
178
192
|
/** @type {PostCSSPluginInitializer} */
|
|
179
193
|
opts => {
|
|
180
194
|
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
|
|
181
|
-
return
|
|
182
|
-
|
|
195
|
+
return {
|
|
196
|
+
postcssPlugin: 'postcss-lab-function',
|
|
197
|
+
Declaration: onCSSDeclaration
|
|
183
198
|
};
|
|
184
|
-
}
|
|
185
|
-
/** @typedef {import('postcss').Root} CSSRoot */
|
|
199
|
+
};
|
|
186
200
|
|
|
187
|
-
|
|
201
|
+
postcssPlugin.postcss = true;
|
|
202
|
+
/** @typedef {import('postcss').Plugin} PostCSSPlugin */
|
|
188
203
|
|
|
189
|
-
/** @typedef {(opts: options) =>
|
|
204
|
+
/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */
|
|
190
205
|
|
|
191
|
-
export default
|
|
206
|
+
export { postcssPlugin as default };
|
|
207
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/onCSSFunction.js","../src/options.js","../src/onCSSDeclaration.js","../src/index.js"],"sourcesContent":["import { lab2rgb, lch2rgb } from '@csstools/convert-colors'\nimport { parse } from 'postcss-values-parser'\n\n/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */\nconst onCSSFunction = node => {\n\t/** @type {{ name: string, nodes: CSSNode[] }} */\n\tconst { name, nodes } = node\n\n\tif (isColorFunctionName(name)) {\n\t\tif (isLabFunctionContents(nodes) || isLchFunctionContents(nodes)) {\n\t\t\t// rename the Color function to `rgb`\n\t\t\tObject.assign(node, { name: 'rgb' })\n\n\t\t\t/** @type {CSSPunctuation} Slash punctuation before the Alpha channel. */\n\t\t\tconst slashNode = nodes[3]\n\n\t\t\t/** @type {CSSNumber} Alpha channel. */\n\t\t\tconst alphaNode = nodes[4]\n\n\t\t\tif (alphaNode) {\n\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t// transform the Alpha channel from a Percentage to (0-1) Number\n\t\t\t\t\tObject.assign(alphaNode, { value: String(alphaNode.value / 100), unit: '' })\n\t\t\t\t}\n\n\t\t\t\t// if the color is fully opaque (i.e. the Alpha channel is `1`)\n\t\t\t\tif (alphaNode.value === '1') {\n\t\t\t\t\t// remove the Slash and Alpha channel\n\t\t\t\t\tslashNode.remove()\n\t\t\t\t\talphaNode.remove()\n\t\t\t\t} else {\n\t\t\t\t\t// otherwise, rename the Color function to `rgba`\n\t\t\t\t\tObject.assign(node, { name: 'rgba' })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// replace a remaining Slash with a Comma\n\t\t\tif (slashNode && isSlash(slashNode)) {\n\t\t\t\tslashNode.replaceWith(commaNode.clone())\n\t\t\t}\n\n\t\t\t/** Extracted Color channels. */\n\t\t\tconst [channelNode1, channelNode2, channelNode3] = nodes\n\n\t\t\t/** Corresponding Color transformer. */\n\t\t\tconst toRGB = isLabColorFunctionName(name) ? lab2rgb : lch2rgb\n\n\t\t\t/** RGB channels from the source color. */\n\t\t\tconst rgbValues = toRGB(\n\t\t\t\t...[\n\t\t\t\t\tchannelNode1.value,\n\t\t\t\t\tchannelNode2.value,\n\t\t\t\t\tchannelNode3.value\n\t\t\t\t].map(\n\t\t\t\t\tchannelNumber => parseFloat(channelNumber)\n\t\t\t\t)\n\t\t\t).map(\n\t\t\t\tchannelValue => Math.max(Math.min(parseInt(channelValue * 2.55), 255), 0)\n\t\t\t)\n\n\t\t\tchannelNode3.replaceWith(\n\t\t\t\tchannelNode3.clone({ value: String(rgbValues[2]) })\n\t\t\t)\n\n\t\t\tchannelNode2.replaceWith(\n\t\t\t\tchannelNode2.clone({ value: String(rgbValues[1]) }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\n\t\t\tchannelNode1.replaceWith(\n\t\t\t\tchannelNode1.clone({ value: String(rgbValues[0]), unit: '' }),\n\t\t\t\tcommaNode.clone()\n\t\t\t)\n\t\t}\n\t}\n}\n\nexport default onCSSFunction\n\nconst commaNode = parse(',').first\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the function name is `lab` or `lch`. */\nconst isColorFunctionName = createRegExpTest(/^(lab|lch)$/i)\n\n/** Return whether the function name is `calc`. */\nconst isCalcFunctionName = createRegExpTest(/^calc$/i)\n\n/** Return whether the function name is `lab`. */\nconst isLabColorFunctionName = createRegExpTest(/^lab$/i)\n\n/** Return whether the unit is alpha-like. */\nconst isAlphaLikeUnit = createRegExpTest(/^%?$/i)\n\n/** Return whether the unit is hue-like. */\nconst isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is an Alpha-like unit. */\nconst isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit)\n\n/** @type {(node: CSSFunction) => boolean} Return whether the node is a calc() function. */\nconst isCalc = node => node.type === 'func' && isCalcFunctionName(node.name)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Hue-like unit. */\nconst isHue = node => isCalc(node) || node.type === 'numeric' && isHueLikeUnit(node.unit)\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Number unit. */\nconst isNumber = node => isCalc(node) || node.type === 'numeric' && node.unit === ''\n\n/** @type {(node: CSSNumber) => boolean} Return whether the node is a Percentage unit. */\nconst isPercentage = node => isCalc(node) || node.type === 'numeric' && node.unit === '%'\n\n/** @type {(node: CSSOperator) => boolean} Return whether the node is a Slash delimiter. */\nconst isSlash = node => node.type === 'operator' && node.value === '/'\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lab() function. */\nconst isLabFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof labFunctionContents[index] === 'function' && labFunctionContents[index](node)\n)\n\n/** Set of nodes in a lab() function. */\nconst labFunctionContents = [isPercentage, isNumber, isNumber, isSlash, isAlphaValue]\n\n/** @type {(nodes: Node[]) => boolean} Return whether a set of nodes is a lch() function. */\nconst isLchFunctionContents = nodes => nodes.every(\n\t(node, index) => typeof lchFunctionContents[index] === 'function' && lchFunctionContents[index](node)\n)\n\n/** Set of nodes in a lch() function. */\nconst lchFunctionContents = [isPercentage, isNumber, isHue, isSlash, isAlphaValue]\n\n/** @typedef {import('postcss-values-parser').Func} CSSFunction */\n/** @typedef {import('postcss-values-parser').Node} CSSNode */\n/** @typedef {import('postcss-values-parser').Numeric} CSSNumber */\n/** @typedef {import('postcss-values-parser').Operator} CSSOperator */\n/** @typedef {import('postcss-values-parser').Punctuation} CSSPunctuation */\n","export default {\n\t/** Whether to preserve the original functional color declaration. */\n\tpreserve: false\n}\n","import { parse } from 'postcss-values-parser'\nimport onCSSFunction from './onCSSFunction'\nimport options from './options'\n\n/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */\nconst onCSSDeclaration = (decl, { result }) => {\n\tconst { value: originalValue } = decl\n\n\tif (hasAnyColorFunction(originalValue)) {\n\t\tlet valueAST\n\n\t\ttry {\n\t\t\tvalueAST = parse(originalValue, { ignoreUnknownWords: true })\n\t\t} catch (error) {\n\t\t\tdecl.warn(\n\t\t\t\tresult,\n\t\t\t\t`Failed to parse value '${originalValue}' as a lab or hcl function. Leaving the original value intact.`\n\t\t\t)\n\t\t}\n\n\t\tif (typeof valueAST === 'undefined') {\n\t\t\treturn\n\t\t}\n\n\t\tvalueAST.walkType('func', onCSSFunction)\n\n\t\tconst modifiedValue = String(valueAST)\n\n\t\tif (modifiedValue !== originalValue) {\n\t\t\tif (options.preserve) decl.cloneBefore({ value: modifiedValue })\n\t\t\telse decl.value = modifiedValue\n\t\t}\n\t}\n}\n\nexport default onCSSDeclaration\n\n/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */\nconst createRegExpTest = Function.bind.bind(RegExp.prototype.test)\n\n/** Return whether the value has a lab() or lch() function. */\nconst hasAnyColorFunction = createRegExpTest(/(^|[^\\w-])(lab|lch)\\(/i)\n\n/** @typedef {import('postcss').Declaration} CSSDeclaration */\n","import onCSSDeclaration from './onCSSDeclaration'\nimport options from './options'\n\n/** Transform lab() and lch() functions in CSS. */\nconst postcssPlugin = /** @type {PostCSSPluginInitializer} */ opts => {\n\toptions.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false\n\n\treturn {\n\t\tpostcssPlugin: 'postcss-lab-function',\n\t\tDeclaration: onCSSDeclaration,\n\t}\n}\n\npostcssPlugin.postcss = true\n\nexport default postcssPlugin\n\n/** @typedef {import('postcss').Plugin} PostCSSPlugin */\n/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */\n"],"names":["onCSSFunction","node","name","nodes","isColorFunctionName","isLabFunctionContents","isLchFunctionContents","Object","assign","slashNode","alphaNode","isPercentage","isCalc","value","String","unit","remove","isSlash","replaceWith","commaNode","clone","channelNode1","channelNode2","channelNode3","toRGB","isLabColorFunctionName","lab2rgb","lch2rgb","rgbValues","map","channelNumber","parseFloat","channelValue","Math","max","min","parseInt","parse","first","createRegExpTest","Function","bind","RegExp","prototype","test","isCalcFunctionName","isAlphaLikeUnit","isHueLikeUnit","isAlphaValue","type","isHue","isNumber","every","index","labFunctionContents","lchFunctionContents","preserve","onCSSDeclaration","decl","result","originalValue","hasAnyColorFunction","valueAST","ignoreUnknownWords","error","warn","walkType","modifiedValue","options","cloneBefore","postcssPlugin","opts","Boolean","Declaration","postcss"],"mappings":";;;AAGA;;AACA,MAAMA,aAAa,GAAGC,IAAI,IAAI;AAC7B;AACA,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBF,IAAxB;;AAEA,MAAIG,mBAAmB,CAACF,IAAD,CAAvB,EAA+B;AAC9B,QAAIG,qBAAqB,CAACF,KAAD,CAArB,IAAgCG,qBAAqB,CAACH,KAAD,CAAzD,EAAkE;AACjE;AACAI,MAAAA,MAAM,CAACC,MAAP,CAAcP,IAAd,EAAoB;AAAEC,QAAAA,IAAI,EAAE;AAAR,OAApB;AAEA;;AACA,YAAMO,SAAS,GAAGN,KAAK,CAAC,CAAD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d,CAAmBC,MAAM,CAACC,SAAP,CAAiBC,IAApC,CAAzB;AAEA;;AACA,MAAMiB,mBAAmB,GAAGtB,gBAAgB,CAAC,wBAAD,CAA5C;AAEA;;ACxCA;;MACM+B,aAAa;AAAG;AAAwCC,IAAI,IAAI;AACrEH,EAAAA,OAAO,CAACZ,QAAR,GAAmB,cAAcjD,MAAM,CAACgE,IAAD,CAApB,GAA6BC,OAAO,CAACD,IAAI,CAACf,QAAN,CAApC,GAAsD,KAAzE;AAEA,SAAO;AACNc,IAAAA,aAAa,EAAE,sBADT;AAENG,IAAAA,WAAW,EAAEhB;AAFP,GAAP;AAIA;;AAEDa,aAAa,CAACI,OAAd,GAAwB,IAAxB;AAIA;;AACA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-lab-function",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Use lab() and lch() color functions in CSS",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -19,24 +19,27 @@
|
|
|
19
19
|
"lint:fix": "npx eslint --cache --fix",
|
|
20
20
|
"pretest": "npm install && npm run build",
|
|
21
21
|
"test": "npm run lint && npm run tape",
|
|
22
|
-
"tape": "npx postcss-tape"
|
|
22
|
+
"tape": "npx postcss-tape",
|
|
23
|
+
"prepublishOnly": "npm test"
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
26
|
+
"node": ">=12"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@csstools/convert-colors": "
|
|
29
|
-
"postcss": "
|
|
30
|
-
|
|
29
|
+
"@csstools/convert-colors": "2.0.0",
|
|
30
|
+
"postcss-values-parser": "6.0.1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"postcss": "^8.3"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "^7.
|
|
34
|
-
"@babel/preset-env": "^7.
|
|
35
|
-
"babel
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"postcss
|
|
38
|
-
"
|
|
39
|
-
"rollup
|
|
36
|
+
"@babel/core": "^7.16.0",
|
|
37
|
+
"@babel/preset-env": "^7.16.4",
|
|
38
|
+
"@rollup/plugin-babel": "^5.3.0",
|
|
39
|
+
"eslint": "^8.2.0",
|
|
40
|
+
"postcss": "^8.3.11",
|
|
41
|
+
"postcss-tape": "^6.0.1",
|
|
42
|
+
"rollup": "^2.60.0"
|
|
40
43
|
},
|
|
41
44
|
"babel": {
|
|
42
45
|
"presets": [
|
|
@@ -54,23 +57,9 @@
|
|
|
54
57
|
"node": true
|
|
55
58
|
},
|
|
56
59
|
"extends": "eslint:recommended",
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"input": "src/index.js",
|
|
61
|
-
"plugins": [
|
|
62
|
-
"rollup-plugin-babel"
|
|
63
|
-
],
|
|
64
|
-
"output": [
|
|
65
|
-
{
|
|
66
|
-
"file": "dist/index.cjs.js",
|
|
67
|
-
"format": "cjs"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"file": "dist/index.esm.js",
|
|
71
|
-
"format": "esm"
|
|
72
|
-
}
|
|
73
|
-
]
|
|
60
|
+
"parserOptions": {
|
|
61
|
+
"sourceType": "module"
|
|
62
|
+
}
|
|
74
63
|
},
|
|
75
64
|
"keywords": [
|
|
76
65
|
"postcss",
|
package/CHANGELOG.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Changes to PostCSS Lab Function
|
|
2
|
-
|
|
3
|
-
### 3.1.0 (April 25, 2020)
|
|
4
|
-
|
|
5
|
-
- Updated: `postcss-values-parser` to 3.2.0 (minor).
|
|
6
|
-
|
|
7
|
-
### 3.0.1 (April 12, 2020)
|
|
8
|
-
|
|
9
|
-
- Updated: Ownership moved to CSSTools.
|
|
10
|
-
|
|
11
|
-
### 3.0.0 (April 12, 2020)
|
|
12
|
-
|
|
13
|
-
- Updated: `postcss-values-parser` to 3.1.1 (major).
|
|
14
|
-
- Updated: Node support to 10.0.0 (major).
|
|
15
|
-
- Updated: Feature to use new percentage syntax.
|
|
16
|
-
- Removed: Support for the removed `gray()` function.
|
|
17
|
-
|
|
18
|
-
### 2.0.1 (September 18, 2018)
|
|
19
|
-
|
|
20
|
-
- Updated: PostCSS Values Parser 2.0.0
|
|
21
|
-
|
|
22
|
-
### 2.0.0 (September 17, 2018)
|
|
23
|
-
|
|
24
|
-
- Updated: Support for PostCSS 7+
|
|
25
|
-
- Updated: Support for Node 6+
|
|
26
|
-
|
|
27
|
-
### 1.1.0 (July 24, 2018)
|
|
28
|
-
|
|
29
|
-
- Added: Support for `gray(a / b)` as `lab(a 0 0 / b)`
|
|
30
|
-
|
|
31
|
-
### 1.0.1 (May 11, 2018)
|
|
32
|
-
|
|
33
|
-
- Fixed: Values beyond the acceptable 0-255 RGB range
|
|
34
|
-
|
|
35
|
-
### 1.0.0 (May 11, 2018)
|
|
36
|
-
|
|
37
|
-
- Initial version
|