@yorkjs/hive-ui 2.1.1 → 2.1.2
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/package.json
CHANGED
|
@@ -12,6 +12,7 @@ export interface IRemoteImageProps extends Omit<ImageProps, 'src'> {
|
|
|
12
12
|
height?: number
|
|
13
13
|
/** 是否不进行裁剪(等比缩放) */
|
|
14
14
|
noCrop?: boolean
|
|
15
|
+
imagePixelRatio?: number
|
|
15
16
|
/** 图片质量 1-100 */
|
|
16
17
|
quality?: string | number
|
|
17
18
|
/** 自定义样式类 */
|
|
@@ -25,6 +26,7 @@ const RemoteImage: React.FC<IRemoteImageProps> = (props) => {
|
|
|
25
26
|
height = 50,
|
|
26
27
|
noCrop = false,
|
|
27
28
|
quality,
|
|
29
|
+
imagePixelRatio,
|
|
28
30
|
mode = 'aspectFill',
|
|
29
31
|
className,
|
|
30
32
|
...restProps
|
|
@@ -37,9 +39,9 @@ const RemoteImage: React.FC<IRemoteImageProps> = (props) => {
|
|
|
37
39
|
height,
|
|
38
40
|
noCrop,
|
|
39
41
|
quality,
|
|
42
|
+
imagePixelRatio
|
|
40
43
|
})
|
|
41
44
|
}, [url, width, height, noCrop, quality])
|
|
42
|
-
console.log("🚀 ~ RemoteImage ~ responsiveSrc:", responsiveSrc)
|
|
43
45
|
|
|
44
46
|
const containerStyle: React.CSSProperties = {
|
|
45
47
|
width: width ? `${width}px` : 'auto',
|
package/src/util/function.ts
CHANGED
|
@@ -87,7 +87,7 @@ function isResponsiveImage(uri: string) {
|
|
|
87
87
|
&& (uri.indexOf('clouddn') > 0 || uri.indexOf('img.finstao.com') > 0)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
const
|
|
90
|
+
const DEFAULT_IMAGE_PIXEL_RATIO = Math.max(2, pixelRatio || 2)
|
|
91
91
|
|
|
92
92
|
export interface IWatermarkOptions {
|
|
93
93
|
text?: string
|
|
@@ -102,6 +102,7 @@ export interface IGetResponsiveImageOptions {
|
|
|
102
102
|
height?: number
|
|
103
103
|
noCrop?: boolean
|
|
104
104
|
quality?: string | number
|
|
105
|
+
imagePixelRatio?: number
|
|
105
106
|
supportWebp?: boolean
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -115,6 +116,7 @@ export default function getResponsiveImage(options: IGetResponsiveImageOptions):
|
|
|
115
116
|
height,
|
|
116
117
|
noCrop,
|
|
117
118
|
quality,
|
|
119
|
+
imagePixelRatio: customPixelRatio
|
|
118
120
|
} = options
|
|
119
121
|
|
|
120
122
|
if (!url) return ''
|
|
@@ -124,15 +126,17 @@ export default function getResponsiveImage(options: IGetResponsiveImageOptions):
|
|
|
124
126
|
return url
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
const ratio = customPixelRatio || DEFAULT_IMAGE_PIXEL_RATIO
|
|
130
|
+
|
|
127
131
|
const suffix: string[] = []
|
|
128
132
|
|
|
129
133
|
if (typeof width === 'number') {
|
|
130
|
-
const w = Math.floor(width *
|
|
134
|
+
const w = Math.floor(width * ratio)
|
|
131
135
|
suffix.push('w', w.toString())
|
|
132
136
|
}
|
|
133
137
|
|
|
134
138
|
if (typeof height === 'number') {
|
|
135
|
-
const h = Math.floor(height *
|
|
139
|
+
const h = Math.floor(height * ratio)
|
|
136
140
|
suffix.push('h', h.toString())
|
|
137
141
|
}
|
|
138
142
|
|