mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 10:54:06 -06:00
feat: add configuration option for enabling browser-native view transitions
This commit is contained in:
parent
82abc95d36
commit
de33ab6dda
@ -11,6 +11,7 @@ const config: QuartzConfig = {
|
||||
pageTitle: "Quartz 4",
|
||||
pageTitleSuffix: "",
|
||||
enableSPA: true,
|
||||
enableViewTransitions: true,
|
||||
enablePopovers: true,
|
||||
analytics: {
|
||||
provider: "plausible",
|
||||
|
||||
@ -56,6 +56,12 @@ export interface GlobalConfiguration {
|
||||
pageTitleSuffix?: string
|
||||
/** Whether to enable single-page-app style rendering. this prevents flashes of unstyled content and improves smoothness of Quartz */
|
||||
enableSPA: boolean
|
||||
/**
|
||||
* `enableSPA: true` required; Whether to enable browser-native view transitions for single-page-app style rendering.
|
||||
*
|
||||
* Customizing your animations: https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API/Using#customizing_your_animations.
|
||||
*/
|
||||
enableViewTransitions: boolean
|
||||
/** Whether to display Wikipedia-style popovers when hovering over links */
|
||||
enablePopovers: boolean
|
||||
/** Analytics mode */
|
||||
|
||||
@ -235,7 +235,7 @@ export function renderPage(
|
||||
const doc = (
|
||||
<html lang={lang} dir={direction}>
|
||||
<Head {...componentData} />
|
||||
<body data-slug={slug}>
|
||||
<body data-slug={slug} data-view-transitions={cfg.enableViewTransitions}>
|
||||
<div id="quartz-root" class="page">
|
||||
<Body {...componentData}>
|
||||
{LeftComponent}
|
||||
|
||||
@ -128,9 +128,8 @@ async function _navigate(url: URL, isBack: boolean = false) {
|
||||
}
|
||||
|
||||
notifyNav(getFullSlug(window))
|
||||
})
|
||||
|
||||
delete announcer.dataset.persist
|
||||
})
|
||||
}
|
||||
|
||||
async function navigate(url: URL, isBack: boolean = false) {
|
||||
|
||||
@ -46,10 +46,15 @@ export async function fetchCanonical(url: URL): Promise<Response> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Wraps a DOM update in a View Transition if supported by the browser and enabled in config.
|
||||
* Falls back to immediate execution if the API is unavailable or disabled.
|
||||
*/
|
||||
export function startViewTransition(callback: () => void): void {
|
||||
document.startViewTransition?.(() => callback()) ?? callback()
|
||||
const enableViewTransitions = document.body.dataset.viewTransitions === "true"
|
||||
|
||||
if (enableViewTransitions && document.startViewTransition) {
|
||||
document.startViewTransition(() => callback())
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
.backlinks {
|
||||
flex-direction: column;
|
||||
view-transition-name: backlinks;
|
||||
|
||||
& > h3 {
|
||||
font-size: 1rem;
|
||||
|
||||
3
quartz/components/styles/comments.scss
Normal file
3
quartz/components/styles/comments.scss
Normal file
@ -0,0 +1,3 @@
|
||||
.giscus {
|
||||
view-transition-name: giscus;
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
margin: 0;
|
||||
text-align: inherit;
|
||||
flex-shrink: 0;
|
||||
view-transition-name: darkmode;
|
||||
|
||||
& svg {
|
||||
position: absolute;
|
||||
|
||||
@ -30,9 +30,10 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: hidden;
|
||||
|
||||
min-height: 1.2rem;
|
||||
flex: 0 1 auto;
|
||||
view-transition-name: explorer;
|
||||
|
||||
&.collapsed {
|
||||
flex: 0 1 1.2rem;
|
||||
& .fold {
|
||||
|
||||
@ -2,6 +2,7 @@ footer {
|
||||
text-align: left;
|
||||
margin-bottom: 4rem;
|
||||
opacity: 0.7;
|
||||
view-transition-name: footer;
|
||||
|
||||
& ul {
|
||||
list-style: none;
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
@use "../../styles/variables.scss" as *;
|
||||
|
||||
.graph {
|
||||
view-transition-name: graph;
|
||||
|
||||
& > h3 {
|
||||
font-size: 1rem;
|
||||
margin: 0;
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
margin: 0;
|
||||
text-align: inherit;
|
||||
flex-shrink: 0;
|
||||
view-transition-name: readermode;
|
||||
|
||||
& svg {
|
||||
position: absolute;
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
.recent-notes {
|
||||
view-transition-name: recent-notes;
|
||||
|
||||
& > h3 {
|
||||
margin: 0.5rem 0 0 0;
|
||||
font-size: 1rem;
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
overflow-y: hidden;
|
||||
min-height: 1.4rem;
|
||||
flex: 0 0.5 auto;
|
||||
view-transition-name: toc;
|
||||
|
||||
&:has(button.toc-header.collapsed) {
|
||||
flex: 0 1 1.4rem;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user