-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
13 changed files
with
335 additions
and
29 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
export interface Props { | ||
href: string; | ||
} | ||
const {href} = Astro.props; | ||
--- | ||
|
||
{href && (<a href={"javascript:top.sessionStorage.setItem('vtbag-ui-standby','true'),top.location.assign('" + href + "')"}><slot/></a>)} | ||
|
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#vtbag-bar-outer { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 8px; | ||
background-color: var(--sl-color-black); | ||
z-index: 1000; | ||
view-transition-name: vtbag-bar-outer; | ||
} | ||
#vtbag-bar { | ||
background-color: var(--sl-color-accent); | ||
height: 100%; | ||
} | ||
:root.vtbag-bar-old #vtbag-bar-inner { | ||
height: 100%; | ||
width: 25%; | ||
background-color: var(--sl-color-white); | ||
animation: slide 0.5s ease-in-out alternate infinite; | ||
} | ||
|
||
:root.vtbag-bar-old :is(#vtbag-bar, #vtbag-bar-inner) { | ||
border-radius: 3pt; | ||
transition: opacity 0.25s 0.25s; | ||
|
||
@starting-style { | ||
opacity: 0; | ||
} | ||
|
||
} | ||
@keyframes slide { | ||
0% { | ||
transform: translateX(30%); | ||
} | ||
100% { | ||
transform: translateX(75%); | ||
} | ||
} | ||
|
||
:root.vtbag-bar-freeze #vtbag-bar { | ||
background-color: red; | ||
} | ||
:root.vtbag-bar-new #vtbag-bar { | ||
background-color: var(--sl-color-white); | ||
} | ||
|
||
::view-transition-old(vtbag-bar-outer), | ||
::view-transition-new(vtbag-bar-outer) { | ||
animation: none; | ||
} | ||
|
||
:active-view-transition, | ||
:root.vtbag-bar-loading *, | ||
:root.vtbag-bar-loading { | ||
cursor: pointer !important; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,126 @@ | ||
document.documentElement.classList.add("vtbag-bar-loading", "vtbag-bar-new"); | ||
|
||
let timeout:any; | ||
let width = -1; | ||
export function addBar(first:number) { | ||
document.querySelector("#vtbag-bar-outer")?.remove(); | ||
console.log("adding"); | ||
document.body.insertAdjacentHTML( | ||
"afterbegin", | ||
`<div id="vtbag-bar-outer"><div id="vtbag-bar"><div id="vtbag-bar-inner"/></div></div>` | ||
); | ||
const timing = [ | ||
10, 20, 30, 40, 50, 100, 90, 80, 70, 60, 50, 40, 20, 25, 30, 35, 40, 45, | ||
50, 55, 60, 65, 70, 75, 70, 65, 60, 55, 50, 45, 400, 35, 30, 25, 20, 20, | ||
20, 20, 20, 20, 200, 20, 20, 20, 20, 400, 20, 20, 20, 20, 200, 20, 20, 20, | ||
20, 30, 40, 50, 600, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, | ||
180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, | ||
330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, | ||
]; | ||
timing[-1] = first; | ||
let step = -1; | ||
const f = () => { | ||
width += 1; | ||
console.log("width:", width); | ||
const bar = document.getElementById("vtbag-bar"); | ||
if (bar) { | ||
bar.style.width = `${width}%`; | ||
if (timing[step] !== undefined) { | ||
console.log("waiting for", timing[step], "ms"); | ||
clearTimeout(timeout); | ||
timeout = setTimeout(f, timing[step++]); | ||
} | ||
sessionStorage.setItem("vtbag-bar", ""+width); | ||
} | ||
}; | ||
//f(); | ||
return document.getElementById("vtbag-bar"); | ||
} | ||
|
||
const storedWidth = () => ~~sessionStorage.getItem("vtbag-bar")!; | ||
|
||
// @ts-expect-error | ||
navigation.addEventListener("navigate", (e) => { | ||
console.log("event:", "navigate", e); | ||
|
||
const back = | ||
e.navigationType === "traverse" && | ||
// @ts-expect-error | ||
e.destination.index < navigation.currentEntry.index; | ||
|
||
if ( | ||
!e.downloadRequest && | ||
e.userInitiated && | ||
(!e.destination.sameDocument || | ||
(!back && !e.hashChange) || | ||
// @ts-expect-error | ||
(back && !new URL(navigation.currentEntry.url).hash)) | ||
) { | ||
document.documentElement.classList.add("vtbag-bar-loading", "vtbag-bar-old"); | ||
width = -1; | ||
addBar(0); | ||
} | ||
}); | ||
|
||
addEventListener("DOMContentLoaded", (_e) => | ||
stop("DOMContentloaded", storedWidth() !== 0) | ||
); | ||
|
||
function stop(where: string, extend: boolean) { | ||
console.log("stop", where, extend); | ||
clearTimeout(timeout); | ||
const bar = document.getElementById("vtbag-bar"); | ||
if (bar) { | ||
if (extend) { | ||
bar.style.width = "100%"; | ||
setTimeout(() => { | ||
document.documentElement.classList.remove( | ||
"vtbag-bar-loading", | ||
"vtbag-bar-freeze", | ||
"vtbag-bar-old", | ||
"vtbag-bar-new" | ||
); | ||
bar.parentElement?.remove(); | ||
}, 200); | ||
return; | ||
} | ||
bar.parentElement?.remove(); | ||
} | ||
document.documentElement.classList.remove( | ||
"vtbag-bar-loading", | ||
"vtbag-bar-freeze", | ||
"vtbag-bar-old", | ||
"vtbag-bar-new" | ||
); | ||
} | ||
|
||
["pageswap", "pagereveal"].forEach((event) => | ||
addEventListener(event, (e) => { | ||
// @ts-expect-errork | ||
console.log("event:", event, e.viewTransition); | ||
// @ts-expect-error | ||
if (e.viewTransition) { | ||
let bar = document.getElementById("vtbag-bar"); | ||
width = storedWidth(); | ||
console.log("width :>> ", width); | ||
if (bar) { | ||
// pageswap | ||
if (width < 1) { | ||
stop("pageswap", false); | ||
return; | ||
} | ||
document.documentElement.classList?.add("vtbag-bar-freeze"); | ||
width+=30; | ||
addBar(0); | ||
} else { | ||
// pagereveal | ||
if (width < 1) return; | ||
bar = addBar(0); | ||
// @ts-expect-error | ||
e.viewTransition.ready.then(() => stop("ready", true)); | ||
} | ||
} else { | ||
stop("no viewTransition", 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
Oops, something went wrong.