test: lock journey lifecycle and static fallback
This commit is contained in:
@@ -51,6 +51,7 @@ export function useMotionPreferences(): MotionPreferences {
|
||||
let reducedQuery: MediaQueryList | undefined;
|
||||
let coarseQuery: MediaQueryList | undefined;
|
||||
let connection: NetworkInformationLike | undefined;
|
||||
let requiresExplicitEnable = false;
|
||||
let teardown = (): void => {};
|
||||
|
||||
const viewportWidth = (): number => window.visualViewport?.width ?? window.innerWidth;
|
||||
@@ -60,7 +61,7 @@ export function useMotionPreferences(): MotionPreferences {
|
||||
policy.value = resolveMotionPolicy({
|
||||
systemReduce: systemReduce.value,
|
||||
savedPause: paused.value,
|
||||
savedStatic: maximumQuality.value === 'static',
|
||||
savedStatic: maximumQuality.value === 'static' || requiresExplicitEnable,
|
||||
dataSaver: dataSaver.value,
|
||||
width: viewportWidth(),
|
||||
coarsePointer,
|
||||
@@ -79,6 +80,7 @@ export function useMotionPreferences(): MotionPreferences {
|
||||
};
|
||||
|
||||
const setPaused = (value: boolean): void => {
|
||||
if (!value) requiresExplicitEnable = false;
|
||||
paused.value = value;
|
||||
persist(MOTION_PREFERENCE_KEYS.pause, String(value));
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -87,6 +89,7 @@ export function useMotionPreferences(): MotionPreferences {
|
||||
};
|
||||
|
||||
const setMaximumQuality = (value: QualityTier): void => {
|
||||
if (value !== 'static') requiresExplicitEnable = false;
|
||||
maximumQuality.value = value;
|
||||
persist(MOTION_PREFERENCE_KEYS.maximumQuality, value);
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -112,7 +115,9 @@ export function useMotionPreferences(): MotionPreferences {
|
||||
connection = (window.navigator as Navigator & { connection?: NetworkInformationLike }).connection;
|
||||
|
||||
const updateReduced = (): void => {
|
||||
systemReduce.value = reducedQuery?.matches ?? true;
|
||||
const nextSystemReduce = reducedQuery?.matches ?? true;
|
||||
if (systemReduce.value && !nextSystemReduce) requiresExplicitEnable = true;
|
||||
systemReduce.value = nextSystemReduce;
|
||||
updatePolicy();
|
||||
};
|
||||
const updateCoarse = (): void => updatePolicy();
|
||||
|
||||
Reference in New Issue
Block a user