@antv/g-lite 1.0.67 → 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
  }
@@ -21002,6 +20966,17 @@
21002
20966
  }
21003
20967
  _this.setCursor(_this.context.eventService.cursor);
21004
20968
  };
20969
+ this.onClick = function (nativeEvent) {
20970
+ var _this$context$renderi3, _this$context$renderi4;
20971
+ var canvas = (_this$context$renderi3 = _this.context.renderingContext.root) === null || _this$context$renderi3 === void 0 ? void 0 : (_this$context$renderi4 = _this$context$renderi3.ownerDocument) === null || _this$context$renderi4 === void 0 ? void 0 : _this$context$renderi4.defaultView;
20972
+ var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
20973
+ for (var _iterator2 = _createForOfIteratorHelperLoose(normalizedEvents), _step2; !(_step2 = _iterator2()).done;) {
20974
+ var normalizedEvent = _step2.value;
20975
+ var event = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
20976
+ _this.context.eventService.mapEvent(event);
20977
+ }
20978
+ _this.setCursor(_this.context.eventService.cursor);
20979
+ };
21005
20980
  }
21006
20981
  var _proto = EventPlugin.prototype;
21007
20982
  _proto.apply = function apply(context) {
@@ -21031,8 +21006,8 @@
21031
21006
  nativeEvent.preventDefault();
21032
21007
  }
21033
21008
  }
21034
- for (var _iterator2 = _createForOfIteratorHelperLoose(events), _step2; !(_step2 = _iterator2()).done;) {
21035
- var event = _step2.value;
21009
+ for (var _iterator3 = _createForOfIteratorHelperLoose(events), _step3; !(_step3 = _iterator3()).done;) {
21010
+ var event = _step3.value;
21036
21011
  var federatedEvent = _this2.bootstrapEvent(_this2.rootPointerEvent, event, canvas, nativeEvent);
21037
21012
  _this2.context.eventService.mapEvent(federatedEvent);
21038
21013
  }
@@ -21050,8 +21025,8 @@
21050
21025
  // @see https://github.com/antvis/G/issues/1235
21051
21026
  }
21052
21027
  var normalizedEvents = _this2.normalizeToPointerEvent(nativeEvent, canvas);
21053
- for (var _iterator3 = _createForOfIteratorHelperLoose(normalizedEvents), _step3; !(_step3 = _iterator3()).done;) {
21054
- var normalizedEvent = _step3.value;
21028
+ for (var _iterator4 = _createForOfIteratorHelperLoose(normalizedEvents), _step4; !(_step4 = _iterator4()).done;) {
21029
+ var normalizedEvent = _step4.value;
21055
21030
  var event = _this2.bootstrapEvent(_this2.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
21056
21031
  event.type += outside;
21057
21032
  _this2.context.eventService.mapEvent(event);
@@ -21061,11 +21036,11 @@
21061
21036
  renderingService.hooks.pointerMove.tap(EventPlugin.tag, this.onPointerMove);
21062
21037
  renderingService.hooks.pointerOver.tap(EventPlugin.tag, this.onPointerMove);
21063
21038
  renderingService.hooks.pointerOut.tap(EventPlugin.tag, this.onPointerMove);
21064
- renderingService.hooks.click.tap(EventPlugin.tag, this.onPointerMove);
21039
+ renderingService.hooks.click.tap(EventPlugin.tag, this.onClick);
21065
21040
  renderingService.hooks.pointerCancel.tap(EventPlugin.tag, function (nativeEvent) {
21066
21041
  var normalizedEvents = _this2.normalizeToPointerEvent(nativeEvent, canvas);
21067
- for (var _iterator4 = _createForOfIteratorHelperLoose(normalizedEvents), _step4; !(_step4 = _iterator4()).done;) {
21068
- var normalizedEvent = _step4.value;
21042
+ for (var _iterator5 = _createForOfIteratorHelperLoose(normalizedEvents), _step5; !(_step5 = _iterator5()).done;) {
21043
+ var normalizedEvent = _step5.value;
21069
21044
  var event = _this2.bootstrapEvent(_this2.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
21070
21045
  _this2.context.eventService.mapEvent(event);
21071
21046
  }
@@ -21372,20 +21347,12 @@
21372
21347
  runtime.sceneGraphService.dirtifyToRoot(object);
21373
21348
  renderingService.dirtify();
21374
21349
  };
21375
- renderingService.hooks.init.tapPromise(PrepareRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
21376
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21377
- while (1) switch (_context.prev = _context.next) {
21378
- case 0:
21379
- canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21380
- canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
21381
- canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
21382
- canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
21383
- case 4:
21384
- case "end":
21385
- return _context.stop();
21386
- }
21387
- }, _callee);
21388
- })));
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
+ });
21389
21356
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
21390
21357
  canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21391
21358
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
@@ -21472,6 +21439,7 @@
21472
21439
  CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
21473
21440
  CanvasEvent["RESIZE"] = "resize";
21474
21441
  CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
21442
+ CanvasEvent["RENDERER_CHANGED"] = "rendererchanged";
21475
21443
  })(exports.CanvasEvent || (exports.CanvasEvent = {}));
21476
21444
  var DEFAULT_CAMERA_Z = 500;
21477
21445
  var DEFAULT_CAMERA_NEAR = 0.1;
@@ -21620,23 +21588,7 @@
21620
21588
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
21621
21589
  });
21622
21590
  _this.initDefaultCamera(canvasWidth, canvasHeight);
21623
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
21624
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21625
- while (1) switch (_context.prev = _context.next) {
21626
- case 0:
21627
- _context.next = 2;
21628
- return _this.initRenderer(renderer);
21629
- case 2:
21630
- _this.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
21631
- if (_this.readyPromise) {
21632
- _this.resolveReadyPromise();
21633
- }
21634
- case 4:
21635
- case "end":
21636
- return _context.stop();
21637
- }
21638
- }, _callee);
21639
- }))();
21591
+ _this.initRenderer(renderer, true);
21640
21592
  return _this;
21641
21593
  }
21642
21594
  var _proto = Canvas.prototype;
@@ -21814,123 +21766,119 @@
21814
21766
  var _this4 = this;
21815
21767
  var tick = function tick() {
21816
21768
  _this4.render();
21817
- _this4.frameId = requestAnimationFrame(tick);
21769
+ _this4.frameId = _this4.requestAnimationFrame(tick);
21818
21770
  };
21819
21771
  tick();
21820
21772
  };
21821
- _proto.initRenderer = /*#__PURE__*/function () {
21822
- var _initRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderer) {
21823
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
21824
- while (1) switch (_context2.prev = _context2.next) {
21825
- case 0:
21826
- if (renderer) {
21827
- _context2.next = 2;
21828
- break;
21829
- }
21830
- throw new Error('Renderer is required.');
21831
- case 2:
21832
- // reset
21833
- this.inited = false;
21834
- this.readyPromise = undefined;
21835
- // FIXME: should re-create here?
21836
- this.context.rBushRoot = new rbush();
21837
- // reset rendering plugins
21838
- this.context.renderingPlugins = [];
21839
- this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
21840
- //
21841
- this.loadRendererContainerModule(renderer);
21842
- // init context service
21843
- this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
21844
- // init rendering service
21845
- this.context.renderingService = new RenderingService(runtime, this.context);
21846
- // init event service
21847
- this.context.eventService = new EventService(runtime, this.context);
21848
- this.context.eventService.init();
21849
- _context2.next = 14;
21850
- return this.context.contextService.init();
21851
- case 14:
21852
- _context2.next = 16;
21853
- return this.context.renderingService.init();
21854
- case 16:
21855
- this.inited = true;
21856
- this.getRoot().forEach(function (node) {
21857
- var renderable = node.renderable;
21858
- if (renderable) {
21859
- renderable.renderBoundsDirty = true;
21860
- renderable.boundsDirty = true;
21861
- renderable.dirty = true;
21862
- }
21863
- });
21864
- // keep current scenegraph unchanged, just trigger mounted event
21865
- this.mountChildren(this.getRoot());
21866
- if (renderer.getConfig().enableAutoRendering) {
21867
- this.run();
21868
- }
21869
- case 20:
21870
- case "end":
21871
- 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();
21872
21807
  }
21873
- }, _callee2, this);
21874
- }));
21875
- function initRenderer(_x) {
21876
- 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
+ });
21877
21823
  }
21878
- return initRenderer;
21879
- }();
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
+ };
21880
21847
  _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
21881
- var _this5 = this;
21848
+ var _this6 = this;
21882
21849
  // load other container modules provided by g-canvas/g-svg/g-webgl
21883
21850
  var plugins = renderer.getPlugins();
21884
21851
  plugins.forEach(function (plugin) {
21885
- plugin.context = _this5.context;
21852
+ plugin.context = _this6.context;
21886
21853
  plugin.init(runtime);
21887
21854
  });
21888
21855
  };
21889
- _proto.setRenderer = /*#__PURE__*/function () {
21890
- var _setRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(renderer) {
21891
- var canvasConfig, oldRenderer;
21892
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
21893
- while (1) switch (_context3.prev = _context3.next) {
21894
- case 0:
21895
- // update canvas' config
21896
- canvasConfig = this.getConfig();
21897
- if (!(canvasConfig.renderer === renderer)) {
21898
- _context3.next = 3;
21899
- break;
21900
- }
21901
- return _context3.abrupt("return");
21902
- case 3:
21903
- oldRenderer = canvasConfig.renderer;
21904
- canvasConfig.renderer = renderer;
21905
- // keep all children undestroyed
21906
- this.destroy(false, true);
21907
- // destroy all plugins, reverse will mutate origin array
21908
- [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
21909
- plugin.destroy(runtime);
21910
- });
21911
- _context3.next = 9;
21912
- return this.initRenderer(renderer);
21913
- case 9:
21914
- case "end":
21915
- return _context3.stop();
21916
- }
21917
- }, _callee3, this);
21918
- }));
21919
- function setRenderer(_x2) {
21920
- 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;
21921
21861
  }
21922
- return setRenderer;
21923
- }();
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
+ };
21924
21872
  _proto.setCursor = function setCursor(cursor) {
21925
21873
  var canvasConfig = this.getConfig();
21926
21874
  canvasConfig.cursor = cursor;
21927
21875
  this.getContextService().applyCursorStyle(cursor);
21928
21876
  };
21929
21877
  _proto.unmountChildren = function unmountChildren(parent) {
21930
- var _this6 = this;
21878
+ var _this7 = this;
21931
21879
  // unmountChildren recursively
21932
21880
  parent.childNodes.forEach(function (child) {
21933
- _this6.unmountChildren(child);
21881
+ _this7.unmountChildren(child);
21934
21882
  });
21935
21883
  if (this.inited) {
21936
21884
  if (parent.isMutationObserved) {
@@ -21953,7 +21901,7 @@
21953
21901
  }
21954
21902
  };
21955
21903
  _proto.mountChildren = function mountChildren(parent) {
21956
- var _this7 = this;
21904
+ var _this8 = this;
21957
21905
  if (this.inited) {
21958
21906
  if (!parent.isConnected) {
21959
21907
  parent.ownerDocument = this.document;
@@ -21970,7 +21918,7 @@
21970
21918
  }
21971
21919
  // recursively mount children
21972
21920
  parent.childNodes.forEach(function (child) {
21973
- _this7.mountChildren(child);
21921
+ _this8.mountChildren(child);
21974
21922
  });
21975
21923
  // trigger after mounted
21976
21924
  if (parent.isCustomElement) {
@@ -22014,11 +21962,11 @@
22014
21962
  _createClass(Canvas, [{
22015
21963
  key: "ready",
22016
21964
  get: function get() {
22017
- var _this8 = this;
21965
+ var _this9 = this;
22018
21966
  if (!this.readyPromise) {
22019
21967
  this.readyPromise = new Promise(function (resolve) {
22020
- _this8.resolveReadyPromise = function () {
22021
- resolve(_this8);
21968
+ _this9.resolveReadyPromise = function () {
21969
+ resolve(_this9);
22022
21970
  };
22023
21971
  });
22024
21972
  if (this.inited) {