diff --git a/docs/src/app.css b/docs/src/app.css index c23981ccd..738de355a 100644 --- a/docs/src/app.css +++ b/docs/src/app.css @@ -172,3 +172,11 @@ code[data-line-numbers] > [data-line]::before { .ToggleGroup { user-select: none; } + +/* Disable view transitions for reduced motion */ +@media (prefers-reduced-motion: reduce) { + ::view-transition-old(root), + ::view-transition-new(root) { + animation: none; + } +} diff --git a/docs/src/lib/components/Code.svelte b/docs/src/lib/components/Code.svelte index 98af9c8d9..fbf2b5d03 100644 --- a/docs/src/lib/components/Code.svelte +++ b/docs/src/lib/components/Code.svelte @@ -1,10 +1,14 @@ @@ -81,24 +85,24 @@ {#if source}
 				
-					{#await highlighter}
-						
Loading...
- {:then h} + {#if highlighter} - {@html h.codeToHtml(sourceStr, { - lang: language, - themes: { - light: 'github-light-default', - dark: 'github-dark-default' - }, - meta: highlight ? { __raw: `{${highlight}}` } : undefined, - transformers: highlight ? [transformerMetaHighlight()] : undefined - })} - {:catch error} -
Error loading code highlighting: {error.message}
- {/await} - -
+ {@html highlighter.codeToHtml( + sourceStr, + { + lang: language, + themes: { + light: 'github-light-default', + dark: 'github-dark-default' + }, + meta: highlight ? { __raw: `{${highlight}}` } : undefined, + transformers: highlight ? [transformerMetaHighlight()] : undefined + } + )} + {:else} +
Loading...
+ {/if} +
{#if copyButton !== false} diff --git a/docs/src/lib/components/Example.svelte b/docs/src/lib/components/Example.svelte index 14d42920a..35bcdbc74 100644 --- a/docs/src/lib/components/Example.svelte +++ b/docs/src/lib/components/Example.svelte @@ -98,6 +98,15 @@ let ref = $state(null); let data = $derived(ref?.data); + // Ensure component name is always resolved consistently + const resolvedComponent = $derived(component ?? page.params.name ?? ''); + // Only set view-transition-name on detail pages (when page.params.example matches) + // This prevents conflicts with ExampleScreenshot on listing pages + const isDetailPage = $derived(page.params.example === name); + const viewTransitionName = $derived( + isDetailPage && resolvedComponent && name ? `lc-${resolvedComponent}-${name}` : undefined + ); + let canResize = $derived.by(() => { // Prop if (typeof noResize === 'boolean') { @@ -134,6 +143,7 @@ )} bind:this={containerEl} style:width={containerWidth ? `${containerWidth}px` : undefined} + style:view-transition-name={viewTransitionName} > diff --git a/docs/src/lib/components/ExampleScreenshot.svelte b/docs/src/lib/components/ExampleScreenshot.svelte index eb968ed93..235f5630c 100644 --- a/docs/src/lib/components/ExampleScreenshot.svelte +++ b/docs/src/lib/components/ExampleScreenshot.svelte @@ -16,10 +16,15 @@ } = $props(); const basePath = $derived(`/screenshots/${component}/${example}`); + const viewTransitionName = $derived(`lc-${component}-${example}`); const sizes = [ { width: '240w', light: '@sm:hidden dark:hidden', dark: 'dark:block dark:@sm:hidden' }, - { width: '400w', light: '@sm:block @lg:hidden dark:hidden', dark: 'dark:@sm:block dark:@lg:hidden' }, + { + width: '400w', + light: '@sm:block @lg:hidden dark:hidden', + dark: 'dark:@sm:block dark:@lg:hidden' + }, { width: '800w', light: '@lg:block dark:hidden', dark: 'dark:@lg:block' } ]; @@ -33,6 +38,7 @@ aspect === 'screenshot' && 'aspect-8/3', // roughly 800x300 for many cartesian background && 'bg-surface-100 dark:bg-surface-200' )} + style:view-transition-name={viewTransitionName} > {#each ['light', 'dark'] as mode} {#each sizes as size} diff --git a/docs/src/lib/markdown/config/pretty-code.js b/docs/src/lib/markdown/config/pretty-code.js index 11795de20..df2e8c9d5 100644 --- a/docs/src/lib/markdown/config/pretty-code.js +++ b/docs/src/lib/markdown/config/pretty-code.js @@ -6,8 +6,8 @@ import { shikiDiffTransformer } from '../transformers/shiki-diff.js'; */ export const prettyCodeOptions = { theme: { - light: 'github-light', - dark: 'github-dark' + light: 'github-light-default', + dark: 'github-dark-default' }, keepBackground: false, defaultLang: { diff --git a/docs/src/lib/page-transitions.ts b/docs/src/lib/page-transitions.ts new file mode 100644 index 000000000..60f5f163f --- /dev/null +++ b/docs/src/lib/page-transitions.ts @@ -0,0 +1,16 @@ +import { onNavigate } from '$app/navigation'; + +export const preparePageTransition = () => { + onNavigate((navigation) => { + if (!document.startViewTransition) { + return; + } + + return new Promise((resolve) => { + document.startViewTransition(async () => { + resolve(); + await navigation.complete; + }); + }); + }); +}; diff --git a/docs/src/routes/+layout.svelte b/docs/src/routes/+layout.svelte index 03633a5fe..eeb2880ac 100644 --- a/docs/src/routes/+layout.svelte +++ b/docs/src/routes/+layout.svelte @@ -6,6 +6,7 @@ import { dev } from '$app/environment'; import { page } from '$app/state'; + import { preparePageTransition } from '$lib/page-transitions'; import '@fontsource-variable/inter'; import '../app.css'; @@ -51,6 +52,9 @@ }; } }); + + // View transition for navigation + preparePageTransition(); {@render children()} diff --git a/packages/layerchart/src/lib/docs/Code.svelte b/packages/layerchart/src/lib/docs/Code.svelte index 5651de976..eed427e13 100644 --- a/packages/layerchart/src/lib/docs/Code.svelte +++ b/packages/layerchart/src/lib/docs/Code.svelte @@ -1,9 +1,13 @@ @@ -37,20 +41,17 @@ {#if source}
       
-        {#await highlighter}
-          
Loading...
- {:then h} - {@html h.codeToHtml(source, { + {#if highlighter} + {@html highlighter.codeToHtml(source, { lang: language, themes: { light: 'github-light-default', dark: 'github-dark-default', }, })} - {:catch error} -
Error loading code highlighting: {error.message}
- {/await} - + {:else} +
Loading...
+ {/if}