util-helpers 4.21.0 → 4.21.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/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "4.21.0";
1
+ var VERSION = "4.21.2";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -32,7 +32,11 @@ function compressImage(img, options) {
32
32
  var numCanvasHeight = toNumber(typeof canvasHeight === 'function' ? canvasHeight(info, options) : canvasHeight);
33
33
  canvas.width = numCanvasWidth || image.width;
34
34
  canvas.height = numCanvasHeight || image.height;
35
- if (background && background !== 'none') {
35
+ var bgIsTransparent = background === 'none' || background === 'transparent';
36
+ if (bgIsTransparent) {
37
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
38
+ }
39
+ else {
36
40
  ctx.fillStyle = background;
37
41
  ctx.fillRect(0, 0, canvas.width, canvas.height);
38
42
  }
@@ -44,7 +48,13 @@ function compressImage(img, options) {
44
48
  }
45
49
  var outOffset = typeof offset === 'function' ? offset(info, options) : offset;
46
50
  beforeDraw === null || beforeDraw === void 0 ? void 0 : beforeDraw(info, options);
47
- ctx.drawImage(image, internalOffset[0] + toNumber(outOffset[0]), internalOffset[1] + toNumber(outOffset[1]), image.width, image.height);
51
+ var dx = internalOffset[0] + toNumber(outOffset[0]);
52
+ var dy = internalOffset[1] + toNumber(outOffset[1]);
53
+ ctx.drawImage(image, dx, dy, image.width, image.height);
54
+ if (type === 'image/png' && bgIsTransparent) {
55
+ ctx.globalCompositeOperation = 'destination-in';
56
+ ctx.drawImage(image, dx, dy, image.width, image.height);
57
+ }
48
58
  afterDraw === null || afterDraw === void 0 ? void 0 : afterDraw(info, options);
49
59
  if (format === 'blob') {
50
60
  canvasToBlob(canvas, type, numQuality).then(resolve).catch(reject);
@@ -3,18 +3,32 @@ import divide from './divide.js';
3
3
  import gcd from './gcd.js';
4
4
  import loadImageWithBlob from './loadImageWithBlob.js';
5
5
  import bytesToSize from './bytesToSize.js';
6
+ import Cache from './utils/Cache.js';
7
+ import { revokeObjectURL } from './utils/native.js';
6
8
 
9
+ var cache = new Cache({ max: 1 });
10
+ cache.on('del', function (v) {
11
+ if (v.r) {
12
+ try {
13
+ revokeObjectURL(v.data.image.src);
14
+ }
15
+ catch (_a) {
16
+ }
17
+ }
18
+ });
7
19
  function calcContrast(w, h) {
8
20
  var n = gcd(w, h);
9
21
  return "".concat(divide(round(w), n), ":").concat(divide(round(h), n));
10
22
  }
11
- var cacheImage;
12
- var cacheResult;
13
- function getImageInfo(img, useCache, ajaxOptions) {
14
- if (useCache === void 0) { useCache = true; }
23
+ function getImageInfo(img, cacheOptions, ajaxOptions) {
24
+ if (cacheOptions === void 0) { cacheOptions = true; }
25
+ var _cacheOptions = {
26
+ useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
27
+ autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
28
+ };
15
29
  return new Promise(function (resolve, reject) {
16
- if (useCache && cacheImage === img && cacheResult) {
17
- resolve(cacheResult);
30
+ if (_cacheOptions.useCache && cache.has(img)) {
31
+ resolve(cache.get(img).data);
18
32
  }
19
33
  else {
20
34
  loadImageWithBlob(img, false, ajaxOptions)
@@ -31,9 +45,11 @@ function getImageInfo(img, useCache, ajaxOptions) {
31
45
  image: image,
32
46
  blob: blob
33
47
  };
34
- if (useCache) {
35
- cacheImage = img;
36
- cacheResult = result;
48
+ if (_cacheOptions.useCache) {
49
+ cache.set(img, {
50
+ data: result,
51
+ r: _cacheOptions.autoRevokeOnDel
52
+ });
37
53
  }
38
54
  resolve(result);
39
55
  })
package/esm/index.js CHANGED
@@ -64,6 +64,6 @@ export { default as findTreeSelect } from './findTreeSelect.js';
64
64
  export { setDisableWarning } from './utils/config.js';
65
65
  export { default as VERSION } from './VERSION.js';
66
66
 
67
- var version = "4.21.0";
67
+ var version = "4.21.2";
68
68
 
69
69
  export { version };
package/esm/loadImage.js CHANGED
@@ -1,13 +1,26 @@
1
1
  import { isBlob } from 'ut2';
2
- import { createObjectURL, revokeObjectURL } from './utils/native.js';
2
+ import { revokeObjectURL, createObjectURL } from './utils/native.js';
3
+ import Cache from './utils/Cache.js';
3
4
 
4
- var cacheImage;
5
- var cacheResult;
6
- function loadImage(img, useCache) {
7
- if (useCache === void 0) { useCache = true; }
5
+ var cache = new Cache({ max: 1 });
6
+ cache.on('del', function (v) {
7
+ if (v.r) {
8
+ try {
9
+ revokeObjectURL(v.data.src);
10
+ }
11
+ catch (_a) {
12
+ }
13
+ }
14
+ });
15
+ function loadImage(img, cacheOptions) {
16
+ if (cacheOptions === void 0) { cacheOptions = true; }
17
+ var _cacheOptions = {
18
+ useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
19
+ autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
20
+ };
8
21
  return new Promise(function (resolve, reject) {
9
- if (useCache && cacheImage === img && cacheResult) {
10
- resolve(cacheResult);
22
+ if (_cacheOptions.useCache && cache.has(img)) {
23
+ resolve(cache.get(img).data);
11
24
  }
12
25
  else {
13
26
  var imgIsBlob_1 = isBlob(img);
@@ -17,12 +30,11 @@ function loadImage(img, useCache) {
17
30
  image_1.crossOrigin = 'anonymous';
18
31
  }
19
32
  image_1.onload = function () {
20
- if (imgIsBlob_1) {
21
- revokeObjectURL(url_1);
22
- }
23
- if (useCache) {
24
- cacheImage = img;
25
- cacheResult = image_1;
33
+ if (_cacheOptions.useCache) {
34
+ cache.set(img, {
35
+ data: image_1,
36
+ r: _cacheOptions.autoRevokeOnDel
37
+ });
26
38
  }
27
39
  resolve(image_1);
28
40
  };
@@ -1,13 +1,26 @@
1
- import { createObjectURL, revokeObjectURL } from './utils/native.js';
1
+ import { revokeObjectURL, createObjectURL } from './utils/native.js';
2
2
  import getFileBlob from './getFileBlob.js';
3
+ import Cache from './utils/Cache.js';
3
4
 
4
- var cacheImage;
5
- var cacheResult;
6
- function loadImageWithBlob(img, useCache, ajaxOptions) {
7
- if (useCache === void 0) { useCache = true; }
5
+ var cache = new Cache({ max: 1 });
6
+ cache.on('del', function (v) {
7
+ if (v.r) {
8
+ try {
9
+ revokeObjectURL(v.data.image.src);
10
+ }
11
+ catch (_a) {
12
+ }
13
+ }
14
+ });
15
+ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
16
+ if (cacheOptions === void 0) { cacheOptions = true; }
17
+ var _cacheOptions = {
18
+ useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
19
+ autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
20
+ };
8
21
  return new Promise(function (resolve, reject) {
9
- if (useCache && cacheImage === img && cacheResult) {
10
- resolve(cacheResult);
22
+ if (_cacheOptions.useCache && cache.has(img)) {
23
+ resolve(cache.get(img).data);
11
24
  }
12
25
  else {
13
26
  getFileBlob(img, ajaxOptions)
@@ -15,11 +28,12 @@ function loadImageWithBlob(img, useCache, ajaxOptions) {
15
28
  var url = createObjectURL(blob);
16
29
  var image = new Image();
17
30
  image.onload = function () {
18
- revokeObjectURL(url);
19
31
  var result = { blob: blob, image: image };
20
- if (useCache) {
21
- cacheImage = img;
22
- cacheResult = result;
32
+ if (_cacheOptions.useCache) {
33
+ cache.set(img, {
34
+ data: result,
35
+ r: _cacheOptions.autoRevokeOnDel
36
+ });
23
37
  }
24
38
  resolve(result);
25
39
  };
@@ -0,0 +1,72 @@
1
+ var EmitterPro = /** @class */ (function () {
2
+ function EmitterPro() {
3
+ this.handler = {};
4
+ }
5
+ EmitterPro.prototype.eventNames = function () {
6
+ return Object.keys(this.handler);
7
+ };
8
+ EmitterPro.prototype.listeners = function (eventName) {
9
+ return this.handler[eventName] || [];
10
+ };
11
+ EmitterPro.prototype.hasListener = function (eventName, listener) {
12
+ return this.listeners(eventName).some(function (item) { return item === listener; });
13
+ };
14
+ EmitterPro.prototype.on = function (eventName, listener) {
15
+ if (!this.handler[eventName]) {
16
+ this.handler[eventName] = [listener];
17
+ }
18
+ else {
19
+ // 不允许添加相同的方法
20
+ if (!this.hasListener(eventName, listener)) {
21
+ this.handler[eventName].push(listener);
22
+ }
23
+ }
24
+ return this;
25
+ };
26
+ EmitterPro.prototype.off = function (eventName, listener) {
27
+ if (this.handler[eventName]) {
28
+ if (typeof listener === 'function') {
29
+ this.handler[eventName] = this.handler[eventName].filter(function (item) { return item !== listener; });
30
+ }
31
+ else {
32
+ delete this.handler[eventName];
33
+ }
34
+ }
35
+ return this;
36
+ };
37
+ EmitterPro.prototype.emit = function (eventName) {
38
+ var args = [];
39
+ for (var _i = 1; _i < arguments.length; _i++) {
40
+ args[_i - 1] = arguments[_i];
41
+ }
42
+ var listeners = this.listeners(eventName);
43
+ if (listeners.length > 0) {
44
+ listeners.forEach(function (listener) {
45
+ // eslint-disable-next-line prefer-spread
46
+ listener.apply(void 0, args);
47
+ });
48
+ return true;
49
+ }
50
+ return false;
51
+ };
52
+ EmitterPro.prototype.once = function (eventName, listener) {
53
+ var _this = this;
54
+ var wrap = function () {
55
+ var args = [];
56
+ for (var _i = 0; _i < arguments.length; _i++) {
57
+ args[_i] = arguments[_i];
58
+ }
59
+ // eslint-disable-next-line prefer-spread
60
+ listener.apply(void 0, args);
61
+ _this.off(eventName, wrap);
62
+ };
63
+ return this.on(eventName, wrap);
64
+ };
65
+ EmitterPro.prototype.offAll = function () {
66
+ this.handler = {};
67
+ return this;
68
+ };
69
+ return EmitterPro;
70
+ }());
71
+
72
+ export { EmitterPro as default };
@@ -0,0 +1,47 @@
1
+ import { __extends, __assign } from 'tslib';
2
+ import EmitterPro from '../node_modules/.pnpm/emitter-pro@1.0.3/node_modules/emitter-pro/dist/emitter-pro.esm.js';
3
+ import { forEach } from 'ut2';
4
+
5
+ var Cache = (function (_super) {
6
+ __extends(Cache, _super);
7
+ function Cache(options) {
8
+ var _this = _super.call(this) || this;
9
+ _this.data = [];
10
+ _this.options = __assign({ max: 10 }, options);
11
+ return _this;
12
+ }
13
+ Cache.prototype.has = function (k) {
14
+ return !!this.data.find(function (item) { return item.k === k; });
15
+ };
16
+ Cache.prototype.get = function (k) {
17
+ var _a;
18
+ return (_a = this.data.find(function (item) { return item.k === k; })) === null || _a === void 0 ? void 0 : _a.v;
19
+ };
20
+ Cache.prototype.checkLimit = function () {
21
+ var _this = this;
22
+ if (this.options.max !== 0) {
23
+ var limit = this.data.length - this.options.max;
24
+ if (limit >= 0) {
25
+ var delArr = this.data.splice(0, limit + 1);
26
+ forEach(delArr, function (item) {
27
+ _this.emit('del', item.v, item.k);
28
+ });
29
+ }
30
+ }
31
+ };
32
+ Cache.prototype.set = function (k, v) {
33
+ var newData = { k: k, v: v };
34
+ if (this.has(k)) {
35
+ var index = this.data.findIndex(function (item) { return item.k === k; });
36
+ this.data.splice(index, 1, newData);
37
+ }
38
+ else {
39
+ this.checkLimit();
40
+ this.data.push(newData);
41
+ }
42
+ };
43
+ return Cache;
44
+ }(EmitterPro));
45
+ var Cache$1 = Cache;
46
+
47
+ export { Cache$1 as default };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "4.21.0";
3
+ var VERSION = "4.21.2";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -34,7 +34,11 @@ function compressImage(img, options) {
34
34
  var numCanvasHeight = ut2.toNumber(typeof canvasHeight === 'function' ? canvasHeight(info, options) : canvasHeight);
35
35
  canvas.width = numCanvasWidth || image.width;
36
36
  canvas.height = numCanvasHeight || image.height;
37
- if (background && background !== 'none') {
37
+ var bgIsTransparent = background === 'none' || background === 'transparent';
38
+ if (bgIsTransparent) {
39
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
40
+ }
41
+ else {
38
42
  ctx.fillStyle = background;
39
43
  ctx.fillRect(0, 0, canvas.width, canvas.height);
40
44
  }
@@ -46,7 +50,13 @@ function compressImage(img, options) {
46
50
  }
47
51
  var outOffset = typeof offset === 'function' ? offset(info, options) : offset;
48
52
  beforeDraw === null || beforeDraw === void 0 ? void 0 : beforeDraw(info, options);
49
- ctx.drawImage(image, internalOffset[0] + ut2.toNumber(outOffset[0]), internalOffset[1] + ut2.toNumber(outOffset[1]), image.width, image.height);
53
+ var dx = internalOffset[0] + ut2.toNumber(outOffset[0]);
54
+ var dy = internalOffset[1] + ut2.toNumber(outOffset[1]);
55
+ ctx.drawImage(image, dx, dy, image.width, image.height);
56
+ if (type === 'image/png' && bgIsTransparent) {
57
+ ctx.globalCompositeOperation = 'destination-in';
58
+ ctx.drawImage(image, dx, dy, image.width, image.height);
59
+ }
50
60
  afterDraw === null || afterDraw === void 0 ? void 0 : afterDraw(info, options);
51
61
  if (format === 'blob') {
52
62
  canvasToBlob(canvas, type, numQuality).then(resolve).catch(reject);
@@ -5,18 +5,32 @@ var divide = require('./divide.js');
5
5
  var gcd = require('./gcd.js');
6
6
  var loadImageWithBlob = require('./loadImageWithBlob.js');
7
7
  var bytesToSize = require('./bytesToSize.js');
8
+ var Cache = require('./utils/Cache.js');
9
+ var native = require('./utils/native.js');
8
10
 
11
+ var cache = new Cache({ max: 1 });
12
+ cache.on('del', function (v) {
13
+ if (v.r) {
14
+ try {
15
+ native.revokeObjectURL(v.data.image.src);
16
+ }
17
+ catch (_a) {
18
+ }
19
+ }
20
+ });
9
21
  function calcContrast(w, h) {
10
22
  var n = gcd(w, h);
11
23
  return "".concat(divide(ut2.round(w), n), ":").concat(divide(ut2.round(h), n));
12
24
  }
13
- var cacheImage;
14
- var cacheResult;
15
- function getImageInfo(img, useCache, ajaxOptions) {
16
- if (useCache === void 0) { useCache = true; }
25
+ function getImageInfo(img, cacheOptions, ajaxOptions) {
26
+ if (cacheOptions === void 0) { cacheOptions = true; }
27
+ var _cacheOptions = {
28
+ useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
29
+ autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
30
+ };
17
31
  return new Promise(function (resolve, reject) {
18
- if (useCache && cacheImage === img && cacheResult) {
19
- resolve(cacheResult);
32
+ if (_cacheOptions.useCache && cache.has(img)) {
33
+ resolve(cache.get(img).data);
20
34
  }
21
35
  else {
22
36
  loadImageWithBlob(img, false, ajaxOptions)
@@ -33,9 +47,11 @@ function getImageInfo(img, useCache, ajaxOptions) {
33
47
  image: image,
34
48
  blob: blob
35
49
  };
36
- if (useCache) {
37
- cacheImage = img;
38
- cacheResult = result;
50
+ if (_cacheOptions.useCache) {
51
+ cache.set(img, {
52
+ data: result,
53
+ r: _cacheOptions.autoRevokeOnDel
54
+ });
39
55
  }
40
56
  resolve(result);
41
57
  })
package/lib/index.js CHANGED
@@ -66,7 +66,7 @@ var findTreeSelect = require('./findTreeSelect.js');
66
66
  var config = require('./utils/config.js');
67
67
  var VERSION = require('./VERSION.js');
68
68
 
69
- exports.version = "4.21.0";
69
+ exports.version = "4.21.2";
70
70
 
71
71
  exports.isMobile = isMobile;
72
72
  exports.isTelephone = isTelephone;
package/lib/loadImage.js CHANGED
@@ -2,14 +2,27 @@
2
2
 
3
3
  var ut2 = require('ut2');
4
4
  var native = require('./utils/native.js');
5
+ var Cache = require('./utils/Cache.js');
5
6
 
6
- var cacheImage;
7
- var cacheResult;
8
- function loadImage(img, useCache) {
9
- if (useCache === void 0) { useCache = true; }
7
+ var cache = new Cache({ max: 1 });
8
+ cache.on('del', function (v) {
9
+ if (v.r) {
10
+ try {
11
+ native.revokeObjectURL(v.data.src);
12
+ }
13
+ catch (_a) {
14
+ }
15
+ }
16
+ });
17
+ function loadImage(img, cacheOptions) {
18
+ if (cacheOptions === void 0) { cacheOptions = true; }
19
+ var _cacheOptions = {
20
+ useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
21
+ autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
22
+ };
10
23
  return new Promise(function (resolve, reject) {
11
- if (useCache && cacheImage === img && cacheResult) {
12
- resolve(cacheResult);
24
+ if (_cacheOptions.useCache && cache.has(img)) {
25
+ resolve(cache.get(img).data);
13
26
  }
14
27
  else {
15
28
  var imgIsBlob_1 = ut2.isBlob(img);
@@ -19,12 +32,11 @@ function loadImage(img, useCache) {
19
32
  image_1.crossOrigin = 'anonymous';
20
33
  }
21
34
  image_1.onload = function () {
22
- if (imgIsBlob_1) {
23
- native.revokeObjectURL(url_1);
24
- }
25
- if (useCache) {
26
- cacheImage = img;
27
- cacheResult = image_1;
35
+ if (_cacheOptions.useCache) {
36
+ cache.set(img, {
37
+ data: image_1,
38
+ r: _cacheOptions.autoRevokeOnDel
39
+ });
28
40
  }
29
41
  resolve(image_1);
30
42
  };
@@ -2,14 +2,27 @@
2
2
 
3
3
  var native = require('./utils/native.js');
4
4
  var getFileBlob = require('./getFileBlob.js');
5
+ var Cache = require('./utils/Cache.js');
5
6
 
6
- var cacheImage;
7
- var cacheResult;
8
- function loadImageWithBlob(img, useCache, ajaxOptions) {
9
- if (useCache === void 0) { useCache = true; }
7
+ var cache = new Cache({ max: 1 });
8
+ cache.on('del', function (v) {
9
+ if (v.r) {
10
+ try {
11
+ native.revokeObjectURL(v.data.image.src);
12
+ }
13
+ catch (_a) {
14
+ }
15
+ }
16
+ });
17
+ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
18
+ if (cacheOptions === void 0) { cacheOptions = true; }
19
+ var _cacheOptions = {
20
+ useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
21
+ autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
22
+ };
10
23
  return new Promise(function (resolve, reject) {
11
- if (useCache && cacheImage === img && cacheResult) {
12
- resolve(cacheResult);
24
+ if (_cacheOptions.useCache && cache.has(img)) {
25
+ resolve(cache.get(img).data);
13
26
  }
14
27
  else {
15
28
  getFileBlob(img, ajaxOptions)
@@ -17,11 +30,12 @@ function loadImageWithBlob(img, useCache, ajaxOptions) {
17
30
  var url = native.createObjectURL(blob);
18
31
  var image = new Image();
19
32
  image.onload = function () {
20
- native.revokeObjectURL(url);
21
33
  var result = { blob: blob, image: image };
22
- if (useCache) {
23
- cacheImage = img;
24
- cacheResult = result;
34
+ if (_cacheOptions.useCache) {
35
+ cache.set(img, {
36
+ data: result,
37
+ r: _cacheOptions.autoRevokeOnDel
38
+ });
25
39
  }
26
40
  resolve(result);
27
41
  };
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ exports.default = /** @class */ (function () {
4
+ function EmitterPro() {
5
+ this.handler = {};
6
+ }
7
+ EmitterPro.prototype.eventNames = function () {
8
+ return Object.keys(this.handler);
9
+ };
10
+ EmitterPro.prototype.listeners = function (eventName) {
11
+ return this.handler[eventName] || [];
12
+ };
13
+ EmitterPro.prototype.hasListener = function (eventName, listener) {
14
+ return this.listeners(eventName).some(function (item) { return item === listener; });
15
+ };
16
+ EmitterPro.prototype.on = function (eventName, listener) {
17
+ if (!this.handler[eventName]) {
18
+ this.handler[eventName] = [listener];
19
+ }
20
+ else {
21
+ // 不允许添加相同的方法
22
+ if (!this.hasListener(eventName, listener)) {
23
+ this.handler[eventName].push(listener);
24
+ }
25
+ }
26
+ return this;
27
+ };
28
+ EmitterPro.prototype.off = function (eventName, listener) {
29
+ if (this.handler[eventName]) {
30
+ if (typeof listener === 'function') {
31
+ this.handler[eventName] = this.handler[eventName].filter(function (item) { return item !== listener; });
32
+ }
33
+ else {
34
+ delete this.handler[eventName];
35
+ }
36
+ }
37
+ return this;
38
+ };
39
+ EmitterPro.prototype.emit = function (eventName) {
40
+ var args = [];
41
+ for (var _i = 1; _i < arguments.length; _i++) {
42
+ args[_i - 1] = arguments[_i];
43
+ }
44
+ var listeners = this.listeners(eventName);
45
+ if (listeners.length > 0) {
46
+ listeners.forEach(function (listener) {
47
+ // eslint-disable-next-line prefer-spread
48
+ listener.apply(void 0, args);
49
+ });
50
+ return true;
51
+ }
52
+ return false;
53
+ };
54
+ EmitterPro.prototype.once = function (eventName, listener) {
55
+ var _this = this;
56
+ var wrap = function () {
57
+ var args = [];
58
+ for (var _i = 0; _i < arguments.length; _i++) {
59
+ args[_i] = arguments[_i];
60
+ }
61
+ // eslint-disable-next-line prefer-spread
62
+ listener.apply(void 0, args);
63
+ _this.off(eventName, wrap);
64
+ };
65
+ return this.on(eventName, wrap);
66
+ };
67
+ EmitterPro.prototype.offAll = function () {
68
+ this.handler = {};
69
+ return this;
70
+ };
71
+ return EmitterPro;
72
+ }());
73
+
74
+ module.exports = exports.default;
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var emitterPro_esm = require('../node_modules/.pnpm/emitter-pro@1.0.3/node_modules/emitter-pro/dist/emitter-pro.esm.js');
5
+ var ut2 = require('ut2');
6
+
7
+ var Cache = (function (_super) {
8
+ tslib.__extends(Cache, _super);
9
+ function Cache(options) {
10
+ var _this = _super.call(this) || this;
11
+ _this.data = [];
12
+ _this.options = tslib.__assign({ max: 10 }, options);
13
+ return _this;
14
+ }
15
+ Cache.prototype.has = function (k) {
16
+ return !!this.data.find(function (item) { return item.k === k; });
17
+ };
18
+ Cache.prototype.get = function (k) {
19
+ var _a;
20
+ return (_a = this.data.find(function (item) { return item.k === k; })) === null || _a === void 0 ? void 0 : _a.v;
21
+ };
22
+ Cache.prototype.checkLimit = function () {
23
+ var _this = this;
24
+ if (this.options.max !== 0) {
25
+ var limit = this.data.length - this.options.max;
26
+ if (limit >= 0) {
27
+ var delArr = this.data.splice(0, limit + 1);
28
+ ut2.forEach(delArr, function (item) {
29
+ _this.emit('del', item.v, item.k);
30
+ });
31
+ }
32
+ }
33
+ };
34
+ Cache.prototype.set = function (k, v) {
35
+ var newData = { k: k, v: v };
36
+ if (this.has(k)) {
37
+ var index = this.data.findIndex(function (item) { return item.k === k; });
38
+ this.data.splice(index, 1, newData);
39
+ }
40
+ else {
41
+ this.checkLimit();
42
+ this.data.push(newData);
43
+ }
44
+ };
45
+ return Cache;
46
+ }(emitterPro_esm));
47
+ var Cache$1 = Cache;
48
+
49
+ module.exports = Cache$1;