--- install scripts ---
### prepublishOnly
npm-run-all --parallel test build
--- package/package.json (excerpt) ---
{
"name": "@antv/color-util",
"version": "2.0.6",
"description": "A common util collection for antv projects",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "esm/index.js",
"files": [
"src",
"package.json",
"esm",
"lib",
"README.md"
],
"scripts": {
"build": "npm run clean && run-p build:*",
"build:esm": "tsc -p tsconfig.json --target ES5 --module ESNext --outDir esm",
"build:cjs": "tsc -p tsconfig.json --target ES5 --module commonjs --outDir lib",
"clean": "rm -rf lib && rm -rf esm",
"coverage": "npm run coverage-generator && npm run coverage-viewer",
"coverage-generator": "torch --coverage --compile --source-pattern src/*.js,src/**/*.js --opts __tests__/mocha.opts",
"coverage-viewer": "torch-coverage",
"test": "torch --renderer --compile --opts __tests__/mocha.opts",
"test-live": "torch --compile --interactive --opts __tests__/mocha.opts",
"tsc": "tsc --noEmit",
"typecheck": "tsc --noEmit",
"prepublishOnly": "npm-run-all --parallel test build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/antvis/util.git"
},
"keywords": [
"util",
"antv",
"g"
],
"author": "https://github.com/orgs/antvis/people",
"license": "ISC",
"bugs": {
"url": "https://github.com/antvis/util/issues"
},
"devDependencies": {
"@antv/torch": "^1.0.0",
"less": "^3.9.0",
"npm-run-all": "^4.1.5"
},
"homepage": "https://github.com/antvis
--- package/src/index.ts (excerpt) ---
import { map, memoize, isString, each } from '@antv/util';
const RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
const regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
const regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
const regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
const isGradientColor = (val) => /^[r,R,L,l]{1}[\s]*\(/.test(val);
// 创建辅助 tag 取颜色
const createTmp = (): HTMLElement => {
const i = document.createElement('i');
i.title = 'Web Colour Picker';
i.style.display = 'none';
document.body.appendChild(i);
return i;
};
// 获取颜色之间的插值
const getValue = (start: number[], end: number[], percent: number, index: number): number => {
return start[index] + (end[index] - start[index]) * percent;
};
// 数组转换成颜色
function arr2rgb(arr: number[]): string {
return `#${toHex(arr[0])}${toHex(arr[1])}${toHex(arr[2])}`;
}
// rgb 颜色转换成数组
const rgb2arr = (str: string): number[] => {
return [
parseInt(str.substr(1, 2), 16),
parseInt(str.substr(3, 2), 16),
parseInt(str.substr(5, 2), 16),
];
};
// 将数值从 0-255 转换成16进制字符串
const toHex = (value: number): string => {
const x16Value = Math.round(value).toString(16);
return x16Value.length === 1 ? `0${x16Value}` : x16Value;
};
// 计算颜色
const calColor = (points: number[][], percent: number) => {
const fixedPercent = isNaN(Number(percent)) || percent < 0 ? 0 :
percent > 1 ? 1 :
Number(percent);
const steps = points.length - 1;
const step = Math.floor(steps * fixedPercent);
const
--- package/lib/index.js (excerpt) ---
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("@antv/util");
var RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
var isGradientColor = function (val) { return /^[r,R,L,l]{1}[\s]*\(/.test(val); };
// 创建辅助 tag 取颜色
var createTmp = function () {
var i = document.createElement('i');
i.title = 'Web Colour Picker';
i.style.display = 'none';
document.body.appendChild(i);
return i;
};
// 获取颜色之间的插值
var getValue = function (start, end, percent, index) {
return start[index] + (end[index] - start[index]) * percent;
};
// 数组转换成颜色
function arr2rgb(arr) {
return "#" + toHex(arr[0]) + toHex(arr[1]) + toHex(arr[2]);
}
// rgb 颜色转换成数组
var rgb2arr = function (str) {
return [
parseInt(str.substr(1, 2), 16),
parseInt(str.substr(3, 2), 16),
parseInt(str.substr(5, 2), 16),
];
};
// 将数值从 0-255 转换成16进制字符串
var toHex = function (value) {
var x16Value = Math.round(value).toString(16);
return x16Value.length === 1 ? "0" + x16Value : x16Value;
};
// 计算颜色
var calColor = function (points, percent) {
var fixedPercent = isNaN(Number(percent)) || percent < 0 ? 0 :
percent > 1 ? 1 :
Number(percent);
var steps = points.length - 1;
var step = Math.floor(steps * fixedPercent);
var left = steps * fix{
"name": "@antv/color-util",
"version": "2.0.6",
"description": "A common util collection for antv projects",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"module": "esm/index.js",
"files": [
"src",
"package.json",
"esm",
"lib",
"README.md"
],
"scripts": {
"build": "npm run clean && run-p build:*",
"build:esm": "tsc -p tsconfig.json --target ES5 --module ESNext --outDir esm",
"build:cjs": "tsc -p tsconfig.json --target ES5 --module commonjs --outDir lib",
"clean": "rm -rf lib && rm -rf esm",
"coverage": "npm run coverage-generator && npm run coverage-viewer",
"coverage-generator": "torch --coverage --compile --source-pattern src/*.js,src/**/*.js --opts __tests__/mocha.opts",
"coverage-viewer": "torch-coverage",
"test": "torch --renderer --compile --opts __tests__/mocha.opts",
"test-live": "torch --compile --interactive --opts __tests__/mocha.opts",
"tsc": "tsc --noEmit",
"typecheck": "tsc --noEmit",
"prepublishOnly": "npm-run-all --parallel test build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/antvis/util.git"
},
"keywords": [
"util",
"antv",
"g"
],
"author": "https://github.com/orgs/antvis/people",
"license": "ISC",
"bugs": {
"url": "https://github.com/antvis/util/issues"
},
"devDependencies": {
"@antv/torch": "^1.0.0",
"less": "^3.9.0",
"npm-run-all": "^4.1.5"
},
"homepage": "https://github.com/antvis
import { map, memoize, isString, each } from '@antv/util';
const RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
const regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
const regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
const regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
const isGradientColor = (val) => /^[r,R,L,l]{1}[\s]*\(/.test(val);
// 创建辅助 tag 取颜色
const createTmp = (): HTMLElement => {
const i = document.createElement('i');
i.title = 'Web Colour Picker';
i.style.display = 'none';
document.body.appendChild(i);
return i;
};
// 获取颜色之间的插值
const getValue = (start: number[], end: number[], percent: number, index: number): number => {
return start[index] + (end[index] - start[index]) * percent;
};
// 数组转换成颜色
function arr2rgb(arr: number[]): string {
return `#${toHex(arr[0])}${toHex(arr[1])}${toHex(arr[2])}`;
}
// rgb 颜色转换成数组
const rgb2arr = (str: string): number[] => {
return [
parseInt(str.substr(1, 2), 16),
parseInt(str.substr(3, 2), 16),
parseInt(str.substr(5, 2), 16),
];
};
// 将数值从 0-255 转换成16进制字符串
const toHex = (value: number): string => {
const x16Value = Math.round(value).toString(16);
return x16Value.length === 1 ? `0${x16Value}` : x16Value;
};
// 计算颜色
const calColor = (points: number[][], percent: number) => {
const fixedPercent = isNaN(Number(percent)) || percent < 0 ? 0 :
percent > 1 ? 1 :
Number(percent);
const steps = points.length - 1;
const step = Math.floor(steps * fixedPercent);
const
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("@antv/util");
var RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
var isGradientColor = function (val) { return /^[r,R,L,l]{1}[\s]*\(/.test(val); };
// 创建辅助 tag 取颜色
var createTmp = function () {
var i = document.createElement('i');
i.title = 'Web Colour Picker';
i.style.display = 'none';
document.body.appendChild(i);
return i;
};
// 获取颜色之间的插值
var getValue = function (start, end, percent, index) {
return start[index] + (end[index] - start[index]) * percent;
};
// 数组转换成颜色
function arr2rgb(arr) {
return "#" + toHex(arr[0]) + toHex(arr[1]) + toHex(arr[2]);
}
// rgb 颜色转换成数组
var rgb2arr = function (str) {
return [
parseInt(str.substr(1, 2), 16),
parseInt(str.substr(3, 2), 16),
parseInt(str.substr(5, 2), 16),
];
};
// 将数值从 0-255 转换成16进制字符串
var toHex = function (value) {
var x16Value = Math.round(value).toString(16);
return x16Value.length === 1 ? "0" + x16Value : x16Value;
};
// 计算颜色
var calColor = function (points, percent) {
var fixedPercent = isNaN(Number(percent)) || percent < 0 ? 0 :
percent > 1 ? 1 :
Number(percent);
var steps = points.length - 1;
var step = Math.floor(steps * fixedPercent);
var left = steps * fix