-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implementation is not complete and code is *probably* bad. Will improve and fix remaining issues later.
- Loading branch information
Showing
8 changed files
with
144 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,9 +37,11 @@ | |
"prepack": "pnpm build" | ||
}, | ||
"dependencies": { | ||
"@catppuccin/palette": "^1.0.1" | ||
"@catppuccin/palette": "^1.0.1", | ||
"culori": "^3.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/culori": "^2.0.4", | ||
"@unocss/core": "^0.58.2", | ||
"prettier": "^3.1.1", | ||
"typescript": "^5.3.3", | ||
|
@@ -48,5 +50,10 @@ | |
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/package.json b/package.json | ||
index a03ee24a4907bb93a9e4912ba5ce1046589b8408..fa80924eb29ff92881c58cf0e474bea6b67374ba 100644 | ||
--- a/package.json | ||
+++ b/package.json | ||
@@ -8,6 +8,7 @@ | ||
"jsdelivr": "./bundled/culori.umd.js", | ||
"exports": { | ||
"./require": "./bundled/culori.cjs", | ||
+ "./export": "./bundled/culori.mjs", | ||
".": "./src/index.js", | ||
"./css": "./src/bootstrap/css.js", | ||
"./all": "./src/bootstrap/all.js", |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const SHADE_RANGE = [ | ||
50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950, | ||
] as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { formatHex, interpolate } from 'culori/export'; | ||
|
||
import { SHADE_RANGE } from './constants.ts'; | ||
|
||
import type { ColorFormat } from '@catppuccin/palette'; | ||
|
||
export const generateShadePalette = (colour: ColorFormat) => { | ||
let resultObject = {} as Record<keyof typeof SHADE_RANGE | 'DEFAULT', string>; | ||
|
||
const colourShade = mapLightnessToShadeRange(colour.hsl.l * 100); | ||
|
||
const [lighten, darken] = SHADE_RANGE.reduce( | ||
([lighten, darken], shade) => { | ||
if (shade < colourShade) { | ||
return [[...lighten, shade], darken]; | ||
} else if (shade > colourShade) { | ||
return [lighten, [...darken, shade]]; | ||
} | ||
return [lighten, darken]; | ||
}, | ||
[[], []] as number[][] | ||
); | ||
|
||
lighten.reverse().map((shade, i) => { | ||
resultObject[shade] ??= formatHex( | ||
interpolate( | ||
[colour.hex, 'white'], | ||
'hsl' | ||
)((i + 1) / (SHADE_RANGE.length - 1)) | ||
); | ||
}); | ||
darken.map((shade, i) => { | ||
resultObject[shade] ??= formatHex( | ||
interpolate( | ||
[colour.hex, 'black'], | ||
'hsl' | ||
)((i + 1) / (SHADE_RANGE.length - 1)) | ||
); | ||
}); | ||
|
||
resultObject['DEFAULT'] = resultObject[colourShade] = colour.hex; | ||
|
||
return resultObject; | ||
}; | ||
|
||
function mapLightnessToShadeRange(lightness: number) { | ||
return SHADE_RANGE[ | ||
Math.floor((100 - lightness) / (100 / SHADE_RANGE.length)) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters