Skip to content

Commit ee1de3a

Browse files
added thememaker / chart themes
1 parent d6e0a10 commit ee1de3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+18039
-0
lines changed

pnpm-lock.yaml

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

tools/theme-maker/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

tools/theme-maker/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# theme-maker
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.3.5. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

tools/theme-maker/bun.lock

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

tools/theme-maker/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello via Bun!");

tools/theme-maker/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "theme-maker",
3+
"module": "index.ts",
4+
"type": "module",
5+
"private": true,
6+
"devDependencies": {
7+
"@types/bun": "latest"
8+
},
9+
"peerDependencies": {
10+
"typescript": "^5"
11+
},
12+
"dependencies": {
13+
"@cantoo/color-blindness": "^1.0.5",
14+
"@types/chroma-js": "^3.1.2",
15+
"chroma-js": "^3.2.0"
16+
}
17+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import chroma, { type Color } from "chroma-js";
2+
import { createPalettes } from "../lib/testing";
3+
4+
const paletteAudit = (colors: string[]) => {
5+
const conflicts = [];
6+
const THRESHOLD = 6;
7+
const thirdOfList = Math.floor(colors.length / 3);
8+
for (let i = 0; i < thirdOfList; i++) {
9+
for (let j = colors.length - 1; j >= colors.length - thirdOfList; j--) {
10+
const distance = chroma.deltaE(colors[i]!, colors[j]!);
11+
if (distance < THRESHOLD) {
12+
conflicts.push({
13+
pair: [colors[i], colors[j]],
14+
indices: [i, j],
15+
distance: distance,
16+
});
17+
continue;
18+
}
19+
}
20+
}
21+
return conflicts;
22+
};
23+
24+
export const divergingAudit = (palette: string[]) => {
25+
const simulatedPalettes = createPalettes(palette);
26+
27+
const results = Object.entries(simulatedPalettes).map(
28+
([type, simPalette]) => {
29+
return {
30+
visionType: type,
31+
conflicts: paletteAudit(simPalette),
32+
};
33+
},
34+
);
35+
results.push({
36+
visionType: "trichromacy",
37+
conflicts: paletteAudit(palette),
38+
});
39+
return results;
40+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function line(content: string, depth: number): string {
2+
return `\n${"\t".repeat(depth)}${content}`;
3+
}
4+
5+
export class FileBuilder {
6+
private lines: string[] = [];
7+
8+
addLine(content: string, depth: number = 0): void {
9+
this.lines.push(`${"\t".repeat(depth)}${content}`);
10+
}
11+
12+
addEmptyLine(): void {
13+
this.lines.push("");
14+
}
15+
16+
build(): string {
17+
return this.lines.join("\n");
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import chroma, { type Color } from "chroma-js";
2+
import {
3+
protanopia,
4+
protanomaly,
5+
deuteranopia,
6+
deuteranomaly,
7+
tritanopia,
8+
tritanomaly,
9+
} from "@cantoo/color-blindness";
10+
11+
export const createPalettes = (palette: string[]) => {
12+
const protanopiaPalette: string[] = [];
13+
const protanomalyPalette: string[] = [];
14+
const deuteranopiaPalette: string[] = [];
15+
const deuteranomalyPalette: string[] = [];
16+
const tritanopiaPalette: string[] = [];
17+
const tritanomalyPalette: string[] = [];
18+
palette.forEach((color) => {
19+
protanopiaPalette.push(protanopia(color));
20+
protanomalyPalette.push(protanomaly(color));
21+
deuteranopiaPalette.push(deuteranopia(color));
22+
deuteranomalyPalette.push(deuteranomaly(color));
23+
tritanopiaPalette.push(tritanopia(color));
24+
tritanomalyPalette.push(tritanomaly(color));
25+
});
26+
return {
27+
protanopia: protanopiaPalette,
28+
protanomaly: protanomalyPalette,
29+
deuteranopia: deuteranopiaPalette,
30+
deuteranomaly: deuteranomalyPalette,
31+
tritanopia: tritanopiaPalette,
32+
tritanomaly: tritanomalyPalette,
33+
};
34+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import chroma from "chroma-js";
2+
import { createPalettes } from "../lib/testing";
3+
4+
const paletteAudit = (colors: string[]) => {
5+
const conflicts = [];
6+
const THRESHOLD = 10; // Standard JND (Just Noticeable Difference) for accessibility is ~15-20
7+
for (let i = 0; i < colors.length; i++) {
8+
for (let j = i + 1; j < colors.length; j++) {
9+
const distance = chroma.deltaE(colors[i]!, colors[j]!);
10+
if (distance < THRESHOLD) {
11+
conflicts.push({
12+
pair: [colors[i], colors[j]],
13+
indices: [i, j],
14+
distance: distance,
15+
});
16+
continue;
17+
}
18+
}
19+
}
20+
return conflicts;
21+
};
22+
23+
export const qualitativeAudit = (palette: string[]) => {
24+
const simulatedPalettes = createPalettes(palette);
25+
26+
const results = Object.entries(simulatedPalettes).map(
27+
([type, simPalette]) => {
28+
return {
29+
visionType: type,
30+
conflicts: paletteAudit(simPalette),
31+
};
32+
},
33+
);
34+
results.push({
35+
visionType: "trichromacy",
36+
conflicts: paletteAudit(palette),
37+
});
38+
return results;
39+
};

0 commit comments

Comments
 (0)