Skip to content

Commit 1d34ef8

Browse files
committed
ensure minimum colour contrast for datapack descriptions
1 parent 76a5f21 commit 1d34ef8

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

bun.lock

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"typescript": "~5.8.3"
1111
},
1212
"dependencies": {
13+
"accessible-colors": "^1.0.8",
1314
"dompurify": "^3.2.6",
1415
"jszip": "^3.10.1",
1516
"typescript-event-target": "^1.1.1",

src/main.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type DatapackStoreEvents, datapackStore } from "./datapackStore";
44
import { getExportSettings } from "./page_interactions/settings";
55
import { getStructureSets } from "./structureSet";
66
import { showIntroIfNotShown } from "./page_interactions/introDialog";
7+
import { suggestAAAColorVariant } from "accessible-colors";
78

89
const fileUploadElement = document.getElementById("input")!;
910
fileUploadElement.addEventListener("change", onFileUploaded, { passive: true });
@@ -80,12 +81,16 @@ function getNameAndDescription(mcmeta: any): { name: string; description: string
8081
}
8182

8283
function descriptionToDisplayable(description: Datapack["description"]): string {
83-
if (Array.isArray(description))
84+
if (Array.isArray(description)) {
85+
const backgroundColor = document.getElementById("datapack-display")!.style.backgroundColor;
8486
return description
85-
.map((desc) => ({ text: sanitizeHtml(desc.text), color: desc.color }))
87+
.map((desc) => ({
88+
text: sanitizeHtml(desc.text),
89+
color: suggestAAAColorVariant(desc.color, backgroundColor),
90+
}))
8691
.map((desc) => `<span style="color: ${desc.color}">${desc.text}</span>`)
8792
.join("");
88-
else return description;
93+
} else return description;
8994
}
9095

9196
function sanitizeHtml(unsafe: string): string {

0 commit comments

Comments
 (0)