Skip to content

Commit 3395668

Browse files
authoredFeb 18, 2025··
Chore: Replace PNG indicators with generated SVGs (#508)
Deletes PNG indicators, and replaces them with a build plugin which will generate lightweight SVGs. These are about 1/8th the size
1 parent b673fca commit 3395668

File tree

1,285 files changed

+61
-1
lines changed

Some content is hidden

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

1,285 files changed

+61
-1
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
.vscode-test/
33
.vsix
44
dist
5-
out
5+
out
6+
src/img/indicators

‎_scripts/generate-indicators.mjs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
const generateDistinctColor = (index) => {
5+
const goldenRatio = 0.618033988749895;
6+
7+
const hue = (index * goldenRatio * 360) % 360;
8+
9+
const saturation = 85 + Math.random() * 15;
10+
const lightness = 45 + Math.random() * 20;
11+
12+
return `hsl(${Math.round(hue)}, ${Math.round(saturation)}%, ${Math.round(lightness)}%)`;
13+
};
14+
15+
const createSvgContent = (color) => {
16+
return `<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" fill="${color}" r="30"/></svg>`;
17+
};
18+
19+
export const generateIndicators = (count) => {
20+
const outputDir = path.join("src", "img", "indicators");
21+
22+
// Check if directory exists and has files
23+
if (fs.existsSync(outputDir)) {
24+
const existingFiles = fs.readdirSync(outputDir).filter((file) => file.endsWith(".svg"));
25+
if (existingFiles.length) {
26+
return;
27+
}
28+
}
29+
30+
fs.mkdirSync(outputDir, { recursive: true });
31+
32+
const colors = new Set();
33+
let index = 0;
34+
35+
while (colors.size < count) {
36+
colors.add(generateDistinctColor(index));
37+
index++;
38+
}
39+
40+
colors.forEach((color) => {
41+
const safeFileName = color
42+
.replace("hsl(", "")
43+
.replace(")", "")
44+
.replace(/, /g, "-")
45+
.replace(/%/g, "");
46+
const fileName = path.join(outputDir, `${safeFileName}.svg`);
47+
fs.writeFileSync(fileName, createSvgContent(color));
48+
});
49+
};

0 commit comments

Comments
 (0)
Please sign in to comment.