@antv/g 5.8.5 → 5.8.8

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.umd.js CHANGED
@@ -11372,13 +11372,8 @@
11372
11372
  }
11373
11373
  var path = path2Absolute(pathInput);
11374
11374
  var params = __assign({}, paramsParser);
11375
- var allPathCommands = [];
11376
- var ii = path.length;
11377
- var pathCommand = '';
11378
- for (var i = 0; i < ii; i += 1) {
11379
- pathCommand = path[i][0];
11375
+ for (var i = 0; i < path.length; i += 1) {
11380
11376
  // Save current path command
11381
- allPathCommands[i] = pathCommand;
11382
11377
  path[i] = normalizeSegment(path[i], params);
11383
11378
  var segment = path[i];
11384
11379
  var seglen = segment.length;
@@ -11960,9 +11955,12 @@
11960
11955
  /**
11961
11956
  * Returns a {x,y} point at a given length, the total length and
11962
11957
  * the shape minimum and maximum {x,y} coordinates of an A (arc-to) segment.
11958
+ *
11959
+ * For better performance, it can skip calculate bbox or length in some scenario.
11963
11960
  */
11964
- function segmentArcFactory(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, distance) {
11961
+ function segmentArcFactory(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, distance, options) {
11965
11962
  var _a;
11963
+ var _b = options.bbox, bbox = _b === void 0 ? true : _b, _c = options.length, length = _c === void 0 ? true : _c, _d = options.sampleSize, sampleSize = _d === void 0 ? 10 : _d;
11966
11964
  var distanceIsNumber = typeof distance === 'number';
11967
11965
  var x = X1;
11968
11966
  var y = Y1;
@@ -11975,13 +11973,16 @@
11975
11973
  if (distanceIsNumber && distance <= 0) {
11976
11974
  POINT = { x: x, y: y };
11977
11975
  }
11978
- // bad perf when size = 300
11979
- var sampleSize = 100;
11976
+ // bad perf when size > 100
11980
11977
  for (var j = 0; j <= sampleSize; j += 1) {
11981
11978
  t = j / sampleSize;
11982
11979
  (_a = getPointAtArcSegmentLength(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, t), x = _a.x, y = _a.y);
11983
- POINTS = POINTS.concat({ x: x, y: y });
11984
- LENGTH += distanceSquareRoot(cur, [x, y]);
11980
+ if (bbox) {
11981
+ POINTS.push({ x: x, y: y });
11982
+ }
11983
+ if (length) {
11984
+ LENGTH += distanceSquareRoot(cur, [x, y]);
11985
+ }
11985
11986
  cur = [x, y];
11986
11987
  if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
11987
11988
  var dv = (LENGTH - distance) / (LENGTH - prev[2]);
@@ -12024,8 +12025,9 @@
12024
12025
  * Returns the length of a C (cubic-bezier) segment
12025
12026
  * or an {x,y} point at a given length.
12026
12027
  */
12027
- function segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, distance) {
12028
+ function segmentCubicFactory(x1, y1, c1x, c1y, c2x, c2y, x2, y2, distance, options) {
12028
12029
  var _a;
12030
+ var _b = options.bbox, bbox = _b === void 0 ? true : _b, _c = options.length, length = _c === void 0 ? true : _c, _d = options.sampleSize, sampleSize = _d === void 0 ? 10 : _d;
12029
12031
  var distanceIsNumber = typeof distance === 'number';
12030
12032
  var x = x1;
12031
12033
  var y = y1;
@@ -12039,12 +12041,15 @@
12039
12041
  POINT = { x: x, y: y };
12040
12042
  }
12041
12043
  // bad perf when size = 300
12042
- var sampleSize = 30;
12043
12044
  for (var j = 0; j <= sampleSize; j += 1) {
12044
12045
  t = j / sampleSize;
12045
12046
  (_a = getPointAtCubicSegmentLength(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t), x = _a.x, y = _a.y);
12046
- POINTS = POINTS.concat({ x: x, y: y });
12047
- LENGTH += distanceSquareRoot(cur, [x, y]);
12047
+ if (bbox) {
12048
+ POINTS.push({ x: x, y: y });
12049
+ }
12050
+ if (length) {
12051
+ LENGTH += distanceSquareRoot(cur, [x, y]);
12052
+ }
12048
12053
  cur = [x, y];
12049
12054
  if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
12050
12055
  var dv = (LENGTH - distance) / (LENGTH - prev[2]);
@@ -12089,8 +12094,9 @@
12089
12094
  * Returns a {x,y} point at a given length, the total length and
12090
12095
  * the minimum and maximum {x,y} coordinates of a Q (quadratic-bezier) segment.
12091
12096
  */
12092
- function segmentQuadFactory(x1, y1, qx, qy, x2, y2, distance) {
12097
+ function segmentQuadFactory(x1, y1, qx, qy, x2, y2, distance, options) {
12093
12098
  var _a;
12099
+ var _b = options.bbox, bbox = _b === void 0 ? true : _b, _c = options.length, length = _c === void 0 ? true : _c, _d = options.sampleSize, sampleSize = _d === void 0 ? 10 : _d;
12094
12100
  var distanceIsNumber = typeof distance === 'number';
12095
12101
  var x = x1;
12096
12102
  var y = y1;
@@ -12103,12 +12109,15 @@
12103
12109
  if (distanceIsNumber && distance <= 0) {
12104
12110
  POINT = { x: x, y: y };
12105
12111
  }
12106
- var sampleSize = 30;
12107
12112
  for (var j = 0; j <= sampleSize; j += 1) {
12108
12113
  t = j / sampleSize;
12109
12114
  (_a = getPointAtQuadSegmentLength(x1, y1, qx, qy, x2, y2, t), x = _a.x, y = _a.y);
12110
- POINTS = POINTS.concat({ x: x, y: y });
12111
- LENGTH += distanceSquareRoot(cur, [x, y]);
12115
+ if (bbox) {
12116
+ POINTS.push({ x: x, y: y });
12117
+ }
12118
+ if (length) {
12119
+ LENGTH += distanceSquareRoot(cur, [x, y]);
12120
+ }
12112
12121
  cur = [x, y];
12113
12122
  if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
12114
12123
  var dv = (LENGTH - distance) / (LENGTH - prev[2]);
@@ -12142,7 +12151,7 @@
12142
12151
  * of a shape, the shape total length and
12143
12152
  * the shape minimum and maximum {x,y} coordinates.
12144
12153
  */
12145
- function pathLengthFactory(pathInput, distance) {
12154
+ function pathLengthFactory(pathInput, distance, options) {
12146
12155
  var _a, _b, _c, _d, _e, _f;
12147
12156
  var path = normalizePath(pathInput);
12148
12157
  var distanceIsNumber = typeof distance === 'number';
@@ -12183,13 +12192,13 @@
12183
12192
  (_a = segmentLineFactory(data[0], data[1], data[2], data[3], (distance || 0) - LENGTH), length = _a.length, min = _a.min, max = _a.max, point = _a.point);
12184
12193
  }
12185
12194
  else if (pathCommand === 'A') {
12186
- (_b = segmentArcFactory(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], (distance || 0) - LENGTH), length = _b.length, min = _b.min, max = _b.max, point = _b.point);
12195
+ (_b = segmentArcFactory(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], (distance || 0) - LENGTH, options || {}), length = _b.length, min = _b.min, max = _b.max, point = _b.point);
12187
12196
  }
12188
12197
  else if (pathCommand === 'C') {
12189
- (_c = segmentCubicFactory(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], (distance || 0) - LENGTH), length = _c.length, min = _c.min, max = _c.max, point = _c.point);
12198
+ (_c = segmentCubicFactory(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], (distance || 0) - LENGTH, options || {}), length = _c.length, min = _c.min, max = _c.max, point = _c.point);
12190
12199
  }
12191
12200
  else if (pathCommand === 'Q') {
12192
- (_d = segmentQuadFactory(data[0], data[1], data[2], data[3], data[4], data[5], (distance || 0) - LENGTH), length = _d.length, min = _d.min, max = _d.max, point = _d.point);
12201
+ (_d = segmentQuadFactory(data[0], data[1], data[2], data[3], data[4], data[5], (distance || 0) - LENGTH, options || {}), length = _d.length, min = _d.min, max = _d.max, point = _d.point);
12193
12202
  }
12194
12203
  else if (pathCommand === 'Z') {
12195
12204
  data = [x, y, mx, my];
@@ -12225,10 +12234,9 @@
12225
12234
  /**
12226
12235
  * Returns the bounding box of a shape.
12227
12236
  */
12228
- function getPathBBoxTotalLength(path) {
12237
+ function getPathBBox(path, options) {
12229
12238
  if (!path) {
12230
12239
  return {
12231
- length: 0,
12232
12240
  x: 0,
12233
12241
  y: 0,
12234
12242
  width: 0,
@@ -12240,11 +12248,10 @@
12240
12248
  cz: 0,
12241
12249
  };
12242
12250
  }
12243
- var _a = pathLengthFactory(path), length = _a.length, _b = _a.min, xMin = _b.x, yMin = _b.y, _c = _a.max, xMax = _c.x, yMax = _c.y;
12251
+ var _a = pathLengthFactory(path, undefined, __assign(__assign({}, options), { length: false })), _b = _a.min, xMin = _b.x, yMin = _b.y, _c = _a.max, xMax = _c.x, yMax = _c.y;
12244
12252
  var width = xMax - xMin;
12245
12253
  var height = yMax - yMin;
12246
12254
  return {
12247
- length: length,
12248
12255
  width: width,
12249
12256
  height: height,
12250
12257
  x: xMin,
@@ -12258,6 +12265,16 @@
12258
12265
  };
12259
12266
  }
12260
12267
 
12268
+ /**
12269
+ * Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
12270
+ *
12271
+ * The `normalizePath` version is lighter, faster, more efficient and more accurate
12272
+ * with paths that are not `curveArray`.
12273
+ */
12274
+ function getTotalLength(pathInput, options) {
12275
+ return pathLengthFactory(pathInput, undefined, __assign(__assign({}, options), { bbox: false, length: true })).length;
12276
+ }
12277
+
12261
12278
  function getRotations(a) {
12262
12279
  var segCount = a.length;
12263
12280
  var pointCount = segCount - 1;
@@ -12369,8 +12386,8 @@
12369
12386
  /**
12370
12387
  * Returns [x,y] coordinates of a point at a given length of a shape.
12371
12388
  */
12372
- function getPointAtLength(pathInput, distance) {
12373
- return pathLengthFactory(pathInput, distance).point;
12389
+ function getPointAtLength(pathInput, distance, options) {
12390
+ return pathLengthFactory(pathInput, distance, __assign(__assign({}, options), { bbox: false, length: true })).point;
12374
12391
  }
12375
12392
 
12376
12393
  function splitCubic(pts, t) {
@@ -12398,7 +12415,7 @@
12398
12415
  var segmentData = i && pathArray[i - 1].slice(-2).concat(segment.slice(1));
12399
12416
  // @ts-ignore
12400
12417
  var curveLength = i
12401
- ? segmentCubicFactory(segmentData[0], segmentData[1], segmentData[2], segmentData[3], segmentData[4], segmentData[5], segmentData[6], segmentData[7], segmentData[8]).length
12418
+ ? segmentCubicFactory(segmentData[0], segmentData[1], segmentData[2], segmentData[3], segmentData[4], segmentData[5], segmentData[6], segmentData[7], segmentData[8], { bbox: false }).length
12402
12419
  : 0;
12403
12420
  var subsegs;
12404
12421
  if (i) {
@@ -14517,6 +14534,13 @@
14517
14534
 
14518
14535
  var CanvasConfig = exports.Syringe.defineToken('');
14519
14536
 
14537
+ function getOrCalculatePathTotalLength(path) {
14538
+ if (path.parsedStyle.path.totalLength === 0) {
14539
+ path.parsedStyle.path.totalLength = getTotalLength(path.parsedStyle.path.absolutePath);
14540
+ }
14541
+
14542
+ return path.parsedStyle.path.totalLength;
14543
+ }
14520
14544
  function hasArcOrBezier(path) {
14521
14545
  var hasArc = false;
14522
14546
  var count = path.length;
@@ -18182,14 +18206,14 @@
18182
18206
  zCommandIndexes = _path2Curve[1]; // for later use
18183
18207
 
18184
18208
 
18185
- var segments = path2Segments(curve);
18209
+ var segments = path2Segments(curve); // Only calculate bbox here since we don't need length now.
18210
+
18211
+ var _getPathBBox = getPathBBox(absolutePath),
18212
+ x = _getPathBBox.x,
18213
+ y = _getPathBBox.y,
18214
+ width = _getPathBBox.width,
18215
+ height = _getPathBBox.height; // const { x, y, width, height, length } = getPathBBoxTotalLength(absolutePath);
18186
18216
 
18187
- var _getPathBBoxTotalLeng = getPathBBoxTotalLength(absolutePath),
18188
- x = _getPathBBoxTotalLeng.x,
18189
- y = _getPathBBoxTotalLeng.y,
18190
- width = _getPathBBoxTotalLeng.width,
18191
- height = _getPathBBoxTotalLeng.height,
18192
- length = _getPathBBoxTotalLeng.length;
18193
18217
 
18194
18218
  return {
18195
18219
  absolutePath: absolutePath,
@@ -18198,7 +18222,9 @@
18198
18222
  polygons: polygons,
18199
18223
  polylines: polylines,
18200
18224
  curve: curve,
18201
- totalLength: length,
18225
+ // Delay the calculation of length.
18226
+ // totalLength: length,
18227
+ totalLength: 0,
18202
18228
  zCommandIndexes: zCommandIndexes,
18203
18229
  // rect: new Rectangle(
18204
18230
  // Number.isFinite(x) ? x : 0,
@@ -23855,6 +23881,10 @@
23855
23881
  return new Point(transformed[0], transformed[1]);
23856
23882
  };
23857
23883
 
23884
+ _proto.getPointAtLength = function getPointAtLength(distance) {
23885
+ return this.getPoint(distance / this.getTotalLength());
23886
+ };
23887
+
23858
23888
  _proto.getTotalLength = function getTotalLength() {
23859
23889
  // TODO: account for z1/z2 in 3D line
23860
23890
  var _this$parsedStyle4 = this.parsedStyle,
@@ -24033,32 +24063,44 @@
24033
24063
  cloned.setLocalPosition(ox - defX, oy - defY); // TODO: orient of marker
24034
24064
  }
24035
24065
  }
24036
- };
24066
+ }
24067
+ /**
24068
+ * Returns the total length of the path.
24069
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getTotalLength
24070
+ */
24071
+ ;
24037
24072
 
24038
24073
  _proto.getTotalLength = function getTotalLength() {
24039
- return this.parsedStyle.path.totalLength;
24074
+ return getOrCalculatePathTotalLength(this);
24040
24075
  }
24041
24076
  /**
24042
- * Get point according to ratio
24077
+ * Returns the point at a given distance along the path.
24078
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength
24043
24079
  */
24044
24080
  ;
24045
24081
 
24046
- _proto.getPoint = function getPoint(ratio) {
24082
+ _proto.getPointAtLength = function getPointAtLength$1(distance) {
24047
24083
  var _this$parsedStyle4 = this.parsedStyle,
24048
24084
  defX = _this$parsedStyle4.defX,
24049
24085
  defY = _this$parsedStyle4.defY,
24050
- _this$parsedStyle4$pa = _this$parsedStyle4.path,
24051
- totalLength = _this$parsedStyle4$pa.totalLength,
24052
- absolutePath = _this$parsedStyle4$pa.absolutePath;
24086
+ absolutePath = _this$parsedStyle4.path.absolutePath;
24053
24087
 
24054
- var _getPointAtLength = getPointAtLength(absolutePath, ratio * totalLength),
24055
- x = _getPointAtLength.x,
24056
- y = _getPointAtLength.y;
24088
+ var _getPointAtLength2 = getPointAtLength(absolutePath, distance),
24089
+ x = _getPointAtLength2.x,
24090
+ y = _getPointAtLength2.y;
24057
24091
 
24058
24092
  var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
24059
24093
 
24060
24094
  return new Point(transformed[0], transformed[1]);
24061
24095
  }
24096
+ /**
24097
+ * Returns the point at a given ratio of the total length in path.
24098
+ */
24099
+ ;
24100
+
24101
+ _proto.getPoint = function getPoint(ratio) {
24102
+ return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this));
24103
+ }
24062
24104
  /**
24063
24105
  * Get start tangent vector
24064
24106
  */
@@ -24316,6 +24358,10 @@
24316
24358
  return this.parsedStyle.points.totalLength;
24317
24359
  };
24318
24360
 
24361
+ _proto.getPointAtLength = function getPointAtLength(distance) {
24362
+ return this.getPoint(distance / this.getTotalLength());
24363
+ };
24364
+
24319
24365
  _proto.getPoint = function getPoint(ratio) {
24320
24366
  var _this$parsedStyle = this.parsedStyle,
24321
24367
  defX = _this$parsedStyle.defX,
@@ -26924,6 +26970,19 @@
26924
26970
 
26925
26971
  return zIndex1 - zIndex2;
26926
26972
  }
26973
+ function findClosestClipPathTarget(object) {
26974
+ var el = object;
26975
+
26976
+ do {
26977
+ var _el$style;
26978
+
26979
+ var clipPath = (_el$style = el.style) === null || _el$style === void 0 ? void 0 : _el$style.clipPath;
26980
+ if (clipPath) return el;
26981
+ el = el.parentElement;
26982
+ } while (el !== null);
26983
+
26984
+ return null;
26985
+ }
26927
26986
  var SceneGraphService = exports.Syringe.defineToken('');
26928
26987
  /**
26929
26988
  * update transform in scene graph
@@ -27616,16 +27675,16 @@
27616
27675
  }
27617
27676
  }); // account for clip path
27618
27677
 
27619
- var clipPath = element.parsedStyle.clipPath;
27678
+ var clipped = findClosestClipPathTarget(element);
27620
27679
 
27621
- if (clipPath) {
27622
- var clipPathBounds = this.getTransformedGeometryBounds(clipPath, true);
27680
+ if (clipped) {
27681
+ var clipPathBounds = this.getTransformedGeometryBounds(clipped.style.clipPath, true);
27623
27682
  var transformParentBounds;
27624
27683
 
27625
27684
  if (clipPathBounds) {
27626
27685
  transformParentBounds = new AABB(); // intersect with original geometry
27627
27686
 
27628
- transformParentBounds.setFromTransformedAABB(clipPathBounds, this.getWorldTransform(element));
27687
+ transformParentBounds.setFromTransformedAABB(clipPathBounds, this.getWorldTransform(clipped));
27629
27688
  }
27630
27689
 
27631
27690
  if (!aabb) {
@@ -33936,12 +33995,14 @@
33936
33995
  exports.displayObjectPool = displayObjectPool;
33937
33996
  exports.equalSet = equalSet;
33938
33997
  exports.extractPolygons = extractPolygons;
33998
+ exports.findClosestClipPathTarget = findClosestClipPathTarget;
33939
33999
  exports.formatAttribute = formatAttribute;
33940
34000
  exports.fromRotationTranslationScale = fromRotationTranslationScale$1;
33941
34001
  exports.getAngle = getAngle;
33942
34002
  exports.getEasingFunction = getEasingFunction;
33943
34003
  exports.getEuler = getEuler;
33944
34004
  exports.getHeight = getHeight;
34005
+ exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;
33945
34006
  exports.getOrCreateKeyword = getOrCreateKeyword;
33946
34007
  exports.getOrCreateRGBA = getOrCreateRGBA;
33947
34008
  exports.getRotationInRadians = getRotationInRadians;