Skip to content

Commit

Permalink
use tree-shakable ESM @ctrl/tinycolor to replace tinycolor2 (#69)
Browse files Browse the repository at this point in the history
* deps: use ESM @ctrl/tinycolor to replace tinycolor2

* fix: lint
  • Loading branch information
Wendell Hu authored Nov 12, 2020
1 parent bd17ccf commit 50616a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"author": "afc163 <afc163@gmail.com>",
"license": "MIT",
"dependencies": {
"tinycolor2": "^1.4.1"
"@ctrl/tinycolor": "^3.1.6"
},
"devDependencies": {
"@types/jest": "^26.0.0",
Expand Down
12 changes: 6 additions & 6 deletions src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tinycolor from 'tinycolor2';
import { TinyColor } from '@ctrl/tinycolor';

const hueStep = 2; // 色相阶梯
const saturationStep = 0.16; // 饱和度阶梯,浅色部分
Expand Down Expand Up @@ -90,10 +90,10 @@ interface Opts {

export default function generate(color: string, opts: Opts = {}): string[] {
const patterns: Array<string> = [];
const pColor = tinycolor(color);
const pColor = new TinyColor(color);
for (let i = lightColorCount; i > 0; i -= 1) {
const hsv = pColor.toHsv();
const colorString: string = tinycolor({
const colorString: string = new TinyColor({
h: getHue(hsv, i, true),
s: getSaturation(hsv, i, true),
v: getValue(hsv, i, true),
Expand All @@ -103,7 +103,7 @@ export default function generate(color: string, opts: Opts = {}): string[] {
patterns.push(pColor.toHexString());
for (let i = 1; i <= darkColorCount; i += 1) {
const hsv = pColor.toHsv();
const colorString: string = tinycolor({
const colorString: string = new TinyColor({
h: getHue(hsv, i),
s: getSaturation(hsv, i),
v: getValue(hsv, i),
Expand All @@ -114,8 +114,8 @@ export default function generate(color: string, opts: Opts = {}): string[] {
// dark theme patterns
if (opts.theme === 'dark') {
return darkColorMap.map(({ index, opacity }) => {
const darkColorString: string = tinycolor
.mix(opts.backgroundColor || '#141414', patterns[index], opacity * 100)
const darkColorString: string = new TinyColor(opts.backgroundColor || '#141414')
.mix(patterns[index], opacity * 100)
.toHexString();
return darkColorString;
});
Expand Down

0 comments on commit 50616a4

Please sign in to comment.