@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
@@ -31,18 +31,14 @@ var _shapes = require("../shapes");
31
31
 
32
32
  var _interfaces2 = require("../css/interfaces");
33
33
 
34
- var _css = require("../css");
35
-
36
34
  var DEFAULT_STYLE_PROPS = {
37
- x: '',
38
- y: '',
39
- z: '',
40
35
  anchor: [0, 0],
41
36
  opacity: '',
42
37
  fillOpacity: '',
43
38
  strokeOpacity: '',
44
39
  fill: '',
45
40
  stroke: '',
41
+ transform: '',
46
42
  transformOrigin: '',
47
43
  visibility: '',
48
44
  pointerEvents: '',
@@ -307,7 +303,6 @@ function (_super) {
307
303
  }
308
304
 
309
305
  this.sceneGraphService.setPosition(this, (0, _utils.createVec3)(position, y, z));
310
- this.syncLocalPosition();
311
306
  return this;
312
307
  };
313
308
  /**
@@ -325,7 +320,6 @@ function (_super) {
325
320
  }
326
321
 
327
322
  this.sceneGraphService.setLocalPosition(this, (0, _utils.createVec3)(position, y, z));
328
- this.syncLocalPosition();
329
323
  return this;
330
324
  };
331
325
  /**
@@ -343,7 +337,6 @@ function (_super) {
343
337
  }
344
338
 
345
339
  this.sceneGraphService.translate(this, (0, _utils.createVec3)(position, y, z));
346
- this.syncLocalPosition();
347
340
  return this;
348
341
  };
349
342
  /**
@@ -361,7 +354,6 @@ function (_super) {
361
354
  }
362
355
 
363
356
  this.sceneGraphService.translateLocal(this, (0, _utils.createVec3)(position, y, z));
364
- this.syncLocalPosition();
365
357
  return this;
366
358
  };
367
359
 
@@ -520,26 +512,13 @@ function (_super) {
520
512
  return this.sceneGraphService.getWorldTransform(this);
521
513
  };
522
514
 
523
- DisplayObject.prototype.resetLocalTransform = function () {
524
- this.sceneGraphService.resetLocalTransform(this);
515
+ DisplayObject.prototype.setLocalTransform = function (transform) {
516
+ this.sceneGraphService.setLocalTransform(this, transform);
517
+ return this;
525
518
  };
526
- /**
527
- * sync style.x/y when local position changed
528
- *
529
- * Mixins may not declare private/protected properties
530
- * however, you can use ES2020 private fields
531
- */
532
-
533
-
534
- DisplayObject.prototype.syncLocalPosition = function () {
535
- var localPosition = this.getLocalPosition();
536
- this.attributes.x = localPosition[0];
537
- this.attributes.y = localPosition[1];
538
- this.attributes.z = localPosition[2]; // should not affect computed style
539
519
 
540
- this.parsedStyle.x = new _css.CSSUnitValue(this.attributes.x, 'px');
541
- this.parsedStyle.y = new _css.CSSUnitValue(this.attributes.y, 'px');
542
- this.parsedStyle.z = new _css.CSSUnitValue(this.attributes.z, 'px');
520
+ DisplayObject.prototype.resetLocalTransform = function () {
521
+ this.sceneGraphService.resetLocalTransform(this);
543
522
  }; // #endregion transformable
544
523
  // #region animatable
545
524
 
@@ -3,10 +3,14 @@ import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
3
3
  import { DisplayObject } from './DisplayObject';
4
4
  import type { CSSUnitValue } from '../css';
5
5
  export interface EllipseStyleProps extends BaseStyleProps {
6
+ cx?: number | string;
7
+ cy?: number | string;
6
8
  rx: number | string;
7
9
  ry: number | string;
8
10
  }
9
11
  export interface ParsedEllipseStyleProps extends ParsedBaseStyleProps {
12
+ cx: CSSUnitValue;
13
+ cy: CSSUnitValue;
10
14
  rx: CSSUnitValue;
11
15
  ry: CSSUnitValue;
12
16
  }
@@ -26,6 +26,8 @@ function (_super) {
26
26
  return _super.call(this, (0, _tslib.__assign)({
27
27
  type: _types.Shape.ELLIPSE,
28
28
  style: (0, _tslib.__assign)({
29
+ cx: '',
30
+ cy: '',
29
31
  rx: '',
30
32
  ry: '',
31
33
  anchor: [0.5, 0.5],
@@ -3,10 +3,14 @@ import { DisplayObject } from './DisplayObject';
3
3
  import type { DisplayObjectConfig } from '../dom';
4
4
  import type { CSSUnitValue } from '../css';
5
5
  export interface GroupStyleProps extends BaseStyleProps {
6
+ x?: number | string;
7
+ y?: number | string;
6
8
  width?: number | string;
7
9
  height?: number | string;
8
10
  }
9
11
  export interface ParsedGroupStyleProps extends ParsedBaseStyleProps {
12
+ x: CSSUnitValue;
13
+ y: CSSUnitValue;
10
14
  width?: CSSUnitValue;
11
15
  height?: CSSUnitValue;
12
16
  }
@@ -36,6 +36,8 @@ function (_super) {
36
36
  return _super.call(this, (0, _tslib.__assign)({
37
37
  type: _types.Shape.GROUP,
38
38
  style: (0, _tslib.__assign)({
39
+ x: '',
40
+ y: '',
39
41
  width: '',
40
42
  height: ''
41
43
  }, style)
@@ -4,19 +4,19 @@ import type { DisplayObjectConfig } from '../dom';
4
4
  import { AABB } from '../shapes';
5
5
  import type { CSSUnitValue } from '../css';
6
6
  export interface HTMLStyleProps extends BaseStyleProps {
7
+ x?: number | string;
8
+ y?: number | string;
7
9
  innerHTML: string | HTMLElement;
8
10
  width: number;
9
11
  height: number;
10
- className?: string | string[];
11
- style?: string;
12
12
  }
13
13
  export interface ParsedHTMLStyleProps extends ParsedBaseStyleProps {
14
+ x: CSSUnitValue;
15
+ y: CSSUnitValue;
14
16
  $el: HTMLElement;
15
17
  innerHTML: string | HTMLElement;
16
18
  width: CSSUnitValue;
17
19
  height: CSSUnitValue;
18
- className?: string | string[];
19
- style?: string;
20
20
  }
21
21
  /**
22
22
  * HTML container
@@ -36,9 +36,11 @@ function (_super) {
36
36
  _this = _super.call(this, (0, _tslib.__assign)({
37
37
  type: _types.Shape.HTML,
38
38
  style: (0, _tslib.__assign)({
39
- innerHTML: '',
40
- className: '',
41
- style: ''
39
+ x: '',
40
+ y: '',
41
+ width: '',
42
+ height: '',
43
+ innerHTML: ''
42
44
  }, style)
43
45
  }, rest)) || this;
44
46
  _this.cullable.enable = false;
@@ -3,12 +3,16 @@ import { DisplayObject } from './DisplayObject';
3
3
  import type { DisplayObjectConfig } from '../dom';
4
4
  import type { CSSUnitValue } from '../css';
5
5
  export interface ImageStyleProps extends BaseStyleProps {
6
+ x?: number | string;
7
+ y?: number | string;
6
8
  img?: string | HTMLImageElement;
7
9
  src?: string | HTMLImageElement;
8
10
  width?: number | string;
9
11
  height?: number | string;
10
12
  }
11
13
  export interface ParsedImageStyleProps extends ParsedBaseStyleProps {
14
+ x: CSSUnitValue;
15
+ y: CSSUnitValue;
12
16
  img?: string | HTMLImageElement;
13
17
  src?: string | HTMLImageElement;
14
18
  width?: CSSUnitValue;
@@ -26,6 +26,8 @@ function (_super) {
26
26
  return _super.call(this, (0, _tslib.__assign)({
27
27
  type: _types.Shape.IMAGE,
28
28
  style: (0, _tslib.__assign)({
29
+ x: '',
30
+ y: '',
29
31
  img: '',
30
32
  width: '',
31
33
  height: '',
@@ -47,6 +47,7 @@ function (_super) {
47
47
  }
48
48
 
49
49
  Line.prototype.getPoint = function (ratio) {
50
+ // TODO: account for z1/z2 in 3D line
50
51
  var _a = this.parsedStyle,
51
52
  x1 = _a.x1,
52
53
  y1 = _a.y1,
@@ -59,6 +60,7 @@ function (_super) {
59
60
  };
60
61
 
61
62
  Line.prototype.getTotalLength = function () {
63
+ // TODO: account for z1/z2 in 3D line
62
64
  var _a = this.parsedStyle,
63
65
  x1 = _a.x1,
64
66
  y1 = _a.y1,
@@ -4,8 +4,8 @@ import type { DisplayObjectConfig } from '../dom';
4
4
  import { Point } from '../shapes';
5
5
  import type { Rectangle } from '../shapes/Rectangle';
6
6
  export interface PathStyleProps extends BaseStyleProps {
7
- path?: string | PathCommand[];
8
- d?: string | PathCommand[];
7
+ path?: string | PathCommand[] | DisplayObject;
8
+ d?: string | PathCommand[] | DisplayObject;
9
9
  }
10
10
  export interface PathSegment {
11
11
  command: PathCommand[0];
@@ -26,7 +26,7 @@ function (_super) {
26
26
  return _super.call(this, (0, _tslib.__assign)({
27
27
  type: _types.Shape.POLYGON,
28
28
  style: (0, _tslib.__assign)({
29
- points: [],
29
+ points: '',
30
30
  miterLimit: 4,
31
31
  lineWidth: 1
32
32
  }, style)
@@ -30,7 +30,7 @@ function (_super) {
30
30
  return _super.call(this, (0, _tslib.__assign)({
31
31
  type: _types.Shape.POLYLINE,
32
32
  style: (0, _tslib.__assign)({
33
- points: [],
33
+ points: '',
34
34
  lineWidth: 1,
35
35
  miterLimit: 4
36
36
  }, style)
@@ -3,13 +3,17 @@ import { DisplayObject } from './DisplayObject';
3
3
  import type { DisplayObjectConfig } from '../dom';
4
4
  import type { CSSUnitValue } from '../css';
5
5
  export interface RectStyleProps extends BaseStyleProps {
6
+ x?: number | string;
7
+ y?: number | string;
6
8
  width: number | string;
7
9
  height: number | string;
8
10
  radius?: number | string;
9
11
  }
10
12
  export interface ParsedRectStyleProps extends ParsedBaseStyleProps {
11
- width?: CSSUnitValue;
12
- height?: CSSUnitValue;
13
+ x: CSSUnitValue;
14
+ y: CSSUnitValue;
15
+ width: CSSUnitValue;
16
+ height: CSSUnitValue;
13
17
  radius?: CSSUnitValue;
14
18
  }
15
19
  export declare class Rect extends DisplayObject<RectStyleProps, ParsedRectStyleProps> {
@@ -26,6 +26,8 @@ function (_super) {
26
26
  return _super.call(this, (0, _tslib.__assign)({
27
27
  type: _types.Shape.RECT,
28
28
  style: (0, _tslib.__assign)({
29
+ x: '',
30
+ y: '',
29
31
  width: '',
30
32
  height: '',
31
33
  radius: '',
@@ -4,6 +4,8 @@ import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
4
4
  import { DisplayObject } from './DisplayObject';
5
5
  import type { CSSUnitValue, CSSGlobalKeywords, CSSKeywordValue } from '../css';
6
6
  export interface TextStyleProps extends BaseStyleProps {
7
+ x?: number | string;
8
+ y?: number | string;
7
9
  text: string;
8
10
  /** 设置文本内容的当前对齐方式 */
9
11
  textAlign?: CSSGlobalKeywords | 'start' | 'center' | 'end' | 'left' | 'right';
@@ -31,6 +33,8 @@ export interface TextStyleProps extends BaseStyleProps {
31
33
  dy?: number | string;
32
34
  }
33
35
  export interface ParsedTextStyleProps extends ParsedBaseStyleProps {
36
+ x: CSSUnitValue;
37
+ y: CSSUnitValue;
34
38
  text: string;
35
39
  /** 设置文本内容的当前对齐方式 */
36
40
  textAlign?: CSSKeywordValue;
@@ -31,6 +31,8 @@ function (_super) {
31
31
  _this = _super.call(this, (0, _tslib.__assign)({
32
32
  type: _types.Shape.TEXT,
33
33
  style: (0, _tslib.__assign)({
34
+ x: '',
35
+ y: '',
34
36
  text: '',
35
37
  fontSize: '',
36
38
  fontFamily: '',
@@ -556,6 +556,7 @@ function (_super) {
556
556
 
557
557
 
558
558
  Element.prototype.removeAttribute = function (attributeName) {
559
+ this.setAttribute(attributeName, null);
559
560
  delete this.attributes[attributeName];
560
561
  };
561
562
  /**
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.containerModule = void 0;
7
7
 
8
+ var _tslib = require("tslib");
9
+
8
10
  var _manaSyringe = require("mana-syringe");
9
11
 
10
12
  var _eventemitter = require("eventemitter3");
@@ -15,6 +17,8 @@ var _services = require("./services");
15
17
 
16
18
  var _css = require("./css");
17
19
 
20
+ var _layout = require("./css/layout");
21
+
18
22
  var containerModule = (0, _manaSyringe.Module)(function (register) {
19
23
  (0, _manaSyringe.decorate)((0, _manaSyringe.injectable)(), _eventemitter.EventEmitter); // bind DisplayObject pool
20
24
 
@@ -77,6 +81,90 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
77
81
  register(_css.CSSPropertyPoints);
78
82
  register(_css.CSSPropertyClipPath);
79
83
  register(_css.CSSPropertyText);
80
- register(_css.CSSPropertyTextTransform);
84
+ register(_css.CSSPropertyTextTransform); // bind layout engine
85
+
86
+ register(_layout.LayoutEngine);
87
+ register(_layout.LayoutEdges);
88
+ register({
89
+ token: _layout.LayoutEdgesFactory,
90
+ useFactory: function useFactory(context) {
91
+ return function (options) {
92
+ var container = context.container.createChild();
93
+ container.register({
94
+ token: _layout.LayoutEdgesOptions,
95
+ useValue: options
96
+ });
97
+ return container.get(_layout.LayoutEdges);
98
+ };
99
+ }
100
+ });
101
+ register({
102
+ token: _layout.LayoutContextFactory,
103
+ useFactory: function useFactory(context) {
104
+ return function (options) {
105
+ var container = context.container.createChild();
106
+ container.register(_layout.LayoutContext);
107
+ container.register(_layout.LayoutChildren);
108
+ container.register({
109
+ token: _layout.LayoutChildrenFactory,
110
+ useFactory: function useFactory(childContext) {
111
+ return function (childOptions) {
112
+ var childContainer = childContext.container.createChild();
113
+ childContainer.register({
114
+ token: _layout.LayoutChildrenOptions,
115
+ useValue: childOptions
116
+ });
117
+ return childContainer.get(_layout.LayoutChildren);
118
+ };
119
+ }
120
+ });
121
+ container.register(_layout.FragmentResult);
122
+ container.register({
123
+ token: _layout.FragmentResultFactory,
124
+ useFactory: function useFactory(childContext) {
125
+ return function (childOptions, node) {
126
+ var childContainer = childContext.container.createChild();
127
+ childContainer.register({
128
+ token: _layout.FragmentResultOptions,
129
+ useValue: childOptions
130
+ });
131
+ childContainer.register({
132
+ token: _layout.ContextNode,
133
+ useValue: node
134
+ });
135
+ return childContainer.get(_layout.FragmentResult);
136
+ };
137
+ }
138
+ });
139
+ container.register(_layout.LayoutFragment);
140
+ container.register({
141
+ token: _layout.LayoutFragmentFactory,
142
+ useFactory: function useFactory(childContext) {
143
+ return function (childOptions) {
144
+ var childContainer = childContext.container.createChild();
145
+ childContainer.register({
146
+ token: _layout.LayoutFragmentOptions,
147
+ useValue: childOptions
148
+ });
149
+ return childContainer.get(_layout.LayoutFragment);
150
+ };
151
+ }
152
+ });
153
+ var layoutChildrenFactory = container.get(_layout.LayoutChildrenFactory);
154
+ var layoutFragmentFactory = container.get(_layout.LayoutFragmentFactory);
155
+ var fragmentResultFactory = container.get(_layout.FragmentResultFactory);
156
+ container.register({
157
+ token: _layout.LayoutContextOptions,
158
+ useValue: (0, _tslib.__assign)((0, _tslib.__assign)({}, options), {
159
+ layoutChildrenFactory: layoutChildrenFactory,
160
+ layoutFragmentFactory: layoutFragmentFactory,
161
+ fragmentResultFactory: fragmentResultFactory
162
+ })
163
+ });
164
+ var layoutContext = container.get(_layout.LayoutContext);
165
+ return layoutContext;
166
+ };
167
+ }
168
+ });
81
169
  });
82
170
  exports.containerModule = containerModule;
package/lib/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import 'reflect-metadata';
2
2
  import * as ManaSyringe from 'mana-syringe';
3
+ import { LayoutEngine } from './css/layout';
3
4
  export { ManaSyringe };
5
+ declare const layoutEngine: LayoutEngine;
6
+ export { layoutEngine };
4
7
  export * from './types';
5
8
  export * from './css';
6
9
  export * from './dom';
package/lib/index.js CHANGED
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  var _exportNames = {
9
+ layoutEngine: true,
9
10
  ManaSyringe: true
10
11
  };
11
- exports.ManaSyringe = void 0;
12
+ exports.layoutEngine = exports.ManaSyringe = void 0;
12
13
 
13
14
  require("reflect-metadata");
14
15
 
@@ -18,6 +19,8 @@ exports.ManaSyringe = ManaSyringe;
18
19
 
19
20
  var _globalModule = require("./global-module");
20
21
 
22
+ var _layout = require("./css/layout");
23
+
21
24
  var _types = require("./types");
22
25
 
23
26
  Object.keys(_types).forEach(function (key) {
@@ -190,4 +193,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
190
193
 
191
194
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
192
195
 
193
- ManaSyringe.GlobalContainer.load(_globalModule.containerModule);
196
+ ManaSyringe.GlobalContainer.load(_globalModule.containerModule);
197
+ var layoutEngine = ManaSyringe.GlobalContainer.get(_layout.LayoutEngine);
198
+ exports.layoutEngine = layoutEngine;
@@ -376,7 +376,11 @@ function (_super) {
376
376
  while (leaveEvent.target && !e.composedPath().includes(leaveEvent.target)) {
377
377
  leaveEvent.currentTarget = leaveEvent.target;
378
378
  this.notifyTarget(leaveEvent);
379
- if (isMouse) this.notifyTarget(leaveEvent, 'mouseleave');
379
+
380
+ if (isMouse) {
381
+ // console.error(leaveEvent.target);
382
+ this.notifyTarget(leaveEvent, 'mouseleave');
383
+ }
380
384
 
381
385
  if (_Node.Node.isNode(leaveEvent.target)) {
382
386
  leaveEvent.target = leaveEvent.target.parentNode;
@@ -481,7 +485,11 @@ function (_super) {
481
485
  while (leaveEvent.target && leaveEvent.target !== (_Node.Node.isNode(this.rootTarget) && this.rootTarget.parentNode)) {
482
486
  leaveEvent.currentTarget = leaveEvent.target;
483
487
  this.notifyTarget(leaveEvent);
484
- if (isMouse) this.notifyTarget(leaveEvent, 'mouseleave');
488
+
489
+ if (isMouse) {
490
+ // console.error(leaveEvent.target, 'out');
491
+ this.notifyTarget(leaveEvent, 'mouseleave');
492
+ }
485
493
 
486
494
  if (_Node.Node.isNode(leaveEvent.target)) {
487
495
  leaveEvent.target = leaveEvent.target.parentNode;
@@ -3,7 +3,7 @@
3
3
  * used in following scenes:
4
4
  * - g `ctx.measureText`
5
5
  * - g-plugin-canvas-picker `ctx.isPointInPath`
6
- * - g-plugin-webgl-renderer `ctx.createLinearGradient` and generate texture
6
+ * - g-plugin-device-renderer `ctx.createLinearGradient` and generate texture
7
7
  */
8
8
  export declare class OffscreenCanvasCreator {
9
9
  private canvas;
@@ -13,7 +13,7 @@ var _manaSyringe = require("mana-syringe");
13
13
  * used in following scenes:
14
14
  * - g `ctx.measureText`
15
15
  * - g-plugin-canvas-picker `ctx.isPointInPath`
16
- * - g-plugin-webgl-renderer `ctx.createLinearGradient` and generate texture
16
+ * - g-plugin-device-renderer `ctx.createLinearGradient` and generate texture
17
17
  */
18
18
  var OffscreenCanvasCreator =
19
19
  /** @class */
@@ -66,7 +66,7 @@ export declare class RenderingService {
66
66
  endFrame: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
67
67
  destroy: SyncHook<[], void, import("tapable").UnsetAdditionalOptions>;
68
68
  /**
69
- * use async but faster method such as GPU-based picking in `g-plugin-webgl-renderer`
69
+ * use async but faster method such as GPU-based picking in `g-plugin-device-renderer`
70
70
  */
71
71
  pick: AsyncSeriesWaterfallHook<[PickingResult], PickingResult>;
72
72
  /**
@@ -95,7 +95,7 @@ function () {
95
95
  destroy: new _tapable.SyncHook([]),
96
96
 
97
97
  /**
98
- * use async but faster method such as GPU-based picking in `g-plugin-webgl-renderer`
98
+ * use async but faster method such as GPU-based picking in `g-plugin-device-renderer`
99
99
  */
100
100
  pick: new _tapable.AsyncSeriesWaterfallHook(['result']),
101
101
 
@@ -35,6 +35,7 @@ export interface SceneGraphService {
35
35
  getLocalRotation: (element: INode) => quat;
36
36
  getWorldTransform: (element: INode, transform?: Transform) => mat4;
37
37
  getLocalTransform: (element: INode, transform?: Transform) => mat4;
38
+ setLocalTransform: (element: INode, transform: mat4) => void;
38
39
  resetLocalTransform: (element: INode) => void;
39
40
  getBounds: (element: INode, render?: boolean) => AABB;
40
41
  getLocalBounds: (element: INode, render?: boolean) => AABB;
@@ -129,6 +130,7 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
129
130
  getLocalRotation(element: INode): import("gl-matrix").vec4;
130
131
  getLocalScale(element: INode): vec3;
131
132
  getLocalTransform(element: INode): mat4;
133
+ setLocalTransform(element: INode, transform: mat4): void;
132
134
  resetLocalTransform(element: INode): void;
133
135
  private getTransformedGeometryBounds;
134
136
  /**
@@ -607,6 +607,18 @@ function () {
607
607
  return transform.localTransform;
608
608
  };
609
609
 
610
+ DefaultSceneGraphService.prototype.setLocalTransform = function (element, transform) {
611
+ var t = _glMatrix.mat4.getTranslation(_glMatrix.vec3.create(), transform);
612
+
613
+ var r = _glMatrix.mat4.getRotation(_glMatrix.quat.create(), transform);
614
+
615
+ var s = _glMatrix.mat4.getScaling(_glMatrix.vec3.create(), transform);
616
+
617
+ this.setLocalScale(element, s);
618
+ this.setLocalPosition(element, t);
619
+ this.setLocalRotation(element, r);
620
+ };
621
+
610
622
  DefaultSceneGraphService.prototype.resetLocalTransform = function (element) {
611
623
  this.setLocalScale(element, [1, 1, 1]);
612
624
  this.setLocalPosition(element, [0, 0, 0]);
@@ -4,7 +4,5 @@ export declare class CircleUpdater implements GeometryAABBUpdater<ParsedCircleSt
4
4
  update(parsedStyle: ParsedCircleStyleProps, object: Circle): {
5
5
  width: number;
6
6
  height: number;
7
- x: number;
8
- y: number;
9
7
  };
10
8
  }
@@ -19,16 +19,12 @@ function () {
19
19
  function CircleUpdater() {}
20
20
 
21
21
  CircleUpdater.prototype.update = function (parsedStyle, object) {
22
- var r = parsedStyle.r,
23
- x = parsedStyle.x,
24
- y = parsedStyle.y;
22
+ var r = parsedStyle.r;
25
23
  var width = r.value * 2;
26
24
  var height = r.value * 2;
27
25
  return {
28
26
  width: width,
29
- height: height,
30
- x: x.value || 0,
31
- y: y.value || 0
27
+ height: height
32
28
  };
33
29
  };
34
30
 
@@ -4,7 +4,5 @@ export declare class EllipseUpdater implements GeometryAABBUpdater<ParsedEllipse
4
4
  update(parsedStyle: ParsedEllipseStyleProps, object: Ellipse): {
5
5
  width: number;
6
6
  height: number;
7
- x: number;
8
- y: number;
9
7
  };
10
8
  }
@@ -20,16 +20,12 @@ function () {
20
20
 
21
21
  EllipseUpdater.prototype.update = function (parsedStyle, object) {
22
22
  var rx = parsedStyle.rx,
23
- ry = parsedStyle.ry,
24
- x = parsedStyle.x,
25
- y = parsedStyle.y;
23
+ ry = parsedStyle.ry;
26
24
  var width = rx.value * 2;
27
25
  var height = ry.value * 2;
28
26
  return {
29
27
  width: width,
30
- height: height,
31
- x: x.value || 0,
32
- y: y.value || 0
28
+ height: height
33
29
  };
34
30
  };
35
31
 
@@ -4,7 +4,5 @@ export declare class LineUpdater implements GeometryAABBUpdater<ParsedLineStyleP
4
4
  update(parsedStyle: ParsedLineStyleProps): {
5
5
  width: number;
6
6
  height: number;
7
- x: number;
8
- y: number;
9
7
  };
10
8
  }
@@ -31,9 +31,7 @@ function () {
31
31
  var height = maxY - minY;
32
32
  return {
33
33
  width: width,
34
- height: height,
35
- x: minX,
36
- y: minY
34
+ height: height
37
35
  };
38
36
  };
39
37
 
@@ -4,7 +4,5 @@ export declare class PathUpdater implements GeometryAABBUpdater<ParsedPathStyleP
4
4
  update(parsedStyle: ParsedPathStyleProps): {
5
5
  width: number;
6
6
  height: number;
7
- x: number;
8
- y: number;
9
7
  };
10
8
  }