| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| export const ENVIRONMENT_SWITCH_DURATION_MS = 980; |
| export const ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS = 400; |
|
|
| export interface EnvironmentSwitchSnapshot { |
| visible: boolean; |
| target: string; |
| } |
|
|
| let snapshot: EnvironmentSwitchSnapshot = { visible: false, target: "" }; |
| const listeners = new Set<() => void>(); |
| let hideTimeoutId: ReturnType<typeof setTimeout> | null = null; |
|
|
| function setSnapshot(next: EnvironmentSwitchSnapshot) { |
| snapshot = next; |
| if (typeof document !== "undefined") { |
| if (next.visible) { |
| document.body.setAttribute("data-environment-switching", "true"); |
| } else { |
| document.body.removeAttribute("data-environment-switching"); |
| } |
| } |
| listeners.forEach((listener) => listener()); |
| } |
|
|
| export function triggerEnvironmentSwitch(target: string) { |
| setSnapshot({ visible: true, target }); |
| if (hideTimeoutId) clearTimeout(hideTimeoutId); |
| hideTimeoutId = setTimeout(() => { |
| setSnapshot({ visible: false, target: "" }); |
| hideTimeoutId = null; |
| }, ENVIRONMENT_SWITCH_DURATION_MS); |
| } |
|
|
| export function dismissEnvironmentSwitch() { |
| if (hideTimeoutId) { |
| clearTimeout(hideTimeoutId); |
| hideTimeoutId = null; |
| } |
| setSnapshot({ visible: false, target: "" }); |
| } |
|
|
| export function subscribeEnvironmentSwitch(listener: () => void) { |
| listeners.add(listener); |
| return () => { |
| listeners.delete(listener); |
| }; |
| } |
|
|
| export function getEnvironmentSwitchSnapshot() { |
| return snapshot; |
| } |
|
|
| |
|
|
| export function __resetEnvironmentSwitchOverlayForTests() { |
| if (hideTimeoutId) { |
| clearTimeout(hideTimeoutId); |
| hideTimeoutId = null; |
| } |
| setSnapshot({ visible: false, target: "" }); |
| } |
|
|