@antv/g 5.0.8 → 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/dist/index.umd.min.js +2 -2
- package/es/Canvas.d.ts +4 -0
- package/es/Canvas.js +40 -5
- package/es/display-objects/DisplayObject.js +3 -1
- package/es/plugins/EventPlugin.js +2 -1
- package/es/services/ContextService.d.ts +2 -1
- package/es/services/EventService.js +4 -2
- package/es/types.d.ts +15 -6
- package/es/utils/canvas.js +7 -5
- package/es/utils/path.js +13 -4
- package/es/utils/raf.d.ts +1 -2
- package/es/utils/raf.js +1 -15
- package/lib/Canvas.d.ts +4 -0
- package/lib/Canvas.js +40 -4
- package/lib/display-objects/DisplayObject.js +3 -1
- package/lib/plugins/EventPlugin.js +2 -1
- package/lib/services/ContextService.d.ts +2 -1
- package/lib/services/EventService.js +4 -2
- package/lib/types.d.ts +15 -6
- package/lib/utils/canvas.js +7 -5
- package/lib/utils/path.js +15 -4
- package/lib/utils/raf.d.ts +1 -2
- package/lib/utils/raf.js +13 -16
- package/package.json +5 -3
package/es/Canvas.d.ts
CHANGED
|
@@ -48,6 +48,9 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
48
48
|
*/
|
|
49
49
|
private eventService;
|
|
50
50
|
private renderingService;
|
|
51
|
+
private inited;
|
|
52
|
+
private readyPromise;
|
|
53
|
+
private resolveReadyPromise;
|
|
51
54
|
constructor(config: CanvasConfig);
|
|
52
55
|
private initRenderingContext;
|
|
53
56
|
private initDefaultCamera;
|
|
@@ -71,6 +74,7 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
71
74
|
rendered: number;
|
|
72
75
|
};
|
|
73
76
|
getComputedStyle(node: DisplayObject): any;
|
|
77
|
+
get ready(): Promise<any>;
|
|
74
78
|
destroy(destroyScenegraph?: boolean): void;
|
|
75
79
|
/**
|
|
76
80
|
* compatible with G 3.0
|
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';
|
|
@@ -42,7 +42,8 @@ function (_super) {
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
_this.container = globalContainer.createChild();
|
|
45
|
-
_this.Element = DisplayObject;
|
|
45
|
+
_this.Element = DisplayObject;
|
|
46
|
+
_this.inited = false; // create document
|
|
46
47
|
|
|
47
48
|
_this.document = new Document();
|
|
48
49
|
_this.document.defaultView = _this; // create registry of custom elements
|
|
@@ -162,6 +163,28 @@ function (_super) {
|
|
|
162
163
|
return node.parsedStyle;
|
|
163
164
|
};
|
|
164
165
|
|
|
166
|
+
Object.defineProperty(Canvas.prototype, "ready", {
|
|
167
|
+
get: function get() {
|
|
168
|
+
var _this = this;
|
|
169
|
+
|
|
170
|
+
if (!this.readyPromise) {
|
|
171
|
+
this.readyPromise = new Promise(function (resolve) {
|
|
172
|
+
_this.resolveReadyPromise = function () {
|
|
173
|
+
resolve(_this);
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (this.inited) {
|
|
178
|
+
this.resolveReadyPromise();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return this.readyPromise;
|
|
183
|
+
},
|
|
184
|
+
enumerable: false,
|
|
185
|
+
configurable: true
|
|
186
|
+
});
|
|
187
|
+
|
|
165
188
|
Canvas.prototype.destroy = function (destroyScenegraph) {
|
|
166
189
|
if (destroyScenegraph === void 0) {
|
|
167
190
|
destroyScenegraph = true;
|
|
@@ -170,7 +193,8 @@ function (_super) {
|
|
|
170
193
|
this.emit(CanvasEvent.BEFORE_DESTROY, function () {});
|
|
171
194
|
|
|
172
195
|
if (this.frameId) {
|
|
173
|
-
|
|
196
|
+
var cancelRAF = this.getConfig().cancelAnimationFrame || cancelAnimationFrame;
|
|
197
|
+
cancelRAF(this.frameId);
|
|
174
198
|
} // unmount all children
|
|
175
199
|
|
|
176
200
|
|
|
@@ -261,10 +285,12 @@ function (_super) {
|
|
|
261
285
|
Canvas.prototype.run = function () {
|
|
262
286
|
var _this = this;
|
|
263
287
|
|
|
288
|
+
var rAF = this.getConfig().requestAnimationFrame || requestAnimationFrame;
|
|
289
|
+
|
|
264
290
|
var tick = function tick() {
|
|
265
291
|
_this.render();
|
|
266
292
|
|
|
267
|
-
_this.frameId =
|
|
293
|
+
_this.frameId = rAF(tick);
|
|
268
294
|
};
|
|
269
295
|
|
|
270
296
|
tick();
|
|
@@ -275,8 +301,11 @@ function (_super) {
|
|
|
275
301
|
|
|
276
302
|
if (!renderer) {
|
|
277
303
|
throw new Error('Renderer is required.');
|
|
278
|
-
}
|
|
304
|
+
} // reset
|
|
305
|
+
|
|
279
306
|
|
|
307
|
+
this.inited = false;
|
|
308
|
+
this.readyPromise = undefined;
|
|
280
309
|
this.loadCommonContainerModule();
|
|
281
310
|
this.loadRendererContainerModule(renderer); // init context
|
|
282
311
|
|
|
@@ -286,6 +315,12 @@ function (_super) {
|
|
|
286
315
|
contextService.init();
|
|
287
316
|
this.renderingService.init().then(function () {
|
|
288
317
|
_this.emit(CanvasEvent.READY, {});
|
|
318
|
+
|
|
319
|
+
if (_this.readyPromise) {
|
|
320
|
+
_this.resolveReadyPromise();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
_this.inited = true;
|
|
289
324
|
});
|
|
290
325
|
|
|
291
326
|
if (renderer.getConfig().enableAutoRendering) {
|
|
@@ -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 &&
|
|
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;
|
|
@@ -595,11 +595,13 @@ function (_super) {
|
|
|
595
595
|
e.eventPhase = e.AT_TARGET;
|
|
596
596
|
e.currentTarget = e.target;
|
|
597
597
|
this.notifyTarget(e, type);
|
|
598
|
-
if (e.propagationStopped || e.propagationImmediatelyStopped) return; //
|
|
598
|
+
if (e.propagationStopped || e.propagationImmediatelyStopped) return; // find current target in composed path
|
|
599
|
+
|
|
600
|
+
var index = composedPath.indexOf(e.currentTarget); // bubbling phase
|
|
599
601
|
|
|
600
602
|
e.eventPhase = e.BUBBLING_PHASE;
|
|
601
603
|
|
|
602
|
-
for (var i = 1; i < composedPath.length; i++) {
|
|
604
|
+
for (var i = index + 1; i < composedPath.length; i++) {
|
|
603
605
|
e.currentTarget = composedPath[i];
|
|
604
606
|
this.notifyTarget(e, type);
|
|
605
607
|
if (e.propagationStopped || e.propagationImmediatelyStopped) return;
|
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
|
|
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;
|
package/es/utils/canvas.js
CHANGED
|
@@ -5,11 +5,13 @@ var defaultCanvasIdCounter = 0;
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export function cleanExistedCanvas(container, canvas) {
|
|
8
|
-
|
|
8
|
+
if (container) {
|
|
9
|
+
var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (canvasMap[id]) {
|
|
12
|
+
canvasMap[id].destroy();
|
|
13
|
+
}
|
|
13
14
|
|
|
14
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.d.ts
CHANGED
|
@@ -48,6 +48,9 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
48
48
|
*/
|
|
49
49
|
private eventService;
|
|
50
50
|
private renderingService;
|
|
51
|
+
private inited;
|
|
52
|
+
private readyPromise;
|
|
53
|
+
private resolveReadyPromise;
|
|
51
54
|
constructor(config: CanvasConfig);
|
|
52
55
|
private initRenderingContext;
|
|
53
56
|
private initDefaultCamera;
|
|
@@ -71,6 +74,7 @@ export declare class Canvas extends EventTarget implements ICanvas {
|
|
|
71
74
|
rendered: number;
|
|
72
75
|
};
|
|
73
76
|
getComputedStyle(node: DisplayObject): any;
|
|
77
|
+
get ready(): Promise<any>;
|
|
74
78
|
destroy(destroyScenegraph?: boolean): void;
|
|
75
79
|
/**
|
|
76
80
|
* compatible with G 3.0
|
package/lib/Canvas.js
CHANGED
|
@@ -64,7 +64,8 @@ function (_super) {
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
_this.container = _globalModule.globalContainer.createChild();
|
|
67
|
-
_this.Element = _DisplayObject.DisplayObject;
|
|
67
|
+
_this.Element = _DisplayObject.DisplayObject;
|
|
68
|
+
_this.inited = false; // create document
|
|
68
69
|
|
|
69
70
|
_this.document = new _dom.Document();
|
|
70
71
|
_this.document.defaultView = _this; // create registry of custom elements
|
|
@@ -183,6 +184,28 @@ function (_super) {
|
|
|
183
184
|
return node.parsedStyle;
|
|
184
185
|
};
|
|
185
186
|
|
|
187
|
+
Object.defineProperty(Canvas.prototype, "ready", {
|
|
188
|
+
get: function get() {
|
|
189
|
+
var _this = this;
|
|
190
|
+
|
|
191
|
+
if (!this.readyPromise) {
|
|
192
|
+
this.readyPromise = new Promise(function (resolve) {
|
|
193
|
+
_this.resolveReadyPromise = function () {
|
|
194
|
+
resolve(_this);
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (this.inited) {
|
|
199
|
+
this.resolveReadyPromise();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return this.readyPromise;
|
|
204
|
+
},
|
|
205
|
+
enumerable: false,
|
|
206
|
+
configurable: true
|
|
207
|
+
});
|
|
208
|
+
|
|
186
209
|
Canvas.prototype.destroy = function (destroyScenegraph) {
|
|
187
210
|
if (destroyScenegraph === void 0) {
|
|
188
211
|
destroyScenegraph = true;
|
|
@@ -191,7 +214,9 @@ function (_super) {
|
|
|
191
214
|
this.emit(CanvasEvent.BEFORE_DESTROY, function () {});
|
|
192
215
|
|
|
193
216
|
if (this.frameId) {
|
|
194
|
-
(
|
|
217
|
+
var cancelRAF = this.getConfig().cancelAnimationFrame || _raf.cancelAnimationFrame;
|
|
218
|
+
|
|
219
|
+
cancelRAF(this.frameId);
|
|
195
220
|
} // unmount all children
|
|
196
221
|
|
|
197
222
|
|
|
@@ -282,10 +307,12 @@ function (_super) {
|
|
|
282
307
|
Canvas.prototype.run = function () {
|
|
283
308
|
var _this = this;
|
|
284
309
|
|
|
310
|
+
var rAF = this.getConfig().requestAnimationFrame || _raf.requestAnimationFrame;
|
|
311
|
+
|
|
285
312
|
var tick = function tick() {
|
|
286
313
|
_this.render();
|
|
287
314
|
|
|
288
|
-
_this.frameId =
|
|
315
|
+
_this.frameId = rAF(tick);
|
|
289
316
|
};
|
|
290
317
|
|
|
291
318
|
tick();
|
|
@@ -296,8 +323,11 @@ function (_super) {
|
|
|
296
323
|
|
|
297
324
|
if (!renderer) {
|
|
298
325
|
throw new Error('Renderer is required.');
|
|
299
|
-
}
|
|
326
|
+
} // reset
|
|
327
|
+
|
|
300
328
|
|
|
329
|
+
this.inited = false;
|
|
330
|
+
this.readyPromise = undefined;
|
|
301
331
|
this.loadCommonContainerModule();
|
|
302
332
|
this.loadRendererContainerModule(renderer); // init context
|
|
303
333
|
|
|
@@ -307,6 +337,12 @@ function (_super) {
|
|
|
307
337
|
contextService.init();
|
|
308
338
|
this.renderingService.init().then(function () {
|
|
309
339
|
_this.emit(CanvasEvent.READY, {});
|
|
340
|
+
|
|
341
|
+
if (_this.readyPromise) {
|
|
342
|
+
_this.resolveReadyPromise();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
_this.inited = true;
|
|
310
346
|
});
|
|
311
347
|
|
|
312
348
|
if (renderer.getConfig().enableAutoRendering) {
|
|
@@ -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 &&
|
|
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;
|
|
@@ -623,11 +623,13 @@ function (_super) {
|
|
|
623
623
|
e.eventPhase = e.AT_TARGET;
|
|
624
624
|
e.currentTarget = e.target;
|
|
625
625
|
this.notifyTarget(e, type);
|
|
626
|
-
if (e.propagationStopped || e.propagationImmediatelyStopped) return; //
|
|
626
|
+
if (e.propagationStopped || e.propagationImmediatelyStopped) return; // find current target in composed path
|
|
627
|
+
|
|
628
|
+
var index = composedPath.indexOf(e.currentTarget); // bubbling phase
|
|
627
629
|
|
|
628
630
|
e.eventPhase = e.BUBBLING_PHASE;
|
|
629
631
|
|
|
630
|
-
for (var i = 1; i < composedPath.length; i++) {
|
|
632
|
+
for (var i = index + 1; i < composedPath.length; i++) {
|
|
631
633
|
e.currentTarget = composedPath[i];
|
|
632
634
|
this.notifyTarget(e, type);
|
|
633
635
|
if (e.propagationStopped || e.propagationImmediatelyStopped) return;
|
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
|
|
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;
|
package/lib/utils/canvas.js
CHANGED
|
@@ -11,11 +11,13 @@ var defaultCanvasIdCounter = 0;
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
function cleanExistedCanvas(container, canvas) {
|
|
14
|
-
|
|
14
|
+
if (container) {
|
|
15
|
+
var id = typeof container === 'string' ? container : container.id || defaultCanvasIdCounter++;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
if (canvasMap[id]) {
|
|
18
|
+
canvasMap[id].destroy();
|
|
19
|
+
}
|
|
19
20
|
|
|
20
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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:
|
package/lib/utils/raf.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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.
|
|
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",
|
|
@@ -37,18 +37,20 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/antvis/g#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@antv/g-math": "^1.0.
|
|
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": "
|
|
55
|
+
"gitHead": "6b7cd8851e36923301115549bef7b003ae09a4b0"
|
|
54
56
|
}
|