@antv/g 5.0.13 → 5.0.16

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 (244) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +3 -0
  3. package/es/Canvas.js +9 -9
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +11 -17
  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 +4 -2
  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 +4 -3
  14. package/es/display-objects/DisplayObject.js +80 -49
  15. package/es/display-objects/Ellipse.d.ts +6 -3
  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 +14 -9
  19. package/es/display-objects/HTML.d.ts +6 -1
  20. package/es/display-objects/HTML.js +10 -5
  21. package/es/display-objects/Image.d.ts +12 -7
  22. package/es/display-objects/Image.js +10 -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 +8 -5
  32. package/es/display-objects/Rect.js +9 -4
  33. package/es/display-objects/Text.d.ts +9 -6
  34. package/es/display-objects/Text.js +15 -10
  35. package/es/dom/Animation.js +1 -1
  36. package/es/dom/AnimationTimeline.js +1 -2
  37. package/es/dom/CustomElementRegistry.js +12 -12
  38. package/es/dom/Document.d.ts +1 -0
  39. package/es/dom/Document.js +21 -1
  40. package/es/dom/Element.d.ts +14 -9
  41. package/es/dom/Element.js +41 -14
  42. package/es/dom/EventTarget.d.ts +2 -2
  43. package/es/dom/EventTarget.js +4 -3
  44. package/es/dom/KeyframeList.js +1 -1
  45. package/es/dom/MutationEvent.d.ts +15 -0
  46. package/es/dom/MutationEvent.js +29 -0
  47. package/es/dom/MutationObserver.d.ts +36 -0
  48. package/es/dom/MutationObserver.js +413 -0
  49. package/es/dom/MutationRecord.d.ts +14 -0
  50. package/es/dom/MutationRecord.js +31 -0
  51. package/es/dom/Node.d.ts +35 -3
  52. package/es/dom/Node.js +184 -17
  53. package/es/dom/index.d.ts +3 -0
  54. package/es/dom/index.js +3 -0
  55. package/es/dom/interfaces.d.ts +36 -8
  56. package/es/dom/interfaces.js +23 -5
  57. package/es/global-module.d.ts +4 -1
  58. package/es/global-module.js +38 -80
  59. package/es/index.d.ts +1 -0
  60. package/es/index.js +1 -0
  61. package/es/plugins/CullingPlugin.d.ts +0 -2
  62. package/es/plugins/CullingPlugin.js +3 -24
  63. package/es/plugins/DirtyCheckPlugin.js +2 -2
  64. package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
  65. package/es/plugins/FrustumCullingStrategy.js +40 -33
  66. package/es/plugins/PrepareRendererPlugin.js +21 -5
  67. package/es/property-handlers/aabb.js +22 -24
  68. package/es/property-handlers/anchor.js +2 -1
  69. package/es/property-handlers/color.js +5 -2
  70. package/es/property-handlers/dimension.d.ts +15 -2
  71. package/es/property-handlers/dimension.js +77 -8
  72. package/es/property-handlers/index.d.ts +3 -0
  73. package/es/property-handlers/index.js +4 -1
  74. package/es/property-handlers/inherit.d.ts +6 -0
  75. package/es/property-handlers/inherit.js +25 -0
  76. package/es/property-handlers/interfaces.d.ts +2 -2
  77. package/es/property-handlers/lineDash.d.ts +6 -1
  78. package/es/property-handlers/lineDash.js +23 -4
  79. package/es/property-handlers/offsetDistance.js +2 -2
  80. package/es/property-handlers/path.d.ts +1 -1
  81. package/es/property-handlers/text.d.ts +2 -0
  82. package/es/property-handlers/text.js +3 -0
  83. package/es/property-handlers/textTransform.d.ts +6 -0
  84. package/es/property-handlers/textTransform.js +19 -0
  85. package/es/services/EventService.js +3 -5
  86. package/es/services/RenderingContext.d.ts +5 -8
  87. package/es/services/RenderingContext.js +6 -7
  88. package/es/services/RenderingService.js +2 -8
  89. package/es/services/SceneGraphSelector.d.ts +3 -2
  90. package/es/services/SceneGraphSelector.js +8 -4
  91. package/es/services/SceneGraphService.d.ts +7 -14
  92. package/es/services/SceneGraphService.js +14 -82
  93. package/es/services/aabb/CircleUpdater.d.ts +2 -2
  94. package/es/services/aabb/CircleUpdater.js +21 -11
  95. package/es/services/aabb/EllipseUpdater.d.ts +2 -2
  96. package/es/services/aabb/EllipseUpdater.js +28 -13
  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.d.ts +2 -2
  101. package/es/services/aabb/RectUpdater.js +33 -17
  102. package/es/services/aabb/TextUpdater.js +19 -10
  103. package/es/services/aabb/interfaces.d.ts +1 -1
  104. package/es/services/aabb/interfaces.js +1 -1
  105. package/es/services/text/index.js +19 -21
  106. package/es/shapes/AABB.d.ts +1 -0
  107. package/es/shapes/AABB.js +8 -0
  108. package/es/types.d.ts +48 -27
  109. package/es/types.js +50 -31
  110. package/es/utils/custom-easing.js +1 -1
  111. package/es/utils/event.js +5 -3
  112. package/es/utils/index.d.ts +1 -0
  113. package/es/utils/index.js +2 -1
  114. package/es/utils/interpolation.d.ts +1 -0
  115. package/es/utils/interpolation.js +41 -8
  116. package/es/utils/path.d.ts +1 -1
  117. package/es/utils/path.js +16 -16
  118. package/es/utils/raf.d.ts +1 -1
  119. package/es/utils/raf.js +0 -2
  120. package/es/utils/string.d.ts +1 -0
  121. package/es/utils/string.js +9 -0
  122. package/es/utils/text.js +3 -3
  123. package/lib/Canvas.d.ts +3 -0
  124. package/lib/Canvas.js +7 -7
  125. package/lib/camera/Camera.d.ts +3 -2
  126. package/lib/camera/Camera.js +20 -10
  127. package/lib/canvas-module.js +10 -15
  128. package/lib/components/Transform.d.ts +0 -1
  129. package/lib/components/Transform.js +0 -1
  130. package/lib/display-objects/Circle.d.ts +4 -2
  131. package/lib/display-objects/Circle.js +7 -2
  132. package/lib/display-objects/CustomElement.d.ts +3 -2
  133. package/lib/display-objects/CustomElement.js +9 -6
  134. package/lib/display-objects/DisplayObject.d.ts +4 -3
  135. package/lib/display-objects/DisplayObject.js +79 -46
  136. package/lib/display-objects/Ellipse.d.ts +6 -3
  137. package/lib/display-objects/Ellipse.js +7 -2
  138. package/lib/display-objects/Group.d.ts +18 -2
  139. package/lib/display-objects/Group.js +13 -9
  140. package/lib/display-objects/HTML.d.ts +6 -1
  141. package/lib/display-objects/HTML.js +9 -5
  142. package/lib/display-objects/Image.d.ts +12 -7
  143. package/lib/display-objects/Image.js +9 -2
  144. package/lib/display-objects/Line.d.ts +1 -1
  145. package/lib/display-objects/Line.js +11 -3
  146. package/lib/display-objects/Path.d.ts +3 -2
  147. package/lib/display-objects/Path.js +9 -4
  148. package/lib/display-objects/Polygon.d.ts +1 -1
  149. package/lib/display-objects/Polygon.js +8 -2
  150. package/lib/display-objects/Polyline.d.ts +1 -1
  151. package/lib/display-objects/Polyline.js +9 -4
  152. package/lib/display-objects/Rect.d.ts +8 -5
  153. package/lib/display-objects/Rect.js +8 -3
  154. package/lib/display-objects/Text.d.ts +9 -6
  155. package/lib/display-objects/Text.js +14 -9
  156. package/lib/dom/Animation.js +1 -1
  157. package/lib/dom/AnimationTimeline.js +1 -2
  158. package/lib/dom/CustomElementRegistry.js +11 -11
  159. package/lib/dom/Document.d.ts +1 -0
  160. package/lib/dom/Document.js +22 -1
  161. package/lib/dom/Element.d.ts +14 -9
  162. package/lib/dom/Element.js +43 -14
  163. package/lib/dom/EventTarget.d.ts +2 -2
  164. package/lib/dom/EventTarget.js +4 -3
  165. package/lib/dom/KeyframeList.js +1 -1
  166. package/lib/dom/MutationEvent.d.ts +15 -0
  167. package/lib/dom/MutationEvent.js +37 -0
  168. package/lib/dom/MutationObserver.d.ts +36 -0
  169. package/lib/dom/MutationObserver.js +424 -0
  170. package/lib/dom/MutationRecord.d.ts +14 -0
  171. package/lib/dom/MutationRecord.js +38 -0
  172. package/lib/dom/Node.d.ts +35 -3
  173. package/lib/dom/Node.js +185 -16
  174. package/lib/dom/index.d.ts +3 -0
  175. package/lib/dom/index.js +39 -0
  176. package/lib/dom/interfaces.d.ts +36 -8
  177. package/lib/dom/interfaces.js +23 -5
  178. package/lib/global-module.d.ts +4 -1
  179. package/lib/global-module.js +44 -76
  180. package/lib/index.d.ts +1 -0
  181. package/lib/index.js +3 -1
  182. package/lib/plugins/CullingPlugin.d.ts +0 -2
  183. package/lib/plugins/CullingPlugin.js +2 -23
  184. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  185. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  186. package/lib/plugins/FrustumCullingStrategy.js +41 -33
  187. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  188. package/lib/property-handlers/aabb.js +21 -23
  189. package/lib/property-handlers/anchor.js +3 -1
  190. package/lib/property-handlers/color.js +6 -3
  191. package/lib/property-handlers/dimension.d.ts +15 -2
  192. package/lib/property-handlers/dimension.js +80 -7
  193. package/lib/property-handlers/index.d.ts +3 -0
  194. package/lib/property-handlers/index.js +39 -0
  195. package/lib/property-handlers/inherit.d.ts +6 -0
  196. package/lib/property-handlers/inherit.js +34 -0
  197. package/lib/property-handlers/interfaces.d.ts +2 -2
  198. package/lib/property-handlers/lineDash.d.ts +6 -1
  199. package/lib/property-handlers/lineDash.js +25 -4
  200. package/lib/property-handlers/offsetDistance.js +1 -1
  201. package/lib/property-handlers/path.d.ts +1 -1
  202. package/lib/property-handlers/text.d.ts +2 -0
  203. package/lib/property-handlers/text.js +10 -0
  204. package/lib/property-handlers/textTransform.d.ts +6 -0
  205. package/lib/property-handlers/textTransform.js +27 -0
  206. package/lib/services/EventService.js +3 -5
  207. package/lib/services/RenderingContext.d.ts +5 -8
  208. package/lib/services/RenderingContext.js +8 -9
  209. package/lib/services/RenderingService.js +1 -7
  210. package/lib/services/SceneGraphSelector.d.ts +3 -2
  211. package/lib/services/SceneGraphSelector.js +10 -3
  212. package/lib/services/SceneGraphService.d.ts +7 -14
  213. package/lib/services/SceneGraphService.js +15 -82
  214. package/lib/services/aabb/CircleUpdater.d.ts +2 -2
  215. package/lib/services/aabb/CircleUpdater.js +20 -10
  216. package/lib/services/aabb/EllipseUpdater.d.ts +2 -2
  217. package/lib/services/aabb/EllipseUpdater.js +27 -12
  218. package/lib/services/aabb/LineUpdater.js +1 -1
  219. package/lib/services/aabb/PathUpdater.js +1 -1
  220. package/lib/services/aabb/PolylineUpdater.js +2 -2
  221. package/lib/services/aabb/RectUpdater.d.ts +2 -2
  222. package/lib/services/aabb/RectUpdater.js +32 -16
  223. package/lib/services/aabb/TextUpdater.js +18 -9
  224. package/lib/services/aabb/interfaces.d.ts +1 -1
  225. package/lib/services/aabb/interfaces.js +1 -1
  226. package/lib/services/text/index.js +19 -21
  227. package/lib/shapes/AABB.d.ts +1 -0
  228. package/lib/shapes/AABB.js +8 -0
  229. package/lib/types.d.ts +48 -27
  230. package/lib/types.js +56 -35
  231. package/lib/utils/custom-easing.js +1 -1
  232. package/lib/utils/event.js +5 -3
  233. package/lib/utils/index.d.ts +1 -0
  234. package/lib/utils/index.js +13 -0
  235. package/lib/utils/interpolation.d.ts +1 -0
  236. package/lib/utils/interpolation.js +43 -7
  237. package/lib/utils/path.d.ts +1 -1
  238. package/lib/utils/path.js +15 -15
  239. package/lib/utils/raf.d.ts +1 -1
  240. package/lib/utils/raf.js +0 -2
  241. package/lib/utils/string.d.ts +1 -0
  242. package/lib/utils/string.js +16 -0
  243. package/lib/utils/text.js +3 -3
  244. package/package.json +6 -4
@@ -2,39 +2,52 @@ import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { isString } from '@antv/util';
4
4
  import { GeometryAABBUpdater } from './interfaces';
5
- import { SHAPE } from '../../types';
5
+ import { Shape } from '../../types';
6
6
 
7
7
  var RectUpdater =
8
8
  /** @class */
9
9
  function () {
10
10
  function RectUpdater() {}
11
11
 
12
- RectUpdater.prototype.update = function (attributes) {
13
- var img = attributes.img,
14
- _a = attributes.x,
12
+ RectUpdater.prototype.update = function (parsedStyle, object) {
13
+ var img = parsedStyle.img,
14
+ _a = parsedStyle.x,
15
15
  x = _a === void 0 ? 0 : _a,
16
- _b = attributes.y,
16
+ _b = parsedStyle.y,
17
17
  y = _b === void 0 ? 0 : _b,
18
- _c = attributes.width,
19
- width = _c === void 0 ? 0 : _c,
20
- _d = attributes.height,
21
- height = _d === void 0 ? 0 : _d;
22
- var contentWidth;
23
- var contentHeight; // resize with HTMLImageElement's size
18
+ width = parsedStyle.width,
19
+ height = parsedStyle.height;
20
+ var contentWidth = 0;
21
+ var contentHeight = 0;
22
+ var widthUnit = width.unit,
23
+ widthValue = width.value;
24
+ var heightUnit = height.unit,
25
+ heightValue = height.value;
26
+
27
+ if (widthUnit === '' || widthUnit === 'px') {
28
+ contentWidth = widthValue;
29
+ }
30
+
31
+ if (heightUnit === '' || heightUnit === 'px') {
32
+ contentHeight = heightValue;
33
+ } // resize with HTMLImageElement's size
34
+
24
35
 
25
36
  if (img && !isString(img)) {
26
- if (!attributes.width) {
37
+ if (!contentWidth) {
27
38
  contentWidth = img.width;
28
39
  }
29
40
 
30
- if (!attributes.height) {
41
+ if (!contentHeight) {
31
42
  contentHeight = img.height;
32
43
  }
33
44
  }
34
45
 
46
+ object.parsedStyle.widthInPixels = contentWidth;
47
+ object.parsedStyle.heightInPixels = contentHeight;
35
48
  return {
36
- width: contentWidth || width,
37
- height: contentHeight || height,
49
+ width: contentWidth,
50
+ height: contentHeight,
38
51
  x: x,
39
52
  y: y
40
53
  };
@@ -43,10 +56,13 @@ function () {
43
56
  RectUpdater = __decorate([singleton({
44
57
  token: [{
45
58
  token: GeometryAABBUpdater,
46
- named: SHAPE.Rect
59
+ named: Shape.RECT
60
+ }, {
61
+ token: GeometryAABBUpdater,
62
+ named: Shape.IMAGE
47
63
  }, {
48
64
  token: GeometryAABBUpdater,
49
- named: SHAPE.Image
65
+ named: Shape.GROUP
50
66
  }]
51
67
  })], RectUpdater);
52
68
  return RectUpdater;
@@ -3,7 +3,7 @@ import { vec3 } from 'gl-matrix';
3
3
  import { singleton, inject } from 'mana-syringe';
4
4
  import { GeometryAABBUpdater } from './interfaces';
5
5
  import { TextService } from '../text';
6
- import { SHAPE } from '../../types';
6
+ import { Shape } from '../../types';
7
7
 
8
8
  var TextUpdater =
9
9
  /** @class */
@@ -14,13 +14,14 @@ function () {
14
14
  var _a = parsedStyle.text,
15
15
  text = _a === void 0 ? '' : _a,
16
16
  textAlign = parsedStyle.textAlign,
17
- _b = parsedStyle.lineWidth,
18
- lineWidth = _b === void 0 ? 0 : _b,
17
+ lineWidth = parsedStyle.lineWidth,
19
18
  textBaseline = parsedStyle.textBaseline,
20
- _c = parsedStyle.x,
21
- x = _c === void 0 ? 0 : _c,
22
- _d = parsedStyle.y,
23
- y = _d === void 0 ? 0 : _d;
19
+ _b = parsedStyle.x,
20
+ x = _b === void 0 ? 0 : _b,
21
+ _c = parsedStyle.y,
22
+ y = _c === void 0 ? 0 : _c,
23
+ dx = parsedStyle.dx,
24
+ dy = parsedStyle.dy;
24
25
  var metrics = this.textService.measureText(text, parsedStyle);
25
26
  parsedStyle.metrics = metrics;
26
27
  var width = metrics.width,
@@ -34,10 +35,10 @@ function () {
34
35
  var lineXOffset = 0;
35
36
 
36
37
  if (textAlign === 'center') {
37
- lineXOffset = lineWidth / 2;
38
+ lineXOffset = lineWidth.value / 2;
38
39
  anchor = [0.5, 1];
39
40
  } else if (textAlign === 'right' || textAlign === 'end') {
40
- lineXOffset = lineWidth;
41
+ lineXOffset = lineWidth.value;
41
42
  anchor = [1, 1];
42
43
  } // update anchor
43
44
 
@@ -57,6 +58,14 @@ function () {
57
58
  } // TODO: ideographic & bottom
58
59
 
59
60
 
61
+ if (dx && dx.unit === 'px') {
62
+ lineXOffset += dx.value;
63
+ }
64
+
65
+ if (dy && dy.unit === 'px') {
66
+ lineYOffset += dy.value;
67
+ }
68
+
60
69
  return {
61
70
  width: halfExtents[0] * 2,
62
71
  height: halfExtents[1] * 2,
@@ -72,7 +81,7 @@ function () {
72
81
  TextUpdater = __decorate([singleton({
73
82
  token: {
74
83
  token: GeometryAABBUpdater,
75
- named: SHAPE.Text
84
+ named: Shape.TEXT
76
85
  }
77
86
  })], TextUpdater);
78
87
  return TextUpdater;
@@ -1,7 +1,7 @@
1
1
  import type { DisplayObject } from '../../display-objects/DisplayObject';
2
2
  import type { ParsedBaseStyleProps } from '../../types';
3
3
  export declare const GeometryUpdaterFactory = "GeometryUpdaterFactory";
4
- export declare const GeometryAABBUpdater = "GeometryAABBGenerator";
4
+ export declare const GeometryAABBUpdater = "GeometryAABBUpdater";
5
5
  export interface GeometryAABBUpdater<T extends ParsedBaseStyleProps = any> {
6
6
  update: (parsedStyle: T, object: DisplayObject) => {
7
7
  width: number;
@@ -1,2 +1,2 @@
1
1
  export var GeometryUpdaterFactory = 'GeometryUpdaterFactory';
2
- export var GeometryAABBUpdater = 'GeometryAABBGenerator';
2
+ export var GeometryAABBUpdater = 'GeometryAABBUpdater';
@@ -24,8 +24,8 @@ var regexCannotStartJaJp = /[)\]}〕〉》」』】〙〗〟'"⦆»ヽヾー
24
24
  var regexCannotEndJaJp = /[([{〔〈《「『【〘〖〝'"⦅«—...‥〳〴〵]/;
25
25
  var regexCannotStartKoKr = /[!%),.:;?\]}¢°'"†‡℃〆〈《「『〕!%),.:;?]}]/;
26
26
  var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
27
- var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
28
- var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
27
+ var regexCannotStart = new RegExp("".concat(regexCannotStartZhCn.source, "|").concat(regexCannotStartZhTw.source, "|").concat(regexCannotStartJaJp.source, "|").concat(regexCannotStartKoKr.source));
28
+ var regexCannotEnd = new RegExp("".concat(regexCannotEndZhCn.source, "|").concat(regexCannotEndZhTw.source, "|").concat(regexCannotEndJaJp.source, "|").concat(regexCannotEndKoKr.source));
29
29
 
30
30
  var TextService =
31
31
  /** @class */
@@ -93,7 +93,7 @@ function () {
93
93
  context.textBaseline = 'alphabetic';
94
94
  context.fillStyle = '#000';
95
95
  context.fillText(metricsString, 0, baseline);
96
- var imagedata = context.getImageData(0, 0, width, height).data;
96
+ var imagedata = context.getImageData(0, 0, width || 1, height || 1).data;
97
97
  var pixels = imagedata.length;
98
98
  var line = width * 4;
99
99
  var i = 0;
@@ -141,29 +141,27 @@ function () {
141
141
  };
142
142
 
143
143
  TextService.prototype.measureText = function (text, attributes) {
144
- var _a = attributes.fontSize,
145
- fontSize = _a === void 0 ? 0 : _a,
144
+ var fontSize = attributes.fontSize,
146
145
  wordWrap = attributes.wordWrap,
147
- _b = attributes.lineHeight,
148
- strokeHeight = _b === void 0 ? 0 : _b,
149
- _c = attributes.lineWidth,
150
- lineWidth = _c === void 0 ? 0 : _c,
146
+ _a = attributes.lineHeight,
147
+ strokeHeight = _a === void 0 ? 0 : _a,
148
+ lineWidth = attributes.lineWidth,
151
149
  textBaseline = attributes.textBaseline,
152
150
  textAlign = attributes.textAlign,
153
- _d = attributes.letterSpacing,
154
- letterSpacing = _d === void 0 ? 0 : _d,
151
+ _b = attributes.letterSpacing,
152
+ letterSpacing = _b === void 0 ? 0 : _b,
155
153
  dropShadow = attributes.dropShadow,
156
- _e = attributes.dropShadowDistance,
157
- dropShadowDistance = _e === void 0 ? 0 : _e,
158
- _f = attributes.leading,
159
- leading = _f === void 0 ? 0 : _f;
154
+ _c = attributes.dropShadowDistance,
155
+ dropShadowDistance = _c === void 0 ? 0 : _c,
156
+ _d = attributes.leading,
157
+ leading = _d === void 0 ? 0 : _d;
160
158
  var font = toFontString(attributes);
161
159
  var fontProperties = this.measureFont(font); // fallback in case UA disallow canvas data extraction
162
160
  // (toDataURI, getImageData functions)
163
161
 
164
162
  if (fontProperties.fontSize === 0) {
165
- fontProperties.fontSize = fontSize;
166
- fontProperties.ascent = fontSize;
163
+ fontProperties.fontSize = fontSize.value;
164
+ fontProperties.ascent = fontSize.value;
167
165
  }
168
166
 
169
167
  var context = this.offscreenCanvas.getOrCreateContext();
@@ -179,14 +177,14 @@ function () {
179
177
  maxLineWidth = Math.max(maxLineWidth, lineWidth_1);
180
178
  }
181
179
 
182
- var width = maxLineWidth + lineWidth;
180
+ var width = maxLineWidth + lineWidth.value;
183
181
 
184
182
  if (dropShadow) {
185
183
  width += dropShadowDistance;
186
184
  }
187
185
 
188
- var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
189
- var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading);
186
+ var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth.value;
187
+ var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth.value) + (lines.length - 1) * (lineHeight + leading);
190
188
 
191
189
  if (dropShadow) {
192
190
  height += dropShadowDistance;
@@ -222,7 +220,7 @@ function () {
222
220
  offsetX -= width;
223
221
  }
224
222
 
225
- return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
223
+ return new Rectangle(offsetX - lineWidth.value / 2, offsetY + i * lineHeight, width + lineWidth.value, lineHeight);
226
224
  })
227
225
  };
228
226
  };
@@ -7,6 +7,7 @@ import type { Plane } from './Plane';
7
7
  * @see https://github.com/antvis/GWebGPUEngine/issues/3
8
8
  */
9
9
  export declare class AABB {
10
+ static isEmpty(aabb: AABB): boolean;
10
11
  center: vec3;
11
12
  halfExtents: vec3;
12
13
  min: vec3;
package/es/shapes/AABB.js CHANGED
@@ -14,6 +14,10 @@ function () {
14
14
  this.update(center, halfExtents);
15
15
  }
16
16
 
17
+ AABB.isEmpty = function (aabb) {
18
+ return !aabb || aabb.halfExtents[0] === 0 && aabb.halfExtents[1] === 0 && aabb.halfExtents[2] === 0;
19
+ };
20
+
17
21
  AABB.prototype.update = function (center, halfExtents) {
18
22
  this.center = vec3.copy(vec3.create(), center || vec3.create());
19
23
  this.halfExtents = vec3.copy(vec3.create(), halfExtents || vec3.fromValues(0, 0, 0));
@@ -39,6 +43,10 @@ function () {
39
43
  };
40
44
 
41
45
  AABB.prototype.add = function (aabb) {
46
+ if (AABB.isEmpty(aabb)) {
47
+ return;
48
+ }
49
+
42
50
  var tc = this.center;
43
51
  var tcx = tc[0];
44
52
  var tcy = tc[1];
package/es/types.d.ts CHANGED
@@ -2,19 +2,19 @@
2
2
  import type { vec2, vec3 } from 'gl-matrix';
3
3
  import type { ParsedPathStyleProps, ParsedPolylineStyleProps } from './display-objects';
4
4
  import type { DisplayObject } from './display-objects';
5
- import type { ParsedColorStyleProperty } from './property-handlers';
5
+ import type { ParsedColorStyleProperty, ParsedElement } from './property-handlers';
6
6
  import type { IRenderer } from './AbstractRenderer';
7
- export declare enum SHAPE {
8
- Group = "group",
9
- Circle = "circle",
10
- Ellipse = "ellipse",
11
- Image = "image",
12
- Rect = "rect",
13
- Line = "line",
14
- Polyline = "polyline",
15
- Polygon = "polygon",
16
- Text = "text",
17
- Path = "path",
7
+ export declare enum Shape {
8
+ GROUP = "g",
9
+ CIRCLE = "circle",
10
+ ELLIPSE = "ellipse",
11
+ IMAGE = "image",
12
+ RECT = "rect",
13
+ LINE = "line",
14
+ POLYLINE = "polyline",
15
+ POLYGON = "polygon",
16
+ TEXT = "text",
17
+ PATH = "path",
18
18
  HTML = "html"
19
19
  }
20
20
  declare type ColorType = string | null;
@@ -26,17 +26,31 @@ export interface EventPosition {
26
26
  x: number;
27
27
  y: number;
28
28
  }
29
- export declare enum LINE_CAP {
30
- Butt = "butt",
31
- Round = "round",
32
- Square = "square"
29
+ export declare enum LineCap {
30
+ BUTT = "butt",
31
+ ROUND = "round",
32
+ SQUARE = "square"
33
33
  }
34
- export declare enum LINE_JOIN {
35
- Bevel = "bevel",
36
- Round = "round",
37
- Miter = "miter"
34
+ export declare enum LineJoin {
35
+ BEVEL = "bevel",
36
+ ROUND = "round",
37
+ MITER = "miter"
38
+ }
39
+ export declare enum TextTransform {
40
+ CAPITALIZE = "capitalize",
41
+ UPPERCASE = "uppercase",
42
+ LOWERCASE = "lowercase",
43
+ NONE = "none"
44
+ }
45
+ export declare enum TextAlign {
46
+ START = "start",
47
+ CENTER = "center",
48
+ END = "end",
49
+ LEFT = "left",
50
+ RIGHT = "right"
38
51
  }
39
52
  export interface BaseStyleProps {
53
+ class?: string;
40
54
  /**
41
55
  * x in local space
42
56
  */
@@ -100,17 +114,16 @@ export interface BaseStyleProps {
100
114
  /** 整体透明度 */
101
115
  opacity?: number;
102
116
  /** 线宽 */
103
- lineWidth?: number;
117
+ lineWidth?: string | number;
104
118
  /** 指定如何绘制每一条线段末端 */
105
- lineCap?: LINE_CAP;
119
+ lineCap?: LineCap;
106
120
  /** 用来设置2个长度不为0的相连部分(线段,圆弧,曲线)如何连接在一起的属性(长度为0的变形部分,其指定的末端和控制点在同一位置,会被忽略) */
107
- lineJoin?: LINE_JOIN;
121
+ lineJoin?: LineJoin;
108
122
  /**
109
123
  * 设置线的虚线样式,可以指定一个数组。一组描述交替绘制线段和间距(坐标空间单位)长度的数字。 如果数组元素的数量是奇数, 数组的元素会被复制并重复。例如, [5, 15, 25] 会变成 [5, 15, 25, 5, 15, 25]。这个属性取决于浏览器是否支持 setLineDash() 函数。
110
124
  */
111
125
  lineDash?: number[] | null;
112
126
  lineDashOffset?: number;
113
- padding?: number[] | number;
114
127
  /**
115
128
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowBlur
116
129
  */
@@ -127,16 +140,23 @@ export interface BaseStyleProps {
127
140
  * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter
128
141
  */
129
142
  filter?: string;
143
+ /**
144
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
145
+ */
146
+ textTransform?: TextTransform;
147
+ /**
148
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit
149
+ */
150
+ miterLimit?: number;
130
151
  }
131
- export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'fill' | 'stroke' | 'path' | 'points'> {
152
+ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'fill' | 'stroke' | 'path' | 'points' | 'lineWidth' | 'shadowColor'> {
132
153
  fill?: ParsedColorStyleProperty;
133
154
  stroke?: ParsedColorStyleProperty;
134
155
  path?: ParsedPathStyleProps;
135
156
  points?: ParsedPolylineStyleProps;
136
157
  x?: number;
137
158
  y?: number;
138
- width?: number;
139
- height?: number;
159
+ lineWidth?: ParsedElement;
140
160
  /**
141
161
  * x according to definition, eg. Line's x1/x2, Polyline's points
142
162
  */
@@ -147,6 +167,7 @@ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'fill' | 'str
147
167
  */
148
168
  offsetX?: number;
149
169
  offsetY?: number;
170
+ shadowColor?: ParsedColorStyleProperty;
150
171
  }
151
172
  export declare type Cursor = 'auto' | 'default' | 'none' | 'context-menu' | 'help' | 'pointer' | 'progress' | 'wait' | 'cell' | 'crosshair' | 'text' | 'vertical-text' | 'alias' | 'copy' | 'move' | 'no-drop' | 'not-allowed' | 'grab' | 'grabbing' | 'all-scroll' | 'col-resize' | 'row-resize' | 'n-resize' | 'e-resize' | 's-resize' | 'w-resize' | 'ne-resize' | 'nw-resize' | 'se-resize' | 'sw-resize' | 'ew-resize' | 'ns-resize' | 'nesw-resize' | 'nwse-resize' | 'zoom-in' | 'zoom-out';
152
173
  export interface RendererConfig {
package/es/types.js CHANGED
@@ -1,33 +1,52 @@
1
- export var SHAPE;
2
-
3
- (function (SHAPE) {
4
- SHAPE["Group"] = "group";
5
- SHAPE["Circle"] = "circle";
6
- SHAPE["Ellipse"] = "ellipse";
7
- SHAPE["Image"] = "image";
8
- SHAPE["Rect"] = "rect";
9
- SHAPE["Line"] = "line";
10
- SHAPE["Polyline"] = "polyline";
11
- SHAPE["Polygon"] = "polygon";
12
- SHAPE["Text"] = "text";
13
- SHAPE["Path"] = "path";
14
- SHAPE["HTML"] = "html";
15
- })(SHAPE || (SHAPE = {}));
16
-
17
- export var LINE_CAP;
18
-
19
- (function (LINE_CAP) {
20
- LINE_CAP["Butt"] = "butt";
21
- LINE_CAP["Round"] = "round";
22
- LINE_CAP["Square"] = "square";
23
- })(LINE_CAP || (LINE_CAP = {}));
24
-
25
- export var LINE_JOIN;
26
-
27
- (function (LINE_JOIN) {
28
- LINE_JOIN["Bevel"] = "bevel";
29
- LINE_JOIN["Round"] = "round";
30
- LINE_JOIN["Miter"] = "miter";
31
- })(LINE_JOIN || (LINE_JOIN = {}));
1
+ export var Shape;
2
+
3
+ (function (Shape) {
4
+ Shape["GROUP"] = "g";
5
+ Shape["CIRCLE"] = "circle";
6
+ Shape["ELLIPSE"] = "ellipse";
7
+ Shape["IMAGE"] = "image";
8
+ Shape["RECT"] = "rect";
9
+ Shape["LINE"] = "line";
10
+ Shape["POLYLINE"] = "polyline";
11
+ Shape["POLYGON"] = "polygon";
12
+ Shape["TEXT"] = "text";
13
+ Shape["PATH"] = "path";
14
+ Shape["HTML"] = "html";
15
+ })(Shape || (Shape = {}));
16
+
17
+ export var LineCap;
18
+
19
+ (function (LineCap) {
20
+ LineCap["BUTT"] = "butt";
21
+ LineCap["ROUND"] = "round";
22
+ LineCap["SQUARE"] = "square";
23
+ })(LineCap || (LineCap = {}));
24
+
25
+ export var LineJoin;
26
+
27
+ (function (LineJoin) {
28
+ LineJoin["BEVEL"] = "bevel";
29
+ LineJoin["ROUND"] = "round";
30
+ LineJoin["MITER"] = "miter";
31
+ })(LineJoin || (LineJoin = {}));
32
+
33
+ export var TextTransform;
34
+
35
+ (function (TextTransform) {
36
+ TextTransform["CAPITALIZE"] = "capitalize";
37
+ TextTransform["UPPERCASE"] = "uppercase";
38
+ TextTransform["LOWERCASE"] = "lowercase";
39
+ TextTransform["NONE"] = "none";
40
+ })(TextTransform || (TextTransform = {}));
41
+
42
+ export var TextAlign;
43
+
44
+ (function (TextAlign) {
45
+ TextAlign["START"] = "start";
46
+ TextAlign["CENTER"] = "center";
47
+ TextAlign["END"] = "end";
48
+ TextAlign["LEFT"] = "left";
49
+ TextAlign["RIGHT"] = "right";
50
+ })(TextAlign || (TextAlign = {}));
32
51
 
33
52
  export var CanvasConfig = 'CanvasConfig';
@@ -6,7 +6,7 @@ import { __read, __spreadArray } from "tslib";
6
6
  import { bezier } from './bezier-easing';
7
7
  export var convertToDash = function convertToDash(str) {
8
8
  str = str.replace(/([A-Z])/g, function (letter) {
9
- return "-" + letter.toLowerCase();
9
+ return "-".concat(letter.toLowerCase());
10
10
  }); // Remove first dash
11
11
 
12
12
  return str.charAt(0) === '-' ? str.substr(1) : str;
package/es/utils/event.js CHANGED
@@ -26,9 +26,11 @@ export function normalizeToPointerEvent(event) {
26
26
 
27
27
  if (isTouchEvent(event)) {
28
28
  for (var i = 0; i < event.changedTouches.length; i++) {
29
- var touch = event.changedTouches[i];
30
- if (isUndefined(touch.button)) touch.button = event.touches.length ? 1 : 0;
31
- if (isUndefined(touch.buttons)) touch.buttons = event.touches.length ? 1 : 0;
29
+ var touch = event.changedTouches[i]; // use changedTouches instead of touches since touchend has no touches
30
+ // @see https://stackoverflow.com/a/10079076
31
+
32
+ if (isUndefined(touch.button)) touch.button = event.changedTouches.length ? 1 : 0;
33
+ if (isUndefined(touch.buttons)) touch.buttons = event.changedTouches.length ? 1 : 0;
32
34
 
33
35
  if (isUndefined(touch.isPrimary)) {
34
36
  touch.isPrimary = event.touches.length === 1 && event.type === 'touchstart';
@@ -3,3 +3,4 @@ export * from './interpolation';
3
3
  export * from './path';
4
4
  export * from './raf';
5
5
  export * from './text';
6
+ export * from './string';
package/es/utils/index.js CHANGED
@@ -2,4 +2,5 @@ export * from './math';
2
2
  export * from './interpolation';
3
3
  export * from './path';
4
4
  export * from './raf';
5
- export * from './text';
5
+ export * from './text';
6
+ export * from './string';
@@ -1,3 +1,4 @@
1
1
  import type { AnimationEffectTiming } from '../dom';
2
2
  import type { IElement } from '../dom/interfaces';
3
3
  export declare function convertEffectInput(keyframes: ComputedKeyframe[], timing: AnimationEffectTiming, target: IElement | null): (target: IElement, fraction: number) => void;
4
+ export declare function formatAttribute(name: string, value: any): [string, any];
@@ -1,10 +1,7 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
- import { stylePropertyMergerFactory, stylePropertyParserFactory } from '../global-module'; // import {
3
- // StylePropertyMergerFactory,
4
- // StylePropertyParserFactory,
5
- // } from '../property-handlers/interfaces';
6
-
2
+ import { stylePropertyMergerFactory, stylePropertyParserFactory } from '../global-module';
7
3
  import { parseEasingFunction } from './animation';
4
+ import { camelCase } from './string';
8
5
  export function convertEffectInput(keyframes, timing, target) {
9
6
  var propertySpecificKeyframeGroups = makePropertySpecificKeyframeGroups(keyframes, timing);
10
7
  var interpolations = makeInterpolations(propertySpecificKeyframeGroups, target);
@@ -120,9 +117,9 @@ function propertyInterpolation(property, left, right, target) {
120
117
 
121
118
  if (parser) {
122
119
  // @ts-ignore
123
- parsedLeft = parser(left, target); // @ts-ignore
120
+ parsedLeft = parser(left, target, property); // @ts-ignore
124
121
 
125
- parsedRight = parser(right, target);
122
+ parsedRight = parser(right, target, property);
126
123
  } // merger [left, right, n2string()]
127
124
 
128
125
 
@@ -179,4 +176,40 @@ convertToString) {
179
176
  return function (f) {
180
177
  return convertToString(interpolate(from, to, f));
181
178
  };
182
- };
179
+ };
180
+
181
+ var FORMAT_ATTR_MAP = {
182
+ d: {
183
+ alias: 'path'
184
+ },
185
+ cx: {
186
+ alias: 'x'
187
+ },
188
+ cy: {
189
+ alias: 'y'
190
+ },
191
+ strokeDasharray: {
192
+ alias: 'lineDash'
193
+ },
194
+ strokeWidth: {
195
+ alias: 'lineWidth'
196
+ },
197
+ textAnchor: {
198
+ alias: 'textAlign',
199
+ values: {
200
+ middle: 'center'
201
+ }
202
+ },
203
+ src: {
204
+ alias: 'img'
205
+ }
206
+ };
207
+ export function formatAttribute(name, value) {
208
+ var _a;
209
+
210
+ var attributeName = camelCase(name);
211
+ var map = FORMAT_ATTR_MAP[attributeName];
212
+ attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
213
+ var attributeValue = ((_a = map === null || map === void 0 ? void 0 : map.values) === null || _a === void 0 ? void 0 : _a[value]) || value;
214
+ return [attributeName, attributeValue];
215
+ }
@@ -5,7 +5,7 @@ export declare function getDrawDirection(pathArray: PathCommand[]): boolean;
5
5
  export declare function getPathArea(pathArray: PathCommand[]): number;
6
6
  export declare function reverseCurve(pathArray: PathCommand[]): PathCommand[];
7
7
  export declare function clonePath(pathArray: PathCommand[]): PathCommand[];
8
- export declare function getRotatedCurve(a: PathCommand[], b: PathCommand[]): (string[] | ["a" | "A", number, number, number, number, number, number, number] | ["C" | "c", number, number, number, number, number, number] | ["o" | "O", number, number] | ["h" | "H", number] | ["l" | "L", number, number] | ["M" | "m", number, number] | ["r" | "R", number, number, number, number] | ["q" | "Q", number, number, number, number] | ["s" | "S", number, number, number, number, number, number, number] | ["t" | "T", number, number] | ["v" | "V", number] | ["u" | "U", number, number, number])[];
8
+ export declare function getRotatedCurve(a: PathCommand[], b: PathCommand[]): (string[] | ["a" | "A", number, number, number, number, number, number, number] | ["C" | "c", number, number, number, number, number, number] | ["o" | "O", number, number] | ["h" | "H", number] | ["l" | "L", number, number] | ["m" | "M", number, number] | ["r" | "R", number, number, number, number] | ["q" | "Q", number, number, number, number] | ["s" | "S", number, number, number, number, number, number, number] | ["t" | "T", number, number] | ["v" | "V", number] | ["u" | "U", number, number, number])[];
9
9
  /**
10
10
  * convert object to path, should account for:
11
11
  * * transform & origin