@antv/g-lite 1.2.21 → 1.3.0-next.1

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
@@ -3548,7 +3548,7 @@ var parseGradient$1 = (function () {
3548
3548
  return getAST();
3549
3549
  };
3550
3550
  })();
3551
- function computeLinearGradient(width, height, angle) {
3551
+ function computeLinearGradient(min, width, height, angle) {
3552
3552
  var rad = deg2rad(angle.value);
3553
3553
  var rx = 0;
3554
3554
  var ry = 0;
@@ -3557,13 +3557,13 @@ function computeLinearGradient(width, height, angle) {
3557
3557
  // get the length of gradient line
3558
3558
  // @see https://observablehq.com/@danburzo/css-gradient-line
3559
3559
  var length = Math.abs(width * Math.cos(rad)) + Math.abs(height * Math.sin(rad));
3560
- var x1 = rcx - (Math.cos(rad) * length) / 2;
3561
- var y1 = rcy - (Math.sin(rad) * length) / 2;
3562
- var x2 = rcx + (Math.cos(rad) * length) / 2;
3563
- var y2 = rcy + (Math.sin(rad) * length) / 2;
3560
+ var x1 = min[0] + rcx - (Math.cos(rad) * length) / 2;
3561
+ var y1 = min[1] + rcy - (Math.sin(rad) * length) / 2;
3562
+ var x2 = min[0] + rcx + (Math.cos(rad) * length) / 2;
3563
+ var y2 = min[1] + rcy + (Math.sin(rad) * length) / 2;
3564
3564
  return { x1: x1, y1: y1, x2: x2, y2: y2 };
3565
3565
  }
3566
- function computeRadialGradient(width, height, cx, cy, size) {
3566
+ function computeRadialGradient(min, width, height, cx, cy, size) {
3567
3567
  // 'px'
3568
3568
  var x = cx.value;
3569
3569
  var y = cy.value;
@@ -3594,7 +3594,7 @@ function computeRadialGradient(width, height, cx, cy, size) {
3594
3594
  }
3595
3595
  }
3596
3596
  }
3597
- return { x: x, y: y, r: r };
3597
+ return { x: x + min[0], y: y + min[1], r: r };
3598
3598
  }
3599
3599
 
3600
3600
  var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
@@ -4791,11 +4791,10 @@ function getArcParams(startPoint, params) {
4791
4791
  };
4792
4792
  }
4793
4793
  function commandsToPathString(commands, object, transform) {
4794
- var _a = object.parsedStyle, _b = _a.defX, defX = _b === void 0 ? 0 : _b, _c = _a.defY, defY = _c === void 0 ? 0 : _c;
4795
4794
  return commands.reduce(function (prev, cur) {
4796
4795
  var path = '';
4797
4796
  if (cur[0] === 'M' || cur[0] === 'L') {
4798
- var p = vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
4797
+ var p = vec3.fromValues(cur[1], cur[2], 0);
4799
4798
  if (transform) {
4800
4799
  vec3.transformMat4(p, p, transform);
4801
4800
  }
@@ -4805,9 +4804,9 @@ function commandsToPathString(commands, object, transform) {
4805
4804
  path = cur[0];
4806
4805
  }
4807
4806
  else if (cur[0] === 'C') {
4808
- var p1 = vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
4809
- var p2 = vec3.fromValues(cur[3] - defX, cur[4] - defY, 0);
4810
- var p3 = vec3.fromValues(cur[5] - defX, cur[6] - defY, 0);
4807
+ var p1 = vec3.fromValues(cur[1], cur[2], 0);
4808
+ var p2 = vec3.fromValues(cur[3], cur[4], 0);
4809
+ var p3 = vec3.fromValues(cur[5], cur[6], 0);
4811
4810
  if (transform) {
4812
4811
  vec3.transformMat4(p1, p1, transform);
4813
4812
  vec3.transformMat4(p2, p2, transform);
@@ -4816,15 +4815,15 @@ function commandsToPathString(commands, object, transform) {
4816
4815
  path = "".concat(cur[0]).concat(p1[0], ",").concat(p1[1], ",").concat(p2[0], ",").concat(p2[1], ",").concat(p3[0], ",").concat(p3[1]);
4817
4816
  }
4818
4817
  else if (cur[0] === 'A') {
4819
- var c = vec3.fromValues(cur[6] - defX, cur[7] - defY, 0);
4818
+ var c = vec3.fromValues(cur[6], cur[7], 0);
4820
4819
  if (transform) {
4821
4820
  vec3.transformMat4(c, c, transform);
4822
4821
  }
4823
4822
  path = "".concat(cur[0]).concat(cur[1], ",").concat(cur[2], ",").concat(cur[3], ",").concat(cur[4], ",").concat(cur[5], ",").concat(c[0], ",").concat(c[1]);
4824
4823
  }
4825
4824
  else if (cur[0] === 'Q') {
4826
- var p1 = vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
4827
- var p2 = vec3.fromValues(cur[3] - defX, cur[4] - defY, 0);
4825
+ var p1 = vec3.fromValues(cur[1], cur[2], 0);
4826
+ var p2 = vec3.fromValues(cur[3], cur[4], 0);
4828
4827
  if (transform) {
4829
4828
  vec3.transformMat4(p1, p1, transform);
4830
4829
  vec3.transformMat4(p2, p2, transform);
@@ -4902,7 +4901,6 @@ function rectToCommands(width, height, x, y, radius) {
4902
4901
  /**
4903
4902
  * convert object to path, should account for:
4904
4903
  * * transform & origin
4905
- * * anchor
4906
4904
  * * lineWidth
4907
4905
  */
4908
4906
  function convertToPath(object, transform) {
@@ -4945,7 +4943,7 @@ function convertToPath(object, transform) {
4945
4943
  return commandsToPathString(commands, object, transform);
4946
4944
  }
4947
4945
  }
4948
- function translatePathToString(absolutePath, defX, defY, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
4946
+ function translatePathToString(absolutePath, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
4949
4947
  if (startOffsetX === void 0) { startOffsetX = 0; }
4950
4948
  if (startOffsetY === void 0) { startOffsetY = 0; }
4951
4949
  if (endOffsetX === void 0) { endOffsetX = 0; }
@@ -4964,27 +4962,27 @@ function translatePathToString(absolutePath, defX, defY, startOffsetX, startOffs
4964
4962
  case 'M':
4965
4963
  // Use start marker offset
4966
4964
  if (useStartOffset) {
4967
- return "M ".concat(params[1] - defX + startOffsetX, ",").concat(params[2] - defY + startOffsetY, " L ").concat(params[1] - defX, ",").concat(params[2] - defY);
4965
+ return "M ".concat(params[1] + startOffsetX, ",").concat(params[2] + startOffsetY, " L ").concat(params[1], ",").concat(params[2]);
4968
4966
  }
4969
4967
  else {
4970
- return "M ".concat(params[1] - defX, ",").concat(params[2] - defY);
4968
+ return "M ".concat(params[1], ",").concat(params[2]);
4971
4969
  }
4972
4970
  case 'L':
4973
- return "L ".concat(params[1] - defX + (useEndOffset ? endOffsetX : 0), ",").concat(params[2] - defY + (useEndOffset ? endOffsetY : 0));
4971
+ return "L ".concat(params[1] + (useEndOffset ? endOffsetX : 0), ",").concat(params[2] + (useEndOffset ? endOffsetY : 0));
4974
4972
  case 'Q':
4975
- return ("Q ".concat(params[1] - defX, " ").concat(params[2] - defY, ",").concat(params[3] - defX, " ").concat(params[4] - defY) +
4973
+ return ("Q ".concat(params[1], " ").concat(params[2], ",").concat(params[3], " ").concat(params[4]) +
4976
4974
  (useEndOffset
4977
- ? " L ".concat(params[3] - defX + endOffsetX, ",").concat(params[4] - defY + endOffsetY)
4975
+ ? " L ".concat(params[3] + endOffsetX, ",").concat(params[4] + endOffsetY)
4978
4976
  : ''));
4979
4977
  case 'C':
4980
- return ("C ".concat(params[1] - defX, " ").concat(params[2] - defY, ",").concat(params[3] - defX, " ").concat(params[4] - defY, ",").concat(params[5] - defX, " ").concat(params[6] - defY) +
4978
+ return ("C ".concat(params[1], " ").concat(params[2], ",").concat(params[3], " ").concat(params[4], ",").concat(params[5], " ").concat(params[6]) +
4981
4979
  (useEndOffset
4982
- ? " L ".concat(params[5] - defX + endOffsetX, ",").concat(params[6] - defY + endOffsetY)
4980
+ ? " L ".concat(params[5] + endOffsetX, ",").concat(params[6] + endOffsetY)
4983
4981
  : ''));
4984
4982
  case 'A':
4985
- return ("A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6] - defX, " ").concat(params[7] - defY) +
4983
+ return ("A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6], " ").concat(params[7]) +
4986
4984
  (useEndOffset
4987
- ? " L ".concat(params[6] - defX + endOffsetX, ",").concat(params[7] - defY + endOffsetY)
4985
+ ? " L ".concat(params[6] + endOffsetX, ",").concat(params[7] + endOffsetY)
4988
4986
  : ''));
4989
4987
  case 'Z':
4990
4988
  return 'Z';
@@ -5114,12 +5112,8 @@ function parsePoints(pointsOrStr, object) {
5114
5112
  segments.push(segmentT);
5115
5113
  }
5116
5114
  });
5117
- var minX = Math.min.apply(Math, __spreadArray([], __read(points.map(function (point) { return point[0]; })), false));
5118
- var minY = Math.min.apply(Math, __spreadArray([], __read(points.map(function (point) { return point[1]; })), false));
5119
- if (object) {
5120
- object.parsedStyle.defX = minX;
5121
- object.parsedStyle.defY = minY;
5122
- }
5115
+ // const minX = Math.min(...points.map((point) => point[0]));
5116
+ // const minY = Math.min(...points.map((point) => point[1]));
5123
5117
  return {
5124
5118
  points: points,
5125
5119
  totalLength: totalLength,
@@ -6245,34 +6239,24 @@ var BUILT_IN_PROPERTIES = [
6245
6239
  l: true,
6246
6240
  syntax: PropertySyntax.TRANSFORM_ORIGIN,
6247
6241
  },
6248
- {
6249
- n: 'anchor',
6250
- p: 99,
6251
- d: function (nodeName) {
6252
- if (nodeName === Shape.CIRCLE || nodeName === Shape.ELLIPSE) {
6253
- return '0.5 0.5';
6254
- }
6255
- return '0 0';
6256
- },
6257
- l: true,
6258
- syntax: PropertySyntax.LENGTH_PERCENTAGE_12,
6259
- },
6260
- // <circle> & <ellipse>
6261
6242
  {
6262
6243
  n: 'cx',
6263
6244
  int: true,
6245
+ l: true,
6264
6246
  d: '0',
6265
6247
  syntax: PropertySyntax.COORDINATE,
6266
6248
  },
6267
6249
  {
6268
6250
  n: 'cy',
6269
6251
  int: true,
6252
+ l: true,
6270
6253
  d: '0',
6271
6254
  syntax: PropertySyntax.COORDINATE,
6272
6255
  },
6273
6256
  {
6274
6257
  n: 'cz',
6275
6258
  int: true,
6259
+ l: true,
6276
6260
  d: '0',
6277
6261
  syntax: PropertySyntax.COORDINATE,
6278
6262
  },
@@ -6302,6 +6286,7 @@ var BUILT_IN_PROPERTIES = [
6302
6286
  // x in local space
6303
6287
  n: 'x',
6304
6288
  int: true,
6289
+ l: true,
6305
6290
  d: '0',
6306
6291
  syntax: PropertySyntax.COORDINATE,
6307
6292
  },
@@ -6309,6 +6294,7 @@ var BUILT_IN_PROPERTIES = [
6309
6294
  // y in local space
6310
6295
  n: 'y',
6311
6296
  int: true,
6297
+ l: true,
6312
6298
  d: '0',
6313
6299
  syntax: PropertySyntax.COORDINATE,
6314
6300
  },
@@ -6316,6 +6302,7 @@ var BUILT_IN_PROPERTIES = [
6316
6302
  // z in local space
6317
6303
  n: 'z',
6318
6304
  int: true,
6305
+ l: true,
6319
6306
  d: '0',
6320
6307
  syntax: PropertySyntax.COORDINATE,
6321
6308
  },
@@ -6656,7 +6643,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6656
6643
  // @ts-ignore
6657
6644
  if (attributes.points) {
6658
6645
  // @ts-ignore
6659
- object.parsedStyle.points = parsePoints(attributes.points, object);
6646
+ object.parsedStyle.points = parsePoints(attributes.points);
6660
6647
  }
6661
6648
  // Path
6662
6649
  // @ts-ignore
@@ -6668,8 +6655,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6668
6655
  object.parsedStyle.path = parsePath(
6669
6656
  // @ts-ignore
6670
6657
  attributes.path);
6671
- object.parsedStyle.defX = object.parsedStyle.path.rect.x;
6672
- object.parsedStyle.defY = object.parsedStyle.path.rect.y;
6673
6658
  }
6674
6659
  // Text
6675
6660
  if (attributes.textTransform) {
@@ -6681,11 +6666,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6681
6666
  if (attributes.offsetPath) {
6682
6667
  this.runtime.CSSPropertySyntaxFactory['<defined-path>'].calculator('offsetPath', oldOffsetPath, attributes.offsetPath, object, this.runtime);
6683
6668
  }
6684
- if (attributes.anchor) {
6685
- object.parsedStyle.anchor = parseDimensionArrayFormat(
6686
- // @ts-ignorex
6687
- attributes.anchor, 2);
6688
- }
6689
6669
  if (attributes.transform) {
6690
6670
  object.parsedStyle.transform = parseTransform(attributes.transform);
6691
6671
  }
@@ -6717,53 +6697,9 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6717
6697
  // @ts-ignore
6718
6698
  attributes.markerMid, null, null);
6719
6699
  }
6720
- if (
6721
- // Circle & Ellipse
6722
- ((object.nodeName === Shape.CIRCLE ||
6723
- object.nodeName === Shape.ELLIPSE) &&
6724
- // @ts-ignore
6725
- (!isNil(attributes.cx) ||
6726
- // @ts-ignore
6727
- !isNil(attributes.cy))) ||
6728
- ((object.nodeName === Shape.RECT ||
6729
- object.nodeName === Shape.IMAGE ||
6730
- object.nodeName === Shape.GROUP ||
6731
- object.nodeName === Shape.HTML ||
6732
- object.nodeName === Shape.TEXT ||
6733
- object.nodeName === Shape.MESH) &&
6734
- // @ts-ignore
6735
- (!isNil(attributes.x) ||
6736
- // @ts-ignore
6737
- !isNil(attributes.y) ||
6738
- // @ts-ignore
6739
- !isNil(attributes.z))) ||
6740
- // Line
6741
- (object.nodeName === Shape.LINE &&
6742
- // @ts-ignore
6743
- (!isNil(attributes.x1) ||
6744
- // @ts-ignore
6745
- !isNil(attributes.y1) ||
6746
- // @ts-ignore
6747
- !isNil(attributes.z1) ||
6748
- // @ts-ignore
6749
- !isNil(attributes.x2) ||
6750
- // @ts-ignore
6751
- !isNil(attributes.y2) ||
6752
- // @ts-ignore
6753
- !isNil(attributes.z2)))) {
6754
- this.runtime.CSSPropertySyntaxFactory['<coordinate>'].postProcessor(object, attributeNames_1);
6755
- }
6756
6700
  if (!isNil(attributes.zIndex)) {
6757
6701
  this.runtime.CSSPropertySyntaxFactory['<z-index>'].postProcessor(object, attributeNames_1);
6758
6702
  }
6759
- // @ts-ignore
6760
- if (attributes.path) {
6761
- this.runtime.CSSPropertySyntaxFactory['<path>'].postProcessor(object, attributeNames_1);
6762
- }
6763
- // @ts-ignore
6764
- if (attributes.points) {
6765
- this.runtime.CSSPropertySyntaxFactory['<list-of-points>'].postProcessor(object, attributeNames_1);
6766
- }
6767
6703
  if (!isNil(attributes.offsetDistance)) {
6768
6704
  this.runtime.CSSPropertySyntaxFactory['<offset-distance>'].postProcessor(object, attributeNames_1);
6769
6705
  }
@@ -6798,7 +6734,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6798
6734
  // points 50
6799
6735
  // text 50
6800
6736
  // textTransform 51
6801
- // anchor 99
6802
6737
  // transform 100
6803
6738
  // transformOrigin 100
6804
6739
  if (usedAttributes === null || usedAttributes === void 0 ? void 0 : usedAttributes.length) {
@@ -6810,7 +6745,6 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6810
6745
  // 'points',
6811
6746
  // 'text',
6812
6747
  // 'textTransform',
6813
- // 'anchor',
6814
6748
  // 'transform',
6815
6749
  // 'transformOrigin',
6816
6750
  // ].forEach((name) => {
@@ -7031,12 +6965,12 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7031
6965
  geometry_1.renderBounds = new AABB();
7032
6966
  }
7033
6967
  var parsedStyle = object.parsedStyle;
7034
- var _a = geometryUpdater.update(parsedStyle, object), width = _a.width, height = _a.height, _b = _a.depth, depth = _b === void 0 ? 0 : _b, _c = _a.offsetX, offsetX = _c === void 0 ? 0 : _c, _d = _a.offsetY, offsetY = _d === void 0 ? 0 : _d, _e = _a.offsetZ, offsetZ = _e === void 0 ? 0 : _e;
6968
+ var _a = geometryUpdater.update(parsedStyle, object), _b = _a.cx, cx = _b === void 0 ? 0 : _b, _c = _a.cy, cy = _c === void 0 ? 0 : _c, _d = _a.cz, cz = _d === void 0 ? 0 : _d, _e = _a.hwidth, hwidth = _e === void 0 ? 0 : _e, _f = _a.hheight, hheight = _f === void 0 ? 0 : _f, _g = _a.hdepth, hdepth = _g === void 0 ? 0 : _g;
7035
6969
  // init with content box
7036
6970
  var halfExtents = [
7037
- Math.abs(width) / 2,
7038
- Math.abs(height) / 2,
7039
- depth / 2,
6971
+ Math.abs(hwidth),
6972
+ Math.abs(hheight),
6973
+ hdepth,
7040
6974
  ];
7041
6975
  // const halfExtents = vec3.set(
7042
6976
  // tmpVec3a,
@@ -7045,30 +6979,12 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7045
6979
  // depth / 2,
7046
6980
  // );
7047
6981
  // anchor is center by default, don't account for lineWidth here
7048
- var _f = parsedStyle, stroke = _f.stroke, lineWidth = _f.lineWidth,
6982
+ var _h = parsedStyle, stroke = _h.stroke, lineWidth = _h.lineWidth,
7049
6983
  // lineCap,
7050
6984
  // lineJoin,
7051
6985
  // miterLimit,
7052
- increasedLineWidthForHitTesting = _f.increasedLineWidthForHitTesting, shadowType = _f.shadowType, shadowColor = _f.shadowColor, _g = _f.filter, filter = _g === void 0 ? [] : _g, transformOrigin = _f.transformOrigin;
7053
- var anchor = parsedStyle.anchor;
7054
- // <Text> use textAlign & textBaseline instead of anchor
7055
- if (nodeName === Shape.TEXT) {
7056
- delete parsedStyle.anchor;
7057
- }
7058
- else if (nodeName === Shape.MESH) {
7059
- parsedStyle.anchor[2] = 0.5;
7060
- }
7061
- var center = [
7062
- ((1 - ((anchor && anchor[0]) || 0) * 2) * width) / 2 + offsetX,
7063
- ((1 - ((anchor && anchor[1]) || 0) * 2) * height) / 2 + offsetY,
7064
- (1 - ((anchor && anchor[2]) || 0) * 2) * halfExtents[2] + offsetZ,
7065
- ];
7066
- // const center = vec3.set(
7067
- // tmpVec3b,
7068
- // ((1 - ((anchor && anchor[0]) || 0) * 2) * width) / 2 + offsetX,
7069
- // ((1 - ((anchor && anchor[1]) || 0) * 2) * height) / 2 + offsetY,
7070
- // (1 - ((anchor && anchor[2]) || 0) * 2) * halfExtents[2] + offsetZ,
7071
- // );
6986
+ increasedLineWidthForHitTesting = _h.increasedLineWidthForHitTesting, shadowType = _h.shadowType, shadowColor = _h.shadowColor, _j = _h.filter, filter = _j === void 0 ? [] : _j, transformOrigin = _h.transformOrigin;
6987
+ var center = [cx, cy, cz];
7072
6988
  // update geometry's AABB
7073
6989
  geometry_1.contentBounds.update(center, halfExtents);
7074
6990
  // @see https://github.molgen.mpg.de/git-mirror/cairo/blob/master/src/cairo-stroke-style.c#L97..L128
@@ -7101,8 +7017,8 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7101
7017
  geometry_1.renderBounds.update(center, halfExtents);
7102
7018
  // account for shadow, only support constant value now
7103
7019
  if (shadowColor && shadowType && shadowType !== 'inner') {
7104
- var _h = geometry_1.renderBounds, min = _h.min, max = _h.max;
7105
- var _j = parsedStyle, shadowBlur = _j.shadowBlur, shadowOffsetX = _j.shadowOffsetX, shadowOffsetY = _j.shadowOffsetY;
7020
+ var _k = geometry_1.renderBounds, min = _k.min, max = _k.max;
7021
+ var _l = parsedStyle, shadowBlur = _l.shadowBlur, shadowOffsetX = _l.shadowOffsetX, shadowOffsetY = _l.shadowOffsetY;
7106
7022
  var shadowBlurInPixels = shadowBlur || 0;
7107
7023
  var shadowOffsetXInPixels = shadowOffsetX || 0;
7108
7024
  var shadowOffsetYInPixels = shadowOffsetY || 0;
@@ -7139,12 +7055,11 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7139
7055
  geometry_1.renderBounds.setMinMax(min, max);
7140
7056
  }
7141
7057
  });
7142
- anchor = parsedStyle.anchor;
7143
7058
  // if (nodeName === Shape.RECT) {
7144
7059
  // account for negative width / height of Rect
7145
7060
  // @see https://github.com/antvis/g/issues/957
7146
- var flipY = width < 0;
7147
- var flipX = height < 0;
7061
+ var flipY = hwidth < 0;
7062
+ var flipX = hheight < 0;
7148
7063
  // } else {
7149
7064
  // }
7150
7065
  // set transform origin
@@ -7156,19 +7071,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7156
7071
  (transformOrigin
7157
7072
  ? convertPercentUnit(transformOrigin[1], 1, object)
7158
7073
  : 0);
7159
- usedOriginXValue =
7160
- usedOriginXValue -
7161
- (flipY ? -1 : 1) *
7162
- ((anchor && anchor[0]) || 0) *
7163
- geometry_1.contentBounds.halfExtents[0] *
7164
- 2;
7165
- usedOriginYValue =
7166
- usedOriginYValue -
7167
- (flipX ? -1 : 1) *
7168
- ((anchor && anchor[1]) || 0) *
7169
- geometry_1.contentBounds.halfExtents[1] *
7170
- 2;
7171
- object.setOrigin(usedOriginXValue, usedOriginYValue);
7074
+ object.setOrigin(cx - hwidth + usedOriginXValue, cy - hheight + usedOriginYValue);
7172
7075
  // FIXME setOrigin may have already dirtified to root.
7173
7076
  this.runtime.sceneGraphService.dirtifyToRoot(object);
7174
7077
  }
@@ -7390,177 +7293,6 @@ var CSSPropertyLengthOrPercentage14 = /** @class */ (function () {
7390
7293
  return CSSPropertyLengthOrPercentage14;
7391
7294
  }());
7392
7295
 
7393
- var tmpMat4 = mat4.create();
7394
- function parsedTransformToMat4(transform, object) {
7395
- var defX = object.parsedStyle.defX || 0;
7396
- var defY = object.parsedStyle.defY || 0;
7397
- // reset transform
7398
- object.resetLocalTransform();
7399
- object.setLocalPosition(defX, defY);
7400
- transform.forEach(function (parsed) {
7401
- var t = parsed.t, d = parsed.d;
7402
- if (t === 'scale') {
7403
- // scale(1) scale(1, 1)
7404
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1, 1];
7405
- object.scaleLocal(newScale[0], newScale[1], 1);
7406
- }
7407
- else if (t === 'scalex') {
7408
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7409
- object.scaleLocal(newScale[0], 1, 1);
7410
- }
7411
- else if (t === 'scaley') {
7412
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7413
- object.scaleLocal(1, newScale[0], 1);
7414
- }
7415
- else if (t === 'scalez') {
7416
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7417
- object.scaleLocal(1, 1, newScale[0]);
7418
- }
7419
- else if (t === 'scale3d') {
7420
- var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1, 1, 1];
7421
- object.scaleLocal(newScale[0], newScale[1], newScale[2]);
7422
- }
7423
- else if (t === 'translate') {
7424
- var newTranslation = d || [Opx, Opx];
7425
- object.translateLocal(newTranslation[0].value, newTranslation[1].value, 0);
7426
- }
7427
- else if (t === 'translatex') {
7428
- var newTranslation = d || [Opx];
7429
- object.translateLocal(newTranslation[0].value, 0, 0);
7430
- }
7431
- else if (t === 'translatey') {
7432
- var newTranslation = d || [Opx];
7433
- object.translateLocal(0, newTranslation[0].value, 0);
7434
- }
7435
- else if (t === 'translatez') {
7436
- var newTranslation = d || [Opx];
7437
- object.translateLocal(0, 0, newTranslation[0].value);
7438
- }
7439
- else if (t === 'translate3d') {
7440
- var newTranslation = d || [Opx, Opx, Opx];
7441
- object.translateLocal(newTranslation[0].value, newTranslation[1].value, newTranslation[2].value);
7442
- }
7443
- else if (t === 'rotate') {
7444
- var newAngles = d || [Odeg];
7445
- object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
7446
- }
7447
- else if (t === 'rotatex') {
7448
- var newAngles = d || [Odeg];
7449
- object.rotateLocal(convertAngleUnit(newAngles[0]), 0, 0);
7450
- }
7451
- else if (t === 'rotatey') {
7452
- var newAngles = d || [Odeg];
7453
- object.rotateLocal(0, convertAngleUnit(newAngles[0]), 0);
7454
- }
7455
- else if (t === 'rotatez') {
7456
- var newAngles = d || [Odeg];
7457
- object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
7458
- }
7459
- else if (t === 'rotate3d') ;
7460
- else if (t === 'skew') {
7461
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0, 0];
7462
- object.setLocalSkew(deg2rad(newSkew[0]), deg2rad(newSkew[1]));
7463
- }
7464
- else if (t === 'skewx') {
7465
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7466
- object.setLocalSkew(deg2rad(newSkew[0]), object.getLocalSkew()[1]);
7467
- }
7468
- else if (t === 'skewy') {
7469
- var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7470
- object.setLocalSkew(object.getLocalSkew()[0], deg2rad(newSkew[0]));
7471
- }
7472
- else if (t === 'matrix') {
7473
- var _a = __read(d.map(function (s) { return s.value; }), 6), a = _a[0], b = _a[1], c = _a[2], dd = _a[3], tx = _a[4], ty = _a[5];
7474
- object.setLocalTransform(mat4.set(tmpMat4, a, b, 0, 0, c, dd, 0, 0, 0, 0, 1, 0, tx + defX, ty + defY, 0, 1));
7475
- }
7476
- else if (t === 'matrix3d') {
7477
- // @ts-ignore
7478
- mat4.set.apply(mat4, __spreadArray([tmpMat4], __read(d.map(function (s) { return s.value; })), false));
7479
- tmpMat4[12] += defX;
7480
- tmpMat4[13] += defY;
7481
- object.setLocalTransform(tmpMat4);
7482
- }
7483
- });
7484
- return object.getLocalTransform();
7485
- }
7486
-
7487
- /**
7488
- * local position
7489
- */
7490
- var CSSPropertyLocalPosition = /** @class */ (function (_super) {
7491
- __extends(CSSPropertyLocalPosition, _super);
7492
- function CSSPropertyLocalPosition() {
7493
- return _super !== null && _super.apply(this, arguments) || this;
7494
- }
7495
- /**
7496
- * update local position
7497
- */
7498
- CSSPropertyLocalPosition.prototype.postProcessor = function (object, attributes) {
7499
- var x;
7500
- var y;
7501
- var z;
7502
- switch (object.nodeName) {
7503
- case Shape.CIRCLE:
7504
- case Shape.ELLIPSE:
7505
- var _a = object.parsedStyle, cx = _a.cx, cy = _a.cy, cz = _a.cz;
7506
- if (!isNil(cx)) {
7507
- x = cx;
7508
- }
7509
- if (!isNil(cy)) {
7510
- y = cy;
7511
- }
7512
- if (!isNil(cz)) {
7513
- z = cz;
7514
- }
7515
- break;
7516
- case Shape.LINE:
7517
- var _b = object.parsedStyle, x1 = _b.x1, x2 = _b.x2, y1 = _b.y1, y2 = _b.y2;
7518
- var minX = Math.min(x1, x2);
7519
- var minY = Math.min(y1, y2);
7520
- x = minX;
7521
- y = minY;
7522
- z = 0;
7523
- break;
7524
- case Shape.RECT:
7525
- case Shape.IMAGE:
7526
- case Shape.GROUP:
7527
- case Shape.HTML:
7528
- case Shape.TEXT:
7529
- case Shape.MESH:
7530
- if (!isNil(object.parsedStyle.x)) {
7531
- x = object.parsedStyle.x;
7532
- }
7533
- if (!isNil(object.parsedStyle.y)) {
7534
- y = object.parsedStyle.y;
7535
- }
7536
- if (!isNil(object.parsedStyle.z)) {
7537
- z = object.parsedStyle.z;
7538
- }
7539
- break;
7540
- }
7541
- if (object.nodeName !== Shape.PATH &&
7542
- object.nodeName !== Shape.POLYLINE &&
7543
- object.nodeName !== Shape.POLYGON) {
7544
- object.parsedStyle.defX = x || 0;
7545
- object.parsedStyle.defY = y || 0;
7546
- }
7547
- var needResetLocalPosition = !isNil(x) || !isNil(y) || !isNil(z);
7548
- // only if `transform` won't be processed later
7549
- if (needResetLocalPosition && attributes.indexOf('transform') === -1) {
7550
- // account for current transform if needed
7551
- var transform = object.parsedStyle.transform;
7552
- if (transform && transform.length) {
7553
- parsedTransformToMat4(transform, object);
7554
- }
7555
- else {
7556
- var _c = __read(object.getLocalPosition(), 3), ox = _c[0], oy = _c[1], oz = _c[2];
7557
- object.setLocalPosition(isNil(x) ? ox : x, isNil(y) ? oy : y, isNil(z) ? oz : z);
7558
- }
7559
- }
7560
- };
7561
- return CSSPropertyLocalPosition;
7562
- }(CSSPropertyLengthOrPercentage));
7563
-
7564
7296
  var CSSPropertyMarker = /** @class */ (function () {
7565
7297
  function CSSPropertyMarker() {
7566
7298
  }
@@ -7614,8 +7346,6 @@ var CSSPropertyOffsetDistance = /** @class */ (function () {
7614
7346
  // set position in world space
7615
7347
  var point = offsetPath.getPoint(offsetDistance);
7616
7348
  if (point) {
7617
- object.parsedStyle.defX = point.x;
7618
- object.parsedStyle.defY = point.y;
7619
7349
  object.setLocalPosition(point.x, point.y);
7620
7350
  }
7621
7351
  }
@@ -7664,18 +7394,6 @@ var CSSPropertyPath = /** @class */ (function () {
7664
7394
  }
7665
7395
  return parsed;
7666
7396
  };
7667
- /**
7668
- * update local position
7669
- */
7670
- CSSPropertyPath.prototype.postProcessor = function (object, attributes) {
7671
- object.parsedStyle.defX = object.parsedStyle.path.rect.x;
7672
- object.parsedStyle.defY = object.parsedStyle.path.rect.y;
7673
- if (object.nodeName === Shape.PATH &&
7674
- attributes.indexOf('transform') === -1) {
7675
- var _a = object.parsedStyle, _b = _a.defX, defX = _b === void 0 ? 0 : _b, _c = _a.defY, defY = _c === void 0 ? 0 : _c;
7676
- object.setLocalPosition(defX, defY);
7677
- }
7678
- };
7679
7397
  return CSSPropertyPath;
7680
7398
  }());
7681
7399
 
@@ -7684,17 +7402,6 @@ var CSSPropertyPoints = /** @class */ (function () {
7684
7402
  this.parser = parsePoints;
7685
7403
  this.mixer = mergePoints;
7686
7404
  }
7687
- /**
7688
- * update local position
7689
- */
7690
- CSSPropertyPoints.prototype.postProcessor = function (object, attributes) {
7691
- if ((object.nodeName === Shape.POLYGON ||
7692
- object.nodeName === Shape.POLYLINE) &&
7693
- attributes.indexOf('transform') === -1) {
7694
- var _a = object.parsedStyle, defX = _a.defX, defY = _a.defY;
7695
- object.setLocalPosition(defX, defY);
7696
- }
7697
- };
7698
7405
  return CSSPropertyPoints;
7699
7406
  }());
7700
7407
 
@@ -8103,6 +7810,95 @@ function toFontString(attributes) {
8103
7810
  return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSizeString, " ").concat(fontFamilies.join(','));
8104
7811
  }
8105
7812
 
7813
+ var tmpMat4 = mat4.create();
7814
+ function parsedTransformToMat4(transform, object) {
7815
+ // reset transform
7816
+ object.resetLocalTransform();
7817
+ transform.forEach(function (parsed) {
7818
+ var t = parsed.t, d = parsed.d;
7819
+ if (t === 'scale') {
7820
+ // scale(1) scale(1, 1)
7821
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1, 1];
7822
+ object.scaleLocal(newScale[0], newScale[1], 1);
7823
+ }
7824
+ else if (t === 'scalex') {
7825
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7826
+ object.scaleLocal(newScale[0], 1, 1);
7827
+ }
7828
+ else if (t === 'scaley') {
7829
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7830
+ object.scaleLocal(1, newScale[0], 1);
7831
+ }
7832
+ else if (t === 'scalez') {
7833
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1];
7834
+ object.scaleLocal(1, 1, newScale[0]);
7835
+ }
7836
+ else if (t === 'scale3d') {
7837
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [1, 1, 1];
7838
+ object.scaleLocal(newScale[0], newScale[1], newScale[2]);
7839
+ }
7840
+ else if (t === 'translate') {
7841
+ var newTranslation = d || [Opx, Opx];
7842
+ object.translateLocal(newTranslation[0].value, newTranslation[1].value, 0);
7843
+ }
7844
+ else if (t === 'translatex') {
7845
+ var newTranslation = d || [Opx];
7846
+ object.translateLocal(newTranslation[0].value, 0, 0);
7847
+ }
7848
+ else if (t === 'translatey') {
7849
+ var newTranslation = d || [Opx];
7850
+ object.translateLocal(0, newTranslation[0].value, 0);
7851
+ }
7852
+ else if (t === 'translatez') {
7853
+ var newTranslation = d || [Opx];
7854
+ object.translateLocal(0, 0, newTranslation[0].value);
7855
+ }
7856
+ else if (t === 'translate3d') {
7857
+ var newTranslation = d || [Opx, Opx, Opx];
7858
+ object.translateLocal(newTranslation[0].value, newTranslation[1].value, newTranslation[2].value);
7859
+ }
7860
+ else if (t === 'rotate') {
7861
+ var newAngles = d || [Odeg];
7862
+ object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
7863
+ }
7864
+ else if (t === 'rotatex') {
7865
+ var newAngles = d || [Odeg];
7866
+ object.rotateLocal(convertAngleUnit(newAngles[0]), 0, 0);
7867
+ }
7868
+ else if (t === 'rotatey') {
7869
+ var newAngles = d || [Odeg];
7870
+ object.rotateLocal(0, convertAngleUnit(newAngles[0]), 0);
7871
+ }
7872
+ else if (t === 'rotatez') {
7873
+ var newAngles = d || [Odeg];
7874
+ object.rotateLocal(0, 0, convertAngleUnit(newAngles[0]));
7875
+ }
7876
+ else if (t === 'rotate3d') ;
7877
+ else if (t === 'skew') {
7878
+ var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0, 0];
7879
+ object.setLocalSkew(deg2rad(newSkew[0]), deg2rad(newSkew[1]));
7880
+ }
7881
+ else if (t === 'skewx') {
7882
+ var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7883
+ object.setLocalSkew(deg2rad(newSkew[0]), object.getLocalSkew()[1]);
7884
+ }
7885
+ else if (t === 'skewy') {
7886
+ var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) { return s.value; })) || [0];
7887
+ object.setLocalSkew(object.getLocalSkew()[0], deg2rad(newSkew[0]));
7888
+ }
7889
+ else if (t === 'matrix') {
7890
+ var _a = __read(d.map(function (s) { return s.value; }), 6), a = _a[0], b = _a[1], c = _a[2], dd = _a[3], tx = _a[4], ty = _a[5];
7891
+ object.setLocalTransform(mat4.set(tmpMat4, a, b, 0, 0, c, dd, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1));
7892
+ }
7893
+ else if (t === 'matrix3d') {
7894
+ // @ts-ignore
7895
+ mat4.set.apply(mat4, __spreadArray([tmpMat4], __read(d.map(function (s) { return s.value; })), false));
7896
+ object.setLocalTransform(tmpMat4);
7897
+ }
7898
+ });
7899
+ return object.getLocalTransform();
7900
+ }
7901
+
8106
7902
  /**
8107
7903
  * @see /zh/docs/api/animation#支持变换的属性
8108
7904
  *
@@ -8207,12 +8003,12 @@ var CircleUpdater = /** @class */ (function () {
8207
8003
  function CircleUpdater() {
8208
8004
  }
8209
8005
  CircleUpdater.prototype.update = function (parsedStyle, object) {
8210
- var r = parsedStyle.r;
8211
- var width = r * 2;
8212
- var height = r * 2;
8006
+ var _a = parsedStyle.cx, cx = _a === void 0 ? 0 : _a, _b = parsedStyle.cy, cy = _b === void 0 ? 0 : _b, _c = parsedStyle.r, r = _c === void 0 ? 0 : _c;
8213
8007
  return {
8214
- width: width,
8215
- height: height,
8008
+ cx: cx,
8009
+ cy: cy,
8010
+ hwidth: r,
8011
+ hheight: r,
8216
8012
  };
8217
8013
  };
8218
8014
  return CircleUpdater;
@@ -8222,12 +8018,12 @@ var EllipseUpdater = /** @class */ (function () {
8222
8018
  function EllipseUpdater() {
8223
8019
  }
8224
8020
  EllipseUpdater.prototype.update = function (parsedStyle, object) {
8225
- var rx = parsedStyle.rx, ry = parsedStyle.ry;
8226
- var width = rx * 2;
8227
- var height = ry * 2;
8021
+ var _a = parsedStyle.cx, cx = _a === void 0 ? 0 : _a, _b = parsedStyle.cy, cy = _b === void 0 ? 0 : _b, _c = parsedStyle.rx, rx = _c === void 0 ? 0 : _c, _d = parsedStyle.ry, ry = _d === void 0 ? 0 : _d;
8228
8022
  return {
8229
- width: width,
8230
- height: height,
8023
+ cx: cx,
8024
+ cy: cy,
8025
+ hwidth: rx,
8026
+ hheight: ry,
8231
8027
  };
8232
8028
  };
8233
8029
  return EllipseUpdater;
@@ -8244,9 +8040,13 @@ var LineUpdater = /** @class */ (function () {
8244
8040
  var maxY = Math.max(y1, y2);
8245
8041
  var width = maxX - minX;
8246
8042
  var height = maxY - minY;
8043
+ var hwidth = width / 2;
8044
+ var hheight = height / 2;
8247
8045
  return {
8248
- width: width,
8249
- height: height,
8046
+ cx: minX + hwidth,
8047
+ cy: minY + hheight,
8048
+ hwidth: hwidth,
8049
+ hheight: hheight,
8250
8050
  };
8251
8051
  };
8252
8052
  return LineUpdater;
@@ -8257,10 +8057,14 @@ var PathUpdater = /** @class */ (function () {
8257
8057
  }
8258
8058
  PathUpdater.prototype.update = function (parsedStyle) {
8259
8059
  var path = parsedStyle.path;
8260
- var _a = path.rect, width = _a.width, height = _a.height;
8060
+ var _a = path.rect, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
8061
+ var hwidth = width / 2;
8062
+ var hheight = height / 2;
8261
8063
  return {
8262
- width: width,
8263
- height: height,
8064
+ cx: x + hwidth,
8065
+ cy: y + hheight,
8066
+ hwidth: hwidth,
8067
+ hheight: hheight,
8264
8068
  };
8265
8069
  };
8266
8070
  return PathUpdater;
@@ -8279,14 +8083,20 @@ var PolylineUpdater = /** @class */ (function () {
8279
8083
  var maxY = Math.max.apply(Math, __spreadArray([], __read(points.map(function (point) { return point[1]; })), false));
8280
8084
  var width = maxX - minX;
8281
8085
  var height = maxY - minY;
8086
+ var hwidth = width / 2;
8087
+ var hheight = height / 2;
8282
8088
  return {
8283
- width: width,
8284
- height: height,
8089
+ cx: minX + hwidth,
8090
+ cy: minY + hheight,
8091
+ hwidth: hwidth,
8092
+ hheight: hheight,
8285
8093
  };
8286
8094
  }
8287
8095
  return {
8288
- width: 0,
8289
- height: 0,
8096
+ cx: 0,
8097
+ cy: 0,
8098
+ hwidth: 0,
8099
+ hheight: 0,
8290
8100
  };
8291
8101
  };
8292
8102
  return PolylineUpdater;
@@ -8296,7 +8106,7 @@ var RectUpdater = /** @class */ (function () {
8296
8106
  function RectUpdater() {
8297
8107
  }
8298
8108
  RectUpdater.prototype.update = function (parsedStyle, object) {
8299
- var img = parsedStyle.img, _a = parsedStyle.width, width = _a === void 0 ? 0 : _a, _b = parsedStyle.height, height = _b === void 0 ? 0 : _b;
8109
+ 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;
8300
8110
  var contentWidth = width;
8301
8111
  var contentHeight = height;
8302
8112
  // resize with HTMLImageElement's size
@@ -8311,8 +8121,10 @@ var RectUpdater = /** @class */ (function () {
8311
8121
  }
8312
8122
  }
8313
8123
  return {
8314
- width: contentWidth,
8315
- height: contentHeight,
8124
+ cx: x + contentWidth / 2,
8125
+ cy: y + contentHeight / 2,
8126
+ hwidth: contentWidth / 2,
8127
+ hheight: contentHeight / 2,
8316
8128
  };
8317
8129
  };
8318
8130
  return RectUpdater;
@@ -8335,7 +8147,7 @@ var TextUpdater = /** @class */ (function () {
8335
8147
  };
8336
8148
  TextUpdater.prototype.update = function (parsedStyle, object) {
8337
8149
  var _a, _b;
8338
- var text = parsedStyle.text, textAlign = parsedStyle.textAlign, lineWidth = parsedStyle.lineWidth, textBaseline = parsedStyle.textBaseline, dx = parsedStyle.dx, dy = parsedStyle.dy;
8150
+ 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;
8339
8151
  if (!this.isReadyToMeasure(parsedStyle, object)) {
8340
8152
  parsedStyle.metrics = {
8341
8153
  font: '',
@@ -8353,47 +8165,42 @@ var TextUpdater = /** @class */ (function () {
8353
8165
  lineMetrics: [],
8354
8166
  };
8355
8167
  return {
8356
- width: 0,
8357
- height: 0,
8358
- x: 0,
8359
- y: 0,
8360
- offsetX: 0,
8361
- offsetY: 0,
8168
+ hwidth: 0,
8169
+ hheight: 0,
8170
+ cx: 0,
8171
+ cy: 0,
8362
8172
  };
8363
8173
  }
8364
8174
  var offscreenCanvas = (((_b = (_a = object === null || object === void 0 ? void 0 : object.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.getConfig()) || {}).offscreenCanvas;
8365
8175
  var metrics = this.globalRuntime.textService.measureText(text, parsedStyle, offscreenCanvas);
8366
8176
  parsedStyle.metrics = metrics;
8367
8177
  var width = metrics.width, height = metrics.height, lineHeight = metrics.lineHeight, fontProperties = metrics.fontProperties;
8368
- // anchor is left-top by default
8369
- var halfExtents = [width / 2, height / 2, 0];
8178
+ var hwidth = width / 2;
8179
+ var hheight = height / 2;
8370
8180
  // default 'left'
8371
- var anchor = [0, 1];
8372
- var lineXOffset = 0;
8181
+ var lineXOffset = x + hwidth;
8373
8182
  if (textAlign === 'center' || textAlign === 'middle') {
8374
- lineXOffset = lineWidth / 2;
8375
- anchor = [0.5, 1];
8183
+ lineXOffset += lineWidth / 2 - hwidth;
8376
8184
  }
8377
8185
  else if (textAlign === 'right' || textAlign === 'end') {
8378
- lineXOffset = lineWidth;
8379
- anchor = [1, 1];
8186
+ lineXOffset += lineWidth - hwidth * 2;
8380
8187
  }
8381
- var lineYOffset = 0;
8188
+ var lineYOffset = y - hheight;
8382
8189
  if (textBaseline === 'middle') {
8383
8190
  // eslint-disable-next-line prefer-destructuring
8384
- lineYOffset = halfExtents[1];
8191
+ lineYOffset += hheight;
8385
8192
  }
8386
8193
  else if (textBaseline === 'top' || textBaseline === 'hanging') {
8387
- lineYOffset = halfExtents[1] * 2;
8194
+ lineYOffset += hheight * 2;
8388
8195
  }
8389
8196
  else if (textBaseline === 'alphabetic') {
8390
8197
  // prevent calling getImageData for ascent metrics
8391
- lineYOffset = this.globalRuntime.enableCSSParsing
8198
+ lineYOffset += this.globalRuntime.enableCSSParsing
8392
8199
  ? lineHeight - fontProperties.ascent
8393
8200
  : 0;
8394
8201
  }
8395
8202
  else if (textBaseline === 'bottom' || textBaseline === 'ideographic') {
8396
- lineYOffset = 0;
8203
+ lineYOffset += 0;
8397
8204
  }
8398
8205
  // TODO: ideographic & bottom
8399
8206
  if (dx) {
@@ -8402,13 +8209,11 @@ var TextUpdater = /** @class */ (function () {
8402
8209
  if (dy) {
8403
8210
  lineYOffset += dy;
8404
8211
  }
8405
- // update anchor
8406
- parsedStyle.anchor = [anchor[0], anchor[1], 0];
8407
8212
  return {
8408
- width: halfExtents[0] * 2,
8409
- height: halfExtents[1] * 2,
8410
- offsetX: lineXOffset,
8411
- offsetY: lineYOffset,
8213
+ cx: lineXOffset,
8214
+ cy: lineYOffset,
8215
+ hwidth: hwidth,
8216
+ hheight: hheight,
8412
8217
  };
8413
8218
  };
8414
8219
  return TextUpdater;
@@ -11683,7 +11488,7 @@ var CSSPropertySyntaxFactory = (function () {
11683
11488
  _a[PropertySyntax.LENGTH_PERCENTAGE] = length,
11684
11489
  _a[PropertySyntax.LENGTH_PERCENTAGE_12] = new CSSPropertyLengthOrPercentage12(),
11685
11490
  _a[PropertySyntax.LENGTH_PERCENTAGE_14] = new CSSPropertyLengthOrPercentage14(),
11686
- _a[PropertySyntax.COORDINATE] = new CSSPropertyLocalPosition(),
11491
+ _a[PropertySyntax.COORDINATE] = new CSSPropertyLengthOrPercentage(),
11687
11492
  _a[PropertySyntax.OFFSET_DISTANCE] = new CSSPropertyOffsetDistance(),
11688
11493
  _a[PropertySyntax.OPACITY_VALUE] = new CSSPropertyOpacity(),
11689
11494
  _a[PropertySyntax.PATH] = new CSSPropertyPath(),
@@ -11822,7 +11627,6 @@ var Element = /** @class */ (function (_super) {
11822
11627
  _this.style = {};
11823
11628
  _this.computedStyle = runtime.enableCSSParsing
11824
11629
  ? {
11825
- anchor: unsetKeywordValue,
11826
11630
  opacity: unsetKeywordValue,
11827
11631
  fillOpacity: unsetKeywordValue,
11828
11632
  strokeOpacity: unsetKeywordValue,
@@ -11979,8 +11783,11 @@ var Element = /** @class */ (function (_super) {
11979
11783
  if ((_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) {
11980
11784
  this.ownerDocument.defaultView.mountChildren(child);
11981
11785
  }
11982
- insertedEvent.relatedNode = this;
11983
- child.dispatchEvent(insertedEvent);
11786
+ // @ts-ignore
11787
+ if (child.isMutationObserved) {
11788
+ insertedEvent.relatedNode = this;
11789
+ child.dispatchEvent(insertedEvent);
11790
+ }
11984
11791
  return child;
11985
11792
  };
11986
11793
  Element.prototype.insertBefore = function (newChild, refChild) {
@@ -12285,7 +12092,7 @@ var Element = /** @class */ (function (_super) {
12285
12092
  /**
12286
12093
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
12287
12094
  */
12288
- Element.prototype.setAttribute = function (attributeName, value, force) {
12095
+ Element.prototype.setAttribute = function (attributeName, value, force, memoize) {
12289
12096
  this.attributes[attributeName] = value;
12290
12097
  };
12291
12098
  Element.prototype.getAttributeNS = function (namespace, localName) {
@@ -12326,7 +12133,6 @@ function isDisplayObject(value) {
12326
12133
  }
12327
12134
  var mutationEvent = new MutationEvent(ElementEvent.ATTR_MODIFIED, null, null, null, null, MutationEvent.MODIFICATION, null, null);
12328
12135
  var DEFAULT_STYLE_PROPS = {
12329
- anchor: '',
12330
12136
  opacity: '',
12331
12137
  fillOpacity: '',
12332
12138
  strokeOpacity: '',
@@ -12353,7 +12159,6 @@ var DEFAULT_STYLE_PROPS = {
12353
12159
  shadowType: '',
12354
12160
  };
12355
12161
  var DEFAULT_PARSED_STYLE_PROPS = {
12356
- anchor: [0, 0],
12357
12162
  fill: noneColor,
12358
12163
  stroke: noneColor,
12359
12164
  transform: [],
@@ -12407,7 +12212,6 @@ var DATASET_PREFIX = 'data-';
12407
12212
  var DisplayObject = /** @class */ (function (_super) {
12408
12213
  __extends(DisplayObject, _super);
12409
12214
  function DisplayObject(config) {
12410
- var _a;
12411
12215
  var _this = _super.call(this) || this;
12412
12216
  _this.isCustomElement = false;
12413
12217
  _this.isMutationObserved = false;
@@ -12426,7 +12230,7 @@ var DisplayObject = /** @class */ (function (_super) {
12426
12230
  // eg. group.get('name')
12427
12231
  _this.config = config;
12428
12232
  // compatible with G 3.0
12429
- _this.config.interactive = (_a = _this.config.capture) !== null && _a !== void 0 ? _a : _this.config.interactive;
12233
+ // this.config.interactive = this.config.capture ?? this.config.interactive;
12430
12234
  // init scene graph node
12431
12235
  _this.id = _this.config.id || '';
12432
12236
  _this.name = _this.config.name || '';
@@ -12434,23 +12238,23 @@ var DisplayObject = /** @class */ (function (_super) {
12434
12238
  _this.className = _this.config.className || _this.config.class;
12435
12239
  }
12436
12240
  _this.nodeName = _this.config.type || Shape.GROUP;
12437
- // compatible with G 3.0
12438
- _this.config.style =
12439
- _this.config.style || _this.config.attrs || {};
12440
- Object.assign(_this.config.style, _this.config.attrs);
12441
- // this.config.style = {
12442
- // // ...DEFAULT_STYLE_PROPS,
12443
- // ...this.config.style,
12444
- // ...this.config.attrs,
12445
- // };
12446
- if (_this.config.visible != null) {
12447
- _this.config.style.visibility =
12448
- _this.config.visible === false ? 'hidden' : 'visible';
12449
- }
12450
- if (_this.config.interactive != null) {
12451
- _this.config.style.pointerEvents =
12452
- _this.config.interactive === false ? 'none' : 'auto';
12453
- }
12241
+ // // compatible with G 3.0
12242
+ // this.config.style =
12243
+ // this.config.style || this.config.attrs || ({} as StyleProps);
12244
+ // // Object.assign(this.config.style, this.config.attrs);
12245
+ // // this.config.style = {
12246
+ // // // ...DEFAULT_STYLE_PROPS,
12247
+ // // ...this.config.style,
12248
+ // // ...this.config.attrs,
12249
+ // // };
12250
+ // if (this.config.visible != null) {
12251
+ // this.config.style.visibility =
12252
+ // this.config.visible === false ? 'hidden' : 'visible';
12253
+ // }
12254
+ // if (this.config.interactive != null) {
12255
+ // this.config.style.pointerEvents =
12256
+ // this.config.interactive === false ? 'none' : 'auto';
12257
+ // }
12454
12258
  // merge parsed value
12455
12259
  Object.assign(_this.parsedStyle, runtime.enableCSSParsing
12456
12260
  ? DEFAULT_PARSED_STYLE_PROPS
@@ -13202,12 +13006,15 @@ var CSS = {
13202
13006
 
13203
13007
  var Circle = /** @class */ (function (_super) {
13204
13008
  __extends(Circle, _super);
13009
+ // constructor(options: DisplayObjectConfig<CircleStyleProps> = {}) {
13010
+ // super(options);
13011
+ // this.nodeName = Shape.CIRCLE;
13012
+ // }
13205
13013
  function Circle(_a) {
13206
13014
  if (_a === void 0) { _a = {}; }
13207
13015
  var style = _a.style, rest = __rest(_a, ["style"]);
13208
13016
  return _super.call(this, __assign({ type: Shape.CIRCLE, style: runtime.enableCSSParsing
13209
13017
  ? __assign({ cx: '', cy: '', r: '' }, style) : __assign({}, style), initialParsedStyle: {
13210
- anchor: [0.5, 0.5],
13211
13018
  transformOrigin: runtime.enableCSSParsing
13212
13019
  ? null
13213
13020
  : [PECENTAGE_50, PECENTAGE_50],
@@ -13228,7 +13035,7 @@ var CustomElement = /** @class */ (function (_super) {
13228
13035
  var _this = this;
13229
13036
  var style = _a.style, rest = __rest(_a, ["style"]);
13230
13037
  _this = _super.call(this, __assign({ style: runtime.enableCSSParsing
13231
- ? __assign({ x: '', y: '' }, style) : __assign({}, style) }, rest)) || this;
13038
+ ? __assign({}, style) : __assign({}, style) }, rest)) || this;
13232
13039
  // static get observedAttributes(): string[] {
13233
13040
  // return [];
13234
13041
  // }
@@ -13245,7 +13052,6 @@ var Ellipse = /** @class */ (function (_super) {
13245
13052
  var style = _a.style, rest = __rest(_a, ["style"]);
13246
13053
  return _super.call(this, __assign({ type: Shape.ELLIPSE, style: runtime.enableCSSParsing
13247
13054
  ? __assign({ cx: '', cy: '', rx: '', ry: '' }, style) : __assign({}, style), initialParsedStyle: {
13248
- anchor: [0.5, 0.5],
13249
13055
  transformOrigin: runtime.enableCSSParsing
13250
13056
  ? null
13251
13057
  : [PECENTAGE_50, PECENTAGE_50],
@@ -13270,7 +13076,7 @@ var Group = /** @class */ (function (_super) {
13270
13076
  if (_a === void 0) { _a = {}; }
13271
13077
  var style = _a.style, rest = __rest(_a, ["style"]);
13272
13078
  return _super.call(this, __assign({ type: Shape.GROUP, style: runtime.enableCSSParsing
13273
- ? __assign({ x: '', y: '', width: '', height: '' }, style) : __assign({}, style) }, rest)) || this;
13079
+ ? __assign({ width: '', height: '' }, style) : __assign({}, style) }, rest)) || this;
13274
13080
  }
13275
13081
  return Group;
13276
13082
  }(DisplayObject));
@@ -13415,7 +13221,7 @@ var Line = /** @class */ (function (_super) {
13415
13221
  }
13416
13222
  };
13417
13223
  Line.prototype.transformMarker = function (isStart) {
13418
- var _a = this.parsedStyle, markerStart = _a.markerStart, markerEnd = _a.markerEnd, markerStartOffset = _a.markerStartOffset, markerEndOffset = _a.markerEndOffset, x1 = _a.x1, x2 = _a.x2, y1 = _a.y1, y2 = _a.y2, defX = _a.defX, defY = _a.defY;
13224
+ var _a = this.parsedStyle, markerStart = _a.markerStart, markerEnd = _a.markerEnd, markerStartOffset = _a.markerStartOffset, markerEndOffset = _a.markerEndOffset, x1 = _a.x1, x2 = _a.x2, y1 = _a.y1, y2 = _a.y2;
13419
13225
  var marker = isStart ? markerStart : markerEnd;
13420
13226
  if (!marker || !isDisplayObject(marker)) {
13421
13227
  return;
@@ -13428,16 +13234,16 @@ var Line = /** @class */ (function (_super) {
13428
13234
  var offset;
13429
13235
  var originalAngle;
13430
13236
  if (isStart) {
13431
- ox = x1 - defX;
13432
- oy = y1 - defY;
13237
+ ox = x1;
13238
+ oy = y1;
13433
13239
  x = x2 - x1;
13434
13240
  y = y2 - y1;
13435
13241
  offset = markerStartOffset || 0;
13436
13242
  originalAngle = this.markerStartAngle;
13437
13243
  }
13438
13244
  else {
13439
- ox = x2 - defX;
13440
- oy = y2 - defY;
13245
+ ox = x2;
13246
+ oy = y2;
13441
13247
  x = x1 - x2;
13442
13248
  y = y1 - y2;
13443
13249
  offset = markerEndOffset || 0;
@@ -13451,9 +13257,9 @@ var Line = /** @class */ (function (_super) {
13451
13257
  Line.prototype.getPoint = function (ratio, inWorldSpace) {
13452
13258
  if (inWorldSpace === void 0) { inWorldSpace = false; }
13453
13259
  // TODO: account for z1/z2 in 3D line
13454
- var _a = this.parsedStyle, x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2, defX = _a.defX, defY = _a.defY;
13260
+ var _a = this.parsedStyle, x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
13455
13261
  var _b = linePointAt(x1, y1, x2, y2, ratio), x = _b.x, y = _b.y;
13456
- var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13262
+ var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x, y, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13457
13263
  // apply local transformation
13458
13264
  return new Point(transformed[0], transformed[1]);
13459
13265
  };
@@ -13544,7 +13350,7 @@ var Path = /** @class */ (function (_super) {
13544
13350
  }
13545
13351
  };
13546
13352
  Path.prototype.transformMarker = function (isStart) {
13547
- var _a = this.parsedStyle, markerStart = _a.markerStart, markerEnd = _a.markerEnd, markerStartOffset = _a.markerStartOffset, markerEndOffset = _a.markerEndOffset, defX = _a.defX, defY = _a.defY;
13353
+ var _a = this.parsedStyle, markerStart = _a.markerStart, markerEnd = _a.markerEnd, markerStartOffset = _a.markerStartOffset, markerEndOffset = _a.markerEndOffset;
13548
13354
  var marker = isStart ? markerStart : markerEnd;
13549
13355
  if (!marker || !isDisplayObject(marker)) {
13550
13356
  return;
@@ -13558,8 +13364,8 @@ var Path = /** @class */ (function (_super) {
13558
13364
  var originalAngle;
13559
13365
  if (isStart) {
13560
13366
  var _b = __read(this.getStartTangent(), 2), p1 = _b[0], p2 = _b[1];
13561
- ox = p2[0] - defX;
13562
- oy = p2[1] - defY;
13367
+ ox = p2[0];
13368
+ oy = p2[1];
13563
13369
  x = p1[0] - p2[0];
13564
13370
  y = p1[1] - p2[1];
13565
13371
  offset = markerStartOffset || 0;
@@ -13567,8 +13373,8 @@ var Path = /** @class */ (function (_super) {
13567
13373
  }
13568
13374
  else {
13569
13375
  var _c = __read(this.getEndTangent(), 2), p1 = _c[0], p2 = _c[1];
13570
- ox = p2[0] - defX;
13571
- oy = p2[1] - defY;
13376
+ ox = p2[0];
13377
+ oy = p2[1];
13572
13378
  x = p1[0] - p2[0];
13573
13379
  y = p1[1] - p2[1];
13574
13380
  offset = markerEndOffset || 0;
@@ -13580,18 +13386,18 @@ var Path = /** @class */ (function (_super) {
13580
13386
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
13581
13387
  };
13582
13388
  Path.prototype.placeMarkerMid = function (marker) {
13583
- var _a = this.parsedStyle, segments = _a.path.segments, defX = _a.defX, defY = _a.defY;
13389
+ var segments = this.parsedStyle.path.segments;
13584
13390
  // clear all existed markers
13585
13391
  this.markerMidList.forEach(function (marker) {
13586
13392
  marker.remove();
13587
13393
  });
13588
13394
  if (marker && isDisplayObject(marker)) {
13589
13395
  for (var i = 1; i < segments.length - 1; i++) {
13590
- var _b = __read(segments[i].currentPoint, 2), ox = _b[0], oy = _b[1];
13396
+ var _a = __read(segments[i].currentPoint, 2), ox = _a[0], oy = _a[1];
13591
13397
  var cloned = i === 1 ? marker : marker.cloneNode(true);
13592
13398
  this.markerMidList.push(cloned);
13593
13399
  this.appendChild(cloned);
13594
- cloned.setLocalPosition(ox - defX, oy - defY);
13400
+ cloned.setLocalPosition(ox, oy);
13595
13401
  // TODO: orient of marker
13596
13402
  }
13597
13403
  }
@@ -13609,9 +13415,9 @@ var Path = /** @class */ (function (_super) {
13609
13415
  */
13610
13416
  Path.prototype.getPointAtLength = function (distance, inWorldSpace) {
13611
13417
  if (inWorldSpace === void 0) { inWorldSpace = false; }
13612
- var _a = this.parsedStyle, defX = _a.defX, defY = _a.defY, absolutePath = _a.path.absolutePath;
13613
- var _b = getPointAtLength(absolutePath, distance), x = _b.x, y = _b.y;
13614
- var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13418
+ var absolutePath = this.parsedStyle.path.absolutePath;
13419
+ var _a = getPointAtLength(absolutePath, distance), x = _a.x, y = _a.y;
13420
+ var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x, y, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13615
13421
  // apply local transformation
13616
13422
  return new Point(transformed[0], transformed[1]);
13617
13423
  };
@@ -13750,7 +13556,7 @@ var Polygon = /** @class */ (function (_super) {
13750
13556
  }
13751
13557
  };
13752
13558
  Polygon.prototype.transformMarker = function (isStart) {
13753
- var _a = this.parsedStyle, markerStart = _a.markerStart, markerEnd = _a.markerEnd, markerStartOffset = _a.markerStartOffset, markerEndOffset = _a.markerEndOffset, P = _a.points, defX = _a.defX, defY = _a.defY;
13559
+ var _a = this.parsedStyle, markerStart = _a.markerStart, markerEnd = _a.markerEnd, markerStartOffset = _a.markerStartOffset, markerEndOffset = _a.markerEndOffset, P = _a.points;
13754
13560
  var points = (P || {}).points;
13755
13561
  var marker = isStart ? markerStart : markerEnd;
13756
13562
  if (!marker || !isDisplayObject(marker) || !points) {
@@ -13763,8 +13569,8 @@ var Polygon = /** @class */ (function (_super) {
13763
13569
  var oy;
13764
13570
  var offset;
13765
13571
  var originalAngle;
13766
- ox = points[0][0] - defX;
13767
- oy = points[0][1] - defY;
13572
+ ox = points[0][0];
13573
+ oy = points[0][1];
13768
13574
  if (isStart) {
13769
13575
  x = points[1][0] - points[0][0];
13770
13576
  y = points[1][1] - points[0][1];
@@ -13774,8 +13580,8 @@ var Polygon = /** @class */ (function (_super) {
13774
13580
  else {
13775
13581
  var length_1 = points.length;
13776
13582
  if (!this.parsedStyle.isClosed) {
13777
- ox = points[length_1 - 1][0] - defX;
13778
- oy = points[length_1 - 1][1] - defY;
13583
+ ox = points[length_1 - 1][0];
13584
+ oy = points[length_1 - 1][1];
13779
13585
  x = points[length_1 - 2][0] - points[length_1 - 1][0];
13780
13586
  y = points[length_1 - 2][1] - points[length_1 - 1][1];
13781
13587
  }
@@ -13792,7 +13598,7 @@ var Polygon = /** @class */ (function (_super) {
13792
13598
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
13793
13599
  };
13794
13600
  Polygon.prototype.placeMarkerMid = function (marker) {
13795
- var _a = this.parsedStyle, P = _a.points, defX = _a.defX, defY = _a.defY;
13601
+ var P = this.parsedStyle.points;
13796
13602
  var points = (P || {}).points;
13797
13603
  // clear all existed markers
13798
13604
  this.markerMidList.forEach(function (marker) {
@@ -13801,8 +13607,8 @@ var Polygon = /** @class */ (function (_super) {
13801
13607
  this.markerMidList = [];
13802
13608
  if (marker && isDisplayObject(marker) && points) {
13803
13609
  for (var i = 1; i < (this.parsedStyle.isClosed ? points.length : points.length - 1); i++) {
13804
- var ox = points[i][0] - defX;
13805
- var oy = points[i][1] - defY;
13610
+ var ox = points[i][0];
13611
+ var oy = points[i][1];
13806
13612
  var cloned = i === 1 ? marker : marker.cloneNode(true);
13807
13613
  this.markerMidList.push(cloned);
13808
13614
  this.appendChild(cloned);
@@ -13844,7 +13650,7 @@ var Polyline = /** @class */ (function (_super) {
13844
13650
  };
13845
13651
  Polyline.prototype.getPoint = function (ratio, inWorldSpace) {
13846
13652
  if (inWorldSpace === void 0) { inWorldSpace = false; }
13847
- var _a = this.parsedStyle, defX = _a.defX, defY = _a.defY, _b = _a.points, points = _b.points, segments = _b.segments;
13653
+ var _a = this.parsedStyle.points, points = _a.points, segments = _a.segments;
13848
13654
  var subt = 0;
13849
13655
  var index = 0;
13850
13656
  segments.forEach(function (v, i) {
@@ -13853,8 +13659,8 @@ var Polyline = /** @class */ (function (_super) {
13853
13659
  index = i;
13854
13660
  }
13855
13661
  });
13856
- var _c = linePointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt), x = _c.x, y = _c.y;
13857
- var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13662
+ var _b = linePointAt(points[index][0], points[index][1], points[index + 1][0], points[index + 1][1], subt), x = _b.x, y = _b.y;
13663
+ var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x, y, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform());
13858
13664
  // apply local transformation
13859
13665
  return new Point(transformed[0], transformed[1]);
13860
13666
  };