deepsea-components 5.6.0 → 5.7.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/README.md +23 -23
- package/dist/cjs/components/AutoFit.js +3 -1
- package/dist/cjs/components/AutoFit.js.map +2 -2
- package/dist/cjs/components/AutoScroll.js +16 -1
- package/dist/cjs/components/AutoScroll.js.map +2 -2
- package/dist/cjs/components/AutoSizeTextarea.js.map +1 -1
- package/dist/cjs/components/CircleText.js +31 -2
- package/dist/cjs/components/CircleText.js.map +2 -2
- package/dist/cjs/components/CopyButton.d.ts +9 -0
- package/dist/cjs/components/CopyButton.js +59 -0
- package/dist/cjs/components/CopyButton.js.map +7 -0
- package/dist/cjs/components/Echart.js.map +2 -2
- package/dist/cjs/components/Flow.js +56 -3
- package/dist/cjs/components/Flow.js.map +2 -2
- package/dist/cjs/components/FormLabel.js.map +1 -1
- package/dist/cjs/components/HlsPlayer.js.map +1 -1
- package/dist/cjs/components/InfiniteScroll.js +15 -1
- package/dist/cjs/components/InfiniteScroll.js.map +2 -2
- package/dist/cjs/components/InputFile.js.map +1 -1
- package/dist/cjs/components/LoopSwiper.js +23 -2
- package/dist/cjs/components/LoopSwiper.js.map +2 -2
- package/dist/cjs/components/Ring.js +13 -1
- package/dist/cjs/components/Ring.js.map +2 -2
- package/dist/cjs/components/Scroll.js.map +2 -2
- package/dist/cjs/components/SectionRing.js +3 -1
- package/dist/cjs/components/SectionRing.js.map +2 -2
- package/dist/cjs/components/Skeleton.js.map +2 -2
- package/dist/cjs/components/Title.js.map +2 -2
- package/dist/cjs/components/TransitionBox.js +9 -1
- package/dist/cjs/components/TransitionBox.js.map +2 -2
- package/dist/cjs/components/TransitionNum.js.map +1 -1
- package/dist/cjs/components/Trapezium.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/getReactVersion.js.map +1 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/esm/components/AutoFit.js +9 -9
- package/dist/esm/components/AutoFit.js.map +1 -1
- package/dist/esm/components/AutoScroll.js.map +1 -1
- package/dist/esm/components/AutoSizeTextarea.js +2 -2
- package/dist/esm/components/AutoSizeTextarea.js.map +1 -1
- package/dist/esm/components/CircleText.js.map +1 -1
- package/dist/esm/components/CopyButton.d.ts +9 -0
- package/dist/esm/components/CopyButton.js +29 -0
- package/dist/esm/components/CopyButton.js.map +1 -0
- package/dist/esm/components/Echart.js.map +1 -1
- package/dist/esm/components/Flow.js.map +1 -1
- package/dist/esm/components/FormLabel.js +2 -2
- package/dist/esm/components/FormLabel.js.map +1 -1
- package/dist/esm/components/HlsPlayer.js.map +1 -1
- package/dist/esm/components/InfiniteScroll.js +4 -4
- package/dist/esm/components/InfiniteScroll.js.map +1 -1
- package/dist/esm/components/InputFile.js.map +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.js.map +1 -1
- package/dist/esm/components/SectionRing.js.map +1 -1
- package/dist/esm/components/Skeleton.js.map +1 -1
- package/dist/esm/components/Title.js.map +1 -1
- package/dist/esm/components/TransitionBox.js.map +1 -1
- package/dist/esm/components/TransitionNum.js.map +1 -1
- package/dist/esm/components/Trapezium.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/getReactVersion.js.map +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/package.json +4 -2
- package/src/components/AutoFit.tsx +103 -101
- package/src/components/AutoScroll.tsx +148 -132
- package/src/components/AutoSizeTextarea.tsx +49 -49
- package/src/components/CircleText.tsx +81 -56
- package/src/components/CopyButton.tsx +29 -0
- package/src/components/Echart.tsx +67 -44
- package/src/components/Flow.tsx +270 -214
- package/src/components/FormLabel.tsx +38 -38
- package/src/components/HlsPlayer.tsx +34 -34
- package/src/components/InfiniteScroll.tsx +161 -135
- package/src/components/InputFile.tsx +234 -234
- package/src/components/LoopSwiper.tsx +125 -101
- package/src/components/Ring.tsx +30 -19
- package/src/components/Scroll.tsx +96 -95
- package/src/components/SectionRing.tsx +39 -36
- package/src/components/Skeleton.tsx +47 -46
- package/src/components/Title.tsx +23 -24
- package/src/components/TransitionBox.tsx +44 -36
- package/src/components/TransitionNum.tsx +54 -54
- package/src/components/Trapezium.tsx +59 -59
- package/src/index.ts +1 -0
- package/src/utils/getReactVersion.ts +7 -7
- package/src/utils/index.ts +33 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["drawArc","jsx","_jsx","SectionRing","props","outerRadius","o","innerRadius","i","count","c","angel","a","style","rest","s","Math","PI","arc","radius","startAngle","endAngle","options","width","height","clipPath","Array","fill","map","it","idx","line","anticlockwise","join"],"sources":["../../../src/components/SectionRing.tsx"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"names":["drawArc","jsx","_jsx","SectionRing","props","outerRadius","o","innerRadius","i","count","c","angel","a","style","rest","s","Math","PI","arc","radius","startAngle","endAngle","options","width","height","clipPath","Array","fill","map","it","idx","line","anticlockwise","join"],"sources":["../../../src/components/SectionRing.tsx"],"sourcesContent":["\"use client\"\n\nimport { DrawArcOptions, drawArc } from \"deepsea-tools\"\nimport { FC, HTMLAttributes } from \"react\"\n\nexport interface SectionRingProps extends HTMLAttributes<HTMLDivElement> {\n outerRadius: number\n innerRadius: number\n count: number\n angel: number\n}\n\nexport const SectionRing: FC<SectionRingProps> = props => {\n const { outerRadius: o, innerRadius: i, count: c, angel: a, style, ...rest } = props\n\n const s = (Math.PI * 2) / c - a\n\n function arc(radius: number, startAngle: number, endAngle: number, options: DrawArcOptions = {}) {\n return drawArc(o, o, radius, startAngle, endAngle, options)\n }\n\n return (\n <div\n style={{\n ...style,\n width: o * 2,\n height: o * 2,\n clipPath: `path(\"${Array(c)\n .fill(0)\n .map(\n (it, idx) =>\n `${arc(o, idx *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AG,IAAIlB,CAAC,GAAGG,CAAC,CAAC,EAAE;QAAEgB,IAAI,EAAE,IAAI;QAAEC,aAAa,EAAE;MAAK,CAAC,CAAE,EACrI,CAAC,CACAC,IAAI,CAAC,GAAG,CAAE;IACnB,CAAE;IAAA,GACEnB;EAAI,CACX,CAAC;AAEV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["css","clsx","forwardRef","jsx","_jsx","Skeleton","props","ref","className","loading","children","rest","undefined"],"sources":["../../../src/components/Skeleton.tsx"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"names":["css","clsx","forwardRef","jsx","_jsx","Skeleton","props","ref","className","loading","children","rest","undefined"],"sources":["../../../src/components/Skeleton.tsx"],"sourcesContent":["\"use client\"\n\nimport { css } from \"@emotion/css\"\nimport { clsx } from \"deepsea-tools\"\nimport { forwardRef, HTMLAttributes } from \"react\"\n\nexport interface SkeletonProps extends HTMLAttributes<HTMLDivElement> {\n loading?: boolean\n}\n\nexport const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>((props, ref) => {\n let { className, loading, children, ...rest } = props\n\n loading ??= children === undefined || children === null\n\n return (\n <div\n ref={ref}\n className={clsx(\n css`\n @keyframes shimmer {\n 0% {\n background-position: -400px 0px;\n }\n 100% {\n background-position: 400px 0px;\n }\n }\n `,\n loading &&\n css`\n background-image: linear-gradient(to right, rgba(0, 0, 0, 0.067) 8%, rgba(0, 0, 0, 0.133) 18%, rgba(0, 0, 0, 0.067) 33%);\n animation-duration: 1s;\n animation-fill-mode: forwards;\n animation-iteration-count: infinite;\n animation-name: shimmer;\n animation-timing-function: linear;\n background-size: 800px 104px;\n `,\n className,\n )}\n {...rest}\n >\n {children}\n </div>\n )\n})\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,IAAI,QAAQ,eAAe;AACpC,SAASC,UAAU,QAAwB,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAMlD,OAAO,MAAMC,QAAQ,gBAAGH,UAAU,CAAgC,CAACI,KAAK,EAAEC,GAAG,KAAK;EAC9E,IAAI;IAAEC,SAAS;IAAEC,OAAO;IAAEC,QAAQ;IAAE,GAAGC;EAAK,CAAC,GAAGL,KAAK;EAErDG,OAAO,KAAKC,QAAQ,KAAKE,SAAS,IAAIF,QAAQ,KAAK,IAAI;EAEvD,oBACIN,IAAA;IACIG,GAAG,EAAEA,GAAI;IACTC,SAAS,EAAEP,IAAI,CACXD,GAAI;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,EACDS,OAAO,IACHT,GAAI;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,EACLQ,SACJ,CAAE;IAAA,GACEG,IAAI;IAAAD,QAAA,EAEPA;EAAQ,CACR,CAAC;AAEd,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useImperativeHandle","useLayoutEffect","useRef","createPortal","getReactVersion","jsx","_jsx","major","Title","props","ref","ele","current","title","document","head","querySelector","insertBefore"],"sources":["../../../src/components/Title.tsx"],"sourcesContent":["import { ComponentProps, forwardRef, useImperativeHandle, useLayoutEffect, useRef } from \"react\"\
|
|
1
|
+
{"version":3,"names":["forwardRef","useImperativeHandle","useLayoutEffect","useRef","createPortal","getReactVersion","jsx","_jsx","major","Title","props","ref","ele","current","title","document","head","querySelector","insertBefore"],"sources":["../../../src/components/Title.tsx"],"sourcesContent":["import { ComponentProps, forwardRef, useImperativeHandle, useLayoutEffect, useRef } from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { getReactVersion } from \"../utils/getReactVersion\"\n\nexport type TitleProps = ComponentProps<\"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"],"mappings":"AAAA,SAAyBA,UAAU,EAAEC,mBAAmB,EAAEC,eAAe,EAAEC,MAAM,QAAQ,OAAO;AAChG,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,eAAe;AAAkC,SAAAC,GAAA,IAAAC,IAAA;AAI1D,MAAM,CAACC,KAAK,CAAC,GAAGH,eAAe,CAAC,CAAC;AAEjC,OAAO,MAAMI,KAAK,gBAAGT,UAAU,CAA+B,CAACU,KAAK,EAAEC,GAAG,KAAK;EAC1E,IAAIH,KAAK,IAAI,EAAE,EAAE,oBAAOD,IAAA;IAAOI,GAAG,EAAEA,GAAI;IAAA,GAAKD;EAAK,CAAG,CAAC;EAEtD,MAAME,GAAG,GAAGT,MAAM,CAAmB,IAAI,CAAC;EAE1CF,mBAAmB,CAACU,GAAG,EAAE,MAAMC,GAAG,CAACC,OAA2B,EAAE,CAACD,GAAG,CAACC,OAAO,CAAC,CAAC;EAE9EX,eAAe,CAAC,MAAM;IAClB,MAAMY,KAAK,GAAGC,QAAQ,CAACC,IAAI,CAACC,aAAa,CAAC,OAAO,CAAC;IAClD,IAAIH,KAAK,KAAKF,GAAG,CAACC,OAAO,EAAE;IAC3BE,QAAQ,CAACC,IAAI,CAACE,YAAY,CAACN,GAAG,CAACC,OAAO,EAAsBC,KAAK,CAAC;EACtE,CAAC,EAAE,EAAE,CAAC;EAEN,oBAAOV,YAAY,eAACG,IAAA;IAAOI,GAAG,EAAEC,GAAI;IAAA,GAAKF;EAAK,CAAG,CAAC,EAAEK,QAAQ,CAACC,IAAI,CAAC;AACtE,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useSize","forwardRef","useEffect","useRef","useState","jsx","_jsx","TransitionBox","props","ref","style","containerClassName","containerStyle","children","vertical","horizontal","time","rest","container","size","width","height","count","setCount","Math","min","outerStyle","transitionProperty","filter","Boolean","join","undefined","transitionDuration","overflow","position","className"],"sources":["../../../src/components/TransitionBox.tsx"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"names":["useSize","forwardRef","useEffect","useRef","useState","jsx","_jsx","TransitionBox","props","ref","style","containerClassName","containerStyle","children","vertical","horizontal","time","rest","container","size","width","height","count","setCount","Math","min","outerStyle","transitionProperty","filter","Boolean","join","undefined","transitionDuration","overflow","position","className"],"sources":["../../../src/components/TransitionBox.tsx"],"sourcesContent":["\"use client\"\n\nimport { useSize } from \"ahooks\"\nimport { CSSProperties, FC, forwardRef, HTMLAttributes, 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"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,OAAO,QAAQ,QAAQ;AAChC,SAA4BC,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AAC;EAED,oBACIJ,IAAA;IAAKG,GAAG,EAAEA,GAAI;IAACC,KAAK,EAAEgB,UAAW;IAAA,GAAKT,IAAI;IAAAJ,QAAA,eACtCP,IAAA;MAAK6B,SAAS,EAAExB,kBAAmB;MAACD,KAAK,EAAE;QAAEwB,QAAQ,EAAE,UAAU;QAAE,GAAGtB;MAAe,CAAE;MAACH,GAAG,EAAES,SAAU;MAAAL,QAAA,EAClGA;IAAQ,CACR;EAAC,CACL,CAAC;AAEd,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["setFrameInterval","forwardRef","useEffect","useImperativeHandle","useRef","jsx","_jsx","TransitionNum","props","ref","children","num","period","numToStr","ins","rest","Number","isInteger","RangeError","ele","cache","show","current","get","innerText","String","div","speed","cancel","Math","floor","ceil"],"sources":["../../../src/components/TransitionNum.tsx"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"names":["setFrameInterval","forwardRef","useEffect","useImperativeHandle","useRef","jsx","_jsx","TransitionNum","props","ref","children","num","period","numToStr","ins","rest","Number","isInteger","RangeError","ele","cache","show","current","get","innerText","String","div","speed","cancel","Math","floor","ceil"],"sources":["../../../src/components/TransitionNum.tsx"],"sourcesContent":["\"use client\"\n\nimport { setFrameInterval } from \"deepsea-tools\"\nimport { ForwardedRef, HTMLAttributes, forwardRef, useEffect, useImperativeHandle, useRef } from \"react\"\n\nexport interface TransitionNumProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** 当前数字 */\n children: number\n /** 变换周期,单位帧 */\n period: number\n /** 数字转换为字符串的方法 */\n numToStr?: (num: number) => string\n /** 实例 */\n ins?: ForwardedRef<TransitionNumIns>\n}\n\nexport interface TransitionNumIns {\n get(): number\n}\n\n/** 渐变数字组件 */\nexport const TransitionNum = forwardRef<HTMLDivElement, TransitionNumProps>((props, ref) => {\n const { children: num, period, numToStr, ins, ...rest } = props\n if (!Number.isInteger(num) || !Number.isInteger(period) || period <= 0) {\n throw new RangeError(\"目标数字必须是整数,周期必须是正整数\")\n }\n const ele = useRef<HTMLDivElement>(null)\n const cache = useRef({ num, period, numToStr, show: num })\n cache.current = { ...cache.current, num, period, numToStr }\n\n useImperativeHandle(ref, () => ele.current!, [])\n useImperativeHandle(ins, () => ({ get: () => cache.current.show }), [])\n\n useEffect(() => {\n const { num, period, show, numToStr } = cache.current\n ele.current!.innerText = (numToStr || String)(show)\n if (num === show) return\n const div = ele.current!\n const speed = (num - show) / period\n const cancel = setFrameInterval(() => {\n const { num, numToStr } = cache.current\n cache.current.show += speed\n if ((speed > 0 && cache.current.show > num) || (speed < 0 && cache.current.show < num)) {\n cancel()\n cache.current.show = num\n }\n div.innerText = (numToStr || String)(speed > 0 ? Math.floor(cache.current.show) : Math.ceil(cache.current.show))\n }, 1)\n\n return cancel\n }, [num])\n\n return <div ref={ele} {...rest} />\n})\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,gBAAgB,QAAQ,eAAe;AAChD,SAAuCC,UAAU,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAiBxG;AACA,OAAO,MAAMC,aAAa,gBAAGN,UAAU,CAAqC,CAACO,KAAK,EAAEC,GAAG,KAAK;EACxF,MAAM;IAAEC,QAAQ,EAAEC,GAAG;IAAEC,MAAM;IAAEC,QAAQ;IAAEC,GAAG;IAAE,GAAGC;EAAK,CAAC,GAAGP,KAAK;EAC/D,IAAI,CAACQ,MAAM,CAACC,SAAS,CAACN,GAAG,CAAC,IAAI,CAACK,MAAM,CAACC,SAAS,CAACL,MAAM,CAAC,IAAIA,MAAM,IAAI,CAAC,EAAE;IACpE,MAAM,IAAIM,UAAU,CAAC,oBAAoB,CAAC;EAC9C;EACA,MAAMC,GAAG,GAAGf,MAAM,CAAiB,IAAI,CAAC;EACxC,MAAMgB,KAAK,GAAGhB,MAAM,CAAC;IAAEO,GAAG;IAAEC,MAAM;IAAEC,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AAGE,IAAI,CAACC,KAAK,CAACV,KAAK,CAACE,OAAO,CAACD,IAAI,CAAC,GAAGQ,IAAI,CAACE,IAAI,CAACX,KAAK,CAACE,OAAO,CAACD,IAAI,CAAC,CAAC;IACpH,CAAC,EAAE,CAAC,CAAC;IAEL,OAAOO,MAAM;EACjB,CAAC,EAAE,CAACjB,GAAG,CAAC,CAAC;EAET,oBAAOL,IAAA;IAAKG,GAAG,EAAEU,GAAI;IAAA,GAAKJ;EAAI,CAAG,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["css","clsx","forwardRef","px","transformCSSVariable","jsx","_jsx","Trapezium","props","ref","top","bottom","height","borderRadius","className","style","rest","diff","a","Math","atan","b","tan","c","cos","d","sin","e","PI","f","g","h","width","clipath"],"sources":["../../../src/components/Trapezium.tsx"],"sourcesContent":["\"use client\"\
|
|
1
|
+
{"version":3,"names":["css","clsx","forwardRef","px","transformCSSVariable","jsx","_jsx","Trapezium","props","ref","top","bottom","height","borderRadius","className","style","rest","diff","a","Math","atan","b","tan","c","cos","d","sin","e","PI","f","g","h","width","clipath"],"sources":["../../../src/components/Trapezium.tsx"],"sourcesContent":["\"use client\"\n\nimport { css } from \"@emotion/css\"\nimport { clsx } from \"deepsea-tools\"\nimport { HTMLAttributes, forwardRef } from \"react\"\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"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,IAAI,QAAQ,eAAe;AACpC,SAAyBC,UAAU,QAAQ,OAAO;AAClD,SAASC,EAAE,EAAEC,oBAAoB;AAAkB,SAAAC,GAAA,IAAAC,IAAA;AASnD;AACA,OAAO,MAAMC,SAAS,gBAAGL,UAAU,CAAiC,CAACM,KAAK,EAAEC,GAAG,KAAK;EAChF,MAAM;IAAEC,GAAG;IAAEC,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC,SAAS;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGR,KAAK;EAE9E,MAAMS,IAAI,GAAG,CAACN,MAAM,GAAGD,GAAG,IAAI,CAAC;EAE/B,MAAMQ,CAAC,GAAGC,IAAI,CAACC,IAAI,CAACR,MAAM,GAAGK,IAAI,CAAC,GAAG,CAAC;EAEtC,MAAMI,CAAC,GAAGR,YAAY,GAAGM,IAAI,CAACG,GAAG,CAACJ,CAAC,CAAC;EAEpC,MAAMK,CAAC,GAAGF,CAAC,GAAGF,IAAI,CAACK,GAAG,CAACN,CAAC,GAAG,CAAC,CAAC;EAE7B,MAAMO,CAAC,GAAGJ,CAAC,GAAGF,IAAI,CAACO,GAAG,C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
2
2
|
export * from "./components/AutoScroll";
|
|
3
3
|
export * from "./components/AutoSizeTextarea";
|
|
4
4
|
export * from "./components/CircleText";
|
|
5
|
+
export * from "./components/CopyButton";
|
|
5
6
|
export * from "./components/Echart";
|
|
6
7
|
export * from "./components/Flow";
|
|
7
8
|
export * from "./components/FormLabel";
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./components/AutoFit";
|
|
|
2
2
|
export * from "./components/AutoScroll";
|
|
3
3
|
export * from "./components/AutoSizeTextarea";
|
|
4
4
|
export * from "./components/CircleText";
|
|
5
|
+
export * from "./components/CopyButton";
|
|
5
6
|
export * from "./components/Echart";
|
|
6
7
|
export * from "./components/Flow";
|
|
7
8
|
export * from "./components/FormLabel";
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@components/AutoFit\"\nexport * from \"@components/AutoScroll\"\nexport * from \"@components/AutoSizeTextarea\"\nexport * from \"@components/CircleText\"\nexport * from \"@components/Echart\"\nexport * from \"@components/Flow\"\nexport * from \"@components/FormLabel\"\nexport * from \"@components/HlsPlayer\"\nexport * from \"@components/InfiniteScroll\"\nexport * from \"@components/InputFile\"\nexport * from \"@components/LoopSwiper\"\nexport * from \"@components/Ring\"\nexport * from \"@components/Scroll\"\nexport * from \"@components/SectionRing\"\nexport * from \"@components/Skeleton\"\nexport * from \"@components/Title\"\nexport * from \"@components/TransitionBox\"\nexport * from \"@components/TransitionNum\"\nexport * from \"@components/Trapezium\"\nexport * from \"@utils/getReactVersion\"\nexport * from \"@utils/index\"\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@components/AutoFit\"\nexport * from \"@components/AutoScroll\"\nexport * from \"@components/AutoSizeTextarea\"\nexport * from \"@components/CircleText\"\nexport * from \"@components/CopyButton\"\nexport * from \"@components/Echart\"\nexport * from \"@components/Flow\"\nexport * from \"@components/FormLabel\"\nexport * from \"@components/HlsPlayer\"\nexport * from \"@components/InfiniteScroll\"\nexport * from \"@components/InputFile\"\nexport * from \"@components/LoopSwiper\"\nexport * from \"@components/Ring\"\nexport * from \"@components/Scroll\"\nexport * from \"@components/SectionRing\"\nexport * from \"@components/Skeleton\"\nexport * from \"@components/Title\"\nexport * from \"@components/TransitionBox\"\nexport * from \"@components/TransitionNum\"\nexport * from \"@components/Trapezium\"\nexport * from \"@utils/getReactVersion\"\nexport * from \"@utils/index\"\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["version","reg","getReactVersion","match","slice","map","Number"],"sources":["../../../src/utils/getReactVersion.ts"],"sourcesContent":["import { version } from \"react\"\
|
|
1
|
+
{"version":3,"names":["version","reg","getReactVersion","match","slice","map","Number"],"sources":["../../../src/utils/getReactVersion.ts"],"sourcesContent":["import { version } from \"react\"\n\nconst reg = /(\\d+)\\.(\\d+)\\.(\\d+)/\n\nexport function getReactVersion() {\n return version.match(reg)!.slice(1).map(Number)\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAE/B,MAAMC,GAAG,GAAG,qBAAqB;AAEjC,OAAO,SAASC,eAAeA,CAAA,EAAG;EAC9B,OAAOF,OAAO,CAACG,KAAK,CAACF,GAAG,CAAC,CAAEG,KAAK,CAAC,CAAC,CAAC,CAACC,GAAG,CAACC,MAAM,CAAC;AACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["cssVariableReg","addCSSVariableLine","match","transformCSSVariableName","name","replace","toLowerCase","transformCSSVariable","style","style2","Object","assign","entries","reduce","acc","key","value","px"],"sources":["../../../src/utils/index.ts"],"sourcesContent":["import { CSSProperties } from \"react\"\
|
|
1
|
+
{"version":3,"names":["cssVariableReg","addCSSVariableLine","match","transformCSSVariableName","name","replace","toLowerCase","transformCSSVariable","style","style2","Object","assign","entries","reduce","acc","key","value","px"],"sources":["../../../src/utils/index.ts"],"sourcesContent":["import { CSSProperties } from \"react\"\n\nexport type CSSVariableName = `--${string}`\n\nexport type CSSVariableValue = string | number | undefined\n\nexport interface StyleWithCSSVariable extends CSSProperties {\n [X: CSSVariableName]: CSSVariableValue\n}\n\nconst cssVariableReg = /[A-Z]/\n\nfunction addCSSVariableLine(match: string): string {\n return `-${match}`\n}\n\nexport function transformCSSVariableName(name: string): CSSVariableName {\n return `--${name.replace(cssVariableReg, addCSSVariableLine).toLowerCase()}`\n}\n\nexport function transformCSSVariable(style: Partial<Record<string, CSSVariableValue>>, style2?: CSSProperties): CSSProperties {\n return Object.assign(\n Object.entries(style).reduce((acc: StyleWithCSSVariable, [key, value]) => {\n acc[transformCSSVariableName(key)] = value\n return acc\n }, {}),\n style2,\n )\n}\n\nexport function px(value: string | number | undefined): string | undefined {\n return typeof value === \"number\" ? `${value}px` : value\n}\n"],"mappings":"AAUA,MAAMA,cAAc,GAAG,OAAO;AAE9B,SAASC,kBAAkBA,CAACC,KAAa,EAAU;EAC/C,OAAQ,IAAGA,KAAM,EAAC;AACtB;AAEA,OAAO,SAASC,wBAAwBA,CAACC,IAAY,EAAmB;EACpE,OAAQ,KAAIA,IAAI,CAACC,OAAO,CAACL,cAAc,EAAEC,kBAAkB,CAAC,CAACK,WAAW,CAAC,CAAE,EAAC;AAChF;AAEA,OAAO,SAASC,oBAAoBA,CAACC,KAAgD,EAAEC,MAAsB,EAAiB;EAC1H,OAAOC,MAAM,CAACC,MAAM,CAChBD,MAAM,CAACE,OAAO,CAACJ,KAAK,CAAC,CAACK,MAAM,CAAC,CAACC,GAAyB,EAAE,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;IACtEF,GAAG,CAACX,wBAAwB,CAACY,GAAG,CAAC,CAAC,GAAGC,KAAK;IAC1C,OAAOF,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAAC,EACNL,MACJ,CAAC;AACL;AAEA,OAAO,SAASQ,EAAEA,CAACD,KAAkC,EAAsB;EACvE,OAAO,OAAOA,KAAK,KAAK,QAAQ,GAAI,GAAEA,KAAM,IAAG,GAAGA,KAAK;AAC3D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepsea-components",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
4
4
|
"description": "格数科技自用组件库",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -27,11 +27,12 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@emotion/css": "^11.11.2",
|
|
29
29
|
"ahooks": "^3.7.11",
|
|
30
|
+
"clipboard": "^2.0.11",
|
|
30
31
|
"echarts": "^5.5.0",
|
|
31
32
|
"hls.js": "^1.5.8",
|
|
32
33
|
"smooth-scrollbar": "^8.8.4",
|
|
33
34
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
|
|
34
|
-
"deepsea-tools": "5.
|
|
35
|
+
"deepsea-tools": "5.12.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"@types/react": "^18.3.1",
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"scripts": {
|
|
43
44
|
"dev": "father dev",
|
|
44
45
|
"build": "father build",
|
|
46
|
+
"prebuild": "tsx scripts/export.ts",
|
|
45
47
|
"build:deps": "father prebundle"
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -1,101 +1,103 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { css } from "@emotion/css"
|
|
4
|
-
import { clsx } from "deepsea-tools"
|
|
5
|
-
import { forwardRef, HTMLAttributes, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react"
|
|
6
|
-
import { px, transformCSSVariable } from "../utils"
|
|
7
|
-
|
|
8
|
-
export interface AutoFitProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
-
/** 设计稿宽度,默认 1920 */
|
|
10
|
-
width?: number
|
|
11
|
-
/** 设计稿高度,默认 1080 */
|
|
12
|
-
height?: number
|
|
13
|
-
/**
|
|
14
|
-
* 在哪些方向进行缩放,默认缩放所有方向
|
|
15
|
-
* 1. 水平方向是指,宽度按照设计稿进行占满,高度反向缩放
|
|
16
|
-
* 2. 垂直方向是指,高度按照设计稿进行占满,宽度反向缩放
|
|
17
|
-
* 3. 默认是水平和垂直方向都进行缩放,类似于 background-size: contain 的效果
|
|
18
|
-
*/
|
|
19
|
-
direction?: "horizontal" | "vertical" | "both"
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 自适应缩放组件
|
|
24
|
-
*
|
|
25
|
-
* 注意:
|
|
26
|
-
* 1. 父元素必须设置非 static 定位方式
|
|
27
|
-
* 2. 父元素只能有且仅有一个子元素,那就是 AutoFit
|
|
28
|
-
* 3. 不要设置 AutoFit 的 position、left、top、transform、width、height 属性
|
|
29
|
-
* 4. 在第一次完成缩放前,无论 props 是什么,返回的都是 <div style={{ display: "none" }} />
|
|
30
|
-
* 5. 元素的属性、事件、资源并不是立即加载的,会有一帧的延迟,在第一次完成缩放后才会显示
|
|
31
|
-
*/
|
|
32
|
-
export const AutoFit = forwardRef<HTMLDivElement, AutoFitProps>((props, ref) => {
|
|
33
|
-
const { width: designWidth = 1920, height: designHeight = 1080, direction, className, style, ...rest } = props
|
|
34
|
-
const ele = useRef<HTMLDivElement>(null)
|
|
35
|
-
const [show, setShow] = useState(false)
|
|
36
|
-
const [transform, setTransform] = useState<string | undefined>(undefined)
|
|
37
|
-
const [width, setWidth] = useState<string | undefined>(undefined)
|
|
38
|
-
const [height, setHeight] = useState<string | undefined>(undefined)
|
|
39
|
-
|
|
40
|
-
useImperativeHandle(ref, () => ele.current!, [ele.current])
|
|
41
|
-
useLayoutEffect(() => {
|
|
42
|
-
const element = ele.current
|
|
43
|
-
const parent = element?.parentElement
|
|
44
|
-
if (!element || !parent) return
|
|
45
|
-
function listener(entries: ResizeObserverEntry[]) {
|
|
46
|
-
const entry = entries[0]
|
|
47
|
-
const { contentRect } = entry
|
|
48
|
-
if (direction === "horizontal") {
|
|
49
|
-
const scale = contentRect.width / designWidth
|
|
50
|
-
setTransform(`scale(${scale})`)
|
|
51
|
-
setWidth(px(designWidth))
|
|
52
|
-
setHeight(px(contentRect.height / scale))
|
|
53
|
-
} else if (direction === "vertical") {
|
|
54
|
-
const scale = contentRect.height / designHeight
|
|
55
|
-
setTransform(`scale(${scale})`)
|
|
56
|
-
setWidth(px(contentRect.width / scale))
|
|
57
|
-
setHeight(px(designHeight))
|
|
58
|
-
} else {
|
|
59
|
-
const scale = Math.min(contentRect.width / designWidth, contentRect.height / designHeight)
|
|
60
|
-
setTransform(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { css } from "@emotion/css"
|
|
4
|
+
import { clsx } from "deepsea-tools"
|
|
5
|
+
import { forwardRef, HTMLAttributes, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react"
|
|
6
|
+
import { px, transformCSSVariable } from "../utils"
|
|
7
|
+
|
|
8
|
+
export interface AutoFitProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
/** 设计稿宽度,默认 1920 */
|
|
10
|
+
width?: number
|
|
11
|
+
/** 设计稿高度,默认 1080 */
|
|
12
|
+
height?: number
|
|
13
|
+
/**
|
|
14
|
+
* 在哪些方向进行缩放,默认缩放所有方向
|
|
15
|
+
* 1. 水平方向是指,宽度按照设计稿进行占满,高度反向缩放
|
|
16
|
+
* 2. 垂直方向是指,高度按照设计稿进行占满,宽度反向缩放
|
|
17
|
+
* 3. 默认是水平和垂直方向都进行缩放,类似于 background-size: contain 的效果
|
|
18
|
+
*/
|
|
19
|
+
direction?: "horizontal" | "vertical" | "both"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 自适应缩放组件
|
|
24
|
+
*
|
|
25
|
+
* 注意:
|
|
26
|
+
* 1. 父元素必须设置非 static 定位方式
|
|
27
|
+
* 2. 父元素只能有且仅有一个子元素,那就是 AutoFit
|
|
28
|
+
* 3. 不要设置 AutoFit 的 position、left、top、transform、width、height 属性
|
|
29
|
+
* 4. 在第一次完成缩放前,无论 props 是什么,返回的都是 <div style={{ display: "none" }} />
|
|
30
|
+
* 5. 元素的属性、事件、资源并不是立即加载的,会有一帧的延迟,在第一次完成缩放后才会显示
|
|
31
|
+
*/
|
|
32
|
+
export const AutoFit = forwardRef<HTMLDivElement, AutoFitProps>((props, ref) => {
|
|
33
|
+
const { width: designWidth = 1920, height: designHeight = 1080, direction, className, style, ...rest } = props
|
|
34
|
+
const ele = useRef<HTMLDivElement>(null)
|
|
35
|
+
const [show, setShow] = useState(false)
|
|
36
|
+
const [transform, setTransform] = useState<string | undefined>(undefined)
|
|
37
|
+
const [width, setWidth] = useState<string | undefined>(undefined)
|
|
38
|
+
const [height, setHeight] = useState<string | undefined>(undefined)
|
|
39
|
+
|
|
40
|
+
useImperativeHandle(ref, () => ele.current!, [ele.current])
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
const element = ele.current
|
|
43
|
+
const parent = element?.parentElement
|
|
44
|
+
if (!element || !parent) return
|
|
45
|
+
function listener(entries: ResizeObserverEntry[]) {
|
|
46
|
+
const entry = entries[0]
|
|
47
|
+
const { contentRect } = entry
|
|
48
|
+
if (direction === "horizontal") {
|
|
49
|
+
const scale = contentRect.width / designWidth
|
|
50
|
+
setTransform(`scale(${scale})`)
|
|
51
|
+
setWidth(px(designWidth))
|
|
52
|
+
setHeight(px(contentRect.height / scale))
|
|
53
|
+
} else if (direction === "vertical") {
|
|
54
|
+
const scale = contentRect.height / designHeight
|
|
55
|
+
setTransform(`scale(${scale})`)
|
|
56
|
+
setWidth(px(contentRect.width / scale))
|
|
57
|
+
setHeight(px(designHeight))
|
|
58
|
+
} else {
|
|
59
|
+
const scale = Math.min(contentRect.width / designWidth, contentRect.height / designHeight)
|
|
60
|
+
setTransform(
|
|
61
|
+
`translateX(${(contentRect.width - designWidth * scale) / 2}px) translateY(${(contentRect.height - designHeight * scale) / 2}px) scale(${scale})`,
|
|
62
|
+
)
|
|
63
|
+
setWidth(px(designWidth))
|
|
64
|
+
setHeight(px(designHeight))
|
|
65
|
+
}
|
|
66
|
+
setShow(true)
|
|
67
|
+
}
|
|
68
|
+
const observer = new ResizeObserver(listener)
|
|
69
|
+
observer.observe(parent)
|
|
70
|
+
return () => observer.disconnect()
|
|
71
|
+
}, [ele.current?.parentElement, designWidth, designHeight, direction])
|
|
72
|
+
|
|
73
|
+
if (process.env.NODE_ENV === "development") {
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const parent = ele.current?.parentElement
|
|
76
|
+
if (!parent) return
|
|
77
|
+
const style = getComputedStyle(parent)
|
|
78
|
+
if (style.position === "static") {
|
|
79
|
+
console.warn("AutoFit 组件的父元素的 position 属性不应该是 static")
|
|
80
|
+
}
|
|
81
|
+
}, [ele.current?.parentElement])
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!show) return <div ref={ele} style={{ display: "none" }} />
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div
|
|
88
|
+
ref={ele}
|
|
89
|
+
className={clsx(
|
|
90
|
+
css`
|
|
91
|
+
position: absolute;
|
|
92
|
+
transform: var(--transform);
|
|
93
|
+
transform-origin: top left;
|
|
94
|
+
width: var(--width);
|
|
95
|
+
height: var(--height);
|
|
96
|
+
`,
|
|
97
|
+
className,
|
|
98
|
+
)}
|
|
99
|
+
style={transformCSSVariable({ transform, width, height }, style)}
|
|
100
|
+
{...rest}
|
|
101
|
+
/>
|
|
102
|
+
)
|
|
103
|
+
})
|