util-helpers 4.20.2 → 4.20.3
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/util-helpers.js +10 -10
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/compressImage.js +2 -2
- package/esm/getImageInfo.js +2 -2
- package/esm/index.js +1 -1
- package/esm/loadImageWithBlob.js +5 -4
- package/lib/VERSION.js +1 -1
- package/lib/compressImage.js +2 -2
- package/lib/getImageInfo.js +2 -2
- package/lib/index.js +1 -1
- package/lib/loadImageWithBlob.js +5 -4
- package/package.json +1 -1
- package/types/compressImage.d.ts +3 -1
- package/types/getImageInfo.d.ts +3 -1
- package/types/loadImageWithBlob.d.ts +3 -1
package/esm/VERSION.js
CHANGED
package/esm/compressImage.js
CHANGED
|
@@ -11,8 +11,8 @@ function canvasToBlob(canvas, type, quality) {
|
|
|
11
11
|
function compressImage(img, options) {
|
|
12
12
|
if (options === void 0) { options = {}; }
|
|
13
13
|
return new Promise(function (resolve, reject) {
|
|
14
|
-
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw;
|
|
15
|
-
loadImageWithBlob(img, cacheImage)
|
|
14
|
+
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
|
|
15
|
+
loadImageWithBlob(img, cacheImage, ajaxOptions)
|
|
16
16
|
.then(function (_a) {
|
|
17
17
|
var image = _a.image, blob = _a.blob;
|
|
18
18
|
var numWidth = toNumber(width);
|
package/esm/getImageInfo.js
CHANGED
|
@@ -10,14 +10,14 @@ function calcContrast(w, h) {
|
|
|
10
10
|
}
|
|
11
11
|
var cacheImage;
|
|
12
12
|
var cacheResult;
|
|
13
|
-
function getImageInfo(img, useCache) {
|
|
13
|
+
function getImageInfo(img, useCache, ajaxOptions) {
|
|
14
14
|
if (useCache === void 0) { useCache = true; }
|
|
15
15
|
return new Promise(function (resolve, reject) {
|
|
16
16
|
if (useCache && cacheImage === img && cacheResult) {
|
|
17
17
|
resolve(cacheResult);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
loadImageWithBlob(img, false)
|
|
20
|
+
loadImageWithBlob(img, false, ajaxOptions)
|
|
21
21
|
.then(function (_a) {
|
|
22
22
|
var image = _a.image, blob = _a.blob;
|
|
23
23
|
var width = image.width, height = image.height;
|
package/esm/index.js
CHANGED
package/esm/loadImageWithBlob.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { __assign } from 'tslib';
|
|
1
2
|
import { isBlob } from 'ut2';
|
|
2
3
|
import ajax from './ajax.js';
|
|
3
4
|
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
4
5
|
|
|
5
6
|
var SuccessResponseStatus = [200, 304];
|
|
6
|
-
function getBlob(img) {
|
|
7
|
+
function getBlob(img, ajaxOptions) {
|
|
7
8
|
return new Promise(function (resolve, reject) {
|
|
8
9
|
if (isBlob(img)) {
|
|
9
10
|
resolve(img);
|
|
10
11
|
}
|
|
11
12
|
else {
|
|
12
|
-
ajax(img, { responseType: 'blob' })
|
|
13
|
+
ajax(img, __assign({ responseType: 'blob', headers: { 'sec-fetch-site': 'none' } }, ajaxOptions))
|
|
13
14
|
.then(function (ev) {
|
|
14
15
|
var responseStatus = ev.target.status;
|
|
15
16
|
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
@@ -25,14 +26,14 @@ function getBlob(img) {
|
|
|
25
26
|
}
|
|
26
27
|
var cacheImage;
|
|
27
28
|
var cacheResult;
|
|
28
|
-
function loadImageWithBlob(img, useCache) {
|
|
29
|
+
function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
29
30
|
if (useCache === void 0) { useCache = true; }
|
|
30
31
|
return new Promise(function (resolve, reject) {
|
|
31
32
|
if (useCache && cacheImage === img && cacheResult) {
|
|
32
33
|
resolve(cacheResult);
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
|
-
getBlob(img)
|
|
36
|
+
getBlob(img, ajaxOptions)
|
|
36
37
|
.then(function (blob) {
|
|
37
38
|
var url = createObjectURL(blob);
|
|
38
39
|
var image = new Image();
|
package/lib/VERSION.js
CHANGED
package/lib/compressImage.js
CHANGED
|
@@ -13,8 +13,8 @@ function canvasToBlob(canvas, type, quality) {
|
|
|
13
13
|
function compressImage(img, options) {
|
|
14
14
|
if (options === void 0) { options = {}; }
|
|
15
15
|
return new Promise(function (resolve, reject) {
|
|
16
|
-
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw;
|
|
17
|
-
loadImageWithBlob(img, cacheImage)
|
|
16
|
+
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
|
|
17
|
+
loadImageWithBlob(img, cacheImage, ajaxOptions)
|
|
18
18
|
.then(function (_a) {
|
|
19
19
|
var image = _a.image, blob = _a.blob;
|
|
20
20
|
var numWidth = ut2.toNumber(width);
|
package/lib/getImageInfo.js
CHANGED
|
@@ -12,14 +12,14 @@ function calcContrast(w, h) {
|
|
|
12
12
|
}
|
|
13
13
|
var cacheImage;
|
|
14
14
|
var cacheResult;
|
|
15
|
-
function getImageInfo(img, useCache) {
|
|
15
|
+
function getImageInfo(img, useCache, ajaxOptions) {
|
|
16
16
|
if (useCache === void 0) { useCache = true; }
|
|
17
17
|
return new Promise(function (resolve, reject) {
|
|
18
18
|
if (useCache && cacheImage === img && cacheResult) {
|
|
19
19
|
resolve(cacheResult);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
loadImageWithBlob(img, false)
|
|
22
|
+
loadImageWithBlob(img, false, ajaxOptions)
|
|
23
23
|
.then(function (_a) {
|
|
24
24
|
var image = _a.image, blob = _a.blob;
|
|
25
25
|
var width = image.width, height = image.height;
|
package/lib/index.js
CHANGED
|
@@ -65,7 +65,7 @@ var findTreeSelect = require('./findTreeSelect.js');
|
|
|
65
65
|
var config = require('./utils/config.js');
|
|
66
66
|
var VERSION = require('./VERSION.js');
|
|
67
67
|
|
|
68
|
-
exports.version = "4.20.
|
|
68
|
+
exports.version = "4.20.3";
|
|
69
69
|
|
|
70
70
|
exports.isMobile = isMobile;
|
|
71
71
|
exports.isTelephone = isTelephone;
|
package/lib/loadImageWithBlob.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var tslib = require('tslib');
|
|
3
4
|
var ut2 = require('ut2');
|
|
4
5
|
var ajax = require('./ajax.js');
|
|
5
6
|
var native = require('./utils/native.js');
|
|
6
7
|
|
|
7
8
|
var SuccessResponseStatus = [200, 304];
|
|
8
|
-
function getBlob(img) {
|
|
9
|
+
function getBlob(img, ajaxOptions) {
|
|
9
10
|
return new Promise(function (resolve, reject) {
|
|
10
11
|
if (ut2.isBlob(img)) {
|
|
11
12
|
resolve(img);
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
|
-
ajax(img, { responseType: 'blob' })
|
|
15
|
+
ajax(img, tslib.__assign({ responseType: 'blob', headers: { 'sec-fetch-site': 'none' } }, ajaxOptions))
|
|
15
16
|
.then(function (ev) {
|
|
16
17
|
var responseStatus = ev.target.status;
|
|
17
18
|
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
@@ -27,14 +28,14 @@ function getBlob(img) {
|
|
|
27
28
|
}
|
|
28
29
|
var cacheImage;
|
|
29
30
|
var cacheResult;
|
|
30
|
-
function loadImageWithBlob(img, useCache) {
|
|
31
|
+
function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
31
32
|
if (useCache === void 0) { useCache = true; }
|
|
32
33
|
return new Promise(function (resolve, reject) {
|
|
33
34
|
if (useCache && cacheImage === img && cacheResult) {
|
|
34
35
|
resolve(cacheResult);
|
|
35
36
|
}
|
|
36
37
|
else {
|
|
37
|
-
getBlob(img)
|
|
38
|
+
getBlob(img, ajaxOptions)
|
|
38
39
|
.then(function (blob) {
|
|
39
40
|
var url = native.createObjectURL(blob);
|
|
40
41
|
var image = new Image();
|
package/package.json
CHANGED
package/types/compressImage.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import loadImageWithBlob from './loadImageWithBlob';
|
|
1
2
|
type Info = {
|
|
2
3
|
image: HTMLImageElement;
|
|
3
4
|
blob: Blob;
|
|
@@ -9,7 +10,6 @@ type Options = {
|
|
|
9
10
|
height?: number;
|
|
10
11
|
rotate?: number;
|
|
11
12
|
offset?: [number, number] | ((info: Info, options: Options) => [number, number]);
|
|
12
|
-
cacheImage?: boolean;
|
|
13
13
|
background?: string;
|
|
14
14
|
canvasWidth?: number | ((info: Info, options: Options) => number);
|
|
15
15
|
canvasHeight?: number | ((info: Info, options: Options) => number);
|
|
@@ -19,6 +19,8 @@ type Options = {
|
|
|
19
19
|
beforeCompress?: (imageWithBlob: Pick<Info, 'image' | 'blob'>, options: Options) => void;
|
|
20
20
|
beforeDraw?: (info: Info, options: Options) => void;
|
|
21
21
|
afterDraw?: (info: Info, options: Options) => void;
|
|
22
|
+
cacheImage?: boolean;
|
|
23
|
+
ajaxOptions?: Parameters<typeof loadImageWithBlob>[2];
|
|
22
24
|
};
|
|
23
25
|
declare function compressImage(img: string | Blob, options: Omit<Options, 'format'> & {
|
|
24
26
|
format: 'dataURL';
|
package/types/getImageInfo.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import loadImageWithBlob from './loadImageWithBlob';
|
|
1
2
|
/**
|
|
2
3
|
* 获取图片信息。
|
|
3
4
|
*
|
|
@@ -8,6 +9,7 @@
|
|
|
8
9
|
* @since 4.20.0
|
|
9
10
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
10
11
|
* @param {boolean} [useCache=true] 缓存最近一次成功结果,当图片地址或 blob 对象一致时,直接返回该缓存。避免连续请求同一个图片资源,重复加载问题。
|
|
12
|
+
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
|
11
13
|
* @returns {Promise<ImageInfo>} 图片信息
|
|
12
14
|
* @example
|
|
13
15
|
*
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
* });
|
|
25
27
|
*
|
|
26
28
|
*/
|
|
27
|
-
declare function getImageInfo(img: string | Blob, useCache?: boolean): Promise<{
|
|
29
|
+
declare function getImageInfo(img: string | Blob, useCache?: boolean, ajaxOptions?: Parameters<typeof loadImageWithBlob>[2]): Promise<{
|
|
28
30
|
width: number;
|
|
29
31
|
height: number;
|
|
30
32
|
contrast: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ajax from './ajax';
|
|
1
2
|
/**
|
|
2
3
|
* @typedef {Object} ImageWithBlob HTML图片元素和 blob 对象
|
|
3
4
|
* @property {HTMLImageElement} image HTML图片元素
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
* @since 4.20.0
|
|
14
15
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
15
16
|
* @param {boolean} [useCache=true] 缓存最近一次成功结果,当图片地址或 blob 对象一致时,直接返回该缓存。避免连续请求同一个图片资源,重复加载问题。
|
|
17
|
+
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
|
16
18
|
* @returns {Promise<ImageWithBlob>} HTML图片元素和 blob 对象
|
|
17
19
|
* @example
|
|
18
20
|
*
|
|
@@ -29,7 +31,7 @@
|
|
|
29
31
|
* });
|
|
30
32
|
*
|
|
31
33
|
*/
|
|
32
|
-
declare function loadImageWithBlob(img: string | Blob, useCache?: boolean): Promise<{
|
|
34
|
+
declare function loadImageWithBlob(img: string | Blob, useCache?: boolean, ajaxOptions?: Parameters<typeof ajax>[1]): Promise<{
|
|
33
35
|
image: HTMLImageElement;
|
|
34
36
|
blob: Blob;
|
|
35
37
|
}>;
|