@antv/g 5.0.23-alpha.8 → 5.0.24

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 (150) hide show
  1. package/dist/index.umd.min.js +4 -3
  2. package/es/AbstractRenderer.d.ts +11 -0
  3. package/es/AbstractRenderer.js +17 -2
  4. package/es/Canvas.d.ts +1 -1
  5. package/es/css/CSS.d.ts +2 -1
  6. package/es/css/CSS.js +6 -2
  7. package/es/css/CSSProperty.d.ts +1 -1
  8. package/es/css/StyleValueRegistry.d.ts +2 -1
  9. package/es/css/StyleValueRegistry.js +34 -25
  10. package/es/css/cssom/CSSNumericValue.js +1 -1
  11. package/es/css/index.d.ts +2 -1
  12. package/es/css/index.js +2 -1
  13. package/es/css/interfaces.d.ts +6 -0
  14. package/es/css/interfaces.js +2 -0
  15. package/es/css/layout/FragmentResult.d.ts +32 -0
  16. package/es/css/layout/FragmentResult.js +32 -0
  17. package/es/css/layout/LayoutChildren.d.ts +23 -0
  18. package/es/css/layout/LayoutChildren.js +55 -0
  19. package/es/css/layout/LayoutContext.d.ts +35 -0
  20. package/es/css/layout/LayoutContext.js +35 -0
  21. package/es/css/layout/LayoutDefinition.d.ts +20 -0
  22. package/es/css/layout/LayoutDefinition.js +9 -0
  23. package/es/css/layout/LayoutEdges.d.ts +24 -0
  24. package/es/css/layout/LayoutEdges.js +41 -0
  25. package/es/css/layout/LayoutEngine.d.ts +41 -0
  26. package/es/css/layout/LayoutEngine.js +332 -0
  27. package/es/css/layout/LayoutFragment.d.ts +26 -0
  28. package/es/css/layout/LayoutFragment.js +28 -0
  29. package/es/css/layout/LayoutObject.d.ts +46 -0
  30. package/es/css/layout/LayoutObject.js +172 -0
  31. package/es/css/layout/LayoutRegistry.d.ts +16 -0
  32. package/es/css/layout/LayoutRegistry.js +78 -0
  33. package/es/css/layout/LayoutWorkTask.d.ts +14 -0
  34. package/es/css/layout/LayoutWorkTask.js +1 -0
  35. package/es/css/layout/index.d.ts +11 -0
  36. package/es/css/layout/index.js +11 -0
  37. package/es/css/layout/types.d.ts +104 -0
  38. package/es/css/layout/types.js +66 -0
  39. package/es/css/parser/numeric.d.ts +1 -1
  40. package/es/css/parser/numeric.js +1 -1
  41. package/es/css/parser/transform.js +5 -4
  42. package/es/css/properties/CSSPropertyColor.d.ts +1 -1
  43. package/es/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -1
  44. package/es/display-objects/DisplayObject.d.ts +1 -2
  45. package/es/display-objects/DisplayObject.js +2 -1
  46. package/es/dom/Document.js +2 -2
  47. package/es/global-module.js +91 -8
  48. package/es/index.d.ts +3 -0
  49. package/es/index.js +3 -0
  50. package/es/plugins/CullingPlugin.d.ts +1 -0
  51. package/es/plugins/CullingPlugin.js +8 -3
  52. package/es/plugins/DirtyCheckPlugin.d.ts +1 -0
  53. package/es/plugins/DirtyCheckPlugin.js +7 -2
  54. package/es/plugins/EventPlugin.d.ts +1 -0
  55. package/es/plugins/EventPlugin.js +14 -9
  56. package/es/plugins/PrepareRendererPlugin.d.ts +1 -0
  57. package/es/plugins/PrepareRendererPlugin.js +10 -5
  58. package/es/services/EventService.js +4 -8
  59. package/es/services/OffscreenCanvasCreator.d.ts +1 -1
  60. package/es/services/OffscreenCanvasCreator.js +1 -1
  61. package/es/services/RenderingService.d.ts +18 -18
  62. package/es/services/RenderingService.js +26 -23
  63. package/es/services/SceneGraphService.js +3 -1
  64. package/es/types.d.ts +7 -5
  65. package/es/utils/deferred.d.ts +43 -0
  66. package/es/utils/deferred.js +117 -0
  67. package/es/utils/dom.d.ts +2 -0
  68. package/es/utils/dom.js +8 -0
  69. package/es/utils/index.d.ts +2 -1
  70. package/es/utils/index.js +2 -1
  71. package/es/utils/interpolation.js +1 -1
  72. package/lib/AbstractRenderer.d.ts +11 -0
  73. package/lib/AbstractRenderer.js +17 -2
  74. package/lib/Canvas.d.ts +1 -1
  75. package/lib/css/CSS.d.ts +2 -1
  76. package/lib/css/CSS.js +9 -3
  77. package/lib/css/CSSProperty.d.ts +1 -1
  78. package/lib/css/StyleValueRegistry.d.ts +2 -1
  79. package/lib/css/StyleValueRegistry.js +39 -27
  80. package/lib/css/cssom/CSSNumericValue.js +17 -17
  81. package/lib/css/index.d.ts +2 -1
  82. package/lib/css/index.js +25 -12
  83. package/lib/css/interfaces.d.ts +6 -0
  84. package/lib/css/interfaces.js +12 -0
  85. package/lib/css/layout/FragmentResult.d.ts +32 -0
  86. package/lib/css/layout/FragmentResult.js +51 -0
  87. package/lib/css/layout/LayoutChildren.d.ts +23 -0
  88. package/lib/css/layout/LayoutChildren.js +72 -0
  89. package/lib/css/layout/LayoutContext.d.ts +35 -0
  90. package/lib/css/layout/LayoutContext.js +49 -0
  91. package/lib/css/layout/LayoutDefinition.d.ts +20 -0
  92. package/lib/css/layout/LayoutDefinition.js +16 -0
  93. package/lib/css/layout/LayoutEdges.d.ts +24 -0
  94. package/lib/css/layout/LayoutEdges.js +56 -0
  95. package/lib/css/layout/LayoutEngine.d.ts +41 -0
  96. package/lib/css/layout/LayoutEngine.js +345 -0
  97. package/lib/css/layout/LayoutFragment.d.ts +26 -0
  98. package/lib/css/layout/LayoutFragment.js +44 -0
  99. package/lib/css/layout/LayoutObject.d.ts +46 -0
  100. package/lib/css/layout/LayoutObject.js +182 -0
  101. package/lib/css/layout/LayoutRegistry.d.ts +16 -0
  102. package/lib/css/layout/LayoutRegistry.js +87 -0
  103. package/lib/css/layout/LayoutWorkTask.d.ts +14 -0
  104. package/lib/css/layout/LayoutWorkTask.js +5 -0
  105. package/lib/css/layout/index.d.ts +11 -0
  106. package/lib/css/layout/index.js +148 -0
  107. package/lib/css/layout/types.d.ts +104 -0
  108. package/lib/css/layout/types.js +74 -0
  109. package/lib/css/parser/numeric.d.ts +1 -1
  110. package/lib/css/parser/numeric.js +4 -4
  111. package/lib/css/parser/transform.js +6 -4
  112. package/lib/css/properties/CSSPropertyColor.d.ts +1 -1
  113. package/lib/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -1
  114. package/lib/display-objects/DisplayObject.d.ts +1 -2
  115. package/lib/display-objects/DisplayObject.js +3 -2
  116. package/lib/dom/Document.js +2 -2
  117. package/lib/global-module.js +91 -6
  118. package/lib/index.d.ts +3 -0
  119. package/lib/index.js +7 -2
  120. package/lib/plugins/CullingPlugin.d.ts +1 -0
  121. package/lib/plugins/CullingPlugin.js +7 -3
  122. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -0
  123. package/lib/plugins/DirtyCheckPlugin.js +6 -2
  124. package/lib/plugins/EventPlugin.d.ts +1 -0
  125. package/lib/plugins/EventPlugin.js +13 -9
  126. package/lib/plugins/PrepareRendererPlugin.d.ts +1 -0
  127. package/lib/plugins/PrepareRendererPlugin.js +9 -5
  128. package/lib/services/EventService.js +4 -8
  129. package/lib/services/OffscreenCanvasCreator.d.ts +1 -1
  130. package/lib/services/OffscreenCanvasCreator.js +1 -1
  131. package/lib/services/RenderingService.d.ts +18 -18
  132. package/lib/services/RenderingService.js +26 -23
  133. package/lib/services/SceneGraphService.js +3 -1
  134. package/lib/types.d.ts +7 -5
  135. package/lib/utils/deferred.d.ts +43 -0
  136. package/lib/utils/deferred.js +131 -0
  137. package/lib/utils/dom.d.ts +2 -0
  138. package/lib/utils/dom.js +17 -0
  139. package/lib/utils/index.d.ts +2 -1
  140. package/lib/utils/index.js +17 -4
  141. package/lib/utils/interpolation.js +2 -2
  142. package/package.json +4 -3
  143. package/es/css/LayoutRegistry.d.ts +0 -11
  144. package/es/css/LayoutRegistry.js +0 -22
  145. package/es/utils/hooks.d.ts +0 -280
  146. package/es/utils/hooks.js +0 -753
  147. package/lib/css/LayoutRegistry.d.ts +0 -11
  148. package/lib/css/LayoutRegistry.js +0 -30
  149. package/lib/utils/hooks.d.ts +0 -280
  150. package/lib/utils/hooks.js +0 -759
package/lib/types.d.ts CHANGED
@@ -120,6 +120,10 @@ export interface BaseStyleProps {
120
120
  opacity?: number;
121
121
  /** 线宽 */
122
122
  lineWidth?: string | number;
123
+ /**
124
+ * increased line width when hitting test
125
+ */
126
+ increasedLineWidthForHitTesting?: string | number;
123
127
  /**
124
128
  * 交互区域
125
129
  */
@@ -157,8 +161,9 @@ export interface BaseStyleProps {
157
161
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit
158
162
  */
159
163
  miterLimit?: number;
164
+ display?: string;
160
165
  }
161
- export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x' | 'y' | 'z' | 'opacity' | 'strokeOpacity' | 'fillOpacity' | 'fill' | 'stroke' | 'lineWidth' | 'lineJoin' | 'lineCap' | 'lineDash' | 'lineDashOffset' | 'path' | 'points' | 'shadowColor' | 'shadowBlur' | 'shadowOffsetX' | 'shadowOffsetY' | 'visibility' | 'pointerEvents' | 'zIndex' | 'transformOrigin' | 'textTransform'> {
166
+ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x' | 'y' | 'z' | 'opacity' | 'strokeOpacity' | 'fillOpacity' | 'fill' | 'stroke' | 'lineWidth' | 'increasedLineWidthForHitTesting' | 'lineJoin' | 'lineCap' | 'lineDash' | 'lineDashOffset' | 'path' | 'points' | 'shadowColor' | 'shadowBlur' | 'shadowOffsetX' | 'shadowOffsetY' | 'visibility' | 'pointerEvents' | 'zIndex' | 'transformOrigin' | 'textTransform'> {
162
167
  zIndex?: CSSUnitValue;
163
168
  visibility?: CSSKeywordValue;
164
169
  pointerEvents?: CSSKeywordValue;
@@ -179,6 +184,7 @@ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x
179
184
  width?: CSSUnitValue;
180
185
  height?: CSSUnitValue;
181
186
  lineWidth?: CSSUnitValue;
187
+ increasedLineWidthForHitTesting?: CSSUnitValue;
182
188
  /**
183
189
  * x according to definition, eg. Line's x1/x2, Polyline's points
184
190
  */
@@ -210,10 +216,6 @@ export interface RendererConfig {
210
216
  * enable auto rendering
211
217
  */
212
218
  enableAutoRendering: boolean;
213
- /**
214
- * enable TAA in WebGL
215
- */
216
- enableTAA: boolean;
217
219
  }
218
220
  export declare const CanvasConfig: Syringe.DefinedToken;
219
221
  export interface CanvasConfig {
@@ -0,0 +1,43 @@
1
+ interface PromiseStatus<T> {
2
+ isPending: () => boolean;
3
+ isRejected: () => boolean;
4
+ isFulfilled: () => boolean;
5
+ getFullFilledValue: () => T;
6
+ }
7
+ /**
8
+ * This function allow you to modify a JS Promise by adding some status properties.
9
+ * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
10
+ * But modified according to the specs of promises : https://promisesaplus.com/
11
+ */
12
+ export declare const makeQuerablePromise: <T>(promise: Promise<T>) => PromiseStatus<T>;
13
+ /**
14
+ * Simple implementation of the deferred pattern.
15
+ * An object that exposes a promise and functions to resolve and reject it.
16
+ */
17
+ export declare class Deferred<T = void> {
18
+ resolve: (value: T | PromiseLike<T>) => void;
19
+ reject: (err?: any) => void;
20
+ promise: Promise<T>;
21
+ }
22
+ export declare const equalSet: (as: Set<any>, bs: Set<any>) => boolean;
23
+ /**
24
+ * Nicely typed aliases for some `Object` Methods
25
+ * - PSA: Don't mutate `yourObject`s
26
+ * - Numerical keys are BAD, resolve that issue upstream
27
+ * - Discussion: https://stackoverflow.com/a/65117465/565877
28
+ */
29
+ export declare const ObjectTyped: {
30
+ /**
31
+ * Object.keys, but with nice typing (`Array<keyof T>`)
32
+ */
33
+ keys: <T extends {}>(yourObject: T) => (keyof T)[];
34
+ /**
35
+ * Object.values, but with nice typing
36
+ */
37
+ values: <T_1 extends {}>(yourObject: T_1) => T_1[keyof T_1][];
38
+ /**
39
+ * Object.entries, but with nice typing
40
+ */
41
+ entries: <T_2 extends {}>(yourObject: T_2) => [keyof T_2, T_2[keyof T_2]][];
42
+ };
43
+ export {};
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.makeQuerablePromise = exports.equalSet = exports.ObjectTyped = exports.Deferred = void 0;
7
+
8
+ var _tslib = require("tslib");
9
+
10
+ /**
11
+ * This function allow you to modify a JS Promise by adding some status properties.
12
+ * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
13
+ * But modified according to the specs of promises : https://promisesaplus.com/
14
+ */
15
+ var makeQuerablePromise = function makeQuerablePromise(promise) {
16
+ // Don't modify any promise that has been already modified.
17
+ if (promise.isRejected || promise.isFulfilled) return promise; // Set initial state
18
+
19
+ var isPending = true;
20
+ var isRejected = false;
21
+ var isFulfilled = false;
22
+ var fullFilledValue; // Observe the promise, saving the fulfillment in a closure scope.
23
+
24
+ var result = promise.then(function (v) {
25
+ isFulfilled = true;
26
+ isPending = false;
27
+ fullFilledValue = v;
28
+ return v;
29
+ }, function (e) {
30
+ isRejected = true;
31
+ isPending = false;
32
+ throw e;
33
+ });
34
+
35
+ result.isFulfilled = function () {
36
+ return isFulfilled;
37
+ };
38
+
39
+ result.isPending = function () {
40
+ return isPending;
41
+ };
42
+
43
+ result.isRejected = function () {
44
+ return isRejected;
45
+ };
46
+
47
+ result.getFullFilledValue = function () {
48
+ return fullFilledValue;
49
+ };
50
+
51
+ return result;
52
+ };
53
+ /**
54
+ * Simple implementation of the deferred pattern.
55
+ * An object that exposes a promise and functions to resolve and reject it.
56
+ */
57
+
58
+
59
+ exports.makeQuerablePromise = makeQuerablePromise;
60
+
61
+ var Deferred =
62
+ /** @class */
63
+ function () {
64
+ function Deferred() {
65
+ var _this = this;
66
+
67
+ this.promise = new Promise(function (resolve, reject) {
68
+ _this.resolve = resolve;
69
+ _this.reject = reject;
70
+ });
71
+ }
72
+
73
+ return Deferred;
74
+ }();
75
+
76
+ exports.Deferred = Deferred;
77
+
78
+ var equalSet = function equalSet(as, bs) {
79
+ var e_1, _a;
80
+
81
+ if (as.size !== bs.size) return false;
82
+
83
+ try {
84
+ // eslint-disable-next-line no-restricted-syntax
85
+ for (var as_1 = (0, _tslib.__values)(as), as_1_1 = as_1.next(); !as_1_1.done; as_1_1 = as_1.next()) {
86
+ var a = as_1_1.value;
87
+
88
+ if (!bs.has(a)) {
89
+ return false;
90
+ }
91
+ }
92
+ } catch (e_1_1) {
93
+ e_1 = {
94
+ error: e_1_1
95
+ };
96
+ } finally {
97
+ try {
98
+ if (as_1_1 && !as_1_1.done && (_a = as_1.return)) _a.call(as_1);
99
+ } finally {
100
+ if (e_1) throw e_1.error;
101
+ }
102
+ }
103
+
104
+ return true;
105
+ };
106
+ /**
107
+ * Nicely typed aliases for some `Object` Methods
108
+ * - PSA: Don't mutate `yourObject`s
109
+ * - Numerical keys are BAD, resolve that issue upstream
110
+ * - Discussion: https://stackoverflow.com/a/65117465/565877
111
+ */
112
+
113
+
114
+ exports.equalSet = equalSet;
115
+ var ObjectTyped = {
116
+ /**
117
+ * Object.keys, but with nice typing (`Array<keyof T>`)
118
+ */
119
+ keys: Object.keys,
120
+
121
+ /**
122
+ * Object.values, but with nice typing
123
+ */
124
+ values: Object.values,
125
+
126
+ /**
127
+ * Object.entries, but with nice typing
128
+ */
129
+ entries: Object.entries
130
+ };
131
+ exports.ObjectTyped = ObjectTyped;
@@ -0,0 +1,2 @@
1
+ /// <reference types="offscreencanvas" />
2
+ export declare function setDOMSize($el: HTMLElement | OffscreenCanvas, width: number, height: number): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setDOMSize = setDOMSize;
7
+
8
+ var _canvas = require("./canvas");
9
+
10
+ var PX_SUFFIX = 'px';
11
+
12
+ function setDOMSize($el, width, height) {
13
+ if (_canvas.isBrowser && $el.style) {
14
+ $el.style.width = width + PX_SUFFIX;
15
+ $el.style.height = height + PX_SUFFIX;
16
+ }
17
+ }
@@ -6,4 +6,5 @@ export * from './text';
6
6
  export * from './string';
7
7
  export * from './event';
8
8
  export * from './canvas';
9
- export * from './hooks';
9
+ export * from './deferred';
10
+ export * from './dom';
@@ -108,15 +108,28 @@ Object.keys(_canvas).forEach(function (key) {
108
108
  });
109
109
  });
110
110
 
111
- var _hooks = require("./hooks");
111
+ var _deferred = require("./deferred");
112
112
 
113
- Object.keys(_hooks).forEach(function (key) {
113
+ Object.keys(_deferred).forEach(function (key) {
114
114
  if (key === "default" || key === "__esModule") return;
115
- if (key in exports && exports[key] === _hooks[key]) return;
115
+ if (key in exports && exports[key] === _deferred[key]) return;
116
116
  Object.defineProperty(exports, key, {
117
117
  enumerable: true,
118
118
  get: function get() {
119
- return _hooks[key];
119
+ return _deferred[key];
120
+ }
121
+ });
122
+ });
123
+
124
+ var _dom = require("./dom");
125
+
126
+ Object.keys(_dom).forEach(function (key) {
127
+ if (key === "default" || key === "__esModule") return;
128
+ if (key in exports && exports[key] === _dom[key]) return;
129
+ Object.defineProperty(exports, key, {
130
+ enumerable: true,
131
+ get: function get() {
132
+ return _dom[key];
120
133
  }
121
134
  });
122
135
  });
@@ -10,7 +10,7 @@ var _tslib = require("tslib");
10
10
 
11
11
  var _manaSyringe = require("mana-syringe");
12
12
 
13
- var _css = require("../css");
13
+ var _interfaces = require("../css/interfaces");
14
14
 
15
15
  var _animation = require("./animation");
16
16
 
@@ -127,7 +127,7 @@ function propertyInterpolation(property, left, right, target) {
127
127
  var parsedLeft = left;
128
128
  var parsedRight = right;
129
129
 
130
- var registry = _manaSyringe.GlobalContainer.get(_css.StyleValueRegistry);
130
+ var registry = _manaSyringe.GlobalContainer.get(_interfaces.StyleValueRegistry);
131
131
 
132
132
  var metadata = registry.getMetadata(property);
133
133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "5.0.23-alpha.8",
3
+ "version": "5.0.24",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "homepage": "https://github.com/antvis/g#readme",
40
40
  "dependencies": {
41
- "@antv/g-math": "^1.0.20-alpha.8",
41
+ "@antv/g-math": "^1.0.21",
42
42
  "@antv/util": "^3.0.0",
43
43
  "@types/offscreencanvas": "^2019.6.4",
44
44
  "d3-color": "^1.4.0",
@@ -47,10 +47,11 @@
47
47
  "mana-syringe": "^0.3.0",
48
48
  "reflect-metadata": "^0.1.13",
49
49
  "request-animation-frame-polyfill": "^1.1.2",
50
+ "tapable": "^2.2.1",
50
51
  "tslib": "^2.3.1"
51
52
  },
52
53
  "scripts": {
53
54
  "umd": "webpack"
54
55
  },
55
- "gitHead": "8c28e04155e41a948c323161a35aeda63c2294a4"
56
+ "gitHead": "98a28060c701e8c9c6c23fca672534677c4401b3"
56
57
  }
@@ -1,11 +0,0 @@
1
- /**
2
- *
3
- * @example
4
- *
5
- * // register layout
6
- * CSS.registerLayout('centering', class {});
7
- * // use with `display` property
8
- * group.style.display = 'layout(centering)';
9
- */
10
- export declare class LayoutRegistry {
11
- }
@@ -1,22 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { singleton } from 'mana-syringe';
3
- /**
4
- *
5
- * @example
6
- *
7
- * // register layout
8
- * CSS.registerLayout('centering', class {});
9
- * // use with `display` property
10
- * group.style.display = 'layout(centering)';
11
- */
12
-
13
- var LayoutRegistry =
14
- /** @class */
15
- function () {
16
- function LayoutRegistry() {}
17
-
18
- LayoutRegistry = __decorate([singleton()], LayoutRegistry);
19
- return LayoutRegistry;
20
- }();
21
-
22
- export { LayoutRegistry };
@@ -1,280 +0,0 @@
1
- /**
2
- * a lite tapable implementation
3
- * borrow from https://github.com/funnyecho/hamon
4
- */
5
- declare type Measure<T extends number> = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ? T : never;
6
- declare type Append<T extends any[], U> = {
7
- 0: [U];
8
- 1: [T[0], U];
9
- 2: [T[0], T[1], U];
10
- 3: [T[0], T[1], T[2], U];
11
- 4: [T[0], T[1], T[2], T[3], U];
12
- 5: [T[0], T[1], T[2], T[3], T[4], U];
13
- 6: [T[0], T[1], T[2], T[3], T[4], T[5], U];
14
- 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U];
15
- 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U];
16
- }[Measure<T['length']>];
17
- declare type AsArray<T> = T extends any[] ? T : [];
18
- declare type Callback<E, T> = (error?: E, result?: T) => void;
19
- declare type ITapID = string;
20
- declare type IHookBucketType = any;
21
- declare type IHookBucketHashcode<T> = (...args: AsArray<T>) => IHookBucketType;
22
- declare type IAsyncTapArgs<T, R> = Append<AsArray<T>, Callback<Error, R>>;
23
- declare type ISyncTapCallback<T, R> = (...args: AsArray<T>) => R;
24
- declare type IAsyncTapCallback<T, R> = (...args: IAsyncTapArgs<T, R>) => void;
25
- declare type IPromiseTapCallback<T, R> = (...args: AsArray<T>) => Promise<R>;
26
- export declare type ITapDestroy = () => void;
27
- interface ITapOptions<T, R> {
28
- fn: IAsyncTapCallback<T, R> | ISyncTapCallback<T, R>;
29
- bucket: string;
30
- }
31
- interface IInvokeSeriesObserver<T, R> {
32
- shouldBail?: boolean;
33
- shouldWaterfall?: boolean;
34
- onComplete?: (err: Error, result?: R) => void;
35
- }
36
- interface IInvokeParallelObserver<T, R> {
37
- shouldBail?: boolean;
38
- onComplete?: (err: Error, result?: R) => void;
39
- }
40
- interface IInvokeSynchronouslyObserver<T, R> {
41
- shouldBail?: boolean;
42
- shouldWaterfall?: boolean;
43
- }
44
- /**
45
- * Basic Hook Type
46
- *
47
- * @remarks
48
- * All subtype hooks are extends from `Hook` which provide the tapping and calling logic
49
- *
50
- * @param T - tuple types of calling arguments
51
- * @param R - returning value type of calling
52
- *
53
- * @public
54
- * */
55
- export declare abstract class Hook<T, R> {
56
- private tapIdSeed;
57
- /**
58
- * @internal
59
- * */
60
- protected readonly bucketHashcode: IHookBucketHashcode<T>;
61
- /**
62
- * @internal
63
- * */
64
- protected readonly presetTapBucket: Set<ITapID>;
65
- /**
66
- * @internal
67
- * */
68
- protected readonly tapBuckets: Map<IHookBucketType, Set<ITapID>>;
69
- /**
70
- * @internal
71
- * */
72
- protected readonly tapOptionsCache: Map<ITapID, ITapOptions<T, R>>;
73
- /**
74
- * @param bucketHashcode - calculate the hashcode value of calling arguments
75
- * */
76
- constructor(bucketHashcode?: IHookBucketHashcode<T>);
77
- /**
78
- * clear all tapping from hook
79
- *
80
- * @public
81
- * */
82
- exhaust(): void;
83
- /**
84
- * clear all tapping from hook
85
- *
86
- * @remarks
87
- * The same as `exhaust` {@link Hook.exhaust}
88
- *
89
- * @privateRemarks
90
- * call `exhaust`
91
- *
92
- * @public
93
- * */
94
- destroy(): void;
95
- /**
96
- * @internal
97
- * */
98
- protected insertSyncTap(fn: ISyncTapCallback<T, R>, bucket?: IHookBucketType): ITapDestroy;
99
- /**
100
- * @internal
101
- * */
102
- protected insertAsyncTap(fn: IAsyncTapCallback<T, R>, bucket?: IHookBucketType): ITapDestroy;
103
- /**
104
- * @internal
105
- * */
106
- protected insertPromiseTap(fn: IPromiseTapCallback<T, R | void>, bucket?: IHookBucketType): ITapDestroy;
107
- /**
108
- * @internal
109
- * */
110
- protected invokeSeries(args: AsArray<T>, observer?: IInvokeSeriesObserver<T, R>): void;
111
- /**
112
- * @internal
113
- * */
114
- protected invokeParallel(args: AsArray<T>, observer?: IInvokeParallelObserver<T, R>): void;
115
- /**
116
- * @internal
117
- * */
118
- protected invokeSynchronously(args: AsArray<T>, observer?: IInvokeSynchronouslyObserver<T, R>): R;
119
- /**
120
- * @internal
121
- * */
122
- protected getBucketTaps(args: AsArray<T>): Set<ITapOptions<T, R>>;
123
- /**
124
- * @internal
125
- * */
126
- private tapping;
127
- /**
128
- * @internal
129
- * */
130
- protected popoutTap(tapId: ITapID): void;
131
- /**
132
- * @internal
133
- * */
134
- private generateTapId;
135
- }
136
- /**
137
- * Abstract Sync Hook
138
- *
139
- * @remarks
140
- * Providing `tap` method for synchronous hooks
141
- *
142
- * @public
143
- * */
144
- export declare abstract class SyncTapHook<T, R> extends Hook<T, R> {
145
- /**
146
- * listen to hook
147
- *
148
- * @param fn - Listener callback
149
- * @param bucket - Listen to specified hashcode bucket
150
- * @returns The unTap function
151
- *
152
- * @public
153
- * */
154
- tap(fn: ISyncTapCallback<T, R>, bucket?: IHookBucketType): ITapDestroy;
155
- }
156
- /**
157
- * Abstract Async Hook
158
- *
159
- * @remarks
160
- * Providing `tapAsync` and `tapPromise` methods for asynchronous hooks
161
- *
162
- * @public
163
- * */
164
- export declare abstract class AsyncTapHook<T, R> extends Hook<T, R> {
165
- /**
166
- * listen to hook in async callback mode
167
- *
168
- * @param fn - Listener callback
169
- * The last argument of `fn` which named `cb` will be a function which signature is `(err?: Error, result?: T) => void`.
170
- * When error occur, pass the error to `cb` as first param and the `result` param should be void,
171
- * Otherwise, first param must be void.
172
- *
173
- * @param bucket - Listen to specified hashcode bucket
174
- * @returns The unTap function
175
- *
176
- * @public
177
- * */
178
- tapAsync(fn: IAsyncTapCallback<T, R>, bucket?: IHookBucketType): ITapDestroy;
179
- /**
180
- * listen to hook in async promise mode
181
- *
182
- * @param fn - Listener callback
183
- * When tapping success, return resolved promise.
184
- * Otherwise, throw error or return rejected promise.
185
- *
186
- * @param bucket - Listen to specified hashcode bucket
187
- * @returns The unTap function
188
- *
189
- * @public
190
- * */
191
- tapPromise(fn: IPromiseTapCallback<T, R | void>, bucket?: IHookBucketType): ITapDestroy;
192
- }
193
- /**
194
- * Synchronous Hook
195
- *
196
- * @remarks
197
- * Invoke listener Synchronously and return nothing
198
- *
199
- * @public
200
- * */
201
- export declare class SyncHook<T, R = void> extends SyncTapHook<T, R> {
202
- /**
203
- * call listener with `...args`
204
- *
205
- * @param args - rest parameters of calling arguments
206
- *
207
- * */
208
- call(...args: AsArray<T>): void;
209
- }
210
- /**
211
- * Synchronous Waterfall Hook
212
- *
213
- * @remarks
214
- * Invoke listener Synchronously.
215
- * Those non-undefined value returned from upstream listener, will waterfall to downstream as first element of arguments.
216
- * Calling return with waterfall value of last listener.
217
- *
218
- * @public
219
- * */
220
- export declare class SyncWaterfallHook<T, R> extends SyncTapHook<T, R> {
221
- /**
222
- * call listener with `...args`
223
- *
224
- * @param args - rest parameters of calling arguments
225
- * @returns waterfall value
226
- * */
227
- call(...args: AsArray<T>): R;
228
- }
229
- /**
230
- * Asynchronous Parallel Hook
231
- *
232
- * @remarks
233
- * Invoke listeners in parallel asynchronously
234
- *
235
- * @public
236
- * */
237
- export declare class AsyncParallelHook<T, R = void> extends AsyncTapHook<T, R> {
238
- /**
239
- * call listener with `...args` and `cb`
240
- *
241
- * @param args - rest parameters of calling arguments and `cb`
242
- * The signature of `cb` is `(err?: Error) => void`.
243
- * */
244
- callAsync(...args: IAsyncTapArgs<T, R>): void;
245
- /***
246
- * call listener with `...args`
247
- *
248
- * @param args - rest parameters of calling arguments
249
- * @returns Promise indicated whether calling succeed or failed
250
- * */
251
- callPromise(...args: AsArray<T>): Promise<R>;
252
- }
253
- /**
254
- * Asynchronous Waterfall Hook
255
- *
256
- * @remarks
257
- * Invoke listener in queue Asynchronously.
258
- * Those non-undefined value returned from upstream listener, will waterfall to downstream as first element of arguments.
259
- * Calling return with waterfall value of last listener.
260
- *
261
- * @public
262
- * */
263
- export declare class AsyncSeriesWaterfallHook<T, R> extends AsyncTapHook<T, R> {
264
- /**
265
- * call listener with `...args` and `cb`
266
- *
267
- * @param args - rest parameters of calling arguments and `cb`
268
- * The signature of `cb` is `(err?: Error) => void`.
269
- * */
270
- callAsync(...args: IAsyncTapArgs<T, R>): void;
271
- /***
272
- * call listener with `...args`
273
- *
274
- * @param args - rest parameters of calling arguments
275
- * @returns Promise indicated whether calling succeed or failed
276
- * If calling succeed, promise was resolved with waterfall value.
277
- * */
278
- callPromise(...args: AsArray<T>): Promise<R>;
279
- }
280
- export {};