Skip to content

Commit

Permalink
a bit more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Dec 12, 2024
1 parent daf843e commit 043a35e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@vtbag/cam-shaft": "^1.0.1",
"@vtbag/element-crossing": "^1.0.3",
"@vtbag/inspection-chamber": "^1.0.18",
"@vtbag/turn-signal": "^1.2.0",
"@vtbag/utensil-drawer": "^0.0.2",
"@vtbag/turn-signal": "^1.2.2",
"@vtbag/utensil-drawer": "^0.0.3",
"astro": "^4.16.17",
"astro-d2": "^0.6.0",
"astro-vtbot": "^1.10.7",
Expand Down
2 changes: 1 addition & 1 deletion src/components/TestPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
addEventListener("pagereveal", (e) => {
const d = {};
d.viewTransition = e?.viewTransition;
d.activation = activation("navigation" in window ? window.navigation?.activation : undefined);
d.activation = activation(window.navigation?.activation);
sessionStorage.setItem("vtbag-pagereveal", JSON.stringify(d));
});

Expand Down
3 changes: 2 additions & 1 deletion src/components/ToolsBar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<portal-gate to="end:head">
<script is:inline>
const mark = (entry) => {
if (!entry) return null;
const elem = document.querySelector(
`#toolsbar > div:has(a[href="${
new URL(entry.url).pathname
Expand All @@ -42,7 +43,7 @@
});
addEventListener("pagereveal", (e) => {
if (e.viewTransition) {
const elem = mark(navigation.activation.from);
const elem = mark(window.navigation?.activation.from);
e.viewTransition.finished.then(() =>
elem?.style.removeProperty("view-transition-name")
);
Expand Down
8 changes: 5 additions & 3 deletions src/components/vtbag-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ export function addBar(first:number) {
const storedWidth = () => ~~sessionStorage.getItem("vtbag-bar")!;

// @ts-expect-error
navigation.addEventListener("navigate", (e) => {
(window.navigation as EventTarget)?.addEventListener("navigate", (event) => {
// @ts-expect-error
const e = event as NavigateEvent;
console.log("event:", "navigate", e);

const back =
e.navigationType === "traverse" &&
// @ts-expect-error
e.destination.index < navigation.currentEntry.index;
e.destination.index < window.navigation?.currentEntry.index;

if (
!e.downloadRequest &&
e.userInitiated &&
(!e.destination.sameDocument ||
(!back && !e.hashChange) ||
// @ts-expect-error
(back && !new URL(navigation.currentEntry.url).hash))
(back && !new URL(window.navigation?.currentEntry.url).hash))
) {
document.documentElement.classList.add("vtbag-bar-loading", "vtbag-bar-old");
width = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/basics/hide-and-seek/problem.astro
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import Bsky from "../../../components/Bsky.astro";
addEventListener("pagereveal", (event) => {
if (event.viewTransition) {
if (
new URL(navigation.activation.from.url, location.href).pathname !==
new URL(window.navigation?.activation.from.url, location.href).pathname !==
"/basics/hide-and-seek/problem/"
) {
event.viewTransition.skipTransition?.();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/forge/loading-gear/_Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { title } = Astro.props;
}
});
// @ts-expect-error
window.navigation.addEventListener("navigate", (e) => {
window.navigation?.addEventListener("navigate", (e) => {
console.log(new Date().getTime(), "navigate");
});
addEventListener("DOMContentLoaded", (_e) => {
Expand Down

0 comments on commit 043a35e

Please sign in to comment.