(fn: () => void, type: string)
| 82 | |
| 83 | let globalReduceMotion = false; |
| 84 | function startViewTransition(fn: () => void, type: string) { |
| 85 | if ('startViewTransition' in document) { |
| 86 | // Safari doesn't support :active-view-transition-type() yet, so we fall back to a class on the html element. |
| 87 | document.documentElement.classList.add(toastCss[type]); |
| 88 | if (globalReduceMotion) { |
| 89 | document.documentElement.classList.add(toastCss.reduceMotion); |
| 90 | } |
| 91 | |
| 92 | let viewTransition = document.startViewTransition(() => flushSync(fn)); |
| 93 | |
| 94 | viewTransition.ready.catch(() => {}); |
| 95 | viewTransition.finished.then(() => { |
| 96 | document.documentElement.classList.remove(toastCss[type], toastCss.reduceMotion); |
| 97 | }); |
| 98 | } else { |
| 99 | fn(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // There is a single global toast queue instance for the whole app, initialized lazily. |
| 104 | let globalToastQueue: ToastQueue<SpectrumToastValue> | null = null; |
no test coverage detected