@antv/g-lite 1.0.68 → 1.0.70

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
@@ -9895,6 +9895,9 @@
9895
9895
  this.callbacks = [];
9896
9896
  }
9897
9897
  var _proto = AsyncParallelHook.prototype;
9898
+ _proto.getCallbacksNum = function getCallbacksNum() {
9899
+ return this.callbacks.length;
9900
+ };
9898
9901
  _proto.tapPromise = function tapPromise(options, fn) {
9899
9902
  this.callbacks.push(fn);
9900
9903
  };
@@ -19306,7 +19309,8 @@
19306
19309
  /**
19307
19310
  * called before any frame rendered
19308
19311
  */
19309
- init: new AsyncParallelHook(),
19312
+ init: new SyncHook(),
19313
+ initAsync: new AsyncParallelHook(),
19310
19314
  /**
19311
19315
  * only dirty object which has sth changed will be rendered
19312
19316
  */
@@ -19357,32 +19361,24 @@
19357
19361
  this.context = context;
19358
19362
  }
19359
19363
  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);
19364
+ _proto.init = function init(callback) {
19365
+ var _this = this;
19366
+ var context = _extends({}, this.globalRuntime, this.context);
19367
+ // register rendering plugins
19368
+ this.context.renderingPlugins.forEach(function (plugin) {
19369
+ plugin.apply(context, runtime);
19370
+ });
19371
+ this.hooks.init.call();
19372
+ if (this.hooks.initAsync.getCallbacksNum() === 0) {
19373
+ this.inited = true;
19374
+ callback();
19375
+ } else {
19376
+ this.hooks.initAsync.promise().then(function () {
19377
+ _this.inited = true;
19378
+ callback();
19379
+ });
19383
19380
  }
19384
- return init;
19385
- }();
19381
+ };
19386
19382
  _proto.getStats = function getStats() {
19387
19383
  return this.stats;
19388
19384
  }
@@ -19398,7 +19394,7 @@
19398
19394
  return !enableDirtyRectangleRendering || this.context.renderingContext.renderReasons.has(exports.RenderReason.CAMERA_CHANGED);
19399
19395
  };
19400
19396
  _proto.render = function render(canvasConfig, rerenderCallback) {
19401
- var _this = this;
19397
+ var _this2 = this;
19402
19398
  this.stats.total = 0;
19403
19399
  this.stats.rendered = 0;
19404
19400
  this.zIndexCounter = 0;
@@ -19409,9 +19405,9 @@
19409
19405
  this.renderDisplayObject(renderingContext.root, canvasConfig, renderingContext);
19410
19406
  this.hooks.beginFrame.call();
19411
19407
  renderingContext.renderListCurrentFrame.forEach(function (object) {
19412
- _this.hooks.beforeRender.call(object);
19413
- _this.hooks.render.call(object);
19414
- _this.hooks.afterRender.call(object);
19408
+ _this2.hooks.beforeRender.call(object);
19409
+ _this2.hooks.render.call(object);
19410
+ _this2.hooks.afterRender.call(object);
19415
19411
  });
19416
19412
  this.hooks.endFrame.call();
19417
19413
  renderingContext.renderListCurrentFrame = [];
@@ -19421,7 +19417,7 @@
19421
19417
  // console.log('stats', this.stats);
19422
19418
  };
19423
19419
  _proto.renderDisplayObject = function renderDisplayObject(displayObject, canvasConfig, renderingContext) {
19424
- var _this2 = this;
19420
+ var _this3 = this;
19425
19421
  var _canvasConfig$rendere = canvasConfig.renderer.getConfig(),
19426
19422
  enableDirtyCheck = _canvasConfig$rendere.enableDirtyCheck,
19427
19423
  enableCulling = _canvasConfig$rendere.enableCulling;
@@ -19452,7 +19448,7 @@
19452
19448
  }
19453
19449
  // recursive rendering its children
19454
19450
  (sortable.sorted || displayObject.childNodes).forEach(function (child) {
19455
- _this2.renderDisplayObject(child, canvasConfig, renderingContext);
19451
+ _this3.renderDisplayObject(child, canvasConfig, renderingContext);
19456
19452
  });
19457
19453
  };
19458
19454
  _proto.sort = function sort(displayObject, sortable) {
@@ -20461,7 +20457,9 @@
20461
20457
  fontSize: 0
20462
20458
  };
20463
20459
  var canvas = this.runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
20464
- var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
20460
+ var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas, {
20461
+ willReadFrequently: true
20462
+ });
20465
20463
  context.font = font;
20466
20464
  var metricsString = TEXT_METRICS.MetricsString + TEXT_METRICS.BaselineSymbol;
20467
20465
  var width = Math.ceil(context.measureText(metricsString).width);
@@ -21383,20 +21381,12 @@
21383
21381
  runtime.sceneGraphService.dirtifyToRoot(object);
21384
21382
  renderingService.dirtify();
21385
21383
  };
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
- })));
21384
+ renderingService.hooks.init.tap(PrepareRendererPlugin.tag, function () {
21385
+ canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21386
+ canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
21387
+ canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
21388
+ canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
21389
+ });
21400
21390
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
21401
21391
  canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
21402
21392
  canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
@@ -21483,6 +21473,7 @@
21483
21473
  CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
21484
21474
  CanvasEvent["RESIZE"] = "resize";
21485
21475
  CanvasEvent["DIRTY_RECTANGLE"] = "dirtyrectangle";
21476
+ CanvasEvent["RENDERER_CHANGED"] = "rendererchanged";
21486
21477
  })(exports.CanvasEvent || (exports.CanvasEvent = {}));
21487
21478
  var DEFAULT_CAMERA_Z = 500;
21488
21479
  var DEFAULT_CAMERA_NEAR = 0.1;
@@ -21631,23 +21622,7 @@
21631
21622
  alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
21632
21623
  });
21633
21624
  _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
- }))();
21625
+ _this.initRenderer(renderer, true);
21651
21626
  return _this;
21652
21627
  }
21653
21628
  var _proto = Canvas.prototype;
@@ -21825,123 +21800,120 @@
21825
21800
  var _this4 = this;
21826
21801
  var tick = function tick() {
21827
21802
  _this4.render();
21828
- _this4.frameId = requestAnimationFrame(tick);
21803
+ _this4.frameId = _this4.requestAnimationFrame(tick);
21829
21804
  };
21830
21805
  tick();
21831
21806
  };
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();
21883
- }
21884
- }, _callee2, this);
21885
- }));
21886
- function initRenderer(_x) {
21887
- return _initRenderer.apply(this, arguments);
21807
+ _proto.initRenderer = function initRenderer(renderer, firstContentfullPaint) {
21808
+ var _this5 = this;
21809
+ if (firstContentfullPaint === void 0) {
21810
+ firstContentfullPaint = false;
21888
21811
  }
21889
- return initRenderer;
21890
- }();
21812
+ if (!renderer) {
21813
+ throw new Error('Renderer is required.');
21814
+ }
21815
+ // reset
21816
+ this.inited = false;
21817
+ this.readyPromise = undefined;
21818
+ // FIXME: should re-create here?
21819
+ this.context.rBushRoot = new rbush();
21820
+ // reset rendering plugins
21821
+ this.context.renderingPlugins = [];
21822
+ this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(), new DirtyCheckPlugin(), new CullingPlugin([new FrustumCullingStrategy()]));
21823
+ //
21824
+ this.loadRendererContainerModule(renderer);
21825
+ // init context service
21826
+ this.context.contextService = new this.context.ContextService(_extends({}, runtime, this.context));
21827
+ // init rendering service
21828
+ this.context.renderingService = new RenderingService(runtime, this.context);
21829
+ // init event service
21830
+ this.context.eventService = new EventService(runtime, this.context);
21831
+ this.context.eventService.init();
21832
+ if (this.context.contextService.init) {
21833
+ this.context.contextService.init();
21834
+ this.initRenderingService(renderer, firstContentfullPaint, true);
21835
+ } else {
21836
+ this.context.contextService.initAsync().then(function () {
21837
+ _this5.initRenderingService(renderer, firstContentfullPaint);
21838
+ });
21839
+ }
21840
+ };
21841
+ _proto.initRenderingService = function initRenderingService(renderer, firstContentfullPaint, async) {
21842
+ var _this6 = this;
21843
+ if (firstContentfullPaint === void 0) {
21844
+ firstContentfullPaint = false;
21845
+ }
21846
+ if (async === void 0) {
21847
+ async = false;
21848
+ }
21849
+ this.context.renderingService.init(function () {
21850
+ _this6.inited = true;
21851
+ if (firstContentfullPaint) {
21852
+ if (async) {
21853
+ _this6.requestAnimationFrame(function () {
21854
+ _this6.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
21855
+ });
21856
+ } else {
21857
+ _this6.dispatchEvent(new CustomEvent(exports.CanvasEvent.READY));
21858
+ }
21859
+ if (_this6.readyPromise) {
21860
+ _this6.resolveReadyPromise();
21861
+ }
21862
+ } else {
21863
+ _this6.dispatchEvent(new CustomEvent(exports.CanvasEvent.RENDERER_CHANGED));
21864
+ }
21865
+ if (!firstContentfullPaint) {
21866
+ _this6.getRoot().forEach(function (node) {
21867
+ var renderable = node.renderable;
21868
+ if (renderable) {
21869
+ renderable.renderBoundsDirty = true;
21870
+ renderable.boundsDirty = true;
21871
+ renderable.dirty = true;
21872
+ }
21873
+ });
21874
+ }
21875
+ // keep current scenegraph unchanged, just trigger mounted event
21876
+ _this6.mountChildren(_this6.getRoot());
21877
+ if (renderer.getConfig().enableAutoRendering) {
21878
+ _this6.run();
21879
+ }
21880
+ });
21881
+ };
21891
21882
  _proto.loadRendererContainerModule = function loadRendererContainerModule(renderer) {
21892
- var _this5 = this;
21883
+ var _this7 = this;
21893
21884
  // load other container modules provided by g-canvas/g-svg/g-webgl
21894
21885
  var plugins = renderer.getPlugins();
21895
21886
  plugins.forEach(function (plugin) {
21896
- plugin.context = _this5.context;
21887
+ plugin.context = _this7.context;
21897
21888
  plugin.init(runtime);
21898
21889
  });
21899
21890
  };
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);
21891
+ _proto.setRenderer = function setRenderer(renderer) {
21892
+ // update canvas' config
21893
+ var canvasConfig = this.getConfig();
21894
+ if (canvasConfig.renderer === renderer) {
21895
+ return;
21932
21896
  }
21933
- return setRenderer;
21934
- }();
21897
+ var oldRenderer = canvasConfig.renderer;
21898
+ canvasConfig.renderer = renderer;
21899
+ // keep all children undestroyed
21900
+ this.destroy(false, true);
21901
+ // destroy all plugins, reverse will mutate origin array
21902
+ [].concat(oldRenderer === null || oldRenderer === void 0 ? void 0 : oldRenderer.getPlugins()).reverse().forEach(function (plugin) {
21903
+ plugin.destroy(runtime);
21904
+ });
21905
+ this.initRenderer(renderer);
21906
+ };
21935
21907
  _proto.setCursor = function setCursor(cursor) {
21936
21908
  var canvasConfig = this.getConfig();
21937
21909
  canvasConfig.cursor = cursor;
21938
21910
  this.getContextService().applyCursorStyle(cursor);
21939
21911
  };
21940
21912
  _proto.unmountChildren = function unmountChildren(parent) {
21941
- var _this6 = this;
21913
+ var _this8 = this;
21942
21914
  // unmountChildren recursively
21943
21915
  parent.childNodes.forEach(function (child) {
21944
- _this6.unmountChildren(child);
21916
+ _this8.unmountChildren(child);
21945
21917
  });
21946
21918
  if (this.inited) {
21947
21919
  if (parent.isMutationObserved) {
@@ -21964,7 +21936,7 @@
21964
21936
  }
21965
21937
  };
21966
21938
  _proto.mountChildren = function mountChildren(parent) {
21967
- var _this7 = this;
21939
+ var _this9 = this;
21968
21940
  if (this.inited) {
21969
21941
  if (!parent.isConnected) {
21970
21942
  parent.ownerDocument = this.document;
@@ -21981,7 +21953,7 @@
21981
21953
  }
21982
21954
  // recursively mount children
21983
21955
  parent.childNodes.forEach(function (child) {
21984
- _this7.mountChildren(child);
21956
+ _this9.mountChildren(child);
21985
21957
  });
21986
21958
  // trigger after mounted
21987
21959
  if (parent.isCustomElement) {
@@ -22025,11 +21997,11 @@
22025
21997
  _createClass(Canvas, [{
22026
21998
  key: "ready",
22027
21999
  get: function get() {
22028
- var _this8 = this;
22000
+ var _this10 = this;
22029
22001
  if (!this.readyPromise) {
22030
22002
  this.readyPromise = new Promise(function (resolve) {
22031
- _this8.resolveReadyPromise = function () {
22032
- resolve(_this8);
22003
+ _this10.resolveReadyPromise = function () {
22004
+ resolve(_this10);
22033
22005
  };
22034
22006
  });
22035
22007
  if (this.inited) {