@antv/g-lite 2.0.7 → 2.0.9

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
@@ -67,6 +67,10 @@ export declare class Canvas extends EventTarget implements ICanvas {
67
67
  * is this native event a MouseEvent?
68
68
  */
69
69
  isMouseEvent: (event: InteractivePointerEvent) => event is MouseEvent;
70
+ /**
71
+ * double click speed (ms), default is 200ms
72
+ */
73
+ dblClickSpeed?: CanvasConfig['dblClickSpeed'];
70
74
  /**
71
75
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element
72
76
  */
@@ -1,5 +1,5 @@
1
1
  import type { DisplayObjectConfig } from '../dom';
2
- import { AABB, Rectangle } from '../shapes';
2
+ import { AABB } from '../shapes';
3
3
  import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
4
4
  import { DisplayObject } from './DisplayObject';
5
5
  export interface HTMLStyleProps extends BaseStyleProps {
@@ -32,9 +32,9 @@ export declare class HTML extends DisplayObject<HTMLStyleProps, ParsedHTMLStyleP
32
32
  /**
33
33
  * override with $el.getBoundingClientRect
34
34
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
35
+ *
36
+ * ! The calculation logic of the html element should be consistent with that of the canvas element
35
37
  */
36
- getBoundingClientRect(): Rectangle;
37
- getClientRects(): Rectangle[];
38
- getBounds(): AABB;
38
+ getClientRects(): import("../shapes").Rectangle[];
39
39
  getLocalBounds(): AABB;
40
40
  }
@@ -414,6 +414,7 @@ export interface ICanvas extends IEventTarget {
414
414
  supportsPointerEvents: boolean;
415
415
  isTouchEvent: (event: InteractivePointerEvent) => event is TouchEvent;
416
416
  isMouseEvent: (event: InteractivePointerEvent) => event is MouseEvent;
417
+ dblClickSpeed?: number;
417
418
  render: () => void;
418
419
  destroy: (destroyScenegraph?: boolean) => void;
419
420
  resize: (width: number, height: number) => void;
package/dist/index.esm.js CHANGED
@@ -1424,6 +1424,39 @@ var Rectangle = /** @class */ (function () {
1424
1424
  this.top = y;
1425
1425
  this.bottom = y + height;
1426
1426
  }
1427
+ /**
1428
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect/fromRect_static
1429
+ */
1430
+ Rectangle.fromRect = function (rect) {
1431
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
1432
+ };
1433
+ /**
1434
+ * will return a new rect instance
1435
+ */
1436
+ Rectangle.applyTransform = function (rect, matrix) {
1437
+ var topLeft = vec4.fromValues(rect.x, rect.y, 0, 1);
1438
+ var topRight = vec4.fromValues(rect.x + rect.width, rect.y, 0, 1);
1439
+ var bottomLeft = vec4.fromValues(rect.x, rect.y + rect.height, 0, 1);
1440
+ var bottomRight = vec4.fromValues(rect.x + rect.width, rect.y + rect.height, 0, 1);
1441
+ var transformedTopLeft = vec4.create();
1442
+ var transformedTopRight = vec4.create();
1443
+ var transformedBottomLeft = vec4.create();
1444
+ var transformedBottomRight = vec4.create();
1445
+ vec4.transformMat4(transformedTopLeft, topLeft, matrix);
1446
+ vec4.transformMat4(transformedTopRight, topRight, matrix);
1447
+ vec4.transformMat4(transformedBottomLeft, bottomLeft, matrix);
1448
+ vec4.transformMat4(transformedBottomRight, bottomRight, matrix);
1449
+ var minX = Math.min(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1450
+ var minY = Math.min(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1451
+ var maxX = Math.max(transformedTopLeft[0], transformedTopRight[0], transformedBottomLeft[0], transformedBottomRight[0]);
1452
+ var maxY = Math.max(transformedTopLeft[1], transformedTopRight[1], transformedBottomLeft[1], transformedBottomRight[1]);
1453
+ return Rectangle.fromRect({
1454
+ x: minX,
1455
+ y: minY,
1456
+ width: maxX - minX,
1457
+ height: maxY - minY,
1458
+ });
1459
+ };
1427
1460
  Rectangle.prototype.toJSON = function () { };
1428
1461
  return Rectangle;
1429
1462
  }());
@@ -8308,6 +8341,21 @@ var GroupUpdater = /** @class */ (function () {
8308
8341
  return GroupUpdater;
8309
8342
  }());
8310
8343
 
8344
+ var HTMLUpdater = /** @class */ (function () {
8345
+ function HTMLUpdater() {
8346
+ }
8347
+ HTMLUpdater.prototype.update = function (parsedStyle, object) {
8348
+ var _a = parsedStyle.x, x = _a === void 0 ? 0 : _a, _b = parsedStyle.y, y = _b === void 0 ? 0 : _b, _c = parsedStyle.width, width = _c === void 0 ? 0 : _c, _d = parsedStyle.height, height = _d === void 0 ? 0 : _d;
8349
+ return {
8350
+ cx: x + width / 2,
8351
+ cy: y + height / 2,
8352
+ hwidth: width / 2,
8353
+ hheight: height / 2,
8354
+ };
8355
+ };
8356
+ return HTMLUpdater;
8357
+ }());
8358
+
8311
8359
  function isFederatedEvent(value) {
8312
8360
  return !!value.type;
8313
8361
  }
@@ -9263,9 +9311,10 @@ var EventService = /** @class */ (function () {
9263
9311
  timeStamp: now,
9264
9312
  };
9265
9313
  }
9314
+ var canvas = _this.context.renderingContext.root.ownerDocument.defaultView;
9266
9315
  var clickHistory = trackingData.clicksByButton[from.button];
9267
9316
  if (clickHistory.target === clickEvent.target &&
9268
- now - clickHistory.timeStamp < 200) {
9317
+ now - clickHistory.timeStamp < canvas.dblClickSpeed) {
9269
9318
  ++clickHistory.clickCount;
9270
9319
  }
9271
9320
  else {
@@ -11621,7 +11670,7 @@ var geometryUpdaterFactory = (function () {
11621
11670
  _a[Shape.POLYLINE] = polylineUpdater,
11622
11671
  _a[Shape.POLYGON] = polylineUpdater,
11623
11672
  _a[Shape.PATH] = new PathUpdater(),
11624
- _a[Shape.HTML] = null,
11673
+ _a[Shape.HTML] = new HTMLUpdater(),
11625
11674
  _a[Shape.MESH] = null,
11626
11675
  _a;
11627
11676
  })();
@@ -13134,31 +13183,36 @@ var HTML = /** @class */ (function (_super) {
13134
13183
  /**
13135
13184
  * override with $el.getBoundingClientRect
13136
13185
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect
13137
- */
13138
- HTML.prototype.getBoundingClientRect = function () {
13139
- if (this.parsedStyle.$el) {
13140
- return this.parsedStyle.$el.getBoundingClientRect();
13141
- }
13142
- else {
13143
- var _a = this.parsedStyle, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
13144
- return new Rectangle(x, y, width, height);
13145
- }
13146
- };
13186
+ *
13187
+ * ! The calculation logic of the html element should be consistent with that of the canvas element
13188
+ */
13189
+ // getBoundingClientRect(): Rectangle {
13190
+ // if (this.parsedStyle.$el) {
13191
+ // return this.parsedStyle.$el.getBoundingClientRect();
13192
+ // } else {
13193
+ // const { x, y, width, height } = this.parsedStyle;
13194
+ // return new Rectangle(x, y, width, height);
13195
+ // }
13196
+ // }
13147
13197
  HTML.prototype.getClientRects = function () {
13148
13198
  return [this.getBoundingClientRect()];
13149
13199
  };
13150
- HTML.prototype.getBounds = function () {
13151
- var _a, _b;
13152
- var clientRect = this.getBoundingClientRect();
13153
- // calc context's offset
13154
- // @ts-ignore
13155
- var canvasRect = (_b = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getContextService().getBoundingClientRect();
13156
- var aabb = new AABB();
13157
- var minX = clientRect.left - ((canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.left) || 0);
13158
- var minY = clientRect.top - ((canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.top) || 0);
13159
- aabb.setMinMax([minX, minY, 0], [minX + clientRect.width, minY + clientRect.height, 0]);
13160
- return aabb;
13161
- };
13200
+ // getBounds() {
13201
+ // const clientRect = this.getBoundingClientRect();
13202
+ // // calc context's offset
13203
+ // // @ts-ignore
13204
+ // const canvasRect = this.ownerDocument?.defaultView
13205
+ // ?.getContextService()
13206
+ // .getBoundingClientRect();
13207
+ // const aabb = new AABB();
13208
+ // const minX = clientRect.left - (canvasRect?.left || 0);
13209
+ // const minY = clientRect.top - (canvasRect?.top || 0);
13210
+ // aabb.setMinMax(
13211
+ // [minX, minY, 0],
13212
+ // [minX + clientRect.width, minY + clientRect.height, 0],
13213
+ // );
13214
+ // return aabb;
13215
+ // }
13162
13216
  HTML.prototype.getLocalBounds = function () {
13163
13217
  if (this.parentNode) {
13164
13218
  var parentInvert = mat4.invert(mat4.create(), this.parentNode.getWorldTransform());
@@ -14937,7 +14991,7 @@ var Canvas = /** @class */ (function (_super) {
14937
14991
  _this.document.defaultView = _this;
14938
14992
  // create registry of custom elements
14939
14993
  _this.customElements = new CustomElementRegistry();
14940
- var container = config.container, canvas = config.canvas, offscreenCanvas = config.offscreenCanvas, width = config.width, height = config.height, devicePixelRatio = config.devicePixelRatio, renderer = config.renderer, background = config.background, cursor = config.cursor, document = config.document, requestAnimationFrame = config.requestAnimationFrame, cancelAnimationFrame = config.cancelAnimationFrame, createImage = config.createImage, supportsPointerEvents = config.supportsPointerEvents, supportsTouchEvents = config.supportsTouchEvents, supportsCSSTransform = config.supportsCSSTransform, supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer, useNativeClickEvent = config.useNativeClickEvent, alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas, isTouchEvent = config.isTouchEvent, isMouseEvent = config.isMouseEvent;
14994
+ var container = config.container, canvas = config.canvas, offscreenCanvas = config.offscreenCanvas, width = config.width, height = config.height, devicePixelRatio = config.devicePixelRatio, renderer = config.renderer, background = config.background, cursor = config.cursor, document = config.document, requestAnimationFrame = config.requestAnimationFrame, cancelAnimationFrame = config.cancelAnimationFrame, createImage = config.createImage, supportsPointerEvents = config.supportsPointerEvents, supportsTouchEvents = config.supportsTouchEvents, supportsCSSTransform = config.supportsCSSTransform, supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer, useNativeClickEvent = config.useNativeClickEvent, alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas, isTouchEvent = config.isTouchEvent, isMouseEvent = config.isMouseEvent, dblClickSpeed = config.dblClickSpeed;
14941
14995
  if (!supportsMutipleCanvasesInOneContainer) {
14942
14996
  cleanExistedCanvas(container, _this);
14943
14997
  }
@@ -14985,6 +15039,7 @@ var Canvas = /** @class */ (function (_super) {
14985
15039
  (!_this.supportsPointerEvents ||
14986
15040
  !(event instanceof runtime.globalThis.PointerEvent)));
14987
15041
  });
15042
+ _this.dblClickSpeed = dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200;
14988
15043
  _this.initRenderingContext({
14989
15044
  container: container,
14990
15045
  canvas: canvas,
@@ -15403,5 +15458,5 @@ var Canvas = /** @class */ (function (_super) {
15403
15458
  return Canvas;
15404
15459
  }(EventTarget));
15405
15460
 
15406
- export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GradientType, Group, GroupUpdater, HTML, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBush, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg };
15461
+ export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GradientType, Group, GroupUpdater, HTML, HTMLUpdater, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBush, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg };
15407
15462
  //# sourceMappingURL=index.esm.js.map