Skip to content

Commit

Permalink
fix: fix Illegal invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue committed Sep 14, 2024
1 parent 3b9fd15 commit a1f298d
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions lib/handle-toggle-click.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import { toggleTheme } from './theme'

type StartViewTransition = (
updateCallback?: () => void | Promise<void>,
) => ViewTransition | undefined

type ViewTransition = {
finished?: Promise<void>
ready?: Promise<void>
updateCallbackDone?: Promise<void>
}

async function startCircleAnimation(
callback: () => void,
x: number,
y: number,
) {
const startViewTransition = (
document as unknown as { startViewTransition?: StartViewTransition }
).startViewTransition
const doc = document as unknown as {
startViewTransition?: (updateCallback?: () => unknown) => {
ready?: Promise<void>
}
}

if (typeof startViewTransition !== 'function') {
if (typeof doc.startViewTransition !== 'function') {
callback()
return
}

await startViewTransition(() => {
await doc.startViewTransition(() => {
callback()
})?.ready

Expand Down

0 comments on commit a1f298d

Please sign in to comment.