@tenphi/starlight 0.6.1 → 0.8.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/dist/components/ContrastSelect.astro +78 -0
- package/dist/components/GlobalStyles.js +1132 -170
- package/dist/components/LayoutComponents.js +148 -111
- package/dist/components/Logo.astro +4 -2
- package/dist/components/component-styles.test.ts +24 -0
- package/dist/icons/contrast.svg +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +635 -114
- package/dist/index.js.map +1 -1
- package/dist/overrides/Header.astro +4 -2
- package/dist/overrides/MobileMenuFooter.astro +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
import contrastIcon from "../icons/contrast.svg?raw";
|
|
3
|
+
import { ContrastSelectRoot } from "./LayoutComponents.js";
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<ContrastSelectRoot data-tasty-anatomy="ContrastSelect">
|
|
7
|
+
<label>
|
|
8
|
+
<span class="sr-only">Contrast</span>
|
|
9
|
+
<span class="label-icon" aria-hidden="true" set:html={contrastIcon} />
|
|
10
|
+
<select data-docs-contrast aria-label="Contrast" autocomplete="off">
|
|
11
|
+
<option value="system" selected>System contrast</option>
|
|
12
|
+
<option value="normal">Normal contrast</option>
|
|
13
|
+
<option value="more">High contrast</option>
|
|
14
|
+
</select>
|
|
15
|
+
</label>
|
|
16
|
+
</ContrastSelectRoot>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
type Contrast = "more" | "normal" | "system";
|
|
20
|
+
|
|
21
|
+
const storageKey = "cookbook-appearance";
|
|
22
|
+
const parseContrast = (value: unknown): Contrast =>
|
|
23
|
+
value === "more" || value === "normal" || value === "system"
|
|
24
|
+
? value
|
|
25
|
+
: "system";
|
|
26
|
+
const loadContrast = (): Contrast => {
|
|
27
|
+
try {
|
|
28
|
+
const stored = localStorage.getItem(storageKey);
|
|
29
|
+
if (!stored) return "system";
|
|
30
|
+
const appearance = JSON.parse(stored) as { contrast?: unknown };
|
|
31
|
+
return parseContrast(appearance.contrast);
|
|
32
|
+
} catch {
|
|
33
|
+
return "system";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const storeContrast = (contrast: Contrast): void => {
|
|
37
|
+
try {
|
|
38
|
+
const stored = localStorage.getItem(storageKey);
|
|
39
|
+
const parsed = stored ? (JSON.parse(stored) as unknown) : {};
|
|
40
|
+
const appearance =
|
|
41
|
+
parsed && typeof parsed === "object"
|
|
42
|
+
? (parsed as Record<string, unknown>)
|
|
43
|
+
: {};
|
|
44
|
+
localStorage.setItem(
|
|
45
|
+
storageKey,
|
|
46
|
+
JSON.stringify({ ...appearance, contrast }),
|
|
47
|
+
);
|
|
48
|
+
} catch {
|
|
49
|
+
// CSS media queries still provide the system fallback.
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const updateContrast = (contrast: Contrast, persist = false): void => {
|
|
53
|
+
if (contrast === "system") delete document.documentElement.dataset.contrast;
|
|
54
|
+
else document.documentElement.dataset.contrast = contrast;
|
|
55
|
+
document
|
|
56
|
+
.querySelectorAll<HTMLSelectElement>("[data-docs-contrast]")
|
|
57
|
+
.forEach((select) => (select.value = contrast));
|
|
58
|
+
if (persist) storeContrast(contrast);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
class CookbookContrastSelect extends HTMLElement {
|
|
62
|
+
connectedCallback(): void {
|
|
63
|
+
if (this.dataset.ready === "true") return;
|
|
64
|
+
this.dataset.ready = "true";
|
|
65
|
+
const select = this.querySelector<HTMLSelectElement>(
|
|
66
|
+
"[data-docs-contrast]",
|
|
67
|
+
);
|
|
68
|
+
select?.addEventListener("change", () => {
|
|
69
|
+
updateContrast(parseContrast(select.value), true);
|
|
70
|
+
});
|
|
71
|
+
updateContrast(loadContrast());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!customElements.get("cookbook-contrast-select")) {
|
|
76
|
+
customElements.define("cookbook-contrast-select", CookbookContrastSelect);
|
|
77
|
+
}
|
|
78
|
+
</script>
|