-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dark probe * fix tests --------- Co-authored-by: Philippe Rivière <[email protected]>
- Loading branch information
Showing
11 changed files
with
23 additions
and
13 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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import {observe} from "./observe.js"; | ||
|
||
// Watches dark mode based on theme and user preference. | ||
// TODO: in preview, also watch for changes in the theme meta. | ||
export function dark() { | ||
return observe((notify: (dark: boolean) => void) => { | ||
let dark: boolean | undefined; | ||
const media = matchMedia("(prefers-color-scheme: dark)"); | ||
const probe = document.createElement("div"); | ||
probe.style.transitionProperty = "color, background-color"; | ||
probe.style.transitionDuration = "1ms"; | ||
const changed = () => { | ||
const d = getComputedStyle(document.body).getPropertyValue("color-scheme") === "dark"; | ||
const s = getComputedStyle(document.body).getPropertyValue("color-scheme").split(/\s+/); | ||
let d: boolean; | ||
if (s.includes("light") && s.includes("dark")) d = media.matches; | ||
else d = s.includes("dark"); | ||
if (dark === d) return; // only notify if changed | ||
notify((dark = d)); | ||
}; | ||
document.body.appendChild(probe); | ||
changed(); | ||
probe.addEventListener("transitionstart", changed); | ||
media.addEventListener("change", changed); | ||
return () => media.removeEventListener("change", changed); | ||
return () => { | ||
probe.removeEventListener("transitionstart", changed); | ||
media.removeEventListener("change", changed); | ||
}; | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -8,15 +8,15 @@ | |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" crossorigin> | ||
<link rel="preload" as="style" href="./_observablehq/theme-air,near-midnight.00000004.css"> | ||
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000006.css"> | ||
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000007.css"> | ||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" crossorigin> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/theme-air,near-midnight.00000004.css"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000006.css"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000007.css"> | ||
<link rel="modulepreload" href="./_observablehq/client.00000001.js"> | ||
<link rel="modulepreload" href="./_observablehq/runtime.00000002.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib.00000003.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/duckdb.00000005.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000007.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000006.js"> | ||
<link rel="modulepreload" href="./_npm/@duckdb/[email protected]/cd372fb8.js"> | ||
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js"> | ||
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js"> | ||
|
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 +1 @@ | ||
import "../_observablehq/stdlib/inputs.00000006.js"; | ||
import "../_observablehq/stdlib/inputs.00000005.js"; |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -7,15 +7,15 @@ | |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" crossorigin> | ||
<link rel="preload" as="style" href="./_observablehq/theme-air,near-midnight.00000004.css"> | ||
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000005.css"> | ||
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000006.css"> | ||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" crossorigin> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/theme-air,near-midnight.00000004.css"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000005.css"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000006.css"> | ||
<link rel="modulepreload" href="./_observablehq/client.00000001.js"> | ||
<link rel="modulepreload" href="./_observablehq/runtime.00000002.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib.00000003.js"> | ||
<link rel="modulepreload" href="./_import/index.4bdc071f.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000006.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000005.js"> | ||
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js"> | ||
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js"> | ||
<script type="module"> | ||
|
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -7,15 +7,15 @@ | |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" crossorigin> | ||
<link rel="preload" as="style" href="./_observablehq/theme-air,near-midnight.00000004.css"> | ||
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000006.css"> | ||
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000007.css"> | ||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" crossorigin> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/theme-air,near-midnight.00000004.css"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000006.css"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000007.css"> | ||
<link rel="modulepreload" href="./_observablehq/client.00000001.js"> | ||
<link rel="modulepreload" href="./_observablehq/runtime.00000002.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib.00000003.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/duckdb.00000005.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000007.js"> | ||
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000006.js"> | ||
<link rel="modulepreload" href="./_npm/@duckdb/[email protected]/cd372fb8.js"> | ||
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js"> | ||
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js"> | ||
|