Skip to content

Commit 4a71f6f

Browse files
committed
🎉 Zero Dependency!
1 parent 9fa9a32 commit 4a71f6f

File tree

15 files changed

+1122
-2229
lines changed

15 files changed

+1122
-2229
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.3.5/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.3.7/schema.json",
33
"files": {
44
"includes": ["**", "!**/node_modules", "!**/dist", "!**/package-lock.json", "!**/package.json"]
55
},

package-lock.json

Lines changed: 733 additions & 2138 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"scripts": {
4141
"build": "npm run clean && rslib build",
4242
"build:watch": "rslib build --watch",
43-
"test": "vitest",
43+
"test": "rstest",
4444
"prepublish": "npm run build && npm run test",
4545
"postversion": "npm publish --access public",
4646
"clean": "rimraf dist/",
@@ -68,24 +68,21 @@
6868
],
6969
"author": "@ibodev1 <github.com/ibodev1>",
7070
"description": "Color palette generation library for TailwindCSS.",
71-
"dependencies": {
72-
"chroma-js": "^3.1.2"
73-
},
7471
"peerDependencies": {
7572
"tailwindcss": ">=3.4.0 || >=4.0.0 || insiders"
7673
},
7774
"devDependencies": {
78-
"@biomejs/biome": "^2.3.5",
79-
"@rslib/core": "^0.17.2",
80-
"@swc/core": "^1.15.2",
75+
"@biomejs/biome": "^2.3.7",
76+
"@rslib/core": "^0.18.2",
77+
"@rstest/core": "^0.6.6",
78+
"@swc/core": "^1.15.3",
8179
"@tailwindcss/postcss": "^4.1.17",
8280
"@types/chroma-js": "^3.1.2",
8381
"@types/node": "^24.10.1",
8482
"postcss": "^8.5.6",
85-
"rimraf": "^6.1.0",
83+
"rimraf": "^6.1.2",
8684
"tailwindcss": "^4.1.17",
87-
"typescript": "^5.9.3",
88-
"vitest": "^4.0.9"
85+
"typescript": "^5.9.3"
8986
},
90-
"packageManager": "[email protected].2"
87+
"packageManager": "[email protected].4"
9188
}

rslib.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { defineConfig } from '@rslib/core';
33
export default defineConfig({
44
source: {
55
entry: {
6-
index: 'src/**/*.ts',
6+
index: 'src/index.ts',
7+
getPalette: 'src/getPalette.ts',
78
},
89
tsconfigPath: './tsconfig.json',
910
},
1011
lib: [
1112
{
1213
format: 'esm',
1314
dts: true,
14-
bundle: false,
15+
bundle: true,
1516
output: {
1617
minify: false,
1718
sourceMap: true,

src/consts.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/generateColorPalette.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/getPalette.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
1-
import { initialOptions } from './consts.js';
2-
import generateColorPalette from './generateColorPalette.js';
3-
import PaletteError from './palette-error.js';
4-
import type { ColorResultOptions, Palette, PaletteResult } from './types.js';
5-
import { checkParam, getHexColor, isValidColor } from './utils.js';
1+
import type { ColorResultOptions, Palette, PaletteProp, PaletteResult } from './types/index.ts';
2+
import { darkenColor, getHexColor, isValidColor } from './utils/color.ts';
3+
import PaletteError from './utils/error.ts';
4+
import { checkParam, initialOptions } from './utils/index.ts';
5+
6+
const calculateDarkenValue = (shade: number, mainShade: number): number => {
7+
return (shade - mainShade) / 100 / 2;
8+
};
9+
10+
const shadeColor = (primaryColor: string, mainShade: number, shade: number): string => {
11+
return darkenColor(primaryColor, calculateDarkenValue(shade, mainShade));
12+
};
13+
14+
const colorResult = (
15+
fn: (primaryColor: string, mainShade: number, shade: number) => string,
16+
options: ColorResultOptions,
17+
): Record<PaletteProp, string> => {
18+
return options.shades.reduce((acc: Record<string, string>, shade: number) => {
19+
acc[String(shade)] = fn(options.primaryColor, options.mainShade, shade);
20+
return acc;
21+
}, {});
22+
};
23+
24+
const generateColorPalette = (options: ColorResultOptions): Record<PaletteProp, string> => {
25+
try {
26+
const palette = colorResult(shadeColor, options);
27+
palette.DEFAULT = getHexColor(options.primaryColor);
28+
return Object.freeze(palette);
29+
} catch (error) {
30+
console.error('Error generating color palette:', error);
31+
return Object.create(null);
32+
}
33+
};
634

735
export const getPalette = (params: Palette[] | Palette | string): PaletteResult => {
836
const palette: PaletteResult = {};

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createPlugin from 'tailwindcss/plugin';
2-
import { getPalette } from './getPalette.js';
3-
import PaletteError from './palette-error.js';
4-
import { convertResultToCSS, getPalettesFromOptions } from './utils.js';
2+
import { getPalette } from './getPalette.ts';
3+
import PaletteError from './utils/error.ts';
4+
import { convertResultToCSS, getPalettesFromOptions } from './utils/index.ts';
55

66
type PluginWithOptions = ReturnType<typeof createPlugin.withOptions<Record<string, string>>>;
77

File renamed without changes.

0 commit comments

Comments
 (0)