pubo-utils 1.0.67 → 1.0.69

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.
Files changed (52) hide show
  1. package/dist/pubo-utils.js +1 -1
  2. package/es/array/index.d.ts +1 -0
  3. package/es/array/index.js +25 -0
  4. package/es/base64/index.js +16 -21
  5. package/es/color/utils.d.ts +10 -1
  6. package/es/color/utils.js +2 -15
  7. package/es/debounce/index.js +13 -25
  8. package/es/emitter/index.js +17 -42
  9. package/es/factory/index.d.ts +5 -5
  10. package/es/factory/index.js +2 -6
  11. package/es/index.d.ts +2 -0
  12. package/es/index.js +3 -1
  13. package/es/level/index.js +1 -9
  14. package/es/loop/index.d.ts +1 -1
  15. package/es/loop/index.js +67 -118
  16. package/es/math/geometry.js +11 -23
  17. package/es/promise/index.js +16 -25
  18. package/es/queue/index.js +70 -129
  19. package/es/random/index.js +0 -5
  20. package/es/regexp-list/index.d.ts +7 -0
  21. package/es/regexp-list/index.js +20 -0
  22. package/es/sleep/index.js +62 -96
  23. package/es/stack/index.js +1 -16
  24. package/es/throttle/index.js +12 -19
  25. package/es/trigger/index.js +1 -10
  26. package/es/watch-dog/index.js +3 -11
  27. package/lib/array/index.d.ts +1 -0
  28. package/lib/array/index.js +32 -0
  29. package/lib/base64/index.js +16 -24
  30. package/lib/color/utils.d.ts +10 -1
  31. package/lib/color/utils.js +9 -22
  32. package/lib/debounce/index.js +16 -28
  33. package/lib/emitter/index.js +18 -44
  34. package/lib/factory/index.d.ts +5 -5
  35. package/lib/factory/index.js +5 -9
  36. package/lib/index.d.ts +2 -0
  37. package/lib/index.js +26 -44
  38. package/lib/level/index.js +1 -10
  39. package/lib/loop/index.d.ts +1 -1
  40. package/lib/loop/index.js +73 -125
  41. package/lib/math/geometry.js +21 -36
  42. package/lib/promise/index.js +19 -27
  43. package/lib/queue/index.js +70 -130
  44. package/lib/random/index.js +3 -8
  45. package/lib/regexp-list/index.d.ts +7 -0
  46. package/lib/regexp-list/index.js +26 -0
  47. package/lib/sleep/index.js +66 -99
  48. package/lib/stack/index.js +1 -17
  49. package/lib/throttle/index.js +12 -21
  50. package/lib/trigger/index.js +1 -11
  51. package/lib/watch-dog/index.js +3 -12
  52. package/package.json +2 -2
package/es/loop/index.js CHANGED
@@ -4,7 +4,6 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
4
4
  resolve(value);
5
5
  });
6
6
  }
7
-
8
7
  return new (P || (P = Promise))(function (resolve, reject) {
9
8
  function fulfilled(value) {
10
9
  try {
@@ -13,7 +12,6 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
13
12
  reject(e);
14
13
  }
15
14
  }
16
-
17
15
  function rejected(value) {
18
16
  try {
19
17
  step(generator["throw"](value));
@@ -21,29 +19,26 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
21
19
  reject(e);
22
20
  }
23
21
  }
24
-
25
22
  function step(result) {
26
23
  result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
24
  }
28
-
29
25
  step((generator = generator.apply(thisArg, _arguments || [])).next());
30
26
  });
31
27
  };
32
-
33
28
  var __generator = this && this.__generator || function (thisArg, body) {
34
29
  var _ = {
35
- label: 0,
36
- sent: function sent() {
37
- if (t[0] & 1) throw t[1];
38
- return t[1];
30
+ label: 0,
31
+ sent: function sent() {
32
+ if (t[0] & 1) throw t[1];
33
+ return t[1];
34
+ },
35
+ trys: [],
36
+ ops: []
39
37
  },
40
- trys: [],
41
- ops: []
42
- },
43
- f,
44
- y,
45
- t,
46
- g;
38
+ f,
39
+ y,
40
+ t,
41
+ g;
47
42
  return g = {
48
43
  next: verb(0),
49
44
  "throw": verb(1),
@@ -51,88 +46,66 @@ var __generator = this && this.__generator || function (thisArg, body) {
51
46
  }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
52
47
  return this;
53
48
  }), g;
54
-
55
49
  function verb(n) {
56
50
  return function (v) {
57
51
  return step([n, v]);
58
52
  };
59
53
  }
60
-
61
54
  function step(op) {
62
55
  if (f) throw new TypeError("Generator is already executing.");
63
-
64
- while (_) {
65
- try {
66
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
67
- if (y = 0, t) op = [op[0] & 2, t.value];
68
-
69
- switch (op[0]) {
70
- case 0:
71
- case 1:
56
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [0];
74
+ continue;
75
+ case 7:
76
+ op = _.ops.pop();
77
+ _.trys.pop();
78
+ continue;
79
+ default:
80
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
81
+ _ = 0;
82
+ continue;
83
+ }
84
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
+ _.label = op[1];
86
+ break;
87
+ }
88
+ if (op[0] === 6 && _.label < t[1]) {
89
+ _.label = t[1];
72
90
  t = op;
73
91
  break;
74
-
75
- case 4:
76
- _.label++;
77
- return {
78
- value: op[1],
79
- done: false
80
- };
81
-
82
- case 5:
83
- _.label++;
84
- y = op[1];
85
- op = [0];
86
- continue;
87
-
88
- case 7:
89
- op = _.ops.pop();
90
-
91
- _.trys.pop();
92
-
93
- continue;
94
-
95
- default:
96
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
97
- _ = 0;
98
- continue;
99
- }
100
-
101
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
102
- _.label = op[1];
103
- break;
104
- }
105
-
106
- if (op[0] === 6 && _.label < t[1]) {
107
- _.label = t[1];
108
- t = op;
109
- break;
110
- }
111
-
112
- if (t && _.label < t[2]) {
113
- _.label = t[2];
114
-
115
- _.ops.push(op);
116
-
117
- break;
118
- }
119
-
120
- if (t[2]) _.ops.pop();
121
-
122
- _.trys.pop();
123
-
124
- continue;
125
- }
126
-
127
- op = body.call(thisArg, _);
128
- } catch (e) {
129
- op = [6, e];
130
- y = 0;
131
- } finally {
132
- f = t = 0;
92
+ }
93
+ if (t && _.label < t[2]) {
94
+ _.label = t[2];
95
+ _.ops.push(op);
96
+ break;
97
+ }
98
+ if (t[2]) _.ops.pop();
99
+ _.trys.pop();
100
+ continue;
133
101
  }
102
+ op = body.call(thisArg, _);
103
+ } catch (e) {
104
+ op = [6, e];
105
+ y = 0;
106
+ } finally {
107
+ f = t = 0;
134
108
  }
135
-
136
109
  if (op[0] & 5) throw op[1];
137
110
  return {
138
111
  value: op[0] ? op[1] : void 0,
@@ -140,57 +113,41 @@ var __generator = this && this.__generator || function (thisArg, body) {
140
113
  };
141
114
  }
142
115
  };
143
-
144
116
  import { sleep } from '../sleep';
145
117
  export var loop = function loop(cb, time) {
146
118
  var onOff = true;
147
-
148
119
  var stop = function stop() {
149
120
  onOff = false;
150
121
  };
151
-
152
122
  var _fn = function fn() {
153
123
  return __awaiter(void 0, void 0, void 0, function () {
154
124
  return __generator(this, function (_a) {
155
125
  switch (_a.label) {
156
126
  case 0:
157
- return [4
158
- /*yield*/
159
- , cb(stop)];
160
-
127
+ return [4 /*yield*/, cb(stop)];
161
128
  case 1:
162
129
  _a.sent();
163
-
164
- return [4
165
- /*yield*/
166
- , sleep(time)];
167
-
130
+ return [4 /*yield*/, sleep(time)];
168
131
  case 2:
169
132
  _a.sent();
170
-
171
133
  if (onOff) {
172
134
  _fn();
173
135
  } else {
174
136
  _fn = null;
175
137
  }
176
-
177
- return [2
178
- /*return*/
179
- ];
138
+ return [2 /*return*/];
180
139
  }
181
140
  });
182
141
  });
183
142
  };
184
143
 
185
144
  _fn();
186
-
187
145
  return stop;
188
146
  };
189
147
  export var waitFor = function waitFor(bool, _a) {
190
148
  var _b = _a === void 0 ? {} : _a,
191
- checkTime = _b.checkTime,
192
- timeout = _b.timeout;
193
-
149
+ checkTime = _b.checkTime,
150
+ timeout = _b.timeout;
194
151
  return new Promise(function (resolve, reject) {
195
152
  var stop = loop(function () {
196
153
  return __awaiter(void 0, void 0, void 0, function () {
@@ -198,26 +155,18 @@ export var waitFor = function waitFor(bool, _a) {
198
155
  return __generator(this, function (_a) {
199
156
  switch (_a.label) {
200
157
  case 0:
201
- return [4
202
- /*yield*/
203
- , bool()];
204
-
158
+ return [4 /*yield*/, bool()];
205
159
  case 1:
206
160
  res = _a.sent();
207
-
208
161
  if (res) {
209
162
  stop();
210
163
  resolve(res);
211
164
  }
212
-
213
- return [2
214
- /*return*/
215
- ];
165
+ return [2 /*return*/];
216
166
  }
217
167
  });
218
168
  });
219
169
  }, checkTime || 100);
220
-
221
170
  if (timeout) {
222
171
  setTimeout(function () {
223
172
  stop();
@@ -1,7 +1,7 @@
1
1
  var __values = this && this.__values || function (o) {
2
2
  var s = typeof Symbol === "function" && Symbol.iterator,
3
- m = s && o[s],
4
- i = 0;
3
+ m = s && o[s],
4
+ i = 0;
5
5
  if (m) return m.call(o);
6
6
  if (o && typeof o.length === "number") return {
7
7
  next: function next() {
@@ -14,25 +14,23 @@ var __values = this && this.__values || function (o) {
14
14
  };
15
15
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
16
16
  };
17
-
18
17
  export var getDistance = function getDistance(a, b) {
19
18
  return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
20
- }; // 弧度转角度
21
-
19
+ };
20
+ // 弧度转角度
22
21
  export var degrees = function degrees(rad) {
23
22
  return rad * 180 / Math.PI;
24
- }; // 角度转弧度
25
-
23
+ };
24
+ // 角度转弧度
26
25
  export var radians = function radians(deg) {
27
26
  return deg * Math.PI / 180;
28
- }; // 获取角度
29
-
27
+ };
28
+ // 获取角度
30
29
  export var getAngle = function getAngle(_a) {
31
30
  var w = _a.w,
32
- h = _a.h;
31
+ h = _a.h;
33
32
  var a = degrees(Math.asin(h / Math.sqrt(Math.pow(w, 2) + Math.pow(h, 2))));
34
33
  var res;
35
-
36
34
  if (w <= 0) {
37
35
  res = 180 - a;
38
36
  } else if (a > 0) {
@@ -40,46 +38,37 @@ export var getAngle = function getAngle(_a) {
40
38
  } else {
41
39
  res = 360 + a;
42
40
  }
43
-
44
41
  if (res < -180) {
45
42
  res = res + 360;
46
43
  }
47
-
48
44
  if (res > 180) {
49
45
  res = res - 360;
50
46
  }
51
-
52
47
  return res;
53
48
  };
54
49
  export function filterKeyPoints(list, len) {
55
50
  if (len === void 0) {
56
51
  len = 0.5;
57
52
  }
58
-
59
53
  if (list.length < 3 || len <= 0) {
60
54
  return list;
61
55
  }
62
-
63
56
  var last;
64
57
  return list.filter(function (item, i) {
65
58
  if (i > 0 && getDistance(last, item) < len) {
66
59
  return false;
67
60
  }
68
-
69
61
  last = list[i];
70
62
  return true;
71
63
  });
72
- } // 获取中心点坐标
73
-
64
+ }
65
+ // 获取中心点坐标
74
66
  export function getCenter(list) {
75
67
  var e_1, _a;
76
-
77
68
  var tmp = [0, 0];
78
-
79
69
  try {
80
70
  for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
81
71
  var item = list_1_1.value;
82
-
83
72
  if (Array.isArray(item)) {
84
73
  tmp[0] += item[0];
85
74
  tmp[1] += item[1];
@@ -99,7 +88,6 @@ export function getCenter(list) {
99
88
  if (e_1) throw e_1.error;
100
89
  }
101
90
  }
102
-
103
91
  return {
104
92
  x: tmp[0] / list.length,
105
93
  y: tmp[1] / list.length
@@ -2,14 +2,11 @@ var __read = this && this.__read || function (o, n) {
2
2
  var m = typeof Symbol === "function" && o[Symbol.iterator];
3
3
  if (!m) return o;
4
4
  var i = m.call(o),
5
- r,
6
- ar = [],
7
- e;
8
-
5
+ r,
6
+ ar = [],
7
+ e;
9
8
  try {
10
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
11
- ar.push(r.value);
12
- }
9
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
13
10
  } catch (error) {
14
11
  e = {
15
12
  error: error
@@ -21,45 +18,39 @@ var __read = this && this.__read || function (o, n) {
21
18
  if (e) throw e.error;
22
19
  }
23
20
  }
24
-
25
21
  return ar;
26
22
  };
27
-
28
- var __spread = this && this.__spread || function () {
29
- for (var ar = [], i = 0; i < arguments.length; i++) {
30
- ar = ar.concat(__read(arguments[i]));
23
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
24
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25
+ if (ar || !(i in from)) {
26
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
27
+ ar[i] = from[i];
28
+ }
31
29
  }
32
-
33
- return ar;
34
- }; // 回调函数转异步函数
35
-
36
-
30
+ return to.concat(ar || Array.prototype.slice.call(from));
31
+ };
32
+ // 回调函数转异步函数
37
33
  export var callbackToPromise = function callbackToPromise(fn) {
38
34
  return function () {
39
35
  var args = [];
40
-
41
36
  for (var _i = 0; _i < arguments.length; _i++) {
42
37
  args[_i] = arguments[_i];
43
38
  }
44
-
45
39
  return new Promise(function (resolve, reject) {
46
- fn.apply(void 0, __spread(args, [function (err) {
40
+ fn.apply(void 0, __spreadArray(__spreadArray([], __read(args), false), [function (err) {
47
41
  var rest = [];
48
-
49
42
  for (var _i = 1; _i < arguments.length; _i++) {
50
43
  rest[_i - 1] = arguments[_i];
51
44
  }
52
-
53
45
  if (err) {
54
46
  reject(err);
55
47
  }
56
-
57
48
  if (rest.length < 2) {
58
49
  resolve(rest[0]);
59
50
  } else {
60
- resolve(__spread(rest));
51
+ resolve(__spreadArray([], __read(rest), false));
61
52
  }
62
- }]));
53
+ }], false));
63
54
  });
64
55
  };
65
56
  };