@antv/g 5.0.23 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/dist/index.umd.min.js +3 -2
  2. package/es/AbstractRenderer.d.ts +11 -0
  3. package/es/AbstractRenderer.js +17 -2
  4. package/es/Canvas.d.ts +1 -1
  5. package/es/Canvas.js +2 -0
  6. package/es/components/Geometry.d.ts +0 -4
  7. package/es/css/CSS.d.ts +2 -1
  8. package/es/css/CSS.js +5 -1
  9. package/es/css/CSSProperty.d.ts +2 -1
  10. package/es/css/StyleValueRegistry.d.ts +2 -1
  11. package/es/css/StyleValueRegistry.js +71 -88
  12. package/es/css/index.d.ts +1 -1
  13. package/es/css/index.js +1 -1
  14. package/es/css/layout/FragmentResult.d.ts +32 -0
  15. package/es/css/layout/FragmentResult.js +32 -0
  16. package/es/css/layout/LayoutChildren.d.ts +23 -0
  17. package/es/css/layout/LayoutChildren.js +55 -0
  18. package/es/css/layout/LayoutContext.d.ts +35 -0
  19. package/es/css/layout/LayoutContext.js +35 -0
  20. package/es/css/layout/LayoutDefinition.d.ts +20 -0
  21. package/es/css/layout/LayoutDefinition.js +9 -0
  22. package/es/css/layout/LayoutEdges.d.ts +24 -0
  23. package/es/css/layout/LayoutEdges.js +41 -0
  24. package/es/css/layout/LayoutEngine.d.ts +41 -0
  25. package/es/css/layout/LayoutEngine.js +332 -0
  26. package/es/css/layout/LayoutFragment.d.ts +26 -0
  27. package/es/css/layout/LayoutFragment.js +28 -0
  28. package/es/css/layout/LayoutObject.d.ts +46 -0
  29. package/es/css/layout/LayoutObject.js +172 -0
  30. package/es/css/layout/LayoutRegistry.d.ts +16 -0
  31. package/es/css/layout/LayoutRegistry.js +78 -0
  32. package/es/css/layout/LayoutWorkTask.d.ts +14 -0
  33. package/es/css/layout/LayoutWorkTask.js +1 -0
  34. package/es/css/layout/index.d.ts +11 -0
  35. package/es/css/layout/index.js +11 -0
  36. package/es/css/layout/types.d.ts +104 -0
  37. package/es/css/layout/types.js +66 -0
  38. package/es/css/parser/color.d.ts +1 -1
  39. package/es/css/parser/color.js +2 -2
  40. package/es/css/parser/dimension.js +5 -1
  41. package/es/css/parser/path.d.ts +2 -2
  42. package/es/css/parser/path.js +9 -2
  43. package/es/css/parser/points.d.ts +8 -1
  44. package/es/css/parser/points.js +33 -3
  45. package/es/css/parser/transform.js +1 -1
  46. package/es/css/properties/CSSPropertyClipPath.js +7 -1
  47. package/es/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  48. package/es/css/properties/CSSPropertyLocalPosition.js +59 -20
  49. package/es/css/properties/CSSPropertyPath.d.ts +2 -2
  50. package/es/css/properties/CSSPropertyPath.js +7 -5
  51. package/es/css/properties/CSSPropertyPoints.js +3 -4
  52. package/es/css/properties/CSSPropertyTransform.d.ts +1 -1
  53. package/es/css/properties/CSSPropertyTransform.js +76 -104
  54. package/es/display-objects/Circle.d.ts +4 -0
  55. package/es/display-objects/Circle.js +2 -0
  56. package/es/display-objects/CustomElement.d.ts +6 -2
  57. package/es/display-objects/CustomElement.js +15 -5
  58. package/es/display-objects/DisplayObject.d.ts +1 -7
  59. package/es/display-objects/DisplayObject.js +6 -26
  60. package/es/display-objects/Ellipse.d.ts +4 -0
  61. package/es/display-objects/Ellipse.js +2 -0
  62. package/es/display-objects/Group.d.ts +4 -0
  63. package/es/display-objects/Group.js +2 -0
  64. package/es/display-objects/HTML.d.ts +4 -4
  65. package/es/display-objects/HTML.js +5 -3
  66. package/es/display-objects/Image.d.ts +4 -0
  67. package/es/display-objects/Image.js +2 -0
  68. package/es/display-objects/Line.js +2 -0
  69. package/es/display-objects/Path.d.ts +2 -2
  70. package/es/display-objects/Polygon.js +1 -1
  71. package/es/display-objects/Polyline.js +1 -1
  72. package/es/display-objects/Rect.d.ts +6 -2
  73. package/es/display-objects/Rect.js +2 -0
  74. package/es/display-objects/Text.d.ts +4 -0
  75. package/es/display-objects/Text.js +2 -0
  76. package/es/dom/Element.js +1 -0
  77. package/es/global-module.js +87 -1
  78. package/es/index.d.ts +3 -0
  79. package/es/index.js +3 -0
  80. package/es/services/EventService.js +10 -2
  81. package/es/services/OffscreenCanvasCreator.d.ts +1 -1
  82. package/es/services/OffscreenCanvasCreator.js +1 -1
  83. package/es/services/RenderingService.d.ts +1 -1
  84. package/es/services/RenderingService.js +1 -1
  85. package/es/services/SceneGraphService.d.ts +2 -0
  86. package/es/services/SceneGraphService.js +9 -0
  87. package/es/services/aabb/CircleUpdater.d.ts +0 -2
  88. package/es/services/aabb/CircleUpdater.js +2 -6
  89. package/es/services/aabb/EllipseUpdater.d.ts +0 -2
  90. package/es/services/aabb/EllipseUpdater.js +2 -6
  91. package/es/services/aabb/LineUpdater.d.ts +0 -2
  92. package/es/services/aabb/LineUpdater.js +1 -3
  93. package/es/services/aabb/PathUpdater.d.ts +0 -2
  94. package/es/services/aabb/PathUpdater.js +1 -5
  95. package/es/services/aabb/PolylineUpdater.d.ts +0 -2
  96. package/es/services/aabb/PolylineUpdater.js +1 -3
  97. package/es/services/aabb/RectUpdater.d.ts +0 -2
  98. package/es/services/aabb/RectUpdater.js +1 -5
  99. package/es/services/aabb/TextUpdater.d.ts +7 -0
  100. package/es/services/aabb/TextUpdater.js +0 -4
  101. package/es/services/aabb/interfaces.d.ts +0 -3
  102. package/es/types.d.ts +7 -23
  103. package/es/types.js +1 -0
  104. package/es/utils/deferred.d.ts +43 -0
  105. package/es/utils/deferred.js +117 -0
  106. package/es/utils/dom.d.ts +2 -0
  107. package/es/utils/dom.js +8 -0
  108. package/es/utils/index.d.ts +2 -0
  109. package/es/utils/index.js +3 -1
  110. package/es/utils/interpolation.js +2 -8
  111. package/es/utils/math.js +4 -3
  112. package/es/utils/path.d.ts +2 -2
  113. package/es/utils/path.js +61 -24
  114. package/lib/AbstractRenderer.d.ts +11 -0
  115. package/lib/AbstractRenderer.js +17 -2
  116. package/lib/Canvas.d.ts +1 -1
  117. package/lib/Canvas.js +2 -0
  118. package/lib/components/Geometry.d.ts +0 -4
  119. package/lib/css/CSS.d.ts +2 -1
  120. package/lib/css/CSS.js +7 -1
  121. package/lib/css/CSSProperty.d.ts +2 -1
  122. package/lib/css/StyleValueRegistry.d.ts +2 -1
  123. package/lib/css/StyleValueRegistry.js +70 -88
  124. package/lib/css/index.d.ts +1 -1
  125. package/lib/css/index.js +12 -12
  126. package/lib/css/layout/FragmentResult.d.ts +32 -0
  127. package/lib/css/layout/FragmentResult.js +51 -0
  128. package/lib/css/layout/LayoutChildren.d.ts +23 -0
  129. package/lib/css/layout/LayoutChildren.js +72 -0
  130. package/lib/css/layout/LayoutContext.d.ts +35 -0
  131. package/lib/css/layout/LayoutContext.js +49 -0
  132. package/lib/css/layout/LayoutDefinition.d.ts +20 -0
  133. package/lib/css/layout/LayoutDefinition.js +16 -0
  134. package/lib/css/layout/LayoutEdges.d.ts +24 -0
  135. package/lib/css/layout/LayoutEdges.js +56 -0
  136. package/lib/css/layout/LayoutEngine.d.ts +41 -0
  137. package/lib/css/layout/LayoutEngine.js +345 -0
  138. package/lib/css/layout/LayoutFragment.d.ts +26 -0
  139. package/lib/css/layout/LayoutFragment.js +44 -0
  140. package/lib/css/layout/LayoutObject.d.ts +46 -0
  141. package/lib/css/layout/LayoutObject.js +182 -0
  142. package/lib/css/layout/LayoutRegistry.d.ts +16 -0
  143. package/lib/css/layout/LayoutRegistry.js +87 -0
  144. package/lib/css/layout/LayoutWorkTask.d.ts +14 -0
  145. package/lib/css/layout/LayoutWorkTask.js +5 -0
  146. package/lib/css/layout/index.d.ts +11 -0
  147. package/lib/css/layout/index.js +148 -0
  148. package/lib/css/layout/types.d.ts +104 -0
  149. package/lib/css/layout/types.js +74 -0
  150. package/lib/css/parser/color.d.ts +1 -1
  151. package/lib/css/parser/color.js +1 -1
  152. package/lib/css/parser/dimension.js +4 -0
  153. package/lib/css/parser/path.d.ts +2 -2
  154. package/lib/css/parser/path.js +9 -2
  155. package/lib/css/parser/points.d.ts +8 -1
  156. package/lib/css/parser/points.js +33 -3
  157. package/lib/css/parser/transform.js +1 -1
  158. package/lib/css/properties/CSSPropertyClipPath.js +8 -1
  159. package/lib/css/properties/CSSPropertyLocalPosition.d.ts +0 -9
  160. package/lib/css/properties/CSSPropertyLocalPosition.js +60 -20
  161. package/lib/css/properties/CSSPropertyPath.d.ts +2 -2
  162. package/lib/css/properties/CSSPropertyPath.js +7 -5
  163. package/lib/css/properties/CSSPropertyPoints.js +3 -4
  164. package/lib/css/properties/CSSPropertyTransform.d.ts +1 -1
  165. package/lib/css/properties/CSSPropertyTransform.js +75 -103
  166. package/lib/display-objects/Circle.d.ts +4 -0
  167. package/lib/display-objects/Circle.js +2 -0
  168. package/lib/display-objects/CustomElement.d.ts +6 -2
  169. package/lib/display-objects/CustomElement.js +13 -4
  170. package/lib/display-objects/DisplayObject.d.ts +1 -7
  171. package/lib/display-objects/DisplayObject.js +6 -27
  172. package/lib/display-objects/Ellipse.d.ts +4 -0
  173. package/lib/display-objects/Ellipse.js +2 -0
  174. package/lib/display-objects/Group.d.ts +4 -0
  175. package/lib/display-objects/Group.js +2 -0
  176. package/lib/display-objects/HTML.d.ts +4 -4
  177. package/lib/display-objects/HTML.js +5 -3
  178. package/lib/display-objects/Image.d.ts +4 -0
  179. package/lib/display-objects/Image.js +2 -0
  180. package/lib/display-objects/Line.js +2 -0
  181. package/lib/display-objects/Path.d.ts +2 -2
  182. package/lib/display-objects/Polygon.js +1 -1
  183. package/lib/display-objects/Polyline.js +1 -1
  184. package/lib/display-objects/Rect.d.ts +6 -2
  185. package/lib/display-objects/Rect.js +2 -0
  186. package/lib/display-objects/Text.d.ts +4 -0
  187. package/lib/display-objects/Text.js +2 -0
  188. package/lib/dom/Element.js +1 -0
  189. package/lib/global-module.js +89 -1
  190. package/lib/index.d.ts +3 -0
  191. package/lib/index.js +7 -2
  192. package/lib/services/EventService.js +10 -2
  193. package/lib/services/OffscreenCanvasCreator.d.ts +1 -1
  194. package/lib/services/OffscreenCanvasCreator.js +1 -1
  195. package/lib/services/RenderingService.d.ts +1 -1
  196. package/lib/services/RenderingService.js +1 -1
  197. package/lib/services/SceneGraphService.d.ts +2 -0
  198. package/lib/services/SceneGraphService.js +12 -0
  199. package/lib/services/aabb/CircleUpdater.d.ts +0 -2
  200. package/lib/services/aabb/CircleUpdater.js +2 -6
  201. package/lib/services/aabb/EllipseUpdater.d.ts +0 -2
  202. package/lib/services/aabb/EllipseUpdater.js +2 -6
  203. package/lib/services/aabb/LineUpdater.d.ts +0 -2
  204. package/lib/services/aabb/LineUpdater.js +1 -3
  205. package/lib/services/aabb/PathUpdater.d.ts +0 -2
  206. package/lib/services/aabb/PathUpdater.js +1 -5
  207. package/lib/services/aabb/PolylineUpdater.d.ts +0 -2
  208. package/lib/services/aabb/PolylineUpdater.js +1 -3
  209. package/lib/services/aabb/RectUpdater.d.ts +0 -2
  210. package/lib/services/aabb/RectUpdater.js +1 -5
  211. package/lib/services/aabb/TextUpdater.d.ts +7 -0
  212. package/lib/services/aabb/TextUpdater.js +0 -4
  213. package/lib/services/aabb/interfaces.d.ts +0 -3
  214. package/lib/types.d.ts +7 -23
  215. package/lib/types.js +1 -0
  216. package/lib/utils/deferred.d.ts +43 -0
  217. package/lib/utils/deferred.js +131 -0
  218. package/lib/utils/dom.d.ts +2 -0
  219. package/lib/utils/dom.js +17 -0
  220. package/lib/utils/index.d.ts +2 -0
  221. package/lib/utils/index.js +26 -0
  222. package/lib/utils/interpolation.js +2 -8
  223. package/lib/utils/math.js +4 -3
  224. package/lib/utils/path.d.ts +2 -2
  225. package/lib/utils/path.js +55 -24
  226. package/package.json +3 -3
  227. package/es/css/LayoutRegistry.d.ts +0 -11
  228. package/es/css/LayoutRegistry.js +0 -22
  229. package/lib/css/LayoutRegistry.d.ts +0 -11
  230. package/lib/css/LayoutRegistry.js +0 -30
@@ -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
  */
@@ -161,8 +150,9 @@ export interface BaseStyleProps {
161
150
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit
162
151
  */
163
152
  miterLimit?: number;
153
+ display?: string;
164
154
  }
165
- 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'> {
166
156
  zIndex?: CSSUnitValue;
167
157
  visibility?: CSSKeywordValue;
168
158
  pointerEvents?: CSSKeywordValue;
@@ -176,10 +166,8 @@ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'anchor' | 'x
176
166
  lineJoin?: CSSKeywordValue;
177
167
  lineDashOffset?: CSSUnitValue;
178
168
  anchor?: [CSSUnitValue, CSSUnitValue, CSSUnitValue];
169
+ transform: ParsedTransform[];
179
170
  transformOrigin?: [CSSUnitValue, CSSUnitValue, CSSUnitValue];
180
- x?: CSSUnitValue;
181
- y?: CSSUnitValue;
182
- z?: CSSUnitValue;
183
171
  width?: CSSUnitValue;
184
172
  height?: CSSUnitValue;
185
173
  lineWidth?: CSSUnitValue;
@@ -215,10 +203,6 @@ export interface RendererConfig {
215
203
  * enable auto rendering
216
204
  */
217
205
  enableAutoRendering: boolean;
218
- /**
219
- * enable TAA in WebGL
220
- */
221
- enableTAA: boolean;
222
206
  }
223
207
  export declare const CanvasConfig: Syringe.DefinedToken;
224
208
  export interface CanvasConfig {
@@ -250,7 +234,7 @@ export interface CanvasConfig {
250
234
  /**
251
235
  * replace `new window.Image()`
252
236
  */
253
- createImage?: () => HTMLImageElement;
237
+ createImage?: (src: string) => HTMLImageElement;
254
238
  /**
255
239
  * limits query
256
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;
@@ -0,0 +1,43 @@
1
+ interface PromiseStatus<T> {
2
+ isPending: () => boolean;
3
+ isRejected: () => boolean;
4
+ isFulfilled: () => boolean;
5
+ getFullFilledValue: () => T;
6
+ }
7
+ /**
8
+ * This function allow you to modify a JS Promise by adding some status properties.
9
+ * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
10
+ * But modified according to the specs of promises : https://promisesaplus.com/
11
+ */
12
+ export declare const makeQuerablePromise: <T>(promise: Promise<T>) => PromiseStatus<T>;
13
+ /**
14
+ * Simple implementation of the deferred pattern.
15
+ * An object that exposes a promise and functions to resolve and reject it.
16
+ */
17
+ export declare class Deferred<T = void> {
18
+ resolve: (value: T | PromiseLike<T>) => void;
19
+ reject: (err?: any) => void;
20
+ promise: Promise<T>;
21
+ }
22
+ export declare const equalSet: (as: Set<any>, bs: Set<any>) => boolean;
23
+ /**
24
+ * Nicely typed aliases for some `Object` Methods
25
+ * - PSA: Don't mutate `yourObject`s
26
+ * - Numerical keys are BAD, resolve that issue upstream
27
+ * - Discussion: https://stackoverflow.com/a/65117465/565877
28
+ */
29
+ export declare const ObjectTyped: {
30
+ /**
31
+ * Object.keys, but with nice typing (`Array<keyof T>`)
32
+ */
33
+ keys: <T extends {}>(yourObject: T) => (keyof T)[];
34
+ /**
35
+ * Object.values, but with nice typing
36
+ */
37
+ values: <T_1 extends {}>(yourObject: T_1) => T_1[keyof T_1][];
38
+ /**
39
+ * Object.entries, but with nice typing
40
+ */
41
+ entries: <T_2 extends {}>(yourObject: T_2) => [keyof T_2, T_2[keyof T_2]][];
42
+ };
43
+ export {};
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.makeQuerablePromise = exports.equalSet = exports.ObjectTyped = exports.Deferred = void 0;
7
+
8
+ var _tslib = require("tslib");
9
+
10
+ /**
11
+ * This function allow you to modify a JS Promise by adding some status properties.
12
+ * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
13
+ * But modified according to the specs of promises : https://promisesaplus.com/
14
+ */
15
+ var makeQuerablePromise = function makeQuerablePromise(promise) {
16
+ // Don't modify any promise that has been already modified.
17
+ if (promise.isRejected || promise.isFulfilled) return promise; // Set initial state
18
+
19
+ var isPending = true;
20
+ var isRejected = false;
21
+ var isFulfilled = false;
22
+ var fullFilledValue; // Observe the promise, saving the fulfillment in a closure scope.
23
+
24
+ var result = promise.then(function (v) {
25
+ isFulfilled = true;
26
+ isPending = false;
27
+ fullFilledValue = v;
28
+ return v;
29
+ }, function (e) {
30
+ isRejected = true;
31
+ isPending = false;
32
+ throw e;
33
+ });
34
+
35
+ result.isFulfilled = function () {
36
+ return isFulfilled;
37
+ };
38
+
39
+ result.isPending = function () {
40
+ return isPending;
41
+ };
42
+
43
+ result.isRejected = function () {
44
+ return isRejected;
45
+ };
46
+
47
+ result.getFullFilledValue = function () {
48
+ return fullFilledValue;
49
+ };
50
+
51
+ return result;
52
+ };
53
+ /**
54
+ * Simple implementation of the deferred pattern.
55
+ * An object that exposes a promise and functions to resolve and reject it.
56
+ */
57
+
58
+
59
+ exports.makeQuerablePromise = makeQuerablePromise;
60
+
61
+ var Deferred =
62
+ /** @class */
63
+ function () {
64
+ function Deferred() {
65
+ var _this = this;
66
+
67
+ this.promise = new Promise(function (resolve, reject) {
68
+ _this.resolve = resolve;
69
+ _this.reject = reject;
70
+ });
71
+ }
72
+
73
+ return Deferred;
74
+ }();
75
+
76
+ exports.Deferred = Deferred;
77
+
78
+ var equalSet = function equalSet(as, bs) {
79
+ var e_1, _a;
80
+
81
+ if (as.size !== bs.size) return false;
82
+
83
+ try {
84
+ // eslint-disable-next-line no-restricted-syntax
85
+ for (var as_1 = (0, _tslib.__values)(as), as_1_1 = as_1.next(); !as_1_1.done; as_1_1 = as_1.next()) {
86
+ var a = as_1_1.value;
87
+
88
+ if (!bs.has(a)) {
89
+ return false;
90
+ }
91
+ }
92
+ } catch (e_1_1) {
93
+ e_1 = {
94
+ error: e_1_1
95
+ };
96
+ } finally {
97
+ try {
98
+ if (as_1_1 && !as_1_1.done && (_a = as_1.return)) _a.call(as_1);
99
+ } finally {
100
+ if (e_1) throw e_1.error;
101
+ }
102
+ }
103
+
104
+ return true;
105
+ };
106
+ /**
107
+ * Nicely typed aliases for some `Object` Methods
108
+ * - PSA: Don't mutate `yourObject`s
109
+ * - Numerical keys are BAD, resolve that issue upstream
110
+ * - Discussion: https://stackoverflow.com/a/65117465/565877
111
+ */
112
+
113
+
114
+ exports.equalSet = equalSet;
115
+ var ObjectTyped = {
116
+ /**
117
+ * Object.keys, but with nice typing (`Array<keyof T>`)
118
+ */
119
+ keys: Object.keys,
120
+
121
+ /**
122
+ * Object.values, but with nice typing
123
+ */
124
+ values: Object.values,
125
+
126
+ /**
127
+ * Object.entries, but with nice typing
128
+ */
129
+ entries: Object.entries
130
+ };
131
+ exports.ObjectTyped = ObjectTyped;
@@ -0,0 +1,2 @@
1
+ /// <reference types="offscreencanvas" />
2
+ export declare function setDOMSize($el: HTMLElement | OffscreenCanvas, width: number, height: number): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setDOMSize = setDOMSize;
7
+
8
+ var _canvas = require("./canvas");
9
+
10
+ var PX_SUFFIX = 'px';
11
+
12
+ function setDOMSize($el, width, height) {
13
+ if (_canvas.isBrowser && $el.style) {
14
+ $el.style.width = width + PX_SUFFIX;
15
+ $el.style.height = height + PX_SUFFIX;
16
+ }
17
+ }
@@ -6,3 +6,5 @@ export * from './text';
6
6
  export * from './string';
7
7
  export * from './event';
8
8
  export * from './canvas';
9
+ export * from './deferred';
10
+ export * from './dom';
@@ -106,4 +106,30 @@ Object.keys(_canvas).forEach(function (key) {
106
106
  return _canvas[key];
107
107
  }
108
108
  });
109
+ });
110
+
111
+ var _deferred = require("./deferred");
112
+
113
+ Object.keys(_deferred).forEach(function (key) {
114
+ if (key === "default" || key === "__esModule") return;
115
+ if (key in exports && exports[key] === _deferred[key]) return;
116
+ Object.defineProperty(exports, key, {
117
+ enumerable: true,
118
+ get: function get() {
119
+ return _deferred[key];
120
+ }
121
+ });
122
+ });
123
+
124
+ var _dom = require("./dom");
125
+
126
+ Object.keys(_dom).forEach(function (key) {
127
+ if (key === "default" || key === "__esModule") return;
128
+ if (key in exports && exports[key] === _dom[key]) return;
129
+ Object.defineProperty(exports, key, {
130
+ enumerable: true,
131
+ get: function get() {
132
+ return _dom[key];
133
+ }
134
+ });
109
135
  });
@@ -136,8 +136,8 @@ function propertyInterpolation(property, left, right, target) {
136
136
 
137
137
  if (propertyHandler) {
138
138
  if (propertyHandler.parser) {
139
- parsedLeft = propertyHandler.parser(left);
140
- parsedRight = propertyHandler.parser(right);
139
+ parsedLeft = propertyHandler.parser(left, target);
140
+ parsedRight = propertyHandler.parser(right, target);
141
141
  } // if (propertyHandler.calculator) {
142
142
  // parsedLeft = propertyHandler.calculator(parsedLeft);
143
143
  // // parsedLeft = handler.calculator
@@ -199,12 +199,6 @@ var FORMAT_ATTR_MAP = {
199
199
  d: {
200
200
  alias: 'path'
201
201
  },
202
- cx: {
203
- alias: 'x'
204
- },
205
- cy: {
206
- alias: 'y'
207
- },
208
202
  strokeDasharray: {
209
203
  alias: 'lineDash'
210
204
  },
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,10 +297,16 @@ 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) {
@@ -302,9 +325,11 @@ function rectToCommands(width, height, x, y, radius) {
302
325
  */
303
326
 
304
327
 
305
- function convertToPath(object) {
306
- var localTransform = object.getLocalTransform();
307
- var anchor = object.style.anchor;
328
+ function convertToPath(object, applyLocalTransform) {
329
+ if (applyLocalTransform === void 0) {
330
+ applyLocalTransform = true;
331
+ }
332
+
308
333
  var commands = [];
309
334
 
310
335
  switch (object.nodeName) {
@@ -321,9 +346,9 @@ function convertToPath(object) {
321
346
  {
322
347
  var _b = object.parsedStyle,
323
348
  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);
349
+ cx = _b.cx,
350
+ cy = _b.cy;
351
+ commands = ellipseToCommands(r.value, r.value, cx.value, cy.value);
327
352
  break;
328
353
  }
329
354
 
@@ -332,16 +357,16 @@ function convertToPath(object) {
332
357
  var _c = object.parsedStyle,
333
358
  rx = _c.rx,
334
359
  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);
360
+ cx = _c.cx,
361
+ cy = _c.cy;
362
+ commands = ellipseToCommands(rx.value, ry.value, cx.value, cy.value);
338
363
  break;
339
364
  }
340
365
 
341
366
  case _types.Shape.POLYLINE:
342
367
  case _types.Shape.POLYGON:
343
368
  var points = object.parsedStyle.points;
344
- commands = polygonToCommands(points.points);
369
+ commands = polygonToCommands(points.points, object.nodeName === _types.Shape.POLYGON);
345
370
  break;
346
371
 
347
372
  case _types.Shape.RECT:
@@ -355,11 +380,17 @@ function convertToPath(object) {
355
380
  break;
356
381
 
357
382
  case _types.Shape.PATH:
358
- commands = object.parsedStyle.path.curve;
383
+ var _e = object.parsedStyle.path,
384
+ curve = _e.curve,
385
+ zCommandIndexes = _e.zCommandIndexes;
386
+ commands = (0, _tslib.__spreadArray)([], (0, _tslib.__read)(curve), false);
387
+ zCommandIndexes.forEach(function (zIndex, index) {
388
+ commands.splice(zIndex + index, 1, ['Z']);
389
+ });
359
390
  break;
360
391
  }
361
392
 
362
393
  if (commands.length) {
363
- return commandsToPathString(commands, localTransform, anchor, object.parsedStyle);
394
+ return commandsToPathString(commands, object, applyLocalTransform);
364
395
  }
365
396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "5.0.23",
3
+ "version": "5.1.1",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "homepage": "https://github.com/antvis/g#readme",
40
40
  "dependencies": {
41
- "@antv/g-math": "^1.0.20",
41
+ "@antv/g-math": "^1.1.1",
42
42
  "@antv/util": "^3.0.0",
43
43
  "@types/offscreencanvas": "^2019.6.4",
44
44
  "d3-color": "^1.4.0",
@@ -53,5 +53,5 @@
53
53
  "scripts": {
54
54
  "umd": "webpack"
55
55
  },
56
- "gitHead": "e2325a6285d12ef05abd9f9e12cf095280006167"
56
+ "gitHead": "5152e91b7489c53f5d2a5c3d7cb645716c506f26"
57
57
  }