@antv/g 5.0.23 → 5.1.1

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