-
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.
- Loading branch information
Showing
10 changed files
with
657 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { type Color, Palette, type PaletteName } from "viridis"; | ||
|
||
const outputCssFile = path.join(__dirname, "ui", "theme", "chartThemes.css"); | ||
const outputTsFile = path.join(__dirname, "ui", "theme", "chartThemes.ts"); | ||
|
||
const scale = 9; | ||
const totalScale = 12; | ||
|
||
let outputCss = ""; | ||
|
||
for (const paletteName of Object.keys(Palette) as PaletteName[]) { | ||
let light = ""; | ||
let dark = ""; | ||
|
||
light += `.chart-${paletteName.toLowerCase()} {\n`; | ||
dark += `.dark.chart-${paletteName.toLowerCase()} {\n`; | ||
|
||
for (let darkIndex = 0; darkIndex < totalScale; darkIndex++) { | ||
const lightIndex = darkIndex - (totalScale - scale); | ||
const color = Palette[paletteName].getColor(darkIndex + 1, 1, totalScale); | ||
if (darkIndex > 0 && darkIndex < scale) { | ||
dark += ` --chart-${darkIndex + 1}: ${color.toString()}; /* ${isLight(color.getContrastingColor()) ? "light" : "dark"} */\n`; | ||
} | ||
if (lightIndex >= 0 && lightIndex < scale) { | ||
light += ` --chart-${lightIndex + 1}: ${color.toString()}; /* ${isLight(color.getContrastingColor()) ? "light" : "dark"} */\n`; | ||
} | ||
} | ||
light += "}\n\n"; | ||
dark += "}\n\n"; | ||
|
||
outputCss += light; | ||
outputCss += dark; | ||
} | ||
|
||
const outputTs = `import "./chartThemes.css"; | ||
export type ChartTheme = | ||
${Object.keys(Palette) | ||
.map((paletteName) => ` | "chart-${paletteName.toLowerCase()}"`) | ||
.join("\n")}; | ||
export const chartThemes: ChartTheme[] = [ | ||
${Object.keys(Palette) | ||
.map((paletteName) => ` "chart-${paletteName.toLowerCase()}"`) | ||
.join(",\n")} | ||
]; | ||
`; | ||
|
||
fs.writeFileSync(outputCssFile, outputCss, "utf-8"); | ||
fs.writeFileSync(outputTsFile, outputTs, "utf-8"); | ||
|
||
function isLight(color: Color) { | ||
return color.red + color.green + color.blue > 382; | ||
} |
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import "../ui/theme/themes.css"; | ||
@import "../ui/theme/chartThemes.css"; | ||
@import "./rspress.css"; |
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
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
Oops, something went wrong.