util-helpers 4.20.8 → 4.21.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 CHANGED
@@ -100,6 +100,7 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
100
100
  - [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
101
101
  - [compressImage](https://doly-dev.github.io/util-helpers/module-Other.html#.compressImage) - 压缩图片
102
102
  - [download](https://doly-dev.github.io/util-helpers/module-Other.html#.download) - 下载
103
+ - [getFileBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.getFileBlob) - 获取文件 Blob
103
104
  - [getImageInfo](https://doly-dev.github.io/util-helpers/module-Other.html#.getImageInfo) - 获取图片信息
104
105
  - [loadImage](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImage) - 加载图片
105
106
  - [loadImageWithBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImageWithBlob) - 加载图片和 blob 对象
@@ -26,11 +26,15 @@
26
26
 
27
27
  function isObject(value) {
28
28
  var type = typeof value;
29
- return value != null && (type === 'object' || type === 'function');
29
+ return type === 'function' || (type === 'object' && !!value);
30
+ }
31
+
32
+ function getTag(value) {
33
+ return objectProtoToString.call(value);
30
34
  }
31
35
 
32
36
  function isSymbol(value) {
33
- return typeof value === 'symbol' || objectProtoToString.call(value) === symbolTag;
37
+ return typeof value === 'symbol' || getTag(value) === symbolTag;
34
38
  }
35
39
 
36
40
  var reIsBinary = /^0b[01]+$/i;
@@ -67,22 +71,26 @@
67
71
  return remainder ? result - remainder : result;
68
72
  }
69
73
 
74
+ function isNil(value) {
75
+ return value == null;
76
+ }
77
+
70
78
  var symbolToString = symbolProto ? symbolProto.toString : undefined;
71
79
  function baseToString(value) {
72
80
  if (typeof value === 'string') {
73
81
  return value;
74
82
  }
75
83
  if (isArray(value)) {
76
- return "".concat(value.map(baseToString));
84
+ return '' + value.map(baseToString);
77
85
  }
78
86
  if (isSymbol(value)) {
79
87
  return symbolToString ? symbolToString.call(value) : '';
80
88
  }
81
89
  var result = '' + value;
82
- return result == '0' && 1 / value === -Infinity ? '-0' : result;
90
+ return result === '0' && 1 / value === -Infinity ? '-0' : result;
83
91
  }
84
92
  function toString(value) {
85
- return value == null ? '' : baseToString(value);
93
+ return isNil(value) ? '' : baseToString(value);
86
94
  }
87
95
 
88
96
  var blobExisted = typeof Blob !== 'undefined';
@@ -90,7 +98,7 @@
90
98
  if (blobExisted && value instanceof Blob) {
91
99
  return true;
92
100
  }
93
- return objectProtoToString.call(value) === blobTag;
101
+ return getTag(value) === blobTag;
94
102
  }
95
103
 
96
104
  var freeGlobalThis = globalThisExisted && globalThis.Object === Object && globalThis;
@@ -104,7 +112,7 @@
104
112
  }
105
113
 
106
114
  function isNumber(value) {
107
- return typeof value === 'number' || objectProtoToString.call(value) === numberTag;
115
+ return typeof value === 'number' || getTag(value) === numberTag;
108
116
  }
109
117
 
110
118
  function isNaN(value) {
@@ -116,7 +124,7 @@
116
124
  }
117
125
 
118
126
  function isString(value) {
119
- return typeof value === 'string' || objectProtoToString.call(value) === stringTag;
127
+ return typeof value === 'string' || getTag(value) === stringTag;
120
128
  }
121
129
 
122
130
  function decimalAdjust(type, value, precision) {
@@ -1385,31 +1393,32 @@
1385
1393
  }
1386
1394
 
1387
1395
  var SuccessResponseStatus = [200, 304];
1388
- function getBlob(img, ajaxOptions) {
1396
+ function getFileBlob(file, ajaxOptions) {
1389
1397
  return new Promise(function (resolve, reject) {
1390
- if (isBlob(img)) {
1391
- resolve(img);
1398
+ if (isBlob(file)) {
1399
+ resolve(file);
1392
1400
  }
1393
1401
  else {
1394
- ajax(img, __assign({ responseType: 'blob' }, ajaxOptions))
1402
+ ajax(file, __assign({ responseType: 'blob' }, ajaxOptions))
1395
1403
  .then(function (ev) {
1396
1404
  var responseStatus = ev.target.status;
1397
1405
  if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
1398
1406
  resolve(ev.target.response);
1399
1407
  }
1400
1408
  else {
1401
- var err = new Error("[loadImageWithBlob] The image does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(img, "'."));
1409
+ var err = new Error("The file does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(file, "'."));
1402
1410
  console.error(err);
1403
1411
  reject(err);
1404
1412
  }
1405
1413
  })
1406
1414
  .catch(function (err) {
1407
- console.error(new Error("[loadImageWithBlob] Failed to request image. ".concat(err)));
1415
+ console.error(new Error("Failed to request file. ".concat(err)));
1408
1416
  reject(err);
1409
1417
  });
1410
1418
  }
1411
1419
  });
1412
1420
  }
1421
+
1413
1422
  var cacheImage$2;
1414
1423
  var cacheResult$2;
1415
1424
  function loadImageWithBlob(img, useCache, ajaxOptions) {
@@ -1419,12 +1428,11 @@
1419
1428
  resolve(cacheResult$2);
1420
1429
  }
1421
1430
  else {
1422
- getBlob(img, ajaxOptions)
1431
+ getFileBlob(img, ajaxOptions)
1423
1432
  .then(function (blob) {
1424
1433
  var url = createObjectURL(blob);
1425
1434
  var image = new Image();
1426
1435
  image.onload = function () {
1427
- revokeObjectURL(url);
1428
1436
  var result = { blob: blob, image: image };
1429
1437
  if (useCache) {
1430
1438
  cacheImage$2 = img;
@@ -1487,7 +1495,13 @@
1487
1495
  }
1488
1496
  var outOffset = typeof offset === 'function' ? offset(info, options) : offset;
1489
1497
  beforeDraw === null || beforeDraw === void 0 ? void 0 : beforeDraw(info, options);
1490
- ctx.drawImage(image, internalOffset[0] + toNumber(outOffset[0]), internalOffset[1] + toNumber(outOffset[1]), image.width, image.height);
1498
+ var dx = internalOffset[0] + toNumber(outOffset[0]);
1499
+ var dy = internalOffset[1] + toNumber(outOffset[1]);
1500
+ ctx.drawImage(image, dx, dy, image.width, image.height);
1501
+ if (type === 'image/png') {
1502
+ ctx.globalCompositeOperation = 'destination-in';
1503
+ ctx.drawImage(image, dx, dy, image.width, image.height);
1504
+ }
1491
1505
  afterDraw === null || afterDraw === void 0 ? void 0 : afterDraw(info, options);
1492
1506
  if (format === 'blob') {
1493
1507
  canvasToBlob(canvas, type, numQuality).then(resolve).catch(reject);
@@ -1636,9 +1650,6 @@
1636
1650
  image_1.crossOrigin = 'anonymous';
1637
1651
  }
1638
1652
  image_1.onload = function () {
1639
- if (imgIsBlob_1) {
1640
- revokeObjectURL(url_1);
1641
- }
1642
1653
  if (useCache) {
1643
1654
  cacheImage = img;
1644
1655
  cacheResult = image_1;
@@ -1990,9 +2001,9 @@
1990
2001
  return internalFindTreeSelect(tree, predicate, childrenField);
1991
2002
  }
1992
2003
 
1993
- var VERSION = "4.20.8";
2004
+ var VERSION = "4.21.1";
1994
2005
 
1995
- var version = "4.20.8";
2006
+ var version = "4.21.1";
1996
2007
 
1997
2008
  exports.VERSION = VERSION;
1998
2009
  exports.ajax = ajax;
@@ -2012,6 +2023,7 @@
2012
2023
  exports.formatMobile = formatMobile;
2013
2024
  exports.formatMoney = formatMoney;
2014
2025
  exports.gcd = gcd;
2026
+ exports.getFileBlob = getFileBlob;
2015
2027
  exports.getImageInfo = getImageInfo;
2016
2028
  exports.isBankCard = isBankCard;
2017
2029
  exports.isBusinessLicense = isBusinessLicense;