feat: animate user and admin drawers
parent
40d32f5bfc
commit
5e71f81c5a
@ -0,0 +1,109 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
const openingFrames = new WeakMap();
|
||||
const closingTransitions = new WeakMap();
|
||||
const transitionFallbackMs = 360;
|
||||
|
||||
function prefersReducedMotion() {
|
||||
return window.matchMedia?.('(prefers-reduced-motion: reduce)').matches === true;
|
||||
}
|
||||
|
||||
function cancelOpening(dialog) {
|
||||
const frames = openingFrames.get(dialog);
|
||||
if (!frames) return;
|
||||
cancelAnimationFrame(frames.first);
|
||||
cancelAnimationFrame(frames.second);
|
||||
openingFrames.delete(dialog);
|
||||
}
|
||||
|
||||
function cancelClosing(dialog) {
|
||||
const transition = closingTransitions.get(dialog);
|
||||
if (transition) transition.cancel();
|
||||
}
|
||||
|
||||
function nativeClose(dialog) {
|
||||
if (dialog.open && typeof dialog.close === 'function') dialog.close();
|
||||
else dialog.removeAttribute('open');
|
||||
}
|
||||
|
||||
function openDrawerWithMotion(dialog) {
|
||||
if (!dialog) return false;
|
||||
cancelOpening(dialog);
|
||||
cancelClosing(dialog);
|
||||
|
||||
if (dialog.open) {
|
||||
dialog.classList.add('is-drawer-visible');
|
||||
return true;
|
||||
}
|
||||
|
||||
dialog.classList.remove('is-drawer-visible');
|
||||
if (typeof dialog.showModal === 'function') dialog.showModal();
|
||||
else dialog.setAttribute('open', 'open');
|
||||
|
||||
if (prefersReducedMotion()) {
|
||||
dialog.classList.add('is-drawer-visible');
|
||||
return true;
|
||||
}
|
||||
|
||||
const frames = { first: 0, second: 0 };
|
||||
frames.first = requestAnimationFrame(() => {
|
||||
frames.second = requestAnimationFrame(() => {
|
||||
openingFrames.delete(dialog);
|
||||
if (dialog.open) dialog.classList.add('is-drawer-visible');
|
||||
});
|
||||
});
|
||||
openingFrames.set(dialog, frames);
|
||||
return true;
|
||||
}
|
||||
|
||||
function closeDrawerWithMotion(dialog) {
|
||||
if (!dialog) return Promise.resolve(false);
|
||||
const active = closingTransitions.get(dialog);
|
||||
if (active) return active.promise;
|
||||
|
||||
cancelOpening(dialog);
|
||||
if (!dialog.open) {
|
||||
dialog.classList.remove('is-drawer-visible');
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
if (prefersReducedMotion() || !dialog.classList.contains('is-drawer-visible')) {
|
||||
dialog.classList.remove('is-drawer-visible');
|
||||
nativeClose(dialog);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
let resolveTransition;
|
||||
let settled = false;
|
||||
let timeout = 0;
|
||||
const finish = closed => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timeout);
|
||||
dialog.removeEventListener('transitionend', onTransitionEnd);
|
||||
dialog.removeEventListener('transitioncancel', onTransitionCancel);
|
||||
closingTransitions.delete(dialog);
|
||||
if (closed) nativeClose(dialog);
|
||||
resolveTransition(closed);
|
||||
};
|
||||
const onTransitionEnd = event => {
|
||||
if (event.target === dialog && event.propertyName === 'transform') finish(true);
|
||||
};
|
||||
const onTransitionCancel = event => {
|
||||
if (event.target === dialog && event.propertyName === 'transform') finish(true);
|
||||
};
|
||||
const promise = new Promise(resolve => { resolveTransition = resolve; });
|
||||
closingTransitions.set(dialog, { promise, cancel: () => finish(false) });
|
||||
dialog.addEventListener('transitionend', onTransitionEnd);
|
||||
dialog.addEventListener('transitioncancel', onTransitionCancel);
|
||||
dialog.classList.remove('is-drawer-visible');
|
||||
timeout = window.setTimeout(() => finish(true), transitionFallbackMs);
|
||||
return promise;
|
||||
}
|
||||
|
||||
window.VenixDrawerMotion = Object.freeze({
|
||||
closeDrawerWithMotion,
|
||||
openDrawerWithMotion,
|
||||
});
|
||||
})();
|
||||
@ -1,2 +1,2 @@
|
||||
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
|
||||
{assign var=venix_asset_version value='2026100304' scope='global'}
|
||||
{assign var=venix_asset_version value='2026100305' scope='global'}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$read = static function (string $path): string {
|
||||
$contents = file_get_contents($path);
|
||||
if (!is_string($contents)) {
|
||||
throw new RuntimeException('Unable to read ' . $path);
|
||||
}
|
||||
return $contents;
|
||||
};
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$motion = $read($root . '/public/cloud/drawer-motion.js');
|
||||
$assert(str_contains($motion, 'window.VenixDrawerMotion = Object.freeze')
|
||||
&& str_contains($motion, 'requestAnimationFrame')
|
||||
&& str_contains($motion, "event.propertyName === 'transform'")
|
||||
&& str_contains($motion, "prefers-reduced-motion: reduce"),
|
||||
'The shared drawer motion controller must coordinate entry, exit and reduced motion.');
|
||||
|
||||
foreach (['account-drawer.js', 'announcements.js', 'admin-instances.js', 'admin-operations.js', 'admin-billing.js'] as $script) {
|
||||
$source = $read($root . '/public/cloud/' . $script);
|
||||
$assert(str_contains($source, 'window.VenixDrawerMotion')
|
||||
&& str_contains($source, 'openDrawerWithMotion')
|
||||
&& str_contains($source, 'closeDrawerWithMotion'),
|
||||
'Drawer runtime does not use the shared motion controller: ' . $script);
|
||||
}
|
||||
|
||||
$accountDrawer = $read($root . '/public/cloud/account-drawer.js');
|
||||
$assert(str_contains($accountDrawer, "event.key === 'Escape'")
|
||||
&& str_contains($accountDrawer, "typeof drawer.showModal !== 'function'"),
|
||||
'The account drawer must retain Escape support when native modal dialogs are unavailable.');
|
||||
|
||||
$adminBilling = $read($root . '/public/cloud/admin-billing.js');
|
||||
$assert(str_contains($adminBilling, 'detailClosePromise')
|
||||
&& str_contains($adminBilling, 'if (closing) await closing;'),
|
||||
'Billing route restoration must wait for an in-flight drawer exit.');
|
||||
|
||||
$userShell = $read($root . '/resources/views/venix/user/panel_topbar.tpl');
|
||||
$adminShell = $read($root . '/resources/views/venix/admin/static_header.tpl');
|
||||
$assert(str_contains($userShell, '/cloud/drawer-motion.js?v={$venix_asset_version')
|
||||
&& str_contains($adminShell, '/cloud/drawer-motion.js?v={$venix_asset_version}'),
|
||||
'The shared drawer motion controller must use the common cache key on user and admin pages.');
|
||||
|
||||
$userCss = $read($root . '/public/cloud/client.css');
|
||||
$adminCss = $read($root . '/public/theme/venix/css/admin-home.css');
|
||||
$assert(str_contains($userCss, '.panel-announcements-drawer.is-drawer-visible')
|
||||
&& str_contains($userCss, '.panel-account-drawer.is-drawer-visible')
|
||||
&& str_contains($userCss, '@media (prefers-reduced-motion: reduce)'),
|
||||
'User drawers must slide from the side and respect reduced motion.');
|
||||
$assert(str_contains($adminCss, '[data-admin-instance-drawer].is-drawer-visible')
|
||||
&& str_contains($adminCss, '@media (prefers-reduced-motion: reduce)'),
|
||||
'Administrator drawers must slide from the side and respect reduced motion.');
|
||||
|
||||
echo "Shared user and administrator drawer motion checks passed.\n";
|
||||
Loading…
Reference in New Issue