mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 19:04:06 -06:00
feat: implement view transition functionality
This commit is contained in:
parent
52460f376f
commit
82abc95d36
@ -1,6 +1,6 @@
|
|||||||
import micromorph from "micromorph"
|
import micromorph from "micromorph"
|
||||||
import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path"
|
import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path"
|
||||||
import { fetchCanonical } from "./util"
|
import { fetchCanonical, startViewTransition } from "./util"
|
||||||
|
|
||||||
// adapted from `micromorph`
|
// adapted from `micromorph`
|
||||||
// https://github.com/natemoo-re/micromorph
|
// https://github.com/natemoo-re/micromorph
|
||||||
@ -102,6 +102,7 @@ async function _navigate(url: URL, isBack: boolean = false) {
|
|||||||
html.body.appendChild(announcer)
|
html.body.appendChild(announcer)
|
||||||
|
|
||||||
// morph body
|
// morph body
|
||||||
|
startViewTransition(() => {
|
||||||
micromorph(document.body, html.body)
|
micromorph(document.body, html.body)
|
||||||
|
|
||||||
// scroll into place and add history
|
// scroll into place and add history
|
||||||
@ -127,6 +128,8 @@ async function _navigate(url: URL, isBack: boolean = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifyNav(getFullSlug(window))
|
notifyNav(getFullSlug(window))
|
||||||
|
})
|
||||||
|
|
||||||
delete announcer.dataset.persist
|
delete announcer.dataset.persist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,3 +44,12 @@ export async function fetchCanonical(url: URL): Promise<Response> {
|
|||||||
const [_, redirect] = text.match(canonicalRegex) ?? []
|
const [_, redirect] = text.match(canonicalRegex) ?? []
|
||||||
return redirect ? fetch(`${new URL(redirect, url)}`) : res
|
return redirect ? fetch(`${new URL(redirect, url)}`) : res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a DOM update in a View Transition if supported by the browser.
|
||||||
|
* Falls back to immediate execution if the API is unavailable.
|
||||||
|
* @param callback - The function containing DOM updates to animate
|
||||||
|
*/
|
||||||
|
export function startViewTransition(callback: () => void): void {
|
||||||
|
document.startViewTransition?.(() => callback()) ?? callback()
|
||||||
|
}
|
||||||
|
|||||||
@ -4,6 +4,10 @@
|
|||||||
@use "./syntax.scss";
|
@use "./syntax.scss";
|
||||||
@use "./callouts.scss";
|
@use "./callouts.scss";
|
||||||
|
|
||||||
|
::view-transition {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
text-size-adjust: none;
|
text-size-adjust: none;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user