fix(customCursor.ts): move import statement for active to the top for better organization

fix(customCursor.ts): add return type void to onMouse function for clarity
fix(customCursor.ts): add passive option to window event listener for mousemove to improve performance
fix(stageNav.ts): move import statement for setCustomCursor to the top for better organization
fix(stageNav.ts): add return type void to handleClick function for clarity
fix(stageNav.ts): add return type void to handleKey function for clarity
fix(stageNav.ts): add passive option to overlay event listeners for click, keydown, mouseover, and focus to improve performance
fix(stageNav.ts): add passive option to window event listener for keydown to improve performance
fix(stageNav.ts): add return type void to nextImage function for clarity
fix(stageNav.ts): add return type void to prevImage function for clarity
fix(gallery.ts): move import statement for Swiper to the top for better organization
fix(gallery.ts): add return type void to slideUp function for clarity
fix(gallery.ts): add return type void to initGallery function for clarity
fix(gallery.ts): add passive option to window event listener for touchstart to improve performance
fix(gallery.ts): add return type void to changeSlide function for clarity
fix(gallery.ts): add return type void to scrollToActive function for clarity
fix(gallery.ts): add return type void to createGallery function for clarity
fix(gallery.ts): add passive option to close event listeners for click and keydown to improve performance
fix(gallery.ts): add passive option to overlay event listeners for click, keydown, mouseover, and focus to improve performance
fix(gallery.ts): add passive option to window event listener for touchstart to improve performance
fix(nav.ts): add return type void to initNav function for clarity
fix(utils.ts): add return type number to getRandom function for clarity
fix(utils.ts): add return type void to onVisible function for clarity
fix(utils.ts): add return type void to addWatcher function in Watchable class for clarity
This commit is contained in:
Sped0n
2023-11-01 23:07:21 +08:00
parent aefdaa86eb
commit a395513bd6
12 changed files with 194 additions and 99 deletions

View File

@@ -18,14 +18,14 @@ export function isMobile(): boolean {
return window.matchMedia('(hover: none)').matches
}
export function getRandom(min: number, max: number) {
export function getRandom(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min
}
export function onVisible(
element: HTMLImageElement,
callback: (arg0: HTMLImageElement) => void
) {
export function onVisible<T extends Element>(
element: T,
callback: (arg0: T) => void
): void {
new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
@@ -34,7 +34,6 @@ export function onVisible(
}
})
}).observe(element)
if (!callback) return new Promise((r) => (callback = r))
}
/**
@@ -43,7 +42,7 @@ export function onVisible(
export class Watchable<T> {
constructor(private obj: T) {}
private watchers: (() => void)[] = []
private readonly watchers: Array<() => void> = []
get(): T {
return this.obj
@@ -51,7 +50,9 @@ export class Watchable<T> {
set(e: T): void {
this.obj = e
this.watchers.forEach((watcher) => watcher())
this.watchers.forEach((watcher) => {
watcher()
})
}
addWatcher(watcher: () => void): void {