@antv/g-lite 2.2.8 → 2.2.10

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
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @antv/g-lite
3
3
  * @description A core module for rendering engine implements DOM API.
4
- * @version 2.2.8
5
- * @date 11/27/2024, 12:17:33 PM
4
+ * @version 2.2.10
5
+ * @date 12/20/2024, 6:51:24 AM
6
6
  * @author AntVis
7
7
  * @docs https://g.antv.antgroup.com/
8
8
  */
@@ -4213,16 +4213,22 @@ function parseDimensionArrayFormat(string, size) {
4213
4213
  }
4214
4214
  return [parsed[0], parsed[1]];
4215
4215
  }
4216
- if (parsed.length === 1) {
4217
- return [parsed[0], parsed[0], parsed[0], parsed[0]];
4218
- }
4219
- if (parsed.length === 2) {
4220
- return [parsed[0], parsed[1], parsed[0], parsed[1]];
4216
+ if (size === 4) {
4217
+ if (parsed.length === 1) {
4218
+ return [parsed[0], parsed[0], parsed[0], parsed[0]];
4219
+ }
4220
+ if (parsed.length === 2) {
4221
+ return [parsed[0], parsed[1], parsed[0], parsed[1]];
4222
+ }
4223
+ if (parsed.length === 3) {
4224
+ return [parsed[0], parsed[1], parsed[2], parsed[1]];
4225
+ }
4226
+ return [parsed[0], parsed[1], parsed[2], parsed[3]];
4221
4227
  }
4222
- if (parsed.length === 3) {
4223
- return [parsed[0], parsed[1], parsed[2], parsed[1]];
4228
+ if (size === 'even' && parsed.length % 2 === 1) {
4229
+ return [].concat(_toConsumableArray(parsed), _toConsumableArray(parsed));
4224
4230
  }
4225
- return [parsed[0], parsed[1], parsed[2], parsed[3]];
4231
+ return parsed;
4226
4232
  }
4227
4233
 
4228
4234
  // export function mergeDimensionList(
@@ -5088,7 +5094,7 @@ function translatePathToString(absolutePath) {
5088
5094
  case 'C':
5089
5095
  return "C ".concat(params[1], " ").concat(params[2], ",").concat(params[3], " ").concat(params[4], ",").concat(params[5] + endOffsetXTemp, " ").concat(params[6] + endOffsetYTemp);
5090
5096
  case 'A':
5091
- return "A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6] + endOffsetXTemp, " ").concat(params[7] + endOffsetYTemp);
5097
+ return "A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6], " ").concat(params[7]).concat(useEndOffset ? " L ".concat(params[6] + endOffsetX, ",").concat(params[7] + endOffsetY) : '');
5092
5098
  case 'Z':
5093
5099
  return 'Z';
5094
5100
  default:
@@ -6425,7 +6431,8 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
6425
6431
  }
6426
6432
  // Polyline
6427
6433
  if (list.has('lineDash') && !util.isNil(attributes.lineDash)) {
6428
- object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6434
+ // dom标准自动转化奇数长度数组,webgl需要手动处理
6435
+ object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 'even');
6429
6436
  }
6430
6437
  // @ts-ignore
6431
6438
  if (list.has('points') && attributes.points) {
@@ -8884,11 +8891,6 @@ var Node = /*#__PURE__*/function (_EventTarget) {
8884
8891
  }
8885
8892
  return temp;
8886
8893
  }
8887
-
8888
- /**
8889
- * iterate current node and its descendants
8890
- * @param callback - callback to execute for each node, return false to break
8891
- */
8892
8894
  }, {
8893
8895
  key: "forEach",
8894
8896
  value: function forEach(callback) {
@@ -8942,7 +8944,6 @@ var EventService = /*#__PURE__*/function () {
8942
8944
  function EventService(globalRuntime, context) {
8943
8945
  var _this = this;
8944
8946
  _classCallCheck(this, EventService);
8945
- this.emitter = new EventEmitter();
8946
8947
  /**
8947
8948
  * Store HTML elements in current canvas.
8948
8949
  */
@@ -9019,7 +9020,7 @@ var EventService = /*#__PURE__*/function () {
9019
9020
  }
9020
9021
  var canvas = _this.context.renderingContext.root.ownerDocument.defaultView;
9021
9022
  var clickHistory = trackingData.clicksByButton[from.button];
9022
- if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.dblClickSpeed) {
9023
+ if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.getConfig().dblClickSpeed) {
9023
9024
  ++clickHistory.clickCount;
9024
9025
  } else {
9025
9026
  clickHistory.clickCount = 1;
@@ -9234,7 +9235,6 @@ var EventService = /*#__PURE__*/function () {
9234
9235
  }, {
9235
9236
  key: "destroy",
9236
9237
  value: function destroy() {
9237
- this.emitter.removeAllListeners();
9238
9238
  this.mappingTable = {};
9239
9239
  this.mappingState = {};
9240
9240
  this.eventPool.clear();
@@ -9370,7 +9370,6 @@ var EventService = /*#__PURE__*/function () {
9370
9370
  e.currentTarget = canvas;
9371
9371
  this.notifyListeners(e, type);
9372
9372
  }
9373
- this.emitter.emit(type || e.type, e);
9374
9373
  }
9375
9374
  }, {
9376
9375
  key: "propagate",
@@ -10225,22 +10224,35 @@ var DefaultSceneGraphSelector = /*#__PURE__*/function () {
10225
10224
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
10226
10225
  */
10227
10226
  var ElementEvent = /*#__PURE__*/function (ElementEvent) {
10228
- ElementEvent["REPARENT"] = "reparent";
10229
- ElementEvent["DESTROY"] = "destroy";
10230
10227
  ElementEvent["ATTR_MODIFIED"] = "DOMAttrModified";
10231
10228
  ElementEvent["INSERTED"] = "DOMNodeInserted";
10232
- ElementEvent["REMOVED"] = "removed";
10233
10229
  ElementEvent["MOUNTED"] = "DOMNodeInsertedIntoDocument";
10230
+ ElementEvent["REMOVED"] = "removed";
10234
10231
  ElementEvent["UNMOUNTED"] = "DOMNodeRemovedFromDocument";
10232
+ ElementEvent["REPARENT"] = "reparent";
10233
+ ElementEvent["DESTROY"] = "destroy";
10235
10234
  ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
10236
10235
  ElementEvent["CULLED"] = "culled";
10237
10236
  return ElementEvent;
10238
10237
  }({});
10239
10238
 
10239
+ // #region EventTarget
10240
+
10241
+ // #region Node
10242
+
10243
+ // #region Element
10244
+
10245
+ // #region AnimationTimeline
10246
+
10247
+ // #region Document
10248
+
10249
+ // #region CSSStyleDeclaration
10240
10250
  /**
10241
10251
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleDeclaration
10242
10252
  */
10243
10253
 
10254
+ // #region Canvas
10255
+
10244
10256
  var MutationEvent = /*#__PURE__*/function (_FederatedEvent) {
10245
10257
  function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
10246
10258
  var _this;
@@ -11505,7 +11517,7 @@ var TextService = /*#__PURE__*/function () {
11505
11517
  }
11506
11518
 
11507
11519
  // Backspace from line's end.
11508
- var currentLineLength = lines[lineIndex].length;
11520
+ var currentLineLength = lines[lineIndex] ? lines[lineIndex].length : 0;
11509
11521
  var lastLineWidth = 0;
11510
11522
  var lastLineIndex = currentLineLength;
11511
11523
  for (var i = 0; i < currentLineLength; i++) {
@@ -15311,109 +15323,63 @@ var afterRenderEvent = new CustomEvent(CanvasEvent.AFTER_RENDER);
15311
15323
  * * `window.devicePixelRatio`
15312
15324
  *
15313
15325
  * prototype chains: Canvas(Window) -> EventTarget
15326
+ *
15327
+ * @docs https://g.antv.antgroup.com/api/canvas/intro
15314
15328
  */
15315
15329
  var Canvas = /*#__PURE__*/function (_EventTarget) {
15316
15330
  function Canvas(config) {
15317
15331
  var _this;
15318
15332
  _classCallCheck(this, Canvas);
15319
15333
  _this = _callSuper(this, Canvas);
15320
-
15321
- // create document
15334
+ // #region environment
15322
15335
  /**
15323
15336
  * window.document
15324
15337
  */
15325
- /**
15326
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
15327
- */
15328
- /**
15329
- * @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
15330
- */
15331
- /**
15332
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
15333
- */
15334
- /**
15335
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
15336
- */
15337
- /**
15338
- * whether the runtime supports PointerEvent?
15339
- * if not, the event system won't trigger pointer events like `pointerdown`
15340
- */
15341
- /**
15342
- * whether the runtime supports TouchEvent?
15343
- * if not, the event system won't trigger touch events like `touchstart`
15344
- */
15345
- /**
15346
- * is this native event a TouchEvent?
15347
- */
15348
- /**
15349
- * is this native event a MouseEvent?
15350
- */
15351
15338
  /**
15352
15339
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element
15353
15340
  */
15354
15341
  _this.Element = DisplayObject;
15355
15342
  _this.inited = false;
15356
15343
  _this.context = {};
15357
- _this.document = new Document();
15358
- _this.document.defaultView = _this;
15359
-
15360
- // create registry of custom elements
15361
- _this.customElements = new CustomElementRegistry();
15362
15344
  var container = config.container,
15363
15345
  canvas = config.canvas,
15364
- offscreenCanvas = config.offscreenCanvas,
15346
+ renderer = config.renderer,
15365
15347
  width = config.width,
15366
15348
  height = config.height,
15367
- devicePixelRatio = config.devicePixelRatio,
15368
- renderer = config.renderer,
15369
15349
  background = config.background,
15370
15350
  cursor = config.cursor,
15371
- document = config.document,
15351
+ supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
15352
+ _config$cleanUpOnDest = config.cleanUpOnDestroy,
15353
+ cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
15354
+ offscreenCanvas = config.offscreenCanvas,
15355
+ devicePixelRatio = config.devicePixelRatio,
15372
15356
  requestAnimationFrame = config.requestAnimationFrame,
15373
15357
  cancelAnimationFrame = config.cancelAnimationFrame,
15374
15358
  createImage = config.createImage,
15375
- enableLargeImageOptimization = config.enableLargeImageOptimization,
15376
- supportsPointerEvents = config.supportsPointerEvents,
15377
15359
  supportsTouchEvents = config.supportsTouchEvents,
15378
- supportsCSSTransform = config.supportsCSSTransform,
15379
- _config$cleanUpOnDest = config.cleanUpOnDestroy,
15380
- cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
15381
- supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
15382
- useNativeClickEvent = config.useNativeClickEvent,
15383
- alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas,
15360
+ supportsPointerEvents = config.supportsPointerEvents,
15384
15361
  isTouchEvent = config.isTouchEvent,
15385
15362
  isMouseEvent = config.isMouseEvent,
15386
15363
  dblClickSpeed = config.dblClickSpeed;
15387
- if (!supportsMutipleCanvasesInOneContainer) {
15388
- cleanExistedCanvas(container, _this, cleanUpOnDestroy);
15389
- }
15390
15364
  var canvasWidth = width;
15391
15365
  var canvasHeight = height;
15392
- var dpr = devicePixelRatio;
15366
+ var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
15367
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
15368
+
15393
15369
  // use user-defined <canvas> or OffscreenCanvas
15394
15370
  if (canvas) {
15395
15371
  // infer width & height with dpr
15396
- dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
15397
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
15398
15372
  canvasWidth = width || getWidth(canvas) || canvas.width / dpr;
15399
15373
  canvasHeight = height || getHeight(canvas) || canvas.height / dpr;
15400
15374
  }
15401
15375
 
15402
- // override it in runtime
15403
- if (offscreenCanvas) {
15404
- runtime.offscreenCanvas = offscreenCanvas;
15405
- }
15406
-
15407
15376
  /**
15408
15377
  * implements `Window` interface
15409
15378
  */
15379
+ _this.customElements = new CustomElementRegistry();
15410
15380
  _this.devicePixelRatio = dpr;
15411
15381
  _this.requestAnimationFrame = requestAnimationFrame !== null && requestAnimationFrame !== void 0 ? requestAnimationFrame : raf.bind(runtime.globalThis);
15412
15382
  _this.cancelAnimationFrame = cancelAnimationFrame !== null && cancelAnimationFrame !== void 0 ? cancelAnimationFrame : caf.bind(runtime.globalThis);
15413
-
15414
- /**
15415
- * limits query
15416
- */
15417
15383
  // the following feature-detect from hammer.js
15418
15384
  // @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
15419
15385
  _this.supportsTouchEvents = supportsTouchEvents !== null && supportsTouchEvents !== void 0 ? supportsTouchEvents : 'ontouchstart' in runtime.globalThis;
@@ -15424,25 +15390,36 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15424
15390
  _this.isMouseEvent = isMouseEvent !== null && isMouseEvent !== void 0 ? isMouseEvent : function (event) {
15425
15391
  return !runtime.globalThis.MouseEvent || event instanceof runtime.globalThis.MouseEvent && (!_this.supportsPointerEvents || !(event instanceof runtime.globalThis.PointerEvent));
15426
15392
  };
15427
- _this.dblClickSpeed = dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200;
15428
- _this.initRenderingContext({
15429
- container: container,
15430
- canvas: canvas,
15393
+
15394
+ // override it in runtime
15395
+ if (offscreenCanvas) {
15396
+ runtime.offscreenCanvas = offscreenCanvas;
15397
+ }
15398
+
15399
+ // create document
15400
+ _this.document = new Document();
15401
+ _this.document.defaultView = _this;
15402
+ if (!supportsMutipleCanvasesInOneContainer) {
15403
+ cleanExistedCanvas(container, _this, cleanUpOnDestroy);
15404
+ }
15405
+ _this.initRenderingContext(_objectSpread(_objectSpread({}, config), {}, {
15431
15406
  width: canvasWidth,
15432
15407
  height: canvasHeight,
15433
- renderer: renderer,
15434
- offscreenCanvas: offscreenCanvas,
15435
- devicePixelRatio: dpr,
15436
- cursor: cursor || 'default',
15437
- background: background || 'transparent',
15438
- createImage: createImage,
15439
- enableLargeImageOptimization: enableLargeImageOptimization,
15440
- document: document,
15441
- supportsCSSTransform: supportsCSSTransform,
15442
- useNativeClickEvent: useNativeClickEvent,
15408
+ background: background !== null && background !== void 0 ? background : 'transparent',
15409
+ cursor: cursor !== null && cursor !== void 0 ? cursor : 'default',
15443
15410
  cleanUpOnDestroy: cleanUpOnDestroy,
15444
- alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
15445
- });
15411
+ devicePixelRatio: dpr,
15412
+ requestAnimationFrame: _this.requestAnimationFrame,
15413
+ cancelAnimationFrame: _this.cancelAnimationFrame,
15414
+ supportsTouchEvents: _this.supportsTouchEvents,
15415
+ supportsPointerEvents: _this.supportsPointerEvents,
15416
+ isTouchEvent: _this.isTouchEvent,
15417
+ isMouseEvent: _this.isMouseEvent,
15418
+ dblClickSpeed: dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200,
15419
+ createImage: createImage !== null && createImage !== void 0 ? createImage : function () {
15420
+ return new window.Image();
15421
+ }
15422
+ }));
15446
15423
  _this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
15447
15424
  _this.initRenderer(renderer, true);
15448
15425
  return _this;
@@ -15603,8 +15580,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15603
15580
  if (this.context.rBushRoot) {
15604
15581
  // clear rbush
15605
15582
  this.context.rBushRoot.clear();
15606
- this.context.rBushRoot = null;
15607
- this.context.renderingContext.root = null;
15608
15583
  }
15609
15584
  if (!skipTriggerEvent) {
15610
15585
  this.dispatchEvent(new CustomEvent(CanvasEvent.AFTER_DESTROY));
@@ -15701,6 +15676,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15701
15676
  key: "render",
15702
15677
  value: function render(frame) {
15703
15678
  var _this4 = this;
15679
+ // console.log('render ----------------------');
15704
15680
  if (frame) {
15705
15681
  beforeRenderEvent.detail = frame;
15706
15682
  afterRenderEvent.detail = frame;
@@ -15764,6 +15740,8 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15764
15740
  } else {
15765
15741
  this.context.contextService.initAsync().then(function () {
15766
15742
  _this6.initRenderingService(renderer, firstContentfullPaint);
15743
+ })["catch"](function (err) {
15744
+ console.error(err);
15767
15745
  });
15768
15746
  }
15769
15747
  }