deepsea-components 2.3.3 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +6 -27
- package/dist/cjs/index.js +74 -66
- package/dist/cjs/index.js.map +3 -3
- package/dist/esm/index.d.ts +6 -27
- package/dist/esm/index.js +106 -104
- package/dist/esm/index.js.map +1 -1
- package/package.json +45 -45
- package/src/index.tsx +76 -91
package/src/index.tsx
CHANGED
|
@@ -501,111 +501,96 @@ export const Trapezium = forwardRef<HTMLDivElement, TrapeziumProps>((props, ref)
|
|
|
501
501
|
return <div ref={ref} style={{ width: bottom, height, clipPath: `path("M ${diff + f} ${0} A ${borderRadius} ${borderRadius} 0 0 0 ${diff - g} ${h} L ${c} ${height - d} A ${borderRadius} ${borderRadius} 0 0 0 ${b} ${height} L ${bottom - b} ${height} A ${borderRadius} ${borderRadius} 0 0 0 ${bottom - c} ${height - d} L ${top + diff + g} ${h} A ${borderRadius} ${borderRadius} 0 0 0 ${top + diff - f} ${0} Z")`, ...style }} {...other} />
|
|
502
502
|
})
|
|
503
503
|
|
|
504
|
-
export interface LoopSwiperProps<
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
/** 每个元素的key */
|
|
510
|
-
keyExactor?: (item: T, index: number, array: T[]) => string
|
|
511
|
-
/** 水平方向是宽度,垂直方向是高度 */
|
|
512
|
-
size: number
|
|
513
|
-
/** 元素之间间隔 */
|
|
514
|
-
gap?: number
|
|
515
|
-
/** 起始位置 */
|
|
516
|
-
start?: number
|
|
517
|
-
/** 速度,水平方向正数为向左,水平方向负数为向右,垂直方向正数为向上,水平方向负数为向下 */
|
|
518
|
-
speed: number
|
|
519
|
-
/** 是否暂停播放 */
|
|
520
|
-
paused?: boolean
|
|
521
|
-
/** 容器的类名 */
|
|
522
|
-
className?: string
|
|
523
|
-
/** x 水平方向,y 垂直方向 */
|
|
524
|
-
direction?: "x" | "y"
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
export interface LoopSwiperItem {
|
|
528
|
-
key: string
|
|
529
|
-
dom: HTMLDivElement | null
|
|
530
|
-
offset: number
|
|
504
|
+
export interface LoopSwiperProps extends HTMLAttributes<HTMLDivElement> {
|
|
505
|
+
direction?: "horizontal" | "vertical"
|
|
506
|
+
reverse?: boolean
|
|
507
|
+
period: number
|
|
508
|
+
gap?: CSSProperties["gap"]
|
|
531
509
|
}
|
|
532
510
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
511
|
+
css`
|
|
512
|
+
@keyframes deepsea-horizontal-loop-swipe {
|
|
513
|
+
from {
|
|
514
|
+
transform: translateX(0);
|
|
515
|
+
}
|
|
516
|
+
to {
|
|
517
|
+
transform: translateX(-100%);
|
|
518
|
+
}
|
|
538
519
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
keysRef.current = keys
|
|
547
|
-
eles.current = keys.map((key, idx) => ({ key, dom: null, offset: idx * (size + gap) + start }))
|
|
520
|
+
@keyframes deepsea-reverse-horizontal-loop-swipe {
|
|
521
|
+
from {
|
|
522
|
+
transform: translateX(0);
|
|
523
|
+
}
|
|
524
|
+
to {
|
|
525
|
+
transform: translateX(100%);
|
|
526
|
+
}
|
|
548
527
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
direction === "x" && speed < 0 ? it.dom!.style.setProperty("right", `0`) : it.dom!.style.setProperty("left", `0`)
|
|
557
|
-
direction === "y" && speed < 0 ? it.dom!.style.setProperty("bottom", `0`) : it.dom!.style.setProperty("top", `0`)
|
|
558
|
-
it.dom!.style.setProperty("transform", `translate${direction.toUpperCase()}(${it.offset * (speed > 0 ? 1 : -1)}px)`)
|
|
559
|
-
})
|
|
528
|
+
@keyframes deepsea-vertical-loop-swipe {
|
|
529
|
+
from {
|
|
530
|
+
transform: translateY(0);
|
|
531
|
+
}
|
|
532
|
+
to {
|
|
533
|
+
transform: translateY(-100%);
|
|
534
|
+
}
|
|
560
535
|
}
|
|
536
|
+
@keyframes deepsea-reverse-vertical-loop-swipe {
|
|
537
|
+
from {
|
|
538
|
+
transform: translateY(0);
|
|
539
|
+
}
|
|
540
|
+
to {
|
|
541
|
+
transform: translateY(100%);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
`
|
|
561
545
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
546
|
+
/** 循环播放组件 */
|
|
547
|
+
export const LoopSwiper = forwardRef<HTMLDivElement, LoopSwiperProps>((props, ref) => {
|
|
548
|
+
const { style, children, direction, period, reverse, gap, ...others } = props
|
|
549
|
+
const wrapper = useRef<HTMLDivElement>(null)
|
|
550
|
+
const container = useRef<HTMLDivElement>(null)
|
|
551
|
+
const [swiper, setSwiper] = useState(false)
|
|
552
|
+
const directionRef = useRef(direction)
|
|
553
|
+
directionRef.current = direction
|
|
554
|
+
const flexDirection: CSSProperties["flexDirection"] = direction === "vertical" ? (reverse ? "column-reverse" : "column") : reverse ? "row-reverse" : "row"
|
|
555
|
+
const animationName = swiper ? (direction === "vertical" ? (reverse ? "deepsea-reverse-vertical-loop-swipe" : "deepsea-vertical-loop-swipe") : reverse ? "deepsea-reverse-horizontal-loop-swipe" : "deepsea-horizontal-loop-swipe") : "none"
|
|
556
|
+
const animationDuration = `${period}ms`
|
|
557
|
+
const animationTimingFunction = "linear"
|
|
558
|
+
const animationIterationCount = "infinite"
|
|
559
|
+
|
|
560
|
+
useImperativeHandle(ref, () => wrapper.current!)
|
|
565
561
|
|
|
566
562
|
useEffect(() => {
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
it.offset = minOffset + (index - minIndex) * (size + gap)
|
|
582
|
-
let newOffset = it.offset - Math.abs(speed)
|
|
583
|
-
if (newOffset + size + gap <= 0) {
|
|
584
|
-
newOffset += eles.current.length * (size + gap)
|
|
563
|
+
const wrapperEle = wrapper.current!
|
|
564
|
+
const containerEle = container.current!
|
|
565
|
+
let wrapperWidth = 0
|
|
566
|
+
let wrapperHeight = 0
|
|
567
|
+
let containerWidth = 0
|
|
568
|
+
let containerHeight = 0
|
|
569
|
+
const observer = new ResizeObserver(entries => {
|
|
570
|
+
entries.forEach(entry => {
|
|
571
|
+
if (entry.target === wrapperEle) {
|
|
572
|
+
wrapperWidth = entry.contentRect.width
|
|
573
|
+
wrapperHeight = entry.contentRect.height
|
|
574
|
+
} else if (entry.target === containerEle) {
|
|
575
|
+
containerWidth = entry.contentRect.width
|
|
576
|
+
containerHeight = entry.contentRect.height
|
|
585
577
|
}
|
|
586
|
-
it.offset = newOffset
|
|
587
578
|
})
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
579
|
+
setSwiper(directionRef.current === "vertical" ? containerHeight > wrapperHeight : containerWidth > wrapperWidth)
|
|
580
|
+
})
|
|
581
|
+
observer.observe(wrapperEle)
|
|
582
|
+
observer.observe(containerEle)
|
|
592
583
|
}, [])
|
|
593
584
|
|
|
594
|
-
function ref(dom: HTMLDivElement | null, index: number) {
|
|
595
|
-
if (!eles.current[index]) return
|
|
596
|
-
eles.current[index].dom = dom
|
|
597
|
-
}
|
|
598
|
-
|
|
599
585
|
return (
|
|
600
|
-
<
|
|
601
|
-
{
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
</Fragment>
|
|
586
|
+
<div ref={wrapper} style={{ display: "flex", flexDirection, gap, ...style }} {...others}>
|
|
587
|
+
<div ref={container} style={{ display: "flex", flexDirection, gap, animationName, animationTimingFunction, animationDuration, animationIterationCount }}>
|
|
588
|
+
{children}
|
|
589
|
+
</div>
|
|
590
|
+
<div style={{ display: swiper ? "flex" : "none", flexDirection, gap, animationName, animationTimingFunction, animationDuration, animationIterationCount }}>{children}</div>
|
|
591
|
+
</div>
|
|
607
592
|
)
|
|
608
|
-
}
|
|
593
|
+
})
|
|
609
594
|
|
|
610
595
|
export interface SectionRingProps extends HTMLAttributes<HTMLDivElement> {
|
|
611
596
|
outerRadius: number
|