@antv/g 5.0.15 → 5.0.18

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 (236) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +7 -1
  3. package/es/Canvas.js +9 -10
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +4 -2
  7. package/es/components/Transform.d.ts +0 -1
  8. package/es/components/Transform.js +0 -1
  9. package/es/display-objects/Circle.d.ts +1 -1
  10. package/es/display-objects/Circle.js +8 -3
  11. package/es/display-objects/CustomElement.d.ts +3 -2
  12. package/es/display-objects/CustomElement.js +9 -6
  13. package/es/display-objects/DisplayObject.d.ts +9 -3
  14. package/es/display-objects/DisplayObject.js +97 -50
  15. package/es/display-objects/Ellipse.d.ts +1 -1
  16. package/es/display-objects/Ellipse.js +8 -3
  17. package/es/display-objects/Group.d.ts +18 -2
  18. package/es/display-objects/Group.js +11 -9
  19. package/es/display-objects/HTML.d.ts +1 -1
  20. package/es/display-objects/HTML.js +9 -4
  21. package/es/display-objects/Image.d.ts +5 -3
  22. package/es/display-objects/Image.js +8 -3
  23. package/es/display-objects/Line.d.ts +1 -1
  24. package/es/display-objects/Line.js +12 -4
  25. package/es/display-objects/Path.d.ts +3 -2
  26. package/es/display-objects/Path.js +10 -5
  27. package/es/display-objects/Polygon.d.ts +1 -1
  28. package/es/display-objects/Polygon.js +9 -3
  29. package/es/display-objects/Polyline.d.ts +1 -1
  30. package/es/display-objects/Polyline.js +10 -5
  31. package/es/display-objects/Rect.d.ts +1 -1
  32. package/es/display-objects/Rect.js +8 -3
  33. package/es/display-objects/Text.d.ts +32 -4
  34. package/es/display-objects/Text.js +70 -10
  35. package/es/dom/Animation.js +2 -2
  36. package/es/dom/AnimationTimeline.js +1 -2
  37. package/es/dom/CustomElementRegistry.js +12 -12
  38. package/es/dom/Document.d.ts +2 -1
  39. package/es/dom/Document.js +22 -2
  40. package/es/dom/Element.d.ts +38 -5
  41. package/es/dom/Element.js +115 -16
  42. package/es/dom/EventTarget.d.ts +2 -2
  43. package/es/dom/EventTarget.js +4 -3
  44. package/es/dom/FederatedEvent.d.ts +4 -1
  45. package/es/dom/KeyframeList.js +1 -1
  46. package/es/dom/MutationEvent.d.ts +15 -0
  47. package/es/dom/MutationEvent.js +29 -0
  48. package/es/dom/MutationObserver.d.ts +36 -0
  49. package/es/dom/MutationObserver.js +413 -0
  50. package/es/dom/MutationRecord.d.ts +14 -0
  51. package/es/dom/MutationRecord.js +31 -0
  52. package/es/dom/Node.d.ts +35 -3
  53. package/es/dom/Node.js +184 -17
  54. package/es/dom/index.d.ts +3 -0
  55. package/es/dom/index.js +3 -0
  56. package/es/dom/interfaces.d.ts +39 -8
  57. package/es/dom/interfaces.js +23 -5
  58. package/es/global-module.d.ts +1 -0
  59. package/es/global-module.js +11 -13
  60. package/es/index.d.ts +1 -0
  61. package/es/index.js +1 -0
  62. package/es/plugins/CullingPlugin.d.ts +0 -2
  63. package/es/plugins/CullingPlugin.js +3 -24
  64. package/es/plugins/DirtyCheckPlugin.js +2 -2
  65. package/es/plugins/EventPlugin.d.ts +1 -0
  66. package/es/plugins/EventPlugin.js +15 -5
  67. package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
  68. package/es/plugins/FrustumCullingStrategy.js +41 -33
  69. package/es/plugins/PrepareRendererPlugin.js +21 -5
  70. package/es/property-handlers/aabb.js +19 -20
  71. package/es/property-handlers/color.js +5 -2
  72. package/es/property-handlers/dimension.d.ts +15 -3
  73. package/es/property-handlers/dimension.js +50 -9
  74. package/es/property-handlers/index.d.ts +3 -0
  75. package/es/property-handlers/index.js +4 -1
  76. package/es/property-handlers/inherit.d.ts +6 -0
  77. package/es/property-handlers/inherit.js +25 -0
  78. package/es/property-handlers/interfaces.d.ts +2 -2
  79. package/es/property-handlers/lineDash.d.ts +6 -1
  80. package/es/property-handlers/lineDash.js +23 -4
  81. package/es/property-handlers/offsetDistance.js +2 -2
  82. package/es/property-handlers/text.d.ts +2 -0
  83. package/es/property-handlers/text.js +3 -0
  84. package/es/property-handlers/textTransform.d.ts +6 -0
  85. package/es/property-handlers/textTransform.js +19 -0
  86. package/es/services/EventService.js +11 -7
  87. package/es/services/RenderingContext.d.ts +5 -8
  88. package/es/services/RenderingContext.js +6 -7
  89. package/es/services/RenderingService.d.ts +12 -2
  90. package/es/services/RenderingService.js +23 -12
  91. package/es/services/SceneGraphSelector.d.ts +3 -2
  92. package/es/services/SceneGraphSelector.js +8 -4
  93. package/es/services/SceneGraphService.d.ts +0 -7
  94. package/es/services/SceneGraphService.js +17 -87
  95. package/es/services/aabb/CircleUpdater.js +3 -3
  96. package/es/services/aabb/EllipseUpdater.js +2 -2
  97. package/es/services/aabb/LineUpdater.js +2 -2
  98. package/es/services/aabb/PathUpdater.js +2 -2
  99. package/es/services/aabb/PolylineUpdater.js +3 -3
  100. package/es/services/aabb/RectUpdater.js +4 -4
  101. package/es/services/aabb/TextUpdater.js +31 -10
  102. package/es/services/text/index.js +19 -21
  103. package/es/shapes/AABB.js +5 -0
  104. package/es/types.d.ts +48 -24
  105. package/es/types.js +50 -31
  106. package/es/utils/animation.js +1 -1
  107. package/es/utils/custom-easing.js +1 -1
  108. package/es/utils/event.js +7 -4
  109. package/es/utils/index.d.ts +2 -0
  110. package/es/utils/index.js +3 -1
  111. package/es/utils/interpolation.d.ts +1 -0
  112. package/es/utils/interpolation.js +41 -8
  113. package/es/utils/path.js +11 -11
  114. package/es/utils/raf.d.ts +1 -1
  115. package/es/utils/raf.js +0 -2
  116. package/es/utils/string.d.ts +1 -0
  117. package/es/utils/string.js +9 -0
  118. package/es/utils/text.js +3 -3
  119. package/lib/Canvas.d.ts +7 -1
  120. package/lib/Canvas.js +7 -8
  121. package/lib/camera/Camera.d.ts +3 -2
  122. package/lib/camera/Camera.js +20 -10
  123. package/lib/canvas-module.js +3 -1
  124. package/lib/components/Transform.d.ts +0 -1
  125. package/lib/components/Transform.js +0 -1
  126. package/lib/display-objects/Circle.d.ts +1 -1
  127. package/lib/display-objects/Circle.js +7 -2
  128. package/lib/display-objects/CustomElement.d.ts +3 -2
  129. package/lib/display-objects/CustomElement.js +9 -6
  130. package/lib/display-objects/DisplayObject.d.ts +9 -3
  131. package/lib/display-objects/DisplayObject.js +97 -47
  132. package/lib/display-objects/Ellipse.d.ts +1 -1
  133. package/lib/display-objects/Ellipse.js +7 -2
  134. package/lib/display-objects/Group.d.ts +18 -2
  135. package/lib/display-objects/Group.js +10 -9
  136. package/lib/display-objects/HTML.d.ts +1 -1
  137. package/lib/display-objects/HTML.js +8 -4
  138. package/lib/display-objects/Image.d.ts +5 -3
  139. package/lib/display-objects/Image.js +7 -2
  140. package/lib/display-objects/Line.d.ts +1 -1
  141. package/lib/display-objects/Line.js +11 -3
  142. package/lib/display-objects/Path.d.ts +3 -2
  143. package/lib/display-objects/Path.js +9 -4
  144. package/lib/display-objects/Polygon.d.ts +1 -1
  145. package/lib/display-objects/Polygon.js +8 -2
  146. package/lib/display-objects/Polyline.d.ts +1 -1
  147. package/lib/display-objects/Polyline.js +9 -4
  148. package/lib/display-objects/Rect.d.ts +1 -1
  149. package/lib/display-objects/Rect.js +7 -2
  150. package/lib/display-objects/Text.d.ts +32 -4
  151. package/lib/display-objects/Text.js +69 -9
  152. package/lib/dom/Animation.js +2 -2
  153. package/lib/dom/AnimationTimeline.js +1 -2
  154. package/lib/dom/CustomElementRegistry.js +11 -11
  155. package/lib/dom/Document.d.ts +2 -1
  156. package/lib/dom/Document.js +24 -3
  157. package/lib/dom/Element.d.ts +38 -5
  158. package/lib/dom/Element.js +117 -16
  159. package/lib/dom/EventTarget.d.ts +2 -2
  160. package/lib/dom/EventTarget.js +4 -3
  161. package/lib/dom/FederatedEvent.d.ts +4 -1
  162. package/lib/dom/KeyframeList.js +1 -1
  163. package/lib/dom/MutationEvent.d.ts +15 -0
  164. package/lib/dom/MutationEvent.js +37 -0
  165. package/lib/dom/MutationObserver.d.ts +36 -0
  166. package/lib/dom/MutationObserver.js +424 -0
  167. package/lib/dom/MutationRecord.d.ts +14 -0
  168. package/lib/dom/MutationRecord.js +38 -0
  169. package/lib/dom/Node.d.ts +35 -3
  170. package/lib/dom/Node.js +185 -16
  171. package/lib/dom/index.d.ts +3 -0
  172. package/lib/dom/index.js +39 -0
  173. package/lib/dom/interfaces.d.ts +39 -8
  174. package/lib/dom/interfaces.js +23 -5
  175. package/lib/global-module.d.ts +1 -0
  176. package/lib/global-module.js +12 -8
  177. package/lib/index.d.ts +1 -0
  178. package/lib/index.js +3 -1
  179. package/lib/plugins/CullingPlugin.d.ts +0 -2
  180. package/lib/plugins/CullingPlugin.js +2 -23
  181. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  182. package/lib/plugins/EventPlugin.d.ts +1 -0
  183. package/lib/plugins/EventPlugin.js +13 -5
  184. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  185. package/lib/plugins/FrustumCullingStrategy.js +42 -33
  186. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  187. package/lib/property-handlers/aabb.js +18 -19
  188. package/lib/property-handlers/color.js +6 -3
  189. package/lib/property-handlers/dimension.d.ts +15 -3
  190. package/lib/property-handlers/dimension.js +50 -8
  191. package/lib/property-handlers/index.d.ts +3 -0
  192. package/lib/property-handlers/index.js +39 -0
  193. package/lib/property-handlers/inherit.d.ts +6 -0
  194. package/lib/property-handlers/inherit.js +34 -0
  195. package/lib/property-handlers/interfaces.d.ts +2 -2
  196. package/lib/property-handlers/lineDash.d.ts +6 -1
  197. package/lib/property-handlers/lineDash.js +25 -4
  198. package/lib/property-handlers/offsetDistance.js +1 -1
  199. package/lib/property-handlers/text.d.ts +2 -0
  200. package/lib/property-handlers/text.js +10 -0
  201. package/lib/property-handlers/textTransform.d.ts +6 -0
  202. package/lib/property-handlers/textTransform.js +27 -0
  203. package/lib/services/EventService.js +11 -7
  204. package/lib/services/RenderingContext.d.ts +5 -8
  205. package/lib/services/RenderingContext.js +8 -9
  206. package/lib/services/RenderingService.d.ts +12 -2
  207. package/lib/services/RenderingService.js +23 -11
  208. package/lib/services/SceneGraphSelector.d.ts +3 -2
  209. package/lib/services/SceneGraphSelector.js +10 -3
  210. package/lib/services/SceneGraphService.d.ts +0 -7
  211. package/lib/services/SceneGraphService.js +18 -91
  212. package/lib/services/aabb/CircleUpdater.js +2 -2
  213. package/lib/services/aabb/EllipseUpdater.js +1 -1
  214. package/lib/services/aabb/LineUpdater.js +1 -1
  215. package/lib/services/aabb/PathUpdater.js +1 -1
  216. package/lib/services/aabb/PolylineUpdater.js +2 -2
  217. package/lib/services/aabb/RectUpdater.js +3 -3
  218. package/lib/services/aabb/TextUpdater.js +30 -9
  219. package/lib/services/text/index.js +19 -21
  220. package/lib/shapes/AABB.js +5 -0
  221. package/lib/types.d.ts +48 -24
  222. package/lib/types.js +56 -35
  223. package/lib/utils/animation.js +1 -1
  224. package/lib/utils/custom-easing.js +1 -1
  225. package/lib/utils/event.js +7 -4
  226. package/lib/utils/index.d.ts +2 -0
  227. package/lib/utils/index.js +26 -0
  228. package/lib/utils/interpolation.d.ts +1 -0
  229. package/lib/utils/interpolation.js +43 -7
  230. package/lib/utils/path.js +10 -10
  231. package/lib/utils/raf.d.ts +1 -1
  232. package/lib/utils/raf.js +0 -2
  233. package/lib/utils/string.d.ts +1 -0
  234. package/lib/utils/string.js +16 -0
  235. package/lib/utils/text.js +3 -3
  236. package/package.json +5 -3
@@ -3,17 +3,19 @@ import { DisplayObject } from './DisplayObject';
3
3
  import type { DisplayObjectConfig } from '../dom';
4
4
  import type { ParsedElement } from '../property-handlers';
5
5
  export interface ImageStyleProps extends BaseStyleProps {
6
- img: string | HTMLImageElement;
6
+ img?: string | HTMLImageElement;
7
+ src?: string | HTMLImageElement;
7
8
  width?: number | string;
8
9
  height?: number | string;
9
10
  }
10
11
  export interface ParsedImageStyleProps extends ParsedBaseStyleProps {
11
- img: string | HTMLImageElement;
12
+ img?: string | HTMLImageElement;
13
+ src?: string | HTMLImageElement;
12
14
  width?: ParsedElement;
13
15
  height?: ParsedElement;
14
16
  widthInPixels?: number;
15
17
  heightInPixels?: number;
16
18
  }
17
19
  export declare class Image extends DisplayObject<ImageStyleProps, ParsedImageStyleProps> {
18
- constructor({ style, ...rest }: DisplayObjectConfig<ImageStyleProps>);
20
+ constructor({ style, ...rest }?: DisplayObjectConfig<ImageStyleProps>);
19
21
  }
@@ -17,14 +17,19 @@ function (_super) {
17
17
  (0, _tslib.__extends)(Image, _super);
18
18
 
19
19
  function Image(_a) {
20
+ if (_a === void 0) {
21
+ _a = {};
22
+ }
23
+
20
24
  var style = _a.style,
21
25
  rest = (0, _tslib.__rest)(_a, ["style"]);
22
26
  return _super.call(this, (0, _tslib.__assign)({
23
- type: _types.SHAPE.Image,
27
+ type: _types.Shape.IMAGE,
24
28
  style: (0, _tslib.__assign)({
25
29
  img: '',
26
30
  width: 'auto',
27
- height: 'auto'
31
+ height: 'auto',
32
+ lineWidth: 0
28
33
  }, style)
29
34
  }, rest)) || this;
30
35
  }
@@ -23,7 +23,7 @@ export interface ParsedLineStyleProps extends ParsedBaseStyleProps {
23
23
  isBillboard?: boolean;
24
24
  }
25
25
  export declare class Line extends DisplayObject<LineStyleProps, ParsedLineStyleProps> {
26
- constructor({ style, ...rest }: DisplayObjectConfig<LineStyleProps>);
26
+ constructor({ style, ...rest }?: DisplayObjectConfig<LineStyleProps>);
27
27
  getPoint(ratio: number): Point;
28
28
  getTotalLength(): number;
29
29
  }
@@ -21,10 +21,14 @@ function (_super) {
21
21
  (0, _tslib.__extends)(Line, _super);
22
22
 
23
23
  function Line(_a) {
24
+ if (_a === void 0) {
25
+ _a = {};
26
+ }
27
+
24
28
  var style = _a.style,
25
29
  rest = (0, _tslib.__rest)(_a, ["style"]);
26
30
  return _super.call(this, (0, _tslib.__assign)({
27
- type: _types.SHAPE.Line,
31
+ type: _types.Shape.LINE,
28
32
  style: (0, _tslib.__assign)({
29
33
  x1: 0,
30
34
  y1: 0,
@@ -32,8 +36,12 @@ function (_super) {
32
36
  y2: 0,
33
37
  z1: 0,
34
38
  z2: 0,
35
- lineJoin: _types.LINE_JOIN.Miter,
36
- lineCap: _types.LINE_CAP.Butt,
39
+ lineJoin: _types.LineJoin.MITER,
40
+ lineCap: _types.LineCap.BUTT,
41
+
42
+ /**
43
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
44
+ */
37
45
  lineWidth: 1,
38
46
  isBillboard: false
39
47
  }, style)
@@ -4,7 +4,8 @@ import type { DisplayObjectConfig } from '../dom';
4
4
  import { Point } from '../shapes';
5
5
  import type { Rect } from '../shapes/Rect';
6
6
  export interface PathStyleProps extends BaseStyleProps {
7
- path: string | PathCommand[];
7
+ path?: string | PathCommand[];
8
+ d?: string | PathCommand[];
8
9
  }
9
10
  export interface PathSegment {
10
11
  command: PathCommand[0];
@@ -30,7 +31,7 @@ export interface ParsedPathStyleProps {
30
31
  export declare class Path extends DisplayObject<PathStyleProps, {
31
32
  path: ParsedPathStyleProps;
32
33
  }> {
33
- constructor({ style, ...rest }: DisplayObjectConfig<PathStyleProps>);
34
+ constructor({ style, ...rest }?: DisplayObjectConfig<PathStyleProps>);
34
35
  getTotalLength(): number;
35
36
  /**
36
37
  * Get point according to ratio
@@ -23,15 +23,20 @@ function (_super) {
23
23
  (0, _tslib.__extends)(Path, _super);
24
24
 
25
25
  function Path(_a) {
26
+ if (_a === void 0) {
27
+ _a = {};
28
+ }
29
+
26
30
  var style = _a.style,
27
31
  rest = (0, _tslib.__rest)(_a, ["style"]);
28
32
  return _super.call(this, (0, _tslib.__assign)({
29
- type: _types.SHAPE.Path,
33
+ type: _types.Shape.PATH,
30
34
  style: (0, _tslib.__assign)({
31
35
  path: '',
32
- lineJoin: _types.LINE_JOIN.Miter,
33
- lineCap: _types.LINE_CAP.Butt,
34
- lineWidth: 1
36
+ lineJoin: _types.LineJoin.MITER,
37
+ lineCap: _types.LineCap.BUTT,
38
+ lineWidth: 1,
39
+ miterLimit: 4
35
40
  }, style)
36
41
  }, rest)) || this;
37
42
  }
@@ -5,5 +5,5 @@ export interface PolygonStyleProps extends BaseStyleProps {
5
5
  points: [number, number][];
6
6
  }
7
7
  export declare class Polygon extends DisplayObject<PolygonStyleProps, ParsedBaseStyleProps> {
8
- constructor({ style, ...rest }: DisplayObjectConfig<PolygonStyleProps>);
8
+ constructor({ style, ...rest }?: DisplayObjectConfig<PolygonStyleProps>);
9
9
  }
@@ -17,12 +17,18 @@ function (_super) {
17
17
  (0, _tslib.__extends)(Polygon, _super);
18
18
 
19
19
  function Polygon(_a) {
20
+ if (_a === void 0) {
21
+ _a = {};
22
+ }
23
+
20
24
  var style = _a.style,
21
25
  rest = (0, _tslib.__rest)(_a, ["style"]);
22
26
  return _super.call(this, (0, _tslib.__assign)({
23
- type: _types.SHAPE.Polygon,
27
+ type: _types.Shape.POLYGON,
24
28
  style: (0, _tslib.__assign)({
25
- points: []
29
+ points: [],
30
+ miterLimit: 4,
31
+ lineWidth: 1
26
32
  }, style)
27
33
  }, rest)) || this;
28
34
  }
@@ -11,7 +11,7 @@ export interface ParsedPolylineStyleProps {
11
11
  totalLength: number;
12
12
  }
13
13
  export declare class Polyline extends DisplayObject<PolylineStyleProps, ParsedBaseStyleProps> {
14
- constructor({ style, ...rest }: DisplayObjectConfig<PolylineStyleProps>);
14
+ constructor({ style, ...rest }?: DisplayObjectConfig<PolylineStyleProps>);
15
15
  getTotalLength(): number;
16
16
  getPoint(ratio: number): Point;
17
17
  getStartTangent(): number[][];
@@ -21,15 +21,20 @@ function (_super) {
21
21
  (0, _tslib.__extends)(Polyline, _super);
22
22
 
23
23
  function Polyline(_a) {
24
+ if (_a === void 0) {
25
+ _a = {};
26
+ }
27
+
24
28
  var style = _a.style,
25
29
  rest = (0, _tslib.__rest)(_a, ["style"]);
26
30
  return _super.call(this, (0, _tslib.__assign)({
27
- type: _types.SHAPE.Polyline,
31
+ type: _types.Shape.POLYLINE,
28
32
  style: (0, _tslib.__assign)({
29
33
  points: [],
30
- lineJoin: _types.LINE_JOIN.Miter,
31
- lineCap: _types.LINE_CAP.Butt,
32
- lineWidth: 1
34
+ lineJoin: _types.LineJoin.MITER,
35
+ lineCap: _types.LineCap.BUTT,
36
+ lineWidth: 1,
37
+ miterLimit: 4
33
38
  }, style)
34
39
  }, rest)) || this;
35
40
  }
@@ -15,5 +15,5 @@ export interface ParsedRectStyleProps extends ParsedBaseStyleProps {
15
15
  radius?: number;
16
16
  }
17
17
  export declare class Rect extends DisplayObject<RectStyleProps, ParsedRectStyleProps> {
18
- constructor({ style, ...rest }: DisplayObjectConfig<RectStyleProps>);
18
+ constructor({ style, ...rest }?: DisplayObjectConfig<RectStyleProps>);
19
19
  }
@@ -17,13 +17,18 @@ function (_super) {
17
17
  (0, _tslib.__extends)(Rect, _super);
18
18
 
19
19
  function Rect(_a) {
20
+ if (_a === void 0) {
21
+ _a = {};
22
+ }
23
+
20
24
  var style = _a.style,
21
25
  rest = (0, _tslib.__rest)(_a, ["style"]);
22
26
  return _super.call(this, (0, _tslib.__assign)({
23
- type: _types.SHAPE.Rect,
27
+ type: _types.Shape.RECT,
24
28
  style: (0, _tslib.__assign)({
25
29
  width: 'auto',
26
- height: 'auto'
30
+ height: 'auto',
31
+ lineWidth: 0
27
32
  }, style)
28
33
  }, rest)) || this;
29
34
  }
@@ -2,16 +2,17 @@ import type { TextMetrics } from '../services/text';
2
2
  import type { DisplayObjectConfig } from '../dom/interfaces';
3
3
  import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
4
4
  import { DisplayObject } from './DisplayObject';
5
+ import type { ParsedElement } from '../property-handlers';
5
6
  export interface TextStyleProps extends BaseStyleProps {
6
7
  text: string;
7
8
  /** 设置文本内容的当前对齐方式 */
8
- textAlign?: 'start' | 'center' | 'end' | 'left' | 'right';
9
+ textAlign?: 'inherit' | 'start' | 'center' | 'end' | 'left' | 'right';
9
10
  /** 设置在绘制文本时使用的当前文本基线 */
10
11
  textBaseline?: 'top' | 'hanging' | 'middle' | 'alphabetic' | 'ideographic' | 'bottom';
11
12
  /** 字体样式 */
12
13
  fontStyle?: 'normal' | 'italic' | 'oblique';
13
14
  /** 文本字体大小 */
14
- fontSize?: number;
15
+ fontSize?: number | string;
15
16
  /** 文本字体 */
16
17
  fontFamily?: string;
17
18
  /** 文本粗细 */
@@ -28,6 +29,8 @@ export interface TextStyleProps extends BaseStyleProps {
28
29
  wordWrapWidth?: number;
29
30
  dropShadow?: boolean;
30
31
  dropShadowDistance?: number;
32
+ dx?: number | string;
33
+ dy?: number | string;
31
34
  }
32
35
  export interface ParsedTextStyleProps extends ParsedBaseStyleProps {
33
36
  text: string;
@@ -38,7 +41,7 @@ export interface ParsedTextStyleProps extends ParsedBaseStyleProps {
38
41
  /** 字体样式 */
39
42
  fontStyle?: 'normal' | 'italic' | 'oblique';
40
43
  /** 文本字体大小 */
41
- fontSize?: number;
44
+ fontSize?: ParsedElement;
42
45
  /** 文本字体 */
43
46
  fontFamily?: string;
44
47
  /** 文本粗细 */
@@ -56,8 +59,33 @@ export interface ParsedTextStyleProps extends ParsedBaseStyleProps {
56
59
  dropShadow?: boolean;
57
60
  dropShadowDistance?: number;
58
61
  metrics?: TextMetrics;
62
+ dx?: ParsedElement;
63
+ dy?: ParsedElement;
59
64
  }
65
+ /**
66
+ * <text> @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement
67
+ */
60
68
  export declare class Text extends DisplayObject<TextStyleProps, ParsedTextStyleProps> {
61
- constructor({ style, ...rest }: DisplayObjectConfig<TextStyleProps>);
69
+ /**
70
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement#constants
71
+ */
72
+ LENGTHADJUST_SPACING: number;
73
+ LENGTHADJUST_SPACINGANDGLYPHS: number;
74
+ LENGTHADJUST_UNKNOWN: number;
75
+ constructor({ style, ...rest }?: DisplayObjectConfig<TextStyleProps>);
76
+ lengthAdjust: SVGAnimatedEnumeration;
77
+ textLength: SVGAnimatedLength;
78
+ getCharNumAtPosition(point?: DOMPointInit): number;
79
+ /**
80
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
81
+ */
82
+ getComputedTextLength(): number;
83
+ getEndPositionOfChar(charnum: number): DOMPoint;
84
+ getExtentOfChar(charnum: number): DOMRect;
85
+ getNumberOfChars(): number;
86
+ getRotationOfChar(charnum: number): number;
87
+ getStartPositionOfChar(charnum: number): DOMPoint;
88
+ getSubStringLength(charnum: number, nchars: number): number;
89
+ selectSubString(charnum: number, nchars: number): void;
62
90
  getLineBoundingRects(): import("..").Rectangle[];
63
91
  }
@@ -11,24 +11,33 @@ var _types = require("../types");
11
11
 
12
12
  var _DisplayObject = require("./DisplayObject");
13
13
 
14
+ /**
15
+ * <text> @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement
16
+ */
14
17
  var Text =
15
18
  /** @class */
16
19
  function (_super) {
17
20
  (0, _tslib.__extends)(Text, _super);
18
21
 
19
22
  function Text(_a) {
23
+ if (_a === void 0) {
24
+ _a = {};
25
+ }
26
+
27
+ var _this = this;
28
+
20
29
  var style = _a.style,
21
30
  rest = (0, _tslib.__rest)(_a, ["style"]);
22
- return _super.call(this, (0, _tslib.__assign)({
23
- type: _types.SHAPE.Text,
31
+ _this = _super.call(this, (0, _tslib.__assign)({
32
+ type: _types.Shape.TEXT,
24
33
  style: (0, _tslib.__assign)({
25
34
  text: '',
26
- fontSize: 12,
27
- fontFamily: 'sans-serif',
35
+ fontSize: 'inherit',
36
+ fontFamily: 'inherit',
28
37
  fontStyle: 'normal',
29
38
  fontWeight: 'normal',
30
39
  fontVariant: 'normal',
31
- textAlign: 'start',
40
+ textAlign: 'inherit',
32
41
  textBaseline: 'alphabetic',
33
42
  dropShadow: false,
34
43
  // dropShadowAlpha: 1,
@@ -39,20 +48,71 @@ function (_super) {
39
48
  fill: '#000',
40
49
  letterSpacing: 0,
41
50
  lineHeight: 0,
42
- lineJoin: _types.LINE_JOIN.Miter,
43
- lineCap: _types.LINE_CAP.Butt,
51
+ lineJoin: _types.LineJoin.MITER,
52
+ lineCap: _types.LineCap.BUTT,
44
53
  lineWidth: 0,
45
54
  miterLimit: 10,
46
- // padding: 0,
47
55
  stroke: '#000',
48
56
  whiteSpace: 'pre',
49
57
  wordWrap: false,
50
58
  wordWrapWidth: 0,
51
- leading: 0
59
+ leading: 0,
60
+ dx: 0,
61
+ dy: 0
52
62
  }, style)
53
63
  }, rest)) || this;
64
+ /**
65
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement#constants
66
+ */
67
+
68
+ _this.LENGTHADJUST_SPACING = 1;
69
+ _this.LENGTHADJUST_SPACINGANDGLYPHS = 2;
70
+ _this.LENGTHADJUST_UNKNOWN = 0;
71
+ return _this;
54
72
  }
55
73
 
74
+ Text.prototype.getCharNumAtPosition = function (point) {
75
+ throw new Error('Method not implemented.');
76
+ };
77
+ /**
78
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement
79
+ */
80
+
81
+
82
+ Text.prototype.getComputedTextLength = function () {
83
+ var _a;
84
+
85
+ return ((_a = this.parsedStyle.metrics) === null || _a === void 0 ? void 0 : _a.maxLineWidth) || 0;
86
+ };
87
+
88
+ Text.prototype.getEndPositionOfChar = function (charnum) {
89
+ throw new Error('Method not implemented.');
90
+ };
91
+
92
+ Text.prototype.getExtentOfChar = function (charnum) {
93
+ throw new Error('Method not implemented.');
94
+ };
95
+
96
+ Text.prototype.getNumberOfChars = function () {
97
+ throw new Error('Method not implemented.');
98
+ };
99
+
100
+ Text.prototype.getRotationOfChar = function (charnum) {
101
+ throw new Error('Method not implemented.');
102
+ };
103
+
104
+ Text.prototype.getStartPositionOfChar = function (charnum) {
105
+ throw new Error('Method not implemented.');
106
+ };
107
+
108
+ Text.prototype.getSubStringLength = function (charnum, nchars) {
109
+ throw new Error('Method not implemented.');
110
+ };
111
+
112
+ Text.prototype.selectSubString = function (charnum, nchars) {
113
+ throw new Error('Method not implemented.');
114
+ };
115
+
56
116
  Text.prototype.getLineBoundingRects = function () {
57
117
  var _a;
58
118
 
@@ -31,7 +31,7 @@ function () {
31
31
  this.effect = effect;
32
32
  effect.animation = this;
33
33
  this.timeline = timeline;
34
- this.id = "" + sequenceNumber++;
34
+ this.id = "".concat(sequenceNumber++);
35
35
  this._inEffect = !!this.effect.update(0);
36
36
  this._holdTime = 0;
37
37
  this._paused = false;
@@ -240,7 +240,7 @@ function () {
240
240
  get: function get() {
241
241
  var _a;
242
242
 
243
- return Number((_a = this.effect) === null || _a === void 0 ? void 0 : _a.getComputedTiming().activeDuration);
243
+ return Number((_a = this.effect) === null || _a === void 0 ? void 0 : _a.getComputedTiming().endTime);
244
244
  },
245
245
  enumerable: false,
246
246
  configurable: true
@@ -165,8 +165,7 @@ function () {
165
165
 
166
166
  this.rafCallbacks.push([id, f]);
167
167
  return id;
168
- }; // eslint-disable-next-line @typescript-eslint/ban-types
169
-
168
+ };
170
169
 
171
170
  AnimationTimeline.prototype.requestAnimationFrame = function (f) {
172
171
  var _this = this;
@@ -19,17 +19,17 @@ var CustomElementRegistry =
19
19
  function () {
20
20
  function CustomElementRegistry() {
21
21
  this.registry = {};
22
- this.define(_types.SHAPE.Circle, _displayObjects.Circle);
23
- this.define(_types.SHAPE.Ellipse, _displayObjects.Ellipse);
24
- this.define(_types.SHAPE.Rect, _displayObjects.Rect);
25
- this.define(_types.SHAPE.Image, _displayObjects.Image);
26
- this.define(_types.SHAPE.Line, _displayObjects.Line);
27
- this.define(_types.SHAPE.Group, _displayObjects.Group);
28
- this.define(_types.SHAPE.Path, _displayObjects.Path);
29
- this.define(_types.SHAPE.Polygon, _displayObjects.Polygon);
30
- this.define(_types.SHAPE.Polyline, _displayObjects.Polyline);
31
- this.define(_types.SHAPE.Text, _displayObjects.Text);
32
- this.define(_types.SHAPE.HTML, _displayObjects.HTML);
22
+ this.define(_types.Shape.CIRCLE, _displayObjects.Circle);
23
+ this.define(_types.Shape.ELLIPSE, _displayObjects.Ellipse);
24
+ this.define(_types.Shape.RECT, _displayObjects.Rect);
25
+ this.define(_types.Shape.IMAGE, _displayObjects.Image);
26
+ this.define(_types.Shape.LINE, _displayObjects.Line);
27
+ this.define(_types.Shape.GROUP, _displayObjects.Group);
28
+ this.define(_types.Shape.PATH, _displayObjects.Path);
29
+ this.define(_types.Shape.POLYGON, _displayObjects.Polygon);
30
+ this.define(_types.Shape.POLYLINE, _displayObjects.Polyline);
31
+ this.define(_types.Shape.TEXT, _displayObjects.Text);
32
+ this.define(_types.Shape.HTML, _displayObjects.HTML);
33
33
  }
34
34
 
35
35
  CustomElementRegistry.prototype.define = function (name, constructor) {
@@ -1,6 +1,6 @@
1
1
  import { Node } from './Node';
2
2
  import { AnimationTimeline } from './AnimationTimeline';
3
- import { Group } from '../display-objects/Group';
3
+ import { Group } from '../display-objects';
4
4
  import type { DisplayObject } from '../display-objects/DisplayObject';
5
5
  import type { IDocument, IElement, INode, ICanvas, DisplayObjectConfig } from './interfaces';
6
6
  import type { BaseStyleProps } from '../types';
@@ -34,6 +34,7 @@ export declare class Document extends Node implements IDocument {
34
34
  * @example const circle = document.createElement('circle', { style: { r: 10 } });
35
35
  */
36
36
  createElement<T extends DisplayObject<StyleProps>, StyleProps extends BaseStyleProps>(tagName: string, options: DisplayObjectConfig<StyleProps>): T;
37
+ createElementNS<T extends DisplayObject<StyleProps>, StyleProps extends BaseStyleProps>(namespaceURI: string, tagName: string, options: DisplayObjectConfig<StyleProps>): T;
37
38
  cloneNode(deep?: boolean): this;
38
39
  destroy(): void;
39
40
  /**
@@ -11,7 +11,9 @@ var _Node = require("./Node");
11
11
 
12
12
  var _AnimationTimeline = require("./AnimationTimeline");
13
13
 
14
- var _Group = require("../display-objects/Group");
14
+ var _displayObjects = require("../display-objects");
15
+
16
+ var _types = require("../types");
15
17
 
16
18
  /**
17
19
  * the entry of DOM tree
@@ -37,8 +39,16 @@ function (_super) {
37
39
 
38
40
  _this.timeline = new _AnimationTimeline.AnimationTimeline(); // like <html> in DOM tree
39
41
 
40
- _this.documentElement = new _Group.Group({
41
- id: 'g-root'
42
+ _this.documentElement = new _displayObjects.Group({
43
+ id: 'g-root',
44
+ style: {
45
+ textAlign: _types.TextAlign.START,
46
+ fontSize: '16px',
47
+ fontFamily: 'sans-serif' // fontStyle: 'normal',
48
+ // fontWeight: 'normal',
49
+ // fontVariant: 'normal',
50
+
51
+ }
42
52
  });
43
53
  _this.documentElement.ownerDocument = _this;
44
54
  _this.documentElement.parentNode = _this;
@@ -79,8 +89,19 @@ function (_super) {
79
89
  */
80
90
 
81
91
  Document.prototype.createElement = function (tagName, options) {
92
+ // d3 will use <tspan>
82
93
  var clazz = this.defaultView.customElements.get(tagName);
94
+
95
+ if (!clazz) {
96
+ console.warn('Unsupported tagName: ', tagName);
97
+ clazz = tagName === 'tspan' ? _displayObjects.Text : _displayObjects.Group;
98
+ }
99
+
83
100
  return new clazz(options);
101
+ };
102
+
103
+ Document.prototype.createElementNS = function (namespaceURI, tagName, options) {
104
+ return this.createElement(tagName, options);
84
105
  }; // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
106
 
86
107
 
@@ -3,7 +3,7 @@ import { Cullable, Geometry, Renderable, Transform, Sortable } from '../componen
3
3
  import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
4
4
  import { Node } from './Node';
5
5
  import type { AABB, Rectangle } from '../shapes';
6
- import type { IEventTarget, IElement, INode } from './interfaces';
6
+ import type { IEventTarget, IElement, INode, ICSSStyleDeclaration } from './interfaces';
7
7
  /**
8
8
  * Has following capabilities:
9
9
  * * Node insert/remove, eg. appendChild, removeChild, remove...
@@ -28,12 +28,17 @@ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyl
28
28
  * used in `getElementsByClassName`
29
29
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
30
30
  */
31
- className: string;
31
+ get className(): string;
32
+ set className(className: string);
32
33
  /**
33
34
  * used in `getElementsByName`
34
35
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName
35
36
  */
36
37
  name: string;
38
+ /**
39
+ * https://developer.mozilla.org/zh-CN/docs/Web/API/Element/namespaceURI
40
+ */
41
+ namespaceURI: string;
37
42
  /**
38
43
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
39
44
  */
@@ -41,6 +46,12 @@ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyl
41
46
  interactive: boolean;
42
47
  scrollLeft: number;
43
48
  scrollTop: number;
49
+ /**
50
+ * We don't support border now
51
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop
52
+ */
53
+ clientTop: number;
54
+ clientLeft: number;
44
55
  get tagName(): string;
45
56
  get children(): IElement[];
46
57
  get childElementCount(): number;
@@ -127,16 +138,28 @@ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyl
127
138
  * compatible with `style`
128
139
  * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
129
140
  */
130
- style: StyleProps;
141
+ style: StyleProps & ICSSStyleDeclaration<StyleProps>;
131
142
  parsedStyle: ParsedStyleProps;
132
143
  /**
133
144
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes
134
145
  */
135
- attributes: StyleProps;
146
+ readonly attributes: StyleProps;
147
+ /**
148
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames
149
+ */
150
+ getAttributeNames(): string[];
136
151
  /**
137
152
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
138
153
  */
139
- getAttribute(attributeName: keyof StyleProps): StyleProps[keyof StyleProps];
154
+ getAttribute(name: keyof StyleProps): any;
155
+ /**
156
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
157
+ */
158
+ hasAttribute(qualifiedName: string): boolean;
159
+ /**
160
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributes
161
+ */
162
+ hasAttributes(): boolean;
140
163
  /**
141
164
  * should use removeAttribute() instead of setting the attribute value to null either directly or using setAttribute(). Many attributes will not behave as expected if you set them to null.
142
165
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute
@@ -146,4 +169,14 @@ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyl
146
169
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
147
170
  */
148
171
  setAttribute<Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean): void;
172
+ getAttributeNS(namespace: string, localName: string): string;
173
+ getAttributeNode(qualifiedName: string): Attr;
174
+ getAttributeNodeNS(namespace: string, localName: string): Attr;
175
+ hasAttributeNS(namespace: string, localName: string): boolean;
176
+ removeAttributeNS(namespace: string, localName: string): void;
177
+ removeAttributeNode(attr: Attr): Attr;
178
+ setAttributeNS(namespace: string, qualifiedName: string, value: string): void;
179
+ setAttributeNode(attr: Attr): Attr;
180
+ setAttributeNodeNS(attr: Attr): Attr;
181
+ toggleAttribute(qualifiedName: string, force?: boolean): boolean;
149
182
  }