fade in prompt metadata transitions (#23037)

This commit is contained in:
Dax
2026-04-17 02:12:41 -04:00
committed by GitHub
parent 7605acff65
commit 65b2a10e97
5 changed files with 87 additions and 22 deletions
@@ -1,7 +1,38 @@
import { createSignal, type Accessor } from "solid-js"
import { createEffect, createSignal, on, onCleanup, type Accessor } from "solid-js"
import { debounce, type Scheduled } from "@solid-primitives/scheduled"
export function createDebouncedSignal<T>(value: T, ms: number): [Accessor<T>, Scheduled<[value: T]>] {
const [get, set] = createSignal(value)
return [get, debounce((v: T) => set(() => v), ms)]
}
export function createFadeIn(show: Accessor<boolean>, enabled: Accessor<boolean>) {
const [alpha, setAlpha] = createSignal(show() ? 1 : 0)
createEffect(
on([show, enabled], ([visible, animate], previous) => {
if (!visible) {
setAlpha(0)
return
}
if (!animate || !previous) {
setAlpha(1)
return
}
const start = performance.now()
setAlpha(0)
const timer = setInterval(() => {
const progress = Math.min((performance.now() - start) / 160, 1)
setAlpha(progress * progress * (3 - 2 * progress))
if (progress >= 1) clearInterval(timer)
}, 16)
onCleanup(() => clearInterval(timer))
}),
)
return alpha
}