* init * fix: electron Signed-off-by: Innei <i@innei.in> * update Signed-off-by: Innei <i@innei.in> * fix: build Signed-off-by: Innei <i@innei.in> * fix: lint Signed-off-by: Innei <i@innei.in> * fix: test Signed-off-by: Innei <i@innei.in> --------- Signed-off-by: Innei <i@innei.in>
24 lines
648 B
TypeScript
24 lines
648 B
TypeScript
import type { ReactEventHandler } from "react"
|
|
|
|
export const stopPropagation: ReactEventHandler<any> = (e) => e.stopPropagation()
|
|
|
|
export const preventDefault: ReactEventHandler<any> = (e) => e.preventDefault()
|
|
|
|
export const nextFrame = (fn: (...args: any[]) => any) => {
|
|
requestAnimationFrame(() => {
|
|
requestAnimationFrame(() => {
|
|
fn()
|
|
})
|
|
})
|
|
}
|
|
|
|
export const getElementTop = (element: HTMLElement) => {
|
|
let actualTop = element.offsetTop
|
|
let current = element.offsetParent as HTMLElement
|
|
while (current !== null) {
|
|
actualTop += current.offsetTop
|
|
current = current.offsetParent as HTMLElement
|
|
}
|
|
return actualTop
|
|
}
|