-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
641 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ module.exports = { | |
rules: {}, | ||
}, | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"semi": true, | ||
"semi": false, | ||
"tabWidth": 2, | ||
"printWidth": 80, | ||
"singleQuote": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
const primaryColorScheme = ""; // "light" | "dark" | ||
const primaryColorScheme = "" // "light" | "dark" | ||
|
||
// Get theme data from local storage | ||
const currentTheme = localStorage.getItem("theme"); | ||
const currentTheme = localStorage.getItem("theme") | ||
|
||
function getPreferTheme() { | ||
// return theme value in local storage if it is set | ||
if (currentTheme) return currentTheme; | ||
if (currentTheme) return currentTheme | ||
|
||
// return primary color scheme if it is set | ||
if (primaryColorScheme) return primaryColorScheme; | ||
if (primaryColorScheme) return primaryColorScheme | ||
|
||
// return user device's prefer color scheme | ||
return window.matchMedia("(prefers-color-scheme: dark)").matches | ||
? "dark" | ||
: "light"; | ||
: "light" | ||
} | ||
|
||
let themeValue = getPreferTheme(); | ||
let themeValue = getPreferTheme() | ||
|
||
function setPreference() { | ||
localStorage.setItem("theme", themeValue); | ||
reflectPreference(); | ||
localStorage.setItem("theme", themeValue) | ||
reflectPreference() | ||
} | ||
|
||
function reflectPreference() { | ||
document.firstElementChild.setAttribute("data-theme", themeValue); | ||
document.firstElementChild.setAttribute("data-theme", themeValue) | ||
|
||
document.querySelector("#theme-btn")?.setAttribute("aria-label", themeValue); | ||
document.querySelector("#theme-btn")?.setAttribute("aria-label", themeValue) | ||
|
||
// Get a reference to the body element | ||
const body = document.body; | ||
const body = document.body | ||
|
||
// Check if the body element exists before using getComputedStyle | ||
if (body) { | ||
// Get the computed styles for the body element | ||
const computedStyles = window.getComputedStyle(body); | ||
const computedStyles = window.getComputedStyle(body) | ||
|
||
// Get the background color property | ||
const bgColor = computedStyles.backgroundColor; | ||
const bgColor = computedStyles.backgroundColor | ||
|
||
// Set the background color in <meta theme-color ... /> | ||
document | ||
.querySelector("meta[name='theme-color']") | ||
?.setAttribute("content", bgColor); | ||
?.setAttribute("content", bgColor) | ||
} | ||
} | ||
|
||
// set early so no page flashes / CSS is made aware | ||
reflectPreference(); | ||
reflectPreference() | ||
|
||
window.onload = () => { | ||
function setThemeFeature() { | ||
// set on load so screen readers can get the latest value on the button | ||
reflectPreference(); | ||
reflectPreference() | ||
|
||
// now this script can find and listen for clicks on the control | ||
document.querySelector("#theme-btn")?.addEventListener("click", () => { | ||
themeValue = themeValue === "light" ? "dark" : "light"; | ||
setPreference(); | ||
}); | ||
themeValue = themeValue === "light" ? "dark" : "light" | ||
setPreference() | ||
}) | ||
} | ||
|
||
setThemeFeature(); | ||
setThemeFeature() | ||
|
||
// Runs on view transitions navigation | ||
document.addEventListener("astro:after-swap", setThemeFeature); | ||
}; | ||
document.addEventListener("astro:after-swap", setThemeFeature) | ||
} | ||
|
||
// sync with system changes | ||
window | ||
.matchMedia("(prefers-color-scheme: dark)") | ||
.addEventListener("change", ({ matches: isDark }) => { | ||
themeValue = isDark ? "dark" : "light"; | ||
setPreference(); | ||
}); | ||
themeValue = isDark ? "dark" : "light" | ||
setPreference() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.