mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-22 14:09:30 -07:00
dump layerPosSet, now FIFO can handle most part of position passing
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import { overlayEnable } from './overlay'
|
import { overlayEnable } from './overlay'
|
||||||
import {
|
import {
|
||||||
styleCache,
|
|
||||||
FIFO,
|
FIFO,
|
||||||
layersStyleSet,
|
layerPosSet,
|
||||||
center,
|
center,
|
||||||
type position,
|
type position,
|
||||||
createImgElement,
|
createImgElement,
|
||||||
@@ -23,10 +22,11 @@ export const layers: HTMLDivElement[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// layers position caching
|
// layers position caching
|
||||||
export const layersStyleArray: string[][] = [
|
let topLayerPos: number[] = [0, 0]
|
||||||
['0px', '0px', '0px', '0px', '0px'],
|
|
||||||
['0px', '0px', '0px', '0px', '0px']
|
export const topLayerPosSet = (): void => {
|
||||||
]
|
layerPosSet(topLayerPos[0], topLayerPos[1], layers[4])
|
||||||
|
}
|
||||||
|
|
||||||
// global index for "activated"
|
// global index for "activated"
|
||||||
export let globalIndex: number = 0
|
export let globalIndex: number = 0
|
||||||
@@ -37,9 +37,9 @@ let last: position = { x: 0, y: 0 }
|
|||||||
// activate top image
|
// activate top image
|
||||||
const activate = (index: number, x: number, y: number): void => {
|
const activate = (index: number, x: number, y: number): void => {
|
||||||
const imgElem: HTMLImageElement = createImgElement(imagesArray[index])
|
const imgElem: HTMLImageElement = createImgElement(imagesArray[index])
|
||||||
styleCache(x, y, layersStyleArray)
|
topLayerPos = [x, y]
|
||||||
layersStyleSet(layersStyleArray, layers)
|
FIFO(imgElem, layers, true)
|
||||||
FIFO(imgElem, layers)
|
topLayerPosSet()
|
||||||
last = { x, y }
|
last = { x, y }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +66,6 @@ export const handleOnMove = (e: MouseEvent): void => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function enterOverlay(): Promise<void> {
|
async function enterOverlay(): Promise<void> {
|
||||||
layers[4].style.backgroundImage = ''
|
|
||||||
const topLayerImage = layers[4].lastElementChild as HTMLImageElement
|
|
||||||
topLayerImage.style.transition = ''
|
|
||||||
// stop images animation
|
// stop images animation
|
||||||
window.removeEventListener('mousemove', handleOnMove)
|
window.removeEventListener('mousemove', handleOnMove)
|
||||||
// set top image
|
// set top image
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
delay,
|
delay,
|
||||||
layersStyleSet,
|
|
||||||
center,
|
center,
|
||||||
createImgElement,
|
createImgElement,
|
||||||
calcImageIndex,
|
calcImageIndex,
|
||||||
@@ -8,12 +7,12 @@ import {
|
|||||||
mouseToTransform
|
mouseToTransform
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import {
|
import {
|
||||||
layersStyleArray,
|
|
||||||
layers,
|
layers,
|
||||||
handleOnMove,
|
handleOnMove,
|
||||||
globalIndex,
|
globalIndex,
|
||||||
globalIndexDec,
|
globalIndexDec,
|
||||||
globalIndexInc
|
globalIndexInc,
|
||||||
|
topLayerPosSet
|
||||||
} from './desktop'
|
} from './desktop'
|
||||||
import { imagesArray, imagesArrayLen } from './dataFetch'
|
import { imagesArray, imagesArrayLen } from './dataFetch'
|
||||||
import { imgIndexSpanUpdate } from './indexDisp'
|
import { imgIndexSpanUpdate } from './indexDisp'
|
||||||
@@ -33,14 +32,7 @@ const setCursorText = (text: string): void => {
|
|||||||
|
|
||||||
// overlay cursor event handler
|
// overlay cursor event handler
|
||||||
const setTextPos = (e: MouseEvent): void => {
|
const setTextPos = (e: MouseEvent): void => {
|
||||||
// overlayCursor.style.left = `${e.clientX}px`
|
overlayCursor.style.transform = mouseToTransform(e.clientX, e.clientY, false, true)
|
||||||
// overlayCursor.style.top = `${e.clientY}px`
|
|
||||||
overlayCursor.style.transform = mouseToTransform(
|
|
||||||
`${e.clientX}px`,
|
|
||||||
`${e.clientY}px`,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable listeners
|
// disable listeners
|
||||||
@@ -67,7 +59,7 @@ export const overlayDisable = (): void => {
|
|||||||
// handle close click
|
// handle close click
|
||||||
async function handleCloseClick(): Promise<void> {
|
async function handleCloseClick(): Promise<void> {
|
||||||
overlayDisable()
|
overlayDisable()
|
||||||
layersStyleSet(layersStyleArray, layers)
|
topLayerPosSet()
|
||||||
for (let i: number = 4; i >= 0; i--) {
|
for (let i: number = 4; i >= 0; i--) {
|
||||||
layers[i].dataset.status = `r${4 - i}`
|
layers[i].dataset.status = `r${4 - i}`
|
||||||
}
|
}
|
||||||
@@ -81,14 +73,14 @@ async function handleCloseClick(): Promise<void> {
|
|||||||
const handlePrevClick = (): void => {
|
const handlePrevClick = (): void => {
|
||||||
globalIndexDec()
|
globalIndexDec()
|
||||||
const imgIndex = calcImageIndex(globalIndex, imagesArrayLen)
|
const imgIndex = calcImageIndex(globalIndex, imagesArrayLen)
|
||||||
FIFO(createImgElement(imagesArray[imgIndex]), layers)
|
FIFO(createImgElement(imagesArray[imgIndex]), layers, false)
|
||||||
imgIndexSpanUpdate(imgIndex + 1, imagesArrayLen)
|
imgIndexSpanUpdate(imgIndex + 1, imagesArrayLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleNextClick = (): void => {
|
const handleNextClick = (): void => {
|
||||||
globalIndexInc()
|
globalIndexInc()
|
||||||
const imgIndex = calcImageIndex(globalIndex, imagesArrayLen)
|
const imgIndex = calcImageIndex(globalIndex, imagesArrayLen)
|
||||||
FIFO(createImgElement(imagesArray[imgIndex]), layers)
|
FIFO(createImgElement(imagesArray[imgIndex]), layers, false)
|
||||||
imgIndexSpanUpdate(imgIndex + 1, imagesArrayLen)
|
imgIndexSpanUpdate(imgIndex + 1, imagesArrayLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,16 +18,6 @@ export interface deviceType {
|
|||||||
desktop: boolean
|
desktop: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache a xy position to array
|
|
||||||
export const styleCache = (x: number, y: number, styleArray: string[][]): void => {
|
|
||||||
// pop element if length surpass limitation
|
|
||||||
styleArray[0].shift()
|
|
||||||
styleArray[1].shift()
|
|
||||||
// push new element
|
|
||||||
styleArray[0].push(`${x}px`)
|
|
||||||
styleArray[1].push(`${y}px`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0 to 0001, 25 to 0025
|
// 0 to 0001, 25 to 0025
|
||||||
export const duper = (num: number): string => {
|
export const duper = (num: number): string => {
|
||||||
return ('0000' + num.toString()).slice(-4)
|
return ('0000' + num.toString()).slice(-4)
|
||||||
@@ -37,7 +27,7 @@ export const duper = (num: number): string => {
|
|||||||
export const FIFO = (
|
export const FIFO = (
|
||||||
element: HTMLImageElement,
|
element: HTMLImageElement,
|
||||||
layersArray: HTMLDivElement[],
|
layersArray: HTMLDivElement[],
|
||||||
fifoPosition: boolean = true
|
passPosition: boolean = true
|
||||||
): void => {
|
): void => {
|
||||||
function layerProcess(layerL: HTMLDivElement, layerH: HTMLDivElement): void {
|
function layerProcess(layerL: HTMLDivElement, layerH: HTMLDivElement): void {
|
||||||
if (layerL.childElementCount !== 0)
|
if (layerL.childElementCount !== 0)
|
||||||
@@ -45,7 +35,7 @@ export const FIFO = (
|
|||||||
if (layerH.childElementCount !== 0) {
|
if (layerH.childElementCount !== 0) {
|
||||||
const layerHNode = layerH.lastElementChild as HTMLImageElement
|
const layerHNode = layerH.lastElementChild as HTMLImageElement
|
||||||
layerL.appendChild(layerHNode.cloneNode(true))
|
layerL.appendChild(layerHNode.cloneNode(true))
|
||||||
if (fifoPosition) layerL.style.transform = layerH.style.transform
|
if (passPosition) layerL.style.transform = layerH.style.transform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i: number = 0; i <= 3; i++) {
|
for (let i: number = 0; i <= 3; i++) {
|
||||||
@@ -57,27 +47,19 @@ export const FIFO = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const mouseToTransform = (
|
export const mouseToTransform = (
|
||||||
x: string,
|
x: number,
|
||||||
y: string,
|
y: number,
|
||||||
centerCorrection: boolean = true,
|
centerCorrection: boolean = true,
|
||||||
accelerate: boolean = false
|
accelerate: boolean = false
|
||||||
): string => {
|
): string => {
|
||||||
return `translate${accelerate ? '3d' : ''}(${
|
return `translate${accelerate ? '3d' : ''}(${
|
||||||
centerCorrection ? `calc(${x} - 50%)` : `${x}`
|
centerCorrection ? `calc(${x}px - 50%)` : `${x}px`
|
||||||
}, ${centerCorrection ? `calc(${y} - 50%)` : `${y}`}${accelerate ? ', 0' : ''})`
|
}, ${centerCorrection ? `calc(${y}px - 50%)` : `${y}px`}${accelerate ? ', 0' : ''})`
|
||||||
}
|
}
|
||||||
|
|
||||||
// set position for 5 image display layers
|
// set position for layer
|
||||||
export const layersStyleSet = (
|
export const layerPosSet = (x: number, y: number, layer: HTMLDivElement): void => {
|
||||||
styleArray: string[][],
|
layer.style.transform = mouseToTransform(x, y)
|
||||||
layersArray: HTMLDivElement[]
|
|
||||||
): void => {
|
|
||||||
function posSet(layer: HTMLDivElement, index: number): void {
|
|
||||||
layer.style.transform = mouseToTransform(styleArray[0][index], styleArray[1][index])
|
|
||||||
}
|
|
||||||
for (let i = 4; i >= 0; i--) {
|
|
||||||
posSet(layersArray[i], i)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
||||||
@@ -99,7 +81,7 @@ export const center = (e: HTMLDivElement): void => {
|
|||||||
} else {
|
} else {
|
||||||
y = (window.innerHeight - 31) / 2 + 31
|
y = (window.innerHeight - 31) / 2 + 31
|
||||||
}
|
}
|
||||||
e.style.transform = mouseToTransform(`${x}px`, `${y}px`)
|
e.style.transform = mouseToTransform(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createImgElement = (input: ImageData): HTMLImageElement => {
|
export const createImgElement = (input: ImageData): HTMLImageElement => {
|
||||||
|
|||||||
Reference in New Issue
Block a user