@antv/g 5.0.22-alpha.6 → 5.0.23-alpha.10

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 (164) hide show
  1. package/dist/index.umd.min.js +3 -3
  2. package/es/AbstractRenderer.js +5 -0
  3. package/es/camera/Camera.js +2 -2
  4. package/es/css/cssom/CSSKeywordValue.d.ts +1 -1
  5. package/es/css/cssom/CSSNumericSumValue.d.ts +1 -1
  6. package/es/css/cssom/CSSNumericValue.d.ts +141 -4
  7. package/es/css/cssom/CSSNumericValue.js +1166 -5
  8. package/es/css/cssom/CSSTransformValue.d.ts +1 -1
  9. package/es/css/cssom/index.d.ts +0 -10
  10. package/es/css/cssom/index.js +1 -11
  11. package/es/css/parser/color.js +1 -1
  12. package/es/css/parser/dimension.js +1 -2
  13. package/es/css/parser/numeric.d.ts +1 -1
  14. package/es/css/parser/numeric.js +2 -2
  15. package/es/css/parser/path.d.ts +2 -2
  16. package/es/css/parser/path.js +1 -1
  17. package/es/css/parser/points.js +1 -1
  18. package/es/css/parser/transform-origin.d.ts +1 -1
  19. package/es/css/parser/transform-origin.js +2 -2
  20. package/es/css/parser/transform.d.ts +1 -3
  21. package/es/css/parser/transform.js +9 -8
  22. package/es/css/properties/CSSPropertyPath.d.ts +14 -2
  23. package/es/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  24. package/es/css/properties/CSSPropertyTransform.js +3 -4
  25. package/es/display-objects/DisplayObject.js +4 -5
  26. package/es/display-objects/Path.d.ts +15 -15
  27. package/es/display-objects/Path.js +1 -1
  28. package/es/display-objects/Polygon.d.ts +8 -1
  29. package/es/display-objects/Polyline.d.ts +7 -5
  30. package/es/dom/Document.js +2 -2
  31. package/es/dom/Element.js +1 -2
  32. package/es/dom/EventTarget.js +1 -1
  33. package/es/dom/FederatedTouchEvent.d.ts +5 -3
  34. package/es/plugins/CullingPlugin.d.ts +0 -1
  35. package/es/plugins/CullingPlugin.js +3 -8
  36. package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
  37. package/es/plugins/DirtyCheckPlugin.js +9 -8
  38. package/es/plugins/EventPlugin.d.ts +1 -1
  39. package/es/plugins/EventPlugin.js +163 -148
  40. package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
  41. package/es/plugins/PrepareRendererPlugin.js +16 -17
  42. package/es/services/EventService.d.ts +8 -0
  43. package/es/services/EventService.js +274 -20
  44. package/es/services/RenderingService.d.ts +17 -16
  45. package/es/services/RenderingService.js +19 -18
  46. package/es/services/SceneGraphService.js +1 -1
  47. package/es/services/aabb/PathUpdater.d.ts +3 -3
  48. package/es/services/aabb/PolylineUpdater.d.ts +3 -3
  49. package/es/services/aabb/RectUpdater.js +1 -1
  50. package/es/types.d.ts +5 -3
  51. package/es/utils/assert.d.ts +6 -0
  52. package/es/utils/assert.js +18 -0
  53. package/es/utils/event.d.ts +18 -16
  54. package/es/utils/hooks.d.ts +280 -0
  55. package/es/utils/hooks.js +753 -0
  56. package/es/utils/index.d.ts +1 -0
  57. package/es/utils/index.js +2 -1
  58. package/es/utils/math.d.ts +1 -0
  59. package/es/utils/math.js +13 -2
  60. package/es/utils/string.d.ts +1 -0
  61. package/es/utils/string.js +8 -0
  62. package/es/utils/text.js +2 -1
  63. package/lib/AbstractRenderer.js +5 -0
  64. package/lib/camera/Camera.js +4 -4
  65. package/lib/css/cssom/CSSKeywordValue.d.ts +1 -1
  66. package/lib/css/cssom/CSSNumericSumValue.d.ts +1 -1
  67. package/lib/css/cssom/CSSNumericValue.d.ts +141 -4
  68. package/lib/css/cssom/CSSNumericValue.js +1226 -52
  69. package/lib/css/cssom/CSSTransformValue.d.ts +1 -1
  70. package/lib/css/cssom/index.d.ts +0 -10
  71. package/lib/css/cssom/index.js +0 -130
  72. package/lib/css/parser/color.js +5 -5
  73. package/lib/css/parser/dimension.js +1 -3
  74. package/lib/css/parser/numeric.d.ts +1 -1
  75. package/lib/css/parser/numeric.js +7 -7
  76. package/lib/css/parser/path.d.ts +2 -2
  77. package/lib/css/parser/path.js +4 -4
  78. package/lib/css/parser/points.js +2 -2
  79. package/lib/css/parser/transform-origin.d.ts +1 -1
  80. package/lib/css/parser/transform-origin.js +4 -4
  81. package/lib/css/parser/transform.d.ts +1 -3
  82. package/lib/css/parser/transform.js +25 -24
  83. package/lib/css/properties/CSSPropertyPath.d.ts +14 -2
  84. package/lib/css/properties/CSSPropertyTextTransform.d.ts +2 -2
  85. package/lib/css/properties/CSSPropertyTransform.js +18 -20
  86. package/lib/display-objects/DisplayObject.js +7 -9
  87. package/lib/display-objects/Path.d.ts +15 -15
  88. package/lib/display-objects/Path.js +3 -3
  89. package/lib/display-objects/Polygon.d.ts +8 -1
  90. package/lib/display-objects/Polyline.d.ts +7 -5
  91. package/lib/dom/Document.js +2 -2
  92. package/lib/dom/Element.js +1 -3
  93. package/lib/dom/EventTarget.js +9 -9
  94. package/lib/dom/FederatedTouchEvent.d.ts +5 -3
  95. package/lib/plugins/CullingPlugin.d.ts +0 -1
  96. package/lib/plugins/CullingPlugin.js +3 -7
  97. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
  98. package/lib/plugins/DirtyCheckPlugin.js +10 -8
  99. package/lib/plugins/EventPlugin.d.ts +1 -1
  100. package/lib/plugins/EventPlugin.js +172 -156
  101. package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
  102. package/lib/plugins/PrepareRendererPlugin.js +16 -16
  103. package/lib/services/EventService.d.ts +8 -0
  104. package/lib/services/EventService.js +274 -19
  105. package/lib/services/RenderingService.d.ts +17 -16
  106. package/lib/services/RenderingService.js +21 -20
  107. package/lib/services/SceneGraphService.js +3 -3
  108. package/lib/services/aabb/PathUpdater.d.ts +3 -3
  109. package/lib/services/aabb/PolylineUpdater.d.ts +3 -3
  110. package/lib/services/aabb/RectUpdater.js +3 -3
  111. package/lib/types.d.ts +5 -3
  112. package/lib/utils/assert.d.ts +6 -0
  113. package/lib/utils/assert.js +30 -0
  114. package/lib/utils/event.d.ts +18 -16
  115. package/lib/utils/hooks.d.ts +280 -0
  116. package/lib/utils/hooks.js +759 -0
  117. package/lib/utils/index.d.ts +1 -0
  118. package/lib/utils/index.js +13 -0
  119. package/lib/utils/math.d.ts +1 -0
  120. package/lib/utils/math.js +17 -4
  121. package/lib/utils/string.d.ts +1 -0
  122. package/lib/utils/string.js +11 -0
  123. package/lib/utils/text.js +5 -3
  124. package/package.json +4 -7
  125. package/es/css/cssom/CSSMathInvert.d.ts +0 -14
  126. package/es/css/cssom/CSSMathInvert.js +0 -84
  127. package/es/css/cssom/CSSMathMax.d.ts +0 -17
  128. package/es/css/cssom/CSSMathMax.js +0 -118
  129. package/es/css/cssom/CSSMathMin.d.ts +0 -17
  130. package/es/css/cssom/CSSMathMin.js +0 -119
  131. package/es/css/cssom/CSSMathNegate.d.ts +0 -14
  132. package/es/css/cssom/CSSMathNegate.js +0 -80
  133. package/es/css/cssom/CSSMathProduct.d.ts +0 -16
  134. package/es/css/cssom/CSSMathProduct.js +0 -109
  135. package/es/css/cssom/CSSMathSum.d.ts +0 -17
  136. package/es/css/cssom/CSSMathSum.js +0 -117
  137. package/es/css/cssom/CSSMathValue.d.ts +0 -11
  138. package/es/css/cssom/CSSMathValue.js +0 -27
  139. package/es/css/cssom/CSSMathVariadic.d.ts +0 -9
  140. package/es/css/cssom/CSSMathVariadic.js +0 -44
  141. package/es/css/cssom/CSSNumericValueType.d.ts +0 -33
  142. package/es/css/cssom/CSSNumericValueType.js +0 -259
  143. package/es/css/cssom/CSSUnitValue.d.ts +0 -33
  144. package/es/css/cssom/CSSUnitValue.js +0 -252
  145. package/lib/css/cssom/CSSMathInvert.d.ts +0 -14
  146. package/lib/css/cssom/CSSMathInvert.js +0 -94
  147. package/lib/css/cssom/CSSMathMax.d.ts +0 -17
  148. package/lib/css/cssom/CSSMathMax.js +0 -128
  149. package/lib/css/cssom/CSSMathMin.d.ts +0 -17
  150. package/lib/css/cssom/CSSMathMin.js +0 -128
  151. package/lib/css/cssom/CSSMathNegate.d.ts +0 -14
  152. package/lib/css/cssom/CSSMathNegate.js +0 -89
  153. package/lib/css/cssom/CSSMathProduct.d.ts +0 -16
  154. package/lib/css/cssom/CSSMathProduct.js +0 -119
  155. package/lib/css/cssom/CSSMathSum.d.ts +0 -17
  156. package/lib/css/cssom/CSSMathSum.js +0 -129
  157. package/lib/css/cssom/CSSMathValue.d.ts +0 -11
  158. package/lib/css/cssom/CSSMathValue.js +0 -35
  159. package/lib/css/cssom/CSSMathVariadic.d.ts +0 -9
  160. package/lib/css/cssom/CSSMathVariadic.js +0 -55
  161. package/lib/css/cssom/CSSNumericValueType.d.ts +0 -33
  162. package/lib/css/cssom/CSSNumericValueType.js +0 -272
  163. package/lib/css/cssom/CSSUnitValue.d.ts +0 -33
  164. package/lib/css/cssom/CSSUnitValue.js +0 -267
@@ -0,0 +1,753 @@
1
+ /**
2
+ * a lite tapable implementation
3
+ * borrow from https://github.com/funnyecho/hamon
4
+ */
5
+ import { __extends, __read, __spreadArray, __values } from "tslib";
6
+
7
+ function once(fn) {
8
+ var called = false;
9
+ return function onceWrapper() {
10
+ var args = [];
11
+
12
+ for (var _i = 0; _i < arguments.length; _i++) {
13
+ args[_i] = arguments[_i];
14
+ }
15
+
16
+ if (called) return;
17
+ called = true;
18
+ fn.apply(void 0, __spreadArray([], __read(args), false));
19
+ };
20
+ }
21
+
22
+ function invokeSeriesNext(observer, args, list) {
23
+ var onComplete;
24
+
25
+ if (typeof observer.onComplete === 'function') {
26
+ onComplete = observer.onComplete;
27
+ } else {
28
+ onComplete = function unImplementOnComplete(err, result) {//
29
+ };
30
+ }
31
+
32
+ if (!list.length) {
33
+ if (observer.shouldWaterfall) {
34
+ onComplete(null, args[0]);
35
+ } else {
36
+ onComplete(null, undefined);
37
+ }
38
+
39
+ return;
40
+ }
41
+
42
+ var tap = list.shift();
43
+ var downstreamTaps = list;
44
+ var downstreamArgs = Array.from(args); // @ts-ignore
45
+
46
+ var nextArgs = __spreadArray(__spreadArray([], __read(args), false), [function onNext(err, result) {
47
+ if (err != null) {
48
+ onComplete(err);
49
+ return;
50
+ }
51
+
52
+ if (result !== undefined && observer.shouldBail === true) {
53
+ onComplete(null, result);
54
+ return;
55
+ }
56
+
57
+ if (result !== undefined && observer.shouldWaterfall === true) {
58
+ downstreamArgs[0] = result;
59
+ }
60
+
61
+ invokeSeriesNext(observer, downstreamArgs, downstreamTaps);
62
+ }], false);
63
+
64
+ tap.fn.apply(tap, __spreadArray([], __read(nextArgs), false));
65
+ }
66
+
67
+ function invokeParallel(observer, args, list) {
68
+ var e_1, _a;
69
+
70
+ var onComplete;
71
+
72
+ if (typeof observer.onComplete === 'function') {
73
+ onComplete = observer.onComplete;
74
+ } else {
75
+ onComplete = function unImplementOnComplete(err, result) {//
76
+ };
77
+ }
78
+
79
+ if (!list.length) {
80
+ onComplete(null, undefined);
81
+ return;
82
+ }
83
+
84
+ var parallelSize = list.length; // @ts-ignore
85
+
86
+ var nextArgs = __spreadArray(__spreadArray([], __read(args), false), [function onNext(err, result) {
87
+ if (err != null) {
88
+ onComplete(err);
89
+ return;
90
+ }
91
+
92
+ if (result !== undefined && observer.shouldBail === true) {
93
+ onComplete(null, result);
94
+ return;
95
+ }
96
+
97
+ --parallelSize;
98
+
99
+ if (parallelSize <= 0) {
100
+ onComplete(null, args[0]);
101
+ return;
102
+ }
103
+ }], false);
104
+
105
+ try {
106
+ for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
107
+ var option = list_1_1.value;
108
+ option.fn.apply(option, __spreadArray([], __read(nextArgs), false));
109
+ }
110
+ } catch (e_1_1) {
111
+ e_1 = {
112
+ error: e_1_1
113
+ };
114
+ } finally {
115
+ try {
116
+ if (list_1_1 && !list_1_1.done && (_a = list_1.return)) _a.call(list_1);
117
+ } finally {
118
+ if (e_1) throw e_1.error;
119
+ }
120
+ }
121
+ }
122
+
123
+ function invokeSynchronously(observer, args, list) {
124
+ var e_2, _a;
125
+
126
+ if (!list.length) {
127
+ if (observer.shouldWaterfall) return args[0];else return undefined;
128
+ }
129
+
130
+ var downstreamArgs = Array.from(args);
131
+
132
+ try {
133
+ for (var list_2 = __values(list), list_2_1 = list_2.next(); !list_2_1.done; list_2_1 = list_2.next()) {
134
+ var option = list_2_1.value;
135
+ var fn = option.fn;
136
+ var result = fn.apply(void 0, __spreadArray([], __read(downstreamArgs), false));
137
+
138
+ if (result !== undefined && observer.shouldBail === true) {
139
+ return result;
140
+ }
141
+
142
+ if (result !== undefined && observer.shouldWaterfall === true) {
143
+ downstreamArgs[0] = result;
144
+ }
145
+ }
146
+ } catch (e_2_1) {
147
+ e_2 = {
148
+ error: e_2_1
149
+ };
150
+ } finally {
151
+ try {
152
+ if (list_2_1 && !list_2_1.done && (_a = list_2.return)) _a.call(list_2);
153
+ } finally {
154
+ if (e_2) throw e_2.error;
155
+ }
156
+ }
157
+
158
+ if (observer.shouldWaterfall) return downstreamArgs[0];else return undefined;
159
+ }
160
+ /**
161
+ * Basic Hook Type
162
+ *
163
+ * @remarks
164
+ * All subtype hooks are extends from `Hook` which provide the tapping and calling logic
165
+ *
166
+ * @param T - tuple types of calling arguments
167
+ * @param R - returning value type of calling
168
+ *
169
+ * @public
170
+ * */
171
+
172
+
173
+ var Hook =
174
+ /** @class */
175
+ function () {
176
+ /**
177
+ * @param bucketHashcode - calculate the hashcode value of calling arguments
178
+ * */
179
+ function Hook(bucketHashcode) {
180
+ this.tapIdSeed = 0;
181
+ this.presetTapBucket = new Set();
182
+ this.tapBuckets = new Map();
183
+ this.tapOptionsCache = new Map();
184
+ this.bucketHashcode = bucketHashcode;
185
+ }
186
+ /**
187
+ * clear all tapping from hook
188
+ *
189
+ * @public
190
+ * */
191
+
192
+
193
+ Hook.prototype.exhaust = function () {
194
+ this.presetTapBucket.clear();
195
+ this.tapBuckets.clear();
196
+ this.tapOptionsCache.clear();
197
+ };
198
+ /**
199
+ * clear all tapping from hook
200
+ *
201
+ * @remarks
202
+ * The same as `exhaust` {@link Hook.exhaust}
203
+ *
204
+ * @privateRemarks
205
+ * call `exhaust`
206
+ *
207
+ * @public
208
+ * */
209
+
210
+
211
+ Hook.prototype.destroy = function () {
212
+ this.exhaust();
213
+ };
214
+ /**
215
+ * @internal
216
+ * */
217
+
218
+
219
+ Hook.prototype.insertSyncTap = function (fn, bucket) {
220
+ return this.tapping(fn, bucket);
221
+ };
222
+ /**
223
+ * @internal
224
+ * */
225
+
226
+
227
+ Hook.prototype.insertAsyncTap = function (fn, bucket) {
228
+ function asyncTapFn() {
229
+ var args = [];
230
+
231
+ for (var _i = 0; _i < arguments.length; _i++) {
232
+ args[_i] = arguments[_i];
233
+ }
234
+
235
+ var invokeCb = args[args.length - 1];
236
+
237
+ try {
238
+ fn.apply(void 0, __spreadArray([], __read(args), false));
239
+ } catch (e) {
240
+ invokeCb(e);
241
+ }
242
+ }
243
+
244
+ return this.tapping(asyncTapFn, bucket);
245
+ };
246
+ /**
247
+ * @internal
248
+ * */
249
+
250
+
251
+ Hook.prototype.insertPromiseTap = function (fn, bucket) {
252
+ function promiseTapFn() {
253
+ var args = [];
254
+
255
+ for (var _i = 0; _i < arguments.length; _i++) {
256
+ args[_i] = arguments[_i];
257
+ }
258
+
259
+ var invokeCb = args.pop();
260
+ var invokeArgs = args;
261
+
262
+ try {
263
+ Promise.resolve(fn.apply(void 0, __spreadArray([], __read(invokeArgs), false))).then(function (tapResult) {
264
+ invokeCb(null, tapResult);
265
+ }, function (e) {
266
+ invokeCb(e);
267
+ });
268
+ } catch (e) {
269
+ invokeCb(e);
270
+ }
271
+ }
272
+
273
+ return this.tapping(promiseTapFn, bucket);
274
+ };
275
+ /**
276
+ * @internal
277
+ * */
278
+
279
+
280
+ Hook.prototype.invokeSeries = function (args, observer) {
281
+ if (!observer) {
282
+ observer = {};
283
+ }
284
+
285
+ if (typeof observer.onComplete === 'function') {
286
+ // @ts-ignored
287
+ observer.onComplete = once(observer.onComplete);
288
+ }
289
+
290
+ invokeSeriesNext(observer, args, Array.from(this.getBucketTaps(args)));
291
+ };
292
+ /**
293
+ * @internal
294
+ * */
295
+
296
+
297
+ Hook.prototype.invokeParallel = function (args, observer) {
298
+ if (!observer) {
299
+ observer = {};
300
+ }
301
+
302
+ if (typeof observer.onComplete === 'function') {
303
+ // @ts-ignored
304
+ observer.onComplete = once(observer.onComplete);
305
+ }
306
+
307
+ invokeParallel(observer, args, Array.from(this.getBucketTaps(args)));
308
+ };
309
+ /**
310
+ * @internal
311
+ * */
312
+
313
+
314
+ Hook.prototype.invokeSynchronously = function (args, observer) {
315
+ if (!observer) {
316
+ observer = {};
317
+ }
318
+
319
+ return invokeSynchronously(observer, args, Array.from(this.getBucketTaps(args)));
320
+ };
321
+ /**
322
+ * @internal
323
+ * */
324
+
325
+
326
+ Hook.prototype.getBucketTaps = function (args) {
327
+ var e_3, _a;
328
+
329
+ var presetTaps = Array.from(this.presetTapBucket);
330
+ var bucketTaps = [];
331
+
332
+ if (typeof this.bucketHashcode === 'function') {
333
+ var bucket = this.bucketHashcode.apply(this, __spreadArray([], __read(args), false));
334
+
335
+ if (this.tapBuckets.has(bucket)) {
336
+ bucketTaps = Array.from(this.tapBuckets.get(bucket));
337
+ }
338
+ }
339
+
340
+ var selectedTapIds = new Set(__spreadArray(__spreadArray([], __read(presetTaps), false), __read(bucketTaps), false));
341
+ var selectedTapOptions = new Set();
342
+
343
+ try {
344
+ for (var selectedTapIds_1 = __values(selectedTapIds), selectedTapIds_1_1 = selectedTapIds_1.next(); !selectedTapIds_1_1.done; selectedTapIds_1_1 = selectedTapIds_1.next()) {
345
+ var tapId = selectedTapIds_1_1.value;
346
+ selectedTapOptions.add(this.tapOptionsCache.get(tapId));
347
+ }
348
+ } catch (e_3_1) {
349
+ e_3 = {
350
+ error: e_3_1
351
+ };
352
+ } finally {
353
+ try {
354
+ if (selectedTapIds_1_1 && !selectedTapIds_1_1.done && (_a = selectedTapIds_1.return)) _a.call(selectedTapIds_1);
355
+ } finally {
356
+ if (e_3) throw e_3.error;
357
+ }
358
+ }
359
+
360
+ return selectedTapOptions;
361
+ };
362
+ /**
363
+ * @internal
364
+ * */
365
+
366
+
367
+ Hook.prototype.tapping = function (fn, bucketHash) {
368
+ var _this = this;
369
+
370
+ var tapBucket = this.presetTapBucket;
371
+
372
+ if (bucketHash) {
373
+ if (!this.tapBuckets.has(bucketHash)) {
374
+ this.tapBuckets.set(bucketHash, new Set());
375
+ }
376
+
377
+ tapBucket = this.tapBuckets.get(bucketHash);
378
+ }
379
+
380
+ var tapId = this.generateTapId();
381
+ var options = {
382
+ fn: fn,
383
+ bucket: bucketHash
384
+ };
385
+ this.tapOptionsCache.set(tapId, options);
386
+ tapBucket.add(tapId);
387
+ return function () {
388
+ _this.popoutTap(tapId);
389
+ };
390
+ };
391
+ /**
392
+ * @internal
393
+ * */
394
+
395
+
396
+ Hook.prototype.popoutTap = function (tapId) {
397
+ var options = this.tapOptionsCache.get(tapId);
398
+ if (!options) return;
399
+ var bucketHash = options.bucket;
400
+
401
+ if (!bucketHash) {
402
+ this.presetTapBucket.delete(tapId);
403
+ } else {
404
+ if (this.tapBuckets.has(bucketHash)) {
405
+ this.tapBuckets.get(bucketHash).delete(tapId);
406
+ }
407
+ }
408
+
409
+ this.tapOptionsCache.delete(tapId);
410
+ };
411
+ /**
412
+ * @internal
413
+ * */
414
+
415
+
416
+ Hook.prototype.generateTapId = function () {
417
+ return "tap:".concat(++this.tapIdSeed, "?").concat(Date.now());
418
+ };
419
+
420
+ return Hook;
421
+ }();
422
+
423
+ export { Hook };
424
+ /**
425
+ * Abstract Sync Hook
426
+ *
427
+ * @remarks
428
+ * Providing `tap` method for synchronous hooks
429
+ *
430
+ * @public
431
+ * */
432
+
433
+ var SyncTapHook =
434
+ /** @class */
435
+ function (_super) {
436
+ __extends(SyncTapHook, _super);
437
+
438
+ function SyncTapHook() {
439
+ return _super !== null && _super.apply(this, arguments) || this;
440
+ }
441
+ /**
442
+ * listen to hook
443
+ *
444
+ * @param fn - Listener callback
445
+ * @param bucket - Listen to specified hashcode bucket
446
+ * @returns The unTap function
447
+ *
448
+ * @public
449
+ * */
450
+
451
+
452
+ SyncTapHook.prototype.tap = function (fn, bucket) {
453
+ return this.insertSyncTap(fn, bucket);
454
+ };
455
+
456
+ return SyncTapHook;
457
+ }(Hook);
458
+
459
+ export { SyncTapHook };
460
+ /**
461
+ * Abstract Async Hook
462
+ *
463
+ * @remarks
464
+ * Providing `tapAsync` and `tapPromise` methods for asynchronous hooks
465
+ *
466
+ * @public
467
+ * */
468
+
469
+ var AsyncTapHook =
470
+ /** @class */
471
+ function (_super) {
472
+ __extends(AsyncTapHook, _super);
473
+
474
+ function AsyncTapHook() {
475
+ return _super !== null && _super.apply(this, arguments) || this;
476
+ }
477
+ /**
478
+ * listen to hook in async callback mode
479
+ *
480
+ * @param fn - Listener callback
481
+ * The last argument of `fn` which named `cb` will be a function which signature is `(err?: Error, result?: T) => void`.
482
+ * When error occur, pass the error to `cb` as first param and the `result` param should be void,
483
+ * Otherwise, first param must be void.
484
+ *
485
+ * @param bucket - Listen to specified hashcode bucket
486
+ * @returns The unTap function
487
+ *
488
+ * @public
489
+ * */
490
+
491
+
492
+ AsyncTapHook.prototype.tapAsync = function (fn, bucket) {
493
+ return this.insertAsyncTap(fn, bucket);
494
+ };
495
+ /**
496
+ * listen to hook in async promise mode
497
+ *
498
+ * @param fn - Listener callback
499
+ * When tapping success, return resolved promise.
500
+ * Otherwise, throw error or return rejected promise.
501
+ *
502
+ * @param bucket - Listen to specified hashcode bucket
503
+ * @returns The unTap function
504
+ *
505
+ * @public
506
+ * */
507
+
508
+
509
+ AsyncTapHook.prototype.tapPromise = function (fn, bucket) {
510
+ return this.insertPromiseTap(fn, bucket);
511
+ };
512
+
513
+ return AsyncTapHook;
514
+ }(Hook);
515
+
516
+ export { AsyncTapHook };
517
+ /**
518
+ * Synchronous Hook
519
+ *
520
+ * @remarks
521
+ * Invoke listener Synchronously and return nothing
522
+ *
523
+ * @public
524
+ * */
525
+
526
+ var SyncHook =
527
+ /** @class */
528
+ function (_super) {
529
+ __extends(SyncHook, _super);
530
+
531
+ function SyncHook() {
532
+ return _super !== null && _super.apply(this, arguments) || this;
533
+ }
534
+ /**
535
+ * call listener with `...args`
536
+ *
537
+ * @param args - rest parameters of calling arguments
538
+ *
539
+ * */
540
+
541
+
542
+ SyncHook.prototype.call = function () {
543
+ var args = [];
544
+
545
+ for (var _i = 0; _i < arguments.length; _i++) {
546
+ args[_i] = arguments[_i];
547
+ }
548
+
549
+ this.invokeSynchronously(args);
550
+ };
551
+
552
+ return SyncHook;
553
+ }(SyncTapHook);
554
+
555
+ export { SyncHook };
556
+ /**
557
+ * Synchronous Waterfall Hook
558
+ *
559
+ * @remarks
560
+ * Invoke listener Synchronously.
561
+ * Those non-undefined value returned from upstream listener, will waterfall to downstream as first element of arguments.
562
+ * Calling return with waterfall value of last listener.
563
+ *
564
+ * @public
565
+ * */
566
+
567
+ var SyncWaterfallHook =
568
+ /** @class */
569
+ function (_super) {
570
+ __extends(SyncWaterfallHook, _super);
571
+
572
+ function SyncWaterfallHook() {
573
+ return _super !== null && _super.apply(this, arguments) || this;
574
+ }
575
+ /**
576
+ * call listener with `...args`
577
+ *
578
+ * @param args - rest parameters of calling arguments
579
+ * @returns waterfall value
580
+ * */
581
+
582
+
583
+ SyncWaterfallHook.prototype.call = function () {
584
+ var args = [];
585
+
586
+ for (var _i = 0; _i < arguments.length; _i++) {
587
+ args[_i] = arguments[_i];
588
+ }
589
+
590
+ return this.invokeSynchronously(args, {
591
+ shouldWaterfall: true
592
+ });
593
+ };
594
+
595
+ return SyncWaterfallHook;
596
+ }(SyncTapHook);
597
+
598
+ export { SyncWaterfallHook };
599
+ /**
600
+ * Asynchronous Parallel Hook
601
+ *
602
+ * @remarks
603
+ * Invoke listeners in parallel asynchronously
604
+ *
605
+ * @public
606
+ * */
607
+
608
+ var AsyncParallelHook =
609
+ /** @class */
610
+ function (_super) {
611
+ __extends(AsyncParallelHook, _super);
612
+
613
+ function AsyncParallelHook() {
614
+ return _super !== null && _super.apply(this, arguments) || this;
615
+ }
616
+ /**
617
+ * call listener with `...args` and `cb`
618
+ *
619
+ * @param args - rest parameters of calling arguments and `cb`
620
+ * The signature of `cb` is `(err?: Error) => void`.
621
+ * */
622
+
623
+
624
+ AsyncParallelHook.prototype.callAsync = function () {
625
+ var args = [];
626
+
627
+ for (var _i = 0; _i < arguments.length; _i++) {
628
+ args[_i] = arguments[_i];
629
+ }
630
+
631
+ var asyncCb = args.pop();
632
+ this.invokeParallel( // @ts-ignored
633
+ args, {
634
+ onComplete: function onComplete(err) {
635
+ if (err != null) {
636
+ asyncCb(err);
637
+ } else {
638
+ asyncCb();
639
+ }
640
+ }
641
+ });
642
+ };
643
+ /***
644
+ * call listener with `...args`
645
+ *
646
+ * @param args - rest parameters of calling arguments
647
+ * @returns Promise indicated whether calling succeed or failed
648
+ * */
649
+
650
+
651
+ AsyncParallelHook.prototype.callPromise = function () {
652
+ var _this = this;
653
+
654
+ var args = [];
655
+
656
+ for (var _i = 0; _i < arguments.length; _i++) {
657
+ args[_i] = arguments[_i];
658
+ }
659
+
660
+ return new Promise(function (resolve, reject) {
661
+ _this.invokeParallel(args, {
662
+ onComplete: function onComplete(err, result) {
663
+ if (err != null) {
664
+ reject(err);
665
+ } else {
666
+ resolve(result);
667
+ }
668
+ }
669
+ });
670
+ });
671
+ };
672
+
673
+ return AsyncParallelHook;
674
+ }(AsyncTapHook);
675
+
676
+ export { AsyncParallelHook };
677
+ /**
678
+ * Asynchronous Waterfall Hook
679
+ *
680
+ * @remarks
681
+ * Invoke listener in queue Asynchronously.
682
+ * Those non-undefined value returned from upstream listener, will waterfall to downstream as first element of arguments.
683
+ * Calling return with waterfall value of last listener.
684
+ *
685
+ * @public
686
+ * */
687
+
688
+ var AsyncSeriesWaterfallHook =
689
+ /** @class */
690
+ function (_super) {
691
+ __extends(AsyncSeriesWaterfallHook, _super);
692
+
693
+ function AsyncSeriesWaterfallHook() {
694
+ return _super !== null && _super.apply(this, arguments) || this;
695
+ }
696
+ /**
697
+ * call listener with `...args` and `cb`
698
+ *
699
+ * @param args - rest parameters of calling arguments and `cb`
700
+ * The signature of `cb` is `(err?: Error) => void`.
701
+ * */
702
+
703
+
704
+ AsyncSeriesWaterfallHook.prototype.callAsync = function () {
705
+ var args = [];
706
+
707
+ for (var _i = 0; _i < arguments.length; _i++) {
708
+ args[_i] = arguments[_i];
709
+ }
710
+
711
+ var asyncCb = args.pop();
712
+ this.invokeSeries( // @ts-ignored
713
+ args, {
714
+ shouldWaterfall: true,
715
+ onComplete: asyncCb
716
+ });
717
+ };
718
+ /***
719
+ * call listener with `...args`
720
+ *
721
+ * @param args - rest parameters of calling arguments
722
+ * @returns Promise indicated whether calling succeed or failed
723
+ * If calling succeed, promise was resolved with waterfall value.
724
+ * */
725
+
726
+
727
+ AsyncSeriesWaterfallHook.prototype.callPromise = function () {
728
+ var _this = this;
729
+
730
+ var args = [];
731
+
732
+ for (var _i = 0; _i < arguments.length; _i++) {
733
+ args[_i] = arguments[_i];
734
+ }
735
+
736
+ return new Promise(function (resolve, reject) {
737
+ _this.invokeSeries(args, {
738
+ shouldWaterfall: true,
739
+ onComplete: function onComplete(err, result) {
740
+ if (err != null) {
741
+ reject(err);
742
+ } else {
743
+ resolve(result);
744
+ }
745
+ }
746
+ });
747
+ });
748
+ };
749
+
750
+ return AsyncSeriesWaterfallHook;
751
+ }(AsyncTapHook);
752
+
753
+ export { AsyncSeriesWaterfallHook };