@antv/g 5.0.10 → 5.0.11

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.
package/es/Canvas.js CHANGED
@@ -8,7 +8,7 @@ import { RenderingContext, RENDER_REASON } from './services/RenderingContext';
8
8
  import { EventService } from './services/EventService';
9
9
  import { Camera, CAMERA_EVENT, CAMERA_PROJECTION_MODE, DefaultCamera } from './camera';
10
10
  import { containerModule as commonContainerModule } from './canvas-module';
11
- import { cancelAnimationFrame } from './utils/raf';
11
+ import { cancelAnimationFrame, requestAnimationFrame } from './utils/raf';
12
12
  import { Document, EventTarget, ElementEvent } from './dom';
13
13
  import { CustomElementRegistry } from './dom/CustomElementRegistry';
14
14
  import { globalContainer } from './global-module';
@@ -193,7 +193,8 @@ function (_super) {
193
193
  this.emit(CanvasEvent.BEFORE_DESTROY, function () {});
194
194
 
195
195
  if (this.frameId) {
196
- cancelAnimationFrame(this.frameId);
196
+ var cancelRAF = this.getConfig().cancelAnimationFrame || cancelAnimationFrame;
197
+ cancelRAF(this.frameId);
197
198
  } // unmount all children
198
199
 
199
200
 
@@ -284,10 +285,12 @@ function (_super) {
284
285
  Canvas.prototype.run = function () {
285
286
  var _this = this;
286
287
 
288
+ var rAF = this.getConfig().requestAnimationFrame || requestAnimationFrame;
289
+
287
290
  var tick = function tick() {
288
291
  _this.render();
289
292
 
290
- _this.frameId = requestAnimationFrame(tick);
293
+ _this.frameId = rAF(tick);
291
294
  };
292
295
 
293
296
  tick();
@@ -16,7 +16,9 @@ var DEFAULT_STYLE_PROPS = {
16
16
  origin: [0, 0, 0],
17
17
  opacity: 1,
18
18
  fillOpacity: 1,
19
- strokeOpacity: 1
19
+ strokeOpacity: 1,
20
+ fill: 'transparent',
21
+ stroke: 'transparent'
20
22
  };
21
23
  /**
22
24
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
@@ -131,7 +131,8 @@ function () {
131
131
 
132
132
  var $element = _this.contextService.getDomElement();
133
133
 
134
- var outside = $element && nativeEvent.target && nativeEvent.target !== $element && $element.contains && // @ts-ignore
134
+ var outside = $element && nativeEvent.target && nativeEvent.target !== $element && // @ts-ignore
135
+ $element.contains && // @ts-ignore
135
136
  !$element.contains(nativeEvent.target) ? 'outside' : '';
136
137
  var normalizedEvents = normalizeToPointerEvent(nativeEvent);
137
138
 
@@ -1,10 +1,11 @@
1
+ /// <reference types="offscreencanvas" />
1
2
  import { Syringe } from 'mana-syringe';
2
3
  export declare const ContextService: Syringe.DefinedToken;
3
4
  export interface ContextService<Context> {
4
5
  init: () => void;
5
6
  destroy: () => void;
6
7
  getContext: () => Context | null;
7
- getDomElement: () => HTMLElement | null;
8
+ getDomElement: () => HTMLElement | OffscreenCanvas | null;
8
9
  getDPR: () => number;
9
10
  getBoundingClientRect: () => DOMRect | undefined;
10
11
  resize: (width: number, height: number) => void;
package/es/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,17 +172,27 @@ 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
193
  width: number;
182
194
  /**
183
195
  * 画布高度
184
- * @type {number}
185
196
  */
186
197
  height: number;
187
198
  /**
@@ -190,12 +201,10 @@ export interface CanvasConfig {
190
201
  background?: ColorType;
191
202
  /**
192
203
  * 是否可监听
193
- * @type {boolean}
194
204
  */
195
205
  capture?: boolean;
196
206
  /**
197
207
  * 画布的 cursor 样式
198
- * @type {Cursor}
199
208
  */
200
209
  cursor?: Cursor;
201
210
  [key: string]: any;
@@ -5,11 +5,13 @@ var defaultCanvasIdCounter = 0;
5
5
  */
6
6
 
7
7
  export function cleanExistedCanvas(container, canvas) {
8
- var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
8
+ if (container) {
9
+ var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
9
10
 
10
- if (canvasMap[id]) {
11
- canvasMap[id].destroy();
12
- }
11
+ if (canvasMap[id]) {
12
+ canvasMap[id].destroy();
13
+ }
13
14
 
14
- canvasMap[id] = canvas;
15
+ canvasMap[id] = canvas;
16
+ }
15
17
  }
package/es/utils/path.js CHANGED
@@ -225,6 +225,10 @@ function commandsToPathString(commands, localTransform, anchor, parsedStyle) {
225
225
  vec3.transformMat4(p2, p2, localTransform);
226
226
  vec3.transformMat4(p3, p3, localTransform);
227
227
  path = "" + cur[0] + p1[0] + "," + p1[1] + "," + p2[0] + "," + p2[1] + "," + p3[0] + "," + p3[1];
228
+ } else if (cur[0] === 'A') {
229
+ var c = vec3.fromValues(cur[6] - x, cur[7] - y, 0);
230
+ vec3.transformMat4(c, c, localTransform);
231
+ path = "" + cur[0] + cur[1] + "," + cur[2] + "," + cur[3] + "," + cur[4] + "," + cur[5] + "," + c[0] + "," + c[1];
228
232
  }
229
233
 
230
234
  return prev += path;
@@ -252,8 +256,12 @@ function polygonToCommands(points) {
252
256
  });
253
257
  }
254
258
 
255
- function rectToCommands(width, height, x, y) {
256
- // FIXME: account for radius
259
+ function rectToCommands(width, height, x, y, radius) {
260
+ // @see https://gist.github.com/danielpquinn/dd966af424030d47e476
261
+ if (radius) {
262
+ 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']];
263
+ }
264
+
257
265
  return [['M', x, y], ['L', x + width, y], ['L', x + width, y + height], ['L', x, y + height], ['Z']];
258
266
  }
259
267
  /**
@@ -315,8 +323,9 @@ export function convertToPath(object) {
315
323
  width = _h.width,
316
324
  height = _h.height,
317
325
  x = _h.x,
318
- y = _h.y;
319
- commands = rectToCommands(width, height, x, y);
326
+ y = _h.y,
327
+ radius = _h.radius;
328
+ commands = rectToCommands(width, height, x, y, radius);
320
329
  break;
321
330
 
322
331
  case SHAPE.Path:
package/es/utils/raf.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- declare function requestAnimationFrame(fn: FrameRequestCallback): number;
2
- declare function cancelAnimationFrame(handler: number): void;
1
+ import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-polyfill';
3
2
  export { requestAnimationFrame, cancelAnimationFrame };
package/es/utils/raf.js CHANGED
@@ -1,16 +1,2 @@
1
- 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); }
2
-
3
- function requestAnimationFrame(fn) {
4
- var method = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : // eslint-disable-next-line @typescript-eslint/ban-types
5
- function (f) {
6
- return setTimeout(f, 16);
7
- };
8
- return method(fn);
9
- }
10
-
11
- function cancelAnimationFrame(handler) {
12
- var method = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.cancelAnimationFrame ? window.cancelAnimationFrame : clearTimeout;
13
- return method(handler);
14
- }
15
-
1
+ import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-polyfill';
16
2
  export { requestAnimationFrame, cancelAnimationFrame };
package/lib/Canvas.js CHANGED
@@ -214,7 +214,9 @@ function (_super) {
214
214
  this.emit(CanvasEvent.BEFORE_DESTROY, function () {});
215
215
 
216
216
  if (this.frameId) {
217
- (0, _raf.cancelAnimationFrame)(this.frameId);
217
+ var cancelRAF = this.getConfig().cancelAnimationFrame || _raf.cancelAnimationFrame;
218
+
219
+ cancelRAF(this.frameId);
218
220
  } // unmount all children
219
221
 
220
222
 
@@ -305,10 +307,12 @@ function (_super) {
305
307
  Canvas.prototype.run = function () {
306
308
  var _this = this;
307
309
 
310
+ var rAF = this.getConfig().requestAnimationFrame || _raf.requestAnimationFrame;
311
+
308
312
  var tick = function tick() {
309
313
  _this.render();
310
314
 
311
- _this.frameId = requestAnimationFrame(tick);
315
+ _this.frameId = rAF(tick);
312
316
  };
313
317
 
314
318
  tick();
@@ -34,7 +34,9 @@ var DEFAULT_STYLE_PROPS = {
34
34
  origin: [0, 0, 0],
35
35
  opacity: 1,
36
36
  fillOpacity: 1,
37
- strokeOpacity: 1
37
+ strokeOpacity: 1,
38
+ fill: 'transparent',
39
+ stroke: 'transparent'
38
40
  };
39
41
  /**
40
42
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
@@ -145,7 +145,8 @@ function () {
145
145
 
146
146
  var $element = _this.contextService.getDomElement();
147
147
 
148
- var outside = $element && nativeEvent.target && nativeEvent.target !== $element && $element.contains && // @ts-ignore
148
+ var outside = $element && nativeEvent.target && nativeEvent.target !== $element && // @ts-ignore
149
+ $element.contains && // @ts-ignore
149
150
  !$element.contains(nativeEvent.target) ? 'outside' : '';
150
151
  var normalizedEvents = (0, _event.normalizeToPointerEvent)(nativeEvent);
151
152
 
@@ -1,10 +1,11 @@
1
+ /// <reference types="offscreencanvas" />
1
2
  import { Syringe } from 'mana-syringe';
2
3
  export declare const ContextService: Syringe.DefinedToken;
3
4
  export interface ContextService<Context> {
4
5
  init: () => void;
5
6
  destroy: () => void;
6
7
  getContext: () => Context | null;
7
- getDomElement: () => HTMLElement | null;
8
+ getDomElement: () => HTMLElement | OffscreenCanvas | null;
8
9
  getDPR: () => number;
9
10
  getBoundingClientRect: () => DOMRect | undefined;
10
11
  resize: (width: number, height: number) => void;
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,17 +172,27 @@ 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
193
  width: number;
182
194
  /**
183
195
  * 画布高度
184
- * @type {number}
185
196
  */
186
197
  height: number;
187
198
  /**
@@ -190,12 +201,10 @@ export interface CanvasConfig {
190
201
  background?: ColorType;
191
202
  /**
192
203
  * 是否可监听
193
- * @type {boolean}
194
204
  */
195
205
  capture?: boolean;
196
206
  /**
197
207
  * 画布的 cursor 样式
198
- * @type {Cursor}
199
208
  */
200
209
  cursor?: Cursor;
201
210
  [key: string]: any;
@@ -11,11 +11,13 @@ var defaultCanvasIdCounter = 0;
11
11
  */
12
12
 
13
13
  function cleanExistedCanvas(container, canvas) {
14
- var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
14
+ if (container) {
15
+ var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
15
16
 
16
- if (canvasMap[id]) {
17
- canvasMap[id].destroy();
18
- }
17
+ if (canvasMap[id]) {
18
+ canvasMap[id].destroy();
19
+ }
19
20
 
20
- canvasMap[id] = canvas;
21
+ canvasMap[id] = canvas;
22
+ }
21
23
  }
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,2 @@
1
- declare function requestAnimationFrame(fn: FrameRequestCallback): number;
2
- declare function cancelAnimationFrame(handler: number): void;
1
+ import { requestAnimationFrame, cancelAnimationFrame } from 'request-animation-frame-polyfill';
3
2
  export { requestAnimationFrame, cancelAnimationFrame };
package/lib/utils/raf.js CHANGED
@@ -3,20 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.cancelAnimationFrame = cancelAnimationFrame;
7
- exports.requestAnimationFrame = requestAnimationFrame;
8
-
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); }
10
-
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);
17
- }
6
+ Object.defineProperty(exports, "cancelAnimationFrame", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _requestAnimationFramePolyfill.cancelAnimationFrame;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "requestAnimationFrame", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _requestAnimationFramePolyfill.requestAnimationFrame;
16
+ }
17
+ });
18
18
 
19
- function cancelAnimationFrame(handler) {
20
- var method = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.cancelAnimationFrame ? window.cancelAnimationFrame : clearTimeout;
21
- return method(handler);
22
- }
19
+ var _requestAnimationFramePolyfill = require("request-animation-frame-polyfill");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "5.0.10",
3
+ "version": "5.0.11",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -40,15 +40,17 @@
40
40
  "@antv/g-math": "^1.0.9",
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": "6b7cd8851e36923301115549bef7b003ae09a4b0"
54
56
  }