@antv/g-lite 2.0.1 → 2.0.3

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/Canvas.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="webxr" />
1
2
  import type { IRenderer } from './AbstractRenderer';
2
3
  import { DisplayObject } from './display-objects/DisplayObject';
3
4
  import type { CanvasContext, IChildNode } from './dom';
@@ -124,7 +125,7 @@ export declare class Canvas extends EventTarget implements ICanvas {
124
125
  * But the canvas remains running which means display objects can be appended later.
125
126
  */
126
127
  destroyChildren(): void;
127
- render(): void;
128
+ render(frame?: XRFrame): void;
128
129
  private run;
129
130
  private initRenderer;
130
131
  private initRenderingService;
@@ -169,6 +169,10 @@ export declare class Camera implements ICamera {
169
169
  * 设置相机矩阵
170
170
  */
171
171
  setMatrix(matrix: mat4): this;
172
+ /**
173
+ * Set projection matrix manually.
174
+ */
175
+ setProjectionMatrix(matrix: mat4): void;
172
176
  setFov(fov: number): this;
173
177
  setAspect(aspect: number): this;
174
178
  setNear(near: number): this;
package/dist/index.esm.js CHANGED
@@ -1699,6 +1699,12 @@ var Camera = /** @class */ (function () {
1699
1699
  this._update();
1700
1700
  return this;
1701
1701
  };
1702
+ /**
1703
+ * Set projection matrix manually.
1704
+ */
1705
+ Camera.prototype.setProjectionMatrix = function (matrix) {
1706
+ this.projectionMatrix = matrix;
1707
+ };
1702
1708
  Camera.prototype.setFov = function (fov) {
1703
1709
  this.setPerspective(this.near, this.far, fov, this.aspect);
1704
1710
  return this;
@@ -9488,13 +9494,35 @@ var EventService = /** @class */ (function () {
9488
9494
  this.mappingState = {};
9489
9495
  this.eventPool.clear();
9490
9496
  };
9491
- EventService.prototype.client2Viewport = function (client) {
9497
+ EventService.prototype.getScale = function () {
9492
9498
  var bbox = this.context.contextService.getBoundingClientRect();
9493
- return new Point(client.x - ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), client.y - ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
9499
+ var scaleX = 1;
9500
+ var scaleY = 1;
9501
+ var $el = this.context.contextService.getDomElement();
9502
+ if ($el && bbox) {
9503
+ var offsetWidth = $el.offsetWidth, offsetHeight = $el.offsetHeight;
9504
+ scaleX = bbox.width / offsetWidth;
9505
+ scaleY = bbox.height / offsetHeight;
9506
+ }
9507
+ return {
9508
+ scaleX: scaleX,
9509
+ scaleY: scaleY,
9510
+ bbox: bbox,
9511
+ };
9512
+ };
9513
+ /**
9514
+ * Should account for CSS Transform applied on container.
9515
+ * @see https://github.com/antvis/G/issues/1161
9516
+ * @see https://github.com/antvis/G/issues/1677
9517
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
9518
+ */
9519
+ EventService.prototype.client2Viewport = function (client) {
9520
+ var _a = this.getScale(), scaleX = _a.scaleX, scaleY = _a.scaleY, bbox = _a.bbox;
9521
+ return new Point((client.x - ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0)) / scaleX, (client.y - ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0)) / scaleY);
9494
9522
  };
9495
9523
  EventService.prototype.viewport2Client = function (canvas) {
9496
- var bbox = this.context.contextService.getBoundingClientRect();
9497
- return new Point(canvas.x + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), canvas.y + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
9524
+ var _a = this.getScale(), scaleX = _a.scaleX, scaleY = _a.scaleY, bbox = _a.bbox;
9525
+ return new Point((canvas.x + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0)) * scaleX, (canvas.y + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0)) * scaleY);
9498
9526
  };
9499
9527
  EventService.prototype.viewport2Canvas = function (_a) {
9500
9528
  var x = _a.x, y = _a.y;
@@ -10078,7 +10106,7 @@ var RenderingService = /** @class */ (function () {
10078
10106
  return (!enableDirtyRectangleRendering ||
10079
10107
  this.context.renderingContext.renderReasons.has(RenderReason.CAMERA_CHANGED));
10080
10108
  };
10081
- RenderingService.prototype.render = function (canvasConfig, rerenderCallback) {
10109
+ RenderingService.prototype.render = function (canvasConfig, frame, rerenderCallback) {
10082
10110
  var _this = this;
10083
10111
  this.stats.total = 0;
10084
10112
  this.stats.rendered = 0;
@@ -10097,7 +10125,7 @@ var RenderingService = /** @class */ (function () {
10097
10125
  if (shouldTriggerRenderHooks) {
10098
10126
  this.renderDisplayObject(renderingContext.root, canvasConfig, renderingContext);
10099
10127
  }
10100
- this.hooks.beginFrame.call();
10128
+ this.hooks.beginFrame.call(frame);
10101
10129
  if (shouldTriggerRenderHooks) {
10102
10130
  renderingContext.renderListCurrentFrame.forEach(function (object) {
10103
10131
  _this.hooks.beforeRender.call(object);
@@ -10105,7 +10133,7 @@ var RenderingService = /** @class */ (function () {
10105
10133
  _this.hooks.afterRender.call(object);
10106
10134
  });
10107
10135
  }
10108
- this.hooks.endFrame.call();
10136
+ this.hooks.endFrame.call(frame);
10109
10137
  renderingContext.renderListCurrentFrame = [];
10110
10138
  renderingContext.renderReasons.clear();
10111
10139
  rerenderCallback();
@@ -14459,28 +14487,6 @@ var EventPlugin = /** @class */ (function () {
14459
14487
  _this.setCursor(_this.context.eventService.cursor);
14460
14488
  });
14461
14489
  };
14462
- EventPlugin.prototype.getViewportXY = function (nativeEvent) {
14463
- var x;
14464
- var y;
14465
- /**
14466
- * Should account for CSS Transform applied on container.
14467
- * @see https://github.com/antvis/G/issues/1161
14468
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/offsetX
14469
- */
14470
- var offsetX = nativeEvent.offsetX, offsetY = nativeEvent.offsetY, clientX = nativeEvent.clientX, clientY = nativeEvent.clientY;
14471
- if (this.context.config.supportsCSSTransform &&
14472
- !isNil(offsetX) &&
14473
- !isNil(offsetY)) {
14474
- x = offsetX;
14475
- y = offsetY;
14476
- }
14477
- else {
14478
- var point = this.context.eventService.client2Viewport(new Point(clientX, clientY));
14479
- x = point.x;
14480
- y = point.y;
14481
- }
14482
- return { x: x, y: y };
14483
- };
14484
14490
  EventPlugin.prototype.bootstrapEvent = function (event, normalizedEvent, view, nativeEvent) {
14485
14491
  event.view = view;
14486
14492
  event.originalEvent = null;
@@ -14496,7 +14502,10 @@ var EventPlugin = /** @class */ (function () {
14496
14502
  event.tiltY = normalizedEvent.tiltY;
14497
14503
  event.twist = normalizedEvent.twist;
14498
14504
  this.transferMouseData(event, normalizedEvent);
14499
- var _a = this.getViewportXY(normalizedEvent), x = _a.x, y = _a.y;
14505
+ var _a = this.context.eventService.client2Viewport({
14506
+ x: normalizedEvent.clientX,
14507
+ y: normalizedEvent.clientY,
14508
+ }), x = _a.x, y = _a.y;
14500
14509
  event.viewport.x = x;
14501
14510
  event.viewport.y = y;
14502
14511
  var _b = this.context.eventService.viewport2Canvas(event.viewport), canvasX = _b.x, canvasY = _b.y;
@@ -14523,7 +14532,10 @@ var EventPlugin = /** @class */ (function () {
14523
14532
  event.deltaX = nativeEvent.deltaX;
14524
14533
  event.deltaY = nativeEvent.deltaY;
14525
14534
  event.deltaZ = nativeEvent.deltaZ;
14526
- var _a = this.getViewportXY(nativeEvent), x = _a.x, y = _a.y;
14535
+ var _a = this.context.eventService.client2Viewport({
14536
+ x: nativeEvent.clientX,
14537
+ y: nativeEvent.clientY,
14538
+ }), x = _a.x, y = _a.y;
14527
14539
  event.viewport.x = x;
14528
14540
  event.viewport.y = y;
14529
14541
  var _b = this.context.eventService.viewport2Canvas(event.viewport), canvasX = _b.x, canvasY = _b.y;
@@ -15175,11 +15187,11 @@ var Canvas = /** @class */ (function (_super) {
15175
15187
  Canvas.prototype.destroyChildren = function () {
15176
15188
  this.document.documentElement.destroyChildren();
15177
15189
  };
15178
- Canvas.prototype.render = function () {
15190
+ Canvas.prototype.render = function (frame) {
15179
15191
  var _this = this;
15180
15192
  this.dispatchEvent(beforeRenderEvent);
15181
15193
  var renderingService = this.getRenderingService();
15182
- renderingService.render(this.getConfig(), function () {
15194
+ renderingService.render(this.getConfig(), frame, function () {
15183
15195
  // trigger actual rerender event
15184
15196
  // @see https://github.com/antvis/G/issues/1268
15185
15197
  _this.dispatchEvent(rerenderEvent);
@@ -15188,8 +15200,8 @@ var Canvas = /** @class */ (function (_super) {
15188
15200
  };
15189
15201
  Canvas.prototype.run = function () {
15190
15202
  var _this = this;
15191
- var tick = function () {
15192
- _this.render();
15203
+ var tick = function (time, frame) {
15204
+ _this.render(frame);
15193
15205
  _this.frameId = _this.requestAnimationFrame(tick);
15194
15206
  };
15195
15207
  tick();