mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* chore: [virtual-list] remove ts-nocheck directive and unused code * chore: remove compatible code * chore: add line --------- Co-authored-by: warmthsea <2586244885@qq.com>
89 lines
1.9 KiB
TypeScript
89 lines
1.9 KiB
TypeScript
import {
|
|
BACKWARD,
|
|
FORWARD,
|
|
HORIZONTAL,
|
|
LTR,
|
|
RTL,
|
|
RTL_OFFSET_NAG,
|
|
RTL_OFFSET_POS_ASC,
|
|
RTL_OFFSET_POS_DESC,
|
|
} from './defaults'
|
|
|
|
import type { CSSProperties } from 'vue'
|
|
import type { Direction, RTLOffsetType } from './types'
|
|
|
|
export const getScrollDir = (prev: number, cur: number) =>
|
|
prev < cur ? FORWARD : BACKWARD
|
|
|
|
export const isHorizontal = (dir: string) =>
|
|
dir === LTR || dir === RTL || dir === HORIZONTAL
|
|
|
|
export const isRTL = (dir: Direction) => dir === RTL
|
|
|
|
let cachedRTLResult: RTLOffsetType | null = null
|
|
|
|
export function getRTLOffsetType(recalculate = false): RTLOffsetType {
|
|
if (cachedRTLResult === null || recalculate) {
|
|
const outerDiv = document.createElement('div')
|
|
const outerStyle = outerDiv.style
|
|
outerStyle.width = '50px'
|
|
outerStyle.height = '50px'
|
|
outerStyle.overflow = 'scroll'
|
|
outerStyle.direction = 'rtl'
|
|
|
|
const innerDiv = document.createElement('div')
|
|
const innerStyle = innerDiv.style
|
|
innerStyle.width = '100px'
|
|
innerStyle.height = '100px'
|
|
|
|
outerDiv.appendChild(innerDiv)
|
|
|
|
document.body.appendChild(outerDiv)
|
|
|
|
if (outerDiv.scrollLeft > 0) {
|
|
cachedRTLResult = RTL_OFFSET_POS_DESC
|
|
} else {
|
|
outerDiv.scrollLeft = 1
|
|
if (outerDiv.scrollLeft === 0) {
|
|
cachedRTLResult = RTL_OFFSET_NAG
|
|
} else {
|
|
cachedRTLResult = RTL_OFFSET_POS_ASC
|
|
}
|
|
}
|
|
|
|
document.body.removeChild(outerDiv)
|
|
|
|
return cachedRTLResult
|
|
}
|
|
|
|
return cachedRTLResult
|
|
}
|
|
|
|
type RenderThumbStyleParams = {
|
|
bar: {
|
|
size: 'height' | 'width'
|
|
axis: 'X' | 'Y'
|
|
}
|
|
size: string
|
|
move: number
|
|
}
|
|
|
|
export function renderThumbStyle(
|
|
{ move, size, bar }: RenderThumbStyleParams,
|
|
layout: string
|
|
) {
|
|
const style: CSSProperties = {}
|
|
const translate = `translate${bar.axis}(${move}px)`
|
|
|
|
style[bar.size] = size
|
|
style.transform = translate
|
|
|
|
if (layout === 'horizontal') {
|
|
style.height = '100%'
|
|
} else {
|
|
style.width = '100%'
|
|
}
|
|
|
|
return style
|
|
}
|