Skip to content
This repository was archived by the owner on May 19, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .github/workflows/.after-public.go-build

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Setup Node.js environment
uses: actions/setup-node@v2.1.5
with:
node-version: '12'

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ./node_modules
key: ${{ runner.os }}-build-cache-node-modules-${{ hashFiles('**/package.json') }}
restore-keys: |
cache-node-modules-

- name: Run ci
run: |
npm install
npm run ci

- name: coverall
if: success()
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
A JavaScript library for color computation.
</div>

[![Build Status](https://github.com/antvis/smart-color/workflows/build/badge.svg?branch=master)](https://github.com/antvis/smart-color/actions)
[![Coverage Status](https://img.shields.io/coveralls/github/antvis/smart-color/master.svg)](https://coveralls.io/github/antvis/smart-color?branch=master)
[![npm Version](https://img.shields.io/npm/v/@antv/smart-color.svg)](https://www.npmjs.com/package/@antv/smart-color)
[![npm Download](https://img.shields.io/npm/dm/@antv/smart-color.svg)](https://www.npmjs.com/package/@antv/smart-color)
[![npm License](https://img.shields.io/npm/l/@antv/smart-color.svg)](https://www.npmjs.com/package/@antv/smart-color)

## ✨ Features

* **Palette Generation**: Generate categorical or discrete scale palette based on [color scheme](https://github.com/neoddish/color-palette-json-schema#colorschemetype).
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/evaluators/CIEDE2000.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from '@antv/color-schema';
import { colorDifference } from '@src/index';
import { colorDifference } from '../../../src/index';

describe('CIEDE2000', () => {
const color1: Color = {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/evaluators/contrastRatio.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from '@antv/color-schema';
import { colorDifference } from '@src/index';
import { colorDifference } from '../../../src/index';

describe('contrast ratio', () => {
const color1: Color = {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/extractors/getPaletteFromImage.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EventEmitter from 'wolfy87-eventemitter';
import { getPaletteFromImage } from '@src/index';
import { getPaletteFromImage } from '../../../src/index';

describe('import palette by image', () => {
beforeAll(() => {
Expand All @@ -21,7 +21,7 @@ describe('import palette by image', () => {
}
}

addEventListener(event, callback) {
addEventListener(event: string, callback: Function) {
this.ee.addListener(event, callback);
}

Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/extractors/getPaletteFromString.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPaletteFromString } from '@src/index';
import { getPaletteFromString } from '../../../src/index';

describe('import palette', () => {
test('import palette by string', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/generators/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from '@antv/color-schema';
import { paletteGeneration, colorToArray, colorToHex } from '@src/index';
import { paletteGeneration, colorToArray, colorToHex } from '../../../src/index';

describe('Palette Generator', () => {
const color: Color = { model: 'rgb', value: { r: 123, g: 123, b: 0 } };
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/generators/random.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RGBColor } from '@antv/color-schema';
import { randomColor } from '@src/generators/random';
import { randomColor } from '../../../src/generators/random';

describe('Random Generator', () => {
test('should generate random colors', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/optimizers/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CategoricalPalette } from '@antv/color-schema';
import { paletteOptimization, colorDifference, SimulationType, colorSimulation } from '@src/index';
import { paletteOptimization, colorDifference, SimulationType, colorSimulation } from '../../../src/index';

const getMinDifference = (palette: CategoricalPalette, simulationType: SimulationType = 'normal') => {
let minDifference = Infinity;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/simulators/grayScale.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color, RGBAColor } from '@antv/color-schema';
import { colorToGray, invertGrayscale, colorSimulation } from '@src/index';
import { colorToGray, invertGrayscale, colorSimulation } from '../../../src/index';

describe('grayscale', () => {
const rgb: Color = {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/utils/colorBlend.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Color } from '@antv/color-schema';
import { colorBlend, colorToHex, hexToColor } from '@src/index';
import { WHITE } from '@src/constant';
import { colorBlend, colorToHex, hexToColor } from '../../../src/index';
import { WHITE } from '../../../src/constant';

const colorTop: Color = { model: 'rgb', value: { r: 91, g: 143, b: 249 } };
const colorBottom: Color = { model: 'rgb', value: { r: 97, g: 221, b: 170 } };
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/utils/colorComputation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hueOffset } from '@src/utils/colorComputation';
import { hexToColor, colorToHex, colorDarken, colorBrighten } from '@src/index';
import { hueOffset } from '../../../src/utils/colorComputation';
import { hexToColor, colorToHex, colorDarken, colorBrighten } from '../../../src/index';

describe('Color computation', () => {
test('hue offset', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/utils/colorConversion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from '@antv/color-schema';
import { arrayToColor, colorToArray, colorToGray, hexToColor, colorToHex, nameToColor } from '@src/index';
import { arrayToColor, colorToArray, colorToGray, hexToColor, colorToHex, nameToColor } from '../../../src/index';

const black: Color = {
model: 'rgb',
Expand Down
42 changes: 22 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,12 @@
"ava",
"color"
],
"repository": {
"type": "git",
"url": "git+https://github.com/antvis/smart-color.git"
},
"author": {
"name": "AntV",
"url": "https://antv.vision/"
},
"license": "MIT",
"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/antvis/smart-color/issues"
"dependencies": {
"@antv/color-schema": "^0.2.2",
"chroma-js": "^2.1.2",
"color-blind": "^0.1.1",
"quantize": "^1.0.2"
},
"homepage": "https://antvis.github.io/smart-color",
"devDependencies": {
"@babel/runtime": "^7.14.6",
"@commitlint/cli": "^12.1.4",
Expand Down Expand Up @@ -100,9 +90,21 @@
"limit": "24 Kb"
}
],
"dependencies": {
"@antv/color-schema": "^0.2.2",
"chroma-js": "^2.1.2",
"color-blind": "^0.1.1"
}
"repository": {
"type": "git",
"url": "git+https://github.com/antvis/smart-color.git"
},
"author": {
"name": "AntV",
"url": "https://antv.vision/"
},

"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/antvis/smart-color/issues"
},
"homepage": "https://antvis.github.io/smart-color",
"license": "MIT"
}
3 changes: 2 additions & 1 deletion src/extractors/getPaletteFromImage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-ignore
import quantize from 'quantize';
import { Palette } from '@antv/color-schema';
// @ts-ignore
// package quantize has error, when color number >= 7, https://github.com/olivierlesnicki/quantize/issues/9
// However, the owner of the package did not merge the pr to fix the issue.
// TODO: modified median cut quantization ts version
import { loadImage, arrayToColor } from '../utils';
import quantize from './quantize';

// sample pixels in image
const imageToPixels = (image: HTMLImageElement, quality: number): [number, number, number][] => {
Expand Down
Loading