@antv/g-lite 1.2.3 → 1.2.5

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.
@@ -1,6 +1,5 @@
1
- import type { CSSUnitValue } from '../css';
2
1
  import type { DisplayObjectConfig } from '../dom';
3
- import { AABB } from '../shapes';
2
+ import { AABB, Rectangle } from '../shapes';
4
3
  import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
5
4
  import { DisplayObject } from './DisplayObject';
6
5
  export interface HTMLStyleProps extends BaseStyleProps {
@@ -11,12 +10,12 @@ export interface HTMLStyleProps extends BaseStyleProps {
11
10
  height?: number | string;
12
11
  }
13
12
  export interface ParsedHTMLStyleProps extends ParsedBaseStyleProps {
14
- x: CSSUnitValue;
15
- y: CSSUnitValue;
13
+ x: number;
14
+ y: number;
16
15
  $el: HTMLElement;
17
16
  innerHTML: string | HTMLElement;
18
- width: CSSUnitValue;
19
- height: CSSUnitValue;
17
+ width: number;
18
+ height: number;
20
19
  }
21
20
  /**
22
21
  * HTML container
@@ -34,8 +33,8 @@ export declare class HTML extends DisplayObject<HTMLStyleProps, ParsedHTMLStyleP
34
33
  * override with $el.getBoundingClientRect
35
34
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
36
35
  */
37
- getBoundingClientRect(): DOMRect;
38
- getClientRects(): DOMRect[];
36
+ getBoundingClientRect(): Rectangle;
37
+ getClientRects(): Rectangle[];
39
38
  getBounds(): AABB;
40
39
  getLocalBounds(): AABB;
41
40
  }
@@ -6,13 +6,14 @@ import { PropertySyntax } from './css/interfaces';
6
6
  import type { HTML } from './display-objects';
7
7
  import type { GeometryAABBUpdater, SceneGraphSelector, SceneGraphService } from './services';
8
8
  import { OffscreenCanvasCreator, TextService } from './services';
9
- import { Shape } from './types';
9
+ import { CanvasLike, Shape } from './types';
10
10
  export declare const runtime: GlobalRuntime;
11
11
  export interface GlobalRuntime {
12
12
  CameraContribution: new () => Camera;
13
13
  AnimationTimeline: any;
14
14
  EasingFunction: (...args: any[]) => (t: number) => number;
15
- offscreenCanvas: OffscreenCanvasCreator;
15
+ offscreenCanvasCreator: OffscreenCanvasCreator;
16
+ offscreenCanvas: CanvasLike;
16
17
  sceneGraphSelector: SceneGraphSelector;
17
18
  sceneGraphService: SceneGraphService;
18
19
  textService: TextService;
package/dist/index.esm.js CHANGED
@@ -8198,7 +8198,6 @@ var TextUpdater = /** @class */ (function () {
8198
8198
  TextUpdater.prototype.update = function (parsedStyle, object) {
8199
8199
  var _a, _b;
8200
8200
  var text = parsedStyle.text, textAlign = parsedStyle.textAlign, lineWidth = parsedStyle.lineWidth, textBaseline = parsedStyle.textBaseline, dx = parsedStyle.dx, dy = parsedStyle.dy;
8201
- var offscreenCanvas = (((_b = (_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getConfig()) || {}).offscreenCanvas;
8202
8201
  if (!this.isReadyToMeasure(parsedStyle, object)) {
8203
8202
  parsedStyle.metrics = {
8204
8203
  font: '',
@@ -8224,6 +8223,7 @@ var TextUpdater = /** @class */ (function () {
8224
8223
  offsetY: 0,
8225
8224
  };
8226
8225
  }
8226
+ var offscreenCanvas = (((_b = (_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getConfig()) || {}).offscreenCanvas;
8227
8227
  var metrics = this.globalRuntime.textService.measureText(text, parsedStyle, offscreenCanvas);
8228
8228
  parsedStyle.metrics = metrics;
8229
8229
  var width = metrics.width, height = metrics.height, lineHeight = metrics.lineHeight, fontProperties = metrics.fontProperties;
@@ -9889,8 +9889,8 @@ var OffscreenCanvasCreator = /** @class */ (function () {
9889
9889
  return this.canvas;
9890
9890
  }
9891
9891
  // user-defined offscreen canvas
9892
- if (offscreenCanvas) {
9893
- this.canvas = offscreenCanvas;
9892
+ if (offscreenCanvas || runtime.offscreenCanvas) {
9893
+ this.canvas = offscreenCanvas || runtime.offscreenCanvas;
9894
9894
  this.context = this.canvas.getContext('2d', contextAttributes);
9895
9895
  }
9896
9896
  else {
@@ -11167,8 +11167,8 @@ var TextService = /** @class */ (function () {
11167
11167
  descent: 0,
11168
11168
  fontSize: 0,
11169
11169
  };
11170
- var canvas = this.runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
11171
- var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas, {
11170
+ var canvas = this.runtime.offscreenCanvasCreator.getOrCreateCanvas(offscreenCanvas);
11171
+ var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas, {
11172
11172
  willReadFrequently: true,
11173
11173
  });
11174
11174
  context.font = font;
@@ -11253,7 +11253,7 @@ var TextService = /** @class */ (function () {
11253
11253
  // fontSize,
11254
11254
  // };
11255
11255
  // }
11256
- var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
11256
+ var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
11257
11257
  context.font = font;
11258
11258
  // no overflowing by default
11259
11259
  parsedStyle.isOverflowing = false;
@@ -11351,7 +11351,7 @@ var TextService = /** @class */ (function () {
11351
11351
  TextService.prototype.wordWrap = function (text, parsedStyle, offscreenCanvas) {
11352
11352
  var _this = this;
11353
11353
  var _a = parsedStyle.wordWrapWidth, wordWrapWidth = _a === void 0 ? 0 : _a, letterSpacing = parsedStyle.letterSpacing, _b = parsedStyle.maxLines, maxLines = _b === void 0 ? Infinity : _b, textOverflow = parsedStyle.textOverflow;
11354
- var context = this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
11354
+ var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
11355
11355
  var maxWidth = wordWrapWidth + letterSpacing;
11356
11356
  var ellipsis = '';
11357
11357
  if (textOverflow === 'ellipsis') {
@@ -11550,10 +11550,10 @@ var getGlobalThis = function () {
11550
11550
  // @ts-ignore
11551
11551
  if (typeof global !== 'undefined')
11552
11552
  return global;
11553
+ return {};
11553
11554
  // [!] Error: The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
11554
11555
  // @see https://rollupjs.org/troubleshooting/#error-this-is-undefined
11555
11556
  // if (typeof this !== 'undefined') return this;
11556
- throw new Error('Unable to locate global `this`');
11557
11557
  };
11558
11558
  /**
11559
11559
  * Camera
@@ -11565,7 +11565,7 @@ runtime.CameraContribution = Camera;
11565
11565
  */
11566
11566
  runtime.AnimationTimeline = null;
11567
11567
  runtime.EasingFunction = null;
11568
- runtime.offscreenCanvas = new OffscreenCanvasCreator();
11568
+ runtime.offscreenCanvasCreator = new OffscreenCanvasCreator();
11569
11569
  runtime.nativeHTMLMap = new WeakMap();
11570
11570
  runtime.sceneGraphSelector = new DefaultSceneGraphSelector();
11571
11571
  runtime.sceneGraphService = new DefaultSceneGraphService(runtime);
@@ -13140,7 +13140,13 @@ var HTML = /** @class */ (function (_super) {
13140
13140
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
13141
13141
  */
13142
13142
  HTML.prototype.getBoundingClientRect = function () {
13143
- return this.parsedStyle.$el.getBoundingClientRect();
13143
+ if (this.parsedStyle.$el) {
13144
+ return this.parsedStyle.$el.getBoundingClientRect();
13145
+ }
13146
+ else {
13147
+ var _a = this.parsedStyle, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
13148
+ return new Rectangle(x, y, width, height);
13149
+ }
13144
13150
  };
13145
13151
  HTML.prototype.getClientRects = function () {
13146
13152
  return [this.getBoundingClientRect()];
@@ -13151,18 +13157,11 @@ var HTML = /** @class */ (function (_super) {
13151
13157
  // calc context's offset
13152
13158
  // @ts-ignore
13153
13159
  var canvasRect = (_b = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getContextService().getBoundingClientRect();
13154
- if (canvasRect) {
13155
- var minX = clientRect.left - canvasRect.left;
13156
- var minY = clientRect.top - canvasRect.top;
13157
- var aabb = new AABB();
13158
- // aabb.setMinMax(
13159
- // vec3.fromValues(minX, minY, 0),
13160
- // vec3.fromValues(minX + clientRect.width, minY + clientRect.height, 0),
13161
- // );
13162
- aabb.setMinMax([minX, minY, 0], [minX + clientRect.width, minY + clientRect.height, 0]);
13163
- return aabb;
13164
- }
13165
- return null;
13160
+ var aabb = new AABB();
13161
+ var minX = clientRect.left - ((canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.left) || 0);
13162
+ var minY = clientRect.top - ((canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.top) || 0);
13163
+ aabb.setMinMax([minX, minY, 0], [minX + clientRect.width, minY + clientRect.height, 0]);
13164
+ return aabb;
13166
13165
  };
13167
13166
  HTML.prototype.getLocalBounds = function () {
13168
13167
  if (this.parentNode) {
@@ -14898,6 +14897,10 @@ var Canvas = /** @class */ (function (_super) {
14898
14897
  canvasWidth = width || getWidth(canvas) || canvas.width / dpr;
14899
14898
  canvasHeight = height || getHeight(canvas) || canvas.height / dpr;
14900
14899
  }
14900
+ // override it in runtime
14901
+ if (offscreenCanvas) {
14902
+ runtime.offscreenCanvas = offscreenCanvas;
14903
+ }
14901
14904
  /**
14902
14905
  * implements `Window` interface
14903
14906
  */