@antv/g 5.0.23-alpha.9 → 5.1.0

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 (256) 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/Canvas.js +2 -0
  6. package/es/css/CSS.d.ts +2 -1
  7. package/es/css/CSS.js +6 -2
  8. package/es/css/CSSProperty.d.ts +3 -2
  9. package/es/css/StyleValueRegistry.d.ts +4 -2
  10. package/es/css/StyleValueRegistry.js +100 -95
  11. package/es/css/cssom/CSSNumericValue.js +1 -1
  12. package/es/css/index.d.ts +2 -1
  13. package/es/css/index.js +2 -1
  14. package/es/css/interfaces.d.ts +6 -0
  15. package/es/css/interfaces.js +2 -0
  16. package/es/css/layout/FragmentResult.d.ts +32 -0
  17. package/es/css/layout/FragmentResult.js +32 -0
  18. package/es/css/layout/LayoutChildren.d.ts +23 -0
  19. package/es/css/layout/LayoutChildren.js +55 -0
  20. package/es/css/layout/LayoutContext.d.ts +35 -0
  21. package/es/css/layout/LayoutContext.js +35 -0
  22. package/es/css/layout/LayoutDefinition.d.ts +20 -0
  23. package/es/css/layout/LayoutDefinition.js +9 -0
  24. package/es/css/layout/LayoutEdges.d.ts +24 -0
  25. package/es/css/layout/LayoutEdges.js +41 -0
  26. package/es/css/layout/LayoutEngine.d.ts +41 -0
  27. package/es/css/layout/LayoutEngine.js +332 -0
  28. package/es/css/layout/LayoutFragment.d.ts +26 -0
  29. package/es/css/layout/LayoutFragment.js +28 -0
  30. package/es/css/layout/LayoutObject.d.ts +46 -0
  31. package/es/css/layout/LayoutObject.js +172 -0
  32. package/es/css/layout/LayoutRegistry.d.ts +16 -0
  33. package/es/css/layout/LayoutRegistry.js +78 -0
  34. package/es/css/layout/LayoutWorkTask.d.ts +14 -0
  35. package/es/css/layout/LayoutWorkTask.js +1 -0
  36. package/es/css/layout/index.d.ts +11 -0
  37. package/es/css/layout/index.js +11 -0
  38. package/es/css/layout/types.d.ts +104 -0
  39. package/es/css/layout/types.js +66 -0
  40. package/es/css/parser/color.d.ts +1 -1
  41. package/es/css/parser/color.js +2 -2
  42. package/es/css/parser/dimension.js +5 -1
  43. package/es/css/parser/path.d.ts +2 -2
  44. package/es/css/parser/path.js +9 -2
  45. package/es/css/parser/points.d.ts +8 -1
  46. package/es/css/parser/points.js +33 -3
  47. package/es/css/parser/transform.js +1 -1
  48. package/es/css/properties/CSSPropertyClipPath.js +7 -1
  49. package/es/css/properties/CSSPropertyColor.d.ts +1 -1
  50. package/es/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -1
  51. package/es/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  52. package/es/css/properties/CSSPropertyLocalPosition.js +64 -20
  53. package/es/css/properties/CSSPropertyPath.d.ts +2 -2
  54. package/es/css/properties/CSSPropertyPath.js +7 -5
  55. package/es/css/properties/CSSPropertyPoints.js +3 -4
  56. package/es/css/properties/CSSPropertyTransform.d.ts +1 -1
  57. package/es/css/properties/CSSPropertyTransform.js +76 -104
  58. package/es/display-objects/Circle.d.ts +4 -0
  59. package/es/display-objects/Circle.js +2 -0
  60. package/es/display-objects/DisplayObject.d.ts +2 -9
  61. package/es/display-objects/DisplayObject.js +8 -27
  62. package/es/display-objects/Ellipse.d.ts +4 -0
  63. package/es/display-objects/Ellipse.js +2 -0
  64. package/es/display-objects/Group.d.ts +4 -0
  65. package/es/display-objects/Group.js +2 -0
  66. package/es/display-objects/HTML.d.ts +4 -4
  67. package/es/display-objects/HTML.js +5 -3
  68. package/es/display-objects/Image.d.ts +4 -0
  69. package/es/display-objects/Image.js +2 -0
  70. package/es/display-objects/Line.js +2 -0
  71. package/es/display-objects/Path.d.ts +2 -2
  72. package/es/display-objects/Polygon.js +1 -1
  73. package/es/display-objects/Polyline.js +1 -1
  74. package/es/display-objects/Rect.d.ts +6 -2
  75. package/es/display-objects/Rect.js +2 -0
  76. package/es/display-objects/Text.d.ts +4 -0
  77. package/es/display-objects/Text.js +2 -0
  78. package/es/dom/Document.js +2 -2
  79. package/es/dom/Element.js +1 -0
  80. package/es/global-module.js +91 -8
  81. package/es/index.d.ts +3 -0
  82. package/es/index.js +3 -0
  83. package/es/plugins/CullingPlugin.d.ts +1 -0
  84. package/es/plugins/CullingPlugin.js +8 -3
  85. package/es/plugins/DirtyCheckPlugin.d.ts +1 -0
  86. package/es/plugins/DirtyCheckPlugin.js +7 -2
  87. package/es/plugins/EventPlugin.d.ts +1 -0
  88. package/es/plugins/EventPlugin.js +14 -9
  89. package/es/plugins/PrepareRendererPlugin.d.ts +1 -0
  90. package/es/plugins/PrepareRendererPlugin.js +10 -5
  91. package/es/services/EventService.js +14 -10
  92. package/es/services/OffscreenCanvasCreator.d.ts +1 -1
  93. package/es/services/OffscreenCanvasCreator.js +1 -1
  94. package/es/services/RenderingService.d.ts +18 -18
  95. package/es/services/RenderingService.js +26 -23
  96. package/es/services/SceneGraphService.d.ts +2 -0
  97. package/es/services/SceneGraphService.js +12 -1
  98. package/es/services/aabb/CircleUpdater.d.ts +0 -2
  99. package/es/services/aabb/CircleUpdater.js +2 -6
  100. package/es/services/aabb/EllipseUpdater.d.ts +0 -2
  101. package/es/services/aabb/EllipseUpdater.js +2 -6
  102. package/es/services/aabb/LineUpdater.d.ts +0 -2
  103. package/es/services/aabb/LineUpdater.js +1 -3
  104. package/es/services/aabb/PathUpdater.d.ts +0 -2
  105. package/es/services/aabb/PathUpdater.js +1 -5
  106. package/es/services/aabb/PolylineUpdater.d.ts +0 -2
  107. package/es/services/aabb/PolylineUpdater.js +1 -3
  108. package/es/services/aabb/RectUpdater.d.ts +0 -2
  109. package/es/services/aabb/RectUpdater.js +1 -5
  110. package/es/services/aabb/TextUpdater.d.ts +7 -0
  111. package/es/services/aabb/TextUpdater.js +0 -4
  112. package/es/services/aabb/interfaces.d.ts +0 -3
  113. package/es/types.d.ts +12 -23
  114. package/es/types.js +1 -0
  115. package/es/utils/deferred.d.ts +43 -0
  116. package/es/utils/deferred.js +117 -0
  117. package/es/utils/dom.d.ts +2 -0
  118. package/es/utils/dom.js +8 -0
  119. package/es/utils/index.d.ts +2 -1
  120. package/es/utils/index.js +2 -1
  121. package/es/utils/interpolation.js +3 -9
  122. package/es/utils/math.js +4 -3
  123. package/es/utils/path.d.ts +2 -2
  124. package/es/utils/path.js +61 -24
  125. package/lib/AbstractRenderer.d.ts +11 -0
  126. package/lib/AbstractRenderer.js +17 -2
  127. package/lib/Canvas.d.ts +1 -1
  128. package/lib/Canvas.js +2 -0
  129. package/lib/css/CSS.d.ts +2 -1
  130. package/lib/css/CSS.js +9 -3
  131. package/lib/css/CSSProperty.d.ts +3 -2
  132. package/lib/css/StyleValueRegistry.d.ts +4 -2
  133. package/lib/css/StyleValueRegistry.js +104 -96
  134. package/lib/css/cssom/CSSNumericValue.js +17 -17
  135. package/lib/css/index.d.ts +2 -1
  136. package/lib/css/index.js +25 -12
  137. package/lib/css/interfaces.d.ts +6 -0
  138. package/lib/css/interfaces.js +12 -0
  139. package/lib/css/layout/FragmentResult.d.ts +32 -0
  140. package/lib/css/layout/FragmentResult.js +51 -0
  141. package/lib/css/layout/LayoutChildren.d.ts +23 -0
  142. package/lib/css/layout/LayoutChildren.js +72 -0
  143. package/lib/css/layout/LayoutContext.d.ts +35 -0
  144. package/lib/css/layout/LayoutContext.js +49 -0
  145. package/lib/css/layout/LayoutDefinition.d.ts +20 -0
  146. package/lib/css/layout/LayoutDefinition.js +16 -0
  147. package/lib/css/layout/LayoutEdges.d.ts +24 -0
  148. package/lib/css/layout/LayoutEdges.js +56 -0
  149. package/lib/css/layout/LayoutEngine.d.ts +41 -0
  150. package/lib/css/layout/LayoutEngine.js +345 -0
  151. package/lib/css/layout/LayoutFragment.d.ts +26 -0
  152. package/lib/css/layout/LayoutFragment.js +44 -0
  153. package/lib/css/layout/LayoutObject.d.ts +46 -0
  154. package/lib/css/layout/LayoutObject.js +182 -0
  155. package/lib/css/layout/LayoutRegistry.d.ts +16 -0
  156. package/lib/css/layout/LayoutRegistry.js +87 -0
  157. package/lib/css/layout/LayoutWorkTask.d.ts +14 -0
  158. package/lib/css/layout/LayoutWorkTask.js +5 -0
  159. package/lib/css/layout/index.d.ts +11 -0
  160. package/lib/css/layout/index.js +148 -0
  161. package/lib/css/layout/types.d.ts +104 -0
  162. package/lib/css/layout/types.js +74 -0
  163. package/lib/css/parser/color.d.ts +1 -1
  164. package/lib/css/parser/color.js +1 -1
  165. package/lib/css/parser/dimension.js +4 -0
  166. package/lib/css/parser/path.d.ts +2 -2
  167. package/lib/css/parser/path.js +9 -2
  168. package/lib/css/parser/points.d.ts +8 -1
  169. package/lib/css/parser/points.js +33 -3
  170. package/lib/css/parser/transform.js +1 -1
  171. package/lib/css/properties/CSSPropertyClipPath.js +8 -1
  172. package/lib/css/properties/CSSPropertyColor.d.ts +1 -1
  173. package/lib/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -1
  174. package/lib/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  175. package/lib/css/properties/CSSPropertyLocalPosition.js +65 -20
  176. package/lib/css/properties/CSSPropertyPath.d.ts +2 -2
  177. package/lib/css/properties/CSSPropertyPath.js +7 -5
  178. package/lib/css/properties/CSSPropertyPoints.js +3 -4
  179. package/lib/css/properties/CSSPropertyTransform.d.ts +1 -1
  180. package/lib/css/properties/CSSPropertyTransform.js +75 -103
  181. package/lib/display-objects/Circle.d.ts +4 -0
  182. package/lib/display-objects/Circle.js +2 -0
  183. package/lib/display-objects/DisplayObject.d.ts +2 -9
  184. package/lib/display-objects/DisplayObject.js +9 -29
  185. package/lib/display-objects/Ellipse.d.ts +4 -0
  186. package/lib/display-objects/Ellipse.js +2 -0
  187. package/lib/display-objects/Group.d.ts +4 -0
  188. package/lib/display-objects/Group.js +2 -0
  189. package/lib/display-objects/HTML.d.ts +4 -4
  190. package/lib/display-objects/HTML.js +5 -3
  191. package/lib/display-objects/Image.d.ts +4 -0
  192. package/lib/display-objects/Image.js +2 -0
  193. package/lib/display-objects/Line.js +2 -0
  194. package/lib/display-objects/Path.d.ts +2 -2
  195. package/lib/display-objects/Polygon.js +1 -1
  196. package/lib/display-objects/Polyline.js +1 -1
  197. package/lib/display-objects/Rect.d.ts +6 -2
  198. package/lib/display-objects/Rect.js +2 -0
  199. package/lib/display-objects/Text.d.ts +4 -0
  200. package/lib/display-objects/Text.js +2 -0
  201. package/lib/dom/Document.js +2 -2
  202. package/lib/dom/Element.js +1 -0
  203. package/lib/global-module.js +91 -6
  204. package/lib/index.d.ts +3 -0
  205. package/lib/index.js +7 -2
  206. package/lib/plugins/CullingPlugin.d.ts +1 -0
  207. package/lib/plugins/CullingPlugin.js +7 -3
  208. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -0
  209. package/lib/plugins/DirtyCheckPlugin.js +6 -2
  210. package/lib/plugins/EventPlugin.d.ts +1 -0
  211. package/lib/plugins/EventPlugin.js +13 -9
  212. package/lib/plugins/PrepareRendererPlugin.d.ts +1 -0
  213. package/lib/plugins/PrepareRendererPlugin.js +9 -5
  214. package/lib/services/EventService.js +14 -10
  215. package/lib/services/OffscreenCanvasCreator.d.ts +1 -1
  216. package/lib/services/OffscreenCanvasCreator.js +1 -1
  217. package/lib/services/RenderingService.d.ts +18 -18
  218. package/lib/services/RenderingService.js +26 -23
  219. package/lib/services/SceneGraphService.d.ts +2 -0
  220. package/lib/services/SceneGraphService.js +15 -1
  221. package/lib/services/aabb/CircleUpdater.d.ts +0 -2
  222. package/lib/services/aabb/CircleUpdater.js +2 -6
  223. package/lib/services/aabb/EllipseUpdater.d.ts +0 -2
  224. package/lib/services/aabb/EllipseUpdater.js +2 -6
  225. package/lib/services/aabb/LineUpdater.d.ts +0 -2
  226. package/lib/services/aabb/LineUpdater.js +1 -3
  227. package/lib/services/aabb/PathUpdater.d.ts +0 -2
  228. package/lib/services/aabb/PathUpdater.js +1 -5
  229. package/lib/services/aabb/PolylineUpdater.d.ts +0 -2
  230. package/lib/services/aabb/PolylineUpdater.js +1 -3
  231. package/lib/services/aabb/RectUpdater.d.ts +0 -2
  232. package/lib/services/aabb/RectUpdater.js +1 -5
  233. package/lib/services/aabb/TextUpdater.d.ts +7 -0
  234. package/lib/services/aabb/TextUpdater.js +0 -4
  235. package/lib/services/aabb/interfaces.d.ts +0 -3
  236. package/lib/types.d.ts +12 -23
  237. package/lib/types.js +1 -0
  238. package/lib/utils/deferred.d.ts +43 -0
  239. package/lib/utils/deferred.js +131 -0
  240. package/lib/utils/dom.d.ts +2 -0
  241. package/lib/utils/dom.js +17 -0
  242. package/lib/utils/index.d.ts +2 -1
  243. package/lib/utils/index.js +17 -4
  244. package/lib/utils/interpolation.js +4 -10
  245. package/lib/utils/math.js +4 -3
  246. package/lib/utils/path.d.ts +2 -2
  247. package/lib/utils/path.js +55 -24
  248. package/package.json +4 -3
  249. package/es/css/LayoutRegistry.d.ts +0 -11
  250. package/es/css/LayoutRegistry.js +0 -22
  251. package/es/utils/hooks.d.ts +0 -280
  252. package/es/utils/hooks.js +0 -753
  253. package/lib/css/LayoutRegistry.d.ts +0 -11
  254. package/lib/css/LayoutRegistry.js +0 -30
  255. package/lib/utils/hooks.d.ts +0 -280
  256. package/lib/utils/hooks.js +0 -759
@@ -0,0 +1,32 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { inject, injectable, Syringe } from 'mana-syringe';
3
+ import { LayoutObject } from './LayoutObject';
4
+ import { LayoutContext } from './LayoutContext';
5
+ export var FragmentResultFactory = Syringe.defineToken('FragmentResultFactory');
6
+ /**
7
+ * The web developer defined layout method can return either a FragmentResultOptions or a FragmentResult.
8
+ */
9
+
10
+ export var FragmentResultOptions = Syringe.defineToken('FragmentResultOptions');
11
+ export var ContextNode = Syringe.defineToken('contextNode');
12
+
13
+ var FragmentResult =
14
+ /** @class */
15
+ function () {
16
+ function FragmentResult(_layoutContext, _node, options) {
17
+ this._layoutContext = _layoutContext;
18
+ this._node = _node;
19
+ this.options = options;
20
+ this.layoutContext = _layoutContext;
21
+ this.inlineSize = options === null || options === void 0 ? void 0 : options.inlineSize;
22
+ this.blockSize = options === null || options === void 0 ? void 0 : options.blockSize;
23
+ this.childFragments = options === null || options === void 0 ? void 0 : options.childFragments;
24
+ this.data = options.data;
25
+ this.node = _node;
26
+ }
27
+
28
+ FragmentResult = __decorate([injectable(), __param(0, inject(LayoutContext)), __param(1, inject(ContextNode)), __param(2, inject(FragmentResultOptions)), __metadata("design:paramtypes", [LayoutContext, LayoutObject, Object])], FragmentResult);
29
+ return FragmentResult;
30
+ }();
31
+
32
+ export { FragmentResult };
@@ -0,0 +1,23 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import type { LayoutObject } from './LayoutObject';
3
+ import { LayoutContext } from './LayoutContext';
4
+ import type { LayoutFragment } from './LayoutFragment';
5
+ import type { IntrinsicSizes, LayoutConstraints } from './types';
6
+ export declare const LayoutChildrenFactory: Syringe.DefinedToken;
7
+ export interface LayoutChildrenFactory {
8
+ (options: LayoutChildrenOptions): LayoutChildren;
9
+ }
10
+ export declare const LayoutChildrenOptions: Syringe.DefinedToken;
11
+ export interface LayoutChildrenOptions {
12
+ node: LayoutObject;
13
+ }
14
+ export declare class LayoutChildren {
15
+ protected readonly _layoutContext: LayoutContext;
16
+ protected readonly options: LayoutChildrenOptions;
17
+ node: LayoutObject;
18
+ readonly styleMap: Map<string, any>;
19
+ layoutContext: LayoutContext;
20
+ constructor(_layoutContext: LayoutContext, options: LayoutChildrenOptions);
21
+ intrinsicSizes(): Promise<IntrinsicSizes>;
22
+ layoutNextFragment(constraints: LayoutConstraints): Promise<LayoutFragment>;
23
+ }
@@ -0,0 +1,55 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { inject, injectable, Syringe } from 'mana-syringe';
3
+ import { Deferred } from '../../utils';
4
+ import { LayoutContext } from './LayoutContext';
5
+ import { LayoutTaskType } from './types';
6
+ export var LayoutChildrenFactory = Syringe.defineToken('LayoutChildrenFactory');
7
+ export var LayoutChildrenOptions = Syringe.defineToken('LayoutChildrenOptions');
8
+
9
+ var LayoutChildren =
10
+ /** @class */
11
+ function () {
12
+ function LayoutChildren(_layoutContext, options) {
13
+ this._layoutContext = _layoutContext;
14
+ this.options = options;
15
+ this.layoutContext = _layoutContext;
16
+ this.node = options.node;
17
+ this.styleMap = options.node.getAllStyle();
18
+ }
19
+
20
+ LayoutChildren.prototype.intrinsicSizes = function () {
21
+ // if (this.contextId !== this.layoutContext.contextId) {
22
+ // throw new Error('Invalid State: wrong layout context');
23
+ // }
24
+ var deferred = new Deferred();
25
+ this.layoutContext.appendWorkTask({
26
+ layoutChild: this,
27
+ taskType: LayoutTaskType.IntrinsicSizes,
28
+ deferred: deferred
29
+ });
30
+ return deferred.promise;
31
+ };
32
+
33
+ LayoutChildren.prototype.layoutNextFragment = function (constraints) {
34
+ // if (this.layoutContext.contextId !== this.layoutContext.contextId) {
35
+ // throw new Error('Invalid State: wrong layout context');
36
+ // }
37
+ if (this.layoutContext.mode === LayoutTaskType.IntrinsicSizes) {
38
+ throw new Error('Not Supported: cant call layoutNextFragment in intrinsicSizes');
39
+ }
40
+
41
+ var deferred = new Deferred();
42
+ this.layoutContext.appendWorkTask({
43
+ layoutConstraints: constraints,
44
+ layoutChild: this,
45
+ taskType: LayoutTaskType.Layout,
46
+ deferred: deferred
47
+ });
48
+ return deferred.promise;
49
+ };
50
+
51
+ LayoutChildren = __decorate([injectable(), __param(0, inject(LayoutContext)), __param(1, inject(LayoutChildrenOptions)), __metadata("design:paramtypes", [LayoutContext, Object])], LayoutChildren);
52
+ return LayoutChildren;
53
+ }();
54
+
55
+ export { LayoutChildren };
@@ -0,0 +1,35 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import type { LayoutWorkTask } from './LayoutWorkTask';
3
+ import type { LayoutTaskType } from './types';
4
+ import type { ContextId } from './types';
5
+ import type { FragmentResultFactory } from './FragmentResult';
6
+ import type { LayoutChildrenFactory } from './LayoutChildren';
7
+ import type { LayoutFragmentFactory } from './LayoutFragment';
8
+ export declare const LayoutContextFactory: Syringe.DefinedToken;
9
+ export interface LayoutContextFactory {
10
+ (options: {
11
+ mode: LayoutTaskType;
12
+ }): LayoutContext;
13
+ }
14
+ export declare const LayoutContextOptions: Syringe.DefinedToken;
15
+ export interface LayoutContextOptions {
16
+ mode: LayoutTaskType;
17
+ layoutChildrenFactory: LayoutChildrenFactory;
18
+ fragmentResultFactory: FragmentResultFactory;
19
+ layoutFragmentFactory: LayoutFragmentFactory;
20
+ }
21
+ /**
22
+ * 每次layout 有单独的 context
23
+ */
24
+ export declare class LayoutContext {
25
+ protected readonly options: LayoutContextOptions;
26
+ contextId: ContextId;
27
+ workQueue: LayoutWorkTask[];
28
+ mode: LayoutTaskType;
29
+ layoutChildrenFactory: LayoutChildrenFactory;
30
+ fragmentResultFactory: FragmentResultFactory;
31
+ layoutFragmentFactory: LayoutFragmentFactory;
32
+ constructor(options: LayoutContextOptions);
33
+ appendWorkTask(work: LayoutWorkTask): void;
34
+ clearWorkQueue(): void;
35
+ }
@@ -0,0 +1,35 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { inject, singleton, Syringe } from 'mana-syringe';
3
+ export var LayoutContextFactory = Syringe.defineToken('LayoutContextFactory');
4
+ export var LayoutContextOptions = Syringe.defineToken('LayoutContextOptions');
5
+ var guid = 0;
6
+ /**
7
+ * 每次layout 有单独的 context
8
+ */
9
+
10
+ var LayoutContext =
11
+ /** @class */
12
+ function () {
13
+ function LayoutContext(options) {
14
+ this.options = options;
15
+ this.workQueue = [];
16
+ this.contextId = "".concat(guid++);
17
+ this.mode = options.mode;
18
+ this.layoutChildrenFactory = options.layoutChildrenFactory;
19
+ this.fragmentResultFactory = options.fragmentResultFactory;
20
+ this.layoutFragmentFactory = options.layoutFragmentFactory;
21
+ }
22
+
23
+ LayoutContext.prototype.appendWorkTask = function (work) {
24
+ this.workQueue.push(work);
25
+ };
26
+
27
+ LayoutContext.prototype.clearWorkQueue = function () {
28
+ this.workQueue = [];
29
+ };
30
+
31
+ LayoutContext = __decorate([singleton(), __param(0, inject(LayoutContextOptions)), __metadata("design:paramtypes", [Object])], LayoutContext);
32
+ return LayoutContext;
33
+ }();
34
+
35
+ export { LayoutContext };
@@ -0,0 +1,20 @@
1
+ import type { IntrinsicSizes, LayoutConstraints, LayoutOptions } from './types';
2
+ import type { FragmentResultOptions, FragmentResult } from './FragmentResult';
3
+ import type { LayoutChildren } from './LayoutChildren';
4
+ import type { LayoutEdges } from './LayoutEdges';
5
+ export declare abstract class AbstractLayoutDefinition {
6
+ static inputProperties: string[];
7
+ static childrenInputProperties: string[];
8
+ static layoutOptions: LayoutOptions;
9
+ abstract intrinsicSizes(children: LayoutChildren[], edges: LayoutEdges, styleMap: Map<string, any>): Promise<IntrinsicSizes>;
10
+ abstract layout(children: LayoutChildren[], edges: LayoutEdges, constraints: LayoutConstraints, styleMap: Map<string, any>): Promise<FragmentResultOptions | FragmentResult>;
11
+ }
12
+ /**
13
+ * internal use
14
+ */
15
+ export declare type LayoutDefinitionCtor = {
16
+ new (): AbstractLayoutDefinition;
17
+ inputProperties: string[];
18
+ childrenInputProperties: string[];
19
+ layoutOptions: LayoutOptions;
20
+ };
@@ -0,0 +1,9 @@
1
+ var AbstractLayoutDefinition =
2
+ /** @class */
3
+ function () {
4
+ function AbstractLayoutDefinition() {}
5
+
6
+ return AbstractLayoutDefinition;
7
+ }();
8
+
9
+ export { AbstractLayoutDefinition };
@@ -0,0 +1,24 @@
1
+ import { Syringe } from 'mana-syringe';
2
+ import type { LayoutObject } from './LayoutObject';
3
+ export declare const LayoutEdgesFactory: Syringe.DefinedToken;
4
+ export interface LayoutEdgesFactory {
5
+ (options: LayoutEdgesOptions): LayoutEdges;
6
+ }
7
+ export declare const LayoutEdgesOptions: Syringe.DefinedToken;
8
+ export interface LayoutEdgesOptions {
9
+ node: LayoutObject;
10
+ }
11
+ /**
12
+ * https://drafts.css-houdini.org/css-layout-api/#layoutedges
13
+ * the size of border, scrollbar, padding
14
+ */
15
+ export declare class LayoutEdges {
16
+ protected readonly options: LayoutEdgesOptions;
17
+ readonly inlineStart: number;
18
+ readonly inlineEnd: number;
19
+ readonly blockStart: number;
20
+ readonly blockEnd: number;
21
+ readonly inline: number;
22
+ readonly block: number;
23
+ constructor(options: LayoutEdgesOptions);
24
+ }
@@ -0,0 +1,41 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { inject, injectable, Syringe } from 'mana-syringe';
3
+ import { PropertyName } from './types';
4
+ export var LayoutEdgesFactory = Syringe.defineToken('LayoutEdgesFactory');
5
+ export var LayoutEdgesOptions = Syringe.defineToken('LayoutEdgesOptions');
6
+ var SCROLLBAR_SIZES = [0, 0, 0, 0];
7
+ /**
8
+ * https://drafts.css-houdini.org/css-layout-api/#layoutedges
9
+ * the size of border, scrollbar, padding
10
+ */
11
+
12
+ var LayoutEdges =
13
+ /** @class */
14
+ function () {
15
+ function LayoutEdges(options) {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
17
+
18
+ this.options = options;
19
+ var node = options.node;
20
+ var styleMap = node.getAllStyle();
21
+ var borderTopWidth = (_b = (_a = styleMap.get(PropertyName.PADDING_TOP)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0;
22
+ var borderRightWidth = (_d = (_c = styleMap.get(PropertyName.PADDING_END)) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0;
23
+ var borderBottomWidth = (_f = (_e = styleMap.get(PropertyName.PADDING_BOTTOM)) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : 0;
24
+ var borderLeftWidth = (_h = (_g = styleMap.get(PropertyName.PADDING_START)) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0;
25
+ var paddingTopWidth = (_k = (_j = styleMap.get(PropertyName.PADDING_TOP)) === null || _j === void 0 ? void 0 : _j.value) !== null && _k !== void 0 ? _k : 0;
26
+ var paddingRightWidth = (_m = (_l = styleMap.get(PropertyName.PADDING_END)) === null || _l === void 0 ? void 0 : _l.value) !== null && _m !== void 0 ? _m : 0;
27
+ var paddingBottomWidth = (_p = (_o = styleMap.get(PropertyName.PADDING_BOTTOM)) === null || _o === void 0 ? void 0 : _o.value) !== null && _p !== void 0 ? _p : 0;
28
+ var paddingLeftWidth = (_r = (_q = styleMap.get(PropertyName.PADDING_START)) === null || _q === void 0 ? void 0 : _q.value) !== null && _r !== void 0 ? _r : 0;
29
+ this.blockStart = borderTopWidth + SCROLLBAR_SIZES[0] + paddingTopWidth;
30
+ this.inlineStart = borderRightWidth + SCROLLBAR_SIZES[1] + paddingRightWidth;
31
+ this.blockEnd = borderBottomWidth + SCROLLBAR_SIZES[2] + paddingBottomWidth;
32
+ this.inlineEnd = borderLeftWidth + SCROLLBAR_SIZES[3] + paddingLeftWidth;
33
+ this.block = this.blockStart + this.blockEnd;
34
+ this.inline = this.inlineStart + this.inlineEnd;
35
+ }
36
+
37
+ LayoutEdges = __decorate([injectable(), __param(0, inject(LayoutEdgesOptions)), __metadata("design:paramtypes", [Object])], LayoutEdges);
38
+ return LayoutEdges;
39
+ }();
40
+
41
+ export { LayoutEdges };
@@ -0,0 +1,41 @@
1
+ import type { LayoutObject } from './LayoutObject';
2
+ import { LayoutRegistry } from './LayoutRegistry';
3
+ import type { IntrinsicSizes, LayoutConstraints } from './types';
4
+ import { LayoutContextFactory } from './LayoutContext';
5
+ import { LayoutEdgesFactory } from './LayoutEdges';
6
+ import type { LayoutWorkTask } from './LayoutWorkTask';
7
+ import type { LayoutFragmentOptions } from './LayoutFragment';
8
+ export declare class LayoutEngine {
9
+ protected readonly _layoutRegistry: LayoutRegistry;
10
+ protected readonly _layoutContextFactory: LayoutContextFactory;
11
+ protected readonly _layoutEdgesFactory: LayoutEdgesFactory;
12
+ protected layoutRegistry: LayoutRegistry;
13
+ protected layoutContextFactory: LayoutContextFactory;
14
+ protected layoutEdgesFactory: LayoutEdgesFactory;
15
+ constructor(_layoutRegistry: LayoutRegistry, _layoutContextFactory: LayoutContextFactory, _layoutEdgesFactory: LayoutEdgesFactory);
16
+ /**
17
+ * This function takes the root of the box-tree, a LayoutConstraints object, and compute the position of every node in the tree
18
+ * @param rootNode root node of the layout object tree
19
+ * @param rootPageConstraints layout constraints
20
+ * @returns
21
+ */
22
+ computeLayout(rootNode: LayoutObject, rootPageConstraints: LayoutConstraints): Promise<void>;
23
+ /**
24
+ * calculate intrinsicSize of node tree, use depth dirst / post order traversal
25
+ * @param rootNode
26
+ */
27
+ determineAllIntrinsicSizes(rootNode: LayoutObject): Promise<void>;
28
+ protected getLayoutDefinitionName(node: LayoutObject): any;
29
+ /**
30
+ * calculate the min/max content size of node
31
+ * @param node current layout object
32
+ * @param childNodes children of the current node
33
+ */
34
+ protected determineIntrinsicSizes(node: LayoutObject, childNodes: LayoutObject[]): Promise<void>;
35
+ protected invokeIntrinsicSizesCallback(layoutName: string, node: LayoutObject, childNodes: LayoutObject[]): Promise<void>;
36
+ protected calculateLayout(node: LayoutObject, childNodes: LayoutObject[], layoutConstraints: LayoutConstraints): Promise<void>;
37
+ protected invokeLayoutCallback(layoutName: string, node: LayoutObject, childNodes: LayoutObject[], layoutConstraints: LayoutConstraints): Promise<void>;
38
+ protected runWorkQueue<T>(promise: Promise<T>, workQueue: LayoutWorkTask[]): Generator<any, T, any>;
39
+ protected getNodeIntrisicSizes(node: LayoutObject): IntrinsicSizes;
40
+ protected getNodeFragment(node: LayoutObject, constraints: LayoutConstraints): LayoutFragmentOptions;
41
+ }
@@ -0,0 +1,332 @@
1
+ import { __awaiter, __decorate, __generator, __metadata, __param, __read, __spreadArray } from "tslib";
2
+ import { inject, singleton } from 'mana-syringe';
3
+ import { LayoutRegistry } from './LayoutRegistry';
4
+ import { PropertyName } from './types';
5
+ import { LayoutTaskType } from './types';
6
+ import { LayoutContextFactory } from './LayoutContext';
7
+ import { LayoutEdgesFactory } from './LayoutEdges';
8
+ import { makeQuerablePromise } from '../../utils';
9
+ import { FragmentResult } from './FragmentResult';
10
+
11
+ var delay = function delay(minisecond) {
12
+ if (minisecond === void 0) {
13
+ minisecond = 0;
14
+ }
15
+
16
+ return new Promise(function (resolve) {
17
+ setTimeout(function () {
18
+ resolve();
19
+ }, minisecond);
20
+ });
21
+ };
22
+
23
+ var LayoutEngine =
24
+ /** @class */
25
+ function () {
26
+ function LayoutEngine(_layoutRegistry, _layoutContextFactory, _layoutEdgesFactory) {
27
+ this._layoutRegistry = _layoutRegistry;
28
+ this._layoutContextFactory = _layoutContextFactory;
29
+ this._layoutEdgesFactory = _layoutEdgesFactory;
30
+ this.layoutRegistry = _layoutRegistry;
31
+ this.layoutContextFactory = _layoutContextFactory;
32
+ this.layoutEdgesFactory = _layoutEdgesFactory; // layoutContributions.getContributions().forEach((layoutContrib) => {
33
+ // layoutContrib.registerLayout(_layoutRegistry);
34
+ // });
35
+ }
36
+ /**
37
+ * This function takes the root of the box-tree, a LayoutConstraints object, and compute the position of every node in the tree
38
+ * @param rootNode root node of the layout object tree
39
+ * @param rootPageConstraints layout constraints
40
+ * @returns
41
+ */
42
+
43
+
44
+ LayoutEngine.prototype.computeLayout = function (rootNode, rootPageConstraints) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ return [4
50
+ /*yield*/
51
+ , this.determineIntrinsicSizes(rootNode, rootNode.children)];
52
+
53
+ case 1:
54
+ _a.sent();
55
+
56
+ return [4
57
+ /*yield*/
58
+ , this.calculateLayout(rootNode, rootNode.children, rootPageConstraints)];
59
+
60
+ case 2:
61
+ _a.sent();
62
+
63
+ return [2
64
+ /*return*/
65
+ ];
66
+ }
67
+ });
68
+ });
69
+ };
70
+ /**
71
+ * calculate intrinsicSize of node tree, use depth dirst / post order traversal
72
+ * @param rootNode
73
+ */
74
+
75
+
76
+ LayoutEngine.prototype.determineAllIntrinsicSizes = function (rootNode) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ return __generator(this, function (_a) {
79
+ return [2
80
+ /*return*/
81
+ ];
82
+ });
83
+ });
84
+ };
85
+
86
+ LayoutEngine.prototype.getLayoutDefinitionName = function (node) {
87
+ var layoutStyle = node.getAllStyle().get(PropertyName.LAYOUT);
88
+
89
+ if (!layoutStyle) {
90
+ throw new Error('layout property not found');
91
+ }
92
+
93
+ return layoutStyle.value;
94
+ };
95
+ /**
96
+ * calculate the min/max content size of node
97
+ * @param node current layout object
98
+ * @param childNodes children of the current node
99
+ */
100
+
101
+
102
+ LayoutEngine.prototype.determineIntrinsicSizes = function (node, childNodes) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var layoutName;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0:
108
+ layoutName = this.getLayoutDefinitionName(node);
109
+ return [4
110
+ /*yield*/
111
+ , this.invokeIntrinsicSizesCallback(layoutName, node, childNodes)];
112
+
113
+ case 1:
114
+ _a.sent();
115
+
116
+ return [2
117
+ /*return*/
118
+ ];
119
+ }
120
+ });
121
+ });
122
+ };
123
+
124
+ LayoutEngine.prototype.invokeIntrinsicSizesCallback = function (layoutName, node, childNodes) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var LayoutDef, layoutInstance, context, _a, inputProperties, children, edges, styleMap, value, generator, intrinsicSizesValue;
127
+
128
+ return __generator(this, function (_b) {
129
+ switch (_b.label) {
130
+ case 0:
131
+ LayoutDef = this.layoutRegistry.getLayout(layoutName);
132
+ layoutInstance = new LayoutDef();
133
+ context = this.layoutContextFactory({
134
+ mode: LayoutTaskType.IntrinsicSizes
135
+ });
136
+ _a = LayoutDef.inputProperties, inputProperties = _a === void 0 ? [] : _a;
137
+ children = [];
138
+ childNodes.forEach(function (childNode) {
139
+ var layoutChild = context.layoutChildrenFactory({
140
+ node: childNode
141
+ });
142
+ children.push(layoutChild);
143
+ });
144
+ edges = this.layoutEdgesFactory({
145
+ node: node
146
+ });
147
+ styleMap = node.getStyle.apply(node, __spreadArray([], __read(inputProperties), false));
148
+ value = layoutInstance.intrinsicSizes(children, edges, styleMap);
149
+ generator = this.runWorkQueue(value, context.workQueue);
150
+ generator.next();
151
+ return [4
152
+ /*yield*/
153
+ , delay()];
154
+
155
+ case 1:
156
+ _b.sent();
157
+
158
+ intrinsicSizesValue = generator.next().value;
159
+ context.clearWorkQueue();
160
+ node.setIntrisicSizes(intrinsicSizesValue);
161
+ return [2
162
+ /*return*/
163
+ ];
164
+ }
165
+ });
166
+ });
167
+ };
168
+
169
+ LayoutEngine.prototype.calculateLayout = function (node, childNodes, layoutConstraints) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ var layoutName;
172
+ return __generator(this, function (_a) {
173
+ switch (_a.label) {
174
+ case 0:
175
+ layoutName = this.getLayoutDefinitionName(node);
176
+ return [4
177
+ /*yield*/
178
+ , this.invokeLayoutCallback(layoutName, node, childNodes, layoutConstraints)];
179
+
180
+ case 1:
181
+ _a.sent();
182
+
183
+ return [2
184
+ /*return*/
185
+ ];
186
+ }
187
+ });
188
+ });
189
+ };
190
+
191
+ LayoutEngine.prototype.invokeLayoutCallback = function (layoutName, node, childNodes, layoutConstraints) {
192
+ return __awaiter(this, void 0, void 0, function () {
193
+ var LayoutDef, layoutInstance, context, _a, inputProperties, children, edges, styleMap, value, generator, fragmentResultvalue, fragmentResult, layoutFragment;
194
+
195
+ return __generator(this, function (_b) {
196
+ switch (_b.label) {
197
+ case 0:
198
+ LayoutDef = this.layoutRegistry.getLayout(layoutName);
199
+ layoutInstance = new LayoutDef();
200
+ context = this.layoutContextFactory({
201
+ mode: LayoutTaskType.Layout
202
+ });
203
+ _a = LayoutDef.inputProperties, inputProperties = _a === void 0 ? [] : _a;
204
+ children = [];
205
+ childNodes.forEach(function (childNode) {
206
+ var layoutChild = context.layoutChildrenFactory({
207
+ node: childNode
208
+ });
209
+ children.push(layoutChild);
210
+ });
211
+ edges = this.layoutEdgesFactory({
212
+ node: node
213
+ });
214
+ styleMap = node.getStyle.apply(node, __spreadArray([], __read(inputProperties), false));
215
+ value = layoutInstance.layout(children, edges, layoutConstraints, styleMap);
216
+ generator = this.runWorkQueue(value, context.workQueue);
217
+ generator.next();
218
+ return [4
219
+ /*yield*/
220
+ , delay()];
221
+
222
+ case 1:
223
+ _b.sent();
224
+
225
+ fragmentResultvalue = generator.next().value;
226
+ context.clearWorkQueue();
227
+ fragmentResult = fragmentResultvalue instanceof FragmentResult ? fragmentResultvalue : context.fragmentResultFactory(fragmentResultvalue);
228
+ layoutFragment = context.layoutFragmentFactory({
229
+ inlineSize: fragmentResult.inlineSize,
230
+ blockSize: fragmentResult.blockSize,
231
+ data: fragmentResult.data
232
+ });
233
+ node.setComputedLayout(layoutFragment);
234
+ childNodes.forEach(function (childNode, index) {
235
+ childNode.setComputedLayout(fragmentResult.childFragments[index]);
236
+ });
237
+ return [2
238
+ /*return*/
239
+ ];
240
+ }
241
+ });
242
+ });
243
+ };
244
+
245
+ LayoutEngine.prototype.runWorkQueue = function (promise, workQueue) {
246
+ var querablePromise;
247
+
248
+ var _this = this;
249
+
250
+ return __generator(this, function (_a) {
251
+ switch (_a.label) {
252
+ case 0:
253
+ querablePromise = makeQuerablePromise(promise);
254
+
255
+ if (workQueue.length > 0 && querablePromise.isPending()) {
256
+ workQueue.forEach(function (workTask) {
257
+ if (workTask.taskType === LayoutTaskType.IntrinsicSizes) {
258
+ var layoutChild = workTask.layoutChild,
259
+ deferred = workTask.deferred;
260
+ var node = layoutChild.node;
261
+ deferred.resolve(_this.getNodeIntrisicSizes(node));
262
+ }
263
+
264
+ if (workTask.taskType === LayoutTaskType.Layout) {
265
+ var layoutChild = workTask.layoutChild,
266
+ deferred = workTask.deferred,
267
+ layoutConstraints = workTask.layoutConstraints;
268
+ var node = layoutChild.node,
269
+ layoutContext = layoutChild.layoutContext;
270
+
271
+ var fragment = _this.getNodeFragment(node, layoutConstraints);
272
+
273
+ deferred.resolve(layoutContext.layoutFragmentFactory(fragment));
274
+ }
275
+ });
276
+ } // wait promise to resolve
277
+
278
+
279
+ return [4
280
+ /*yield*/
281
+ ];
282
+
283
+ case 1:
284
+ // wait promise to resolve
285
+ _a.sent();
286
+
287
+ if (!querablePromise.isFulfilled()) {
288
+ throw new Error('promise not fullfilled!');
289
+ }
290
+
291
+ return [2
292
+ /*return*/
293
+ , querablePromise.getFullFilledValue()];
294
+ }
295
+ });
296
+ };
297
+
298
+ LayoutEngine.prototype.getNodeIntrisicSizes = function (node) {
299
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; // calculate from border box, depend on writing mode of current layout
300
+
301
+
302
+ var styleMap = node.getAllStyle();
303
+ var minWidth = ((_a = styleMap.get(PropertyName.MIN_WIDTH)) === null || _a === void 0 ? void 0 : _a.value) || ((_b = node.intrisicSizes) === null || _b === void 0 ? void 0 : _b.minContentInlineSize) || ((_c = styleMap.get(PropertyName.WIDTH)) === null || _c === void 0 ? void 0 : _c.value) || 0;
304
+ var maxWidth = ((_d = styleMap.get(PropertyName.MAX_WIDTH)) === null || _d === void 0 ? void 0 : _d.value) || ((_e = node.intrisicSizes) === null || _e === void 0 ? void 0 : _e.maxContentInlineSize) || ((_f = styleMap.get(PropertyName.WIDTH)) === null || _f === void 0 ? void 0 : _f.value) || 0;
305
+ var minHeight = ((_g = styleMap.get(PropertyName.MIN_HEIGHT)) === null || _g === void 0 ? void 0 : _g.value) || ((_h = node.intrisicSizes) === null || _h === void 0 ? void 0 : _h.minContentBlockSize) || ((_j = styleMap.get(PropertyName.HEIGHT)) === null || _j === void 0 ? void 0 : _j.value) || 0;
306
+ var maxHeight = ((_k = styleMap.get(PropertyName.MAX_HEIGHT)) === null || _k === void 0 ? void 0 : _k.value) || ((_l = node.intrisicSizes) === null || _l === void 0 ? void 0 : _l.maxContentBlockSize) || ((_m = styleMap.get(PropertyName.HEIGHT)) === null || _m === void 0 ? void 0 : _m.value) || 0;
307
+ return {
308
+ minContentInlineSize: minWidth,
309
+ maxContentInlineSize: maxWidth,
310
+ minContentBlockSize: minHeight,
311
+ maxContentBlockSize: maxHeight
312
+ };
313
+ };
314
+
315
+ LayoutEngine.prototype.getNodeFragment = function (node, constraints) {
316
+ var _a, _b, _c, _d, _e, _f; // TODO
317
+
318
+
319
+ var width = ((_a = node.getComputedLayout()) === null || _a === void 0 ? void 0 : _a.inlineSize) || ((_b = node.getAllStyle().get(PropertyName.MIN_WIDTH)) === null || _b === void 0 ? void 0 : _b.value) || ((_c = node.getAllStyle().get(PropertyName.WIDTH)) === null || _c === void 0 ? void 0 : _c.value) || 0;
320
+ var height = ((_d = node.getComputedLayout()) === null || _d === void 0 ? void 0 : _d.blockSize) || ((_e = node.getAllStyle().get(PropertyName.MIN_HEIGHT)) === null || _e === void 0 ? void 0 : _e.value) || ((_f = node.getAllStyle().get(PropertyName.HEIGHT)) === null || _f === void 0 ? void 0 : _f.value) || 0;
321
+ return {
322
+ inlineSize: width,
323
+ blockSize: height,
324
+ data: constraints.data
325
+ };
326
+ };
327
+
328
+ LayoutEngine = __decorate([singleton(), __param(0, inject(LayoutRegistry)), __param(1, inject(LayoutContextFactory)), __param(2, inject(LayoutEdgesFactory)), __metadata("design:paramtypes", [LayoutRegistry, Function, Function])], LayoutEngine);
329
+ return LayoutEngine;
330
+ }();
331
+
332
+ export { LayoutEngine };