@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.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
  }
@@ -14028,6 +13992,17 @@ var EventPlugin = /*#__PURE__*/function () {
14028
13992
  }
14029
13993
  _this.setCursor(_this.context.eventService.cursor);
14030
13994
  };
13995
+ this.onClick = function (nativeEvent) {
13996
+ var _this$context$renderi3, _this$context$renderi4;
13997
+ 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;
13998
+ var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
13999
+ for (var _iterator2 = _createForOfIteratorHelperLoose(normalizedEvents), _step2; !(_step2 = _iterator2()).done;) {
14000
+ var normalizedEvent = _step2.value;
14001
+ var event = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
14002
+ _this.context.eventService.mapEvent(event);
14003
+ }
14004
+ _this.setCursor(_this.context.eventService.cursor);
14005
+ };
14031
14006
  }
14032
14007
  var _proto = EventPlugin.prototype;
14033
14008
  _proto.apply = function apply(context) {
@@ -14057,8 +14032,8 @@ var EventPlugin = /*#__PURE__*/function () {
14057
14032
  nativeEvent.preventDefault();
14058
14033
  }
14059
14034
  }
14060
- for (var _iterator2 = _createForOfIteratorHelperLoose(events), _step2; !(_step2 = _iterator2()).done;) {
14061
- var event = _step2.value;
14035
+ for (var _iterator3 = _createForOfIteratorHelperLoose(events), _step3; !(_step3 = _iterator3()).done;) {
14036
+ var event = _step3.value;
14062
14037
  var federatedEvent = _this2.bootstrapEvent(_this2.rootPointerEvent, event, canvas, nativeEvent);
14063
14038
  _this2.context.eventService.mapEvent(federatedEvent);
14064
14039
  }
@@ -14076,8 +14051,8 @@ var EventPlugin = /*#__PURE__*/function () {
14076
14051
  // @see https://github.com/antvis/G/issues/1235
14077
14052
  }
14078
14053
  var normalizedEvents = _this2.normalizeToPointerEvent(nativeEvent, canvas);
14079
- for (var _iterator3 = _createForOfIteratorHelperLoose(normalizedEvents), _step3; !(_step3 = _iterator3()).done;) {
14080
- var normalizedEvent = _step3.value;
14054
+ for (var _iterator4 = _createForOfIteratorHelperLoose(normalizedEvents), _step4; !(_step4 = _iterator4()).done;) {
14055
+ var normalizedEvent = _step4.value;
14081
14056
  var event = _this2.bootstrapEvent(_this2.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
14082
14057
  event.type += outside;
14083
14058
  _this2.context.eventService.mapEvent(event);
@@ -14087,11 +14062,11 @@ var EventPlugin = /*#__PURE__*/function () {
14087
14062
  renderingService.hooks.pointerMove.tap(EventPlugin.tag, this.onPointerMove);
14088
14063
  renderingService.hooks.pointerOver.tap(EventPlugin.tag, this.onPointerMove);
14089
14064
  renderingService.hooks.pointerOut.tap(EventPlugin.tag, this.onPointerMove);
14090
- renderingService.hooks.click.tap(EventPlugin.tag, this.onPointerMove);
14065
+ renderingService.hooks.click.tap(EventPlugin.tag, this.onClick);
14091
14066
  renderingService.hooks.pointerCancel.tap(EventPlugin.tag, function (nativeEvent) {
14092
14067
  var normalizedEvents = _this2.normalizeToPointerEvent(nativeEvent, canvas);
14093
- for (var _iterator4 = _createForOfIteratorHelperLoose(normalizedEvents), _step4; !(_step4 = _iterator4()).done;) {
14094
- var normalizedEvent = _step4.value;
14068
+ for (var _iterator5 = _createForOfIteratorHelperLoose(normalizedEvents), _step5; !(_step5 = _iterator5()).done;) {
14069
+ var normalizedEvent = _step5.value;
14095
14070
  var event = _this2.bootstrapEvent(_this2.rootPointerEvent, normalizedEvent, canvas, nativeEvent);
14096
14071
  _this2.context.eventService.mapEvent(event);
14097
14072
  }
@@ -14398,20 +14373,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
14398
14373
  runtime.sceneGraphService.dirtifyToRoot(object);
14399
14374
  renderingService.dirtify();
14400
14375
  };
14401
- renderingService.hooks.init.tapPromise(PrepareRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14402
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14403
- while (1) switch (_context.prev = _context.next) {
14404
- case 0:
14405
- canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
14406
- canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
14407
- canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
14408
- canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14409
- case 4:
14410
- case "end":
14411
- return _context.stop();
14412
- }
14413
- }, _callee);
14414
- })));
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
+ });
14415
14382
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
14416
14383
  canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
14417
14384
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
@@ -14498,6 +14465,7 @@ function isCanvas(value) {
14498
14465
  CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
14499
14466
  CanvasEvent["RESIZE"] = "resize";
14500
14467
  CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
14468
+ CanvasEvent["RENDERER_CHANGED"] = "rendererchanged";
14501
14469
  })(exports.CanvasEvent || (exports.CanvasEvent = {}));
14502
14470
  var DEFAULT_CAMERA_Z = 500;
14503
14471
  var DEFAULT_CAMERA_NEAR = 0.1;
@@ -14646,23 +14614,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14646
14614
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
14647
14615
  });
14648
14616
  _this.initDefaultCamera(canvasWidth, canvasHeight);
14649
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
14650
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14651
- while (1) switch (_context.prev = _context.next) {
14652
- case 0:
14653
- _context.next = 2;
14654
- return _this.initRenderer(renderer);
14655
- case 2:
14656
- _this.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
14657
- if (_this.readyPromise) {
14658
- _this.resolveReadyPromise();
14659
- }
14660
- case 4:
14661
- case "end":
14662
- return _context.stop();
14663
- }
14664
- }, _callee);
14665
- }))();
14617
+ _this.initRenderer(renderer, true);
14666
14618
  return _this;
14667
14619
  }
14668
14620
  var _proto = Canvas.prototype;
@@ -14840,123 +14792,119 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14840
14792
  var _this4 = this;
14841
14793
  var tick = function tick() {
14842
14794
  _this4.render();
14843
- _this4.frameId = requestAnimationFrame(tick);
14795
+ _this4.frameId = _this4.requestAnimationFrame(tick);
14844
14796
  };
14845
14797
  tick();
14846
14798
  };
14847
- _proto.initRenderer = /*#__PURE__*/function () {
14848
- var _initRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(renderer) {
14849
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
14850
- while (1) switch (_context2.prev = _context2.next) {
14851
- case 0:
14852
- if (renderer) {
14853
- _context2.next = 2;
14854
- break;
14855
- }
14856
- throw new Error('Renderer is required.');
14857
- case 2:
14858
- // reset
14859
- this.inited = false;
14860
- this.readyPromise = undefined;
14861
- // FIXME: should re-create here?
14862
- this.context.rBushRoot = new RBush__default['default']();
14863
- // reset rendering plugins
14864
- this.context.renderingPlugins = [];
14865
- this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
14866
- //
14867
- this.loadRendererContainerModule(renderer);
14868
- // init context service
14869
- this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
14870
- // init rendering service
14871
- this.context.renderingService = new RenderingService(runtime, this.context);
14872
- // init event service
14873
- this.context.eventService = new EventService(runtime, this.context);
14874
- this.context.eventService.init();
14875
- _context2.next = 14;
14876
- return this.context.contextService.init();
14877
- case 14:
14878
- _context2.next = 16;
14879
- return this.context.renderingService.init();
14880
- case 16:
14881
- this.inited = true;
14882
- this.getRoot().forEach(function (node) {
14883
- var renderable = node.renderable;
14884
- if (renderable) {
14885
- renderable.renderBoundsDirty = true;
14886
- renderable.boundsDirty = true;
14887
- renderable.dirty = true;
14888
- }
14889
- });
14890
- // keep current scenegraph unchanged, just trigger mounted event
14891
- this.mountChildren(this.getRoot());
14892
- if (renderer.getConfig().enableAutoRendering) {
14893
- this.run();
14894
- }
14895
- case 20:
14896
- case "end":
14897
- 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();
14898
14833
  }
14899
- }, _callee2, this);
14900
- }));
14901
- function initRenderer(_x) {
14902
- 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
+ });
14903
14849
  }
14904
- return initRenderer;
14905
- }();
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
+ };
14906
14873
  _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
14907
- var _this5 = this;
14874
+ var _this6 = this;
14908
14875
  // load other container modules provided by g-canvas/g-svg/g-webgl
14909
14876
  var plugins = renderer.getPlugins();
14910
14877
  plugins.forEach(function (plugin) {
14911
- plugin.context = _this5.context;
14878
+ plugin.context = _this6.context;
14912
14879
  plugin.init(runtime);
14913
14880
  });
14914
14881
  };
14915
- _proto.setRenderer = /*#__PURE__*/function () {
14916
- var _setRenderer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(renderer) {
14917
- var canvasConfig, oldRenderer;
14918
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
14919
- while (1) switch (_context3.prev = _context3.next) {
14920
- case 0:
14921
- // update canvas' config
14922
- canvasConfig = this.getConfig();
14923
- if (!(canvasConfig.renderer === renderer)) {
14924
- _context3.next = 3;
14925
- break;
14926
- }
14927
- return _context3.abrupt("return");
14928
- case 3:
14929
- oldRenderer = canvasConfig.renderer;
14930
- canvasConfig.renderer = renderer;
14931
- // keep all children undestroyed
14932
- this.destroy(false, true);
14933
- // destroy all plugins, reverse will mutate origin array
14934
- [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
14935
- plugin.destroy(runtime);
14936
- });
14937
- _context3.next = 9;
14938
- return this.initRenderer(renderer);
14939
- case 9:
14940
- case "end":
14941
- return _context3.stop();
14942
- }
14943
- }, _callee3, this);
14944
- }));
14945
- function setRenderer(_x2) {
14946
- 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;
14947
14887
  }
14948
- return setRenderer;
14949
- }();
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
+ };
14950
14898
  _proto.setCursor = function setCursor(cursor) {
14951
14899
  var canvasConfig = this.getConfig();
14952
14900
  canvasConfig.cursor = cursor;
14953
14901
  this.getContextService().applyCursorStyle(cursor);
14954
14902
  };
14955
14903
  _proto.unmountChildren = function unmountChildren(parent) {
14956
- var _this6 = this;
14904
+ var _this7 = this;
14957
14905
  // unmountChildren recursively
14958
14906
  parent.childNodes.forEach(function (child) {
14959
- _this6.unmountChildren(child);
14907
+ _this7.unmountChildren(child);
14960
14908
  });
14961
14909
  if (this.inited) {
14962
14910
  if (parent.isMutationObserved) {
@@ -14979,7 +14927,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14979
14927
  }
14980
14928
  };
14981
14929
  _proto.mountChildren = function mountChildren(parent) {
14982
- var _this7 = this;
14930
+ var _this8 = this;
14983
14931
  if (this.inited) {
14984
14932
  if (!parent.isConnected) {
14985
14933
  parent.ownerDocument = this.document;
@@ -14996,7 +14944,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
14996
14944
  }
14997
14945
  // recursively mount children
14998
14946
  parent.childNodes.forEach(function (child) {
14999
- _this7.mountChildren(child);
14947
+ _this8.mountChildren(child);
15000
14948
  });
15001
14949
  // trigger after mounted
15002
14950
  if (parent.isCustomElement) {
@@ -15040,11 +14988,11 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15040
14988
  _createClass(Canvas, [{
15041
14989
  key: "ready",
15042
14990
  get: function get() {
15043
- var _this8 = this;
14991
+ var _this9 = this;
15044
14992
  if (!this.readyPromise) {
15045
14993
  this.readyPromise = new Promise(function (resolve) {
15046
- _this8.resolveReadyPromise = function () {
15047
- resolve(_this8);
14994
+ _this9.resolveReadyPromise = function () {
14995
+ resolve(_this9);
15048
14996
  };
15049
14997
  });
15050
14998
  if (this.inited) {