@antv/g 5.0.9 → 5.0.10

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.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
@@ -42,7 +42,8 @@ function (_super) {
42
42
 
43
43
 
44
44
  _this.container = globalContainer.createChild();
45
- _this.Element = DisplayObject; // create document
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;
@@ -275,8 +298,11 @@ function (_super) {
275
298
 
276
299
  if (!renderer) {
277
300
  throw new Error('Renderer is required.');
278
- }
301
+ } // reset
302
+
279
303
 
304
+ this.inited = false;
305
+ this.readyPromise = undefined;
280
306
  this.loadCommonContainerModule();
281
307
  this.loadRendererContainerModule(renderer); // init context
282
308
 
@@ -286,6 +312,12 @@ function (_super) {
286
312
  contextService.init();
287
313
  this.renderingService.init().then(function () {
288
314
  _this.emit(CanvasEvent.READY, {});
315
+
316
+ if (_this.readyPromise) {
317
+ _this.resolveReadyPromise();
318
+ }
319
+
320
+ _this.inited = true;
289
321
  });
290
322
 
291
323
  if (renderer.getConfig().enableAutoRendering) {
@@ -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; // bubbling phase
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/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; // create document
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;
@@ -296,8 +319,11 @@ function (_super) {
296
319
 
297
320
  if (!renderer) {
298
321
  throw new Error('Renderer is required.');
299
- }
322
+ } // reset
323
+
300
324
 
325
+ this.inited = false;
326
+ this.readyPromise = undefined;
301
327
  this.loadCommonContainerModule();
302
328
  this.loadRendererContainerModule(renderer); // init context
303
329
 
@@ -307,6 +333,12 @@ function (_super) {
307
333
  contextService.init();
308
334
  this.renderingService.init().then(function () {
309
335
  _this.emit(CanvasEvent.READY, {});
336
+
337
+ if (_this.readyPromise) {
338
+ _this.resolveReadyPromise();
339
+ }
340
+
341
+ _this.inited = true;
310
342
  });
311
343
 
312
344
  if (renderer.getConfig().enableAutoRendering) {
@@ -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; // bubbling phase
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g",
3
- "version": "5.0.9",
3
+ "version": "5.0.10",
4
4
  "description": "A core module including ECS and DI container.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://github.com/antvis/g#readme",
39
39
  "dependencies": {
40
- "@antv/g-math": "^1.0.8",
40
+ "@antv/g-math": "^1.0.9",
41
41
  "@antv/path-util": "^2.0.14",
42
42
  "@antv/util": "^2.0.13",
43
43
  "d3-color": "^1.4.0",
@@ -50,5 +50,5 @@
50
50
  "scripts": {
51
51
  "umd": "webpack"
52
52
  },
53
- "gitHead": "a7b98694f386141877710e6b3a41695686deb048"
53
+ "gitHead": "4e7fa34bb4dd4bd6c50b0a458ae8b409b59903be"
54
54
  }