@antv/g 5.0.22 → 5.0.23-alpha.4

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