Urara-Blog/node_modules/.pnpm-store/v3/files/53/4b83eb87d1353d8358db3baa6f93fdfad77f48504da313494c5ce653958a9c87395f63f3af87524c24b39c6830492bc8c3ce11ed5587d8202c09e84d123b5a
2022-08-14 01:14:53 +08:00

62 lines
1.1 KiB
Text

'use strict';
const { unit } = require('postcss-value-parser');
const { colord, extend } = require('colord');
const namesPlugin = require('colord/plugins/names');
extend([/** @type {any} */ (namesPlugin)]);
/* Code derived from https://github.com/pigcan/is-color-stop */
const lengthUnits = new Set([
'PX',
'IN',
'CM',
'MM',
'EM',
'REM',
'POINTS',
'PC',
'EX',
'CH',
'VW',
'VH',
'VMIN',
'VMAX',
'%',
]);
/**
* @param {string} input
* @return {boolean}
*/
function isCSSLengthUnit(input) {
return lengthUnits.has(input.toUpperCase());
}
/**
* @param {string|undefined} str
* @return {boolean}
*/
function isStop(str) {
if (str) {
let stop = false;
const node = unit(str);
if (node) {
const number = Number(node.number);
if (number === 0 || (!isNaN(number) && isCSSLengthUnit(node.unit))) {
stop = true;
}
} else {
stop = /^calc\(\S+\)$/g.test(str);
}
return stop;
}
return true;
}
/**
* @param {string} color
* @param {string} [stop]
* @return {boolean}
*/
module.exports = function isColorStop(color, stop) {
return colord(color).isValid() && isStop(stop);
};