@antv/g-lite 1.0.68 → 1.0.69

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.js CHANGED
@@ -3254,25 +3254,6 @@ function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
3254
3254
  return [hasFill, hasStroke];
3255
3255
  }
3256
3256
 
3257
- var AsyncParallelHook = /*#__PURE__*/function () {
3258
- function AsyncParallelHook() {
3259
- this.callbacks = [];
3260
- }
3261
- var _proto = AsyncParallelHook.prototype;
3262
- _proto.tapPromise = function tapPromise(options, fn) {
3263
- this.callbacks.push(fn);
3264
- };
3265
- _proto.promise = function promise() {
3266
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3267
- args[_key] = arguments[_key];
3268
- }
3269
- return Promise.all(this.callbacks.map(function (callback) {
3270
- return callback.apply(void 0, args);
3271
- }));
3272
- };
3273
- return AsyncParallelHook;
3274
- }();
3275
-
3276
3257
  var AsyncSeriesWaterfallHook = /*#__PURE__*/function () {
3277
3258
  function AsyncSeriesWaterfallHook() {
3278
3259
  this.callbacks = [];
@@ -12332,7 +12313,7 @@ var RenderingService = /*#__PURE__*/function () {
12332
12313
  /**
12333
12314
  * called before any frame rendered
12334
12315
  */
12335
- init: new AsyncParallelHook(),
12316
+ init: new SyncHook(),
12336
12317
  /**
12337
12318
  * only dirty object which has sth changed will be rendered
12338
12319
  */
@@ -12383,32 +12364,15 @@ var RenderingService = /*#__PURE__*/function () {
12383
12364
  this.context = context;
12384
12365
  }
12385
12366
  var _proto = RenderingService.prototype;
12386
- _proto.init = /*#__PURE__*/function () {
12387
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
12388
- var context;
12389
- return _regeneratorRuntime().wrap(function _callee$(_context) {
12390
- while (1) switch (_context.prev = _context.next) {
12391
- case 0:
12392
- context = _extends({}, this.globalRuntime, this.context); // register rendering plugins
12393
- this.context.renderingPlugins.forEach(function (plugin) {
12394
- plugin.apply(context, runtime);
12395
- });
12396
- // await this.hooks.init.callPromise();
12397
- _context.next = 4;
12398
- return this.hooks.init.promise();
12399
- case 4:
12400
- this.inited = true;
12401
- case 5:
12402
- case "end":
12403
- return _context.stop();
12404
- }
12405
- }, _callee, this);
12406
- }));
12407
- function init() {
12408
- return _init.apply(this, arguments);
12409
- }
12410
- return init;
12411
- }();
12367
+ _proto.init = function init() {
12368
+ var context = _extends({}, this.globalRuntime, this.context);
12369
+ // register rendering plugins
12370
+ this.context.renderingPlugins.forEach(function (plugin) {
12371
+ plugin.apply(context, runtime);
12372
+ });
12373
+ this.hooks.init.call();
12374
+ this.inited = true;
12375
+ };
12412
12376
  _proto.getStats = function getStats() {
12413
12377
  return this.stats;
12414
12378
  }
@@ -14409,20 +14373,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
14409
14373
  runtime.sceneGraphService.dirtifyToRoot(object);
14410
14374
  renderingService.dirtify();
14411
14375
  };
14412
- renderingService.hooks.init.tapPromise(PrepareRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14413
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14414
- while (1) switch (_context.prev = _context.next) {
14415
- case 0:
14416
- canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
14417
- canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
14418
- canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
14419
- canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14420
- case 4:
14421
- case "end":
14422
- return _context.stop();
14423
- }
14424
- }, _callee);
14425
- })));
14376
+ renderingService.hooks.init.tap(PrepareRendererPlugin.tag, function () {
14377
+ canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
14378
+ canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
14379
+ canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
14380
+ canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14381
+ });
14426
14382
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
14427
14383
  canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
14428
14384
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
@@ -14509,6 +14465,7 @@ function isCanvas(value) {
14509
14465
  CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
14510
14466
  CanvasEvent["RESIZE"] = "resize";
14511
14467
  CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
14468
+ CanvasEvent["RENDERER_CHANGED"] = "rendererchanged";
14512
14469
  })(exports.CanvasEvent || (exports.CanvasEvent = {}));
14513
14470
  var DEFAULT_CAMERA_Z = 500;
14514
14471
  var DEFAULT_CAMERA_NEAR = 0.1;
@@ -14657,23 +14614,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14657
14614
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
14658
14615
  });
14659
14616
  _this.initDefaultCamera(canvasWidth, canvasHeight);
14660
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14661
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14662
- while (1) switch (_context.prev = _context.next) {
14663
- case 0:
14664
- _context.next = 2;
14665
- return _this.initRenderer(renderer);
14666
- case 2:
14667
- _this.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
14668
- if (_this.readyPromise) {
14669
- _this.resolveReadyPromise();
14670
- }
14671
- case 4:
14672
- case "end":
14673
- return _context.stop();
14674
- }
14675
- }, _callee);
14676
- }))();
14617
+ _this.initRenderer(renderer, true);
14677
14618
  return _this;
14678
14619
  }
14679
14620
  var _proto = Canvas.prototype;
@@ -14851,123 +14792,119 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14851
14792
  var _this4 = this;
14852
14793
  var tick = function tick() {
14853
14794
  _this4.render();
14854
- _this4.frameId = requestAnimationFrame(tick);
14795
+ _this4.frameId = _this4.requestAnimationFrame(tick);
14855
14796
  };
14856
14797
  tick();
14857
14798
  };
14858
- _proto.initRenderer = /*#__PURE__*/function () {
14859
- var _initRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderer) {
14860
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
14861
- while (1) switch (_context2.prev = _context2.next) {
14862
- case 0:
14863
- if (renderer) {
14864
- _context2.next = 2;
14865
- break;
14866
- }
14867
- throw new Error('Renderer is required.');
14868
- case 2:
14869
- // reset
14870
- this.inited = false;
14871
- this.readyPromise = undefined;
14872
- // FIXME: should re-create here?
14873
- this.context.rBushRoot = new RBush__default['default']();
14874
- // reset rendering plugins
14875
- this.context.renderingPlugins = [];
14876
- this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
14877
- //
14878
- this.loadRendererContainerModule(renderer);
14879
- // init context service
14880
- this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
14881
- // init rendering service
14882
- this.context.renderingService = new RenderingService(runtime, this.context);
14883
- // init event service
14884
- this.context.eventService = new EventService(runtime, this.context);
14885
- this.context.eventService.init();
14886
- _context2.next = 14;
14887
- return this.context.contextService.init();
14888
- case 14:
14889
- _context2.next = 16;
14890
- return this.context.renderingService.init();
14891
- case 16:
14892
- this.inited = true;
14893
- this.getRoot().forEach(function (node) {
14894
- var renderable = node.renderable;
14895
- if (renderable) {
14896
- renderable.renderBoundsDirty = true;
14897
- renderable.boundsDirty = true;
14898
- renderable.dirty = true;
14899
- }
14900
- });
14901
- // keep current scenegraph unchanged, just trigger mounted event
14902
- this.mountChildren(this.getRoot());
14903
- if (renderer.getConfig().enableAutoRendering) {
14904
- this.run();
14905
- }
14906
- case 20:
14907
- case "end":
14908
- return _context2.stop();
14799
+ _proto.initRenderer = function initRenderer(renderer, firstContentfullPaint) {
14800
+ var _this5 = this;
14801
+ if (firstContentfullPaint === void 0) {
14802
+ firstContentfullPaint = false;
14803
+ }
14804
+ if (!renderer) {
14805
+ throw new Error('Renderer is required.');
14806
+ }
14807
+ // reset
14808
+ this.inited = false;
14809
+ this.readyPromise = undefined;
14810
+ // FIXME: should re-create here?
14811
+ this.context.rBushRoot = new RBush__default['default']();
14812
+ // reset rendering plugins
14813
+ this.context.renderingPlugins = [];
14814
+ this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
14815
+ //
14816
+ this.loadRendererContainerModule(renderer);
14817
+ // init context service
14818
+ this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
14819
+ // init rendering service
14820
+ this.context.renderingService = new RenderingService(runtime, this.context);
14821
+ // init event service
14822
+ this.context.eventService = new EventService(runtime, this.context);
14823
+ this.context.eventService.init();
14824
+ if (this.context.contextService.init) {
14825
+ this.context.contextService.init();
14826
+ this.initRenderingService(renderer, firstContentfullPaint);
14827
+ if (firstContentfullPaint) {
14828
+ this.requestAnimationFrame(function () {
14829
+ _this5.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
14830
+ });
14831
+ if (this.readyPromise) {
14832
+ this.resolveReadyPromise();
14909
14833
  }
14910
- }, _callee2, this);
14911
- }));
14912
- function initRenderer(_x) {
14913
- return _initRenderer.apply(this, arguments);
14834
+ } else {
14835
+ this.dispatchEvent(new CustomEvent(exports.CanvasEvent.RENDERER_CHANGED));
14836
+ }
14837
+ } else {
14838
+ this.context.contextService.initAsync().then(function () {
14839
+ _this5.initRenderingService(renderer, firstContentfullPaint);
14840
+ if (firstContentfullPaint) {
14841
+ _this5.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
14842
+ if (_this5.readyPromise) {
14843
+ _this5.resolveReadyPromise();
14844
+ }
14845
+ } else {
14846
+ _this5.dispatchEvent(new CustomEvent(exports.CanvasEvent.RENDERER_CHANGED));
14847
+ }
14848
+ });
14914
14849
  }
14915
- return initRenderer;
14916
- }();
14850
+ };
14851
+ _proto.initRenderingService = function initRenderingService(renderer, firstContentfullPaint) {
14852
+ if (firstContentfullPaint === void 0) {
14853
+ firstContentfullPaint = false;
14854
+ }
14855
+ this.context.renderingService.init();
14856
+ this.inited = true;
14857
+ if (!firstContentfullPaint) {
14858
+ this.getRoot().forEach(function (node) {
14859
+ var renderable = node.renderable;
14860
+ if (renderable) {
14861
+ renderable.renderBoundsDirty = true;
14862
+ renderable.boundsDirty = true;
14863
+ renderable.dirty = true;
14864
+ }
14865
+ });
14866
+ }
14867
+ // keep current scenegraph unchanged, just trigger mounted event
14868
+ this.mountChildren(this.getRoot());
14869
+ if (renderer.getConfig().enableAutoRendering) {
14870
+ this.run();
14871
+ }
14872
+ };
14917
14873
  _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
14918
- var _this5 = this;
14874
+ var _this6 = this;
14919
14875
  // load other container modules provided by g-canvas/g-svg/g-webgl
14920
14876
  var plugins = renderer.getPlugins();
14921
14877
  plugins.forEach(function (plugin) {
14922
- plugin.context = _this5.context;
14878
+ plugin.context = _this6.context;
14923
14879
  plugin.init(runtime);
14924
14880
  });
14925
14881
  };
14926
- _proto.setRenderer = /*#__PURE__*/function () {
14927
- var _setRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(renderer) {
14928
- var canvasConfig, oldRenderer;
14929
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
14930
- while (1) switch (_context3.prev = _context3.next) {
14931
- case 0:
14932
- // update canvas' config
14933
- canvasConfig = this.getConfig();
14934
- if (!(canvasConfig.renderer === renderer)) {
14935
- _context3.next = 3;
14936
- break;
14937
- }
14938
- return _context3.abrupt("return");
14939
- case 3:
14940
- oldRenderer = canvasConfig.renderer;
14941
- canvasConfig.renderer = renderer;
14942
- // keep all children undestroyed
14943
- this.destroy(false, true);
14944
- // destroy all plugins, reverse will mutate origin array
14945
- [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
14946
- plugin.destroy(runtime);
14947
- });
14948
- _context3.next = 9;
14949
- return this.initRenderer(renderer);
14950
- case 9:
14951
- case "end":
14952
- return _context3.stop();
14953
- }
14954
- }, _callee3, this);
14955
- }));
14956
- function setRenderer(_x2) {
14957
- return _setRenderer.apply(this, arguments);
14882
+ _proto.setRenderer = function setRenderer(renderer) {
14883
+ // update canvas' config
14884
+ var canvasConfig = this.getConfig();
14885
+ if (canvasConfig.renderer === renderer) {
14886
+ return;
14958
14887
  }
14959
- return setRenderer;
14960
- }();
14888
+ var oldRenderer = canvasConfig.renderer;
14889
+ canvasConfig.renderer = renderer;
14890
+ // keep all children undestroyed
14891
+ this.destroy(false, true);
14892
+ // destroy all plugins, reverse will mutate origin array
14893
+ [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
14894
+ plugin.destroy(runtime);
14895
+ });
14896
+ this.initRenderer(renderer);
14897
+ };
14961
14898
  _proto.setCursor = function setCursor(cursor) {
14962
14899
  var canvasConfig = this.getConfig();
14963
14900
  canvasConfig.cursor = cursor;
14964
14901
  this.getContextService().applyCursorStyle(cursor);
14965
14902
  };
14966
14903
  _proto.unmountChildren = function unmountChildren(parent) {
14967
- var _this6 = this;
14904
+ var _this7 = this;
14968
14905
  // unmountChildren recursively
14969
14906
  parent.childNodes.forEach(function (child) {
14970
- _this6.unmountChildren(child);
14907
+ _this7.unmountChildren(child);
14971
14908
  });
14972
14909
  if (this.inited) {
14973
14910
  if (parent.isMutationObserved) {
@@ -14990,7 +14927,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14990
14927
  }
14991
14928
  };
14992
14929
  _proto.mountChildren = function mountChildren(parent) {
14993
- var _this7 = this;
14930
+ var _this8 = this;
14994
14931
  if (this.inited) {
14995
14932
  if (!parent.isConnected) {
14996
14933
  parent.ownerDocument = this.document;
@@ -15007,7 +14944,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15007
14944
  }
15008
14945
  // recursively mount children
15009
14946
  parent.childNodes.forEach(function (child) {
15010
- _this7.mountChildren(child);
14947
+ _this8.mountChildren(child);
15011
14948
  });
15012
14949
  // trigger after mounted
15013
14950
  if (parent.isCustomElement) {
@@ -15051,11 +14988,11 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15051
14988
  _createClass(Canvas, [{
15052
14989
  key: "ready",
15053
14990
  get: function get() {
15054
- var _this8 = this;
14991
+ var _this9 = this;
15055
14992
  if (!this.readyPromise) {
15056
14993
  this.readyPromise = new Promise(function (resolve) {
15057
- _this8.resolveReadyPromise = function () {
15058
- resolve(_this8);
14994
+ _this9.resolveReadyPromise = function () {
14995
+ resolve(_this9);
15059
14996
  };
15060
14997
  });
15061
14998
  if (this.inited) {