mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-23 20:06:37 +08:00
perf(projects): add type declaration for document startViewTransition
This commit is contained in:
parent
cbda4a38a3
commit
d3ebe95076
@ -34,21 +34,25 @@ const darkMode = computed({
|
||||
}
|
||||
});
|
||||
|
||||
function handleSwitch(event: MouseEvent) {
|
||||
async function handleSwitch(event: MouseEvent) {
|
||||
const x = event.clientX;
|
||||
const y = event.clientY;
|
||||
const endRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
|
||||
// @ts-expect-error: Transition API
|
||||
|
||||
if (!document.startViewTransition) {
|
||||
darkMode.value = !darkMode.value;
|
||||
return;
|
||||
}
|
||||
// @ts-expect-error: Transition API
|
||||
|
||||
const endRadius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y));
|
||||
|
||||
const transition = document.startViewTransition(() => {
|
||||
darkMode.value = !darkMode.value;
|
||||
});
|
||||
transition.ready.then(() => {
|
||||
|
||||
await transition.ready;
|
||||
|
||||
const clipPath = [`circle(0px at ${x}px ${y}px)`, `circle(${endRadius}px at ${x}px ${y}px)`];
|
||||
|
||||
document.documentElement.animate(
|
||||
{
|
||||
clipPath: darkMode.value ? clipPath : [...clipPath].reverse()
|
||||
@ -59,7 +63,6 @@ function handleSwitch(event: MouseEvent) {
|
||||
pseudoElement: darkMode.value ? '::view-transition-new(root)' : '::view-transition-old(root)'
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
8
src/typings/global.d.ts
vendored
8
src/typings/global.d.ts
vendored
@ -5,6 +5,14 @@ interface Window {
|
||||
$notification?: import('naive-ui').NotificationProviderInst;
|
||||
}
|
||||
|
||||
interface ViewTransition {
|
||||
ready: Promise<void>;
|
||||
}
|
||||
|
||||
interface Document {
|
||||
startViewTransition?: (callback: () => Promise<void> | void) => ViewTransition;
|
||||
}
|
||||
|
||||
/** 通用类型 */
|
||||
declare namespace Common {
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user