@antv/g-lite 2.2.9 → 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.esm.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.9
5
- * @date 11/27/2024, 2:16:03 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
  */
@@ -4192,16 +4192,22 @@ function parseDimensionArrayFormat(string, size) {
4192
4192
  }
4193
4193
  return [parsed[0], parsed[1]];
4194
4194
  }
4195
- if (parsed.length === 1) {
4196
- return [parsed[0], parsed[0], parsed[0], parsed[0]];
4197
- }
4198
- if (parsed.length === 2) {
4199
- return [parsed[0], parsed[1], parsed[0], parsed[1]];
4195
+ if (size === 4) {
4196
+ if (parsed.length === 1) {
4197
+ return [parsed[0], parsed[0], parsed[0], parsed[0]];
4198
+ }
4199
+ if (parsed.length === 2) {
4200
+ return [parsed[0], parsed[1], parsed[0], parsed[1]];
4201
+ }
4202
+ if (parsed.length === 3) {
4203
+ return [parsed[0], parsed[1], parsed[2], parsed[1]];
4204
+ }
4205
+ return [parsed[0], parsed[1], parsed[2], parsed[3]];
4200
4206
  }
4201
- if (parsed.length === 3) {
4202
- return [parsed[0], parsed[1], parsed[2], parsed[1]];
4207
+ if (size === 'even' && parsed.length % 2 === 1) {
4208
+ return [].concat(_toConsumableArray(parsed), _toConsumableArray(parsed));
4203
4209
  }
4204
- return [parsed[0], parsed[1], parsed[2], parsed[3]];
4210
+ return parsed;
4205
4211
  }
4206
4212
 
4207
4213
  // export function mergeDimensionList(
@@ -5067,7 +5073,7 @@ function translatePathToString(absolutePath) {
5067
5073
  case 'C':
5068
5074
  return "C ".concat(params[1], " ").concat(params[2], ",").concat(params[3], " ").concat(params[4], ",").concat(params[5] + endOffsetXTemp, " ").concat(params[6] + endOffsetYTemp);
5069
5075
  case 'A':
5070
- 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);
5076
+ 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) : '');
5071
5077
  case 'Z':
5072
5078
  return 'Z';
5073
5079
  default:
@@ -6404,7 +6410,8 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
6404
6410
  }
6405
6411
  // Polyline
6406
6412
  if (list.has('lineDash') && !isNil(attributes.lineDash)) {
6407
- object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 2);
6413
+ // dom标准自动转化奇数长度数组,webgl需要手动处理
6414
+ object.parsedStyle.lineDash = parseDimensionArrayFormat(attributes.lineDash, 'even');
6408
6415
  }
6409
6416
  // @ts-ignore
6410
6417
  if (list.has('points') && attributes.points) {
@@ -8863,11 +8870,6 @@ var Node = /*#__PURE__*/function (_EventTarget) {
8863
8870
  }
8864
8871
  return temp;
8865
8872
  }
8866
-
8867
- /**
8868
- * iterate current node and its descendants
8869
- * @param callback - callback to execute for each node, return false to break
8870
- */
8871
8873
  }, {
8872
8874
  key: "forEach",
8873
8875
  value: function forEach(callback) {
@@ -8921,7 +8923,6 @@ var EventService = /*#__PURE__*/function () {
8921
8923
  function EventService(globalRuntime, context) {
8922
8924
  var _this = this;
8923
8925
  _classCallCheck(this, EventService);
8924
- this.emitter = new EventEmitter();
8925
8926
  /**
8926
8927
  * Store HTML elements in current canvas.
8927
8928
  */
@@ -8998,7 +8999,7 @@ var EventService = /*#__PURE__*/function () {
8998
8999
  }
8999
9000
  var canvas = _this.context.renderingContext.root.ownerDocument.defaultView;
9000
9001
  var clickHistory = trackingData.clicksByButton[from.button];
9001
- if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.dblClickSpeed) {
9002
+ if (clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < canvas.getConfig().dblClickSpeed) {
9002
9003
  ++clickHistory.clickCount;
9003
9004
  } else {
9004
9005
  clickHistory.clickCount = 1;
@@ -9213,7 +9214,6 @@ var EventService = /*#__PURE__*/function () {
9213
9214
  }, {
9214
9215
  key: "destroy",
9215
9216
  value: function destroy() {
9216
- this.emitter.removeAllListeners();
9217
9217
  this.mappingTable = {};
9218
9218
  this.mappingState = {};
9219
9219
  this.eventPool.clear();
@@ -9349,7 +9349,6 @@ var EventService = /*#__PURE__*/function () {
9349
9349
  e.currentTarget = canvas;
9350
9350
  this.notifyListeners(e, type);
9351
9351
  }
9352
- this.emitter.emit(type || e.type, e);
9353
9352
  }
9354
9353
  }, {
9355
9354
  key: "propagate",
@@ -10204,22 +10203,35 @@ var DefaultSceneGraphSelector = /*#__PURE__*/function () {
10204
10203
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
10205
10204
  */
10206
10205
  var ElementEvent = /*#__PURE__*/function (ElementEvent) {
10207
- ElementEvent["REPARENT"] = "reparent";
10208
- ElementEvent["DESTROY"] = "destroy";
10209
10206
  ElementEvent["ATTR_MODIFIED"] = "DOMAttrModified";
10210
10207
  ElementEvent["INSERTED"] = "DOMNodeInserted";
10211
- ElementEvent["REMOVED"] = "removed";
10212
10208
  ElementEvent["MOUNTED"] = "DOMNodeInsertedIntoDocument";
10209
+ ElementEvent["REMOVED"] = "removed";
10213
10210
  ElementEvent["UNMOUNTED"] = "DOMNodeRemovedFromDocument";
10211
+ ElementEvent["REPARENT"] = "reparent";
10212
+ ElementEvent["DESTROY"] = "destroy";
10214
10213
  ElementEvent["BOUNDS_CHANGED"] = "bounds-changed";
10215
10214
  ElementEvent["CULLED"] = "culled";
10216
10215
  return ElementEvent;
10217
10216
  }({});
10218
10217
 
10218
+ // #region EventTarget
10219
+
10220
+ // #region Node
10221
+
10222
+ // #region Element
10223
+
10224
+ // #region AnimationTimeline
10225
+
10226
+ // #region Document
10227
+
10228
+ // #region CSSStyleDeclaration
10219
10229
  /**
10220
10230
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleDeclaration
10221
10231
  */
10222
10232
 
10233
+ // #region Canvas
10234
+
10223
10235
  var MutationEvent = /*#__PURE__*/function (_FederatedEvent) {
10224
10236
  function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
10225
10237
  var _this;
@@ -11484,7 +11496,7 @@ var TextService = /*#__PURE__*/function () {
11484
11496
  }
11485
11497
 
11486
11498
  // Backspace from line's end.
11487
- var currentLineLength = lines[lineIndex].length;
11499
+ var currentLineLength = lines[lineIndex] ? lines[lineIndex].length : 0;
11488
11500
  var lastLineWidth = 0;
11489
11501
  var lastLineIndex = currentLineLength;
11490
11502
  for (var i = 0; i < currentLineLength; i++) {
@@ -15290,109 +15302,63 @@ var afterRenderEvent = new CustomEvent(CanvasEvent.AFTER_RENDER);
15290
15302
  * * `window.devicePixelRatio`
15291
15303
  *
15292
15304
  * prototype chains: Canvas(Window) -> EventTarget
15305
+ *
15306
+ * @docs https://g.antv.antgroup.com/api/canvas/intro
15293
15307
  */
15294
15308
  var Canvas = /*#__PURE__*/function (_EventTarget) {
15295
15309
  function Canvas(config) {
15296
15310
  var _this;
15297
15311
  _classCallCheck(this, Canvas);
15298
15312
  _this = _callSuper(this, Canvas);
15299
-
15300
- // create document
15313
+ // #region environment
15301
15314
  /**
15302
15315
  * window.document
15303
15316
  */
15304
- /**
15305
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
15306
- */
15307
- /**
15308
- * @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
15309
- */
15310
- /**
15311
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
15312
- */
15313
- /**
15314
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
15315
- */
15316
- /**
15317
- * whether the runtime supports PointerEvent?
15318
- * if not, the event system won't trigger pointer events like `pointerdown`
15319
- */
15320
- /**
15321
- * whether the runtime supports TouchEvent?
15322
- * if not, the event system won't trigger touch events like `touchstart`
15323
- */
15324
- /**
15325
- * is this native event a TouchEvent?
15326
- */
15327
- /**
15328
- * is this native event a MouseEvent?
15329
- */
15330
15317
  /**
15331
15318
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element
15332
15319
  */
15333
15320
  _this.Element = DisplayObject;
15334
15321
  _this.inited = false;
15335
15322
  _this.context = {};
15336
- _this.document = new Document();
15337
- _this.document.defaultView = _this;
15338
-
15339
- // create registry of custom elements
15340
- _this.customElements = new CustomElementRegistry();
15341
15323
  var container = config.container,
15342
15324
  canvas = config.canvas,
15343
- offscreenCanvas = config.offscreenCanvas,
15325
+ renderer = config.renderer,
15344
15326
  width = config.width,
15345
15327
  height = config.height,
15346
- devicePixelRatio = config.devicePixelRatio,
15347
- renderer = config.renderer,
15348
15328
  background = config.background,
15349
15329
  cursor = config.cursor,
15350
- document = config.document,
15330
+ supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
15331
+ _config$cleanUpOnDest = config.cleanUpOnDestroy,
15332
+ cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
15333
+ offscreenCanvas = config.offscreenCanvas,
15334
+ devicePixelRatio = config.devicePixelRatio,
15351
15335
  requestAnimationFrame = config.requestAnimationFrame,
15352
15336
  cancelAnimationFrame = config.cancelAnimationFrame,
15353
15337
  createImage = config.createImage,
15354
- enableLargeImageOptimization = config.enableLargeImageOptimization,
15355
- supportsPointerEvents = config.supportsPointerEvents,
15356
15338
  supportsTouchEvents = config.supportsTouchEvents,
15357
- supportsCSSTransform = config.supportsCSSTransform,
15358
- _config$cleanUpOnDest = config.cleanUpOnDestroy,
15359
- cleanUpOnDestroy = _config$cleanUpOnDest === void 0 ? true : _config$cleanUpOnDest,
15360
- supportsMutipleCanvasesInOneContainer = config.supportsMutipleCanvasesInOneContainer,
15361
- useNativeClickEvent = config.useNativeClickEvent,
15362
- alwaysTriggerPointerEventOnCanvas = config.alwaysTriggerPointerEventOnCanvas,
15339
+ supportsPointerEvents = config.supportsPointerEvents,
15363
15340
  isTouchEvent = config.isTouchEvent,
15364
15341
  isMouseEvent = config.isMouseEvent,
15365
15342
  dblClickSpeed = config.dblClickSpeed;
15366
- if (!supportsMutipleCanvasesInOneContainer) {
15367
- cleanExistedCanvas(container, _this, cleanUpOnDestroy);
15368
- }
15369
15343
  var canvasWidth = width;
15370
15344
  var canvasHeight = height;
15371
- var dpr = devicePixelRatio;
15345
+ var dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
15346
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
15347
+
15372
15348
  // use user-defined <canvas> or OffscreenCanvas
15373
15349
  if (canvas) {
15374
15350
  // infer width & height with dpr
15375
- dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
15376
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
15377
15351
  canvasWidth = width || getWidth(canvas) || canvas.width / dpr;
15378
15352
  canvasHeight = height || getHeight(canvas) || canvas.height / dpr;
15379
15353
  }
15380
15354
 
15381
- // override it in runtime
15382
- if (offscreenCanvas) {
15383
- runtime.offscreenCanvas = offscreenCanvas;
15384
- }
15385
-
15386
15355
  /**
15387
15356
  * implements `Window` interface
15388
15357
  */
15358
+ _this.customElements = new CustomElementRegistry();
15389
15359
  _this.devicePixelRatio = dpr;
15390
15360
  _this.requestAnimationFrame = requestAnimationFrame !== null && requestAnimationFrame !== void 0 ? requestAnimationFrame : raf.bind(runtime.globalThis);
15391
15361
  _this.cancelAnimationFrame = cancelAnimationFrame !== null && cancelAnimationFrame !== void 0 ? cancelAnimationFrame : caf.bind(runtime.globalThis);
15392
-
15393
- /**
15394
- * limits query
15395
- */
15396
15362
  // the following feature-detect from hammer.js
15397
15363
  // @see https://github.com/hammerjs/hammer.js/blob/master/src/inputjs/input-consts.js#L5
15398
15364
  _this.supportsTouchEvents = supportsTouchEvents !== null && supportsTouchEvents !== void 0 ? supportsTouchEvents : 'ontouchstart' in runtime.globalThis;
@@ -15403,25 +15369,36 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15403
15369
  _this.isMouseEvent = isMouseEvent !== null && isMouseEvent !== void 0 ? isMouseEvent : function (event) {
15404
15370
  return !runtime.globalThis.MouseEvent || event instanceof runtime.globalThis.MouseEvent && (!_this.supportsPointerEvents || !(event instanceof runtime.globalThis.PointerEvent));
15405
15371
  };
15406
- _this.dblClickSpeed = dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200;
15407
- _this.initRenderingContext({
15408
- container: container,
15409
- canvas: canvas,
15372
+
15373
+ // override it in runtime
15374
+ if (offscreenCanvas) {
15375
+ runtime.offscreenCanvas = offscreenCanvas;
15376
+ }
15377
+
15378
+ // create document
15379
+ _this.document = new Document();
15380
+ _this.document.defaultView = _this;
15381
+ if (!supportsMutipleCanvasesInOneContainer) {
15382
+ cleanExistedCanvas(container, _this, cleanUpOnDestroy);
15383
+ }
15384
+ _this.initRenderingContext(_objectSpread(_objectSpread({}, config), {}, {
15410
15385
  width: canvasWidth,
15411
15386
  height: canvasHeight,
15412
- renderer: renderer,
15413
- offscreenCanvas: offscreenCanvas,
15414
- devicePixelRatio: dpr,
15415
- cursor: cursor || 'default',
15416
- background: background || 'transparent',
15417
- createImage: createImage,
15418
- enableLargeImageOptimization: enableLargeImageOptimization,
15419
- document: document,
15420
- supportsCSSTransform: supportsCSSTransform,
15421
- useNativeClickEvent: useNativeClickEvent,
15387
+ background: background !== null && background !== void 0 ? background : 'transparent',
15388
+ cursor: cursor !== null && cursor !== void 0 ? cursor : 'default',
15422
15389
  cleanUpOnDestroy: cleanUpOnDestroy,
15423
- alwaysTriggerPointerEventOnCanvas: alwaysTriggerPointerEventOnCanvas
15424
- });
15390
+ devicePixelRatio: dpr,
15391
+ requestAnimationFrame: _this.requestAnimationFrame,
15392
+ cancelAnimationFrame: _this.cancelAnimationFrame,
15393
+ supportsTouchEvents: _this.supportsTouchEvents,
15394
+ supportsPointerEvents: _this.supportsPointerEvents,
15395
+ isTouchEvent: _this.isTouchEvent,
15396
+ isMouseEvent: _this.isMouseEvent,
15397
+ dblClickSpeed: dblClickSpeed !== null && dblClickSpeed !== void 0 ? dblClickSpeed : 200,
15398
+ createImage: createImage !== null && createImage !== void 0 ? createImage : function () {
15399
+ return new window.Image();
15400
+ }
15401
+ }));
15425
15402
  _this.initDefaultCamera(canvasWidth, canvasHeight, renderer.clipSpaceNearZ);
15426
15403
  _this.initRenderer(renderer, true);
15427
15404
  return _this;
@@ -15678,6 +15655,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15678
15655
  key: "render",
15679
15656
  value: function render(frame) {
15680
15657
  var _this4 = this;
15658
+ // console.log('render ----------------------');
15681
15659
  if (frame) {
15682
15660
  beforeRenderEvent.detail = frame;
15683
15661
  afterRenderEvent.detail = frame;
@@ -15741,6 +15719,8 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
15741
15719
  } else {
15742
15720
  this.context.contextService.initAsync().then(function () {
15743
15721
  _this6.initRenderingService(renderer, firstContentfullPaint);
15722
+ })["catch"](function (err) {
15723
+ console.error(err);
15744
15724
  });
15745
15725
  }
15746
15726
  }