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

@@ -21,7 +21,6 @@ const thresholds = [
const defaultState = {
index: -1,
nextFive: new Array(), // for preload
length: 0,
threshold: thresholds[2].threshold,
trailLength: thresholds[2].trailLength
@@ -36,7 +35,6 @@ export const state = new Watchable<State>(defaultState)
export function initState(length: number): void {
const s = state.get()
s.length = length
s.nextFive = getNextFive(s.index, s.length)
state.set(s)
state.addWatcher(() => {
updateIndexText()
@@ -47,21 +45,18 @@ export function initState(length: number): void {
export function setIndex(index: number): void {
const s = state.get()
s.index = index
s.nextFive = getNextFive(s.index, s.length)
state.set(s)
}
export function incIndex(): void {
const s = state.get()
s.index = increment(s.index, s.length)
s.nextFive = getNextFive(s.index, s.length)
state.set(s)
}
export function decIndex(): void {
const s = state.get()
s.index = decrement(s.index, s.length)
s.nextFive = getNextFive(s.index, s.length)
state.set(s)
}
@@ -82,17 +77,9 @@ export function decThreshold(): void {
*/
function updateThreshold(state: State, inc: number): State {
const i = thresholds.findIndex((t) => state.threshold === t.threshold)
const newItems = thresholds[i + inc]
// out of range
if (!newItems) return state
const i = thresholds.findIndex((t) => state.threshold === t.threshold) + inc
// out of bounds
if (i < 0 || i >= thresholds.length) return state
const newItems = thresholds[i]
return { ...state, ...newItems }
}
export function getNextFive(index: number, length: number): number[] {
const five = []
for (let i = 0; i < 5; i++) {
five.push(increment(index + i, length))
}
return five
}