@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.umd.js CHANGED
@@ -9890,25 +9890,6 @@
9890
9890
  return [hasFill, hasStroke];
9891
9891
  }
9892
9892
 
9893
- var AsyncParallelHook = /*#__PURE__*/function () {
9894
- function AsyncParallelHook() {
9895
- this.callbacks = [];
9896
- }
9897
- var _proto = AsyncParallelHook.prototype;
9898
- _proto.tapPromise = function tapPromise(options, fn) {
9899
- this.callbacks.push(fn);
9900
- };
9901
- _proto.promise = function promise() {
9902
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9903
- args[_key] = arguments[_key];
9904
- }
9905
- return Promise.all(this.callbacks.map(function (callback) {
9906
- return callback.apply(void 0, args);
9907
- }));
9908
- };
9909
- return AsyncParallelHook;
9910
- }();
9911
-
9912
9893
  var AsyncSeriesWaterfallHook = /*#__PURE__*/function () {
9913
9894
  function AsyncSeriesWaterfallHook() {
9914
9895
  this.callbacks = [];
@@ -19306,7 +19287,7 @@
19306
19287
  /**
19307
19288
  * called before any frame rendered
19308
19289
  */
19309
- init: new AsyncParallelHook(),
19290
+ init: new SyncHook(),
19310
19291
  /**
19311
19292
  * only dirty object which has sth changed will be rendered
19312
19293
  */
@@ -19357,32 +19338,15 @@
19357
19338
  this.context = context;
19358
19339
  }
19359
19340
  var _proto = RenderingService.prototype;
19360
- _proto.init = /*#__PURE__*/function () {
19361
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
19362
- var context;
19363
- return _regeneratorRuntime().wrap(function _callee$(_context) {
19364
- while (1) switch (_context.prev = _context.next) {
19365
- case 0:
19366
- context = _extends({}, this.globalRuntime, this.context); // register rendering plugins
19367
- this.context.renderingPlugins.forEach(function (plugin) {
19368
- plugin.apply(context, runtime);
19369
- });
19370
- // await this.hooks.init.callPromise();
19371
- _context.next = 4;
19372
- return this.hooks.init.promise();
19373
- case 4:
19374
- this.inited = true;
19375
- case 5:
19376
- case "end":
19377
- return _context.stop();
19378
- }
19379
- }, _callee, this);
19380
- }));
19381
- function init() {
19382
- return _init.apply(this, arguments);
19383
- }
19384
- return init;
19385
- }();
19341
+ _proto.init = function init() {
19342
+ var context = _extends({}, this.globalRuntime, this.context);
19343
+ // register rendering plugins
19344
+ this.context.renderingPlugins.forEach(function (plugin) {
19345
+ plugin.apply(context, runtime);
19346
+ });
19347
+ this.hooks.init.call();
19348
+ this.inited = true;
19349
+ };
19386
19350
  _proto.getStats = function getStats() {
19387
19351
  return this.stats;
19388
19352
  }
@@ -21383,20 +21347,12 @@
21383
21347
  runtime.sceneGraphService.dirtifyToRoot(object);
21384
21348
  renderingService.dirtify();
21385
21349
  };
21386
- renderingService.hooks.init.tapPromise(PrepareRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
21387
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21388
- while (1) switch (_context.prev = _context.next) {
21389
- case 0:
21390
- canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21391
- canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
21392
- canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
21393
- canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
21394
- case 4:
21395
- case "end":
21396
- return _context.stop();
21397
- }
21398
- }, _callee);
21399
- })));
21350
+ renderingService.hooks.init.tap(PrepareRendererPlugin.tag, function () {
21351
+ canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21352
+ canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
21353
+ canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
21354
+ canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
21355
+ });
21400
21356
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
21401
21357
  canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21402
21358
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
@@ -21483,6 +21439,7 @@
21483
21439
  CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
21484
21440
  CanvasEvent["RESIZE"] = "resize";
21485
21441
  CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
21442
+ CanvasEvent["RENDERER_CHANGED"] = "rendererchanged";
21486
21443
  })(exports.CanvasEvent || (exports.CanvasEvent = {}));
21487
21444
  var DEFAULT_CAMERA_Z = 500;
21488
21445
  var DEFAULT_CAMERA_NEAR = 0.1;
@@ -21631,23 +21588,7 @@
21631
21588
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
21632
21589
  });
21633
21590
  _this.initDefaultCamera(canvasWidth, canvasHeight);
21634
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
21635
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21636
- while (1) switch (_context.prev = _context.next) {
21637
- case 0:
21638
- _context.next = 2;
21639
- return _this.initRenderer(renderer);
21640
- case 2:
21641
- _this.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
21642
- if (_this.readyPromise) {
21643
- _this.resolveReadyPromise();
21644
- }
21645
- case 4:
21646
- case "end":
21647
- return _context.stop();
21648
- }
21649
- }, _callee);
21650
- }))();
21591
+ _this.initRenderer(renderer, true);
21651
21592
  return _this;
21652
21593
  }
21653
21594
  var _proto = Canvas.prototype;
@@ -21825,123 +21766,119 @@
21825
21766
  var _this4 = this;
21826
21767
  var tick = function tick() {
21827
21768
  _this4.render();
21828
- _this4.frameId = requestAnimationFrame(tick);
21769
+ _this4.frameId = _this4.requestAnimationFrame(tick);
21829
21770
  };
21830
21771
  tick();
21831
21772
  };
21832
- _proto.initRenderer = /*#__PURE__*/function () {
21833
- var _initRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderer) {
21834
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
21835
- while (1) switch (_context2.prev = _context2.next) {
21836
- case 0:
21837
- if (renderer) {
21838
- _context2.next = 2;
21839
- break;
21840
- }
21841
- throw new Error('Renderer is required.');
21842
- case 2:
21843
- // reset
21844
- this.inited = false;
21845
- this.readyPromise = undefined;
21846
- // FIXME: should re-create here?
21847
- this.context.rBushRoot = new rbush();
21848
- // reset rendering plugins
21849
- this.context.renderingPlugins = [];
21850
- this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
21851
- //
21852
- this.loadRendererContainerModule(renderer);
21853
- // init context service
21854
- this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
21855
- // init rendering service
21856
- this.context.renderingService = new RenderingService(runtime, this.context);
21857
- // init event service
21858
- this.context.eventService = new EventService(runtime, this.context);
21859
- this.context.eventService.init();
21860
- _context2.next = 14;
21861
- return this.context.contextService.init();
21862
- case 14:
21863
- _context2.next = 16;
21864
- return this.context.renderingService.init();
21865
- case 16:
21866
- this.inited = true;
21867
- this.getRoot().forEach(function (node) {
21868
- var renderable = node.renderable;
21869
- if (renderable) {
21870
- renderable.renderBoundsDirty = true;
21871
- renderable.boundsDirty = true;
21872
- renderable.dirty = true;
21873
- }
21874
- });
21875
- // keep current scenegraph unchanged, just trigger mounted event
21876
- this.mountChildren(this.getRoot());
21877
- if (renderer.getConfig().enableAutoRendering) {
21878
- this.run();
21879
- }
21880
- case 20:
21881
- case "end":
21882
- return _context2.stop();
21773
+ _proto.initRenderer = function initRenderer(renderer, firstContentfullPaint) {
21774
+ var _this5 = this;
21775
+ if (firstContentfullPaint === void 0) {
21776
+ firstContentfullPaint = false;
21777
+ }
21778
+ if (!renderer) {
21779
+ throw new Error('Renderer is required.');
21780
+ }
21781
+ // reset
21782
+ this.inited = false;
21783
+ this.readyPromise = undefined;
21784
+ // FIXME: should re-create here?
21785
+ this.context.rBushRoot = new rbush();
21786
+ // reset rendering plugins
21787
+ this.context.renderingPlugins = [];
21788
+ this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
21789
+ //
21790
+ this.loadRendererContainerModule(renderer);
21791
+ // init context service
21792
+ this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
21793
+ // init rendering service
21794
+ this.context.renderingService = new RenderingService(runtime, this.context);
21795
+ // init event service
21796
+ this.context.eventService = new EventService(runtime, this.context);
21797
+ this.context.eventService.init();
21798
+ if (this.context.contextService.init) {
21799
+ this.context.contextService.init();
21800
+ this.initRenderingService(renderer, firstContentfullPaint);
21801
+ if (firstContentfullPaint) {
21802
+ this.requestAnimationFrame(function () {
21803
+ _this5.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
21804
+ });
21805
+ if (this.readyPromise) {
21806
+ this.resolveReadyPromise();
21883
21807
  }
21884
- }, _callee2, this);
21885
- }));
21886
- function initRenderer(_x) {
21887
- return _initRenderer.apply(this, arguments);
21808
+ } else {
21809
+ this.dispatchEvent(new CustomEvent(exports.CanvasEvent.RENDERER_CHANGED));
21810
+ }
21811
+ } else {
21812
+ this.context.contextService.initAsync().then(function () {
21813
+ _this5.initRenderingService(renderer, firstContentfullPaint);
21814
+ if (firstContentfullPaint) {
21815
+ _this5.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
21816
+ if (_this5.readyPromise) {
21817
+ _this5.resolveReadyPromise();
21818
+ }
21819
+ } else {
21820
+ _this5.dispatchEvent(new CustomEvent(exports.CanvasEvent.RENDERER_CHANGED));
21821
+ }
21822
+ });
21888
21823
  }
21889
- return initRenderer;
21890
- }();
21824
+ };
21825
+ _proto.initRenderingService = function initRenderingService(renderer, firstContentfullPaint) {
21826
+ if (firstContentfullPaint === void 0) {
21827
+ firstContentfullPaint = false;
21828
+ }
21829
+ this.context.renderingService.init();
21830
+ this.inited = true;
21831
+ if (!firstContentfullPaint) {
21832
+ this.getRoot().forEach(function (node) {
21833
+ var renderable = node.renderable;
21834
+ if (renderable) {
21835
+ renderable.renderBoundsDirty = true;
21836
+ renderable.boundsDirty = true;
21837
+ renderable.dirty = true;
21838
+ }
21839
+ });
21840
+ }
21841
+ // keep current scenegraph unchanged, just trigger mounted event
21842
+ this.mountChildren(this.getRoot());
21843
+ if (renderer.getConfig().enableAutoRendering) {
21844
+ this.run();
21845
+ }
21846
+ };
21891
21847
  _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
21892
- var _this5 = this;
21848
+ var _this6 = this;
21893
21849
  // load other container modules provided by g-canvas/g-svg/g-webgl
21894
21850
  var plugins = renderer.getPlugins();
21895
21851
  plugins.forEach(function (plugin) {
21896
- plugin.context = _this5.context;
21852
+ plugin.context = _this6.context;
21897
21853
  plugin.init(runtime);
21898
21854
  });
21899
21855
  };
21900
- _proto.setRenderer = /*#__PURE__*/function () {
21901
- var _setRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(renderer) {
21902
- var canvasConfig, oldRenderer;
21903
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
21904
- while (1) switch (_context3.prev = _context3.next) {
21905
- case 0:
21906
- // update canvas' config
21907
- canvasConfig = this.getConfig();
21908
- if (!(canvasConfig.renderer === renderer)) {
21909
- _context3.next = 3;
21910
- break;
21911
- }
21912
- return _context3.abrupt("return");
21913
- case 3:
21914
- oldRenderer = canvasConfig.renderer;
21915
- canvasConfig.renderer = renderer;
21916
- // keep all children undestroyed
21917
- this.destroy(false, true);
21918
- // destroy all plugins, reverse will mutate origin array
21919
- [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
21920
- plugin.destroy(runtime);
21921
- });
21922
- _context3.next = 9;
21923
- return this.initRenderer(renderer);
21924
- case 9:
21925
- case "end":
21926
- return _context3.stop();
21927
- }
21928
- }, _callee3, this);
21929
- }));
21930
- function setRenderer(_x2) {
21931
- return _setRenderer.apply(this, arguments);
21856
+ _proto.setRenderer = function setRenderer(renderer) {
21857
+ // update canvas' config
21858
+ var canvasConfig = this.getConfig();
21859
+ if (canvasConfig.renderer === renderer) {
21860
+ return;
21932
21861
  }
21933
- return setRenderer;
21934
- }();
21862
+ var oldRenderer = canvasConfig.renderer;
21863
+ canvasConfig.renderer = renderer;
21864
+ // keep all children undestroyed
21865
+ this.destroy(false, true);
21866
+ // destroy all plugins, reverse will mutate origin array
21867
+ [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
21868
+ plugin.destroy(runtime);
21869
+ });
21870
+ this.initRenderer(renderer);
21871
+ };
21935
21872
  _proto.setCursor = function setCursor(cursor) {
21936
21873
  var canvasConfig = this.getConfig();
21937
21874
  canvasConfig.cursor = cursor;
21938
21875
  this.getContextService().applyCursorStyle(cursor);
21939
21876
  };
21940
21877
  _proto.unmountChildren = function unmountChildren(parent) {
21941
- var _this6 = this;
21878
+ var _this7 = this;
21942
21879
  // unmountChildren recursively
21943
21880
  parent.childNodes.forEach(function (child) {
21944
- _this6.unmountChildren(child);
21881
+ _this7.unmountChildren(child);
21945
21882
  });
21946
21883
  if (this.inited) {
21947
21884
  if (parent.isMutationObserved) {
@@ -21964,7 +21901,7 @@
21964
21901
  }
21965
21902
  };
21966
21903
  _proto.mountChildren = function mountChildren(parent) {
21967
- var _this7 = this;
21904
+ var _this8 = this;
21968
21905
  if (this.inited) {
21969
21906
  if (!parent.isConnected) {
21970
21907
  parent.ownerDocument = this.document;
@@ -21981,7 +21918,7 @@
21981
21918
  }
21982
21919
  // recursively mount children
21983
21920
  parent.childNodes.forEach(function (child) {
21984
- _this7.mountChildren(child);
21921
+ _this8.mountChildren(child);
21985
21922
  });
21986
21923
  // trigger after mounted
21987
21924
  if (parent.isCustomElement) {
@@ -22025,11 +21962,11 @@
22025
21962
  _createClass(Canvas, [{
22026
21963
  key: "ready",
22027
21964
  get: function get() {
22028
- var _this8 = this;
21965
+ var _this9 = this;
22029
21966
  if (!this.readyPromise) {
22030
21967
  this.readyPromise = new Promise(function (resolve) {
22031
- _this8.resolveReadyPromise = function () {
22032
- resolve(_this8);
21968
+ _this9.resolveReadyPromise = function () {
21969
+ resolve(_this9);
22033
21970
  };
22034
21971
  });
22035
21972
  if (this.inited) {