1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = isColorStop;
|
---|
7 |
|
---|
8 | var _postcssValueParser = require("postcss-value-parser");
|
---|
9 |
|
---|
10 | var _colord = require("colord");
|
---|
11 |
|
---|
12 | var _names = _interopRequireDefault(require("colord/plugins/names"));
|
---|
13 |
|
---|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
15 |
|
---|
16 | (0, _colord.extend)([_names.default]);
|
---|
17 | /* Code derived from https://github.com/pigcan/is-color-stop */
|
---|
18 |
|
---|
19 | const lengthArray = ['PX', 'IN', 'CM', 'MM', 'EM', 'REM', 'POINTS', 'PC', 'EX', 'CH', 'VW', 'VH', 'VMIN', 'VMAX', '%'];
|
---|
20 |
|
---|
21 | function isCSSLengthUnit(input) {
|
---|
22 | return lengthArray.includes(input.toUpperCase());
|
---|
23 | }
|
---|
24 |
|
---|
25 | function isStop(str) {
|
---|
26 | let stop = !str;
|
---|
27 |
|
---|
28 | if (!stop) {
|
---|
29 | const node = (0, _postcssValueParser.unit)(str);
|
---|
30 |
|
---|
31 | if (node) {
|
---|
32 | if (node.number === 0 || !isNaN(node.number) && isCSSLengthUnit(node.unit)) {
|
---|
33 | stop = true;
|
---|
34 | }
|
---|
35 | } else {
|
---|
36 | stop = /^calc\(\S+\)$/g.test(str);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | return stop;
|
---|
41 | }
|
---|
42 |
|
---|
43 | function isColorStop(color, stop) {
|
---|
44 | return (0, _colord.colord)(color).isValid() && isStop(stop);
|
---|
45 | }
|
---|
46 |
|
---|
47 | module.exports = exports.default; |
---|