deepsea-components 5.7.4 → 5.7.5
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/components/AutoFit.js +1 -1
- package/dist/cjs/components/AutoFit.js.map +2 -2
- package/dist/cjs/components/AutoScroll.js +1 -1
- package/dist/cjs/components/AutoScroll.js.map +2 -2
- package/dist/cjs/components/AutoSizeTextarea.js +1 -1
- package/dist/cjs/components/AutoSizeTextarea.js.map +2 -2
- package/dist/cjs/components/CopyButton.d.ts +7 -3
- package/dist/cjs/components/CopyButton.js.map +2 -2
- package/dist/cjs/components/Echart.d.ts +2 -2
- package/dist/cjs/components/Echart.js.map +1 -1
- package/dist/cjs/components/Flow.js +1 -1
- package/dist/cjs/components/Flow.js.map +2 -2
- package/dist/cjs/components/FormLabel.d.ts +2 -2
- package/dist/cjs/components/FormLabel.js +1 -1
- package/dist/cjs/components/FormLabel.js.map +2 -2
- package/dist/cjs/components/InfiniteScroll.d.ts +26 -3
- package/dist/cjs/components/InfiniteScroll.js +1 -1
- package/dist/cjs/components/InfiniteScroll.js.map +2 -2
- package/dist/cjs/components/LoopSwiper.js +1 -1
- package/dist/cjs/components/LoopSwiper.js.map +2 -2
- package/dist/cjs/components/Ring.js.map +1 -1
- package/dist/cjs/components/Scroll.d.ts +1 -1
- package/dist/cjs/components/Scroll.js +1 -1
- package/dist/cjs/components/Scroll.js.map +2 -2
- package/dist/cjs/components/Skeleton.js +1 -1
- package/dist/cjs/components/Skeleton.js.map +2 -2
- package/dist/cjs/components/Title.d.ts +2 -2
- package/dist/cjs/components/Title.js.map +2 -2
- package/dist/cjs/components/TransitionBox.js.map +1 -1
- package/dist/cjs/components/Trapezium.js +1 -1
- package/dist/cjs/components/Trapezium.js.map +2 -2
- package/dist/esm/components/AutoFit.js +1 -1
- package/dist/esm/components/AutoFit.js.map +1 -1
- package/dist/esm/components/AutoScroll.js +1 -1
- package/dist/esm/components/AutoScroll.js.map +1 -1
- package/dist/esm/components/AutoSizeTextarea.js +1 -1
- package/dist/esm/components/AutoSizeTextarea.js.map +1 -1
- package/dist/esm/components/CopyButton.d.ts +7 -3
- package/dist/esm/components/CopyButton.js.map +1 -1
- package/dist/esm/components/Echart.d.ts +2 -2
- package/dist/esm/components/Echart.js.map +1 -1
- package/dist/esm/components/Flow.js +1 -1
- package/dist/esm/components/Flow.js.map +1 -1
- package/dist/esm/components/FormLabel.d.ts +2 -2
- package/dist/esm/components/FormLabel.js +1 -1
- package/dist/esm/components/FormLabel.js.map +1 -1
- package/dist/esm/components/InfiniteScroll.d.ts +26 -3
- package/dist/esm/components/InfiniteScroll.js +1 -1
- package/dist/esm/components/InfiniteScroll.js.map +1 -1
- package/dist/esm/components/LoopSwiper.js +1 -1
- package/dist/esm/components/LoopSwiper.js.map +1 -1
- package/dist/esm/components/Ring.js.map +1 -1
- package/dist/esm/components/Scroll.d.ts +1 -1
- package/dist/esm/components/Scroll.js +1 -1
- package/dist/esm/components/Scroll.js.map +1 -1
- package/dist/esm/components/Skeleton.js +1 -1
- package/dist/esm/components/Skeleton.js.map +1 -1
- package/dist/esm/components/Title.d.ts +2 -2
- package/dist/esm/components/Title.js.map +1 -1
- package/dist/esm/components/TransitionBox.js.map +1 -1
- package/dist/esm/components/Trapezium.js +1 -1
- package/dist/esm/components/Trapezium.js.map +1 -1
- package/package.json +2 -2
- package/src/components/AutoFit.tsx +3 -2
- package/src/components/AutoScroll.tsx +3 -2
- package/src/components/AutoSizeTextarea.tsx +3 -2
- package/src/components/CopyButton.tsx +2 -2
- package/src/components/Echart.tsx +5 -5
- package/src/components/Flow.tsx +2 -1
- package/src/components/FormLabel.tsx +4 -3
- package/src/components/InfiniteScroll.tsx +4 -3
- package/src/components/LoopSwiper.tsx +3 -2
- package/src/components/Ring.tsx +1 -1
- package/src/components/Scroll.tsx +5 -3
- package/src/components/Skeleton.tsx +3 -2
- package/src/components/Title.tsx +3 -2
- package/src/components/TransitionBox.tsx +1 -1
- package/src/components/Trapezium.tsx +2 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type TitleProps =
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export type TitleProps = ComponentPropsWithoutRef<"title">;
|
|
3
3
|
export declare const Title: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTitleElement>, HTMLTitleElement>, "ref"> & import("react").RefAttributes<HTMLTitleElement>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/Title.tsx"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { ComponentPropsWithoutRef, forwardRef, useImperativeHandle, useLayoutEffect, useRef } from \"react\"\nimport { createPortal } from \"react-dom\"\n\nimport { getReactVersion } from \"../utils/getReactVersion\"\n\nexport type TitleProps = ComponentPropsWithoutRef<\"title\">\n\nconst [major] = getReactVersion()\n\nexport const Title = forwardRef<HTMLTitleElement, TitleProps>((props, ref) => {\n if (major >= 19) return <title ref={ref} {...props} />\n\n const ele = useRef<HTMLTitleElement>(null)\n\n useImperativeHandle(ref, () => ele.current as HTMLTitleElement, [ele.current])\n\n useLayoutEffect(() => {\n const title = document.head.querySelector(\"title\")\n if (title === ele.current) return\n document.head.insertBefore(ele.current as HTMLTitleElement, title)\n }, [])\n\n return createPortal(<title ref={ele} {...props} />, document.head)\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmG;AACnG,uBAA6B;AAE7B,6BAAgC;AAIhC,IAAM,CAAC,KAAK,QAAI,wCAAgB;AAEzB,IAAM,YAAQ,yBAAyC,CAAC,OAAO,QAAQ;AAC1E,MAAI,SAAS;AAAI,WAAO,oCAAC,WAAM,KAAW,GAAG,OAAO;AAEpD,QAAM,UAAM,qBAAyB,IAAI;AAEzC,wCAAoB,KAAK,MAAM,IAAI,SAA6B,CAAC,IAAI,OAAO,CAAC;AAE7E,oCAAgB,MAAM;AAClB,UAAM,QAAQ,SAAS,KAAK,cAAc,OAAO;AACjD,QAAI,UAAU,IAAI;AAAS;AAC3B,aAAS,KAAK,aAAa,IAAI,SAA6B,KAAK;AAAA,EACrE,GAAG,CAAC,CAAC;AAEL,aAAO,+BAAa,oCAAC,WAAM,KAAK,KAAM,GAAG,OAAO,GAAI,SAAS,IAAI;AACrE,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/TransitionBox.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport { useSize } from \"ahooks\"\nimport { CSSProperties, FC,
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport { useSize } from \"ahooks\"\nimport { CSSProperties, FC, HTMLAttributes, forwardRef, useEffect, useRef, useState } from \"react\"\n\nexport interface TransitionBoxProps extends HTMLAttributes<HTMLDivElement> {\n containerClassName?: string\n containerStyle?: CSSProperties\n vertical?: boolean\n horizontal?: boolean\n time?: number\n}\n\n/** 尺寸渐变的组件 */\nexport const TransitionBox: FC<TransitionBoxProps> = forwardRef<HTMLDivElement, TransitionBoxProps>((props, ref) => {\n const { style, containerClassName, containerStyle, children, vertical = true, horizontal = true, time = 3000, ...rest } = props\n const container = useRef<HTMLDivElement>(null)\n const size = useSize(container)\n const width = size?.width ?? 0\n const height = size?.height ?? 0\n const [count, setCount] = useState(0)\n\n useEffect(() => {\n setCount(count => Math.min(count + 1, 3))\n }, [width, height])\n\n const outerStyle: CSSProperties = {\n transitionProperty: count === 3 ? [horizontal && \"width\", vertical && \"height\"].filter(Boolean).join(\", \") : undefined,\n transitionDuration: count === 3 ? `${time}ms` : undefined,\n width,\n height,\n overflow: \"hidden\",\n position: \"relative\",\n ...style,\n }\n\n return (\n <div ref={ref} style={outerStyle} {...rest}>\n <div className={containerClassName} style={{ position: \"absolute\", ...containerStyle }} ref={container}>\n {children}\n </div>\n </div>\n )\n})\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAwB;AACxB,mBAA2F;AAWpF,IAAM,oBAAwC,yBAA+C,CAAC,OAAO,QAAQ;AAChH,QAAM,EAAE,OAAO,oBAAoB,gBAAgB,UAAU,WAAW,MAAM,aAAa,MAAM,OAAO,KAAM,GAAG,KAAK,IAAI;AAC1H,QAAM,gBAAY,qBAAuB,IAAI;AAC7C,QAAM,WAAO,uBAAQ,SAAS;AAC9B,QAAM,QAAQ,MAAM,SAAS;AAC7B,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAS,CAAC;AAEpC,8BAAU,MAAM;AACZ,aAAS,CAAAA,WAAS,KAAK,IAAIA,SAAQ,GAAG,CAAC,CAAC;AAAA,EAC5C,GAAG,CAAC,OAAO,MAAM,CAAC;AAElB,QAAM,aAA4B;AAAA,IAC9B,oBAAoB,UAAU,IAAI,CAAC,cAAc,SAAS,YAAY,QAAQ,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI,IAAI;AAAA,IAC7G,oBAAoB,UAAU,IAAI,GAAG,WAAW;AAAA,IAChD;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,UAAU;AAAA,IACV,GAAG;AAAA,EACP;AAEA,SACI,oCAAC,SAAI,KAAU,OAAO,YAAa,GAAG,QAClC,oCAAC,SAAI,WAAW,oBAAoB,OAAO,EAAE,UAAU,YAAY,GAAG,eAAe,GAAG,KAAK,aACxF,QACL,CACJ;AAER,CAAC;",
|
|
6
6
|
"names": ["count"]
|
|
7
7
|
}
|
|
@@ -23,9 +23,9 @@ __export(Trapezium_exports, {
|
|
|
23
23
|
Trapezium: () => Trapezium
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(Trapezium_exports);
|
|
26
|
-
var import_css = require("@emotion/css");
|
|
27
26
|
var import_deepsea_tools = require("deepsea-tools");
|
|
28
27
|
var import_react = require("react");
|
|
28
|
+
var import_css = require("@emotion/css");
|
|
29
29
|
var import_utils = require("../utils");
|
|
30
30
|
var Trapezium = (0, import_react.forwardRef)((props, ref) => {
|
|
31
31
|
const { top, bottom, height, borderRadius, className, style, ...rest } = props;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/Trapezium.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport { clsx } from \"deepsea-tools\"\nimport { HTMLAttributes, forwardRef } from \"react\"\n\nimport { css } from \"@emotion/css\"\nimport { px, transformCSSVariable } from \"../utils\"\n\nexport interface TrapeziumProps extends HTMLAttributes<HTMLDivElement> {\n top: number\n bottom: number\n height: number\n borderRadius: number\n}\n\n/** 梯形组件 */\nexport const Trapezium = forwardRef<HTMLDivElement, TrapeziumProps>((props, ref) => {\n const { top, bottom, height, borderRadius, className, style, ...rest } = props\n\n const diff = (bottom - top) / 2\n\n const a = Math.atan(height / diff) / 2\n\n const b = borderRadius / Math.tan(a)\n\n const c = b * Math.cos(a * 2)\n\n const d = b * Math.sin(a * 2)\n\n const e = Math.PI / 2 - a\n\n const f = borderRadius / Math.tan(e)\n\n const g = f * Math.cos(a * 2)\n\n const h = f * Math.sin(a * 2)\n\n return (\n <div\n ref={ref}\n className={clsx(\n css`\n width: var(--width);\n height: var(--height);\n clip-path: var(--clip-path);\n `,\n className,\n )}\n style={transformCSSVariable(\n {\n width: px(bottom),\n height: px(height),\n clipath: `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\")`,\n },\n style,\n )}\n {...rest}\n />\n )\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAAqB;AACrB,mBAA2C;AAE3C,iBAAoB;AACpB,mBAAyC;AAUlC,IAAM,gBAAY,yBAA2C,CAAC,OAAO,QAAQ;AAChF,QAAM,EAAE,KAAK,QAAQ,QAAQ,cAAc,WAAW,OAAO,GAAG,KAAK,IAAI;AAEzE,QAAM,QAAQ,SAAS,OAAO;AAE9B,QAAM,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI;AAErC,QAAM,IAAI,eAAe,KAAK,IAAI,CAAC;AAEnC,QAAM,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC;AAE5B,QAAM,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC;AAE5B,QAAM,IAAI,KAAK,KAAK,IAAI;AAExB,QAAM,IAAI,eAAe,KAAK,IAAI,CAAC;AAEnC,QAAM,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC;AAE5B,QAAM,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC;AAE5B,SACI;AAAA,IAAC;AAAA;AAAA,MACG;AAAA,MACA,eAAW;AAAA,QACP;AAAA;AAAA;AAAA;AAAA;AAAA,QAKA;AAAA,MACJ;AAAA,MACA,WAAO;AAAA,QACH;AAAA,UACI,WAAO,iBAAG,MAAM;AAAA,UAChB,YAAQ,iBAAG,MAAM;AAAA,UACjB,SAAS,WAAW,OAAO,KAAK,QAAQ,gBAAgB,sBAAsB,OAAO,KAAK,OAAO,KAAK,SAAS,OAAO,gBAAgB,sBAAsB,KAAK,YAAY,SAAS,KAAK,YAAY,gBAAgB,sBAAsB,SAAS,KAAK,SAAS,OAAO,MAAM,OAAO,KAAK,OAAO,gBAAgB,sBAAsB,MAAM,OAAO,KAAK;AAAA,QAChW;AAAA,QACA;AAAA,MACJ;AAAA,MACC,GAAG;AAAA;AAAA,EACR;AAER,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { css } from "@emotion/css";
|
|
4
3
|
import { clsx } from "deepsea-tools";
|
|
5
4
|
import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { css } from "@emotion/css";
|
|
6
6
|
import { px, transformCSSVariable } from "../utils";
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","forwardRef","useEffect","useImperativeHandle","useLayoutEffect","useRef","useState","css","px","transformCSSVariable","jsx","_jsx","AutoFit","props","ref","width","designWidth","height","designHeight","direction","className","style","rest","ele","show","setShow","transform","setTransform","undefined","setWidth","setHeight","current","element","parent","parentElement","listener","entries","entry","contentRect","scale","Math","min","observer","ResizeObserver","observe","disconnect","process","env","NODE_ENV","getComputedStyle","position","console","warn","display"],"sources":["../../../src/components/AutoFit.tsx"],"sourcesContent":["\"use client\"\n\nimport { clsx } from \"deepsea-tools\"\nimport { HTMLAttributes, forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from \"react\"\n\nimport { css } from \"@emotion/css\"\nimport { px, transformCSSVariable } from \"../utils\"\n\nexport interface AutoFitProps extends HTMLAttributes<HTMLDivElement> {\n /** 设计稿宽度,默认 1920 */\n width?: number\n /** 设计稿高度,默认 1080 */\n height?: number\n /**\n * 在哪些方向进行缩放,默认缩放所有方向\n * 1. 水平方向是指,宽度按照设计稿进行占满,高度反向缩放\n * 2. 垂直方向是指,高度按照设计稿进行占满,宽度反向缩放\n * 3. 默认是水平和垂直方向都进行缩放,类似于 background-size: contain 的效果\n */\n direction?: \"horizontal\" | \"vertical\" | \"both\"\n}\n\n/**\n * 自适应缩放组件\n *\n * 注意:\n * 1. 父元素必须设置非 static 定位方式\n * 2. 父元素只能有且仅有一个子元素,那就是 AutoFit\n * 3. 不要设置 AutoFit 的 position、left、top、transform、width、height 属性\n * 4. 在第一次完成缩放前,无论 props 是什么,返回的都是 <div style={{ display: \"none\" }} />\n * 5. 元素的属性、事件、资源并不是立即加载的,会有一帧的延迟,在第一次完成缩放后才会显示\n */\nexport const AutoFit = forwardRef<HTMLDivElement, AutoFitProps>((props, ref) => {\n const { width: designWidth = 1920, height: designHeight = 1080, direction, className, style, ...rest } = props\n const ele = useRef<HTMLDivElement>(null)\n const [show, setShow] = useState(false)\n const [transform, setTransform] = useState<string | undefined>(undefined)\n const [width, setWidth] = useState<string | undefined>(undefined)\n const [height, setHeight] = useState<string | undefined>(undefined)\n\n useImperativeHandle(ref, () => ele.current!, [ele.current])\n useLayoutEffect(() => {\n const element = ele.current\n const parent = element?.parentElement\n if (!element || !parent) return\n function listener(entries: ResizeObserverEntry[]) {\n const entry = entries[0]\n const { contentRect } = entry\n if (direction === \"horizontal\") {\n const scale = contentRect.width / designWidth\n setTransform(`scale(${scale})`)\n setWidth(px(designWidth))\n setHeight(px(contentRect.height / scale))\n } else if (direction === \"vertical\") {\n const scale = contentRect.height / designHeight\n setTransform(`scale(${scale})`)\n setWidth(px(contentRect.width / scale))\n setHeight(px(designHeight))\n } else {\n const scale = Math.min(contentRect.width / designWidth, contentRect.height / designHeight)\n setTransform(\n `translateX(${(contentRect.width - designWidth * scale) / 2}px) translateY(${(contentRect.height - designHeight * scale) / 2}px) scale(${scale})`,\n )\n setWidth(px(designWidth))\n setHeight(px(designHeight))\n }\n setShow(true)\n }\n const observer = new ResizeObserver(listener)\n observer.observe(parent)\n return () => observer.disconnect()\n }, [ele.current?.parentElement, designWidth, designHeight, direction])\n\n if (process.env.NODE_ENV === \"development\") {\n useEffect(() => {\n const parent = ele.current?.parentElement\n if (!parent) return\n const style = getComputedStyle(parent)\n if (style.position === \"static\") {\n console.warn(\"AutoFit 组件的父元素的 position 属性不应该是 static\")\n }\n }, [ele.current?.parentElement])\n }\n\n if (!show) return <div ref={ele} style={{ display: \"none\" }} />\n\n return (\n <div\n ref={ele}\n className={clsx(\n css`\n position: absolute;\n transform: var(--transform);\n transform-origin: top left;\n width: var(--width);\n height: var(--height);\n `,\n className,\n )}\n style={transformCSSVariable({ transform, width, height }, style)}\n {...rest}\n />\n )\n})\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,IAAI,QAAQ,eAAe;AACpC,SAAyBC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,eAAe,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAErH,SAASC,GAAG,QAAQ,cAAc;AAClC,SAASC,EAAE,EAAEC,oBAAoB;AAAkB,SAAAC,GAAA,IAAAC,IAAA;AAgBnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,gBAAGX,UAAU,CAA+B,CAACY,KAAK,EAAEC,GAAG,KAAK;EAC5E,MAAM;IAAEC,KAAK,EAAEC,WAAW,GAAG,IAAI;IAAEC,MAAM,EAAEC,YAAY,GAAG,IAAI;IAAEC,SAAS;IAAEC,SAAS;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGT,KAAK;EAC9G,MAAMU,GAAG,GAAGlB,MAAM,CAAiB,IAAI,CAAC;EACxC,MAAM,CAACmB,IAAI,EAAEC,OAAO,CAAC,GAAGnB,QAAQ,CAAC,KAAK,CAAC;EACvC,MAAM,CAACoB,SAAS,EAAEC,YAAY,CAAC,GAAGrB,QAAQ,CAAqBsB,SAAS,CAAC;EACzE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AA;IACIG,GAAG,EAAES,GAAI;IACTH,SAAS,EAAEpB,IAAI,CACXO,GAAI;AACpB;AACA;AACA;AACA;AACA;AACA,iBAAiB,EACDa,SACJ,CAAE;IACFC,KAAK,EAAEZ,oBAAoB,CAAC;MAAEiB,SAAS;MAAEX,KAAK;MAAEE;IAAO,CAAC,EAAEI,KAAK,CAAE;IAAA,GAC7DC;EAAI,CACX,CAAC;AAEV,CAAC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { css } from "@emotion/css";
|
|
4
3
|
import { useSize } from "ahooks";
|
|
5
4
|
import { clsx, getArray } from "deepsea-tools";
|
|
6
5
|
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
6
|
+
import { css } from "@emotion/css";
|
|
7
7
|
import { px, transformCSSVariable } from "../utils";
|
|
8
8
|
import { Scroll } from "./Scroll";
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useSize","clsx","getArray","forwardRef","useEffect","useImperativeHandle","useRef","css","px","transformCSSVariable","Scroll","jsx","_jsx","AutoScroll","props","ref","count","itemHeight","animation","duration","onMouseEnter","onMouseLeave","gap","containerClassName","containerStyle","children","playOnMouseEnter","scrollbar","paused","rest","bar","timeout","undefined","ele","size","pausedRef","pausedProps","current","height","range","index","scrollHeight","length","scroll","target","clearTimeout","setTimeout","scrollTo","listener","status","y","offset","scrollToBottom","Math","abs","find","item","addListener","removeListener","onContainerMouseEnter","e","onContainerMouseLeave","className","style"],"sources":["../../../src/components/AutoScroll.tsx"],"sourcesContent":["\"use client\"\n\nimport { useSize } from \"ahooks\"\nimport { clsx, getArray } from \"deepsea-tools\"\nimport { CSSProperties, MouseEvent as ReactMouseEvent, forwardRef, useEffect, useImperativeHandle, useRef } from \"react\"\nimport Scrollbar from \"smooth-scrollbar\"\nimport { ScrollStatus } from \"smooth-scrollbar/interfaces/scrollbar\"\n\nimport { css } from \"@emotion/css\"\nimport { px, transformCSSVariable } from \"../utils\"\nimport { Scroll, ScrollProps } from \"./Scroll\"\n\nexport interface AutoScrollProps extends ScrollProps {\n /** 轮播元素的个数 */\n count: number\n\n /** 轮播元素的高度 */\n itemHeight: number\n\n /**\n * 轮播动画的时间,单位毫秒\n * @default 1000\n */\n animation?: number\n\n /**\n * 每个元素的停留时间,单位毫秒\n * @default 3000\n */\n duration?: number\n\n /**\n * 元素之间的间距\n * @default 0\n */\n gap?: number\n\n /** 容器类名 */\n containerClassName?: string\n\n /** 容器样式 */\n containerStyle?: CSSProperties\n\n /**\n * 在鼠标移入时是否继续播放\n * @default false\n */\n playOnMouseEnter?: boolean\n\n /**\n * 是否暂停\n * @default false\n */\n paused?: boolean\n}\n\nexport const AutoScroll = forwardRef<HTMLDivElement, AutoScrollProps>((props, ref) => {\n const {\n count,\n itemHeight,\n animation = 1000,\n duration = 3000,\n onMouseEnter,\n onMouseLeave,\n gap = 0,\n containerClassName,\n containerStyle,\n children,\n playOnMouseEnter,\n scrollbar,\n paused,\n ...rest\n } = props\n const bar = useRef<Scrollbar | null>(null)\n const timeout = useRef<NodeJS.Timeout | undefined>(undefined)\n const ele = useRef<HTMLDivElement>(null)\n const size = useSize(ele)\n const pausedRef = useRef(false)\n const pausedProps = useRef(paused)\n pausedProps.current = paused\n\n useImperativeHandle(ref, () => ele.current!, [])\n useImperativeHandle(scrollbar, () => bar.current!, [])\n\n useEffect(() => {\n if (playOnMouseEnter) pausedRef.current = false\n }, [playOnMouseEnter])\n\n useEffect(() => {\n if (!size || count === 0) return\n const { height } = size\n const range = getArray(count, index => (itemHeight + gap) * (index + 1) - (index === count - 1 ? gap : 0))\n const scrollHeight = range[range.length - 1]\n if (height >= scrollHeight) return\n function scroll(target: number) {\n clearTimeout(timeout.current)\n timeout.current = setTimeout(() => {\n if (pausedRef.current || pausedProps.current) return scroll(target)\n bar.current?.scrollTo(0, target, animation)\n }, duration)\n }\n scroll(range[0])\n function listener(status: ScrollStatus) {\n const { y } = status.offset\n const scrollToBottom = Math.abs(y + height - scrollHeight) / itemHeight <= 0.05\n const target = scrollToBottom ? 0 : range.find(item => item > y)!\n scroll(target)\n }\n bar.current?.addListener(listener)\n return () => {\n clearTimeout(timeout.current)\n bar.current?.removeListener(listener)\n bar.current?.scrollTo(0, 0)\n }\n }, [size, count, itemHeight, gap, duration, animation])\n\n function onContainerMouseEnter(e: ReactMouseEvent<HTMLDivElement, MouseEvent>) {\n if (playOnMouseEnter) return\n pausedRef.current = true\n onMouseEnter?.(e)\n }\n\n function onContainerMouseLeave(e: ReactMouseEvent<HTMLDivElement, MouseEvent>) {\n if (playOnMouseEnter) return\n pausedRef.current = false\n onMouseLeave?.(e)\n }\n\n return (\n <Scroll ref={ele} scrollbar={bar} onMouseEnter={onContainerMouseEnter} onMouseLeave={onContainerMouseLeave} {...rest}>\n <div\n className={clsx(\n css`\n display: flex;\n flex-direction: column;\n gap: var(--gap, 0);\n & > * {\n flex: none;\n }\n `,\n containerClassName,\n )}\n style={transformCSSVariable({ gap: px(gap) }, containerStyle)}\n >\n {children}\n </div>\n </Scroll>\n )\n})\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,OAAO,QAAQ,QAAQ;AAChC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,eAAe;AAC9C,SAAuDC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAIxH,SAASC,GAAG,QAAQ,cAAc;AAClC,SAASC,EAAE,EAAEC,oBAAoB;AACjC,SAASC,MAAM;AAA+B,SAAAC,GAAA,IAAAC,IAAA;AA8C9C,OAAO,MAAMC,UAAU,gBAAGV,UAAU,CAAkC,CAACW,KAAK,EAAEC,GAAG,KAAK;EAClF,MAAM;IACFC,KAAK;IACLC,UAAU;IACVC,SAAS,GAAG,IAAI;IAChBC,QAAQ,GAAG,IAAI;IACfC,YAAY;IACZC,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BAAgB,EAAE;IACtBS,SAAS,CAACE,OAAO,GAAG,IAAI;IACxBjB,YAAY,GAAGwC,CAAC,CAAC;EACrB;EAEA,SAASC,qBAAqBA,CAACD,CAA8C,EAAE;IAC3E,IAAIlC,gBAAgB,EAAE;IACtBS,SAAS,CAACE,OAAO,GAAG,KAAK;IACzBhB,YAAY,GAAGuC,CAAC,CAAC;EACrB;EAEA,oBACIhD,IAAA,CAACF,MAAM;IAACK,GAAG,EAAEkB,GAAI;IAACN,SAAS,EAAEG,GAAI;IAACV,YAAY,EAAEuC,qBAAsB;IAACtC,YAAY,EAAEwC,qBAAsB;IAAA,GAAKhC,IAAI;IAAAJ,QAAA,eAChHb,IAAA;MACIkD,SAAS,EAAE7D,IAAI,CACXM,GAAI;AACxB;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,EACDgB,kBACJ,CAAE;MACFwC,KAAK,EAAEtD,oBAAoB,CAAC;QAAEa,GAAG,EAAEd,EAAE,CAACc,GAAG;MAAE,CAAC,EAAEE,cAAc,CAAE;MAAAC,QAAA,EAE7DA;IAAQ,CACR;EAAC,CACF,CAAC;AAEjB,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { css } from "@emotion/css";
|
|
4
3
|
import { clsx } from "deepsea-tools";
|
|
5
4
|
import { forwardRef, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { css } from "@emotion/css";
|
|
6
6
|
import { px, transformCSSVariable } from "../utils";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","forwardRef","useImperativeHandle","useLayoutEffect","useRef","useState","css","px","transformCSSVariable","jsx","_jsx","AutoSizeTextArea","props","ref","className","style","rest","height","setHeight","undefined","ele","current","textarea","resizeTextarea","scrollHeight","offsetHeight","clientHeight","addEventListener","removeEventListener"],"sources":["../../../src/components/AutoSizeTextarea.tsx"],"sourcesContent":["\"use client\"\n\nimport { clsx } from \"deepsea-tools\"\nimport { TextareaHTMLAttributes, forwardRef, useImperativeHandle, useLayoutEffect, useRef, useState } from \"react\"\n\nimport { css } from \"@emotion/css\"\nimport { px, transformCSSVariable } from \"../utils\"\n\n/**\n * 自适应高度的文本域\n */\nexport const AutoSizeTextArea = forwardRef<HTMLTextAreaElement, TextareaHTMLAttributes<HTMLTextAreaElement>>((props, ref) => {\n const { className, style, ...rest } = props\n const [height, setHeight] = useState<string | undefined>(undefined)\n const ele = useRef<HTMLTextAreaElement>(null)\n\n useImperativeHandle(ref, () => ele.current!, [])\n\n useLayoutEffect(() => {\n const textarea = ele.current!\n function resizeTextarea() {\n setHeight(\"auto\")\n setHeight(px(textarea.scrollHeight + textarea.offsetHeight - textarea.clientHeight))\n }\n resizeTextarea()\n textarea.addEventListener(\"input\", resizeTextarea)\n textarea.addEventListener(\"change\", resizeTextarea)\n\n return () => {\n textarea.removeEventListener(\"input\", resizeTextarea)\n textarea.removeEventListener(\"change\", resizeTextarea)\n }\n }, [])\n\n return (\n <textarea\n ref={ele}\n className={clsx(\n css`\n height: var(--height);\n resize: none;\n overflow-y: hidden;\n `,\n className,\n )}\n style={transformCSSVariable({ height }, style)}\n {...rest}\n />\n )\n})\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,IAAI,QAAQ,eAAe;AACpC,SAAiCC,UAAU,EAAEC,mBAAmB,EAAEC,eAAe,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAElH,SAASC,GAAG,QAAQ,cAAc;AAClC,SAASC,EAAE,EAAEC,oBAAoB;;AAEjC;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAGA,OAAO,MAAMC,gBAAgB,gBAAGV,UAAU,CAAmE,CAACW,KAAK,EAAEC,GAAG,KAAK;EACzH,MAAM;IAAEC,SAAS;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGJ,KAAK;EAC3C,MAAM,CAACK,MAAM,EAAEC,SAAS,CAAC,GAAGb,QAAQ,CAAqBc,SAAS,CAAC;EACnE,MAAMC,GAAG,GAAGhB,MAAM,CAAsB,IAAI,CAAC;EAE7CF,mBAAmB,CAACW,GAAG,EAAE,MAAMO,GAAG,CAACC,OAAQ,EAAE,EAAE,CAAC;EAEhDlB,eAAe,CAAC,MAAM;IAClB,MAAMmB,QAAQ,GAAGF,GAAG,CAACC,OAAQ;IAC7B,SAASE,cAAcA,CAAA,EAAG;MACtBL,SAAS,CAAC,MAAM,CAAC;MACjBA,SAAS,CAACX,EAAE,CAACe,QAAQ,CAACE,YAAY,GAAGF,QAAQ,CAACG,YAAY,GAAGH,QAAQ,CAACI,YAAY,CAAC,CAAC;IACxF;IACAH,cAAc,CAAC,CAAC;IAChBD,QAAQ,CAACK,gBAAgB,CAAC,OAAO,EAAEJ,cAAc,CAAC;IAClDD,QAAQ,CAACK,gBAAgB,CAAC,QAAQ,EAAEJ,cAAc,CAAC;IAEnD,OAAO,MAAM;MACTD,QAAQ,CAACM,mBAAmB,CAAC,OAAO,EAAEL,cAAc,CAAC;MACrDD,QAAQ,CAACM,mBAAmB,CAAC,QAAQ,EAAEL,cAAc,CAAC;IAC1D,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,oBACIb,IAAA;IACIG,GAAG,EAAEO,GAAI;IACTN,SAAS,EAAEd,IAAI,CACXM,GAAI;AACpB;AACA;AACA;AACA,iBAAiB,EACDQ,SACJ,CAAE;IACFC,KAAK,EAAEP,oBAAoB,CAAC;MAAES;IAAO,CAAC,EAAEF,KAAK,CAAE;IAAA,GAC3CC;EAAI,CACX,CAAC;AAEV,CAAC,CAAC"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Event } from "clipboard";
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
3
3
|
export { Event } from "clipboard";
|
|
4
|
-
export type CopyButtonProps =
|
|
4
|
+
export type CopyButtonProps = ComponentPropsWithoutRef<"button"> & {
|
|
5
5
|
text?: string;
|
|
6
6
|
onCopySuccess?: (e: Event) => void;
|
|
7
7
|
onCopyError?: (e: Event) => void;
|
|
8
8
|
};
|
|
9
|
-
export declare const CopyButton: import("react").ForwardRefExoticComponent<Omit<
|
|
9
|
+
export declare const CopyButton: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
10
|
+
text?: string | undefined;
|
|
11
|
+
onCopySuccess?: ((e: Event) => void) | undefined;
|
|
12
|
+
onCopyError?: ((e: Event) => void) | undefined;
|
|
13
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useLatest","ClipboardJS","forwardRef","useEffect","useImperativeHandle","useRef","jsx","_jsx","Event","CopyButton","props","ref","text","onCopySuccess","_onCoptSuccess","onCopyError","_onCopyError","rest","ele","current","clipboard","on","event","destroy"],"sources":["../../../src/components/CopyButton.tsx"],"sourcesContent":["import { useLatest } from \"ahooks\"\nimport ClipboardJS, { Event } from \"clipboard\"\nimport {
|
|
1
|
+
{"version":3,"names":["useLatest","ClipboardJS","forwardRef","useEffect","useImperativeHandle","useRef","jsx","_jsx","Event","CopyButton","props","ref","text","onCopySuccess","_onCoptSuccess","onCopyError","_onCopyError","rest","ele","current","clipboard","on","event","destroy"],"sources":["../../../src/components/CopyButton.tsx"],"sourcesContent":["import { useLatest } from \"ahooks\"\nimport ClipboardJS, { Event } from \"clipboard\"\nimport { ComponentPropsWithoutRef, forwardRef, useEffect, useImperativeHandle, useRef } from \"react\"\n\nexport { Event } from \"clipboard\"\n\nexport type CopyButtonProps = ComponentPropsWithoutRef<\"button\"> & {\n text?: string\n onCopySuccess?: (e: Event) => void\n onCopyError?: (e: Event) => void\n}\n\nexport const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>((props, ref) => {\n const { text, onCopySuccess: _onCoptSuccess, onCopyError: _onCopyError, ...rest } = props\n const ele = useRef<HTMLButtonElement>(null)\n const onCopySuccess = useLatest(_onCoptSuccess)\n const onCopyError = useLatest(_onCopyError)\n\n useImperativeHandle(ref, () => ele.current!, [ele.current])\n\n useEffect(() => {\n const clipboard = new ClipboardJS(ele.current!)\n clipboard.on(\"success\", event => onCopySuccess.current?.(event))\n clipboard.on(\"error\", event => onCopyError.current?.(event))\n return () => clipboard.destroy()\n }, [])\n\n return <button ref={ele} {...rest} data-clipboard-text={text} />\n})\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAClC,OAAOC,WAAW,MAAiB,WAAW;AAC9C,SAAmCC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAEpG,SAASC,KAAK,QAAQ,WAAW;AAQjC,OAAO,MAAMC,UAAU,gBAAGP,UAAU,CAAqC,CAACQ,KAAK,EAAEC,GAAG,KAAK;EACrF,MAAM;IAAEC,IAAI;IAAEC,aAAa,EAAEC,cAAc;IAAEC,WAAW,EAAEC,YAAY;IAAE,GAAGC;EAAK,CAAC,GAAGP,KAAK;EACzF,MAAMQ,GAAG,GAAGb,MAAM,CAAoB,IAAI,CAAC;EAC3C,MAAMQ,aAAa,GAAGb,SAAS,CAACc,cAAc,CAAC;EAC/C,MAAMC,WAAW,GAAGf,SAAS,CAACgB,YAAY,CAAC;EAE3CZ,mBAAmB,CAACO,GAAG,EAAE,MAAMO,GAAG,CAACC,OAAQ,EAAE,CAACD,GAAG,CAACC,OAAO,CAAC,CAAC;EAE3DhB,SAAS,CAAC,MAAM;IACZ,MAAMiB,SAAS,GAAG,IAAInB,WAAW,CAACiB,GAAG,CAACC,OAAQ,CAAC;IAC/CC,SAAS,CAACC,EAAE,CAAC,SAAS,EAAEC,KAAK,IAAIT,aAAa,CAACM,OAAO,GAAGG,KAAK,CAAC,CAAC;IAChEF,SAAS,CAACC,EAAE,CAAC,OAAO,EAAEC,KAAK,IAAIP,WAAW,CAACI,OAAO,GAAGG,KAAK,CAAC,CAAC;IAC5D,OAAO,MAAMF,SAAS,CAACG,OAAO,CAAC,CAAC;EACpC,CAAC,EAAE,EAAE,CAAC;EAEN,oBAAOhB,IAAA;IAAQI,GAAG,EAAEO,GAAI;IAAA,GAAKD,IAAI;IAAE,uBAAqBL;EAAK,CAAE,CAAC;AACpE,CAAC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BarSeriesOption, ComposeOption, DatasetComponentOption, ECharts, GridComponentOption, LineSeriesOption, PieSeriesOption, TitleComponentOption, TooltipComponentOption } from "echarts";
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentPropsWithoutRef, ForwardRefExoticComponent, ForwardedRef, RefAttributes } from "react";
|
|
3
3
|
export type PieOption = ComposeOption<PieSeriesOption | TitleComponentOption | DatasetComponentOption | GridComponentOption | TooltipComponentOption>;
|
|
4
4
|
export type BarOption = ComposeOption<BarSeriesOption | TitleComponentOption | DatasetComponentOption | GridComponentOption | TooltipComponentOption>;
|
|
5
5
|
export type LineOption = ComposeOption<LineSeriesOption | TitleComponentOption | DatasetComponentOption | GridComponentOption | TooltipComponentOption>;
|
|
6
|
-
export interface EchartProps<T extends any = any> extends Omit<
|
|
6
|
+
export interface EchartProps<T extends any = any> extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
|
|
7
7
|
width: number;
|
|
8
8
|
height: number;
|
|
9
9
|
option: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["init","forwardRef","useEffect","useImperativeHandle","useLayoutEffect","useRef","jsx","_jsx","Echart","props","ref","width","height","option","chart","rest","container","chartRef","ele","current","dispose","setOption","resize","Pie","Bar","Line"],"sources":["../../../src/components/Echart.tsx"],"sourcesContent":["import {\n BarSeriesOption,\n ComposeOption,\n DatasetComponentOption,\n ECharts,\n GridComponentOption,\n
|
|
1
|
+
{"version":3,"names":["init","forwardRef","useEffect","useImperativeHandle","useLayoutEffect","useRef","jsx","_jsx","Echart","props","ref","width","height","option","chart","rest","container","chartRef","ele","current","dispose","setOption","resize","Pie","Bar","Line"],"sources":["../../../src/components/Echart.tsx"],"sourcesContent":["import {\n BarSeriesOption,\n ComposeOption,\n DatasetComponentOption,\n ECharts,\n GridComponentOption,\n LineSeriesOption,\n PieSeriesOption,\n TitleComponentOption,\n TooltipComponentOption,\n init,\n} from \"echarts\"\nimport {\n ComponentPropsWithoutRef,\n ForwardRefExoticComponent,\n ForwardedRef,\n RefAttributes,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n} from \"react\"\n\nexport type PieOption = ComposeOption<PieSeriesOption | TitleComponentOption | DatasetComponentOption | GridComponentOption | TooltipComponentOption>\n\nexport type BarOption = ComposeOption<BarSeriesOption | TitleComponentOption | DatasetComponentOption | GridComponentOption | TooltipComponentOption>\n\nexport type LineOption = ComposeOption<LineSeriesOption | TitleComponentOption | DatasetComponentOption | GridComponentOption | TooltipComponentOption>\n\nexport interface EchartProps<T extends any = any> extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\"> {\n width: number\n height: number\n option: T\n chart?: ForwardedRef<ECharts>\n}\n\nexport type EchartComponent<T extends PieOption | BarOption | LineOption> = ForwardRefExoticComponent<\n Omit<EchartProps<T>, \"ref\"> & RefAttributes<HTMLDivElement>\n>\n\nconst Echart = forwardRef<HTMLDivElement, EchartProps>((props, ref) => {\n const { width, height, option, chart, ...rest } = props\n const container = useRef<HTMLDivElement>(null)\n const chartRef = useRef<ECharts | null>(null)\n\n useLayoutEffect(() => {\n const ele = container.current!\n chartRef.current = init(ele, option, { width, height })\n return () => chartRef.current?.dispose()\n }, [])\n\n useImperativeHandle(ref, () => container.current!, [])\n\n useImperativeHandle(chart, () => chartRef.current!, [])\n\n useEffect(() => {\n chartRef.current?.setOption(option)\n chartRef.current?.resize({ width, height })\n })\n\n return <div ref={container} {...rest} />\n})\n\nexport const Pie = Echart as EchartComponent<PieOption>\nexport const Bar = Echart as EchartComponent<BarOption>\nexport const Line = Echart as EchartComponent<LineOption>\n"],"mappings":"AAAA,SAUIA,IAAI,QACD,SAAS;AAChB,SAKIC,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,MAAM,QACH,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAmBd,MAAMC,MAAM,gBAAGP,UAAU,CAA8B,CAACQ,KAAK,EAAEC,GAAG,KAAK;EACnE,MAAM;IAAEC,KAAK;IAAEC,MAAM;IAAEC,MAAM;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGN,KAAK;EACvD,MAAMO,SAAS,GAAGX,MAAM,CAAiB,IAAI,CAAC;EAC9C,MAAMY,QAAQ,GAAGZ,MAAM,CAAiB,IAAI,CAAC;EAE7CD,eAAe,CAAC,MAAM;IAClB,MAAMc,GAAG,GAAGF,SAAS,CAACG,OAAQ;IAC9BF,QAAQ,CAACE,OAAO,GAAGnB,IAAI,CAACkB,GAAG,EAAEL,MAAM,EAAE;MAAEF,KAAK;MAAEC;IAAO,CAAC,CAAC;IACvD,OAAO,MAAMK,QAAQ,CAACE,OAAO,EAAEC,OAAO,CAAC,CAAC;EAC5C,CAAC,EAAE,EAAE,CAAC;EAENjB,mBAAmB,CAACO,GAAG,EAAE,MAAMM,SAAS,CAACG,OAAQ,EAAE,EAAE,CAAC;EAEtDhB,mBAAmB,CAACW,KAAK,EAAE,MAAMG,QAAQ,CAACE,OAAQ,EAAE,EAAE,CAAC;EAEvDjB,SAAS,CAAC,MAAM;IACZe,QAAQ,CAACE,OAAO,EAAEE,SAAS,CAACR,MAAM,CAAC;IACnCI,QAAQ,CAACE,OAAO,EAAEG,MAAM,CAAC;MAAEX,KAAK;MAAEC;IAAO,CAAC,CAAC;EAC/C,CAAC,CAAC;EAEF,oBAAOL,IAAA;IAAKG,GAAG,EAAEM,SAAU;IAAA,GAAKD;EAAI,CAAG,CAAC;AAC5C,CAAC,CAAC;AAEF,OAAO,MAAMQ,GAAG,GAAGf,MAAoC;AACvD,OAAO,MAAMgB,GAAG,GAAGhB,MAAoC;AACvD,OAAO,MAAMiB,IAAI,GAAGjB,MAAqC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { css } from "@emotion/css";
|
|
4
3
|
import { useSize } from "ahooks";
|
|
5
4
|
import { clsx } from "deepsea-tools";
|
|
6
5
|
import { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
6
|
+
import { css } from "@emotion/css";
|
|
7
7
|
import { px, transformCSSVariable } from "../utils";
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export function getGapRange(gap) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["css","useSize","clsx","useEffect","useImperativeHandle","useRef","useState","px","transformCSSVariable","jsx","_jsx","getGapRange","gap","Array","isArray","getGapCountAndSize","width","itemWidth","minGap","maxGap","count","Math","floor","averageGap","ManualFlow","props","itemHeight","columnGap","rowGap","maxRows","data","render","keyExactor","className","style","wrapperClassName","wrapperStyle","throttle","transitionDuration","onSizeChange","containerClassName","containerStyle","element","rest","minColumnGap","maxColumnGap","columnCount","columnGapSize","setGapAndCount","ele","contentRows","ceil","length","contentShownRows","min","height","getPosition","index","y","x","left","top","getHidden","current","task","timeout","setTimeout","clearTimeout","rowCount","overflow","itemCount","ref","children","map","item","arr","transition","display","Flow","size"],"sources":["../../../src/components/Flow.tsx"],"sourcesContent":["\"use client\"\n\nimport { css } from \"@emotion/css\"\nimport { useSize } from \"ahooks\"\nimport { clsx } from \"deepsea-tools\"\nimport { CSSProperties, HTMLAttributes, Key, ReactNode, RefObject, useEffect, useImperativeHandle, useRef, useState } from \"react\"\nimport { px, transformCSSVariable } from \"../utils\"\n\nexport interface FlowSizeData {\n /** 容器宽度 */\n width: number\n /** 容器高度 */\n height: number\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /** 列间距 */\n columnGap: number\n /** 列数 */\n columnCount: number\n /** 行间距 */\n rowGap: number\n /** 行数 */\n rowCount: number\n /** 元素格数 */\n itemCount: number\n /** 最大行数 */\n maxRows: number | null\n /** 是否有元素被隐藏 */\n overflow: boolean\n}\n\nexport interface FlowProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /**\n * 列间距\n * 1. 如果是数字,表示列间距是固定的\n * 2. 如果是 auto,表示会在尽可能放进更多列的情况下,列间距是平均的\n * 2. 如果是数组,表示列间距是区间的,第一个元素是最小值,第二个元素是最大值\n */\n columnGap?: number | \"auto\" | [number | \"auto\", number | \"auto\"]\n /** 行间距 */\n rowGap?: number\n gap?: number\n /** 最大行数 */\n maxRows?: number | null\n /** 源数据 */\n data?: T[]\n /** 渲染 */\n render: (item: T, index: number, arr: T[]) => ReactNode\n /** key释放器,默认为 index */\n keyExactor?: (item: T, index: number, arr: T[]) => Key\n /**\n * 渲染的元素由两层容器包裹,外层容器类名\n */\n wrapperClassName?: string\n /**\n * 渲染的元素由两层容器包裹,外层容器样式\n */\n wrapperStyle?: CSSProperties\n /**\n * 渲染的元素由两层容器包裹,内层容器类名\n */\n containerClassName?: string\n /**\n * 渲染的元素由两层容器包裹,内层容器样式\n */\n containerStyle?: CSSProperties\n /** 节流时间,单位毫秒,默认200ms,传入 0 不节流 */\n throttle?: number\n /** 动画时间,单位毫秒,默认400ms,传入 0 不展示动画 */\n transitionDuration?: number\n /** 变化的回调函数 */\n onSizeChange?: (sizeData: FlowSizeData) => void\n element?: RefObject<HTMLDivElement>\n}\n\nexport function getGapRange(gap?: undefined | number | \"auto\" | (number | \"auto\")[]): [number, number | \"auto\"] {\n if (typeof gap === \"number\") return [gap, gap]\n if (Array.isArray(gap)) return [typeof gap[0] === \"number\" ? gap[0] : 0, gap[1]]\n return [0, \"auto\"]\n}\n\nexport interface GapAndCount {\n count: number\n gap: number\n}\n\nexport function getGapCountAndSize(width: number, itemWidth: number, minGap: number, maxGap: number | \"auto\"): GapAndCount {\n const count = Math.floor((width + minGap) / (itemWidth + minGap)) || 1\n if (count === 1) return { count, gap: 0 }\n const averageGap = (width - itemWidth * count) / (count - 1)\n if (averageGap < minGap) return { count, gap: minGap }\n if (maxGap !== \"auto\" && averageGap > maxGap) return { count, gap: maxGap }\n return { count, gap: averageGap }\n}\n\nexport interface ManualFlowProps<T> extends FlowProps<T> {\n /** 组件宽度,必须指定 */\n width: number\n}\n\n/** 手动组件,由外界指定宽度,性能更好 */\nexport function ManualFlow<T>(props: ManualFlowProps<T>) {\n let {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n maxRows,\n data = [],\n render,\n keyExactor,\n className,\n style,\n wrapperClassName,\n wrapperStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n containerClassName,\n containerStyle,\n gap = 0,\n width,\n element,\n ...rest\n } = props\n rowGap ??= gap\n columnGap ??= gap\n const [minColumnGap, maxColumnGap] = getGapRange(columnGap)\n const [{ count: columnCount, gap: columnGapSize }, setGapAndCount] = useState(() => getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n const ele = useRef<HTMLDivElement>(null)\n const contentRows = Math.ceil(data.length / columnCount)\n const contentShownRows = typeof maxRows === \"number\" ? Math.min(contentRows, maxRows) : contentRows\n const height = contentShownRows > 0 ? contentShownRows * (itemHeight + rowGap) - rowGap : 0\n\n function getPosition(index: number) {\n const y = Math.floor(index / columnCount)\n const x = index - y * columnCount\n return {\n left: x * (itemWidth + columnGapSize),\n top: y * (itemHeight + rowGap!),\n }\n }\n\n function getHidden(index: number) {\n if (typeof maxRows !== \"number\") return false\n return index >= maxRows * columnCount\n }\n\n useImperativeHandle(element, () => ele.current!, [ele.current])\n\n useEffect(() => {\n function task() {\n setGapAndCount(getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n }\n if (throttle === 0) return task()\n const timeout = setTimeout(task, throttle || 200)\n return () => clearTimeout(timeout)\n }, [width, itemWidth, throttle, minColumnGap, maxColumnGap])\n\n useEffect(() => {\n onSizeChange?.({\n width,\n height,\n itemWidth,\n itemHeight,\n columnGap: columnGapSize,\n columnCount,\n rowGap: rowGap!,\n rowCount: contentShownRows,\n overflow: data.length > contentShownRows * columnCount,\n itemCount: data.length,\n maxRows: maxRows ?? null,\n })\n }, [width, height, columnGapSize, columnCount, rowGap, contentShownRows, data.length, itemWidth, itemHeight, maxRows])\n\n return (\n <div\n ref={ele}\n className={clsx(\n css`\n position: relative;\n height: var(--height);\n overflow: hidden;\n `,\n className,\n )}\n style={transformCSSVariable({ height: px(height) }, style)}\n {...rest}\n >\n {data.map((item, index, arr) => (\n <div\n key={keyExactor ? keyExactor(item, index, arr) : index}\n className={clsx(\n css`\n position: absolute;\n width: var(--width);\n height: var(--height);\n transition: var(--transition);\n left: 0;\n top: 0;\n transform: translate(var(--left), var(--top));\n `,\n wrapperClassName,\n )}\n style={transformCSSVariable(\n {\n width: px(itemWidth),\n height: px(itemHeight),\n transition: transitionDuration === 0 ? \"none\" : `all ${transitionDuration || 400}ms`,\n left: px(getPosition(index).left),\n top: px(getPosition(index).top),\n },\n wrapperStyle,\n )}\n >\n <div\n className={clsx(\n css`\n width: 100%;\n height: 100%;\n display: var(--display);\n `,\n containerClassName,\n )}\n style={transformCSSVariable({ display: getHidden(index) ? \"none\" : \"block\" }, containerStyle)}\n >\n {render(item, index, arr)}\n </div>\n </div>\n ))}\n </div>\n )\n}\n\n/** 自适应浮动组件 */\nexport function Flow<T>(props: FlowProps<T>) {\n const {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n gap,\n maxRows,\n data,\n render,\n keyExactor,\n wrapperClassName,\n wrapperStyle,\n containerClassName,\n containerStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n element,\n ...rest\n } = props\n const ele = useRef<HTMLDivElement>(null)\n const size = useSize(ele)\n const width = useRef(size?.width || 0)\n if (size && size.width !== 0) width.current = size.width\n useImperativeHandle(element, () => ele.current!, [ele.current])\n if (width.current === 0) return <div ref={ele} {...rest} />\n return <ManualFlow element={ele} {...props} width={width.current} />\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,IAAI,QAAQ,eAAe;AACpC,SAAmEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAClI,SAASC,EAAE,EAAEC,oBAAoB;AAAkB,SAAAC,GAAA,IAAAC,IAAA;AA2EnD,OAAO,SAASC,WAAWA,CAACC,GAAuD,EAA6B;EAC5G,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE,OAAO,CAACA,GAAG,EAAEA,GAAG,CAAC;EAC9C,IAAIC,KAAK,CAACC,OAAO,CAACF,GAAG,CAAC,EAAE,OAAO,CAAC,OAAOA,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAGA,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAEA,GAAG,CAAC,CAAC,CAAC,CAAC;EAChF,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC;AACtB;AAOA,OAAO,SAASG,kBAAkBA,CAACC,KAAa,EAAEC,SAAiB,EAAEC,MAAc,EAAEC,MAAuB,EAAe;EACvH,MAAMC,KAAK,GAAGC,IAAI,CAACC,KAAK,CAAC,CAACN,KAAK,GAAGE,MAAM,KAAKD,SAAS,GAAGC,MAAM,CAAC,CAAC,IAAI,CAAC;EACtE,IAAIE,KAAK,KAAK,CAAC,EAAE,OAAO;IAAEA,KAAK;IAAER,GAAG,EAAE;EAAE,CAAC;EACzC,MAAMW,UAAU,GAAG,CAACP,KAAK,GAAGC,SAAS,GAAGG,KAAK,KAAKA,KAAK,GAAG,CAAC,CAAC;EAC5D,IAAIG,UAAU,GAAGL,MAAM,EAAE,OAAO;IAAEE,KAAK;IAAER,GAAG,EAAEM;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C,CAAC;EAC/D,IAAI/C,KAAK,CAAC+C,OAAO,KAAK,CAAC,EAAE,oBAAOrD,IAAA;IAAK6D,GAAG,EAAEtB,GAAI;IAAA,GAAKN;EAAI,CAAG,CAAC;EAC3D,oBAAOjC,IAAA,CAACc,UAAU;IAACkB,OAAO,EAAEO,GAAI;IAAA,GAAKxB,KAAK;IAAET,KAAK,EAAEA,KAAK,CAAC+C;EAAQ,CAAE,CAAC;AACxE"}
|
|
1
|
+
{"version":3,"names":["useSize","clsx","useEffect","useImperativeHandle","useRef","useState","css","px","transformCSSVariable","jsx","_jsx","getGapRange","gap","Array","isArray","getGapCountAndSize","width","itemWidth","minGap","maxGap","count","Math","floor","averageGap","ManualFlow","props","itemHeight","columnGap","rowGap","maxRows","data","render","keyExactor","className","style","wrapperClassName","wrapperStyle","throttle","transitionDuration","onSizeChange","containerClassName","containerStyle","element","rest","minColumnGap","maxColumnGap","columnCount","columnGapSize","setGapAndCount","ele","contentRows","ceil","length","contentShownRows","min","height","getPosition","index","y","x","left","top","getHidden","current","task","timeout","setTimeout","clearTimeout","rowCount","overflow","itemCount","ref","children","map","item","arr","transition","display","Flow","size"],"sources":["../../../src/components/Flow.tsx"],"sourcesContent":["\"use client\"\n\nimport { useSize } from \"ahooks\"\nimport { clsx } from \"deepsea-tools\"\nimport { CSSProperties, HTMLAttributes, Key, ReactNode, RefObject, useEffect, useImperativeHandle, useRef, useState } from \"react\"\n\nimport { css } from \"@emotion/css\"\nimport { px, transformCSSVariable } from \"../utils\"\n\nexport interface FlowSizeData {\n /** 容器宽度 */\n width: number\n /** 容器高度 */\n height: number\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /** 列间距 */\n columnGap: number\n /** 列数 */\n columnCount: number\n /** 行间距 */\n rowGap: number\n /** 行数 */\n rowCount: number\n /** 元素格数 */\n itemCount: number\n /** 最大行数 */\n maxRows: number | null\n /** 是否有元素被隐藏 */\n overflow: boolean\n}\n\nexport interface FlowProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /**\n * 列间距\n * 1. 如果是数字,表示列间距是固定的\n * 2. 如果是 auto,表示会在尽可能放进更多列的情况下,列间距是平均的\n * 2. 如果是数组,表示列间距是区间的,第一个元素是最小值,第二个元素是最大值\n */\n columnGap?: number | \"auto\" | [number | \"auto\", number | \"auto\"]\n /** 行间距 */\n rowGap?: number\n gap?: number\n /** 最大行数 */\n maxRows?: number | null\n /** 源数据 */\n data?: T[]\n /** 渲染 */\n render: (item: T, index: number, arr: T[]) => ReactNode\n /** key释放器,默认为 index */\n keyExactor?: (item: T, index: number, arr: T[]) => Key\n /**\n * 渲染的元素由两层容器包裹,外层容器类名\n */\n wrapperClassName?: string\n /**\n * 渲染的元素由两层容器包裹,外层容器样式\n */\n wrapperStyle?: CSSProperties\n /**\n * 渲染的元素由两层容器包裹,内层容器类名\n */\n containerClassName?: string\n /**\n * 渲染的元素由两层容器包裹,内层容器样式\n */\n containerStyle?: CSSProperties\n /** 节流时间,单位毫秒,默认200ms,传入 0 不节流 */\n throttle?: number\n /** 动画时间,单位毫秒,默认400ms,传入 0 不展示动画 */\n transitionDuration?: number\n /** 变化的回调函数 */\n onSizeChange?: (sizeData: FlowSizeData) => void\n element?: RefObject<HTMLDivElement>\n}\n\nexport function getGapRange(gap?: undefined | number | \"auto\" | (number | \"auto\")[]): [number, number | \"auto\"] {\n if (typeof gap === \"number\") return [gap, gap]\n if (Array.isArray(gap)) return [typeof gap[0] === \"number\" ? gap[0] : 0, gap[1]]\n return [0, \"auto\"]\n}\n\nexport interface GapAndCount {\n count: number\n gap: number\n}\n\nexport function getGapCountAndSize(width: number, itemWidth: number, minGap: number, maxGap: number | \"auto\"): GapAndCount {\n const count = Math.floor((width + minGap) / (itemWidth + minGap)) || 1\n if (count === 1) return { count, gap: 0 }\n const averageGap = (width - itemWidth * count) / (count - 1)\n if (averageGap < minGap) return { count, gap: minGap }\n if (maxGap !== \"auto\" && averageGap > maxGap) return { count, gap: maxGap }\n return { count, gap: averageGap }\n}\n\nexport interface ManualFlowProps<T> extends FlowProps<T> {\n /** 组件宽度,必须指定 */\n width: number\n}\n\n/** 手动组件,由外界指定宽度,性能更好 */\nexport function ManualFlow<T>(props: ManualFlowProps<T>) {\n let {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n maxRows,\n data = [],\n render,\n keyExactor,\n className,\n style,\n wrapperClassName,\n wrapperStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n containerClassName,\n containerStyle,\n gap = 0,\n width,\n element,\n ...rest\n } = props\n rowGap ??= gap\n columnGap ??= gap\n const [minColumnGap, maxColumnGap] = getGapRange(columnGap)\n const [{ count: columnCount, gap: columnGapSize }, setGapAndCount] = useState(() => getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n const ele = useRef<HTMLDivElement>(null)\n const contentRows = Math.ceil(data.length / columnCount)\n const contentShownRows = typeof maxRows === \"number\" ? Math.min(contentRows, maxRows) : contentRows\n const height = contentShownRows > 0 ? contentShownRows * (itemHeight + rowGap) - rowGap : 0\n\n function getPosition(index: number) {\n const y = Math.floor(index / columnCount)\n const x = index - y * columnCount\n return {\n left: x * (itemWidth + columnGapSize),\n top: y * (itemHeight + rowGap!),\n }\n }\n\n function getHidden(index: number) {\n if (typeof maxRows !== \"number\") return false\n return index >= maxRows * columnCount\n }\n\n useImperativeHandle(element, () => ele.current!, [ele.current])\n\n useEffect(() => {\n function task() {\n setGapAndCount(getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n }\n if (throttle === 0) return task()\n const timeout = setTimeout(task, throttle || 200)\n return () => clearTimeout(timeout)\n }, [width, itemWidth, throttle, minColumnGap, maxColumnGap])\n\n useEffect(() => {\n onSizeChange?.({\n width,\n height,\n itemWidth,\n itemHeight,\n columnGap: columnGapSize,\n columnCount,\n rowGap: rowGap!,\n rowCount: contentShownRows,\n overflow: data.length > contentShownRows * columnCount,\n itemCount: data.length,\n maxRows: maxRows ?? null,\n })\n }, [width, height, columnGapSize, columnCount, rowGap, contentShownRows, data.length, itemWidth, itemHeight, maxRows])\n\n return (\n <div\n ref={ele}\n className={clsx(\n css`\n position: relative;\n height: var(--height);\n overflow: hidden;\n `,\n className,\n )}\n style={transformCSSVariable({ height: px(height) }, style)}\n {...rest}\n >\n {data.map((item, index, arr) => (\n <div\n key={keyExactor ? keyExactor(item, index, arr) : index}\n className={clsx(\n css`\n position: absolute;\n width: var(--width);\n height: var(--height);\n transition: var(--transition);\n left: 0;\n top: 0;\n transform: translate(var(--left), var(--top));\n `,\n wrapperClassName,\n )}\n style={transformCSSVariable(\n {\n width: px(itemWidth),\n height: px(itemHeight),\n transition: transitionDuration === 0 ? \"none\" : `all ${transitionDuration || 400}ms`,\n left: px(getPosition(index).left),\n top: px(getPosition(index).top),\n },\n wrapperStyle,\n )}\n >\n <div\n className={clsx(\n css`\n width: 100%;\n height: 100%;\n display: var(--display);\n `,\n containerClassName,\n )}\n style={transformCSSVariable({ display: getHidden(index) ? \"none\" : \"block\" }, containerStyle)}\n >\n {render(item, index, arr)}\n </div>\n </div>\n ))}\n </div>\n )\n}\n\n/** 自适应浮动组件 */\nexport function Flow<T>(props: FlowProps<T>) {\n const {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n gap,\n maxRows,\n data,\n render,\n keyExactor,\n wrapperClassName,\n wrapperStyle,\n containerClassName,\n containerStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n element,\n ...rest\n } = props\n const ele = useRef<HTMLDivElement>(null)\n const size = useSize(ele)\n const width = useRef(size?.width || 0)\n if (size && size.width !== 0) width.current = size.width\n useImperativeHandle(element, () => ele.current!, [ele.current])\n if (width.current === 0) return <div ref={ele} {...rest} />\n return <ManualFlow element={ele} {...props} width={width.current} />\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,OAAO,QAAQ,QAAQ;AAChC,SAASC,IAAI,QAAQ,eAAe;AACpC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KAAK;IAAET,KAAK,EAAEA,KAAK,CAAC+C;EAAQ,CAAE,CAAC;AACxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","Fragment","css","jsx","_jsx","jsxs","_jsxs","FormLabel","props","className","style","before","width","rest","children"],"sources":["../../../src/components/FormLabel.tsx"],"sourcesContent":["import { clsx } from \"deepsea-tools\"\nimport { ComponentPropsWithoutRef, FC, Fragment } from \"react\"\n\nimport { css } from \"@emotion/css\"\n\nexport type FormLabelProps = ComponentPropsWithoutRef<\"div\"> & {\n /**\n * Label 的宽度.\n */\n width: number\n /**\n * 是否在 Label 前面添加一个空白区域,只有当前 Label 为非必选,而存在其他 Label 为必选的时候开启\n */\n before?: boolean\n}\n\n/**\n * 为 Ant Design 的 FormItem 设计的 Label 组件\n */\nexport const FormLabel: FC<FormLabelProps> = props => {\n const { className, style, before, width, ...rest } = props\n\n return (\n <Fragment>\n {!!before && <div style={{ width: 11 }}> </div>}\n <div\n className={clsx(\n css`\n text-align: justify;\n text-align-last: justify;\n `,\n className,\n )}\n style={{ width, ...style }}\n {...rest}\n />\n </Fragment>\n )\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,eAAe;AACpC,SAAuCC,QAAQ,QAAQ,OAAO;AAE9D,SAASC,GAAG,QAAQ,cAAc;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAalC;AACA;AACA;AACA,OAAO,MAAMC,SAA6B,GAAGC,KAAK,IAAI;EAClD,MAAM;IAAEC,SAAS;IAAEC,KAAK;IAAEC,MAAM;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGL,KAAK;EAE1D,oBACIF,KAAA,CAACL,QAAQ;IAAAa,QAAA,GACJ,CAAC,CAACH,MAAM,iBAAIP,IAAA;MAAKM,KAAK,EAAE;QAAEE,KAAK,EAAE;MAAG,CAAE;MAAAE,QAAA,EAAC;IAAM,CAAK,CAAC,eACpDV,IAAA;MACIK,SAAS,EAAET,IAAI,CACXE,GAAI;AACxB;AACA;AACA,qBAAqB,EACDO,SACJ,CAAE;MACFC,KAAK,EAAE;QAAEE,KAAK;QAAE,GAAGF;MAAM,CAAE;MAAA,GACvBG;IAAI,CACX,CAAC;EAAA,CACI,CAAC;AAEnB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type InfiniteScrollProps =
|
|
1
|
+
import { CSSProperties, ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export type InfiniteScrollProps = ComponentPropsWithoutRef<"div"> & {
|
|
3
3
|
/**
|
|
4
4
|
* 滚动的方向
|
|
5
5
|
* @default "vertical"
|
|
@@ -28,4 +28,27 @@ export type InfiniteScrollProps = ComponentProps<"div"> & {
|
|
|
28
28
|
* 子元素会内置的容器中被渲染两次,首尾相连,形成无限滚动的效果
|
|
29
29
|
* 但是,如果内部检测到并没有溢出,那么不会渲染两次,并且没有动画
|
|
30
30
|
*/
|
|
31
|
-
export declare const InfiniteScroll: import("react").ForwardRefExoticComponent<Omit<
|
|
31
|
+
export declare const InfiniteScroll: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
32
|
+
/**
|
|
33
|
+
* 滚动的方向
|
|
34
|
+
* @default "vertical"
|
|
35
|
+
*/
|
|
36
|
+
direction?: "horizontal" | "vertical" | undefined;
|
|
37
|
+
/** 渲染 children 的容器的类名 */
|
|
38
|
+
containerClassName?: string | undefined;
|
|
39
|
+
/** 渲染 children 的容器的样式 */
|
|
40
|
+
containerStyle?: CSSProperties | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* 两个 children 容器之间的间距
|
|
43
|
+
* @default 0
|
|
44
|
+
*/
|
|
45
|
+
gap?: number | undefined;
|
|
46
|
+
/** 一个周期的时间,单位:毫秒 */
|
|
47
|
+
duration: number;
|
|
48
|
+
/** 是否将 gap 的距离也加入 overflow 的计算 */
|
|
49
|
+
withGap?: boolean | undefined;
|
|
50
|
+
/** 尺寸刚好相同时,是否视为溢出 */
|
|
51
|
+
withEqual?: boolean | undefined;
|
|
52
|
+
/** 鼠标移入时,是否停止动画 */
|
|
53
|
+
pauseOnHover?: boolean | undefined;
|
|
54
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { css } from "@emotion/css";
|
|
2
1
|
import { useSize } from "ahooks";
|
|
3
2
|
import { clsx } from "deepsea-tools";
|
|
4
3
|
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
4
|
+
import { css } from "@emotion/css";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useSize","clsx","forwardRef","useEffect","useImperativeHandle","useRef","css","jsx","_jsx","jsxs","_jsxs","InfiniteScroll","props","ref","className","direction","children","containerClassName","containerStyle","gap","duration","withGap","withEqual","pauseOnHover","onMouseEnter","onMouseLeave","rest","wrapper","wrapperSize","ele","current","container","containerSize","bigger","overflow","height","width","animation","undefined","animate","transform","iterations","Infinity","cancel","enter","e","pause","leave","play","playState","style","position"],"sources":["../../../src/components/InfiniteScroll.tsx"],"sourcesContent":["import { useSize } from \"ahooks\"\nimport { clsx } from \"deepsea-tools\"\nimport { CSSProperties, ComponentPropsWithoutRef, MouseEvent as ReactMouseEvent, forwardRef, useEffect, useImperativeHandle, useRef } from \"react\"\n\nimport { css } from \"@emotion/css\"\n\nexport type InfiniteScrollProps = ComponentPropsWithoutRef<\"div\"> & {\n /**\n * 滚动的方向\n * @default \"vertical\"\n */\n direction?: \"vertical\" | \"horizontal\"\n /** 渲染 children 的容器的类名 */\n containerClassName?: string\n /** 渲染 children 的容器的样式 */\n containerStyle?: CSSProperties\n /**\n * 两个 children 容器之间的间距\n * @default 0\n */\n gap?: number\n /** 一个周期的时间,单位:毫秒 */\n duration: number\n /** 是否将 gap 的距离也加入 overflow 的计算 */\n withGap?: boolean\n /** 尺寸刚好相同时,是否视为溢出 */\n withEqual?: boolean\n /** 鼠标移入时,是否停止动画 */\n pauseOnHover?: boolean\n}\n\n/**\n * 无限滚动的组件\n * 子元素会内置的容器中被渲染两次,首尾相连,形成无限滚动的效果\n * 但是,如果内部检测到并没有溢出,那么不会渲染两次,并且没有动画\n */\nexport const InfiniteScroll = forwardRef<HTMLDivElement, InfiniteScrollProps>((props, ref) => {\n const {\n className,\n direction = \"vertical\",\n children,\n containerClassName,\n containerStyle,\n gap = 0,\n duration,\n withGap,\n withEqual,\n pauseOnHover,\n onMouseEnter,\n onMouseLeave,\n ...rest\n } = props\n\n const wrapper = useRef<HTMLDivElement>(null)\n const wrapperSize = useSize(wrapper)\n\n const ele = useRef<HTMLDivElement>(null)\n\n useImperativeHandle(ref, () => wrapper.current as HTMLDivElement, [wrapper.current])\n\n const container = useRef<HTMLDivElement>(null)\n const containerSize = useSize(container)\n\n function bigger(containerSize: number, wrapperSize: number) {\n return withEqual ? containerSize + (withGap ? gap : 0) >= wrapperSize : containerSize + (withGap ? gap : 0) > wrapperSize\n }\n\n const overflow =\n wrapperSize && containerSize\n ? direction === \"vertical\"\n ? bigger(containerSize.height, wrapperSize.height)\n : bigger(containerSize.width, wrapperSize.width)\n : false\n\n const animation = useRef<Animation | undefined>(undefined)\n\n useEffect(() => {\n if (!wrapperSize || !containerSize || !overflow) return\n animation.current = ele.current?.animate(\n {\n transform:\n direction === \"vertical\"\n ? [`translateY(0)`, `translateY(-${containerSize.height + gap}px)`]\n : [`translateX(0)`, `translateX(-${containerSize.width + gap}px)`],\n },\n { duration, iterations: Infinity },\n )\n return () => animation.current?.cancel()\n }, [wrapperSize, containerSize, overflow, direction, duration])\n\n function enter(e: ReactMouseEvent<HTMLDivElement, MouseEvent>) {\n if (pauseOnHover) animation.current?.pause()\n onMouseEnter?.(e)\n }\n\n function leave(e: ReactMouseEvent<HTMLDivElement, MouseEvent>) {\n if (pauseOnHover) animation.current?.play()\n onMouseLeave?.(e)\n }\n\n useEffect(() => {\n if (!pauseOnHover && animation.current?.playState === \"paused\") animation.current?.play()\n }, [animation.current, pauseOnHover])\n\n return (\n <div\n ref={wrapper}\n className={clsx(\n css`\n position: relative;\n ${direction === \"vertical\" ? \"overflow-y: hidden;\" : \"overflow-x: hidden;\"}\n `,\n className,\n )}\n onMouseEnter={enter}\n onMouseLeave={leave}\n {...rest}\n >\n <div\n ref={ele}\n style={{\n position: \"absolute\",\n width: direction === \"vertical\" ? \"100%\" : containerSize && (overflow ? containerSize.width * 2 + gap : containerSize.width),\n height: direction === \"horizontal\" ? \"100%\" : containerSize && (overflow ? containerSize.height * 2 + gap : containerSize.width),\n }}\n >\n <div\n ref={container}\n className={clsx(\n css`\n position: absolute;\n left: 0;\n top: 0;\n ${direction === \"vertical\" ? \"width: 100%;\" : \"height: 100%;\"}\n `,\n containerClassName,\n )}\n style={containerStyle}\n >\n {children}\n </div>\n {overflow && (\n <div\n ref={container}\n className={clsx(\n css`\n position: absolute;\n right: 0;\n bottom: 0;\n ${direction === \"vertical\" ? \"width: 100%;\" : \"height: 100%;\"}\n `,\n containerClassName,\n )}\n style={containerStyle}\n >\n {children}\n </div>\n )}\n </div>\n </div>\n )\n})\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,QAAQ;AAChC,SAASC,IAAI,QAAQ,eAAe;AACpC,SAAiFC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAElJ,SAASC,GAAG,QAAQ,cAAc;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AA2BlC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,gBAAGT,UAAU,CAAsC,CAACU,KAAK,EAAEC,G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AA,GAChBrB,IAAI;IAAAV,QAAA,eAERN,KAAA;MACIG,GAAG,EAAEgB,GAAI;MACTqB,KAAK,EAAE;QACHC,QAAQ,EAAE,UAAU;QACpBf,KAAK,EAAErB,SAAS,KAAK,UAAU,GAAG,MAAM,GAAGiB,aAAa,KAAKE,QAAQ,GAAGF,aAAa,CAACI,KAAK,GAAG,CAAC,GAAGjB,GAAG,GAAGa,aAAa,CAACI,KAAK,CAAC;QAC5HD,MAAM,EAAEpB,SAAS,KAAK,YAAY,GAAG,MAAM,GAAGiB,aAAa,KAAKE,QAAQ,GAAGF,aAAa,CAACG,MAAM,GAAG,CAAC,GAAGhB,GAAG,GAAGa,aAAa,CAACI,KAAK;MACnI,CAAE;MAAApB,QAAA,gBAEFR,IAAA;QACIK,GAAG,EAAEkB,SAAU;QACfjB,SAAS,EAAEb,IAAI,CACXK,GAAI;AAC5B;AACA;AACA;AACA,8BAA8BS,SAAS,KAAK,UAAU,GAAG,cAAc,GAAG,eAAgB;AAC1F,yBAAyB,EACDE,kBACJ,CAAE;QACFiC,KAAK,EAAEhC,cAAe;QAAAF,QAAA,EAErBA;MAAQ,CACR,CAAC,EACLkB,QAAQ,iBACL1B,IAAA;QACIK,GAAG,EAAEkB,SAAU;QACfjB,SAAS,EAAEb,IAAI,CACXK,GAAI;AAChC;AACA;AACA;AACA,kCAAkCS,SAAS,KAAK,UAAU,GAAG,cAAc,GAAG,eAAgB;AAC9F,6BAA6B,EACDE,kBACJ,CAAE;QACFiC,KAAK,EAAEhC,cAAe;QAAAF,QAAA,EAErBA;MAAQ,CACR,CACR;IAAA,CACA;EAAC,CACL,CAAC;AAEd,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { css } from "@emotion/css";
|
|
4
3
|
import { clsx } from "deepsea-tools";
|
|
5
4
|
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
5
|
+
import { css } from "@emotion/css";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
8
|
/** 循环播放组件 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","forwardRef","useEffect","useImperativeHandle","useRef","useState","css","jsx","_jsx","jsxs","_jsxs","LoopSwiper","props","ref","className","style","children","direction","period","reverse","gap","rest","wrapper","container","swiper","setSwiper","directionRef","current","flexDirection","animationName","animationDuration","animationTimingFunction","animationIterationCount","wrapperEle","containerEle","wrapperWidth","wrapperHeight","containerWidth","containerHeight","observer","ResizeObserver","entries","forEach","entry","target","contentRect","width","height","observe","display"],"sources":["../../../src/components/LoopSwiper.tsx"],"sourcesContent":["\"use client\"\n\nimport { clsx } from \"deepsea-tools\"\nimport { CSSProperties, HTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef, useState } from \"react\"\n\nimport { css } from \"@emotion/css\"\n\nexport interface LoopSwiperProps extends HTMLAttributes<HTMLDivElement> {\n direction?: \"horizontal\" | \"vertical\"\n reverse?: boolean\n period: number\n gap?: CSSProperties[\"gap\"]\n}\n\n/** 循环播放组件 */\nexport const LoopSwiper = forwardRef<HTMLDivElement, LoopSwiperProps>((props, ref) => {\n const { className, style, children, direction, period, reverse, gap, ...rest } = props\n const wrapper = useRef<HTMLDivElement>(null)\n const container = useRef<HTMLDivElement>(null)\n const [swiper, setSwiper] = useState(false)\n const directionRef = useRef(direction)\n directionRef.current = direction\n const flexDirection: CSSProperties[\"flexDirection\"] = direction === \"vertical\" ? (reverse ? \"column-reverse\" : \"column\") : reverse ? \"row-reverse\" : \"row\"\n const animationName = swiper\n ? direction === \"vertical\"\n ? reverse\n ? \"deepsea-reverse-vertical-loop-swipe\"\n : \"deepsea-vertical-loop-swipe\"\n : reverse\n ? \"deepsea-reverse-horizontal-loop-swipe\"\n : \"deepsea-horizontal-loop-swipe\"\n : \"none\"\n const animationDuration = `${period}ms`\n const animationTimingFunction = \"linear\"\n const animationIterationCount = \"infinite\"\n\n useImperativeHandle(ref, () => wrapper.current!, [])\n\n useEffect(() => {\n const wrapperEle = wrapper.current!\n const containerEle = container.current!\n let wrapperWidth = 0\n let wrapperHeight = 0\n let containerWidth = 0\n let containerHeight = 0\n const observer = new ResizeObserver(entries => {\n entries.forEach(entry => {\n if (entry.target === wrapperEle) {\n wrapperWidth = entry.contentRect.width\n wrapperHeight = entry.contentRect.height\n } else if (entry.target === containerEle) {\n containerWidth = entry.contentRect.width\n containerHeight = entry.contentRect.height\n }\n })\n setSwiper(directionRef.current === \"vertical\" ? containerHeight > wrapperHeight : containerWidth > wrapperWidth)\n })\n observer.observe(wrapperEle)\n observer.observe(containerEle)\n }, [])\n\n return (\n <div\n ref={wrapper}\n className={clsx(\n css`\n @keyframes deepsea-horizontal-loop-swipe {\n from {\n transform: translateX(0);\n }\n to {\n transform: translateX(-100%);\n }\n }\n @keyframes deepsea-reverse-horizontal-loop-swipe {\n from {\n transform: translateX(0);\n }\n to {\n transform: translateX(100%);\n }\n }\n @keyframes deepsea-vertical-loop-swipe {\n from {\n transform: translateY(0);\n }\n to {\n transform: translateY(-100%);\n }\n }\n @keyframes deepsea-reverse-vertical-loop-swipe {\n from {\n transform: translateY(0);\n }\n to {\n transform: translateY(100%);\n }\n }\n `,\n className,\n )}\n style={{ display: \"flex\", flexDirection, gap, ...style }}\n {...rest}\n >\n <div\n ref={container}\n style={{ display: \"flex\", flexDirection, gap, animationName, animationTimingFunction, animationDuration, animationIterationCount }}\n >\n {children}\n </div>\n <div\n style={{\n display: swiper ? \"flex\" : \"none\",\n flexDirection,\n gap,\n animationName,\n animationTimingFunction,\n animationDuration,\n animationIterationCount,\n }}\n >\n {children}\n </div>\n </div>\n )\n})\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,IAAI,QAAQ,eAAe;AACpC,SAAwCC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC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