@antv/g 5.0.10 → 5.0.13

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 (44) hide show
  1. package/dist/index.umd.min.js +2 -2
  2. package/es/Canvas.js +42 -13
  3. package/es/display-objects/DisplayObject.d.ts +2 -0
  4. package/es/display-objects/DisplayObject.js +13 -1
  5. package/es/display-objects/Polygon.d.ts +2 -5
  6. package/es/display-objects/Polyline.d.ts +2 -6
  7. package/es/dom/FederatedPointerEvent.d.ts +6 -0
  8. package/es/dom/FederatedPointerEvent.js +8 -0
  9. package/es/plugins/EventPlugin.js +2 -1
  10. package/es/property-handlers/aabb.js +28 -24
  11. package/es/services/ContextService.d.ts +2 -1
  12. package/es/services/RenderingService.d.ts +2 -2
  13. package/es/services/RenderingService.js +2 -2
  14. package/es/services/SceneGraphService.d.ts +4 -2
  15. package/es/services/SceneGraphService.js +89 -67
  16. package/es/services/aabb/interfaces.d.ts +1 -0
  17. package/es/types.d.ts +17 -12
  18. package/es/utils/canvas.d.ts +1 -0
  19. package/es/utils/canvas.js +9 -6
  20. package/es/utils/path.js +13 -4
  21. package/es/utils/raf.d.ts +6 -3
  22. package/es/utils/raf.js +13 -14
  23. package/lib/Canvas.js +42 -11
  24. package/lib/display-objects/DisplayObject.d.ts +2 -0
  25. package/lib/display-objects/DisplayObject.js +13 -1
  26. package/lib/display-objects/Polygon.d.ts +2 -5
  27. package/lib/display-objects/Polyline.d.ts +2 -6
  28. package/lib/dom/FederatedPointerEvent.d.ts +6 -0
  29. package/lib/dom/FederatedPointerEvent.js +8 -0
  30. package/lib/plugins/EventPlugin.js +2 -1
  31. package/lib/property-handlers/aabb.js +28 -24
  32. package/lib/services/ContextService.d.ts +2 -1
  33. package/lib/services/RenderingService.d.ts +2 -2
  34. package/lib/services/RenderingService.js +1 -1
  35. package/lib/services/SceneGraphService.d.ts +4 -2
  36. package/lib/services/SceneGraphService.js +95 -67
  37. package/lib/services/aabb/interfaces.d.ts +1 -0
  38. package/lib/types.d.ts +17 -12
  39. package/lib/utils/canvas.d.ts +1 -0
  40. package/lib/utils/canvas.js +11 -5
  41. package/lib/utils/path.js +15 -4
  42. package/lib/utils/raf.d.ts +6 -3
  43. package/lib/utils/raf.js +19 -13
  44. package/package.json +5 -3
package/lib/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="offscreencanvas" />
1
2
  import type { vec2, vec3 } from 'gl-matrix';
2
3
  import type { ParsedPathStyleProps, ParsedPolylineStyleProps } from './display-objects';
3
4
  import type { DisplayObject } from './display-objects';
@@ -171,31 +172,35 @@ export interface CanvasConfig {
171
172
  renderer: IRenderer;
172
173
  /**
173
174
  * 容器
174
- * @type {string|HTMLElement}
175
175
  */
176
- container: string | HTMLElement;
176
+ container?: string | HTMLElement;
177
+ /**
178
+ * support OffscreenCanvas
179
+ */
180
+ canvas?: HTMLCanvasElement | OffscreenCanvas;
181
+ /**
182
+ * window.devicePixelRatio
183
+ */
184
+ devicePixelRatio?: number;
185
+ /**
186
+ * rAF
187
+ */
188
+ requestAnimationFrame?: (callback: FrameRequestCallback) => number;
189
+ cancelAnimationFrame?: (id: number) => void;
177
190
  /**
178
191
  * 画布宽度
179
- * @type {number}
180
192
  */
181
- width: number;
193
+ width?: number;
182
194
  /**
183
195
  * 画布高度
184
- * @type {number}
185
196
  */
186
- height: number;
197
+ height?: number;
187
198
  /**
188
199
  * 画布背景色
189
200
  */
190
201
  background?: ColorType;
191
- /**
192
- * 是否可监听
193
- * @type {boolean}
194
- */
195
- capture?: boolean;
196
202
  /**
197
203
  * 画布的 cursor 样式
198
- * @type {Cursor}
199
204
  */
200
205
  cursor?: Cursor;
201
206
  [key: string]: any;
@@ -3,3 +3,4 @@ import type { Canvas } from '../Canvas';
3
3
  * destroy existed canvas with the same id
4
4
  */
5
5
  export declare function cleanExistedCanvas(container: string | HTMLElement, canvas: Canvas): void;
6
+ export declare const isBrowser: boolean;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.cleanExistedCanvas = cleanExistedCanvas;
7
+ exports.isBrowser = void 0;
7
8
  var canvasMap = {};
8
9
  var defaultCanvasIdCounter = 0;
9
10
  /**
@@ -11,11 +12,16 @@ var defaultCanvasIdCounter = 0;
11
12
  */
12
13
 
13
14
  function cleanExistedCanvas(container, canvas) {
14
- var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
15
+ if (container) {
16
+ var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
15
17
 
16
- if (canvasMap[id]) {
17
- canvasMap[id].destroy();
18
+ if (canvasMap[id]) {
19
+ canvasMap[id].destroy();
20
+ }
21
+
22
+ canvasMap[id] = canvas;
18
23
  }
24
+ }
19
25
 
20
- canvasMap[id] = canvas;
21
- }
26
+ var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
27
+ exports.isBrowser = isBrowser;
package/lib/utils/path.js CHANGED
@@ -251,6 +251,12 @@ function commandsToPathString(commands, localTransform, anchor, parsedStyle) {
251
251
  _glMatrix.vec3.transformMat4(p3, p3, localTransform);
252
252
 
253
253
  path = "" + cur[0] + p1[0] + "," + p1[1] + "," + p2[0] + "," + p2[1] + "," + p3[0] + "," + p3[1];
254
+ } else if (cur[0] === 'A') {
255
+ var c = _glMatrix.vec3.fromValues(cur[6] - x, cur[7] - y, 0);
256
+
257
+ _glMatrix.vec3.transformMat4(c, c, localTransform);
258
+
259
+ path = "" + cur[0] + cur[1] + "," + cur[2] + "," + cur[3] + "," + cur[4] + "," + cur[5] + "," + c[0] + "," + c[1];
254
260
  }
255
261
 
256
262
  return prev += path;
@@ -278,8 +284,12 @@ function polygonToCommands(points) {
278
284
  });
279
285
  }
280
286
 
281
- function rectToCommands(width, height, x, y) {
282
- // FIXME: account for radius
287
+ function rectToCommands(width, height, x, y, radius) {
288
+ // @see https://gist.github.com/danielpquinn/dd966af424030d47e476
289
+ if (radius) {
290
+ return [['M', x, radius + y], ['A', radius, radius, 0, 0, 1, radius + x, y], ['L', width - radius + x, y], ['A', radius, radius, 0, 0, 1, width + x, radius + y], ['L', width + x, height - radius + y], ['A', radius, radius, 0, 0, 1, width - radius + x, height + y], ['L', radius + x, height + y], ['A', radius, radius, 0, 0, 1, x, height - radius + y], ['Z']];
291
+ }
292
+
283
293
  return [['M', x, y], ['L', x + width, y], ['L', x + width, y + height], ['L', x, y + height], ['Z']];
284
294
  }
285
295
  /**
@@ -341,8 +351,9 @@ function convertToPath(object) {
341
351
  width = _h.width,
342
352
  height = _h.height,
343
353
  x = _h.x,
344
- y = _h.y;
345
- commands = rectToCommands(width, height, x, y);
354
+ y = _h.y,
355
+ radius = _h.radius;
356
+ commands = rectToCommands(width, height, x, y, radius);
346
357
  break;
347
358
 
348
359
  case _types.SHAPE.Path:
@@ -1,3 +1,6 @@
1
- declare function requestAnimationFrame(fn: FrameRequestCallback): number;
2
- declare function cancelAnimationFrame(handler: number): void;
3
- export { requestAnimationFrame, cancelAnimationFrame };
1
+ /**
2
+ * use user-defined raf instead of requestAnimationFrame
3
+ */
4
+ export declare function patch(requestAFPatch: (callback: Function) => number, cancelAFPatch: (id: number) => void): void;
5
+ export declare const requestAnimationFrame: (callback: Function) => number;
6
+ export declare const cancelAnimationFrame: (id: number) => void;
package/lib/utils/raf.js CHANGED
@@ -3,20 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.cancelAnimationFrame = cancelAnimationFrame;
7
- exports.requestAnimationFrame = requestAnimationFrame;
6
+ exports.cancelAnimationFrame = void 0;
7
+ exports.patch = patch;
8
+ exports.requestAnimationFrame = void 0;
9
+
10
+ var _requestAnimationFramePolyfill = require("request-animation-frame-polyfill");
8
11
 
9
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
12
+ // import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-polyfill';
13
+ // export { requestAnimationFrame, cancelAnimationFrame };
14
+ var requestAF = _requestAnimationFramePolyfill.requestAnimationFrame;
15
+ var cancelAF = _requestAnimationFramePolyfill.cancelAnimationFrame;
16
+ /**
17
+ * use user-defined raf instead of requestAnimationFrame
18
+ */
10
19
 
11
- function requestAnimationFrame(fn) {
12
- var method = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : // eslint-disable-next-line @typescript-eslint/ban-types
13
- function (f) {
14
- return setTimeout(f, 16);
15
- };
16
- return method(fn);
20
+ function patch(requestAFPatch, cancelAFPatch) {
21
+ requestAF = requestAFPatch;
22
+ cancelAF = cancelAFPatch;
17
23
  }
18
24
 
19
- function cancelAnimationFrame(handler) {
20
- var method = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.cancelAnimationFrame ? window.cancelAnimationFrame : clearTimeout;
21
- return method(handler);
22
- }
25
+ var requestAnimationFrame = requestAF;
26
+ exports.requestAnimationFrame = requestAnimationFrame;
27
+ var cancelAnimationFrame = cancelAF;
28
+ exports.cancelAnimationFrame = cancelAnimationFrame;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "5.0.10",
3
+ "version": "5.0.13",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -37,18 +37,20 @@
37
37
  },
38
38
  "homepage": "https://github.com/antvis/g#readme",
39
39
  "dependencies": {
40
- "@antv/g-math": "^1.0.9",
40
+ "@antv/g-math": "^1.0.10",
41
41
  "@antv/path-util": "^2.0.14",
42
42
  "@antv/util": "^2.0.13",
43
+ "@types/offscreencanvas": "^2019.6.4",
43
44
  "d3-color": "^1.4.0",
44
45
  "eventemitter3": "^4.0.0",
45
46
  "gl-matrix": "^3.1.0",
46
47
  "mana-syringe": "^0.2.2",
48
+ "request-animation-frame-polyfill": "^1.1.2",
47
49
  "tapable": "^2.2.1",
48
50
  "tslib": "^2.3.1"
49
51
  },
50
52
  "scripts": {
51
53
  "umd": "webpack"
52
54
  },
53
- "gitHead": "4e7fa34bb4dd4bd6c50b0a458ae8b409b59903be"
55
+ "gitHead": "e713211a92d77d0820e3252c3e8704aefda9c2e7"
54
56
  }