dracosh 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/locales/de.json +51 -13
- package/locales/en.json +51 -13
- package/locales/fr.json +52 -13
- package/locales/pl.json +53 -13
- package/locales/uk.json +53 -13
- package/package.json +2 -2
- package/src/alerts.js +47 -50
- package/src/background.js +63 -0
- package/src/bug.js +112 -0
- package/src/cli.js +24 -1
- package/src/doctor.js +123 -0
- package/src/notify.js +44 -0
- package/src/player.js +117 -0
- package/src/settings.js +4 -1
- package/src/speech.js +82 -0
- package/src/ui/App.js +9 -8
- package/src/ui/BadgeUnlock.js +4 -6
- package/src/ui/Badges.js +5 -7
- package/src/ui/Companion.js +2 -2
- package/src/ui/Confetti.js +2 -2
- package/src/ui/DieRoll.js +6 -6
- package/src/ui/Import.js +7 -7
- package/src/ui/Preview.js +9 -6
- package/src/ui/Settings.js +10 -7
- package/src/ui/Stats.js +11 -21
- package/src/ui/TheOne.js +2 -2
- package/src/ui/icons.js +2 -4
- package/src/ui/kit.js +88 -11
package/src/ui/Import.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { Box, useInput } from "ink";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { basename,
|
|
4
|
+
import { basename, posix, win32 } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { t } from "../i18n.js";
|
|
7
7
|
import { plainFront } from "../cardline.js";
|
|
@@ -16,20 +16,20 @@ const SHOWN = 3; // cards of each deck, changed cards and lines that can't be ad
|
|
|
16
16
|
const SETTLE_MS = 400; // a key right after a screen appears is the second half of the Enter before it
|
|
17
17
|
|
|
18
18
|
// A path as a terminal pastes a file dragged into it: in quotes, with its spaces escaped, or as a
|
|
19
|
-
// file:// address; "~" is your home folder
|
|
20
|
-
export function cleanPath(typed) {
|
|
19
|
+
// file:// address; "~" is your home folder. On Windows a backslash separates folders, never escapes.
|
|
20
|
+
export function cleanPath(typed, { windows = process.platform === "win32" } = {}) {
|
|
21
21
|
let path = typed.trim();
|
|
22
22
|
if (/^(['"]).*\1$/.test(path)) path = path.slice(1, -1);
|
|
23
|
-
else path = path.replace(/\\(.)/g, "$1");
|
|
23
|
+
else if (!windows) path = path.replace(/\\(.)/g, "$1");
|
|
24
24
|
if (path.startsWith("file://")) {
|
|
25
25
|
try {
|
|
26
|
-
path = fileURLToPath(path);
|
|
26
|
+
path = fileURLToPath(path, { windows });
|
|
27
27
|
} catch {
|
|
28
28
|
// not a file address after all: read as typed
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
if (path === "~" || path.startsWith("~/")) path = homedir() + path.slice(1);
|
|
32
|
-
return path && resolve(path);
|
|
31
|
+
if (path === "~" || path.startsWith("~/") || (windows && path.startsWith("~\\"))) path = homedir() + path.slice(1);
|
|
32
|
+
return path && (windows ? win32 : posix).resolve(path);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const answers = (back) => back.join("; ");
|
package/src/ui/Preview.js
CHANGED
|
@@ -18,7 +18,7 @@ import { Evolution } from "./Evolution.js";
|
|
|
18
18
|
import { Hatch } from "./Hatch.js";
|
|
19
19
|
import { Welcome } from "./Welcome.js";
|
|
20
20
|
import { Header, Snore, useBlink, useMove } from "./Header.js";
|
|
21
|
-
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
21
|
+
import { applyTheme, html, KeyHints, Text, theme, themeName, usePanelWidth } from "./kit.js";
|
|
22
22
|
import { Mascot } from "./Mascot.js";
|
|
23
23
|
import { Stats } from "./Stats.js";
|
|
24
24
|
import { Summary } from "./Summary.js";
|
|
@@ -210,13 +210,14 @@ const SCENES = [
|
|
|
210
210
|
...["mascot", "quiz", "add", "reveal", "cloze", "quiz-look", "unlock", "the-one", "die", "confetti", "stats", "badges", "summary"].map((id) => scene(id))
|
|
211
211
|
];
|
|
212
212
|
|
|
213
|
-
function Menu({ selected, onMove, onPick, onQuit }) {
|
|
213
|
+
function Menu({ selected, onMove, onPick, onTheme, onQuit }) {
|
|
214
214
|
const panel = usePanelWidth();
|
|
215
215
|
useInput((input, key) => {
|
|
216
216
|
if (key.escape || input === "q") return onQuit();
|
|
217
217
|
if (key.upArrow) return onMove(-1);
|
|
218
218
|
if (key.downArrow) return onMove(1);
|
|
219
219
|
if (key.return) onPick();
|
|
220
|
+
if (input === "t") onTheme();
|
|
220
221
|
});
|
|
221
222
|
return html`
|
|
222
223
|
<${Fragment}>
|
|
@@ -241,11 +242,13 @@ function Menu({ selected, onMove, onPick, onQuit }) {
|
|
|
241
242
|
}
|
|
242
243
|
|
|
243
244
|
// `dracosh --preview`: a gallery of every scene and animation, to look at without playing for weeks.
|
|
244
|
-
export function Preview({ alerts }) {
|
|
245
|
+
export function Preview({ alerts, theme: saved }) {
|
|
245
246
|
const { exit } = useApp();
|
|
246
247
|
const [selected, setSelected] = useState(0);
|
|
247
248
|
const [scene, setScene] = useState(null);
|
|
248
249
|
const [run, setRun] = useState(0); // a fresh key per play, so every scene starts from its first frame
|
|
250
|
+
const [look, setLook] = useState(() => themeName(saved)); // t flips between dark and light
|
|
251
|
+
applyTheme(look);
|
|
249
252
|
const back = () => setScene(null);
|
|
250
253
|
const history = useMemo(() => fakeSession({ progress: true }), []);
|
|
251
254
|
const quizSession = useMemo(() => fakeSession(), [run]); // every quiz run starts from zero
|
|
@@ -261,7 +264,7 @@ export function Preview({ alerts }) {
|
|
|
261
264
|
}
|
|
262
265
|
|
|
263
266
|
if (!scene) {
|
|
264
|
-
return wrap(html`<${Menu} selected=${selected} onMove=${(d) => setSelected((s) => (s + d + SCENES.length) % SCENES.length)} onPick=${pick} onQuit=${exit} />`);
|
|
267
|
+
return wrap(html`<${Menu} selected=${selected} onMove=${(d) => setSelected((s) => (s + d + SCENES.length) % SCENES.length)} onPick=${pick} onTheme=${() => setLook((name) => (name === "dark" ? "light" : "dark"))} onQuit=${exit} />`);
|
|
265
268
|
}
|
|
266
269
|
if (scene === "hatch") return wrap(html`<${Hatch} key=${run} play=${alerts.play} onDone=${back} />`);
|
|
267
270
|
if (scene.startsWith("evolve-")) {
|
|
@@ -287,10 +290,10 @@ export function Preview({ alerts }) {
|
|
|
287
290
|
if (scene === "reveal" || scene === "cloze") {
|
|
288
291
|
const words = scene === "reveal" ? DEMO_SENTENCES : DEMO_CLOZE;
|
|
289
292
|
const session = fakeSession({ words, deck: { name: "Demo", directions: "forward" } });
|
|
290
|
-
return html`<${App} key=${run} session=${session} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "off", rhythm: "session" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
|
|
293
|
+
return html`<${App} key=${run} session=${session} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "off", rhythm: "session", theme: look }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
|
|
291
294
|
}
|
|
292
295
|
if (scene === "quiz") {
|
|
293
|
-
return html`<${App} key=${run} session=${quizSession} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always" }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
|
|
296
|
+
return html`<${App} key=${run} session=${quizSession} deck="Demo" initialSettings=${{ ...DEFAULTS, dailyGoal: 5, everyMs: 6000, tips: "always", theme: look }} alerts=${alerts} persistSettings=${async () => {}} onExit=${back} />`;
|
|
294
297
|
}
|
|
295
298
|
return null;
|
|
296
299
|
}
|
package/src/ui/Settings.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Fragment, useState } from "react";
|
|
2
2
|
import { Box, useInput } from "ink";
|
|
3
3
|
import { language, LANGUAGES, t } from "../i18n.js";
|
|
4
|
-
import { GOALS, INTERVALS, QUIET_PRESETS, RHYTHMS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
|
|
4
|
+
import { GOALS, INTERVALS, QUIET_PRESETS, RHYTHMS, THEMES, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
|
|
5
5
|
import { formatQuiet } from "../quiet.js";
|
|
6
6
|
import { aiCostLabel } from "../ai.js";
|
|
7
|
+
import { PLAYS_SOUNDS } from "../player.js";
|
|
7
8
|
import { voiceLabel } from "../voice.js";
|
|
8
9
|
import { languageName } from "../language.js";
|
|
9
10
|
import { elementName } from "../progress.js";
|
|
@@ -16,14 +17,15 @@ function VolumeValue({ value }) {
|
|
|
16
17
|
// label and hint come from settings.rows.<key> in the locale
|
|
17
18
|
const ALL_ROWS = [
|
|
18
19
|
{ key: "language", options: Object.keys(LANGUAGES), format: (code) => LANGUAGES[code] },
|
|
20
|
+
{ key: "theme", options: THEMES, format: (v) => t(`settings.themes.${v}`) },
|
|
19
21
|
{ key: "homeLanguage", action: true, format: (code) => languageName(code) ?? t("settings.notSet") },
|
|
20
22
|
{ key: "ai", action: true, format: aiCostLabel },
|
|
21
23
|
{ key: "rhythm", options: RHYTHMS, format: (v) => t(`settings.rhythms.${v}`) },
|
|
22
24
|
{ key: "everyMs", options: INTERVALS, format: formatInterval },
|
|
23
|
-
{ key: "sound", options: [true, false], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
|
|
24
|
-
{ key: "speak", options: [false, true], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
|
|
25
|
-
{ key: "voice", action: true, format: voiceLabel },
|
|
26
|
-
{ key: "volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v}
|
|
25
|
+
{ key: "sound", options: [true, false], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true, onlyWith: "sounds" },
|
|
26
|
+
{ key: "speak", options: [false, true], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true, onlyWith: "sounds" },
|
|
27
|
+
{ key: "voice", action: true, format: voiceLabel, onlyWith: "sounds" },
|
|
28
|
+
{ key: "volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />`, onlyWith: "sounds" },
|
|
27
29
|
{ key: "dailyGoal", options: GOALS, format: (n) => t("settings.goal", { n }) },
|
|
28
30
|
{ key: "tips", options: TIP_MODES, format: (v) => t(`settings.tipModes.${v}`) },
|
|
29
31
|
{ key: "skipWeekends", options: [true, false], format: (v) => t(v ? "settings.weekendsRest" : "settings.weekendsCount"), toggle: true },
|
|
@@ -44,7 +46,8 @@ const nearestIndex = (options, value) => {
|
|
|
44
46
|
// `startRow` and `onRow`: the row to open on, and each row moved to, so a screen opened from a row
|
|
45
47
|
// comes back to it
|
|
46
48
|
// `element`: the dragon's element, if the die gave it one (the row to go back to the default look)
|
|
47
|
-
|
|
49
|
+
// `sounds`: whether this system plays sounds (Windows doesn't: no Sound, Read aloud, Voice or Volume rows)
|
|
50
|
+
export function Settings({ settings, element = null, sounds = PLAYS_SOUNDS, onChange, onClose, onAction, startRow = 0, onRow = () => {} }) {
|
|
48
51
|
const panel = usePanelWidth();
|
|
49
52
|
const [row, setRowState] = useState(startRow);
|
|
50
53
|
const setRow = (next) => setRowState((r) => {
|
|
@@ -52,7 +55,7 @@ export function Settings({ settings, element = null, onChange, onClose, onAction
|
|
|
52
55
|
onRow(value);
|
|
53
56
|
return value;
|
|
54
57
|
});
|
|
55
|
-
const ROWS = (onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action)).filter((item) => item.onlyWith
|
|
58
|
+
const ROWS = (onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action)).filter((item) => (item.onlyWith === "element" ? element : item.onlyWith === "sounds" ? sounds : true));
|
|
56
59
|
const values = { ...settings, language: settings.language ?? language(), dragonLook: element };
|
|
57
60
|
const labelWidth = Math.max(...ROWS.map((item) => label(item).length)) + 2;
|
|
58
61
|
|
package/src/ui/Stats.js
CHANGED
|
@@ -6,22 +6,12 @@ import { formatRange } from "../vacation.js";
|
|
|
6
6
|
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
7
7
|
|
|
8
8
|
// One shape for every day; only the color tells them apart, GitHub-contribution style.
|
|
9
|
-
const TILE = {
|
|
10
|
-
goal: theme.good,
|
|
11
|
-
halfway: "#3f9d5e",
|
|
12
|
-
some: "#2f6b45",
|
|
13
|
-
none: "#3a3f47",
|
|
14
|
-
rest: "#2a2e35",
|
|
15
|
-
future: "#1c1f25",
|
|
16
|
-
today: theme.accent // today with nothing done yet
|
|
17
|
-
};
|
|
18
|
-
|
|
19
9
|
function tileColor(cell, goal) {
|
|
20
|
-
if (cell.goalMet) return
|
|
21
|
-
if (cell.correct > 0) return cell.correct >= goal / 2 ?
|
|
22
|
-
if (cell.today) return
|
|
23
|
-
if (cell.future) return
|
|
24
|
-
return cell.rest ?
|
|
10
|
+
if (cell.goalMet) return theme.good;
|
|
11
|
+
if (cell.correct > 0) return cell.correct >= goal / 2 ? theme.dayHalfway : theme.daySome;
|
|
12
|
+
if (cell.today) return theme.accent; // today with nothing done yet
|
|
13
|
+
if (cell.future) return theme.dayFuture;
|
|
14
|
+
return cell.rest ? theme.dayRest : theme.dayNone;
|
|
25
15
|
}
|
|
26
16
|
|
|
27
17
|
// A plain full-month grid: weeks as rows under one-letter day headers.
|
|
@@ -48,12 +38,12 @@ function Calendar({ month, goal }) {
|
|
|
48
38
|
|
|
49
39
|
function Legend({ goal }) {
|
|
50
40
|
const items = [
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
41
|
+
[theme.good, t("stats.legend.goal", { goal })],
|
|
42
|
+
[theme.dayHalfway, t("stats.legend.halfway")],
|
|
43
|
+
[theme.daySome, t("stats.legend.some")],
|
|
44
|
+
[theme.dayNone, t("stats.legend.none")],
|
|
45
|
+
[theme.dayRest, t("stats.legend.rest")],
|
|
46
|
+
[theme.accent, t("stats.legend.today")]
|
|
57
47
|
];
|
|
58
48
|
// a box per item, so a longer language wraps whole items instead of splitting one
|
|
59
49
|
return html`
|
package/src/ui/TheOne.js
CHANGED
|
@@ -2,7 +2,7 @@ import { t } from "../i18n.js";
|
|
|
2
2
|
import React, { Fragment, useEffect, useState } from "react";
|
|
3
3
|
import { Box, useInput } from "ink";
|
|
4
4
|
import { RING } from "./icons.js";
|
|
5
|
-
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
5
|
+
import { html, KeyHints, readable, Text, theme, usePanelWidth } from "./kit.js";
|
|
6
6
|
|
|
7
7
|
const FRAME_MS = 110;
|
|
8
8
|
const WIDTH = 16; // pixels; each is drawn two characters wide
|
|
@@ -109,7 +109,7 @@ export function TheOne({ onClose, play = () => {} }) {
|
|
|
109
109
|
${revealed
|
|
110
110
|
? html`
|
|
111
111
|
<${Fragment}>
|
|
112
|
-
<${Text} bold color=${RING.palette.G}>${t("theOne.title")}<//>
|
|
112
|
+
<${Text} bold color=${readable(RING.palette.G)}>${t("theOne.title")}<//>
|
|
113
113
|
<${Text} dimColor>${t("theOne.line")}<//>
|
|
114
114
|
<//>
|
|
115
115
|
`
|
package/src/ui/icons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BADGES } from "../progress.js";
|
|
2
|
-
import { html, Text } from "./kit.js";
|
|
2
|
+
import { html, Text, theme } from "./kit.js";
|
|
3
3
|
import { PixelGrid } from "./Mascot.js";
|
|
4
4
|
|
|
5
5
|
// 8×8 pixel icons for the badge groups, drawn with the same half-block technique as the mascot.
|
|
@@ -237,8 +237,6 @@ const ICON_FOR = {
|
|
|
237
237
|
"dragons-die": "die"
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
-
const LOCKED_COLOR = "#4a5058";
|
|
241
|
-
|
|
242
240
|
// Rank colors for the badge groups that climb (more answers, longer streaks…): the higher, the rarer.
|
|
243
241
|
const TIERS = [
|
|
244
242
|
{ name: "bronze", main: "#d08a4e", shade: "#8a4f1c", light: "#f3c9a0" },
|
|
@@ -326,7 +324,7 @@ export function BadgeIcon({ id, locked = false, flash = false, secret = false })
|
|
|
326
324
|
if (secret) return html`<${PixelGrid} grid=${ICONS.secret.grid.map((row) => [...row])} palette=${ICONS.secret.palette} />`;
|
|
327
325
|
const icon = ICONS[ICON_FOR[id]] ?? ICONS.star;
|
|
328
326
|
const flat = (color) => Object.fromEntries(Object.keys(icon.palette).map((k) => [k, color]));
|
|
329
|
-
const palette = flash ? flat(
|
|
327
|
+
const palette = flash ? flat(theme.flash) : locked ? flat(theme.locked) : paletteFor(id, icon);
|
|
330
328
|
// a locked ring is drawn filled in, so its silhouette doesn't give away what it is
|
|
331
329
|
const own = OWN_GRIDS[id] ?? icon.grid;
|
|
332
330
|
const grid = locked && !flash && id === "one-ring" ? own.map(fillIn) : own;
|
package/src/ui/kit.js
CHANGED
|
@@ -28,17 +28,94 @@ export function Text(props) {
|
|
|
28
28
|
return React.createElement(InsideText.Provider, { value: true }, React.createElement(Transform, { transform: unspill }, text));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// Dracosh
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
// Dracosh palettes: soft violet accents and gold for fire and glory. Dark is the original look; light
|
|
32
|
+
// keeps the same hues, darkened until text reads at 4.5:1 or more on white, in 24-bit color and after
|
|
33
|
+
// the step down to 256 colors (Terminal.app). The dragon and the badge art keep their colors in both.
|
|
34
|
+
export const PALETTES = {
|
|
35
|
+
dark: {
|
|
36
|
+
accent: "#9d7cd8",
|
|
37
|
+
good: "#4ade80",
|
|
38
|
+
bad: "#f87171",
|
|
39
|
+
warn: "#fbbf24",
|
|
40
|
+
text: "#c9ccd3",
|
|
41
|
+
hint: "#8b919c", // the words in key hints: quieter than text, easier to read than dim
|
|
42
|
+
track: "#3a3f47",
|
|
43
|
+
separator: "#5a606b", // the dots between key hints
|
|
44
|
+
mark: "#2a2440", // behind `something to type`
|
|
45
|
+
countdown: "#6b5e8a", // the bar until the next card
|
|
46
|
+
locked: "#4a5058", // a badge not won yet
|
|
47
|
+
flash: "#ffffff", // a badge lighting up
|
|
48
|
+
sky: "#7dd3fc",
|
|
49
|
+
pink: "#f0abfc",
|
|
50
|
+
dayHalfway: "#3f9d5e",
|
|
51
|
+
daySome: "#2f6b45",
|
|
52
|
+
dayNone: "#3a3f47",
|
|
53
|
+
dayRest: "#2a2e35",
|
|
54
|
+
dayFuture: "#1c1f25",
|
|
55
|
+
dieFace: "#f4f4f5",
|
|
56
|
+
dieEdge: "#c7c9d1",
|
|
57
|
+
diePips: "#2a2440"
|
|
58
|
+
},
|
|
59
|
+
light: {
|
|
60
|
+
accent: "#7b4cca",
|
|
61
|
+
good: "#117f3a",
|
|
62
|
+
bad: "#b01212",
|
|
63
|
+
warn: "#9c4a00",
|
|
64
|
+
text: "#303030",
|
|
65
|
+
hint: "#626262",
|
|
66
|
+
track: "#dadada",
|
|
67
|
+
separator: "#a8a8a8",
|
|
68
|
+
mark: "#ece4fa",
|
|
69
|
+
countdown: "#a08ad6",
|
|
70
|
+
locked: "#c6c6c6",
|
|
71
|
+
flash: "#000000",
|
|
72
|
+
sky: "#027fbf",
|
|
73
|
+
pink: "#b0179e",
|
|
74
|
+
dayHalfway: "#5fbf7f",
|
|
75
|
+
daySome: "#a6dcaa",
|
|
76
|
+
dayNone: "#dadada",
|
|
77
|
+
dayRest: "#e8e8e8",
|
|
78
|
+
dayFuture: "#f4f4f4",
|
|
79
|
+
dieFace: "#e4e4e4",
|
|
80
|
+
dieEdge: "#a8a8b0",
|
|
81
|
+
diePips: "#2a2440"
|
|
82
|
+
}
|
|
40
83
|
};
|
|
41
84
|
|
|
85
|
+
// The colors in use. Screens read them while they render, so switching the theme repaints everything.
|
|
86
|
+
export const theme = { ...PALETTES.dark };
|
|
87
|
+
|
|
88
|
+
// what the terminal said its background is ("light" or "dark"), for the auto theme; unknown: dark
|
|
89
|
+
let background = null;
|
|
90
|
+
export function setBackground(value) {
|
|
91
|
+
background = value === "light" || value === "dark" ? value : null;
|
|
92
|
+
}
|
|
93
|
+
export const themeName = (choice) => (choice === "light" || choice === "dark" ? choice : background ?? "dark");
|
|
94
|
+
let applied = "dark";
|
|
95
|
+
export function applyTheme(choice) {
|
|
96
|
+
applied = themeName(choice);
|
|
97
|
+
Object.assign(theme, PALETTES[applied]);
|
|
98
|
+
return applied;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// A sprite's own color (a badge's rank, the dragon's element) used for words: as it is on dark; on
|
|
102
|
+
// light, darkened in steps until it reads at 4.5:1 on white, in 24-bit color and in 256 (chalk's pick).
|
|
103
|
+
const channels = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
|
|
104
|
+
const luminance = (rgb) => rgb.map((v) => v / 255).map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)).reduce((sum, c, i) => sum + c * [0.2126, 0.7152, 0.0722][i], 0);
|
|
105
|
+
const onWhite = (rgb) => 1.05 / (luminance(rgb) + 0.05);
|
|
106
|
+
const STEPS = [0, 95, 135, 175, 215, 255];
|
|
107
|
+
const in256 = ([r, g, b]) => (r === g && g === b ? [r, g, b].map(() => (r < 8 ? 0 : r > 248 ? 255 : 8 + Math.round(((r - 8) / 247) * 24) * 10)) : [r, g, b].map((v) => STEPS[Math.round((v / 255) * 5)]));
|
|
108
|
+
const darkened = new Map();
|
|
109
|
+
export function readable(color) {
|
|
110
|
+
if (!color || applied !== "light") return color;
|
|
111
|
+
if (!darkened.has(color)) {
|
|
112
|
+
let rgb = channels(color);
|
|
113
|
+
for (let scale = 1; scale > 0 && (onWhite(rgb) < 4.5 || onWhite(in256(rgb)) < 4.5); scale -= 0.02) rgb = channels(color).map((v) => Math.round(v * scale));
|
|
114
|
+
darkened.set(color, `#${rgb.map((v) => v.toString(16).padStart(2, "0")).join("")}`);
|
|
115
|
+
}
|
|
116
|
+
return darkened.get(color);
|
|
117
|
+
}
|
|
118
|
+
|
|
42
119
|
// Text where `backticks` mark something to type: shown in the accent color on a faint violet
|
|
43
120
|
// background, like code in docs. Used for the tour's cards; `plain` shows the text as it is.
|
|
44
121
|
export function Marked({ text, plain = false, ...props }) {
|
|
@@ -47,7 +124,7 @@ export function Marked({ text, plain = false, ...props }) {
|
|
|
47
124
|
return React.createElement(
|
|
48
125
|
Text,
|
|
49
126
|
props,
|
|
50
|
-
...parts.map((part, i) => (i % 2 ? React.createElement(Text, { key: i, color: theme.accent, backgroundColor:
|
|
127
|
+
...parts.map((part, i) => (i % 2 ? React.createElement(Text, { key: i, color: theme.accent, backgroundColor: theme.mark, bold: true }, part) : part))
|
|
51
128
|
);
|
|
52
129
|
}
|
|
53
130
|
|
|
@@ -69,7 +146,7 @@ export function KeyHints({ text }) {
|
|
|
69
146
|
const key = KEY.exec(part)?.[0];
|
|
70
147
|
const rest = key ? part.slice(key.length) : part;
|
|
71
148
|
return [
|
|
72
|
-
i > 0 && React.createElement(Text, { key: `s${i}`, color:
|
|
149
|
+
i > 0 && React.createElement(Text, { key: `s${i}`, color: theme.separator }, " · "),
|
|
73
150
|
key && React.createElement(Text, { key: `k${i}`, color: theme.text }, key),
|
|
74
151
|
React.createElement(Text, { key: `r${i}`, color: theme.hint }, rest)
|
|
75
152
|
].filter(Boolean);
|