website

#astro#js#html#css

git clone https://git.pyrossh.dev/website

木 Personal website of pyrossh. Built with astrojs, shiki, vite.


e9c1a81 — pyrossh 2026-11-17T09:39:11+05:30
Modernize the theme toggle, copy button and page transitions
assets/client.js CHANGED
@@ -5,18 +5,35 @@
5
5
  // (no web component, no framework — a stateless click-to-toggle button
6
6
  // doesn't need one). Loaded with `defer` so this runs after the DOM is
7
7
  // parsed and #theme-change already exists.
8
+ //
9
+ // The scheme lives in <meta name="color-scheme"> (see layout.njk and
10
+ // shared.css): "light dark" follows the OS, "light"/"dark" pin an override.
11
+ const colorSchemeMeta = document.querySelector('meta[name="color-scheme"]');
12
+ const systemScheme = () => (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
13
+ const applyScheme = (stored) => {
14
+ colorSchemeMeta.content = stored === "light" || stored === "dark" ? stored : "light dark";
15
+ };
16
+
8
17
  document.getElementById("theme-change").addEventListener("click", () => {
9
- const root = document.documentElement;
10
- // data-theme is tri-state: absent means "follow the OS preference" (see
18
+ // Flip whatever is *currently shown*. Landing back on the OS preference
19
+ // means the user is undoing their override, so drop it instead of
11
- // `color-scheme: light dark` in shared.css). Resolve against that OS
20
+ // storing a value that would silently pin the scheme against future OS
12
- // preference when no explicit value is set yet, so the first click
13
- // always flips to the opposite of what's *currently shown* rather than
21
+ // changes (e.g. automatic day/night switching).
14
- // assuming light.
15
- const currentTheme = root.getAttribute("data-theme");
16
- const isDark = currentTheme ? currentTheme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
22
+ const current = colorSchemeMeta.content === "light dark" ? systemScheme() : colorSchemeMeta.content;
17
- const next = isDark ? "light" : "dark";
23
+ const next = current === "dark" ? "light" : "dark";
18
- root.setAttribute("data-theme", next);
24
+ const stored = next === systemScheme() ? null : next;
25
+ applyScheme(stored);
26
+ try {
19
- localStorage.setItem("theme", next);
27
+ if (stored) localStorage.setItem("theme", stored);
28
+ else localStorage.removeItem("theme");
29
+ } catch {
30
+ // storage blocked: the switch still applies for this page view
31
+ }
32
+ });
33
+
34
+ // Keep other open tabs in sync when the override changes in one of them.
35
+ addEventListener("storage", (e) => {
36
+ if (e.key === "theme" || e.key === null) applyScheme(e.newValue);
20
37
  });
21
38
 
22
39
  // Every file page in a repo loads the same tree (repos/tree.njk), so the tree
@@ -51,14 +68,59 @@ document.addEventListener("click", (e) => {
51
68
  });
52
69
 
53
70
  // Copies the git clone command shown in the repo header (see .clone-cmd in
54
- // repos.css) and flips the button to a checkmark for a bit as feedback,
71
+ // repos.css). The button names its source with Invoker Commands
72
+ // (command="--copy" commandfor=...), and the .copy-tip next to it is both
73
+ // the visible "Copied"/"Copy failed" text and the role="status" live region.
74
+ const copyTimers = new WeakMap();
75
+ let lastCopyMessage = "";
76
+
77
+ const reportCopy = (button, ok) => {
78
+ const tip = button.nextElementSibling;
79
+ clearTimeout(copyTimers.get(button));
80
+ button.removeAttribute("data-copied");
81
+ button.removeAttribute("data-failed");
82
+ tip.textContent = "";
83
+ button.setAttribute(ok ? "data-copied" : "data-failed", "");
84
+ let message = ok ? "Copied" : "Copy failed";
85
+ // VoiceOver skips a message identical to the previous one from the same region.
86
+ if (message === lastCopyMessage) message += " ";
87
+ lastCopyMessage = message;
88
+ requestAnimationFrame(() => (tip.textContent = message));
89
+ copyTimers.set(
90
+ button,
91
+ setTimeout(() => {
92
+ button.removeAttribute("data-copied");
93
+ button.removeAttribute("data-failed");
94
+ tip.textContent = "";
95
+ }, 1500),
96
+ );
97
+ };
98
+
99
+ const copyText = async (button, target) => {
100
+ const text = target.innerText.trim();
101
+ if (!text) return;
102
+ try {
103
+ await navigator.clipboard.writeText(text);
104
+ reportCopy(button, true);
105
+ } catch {
106
+ // no clipboard (insecure context) or permission denied
107
+ reportCopy(button, false);
108
+ }
109
+ };
110
+
111
+ if ("CommandEvent" in window) {
55
- // instead of a tooltip/toast that would need its own positioning logic.
112
+ // `command` events don't bubble, so listen in the capture phase.
113
+ document.addEventListener(
114
+ "command",
115
+ (e) => {
116
+ if (e.command === "--copy") copyText(e.source, e.target);
117
+ },
118
+ true,
119
+ );
120
+ } else {
56
- document.addEventListener("click", (e) => {
121
+ document.addEventListener("click", (e) => {
57
- const btn = e.target.closest(".copy-btn");
122
+ const button = e.target.closest('button[command="--copy"]');
58
- if (!btn) return;
59
- navigator.clipboard.writeText(btn.dataset.clone).then(() => {
60
- clearTimeout(btn._copyResetTimer);
61
- btn.classList.add("copied");
62
- btn._copyResetTimer = setTimeout(() => btn.classList.remove("copied"), 1500);
123
+ const target = button && document.getElementById(button.getAttribute("commandfor"));
124
+ if (target) copyText(button, target);
63
125
  });
64
- });
126
+ }
assets/css/repos.css CHANGED
@@ -97,8 +97,8 @@
97
97
  display: flex;
98
98
  align-items: center;
99
99
  justify-content: center;
100
+ min-inline-size: max(1.6rem, 24px);
100
- width: 1.6rem;
101
+ min-block-size: max(1.6rem, 24px);
101
- height: 1.6rem;
102
102
  padding: 0;
103
103
  border: none;
104
104
  border-radius: 4px;
@@ -116,7 +116,7 @@
116
116
  display: none;
117
117
  }
118
118
 
119
- &.copied {
119
+ &[data-copied] {
120
120
  opacity: 1;
121
121
  color: var(--color-tag);
122
122
 
@@ -128,6 +128,24 @@
128
128
  display: block;
129
129
  }
130
130
  }
131
+
132
+ &[data-failed] {
133
+ opacity: 1;
134
+ }
135
+ }
136
+
137
+ /* The visible feedback and the live region in one element. Hidden with
138
+ opacity, not display/visibility, so its text stays announceable. */
139
+ .copy-tip {
140
+ flex-shrink: 0;
141
+ padding-inline-start: 0.4rem;
142
+ font-size: 0.8em;
143
+ opacity: 0;
144
+ transition: opacity 0.15s;
145
+
146
+ &:not(:empty) {
147
+ opacity: 1;
148
+ }
131
149
  }
132
150
  }
133
151
 
assets/css/shared.css CHANGED
@@ -8,8 +8,12 @@ a { color: inherit; text-decoration: none; }
8
8
  ul, ol { list-style: none; }
9
9
  table { border-collapse: collapse; }
10
10
 
11
+ /* Opted into only when motion is fine, so reduced-motion users get a plain
12
+ instant navigation rather than a transition with its animation removed. */
13
+ @media (prefers-reduced-motion: no-preference) {
11
- @view-transition {
14
+ @view-transition {
12
- navigation: auto;
15
+ navigation: auto;
16
+ }
13
17
  }
14
18
 
15
19
  /* Cross-document view transitions (native browser MPA navigation, no JS).
@@ -56,13 +60,6 @@ table { border-collapse: collapse; }
56
60
  animation: none;
57
61
  }
58
62
 
59
- @media (prefers-reduced-motion: reduce) {
60
- ::view-transition-old(root),
61
- ::view-transition-new(root) {
62
- animation: none !important;
63
- }
64
- }
65
-
66
63
  :root {
67
64
  --color-black: light-dark(hsl(0, 0%, 0%), hsl(0, 0%, 0%));
68
65
  --color-white: light-dark(hsl(0, 0%, 100%), hsl(0, 0%, 100%));
@@ -111,36 +108,48 @@ table { border-collapse: collapse; }
111
108
  --space-section-mb: clamp(0rem, calc(-0.3333rem + 1.6667vw), 1rem);
112
109
  }
113
110
 
114
- /* data-theme is tri-state: absent = follow OS (color-scheme: light dark
111
+ /* <meta name="color-scheme"> in layout.njk is tri-state: "light dark" =
112
+ follow OS (color-scheme: light dark above already does that),
115
- above already does that), "light"/"dark" = explicit user override that
113
+ "light"/"dark" = explicit user override that must win even against an
116
- must win even against an opposite OS preference. Every color below is
117
- driven by light-dark() reading this color-scheme value — no need to
114
+ opposite OS preference. The meta is only a presentational hint that the
115
+ author-level color-scheme above would override, so map it back onto the
116
+ property here. Every color is driven by light-dark() reading this
118
- redeclare each variable per theme. */
117
+ color-scheme value — no need to redeclare each variable per theme. */
119
- :root[data-theme="light"] {
118
+ :root:has(> head > meta[name="color-scheme"][content="light"]) {
120
119
  color-scheme: light;
121
120
  }
122
121
 
123
- :root[data-theme="dark"] {
122
+ :root:has(> head > meta[name="color-scheme"][content="dark"]) {
124
123
  color-scheme: dark;
125
124
  }
126
125
 
127
126
  @media (prefers-color-scheme: dark) {
128
- :root:not([data-theme]) {
127
+ :root:has(> head > meta[name="color-scheme"][content="light dark"]) {
129
128
  --btn-light: block;
130
129
  --btn-dark: none;
131
130
  }
132
131
  }
133
132
 
134
- :root[data-theme="dark"] {
133
+ :root:has(> head > meta[name="color-scheme"][content="dark"]) {
135
134
  --btn-light: block;
136
135
  --btn-dark: none;
137
136
  }
138
137
 
139
- :root[data-theme="light"] {
138
+ :root:has(> head > meta[name="color-scheme"][content="light"]) {
140
139
  --btn-light: none;
141
140
  --btn-dark: block;
142
141
  }
143
142
 
143
+ .visually-hidden {
144
+ position: absolute;
145
+ width: 1px;
146
+ height: 1px;
147
+ margin: -1px;
148
+ overflow: hidden;
149
+ clip-path: inset(50%);
150
+ white-space: nowrap;
151
+ }
152
+
144
153
  [data-tooltip] {
145
154
  position: relative;
146
155
  cursor: help;
changelog.md ADDED
@@ -0,0 +1,61 @@
1
+ # Changelog
2
+
3
+ ## 2026-11-17
4
+
5
+ ### Theme toggle
6
+
7
+ - The chosen theme is now stored in `<meta name="color-scheme">` instead of a
8
+ `data-theme` attribute on `<html>`. A small inline script in `layout.njk`
9
+ sets it from `localStorage` before first paint, and `shared.css` maps it
10
+ back onto the CSS `color-scheme` property with
11
+ `:root:has(> head > meta[name="color-scheme"][content=...])` selectors.
12
+ - You can return to "follow the OS" again. Before, the first click always
13
+ saved `light` or `dark`, and the site stayed pinned to it from then on. Now,
14
+ if a click lands on the theme the OS already uses, the saved value is
15
+ deleted. A saved value is kept if the OS later switches to match it.
16
+ - `localStorage` reads and writes are wrapped in `try`/`catch`, so blocked
17
+ storage no longer breaks the toggle. The theme still switches for that
18
+ page view.
19
+ - Other open tabs follow a change through the `storage` event.
20
+ - Screen readers can now name the icon-only button. Hidden "Switch to
21
+ light theme" / "Switch to dark theme" text switches along with the icon, and
22
+ the icons are hidden from screen readers.
23
+
24
+ ### Clone command copy button
25
+
26
+ - The button declares what it copies with Invoker Commands
27
+ (`command="--copy" commandfor="clone-cmd-text"`). Browsers without
28
+ `CommandEvent` use a click handler that calls the same copy function.
29
+ - A failed copy (no clipboard in an insecure context, or permission denied)
30
+ now shows "Copy failed". Before, it failed silently, leaving an unhandled
31
+ promise rejection.
32
+ - A `role="status"` element next to the button shows "Copied" / "Copy failed",
33
+ both on screen and to screen readers. It is hidden with `opacity` so its
34
+ text can still be announced. A repeated message gets a no-break space so
35
+ VoiceOver reads it again.
36
+ - The button is at least 24×24px (`min-inline-size` / `min-block-size`), and
37
+ its state uses `data-copied` / `data-failed` attributes instead of a
38
+ `.copied` class.
39
+
40
+ ### Page transitions
41
+
42
+ - `@view-transition { navigation: auto }` is now inside
43
+ `@media (prefers-reduced-motion: no-preference)`. Users who ask for reduced
44
+ motion get a normal navigation with no transition, replacing the old rule
45
+ that stripped the animation with `animation: none !important`.
46
+
47
+ ### Kept as is
48
+
49
+ - htmx still loads without `defer`. A deferred htmx starts up while the
50
+ cross-document view transition is running, and the browser skips the
51
+ transition ("Transition was skipped") on repo file and tree pages. A
52
+ comment in `layout.njk` records this.
53
+
54
+ ### Tests
55
+
56
+ - Added Playwright tests for the theme toggle: overriding the OS theme,
57
+ keeping it across a reload, going back to the OS theme, and keeping a saved
58
+ value after the OS switches to match it.
59
+ - Added Playwright tests for the copy button: a successful copy (clipboard
60
+ contents and the "Copied" status) and a failed copy (the "Copy failed"
61
+ status).
src/_includes/layout.njk CHANGED
@@ -2,11 +2,12 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
+ <meta name="color-scheme" content="light dark" />
5
6
  <script>
7
+ try {
6
- var theme = localStorage.getItem("theme");
8
+ var theme = localStorage.getItem("theme");
7
- if (theme === "dark" || theme === "light") {
9
+ if (theme === "dark" || theme === "light") document.querySelector('meta[name="color-scheme"]').content = theme;
8
- document.documentElement.setAttribute("data-theme", theme);
10
+ } catch {}
9
- }
10
11
  </script>
11
12
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
12
13
  <meta name="theme-color" content="#131618" />
@@ -28,6 +29,9 @@
28
29
  <meta name="twitter:title" content="{{ pageTitle }}" />
29
30
  <meta name="twitter:description" content="{{ description or site.description }}" />
30
31
  <script defer src="/assets/client.js"></script>
32
+ {# Deliberately not `defer`: a deferred htmx initializes while the
33
+ cross-document view transition is running and the browser skips the
34
+ transition ("Transition was skipped") on repo file/tree pages. #}
31
35
  <script src="/assets/vendor/htmx.min.js"></script>
32
36
  </head>
33
37
  <body>
src/_includes/repo-layout.njk CHANGED
@@ -5,11 +5,12 @@
5
5
  <div class="tags">{% for tag in tags %}<span class="tag">#{{ tag }}</span>{% endfor %}</div>
6
6
  </div>
7
7
  <h3 class="clone-cmd">
8
- <p>git clone <span class="tag">https://git.pyrossh.dev/{{ title }}</span></p>
9
- <button type="button" class="copy-btn" data-clone="git clone https://git.pyrossh.dev/{{ title }}" aria-label="Copy clone command">
10
- <svg class="icon-copy" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
11
- <svg class="icon-check" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
8
+ <p id="clone-cmd-text">git clone <span class="tag">https://git.pyrossh.dev/{{ title }}</span></p>
9
+ <button type="button" class="copy-btn" command="--copy" commandfor="clone-cmd-text" aria-label="Copy clone command">
10
+ <svg class="icon-copy" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
11
+ <svg class="icon-check" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
12
12
  </button>
13
+ <span class="copy-tip" role="status"></span>
13
14
  </h3>
14
15
  <div class="headerExtension"><h2>{{ desc }}</h2></div>
15
16
  <hr />
src/_includes/site-header.njk CHANGED
@@ -3,7 +3,7 @@
3
3
  <nav>
4
4
  <a href="/" class="logo{% if page.url == '/' %} active{% endif %}">木 {{ site.title }}</a>
5
5
  <div class="links">
6
- <span id="theme-switch"><button id="theme-change" type="button"><svg style="display:var(--btn-light)" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path fill="currentColor" d="M11.288 4.713Q11 4.425 11 4V2q0-.425.288-.712T12 1t.713.288T13 2v2q0 .425-.288.713T12 5t-.712-.288M16.95 7.05q-.275-.275-.275-.687t.275-.713l1.4-1.425q.3-.3.712-.3t.713.3q.275.275.275.7t-.275.7L18.35 7.05q-.275.275-.7.275t-.7-.275M20 13q-.425 0-.713-.288T19 12t.288-.712T20 11h2q.425 0 .713.288T23 12t-.288.713T22 13zm-8.712 9.713Q11 22.425 11 22v-2q0-.425.288-.712T12 19t.713.288T13 20v2q0 .425-.288.713T12 23t-.712-.288M5.65 7.05l-1.425-1.4q-.3-.3-.3-.725t.3-.7q.275-.275.7-.275t.7.275L7.05 5.65q.275.275.275.7t-.275.7q-.3.275-.7.275t-.7-.275m12.7 12.725l-1.4-1.425q-.275-.3-.275-.712t.275-.688t.688-.275t.712.275l1.425 1.4q.3.275.288.7t-.288.725q-.3.3-.725.3t-.7-.3M2 13q-.425 0-.712-.288T1 12t.288-.712T2 11h2q.425 0 .713.288T5 12t-.288.713T4 13zm2.225 6.775q-.275-.275-.275-.7t.275-.7L5.65 16.95q.275-.275.687-.275t.713.275q.3.3.3.713t-.3.712l-1.4 1.4q-.3.3-.725.3t-.7-.3M7.75 16.25Q6 14.5 6 12t1.75-4.25T12 6t4.25 1.75T18 12t-1.75 4.25T12 18t-4.25-1.75"/></svg><svg style="display:var(--btn-dark)" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path fill="currentColor" d="m15 8l-3-3l3-3l3 3zm5 3l-2-2l2-2l2 2zm-7.925 11q-2.1 0-3.937-.8t-3.2-2.162t-2.163-3.2t-.8-3.938q0-3.65 2.325-6.437T10.225 2q-.45 2.475.275 4.838t2.5 4.137t4.138 2.5t4.837.275q-.65 3.6-3.45 5.925T12.075 22"/></svg></button></span>
6
+ <span id="theme-switch"><button id="theme-change" type="button"><span class="visually-hidden" style="display:var(--btn-light)">Switch to light theme</span><svg aria-hidden="true" style="display:var(--btn-light)" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path fill="currentColor" d="M11.288 4.713Q11 4.425 11 4V2q0-.425.288-.712T12 1t.713.288T13 2v2q0 .425-.288.713T12 5t-.712-.288M16.95 7.05q-.275-.275-.275-.687t.275-.713l1.4-1.425q.3-.3.712-.3t.713.3q.275.275.275.7t-.275.7L18.35 7.05q-.275.275-.7.275t-.7-.275M20 13q-.425 0-.713-.288T19 12t.288-.712T20 11h2q.425 0 .713.288T23 12t-.288.713T22 13zm-8.712 9.713Q11 22.425 11 22v-2q0-.425.288-.712T12 19t.713.288T13 20v2q0 .425-.288.713T12 23t-.712-.288M5.65 7.05l-1.425-1.4q-.3-.3-.3-.725t.3-.7q.275-.275.7-.275t.7.275L7.05 5.65q.275.275.275.7t-.275.7q-.3.275-.7.275t-.7-.275m12.7 12.725l-1.4-1.425q-.275-.3-.275-.712t.275-.688t.688-.275t.712.275l1.425 1.4q.3.275.288.7t-.288.725q-.3.3-.725.3t-.7-.3M2 13q-.425 0-.712-.288T1 12t.288-.712T2 11h2q.425 0 .713.288T5 12t-.288.713T4 13zm2.225 6.775q-.275-.275-.275-.7t.275-.7L5.65 16.95q.275-.275.687-.275t.713.275q.3.3.3.713t-.3.712l-1.4 1.4q-.3.3-.725.3t-.7-.3M7.75 16.25Q6 14.5 6 12t1.75-4.25T12 6t4.25 1.75T18 12t-1.75 4.25T12 18t-4.25-1.75"/></svg><span class="visually-hidden" style="display:var(--btn-dark)">Switch to dark theme</span><svg aria-hidden="true" style="display:var(--btn-dark)" viewBox="0 0 24 24" width="1.2em" height="1.2em"><path fill="currentColor" d="m15 8l-3-3l3-3l3 3zm5 3l-2-2l2-2l2 2zm-7.925 11q-2.1 0-3.937-.8t-3.2-2.162t-2.163-3.2t-.8-3.938q0-3.65 2.325-6.437T10.225 2q-.45 2.475.275 4.838t2.5 4.137t4.138 2.5t4.837.275q-.65 3.6-3.45 5.925T12.075 22"/></svg></button></span>
7
7
  <div>|</div>
8
8
  {% for item in site.navItems %}
9
9
  <a href="{{ item.href }}" class="{% if page.url == item.href or (item.href != '/' and page.url.startsWith(item.href)) %}active{% endif %}">{{ item.label }}</a><div>|</div>
tests/pages.test.js CHANGED
@@ -384,3 +384,74 @@ test("no unexpected console errors were logged across visited pages", () => {
384
384
  const unexpected = consoleErrors.filter((msg) => !/this-page-does-not-exist|\/(history|blame)\/\]|\/docs\/package\.json\/\]/.test(msg));
385
385
  assert.deepEqual(unexpected, []);
386
386
  });
387
+
388
+ describe("theme toggle", () => {
389
+ const scheme = () => page.locator('meta[name="color-scheme"]').getAttribute("content");
390
+ const computed = () => page.evaluate(() => getComputedStyle(document.documentElement).colorScheme);
391
+ const stored = () => page.evaluate(() => localStorage.getItem("theme"));
392
+
393
+ test("overrides the OS scheme, then returns to following it", async () => {
394
+ await page.emulateMedia({ colorScheme: "light" });
395
+ await goto("/");
396
+ await page.evaluate(() => localStorage.removeItem("theme"));
397
+ await goto("/");
398
+ assert.equal(await scheme(), "light dark");
399
+ const button = page.getByRole("button", { name: "Switch to dark theme" });
400
+ await assert.doesNotReject(button.waitFor());
401
+
402
+ await button.click();
403
+ assert.equal(await scheme(), "dark");
404
+ assert.equal(await computed(), "dark");
405
+ assert.equal(await stored(), "dark");
406
+
407
+ // Survives a reload via the inline head script.
408
+ await goto("/");
409
+ assert.equal(await scheme(), "dark");
410
+
411
+ // Toggling back onto the OS preference drops the override.
412
+ await page.getByRole("button", { name: "Switch to light theme" }).click();
413
+ assert.equal(await scheme(), "light dark");
414
+ assert.equal(await computed(), "light dark");
415
+ assert.equal(await stored(), null);
416
+ });
417
+
418
+ test("keeps a stored override when the OS later matches it", async () => {
419
+ await page.emulateMedia({ colorScheme: "light" });
420
+ await goto("/");
421
+ await page.evaluate(() => localStorage.setItem("theme", "dark"));
422
+ await page.emulateMedia({ colorScheme: "dark" });
423
+ await goto("/");
424
+ assert.equal(await scheme(), "dark");
425
+ assert.equal(await stored(), "dark");
426
+ await page.emulateMedia({ colorScheme: null });
427
+ await page.evaluate(() => localStorage.removeItem("theme"));
428
+ });
429
+ });
430
+
431
+ describe("clone command copy button", () => {
432
+ const repoId = "website";
433
+
434
+ test("copies the clone command and announces it", async () => {
435
+ const context = await browser.newContext({ permissions: ["clipboard-read", "clipboard-write"] });
436
+ const copyPage = await context.newPage();
437
+ try {
438
+ await copyPage.goto(`${server.url}/repos/${repoId}/`, { waitUntil: "domcontentloaded" });
439
+ await copyPage.getByRole("button", { name: "Copy clone command" }).click();
440
+ await assert.doesNotReject(copyPage.getByRole("status").filter({ hasText: "Copied" }).waitFor());
441
+ assert.equal(await copyPage.evaluate(() => navigator.clipboard.readText()), `git clone https://git.pyrossh.dev/${repoId}`);
442
+ assert.notEqual(await copyPage.locator(".copy-btn").getAttribute("data-copied"), null);
443
+ } finally {
444
+ await context.close();
445
+ }
446
+ });
447
+
448
+ test("shows a failure when the clipboard rejects", async () => {
449
+ await goto(`/repos/${repoId}/`);
450
+ await page.evaluate(() => {
451
+ navigator.clipboard.writeText = () => Promise.reject(new Error("denied"));
452
+ });
453
+ await page.getByRole("button", { name: "Copy clone command" }).click();
454
+ await assert.doesNotReject(page.getByRole("status").filter({ hasText: "Copy failed" }).waitFor());
455
+ assert.notEqual(await page.locator(".copy-btn").getAttribute("data-failed"), null);
456
+ });
457
+ });