mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
feat(web): hero view transitions between timeline and asset viewer
Change-Id: I19e0c7385cc38adbc85177ae9706cff06a6a6964 fix(web): fix e2e test failures for view transitions Change-Id: Ida64f2d509efce0a85a50b89fd4137276a6a6964 Change-Id: I19e0c7385cc38adbc85177ae9706cff06a6a6964
This commit is contained in:
@@ -143,8 +143,9 @@ export const timelineUtils = {
|
|||||||
return page.locator('#asset-grid');
|
return page.locator('#asset-grid');
|
||||||
},
|
},
|
||||||
async waitForTimelineLoad(page: Page) {
|
async waitForTimelineLoad(page: Page) {
|
||||||
await expect(timelineUtils.locator(page)).toBeInViewport();
|
await page.locator('#asset-grid[data-initialized]').waitFor();
|
||||||
await expect.poll(() => thumbnailUtils.locator(page).count()).toBeGreaterThan(0);
|
await expect.poll(() => thumbnailUtils.locator(page).count()).toBeGreaterThan(0);
|
||||||
|
await page.locator('#virtual-timeline:not(.invisible)').waitFor();
|
||||||
},
|
},
|
||||||
async getScrollTop(page: Page) {
|
async getScrollTop(page: Page) {
|
||||||
const queryTop = () =>
|
const queryTop = () =>
|
||||||
@@ -163,14 +164,17 @@ export const assetViewerUtils = {
|
|||||||
return page.locator('#immich-asset-viewer');
|
return page.locator('#immich-asset-viewer');
|
||||||
},
|
},
|
||||||
async waitForViewerLoad(page: Page, asset: TimelineAssetConfig) {
|
async waitForViewerLoad(page: Page, asset: TimelineAssetConfig) {
|
||||||
await page
|
const imgLocator = page.locator(`[data-viewer-content] img[data-testid="preview"][src*="${asset.id}"]`);
|
||||||
.locator(
|
const videoLocator = page.locator(`[data-viewer-content] video[poster*="${asset.id}"]`);
|
||||||
`img[draggable="false"][src="/api/assets/${asset.id}/thumbnail?size=preview&c=${asset.thumbhash}&edited=true"]`,
|
await imgLocator.or(videoLocator).waitFor();
|
||||||
)
|
|
||||||
.or(
|
if ((await videoLocator.count()) === 0) {
|
||||||
page.locator(`video[poster="/api/assets/${asset.id}/thumbnail?size=preview&c=${asset.thumbhash}&edited=true"]`),
|
await expect
|
||||||
)
|
.poll(() => imgLocator.evaluate((img: HTMLImageElement) => img.complete && img.naturalWidth > 0))
|
||||||
.waitFor();
|
.toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
await expect(page.locator('#immich-asset-viewer')).not.toHaveAttribute('data-navigating');
|
||||||
},
|
},
|
||||||
async expectActiveAssetToBe(page: Page, assetId: string) {
|
async expectActiveAssetToBe(page: Page, assetId: string) {
|
||||||
const activeElement = () =>
|
const activeElement = () =>
|
||||||
|
|||||||
Generated
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "immich-monorepo",
|
||||||
|
"version": "2.7.5",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "immich-monorepo",
|
||||||
|
"version": "2.7.5",
|
||||||
|
"engines": {
|
||||||
|
"pnpm": ">=10.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
+150
@@ -75,6 +75,11 @@
|
|||||||
--immich-dark-bg: 10 10 10;
|
--immich-dark-bg: 10 10 10;
|
||||||
--immich-dark-fg: 229 231 235;
|
--immich-dark-fg: 229 231 235;
|
||||||
--immich-dark-gray: 33 33 33;
|
--immich-dark-gray: 33 33 33;
|
||||||
|
|
||||||
|
/* view transition variables */
|
||||||
|
--vt-duration-default: 250ms;
|
||||||
|
--vt-duration-hero: 280ms;
|
||||||
|
--vt-memory-easing: cubic-bezier(0.2, 0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
button:not(:disabled),
|
button:not(:disabled),
|
||||||
@@ -175,3 +180,148 @@
|
|||||||
@apply bg-subtle rounded-lg;
|
@apply bg-subtle rounded-lg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
::view-transition {
|
||||||
|
background: var(--color-black);
|
||||||
|
animation-duration: var(--vt-duration-default);
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-old(*),
|
||||||
|
::view-transition-new(*) {
|
||||||
|
mix-blend-mode: normal;
|
||||||
|
animation-duration: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-old(*) {
|
||||||
|
animation-name: fadeOut;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
::view-transition-new(*) {
|
||||||
|
animation-name: fadeIn;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-old(root) {
|
||||||
|
animation: var(--vt-duration-default) 0s fadeOut forwards;
|
||||||
|
}
|
||||||
|
::view-transition-new(root) {
|
||||||
|
animation: var(--vt-duration-default) 0s fadeIn forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-image-pair(info) {
|
||||||
|
isolation: auto;
|
||||||
|
}
|
||||||
|
::view-transition-old(info) {
|
||||||
|
animation: var(--vt-duration-default) 0s panelSlideOutRight forwards;
|
||||||
|
}
|
||||||
|
::view-transition-new(info) {
|
||||||
|
animation: var(--vt-duration-default) 0s panelSlideInRight forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-group(exclude-previousbutton),
|
||||||
|
::view-transition-group(exclude-nextbutton),
|
||||||
|
::view-transition-group(exclude) {
|
||||||
|
animation: none;
|
||||||
|
z-index: 5;
|
||||||
|
}
|
||||||
|
::view-transition-old(exclude-previousbutton),
|
||||||
|
::view-transition-old(exclude-nextbutton),
|
||||||
|
::view-transition-old(exclude) {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
::view-transition-new(exclude-previousbutton),
|
||||||
|
::view-transition-new(exclude-nextbutton),
|
||||||
|
::view-transition-new(exclude) {
|
||||||
|
animation: none;
|
||||||
|
z-index: 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-group(hero) {
|
||||||
|
animation-duration: var(--vt-duration-hero);
|
||||||
|
animation-timing-function: var(--vt-memory-easing);
|
||||||
|
}
|
||||||
|
::view-transition-old(hero) {
|
||||||
|
animation: none;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
::view-transition-new(hero) {
|
||||||
|
animation: none;
|
||||||
|
align-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes panelSlideInRight {
|
||||||
|
from {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes panelSlideOutRight {
|
||||||
|
from {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes fadeOut {
|
||||||
|
from {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
::view-transition-group(hero) {
|
||||||
|
animation-name: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-old(hero) {
|
||||||
|
animation: none;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
::view-transition-new(hero) {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
html:active-view-transition-type(viewer) {
|
||||||
|
&::view-transition-old(hero) {
|
||||||
|
animation: none;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
&::view-transition-new(hero) {
|
||||||
|
animation: var(--vt-duration-default) 0s fadeIn forwards;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html:active-view-transition-type(timeline) {
|
||||||
|
&::view-transition-old(hero) {
|
||||||
|
animation: var(--vt-duration-default) 0s fadeOut forwards;
|
||||||
|
}
|
||||||
|
&::view-transition-new(hero) {
|
||||||
|
animation: var(--vt-duration-default) 0s fadeIn forwards;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
sharedLink?: SharedLinkResponseDto;
|
sharedLink?: SharedLinkResponseDto;
|
||||||
objectFit?: 'contain' | 'cover';
|
objectFit?: 'contain' | 'cover';
|
||||||
container: Size;
|
container: Size;
|
||||||
|
imageClass?: string;
|
||||||
|
transitionName?: string;
|
||||||
onUrlChange?: (url: string) => void;
|
onUrlChange?: (url: string) => void;
|
||||||
onImageReady?: () => void;
|
onImageReady?: () => void;
|
||||||
onError?: () => void;
|
onError?: () => void;
|
||||||
@@ -35,6 +37,8 @@
|
|||||||
sharedLink,
|
sharedLink,
|
||||||
objectFit = 'contain',
|
objectFit = 'contain',
|
||||||
container,
|
container,
|
||||||
|
imageClass,
|
||||||
|
transitionName,
|
||||||
onUrlChange,
|
onUrlChange,
|
||||||
onImageReady,
|
onImageReady,
|
||||||
onError,
|
onError,
|
||||||
@@ -152,11 +156,12 @@
|
|||||||
{@render backdrop?.()}
|
{@render backdrop?.()}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="absolute inset-0 pointer-events-none"
|
class={['absolute inset-0 pointer-events-none', imageClass]}
|
||||||
style:inset-inline-start={insetInlineStart}
|
style:inset-inline-start={insetInlineStart}
|
||||||
style:top
|
style:top
|
||||||
style:width
|
style:width
|
||||||
style:height
|
style:height
|
||||||
|
style:view-transition-name={transitionName ?? assetViewerManager.transitionName}
|
||||||
>
|
>
|
||||||
{#if show.alphaBackground}
|
{#if show.alphaBackground}
|
||||||
<AlphaBackground />
|
<AlphaBackground />
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
import { editManager, EditToolType } from '$lib/managers/edit/edit-manager.svelte';
|
import { editManager, EditToolType } from '$lib/managers/edit/edit-manager.svelte';
|
||||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
|
import { viewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte';
|
||||||
import { getAssetActions } from '$lib/services/asset.service';
|
import { getAssetActions } from '$lib/services/asset.service';
|
||||||
import { ocrManager } from '$lib/stores/ocr.svelte';
|
import { ocrManager } from '$lib/stores/ocr.svelte';
|
||||||
import { alwaysLoadOriginalVideo } from '$lib/stores/preferences.store';
|
import { alwaysLoadOriginalVideo } from '$lib/stores/preferences.store';
|
||||||
@@ -37,7 +38,7 @@
|
|||||||
import { onDestroy, onMount, untrack } from 'svelte';
|
import { onDestroy, onMount, untrack } from 'svelte';
|
||||||
import type { SwipeCustomEvent } from 'svelte-gestures';
|
import type { SwipeCustomEvent } from 'svelte-gestures';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import { fly } from 'svelte/transition';
|
import { slide } from 'svelte/transition';
|
||||||
import Thumbnail from '../assets/thumbnail/thumbnail.svelte';
|
import Thumbnail from '../assets/thumbnail/thumbnail.svelte';
|
||||||
import ActivityStatus from './activity-status.svelte';
|
import ActivityStatus from './activity-status.svelte';
|
||||||
import ActivityViewer from './activity-viewer.svelte';
|
import ActivityViewer from './activity-viewer.svelte';
|
||||||
@@ -146,8 +147,45 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let detailPanelTransitionName = $state<string | undefined>();
|
||||||
|
let navigationBarTransitionName = $state<string | undefined>();
|
||||||
|
let previousButtonTransitionName = $state<string | undefined>();
|
||||||
|
let nextButtonTransitionName = $state<string | undefined>();
|
||||||
|
|
||||||
|
const activateViewTransitionNames = () => {
|
||||||
|
detailPanelTransitionName = 'info';
|
||||||
|
assetViewerManager.transitionName = 'hero';
|
||||||
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
syncAssetViewerOpenClass(true);
|
syncAssetViewerOpenClass(true);
|
||||||
|
|
||||||
|
const unsubAssetViewerEvents = assetViewerManager.on({
|
||||||
|
ViewerOpenTransition: activateViewTransitionNames,
|
||||||
|
ViewerCloseTransition: activateViewTransitionNames,
|
||||||
|
});
|
||||||
|
const unsubViewTransitionEvents = viewTransitionManager.on({
|
||||||
|
PrepareOldSnapshot: (types) => {
|
||||||
|
if (types.includes('timeline')) {
|
||||||
|
navigationBarTransitionName = 'exclude';
|
||||||
|
previousButtonTransitionName = 'exclude-previousbutton';
|
||||||
|
nextButtonTransitionName = 'exclude-nextbutton';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PrepareNewSnapshot: (types) => {
|
||||||
|
const isViewer = types.includes('viewer');
|
||||||
|
navigationBarTransitionName = isViewer ? 'exclude' : undefined;
|
||||||
|
previousButtonTransitionName = isViewer ? 'exclude-previousbutton' : undefined;
|
||||||
|
nextButtonTransitionName = isViewer ? 'exclude-nextbutton' : undefined;
|
||||||
|
},
|
||||||
|
Finished: () => {
|
||||||
|
navigationBarTransitionName = undefined;
|
||||||
|
previousButtonTransitionName = undefined;
|
||||||
|
nextButtonTransitionName = undefined;
|
||||||
|
assetViewerManager.transitionName = undefined;
|
||||||
|
detailPanelTransitionName = undefined;
|
||||||
|
},
|
||||||
|
});
|
||||||
const slideshowStateUnsubscribe = slideshowState.subscribe((value) => {
|
const slideshowStateUnsubscribe = slideshowState.subscribe((value) => {
|
||||||
if (value === SlideshowState.PlaySlideshow) {
|
if (value === SlideshowState.PlaySlideshow) {
|
||||||
slideshowHistory.reset();
|
slideshowHistory.reset();
|
||||||
@@ -157,7 +195,6 @@
|
|||||||
handlePromiseError(handleStopSlideshow());
|
handlePromiseError(handleStopSlideshow());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const slideshowNavigationUnsubscribe = slideshowNavigation.subscribe((value) => {
|
const slideshowNavigationUnsubscribe = slideshowNavigation.subscribe((value) => {
|
||||||
if (value === SlideshowNavigation.Shuffle) {
|
if (value === SlideshowNavigation.Shuffle) {
|
||||||
slideshowHistory.reset();
|
slideshowHistory.reset();
|
||||||
@@ -166,6 +203,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
unsubAssetViewerEvents();
|
||||||
|
unsubViewTransitionEvents();
|
||||||
slideshowStateUnsubscribe();
|
slideshowStateUnsubscribe();
|
||||||
slideshowNavigationUnsubscribe();
|
slideshowNavigationUnsubscribe();
|
||||||
};
|
};
|
||||||
@@ -192,6 +231,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const tracker = new InvocationTracker();
|
const tracker = new InvocationTracker();
|
||||||
|
let navigating = $state(false);
|
||||||
const navigateAsset = (order?: 'previous' | 'next') => {
|
const navigateAsset = (order?: 'previous' | 'next') => {
|
||||||
if (!order) {
|
if (!order) {
|
||||||
if ($slideshowState === SlideshowState.PlaySlideshow) {
|
if ($slideshowState === SlideshowState.PlaySlideshow) {
|
||||||
@@ -207,7 +247,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tracker.invoke(async () => {
|
navigating = true;
|
||||||
|
const navigation = tracker.invoke(async () => {
|
||||||
const isShuffle =
|
const isShuffle =
|
||||||
$slideshowState === SlideshowState.PlaySlideshow && $slideshowNavigation === SlideshowNavigation.Shuffle;
|
$slideshowState === SlideshowState.PlaySlideshow && $slideshowNavigation === SlideshowNavigation.Shuffle;
|
||||||
|
|
||||||
@@ -244,6 +285,7 @@
|
|||||||
|
|
||||||
await handleStopSlideshow();
|
await handleStopSlideshow();
|
||||||
}, $t('error_while_navigating'));
|
}, $t('error_while_navigating'));
|
||||||
|
void navigation.finally(() => (navigating = false));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -457,13 +499,17 @@
|
|||||||
|
|
||||||
<section
|
<section
|
||||||
id="immich-asset-viewer"
|
id="immich-asset-viewer"
|
||||||
class="fixed start-0 top-0 grid size-full grid-cols-4 grid-rows-[64px_1fr] overflow-hidden bg-black"
|
class="fixed inset-s-0 top-0 z-10 grid size-full grid-cols-4 grid-rows-[64px_1fr] overflow-hidden bg-black"
|
||||||
|
data-navigating={navigating || undefined}
|
||||||
use:focusTrap
|
use:focusTrap
|
||||||
bind:this={assetViewerHtmlElement}
|
bind:this={assetViewerHtmlElement}
|
||||||
>
|
>
|
||||||
<!-- Top navigation bar -->
|
<!-- Top navigation bar -->
|
||||||
{#if $slideshowState === SlideshowState.None && !assetViewerManager.isShowEditor}
|
{#if $slideshowState === SlideshowState.None && !assetViewerManager.isShowEditor}
|
||||||
<div class="col-span-4 col-start-1 row-span-1 row-start-1 transition-transform">
|
<div
|
||||||
|
class="col-span-4 col-start-1 row-span-1 row-start-1 transition-transform"
|
||||||
|
style:view-transition-name={navigationBarTransitionName}
|
||||||
|
>
|
||||||
<AssetViewerNavBar
|
<AssetViewerNavBar
|
||||||
{asset}
|
{asset}
|
||||||
{album}
|
{album}
|
||||||
@@ -496,7 +542,11 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $slideshowState === SlideshowState.None && showNavigation && !assetViewerManager.isShowEditor && !assetViewerManager.isFaceEditMode && previousAsset}
|
{#if $slideshowState === SlideshowState.None && showNavigation && !assetViewerManager.isShowEditor && !assetViewerManager.isFaceEditMode && previousAsset}
|
||||||
<div class="my-auto col-span-1 col-start-1 row-span-full row-start-1 justify-self-start">
|
<div
|
||||||
|
data-test-id="previous-asset"
|
||||||
|
class="my-auto col-span-1 col-start-1 row-span-full row-start-1 justify-self-start"
|
||||||
|
style:view-transition-name={previousButtonTransitionName}
|
||||||
|
>
|
||||||
<PreviousAssetAction onPreviousAsset={() => navigateAsset('previous')} />
|
<PreviousAssetAction onPreviousAsset={() => navigateAsset('previous')} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -569,15 +619,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if $slideshowState === SlideshowState.None && showNavigation && !assetViewerManager.isShowEditor && !assetViewerManager.isFaceEditMode && nextAsset}
|
{#if $slideshowState === SlideshowState.None && showNavigation && !assetViewerManager.isShowEditor && !assetViewerManager.isFaceEditMode && nextAsset}
|
||||||
<div class="my-auto col-span-1 col-start-4 row-span-full row-start-1 justify-self-end">
|
<div
|
||||||
|
data-test-id="next-asset"
|
||||||
|
class="my-auto col-span-1 col-start-4 row-span-full row-start-1 justify-self-end"
|
||||||
|
style:view-transition-name={nextButtonTransitionName}
|
||||||
|
>
|
||||||
<NextAssetAction onNextAsset={() => navigateAsset('next')} />
|
<NextAssetAction onNextAsset={() => navigateAsset('next')} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if showDetailPanel || assetViewerManager.isShowEditor}
|
{#if showDetailPanel || assetViewerManager.isShowEditor}
|
||||||
<div
|
<div
|
||||||
transition:fly={{ duration: 150 }}
|
transition:slide={{ axis: 'x', duration: 150 }}
|
||||||
id="detail-panel"
|
id="detail-panel"
|
||||||
|
style:view-transition-name={detailPanelTransitionName}
|
||||||
class={[
|
class={[
|
||||||
'row-start-1 row-span-4 overflow-y-auto transition-all dark:border-l dark:border-s-immich-dark-gray bg-light',
|
'row-start-1 row-span-4 overflow-y-auto transition-all dark:border-l dark:border-s-immich-dark-gray bg-light',
|
||||||
showDetailPanel ? 'w-90' : 'w-100',
|
showDetailPanel ? 'w-90' : 'w-100',
|
||||||
@@ -630,7 +685,7 @@
|
|||||||
|
|
||||||
{#if isShared && album && assetViewerManager.isShowActivityPanel && authManager.authenticated}
|
{#if isShared && album && assetViewerManager.isShowActivityPanel && authManager.authenticated}
|
||||||
<div
|
<div
|
||||||
transition:fly={{ duration: 150 }}
|
transition:slide={{ axis: 'x', duration: 150 }}
|
||||||
id="activity-panel"
|
id="activity-panel"
|
||||||
class="row-start-1 row-span-5 w-90 md:w-115 overflow-y-auto transition-all dark:border-l dark:border-s-immich-dark-gray"
|
class="row-start-1 row-span-5 w-90 md:w-115 overflow-y-auto transition-all dark:border-l dark:border-s-immich-dark-gray"
|
||||||
translate="yes"
|
translate="yes"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { Icon } from '@immich/ui';
|
import { Icon } from '@immich/ui';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
asset: AssetResponseDto;
|
asset: AssetResponseDto;
|
||||||
@@ -74,6 +75,8 @@
|
|||||||
alt={$getAltText(toTimelineAsset(asset))}
|
alt={$getAltText(toTimelineAsset(asset))}
|
||||||
class="h-full select-none transition-transform motion-reduce:transition-none"
|
class="h-full select-none transition-transform motion-reduce:transition-none"
|
||||||
style:transform={imageTransform}
|
style:transform={imageTransform}
|
||||||
|
onload={() => assetViewerManager.emit('ViewerOpenTransitionReady')}
|
||||||
|
onerror={() => assetViewerManager.emit('ViewerOpenTransitionReady')}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class={[
|
class={[
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
import { AssetMediaSize, viewAsset, type AssetResponseDto } from '@immich/sdk';
|
import { AssetMediaSize, viewAsset, type AssetResponseDto } from '@immich/sdk';
|
||||||
import { LoadingSpinner } from '@immich/ui';
|
import { LoadingSpinner } from '@immich/ui';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import { fade } from 'svelte/transition';
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
asset: AssetResponseDto;
|
asset: AssetResponseDto;
|
||||||
};
|
};
|
||||||
@@ -20,7 +18,7 @@
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div transition:fade={{ duration: 150 }} class="flex h-full select-none place-content-center place-items-center">
|
<div class="flex h-dvh w-dvw select-none place-content-center place-items-center">
|
||||||
{#await Promise.all([loadAssetData(assetId), import('./photo-sphere-viewer-adapter.svelte')])}
|
{#await Promise.all([loadAssetData(assetId), import('./photo-sphere-viewer-adapter.svelte')])}
|
||||||
<LoadingSpinner />
|
<LoadingSpinner />
|
||||||
{:then [data, { default: PhotoSphereViewer }]}
|
{:then [data, { default: PhotoSphereViewer }]}
|
||||||
|
|||||||
@@ -211,6 +211,7 @@
|
|||||||
zoomSpeed: 0.5,
|
zoomSpeed: 0.5,
|
||||||
fisheye: false,
|
fisheye: false,
|
||||||
});
|
});
|
||||||
|
viewer.addEventListener('ready', () => assetViewerManager.emit('ViewerOpenTransitionReady'), { once: true });
|
||||||
const resolutionPlugin = viewer.getPlugin<ResolutionPlugin>(ResolutionPlugin);
|
const resolutionPlugin = viewer.getPlugin<ResolutionPlugin>(ResolutionPlugin);
|
||||||
const zoomHandler = ({ zoomLevel }: events.ZoomUpdatedEvent) => {
|
const zoomHandler = ({ zoomLevel }: events.ZoomUpdatedEvent) => {
|
||||||
// zoomLevel is 0-100
|
// zoomLevel is 0-100
|
||||||
@@ -255,7 +256,12 @@
|
|||||||
<AssetViewerEvents {onZoom} />
|
<AssetViewerEvents {onZoom} />
|
||||||
|
|
||||||
<svelte:document use:shortcuts={[{ shortcut: { key: 'z' }, onShortcut: onZoom, preventDefault: true }]} />
|
<svelte:document use:shortcuts={[{ shortcut: { key: 'z' }, onShortcut: onZoom, preventDefault: true }]} />
|
||||||
<div class="h-full w-full mb-0" bind:this={container}></div>
|
<div
|
||||||
|
id="sphere"
|
||||||
|
class="h-dvh w-dvw mb-0"
|
||||||
|
bind:this={container}
|
||||||
|
style:view-transition-name={assetViewerManager.transitionName}
|
||||||
|
></div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Reset the default tooltip styling */
|
/* Reset the default tooltip styling */
|
||||||
|
|||||||
@@ -28,12 +28,11 @@
|
|||||||
cursor: AssetCursor;
|
cursor: AssetCursor;
|
||||||
element?: HTMLDivElement;
|
element?: HTMLDivElement;
|
||||||
sharedLink?: SharedLinkResponseDto;
|
sharedLink?: SharedLinkResponseDto;
|
||||||
onReady?: () => void;
|
|
||||||
onError?: () => void;
|
onError?: () => void;
|
||||||
onSwipe?: (event: SwipeCustomEvent) => void;
|
onSwipe?: (event: SwipeCustomEvent) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
let { cursor, element = $bindable(), sharedLink, onReady, onError, onSwipe }: Props = $props();
|
let { cursor, element = $bindable(), sharedLink, onError, onSwipe }: Props = $props();
|
||||||
|
|
||||||
const { slideshowState, slideshowLook } = slideshowStore;
|
const { slideshowState, slideshowLook } = slideshowStore;
|
||||||
const asset = $derived(cursor.current);
|
const asset = $derived(cursor.current);
|
||||||
@@ -231,11 +230,11 @@
|
|||||||
{onUrlChange}
|
{onUrlChange}
|
||||||
onImageReady={() => {
|
onImageReady={() => {
|
||||||
visibleImageReady = true;
|
visibleImageReady = true;
|
||||||
onReady?.();
|
assetViewerManager.emit('ViewerOpenTransitionReady');
|
||||||
}}
|
}}
|
||||||
onError={() => {
|
onError={() => {
|
||||||
onError?.();
|
onError?.();
|
||||||
onReady?.();
|
assetViewerManager.emit('ViewerOpenTransitionReady');
|
||||||
}}
|
}}
|
||||||
bind:imgRef={assetViewerManager.imgRef}
|
bind:imgRef={assetViewerManager.imgRef}
|
||||||
bind:ref={adaptiveImage}
|
bind:ref={adaptiveImage}
|
||||||
|
|||||||
@@ -139,6 +139,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<video
|
<video
|
||||||
|
style:view-transition-name={assetViewerManager.transitionName}
|
||||||
bind:this={videoPlayer}
|
bind:this={videoPlayer}
|
||||||
loop={$loopVideoPreference && loopVideo}
|
loop={$loopVideoPreference && loopVideo}
|
||||||
autoplay={$autoPlayVideo}
|
autoplay={$autoPlayVideo}
|
||||||
@@ -147,6 +148,7 @@
|
|||||||
disablePictureInPicture
|
disablePictureInPicture
|
||||||
class="h-full object-contain"
|
class="h-full object-contain"
|
||||||
{...useSwipe(onSwipe)}
|
{...useSwipe(onSwipe)}
|
||||||
|
onloadedmetadata={() => assetViewerManager.emit('ViewerOpenTransitionReady')}
|
||||||
oncanplay={(e) => handleCanPlay(e.currentTarget)}
|
oncanplay={(e) => handleCanPlay(e.currentTarget)}
|
||||||
onended={onVideoEnded}
|
onended={onVideoEnded}
|
||||||
onvolumechange={(e) => ($videoViewerMuted = e.currentTarget.muted)}
|
onvolumechange={(e) => ($videoViewerMuted = e.currentTarget.muted)}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
import type { AssetResponseDto } from '@immich/sdk';
|
import type { AssetResponseDto } from '@immich/sdk';
|
||||||
import { LoadingSpinner } from '@immich/ui';
|
import { LoadingSpinner } from '@immich/ui';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import { fade } from 'svelte/transition';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
asset: AssetResponseDto;
|
asset: AssetResponseDto;
|
||||||
}
|
}
|
||||||
@@ -19,7 +17,7 @@
|
|||||||
]);
|
]);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div transition:fade={{ duration: 150 }} class="flex h-full select-none place-content-center place-items-center">
|
<div class="flex h-full select-none place-content-center place-items-center">
|
||||||
{#await modules}
|
{#await modules}
|
||||||
<LoadingSpinner />
|
<LoadingSpinner />
|
||||||
{:then [PhotoSphereViewer, adapter, videoPlugin]}
|
{:then [PhotoSphereViewer, adapter, videoPlugin]}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { page } from '$app/state';
|
||||||
import { useActions, type ActionArray } from '$lib/actions/use-actions';
|
import { useActions, type ActionArray } from '$lib/actions/use-actions';
|
||||||
import NavigationBar from '$lib/components/shared-components/navigation-bar/navigation-bar.svelte';
|
import NavigationBar from '$lib/components/shared-components/navigation-bar/navigation-bar.svelte';
|
||||||
import UserSidebar from '$lib/components/shared-components/side-bar/user-sidebar.svelte';
|
import UserSidebar from '$lib/components/shared-components/side-bar/user-sidebar.svelte';
|
||||||
import type { HeaderButtonActionItem } from '$lib/types';
|
import type { HeaderButtonActionItem } from '$lib/types';
|
||||||
import { openFileUploadDialog } from '$lib/utils/file-uploader';
|
import { openFileUploadDialog } from '$lib/utils/file-uploader';
|
||||||
|
import { isAssetViewerRoute } from '$lib/utils/navigation';
|
||||||
import { Button, ContextMenuButton, HStack, isMenuItemType, type MenuItemType } from '@immich/ui';
|
import { Button, ContextMenuButton, HStack, isMenuItemType, type MenuItemType } from '@immich/ui';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
@@ -48,7 +50,7 @@
|
|||||||
|
|
||||||
<header>
|
<header>
|
||||||
{#if !hideNavbar}
|
{#if !hideNavbar}
|
||||||
<NavigationBar onUploadClick={() => openFileUploadDialog()} />
|
<NavigationBar hidden={isAssetViewerRoute(page)} onUploadClick={() => openFileUploadDialog()} />
|
||||||
{/if}
|
{/if}
|
||||||
</header>
|
</header>
|
||||||
<div
|
<div
|
||||||
@@ -64,7 +66,7 @@
|
|||||||
<UserSidebar />
|
<UserSidebar />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<main class="relative">
|
<main class="relative w-full">
|
||||||
<div class="{scrollbarClass} absolute {hasTitleClass} w-full overflow-y-auto p-2" use:useActions={use}>
|
<div class="{scrollbarClass} absolute {hasTitleClass} w-full overflow-y-auto p-2" use:useActions={use}>
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
import SearchBar from '$lib/components/shared-components/search-bar/search-bar.svelte';
|
import SearchBar from '$lib/components/shared-components/search-bar/search-bar.svelte';
|
||||||
import SkipLink from '$lib/elements/SkipLink.svelte';
|
import SkipLink from '$lib/elements/SkipLink.svelte';
|
||||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
|
import { viewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte';
|
||||||
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
|
import { featureFlagsManager } from '$lib/managers/feature-flags-manager.svelte';
|
||||||
import { Route } from '$lib/route';
|
import { Route } from '$lib/route';
|
||||||
import { getGlobalActions } from '$lib/services/app.service';
|
import { getGlobalActions } from '$lib/services/app.service';
|
||||||
@@ -27,10 +28,11 @@
|
|||||||
onUploadClick?: () => void;
|
onUploadClick?: () => void;
|
||||||
// TODO: remove once this is only used in <AppShellHeader>
|
// TODO: remove once this is only used in <AppShellHeader>
|
||||||
noBorder?: boolean;
|
noBorder?: boolean;
|
||||||
|
hidden?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
let { onUploadClick, noBorder = false }: Props = $props();
|
let { onUploadClick, noBorder = false, hidden = false }: Props = $props();
|
||||||
|
let viewTransitionName = $state<string | undefined>();
|
||||||
let shouldShowAccountInfoPanel = $state(false);
|
let shouldShowAccountInfoPanel = $state(false);
|
||||||
let shouldShowNotificationPanel = $state(false);
|
let shouldShowNotificationPanel = $state(false);
|
||||||
let innerWidth: number = $state(0);
|
let innerWidth: number = $state(0);
|
||||||
@@ -44,12 +46,32 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return viewTransitionManager.on({
|
||||||
|
PrepareOldSnapshot: (types) => {
|
||||||
|
if (types.includes('viewer')) {
|
||||||
|
viewTransitionName = 'exclude';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PrepareNewSnapshot: (types) => {
|
||||||
|
viewTransitionName = types.includes('timeline') ? 'exclude' : undefined;
|
||||||
|
},
|
||||||
|
Finished: () => {
|
||||||
|
viewTransitionName = undefined;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const { Cast } = $derived(getGlobalActions($t));
|
const { Cast } = $derived(getGlobalActions($t));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window bind:innerWidth />
|
<svelte:window bind:innerWidth />
|
||||||
|
|
||||||
<nav id="dashboard-navbar" class="max-md:h-(--navbar-height-md) h-(--navbar-height) w-dvw text-sm">
|
<nav
|
||||||
|
id="dashboard-navbar"
|
||||||
|
class={['max-md:h-(--navbar-height-md) h-(--navbar-height) w-dvw text-sm', hidden && 'invisible']}
|
||||||
|
style:view-transition-name={viewTransitionName}
|
||||||
|
>
|
||||||
<SkipLink text={$t('skip_to_content')} />
|
<SkipLink text={$t('skip_to_content')} />
|
||||||
<div
|
<div
|
||||||
class="grid h-full grid-cols-[--spacing(32)_auto] items-center py-2 sidebar:grid-cols-[--spacing(64)_auto] {noBorder
|
class="grid h-full grid-cols-[--spacing(32)_auto] items-center py-2 sidebar:grid-cols-[--spacing(64)_auto] {noBorder
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||||
import { filterIsInOrNearViewport } from '$lib/managers/timeline-manager/utils.svelte';
|
import { filterIsInOrNearViewport } from '$lib/managers/timeline-manager/utils.svelte';
|
||||||
import type { ViewerAsset } from '$lib/managers/timeline-manager/viewer-asset.svelte';
|
import type { ViewerAsset } from '$lib/managers/timeline-manager/viewer-asset.svelte';
|
||||||
import type { VirtualScrollManager } from '$lib/managers/VirtualScrollManager/VirtualScrollManager.svelte';
|
|
||||||
import { uploadAssetsStore } from '$lib/stores/upload';
|
import { uploadAssetsStore } from '$lib/stores/upload';
|
||||||
import type { CommonPosition } from '$lib/utils/layout-utils';
|
import type { CommonPosition } from '$lib/utils/layout-utils';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
@@ -12,10 +11,11 @@
|
|||||||
let { isUploading } = uploadAssetsStore;
|
let { isUploading } = uploadAssetsStore;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
heroTransitionAssetId?: string | null;
|
||||||
|
suspendTransitions?: boolean;
|
||||||
viewerAssets: ViewerAsset[];
|
viewerAssets: ViewerAsset[];
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
manager: VirtualScrollManager;
|
|
||||||
thumbnail: Snippet<
|
thumbnail: Snippet<
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -27,9 +27,17 @@
|
|||||||
customThumbnailLayout?: Snippet<[asset: TimelineAsset]>;
|
customThumbnailLayout?: Snippet<[asset: TimelineAsset]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { viewerAssets, width, height, manager, thumbnail, customThumbnailLayout }: Props = $props();
|
const {
|
||||||
|
heroTransitionAssetId,
|
||||||
|
suspendTransitions = false,
|
||||||
|
viewerAssets,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
thumbnail,
|
||||||
|
customThumbnailLayout,
|
||||||
|
}: Props = $props();
|
||||||
|
|
||||||
const transitionDuration = $derived(manager.suspendTransitions && !$isUploading ? 0 : 150);
|
const transitionDuration = $derived(suspendTransitions && !$isUploading ? 0 : 150);
|
||||||
const scaleDuration = $derived(transitionDuration === 0 ? 0 : transitionDuration + 100);
|
const scaleDuration = $derived(transitionDuration === 0 ? 0 : transitionDuration + 100);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -38,11 +46,13 @@
|
|||||||
{#each filterIsInOrNearViewport(viewerAssets) as viewerAsset (viewerAsset.id)}
|
{#each filterIsInOrNearViewport(viewerAssets) as viewerAsset (viewerAsset.id)}
|
||||||
{@const position = viewerAsset.position!}
|
{@const position = viewerAsset.position!}
|
||||||
{@const asset = viewerAsset.asset!}
|
{@const asset = viewerAsset.asset!}
|
||||||
|
{@const transitionName = heroTransitionAssetId === asset.id ? 'hero' : undefined}
|
||||||
|
|
||||||
<!-- note: don't remove data-asset-id - its used by web e2e tests -->
|
<!-- note: don't remove data-asset-id - its used by web e2e tests -->
|
||||||
<div
|
<div
|
||||||
data-asset-id={asset.id}
|
data-asset-id={asset.id}
|
||||||
class="absolute"
|
class="absolute"
|
||||||
|
style:view-transition-name={transitionName}
|
||||||
style:top={position.top + 'px'}
|
style:top={position.top + 'px'}
|
||||||
style:inset-inline-start={position.left + 'px'}
|
style:inset-inline-start={position.left + 'px'}
|
||||||
style:width={position.width + 'px'}
|
style:width={position.width + 'px'}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { focusAsset } from '$lib/components/timeline/actions/focus-actions';
|
||||||
import AssetLayout from '$lib/components/timeline/AssetLayout.svelte';
|
import AssetLayout from '$lib/components/timeline/AssetLayout.svelte';
|
||||||
|
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
||||||
import type { AssetMultiSelectManager } from '$lib/managers/asset-multi-select-manager.svelte';
|
import type { AssetMultiSelectManager } from '$lib/managers/asset-multi-select-manager.svelte';
|
||||||
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
import { TimelineDay } from '$lib/managers/timeline-manager/timeline-day.svelte';
|
import { TimelineDay } from '$lib/managers/timeline-manager/timeline-day.svelte';
|
||||||
import type { TimelineMonth } from '$lib/managers/timeline-manager/timeline-month.svelte';
|
import type { TimelineMonth } from '$lib/managers/timeline-manager/timeline-month.svelte';
|
||||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||||
import { assetsSnapshot, filterIsInOrNearViewport } from '$lib/managers/timeline-manager/utils.svelte';
|
import { assetsSnapshot, filterIsInOrNearViewport } from '$lib/managers/timeline-manager/utils.svelte';
|
||||||
import type { VirtualScrollManager } from '$lib/managers/VirtualScrollManager/VirtualScrollManager.svelte';
|
import { viewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte';
|
||||||
import { uploadAssetsStore } from '$lib/stores/upload';
|
import { uploadAssetsStore } from '$lib/stores/upload';
|
||||||
import type { CommonPosition } from '$lib/utils/layout-utils';
|
import type { CommonPosition } from '$lib/utils/layout-utils';
|
||||||
import { fromTimelinePlainDate, getDateLocaleString } from '$lib/utils/timeline-util';
|
import { fromTimelinePlainDate, getDateLocaleString } from '$lib/utils/timeline-util';
|
||||||
import { Icon } from '@immich/ui';
|
import { Icon } from '@immich/ui';
|
||||||
import { mdiCheckCircle, mdiCircleOutline } from '@mdi/js';
|
import { mdiCheckCircle, mdiCircleOutline } from '@mdi/js';
|
||||||
import type { Snippet } from 'svelte';
|
import { onMount, tick, type Snippet } from 'svelte';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
toViewerHeroAssetId?: string | null;
|
||||||
thumbnail: Snippet<
|
thumbnail: Snippet<
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -28,16 +32,16 @@
|
|||||||
singleSelect: boolean;
|
singleSelect: boolean;
|
||||||
assetInteraction: AssetMultiSelectManager;
|
assetInteraction: AssetMultiSelectManager;
|
||||||
timelineMonth: TimelineMonth;
|
timelineMonth: TimelineMonth;
|
||||||
manager: VirtualScrollManager;
|
|
||||||
onTimelineDaySelect: (timelineDay: TimelineDay, assets: TimelineAsset[]) => void;
|
onTimelineDaySelect: (timelineDay: TimelineDay, assets: TimelineAsset[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
toViewerHeroAssetId,
|
||||||
thumbnail: thumbnailWithGroup,
|
thumbnail: thumbnailWithGroup,
|
||||||
customThumbnailLayout,
|
customThumbnailLayout,
|
||||||
singleSelect,
|
singleSelect,
|
||||||
assetInteraction,
|
assetInteraction,
|
||||||
timelineMonth,
|
timelineMonth,
|
||||||
manager,
|
|
||||||
onTimelineDaySelect,
|
onTimelineDaySelect,
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
@@ -55,6 +59,32 @@
|
|||||||
});
|
});
|
||||||
return getDateLocaleString(date);
|
return getDateLocaleString(date);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let toTimelineHeroAssetId = $state<string | null>(null);
|
||||||
|
let heroTransitionAssetId = $derived(toTimelineHeroAssetId ?? toViewerHeroAssetId ?? null);
|
||||||
|
|
||||||
|
const handleViewerCloseTransition = ({ id }: { id: string }) => {
|
||||||
|
const asset = timelineMonth.findAssetById({ id });
|
||||||
|
if (!asset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void viewTransitionManager.startTransition({
|
||||||
|
types: ['timeline'],
|
||||||
|
performUpdate: async () => {
|
||||||
|
assetViewerManager.emit('ViewerCloseTransitionReady');
|
||||||
|
const event = await eventManager.untilNext('TimelineLoaded');
|
||||||
|
toTimelineHeroAssetId = event.id;
|
||||||
|
await tick();
|
||||||
|
},
|
||||||
|
onFinished: () => {
|
||||||
|
toTimelineHeroAssetId = null;
|
||||||
|
focusAsset(asset.id);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (viewTransitionManager.isSupported()) {
|
||||||
|
onMount(() => assetViewerManager.on({ ViewerCloseTransition: handleViewerCloseTransition }));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each filterIsInOrNearViewport(timelineMonth.timelineDays) as timelineDay, groupIndex (timelineDay.day)}
|
{#each filterIsInOrNearViewport(timelineMonth.timelineDays) as timelineDay, groupIndex (timelineDay.day)}
|
||||||
@@ -99,7 +129,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AssetLayout
|
<AssetLayout
|
||||||
{manager}
|
{heroTransitionAssetId}
|
||||||
|
suspendTransitions={timelineMonth.timelineManager.suspendTransitions}
|
||||||
viewerAssets={timelineDay.viewerAssets}
|
viewerAssets={timelineDay.viewerAssets}
|
||||||
height={timelineDay.height}
|
height={timelineDay.height}
|
||||||
width={timelineDay.width}
|
width={timelineDay.width}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
import { fade, fly } from 'svelte/transition';
|
import { fade, fly } from 'svelte/transition';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
invisible: boolean;
|
||||||
/** Offset from the top of the timeline (e.g., for headers) */
|
/** Offset from the top of the timeline (e.g., for headers) */
|
||||||
timelineTopOffset?: number;
|
timelineTopOffset?: number;
|
||||||
/** Offset from the bottom of the timeline (e.g., for footers) */
|
/** Offset from the bottom of the timeline (e.g., for footers) */
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
invisible = false,
|
||||||
timelineTopOffset = 0,
|
timelineTopOffset = 0,
|
||||||
timelineBottomOffset = 0,
|
timelineBottomOffset = 0,
|
||||||
height = 0,
|
height = 0,
|
||||||
@@ -509,6 +511,7 @@
|
|||||||
aria-valuemin={toScrollY(0)}
|
aria-valuemin={toScrollY(0)}
|
||||||
data-id="scrubber"
|
data-id="scrubber"
|
||||||
class="absolute end-0 z-1 select-none hover:cursor-row-resize"
|
class="absolute end-0 z-1 select-none hover:cursor-row-resize"
|
||||||
|
class:invisible
|
||||||
style:padding-top={PADDING_TOP + 'px'}
|
style:padding-top={PADDING_TOP + 'px'}
|
||||||
style:padding-bottom={PADDING_BOTTOM + 'px'}
|
style:padding-bottom={PADDING_BOTTOM + 'px'}
|
||||||
style:width
|
style:width
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
import Skeleton from '$lib/elements/Skeleton.svelte';
|
import Skeleton from '$lib/elements/Skeleton.svelte';
|
||||||
import type { AssetMultiSelectManager } from '$lib/managers/asset-multi-select-manager.svelte';
|
import type { AssetMultiSelectManager } from '$lib/managers/asset-multi-select-manager.svelte';
|
||||||
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
||||||
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
|
import { startViewerTransition } from '$lib/utils/transition-utils';
|
||||||
import type { TimelineDay } from '$lib/managers/timeline-manager/timeline-day.svelte';
|
import type { TimelineDay } from '$lib/managers/timeline-manager/timeline-day.svelte';
|
||||||
import { isIntersecting } from '$lib/managers/timeline-manager/internal/intersection-support.svelte';
|
import { isIntersecting } from '$lib/managers/timeline-manager/internal/intersection-support.svelte';
|
||||||
import type { TimelineMonth } from '$lib/managers/timeline-manager/timeline-month.svelte';
|
import type { TimelineMonth } from '$lib/managers/timeline-manager/timeline-month.svelte';
|
||||||
@@ -99,6 +101,7 @@
|
|||||||
// Overall scroll percentage through the entire timeline (0-1)
|
// Overall scroll percentage through the entire timeline (0-1)
|
||||||
let timelineScrollPercent: number = $state(0);
|
let timelineScrollPercent: number = $state(0);
|
||||||
let scrubberWidth = $state(0);
|
let scrubberWidth = $state(0);
|
||||||
|
let toViewerHeroAssetId = $state<string | null>(null);
|
||||||
|
|
||||||
const isEmpty = $derived(timelineManager.isInitialized && timelineManager.months.length === 0);
|
const isEmpty = $derived(timelineManager.isInitialized && timelineManager.months.length === 0);
|
||||||
const maxMd = $derived(mediaQueryManager.maxMd);
|
const maxMd = $derived(mediaQueryManager.maxMd);
|
||||||
@@ -207,7 +210,7 @@
|
|||||||
timelineManager.viewportWidth = rect.width;
|
timelineManager.viewportWidth = rect.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const scrollTarget = assetViewerManager.gridScrollTarget?.at;
|
const scrollTarget = getScrollTarget();
|
||||||
let scrolled = false;
|
let scrolled = false;
|
||||||
if (scrollTarget) {
|
if (scrollTarget) {
|
||||||
scrolled = await scrollAndLoadAsset(scrollTarget);
|
scrolled = await scrollAndLoadAsset(scrollTarget);
|
||||||
@@ -219,7 +222,7 @@
|
|||||||
await tick();
|
await tick();
|
||||||
focusAsset(scrollTarget);
|
focusAsset(scrollTarget);
|
||||||
}
|
}
|
||||||
invisible = false;
|
invisible = isAssetViewerRoute(page) ? true : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// note: only modified once in afterNavigate()
|
// note: only modified once in afterNavigate()
|
||||||
@@ -237,10 +240,13 @@
|
|||||||
hasNavigatedToOrFromAssetViewer = isNavigatingToAssetViewer !== isNavigatingFromAssetViewer;
|
hasNavigatedToOrFromAssetViewer = isNavigatingToAssetViewer !== isNavigatingFromAssetViewer;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getScrollTarget = () => {
|
||||||
|
return assetViewerManager.gridScrollTarget?.at ?? page.params.assetId ?? null;
|
||||||
|
};
|
||||||
// afterNavigate is only called after navigation to a new URL, {complete} will resolve
|
// afterNavigate is only called after navigation to a new URL, {complete} will resolve
|
||||||
// after successful navigation.
|
// after successful navigation.
|
||||||
afterNavigate(({ complete }) => {
|
afterNavigate(({ complete }) => {
|
||||||
void complete.finally(() => {
|
void complete.finally(async () => {
|
||||||
const isAssetViewerPage = isAssetViewerRoute(page);
|
const isAssetViewerPage = isAssetViewerRoute(page);
|
||||||
|
|
||||||
// Set initial load state only once - if initialLoadWasAssetViewer is null, then
|
// Set initial load state only once - if initialLoadWasAssetViewer is null, then
|
||||||
@@ -251,6 +257,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
void scrollAfterNavigate();
|
void scrollAfterNavigate();
|
||||||
|
if (!isAssetViewerPage) {
|
||||||
|
const scrollTarget = getScrollTarget();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
eventManager.emit('TimelineLoaded', { id: scrollTarget });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,7 +270,7 @@
|
|||||||
// note: don't throttle, debounch, or otherwise do this function async - it causes flicker
|
// note: don't throttle, debounch, or otherwise do this function async - it causes flicker
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!enableRouting) {
|
if (!enableRouting && !isAssetViewerRoute(page)) {
|
||||||
invisible = false;
|
invisible = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -545,7 +557,7 @@
|
|||||||
assetInteraction.selectAll = timelineManager.assetCount === assetInteraction.assets.length;
|
assetInteraction.selectAll = timelineManager.assetCount === assetInteraction.assets.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
const _onClick = (
|
const defaultThumbnailClick = (
|
||||||
timelineManager: TimelineManager,
|
timelineManager: TimelineManager,
|
||||||
assets: TimelineAsset[],
|
assets: TimelineAsset[],
|
||||||
groupTitle: string,
|
groupTitle: string,
|
||||||
@@ -557,6 +569,25 @@
|
|||||||
}
|
}
|
||||||
void navigate({ targetRoute: 'current', assetId: asset.id });
|
void navigate({ targetRoute: 'current', assetId: asset.id });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleThumbnailClick = (asset: TimelineAsset, timelineDay: TimelineDay) => {
|
||||||
|
if (typeof onThumbnailClick === 'function' || isSelectionMode || assetInteraction.selectionActive) {
|
||||||
|
if (typeof onThumbnailClick === 'function') {
|
||||||
|
onThumbnailClick(asset, timelineManager, timelineDay, defaultThumbnailClick);
|
||||||
|
} else {
|
||||||
|
defaultThumbnailClick(timelineManager, timelineDay.getAssets(), timelineDay.groupTitle, asset);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const openViewer = () => void navigate({ targetRoute: 'current', assetId: asset.id });
|
||||||
|
startViewerTransition(
|
||||||
|
asset.id,
|
||||||
|
openViewer,
|
||||||
|
(id) => (toViewerHeroAssetId = id),
|
||||||
|
() => (toViewerHeroAssetId = null),
|
||||||
|
);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:document onkeydown={onKeyDown} onkeyup={onKeyUp} />
|
<svelte:document onkeydown={onKeyDown} onkeyup={onKeyUp} />
|
||||||
@@ -587,6 +618,7 @@
|
|||||||
{#if timelineManager.months.length > 0}
|
{#if timelineManager.months.length > 0}
|
||||||
<Scrubber
|
<Scrubber
|
||||||
{timelineManager}
|
{timelineManager}
|
||||||
|
{invisible}
|
||||||
height={timelineManager.viewportHeight}
|
height={timelineManager.viewportHeight}
|
||||||
timelineTopOffset={timelineManager.topSectionHeight}
|
timelineTopOffset={timelineManager.topSectionHeight}
|
||||||
timelineBottomOffset={timelineManager.bottomSectionHeight}
|
timelineBottomOffset={timelineManager.bottomSectionHeight}
|
||||||
@@ -618,6 +650,7 @@
|
|||||||
id="asset-grid"
|
id="asset-grid"
|
||||||
class={['scrollbar-hidden h-full overflow-y-auto outline-none', { 'm-0': isEmpty }, { 'ms-0': !isEmpty }]}
|
class={['scrollbar-hidden h-full overflow-y-auto outline-none', { 'm-0': isEmpty }, { 'ms-0': !isEmpty }]}
|
||||||
style:margin-inline-end={(usingMobileDevice ? 0 : scrubberWidth) + 'px'}
|
style:margin-inline-end={(usingMobileDevice ? 0 : scrubberWidth) + 'px'}
|
||||||
|
data-initialized={timelineManager.isInitialized || undefined}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
bind:clientHeight={timelineManager.viewportHeight}
|
bind:clientHeight={timelineManager.viewportHeight}
|
||||||
bind:clientWidth={timelineManager.viewportWidth}
|
bind:clientWidth={timelineManager.viewportWidth}
|
||||||
@@ -666,11 +699,11 @@
|
|||||||
style:width="100%"
|
style:width="100%"
|
||||||
>
|
>
|
||||||
<Month
|
<Month
|
||||||
|
{toViewerHeroAssetId}
|
||||||
{assetInteraction}
|
{assetInteraction}
|
||||||
{customThumbnailLayout}
|
{customThumbnailLayout}
|
||||||
{singleSelect}
|
{singleSelect}
|
||||||
{timelineMonth}
|
{timelineMonth}
|
||||||
manager={timelineManager}
|
|
||||||
onTimelineDaySelect={handleGroupSelect}
|
onTimelineDaySelect={handleGroupSelect}
|
||||||
>
|
>
|
||||||
{#snippet thumbnail({ asset, position, timelineDay, groupIndex })}
|
{#snippet thumbnail({ asset, position, timelineDay, groupIndex })}
|
||||||
@@ -684,13 +717,7 @@
|
|||||||
{asset}
|
{asset}
|
||||||
{albumUsers}
|
{albumUsers}
|
||||||
{groupIndex}
|
{groupIndex}
|
||||||
onClick={(asset) => {
|
onClick={(asset) => handleThumbnailClick(asset, timelineDay)}
|
||||||
if (typeof onThumbnailClick === 'function') {
|
|
||||||
onThumbnailClick(asset, timelineManager, timelineDay, _onClick);
|
|
||||||
} else {
|
|
||||||
_onClick(timelineManager, timelineDay.getAssets(), timelineDay.groupTitle, asset);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
if (isSelectionMode || assetInteraction.selectionActive) {
|
if (isSelectionMode || assetInteraction.selectionActive) {
|
||||||
assetSelectHandler(timelineManager, asset, timelineDay.getAssets(), timelineDay.groupTitle);
|
assetSelectHandler(timelineManager, asset, timelineDay.getAssets(), timelineDay.groupTitle);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
||||||
import { assetCacheManager } from '$lib/managers/AssetCacheManager.svelte';
|
import { assetCacheManager } from '$lib/managers/AssetCacheManager.svelte';
|
||||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
|
import { viewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte';
|
||||||
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
|
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
|
||||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||||
import { websocketEvents } from '$lib/stores/websocket';
|
import { websocketEvents } from '$lib/stores/websocket';
|
||||||
@@ -97,6 +98,12 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = async (asset: { id: string }) => {
|
const handleClose = async (asset: { id: string }) => {
|
||||||
|
if (viewTransitionManager.isSupported()) {
|
||||||
|
const transitionReady = assetViewerManager.untilNext('ViewerCloseTransitionReady');
|
||||||
|
assetViewerManager.emit('ViewerCloseTransition', { id: asset.id });
|
||||||
|
await transitionReady;
|
||||||
|
}
|
||||||
|
|
||||||
invisible = true;
|
invisible = true;
|
||||||
assetViewerManager.gridScrollTarget = { at: asset.id };
|
assetViewerManager.gridScrollTarget = { at: asset.id };
|
||||||
await navigate({
|
await navigate({
|
||||||
|
|||||||
@@ -0,0 +1,327 @@
|
|||||||
|
import { ViewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte';
|
||||||
|
|
||||||
|
function mockViewTransition({
|
||||||
|
updateCallbackDone = Promise.resolve(),
|
||||||
|
finished = Promise.resolve(),
|
||||||
|
ready = Promise.resolve(),
|
||||||
|
skipTransition = vi.fn(),
|
||||||
|
}: {
|
||||||
|
updateCallbackDone?: Promise<void>;
|
||||||
|
finished?: Promise<void>;
|
||||||
|
ready?: Promise<void>;
|
||||||
|
skipTransition?: ReturnType<typeof vi.fn>;
|
||||||
|
} = {}) {
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
document.startViewTransition = vi.fn().mockImplementation((arg: unknown) => {
|
||||||
|
const updateFn = typeof arg === 'function' ? arg : (arg as { update: () => Promise<void> }).update;
|
||||||
|
void updateFn();
|
||||||
|
return { updateCallbackDone, finished, ready, skipTransition };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ViewTransitionManager', () => {
|
||||||
|
let manager: ViewTransitionManager;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
manager = new ViewTransitionManager();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
delete (document as Partial<typeof document> & { startViewTransition?: unknown }).startViewTransition;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when View Transition API is not supported', () => {
|
||||||
|
it('should still call performUpdate', async () => {
|
||||||
|
const performUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate });
|
||||||
|
|
||||||
|
expect(performUpdate).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call onFinished after performUpdate', async () => {
|
||||||
|
const callOrder: string[] = [];
|
||||||
|
const performUpdate = vi.fn().mockImplementation(() => {
|
||||||
|
callOrder.push('performUpdate');
|
||||||
|
});
|
||||||
|
const onFinished = vi.fn().mockImplementation(() => {
|
||||||
|
callOrder.push('onFinished');
|
||||||
|
});
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate, onFinished });
|
||||||
|
|
||||||
|
expect(onFinished).toHaveBeenCalledOnce();
|
||||||
|
expect(callOrder).toEqual(['performUpdate', 'onFinished']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call prepareOldSnapshot or prepareNewSnapshot', async () => {
|
||||||
|
const prepareOldSnapshot = vi.fn();
|
||||||
|
const prepareNewSnapshot = vi.fn();
|
||||||
|
const performUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate, prepareOldSnapshot, prepareNewSnapshot });
|
||||||
|
|
||||||
|
expect(prepareOldSnapshot).not.toHaveBeenCalled();
|
||||||
|
expect(prepareNewSnapshot).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when a transition is already active', () => {
|
||||||
|
it('should skip the first transition and run the second', async () => {
|
||||||
|
let resolveFirstUpdate!: () => void;
|
||||||
|
const firstUpdateCallbackDone = new Promise<void>((resolve) => {
|
||||||
|
resolveFirstUpdate = resolve;
|
||||||
|
});
|
||||||
|
const firstFinished = new Promise<void>(() => {});
|
||||||
|
const firstSkipTransition = vi.fn();
|
||||||
|
|
||||||
|
let callCount = 0;
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
document.startViewTransition = vi.fn().mockImplementation((arg: unknown) => {
|
||||||
|
callCount++;
|
||||||
|
const updateFn = typeof arg === 'function' ? arg : (arg as { update: () => Promise<void> }).update;
|
||||||
|
void updateFn();
|
||||||
|
if (callCount === 1) {
|
||||||
|
return {
|
||||||
|
updateCallbackDone: firstUpdateCallbackDone,
|
||||||
|
finished: firstFinished,
|
||||||
|
ready: Promise.resolve(),
|
||||||
|
skipTransition: firstSkipTransition,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
updateCallbackDone: Promise.resolve(),
|
||||||
|
finished: Promise.resolve(),
|
||||||
|
ready: Promise.resolve(),
|
||||||
|
skipTransition: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const secondPerformUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
const firstPromise = manager.startTransition({
|
||||||
|
performUpdate: async () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await new Promise<void>((r) => queueMicrotask(r));
|
||||||
|
|
||||||
|
// While first is active, start a second — should skip the first and proceed
|
||||||
|
await manager.startTransition({ performUpdate: secondPerformUpdate });
|
||||||
|
expect(firstSkipTransition).toHaveBeenCalledOnce();
|
||||||
|
expect(secondPerformUpdate).toHaveBeenCalledOnce();
|
||||||
|
|
||||||
|
resolveFirstUpdate();
|
||||||
|
await firstPromise;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('skipTransitions', () => {
|
||||||
|
it('should return false when no transition is active', () => {
|
||||||
|
expect(manager.skipTransitions()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call skipTransition on the active transition and return true', async () => {
|
||||||
|
let resolveFinished!: () => void;
|
||||||
|
const finished = new Promise<void>((resolve) => {
|
||||||
|
resolveFinished = resolve;
|
||||||
|
});
|
||||||
|
let resolveUpdate!: () => void;
|
||||||
|
const updateCallbackDone = new Promise<void>((resolve) => {
|
||||||
|
resolveUpdate = resolve;
|
||||||
|
});
|
||||||
|
const skipTransition = vi.fn();
|
||||||
|
|
||||||
|
mockViewTransition({ updateCallbackDone, finished, skipTransition });
|
||||||
|
|
||||||
|
const promise = manager.startTransition({ performUpdate: async () => {} });
|
||||||
|
await new Promise<void>((r) => queueMicrotask(r));
|
||||||
|
|
||||||
|
const skipped = manager.skipTransitions();
|
||||||
|
expect(skipped).toBe(true);
|
||||||
|
expect(skipTransition).toHaveBeenCalledOnce();
|
||||||
|
|
||||||
|
resolveUpdate();
|
||||||
|
resolveFinished();
|
||||||
|
await promise;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow a new transition after skipping', async () => {
|
||||||
|
let resolveFinished!: () => void;
|
||||||
|
const finished = new Promise<void>((resolve) => {
|
||||||
|
resolveFinished = resolve;
|
||||||
|
});
|
||||||
|
let resolveUpdate!: () => void;
|
||||||
|
const updateCallbackDone = new Promise<void>((resolve) => {
|
||||||
|
resolveUpdate = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
mockViewTransition({ updateCallbackDone, finished });
|
||||||
|
|
||||||
|
const promise = manager.startTransition({ performUpdate: async () => {} });
|
||||||
|
await new Promise<void>((r) => queueMicrotask(r));
|
||||||
|
|
||||||
|
manager.skipTransitions();
|
||||||
|
resolveUpdate();
|
||||||
|
resolveFinished();
|
||||||
|
await promise;
|
||||||
|
|
||||||
|
const secondUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
mockViewTransition({ updateCallbackDone: Promise.resolve(), finished: Promise.resolve() });
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate: secondUpdate });
|
||||||
|
expect(secondUpdate).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('error handling', () => {
|
||||||
|
it('should propagate error from performUpdate when API is not supported', async () => {
|
||||||
|
const error = new Error('update failed');
|
||||||
|
const performUpdate = vi.fn().mockRejectedValue(error);
|
||||||
|
|
||||||
|
await expect(manager.startTransition({ performUpdate })).rejects.toThrow('update failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clean up activeViewTransition when performUpdate throws (API supported)', async () => {
|
||||||
|
const error = new Error('update failed');
|
||||||
|
let resolveFinished!: () => void;
|
||||||
|
const finished = new Promise<void>((resolve) => {
|
||||||
|
resolveFinished = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
document.startViewTransition = vi.fn().mockImplementation((arg: unknown) => {
|
||||||
|
const updateFn = typeof arg === 'function' ? arg : (arg as { update: () => Promise<void> }).update;
|
||||||
|
const updateCallbackDone = updateFn();
|
||||||
|
return { updateCallbackDone, finished, ready: Promise.resolve(), skipTransition: vi.fn() };
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(manager.startTransition({ performUpdate: () => Promise.reject(error) })).rejects.toThrow(
|
||||||
|
'update failed',
|
||||||
|
);
|
||||||
|
|
||||||
|
resolveFinished();
|
||||||
|
await new Promise<void>((r) => queueMicrotask(r));
|
||||||
|
|
||||||
|
const secondUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
mockViewTransition();
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate: secondUpdate });
|
||||||
|
expect(secondUpdate).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fallback path', () => {
|
||||||
|
it('should fall back to function argument when object argument throws', async () => {
|
||||||
|
const performUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
const prepareNewSnapshot = vi.fn();
|
||||||
|
const finished = Promise.resolve();
|
||||||
|
const updateCallbackDone = Promise.resolve();
|
||||||
|
|
||||||
|
let callCount = 0;
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
document.startViewTransition = vi.fn().mockImplementation((arg: unknown) => {
|
||||||
|
callCount++;
|
||||||
|
if (callCount === 1 && typeof arg !== 'function') {
|
||||||
|
throw new TypeError('object form not supported');
|
||||||
|
}
|
||||||
|
const updateFn = typeof arg === 'function' ? arg : (arg as { update: () => Promise<void> }).update;
|
||||||
|
void updateFn();
|
||||||
|
return { updateCallbackDone, finished, ready: Promise.resolve(), skipTransition: vi.fn() };
|
||||||
|
});
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate, prepareNewSnapshot, types: ['test'] });
|
||||||
|
|
||||||
|
expect(performUpdate).toHaveBeenCalledOnce();
|
||||||
|
expect(prepareNewSnapshot).toHaveBeenCalledOnce();
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
expect(document.startViewTransition).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('abort signal', () => {
|
||||||
|
it('should pass an AbortSignal to performUpdate', async () => {
|
||||||
|
const performUpdate = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
mockViewTransition();
|
||||||
|
|
||||||
|
await manager.startTransition({ performUpdate });
|
||||||
|
|
||||||
|
expect(performUpdate).toHaveBeenCalledWith(expect.any(AbortSignal));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should abort the signal when transition.ready rejects', async () => {
|
||||||
|
let capturedSignal: AbortSignal | undefined;
|
||||||
|
let resolveUpdate!: () => void;
|
||||||
|
const updateCallbackDone = new Promise<void>((resolve) => {
|
||||||
|
resolveUpdate = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
const readyError = new Error('Transition was aborted because of timeout in DOM update');
|
||||||
|
|
||||||
|
mockViewTransition({
|
||||||
|
updateCallbackDone,
|
||||||
|
finished: Promise.reject(readyError),
|
||||||
|
ready: Promise.reject(readyError),
|
||||||
|
});
|
||||||
|
|
||||||
|
const performUpdate = vi.fn().mockImplementation((signal: AbortSignal) => {
|
||||||
|
capturedSignal = signal;
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
signal.addEventListener('abort', () => resolve(), { once: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const promise = manager.startTransition({ performUpdate });
|
||||||
|
|
||||||
|
await new Promise<void>((r) => queueMicrotask(r));
|
||||||
|
await new Promise<void>((r) => queueMicrotask(r));
|
||||||
|
|
||||||
|
expect(capturedSignal?.aborted).toBe(true);
|
||||||
|
|
||||||
|
resolveUpdate();
|
||||||
|
await promise;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not abort the signal when transition completes normally', async () => {
|
||||||
|
let capturedSignal: AbortSignal | undefined;
|
||||||
|
|
||||||
|
mockViewTransition();
|
||||||
|
|
||||||
|
await manager.startTransition({
|
||||||
|
performUpdate: (signal) => {
|
||||||
|
capturedSignal = signal;
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(capturedSignal?.aborted).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass a non-aborted signal in the unsupported fallback path', async () => {
|
||||||
|
let capturedSignal: AbortSignal | undefined;
|
||||||
|
|
||||||
|
await manager.startTransition({
|
||||||
|
performUpdate: (signal) => {
|
||||||
|
capturedSignal = signal;
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(capturedSignal).toBeInstanceOf(AbortSignal);
|
||||||
|
expect(capturedSignal?.aborted).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isSupported', () => {
|
||||||
|
it('should return false when startViewTransition is not in document', () => {
|
||||||
|
expect(manager.isSupported()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true when startViewTransition is in document', () => {
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
document.startViewTransition = vi.fn();
|
||||||
|
|
||||||
|
expect(manager.isSupported()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import { BaseEventManager } from '$lib/utils/base-event-manager.svelte';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
|
type TransitionEvents = {
|
||||||
|
PrepareOldSnapshot: [string[]];
|
||||||
|
PrepareNewSnapshot: [string[]];
|
||||||
|
Finished: [string[]];
|
||||||
|
};
|
||||||
|
|
||||||
|
interface TransitionRequest {
|
||||||
|
types?: string[];
|
||||||
|
prepareOldSnapshot?: () => void;
|
||||||
|
performUpdate: (signal: AbortSignal) => Promise<void>;
|
||||||
|
prepareNewSnapshot?: () => void;
|
||||||
|
onFinished?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ViewTransitionManager extends BaseEventManager<TransitionEvents> {
|
||||||
|
#activeViewTransition: ViewTransition | null = null;
|
||||||
|
#activeOnFinished: (() => void) | undefined = undefined;
|
||||||
|
|
||||||
|
isSupported() {
|
||||||
|
return 'startViewTransition' in document;
|
||||||
|
}
|
||||||
|
|
||||||
|
skipTransitions() {
|
||||||
|
const skipped = !!this.#activeViewTransition;
|
||||||
|
this.#activeViewTransition?.skipTransition();
|
||||||
|
this.#activeViewTransition = null;
|
||||||
|
const onFinished = this.#activeOnFinished;
|
||||||
|
this.#activeOnFinished = undefined;
|
||||||
|
onFinished?.();
|
||||||
|
return skipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
async startTransition({
|
||||||
|
types,
|
||||||
|
prepareOldSnapshot,
|
||||||
|
performUpdate,
|
||||||
|
prepareNewSnapshot,
|
||||||
|
onFinished,
|
||||||
|
}: TransitionRequest) {
|
||||||
|
if (this.#activeViewTransition) {
|
||||||
|
this.skipTransitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedTypes = types ?? [];
|
||||||
|
|
||||||
|
if (!this.isSupported()) {
|
||||||
|
await performUpdate(AbortSignal.timeout(10_000));
|
||||||
|
onFinished?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit('PrepareOldSnapshot', resolvedTypes);
|
||||||
|
prepareOldSnapshot?.();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const update = async () => {
|
||||||
|
await performUpdate(abortController.signal);
|
||||||
|
this.emit('PrepareNewSnapshot', resolvedTypes);
|
||||||
|
prepareNewSnapshot?.();
|
||||||
|
await tick();
|
||||||
|
};
|
||||||
|
|
||||||
|
let transition: ViewTransition;
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
transition = document.startViewTransition({ update, types });
|
||||||
|
} catch {
|
||||||
|
// Fallback: browsers supporting VT Level 1 but not Level 2 (object form with types) will throw
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
transition = document.startViewTransition(update);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#activeViewTransition = transition;
|
||||||
|
this.#activeOnFinished = onFinished;
|
||||||
|
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
void transition.ready.catch((error: unknown) => {
|
||||||
|
abortController.abort(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
void transition.finished
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => {
|
||||||
|
if (this.#activeViewTransition === transition) {
|
||||||
|
this.#activeViewTransition = null;
|
||||||
|
this.#activeOnFinished = undefined;
|
||||||
|
this.emit('Finished', resolvedTypes);
|
||||||
|
onFinished?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line tscompat/tscompat
|
||||||
|
await transition.updateCallbackDone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const viewTransitionManager = new ViewTransitionManager();
|
||||||
@@ -23,12 +23,17 @@ export type Events = {
|
|||||||
Zoom: [];
|
Zoom: [];
|
||||||
ZoomChange: [ZoomImageWheelState];
|
ZoomChange: [ZoomImageWheelState];
|
||||||
Copy: [];
|
Copy: [];
|
||||||
|
ViewerOpenTransitionReady: [];
|
||||||
|
ViewerOpenTransition: [];
|
||||||
|
ViewerCloseTransition: [{ id: string }];
|
||||||
|
ViewerCloseTransitionReady: [];
|
||||||
};
|
};
|
||||||
|
|
||||||
class AssetViewerManager extends BaseEventManager<Events> {
|
class AssetViewerManager extends BaseEventManager<Events> {
|
||||||
#zoomState = $state(createDefaultZoomState());
|
#zoomState = $state(createDefaultZoomState());
|
||||||
#animationFrameId: number | null = null;
|
#animationFrameId: number | null = null;
|
||||||
|
|
||||||
|
transitionName = $state<string | undefined>();
|
||||||
imgRef = $state<HTMLImageElement | undefined>();
|
imgRef = $state<HTMLImageElement | undefined>();
|
||||||
imageLoaderStatus = $state<ImageLoaderStatus | undefined>();
|
imageLoaderStatus = $state<ImageLoaderStatus | undefined>();
|
||||||
#isImageLoading = $derived.by(() => {
|
#isImageLoading = $derived.by(() => {
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ export type Events = {
|
|||||||
ReleaseEvent: [ReleaseEvent];
|
ReleaseEvent: [ReleaseEvent];
|
||||||
|
|
||||||
WebsocketConnect: [];
|
WebsocketConnect: [];
|
||||||
|
|
||||||
|
TimelineLoaded: [{ id: string | null }];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const eventManager = new BaseEventManager<Events>();
|
export const eventManager = new BaseEventManager<Events>();
|
||||||
|
|||||||
@@ -43,6 +43,50 @@ export class BaseEventManager<Events extends EventsBase> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private once<T extends keyof Events>(event: T, callback: EventCallback<Events, T>) {
|
||||||
|
const unsubscribe = this.#onEvent(event, (...args: Events[T]) => {
|
||||||
|
unsubscribe();
|
||||||
|
return callback(...args);
|
||||||
|
});
|
||||||
|
return unsubscribe;
|
||||||
|
}
|
||||||
|
|
||||||
|
untilNext<T extends keyof Events>(
|
||||||
|
event: T,
|
||||||
|
{ timeoutMs = 10_000, signal }: { timeoutMs?: number; signal?: AbortSignal } = {},
|
||||||
|
): Promise<Events[T] extends [] ? void : Events[T][0]> {
|
||||||
|
type Result = Events[T] extends [] ? void : Events[T][0];
|
||||||
|
return new Promise<Result>((resolve, reject) => {
|
||||||
|
let settled = false;
|
||||||
|
const settle = () => {
|
||||||
|
if (settled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
settled = true;
|
||||||
|
unsubscribe();
|
||||||
|
clearTimeout(timer);
|
||||||
|
signal?.removeEventListener('abort', onAbort);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
const unsubscribe = this.once(event, (...args: Events[T]) => {
|
||||||
|
if (settle()) {
|
||||||
|
resolve(args[0] as Result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
if (settle()) {
|
||||||
|
reject(new Error(`untilNext('${String(event)}') timed out after ${timeoutMs}ms`));
|
||||||
|
}
|
||||||
|
}, timeoutMs);
|
||||||
|
const onAbort = () => {
|
||||||
|
if (settle()) {
|
||||||
|
resolve(undefined as Result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
signal?.addEventListener('abort', onAbort, { once: true });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
emit<T extends keyof Events>(event: T, ...params: Events[T]) {
|
emit<T extends keyof Events>(event: T, ...params: Events[T]) {
|
||||||
const listeners = this.getListeners(event);
|
const listeners = this.getListeners(event);
|
||||||
for (const listener of listeners) {
|
for (const listener of listeners) {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { assetViewerManager } from '$lib/managers/asset-viewer-manager.svelte';
|
||||||
|
import { viewTransitionManager } from '$lib/managers/ViewTransitionManager.svelte';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
|
export function startViewerTransition(
|
||||||
|
heroAssetId: string,
|
||||||
|
openViewer: () => void,
|
||||||
|
activateHeroAsset: (assetId: string) => void,
|
||||||
|
deactivateHeroAsset: () => void,
|
||||||
|
) {
|
||||||
|
void viewTransitionManager.startTransition({
|
||||||
|
types: ['viewer'],
|
||||||
|
prepareOldSnapshot: () => {
|
||||||
|
activateHeroAsset(heroAssetId);
|
||||||
|
},
|
||||||
|
performUpdate: async (signal) => {
|
||||||
|
deactivateHeroAsset();
|
||||||
|
const ready = assetViewerManager.untilNext('ViewerOpenTransitionReady', { signal });
|
||||||
|
openViewer();
|
||||||
|
await ready;
|
||||||
|
assetViewerManager.emit('ViewerOpenTransition');
|
||||||
|
await tick();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class:display-none={assetViewerManager.isViewing}>
|
<div class:invisible={assetViewerManager.isViewing}>
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
<UploadCover />
|
<UploadCover />
|
||||||
@@ -31,7 +31,4 @@
|
|||||||
:root {
|
:root {
|
||||||
overscroll-behavior: none;
|
overscroll-behavior: none;
|
||||||
}
|
}
|
||||||
.display-none {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user