@antv/g-lite 1.3.0-next.10 → 1.3.0-next.11

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.
@@ -31,4 +31,10 @@ export interface GlobalRuntime {
31
31
  * circle.style.r = 100;
32
32
  */
33
33
  enableStyleSyntax: boolean;
34
+ /**
35
+ * Enable using dash-cased attribute.
36
+ * @example
37
+ * circle.setAttribute('stroke-width', '2');
38
+ */
39
+ enableAttributeDashCased: boolean;
34
40
  }
package/dist/index.esm.js CHANGED
@@ -6544,7 +6544,7 @@ var BUILT_IN_PROPERTIES = [
6544
6544
  d: '0',
6545
6545
  },
6546
6546
  ];
6547
- var GEOMETRY_ATTRIBUTE_NAMES = BUILT_IN_PROPERTIES.filter(function (n) { return !!n.l; }).map(function (n) { return n.n; });
6547
+ BUILT_IN_PROPERTIES.filter(function (n) { return !!n.l; }).map(function (n) { return n.n; });
6548
6548
  var propertyMetadataCache = {};
6549
6549
  var unresolvedProperties = new WeakMap();
6550
6550
  // const uniqueAttributeSet = new Set<string>();
@@ -6601,20 +6601,20 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6601
6601
  }; }
6602
6602
  if (!this.runtime.enableCSSParsing) {
6603
6603
  Object.assign(object.attributes, attributes);
6604
- var attributeNames_1 = Object.keys(attributes);
6604
+ var attributeNames = Object.keys(attributes);
6605
6605
  // clipPath
6606
6606
  var oldClipPath = object.parsedStyle.clipPath;
6607
6607
  var oldOffsetPath = object.parsedStyle.offsetPath;
6608
6608
  object.parsedStyle = Object.assign(object.parsedStyle, attributes);
6609
- var needUpdateGeometry_1 = !!options.forceUpdateGeometry;
6610
- if (!needUpdateGeometry_1) {
6611
- for (var i = 0; i < GEOMETRY_ATTRIBUTE_NAMES.length; i++) {
6612
- if (GEOMETRY_ATTRIBUTE_NAMES[i] in attributes) {
6613
- needUpdateGeometry_1 = true;
6614
- break;
6615
- }
6616
- }
6617
- }
6609
+ var needUpdateGeometry = !!options.forceUpdateGeometry;
6610
+ // if (!needUpdateGeometry) {
6611
+ // for (let i = 0; i < GEOMETRY_ATTRIBUTE_NAMES.length; i++) {
6612
+ // if (GEOMETRY_ATTRIBUTE_NAMES[i] in attributes) {
6613
+ // needUpdateGeometry = true;
6614
+ // break;
6615
+ // }
6616
+ // }
6617
+ // }
6618
6618
  if (attributes.fill) {
6619
6619
  object.parsedStyle.fill = parseColor(attributes.fill);
6620
6620
  }
@@ -6697,97 +6697,98 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6697
6697
  attributes.markerMid, null, null);
6698
6698
  }
6699
6699
  if (!isNil(attributes.zIndex)) {
6700
- this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames_1);
6700
+ this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames);
6701
6701
  }
6702
6702
  if (!isNil(attributes.offsetDistance)) {
6703
- this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames_1);
6703
+ this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames);
6704
6704
  }
6705
6705
  if (attributes.transform) {
6706
- this.runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, attributeNames_1);
6706
+ this.runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, attributeNames);
6707
6707
  }
6708
- if (needUpdateGeometry_1) {
6708
+ if (needUpdateGeometry) {
6709
6709
  object.geometry.dirty = true;
6710
6710
  // FIXME setOrigin may have already dirtified to root.
6711
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6711
+ // this.runtime.sceneGraphService.dirtifyToRoot(object);
6712
6712
  }
6713
- return;
6714
6713
  }
6715
- var skipUpdateAttribute = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize = options.memoize;
6716
- var needUpdateGeometry = forceUpdateGeometry;
6717
- var attributeNames = Object.keys(attributes);
6718
- attributeNames.forEach(function (attributeName) {
6719
- var _a;
6720
- if (!skipUpdateAttribute) {
6721
- object.attributes[attributeName] = attributes[attributeName];
6722
- }
6723
- if (!needUpdateGeometry && ((_a = propertyMetadataCache[attributeName]) === null || _a === void 0 ? void 0 : _a.l)) {
6724
- needUpdateGeometry = true;
6725
- }
6726
- });
6727
- if (!skipParse) {
6728
- attributeNames.forEach(function (name) {
6729
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize);
6714
+ else {
6715
+ var skipUpdateAttribute_1 = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize_1 = options.memoize;
6716
+ var needUpdateGeometry_1 = forceUpdateGeometry;
6717
+ var attributeNames_1 = Object.keys(attributes);
6718
+ attributeNames_1.forEach(function (attributeName) {
6719
+ var _a;
6720
+ if (!skipUpdateAttribute_1) {
6721
+ object.attributes[attributeName] = attributes[attributeName];
6722
+ }
6723
+ if (!needUpdateGeometry_1 && ((_a = propertyMetadataCache[attributeName]) === null || _a === void 0 ? void 0 : _a.l)) {
6724
+ needUpdateGeometry_1 = true;
6725
+ }
6730
6726
  });
6731
- }
6732
- // let hasUnresolvedProperties = false;
6733
- // parse according to priority
6734
- // path 50
6735
- // points 50
6736
- // text 50
6737
- // textTransform 51
6738
- // transform 100
6739
- // transformOrigin 100
6740
- if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
6741
- // uniqueAttributeSet.clear();
6742
- attributeNames = Array.from(new Set(attributeNames.concat(usedAttributes)));
6743
- }
6744
- // [
6745
- // 'path',
6746
- // 'points',
6747
- // 'text',
6748
- // 'textTransform',
6749
- // 'transform',
6750
- // 'transformOrigin',
6751
- // ].forEach((name) => {
6752
- // const index = attributeNames.indexOf(name);
6753
- // if (index > -1) {
6754
- // attributeNames.splice(index, 1);
6755
- // attributeNames.push(name);
6756
- // }
6757
- // });
6758
- attributeNames.forEach(function (name) {
6759
- // some style props maybe deleted after parsing such as `anchor` in Text
6760
- if (name in object.computedStyle) {
6761
- object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize);
6727
+ if (!skipParse) {
6728
+ attributeNames_1.forEach(function (name) {
6729
+ object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize_1);
6730
+ });
6762
6731
  }
6763
- });
6764
- // if (hasUnresolvedProperties) {
6765
- // this.dirty = true;
6766
- // return;
6767
- // }
6768
- // update geometry
6769
- if (needUpdateGeometry) {
6770
- object.geometry.dirty = true;
6771
- // FIXME setOrigin may have already dirtified to root.
6772
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6773
- }
6774
- attributeNames.forEach(function (name) {
6775
- if (name in object.parsedStyle) {
6776
- _this.postProcessProperty(name, object, attributeNames);
6732
+ // let hasUnresolvedProperties = false;
6733
+ // parse according to priority
6734
+ // path 50
6735
+ // points 50
6736
+ // text 50
6737
+ // textTransform 51
6738
+ // transform 100
6739
+ // transformOrigin 100
6740
+ if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
6741
+ // uniqueAttributeSet.clear();
6742
+ attributeNames_1 = Array.from(new Set(attributeNames_1.concat(usedAttributes)));
6743
+ }
6744
+ // [
6745
+ // 'path',
6746
+ // 'points',
6747
+ // 'text',
6748
+ // 'textTransform',
6749
+ // 'transform',
6750
+ // 'transformOrigin',
6751
+ // ].forEach((name) => {
6752
+ // const index = attributeNames.indexOf(name);
6753
+ // if (index > -1) {
6754
+ // attributeNames.splice(index, 1);
6755
+ // attributeNames.push(name);
6756
+ // }
6757
+ // });
6758
+ attributeNames_1.forEach(function (name) {
6759
+ // some style props maybe deleted after parsing such as `anchor` in Text
6760
+ if (name in object.computedStyle) {
6761
+ object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize_1);
6762
+ }
6763
+ });
6764
+ // if (hasUnresolvedProperties) {
6765
+ // this.dirty = true;
6766
+ // return;
6767
+ // }
6768
+ // update geometry
6769
+ if (needUpdateGeometry_1) {
6770
+ object.geometry.dirty = true;
6771
+ // FIXME setOrigin may have already dirtified to root.
6772
+ this.runtime.sceneGraphService.dirtifyToRoot(object);
6777
6773
  }
6778
- });
6779
- if (this.runtime.enableCSSParsing && object.children.length) {
6780
- attributeNames.forEach(function (name) {
6781
- if (name in object.parsedStyle && _this.isPropertyInheritable(name)) {
6782
- // update children's inheritable
6783
- object.children.forEach(function (child) {
6784
- child.internalSetAttribute(name, null, {
6785
- skipUpdateAttribute: true,
6786
- skipParse: true,
6787
- });
6788
- });
6774
+ attributeNames_1.forEach(function (name) {
6775
+ if (name in object.parsedStyle) {
6776
+ _this.postProcessProperty(name, object, attributeNames_1);
6789
6777
  }
6790
6778
  });
6779
+ if (this.runtime.enableCSSParsing && object.children.length) {
6780
+ attributeNames_1.forEach(function (name) {
6781
+ if (name in object.parsedStyle && _this.isPropertyInheritable(name)) {
6782
+ // update children's inheritable
6783
+ object.children.forEach(function (child) {
6784
+ child.internalSetAttribute(name, null, {
6785
+ skipUpdateAttribute: true,
6786
+ skipParse: true,
6787
+ });
6788
+ });
6789
+ }
6790
+ });
6791
+ }
6791
6792
  }
6792
6793
  };
6793
6794
  /**
@@ -7562,6 +7563,7 @@ var clock = typeof performance === 'object' && performance.now ? performance : D
7562
7563
  function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
7563
7564
  // account for pointerEvents
7564
7565
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
7566
+ if (pointerEvents === void 0) { pointerEvents = 'auto'; }
7565
7567
  var hasFill = false;
7566
7568
  var hasStroke = false;
7567
7569
  var isFillOtherThanNone = !!fill && !fill.isNone;
@@ -10039,7 +10041,7 @@ var RenderingService = /** @class */ (function () {
10039
10041
  this.zIndexCounter = 0;
10040
10042
  var renderingContext = this.context.renderingContext;
10041
10043
  this.globalRuntime.sceneGraphService.syncHierarchy(renderingContext.root);
10042
- this.globalRuntime.sceneGraphService.triggerPendingEvents();
10044
+ // this.globalRuntime.sceneGraphService.triggerPendingEvents();
10043
10045
  if (renderingContext.renderReasons.size && this.inited) {
10044
10046
  // @ts-ignore
10045
10047
  renderingContext.dirtyRectangleRenderingDisabled =
@@ -10680,6 +10682,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10680
10682
  }
10681
10683
  };
10682
10684
  DefaultSceneGraphService.prototype.getOrigin = function (element) {
10685
+ element.getGeometryBounds();
10683
10686
  return element.transformable.origin;
10684
10687
  };
10685
10688
  /**
@@ -11619,12 +11622,13 @@ runtime.globalThis = getGlobalThis();
11619
11622
  runtime.enableCSSParsing = true;
11620
11623
  runtime.enableDataset = false;
11621
11624
  runtime.enableStyleSyntax = true;
11625
+ runtime.enableAttributeDashCased = false;
11622
11626
 
11623
11627
  var entityCounter = 0;
11624
11628
  function resetEntityCounter() {
11625
11629
  entityCounter = 0;
11626
11630
  }
11627
- var insertedEvent = new MutationEvent(ElementEvent.INSERTED, null, '', '', '', 0, '', '');
11631
+ new MutationEvent(ElementEvent.INSERTED, null, '', '', '', 0, '', '');
11628
11632
  var removedEvent = new MutationEvent(ElementEvent.REMOVED, null, '', '', '', 0, '', '');
11629
11633
  var destroyEvent = new CustomEvent(ElementEvent.DESTROY);
11630
11634
  /**
@@ -11864,8 +11868,8 @@ var Element = /** @class */ (function (_super) {
11864
11868
  if ((_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) {
11865
11869
  this.ownerDocument.defaultView.mountChildren(child);
11866
11870
  }
11867
- insertedEvent.relatedNode = this;
11868
- child.dispatchEvent(insertedEvent);
11871
+ // insertedEvent.relatedNode = this as IElement;
11872
+ // child.dispatchEvent(insertedEvent);
11869
11873
  return child;
11870
11874
  };
11871
11875
  Element.prototype.insertBefore = function (newChild, refChild) {
@@ -12138,8 +12142,10 @@ var Element = /** @class */ (function (_super) {
12138
12142
  }
12139
12143
  var value = this.attributes[name];
12140
12144
  if (value === undefined) {
12141
- var attributeName = formatAttributeName(name);
12142
- value = this.attributes[attributeName];
12145
+ if (runtime.enableAttributeDashCased) {
12146
+ var attributeName = formatAttributeName(name);
12147
+ value = this.attributes[attributeName];
12148
+ }
12143
12149
  // if the given attribute does not exist, the value returned will either be null or ""
12144
12150
  return runtime.enableCSSParsing ? (isNil(value) ? null : value) : value;
12145
12151
  }
@@ -12245,7 +12251,20 @@ var DEFAULT_PARSED_STYLE_PROPS = {
12245
12251
  shadowType: 'outer',
12246
12252
  miterLimit: 10,
12247
12253
  };
12248
- var DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = __assign(__assign({}, DEFAULT_PARSED_STYLE_PROPS), { opacity: 1, fillOpacity: 1, strokeOpacity: 1, visibility: 'visible', pointerEvents: 'auto', lineWidth: 1, lineCap: 'butt', lineJoin: 'miter', increasedLineWidthForHitTesting: 0, fillRule: 'nonzero' });
12254
+ // const DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = {
12255
+ // ...DEFAULT_PARSED_STYLE_PROPS,
12256
+ // opacity: 1,
12257
+ // fillOpacity: 1,
12258
+ // strokeOpacity: 1,
12259
+ // visibility: 'visible',
12260
+ // pointerEvents: 'auto',
12261
+ // lineWidth: 1,
12262
+ // lineCap: 'butt',
12263
+ // lineJoin: 'miter',
12264
+ // increasedLineWidthForHitTesting: 0,
12265
+ // fillRule: 'nonzero',
12266
+ // // TODO: transformOrigin
12267
+ // };
12249
12268
  var INHERITABLE_BASE_STYLE_PROPS = [
12250
12269
  'opacity',
12251
12270
  'fillOpacity',
@@ -12314,12 +12333,9 @@ var DisplayObject = /** @class */ (function (_super) {
12314
12333
  _this.className = _this.config.className || _this.config.class;
12315
12334
  }
12316
12335
  _this.nodeName = _this.config.type || Shape.GROUP;
12317
- // merge parsed value
12318
- Object.assign(_this.parsedStyle, runtime.enableCSSParsing
12319
- ? DEFAULT_PARSED_STYLE_PROPS
12320
- : DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED, _this.config.initialParsedStyle);
12321
12336
  if (runtime.enableCSSParsing) {
12322
12337
  Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
12338
+ Object.assign(_this.parsedStyle, DEFAULT_PARSED_STYLE_PROPS, _this.config.initialParsedStyle);
12323
12339
  }
12324
12340
  // start to process attributes
12325
12341
  _this.initAttributes(_this.config.style);
@@ -12443,10 +12459,14 @@ var DisplayObject = /** @class */ (function (_super) {
12443
12459
  options.usedAttributes = INHERITABLE_STYLE_PROPS;
12444
12460
  }
12445
12461
  // account for FCP, process properties as less as possible
12446
- var formattedAttributes = {};
12447
- for (var name_1 in attributes) {
12448
- var attributeName = formatAttributeName(name_1);
12449
- formattedAttributes[attributeName] = attributes[name_1];
12462
+ var formattedAttributes = attributes;
12463
+ if (runtime.enableAttributeDashCased) {
12464
+ // @ts-ignore
12465
+ formattedAttributes = {};
12466
+ for (var name_1 in attributes) {
12467
+ var attributeName = formatAttributeName(name_1);
12468
+ formattedAttributes[attributeName] = attributes[name_1];
12469
+ }
12450
12470
  }
12451
12471
  runtime.styleValueRegistry.processProperties(this, formattedAttributes, options);
12452
12472
  // redraw at next frame
@@ -12455,14 +12475,16 @@ var DisplayObject = /** @class */ (function (_super) {
12455
12475
  DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
12456
12476
  if (force === void 0) { force = false; }
12457
12477
  if (memoize === void 0) { memoize = true; }
12458
- var attributeName = formatAttributeName(name);
12478
+ if (runtime.enableAttributeDashCased) {
12479
+ name = formatAttributeName(name);
12480
+ }
12459
12481
  // ignore undefined value
12460
12482
  if (isUndefined(value)) {
12461
12483
  return;
12462
12484
  }
12463
- if (force || value !== this.attributes[attributeName]) {
12464
- this.internalSetAttribute(attributeName, value, { memoize: memoize });
12465
- _super.prototype.setAttribute.call(this, attributeName, value);
12485
+ if (force || value !== this.attributes[name]) {
12486
+ this.internalSetAttribute(name, value, { memoize: memoize });
12487
+ _super.prototype.setAttribute.call(this, name, value);
12466
12488
  }
12467
12489
  };
12468
12490
  /**
@@ -12716,8 +12738,10 @@ var DisplayObject = /** @class */ (function (_super) {
12716
12738
  * shortcut for Used value of `visibility`
12717
12739
  */
12718
12740
  DisplayObject.prototype.isVisible = function () {
12719
- var _a;
12720
- return ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) === 'visible';
12741
+ var _a, _b;
12742
+ return runtime.enableCSSParsing
12743
+ ? ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) === 'visible'
12744
+ : ((_b = this.parsedStyle) === null || _b === void 0 ? void 0 : _b.visibility) !== 'hidden';
12721
12745
  };
12722
12746
  Object.defineProperty(DisplayObject.prototype, "interactive", {
12723
12747
  get: function () {
@@ -14693,9 +14717,9 @@ var PrepareRendererPlugin = /** @class */ (function () {
14693
14717
  * sync to RBush later
14694
14718
  */
14695
14719
  this.toSync = new Set();
14720
+ // private isFirstTimeRendering = true;
14721
+ this.syncing = false;
14696
14722
  }
14697
- // private isFirstTimeRendering = true;
14698
- // private syncing = false;
14699
14723
  PrepareRendererPlugin.prototype.apply = function (context) {
14700
14724
  var _this = this;
14701
14725
  var renderingService = context.renderingService, renderingContext = context.renderingContext, rBushRoot = context.rBushRoot;
@@ -14757,25 +14781,17 @@ var PrepareRendererPlugin = /** @class */ (function () {
14757
14781
  _this.toSync.clear();
14758
14782
  });
14759
14783
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
14760
- // if (this.isFirstTimeRendering) {
14761
- // this.isFirstTimeRendering = false;
14762
- // this.syncing = true;
14763
- // // @see https://github.com/antvis/G/issues/1117
14764
- // setTimeout(() => {
14765
- // this.syncRTree();
14766
- // console.log('fcp...');
14767
- // });
14768
- // } else {
14769
- // console.log('next...');
14770
- _this.syncRTree();
14771
- // }
14784
+ requestIdleCallback(function () {
14785
+ _this.syncRTree();
14786
+ });
14772
14787
  });
14773
14788
  };
14774
14789
  PrepareRendererPlugin.prototype.syncRTree = function () {
14775
- // if (this.syncing) {
14776
- // return;
14777
- // }
14778
14790
  var _this = this;
14791
+ if (this.syncing || this.toSync.size === 0) {
14792
+ return;
14793
+ }
14794
+ this.syncing = true;
14779
14795
  // bounds changed, need re-inserting its children
14780
14796
  var bulk = [];
14781
14797
  Array.from(this.toSync)
@@ -14813,9 +14829,10 @@ var PrepareRendererPlugin = /** @class */ (function () {
14813
14829
  // use bulk inserting, which is ~2-3 times faster
14814
14830
  // @see https://github.com/mourner/rbush#bulk-inserting-data
14815
14831
  this.rBush.load(bulk);
14832
+ console.log('sync...', Array.from(this.toSync));
14816
14833
  bulk.length = 0;
14817
14834
  this.toSync.clear();
14818
- // this.syncing = false;
14835
+ this.syncing = false;
14819
14836
  };
14820
14837
  PrepareRendererPlugin.tag = 'Prepare';
14821
14838
  return PrepareRendererPlugin;