@antv/g-lite 1.3.0-next.8 → 2.0.0

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,9 +1,9 @@
1
1
  import { __assign, __read, __extends, __spreadArray, __awaiter, __generator, __values, __rest } from 'tslib';
2
2
  import EventEmitter from 'eventemitter3';
3
3
  import { mat4, vec4, vec3, mat3, quat as quat$1, vec2 } from 'gl-matrix';
4
- import { isNumber, distanceSquareRoot, isString, isNil, clamp, getTotalLength, min, max, isNumberEqual, mod, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isArray, isBoolean, isObject, isUndefined, getPointAtLength } from '@antv/util';
4
+ import { isNumber, distanceSquareRoot, isString, isNil, clamp, getTotalLength, min, max, isNumberEqual, mod, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, isUndefined, isArray, isBoolean, isObject, getPointAtLength } from '@antv/util';
5
5
  import * as d3 from 'd3-color';
6
- import { arcBox, cubicBox, quadBox, polylineLength, lineLength, linePointAt } from '@antv/g-math';
6
+ import { polylineLength, arcBox, cubicBox, quadBox, linePointAt, lineLength } from '@antv/g-math';
7
7
 
8
8
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9
9
 
@@ -641,7 +641,7 @@ var AbstractRenderer = /** @class */ (function () {
641
641
  /**
642
642
  * enable dirty rectangle rendering by default
643
643
  */
644
- enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false }, config);
644
+ enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false, enableSizeAttenuation: true }, config);
645
645
  }
646
646
  AbstractRenderer.prototype.registerPlugin = function (plugin) {
647
647
  var index = this.plugins.findIndex(function (p) { return p === plugin; });
@@ -3165,7 +3165,7 @@ var getOrCreateUnitValue = function (value, unitOrName) {
3165
3165
  if (unitOrName === void 0) { unitOrName = UnitType.kNumber; }
3166
3166
  return new CSSUnitValue(value, unitOrName);
3167
3167
  };
3168
- var PECENTAGE_50 = new CSSUnitValue(50, '%');
3168
+ new CSSUnitValue(50, '%');
3169
3169
 
3170
3170
  /**
3171
3171
  * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy
@@ -3888,6 +3888,9 @@ var parseColor = memoize(function (colorStr) {
3888
3888
  // @see https://github.com/adobe-webplatform/Snap.svg/issues/526
3889
3889
  colorStr = 'black';
3890
3890
  }
3891
+ else if (colorStr === 'none') {
3892
+ return noneColor;
3893
+ }
3891
3894
  // support CSS gradient syntax
3892
3895
  var g = parseGradient(colorStr);
3893
3896
  if (g) {
@@ -4107,10 +4110,8 @@ function parseDimensionArray(string) {
4107
4110
  // },
4108
4111
  // ];
4109
4112
  // }
4110
- function convertPercentUnit(valueWithUnit, vec3Index, target) {
4111
- if (valueWithUnit.value === 0) {
4112
- return 0;
4113
- }
4113
+ function convertPercentUnit(valueWithUnit, vec3Index, target, useMin) {
4114
+ if (useMin === void 0) { useMin = false; }
4114
4115
  if (valueWithUnit.unit === UnitType.kPixels) {
4115
4116
  return Number(valueWithUnit.value);
4116
4117
  }
@@ -4118,7 +4119,8 @@ function convertPercentUnit(valueWithUnit, vec3Index, target) {
4118
4119
  var bounds = target.nodeName === Shape.GROUP
4119
4120
  ? target.getLocalBounds()
4120
4121
  : target.getGeometryBounds();
4121
- return (valueWithUnit.value / 100) * bounds.halfExtents[vec3Index] * 2;
4122
+ return ((useMin ? bounds.min[vec3Index] : 0) +
4123
+ (valueWithUnit.value / 100) * bounds.halfExtents[vec3Index] * 2);
4122
4124
  }
4123
4125
  return 0;
4124
4126
  }
@@ -4221,10 +4223,16 @@ function mergeNumberLists(left, right) {
4221
4223
  }
4222
4224
 
4223
4225
  function getOrCalculatePathTotalLength(path) {
4224
- if (path.parsedStyle.path.totalLength === 0) {
4225
- path.parsedStyle.path.totalLength = getTotalLength(path.parsedStyle.path.absolutePath);
4226
+ if (path.parsedStyle.d.totalLength === 0) {
4227
+ path.parsedStyle.d.totalLength = getTotalLength(path.parsedStyle.d.absolutePath);
4226
4228
  }
4227
- return path.parsedStyle.path.totalLength;
4229
+ return path.parsedStyle.d.totalLength;
4230
+ }
4231
+ function getOrCalculatePolylineTotalLength(polyline) {
4232
+ if (polyline.parsedStyle.points.totalLength === 0) {
4233
+ polyline.parsedStyle.points.totalLength = polylineLength(polyline.parsedStyle.points.points);
4234
+ }
4235
+ return polyline.parsedStyle.points.totalLength;
4228
4236
  }
4229
4237
  function removeRedundantMCommand(path) {
4230
4238
  for (var i = 0; i < path.length; i++) {
@@ -4934,7 +4942,7 @@ function convertToPath(object, transform) {
4934
4942
  }));
4935
4943
  break;
4936
4944
  case Shape.PATH:
4937
- var absolutePath = object.parsedStyle.path.absolutePath;
4945
+ var absolutePath = object.parsedStyle.d.absolutePath;
4938
4946
  commands = __spreadArray([], __read(absolutePath), false);
4939
4947
  break;
4940
4948
  }
@@ -5096,27 +5104,10 @@ function parsePoints(pointsOrStr, object) {
5096
5104
  else {
5097
5105
  points = pointsOrStr;
5098
5106
  }
5099
- var segments = [];
5100
- var tempLength = 0;
5101
- var segmentT;
5102
- var segmentL;
5103
- var totalLength = polylineLength(points);
5104
- points.forEach(function (p, i) {
5105
- if (points[i + 1]) {
5106
- segmentT = [0, 0];
5107
- segmentT[0] = tempLength / totalLength;
5108
- segmentL = lineLength(p[0], p[1], points[i + 1][0], points[i + 1][1]);
5109
- tempLength += segmentL;
5110
- segmentT[1] = tempLength / totalLength;
5111
- segments.push(segmentT);
5112
- }
5113
- });
5114
- // const minX = Math.min(...points.map((point) => point[0]));
5115
- // const minY = Math.min(...points.map((point) => point[1]));
5116
5107
  return {
5117
5108
  points: points,
5118
- totalLength: totalLength,
5119
- segments: segments,
5109
+ totalLength: 0,
5110
+ segments: [],
5120
5111
  };
5121
5112
  }
5122
5113
  function mergePoints(left, right) {
@@ -5957,7 +5948,7 @@ function convertKeyword2Percent(keyword) {
5957
5948
  return '50%';
5958
5949
  }
5959
5950
  else if (keyword === 'left' || keyword === 'top') {
5960
- return '0';
5951
+ return '0%';
5961
5952
  }
5962
5953
  else if (keyword === 'right' || keyword === 'bottom') {
5963
5954
  return '100%';
@@ -6225,16 +6216,17 @@ var BUILT_IN_PROPERTIES = [
6225
6216
  {
6226
6217
  n: 'transformOrigin',
6227
6218
  p: 100,
6228
- // int: true,
6229
- d: function (nodeName) {
6230
- if (nodeName === Shape.CIRCLE || nodeName === Shape.ELLIPSE) {
6231
- return 'center';
6232
- }
6233
- if (nodeName === Shape.TEXT) {
6234
- return 'text-anchor';
6235
- }
6236
- return 'left top';
6237
- },
6219
+ d: '0 0',
6220
+ // // int: true,
6221
+ // d: (nodeName: string) => {
6222
+ // if (nodeName === Shape.CIRCLE || nodeName === Shape.ELLIPSE) {
6223
+ // return 'center';
6224
+ // }
6225
+ // if (nodeName === Shape.TEXT) {
6226
+ // return 'text-anchor';
6227
+ // }
6228
+ // return 'left top';
6229
+ // },
6238
6230
  l: true,
6239
6231
  syntax: PropertySyntax.TRANSFORM_ORIGIN,
6240
6232
  },
@@ -6373,11 +6365,10 @@ var BUILT_IN_PROPERTIES = [
6373
6365
  },
6374
6366
  // Path
6375
6367
  {
6376
- n: 'path',
6368
+ n: 'd',
6377
6369
  int: true,
6378
6370
  l: true,
6379
6371
  d: '',
6380
- a: ['d'],
6381
6372
  syntax: PropertySyntax.PATH,
6382
6373
  p: 50,
6383
6374
  },
@@ -6601,16 +6592,16 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6601
6592
  }; }
6602
6593
  if (!this.runtime.enableCSSParsing) {
6603
6594
  Object.assign(object.attributes, attributes);
6604
- var attributeNames_1 = Object.keys(attributes);
6595
+ var attributeNames = Object.keys(attributes);
6605
6596
  // clipPath
6606
6597
  var oldClipPath = object.parsedStyle.clipPath;
6607
6598
  var oldOffsetPath = object.parsedStyle.offsetPath;
6608
6599
  object.parsedStyle = Object.assign(object.parsedStyle, attributes);
6609
- var needUpdateGeometry_1 = !!options.forceUpdateGeometry;
6610
- if (!needUpdateGeometry_1) {
6600
+ var needUpdateGeometry = !!options.forceUpdateGeometry;
6601
+ if (!needUpdateGeometry) {
6611
6602
  for (var i = 0; i < GEOMETRY_ATTRIBUTE_NAMES.length; i++) {
6612
6603
  if (GEOMETRY_ATTRIBUTE_NAMES[i] in attributes) {
6613
- needUpdateGeometry_1 = true;
6604
+ needUpdateGeometry = true;
6614
6605
  break;
6615
6606
  }
6616
6607
  }
@@ -6646,20 +6637,20 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6646
6637
  }
6647
6638
  // Path
6648
6639
  // @ts-ignore
6649
- if (attributes.path === '') {
6650
- object.parsedStyle.path = __assign({}, EMPTY_PARSED_PATH);
6640
+ if (attributes.d === '') {
6641
+ object.parsedStyle.d = __assign({}, EMPTY_PARSED_PATH);
6651
6642
  }
6652
6643
  // @ts-ignore
6653
- if (attributes.path) {
6654
- object.parsedStyle.path = parsePath(
6644
+ if (attributes.d) {
6645
+ object.parsedStyle.d = parsePath(
6655
6646
  // @ts-ignore
6656
- attributes.path);
6647
+ attributes.d);
6657
6648
  }
6658
6649
  // Text
6659
6650
  if (attributes.textTransform) {
6660
6651
  this.runtime.CSSPropertySyntaxFactory['<text-transform>'].calculator(null, null, { value: attributes.textTransform }, object, null);
6661
6652
  }
6662
- if (attributes.clipPath) {
6653
+ if (!isUndefined(attributes.clipPath)) {
6663
6654
  this.runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('clipPath', oldClipPath, attributes.clipPath, object, this.runtime);
6664
6655
  }
6665
6656
  if (attributes.offsetPath) {
@@ -6697,97 +6688,107 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6697
6688
  attributes.markerMid, null, null);
6698
6689
  }
6699
6690
  if (!isNil(attributes.zIndex)) {
6700
- this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames_1);
6691
+ this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames);
6701
6692
  }
6702
6693
  if (!isNil(attributes.offsetDistance)) {
6703
- this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames_1);
6694
+ this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames);
6704
6695
  }
6705
6696
  if (attributes.transform) {
6706
- this.runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, attributeNames_1);
6697
+ this.runtime.CSSPropertySyntaxFactory['<transform>'].postProcessor(object, attributeNames);
6707
6698
  }
6708
- if (needUpdateGeometry_1) {
6699
+ if (attributes.transformOrigin) {
6700
+ this.runtime.CSSPropertySyntaxFactory['<transform-origin>'].postProcessor(object, attributeNames);
6701
+ }
6702
+ if (needUpdateGeometry) {
6709
6703
  object.geometry.dirty = true;
6710
- // FIXME setOrigin may have already dirtified to root.
6711
- this.runtime.sceneGraphService.dirtifyToRoot(object);
6704
+ object.renderable.boundsDirty = true;
6705
+ object.renderable.renderBoundsDirty = true;
6706
+ if (!options.forceUpdateGeometry) {
6707
+ this.runtime.sceneGraphService.dirtifyToRoot(object);
6708
+ }
6712
6709
  }
6713
- return;
6714
6710
  }
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);
6711
+ else {
6712
+ var skipUpdateAttribute_1 = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize_1 = options.memoize;
6713
+ var needUpdateGeometry_1 = forceUpdateGeometry;
6714
+ var attributeNames_1 = Object.keys(attributes);
6715
+ attributeNames_1.forEach(function (attributeName) {
6716
+ var _a;
6717
+ if (!skipUpdateAttribute_1) {
6718
+ object.attributes[attributeName] = attributes[attributeName];
6719
+ }
6720
+ if (!needUpdateGeometry_1 && ((_a = propertyMetadataCache[attributeName]) === null || _a === void 0 ? void 0 : _a.l)) {
6721
+ needUpdateGeometry_1 = true;
6722
+ }
6730
6723
  });
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);
6724
+ if (!skipParse) {
6725
+ attributeNames_1.forEach(function (name) {
6726
+ object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize_1);
6727
+ });
6762
6728
  }
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);
6729
+ // let hasUnresolvedProperties = false;
6730
+ // parse according to priority
6731
+ // path 50
6732
+ // points 50
6733
+ // text 50
6734
+ // textTransform 51
6735
+ // transform 100
6736
+ // transformOrigin 100
6737
+ if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
6738
+ // uniqueAttributeSet.clear();
6739
+ attributeNames_1 = Array.from(new Set(attributeNames_1.concat(usedAttributes)));
6740
+ }
6741
+ // [
6742
+ // 'path',
6743
+ // 'points',
6744
+ // 'text',
6745
+ // 'textTransform',
6746
+ // 'transform',
6747
+ // 'transformOrigin',
6748
+ // ].forEach((name) => {
6749
+ // const index = attributeNames.indexOf(name);
6750
+ // if (index > -1) {
6751
+ // attributeNames.splice(index, 1);
6752
+ // attributeNames.push(name);
6753
+ // }
6754
+ // });
6755
+ attributeNames_1.forEach(function (name) {
6756
+ // some style props maybe deleted after parsing such as `anchor` in Text
6757
+ if (name in object.computedStyle) {
6758
+ object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize_1);
6759
+ }
6760
+ });
6761
+ // if (hasUnresolvedProperties) {
6762
+ // this.dirty = true;
6763
+ // return;
6764
+ // }
6765
+ // update geometry
6766
+ if (needUpdateGeometry_1) {
6767
+ object.geometry.dirty = true;
6768
+ object.renderable.boundsDirty = true;
6769
+ object.renderable.renderBoundsDirty = true;
6770
+ if (!options.forceUpdateGeometry) {
6771
+ this.runtime.sceneGraphService.dirtifyToRoot(object);
6772
+ }
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
  /**
@@ -6980,11 +6981,15 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6980
6981
  // depth / 2,
6981
6982
  // );
6982
6983
  // anchor is center by default, don't account for lineWidth here
6983
- var _h = parsedStyle, stroke = _h.stroke, lineWidth = _h.lineWidth,
6984
+ var _h = parsedStyle, stroke = _h.stroke, _j = _h.lineWidth, lineWidth = _j === void 0 ? 1 : _j,
6984
6985
  // lineCap,
6985
6986
  // lineJoin,
6986
6987
  // miterLimit,
6987
- increasedLineWidthForHitTesting = _h.increasedLineWidthForHitTesting, shadowType = _h.shadowType, shadowColor = _h.shadowColor, _j = _h.filter, filter = _j === void 0 ? [] : _j, transformOrigin = _h.transformOrigin;
6988
+ _k = _h.increasedLineWidthForHitTesting,
6989
+ // lineCap,
6990
+ // lineJoin,
6991
+ // miterLimit,
6992
+ increasedLineWidthForHitTesting = _k === void 0 ? 0 : _k, _l = _h.shadowType, shadowType = _l === void 0 ? 'outer' : _l, shadowColor = _h.shadowColor, _m = _h.filter, filter = _m === void 0 ? [] : _m, transformOrigin = _h.transformOrigin;
6988
6993
  var center = [cx, cy, cz];
6989
6994
  // update geometry's AABB
6990
6995
  geometry_1.contentBounds.update(center, halfExtents);
@@ -7018,8 +7023,8 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7018
7023
  geometry_1.renderBounds.update(center, halfExtents);
7019
7024
  // account for shadow, only support constant value now
7020
7025
  if (shadowColor && shadowType && shadowType !== 'inner') {
7021
- var _k = geometry_1.renderBounds, min = _k.min, max = _k.max;
7022
- var _l = parsedStyle, shadowBlur = _l.shadowBlur, shadowOffsetX = _l.shadowOffsetX, shadowOffsetY = _l.shadowOffsetY;
7026
+ var _o = geometry_1.renderBounds, min = _o.min, max = _o.max;
7027
+ var _p = parsedStyle, shadowBlur = _p.shadowBlur, shadowOffsetX = _p.shadowOffsetX, shadowOffsetY = _p.shadowOffsetY;
7023
7028
  var shadowBlurInPixels = shadowBlur || 0;
7024
7029
  var shadowOffsetXInPixels = shadowOffsetX || 0;
7025
7030
  var shadowOffsetYInPixels = shadowOffsetY || 0;
@@ -7057,23 +7062,47 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7057
7062
  }
7058
7063
  });
7059
7064
  object.geometry.dirty = false;
7060
- // if (nodeName === Shape.RECT) {
7061
- // account for negative width / height of Rect
7062
7065
  // @see https://github.com/antvis/g/issues/957
7063
7066
  var flipY = hwidth < 0;
7064
7067
  var flipX = hheight < 0;
7065
- // } else {
7066
- // }
7067
7068
  // set transform origin
7068
7069
  var usedOriginXValue = (flipY ? -1 : 1) *
7069
7070
  (transformOrigin
7070
- ? convertPercentUnit(transformOrigin[0], 0, object)
7071
+ ? convertPercentUnit(transformOrigin[0], 0, object, true)
7071
7072
  : 0);
7072
7073
  var usedOriginYValue = (flipX ? -1 : 1) *
7073
7074
  (transformOrigin
7074
- ? convertPercentUnit(transformOrigin[1], 1, object)
7075
+ ? convertPercentUnit(transformOrigin[1], 1, object, true)
7075
7076
  : 0);
7076
- object.setOrigin(cx - hwidth + usedOriginXValue, cy - hheight + usedOriginYValue);
7077
+ if (usedOriginXValue || usedOriginYValue) {
7078
+ object.setOrigin(usedOriginXValue, usedOriginYValue);
7079
+ }
7080
+ }
7081
+ };
7082
+ DefaultStyleValueRegistry.prototype.updateSizeAttenuation = function (node, zoom) {
7083
+ if (node.style.isSizeAttenuation) {
7084
+ if (!node.style.rawLineWidth) {
7085
+ node.style.rawLineWidth = node.style.lineWidth;
7086
+ }
7087
+ node.style.lineWidth = (node.style.rawLineWidth || 1) / zoom;
7088
+ if (node.nodeName === Shape.CIRCLE) {
7089
+ if (!node.style.rawR) {
7090
+ node.style.rawR = node.style.r;
7091
+ }
7092
+ node.style.r = (node.style.rawR || 1) / zoom;
7093
+ }
7094
+ }
7095
+ else {
7096
+ if (node.style.rawLineWidth) {
7097
+ node.style.lineWidth = node.style.rawLineWidth;
7098
+ delete node.style.rawLineWidth;
7099
+ }
7100
+ if (node.nodeName === Shape.CIRCLE) {
7101
+ if (node.style.rawR) {
7102
+ node.style.r = node.style.rawR;
7103
+ delete node.style.rawR;
7104
+ }
7105
+ }
7077
7106
  }
7078
7107
  };
7079
7108
  DefaultStyleValueRegistry.prototype.isPropertyInheritable = function (name) {
@@ -7499,8 +7528,8 @@ function sortedIndex(array, value) {
7499
7528
  return low;
7500
7529
  }
7501
7530
  function sortByZIndex(o1, o2) {
7502
- var zIndex1 = Number(o1.parsedStyle.zIndex);
7503
- var zIndex2 = Number(o2.parsedStyle.zIndex);
7531
+ var zIndex1 = Number(o1.parsedStyle.zIndex || 0);
7532
+ var zIndex2 = Number(o2.parsedStyle.zIndex || 0);
7504
7533
  if (zIndex1 === zIndex2) {
7505
7534
  var parent_1 = o1.parentNode;
7506
7535
  if (parent_1) {
@@ -7564,6 +7593,7 @@ var clock = typeof performance === 'object' && performance.now ? performance : D
7564
7593
  function isFillOrStrokeAffected(pointerEvents, fill, stroke) {
7565
7594
  // account for pointerEvents
7566
7595
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
7596
+ if (pointerEvents === void 0) { pointerEvents = 'auto'; }
7567
7597
  var hasFill = false;
7568
7598
  var hasStroke = false;
7569
7599
  var isFillOtherThanNone = !!fill && !fill.isNone;
@@ -7790,7 +7820,7 @@ var genericFontFamilies = [
7790
7820
  ];
7791
7821
  var stringRegExp = /([\"\'])[^\'\"]+\1/;
7792
7822
  function toFontString(attributes) {
7793
- var fontSize = attributes.fontSize, fontFamily = attributes.fontFamily, fontStyle = attributes.fontStyle, fontVariant = attributes.fontVariant, fontWeight = attributes.fontWeight;
7823
+ var _a = attributes.fontSize, fontSize = _a === void 0 ? 16 : _a, _b = attributes.fontFamily, fontFamily = _b === void 0 ? 'sans-serif' : _b, _c = attributes.fontStyle, fontStyle = _c === void 0 ? 'normal' : _c, _d = attributes.fontVariant, fontVariant = _d === void 0 ? 'normal' : _d, _e = attributes.fontWeight, fontWeight = _e === void 0 ? 'normal' : _e;
7794
7824
  // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
7795
7825
  // const fontSizeString: string = isNumber(fontSize) ? `${fontSize}px` : fontSize.toString();
7796
7826
  var fontSizeString = (isNumber(fontSize) && "".concat(fontSize, "px")) || '16px';
@@ -7818,6 +7848,7 @@ function createSkewMatrix(skewMatrix, skewX, skewY) {
7818
7848
  skewMatrix[1] = Math.tan(skewY); // Skew X axis in Y direction
7819
7849
  return skewMatrix;
7820
7850
  }
7851
+ var SCALE_EPSILON = 0.00001;
7821
7852
  var tmpMat1 = mat4.create();
7822
7853
  var tmpMat2 = mat4.create();
7823
7854
  function parsedTransformToMat4(transform, object) {
@@ -7827,23 +7858,27 @@ function parsedTransformToMat4(transform, object) {
7827
7858
  var t = parsed.t, d = parsed.d;
7828
7859
  if (t === 'scale') {
7829
7860
  // scale(1) scale(1, 1)
7830
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1, 1];
7861
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [
7862
+ 1, 1,
7863
+ ];
7831
7864
  mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], 1]);
7832
7865
  }
7833
7866
  else if (t === 'scalex') {
7834
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7867
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7835
7868
  mat4.fromScaling(tmpMat2, [newScale[0], 1, 1]);
7836
7869
  }
7837
7870
  else if (t === 'scaley') {
7838
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7871
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7839
7872
  mat4.fromScaling(tmpMat2, [1, newScale[0], 1]);
7840
7873
  }
7841
7874
  else if (t === 'scalez') {
7842
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7875
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [1];
7843
7876
  mat4.fromScaling(tmpMat2, [1, 1, newScale[0]]);
7844
7877
  }
7845
7878
  else if (t === 'scale3d') {
7846
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1, 1, 1];
7879
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return Math.max(s.value, SCALE_EPSILON); })) || [
7880
+ 1, 1, 1,
7881
+ ];
7847
7882
  mat4.fromScaling(tmpMat2, [newScale[0], newScale[1], newScale[2]]);
7848
7883
  }
7849
7884
  else if (t === 'translate') {
@@ -7922,6 +7957,9 @@ function parsedTransformToMat4(transform, object) {
7922
7957
  });
7923
7958
  object.setLocalTransform(m_1);
7924
7959
  }
7960
+ else {
7961
+ object.resetLocalTransform();
7962
+ }
7925
7963
  return object.getLocalTransform();
7926
7964
  }
7927
7965
 
@@ -7985,17 +8023,18 @@ var CSSPropertyTransformOrigin = /** @class */ (function () {
7985
8023
  function CSSPropertyTransformOrigin() {
7986
8024
  this.parser = parseTransformOrigin;
7987
8025
  this.parserUnmemoize = parseTransformOriginUnmemoize;
7988
- // calculator(
7989
- // name: string,
7990
- // oldParsed: [CSSUnitValue, CSSUnitValue],
7991
- // parsed: [CSSUnitValue, CSSUnitValue],
7992
- // object: DisplayObject,
7993
- // ): [number, number] {
7994
- // console.log(object, parsed);
7995
- // return [parsed[0].value, parsed[1].value];
7996
- // // return [convertPercentUnit(parsed[0], 0, object), convertPercentUnit(parsed[1], 1, object)];
7997
- // }
7998
8026
  }
8027
+ CSSPropertyTransformOrigin.prototype.postProcessor = function (object) {
8028
+ var transformOrigin = object.parsedStyle.transformOrigin;
8029
+ if (transformOrigin[0].unit === UnitType.kPixels &&
8030
+ transformOrigin[1].unit === UnitType.kPixels) {
8031
+ object.setOrigin(transformOrigin[0].value, transformOrigin[1].value);
8032
+ }
8033
+ else {
8034
+ // Relative to geometry bounds, calculate later.
8035
+ object.getGeometryBounds();
8036
+ }
8037
+ };
7999
8038
  return CSSPropertyTransformOrigin;
8000
8039
  }());
8001
8040
 
@@ -8082,8 +8121,8 @@ var PathUpdater = /** @class */ (function () {
8082
8121
  function PathUpdater() {
8083
8122
  }
8084
8123
  PathUpdater.prototype.update = function (parsedStyle) {
8085
- var path = parsedStyle.path;
8086
- var _a = path.rect, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
8124
+ var d = parsedStyle.d;
8125
+ var _a = d.rect, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
8087
8126
  var hwidth = width / 2;
8088
8127
  var hheight = height / 2;
8089
8128
  return {
@@ -8132,17 +8171,17 @@ var RectUpdater = /** @class */ (function () {
8132
8171
  function RectUpdater() {
8133
8172
  }
8134
8173
  RectUpdater.prototype.update = function (parsedStyle, object) {
8135
- var _a = parsedStyle.x, x = _a === void 0 ? 0 : _a, _b = parsedStyle.y, y = _b === void 0 ? 0 : _b, img = parsedStyle.img, _c = parsedStyle.width, width = _c === void 0 ? 0 : _c, _d = parsedStyle.height, height = _d === void 0 ? 0 : _d;
8174
+ var _a = parsedStyle.x, x = _a === void 0 ? 0 : _a, _b = parsedStyle.y, y = _b === void 0 ? 0 : _b, src = parsedStyle.src, _c = parsedStyle.width, width = _c === void 0 ? 0 : _c, _d = parsedStyle.height, height = _d === void 0 ? 0 : _d;
8136
8175
  var contentWidth = width;
8137
8176
  var contentHeight = height;
8138
8177
  // resize with HTMLImageElement's size
8139
- if (img && !isString(img)) {
8178
+ if (src && !isString(src)) {
8140
8179
  if (!contentWidth) {
8141
- contentWidth = img.width;
8180
+ contentWidth = src.width;
8142
8181
  parsedStyle.width = contentWidth;
8143
8182
  }
8144
8183
  if (!contentHeight) {
8145
- contentHeight = img.height;
8184
+ contentHeight = src.height;
8146
8185
  parsedStyle.height = contentHeight;
8147
8186
  }
8148
8187
  }
@@ -8162,18 +8201,20 @@ var TextUpdater = /** @class */ (function () {
8162
8201
  }
8163
8202
  TextUpdater.prototype.isReadyToMeasure = function (parsedStyle, object) {
8164
8203
  var text = parsedStyle.text, textAlign = parsedStyle.textAlign, textBaseline = parsedStyle.textBaseline, fontSize = parsedStyle.fontSize, fontStyle = parsedStyle.fontStyle, fontWeight = parsedStyle.fontWeight, fontVariant = parsedStyle.fontVariant, lineWidth = parsedStyle.lineWidth;
8165
- return (text &&
8166
- fontSize &&
8167
- fontStyle &&
8168
- fontWeight &&
8169
- fontVariant &&
8170
- textAlign &&
8171
- textBaseline &&
8172
- !isNil(lineWidth));
8204
+ return runtime.enableCSSParsing
8205
+ ? text &&
8206
+ fontSize &&
8207
+ fontStyle &&
8208
+ fontWeight &&
8209
+ fontVariant &&
8210
+ textAlign &&
8211
+ textBaseline &&
8212
+ !isNil(lineWidth)
8213
+ : text;
8173
8214
  };
8174
8215
  TextUpdater.prototype.update = function (parsedStyle, object) {
8175
8216
  var _a, _b;
8176
- var text = parsedStyle.text, textAlign = parsedStyle.textAlign, lineWidth = parsedStyle.lineWidth, textBaseline = parsedStyle.textBaseline, dx = parsedStyle.dx, dy = parsedStyle.dy, _c = parsedStyle.x, x = _c === void 0 ? 0 : _c, _d = parsedStyle.y, y = _d === void 0 ? 0 : _d;
8217
+ var text = parsedStyle.text, _c = parsedStyle.textAlign, textAlign = _c === void 0 ? 'start' : _c, _d = parsedStyle.lineWidth, lineWidth = _d === void 0 ? 1 : _d, _e = parsedStyle.textBaseline, textBaseline = _e === void 0 ? 'alphabetic' : _e, _f = parsedStyle.dx, dx = _f === void 0 ? 0 : _f, _g = parsedStyle.dy, dy = _g === void 0 ? 0 : _g, _h = parsedStyle.x, x = _h === void 0 ? 0 : _h, _j = parsedStyle.y, y = _j === void 0 ? 0 : _j;
8177
8218
  if (!this.isReadyToMeasure(parsedStyle, object)) {
8178
8219
  parsedStyle.metrics = {
8179
8220
  font: '',
@@ -8245,6 +8286,20 @@ var TextUpdater = /** @class */ (function () {
8245
8286
  return TextUpdater;
8246
8287
  }());
8247
8288
 
8289
+ var GroupUpdater = /** @class */ (function () {
8290
+ function GroupUpdater() {
8291
+ }
8292
+ GroupUpdater.prototype.update = function (parsedStyle, object) {
8293
+ return {
8294
+ cx: 0,
8295
+ cy: 0,
8296
+ hwidth: 0,
8297
+ hheight: 0,
8298
+ };
8299
+ };
8300
+ return GroupUpdater;
8301
+ }());
8302
+
8248
8303
  function isFederatedEvent(value) {
8249
8304
  return !!value.type;
8250
8305
  }
@@ -9582,10 +9637,13 @@ var EventService = /** @class */ (function () {
9582
9637
  * whether the native event trigger came from Canvas,
9583
9638
  * should account for HTML shape
9584
9639
  */
9585
- EventService.prototype.isNativeEventFromCanvas = function (event) {
9586
- var _a;
9587
- var $el = this.context.contextService.getDomElement();
9588
- var target = (_a = event.nativeEvent) === null || _a === void 0 ? void 0 : _a.target;
9640
+ EventService.prototype.isNativeEventFromCanvas = function ($el, nativeEvent) {
9641
+ var target = nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.target;
9642
+ // Get event target inside a web component.
9643
+ // @see https://stackoverflow.com/questions/57963312/get-event-target-inside-a-web-component
9644
+ if (target === null || target === void 0 ? void 0 : target.shadowRoot) {
9645
+ target = nativeEvent.composedPath()[0];
9646
+ }
9589
9647
  if (target) {
9590
9648
  // from <canvas>
9591
9649
  if (target === $el) {
@@ -9596,8 +9654,8 @@ var EventService = /** @class */ (function () {
9596
9654
  return $el.contains(target);
9597
9655
  }
9598
9656
  }
9599
- if (event.nativeEvent.composedPath) {
9600
- return event.nativeEvent.composedPath().indexOf($el) > -1;
9657
+ if (nativeEvent === null || nativeEvent === void 0 ? void 0 : nativeEvent.composedPath) {
9658
+ return nativeEvent.composedPath().indexOf($el) > -1;
9601
9659
  }
9602
9660
  // account for Touch
9603
9661
  return false;
@@ -9645,9 +9703,11 @@ var EventService = /** @class */ (function () {
9645
9703
  event.nativeEvent = from.nativeEvent;
9646
9704
  event.originalEvent = from;
9647
9705
  var existedHTML = this.getExistedHTML(event);
9706
+ var $el = this.context.contextService.getDomElement();
9648
9707
  event.target =
9649
9708
  target !== null && target !== void 0 ? target : (existedHTML ||
9650
- (this.isNativeEventFromCanvas(event) && this.pickTarget(event)) ||
9709
+ (this.isNativeEventFromCanvas($el, event.nativeEvent) &&
9710
+ this.pickTarget(event)) ||
9651
9711
  fallbackTarget);
9652
9712
  if (typeof type === 'string') {
9653
9713
  event.type = type;
@@ -9662,9 +9722,11 @@ var EventService = /** @class */ (function () {
9662
9722
  event.nativeEvent = from.nativeEvent;
9663
9723
  event.originalEvent = from;
9664
9724
  var existedHTML = this.getExistedHTML(event);
9725
+ var $el = this.context.contextService.getDomElement();
9665
9726
  event.target =
9666
9727
  existedHTML ||
9667
- (this.isNativeEventFromCanvas(event) && this.pickTarget(event));
9728
+ (this.isNativeEventFromCanvas($el, event.nativeEvent) &&
9729
+ this.pickTarget(event));
9668
9730
  return event;
9669
9731
  };
9670
9732
  EventService.prototype.trackingData = function (id) {
@@ -10664,6 +10726,7 @@ var DefaultSceneGraphService = /** @class */ (function () {
10664
10726
  }
10665
10727
  };
10666
10728
  DefaultSceneGraphService.prototype.getOrigin = function (element) {
10729
+ element.getGeometryBounds();
10667
10730
  return element.transformable.origin;
10668
10731
  };
10669
10732
  /**
@@ -10973,6 +11036,9 @@ var DefaultSceneGraphService = /** @class */ (function () {
10973
11036
  }
10974
11037
  }
10975
11038
  });
11039
+ if (!aabb) {
11040
+ aabb = new AABB();
11041
+ }
10976
11042
  if (render) {
10977
11043
  // FIXME: account for clip path
10978
11044
  var clipped = findClosestClipPathTarget(element);
@@ -10980,28 +11046,19 @@ var DefaultSceneGraphService = /** @class */ (function () {
10980
11046
  // use bounds under world space
10981
11047
  var clipPathBounds = clipped.parsedStyle.clipPath.getBounds(render);
10982
11048
  if (!aabb) {
10983
- aabb = clipPathBounds;
11049
+ aabb.update(clipPathBounds.center, clipPathBounds.halfExtents);
10984
11050
  }
10985
11051
  else if (clipPathBounds) {
10986
11052
  aabb = clipPathBounds.intersection(aabb);
10987
11053
  }
10988
11054
  }
10989
11055
  }
10990
- if (!aabb) {
10991
- aabb = new AABB();
10992
- }
10993
- if (aabb) {
10994
- if (render) {
10995
- renderable.renderBounds = aabb;
10996
- }
10997
- else {
10998
- renderable.bounds = aabb;
10999
- }
11000
- }
11001
11056
  if (render) {
11057
+ renderable.renderBounds = aabb;
11002
11058
  renderable.renderBoundsDirty = false;
11003
11059
  }
11004
11060
  else {
11061
+ renderable.bounds = aabb;
11005
11062
  renderable.boundsDirty = false;
11006
11063
  }
11007
11064
  return aabb;
@@ -11258,13 +11315,13 @@ var TextService = /** @class */ (function () {
11258
11315
  return properties;
11259
11316
  };
11260
11317
  TextService.prototype.measureText = function (text, parsedStyle, offscreenCanvas) {
11261
- var fontSize = parsedStyle.fontSize, wordWrap = parsedStyle.wordWrap, strokeHeight = parsedStyle.lineHeight, lineWidth = parsedStyle.lineWidth, textBaseline = parsedStyle.textBaseline, textAlign = parsedStyle.textAlign, letterSpacing = parsedStyle.letterSpacing, textPath = parsedStyle.textPath; parsedStyle.textPathSide; parsedStyle.textPathStartOffset;
11318
+ var _a = parsedStyle.fontSize, fontSize = _a === void 0 ? 16 : _a, _b = parsedStyle.wordWrap, wordWrap = _b === void 0 ? false : _b, strokeHeight = parsedStyle.lineHeight, _c = parsedStyle.lineWidth, lineWidth = _c === void 0 ? 1 : _c, _d = parsedStyle.textBaseline, textBaseline = _d === void 0 ? 'alphabetic' : _d, _e = parsedStyle.textAlign, textAlign = _e === void 0 ? 'start' : _e, _f = parsedStyle.letterSpacing, letterSpacing = _f === void 0 ? 0 : _f, textPath = parsedStyle.textPath; parsedStyle.textPathSide; parsedStyle.textPathStartOffset;
11262
11319
  var // dropShadow = 0,
11263
11320
  // dropShadowDistance = 0,
11264
- _a = parsedStyle.leading,
11321
+ _g = parsedStyle.leading,
11265
11322
  // dropShadow = 0,
11266
11323
  // dropShadowDistance = 0,
11267
- leading = _a === void 0 ? 0 : _a;
11324
+ leading = _g === void 0 ? 0 : _g;
11268
11325
  var font = toFontString(parsedStyle);
11269
11326
  // if (runtime.enableCSSParsing) {
11270
11327
  var fontProperties = this.measureFont(font, offscreenCanvas);
@@ -11376,7 +11433,7 @@ var TextService = /** @class */ (function () {
11376
11433
  TextService.prototype.setGraphemeOnPath = function () { };
11377
11434
  TextService.prototype.wordWrap = function (text, parsedStyle, offscreenCanvas) {
11378
11435
  var _this = this;
11379
- 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;
11436
+ var _a = parsedStyle.wordWrapWidth, wordWrapWidth = _a === void 0 ? 0 : _a, _b = parsedStyle.letterSpacing, letterSpacing = _b === void 0 ? 0 : _b, _c = parsedStyle.maxLines, maxLines = _c === void 0 ? Infinity : _c, textOverflow = parsedStyle.textOverflow;
11380
11437
  var context = this.runtime.offscreenCanvasCreator.getOrCreateContext(offscreenCanvas);
11381
11438
  var maxWidth = wordWrapWidth + letterSpacing;
11382
11439
  var ellipsis = '';
@@ -11526,7 +11583,7 @@ var geometryUpdaterFactory = (function () {
11526
11583
  _a[Shape.ELLIPSE] = new EllipseUpdater(),
11527
11584
  _a[Shape.RECT] = rectUpdater,
11528
11585
  _a[Shape.IMAGE] = rectUpdater,
11529
- _a[Shape.GROUP] = rectUpdater,
11586
+ _a[Shape.GROUP] = new GroupUpdater(),
11530
11587
  _a[Shape.LINE] = new LineUpdater(),
11531
11588
  _a[Shape.TEXT] = new TextUpdater(runtime),
11532
11589
  _a[Shape.POLYLINE] = polylineUpdater,
@@ -11600,9 +11657,11 @@ runtime.CSSPropertySyntaxFactory = CSSPropertySyntaxFactory;
11600
11657
  runtime.styleValueRegistry = new DefaultStyleValueRegistry(runtime);
11601
11658
  runtime.layoutRegistry = null;
11602
11659
  runtime.globalThis = getGlobalThis();
11603
- runtime.enableCSSParsing = true;
11660
+ runtime.enableCSSParsing = false;
11604
11661
  runtime.enableDataset = false;
11605
11662
  runtime.enableStyleSyntax = true;
11663
+ runtime.enableAttributeDashCased = false;
11664
+ runtime.enableSizeAttenuation = false;
11606
11665
 
11607
11666
  var entityCounter = 0;
11608
11667
  function resetEntityCounter() {
@@ -11848,8 +11907,11 @@ var Element = /** @class */ (function (_super) {
11848
11907
  if ((_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) {
11849
11908
  this.ownerDocument.defaultView.mountChildren(child);
11850
11909
  }
11851
- insertedEvent.relatedNode = this;
11852
- child.dispatchEvent(insertedEvent);
11910
+ // @ts-ignore
11911
+ if (this.isMutationObserved) {
11912
+ insertedEvent.relatedNode = this;
11913
+ child.dispatchEvent(insertedEvent);
11914
+ }
11853
11915
  return child;
11854
11916
  };
11855
11917
  Element.prototype.insertBefore = function (newChild, refChild) {
@@ -12122,8 +12184,10 @@ var Element = /** @class */ (function (_super) {
12122
12184
  }
12123
12185
  var value = this.attributes[name];
12124
12186
  if (value === undefined) {
12125
- var attributeName = formatAttributeName(name);
12126
- value = this.attributes[attributeName];
12187
+ if (runtime.enableAttributeDashCased) {
12188
+ var attributeName = formatAttributeName(name);
12189
+ value = this.attributes[attributeName];
12190
+ }
12127
12191
  // if the given attribute does not exist, the value returned will either be null or ""
12128
12192
  return runtime.enableCSSParsing ? (isNil(value) ? null : value) : value;
12129
12193
  }
@@ -12193,6 +12257,9 @@ var Element = /** @class */ (function (_super) {
12193
12257
  function isDisplayObject(value) {
12194
12258
  return !!(value === null || value === void 0 ? void 0 : value.nodeName);
12195
12259
  }
12260
+ var Proxy = runtime.globalThis.Proxy
12261
+ ? runtime.globalThis.Proxy
12262
+ : function () { };
12196
12263
  var mutationEvent = new MutationEvent(ElementEvent.ATTR_MODIFIED, null, null, null, null, MutationEvent.MODIFICATION, null, null);
12197
12264
  var DEFAULT_STYLE_PROPS = {
12198
12265
  opacity: '',
@@ -12229,7 +12296,20 @@ var DEFAULT_PARSED_STYLE_PROPS = {
12229
12296
  shadowType: 'outer',
12230
12297
  miterLimit: 10,
12231
12298
  };
12232
- 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' });
12299
+ // const DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED = {
12300
+ // ...DEFAULT_PARSED_STYLE_PROPS,
12301
+ // opacity: 1,
12302
+ // fillOpacity: 1,
12303
+ // strokeOpacity: 1,
12304
+ // visibility: 'visible',
12305
+ // pointerEvents: 'auto',
12306
+ // lineWidth: 1,
12307
+ // lineCap: 'butt',
12308
+ // lineJoin: 'miter',
12309
+ // increasedLineWidthForHitTesting: 0,
12310
+ // fillRule: 'nonzero',
12311
+ // // TODO: transformOrigin
12312
+ // };
12233
12313
  var INHERITABLE_BASE_STYLE_PROPS = [
12234
12314
  'opacity',
12235
12315
  'fillOpacity',
@@ -12281,13 +12361,6 @@ var DisplayObject = /** @class */ (function (_super) {
12281
12361
  * push to active animations after calling `animate()`
12282
12362
  */
12283
12363
  _this.activeAnimations = [];
12284
- /**
12285
- * Use `this.style.clipPath` instead.
12286
- * @deprecated
12287
- */
12288
- _this.getClip = function () {
12289
- return this.style.clipPath || null;
12290
- };
12291
12364
  // assign name, id to config
12292
12365
  // eg. group.get('name')
12293
12366
  _this.config = config;
@@ -12298,18 +12371,17 @@ var DisplayObject = /** @class */ (function (_super) {
12298
12371
  _this.className = _this.config.className || _this.config.class;
12299
12372
  }
12300
12373
  _this.nodeName = _this.config.type || Shape.GROUP;
12301
- // merge parsed value
12302
- Object.assign(_this.parsedStyle, runtime.enableCSSParsing
12303
- ? DEFAULT_PARSED_STYLE_PROPS
12304
- : DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED, _this.config.initialParsedStyle);
12305
12374
  if (runtime.enableCSSParsing) {
12306
12375
  Object.assign(_this.attributes, DEFAULT_STYLE_PROPS);
12376
+ Object.assign(_this.parsedStyle, DEFAULT_PARSED_STYLE_PROPS, _this.config.initialParsedStyle);
12377
+ }
12378
+ else if (_this.config.initialParsedStyle) {
12379
+ Object.assign(_this.parsedStyle,
12380
+ // DEFAULT_PARSED_STYLE_PROPS_CSS_DISABLED,
12381
+ _this.config.initialParsedStyle);
12307
12382
  }
12308
12383
  // start to process attributes
12309
12384
  _this.initAttributes(_this.config.style);
12310
- var Proxy = runtime.globalThis.Proxy
12311
- ? runtime.globalThis.Proxy
12312
- : function () { };
12313
12385
  if (runtime.enableDataset) {
12314
12386
  _this.dataset = new Proxy({}, {
12315
12387
  get: function (target, name) {
@@ -12427,10 +12499,14 @@ var DisplayObject = /** @class */ (function (_super) {
12427
12499
  options.usedAttributes = INHERITABLE_STYLE_PROPS;
12428
12500
  }
12429
12501
  // account for FCP, process properties as less as possible
12430
- var formattedAttributes = {};
12431
- for (var name_1 in attributes) {
12432
- var attributeName = formatAttributeName(name_1);
12433
- formattedAttributes[attributeName] = attributes[name_1];
12502
+ var formattedAttributes = attributes;
12503
+ if (runtime.enableAttributeDashCased) {
12504
+ // @ts-ignore
12505
+ formattedAttributes = {};
12506
+ for (var name_1 in attributes) {
12507
+ var attributeName = formatAttributeName(name_1);
12508
+ formattedAttributes[attributeName] = attributes[name_1];
12509
+ }
12434
12510
  }
12435
12511
  runtime.styleValueRegistry.processProperties(this, formattedAttributes, options);
12436
12512
  // redraw at next frame
@@ -12439,14 +12515,16 @@ var DisplayObject = /** @class */ (function (_super) {
12439
12515
  DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
12440
12516
  if (force === void 0) { force = false; }
12441
12517
  if (memoize === void 0) { memoize = true; }
12442
- var attributeName = formatAttributeName(name);
12518
+ if (runtime.enableAttributeDashCased) {
12519
+ name = formatAttributeName(name);
12520
+ }
12443
12521
  // ignore undefined value
12444
12522
  if (isUndefined(value)) {
12445
12523
  return;
12446
12524
  }
12447
- if (force || value !== this.attributes[attributeName]) {
12448
- this.internalSetAttribute(attributeName, value, { memoize: memoize });
12449
- _super.prototype.setAttribute.call(this, attributeName, value);
12525
+ if (force || value !== this.attributes[name]) {
12526
+ this.internalSetAttribute(name, value, { memoize: memoize });
12527
+ _super.prototype.setAttribute.call(this, name, value);
12450
12528
  }
12451
12529
  };
12452
12530
  /**
@@ -12700,8 +12778,10 @@ var DisplayObject = /** @class */ (function (_super) {
12700
12778
  * shortcut for Used value of `visibility`
12701
12779
  */
12702
12780
  DisplayObject.prototype.isVisible = function () {
12703
- var _a;
12704
- return ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) === 'visible';
12781
+ var _a, _b;
12782
+ return runtime.enableCSSParsing
12783
+ ? ((_a = this.parsedStyle) === null || _a === void 0 ? void 0 : _a.visibility) === 'visible'
12784
+ : ((_b = this.parsedStyle) === null || _b === void 0 ? void 0 : _b.visibility) !== 'hidden';
12705
12785
  };
12706
12786
  Object.defineProperty(DisplayObject.prototype, "interactive", {
12707
12787
  get: function () {
@@ -12893,13 +12973,6 @@ var DisplayObject = /** @class */ (function (_super) {
12893
12973
  DisplayObject.prototype.add = function (child, index) {
12894
12974
  return this.appendChild(child, index);
12895
12975
  };
12896
- /**
12897
- * Use `this.style.clipPath` instead.
12898
- * @deprecated
12899
- */
12900
- DisplayObject.prototype.setClip = function (clipPath) {
12901
- this.style.clipPath = clipPath;
12902
- };
12903
12976
  /**
12904
12977
  * @deprecated
12905
12978
  */
@@ -12944,124 +13017,11 @@ var DisplayObject = /** @class */ (function (_super) {
12944
13017
  return DisplayObject;
12945
13018
  }(Element));
12946
13019
 
12947
- /**
12948
- * holds useful CSS-related methods.
12949
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS
12950
- *
12951
- * * CSS Typed OM @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/factory_functions
12952
- * * register property @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty
12953
- * * CSS Layout API
12954
- */
12955
- var CSS = {
12956
- /**
12957
- * <number>
12958
- * @see https://drafts.csswg.org/css-values-4/#number-value
12959
- */
12960
- number: function (n) {
12961
- return new CSSUnitValue(n);
12962
- },
12963
- /**
12964
- * <percentage>
12965
- * @see https://drafts.csswg.org/css-values-4/#percentage-value
12966
- */
12967
- percent: function (n) {
12968
- return new CSSUnitValue(n, '%');
12969
- },
12970
- /**
12971
- * <length>
12972
- */
12973
- px: function (n) {
12974
- return new CSSUnitValue(n, 'px');
12975
- },
12976
- /**
12977
- * <length>
12978
- */
12979
- em: function (n) {
12980
- return new CSSUnitValue(n, 'em');
12981
- },
12982
- rem: function (n) {
12983
- return new CSSUnitValue(n, 'rem');
12984
- },
12985
- /**
12986
- * <angle>
12987
- */
12988
- deg: function (n) {
12989
- return new CSSUnitValue(n, 'deg');
12990
- },
12991
- /**
12992
- * <angle>
12993
- */
12994
- grad: function (n) {
12995
- return new CSSUnitValue(n, 'grad');
12996
- },
12997
- /**
12998
- * <angle>
12999
- */
13000
- rad: function (n) {
13001
- return new CSSUnitValue(n, 'rad');
13002
- },
13003
- /**
13004
- * <angle>
13005
- */
13006
- turn: function (n) {
13007
- return new CSSUnitValue(n, 'turn');
13008
- },
13009
- /**
13010
- * <time>
13011
- */
13012
- s: function (n) {
13013
- return new CSSUnitValue(n, 's');
13014
- },
13015
- /**
13016
- * <time>
13017
- */
13018
- ms: function (n) {
13019
- return new CSSUnitValue(n, 'ms');
13020
- },
13021
- /**
13022
- * CSS Properties & Values API
13023
- *
13024
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS_Properties_and_Values_API
13025
- * @see https://drafts.css-houdini.org/css-properties-values-api/#registering-custom-properties
13026
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty
13027
- */
13028
- registerProperty: function (definition) {
13029
- var name = definition.name, inherits = definition.inherits, interpolable = definition.interpolable, initialValue = definition.initialValue, syntax = definition.syntax;
13030
- runtime.styleValueRegistry.registerMetadata({
13031
- n: name,
13032
- inh: inherits,
13033
- int: interpolable,
13034
- d: initialValue,
13035
- syntax: syntax,
13036
- });
13037
- },
13038
- /**
13039
- * CSS Layout API
13040
- * register layout
13041
- *
13042
- * @see https://github.com/w3c/css-houdini-drafts/blob/main/css-layout-api/EXPLAINER.md
13043
- * @see https://developer.mozilla.org/en-US/docs/Web/Guide/Houdini#css_layout_api
13044
- */
13045
- registerLayout: function (name, clazz) {
13046
- runtime.layoutRegistry.registerLayout(name, clazz);
13047
- },
13048
- };
13049
-
13050
13020
  var Circle = /** @class */ (function (_super) {
13051
13021
  __extends(Circle, _super);
13052
- // constructor(options: DisplayObjectConfig<CircleStyleProps> = {}) {
13053
- // super(options);
13054
- // this.nodeName = Shape.CIRCLE;
13055
- // }
13056
- function Circle(_a) {
13057
- if (_a === void 0) { _a = {}; }
13058
- var style = _a.style, rest = __rest(_a, ["style"]);
13059
- return _super.call(this, __assign({ type: Shape.CIRCLE, style: runtime.enableCSSParsing
13060
- ? __assign({ cx: '', cy: '', r: '' }, style) : style, initialParsedStyle: {
13061
- transformOrigin: runtime.enableCSSParsing
13062
- ? null
13063
- : [PECENTAGE_50, PECENTAGE_50],
13064
- } }, rest)) || this;
13022
+ function Circle(options) {
13023
+ if (options === void 0) { options = {}; }
13024
+ return _super.call(this, __assign({ type: Shape.CIRCLE }, options)) || this;
13065
13025
  }
13066
13026
  return Circle;
13067
13027
  }(DisplayObject));
@@ -13090,15 +13050,9 @@ var CustomElement = /** @class */ (function (_super) {
13090
13050
 
13091
13051
  var Ellipse = /** @class */ (function (_super) {
13092
13052
  __extends(Ellipse, _super);
13093
- function Ellipse(_a) {
13094
- if (_a === void 0) { _a = {}; }
13095
- var style = _a.style, rest = __rest(_a, ["style"]);
13096
- return _super.call(this, __assign({ type: Shape.ELLIPSE, style: runtime.enableCSSParsing
13097
- ? __assign({ cx: '', cy: '', rx: '', ry: '' }, style) : style, initialParsedStyle: {
13098
- transformOrigin: runtime.enableCSSParsing
13099
- ? null
13100
- : [PECENTAGE_50, PECENTAGE_50],
13101
- } }, rest)) || this;
13053
+ function Ellipse(options) {
13054
+ if (options === void 0) { options = {}; }
13055
+ return _super.call(this, __assign({ type: Shape.ELLIPSE }, options)) || this;
13102
13056
  }
13103
13057
  return Ellipse;
13104
13058
  }(DisplayObject));
@@ -13115,11 +13069,9 @@ var Ellipse = /** @class */ (function (_super) {
13115
13069
  */
13116
13070
  var Group = /** @class */ (function (_super) {
13117
13071
  __extends(Group, _super);
13118
- function Group(_a) {
13119
- if (_a === void 0) { _a = {}; }
13120
- var style = _a.style, rest = __rest(_a, ["style"]);
13121
- return _super.call(this, __assign({ type: Shape.GROUP, style: runtime.enableCSSParsing
13122
- ? __assign({ width: '', height: '' }, style) : __assign({}, style) }, rest)) || this;
13072
+ function Group(options) {
13073
+ if (options === void 0) { options = {}; }
13074
+ return _super.call(this, __assign({ type: Shape.GROUP }, options)) || this;
13123
13075
  }
13124
13076
  return Group;
13125
13077
  }(DisplayObject));
@@ -13192,11 +13144,9 @@ var HTML = /** @class */ (function (_super) {
13192
13144
 
13193
13145
  var Image = /** @class */ (function (_super) {
13194
13146
  __extends(Image, _super);
13195
- function Image(_a) {
13196
- if (_a === void 0) { _a = {}; }
13197
- var style = _a.style, rest = __rest(_a, ["style"]);
13198
- return _super.call(this, __assign({ type: Shape.IMAGE, style: runtime.enableCSSParsing
13199
- ? __assign({ x: '', y: '', img: '', width: '', height: '' }, style) : __assign({}, style) }, rest)) || this;
13147
+ function Image(options) {
13148
+ if (options === void 0) { options = {}; }
13149
+ return _super.call(this, __assign({ type: Shape.IMAGE }, options)) || this;
13200
13150
  }
13201
13151
  return Image;
13202
13152
  }(DisplayObject));
@@ -13325,11 +13275,11 @@ var Path = /** @class */ (function (_super) {
13325
13275
  var _this = this;
13326
13276
  var style = _a.style, rest = __rest(_a, ["style"]);
13327
13277
  _this = _super.call(this, __assign({ type: Shape.PATH, style: runtime.enableCSSParsing
13328
- ? __assign({ path: '', miterLimit: '' }, style) : __assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13278
+ ? __assign({ d: '', miterLimit: '' }, style) : __assign({}, style), initialParsedStyle: runtime.enableCSSParsing
13329
13279
  ? null
13330
13280
  : {
13331
13281
  miterLimit: 4,
13332
- path: __assign({}, EMPTY_PARSED_PATH),
13282
+ d: __assign({}, EMPTY_PARSED_PATH),
13333
13283
  } }, rest)) || this;
13334
13284
  _this.markerStartAngle = 0;
13335
13285
  _this.markerEndAngle = 0;
@@ -13354,7 +13304,7 @@ var Path = /** @class */ (function (_super) {
13354
13304
  return _this;
13355
13305
  }
13356
13306
  Path.prototype.attributeChangedCallback = function (attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
13357
- if (attrName === 'path') {
13307
+ if (attrName === 'd') {
13358
13308
  // recalc markers
13359
13309
  this.transformMarker(true);
13360
13310
  this.transformMarker(false);
@@ -13429,7 +13379,7 @@ var Path = /** @class */ (function (_super) {
13429
13379
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
13430
13380
  };
13431
13381
  Path.prototype.placeMarkerMid = function (marker) {
13432
- var segments = this.parsedStyle.path.segments;
13382
+ var segments = this.parsedStyle.d.segments;
13433
13383
  // clear all existed markers
13434
13384
  this.markerMidList.forEach(function (marker) {
13435
13385
  marker.remove();
@@ -13458,7 +13408,7 @@ var Path = /** @class */ (function (_super) {
13458
13408
  */
13459
13409
  Path.prototype.getPointAtLength = function (distance, inWorldSpace) {
13460
13410
  if (inWorldSpace === void 0) { inWorldSpace = false; }
13461
- var absolutePath = this.parsedStyle.path.absolutePath;
13411
+ var absolutePath = this.parsedStyle.d.absolutePath;
13462
13412
  var _a = getPointAtLength(absolutePath, distance), x = _a.x, y = _a.y;
13463
13413
  var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x, y, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13464
13414
  // apply local transformation
@@ -13475,7 +13425,7 @@ var Path = /** @class */ (function (_super) {
13475
13425
  * Get start tangent vector
13476
13426
  */
13477
13427
  Path.prototype.getStartTangent = function () {
13478
- var segments = this.parsedStyle.path.segments;
13428
+ var segments = this.parsedStyle.d.segments;
13479
13429
  var result = [];
13480
13430
  if (segments.length > 1) {
13481
13431
  var startPoint = segments[0].currentPoint;
@@ -13497,7 +13447,7 @@ var Path = /** @class */ (function (_super) {
13497
13447
  * Get end tangent vector
13498
13448
  */
13499
13449
  Path.prototype.getEndTangent = function () {
13500
- var segments = this.parsedStyle.path.segments;
13450
+ var segments = this.parsedStyle.d.segments;
13501
13451
  var length = segments.length;
13502
13452
  var result = [];
13503
13453
  if (length > 1) {
@@ -13685,7 +13635,7 @@ var Polyline = /** @class */ (function (_super) {
13685
13635
  } }, rest)) || this;
13686
13636
  }
13687
13637
  Polyline.prototype.getTotalLength = function () {
13688
- return this.parsedStyle.points.totalLength;
13638
+ return getOrCalculatePolylineTotalLength(this);
13689
13639
  };
13690
13640
  Polyline.prototype.getPointAtLength = function (distance, inWorldSpace) {
13691
13641
  if (inWorldSpace === void 0) { inWorldSpace = false; }
@@ -13693,16 +13643,34 @@ var Polyline = /** @class */ (function (_super) {
13693
13643
  };
13694
13644
  Polyline.prototype.getPoint = function (ratio, inWorldSpace) {
13695
13645
  if (inWorldSpace === void 0) { inWorldSpace = false; }
13696
- var _a = this.parsedStyle.points, points = _a.points, segments = _a.segments;
13646
+ var points = this.parsedStyle.points.points;
13647
+ if (this.parsedStyle.points.segments.length === 0) {
13648
+ var segments_1 = [];
13649
+ var tempLength_1 = 0;
13650
+ var segmentT_1;
13651
+ var segmentL_1;
13652
+ var totalLength_1 = this.getTotalLength();
13653
+ points.forEach(function (p, i) {
13654
+ if (points[i + 1]) {
13655
+ segmentT_1 = [0, 0];
13656
+ segmentT_1[0] = tempLength_1 / totalLength_1;
13657
+ segmentL_1 = lineLength(p[0], p[1], points[i + 1][0], points[i + 1][1]);
13658
+ tempLength_1 += segmentL_1;
13659
+ segmentT_1[1] = tempLength_1 / totalLength_1;
13660
+ segments_1.push(segmentT_1);
13661
+ }
13662
+ });
13663
+ this.parsedStyle.points.segments = segments_1;
13664
+ }
13697
13665
  var subt = 0;
13698
13666
  var index = 0;
13699
- segments.forEach(function (v, i) {
13667
+ this.parsedStyle.points.segments.forEach(function (v, i) {
13700
13668
  if (ratio >= v[0] && ratio <= v[1]) {
13701
13669
  subt = (ratio - v[0]) / (v[1] - v[0]);
13702
13670
  index = i;
13703
13671
  }
13704
13672
  });
13705
- var _b = linePointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt), x = _b.x, y = _b.y;
13673
+ var _a = linePointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt), x = _a.x, y = _a.y;
13706
13674
  var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x, y, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13707
13675
  // apply local transformation
13708
13676
  return new Point(transformed[0], transformed[1]);
@@ -13727,11 +13695,9 @@ var Polyline = /** @class */ (function (_super) {
13727
13695
 
13728
13696
  var Rect = /** @class */ (function (_super) {
13729
13697
  __extends(Rect, _super);
13730
- function Rect(_a) {
13731
- if (_a === void 0) { _a = {}; }
13732
- var style = _a.style, rest = __rest(_a, ["style"]);
13733
- return _super.call(this, __assign({ type: Shape.RECT, style: runtime.enableCSSParsing
13734
- ? __assign({ x: '', y: '', width: '', height: '', radius: '' }, style) : __assign({}, style) }, rest)) || this;
13698
+ function Rect(options) {
13699
+ if (options === void 0) { options = {}; }
13700
+ return _super.call(this, __assign({ type: Shape.RECT }, options)) || this;
13735
13701
  }
13736
13702
  return Rect;
13737
13703
  }(DisplayObject));
@@ -13753,26 +13719,7 @@ var Text = /** @class */ (function (_super) {
13753
13719
  return _super.call(this, __assign({ type: Shape.TEXT, style: runtime.enableCSSParsing
13754
13720
  ? __assign({ x: '', y: '', text: '', fontSize: '', fontFamily: '', fontStyle: '', fontWeight: '', fontVariant: '', textAlign: '', textBaseline: '', textTransform: '', fill: 'black', letterSpacing: '', lineHeight: '', miterLimit: '',
13755
13721
  // whiteSpace: 'pre',
13756
- wordWrap: false, wordWrapWidth: 0, leading: 0, dx: '', dy: '' }, style) : __assign({ fill: 'black' }, style), initialParsedStyle: runtime.enableCSSParsing
13757
- ? {}
13758
- : {
13759
- x: 0,
13760
- y: 0,
13761
- fontSize: 16,
13762
- fontFamily: 'sans-serif',
13763
- fontStyle: 'normal',
13764
- fontWeight: 'normal',
13765
- fontVariant: 'normal',
13766
- lineHeight: 0,
13767
- letterSpacing: 0,
13768
- textBaseline: 'alphabetic',
13769
- textAlign: 'start',
13770
- wordWrap: false,
13771
- wordWrapWidth: 0,
13772
- leading: 0,
13773
- dx: 0,
13774
- dy: 0,
13775
- } }, rest)) || this;
13722
+ wordWrap: false, wordWrapWidth: 0, leading: 0, dx: '', dy: '' }, style) : __assign({ fill: 'black' }, style) }, rest)) || this;
13776
13723
  }
13777
13724
  // lengthAdjust: SVGAnimatedEnumeration;
13778
13725
  // textLength: SVGAnimatedLength;
@@ -13849,6 +13796,109 @@ var CustomElementRegistry = /** @class */ (function () {
13849
13796
  return CustomElementRegistry;
13850
13797
  }());
13851
13798
 
13799
+ /**
13800
+ * holds useful CSS-related methods.
13801
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS
13802
+ *
13803
+ * * CSS Typed OM @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/factory_functions
13804
+ * * register property @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty
13805
+ * * CSS Layout API
13806
+ */
13807
+ var CSS = {
13808
+ /**
13809
+ * <number>
13810
+ * @see https://drafts.csswg.org/css-values-4/#number-value
13811
+ */
13812
+ number: function (n) {
13813
+ return new CSSUnitValue(n);
13814
+ },
13815
+ /**
13816
+ * <percentage>
13817
+ * @see https://drafts.csswg.org/css-values-4/#percentage-value
13818
+ */
13819
+ percent: function (n) {
13820
+ return new CSSUnitValue(n, '%');
13821
+ },
13822
+ /**
13823
+ * <length>
13824
+ */
13825
+ px: function (n) {
13826
+ return new CSSUnitValue(n, 'px');
13827
+ },
13828
+ /**
13829
+ * <length>
13830
+ */
13831
+ em: function (n) {
13832
+ return new CSSUnitValue(n, 'em');
13833
+ },
13834
+ rem: function (n) {
13835
+ return new CSSUnitValue(n, 'rem');
13836
+ },
13837
+ /**
13838
+ * <angle>
13839
+ */
13840
+ deg: function (n) {
13841
+ return new CSSUnitValue(n, 'deg');
13842
+ },
13843
+ /**
13844
+ * <angle>
13845
+ */
13846
+ grad: function (n) {
13847
+ return new CSSUnitValue(n, 'grad');
13848
+ },
13849
+ /**
13850
+ * <angle>
13851
+ */
13852
+ rad: function (n) {
13853
+ return new CSSUnitValue(n, 'rad');
13854
+ },
13855
+ /**
13856
+ * <angle>
13857
+ */
13858
+ turn: function (n) {
13859
+ return new CSSUnitValue(n, 'turn');
13860
+ },
13861
+ /**
13862
+ * <time>
13863
+ */
13864
+ s: function (n) {
13865
+ return new CSSUnitValue(n, 's');
13866
+ },
13867
+ /**
13868
+ * <time>
13869
+ */
13870
+ ms: function (n) {
13871
+ return new CSSUnitValue(n, 'ms');
13872
+ },
13873
+ /**
13874
+ * CSS Properties & Values API
13875
+ *
13876
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS_Properties_and_Values_API
13877
+ * @see https://drafts.css-houdini.org/css-properties-values-api/#registering-custom-properties
13878
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CSS/RegisterProperty
13879
+ */
13880
+ registerProperty: function (definition) {
13881
+ var name = definition.name, inherits = definition.inherits, interpolable = definition.interpolable, initialValue = definition.initialValue, syntax = definition.syntax;
13882
+ runtime.styleValueRegistry.registerMetadata({
13883
+ n: name,
13884
+ inh: inherits,
13885
+ int: interpolable,
13886
+ d: initialValue,
13887
+ syntax: syntax,
13888
+ });
13889
+ },
13890
+ /**
13891
+ * CSS Layout API
13892
+ * register layout
13893
+ *
13894
+ * @see https://github.com/w3c/css-houdini-drafts/blob/main/css-layout-api/EXPLAINER.md
13895
+ * @see https://developer.mozilla.org/en-US/docs/Web/Guide/Houdini#css_layout_api
13896
+ */
13897
+ registerLayout: function (name, clazz) {
13898
+ runtime.layoutRegistry.registerLayout(name, clazz);
13899
+ },
13900
+ };
13901
+
13852
13902
  /**
13853
13903
  * the entry of DOM tree
13854
13904
  * Document -> Node -> EventTarget
@@ -13960,7 +14010,7 @@ var Document = /** @class */ (function (_super) {
13960
14010
  var hitTestList = [];
13961
14011
  rBushNodes.forEach(function (_a) {
13962
14012
  var displayObject = _a.displayObject;
13963
- var pointerEvents = displayObject.parsedStyle.pointerEvents;
14013
+ var _b = displayObject.parsedStyle.pointerEvents, pointerEvents = _b === void 0 ? 'auto' : _b;
13964
14014
  // account for `visibility`
13965
14015
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
13966
14016
  var isVisibilityAffected = [
@@ -14362,21 +14412,8 @@ var EventPlugin = /** @class */ (function () {
14362
14412
  return;
14363
14413
  // account for element in SVG
14364
14414
  var $element = _this.context.contextService.getDomElement();
14365
- var outside = 'outside';
14366
- try {
14367
- outside =
14368
- $element &&
14369
- nativeEvent.target &&
14370
- nativeEvent.target !== $element &&
14371
- $element.contains &&
14372
- !$element.contains(nativeEvent.target)
14373
- ? 'outside'
14374
- : '';
14375
- }
14376
- catch (e) {
14377
- // nativeEvent.target maybe not Node, such as Window
14378
- // @see https://github.com/antvis/G/issues/1235
14379
- }
14415
+ var isNativeEventFromCanvas = _this.context.eventService.isNativeEventFromCanvas($element, nativeEvent);
14416
+ var outside = !isNativeEventFromCanvas ? 'outside' : '';
14380
14417
  var normalizedEvents = _this.normalizeToPointerEvent(nativeEvent, canvas);
14381
14418
  try {
14382
14419
  for (var normalizedEvents_3 = __values(normalizedEvents), normalizedEvents_3_1 = normalizedEvents_3.next(); !normalizedEvents_3_1.done; normalizedEvents_3_1 = normalizedEvents_3.next()) {
@@ -14689,11 +14726,13 @@ var PrepareRendererPlugin = /** @class */ (function () {
14689
14726
  * sync to RBush later
14690
14727
  */
14691
14728
  this.toSync = new Set();
14729
+ this.isFirstTimeRendering = true;
14730
+ this.syncing = false;
14731
+ this.isFirstTimeRenderingFinished = false;
14692
14732
  }
14693
- // private isFirstTimeRendering = true;
14694
- // private syncing = false;
14695
14733
  PrepareRendererPlugin.prototype.apply = function (context) {
14696
14734
  var _this = this;
14735
+ var _a;
14697
14736
  var renderingService = context.renderingService, renderingContext = context.renderingContext, rBushRoot = context.rBushRoot;
14698
14737
  var canvas = renderingContext.root.ownerDocument.defaultView;
14699
14738
  this.rBush = rBushRoot;
@@ -14722,6 +14761,9 @@ var PrepareRendererPlugin = /** @class */ (function () {
14722
14761
  };
14723
14762
  var handleMounted = function (e) {
14724
14763
  var object = e.target;
14764
+ if (runtime.enableSizeAttenuation) {
14765
+ runtime.styleValueRegistry.updateSizeAttenuation(object, canvas.getCamera().getZoom());
14766
+ }
14725
14767
  if (runtime.enableCSSParsing) {
14726
14768
  // recalc style values
14727
14769
  runtime.styleValueRegistry.recalc(object);
@@ -14752,26 +14794,28 @@ var PrepareRendererPlugin = /** @class */ (function () {
14752
14794
  canvas.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
14753
14795
  _this.toSync.clear();
14754
14796
  });
14797
+ var ric = (_a = runtime.globalThis.requestIdleCallback) !== null && _a !== void 0 ? _a : raf.bind(runtime.globalThis);
14755
14798
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
14756
- // if (this.isFirstTimeRendering) {
14757
- // this.isFirstTimeRendering = false;
14758
- // this.syncing = true;
14759
- // // @see https://github.com/antvis/G/issues/1117
14760
- // setTimeout(() => {
14761
- // this.syncRTree();
14762
- // console.log('fcp...');
14763
- // });
14764
- // } else {
14765
- // console.log('next...');
14766
- _this.syncRTree();
14767
- // }
14799
+ if (_this.isFirstTimeRendering) {
14800
+ _this.isFirstTimeRendering = false;
14801
+ _this.syncing = true;
14802
+ ric(function () {
14803
+ _this.syncRTree(true);
14804
+ _this.isFirstTimeRenderingFinished = true;
14805
+ });
14806
+ }
14807
+ else {
14808
+ _this.syncRTree();
14809
+ }
14768
14810
  });
14769
14811
  };
14770
- PrepareRendererPlugin.prototype.syncRTree = function () {
14771
- // if (this.syncing) {
14772
- // return;
14773
- // }
14812
+ PrepareRendererPlugin.prototype.syncRTree = function (force) {
14774
14813
  var _this = this;
14814
+ if (force === void 0) { force = false; }
14815
+ if (!force && (this.syncing || this.toSync.size === 0)) {
14816
+ return;
14817
+ }
14818
+ this.syncing = true;
14775
14819
  // bounds changed, need re-inserting its children
14776
14820
  var bulk = [];
14777
14821
  Array.from(this.toSync)
@@ -14785,6 +14829,14 @@ var PrepareRendererPlugin = /** @class */ (function () {
14785
14829
  }
14786
14830
  var renderBounds = node.getRenderBounds();
14787
14831
  if (renderBounds) {
14832
+ var renderable = node.renderable;
14833
+ if (force) {
14834
+ if (!renderable.dirtyRenderBounds) {
14835
+ renderable.dirtyRenderBounds = new AABB();
14836
+ }
14837
+ // save last dirty aabb
14838
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
14839
+ }
14788
14840
  var _a = __read(renderBounds.getMin(), 2), minX = _a[0], minY = _a[1];
14789
14841
  var _b = __read(renderBounds.getMax(), 2), maxX = _b[0], maxY = _b[1];
14790
14842
  if (!rBushNode.aabb) {
@@ -14811,7 +14863,7 @@ var PrepareRendererPlugin = /** @class */ (function () {
14811
14863
  this.rBush.load(bulk);
14812
14864
  bulk.length = 0;
14813
14865
  this.toSync.clear();
14814
- // this.syncing = false;
14866
+ this.syncing = false;
14815
14867
  };
14816
14868
  PrepareRendererPlugin.tag = 'Prepare';
14817
14869
  return PrepareRendererPlugin;
@@ -14964,10 +15016,20 @@ var Canvas = /** @class */ (function (_super) {
14964
15016
  // redraw when camera changed
14965
15017
  camera.eventEmitter.on(CameraEvent.UPDATED, function () {
14966
15018
  _this.context.renderingContext.renderReasons.add(RenderReason.CAMERA_CHANGED);
15019
+ if (runtime.enableSizeAttenuation &&
15020
+ _this.getConfig().renderer.getConfig().enableSizeAttenuation) {
15021
+ _this.updateSizeAttenuation();
15022
+ }
14967
15023
  });
14968
15024
  // bind camera
14969
15025
  this.context.camera = camera;
14970
15026
  };
15027
+ Canvas.prototype.updateSizeAttenuation = function () {
15028
+ var zoom = this.getCamera().getZoom();
15029
+ this.document.documentElement.forEach(function (node) {
15030
+ runtime.styleValueRegistry.updateSizeAttenuation(node, zoom);
15031
+ });
15032
+ };
14971
15033
  Canvas.prototype.getConfig = function () {
14972
15034
  return this.context.config;
14973
15035
  };
@@ -15318,5 +15380,5 @@ var Canvas = /** @class */ (function (_super) {
15318
15380
  return Canvas;
15319
15381
  }(EventTarget));
15320
15382
 
15321
- 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, 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 };
15383
+ 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 };
15322
15384
  //# sourceMappingURL=index.esm.js.map