@antv/g 5.0.24 → 5.1.2

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 (168) hide show
  1. package/dist/index.umd.min.js +2 -2
  2. package/es/Canvas.js +2 -0
  3. package/es/css/CSS.d.ts +4 -2
  4. package/es/css/CSS.js +6 -2
  5. package/es/css/CSSProperty.d.ts +2 -1
  6. package/es/css/StyleValueRegistry.d.ts +24 -55
  7. package/es/css/StyleValueRegistry.js +120 -138
  8. package/es/css/interfaces.d.ts +110 -0
  9. package/es/css/interfaces.js +75 -0
  10. package/es/css/parser/color.d.ts +1 -1
  11. package/es/css/parser/color.js +2 -2
  12. package/es/css/parser/dimension.js +5 -1
  13. package/es/css/parser/path.d.ts +2 -2
  14. package/es/css/parser/path.js +9 -2
  15. package/es/css/parser/points.d.ts +8 -1
  16. package/es/css/parser/points.js +33 -3
  17. package/es/css/parser/transform.js +1 -1
  18. package/es/css/properties/CSSPropertyClipPath.js +7 -1
  19. package/es/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -2
  20. package/es/css/properties/CSSPropertyLengthOrPercentage.js +34 -14
  21. package/es/css/properties/CSSPropertyLengthOrPercentage12.d.ts +15 -0
  22. package/es/css/properties/CSSPropertyLengthOrPercentage12.js +38 -0
  23. package/es/css/properties/CSSPropertyLengthOrPercentage14.d.ts +25 -0
  24. package/es/css/properties/CSSPropertyLengthOrPercentage14.js +42 -0
  25. package/es/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  26. package/es/css/properties/CSSPropertyLocalPosition.js +59 -20
  27. package/es/css/properties/CSSPropertyPath.d.ts +3 -3
  28. package/es/css/properties/CSSPropertyPath.js +11 -6
  29. package/es/css/properties/CSSPropertyPoints.js +7 -5
  30. package/es/css/properties/CSSPropertyTransform.d.ts +1 -1
  31. package/es/css/properties/CSSPropertyTransform.js +76 -104
  32. package/es/css/properties/index.d.ts +2 -2
  33. package/es/css/properties/index.js +2 -2
  34. package/es/display-objects/Circle.d.ts +4 -0
  35. package/es/display-objects/Circle.js +2 -0
  36. package/es/display-objects/CustomElement.d.ts +6 -2
  37. package/es/display-objects/CustomElement.js +15 -5
  38. package/es/display-objects/DisplayObject.d.ts +1 -7
  39. package/es/display-objects/DisplayObject.js +6 -26
  40. package/es/display-objects/Ellipse.d.ts +4 -0
  41. package/es/display-objects/Ellipse.js +2 -0
  42. package/es/display-objects/Group.d.ts +4 -0
  43. package/es/display-objects/Group.js +2 -0
  44. package/es/display-objects/HTML.d.ts +4 -4
  45. package/es/display-objects/HTML.js +5 -3
  46. package/es/display-objects/Image.d.ts +4 -0
  47. package/es/display-objects/Image.js +2 -0
  48. package/es/display-objects/Line.js +2 -0
  49. package/es/display-objects/Polygon.js +1 -1
  50. package/es/display-objects/Polyline.js +1 -1
  51. package/es/display-objects/Rect.d.ts +11 -4
  52. package/es/display-objects/Rect.js +2 -0
  53. package/es/display-objects/Text.d.ts +4 -0
  54. package/es/display-objects/Text.js +4 -2
  55. package/es/dom/Element.js +1 -0
  56. package/es/global-module.js +4 -4
  57. package/es/services/EventService.js +10 -2
  58. package/es/services/SceneGraphService.d.ts +2 -0
  59. package/es/services/SceneGraphService.js +9 -0
  60. package/es/services/aabb/CircleUpdater.d.ts +0 -2
  61. package/es/services/aabb/CircleUpdater.js +2 -6
  62. package/es/services/aabb/EllipseUpdater.d.ts +0 -2
  63. package/es/services/aabb/EllipseUpdater.js +2 -6
  64. package/es/services/aabb/LineUpdater.d.ts +0 -2
  65. package/es/services/aabb/LineUpdater.js +1 -3
  66. package/es/services/aabb/PathUpdater.d.ts +0 -2
  67. package/es/services/aabb/PathUpdater.js +1 -5
  68. package/es/services/aabb/PolylineUpdater.d.ts +0 -2
  69. package/es/services/aabb/PolylineUpdater.js +1 -3
  70. package/es/services/aabb/RectUpdater.d.ts +0 -2
  71. package/es/services/aabb/RectUpdater.js +1 -5
  72. package/es/services/aabb/TextUpdater.d.ts +7 -0
  73. package/es/services/aabb/TextUpdater.js +0 -4
  74. package/es/services/aabb/interfaces.d.ts +0 -3
  75. package/es/types.d.ts +6 -19
  76. package/es/types.js +1 -0
  77. package/es/utils/interpolation.js +5 -10
  78. package/es/utils/math.js +4 -3
  79. package/es/utils/path.d.ts +2 -2
  80. package/es/utils/path.js +76 -26
  81. package/lib/Canvas.js +2 -0
  82. package/lib/css/CSS.d.ts +4 -2
  83. package/lib/css/CSS.js +6 -2
  84. package/lib/css/CSSProperty.d.ts +2 -1
  85. package/lib/css/StyleValueRegistry.d.ts +24 -55
  86. package/lib/css/StyleValueRegistry.js +120 -137
  87. package/lib/css/interfaces.d.ts +110 -0
  88. package/lib/css/interfaces.js +76 -1
  89. package/lib/css/parser/color.d.ts +1 -1
  90. package/lib/css/parser/color.js +1 -1
  91. package/lib/css/parser/dimension.js +4 -0
  92. package/lib/css/parser/path.d.ts +2 -2
  93. package/lib/css/parser/path.js +9 -2
  94. package/lib/css/parser/points.d.ts +8 -1
  95. package/lib/css/parser/points.js +33 -3
  96. package/lib/css/parser/transform.js +1 -1
  97. package/lib/css/properties/CSSPropertyClipPath.js +8 -1
  98. package/lib/css/properties/CSSPropertyLengthOrPercentage.d.ts +1 -2
  99. package/lib/css/properties/CSSPropertyLengthOrPercentage.js +34 -14
  100. package/lib/css/properties/CSSPropertyLengthOrPercentage12.d.ts +15 -0
  101. package/lib/css/properties/CSSPropertyLengthOrPercentage12.js +48 -0
  102. package/lib/css/properties/CSSPropertyLengthOrPercentage14.d.ts +25 -0
  103. package/lib/css/properties/CSSPropertyLengthOrPercentage14.js +52 -0
  104. package/lib/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  105. package/lib/css/properties/CSSPropertyLocalPosition.js +60 -20
  106. package/lib/css/properties/CSSPropertyPath.d.ts +3 -3
  107. package/lib/css/properties/CSSPropertyPath.js +12 -6
  108. package/lib/css/properties/CSSPropertyPoints.js +8 -5
  109. package/lib/css/properties/CSSPropertyTransform.d.ts +1 -1
  110. package/lib/css/properties/CSSPropertyTransform.js +75 -103
  111. package/lib/css/properties/index.d.ts +2 -2
  112. package/lib/css/properties/index.js +17 -17
  113. package/lib/display-objects/Circle.d.ts +4 -0
  114. package/lib/display-objects/Circle.js +2 -0
  115. package/lib/display-objects/CustomElement.d.ts +6 -2
  116. package/lib/display-objects/CustomElement.js +13 -4
  117. package/lib/display-objects/DisplayObject.d.ts +1 -7
  118. package/lib/display-objects/DisplayObject.js +6 -27
  119. package/lib/display-objects/Ellipse.d.ts +4 -0
  120. package/lib/display-objects/Ellipse.js +2 -0
  121. package/lib/display-objects/Group.d.ts +4 -0
  122. package/lib/display-objects/Group.js +2 -0
  123. package/lib/display-objects/HTML.d.ts +4 -4
  124. package/lib/display-objects/HTML.js +5 -3
  125. package/lib/display-objects/Image.d.ts +4 -0
  126. package/lib/display-objects/Image.js +2 -0
  127. package/lib/display-objects/Line.js +2 -0
  128. package/lib/display-objects/Polygon.js +1 -1
  129. package/lib/display-objects/Polyline.js +1 -1
  130. package/lib/display-objects/Rect.d.ts +11 -4
  131. package/lib/display-objects/Rect.js +2 -0
  132. package/lib/display-objects/Text.d.ts +4 -0
  133. package/lib/display-objects/Text.js +4 -2
  134. package/lib/dom/Element.js +1 -0
  135. package/lib/global-module.js +3 -3
  136. package/lib/services/EventService.js +10 -2
  137. package/lib/services/SceneGraphService.d.ts +2 -0
  138. package/lib/services/SceneGraphService.js +12 -0
  139. package/lib/services/aabb/CircleUpdater.d.ts +0 -2
  140. package/lib/services/aabb/CircleUpdater.js +2 -6
  141. package/lib/services/aabb/EllipseUpdater.d.ts +0 -2
  142. package/lib/services/aabb/EllipseUpdater.js +2 -6
  143. package/lib/services/aabb/LineUpdater.d.ts +0 -2
  144. package/lib/services/aabb/LineUpdater.js +1 -3
  145. package/lib/services/aabb/PathUpdater.d.ts +0 -2
  146. package/lib/services/aabb/PathUpdater.js +1 -5
  147. package/lib/services/aabb/PolylineUpdater.d.ts +0 -2
  148. package/lib/services/aabb/PolylineUpdater.js +1 -3
  149. package/lib/services/aabb/RectUpdater.d.ts +0 -2
  150. package/lib/services/aabb/RectUpdater.js +1 -5
  151. package/lib/services/aabb/TextUpdater.d.ts +7 -0
  152. package/lib/services/aabb/TextUpdater.js +0 -4
  153. package/lib/services/aabb/interfaces.d.ts +0 -3
  154. package/lib/types.d.ts +6 -19
  155. package/lib/types.js +1 -0
  156. package/lib/utils/interpolation.js +6 -10
  157. package/lib/utils/math.js +4 -3
  158. package/lib/utils/path.d.ts +2 -2
  159. package/lib/utils/path.js +70 -26
  160. package/package.json +3 -3
  161. package/es/css/properties/CSSPropertyAnchor.d.ts +0 -8
  162. package/es/css/properties/CSSPropertyAnchor.js +0 -25
  163. package/es/css/properties/CSSPropertyLineDash.d.ts +0 -9
  164. package/es/css/properties/CSSPropertyLineDash.js +0 -25
  165. package/lib/css/properties/CSSPropertyAnchor.d.ts +0 -8
  166. package/lib/css/properties/CSSPropertyAnchor.js +0 -35
  167. package/lib/css/properties/CSSPropertyLineDash.d.ts +0 -9
  168. package/lib/css/properties/CSSPropertyLineDash.js +0 -34
@@ -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: '',
@@ -56,8 +58,8 @@ function (_super) {
56
58
  wordWrap: false,
57
59
  wordWrapWidth: 0,
58
60
  leading: 0,
59
- dx: 0,
60
- dy: 0
61
+ dx: '',
62
+ dy: ''
61
63
  }, style)
62
64
  }, rest)) || this;
63
65
  /**
@@ -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
  /**
@@ -69,11 +69,10 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
69
69
  register(_css.CSSPropertyOpacity);
70
70
  register(_css.CSSPropertyColor);
71
71
  register(_css.CSSPropertyFilter);
72
- register(_css.CSSPropertyLineDash);
72
+ register(_css.CSSPropertyLengthOrPercentage12);
73
73
  register(_css.CSSPropertyShadowBlur);
74
74
  register(_css.CSSPropertyOffsetPath);
75
75
  register(_css.CSSPropertyOffsetDistance);
76
- register(_css.CSSPropertyAnchor);
77
76
  register(_css.CSSPropertyZIndex);
78
77
  register(_css.CSSPropertyTransform);
79
78
  register(_css.CSSPropertyTransformOrigin);
@@ -81,7 +80,8 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
81
80
  register(_css.CSSPropertyPoints);
82
81
  register(_css.CSSPropertyClipPath);
83
82
  register(_css.CSSPropertyText);
84
- register(_css.CSSPropertyTextTransform); // bind layout engine
83
+ register(_css.CSSPropertyTextTransform);
84
+ register(_css.CSSPropertyLengthOrPercentage14); // bind layout engine
85
85
 
86
86
  register(_layout.LayoutEngine);
87
87
  register(_layout.LayoutEdges);
@@ -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;
@@ -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
  }
@@ -21,15 +21,11 @@ function () {
21
21
  PathUpdater.prototype.update = function (parsedStyle) {
22
22
  var path = parsedStyle.path;
23
23
  var _a = path.rect,
24
- minX = _a.x,
25
- minY = _a.y,
26
24
  width = _a.width,
27
25
  height = _a.height;
28
26
  return {
29
27
  width: width,
30
- height: height,
31
- x: minX,
32
- y: minY
28
+ height: height
33
29
  };
34
30
  };
35
31
 
@@ -4,7 +4,5 @@ export declare class PolylineUpdater implements GeometryAABBUpdater<ParsedPolyli
4
4
  update(parsedStyle: ParsedPolylineStyleProps): {
5
5
  width: number;
6
6
  height: number;
7
- x: number;
8
- y: number;
9
7
  };
10
8
  }
@@ -37,9 +37,7 @@ function () {
37
37
  var height = maxY - minY;
38
38
  return {
39
39
  width: width,
40
- height: height,
41
- x: minX,
42
- y: minY
40
+ height: height
43
41
  };
44
42
  };
45
43
 
@@ -4,7 +4,5 @@ export declare class RectUpdater implements GeometryAABBUpdater<ParsedImageStyle
4
4
  update(parsedStyle: ParsedImageStyleProps, object: Image | Rect | Group): {
5
5
  width: number;
6
6
  height: number;
7
- x: number;
8
- y: number;
9
7
  };
10
8
  }
@@ -24,8 +24,6 @@ function () {
24
24
 
25
25
  RectUpdater.prototype.update = function (parsedStyle, object) {
26
26
  var img = parsedStyle.img,
27
- x = parsedStyle.x,
28
- y = parsedStyle.y,
29
27
  width = parsedStyle.width,
30
28
  height = parsedStyle.height;
31
29
  var contentWidth = 0;
@@ -64,9 +62,7 @@ function () {
64
62
 
65
63
  return {
66
64
  width: contentWidth,
67
- height: contentHeight,
68
- x: x.value || 0,
69
- y: y.value || 0
65
+ height: contentHeight
70
66
  };
71
67
  };
72
68
 
@@ -10,5 +10,12 @@ export declare class TextUpdater implements GeometryAABBUpdater<ParsedTextStyleP
10
10
  y: number;
11
11
  offsetX: number;
12
12
  offsetY: number;
13
+ } | {
14
+ width: number;
15
+ height: number;
16
+ offsetX: number;
17
+ offsetY: number;
18
+ x?: undefined;
19
+ y?: undefined;
13
20
  };
14
21
  }
@@ -42,8 +42,6 @@ function () {
42
42
  textAlign = parsedStyle.textAlign,
43
43
  lineWidth = parsedStyle.lineWidth,
44
44
  textBaseline = parsedStyle.textBaseline,
45
- x = parsedStyle.x,
46
- y = parsedStyle.y,
47
45
  dx = parsedStyle.dx,
48
46
  dy = parsedStyle.dy;
49
47
  var offscreenCanvas = (((_b = (_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getConfig()) || {}).offscreenCanvas;
@@ -133,8 +131,6 @@ function () {
133
131
  return {
134
132
  width: halfExtents[0] * 2,
135
133
  height: halfExtents[1] * 2,
136
- x: x.value || 0,
137
- y: y.value || 0,
138
134
  offsetX: lineXOffset,
139
135
  offsetY: lineYOffset
140
136
  };
@@ -8,9 +8,6 @@ export interface GeometryAABBUpdater<T extends ParsedBaseStyleProps = any> {
8
8
  width: number;
9
9
  height: number;
10
10
  depth?: number;
11
- x: number;
12
- y: number;
13
- z?: number;
14
11
  offsetX?: number;
15
12
  offsetY?: number;
16
13
  offsetZ?: number;
package/lib/types.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import type { vec2, vec3 } from 'gl-matrix';
3
3
  import type { DisplayObject } from './display-objects';
4
4
  import type { IRenderer } from './AbstractRenderer';
5
- import type { CSSGlobalKeywords, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSUnitValue } from './css';
5
+ import type { CSSGlobalKeywords, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSUnitValue, ParsedTransform } from './css';
6
6
  import { Syringe } from 'mana-syringe';
7
7
  export declare enum Shape {
8
8
  GROUP = "g",
@@ -15,7 +15,8 @@ export declare enum Shape {
15
15
  POLYGON = "polygon",
16
16
  TEXT = "text",
17
17
  PATH = "path",
18
- HTML = "html"
18
+ HTML = "html",
19
+ MESH = "mesh"
19
20
  }
20
21
  declare type ColorType = string | null;
21
22
  export interface EventPosition {
@@ -51,18 +52,6 @@ export declare enum TextAlign {
51
52
  }
52
53
  export interface BaseStyleProps {
53
54
  class?: string;
54
- /**
55
- * x in local space
56
- */
57
- x?: number | string;
58
- /**
59
- * y in local space
60
- */
61
- y?: number | string;
62
- /**
63
- * z in local space
64
- */
65
- z?: number | string;
66
55
  /**
67
56
  * @see https://developer.mozilla.org/en-US/docs/Web/CSS/transform
68
57
  */
@@ -163,7 +152,7 @@ export interface BaseStyleProps {
163
152
  miterLimit?: number;
164
153
  display?: string;
165
154
  }
166
- export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x' | 'y' | 'z' | 'opacity' | 'strokeOpacity' | 'fillOpacity' | 'fill' | 'stroke' | 'lineWidth' | 'increasedLineWidthForHitTesting' | 'lineJoin' | 'lineCap' | 'lineDash' | 'lineDashOffset' | 'path' | 'points' | 'shadowColor' | 'shadowBlur' | 'shadowOffsetX' | 'shadowOffsetY' | 'visibility' | 'pointerEvents' | 'zIndex' | 'transformOrigin' | 'textTransform'> {
155
+ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x' | 'y' | 'z' | 'opacity' | 'strokeOpacity' | 'fillOpacity' | 'fill' | 'stroke' | 'lineWidth' | 'increasedLineWidthForHitTesting' | 'lineJoin' | 'lineCap' | 'lineDash' | 'lineDashOffset' | 'path' | 'points' | 'shadowColor' | 'shadowBlur' | 'shadowOffsetX' | 'shadowOffsetY' | 'visibility' | 'pointerEvents' | 'zIndex' | 'transform' | 'transformOrigin' | 'textTransform'> {
167
156
  zIndex?: CSSUnitValue;
168
157
  visibility?: CSSKeywordValue;
169
158
  pointerEvents?: CSSKeywordValue;
@@ -177,10 +166,8 @@ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x
177
166
  lineJoin?: CSSKeywordValue;
178
167
  lineDashOffset?: CSSUnitValue;
179
168
  anchor?: [CSSUnitValue, CSSUnitValue, CSSUnitValue];
169
+ transform: ParsedTransform[];
180
170
  transformOrigin?: [CSSUnitValue, CSSUnitValue, CSSUnitValue];
181
- x?: CSSUnitValue;
182
- y?: CSSUnitValue;
183
- z?: CSSUnitValue;
184
171
  width?: CSSUnitValue;
185
172
  height?: CSSUnitValue;
186
173
  lineWidth?: CSSUnitValue;
@@ -247,7 +234,7 @@ export interface CanvasConfig {
247
234
  /**
248
235
  * replace `new window.Image()`
249
236
  */
250
- createImage?: () => HTMLImageElement;
237
+ createImage?: (src: string) => HTMLImageElement;
251
238
  /**
252
239
  * limits query
253
240
  */
package/lib/types.js CHANGED
@@ -22,6 +22,7 @@ exports.Shape = Shape;
22
22
  Shape["TEXT"] = "text";
23
23
  Shape["PATH"] = "path";
24
24
  Shape["HTML"] = "html";
25
+ Shape["MESH"] = "mesh";
25
26
  })(Shape || (exports.Shape = Shape = {}));
26
27
 
27
28
  var LineCap;
@@ -12,6 +12,8 @@ var _manaSyringe = require("mana-syringe");
12
12
 
13
13
  var _interfaces = require("../css/interfaces");
14
14
 
15
+ var _StyleValueRegistry = require("../css/StyleValueRegistry");
16
+
15
17
  var _animation = require("./animation");
16
18
 
17
19
  var _string = require("./string");
@@ -131,13 +133,13 @@ function propertyInterpolation(property, left, right, target) {
131
133
 
132
134
  var metadata = registry.getMetadata(property);
133
135
 
134
- if (metadata && metadata.handler && metadata.interpolable) {
135
- var propertyHandler = _manaSyringe.GlobalContainer.get(metadata.handler);
136
+ if (metadata && metadata.syntax && metadata.interpolable && _StyleValueRegistry.PROPERTY_HANDLERS[metadata.syntax]) {
137
+ var propertyHandler = _manaSyringe.GlobalContainer.get(_StyleValueRegistry.PROPERTY_HANDLERS[metadata.syntax]);
136
138
 
137
139
  if (propertyHandler) {
138
140
  if (propertyHandler.parser) {
139
- parsedLeft = propertyHandler.parser(left);
140
- parsedRight = propertyHandler.parser(right);
141
+ parsedLeft = propertyHandler.parser(left, target);
142
+ parsedRight = propertyHandler.parser(right, target);
141
143
  } // if (propertyHandler.calculator) {
142
144
  // parsedLeft = propertyHandler.calculator(parsedLeft);
143
145
  // // parsedLeft = handler.calculator
@@ -199,12 +201,6 @@ var FORMAT_ATTR_MAP = {
199
201
  d: {
200
202
  alias: 'path'
201
203
  },
202
- cx: {
203
- alias: 'x'
204
- },
205
- cy: {
206
- alias: 'y'
207
- },
208
204
  strokeDasharray: {
209
205
  alias: 'lineDash'
210
206
  },
package/lib/utils/math.js CHANGED
@@ -236,8 +236,8 @@ function makePerspective(out, left, right, top, bottom, near, far) {
236
236
 
237
237
  function decompose(mat) {
238
238
  var row0x = mat[0];
239
- var row0y = mat[3];
240
- var row1x = mat[1];
239
+ var row0y = mat[1];
240
+ var row1x = mat[3];
241
241
  var row1y = mat[4]; // decompose 3x3 matrix
242
242
  // @see https://www.w3.org/TR/css-transforms-1/#decomposing-a-2d-matrix
243
243
 
@@ -267,6 +267,7 @@ function decompose(mat) {
267
267
  } // Compute rotation and renormalize matrix.
268
268
 
269
269
 
270
- var angle = Math.atan2(row0y, row0x);
270
+ var rotation = Math.atan2(row0y, row0x);
271
+ var angle = rad2deg(rotation);
271
272
  return [mat[6], mat[7], scalingX, scalingY, angle];
272
273
  }
@@ -1,4 +1,4 @@
1
- import type { DisplayObject } from '../display-objects';
1
+ import type { Circle, Ellipse, Line, Path, Polyline, Polygon, Rect } from '../display-objects';
2
2
  import type { PathCommand } from '../types';
3
3
  export declare function equalizeSegments(path1: PathCommand[], path2: PathCommand[], TL?: number): PathCommand[][];
4
4
  export declare function getDrawDirection(pathArray: PathCommand[]): boolean;
@@ -12,4 +12,4 @@ export declare function getRotatedCurve(a: PathCommand[], b: PathCommand[]): (st
12
12
  * * anchor
13
13
  * * lineWidth
14
14
  */
15
- export declare function convertToPath(object: DisplayObject): string;
15
+ export declare function convertToPath(object: Circle | Ellipse | Rect | Line | Polyline | Polygon | Path, applyLocalTransform?: boolean): string;
package/lib/utils/path.js CHANGED
@@ -223,18 +223,31 @@ function getRotatedCurve(a, b) {
223
223
  return rotations[computedIndex];
224
224
  }
225
225
 
226
- function commandsToPathString(commands, localTransform, anchor, parsedStyle) {
227
- var _a = parsedStyle.defX,
228
- defX = _a === void 0 ? 0 : _a,
229
- _b = parsedStyle.defY,
230
- defY = _b === void 0 ? 0 : _b;
226
+ function commandsToPathString(commands, object, applyLocalTransform) {
227
+ if (applyLocalTransform === void 0) {
228
+ applyLocalTransform = true;
229
+ }
230
+
231
+ var transform;
232
+
233
+ if (applyLocalTransform) {
234
+ transform = object.getLocalTransform();
235
+ }
236
+
237
+ var _a = object.parsedStyle,
238
+ _b = _a.defX,
239
+ defX = _b === void 0 ? 0 : _b,
240
+ _c = _a.defY,
241
+ defY = _c === void 0 ? 0 : _c;
231
242
  return commands.reduce(function (prev, cur) {
232
243
  var path = '';
233
244
 
234
245
  if (cur[0] === 'M' || cur[0] === 'L') {
235
246
  var p = _glMatrix.vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
236
247
 
237
- _glMatrix.vec3.transformMat4(p, p, localTransform);
248
+ if (applyLocalTransform) {
249
+ _glMatrix.vec3.transformMat4(p, p, transform);
250
+ }
238
251
 
239
252
  path = "".concat(cur[0]).concat(p[0], ",").concat(p[1]);
240
253
  } else if (cur[0] === 'Z') {
@@ -246,17 +259,21 @@ function commandsToPathString(commands, localTransform, anchor, parsedStyle) {
246
259
 
247
260
  var p3 = _glMatrix.vec3.fromValues(cur[5] - defX, cur[6] - defY, 0);
248
261
 
249
- _glMatrix.vec3.transformMat4(p1, p1, localTransform);
262
+ if (applyLocalTransform) {
263
+ _glMatrix.vec3.transformMat4(p1, p1, transform);
250
264
 
251
- _glMatrix.vec3.transformMat4(p2, p2, localTransform);
265
+ _glMatrix.vec3.transformMat4(p2, p2, transform);
252
266
 
253
- _glMatrix.vec3.transformMat4(p3, p3, localTransform);
267
+ _glMatrix.vec3.transformMat4(p3, p3, transform);
268
+ }
254
269
 
255
270
  path = "".concat(cur[0]).concat(p1[0], ",").concat(p1[1], ",").concat(p2[0], ",").concat(p2[1], ",").concat(p3[0], ",").concat(p3[1]);
256
271
  } else if (cur[0] === 'A') {
257
272
  var c = _glMatrix.vec3.fromValues(cur[6] - defX, cur[7] - defY, 0);
258
273
 
259
- _glMatrix.vec3.transformMat4(c, c, localTransform);
274
+ if (applyLocalTransform) {
275
+ _glMatrix.vec3.transformMat4(c, c, transform);
276
+ }
260
277
 
261
278
  path = "".concat(cur[0]).concat(cur[1], ",").concat(cur[2], ",").concat(cur[3], ",").concat(cur[4], ",").concat(cur[5], ",").concat(c[0], ",").concat(c[1]);
262
279
  }
@@ -280,16 +297,30 @@ function ellipseToCommands(rx, ry, cx, cy) {
280
297
  return [['M', left, cy], ['C', left, cy - dy, cx - dx, top, cx, top], ['C', cx + dx, top, right, cy - dy, right, cy], ['C', right, cy + dy, cx + dx, bottom, cx, bottom], ['C', cx - dx, bottom, left, cy + dy, left, cy], ['Z']];
281
298
  }
282
299
 
283
- function polygonToCommands(points) {
284
- return points.map(function (point, i) {
300
+ function polygonToCommands(points, closed) {
301
+ var result = points.map(function (point, i) {
285
302
  return [i === 0 ? 'M' : 'L', point[0], point[1]];
286
303
  });
304
+
305
+ if (closed) {
306
+ result.push(['Z']);
307
+ }
308
+
309
+ return result;
287
310
  }
288
311
 
289
312
  function rectToCommands(width, height, x, y, radius) {
290
313
  // @see https://gist.github.com/danielpquinn/dd966af424030d47e476
291
314
  if (radius) {
292
- return [['M', x, radius + y], ['A', radius, radius, 0, 0, 1, radius + x, y], ['L', width - radius + x, y], ['A', radius, radius, 0, 0, 1, width + x, radius + y], ['L', width + x, height - radius + y], ['A', radius, radius, 0, 0, 1, width - radius + x, height + y], ['L', radius + x, height + y], ['A', radius, radius, 0, 0, 1, x, height - radius + y], ['Z']];
315
+ var _a = (0, _tslib.__read)(radius, 4),
316
+ tlr = _a[0],
317
+ trr = _a[1],
318
+ brr = _a[2],
319
+ blr = _a[3];
320
+
321
+ return [['M', x, tlr + y], tlr ? ['A', tlr, tlr, 0, 0, 1, tlr + x, y] : null, ['L', width - trr + x, y], trr ? ['A', trr, trr, 0, 0, 1, width + x, trr + y] : null, ['L', width + x, height - brr + y], brr ? ['A', brr, brr, 0, 0, 1, width - brr + x, height + y] : null, ['L', blr + x, height + y], blr ? ['A', blr, blr, 0, 0, 1, x, height - blr + y] : null, ['Z']].filter(function (command) {
322
+ return command;
323
+ });
293
324
  }
294
325
 
295
326
  return [['M', x, y], ['L', x + width, y], ['L', x + width, y + height], ['L', x, y + height], ['Z']];
@@ -302,9 +333,11 @@ function rectToCommands(width, height, x, y, radius) {
302
333
  */
303
334
 
304
335
 
305
- function convertToPath(object) {
306
- var localTransform = object.getLocalTransform();
307
- var anchor = object.style.anchor;
336
+ function convertToPath(object, applyLocalTransform) {
337
+ if (applyLocalTransform === void 0) {
338
+ applyLocalTransform = true;
339
+ }
340
+
308
341
  var commands = [];
309
342
 
310
343
  switch (object.nodeName) {
@@ -321,9 +354,9 @@ function convertToPath(object) {
321
354
  {
322
355
  var _b = object.parsedStyle,
323
356
  r = _b.r,
324
- x_1 = _b.x,
325
- y_1 = _b.y;
326
- commands = ellipseToCommands(r.value, r.value, x_1.value, y_1.value);
357
+ cx = _b.cx,
358
+ cy = _b.cy;
359
+ commands = ellipseToCommands(r.value, r.value, cx.value, cy.value);
327
360
  break;
328
361
  }
329
362
 
@@ -332,16 +365,16 @@ function convertToPath(object) {
332
365
  var _c = object.parsedStyle,
333
366
  rx = _c.rx,
334
367
  ry = _c.ry,
335
- x_2 = _c.x,
336
- y_2 = _c.y;
337
- commands = ellipseToCommands(rx.value, ry.value, x_2.value, y_2.value);
368
+ cx = _c.cx,
369
+ cy = _c.cy;
370
+ commands = ellipseToCommands(rx.value, ry.value, cx.value, cy.value);
338
371
  break;
339
372
  }
340
373
 
341
374
  case _types.Shape.POLYLINE:
342
375
  case _types.Shape.POLYGON:
343
376
  var points = object.parsedStyle.points;
344
- commands = polygonToCommands(points.points);
377
+ commands = polygonToCommands(points.points, object.nodeName === _types.Shape.POLYGON);
345
378
  break;
346
379
 
347
380
  case _types.Shape.RECT:
@@ -351,15 +384,26 @@ function convertToPath(object) {
351
384
  x = _d.x,
352
385
  y = _d.y,
353
386
  radius = _d.radius;
354
- commands = rectToCommands(width.value, height.value, x.value, y.value, (radius === null || radius === void 0 ? void 0 : radius.value) || 0);
387
+ var hasRadius = radius && radius.some(function (r) {
388
+ return r.value !== 0;
389
+ });
390
+ commands = rectToCommands(width.value, height.value, x.value, y.value, hasRadius && radius.map(function (r) {
391
+ return r.value;
392
+ }));
355
393
  break;
356
394
 
357
395
  case _types.Shape.PATH:
358
- commands = object.parsedStyle.path.curve;
396
+ var _e = object.parsedStyle.path,
397
+ curve = _e.curve,
398
+ zCommandIndexes = _e.zCommandIndexes;
399
+ commands = (0, _tslib.__spreadArray)([], (0, _tslib.__read)(curve), false);
400
+ zCommandIndexes.forEach(function (zIndex, index) {
401
+ commands.splice(zIndex + index, 1, ['Z']);
402
+ });
359
403
  break;
360
404
  }
361
405
 
362
406
  if (commands.length) {
363
- return commandsToPathString(commands, localTransform, anchor, object.parsedStyle);
407
+ return commandsToPathString(commands, object, applyLocalTransform);
364
408
  }
365
409
  }