Something went wrong. Try again.
doll.systems community website
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142import type { PageLink } from '../lib/layouts';import type { PageScope } from './page-scope';import { motionPaused } from './motion';import { updatePreview } from './page-preview';
// Finish the current dissolve using the most recent selection; never queue hover history.export function previewTransition(element: HTMLElement, scope: PageScope) { let pending: PageLink | undefined; const phase = (value?: 'departing' | 'arriving') => { if (value) element.dataset.previewPhase = value; else delete element.dataset.previewPhase; }; function finish() { phase(); if (pending) updatePreview(element, pending); } function advance() { if (!pending || pending.id === element.dataset.selected) return; if (motionPaused()) finish(); else phase('departing'); } scope.on(element, 'animationend', (event) => { if (event.target !== element) return; if (event.animationName === 'ascii-depart' && pending) { updatePreview(element, pending); phase('arriving'); } else if (event.animationName === 'ascii-arrive') { phase(); advance(); } }); scope.on(document, 'motion:change', () => { if (motionPaused()) finish(); }); scope.defer(() => phase()); return (page: PageLink) => { if (pending?.id === page.id) return; pending = page; if (!element.dataset.previewPhase || motionPaused()) advance(); };}