@antv/g 5.12.1 → 5.13.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.umd.js +898 -124
- package/dist/index.umd.min.js +2 -2
- package/package.json +8 -8
package/dist/index.umd.js
CHANGED
|
@@ -5063,40 +5063,6 @@
|
|
|
5063
5063
|
};
|
|
5064
5064
|
}
|
|
5065
5065
|
|
|
5066
|
-
/**
|
|
5067
|
-
* Returns the bounding box of a shape.
|
|
5068
|
-
*/
|
|
5069
|
-
function getPathBBox(path, options) {
|
|
5070
|
-
if (!path) {
|
|
5071
|
-
return {
|
|
5072
|
-
x: 0,
|
|
5073
|
-
y: 0,
|
|
5074
|
-
width: 0,
|
|
5075
|
-
height: 0,
|
|
5076
|
-
x2: 0,
|
|
5077
|
-
y2: 0,
|
|
5078
|
-
cx: 0,
|
|
5079
|
-
cy: 0,
|
|
5080
|
-
cz: 0,
|
|
5081
|
-
};
|
|
5082
|
-
}
|
|
5083
|
-
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;
|
|
5084
|
-
var width = xMax - xMin;
|
|
5085
|
-
var height = yMax - yMin;
|
|
5086
|
-
return {
|
|
5087
|
-
width: width,
|
|
5088
|
-
height: height,
|
|
5089
|
-
x: xMin,
|
|
5090
|
-
y: yMin,
|
|
5091
|
-
x2: xMax,
|
|
5092
|
-
y2: yMax,
|
|
5093
|
-
cx: xMin + width / 2,
|
|
5094
|
-
cy: yMin + height / 2,
|
|
5095
|
-
// an estimted guess
|
|
5096
|
-
cz: Math.max(width, height) + Math.min(width, height) / 2,
|
|
5097
|
-
};
|
|
5098
|
-
}
|
|
5099
|
-
|
|
5100
5066
|
/**
|
|
5101
5067
|
* Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
|
|
5102
5068
|
*
|
|
@@ -5298,16 +5264,11 @@
|
|
|
5298
5264
|
return result[0].length === result[1].length ? result : equalizeSegments(result[0], result[1], tl);
|
|
5299
5265
|
}
|
|
5300
5266
|
|
|
5301
|
-
var toString = {}.toString;
|
|
5302
|
-
var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
|
|
5303
|
-
|
|
5304
5267
|
/**
|
|
5305
|
-
*
|
|
5306
|
-
* @param {*} fn 对象
|
|
5307
|
-
* @return {Boolean} 是否函数
|
|
5268
|
+
* @see https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isfunction
|
|
5308
5269
|
*/
|
|
5309
5270
|
var isFunction = (function (value) {
|
|
5310
|
-
return
|
|
5271
|
+
return typeof value === 'function';
|
|
5311
5272
|
});
|
|
5312
5273
|
|
|
5313
5274
|
// isFinite,
|
|
@@ -5319,6 +5280,13 @@
|
|
|
5319
5280
|
return value === null || value === undefined;
|
|
5320
5281
|
};
|
|
5321
5282
|
|
|
5283
|
+
var toString = {}.toString;
|
|
5284
|
+
var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
|
|
5285
|
+
|
|
5286
|
+
var isArray = (function (value) {
|
|
5287
|
+
return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
|
|
5288
|
+
});
|
|
5289
|
+
|
|
5322
5290
|
var isObject = (function (value) {
|
|
5323
5291
|
/**
|
|
5324
5292
|
* isObject({}) => true
|
|
@@ -5330,6 +5298,58 @@
|
|
|
5330
5298
|
return (value !== null && type === 'object') || type === 'function';
|
|
5331
5299
|
});
|
|
5332
5300
|
|
|
5301
|
+
/**
|
|
5302
|
+
* @param {Array} arr The array to iterate over.
|
|
5303
|
+
* @return {*} Returns the maximum value.
|
|
5304
|
+
* @example
|
|
5305
|
+
*
|
|
5306
|
+
* max([1, 2]);
|
|
5307
|
+
* // => 2
|
|
5308
|
+
*
|
|
5309
|
+
* max([]);
|
|
5310
|
+
* // => undefined
|
|
5311
|
+
*
|
|
5312
|
+
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
5313
|
+
*
|
|
5314
|
+
* max(data);
|
|
5315
|
+
* // => 1250010
|
|
5316
|
+
* // Math.max(...data) will encounter "Maximum call stack size exceeded" error
|
|
5317
|
+
*/
|
|
5318
|
+
var max$1 = (function (arr) {
|
|
5319
|
+
if (!isArray(arr)) {
|
|
5320
|
+
return undefined;
|
|
5321
|
+
}
|
|
5322
|
+
return arr.reduce(function (prev, curr) {
|
|
5323
|
+
return Math.max(prev, curr);
|
|
5324
|
+
}, arr[0]);
|
|
5325
|
+
});
|
|
5326
|
+
|
|
5327
|
+
/**
|
|
5328
|
+
* @param {Array} arr The array to iterate over.
|
|
5329
|
+
* @return {*} Returns the minimum value.
|
|
5330
|
+
* @example
|
|
5331
|
+
*
|
|
5332
|
+
* min([1, 2]);
|
|
5333
|
+
* // => 1
|
|
5334
|
+
*
|
|
5335
|
+
* min([]);
|
|
5336
|
+
* // => undefined
|
|
5337
|
+
*
|
|
5338
|
+
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
5339
|
+
*
|
|
5340
|
+
* min(data);
|
|
5341
|
+
* // => 1250010
|
|
5342
|
+
* // Math.min(...data) will encounter "Maximum call stack size exceeded" error
|
|
5343
|
+
*/
|
|
5344
|
+
var min$1 = (function (arr) {
|
|
5345
|
+
if (!isArray(arr)) {
|
|
5346
|
+
return undefined;
|
|
5347
|
+
}
|
|
5348
|
+
return arr.reduce(function (prev, curr) {
|
|
5349
|
+
return Math.min(prev, curr);
|
|
5350
|
+
}, arr[0]);
|
|
5351
|
+
});
|
|
5352
|
+
|
|
5333
5353
|
var isString = (function (str) {
|
|
5334
5354
|
return isType(str, 'String');
|
|
5335
5355
|
});
|
|
@@ -5352,6 +5372,16 @@
|
|
|
5352
5372
|
return isType(value, 'Number');
|
|
5353
5373
|
};
|
|
5354
5374
|
|
|
5375
|
+
var PRECISION = 0.00001; // numbers less than this is considered as 0
|
|
5376
|
+
function isNumberEqual(a, b, precision) {
|
|
5377
|
+
if (precision === void 0) { precision = PRECISION; }
|
|
5378
|
+
return Math.abs(a - b) < precision;
|
|
5379
|
+
}
|
|
5380
|
+
|
|
5381
|
+
var mod = function (n, m) {
|
|
5382
|
+
return ((n % m) + m) % m;
|
|
5383
|
+
};
|
|
5384
|
+
|
|
5355
5385
|
/**
|
|
5356
5386
|
* 是否是布尔类型
|
|
5357
5387
|
*
|
|
@@ -5792,6 +5822,10 @@
|
|
|
5792
5822
|
return Math.sqrt(dx * dx + dy * dy);
|
|
5793
5823
|
}
|
|
5794
5824
|
|
|
5825
|
+
function isNumberEqual$1(v1, v2) {
|
|
5826
|
+
return Math.abs(v1 - v2) < 0.001;
|
|
5827
|
+
}
|
|
5828
|
+
|
|
5795
5829
|
function getBBoxByArray(xArr, yArr) {
|
|
5796
5830
|
var minX = Math.min.apply(Math, xArr);
|
|
5797
5831
|
var minY = Math.min.apply(Math, yArr);
|
|
@@ -5804,6 +5838,10 @@
|
|
|
5804
5838
|
height: maxY - minY
|
|
5805
5839
|
};
|
|
5806
5840
|
}
|
|
5841
|
+
|
|
5842
|
+
function piMod(angle) {
|
|
5843
|
+
return (angle + Math.PI * 2) % (Math.PI * 2);
|
|
5844
|
+
}
|
|
5807
5845
|
var line = {
|
|
5808
5846
|
/**
|
|
5809
5847
|
* 计算线段的包围盒
|
|
@@ -5908,6 +5946,687 @@
|
|
|
5908
5946
|
return Math.atan2(y2 - y1, x2 - x1);
|
|
5909
5947
|
}
|
|
5910
5948
|
};
|
|
5949
|
+
var EPSILON$1 = 0.0001;
|
|
5950
|
+
/**
|
|
5951
|
+
* 使用牛顿切割法求最近的点
|
|
5952
|
+
* @param {number[]} xArr 点的 x 数组
|
|
5953
|
+
* @param {number[]} yArr 点的 y 数组
|
|
5954
|
+
* @param {number} x 指定的点 x
|
|
5955
|
+
* @param {number} y 指定的点 y
|
|
5956
|
+
* @param {Function} tCallback 差值函数
|
|
5957
|
+
*/
|
|
5958
|
+
|
|
5959
|
+
function nearestPoint(xArr, yArr, x, y, tCallback, length) {
|
|
5960
|
+
var t = -1;
|
|
5961
|
+
var d = Infinity;
|
|
5962
|
+
var v0 = [x, y];
|
|
5963
|
+
var segNum = 20;
|
|
5964
|
+
|
|
5965
|
+
if (length && length > 200) {
|
|
5966
|
+
segNum = length / 10;
|
|
5967
|
+
}
|
|
5968
|
+
|
|
5969
|
+
var increaseRate = 1 / segNum;
|
|
5970
|
+
var interval = increaseRate / 10;
|
|
5971
|
+
|
|
5972
|
+
for (var i = 0; i <= segNum; i++) {
|
|
5973
|
+
var _t = i * increaseRate;
|
|
5974
|
+
|
|
5975
|
+
var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
|
|
5976
|
+
var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
|
|
5977
|
+
|
|
5978
|
+
if (d1 < d) {
|
|
5979
|
+
t = _t;
|
|
5980
|
+
d = d1;
|
|
5981
|
+
}
|
|
5982
|
+
} // 提前终止
|
|
5983
|
+
|
|
5984
|
+
|
|
5985
|
+
if (t === 0) {
|
|
5986
|
+
return {
|
|
5987
|
+
x: xArr[0],
|
|
5988
|
+
y: yArr[0]
|
|
5989
|
+
};
|
|
5990
|
+
}
|
|
5991
|
+
|
|
5992
|
+
if (t === 1) {
|
|
5993
|
+
var count = xArr.length;
|
|
5994
|
+
return {
|
|
5995
|
+
x: xArr[count - 1],
|
|
5996
|
+
y: yArr[count - 1]
|
|
5997
|
+
};
|
|
5998
|
+
}
|
|
5999
|
+
|
|
6000
|
+
d = Infinity;
|
|
6001
|
+
|
|
6002
|
+
for (var _i = 0; _i < 32; _i++) {
|
|
6003
|
+
if (interval < EPSILON$1) {
|
|
6004
|
+
break;
|
|
6005
|
+
}
|
|
6006
|
+
|
|
6007
|
+
var prev = t - interval;
|
|
6008
|
+
var next = t + interval;
|
|
6009
|
+
var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
|
|
6010
|
+
|
|
6011
|
+
var _d = distance(v0[0], v0[1], _v[0], _v[1]);
|
|
6012
|
+
|
|
6013
|
+
if (prev >= 0 && _d < d) {
|
|
6014
|
+
t = prev;
|
|
6015
|
+
d = _d;
|
|
6016
|
+
} else {
|
|
6017
|
+
var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
|
|
6018
|
+
var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
|
|
6019
|
+
|
|
6020
|
+
if (next <= 1 && d2 < d) {
|
|
6021
|
+
t = next;
|
|
6022
|
+
d = d2;
|
|
6023
|
+
} else {
|
|
6024
|
+
interval *= 0.5;
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
|
|
6029
|
+
return {
|
|
6030
|
+
x: tCallback.apply(void 0, xArr.concat([t])),
|
|
6031
|
+
y: tCallback.apply(void 0, yArr.concat([t]))
|
|
6032
|
+
};
|
|
6033
|
+
} // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
|
|
6034
|
+
|
|
6035
|
+
|
|
6036
|
+
function snapLength(xArr, yArr) {
|
|
6037
|
+
var totalLength = 0;
|
|
6038
|
+
var count = xArr.length;
|
|
6039
|
+
|
|
6040
|
+
for (var i = 0; i < count; i++) {
|
|
6041
|
+
var x = xArr[i];
|
|
6042
|
+
var y = yArr[i];
|
|
6043
|
+
var nextX = xArr[(i + 1) % count];
|
|
6044
|
+
var nextY = yArr[(i + 1) % count];
|
|
6045
|
+
totalLength += distance(x, y, nextX, nextY);
|
|
6046
|
+
}
|
|
6047
|
+
|
|
6048
|
+
return totalLength / 2;
|
|
6049
|
+
}
|
|
6050
|
+
|
|
6051
|
+
function quadraticAt(p0, p1, p2, t) {
|
|
6052
|
+
var onet = 1 - t;
|
|
6053
|
+
return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
|
|
6054
|
+
} // 求极值
|
|
6055
|
+
|
|
6056
|
+
|
|
6057
|
+
function extrema(p0, p1, p2) {
|
|
6058
|
+
var a = p0 + p2 - 2 * p1;
|
|
6059
|
+
|
|
6060
|
+
if (isNumberEqual$1(a, 0)) {
|
|
6061
|
+
return [0.5];
|
|
6062
|
+
}
|
|
6063
|
+
|
|
6064
|
+
var rst = (p0 - p1) / a;
|
|
6065
|
+
|
|
6066
|
+
if (rst <= 1 && rst >= 0) {
|
|
6067
|
+
return [rst];
|
|
6068
|
+
}
|
|
6069
|
+
|
|
6070
|
+
return [];
|
|
6071
|
+
}
|
|
6072
|
+
|
|
6073
|
+
function derivativeAt(p0, p1, p2, t) {
|
|
6074
|
+
return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
|
|
6075
|
+
} // 分割贝塞尔曲线
|
|
6076
|
+
|
|
6077
|
+
|
|
6078
|
+
function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
|
|
6079
|
+
// 划分点
|
|
6080
|
+
var xt = quadraticAt(x1, x2, x3, t);
|
|
6081
|
+
var yt = quadraticAt(y1, y2, y3, t); // 分割的第一条曲线的控制点
|
|
6082
|
+
|
|
6083
|
+
var controlPoint1 = line.pointAt(x1, y1, x2, y2, t); // 分割的第二条曲线的控制点
|
|
6084
|
+
|
|
6085
|
+
var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
|
|
6086
|
+
return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
|
|
6087
|
+
} // 使用迭代法取贝塞尔曲线的长度
|
|
6088
|
+
|
|
6089
|
+
|
|
6090
|
+
function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
|
|
6091
|
+
if (iterationCount === 0) {
|
|
6092
|
+
return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
|
|
6093
|
+
}
|
|
6094
|
+
|
|
6095
|
+
var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
|
|
6096
|
+
var left = quadratics[0];
|
|
6097
|
+
var right = quadratics[1];
|
|
6098
|
+
left.push(iterationCount - 1);
|
|
6099
|
+
right.push(iterationCount - 1);
|
|
6100
|
+
return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
|
|
6101
|
+
}
|
|
6102
|
+
|
|
6103
|
+
var quadratic = {
|
|
6104
|
+
box: function box(x1, y1, x2, y2, x3, y3) {
|
|
6105
|
+
var xExtrema = extrema(x1, x2, x3)[0];
|
|
6106
|
+
var yExtrema = extrema(y1, y2, y3)[0]; // 控制点不加入 box 的计算
|
|
6107
|
+
|
|
6108
|
+
var xArr = [x1, x3];
|
|
6109
|
+
var yArr = [y1, y3];
|
|
6110
|
+
|
|
6111
|
+
if (xExtrema !== undefined) {
|
|
6112
|
+
xArr.push(quadraticAt(x1, x2, x3, xExtrema));
|
|
6113
|
+
}
|
|
6114
|
+
|
|
6115
|
+
if (yExtrema !== undefined) {
|
|
6116
|
+
yArr.push(quadraticAt(y1, y2, y3, yExtrema));
|
|
6117
|
+
}
|
|
6118
|
+
|
|
6119
|
+
return getBBoxByArray(xArr, yArr);
|
|
6120
|
+
},
|
|
6121
|
+
length: function length(x1, y1, x2, y2, x3, y3) {
|
|
6122
|
+
return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
|
|
6123
|
+
},
|
|
6124
|
+
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
6125
|
+
return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
|
|
6126
|
+
},
|
|
6127
|
+
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
6128
|
+
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
|
|
6129
|
+
return distance(point.x, point.y, x0, y0);
|
|
6130
|
+
},
|
|
6131
|
+
interpolationAt: quadraticAt,
|
|
6132
|
+
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
|
|
6133
|
+
return {
|
|
6134
|
+
x: quadraticAt(x1, x2, x3, t),
|
|
6135
|
+
y: quadraticAt(y1, y2, y3, t)
|
|
6136
|
+
};
|
|
6137
|
+
},
|
|
6138
|
+
divide: function divide(x1, y1, x2, y2, x3, y3, t) {
|
|
6139
|
+
return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
|
|
6140
|
+
},
|
|
6141
|
+
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
|
|
6142
|
+
var dx = derivativeAt(x1, x2, x3, t);
|
|
6143
|
+
var dy = derivativeAt(y1, y2, y3, t);
|
|
6144
|
+
var angle = Math.atan2(dy, dx);
|
|
6145
|
+
return piMod(angle);
|
|
6146
|
+
}
|
|
6147
|
+
};
|
|
6148
|
+
|
|
6149
|
+
function cubicAt(p0, p1, p2, p3, t) {
|
|
6150
|
+
var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
|
|
6151
|
+
|
|
6152
|
+
return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
|
|
6153
|
+
}
|
|
6154
|
+
|
|
6155
|
+
function derivativeAt$1(p0, p1, p2, p3, t) {
|
|
6156
|
+
var onet = 1 - t;
|
|
6157
|
+
return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
|
|
6158
|
+
}
|
|
6159
|
+
|
|
6160
|
+
function extrema$1(p0, p1, p2, p3) {
|
|
6161
|
+
var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
|
|
6162
|
+
var b = 6 * p0 - 12 * p1 + 6 * p2;
|
|
6163
|
+
var c = 3 * p1 - 3 * p0;
|
|
6164
|
+
var extremas = [];
|
|
6165
|
+
var t1;
|
|
6166
|
+
var t2;
|
|
6167
|
+
var discSqrt;
|
|
6168
|
+
|
|
6169
|
+
if (isNumberEqual$1(a, 0)) {
|
|
6170
|
+
if (!isNumberEqual$1(b, 0)) {
|
|
6171
|
+
t1 = -c / b;
|
|
6172
|
+
|
|
6173
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
6174
|
+
extremas.push(t1);
|
|
6175
|
+
}
|
|
6176
|
+
}
|
|
6177
|
+
} else {
|
|
6178
|
+
var disc = b * b - 4 * a * c;
|
|
6179
|
+
|
|
6180
|
+
if (isNumberEqual$1(disc, 0)) {
|
|
6181
|
+
extremas.push(-b / (2 * a));
|
|
6182
|
+
} else if (disc > 0) {
|
|
6183
|
+
discSqrt = Math.sqrt(disc);
|
|
6184
|
+
t1 = (-b + discSqrt) / (2 * a);
|
|
6185
|
+
t2 = (-b - discSqrt) / (2 * a);
|
|
6186
|
+
|
|
6187
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
6188
|
+
extremas.push(t1);
|
|
6189
|
+
}
|
|
6190
|
+
|
|
6191
|
+
if (t2 >= 0 && t2 <= 1) {
|
|
6192
|
+
extremas.push(t2);
|
|
6193
|
+
}
|
|
6194
|
+
}
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6197
|
+
return extremas;
|
|
6198
|
+
} // 分割贝塞尔曲线
|
|
6199
|
+
|
|
6200
|
+
|
|
6201
|
+
function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6202
|
+
// 划分点
|
|
6203
|
+
var xt = cubicAt(x1, x2, x3, x4, t);
|
|
6204
|
+
var yt = cubicAt(y1, y2, y3, y4, t); // 计算两点之间的差值点
|
|
6205
|
+
|
|
6206
|
+
var c1 = line.pointAt(x1, y1, x2, y2, t);
|
|
6207
|
+
var c2 = line.pointAt(x2, y2, x3, y3, t);
|
|
6208
|
+
var c3 = line.pointAt(x3, y3, x4, y4, t);
|
|
6209
|
+
var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
|
|
6210
|
+
var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
|
|
6211
|
+
return [[x1, y1, c1.x, c1.y, c12.x, c12.y, xt, yt], [xt, yt, c23.x, c23.y, c3.x, c3.y, x4, y4]];
|
|
6212
|
+
} // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
|
|
6213
|
+
|
|
6214
|
+
|
|
6215
|
+
function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
|
|
6216
|
+
if (iterationCount === 0) {
|
|
6217
|
+
return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
|
|
6218
|
+
}
|
|
6219
|
+
|
|
6220
|
+
var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
|
|
6221
|
+
var left = [].concat(cubics[0], [iterationCount - 1]);
|
|
6222
|
+
var right = [].concat(cubics[1], [iterationCount - 1]);
|
|
6223
|
+
return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
|
|
6224
|
+
}
|
|
6225
|
+
|
|
6226
|
+
var cubic = {
|
|
6227
|
+
extrema: extrema$1,
|
|
6228
|
+
box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
6229
|
+
var xArr = [x1, x4];
|
|
6230
|
+
var yArr = [y1, y4];
|
|
6231
|
+
var xExtrema = extrema$1(x1, x2, x3, x4);
|
|
6232
|
+
var yExtrema = extrema$1(y1, y2, y3, y4);
|
|
6233
|
+
|
|
6234
|
+
for (var i = 0; i < xExtrema.length; i++) {
|
|
6235
|
+
xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
|
|
6236
|
+
}
|
|
6237
|
+
|
|
6238
|
+
for (var _i = 0; _i < yExtrema.length; _i++) {
|
|
6239
|
+
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
|
|
6240
|
+
}
|
|
6241
|
+
|
|
6242
|
+
return getBBoxByArray(xArr, yArr);
|
|
6243
|
+
},
|
|
6244
|
+
length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
6245
|
+
// 迭代三次,划分成 8 段求长度
|
|
6246
|
+
return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
|
|
6247
|
+
},
|
|
6248
|
+
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
|
|
6249
|
+
return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
|
|
6250
|
+
},
|
|
6251
|
+
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
|
|
6252
|
+
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
|
|
6253
|
+
return distance(point.x, point.y, x0, y0);
|
|
6254
|
+
},
|
|
6255
|
+
interpolationAt: cubicAt,
|
|
6256
|
+
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6257
|
+
return {
|
|
6258
|
+
x: cubicAt(x1, x2, x3, x4, t),
|
|
6259
|
+
y: cubicAt(y1, y2, y3, y4, t)
|
|
6260
|
+
};
|
|
6261
|
+
},
|
|
6262
|
+
divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6263
|
+
return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
|
|
6264
|
+
},
|
|
6265
|
+
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6266
|
+
var dx = derivativeAt$1(x1, x2, x3, x4, t);
|
|
6267
|
+
var dy = derivativeAt$1(y1, y2, y3, y4, t);
|
|
6268
|
+
return piMod(Math.atan2(dy, dx));
|
|
6269
|
+
}
|
|
6270
|
+
};
|
|
6271
|
+
/**
|
|
6272
|
+
* @fileoverview 椭圆的一些计算,
|
|
6273
|
+
* - 周长计算参考:https://www.mathsisfun.com/geometry/ellipse-perimeter.html
|
|
6274
|
+
* - 距离计算参考:https://wet-robots.ghost.io/simple-method-for-distance-to-ellipse/
|
|
6275
|
+
* @author dxq613@gmail.com
|
|
6276
|
+
*/
|
|
6277
|
+
|
|
6278
|
+
function copysign(v1, v2) {
|
|
6279
|
+
var absv = Math.abs(v1);
|
|
6280
|
+
return v2 > 0 ? absv : absv * -1;
|
|
6281
|
+
}
|
|
6282
|
+
|
|
6283
|
+
var ellipse = {
|
|
6284
|
+
/**
|
|
6285
|
+
* 包围盒计算
|
|
6286
|
+
* @param {number} x 椭圆中心 x
|
|
6287
|
+
* @param {number} y 椭圆中心 y
|
|
6288
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6289
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6290
|
+
* @return {object} 包围盒
|
|
6291
|
+
*/
|
|
6292
|
+
box: function box(x, y, rx, ry) {
|
|
6293
|
+
return {
|
|
6294
|
+
x: x - rx,
|
|
6295
|
+
y: y - ry,
|
|
6296
|
+
width: rx * 2,
|
|
6297
|
+
height: ry * 2
|
|
6298
|
+
};
|
|
6299
|
+
},
|
|
6300
|
+
|
|
6301
|
+
/**
|
|
6302
|
+
* 计算周长,使用近似法
|
|
6303
|
+
* @param {number} x 椭圆中心 x
|
|
6304
|
+
* @param {number} y 椭圆中心 y
|
|
6305
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6306
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6307
|
+
* @return {number} 椭圆周长
|
|
6308
|
+
*/
|
|
6309
|
+
length: function length(x, y, rx, ry) {
|
|
6310
|
+
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
6311
|
+
},
|
|
6312
|
+
|
|
6313
|
+
/**
|
|
6314
|
+
* 距离椭圆最近的点
|
|
6315
|
+
* @param {number} x 椭圆中心 x
|
|
6316
|
+
* @param {number} y 椭圆中心 y
|
|
6317
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6318
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6319
|
+
* @param {number} x0 指定的点 x
|
|
6320
|
+
* @param {number} y0 指定的点 y
|
|
6321
|
+
* @return {object} 椭圆上距离指定点最近的点
|
|
6322
|
+
*/
|
|
6323
|
+
nearestPoint: function nearestPoint(x, y, rx, ry, x0, y0) {
|
|
6324
|
+
var a = rx;
|
|
6325
|
+
var b = ry; // 假如椭圆半径为0则返回圆心
|
|
6326
|
+
|
|
6327
|
+
if (a === 0 || b === 0) {
|
|
6328
|
+
return {
|
|
6329
|
+
x: x,
|
|
6330
|
+
y: y
|
|
6331
|
+
};
|
|
6332
|
+
} // 转换成 0, 0 为中心的椭圆计算
|
|
6333
|
+
|
|
6334
|
+
|
|
6335
|
+
var relativeX = x0 - x;
|
|
6336
|
+
var relativeY = y0 - y;
|
|
6337
|
+
var px = Math.abs(relativeX);
|
|
6338
|
+
var py = Math.abs(relativeY);
|
|
6339
|
+
var squareA = a * a;
|
|
6340
|
+
var squareB = b * b; // const angle0 = Math.atan2(relativeY, relativeX);
|
|
6341
|
+
|
|
6342
|
+
var t = Math.PI / 4;
|
|
6343
|
+
var nearestX = 0; // 椭圆上的任一点
|
|
6344
|
+
|
|
6345
|
+
var nearestY = 0; // 迭代 4 次
|
|
6346
|
+
|
|
6347
|
+
for (var i = 0; i < 4; i++) {
|
|
6348
|
+
nearestX = a * Math.cos(t);
|
|
6349
|
+
nearestY = b * Math.sin(t);
|
|
6350
|
+
var ex = (squareA - squareB) * Math.pow(Math.cos(t), 3) / a;
|
|
6351
|
+
var ey = (squareB - squareA) * Math.pow(Math.sin(t), 3) / b;
|
|
6352
|
+
var rx1 = nearestX - ex;
|
|
6353
|
+
var ry1 = nearestY - ey;
|
|
6354
|
+
var qx = px - ex;
|
|
6355
|
+
var qy = py - ey;
|
|
6356
|
+
var r = Math.hypot(ry1, rx1);
|
|
6357
|
+
var q = Math.hypot(qy, qx);
|
|
6358
|
+
var delta_c = r * Math.asin((rx1 * qy - ry1 * qx) / (r * q));
|
|
6359
|
+
var delta_t = delta_c / Math.sqrt(squareA + squareB - nearestX * nearestX - nearestY * nearestY);
|
|
6360
|
+
t += delta_t;
|
|
6361
|
+
t = Math.min(Math.PI / 2, Math.max(0, t));
|
|
6362
|
+
}
|
|
6363
|
+
|
|
6364
|
+
return {
|
|
6365
|
+
x: x + copysign(nearestX, relativeX),
|
|
6366
|
+
y: y + copysign(nearestY, relativeY)
|
|
6367
|
+
};
|
|
6368
|
+
},
|
|
6369
|
+
|
|
6370
|
+
/**
|
|
6371
|
+
* 点到椭圆最近的距离
|
|
6372
|
+
* @param {number} x 椭圆中心 x
|
|
6373
|
+
* @param {number} y 椭圆中心 y
|
|
6374
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6375
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6376
|
+
* @param {number} x0 指定的点 x
|
|
6377
|
+
* @param {number} y0 指定的点 y
|
|
6378
|
+
* @return {number} 点到椭圆的距离
|
|
6379
|
+
*/
|
|
6380
|
+
pointDistance: function pointDistance(x, y, rx, ry, x0, y0) {
|
|
6381
|
+
var nearestPoint = this.nearestPoint(x, y, rx, ry, x0, y0);
|
|
6382
|
+
return distance(nearestPoint.x, nearestPoint.y, x0, y0);
|
|
6383
|
+
},
|
|
6384
|
+
|
|
6385
|
+
/**
|
|
6386
|
+
* 根据比例获取点
|
|
6387
|
+
* @param {number} x 椭圆中心 x
|
|
6388
|
+
* @param {number} y 椭圆中心 y
|
|
6389
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6390
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6391
|
+
* @param {number} t 指定比例,x轴方向为 0
|
|
6392
|
+
* @return {object} 点
|
|
6393
|
+
*/
|
|
6394
|
+
pointAt: function pointAt(x, y, rx, ry, t) {
|
|
6395
|
+
var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
|
|
6396
|
+
|
|
6397
|
+
return {
|
|
6398
|
+
x: x + rx * Math.cos(angle),
|
|
6399
|
+
y: y + ry * Math.sin(angle)
|
|
6400
|
+
};
|
|
6401
|
+
},
|
|
6402
|
+
|
|
6403
|
+
/**
|
|
6404
|
+
* 根据比例计算切线角度
|
|
6405
|
+
* @param {number} x 椭圆中心 x
|
|
6406
|
+
* @param {number} y 椭圆中心 y
|
|
6407
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6408
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6409
|
+
* @param {number} t 指定比例 0 - 1 之间,x轴方向为 0。在 0-1 范围之外是循环还是返回 null,还需要调整
|
|
6410
|
+
* @return {number} 角度,在 0 - 2PI 之间
|
|
6411
|
+
*/
|
|
6412
|
+
tangentAngle: function tangentAngle(x, y, rx, ry, t) {
|
|
6413
|
+
var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
|
|
6414
|
+
// 直接使用 x,y 的导数计算, x' = -rx * sin(t); y' = ry * cos(t);
|
|
6415
|
+
|
|
6416
|
+
var tangentAngle = Math.atan2(ry * Math.cos(angle), -rx * Math.sin(angle)); // 也可以使用指定点的切线方程计算,成本有些高
|
|
6417
|
+
// const point = this.pointAt(0, 0, rx, ry, t); // 椭圆的切线同椭圆的中心不相关
|
|
6418
|
+
// let tangentAngle = -1 * Math.atan((ry * ry * point.x) / (rx * rx * point.y));
|
|
6419
|
+
// if (angle >= 0 && angle <= Math.PI) {
|
|
6420
|
+
// tangentAngle += Math.PI;
|
|
6421
|
+
// }
|
|
6422
|
+
|
|
6423
|
+
return piMod(tangentAngle);
|
|
6424
|
+
}
|
|
6425
|
+
};
|
|
6426
|
+
|
|
6427
|
+
function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
|
|
6428
|
+
return -1 * rx * Math.cos(xRotation) * Math.sin(angle) - ry * Math.sin(xRotation) * Math.cos(angle);
|
|
6429
|
+
} // 偏导数 y
|
|
6430
|
+
|
|
6431
|
+
|
|
6432
|
+
function derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
|
|
6433
|
+
return -1 * rx * Math.sin(xRotation) * Math.sin(angle) + ry * Math.cos(xRotation) * Math.cos(angle);
|
|
6434
|
+
} // x 的极值
|
|
6435
|
+
|
|
6436
|
+
|
|
6437
|
+
function xExtrema(rx, ry, xRotation) {
|
|
6438
|
+
return Math.atan(-ry / rx * Math.tan(xRotation));
|
|
6439
|
+
} // y 的极值
|
|
6440
|
+
|
|
6441
|
+
|
|
6442
|
+
function yExtrema(rx, ry, xRotation) {
|
|
6443
|
+
return Math.atan(ry / (rx * Math.tan(xRotation)));
|
|
6444
|
+
} // 根据角度求 x 坐标
|
|
6445
|
+
|
|
6446
|
+
|
|
6447
|
+
function xAt(cx, cy, rx, ry, xRotation, angle) {
|
|
6448
|
+
return rx * Math.cos(xRotation) * Math.cos(angle) - ry * Math.sin(xRotation) * Math.sin(angle) + cx;
|
|
6449
|
+
} // 根据角度求 y 坐标
|
|
6450
|
+
|
|
6451
|
+
|
|
6452
|
+
function yAt(cx, cy, rx, ry, xRotation, angle) {
|
|
6453
|
+
return rx * Math.sin(xRotation) * Math.cos(angle) + ry * Math.cos(xRotation) * Math.sin(angle) + cy;
|
|
6454
|
+
} // 获取点在椭圆上的角度
|
|
6455
|
+
|
|
6456
|
+
|
|
6457
|
+
function getAngle(rx, ry, x0, y0) {
|
|
6458
|
+
var angle = Math.atan2(y0 * rx, x0 * ry); // 转换到 0 - 2PI 内
|
|
6459
|
+
|
|
6460
|
+
return (angle + Math.PI * 2) % (Math.PI * 2);
|
|
6461
|
+
} // 根据角度获取,x,y
|
|
6462
|
+
|
|
6463
|
+
|
|
6464
|
+
function getPoint(rx, ry, angle) {
|
|
6465
|
+
return {
|
|
6466
|
+
x: rx * Math.cos(angle),
|
|
6467
|
+
y: ry * Math.sin(angle)
|
|
6468
|
+
};
|
|
6469
|
+
} // 旋转
|
|
6470
|
+
|
|
6471
|
+
|
|
6472
|
+
function rotate$1(x, y, angle) {
|
|
6473
|
+
var cos = Math.cos(angle);
|
|
6474
|
+
var sin = Math.sin(angle);
|
|
6475
|
+
return [x * cos - y * sin, x * sin + y * cos];
|
|
6476
|
+
}
|
|
6477
|
+
|
|
6478
|
+
var arc = {
|
|
6479
|
+
/**
|
|
6480
|
+
* 计算包围盒
|
|
6481
|
+
* @param {number} cx 圆心 x
|
|
6482
|
+
* @param {number} cy 圆心 y
|
|
6483
|
+
* @param {number} rx x 轴方向的半径
|
|
6484
|
+
* @param {number} ry y 轴方向的半径
|
|
6485
|
+
* @param {number} xRotation 旋转角度
|
|
6486
|
+
* @param {number} startAngle 起始角度
|
|
6487
|
+
* @param {number} endAngle 结束角度
|
|
6488
|
+
* @return {object} 包围盒对象
|
|
6489
|
+
*/
|
|
6490
|
+
box: function box(cx, cy, rx, ry, xRotation, startAngle, endAngle) {
|
|
6491
|
+
var xDim = xExtrema(rx, ry, xRotation);
|
|
6492
|
+
var minX = Infinity;
|
|
6493
|
+
var maxX = -Infinity;
|
|
6494
|
+
var xs = [startAngle, endAngle];
|
|
6495
|
+
|
|
6496
|
+
for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) {
|
|
6497
|
+
var xAngle = xDim + i;
|
|
6498
|
+
|
|
6499
|
+
if (startAngle < endAngle) {
|
|
6500
|
+
if (startAngle < xAngle && xAngle < endAngle) {
|
|
6501
|
+
xs.push(xAngle);
|
|
6502
|
+
}
|
|
6503
|
+
} else {
|
|
6504
|
+
if (endAngle < xAngle && xAngle < startAngle) {
|
|
6505
|
+
xs.push(xAngle);
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
}
|
|
6509
|
+
|
|
6510
|
+
for (var _i = 0; _i < xs.length; _i++) {
|
|
6511
|
+
var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]);
|
|
6512
|
+
|
|
6513
|
+
if (x < minX) {
|
|
6514
|
+
minX = x;
|
|
6515
|
+
}
|
|
6516
|
+
|
|
6517
|
+
if (x > maxX) {
|
|
6518
|
+
maxX = x;
|
|
6519
|
+
}
|
|
6520
|
+
}
|
|
6521
|
+
|
|
6522
|
+
var yDim = yExtrema(rx, ry, xRotation);
|
|
6523
|
+
var minY = Infinity;
|
|
6524
|
+
var maxY = -Infinity;
|
|
6525
|
+
var ys = [startAngle, endAngle];
|
|
6526
|
+
|
|
6527
|
+
for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) {
|
|
6528
|
+
var yAngle = yDim + _i2;
|
|
6529
|
+
|
|
6530
|
+
if (startAngle < endAngle) {
|
|
6531
|
+
if (startAngle < yAngle && yAngle < endAngle) {
|
|
6532
|
+
ys.push(yAngle);
|
|
6533
|
+
}
|
|
6534
|
+
} else {
|
|
6535
|
+
if (endAngle < yAngle && yAngle < startAngle) {
|
|
6536
|
+
ys.push(yAngle);
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
|
|
6541
|
+
for (var _i3 = 0; _i3 < ys.length; _i3++) {
|
|
6542
|
+
var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]);
|
|
6543
|
+
|
|
6544
|
+
if (y < minY) {
|
|
6545
|
+
minY = y;
|
|
6546
|
+
}
|
|
6547
|
+
|
|
6548
|
+
if (y > maxY) {
|
|
6549
|
+
maxY = y;
|
|
6550
|
+
}
|
|
6551
|
+
}
|
|
6552
|
+
|
|
6553
|
+
return {
|
|
6554
|
+
x: minX,
|
|
6555
|
+
y: minY,
|
|
6556
|
+
width: maxX - minX,
|
|
6557
|
+
height: maxY - minY
|
|
6558
|
+
};
|
|
6559
|
+
},
|
|
6560
|
+
|
|
6561
|
+
/**
|
|
6562
|
+
* 获取圆弧的长度,计算圆弧长度时不考虑旋转角度,
|
|
6563
|
+
* 仅跟 rx, ry, startAngle, endAngle 相关
|
|
6564
|
+
* @param {number} cx 圆心 x
|
|
6565
|
+
* @param {number} cy 圆心 y
|
|
6566
|
+
* @param {number} rx x 轴方向的半径
|
|
6567
|
+
* @param {number} ry y 轴方向的半径
|
|
6568
|
+
* @param {number} xRotation 旋转角度
|
|
6569
|
+
* @param {number} startAngle 起始角度
|
|
6570
|
+
* @param {number} endAngle 结束角度
|
|
6571
|
+
*/
|
|
6572
|
+
length: function length(cx, cy, rx, ry, xRotation, startAngle, endAngle) {},
|
|
6573
|
+
|
|
6574
|
+
/**
|
|
6575
|
+
* 获取指定点到圆弧的最近距离的点
|
|
6576
|
+
* @param {number} cx 圆心 x
|
|
6577
|
+
* @param {number} cy 圆心 y
|
|
6578
|
+
* @param {number} rx x 轴方向的半径
|
|
6579
|
+
* @param {number} ry y 轴方向的半径
|
|
6580
|
+
* @param {number} xRotation 旋转角度
|
|
6581
|
+
* @param {number} startAngle 起始角度
|
|
6582
|
+
* @param {number} endAngle 结束角度
|
|
6583
|
+
* @param {number} x0 指定点的 x
|
|
6584
|
+
* @param {number} y0 指定点的 y
|
|
6585
|
+
* @return {object} 到指定点最近距离的点
|
|
6586
|
+
*/
|
|
6587
|
+
nearestPoint: function nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
|
|
6588
|
+
// 将最近距离问题转换成到椭圆中心 0,0 没有旋转的椭圆问题
|
|
6589
|
+
var relativeVector = rotate$1(x0 - cx, y0 - cy, -xRotation);
|
|
6590
|
+
var x1 = relativeVector[0],
|
|
6591
|
+
y1 = relativeVector[1]; // 计算点到椭圆的最近的点
|
|
6592
|
+
|
|
6593
|
+
var relativePoint = ellipse.nearestPoint(0, 0, rx, ry, x1, y1); // 获取点在椭圆上的角度
|
|
6594
|
+
|
|
6595
|
+
var angle = getAngle(rx, ry, relativePoint.x, relativePoint.y); // 点没有在圆弧上
|
|
6596
|
+
|
|
6597
|
+
if (angle < startAngle) {
|
|
6598
|
+
// 小于起始圆弧
|
|
6599
|
+
relativePoint = getPoint(rx, ry, startAngle);
|
|
6600
|
+
} else if (angle > endAngle) {
|
|
6601
|
+
// 大于结束圆弧
|
|
6602
|
+
relativePoint = getPoint(rx, ry, endAngle);
|
|
6603
|
+
} // 旋转到 xRotation 的角度
|
|
6604
|
+
|
|
6605
|
+
|
|
6606
|
+
var vector = rotate$1(relativePoint.x, relativePoint.y, xRotation);
|
|
6607
|
+
return {
|
|
6608
|
+
x: vector[0] + cx,
|
|
6609
|
+
y: vector[1] + cy
|
|
6610
|
+
};
|
|
6611
|
+
},
|
|
6612
|
+
pointDistance: function pointDistance(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
|
|
6613
|
+
var nearestPoint = this.nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0);
|
|
6614
|
+
return distance(nearestPoint.x, nearestPoint.y, x0, y0);
|
|
6615
|
+
},
|
|
6616
|
+
pointAt: function pointAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
|
|
6617
|
+
var angle = (endAngle - startAngle) * t + startAngle;
|
|
6618
|
+
return {
|
|
6619
|
+
x: xAt(cx, cy, rx, ry, xRotation, angle),
|
|
6620
|
+
y: yAt(cx, cy, rx, ry, xRotation, angle)
|
|
6621
|
+
};
|
|
6622
|
+
},
|
|
6623
|
+
tangentAngle: function tangentAngle(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
|
|
6624
|
+
var angle = (endAngle - startAngle) * t + startAngle;
|
|
6625
|
+
var dx = derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
|
|
6626
|
+
var dy = derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
|
|
6627
|
+
return piMod(Math.atan2(dy, dx));
|
|
6628
|
+
}
|
|
6629
|
+
};
|
|
5911
6630
|
|
|
5912
6631
|
function analyzePoints(points) {
|
|
5913
6632
|
// 计算每段的长度和总的长度
|
|
@@ -6513,7 +7232,7 @@
|
|
|
6513
7232
|
set$1(this.planes[2].normal,m3+m1,m7+m5,m11+m9);this.planes[2].distance=m15+m13;// top
|
|
6514
7233
|
set$1(this.planes[3].normal,m3-m1,m7-m5,m11-m9);this.planes[3].distance=m15-m13;// far
|
|
6515
7234
|
set$1(this.planes[4].normal,m3-m2,m7-m6,m11-m10);this.planes[4].distance=m15-m14;// near
|
|
6516
|
-
set$1(this.planes[5].normal,m3+m2,m7+m6,m11+m10);this.planes[5].distance=m15+m14;this.planes.forEach(function(plane){plane.normalize();plane.updatePNVertexFlag();});};return Frustum;}();var Point=/*#__PURE__*/function(){function Point(x,y){if(x===void 0){x=0;}if(y===void 0){y=0;}this.x=0;this.y=0;this.x=x;this.y=y;}var _proto=Point.prototype;_proto.clone=function clone(){return new Point(this.x,this.y);};_proto.copyFrom=function copyFrom(p){this.x=p.x;this.y=p.y;};return Point;}();var Rectangle=/*#__PURE__*/function(){function Rectangle(x,y,width,height){this.x=void 0;this.y=void 0;this.width=void 0;this.height=void 0;this.left=void 0;this.right=void 0;this.top=void 0;this.bottom=void 0;this.x=x;this.y=y;this.width=width;this.height=height;this.left=x;this.right=x+width;this.top=y;this.bottom=y+height;}var _proto=Rectangle.prototype;_proto.toJSON=function toJSON(){};return Rectangle;}();(function(Shape){Shape["GROUP"]="g";Shape["CIRCLE"]="circle";Shape["ELLIPSE"]="ellipse";Shape["IMAGE"]="image";Shape["RECT"]="rect";Shape["LINE"]="line";Shape["POLYLINE"]="polyline";Shape["POLYGON"]="polygon";Shape["TEXT"]="text";Shape["PATH"]="path";Shape["HTML"]="html";Shape["MESH"]="mesh";})(exports.Shape||(exports.Shape={}));var camelCase=memoize(function(str){if(str===void 0){str='';}return str.replace(/-([a-z])/g,function(g){return g[1].toUpperCase();});});function DCHECK(bool){if(!bool){throw new Error();}}function DCHECK_EQ(a,b){if(a!==b){throw new Error();}}function DCHECK_NE(a,b){if(a===b){throw new Error();}}function isFunction$1(func){return typeof func==='function';}var definedProps=function definedProps(obj){return Object.fromEntries(Object.entries(obj).filter(function(_ref){var v=_ref[1];return v!==undefined;}));};var FORMAT_ATTR_MAP={d:{alias:'path'},strokeDasharray:{alias:'lineDash'},strokeWidth:{alias:'lineWidth'},textAnchor:{alias:'textAlign'
|
|
7235
|
+
set$1(this.planes[5].normal,m3+m2,m7+m6,m11+m10);this.planes[5].distance=m15+m14;this.planes.forEach(function(plane){plane.normalize();plane.updatePNVertexFlag();});};return Frustum;}();var Point=/*#__PURE__*/function(){function Point(x,y){if(x===void 0){x=0;}if(y===void 0){y=0;}this.x=0;this.y=0;this.x=x;this.y=y;}var _proto=Point.prototype;_proto.clone=function clone(){return new Point(this.x,this.y);};_proto.copyFrom=function copyFrom(p){this.x=p.x;this.y=p.y;};return Point;}();var Rectangle=/*#__PURE__*/function(){function Rectangle(x,y,width,height){this.x=void 0;this.y=void 0;this.width=void 0;this.height=void 0;this.left=void 0;this.right=void 0;this.top=void 0;this.bottom=void 0;this.x=x;this.y=y;this.width=width;this.height=height;this.left=x;this.right=x+width;this.top=y;this.bottom=y+height;}var _proto=Rectangle.prototype;_proto.toJSON=function toJSON(){};return Rectangle;}();(function(Shape){Shape["GROUP"]="g";Shape["CIRCLE"]="circle";Shape["ELLIPSE"]="ellipse";Shape["IMAGE"]="image";Shape["RECT"]="rect";Shape["LINE"]="line";Shape["POLYLINE"]="polyline";Shape["POLYGON"]="polygon";Shape["TEXT"]="text";Shape["PATH"]="path";Shape["HTML"]="html";Shape["MESH"]="mesh";})(exports.Shape||(exports.Shape={}));var camelCase=memoize(function(str){if(str===void 0){str='';}return str.replace(/-([a-z])/g,function(g){return g[1].toUpperCase();});});function DCHECK(bool){if(!bool){throw new Error();}}function DCHECK_EQ(a,b){if(a!==b){throw new Error();}}function DCHECK_NE(a,b){if(a===b){throw new Error();}}function isFunction$1(func){return typeof func==='function';}var definedProps=function definedProps(obj){return Object.fromEntries(Object.entries(obj).filter(function(_ref){var v=_ref[1];return v!==undefined;}));};var FORMAT_ATTR_MAP={d:{alias:'path'},strokeDasharray:{alias:'lineDash'},strokeWidth:{alias:'lineWidth'},textAnchor:{alias:'textAlign'},src:{alias:'img'}};var formatAttributeName=memoize(function(name){var attributeName=camelCase(name);var map=FORMAT_ATTR_MAP[attributeName];attributeName=(map===null||map===void 0?void 0:map.alias)||attributeName;return attributeName;});var canvasMap={};var defaultCanvasIdCounter=0;/**
|
|
6517
7236
|
* destroy existed canvas with the same id
|
|
6518
7237
|
*/function cleanExistedCanvas(container,canvas){if(container){var id=typeof container==='string'?container:container.id||defaultCanvasIdCounter++;if(canvasMap[id]){canvasMap[id].destroy();}canvasMap[id]=canvas;}}var isBrowser=typeof window!=='undefined'&&typeof window.document!=='undefined';function sortByZIndex(o1,o2){var zIndex1=Number(o1.style.zIndex);var zIndex2=Number(o2.style.zIndex);if(zIndex1===zIndex2){// return o1.entity.getComponent(Sortable).lastSortedIndex - o2.entity.getComponent(Sortable).lastSortedIndex;
|
|
6519
7238
|
var parent=o1.parentNode;if(parent){var children=parent.childNodes||[];return children.indexOf(o1)-children.indexOf(o2);}}return zIndex1-zIndex2;}function findClosestClipPathTarget(object){var el=object;do{var _el$style;var clipPath=(_el$style=el.style)===null||_el$style===void 0?void 0:_el$style.clipPath;if(clipPath)return el;el=el.parentElement;}while(el!==null);return null;}var PX_SUFFIX='px';function setDOMSize($el,width,height){if(isBrowser&&$el.style){$el.style.width=width+PX_SUFFIX;$el.style.height=height+PX_SUFFIX;}}function getStyle($el,property){if(isBrowser){return document.defaultView.getComputedStyle($el,null).getPropertyValue(property);}}function getWidth($el){var width=getStyle($el,'width');if(width==='auto'){return $el.offsetWidth;}return parseFloat(width);}function getHeight($el){var height=getStyle($el,'height');if(height==='auto'){return $el.offsetHeight;}return parseFloat(height);}var ERROR_MSG_METHOD_NOT_IMPLEMENTED='Method not implemented.';var ERROR_MSG_USE_DOCUMENT_ELEMENT='Use document.documentElement instead.';// borrow from hammer.js
|
|
@@ -7243,17 +7962,9 @@
|
|
|
7243
7962
|
if(path===''||Array.isArray(path)&&path.length===0){return {absolutePath:[],hasArc:false,segments:[],polygons:[],polylines:[],curve:[],totalLength:0,zCommandIndexes:[],rect:{x:0,y:0,width:0,height:0}};}var absolutePath;try{absolutePath=normalizePath(path);}catch(e){absolutePath=normalizePath('');console.error("[g]: Invalid SVG Path definition: "+path);}var hasArc=hasArcOrBezier(absolutePath);var _extractPolygons=extractPolygons(absolutePath),polygons=_extractPolygons.polygons,polylines=_extractPolygons.polylines;// convert to curves to do morphing & picking later
|
|
7244
7963
|
// @see http://thednp.github.io/kute.js/svgCubicMorph.html
|
|
7245
7964
|
var _path2Curve=path2Curve(absolutePath,true),curve=_path2Curve[0],zCommandIndexes=_path2Curve[1];// for later use
|
|
7246
|
-
var segments=path2Segments(
|
|
7247
|
-
var _getPathBBox=getPathBBox(
|
|
7248
|
-
|
|
7249
|
-
// totalLength: length,
|
|
7250
|
-
totalLength:0,zCommandIndexes:zCommandIndexes,// rect: new Rectangle(
|
|
7251
|
-
// Number.isFinite(x) ? x : 0,
|
|
7252
|
-
// Number.isFinite(y) ? y : 0,
|
|
7253
|
-
// Number.isFinite(width) ? width : 0,
|
|
7254
|
-
// Number.isFinite(height) ? height : 0,
|
|
7255
|
-
// ),
|
|
7256
|
-
rect:{x:Number.isFinite(x)?x:0,y:Number.isFinite(y)?y:0,width:Number.isFinite(width)?width:0,height:Number.isFinite(height)?height:0}};};var memoizedParsePath=memoize(internalParsePath);function parsePath(path,object){var result=isString(path)?memoizedParsePath(path):internalParsePath(path);if(object){object.parsedStyle.defX=result.rect.x;object.parsedStyle.defY=result.rect.y;}return result;}function mergePaths(left,right,object){var curve1=left.curve;var curve2=right.curve;var curves=[curve1,curve2];if(curve1.length!==curve2.length){curves=equalizeSegments(curve1,curve2);}var curve0=getDrawDirection(curves[0])!==getDrawDirection(curves[1])?reverseCurve(curves[0]):clonePath(curves[0]);return [curve0,getRotatedCurve(curves[1],curve0),function(pathArray){// need converting to path string?
|
|
7965
|
+
var segments=path2Segments(absolutePath);// Only calculate bbox here since we don't need length now.
|
|
7966
|
+
var _getPathBBox=getPathBBox(segments,0),x=_getPathBBox.x,y=_getPathBBox.y,width=_getPathBBox.width,height=_getPathBBox.height;return {absolutePath:absolutePath,hasArc:hasArc,segments:segments,polygons:polygons,polylines:polylines,curve:curve,// Delay the calculation of length.
|
|
7967
|
+
totalLength:0,zCommandIndexes:zCommandIndexes,rect:{x:Number.isFinite(x)?x:0,y:Number.isFinite(y)?y:0,width:Number.isFinite(width)?width:0,height:Number.isFinite(height)?height:0}};};var memoizedParsePath=memoize(internalParsePath);function parsePath(path,object){var result=isString(path)?memoizedParsePath(path):internalParsePath(path);if(object){object.parsedStyle.defX=result.rect.x;object.parsedStyle.defY=result.rect.y;}return result;}function mergePaths(left,right,object){var curve1=left.curve;var curve2=right.curve;var curves=[curve1,curve2];if(curve1.length!==curve2.length){curves=equalizeSegments(curve1,curve2);}var curve0=getDrawDirection(curves[0])!==getDrawDirection(curves[1])?reverseCurve(curves[0]):clonePath(curves[0]);return [curve0,getRotatedCurve(curves[1],curve0),function(pathArray){// need converting to path string?
|
|
7257
7968
|
return pathArray;}];}/**
|
|
7258
7969
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/points
|
|
7259
7970
|
*
|
|
@@ -7352,7 +8063,8 @@
|
|
|
7352
8063
|
* update local position
|
|
7353
8064
|
*/_proto.postProcessor=function postProcessor(object){var x;var y;var z;switch(object.nodeName){case exports.Shape.CIRCLE:case exports.Shape.ELLIPSE:var _object$parsedStyle=object.parsedStyle,cx=_object$parsedStyle.cx,cy=_object$parsedStyle.cy;if(!isNil(cx)){x=cx;}if(!isNil(cy)){y=cy;}break;case exports.Shape.LINE:var _object$parsedStyle2=object.parsedStyle,x1=_object$parsedStyle2.x1,x2=_object$parsedStyle2.x2,y1=_object$parsedStyle2.y1,y2=_object$parsedStyle2.y2;var minX=Math.min(x1,x2);var minY=Math.min(y1,y2);x=minX;y=minY;z=0;break;case exports.Shape.RECT:case exports.Shape.IMAGE:case exports.Shape.GROUP:case exports.Shape.HTML:case exports.Shape.TEXT:case exports.Shape.MESH:if(!isNil(object.parsedStyle.x)){x=object.parsedStyle.x;}if(!isNil(object.parsedStyle.y)){y=object.parsedStyle.y;}break;}if(object.nodeName!==exports.Shape.PATH&&object.nodeName!==exports.Shape.POLYLINE&&object.nodeName!==exports.Shape.POLYGON){object.parsedStyle.defX=x||0;object.parsedStyle.defY=y||0;}var needResetLocalPosition=!isNil(x)||!isNil(y)||!isNil(z);if(needResetLocalPosition){var _object$getLocalPosit=object.getLocalPosition(),ox=_object$getLocalPosit[0],oy=_object$getLocalPosit[1],oz=_object$getLocalPosit[2];object.setLocalPosition(isNil(x)?ox:x,isNil(y)?oy:y,isNil(z)?oz:z);}};return CSSPropertyLocalPosition;}(CSSPropertyLengthOrPercentage);var CSSPropertyMarker=/*#__PURE__*/function(){function CSSPropertyMarker(){}var _proto=CSSPropertyMarker.prototype;_proto.calculator=function calculator(name,oldMarker,newMarker,object){var _newMarker;// unset
|
|
7354
8065
|
if(newMarker instanceof CSSKeywordValue){newMarker=null;}var cloned=(_newMarker=newMarker)===null||_newMarker===void 0?void 0:_newMarker.cloneNode(true);if(cloned){// FIXME: SVG should not inherit parent's style, add a flag here
|
|
7355
|
-
cloned.style.isMarker=true;}return cloned;};return CSSPropertyMarker;}();var CSSPropertyNumber=/*#__PURE__*/function(){function CSSPropertyNumber(){this.mixer=mergeNumbers;this.parser=parseNumber;}var _proto=CSSPropertyNumber.prototype;_proto.calculator=function calculator(name,oldParsed,computed){return computed.value;};return CSSPropertyNumber;}();var CSSPropertyOffsetDistance=/*#__PURE__*/function(){function CSSPropertyOffsetDistance(){this.parser=parseNumber;this.mixer=clampedMergeNumbers(0,1);}var _proto=CSSPropertyOffsetDistance.prototype;_proto.calculator=function calculator(name,oldParsed,computed){return computed.value;};_proto.postProcessor=function postProcessor(object){
|
|
8066
|
+
cloned.style.isMarker=true;}return cloned;};return CSSPropertyMarker;}();var CSSPropertyNumber=/*#__PURE__*/function(){function CSSPropertyNumber(){this.mixer=mergeNumbers;this.parser=parseNumber;}var _proto=CSSPropertyNumber.prototype;_proto.calculator=function calculator(name,oldParsed,computed){return computed.value;};return CSSPropertyNumber;}();var CSSPropertyOffsetDistance=/*#__PURE__*/function(){function CSSPropertyOffsetDistance(){this.parser=parseNumber;this.mixer=clampedMergeNumbers(0,1);}var _proto=CSSPropertyOffsetDistance.prototype;_proto.calculator=function calculator(name,oldParsed,computed){return computed.value;};_proto.postProcessor=function postProcessor(object){var _object$parsedStyle=object.parsedStyle,offsetPath=_object$parsedStyle.offsetPath,offsetDistance=_object$parsedStyle.offsetDistance;if(!offsetPath){return;}var nodeName=offsetPath.nodeName;if(nodeName===exports.Shape.LINE||nodeName===exports.Shape.PATH||nodeName===exports.Shape.POLYLINE){// set position in world space
|
|
8067
|
+
var point=offsetPath.getPoint(offsetDistance);if(point){object.parsedStyle.defX=point.x;object.parsedStyle.defY=point.y;object.setLocalPosition(point.x,point.y);}}};return CSSPropertyOffsetDistance;}();/**
|
|
7356
8068
|
* opacity
|
|
7357
8069
|
*/var CSSPropertyOpacity=/*#__PURE__*/function(){function CSSPropertyOpacity(){this.parser=parseNumber;this.mixer=clampedMergeNumbers(0,1);}var _proto=CSSPropertyOpacity.prototype;_proto.calculator=function calculator(name,oldParsed,computed){return computed.value;};return CSSPropertyOpacity;}();var CSSPropertyPath=/*#__PURE__*/function(){function CSSPropertyPath(){this.parser=parsePath;this.mixer=mergePaths;}var _proto=CSSPropertyPath.prototype;_proto.calculator=function calculator(name,oldParsed,parsed){// unset
|
|
7358
8070
|
if(parsed instanceof CSSKeywordValue&&parsed.value==='unset'){return {absolutePath:[],hasArc:false,segments:[],polygons:[],polylines:[],curve:[],totalLength:0,zCommandIndexes:[],rect:new Rectangle(0,0,0,0)};}return parsed;};/**
|
|
@@ -7400,7 +8112,7 @@
|
|
|
7400
8112
|
* @example
|
|
7401
8113
|
* [10px, 10px] [10%, 10%]
|
|
7402
8114
|
*/var CSSPropertyTransformOrigin=function CSSPropertyTransformOrigin(){this.parser=parseTransformOrigin;};var CSSPropertyZIndex=/*#__PURE__*/function(){function CSSPropertyZIndex(){this.parser=parseNumber;}var _proto=CSSPropertyZIndex.prototype;_proto.calculator=function calculator(name,oldParsed,computed,object){return computed.value;};_proto.postProcessor=function postProcessor(object){if(object.parentNode){var parentEntity=object.parentNode;var parentRenderable=parentEntity.renderable;var parentSortable=parentEntity.sortable;if(parentRenderable){parentRenderable.dirty=true;}// need re-sort on parent
|
|
7403
|
-
if(parentSortable){parentSortable.dirty=true;}}};return CSSPropertyZIndex;}();function getAngle(angle){if(angle===undefined){return 0;}else if(angle>360||angle<-360){return angle%360;}return angle;}function createVec3(x,y,z){if(y===void 0){y=0;}if(z===void 0){z=0;}if(isNumber(x)){return fromValues$2(x,y,z);}if(Array.isArray(x)&&x.length===3){return clone$1(x);}return fromValues$2(x[0],x[1]||y,x[2]||z);}function deg2rad(deg){return deg*(Math.PI/180);}function rad2deg(rad){return rad*(180/Math.PI);}function grad2deg(grads){grads=grads%400;if(grads<0){grads+=400;}return grads/400*360;}function deg2turn(deg){return deg/360;}function turn2deg(turn){return 360*turn;}function getEulerFromQuat(out,quat){var x=quat[0];var y=quat[1];var z=quat[2];var w=quat[3];var x2=x*x;var y2=y*y;var z2=z*z;var w2=w*w;var unit=x2+y2+z2+w2;var test=x*w-y*z;if(test>0.499995*unit){// TODO: Use glmatrix.EPSILON
|
|
8115
|
+
if(parentSortable){parentSortable.dirty=true;}}};return CSSPropertyZIndex;}();function getAngle$1(angle){if(angle===undefined){return 0;}else if(angle>360||angle<-360){return angle%360;}return angle;}function createVec3(x,y,z){if(y===void 0){y=0;}if(z===void 0){z=0;}if(isNumber(x)){return fromValues$2(x,y,z);}if(Array.isArray(x)&&x.length===3){return clone$1(x);}return fromValues$2(x[0],x[1]||y,x[2]||z);}function deg2rad(deg){return deg*(Math.PI/180);}function rad2deg(rad){return rad*(180/Math.PI);}function grad2deg(grads){grads=grads%400;if(grads<0){grads+=400;}return grads/400*360;}function deg2turn(deg){return deg/360;}function turn2deg(turn){return 360*turn;}function getEulerFromQuat(out,quat){var x=quat[0];var y=quat[1];var z=quat[2];var w=quat[3];var x2=x*x;var y2=y*y;var z2=z*z;var w2=w*w;var unit=x2+y2+z2+w2;var test=x*w-y*z;if(test>0.499995*unit){// TODO: Use glmatrix.EPSILON
|
|
7404
8116
|
// singularity at the north pole
|
|
7405
8117
|
out[0]=Math.PI/2;out[1]=2*Math.atan2(y,x);out[2]=0;}else if(test<-0.499995*unit){//TODO: Use glmatrix.EPSILON
|
|
7406
8118
|
// singularity at the south pole
|
|
@@ -7480,27 +8192,58 @@
|
|
|
7480
8192
|
}// 如果不存在点,同时 'Z',则说明是错误,不处理
|
|
7481
8193
|
}else {points.push([params[1],params[2]]);}}// 说明 points 未放入 polygons 或者 polyline
|
|
7482
8194
|
// 仅当只有一个 M,没有 Z 时会发生这种情况
|
|
7483
|
-
if(points.length>0){polylines.push(points);}return {polygons:polygons,polylines:polylines};}function isSamePoint(point1,point2){return point1[0]===point2[0]&&point1[1]===point2[1];}function
|
|
8195
|
+
if(points.length>0){polylines.push(points);}return {polygons:polygons,polylines:polylines};}function isSamePoint(point1,point2){return point1[0]===point2[0]&&point1[1]===point2[1];}function getPathBBox(segments,lineWidth){var xArr=[];var yArr=[];var segmentsWithAngle=[];for(var i=0;i<segments.length;i++){var segment=segments[i];var currentPoint=segment.currentPoint,params=segment.params,prePoint=segment.prePoint;var box=void 0;switch(segment.command){case'Q':box=quadratic.box(prePoint[0],prePoint[1],params[1],params[2],params[3],params[4]);break;case'C':box=cubic.box(prePoint[0],prePoint[1],params[1],params[2],params[3],params[4],params[5],params[6]);break;case'A':var arcParams=segment.arcParams;box=arc.box(arcParams.cx,arcParams.cy,arcParams.rx,arcParams.ry,arcParams.xRotation,arcParams.startAngle,arcParams.endAngle);break;default:xArr.push(currentPoint[0]);yArr.push(currentPoint[1]);break;}if(box){segment.box=box;xArr.push(box.x,box.x+box.width);yArr.push(box.y,box.y+box.height);}if(lineWidth&&(segment.command==='L'||segment.command==='M')&&segment.prePoint&&segment.nextPoint){segmentsWithAngle.push(segment);}}// bbox calculation should ignore NaN for path attribute
|
|
8196
|
+
// ref: https://github.com/antvis/g/issues/210
|
|
8197
|
+
// ref: https://github.com/antvis/G2/issues/3109
|
|
8198
|
+
xArr=xArr.filter(function(item){return !Number.isNaN(item)&&item!==Infinity&&item!==-Infinity;});yArr=yArr.filter(function(item){return !Number.isNaN(item)&&item!==Infinity&&item!==-Infinity;});var minX=min$1(xArr);var minY=min$1(yArr);var maxX=max$1(xArr);var maxY=max$1(yArr);if(segmentsWithAngle.length===0){return {x:minX,y:minY,width:maxX-minX,height:maxY-minY};}for(var _i=0;_i<segmentsWithAngle.length;_i++){var _segment=segmentsWithAngle[_i];var _currentPoint=_segment.currentPoint;var extra=void 0;if(_currentPoint[0]===minX){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);minX=minX-extra.xExtra;}else if(_currentPoint[0]===maxX){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);maxX=maxX+extra.xExtra;}if(_currentPoint[1]===minY){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);minY=minY-extra.yExtra;}else if(_currentPoint[1]===maxY){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);maxY=maxY+extra.yExtra;}}return {x:minX,y:minY,width:maxX-minX,height:maxY-minY};}function getExtraFromSegmentWithAngle(segment,lineWidth){var prePoint=segment.prePoint,currentPoint=segment.currentPoint,nextPoint=segment.nextPoint;var currentAndPre=Math.pow(currentPoint[0]-prePoint[0],2)+Math.pow(currentPoint[1]-prePoint[1],2);var currentAndNext=Math.pow(currentPoint[0]-nextPoint[0],2)+Math.pow(currentPoint[1]-nextPoint[1],2);var preAndNext=Math.pow(prePoint[0]-nextPoint[0],2)+Math.pow(prePoint[1]-nextPoint[1],2);// 以 currentPoint 为顶点的夹角
|
|
8199
|
+
var currentAngle=Math.acos((currentAndPre+currentAndNext-preAndNext)/(2*Math.sqrt(currentAndPre)*Math.sqrt(currentAndNext)));// 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
|
|
8200
|
+
// 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
|
|
8201
|
+
if(!currentAngle||Math.sin(currentAngle)===0||isNumberEqual(currentAngle,0)){return {xExtra:0,yExtra:0};}var xAngle=Math.abs(Math.atan2(nextPoint[1]-currentPoint[1],nextPoint[0]-currentPoint[0]));var yAngle=Math.abs(Math.atan2(nextPoint[0]-currentPoint[0],nextPoint[1]-currentPoint[1]));// 将夹角转为锐角
|
|
8202
|
+
xAngle=xAngle>Math.PI/2?Math.PI-xAngle:xAngle;yAngle=yAngle>Math.PI/2?Math.PI-yAngle:yAngle;// 这里不考虑在水平和垂直方向的投影,直接使用最大差值
|
|
8203
|
+
// 由于上层统一加减了二分之一线宽,这里需要进行弥补
|
|
8204
|
+
var extra={// 水平方向投影
|
|
8205
|
+
xExtra:Math.cos(currentAngle/2-xAngle)*(lineWidth/2*(1/Math.sin(currentAngle/2)))-lineWidth/2||0,// 垂直方向投影
|
|
8206
|
+
yExtra:Math.cos(yAngle-currentAngle/2)*(lineWidth/2*(1/Math.sin(currentAngle/2)))-lineWidth/2||0};return extra;}// 点对称
|
|
8207
|
+
function toSymmetry(point,center){return [center[0]+(center[0]-point[0]),center[1]+(center[1]-point[1])];}function path2Segments(path){var segments=[];var currentPoint=null;// 当前图形
|
|
7484
8208
|
var nextParams=null;// 下一节点的 path 参数
|
|
7485
|
-
|
|
8209
|
+
var startMovePoint=null;// 开始 M 的点,可能会有多个
|
|
7486
8210
|
var lastStartMovePointIndex=0;// 最近一个开始点 M 的索引
|
|
7487
8211
|
var count=path.length;for(var i=0;i<count;i++){var params=path[i];nextParams=path[i+1];var command=params[0];// 数学定义上的参数,便于后面的计算
|
|
7488
|
-
var segment={command:command,prePoint:currentPoint,params:params,startTangent:null,endTangent:null};switch(command){case'M'
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
segment.
|
|
7493
|
-
|
|
8212
|
+
var segment={command:command,prePoint:currentPoint,params:params,startTangent:null,endTangent:null,currentPoint:null,nextPoint:null,arcParams:null};switch(command){case'M':startMovePoint=[params[1],params[2]];lastStartMovePointIndex=i;break;case'A':var arcParams=getArcParams(currentPoint,params);segment.arcParams=arcParams;break;}if(command==='Z'){// 有了 Z 后,当前节点从开始 M 的点开始
|
|
8213
|
+
currentPoint=startMovePoint;// 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
|
|
8214
|
+
nextParams=path[lastStartMovePointIndex+1];}else {var len=params.length;currentPoint=[params[len-2],params[len-1]];}if(nextParams&&nextParams[0]==='Z'){// 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
|
|
8215
|
+
nextParams=path[lastStartMovePointIndex];if(segments[lastStartMovePointIndex]){// 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
|
|
8216
|
+
segments[lastStartMovePointIndex].prePoint=currentPoint;}}segment.currentPoint=currentPoint;// 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
|
|
8217
|
+
if(segments[lastStartMovePointIndex]&&isSamePoint(currentPoint,segments[lastStartMovePointIndex].currentPoint)){segments[lastStartMovePointIndex].prePoint=segment.prePoint;}var nextPoint=nextParams?[nextParams[nextParams.length-2],nextParams[nextParams.length-1]]:null;segment.nextPoint=nextPoint;// Add startTangent and endTangent
|
|
8218
|
+
var prePoint=segment.prePoint;if(['L','H','V'].includes(command)){segment.startTangent=[prePoint[0]-currentPoint[0],prePoint[1]-currentPoint[1]];segment.endTangent=[currentPoint[0]-prePoint[0],currentPoint[1]-prePoint[1]];}else if(command==='Q'){// 二次贝塞尔曲线只有一个控制点
|
|
8219
|
+
var cp=[params[1],params[2]];// 二次贝塞尔曲线的终点为 currentPoint
|
|
8220
|
+
segment.startTangent=[prePoint[0]-cp[0],prePoint[1]-cp[1]];segment.endTangent=[currentPoint[0]-cp[0],currentPoint[1]-cp[1]];}else if(command==='T'){var preSegment=segments[i-1];var _cp=toSymmetry(preSegment.currentPoint,prePoint);if(preSegment.command==='Q'){segment.command='Q';segment.startTangent=[prePoint[0]-_cp[0],prePoint[1]-_cp[1]];segment.endTangent=[currentPoint[0]-_cp[0],currentPoint[1]-_cp[1]];}else {// @ts-ignore
|
|
8221
|
+
segment.command='TL';segment.startTangent=[prePoint[0]-currentPoint[0],prePoint[1]-currentPoint[1]];segment.endTangent=[currentPoint[0]-prePoint[0],currentPoint[1]-prePoint[1]];}}else if(command==='C'){// 三次贝塞尔曲线有两个控制点
|
|
7494
8222
|
var cp1=[params[1],params[2]];var cp2=[params[3],params[4]];segment.startTangent=[prePoint[0]-cp1[0],prePoint[1]-cp1[1]];segment.endTangent=[currentPoint[0]-cp2[0],currentPoint[1]-cp2[1]];// horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
|
|
7495
|
-
if(segment.startTangent[0]===0&&segment.startTangent[1]===0){segment.startTangent=[cp1[0]-cp2[0],cp1[1]-cp2[1]];}if(segment.endTangent[0]===0&&segment.endTangent[1]===0){segment.endTangent=[cp2[0]-cp1[0],cp2[1]-cp1[1]];}}
|
|
8223
|
+
if(segment.startTangent[0]===0&&segment.startTangent[1]===0){segment.startTangent=[cp1[0]-cp2[0],cp1[1]-cp2[1]];}if(segment.endTangent[0]===0&&segment.endTangent[1]===0){segment.endTangent=[cp2[0]-cp1[0],cp2[1]-cp1[1]];}}else if(command==='S'){var _preSegment=segments[i-1];var _cp2=toSymmetry(_preSegment.currentPoint,prePoint);var _cp3=[params[1],params[2]];if(_preSegment.command==='C'){segment.command='C';// 将 S 命令变换为 C 命令
|
|
8224
|
+
segment.startTangent=[prePoint[0]-_cp2[0],prePoint[1]-_cp2[1]];segment.endTangent=[currentPoint[0]-_cp3[0],currentPoint[1]-_cp3[1]];}else {// @ts-ignore
|
|
8225
|
+
segment.command='SQ';// 将 S 命令变换为 SQ 命令
|
|
8226
|
+
segment.startTangent=[prePoint[0]-_cp3[0],prePoint[1]-_cp3[1]];segment.endTangent=[currentPoint[0]-_cp3[0],currentPoint[1]-_cp3[1]];}}else if(command==='A'){var d=0.001;var _ref=segment.arcParams||{},_ref$cx=_ref.cx,cx=_ref$cx===void 0?0:_ref$cx,_ref$cy=_ref.cy,cy=_ref$cy===void 0?0:_ref$cy,_ref$rx=_ref.rx,rx=_ref$rx===void 0?0:_ref$rx,_ref$ry=_ref.ry,ry=_ref$ry===void 0?0:_ref$ry,_ref$sweepFlag=_ref.sweepFlag,sweepFlag=_ref$sweepFlag===void 0?0:_ref$sweepFlag,_ref$startAngle=_ref.startAngle,startAngle=_ref$startAngle===void 0?0:_ref$startAngle,_ref$endAngle=_ref.endAngle,endAngle=_ref$endAngle===void 0?0:_ref$endAngle;if(sweepFlag===0){d*=-1;}var dx1=rx*Math.cos(startAngle-d)+cx;var dy1=ry*Math.sin(startAngle-d)+cy;segment.startTangent=[dx1-startMovePoint[0],dy1-startMovePoint[1]];var dx2=rx*Math.cos(startAngle+endAngle+d)+cx;var dy2=ry*Math.sin(startAngle+endAngle-d)+cy;segment.endTangent=[prePoint[0]-dx2,prePoint[1]-dy2];}segments.push(segment);}return segments;}// 向量长度
|
|
8227
|
+
function vMag(v){return Math.sqrt(v[0]*v[0]+v[1]*v[1]);}// u.v/|u||v|,计算夹角的余弦值
|
|
8228
|
+
function vRatio(u,v){// 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
|
|
8229
|
+
return vMag(u)*vMag(v)?(u[0]*v[0]+u[1]*v[1])/(vMag(u)*vMag(v)):1;}// 向量角度
|
|
8230
|
+
function vAngle(u,v){return (u[0]*v[1]<u[1]*v[0]?-1:1)*Math.acos(vRatio(u,v));}function getArcParams(startPoint,params){var rx=params[1];var ry=params[2];var xRotation=mod(deg2rad(params[3]),Math.PI*2);var arcFlag=params[4];var sweepFlag=params[5];// 弧形起点坐标
|
|
8231
|
+
var x1=startPoint[0];var y1=startPoint[1];// 弧形终点坐标
|
|
8232
|
+
var x2=params[6];var y2=params[7];var xp=Math.cos(xRotation)*(x1-x2)/2.0+Math.sin(xRotation)*(y1-y2)/2.0;var yp=-1*Math.sin(xRotation)*(x1-x2)/2.0+Math.cos(xRotation)*(y1-y2)/2.0;var lambda=xp*xp/(rx*rx)+yp*yp/(ry*ry);if(lambda>1){rx*=Math.sqrt(lambda);ry*=Math.sqrt(lambda);}var diff=rx*rx*(yp*yp)+ry*ry*(xp*xp);var f=diff?Math.sqrt((rx*rx*(ry*ry)-diff)/diff):1;if(arcFlag===sweepFlag){f*=-1;}if(isNaN(f)){f=0;}// 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
|
|
8233
|
+
var cxp=ry?f*rx*yp/ry:0;var cyp=rx?f*-ry*xp/rx:0;// 椭圆圆心坐标
|
|
8234
|
+
var cx=(x1+x2)/2.0+Math.cos(xRotation)*cxp-Math.sin(xRotation)*cyp;var cy=(y1+y2)/2.0+Math.sin(xRotation)*cxp+Math.cos(xRotation)*cyp;// 起始点的单位向量
|
|
8235
|
+
var u=[(xp-cxp)/rx,(yp-cyp)/ry];// 终止点的单位向量
|
|
8236
|
+
var v=[(-1*xp-cxp)/rx,(-1*yp-cyp)/ry];// 计算起始点和圆心的连线,与 x 轴正方向的夹角
|
|
8237
|
+
var theta=vAngle([1,0],u);// 计算圆弧起始点和终止点与椭圆圆心连线的夹角
|
|
8238
|
+
var dTheta=vAngle(u,v);if(vRatio(u,v)<=-1){dTheta=Math.PI;}if(vRatio(u,v)>=1){dTheta=0;}if(sweepFlag===0&&dTheta>0){dTheta=dTheta-2*Math.PI;}if(sweepFlag===1&&dTheta<0){dTheta=dTheta+2*Math.PI;}return {cx:cx,cy:cy,// 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
|
|
8239
|
+
rx:isSamePoint(startPoint,[x2,y2])?0:rx,ry:isSamePoint(startPoint,[x2,y2])?0:ry,startAngle:theta,endAngle:theta+dTheta,xRotation:xRotation,arcFlag:arcFlag,sweepFlag:sweepFlag};}function commandsToPathString(commands,object,transform){var _object$parsedStyle=object.parsedStyle,_object$parsedStyle$d=_object$parsedStyle.defX,defX=_object$parsedStyle$d===void 0?0:_object$parsedStyle$d,_object$parsedStyle$d2=_object$parsedStyle.defY,defY=_object$parsedStyle$d2===void 0?0:_object$parsedStyle$d2;return commands.reduce(function(prev,cur){var path='';if(cur[0]==='M'||cur[0]==='L'){var p=fromValues$2(cur[1]-defX,cur[2]-defY,0);if(transform){transformMat4(p,p,transform);}path=""+cur[0]+p[0]+","+p[1];}else if(cur[0]==='Z'){path=cur[0];}else if(cur[0]==='C'){var p1=fromValues$2(cur[1]-defX,cur[2]-defY,0);var p2=fromValues$2(cur[3]-defX,cur[4]-defY,0);var p3=fromValues$2(cur[5]-defX,cur[6]-defY,0);if(transform){transformMat4(p1,p1,transform);transformMat4(p2,p2,transform);transformMat4(p3,p3,transform);}path=""+cur[0]+p1[0]+","+p1[1]+","+p2[0]+","+p2[1]+","+p3[0]+","+p3[1];}else if(cur[0]==='A'){var c=fromValues$2(cur[6]-defX,cur[7]-defY,0);if(transform){transformMat4(c,c,transform);}path=""+cur[0]+cur[1]+","+cur[2]+","+cur[3]+","+cur[4]+","+cur[5]+","+c[0]+","+c[1];}return prev+=path;},'');}function lineToCommands(x1,y1,x2,y2){return [['M',x1,y1],['L',x2,y2]];}function ellipseToCommands(rx,ry,cx,cy){var factor=(-1+Math.sqrt(2))/3*4;var dx=rx*factor;var dy=ry*factor;var left=cx-rx;var right=cx+rx;var top=cy-ry;var bottom=cy+ry;return [['M',left,cy],['C',left,cy-dy,cx-dx,top,cx,top],['C',cx+dx,top,right,cy-dy,right,cy],['C',right,cy+dy,cx+dx,bottom,cx,bottom],['C',cx-dx,bottom,left,cy+dy,left,cy],['Z']];}function polygonToCommands(points,closed){var result=points.map(function(point,i){return [i===0?'M':'L',point[0],point[1]];});if(closed){result.push(['Z']);}return result;}function rectToCommands(width,height,x,y,radius){// @see https://gist.github.com/danielpquinn/dd966af424030d47e476
|
|
7496
8240
|
if(radius){var tlr=radius[0],trr=radius[1],brr=radius[2],blr=radius[3];var signX=width>0?1:-1;var signY=height>0?1:-1;// sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
|
|
7497
8241
|
var sweepFlag=signX+signY!==0?1:0;return [['M',signX*tlr+x,y],['L',width-signX*trr+x,y],trr?['A',trr,trr,0,0,sweepFlag,width+x,signY*trr+y]:null,['L',width+x,height-signY*brr+y],brr?['A',brr,brr,0,0,sweepFlag,width+x-signX*brr,height+y]:null,['L',x+signX*blr,height+y],blr?['A',blr,blr,0,0,sweepFlag,x,height+y-signY*blr]:null,['L',x,signY*tlr+y],tlr?['A',tlr,tlr,0,0,sweepFlag,signX*tlr+x,y]:null,['Z']].filter(function(command){return command;});}return [['M',x,y],['L',x+width,y],['L',x+width,y+height],['L',x,y+height],['Z']];}/**
|
|
7498
8242
|
* convert object to path, should account for:
|
|
7499
8243
|
* * transform & origin
|
|
7500
8244
|
* * anchor
|
|
7501
8245
|
* * lineWidth
|
|
7502
|
-
*/function convertToPath(object,
|
|
7503
|
-
var isClosed=pathArray[pathArray.length-1][0]==='Z';var offsetX=i===pathArray.length-(isClosed?2:1)?endOffsetX:0;var offsetY=i===pathArray.length-(isClosed?2:1)?endOffsetY:0;switch(command){case'M':return "M "+(params[1]-x+startOffsetX)+","+(params[2]-y+startOffsetY);case'L':return "L "+(params[1]-x+offsetX)+","+(params[2]-y+offsetY);case'Q':return "Q "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x+offsetX)+" "+(params[4]-y+offsetY);case'C':return "C "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x)+" "+(params[4]-y)+","+(params[5]-x+offsetX)+" "+(params[6]-y+offsetY);case'A':return "A "+params[1]+" "+params[2]+" "+params[3]+" "+params[4]+" "+params[5]+" "+(params[6]-x+offsetX)+" "+(params[7]-y+offsetY);case'Z':return 'Z';}}).join(' ');if(~newValue.indexOf('NaN')){return '';}return newValue;}function isFillOrStrokeAffected(pointerEvents,fill,stroke){// account for pointerEvents
|
|
8246
|
+
*/function convertToPath(object,transform){if(transform===void 0){transform=object.getLocalTransform();}var commands=[];switch(object.nodeName){case exports.Shape.LINE:var _object$parsedStyle2=object.parsedStyle,x1=_object$parsedStyle2.x1,y1=_object$parsedStyle2.y1,x2=_object$parsedStyle2.x2,y2=_object$parsedStyle2.y2;commands=lineToCommands(x1,y1,x2,y2);break;case exports.Shape.CIRCLE:{var _object$parsedStyle3=object.parsedStyle,r=_object$parsedStyle3.r,cx=_object$parsedStyle3.cx,cy=_object$parsedStyle3.cy;commands=ellipseToCommands(r,r,cx,cy);break;}case exports.Shape.ELLIPSE:{var _object$parsedStyle4=object.parsedStyle,rx=_object$parsedStyle4.rx,ry=_object$parsedStyle4.ry,_cx=_object$parsedStyle4.cx,_cy=_object$parsedStyle4.cy;commands=ellipseToCommands(rx,ry,_cx,_cy);break;}case exports.Shape.POLYLINE:case exports.Shape.POLYGON:var points=object.parsedStyle.points;commands=polygonToCommands(points.points,object.nodeName===exports.Shape.POLYGON);break;case exports.Shape.RECT:var _object$parsedStyle5=object.parsedStyle,width=_object$parsedStyle5.width,height=_object$parsedStyle5.height,x=_object$parsedStyle5.x,y=_object$parsedStyle5.y,radius=_object$parsedStyle5.radius;var hasRadius=radius&&radius.some(function(r){return r!==0;});commands=rectToCommands(width,height,x,y,hasRadius&&radius.map(function(r){return clamp(r,0,Math.min(Math.abs(width)/2,Math.abs(height)/2));}));break;case exports.Shape.PATH:var _object$parsedStyle$p=object.parsedStyle.path,curve=_object$parsedStyle$p.curve,zCommandIndexes=_object$parsedStyle$p.zCommandIndexes;commands=[].concat(curve);zCommandIndexes.forEach(function(zIndex,index){commands.splice(zIndex+index+1,0,['Z']);});break;}if(commands.length){return commandsToPathString(commands,object,transform);}}function translatePathToString(pathArray,x,y,startOffsetX,startOffsetY,endOffsetX,endOffsetY){if(startOffsetX===void 0){startOffsetX=0;}if(startOffsetY===void 0){startOffsetY=0;}if(endOffsetX===void 0){endOffsetX=0;}if(endOffsetY===void 0){endOffsetY=0;}var newValue=pathArray.map(function(params,i){var command=params[0];var isClosed=pathArray[pathArray.length-1][0]==='Z';var offsetX=i===pathArray.length-(isClosed?2:1)?endOffsetX:0;var offsetY=i===pathArray.length-(isClosed?2:1)?endOffsetY:0;switch(command){case'M':return "M "+(params[1]-x+startOffsetX)+","+(params[2]-y+startOffsetY);case'L':return "L "+(params[1]-x+offsetX)+","+(params[2]-y+offsetY);case'Q':return "Q "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x+offsetX)+" "+(params[4]-y+offsetY);case'C':return "C "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x)+" "+(params[4]-y)+","+(params[5]-x+offsetX)+" "+(params[6]-y+offsetY);case'A':return "A "+params[1]+" "+params[2]+" "+params[3]+" "+params[4]+" "+params[5]+" "+(params[6]-x+offsetX)+" "+(params[7]-y+offsetY);case'Z':return 'Z';}}).join(' ');if(~newValue.indexOf('NaN')){return '';}return newValue;}function isFillOrStrokeAffected(pointerEvents,fill,stroke){// account for pointerEvents
|
|
7504
8247
|
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
|
|
7505
8248
|
var hasFill=false;var hasStroke=false;var isFillOtherThanNone=!!fill&&!fill.isNone;var isStrokeOtherThanNone=!!stroke&&!stroke.isNone;if(pointerEvents==='visiblepainted'||pointerEvents==='painted'||pointerEvents==='auto'){hasFill=isFillOtherThanNone;hasStroke=isStrokeOtherThanNone;}else if(pointerEvents==='visiblefill'||pointerEvents==='fill'){hasFill=true;}else if(pointerEvents==='visiblestroke'||pointerEvents==='stroke'){hasStroke=true;}else if(pointerEvents==='visible'||pointerEvents==='all'){// The values of the fill and stroke do not affect event processing.
|
|
7506
8249
|
hasFill=true;hasStroke=true;}return [hasFill,hasStroke];}// @ts-nocheck
|
|
@@ -7641,7 +8384,7 @@
|
|
|
7641
8384
|
{n:'text',l:true,d:'',syntax:exports.PropertySyntax.TEXT,p:50},{n:'textTransform',l:true,inh:true,k:['capitalize','uppercase','lowercase','none'],d:'none',syntax:exports.PropertySyntax.TEXT_TRANSFORM,p:51// it must get parsed after text
|
|
7642
8385
|
},{n:'font',l:true},{n:'fontSize',int:true,inh:true,/**
|
|
7643
8386
|
* @see https://www.w3schools.com/css/css_font_size.asp
|
|
7644
|
-
*/d:'16px',l:true,syntax:exports.PropertySyntax.LENGTH_PERCENTAGE},{n:'fontFamily',l:true,inh:true,d:'sans-serif'},{n:'fontStyle',l:true,inh:true,k:['normal','italic','oblique'],d:'normal'},{n:'fontWeight',l:true,inh:true,k:['normal','bold','bolder','lighter'],d:'normal'},{n:'fontVariant',l:true,inh:true,k:['normal','small-caps'],d:'normal'},{n:'lineHeight',l:true,syntax:exports.PropertySyntax.LENGTH,int:true,d:'0'},{n:'letterSpacing',l:true,syntax:exports.PropertySyntax.LENGTH,int:true,d:'0'},{n:'miterLimit',l:true,syntax:exports.PropertySyntax.NUMBER,d:function d(nodeName){if(nodeName===exports.Shape.PATH||nodeName===exports.Shape.POLYGON||nodeName===exports.Shape.POLYLINE){return '4';}return '10';}},{n:'wordWrap',l:true},{n:'wordWrapWidth',l:true},{n:'maxLines',l:true},{n:'textOverflow',l:true,d:'clip'},{n:'leading',l:true},{n:'textBaseline',l:true,inh:true,k:['top','hanging','middle','alphabetic','ideographic','bottom'],d:'alphabetic'},{n:'textAlign',l:true,inh:true,k:['start','center','end','left','right'],d:'start'},// {
|
|
8387
|
+
*/d:'16px',l:true,syntax:exports.PropertySyntax.LENGTH_PERCENTAGE},{n:'fontFamily',l:true,inh:true,d:'sans-serif'},{n:'fontStyle',l:true,inh:true,k:['normal','italic','oblique'],d:'normal'},{n:'fontWeight',l:true,inh:true,k:['normal','bold','bolder','lighter'],d:'normal'},{n:'fontVariant',l:true,inh:true,k:['normal','small-caps'],d:'normal'},{n:'lineHeight',l:true,syntax:exports.PropertySyntax.LENGTH,int:true,d:'0'},{n:'letterSpacing',l:true,syntax:exports.PropertySyntax.LENGTH,int:true,d:'0'},{n:'miterLimit',l:true,syntax:exports.PropertySyntax.NUMBER,d:function d(nodeName){if(nodeName===exports.Shape.PATH||nodeName===exports.Shape.POLYGON||nodeName===exports.Shape.POLYLINE){return '4';}return '10';}},{n:'wordWrap',l:true},{n:'wordWrapWidth',l:true},{n:'maxLines',l:true},{n:'textOverflow',l:true,d:'clip'},{n:'leading',l:true},{n:'textBaseline',l:true,inh:true,k:['top','hanging','middle','alphabetic','ideographic','bottom'],d:'alphabetic'},{n:'textAlign',l:true,inh:true,k:['start','center','middle','end','left','right'],d:'start'},// {
|
|
7645
8388
|
// n: 'whiteSpace',
|
|
7646
8389
|
// l: true,
|
|
7647
8390
|
// },
|
|
@@ -7656,7 +8399,7 @@
|
|
|
7656
8399
|
*
|
|
7657
8400
|
* * calculate used value
|
|
7658
8401
|
* * post process
|
|
7659
|
-
*/;_proto.processProperties=function processProperties(object,attributes,options){var _this2=this;if(options===void 0){options={skipUpdateAttribute:false,skipParse:false,forceUpdateGeometry:false,usedAttributes:[]};}var _options=options,skipUpdateAttribute=_options.skipUpdateAttribute,skipParse=_options.skipParse,forceUpdateGeometry=_options.forceUpdateGeometry,usedAttributes=_options.usedAttributes;var needUpdateGeometry=forceUpdateGeometry;var attributeNames=Object.keys(attributes);attributeNames.forEach(function(attributeName){var _propertyMetadataCach;var
|
|
8402
|
+
*/;_proto.processProperties=function processProperties(object,attributes,options){var _this2=this;if(options===void 0){options={skipUpdateAttribute:false,skipParse:false,forceUpdateGeometry:false,usedAttributes:[]};}var _options=options,skipUpdateAttribute=_options.skipUpdateAttribute,skipParse=_options.skipParse,forceUpdateGeometry=_options.forceUpdateGeometry,usedAttributes=_options.usedAttributes;var needUpdateGeometry=forceUpdateGeometry;var attributeNames=Object.keys(attributes);attributeNames.forEach(function(attributeName){var _propertyMetadataCach;var name=formatAttributeName(attributeName);if(!skipUpdateAttribute){object.attributes[name]=attributes[attributeName];}if(!needUpdateGeometry&&((_propertyMetadataCach=propertyMetadataCache[name])===null||_propertyMetadataCach===void 0?void 0:_propertyMetadataCach.l)){needUpdateGeometry=true;}});if(!skipParse){attributeNames.forEach(function(name){object.computedStyle[name]=_this2.parseProperty(name,object.attributes[name],object);});}// let hasUnresolvedProperties = false;
|
|
7660
8403
|
// parse according to priority
|
|
7661
8404
|
attributeNames=sortAttributeNames((usedAttributes===null||usedAttributes===void 0?void 0:usedAttributes.length)?Array.from(new Set(attributeNames.concat(usedAttributes))):attributeNames);// attributeNames.sort((a, b) => priorityMap[a] - priorityMap[b]);
|
|
7662
8405
|
attributeNames.forEach(function(name){// some style props maybe deleted after parsing such as `anchor` in Text
|
|
@@ -7806,11 +8549,11 @@
|
|
|
7806
8549
|
*/ // eslint-disable-next-line @typescript-eslint/ban-types
|
|
7807
8550
|
;_proto.emit=function emit(eventName,object){this.dispatchEvent(new CustomEvent(eventName,object));}/**
|
|
7808
8551
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
|
|
7809
|
-
*/;_proto.dispatchEvent=function dispatchEvent(e){if(!(e instanceof FederatedEvent)){throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');}// should account for Element / Document / Canvas
|
|
8552
|
+
*/;_proto.dispatchEvent=function dispatchEvent(e,skipPropagate){if(skipPropagate===void 0){skipPropagate=false;}if(!(e instanceof FederatedEvent)){throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');}// should account for Element / Document / Canvas
|
|
7810
8553
|
var canvas;// @ts-ignore
|
|
7811
8554
|
if(this.document){canvas=this;// @ts-ignore
|
|
7812
8555
|
}else if(this.defaultView){canvas=this.defaultView;}else {var _this$ownerDocument;canvas=(_this$ownerDocument=this.ownerDocument)===null||_this$ownerDocument===void 0?void 0:_this$ownerDocument.defaultView;}// assign event manager
|
|
7813
|
-
if(canvas){var _e$manager;e.manager=canvas.getEventService()||null;if(!e.manager){return false;}e.defaultPrevented=false;e.path=[];e.target=this;(_e$manager=e.manager)===null||_e$manager===void 0?void 0:_e$manager.dispatchEvent(e);}return !e.defaultPrevented;};return EventTarget;}();/**
|
|
8556
|
+
if(canvas){var _e$manager;e.manager=canvas.getEventService()||null;if(!e.manager){return false;}e.defaultPrevented=false;e.path=[];if(!skipPropagate){e.target=this;}(_e$manager=e.manager)===null||_e$manager===void 0?void 0:_e$manager.dispatchEvent(e,e.type,skipPropagate);}return !e.defaultPrevented;};return EventTarget;}();/**
|
|
7814
8557
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node
|
|
7815
8558
|
*/var Node=/*#__PURE__*/function(_EventTarget){_inheritsLoose(Node,_EventTarget);function Node(){var _this;for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_EventTarget.call.apply(_EventTarget,[this].concat(args))||this;_this.shadow=false;_this.ownerDocument=null;_this.isConnected=false;_this.baseURI='';_this.childNodes=[];_this.nodeType=0;_this.nodeName='';_this.nodeValue=null;_this.parentNode=null;return _this;}Node.isNode=function isNode(target){return !!target.childNodes;};var _proto=Node.prototype;/**
|
|
7816
8559
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/getRootNode
|
|
@@ -8002,7 +8745,7 @@
|
|
|
8002
8745
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames
|
|
8003
8746
|
*/_proto.getAttributeNames=function getAttributeNames(){return Object.keys(this.attributes);}/**
|
|
8004
8747
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
|
|
8005
|
-
*/;_proto.getAttribute=function getAttribute(name){var value=this.attributes[name];if(value===undefined){var
|
|
8748
|
+
*/;_proto.getAttribute=function getAttribute(name){var value=this.attributes[name];if(value===undefined){var attributeName=formatAttributeName(name);value=this.attributes[attributeName];// if the given attribute does not exist, the value returned will either be null or ""
|
|
8006
8749
|
return isNil(value)?null:value;}else {return value;}}/**
|
|
8007
8750
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
|
|
8008
8751
|
*/;_proto.hasAttribute=function hasAttribute(qualifiedName){return this.getAttributeNames().includes(qualifiedName);}/**
|
|
@@ -8045,7 +8788,7 @@
|
|
|
8045
8788
|
* which can lead to unintended consequences if an attempt is made to cache the entire event object.
|
|
8046
8789
|
*
|
|
8047
8790
|
* Therefore, while keeping the above performance considerations in mind, it is possible to provide a clone method that creates a new object when the user really wants to cache it, e.g.
|
|
8048
|
-
*/;_proto.clone=function clone(){return this.manager.clonePointerEvent(this);};return FederatedPointerEvent;}(FederatedMouseEvent);var FederatedWheelEvent=/*#__PURE__*/function(_FederatedMouseEvent){_inheritsLoose(FederatedWheelEvent,_FederatedMouseEvent);function FederatedWheelEvent(){var _this;for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_FederatedMouseEvent.call.apply(_FederatedMouseEvent,[this].concat(args))||this;_this.deltaMode=void 0;_this.deltaX=void 0;_this.deltaY=void 0;_this.deltaZ=void 0;_this.DOM_DELTA_LINE=0;_this.DOM_DELTA_PAGE=1;_this.DOM_DELTA_PIXEL=2;return _this;}var _proto=FederatedWheelEvent.prototype;_proto.clone=function clone(){return this.manager.cloneWheelEvent(this);};return FederatedWheelEvent;}(FederatedMouseEvent);var mutationEvent=new MutationEvent(exports.ElementEvent.ATTR_MODIFIED,null,null,null,null,MutationEvent.MODIFICATION,null,null);var DEFAULT_STYLE_PROPS={anchor:'',opacity:'',fillOpacity:'',strokeOpacity:'',fill:'',stroke:'',transform:'',transformOrigin:'',visibility:'',pointerEvents:'',lineWidth:'',lineCap:'',lineJoin:'',increasedLineWidthForHitTesting:'',fontSize:'',fontFamily:'',fontStyle:'',fontWeight:'',fontVariant:'',textAlign:'',textBaseline:'',textTransform:'',zIndex:'',filter:'',shadowType:''};var DEFAULT_PARSED_STYLE_PROPS={anchor:[0,0],fill:noneColor,stroke:noneColor,transform:[],zIndex:0,filter:[],shadowType:'outer'};/**
|
|
8791
|
+
*/;_proto.clone=function clone(){return this.manager.clonePointerEvent(this);};return FederatedPointerEvent;}(FederatedMouseEvent);var FederatedWheelEvent=/*#__PURE__*/function(_FederatedMouseEvent){_inheritsLoose(FederatedWheelEvent,_FederatedMouseEvent);function FederatedWheelEvent(){var _this;for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_FederatedMouseEvent.call.apply(_FederatedMouseEvent,[this].concat(args))||this;_this.deltaMode=void 0;_this.deltaX=void 0;_this.deltaY=void 0;_this.deltaZ=void 0;_this.DOM_DELTA_LINE=0;_this.DOM_DELTA_PAGE=1;_this.DOM_DELTA_PIXEL=2;return _this;}var _proto=FederatedWheelEvent.prototype;_proto.clone=function clone(){return this.manager.cloneWheelEvent(this);};return FederatedWheelEvent;}(FederatedMouseEvent);var mutationEvent=new MutationEvent(exports.ElementEvent.ATTR_MODIFIED,null,null,null,null,MutationEvent.MODIFICATION,null,null);var DEFAULT_STYLE_PROPS={anchor:'',opacity:'',fillOpacity:'',strokeOpacity:'',fill:'',stroke:'',transform:'',transformOrigin:'',visibility:'',pointerEvents:'',lineWidth:'',lineCap:'',lineJoin:'',increasedLineWidthForHitTesting:'',fontSize:'',fontFamily:'',fontStyle:'',fontWeight:'',fontVariant:'',textAlign:'',textBaseline:'',textTransform:'',zIndex:'',filter:'',shadowType:''};var DEFAULT_PARSED_STYLE_PROPS={anchor:[0,0],fill:noneColor,stroke:noneColor,transform:[],zIndex:0,filter:[],shadowType:'outer'};var INHERITABLE_STYLE_PROPS=['opacity','fillOpacity','strokeOpacity','transformOrigin','visibility','pointerEvents','lineWidth','lineCap','lineJoin','increasedLineWidthForHitTesting','fontSize','fontFamily','fontStyle','fontWeight','fontVariant','textAlign','textBaseline','textTransform'];/**
|
|
8049
8792
|
* prototype chains: DisplayObject -> Element -> Node -> EventTarget
|
|
8050
8793
|
*
|
|
8051
8794
|
* mixins: Animatable, Transformable, Visible
|
|
@@ -8068,7 +8811,7 @@
|
|
|
8068
8811
|
* push to active animations after calling `animate()`
|
|
8069
8812
|
*/function DisplayObject(config){var _this$config$capture;var _this;_this=_Element.call(this)||this;// assign name, id to config
|
|
8070
8813
|
// eg. group.get('name')
|
|
8071
|
-
_this.config=void 0;_this.isCustomElement=false;_this.activeAnimations=[];_this.getClip=function(){return this.style.clipPath||null;};_this.config=config;// compatible with G 3.0
|
|
8814
|
+
_this.config=void 0;_this.isCustomElement=false;_this.isMutationObserved=false;_this.activeAnimations=[];_this.getClip=function(){return this.style.clipPath||null;};_this.config=config;// compatible with G 3.0
|
|
8072
8815
|
_this.config.interactive=(_this$config$capture=_this.config.capture)!==null&&_this$config$capture!==void 0?_this$config$capture:_this.config.interactive;// init scene graph node
|
|
8073
8816
|
_this.id=_this.config.id||'';_this.name=_this.config.name||'';if(_this.config.className||_this.config.class){_this.className=_this.config.className||_this.config.class;}_this.nodeName=_this.config.type||exports.Shape.GROUP;// compatible with G 3.0
|
|
8074
8817
|
_this.config.style=_extends({},_this.config.style,_this.config.attrs);if(_this.config.visible!=null){_this.config.style.visibility=_this.config.visible===false?'hidden':'visible';}if(_this.config.interactive!=null){_this.config.style.pointerEvents=_this.config.interactive===false?'none':'auto';}// merge parsed value
|
|
@@ -8087,19 +8830,12 @@
|
|
|
8087
8830
|
id:this.id,name:this.name,className:this.name,interactive:this.interactive,style:clonedStyle});// apply transform
|
|
8088
8831
|
cloned.setLocalTransform(this.getLocalTransform());if(deep){this.children.forEach(function(child){// skip marker
|
|
8089
8832
|
if(!child.style.isMarker){var clonedChild=child.cloneNode(deep);cloned.appendChild(clonedChild);}});}return cloned;};_proto.initAttributes=function initAttributes(attributes){if(attributes===void 0){attributes={};}var renderable=this.renderable;// account for FCP, process properties as less as possible
|
|
8090
|
-
runtime.styleValueRegistry.processProperties(this,attributes,{forceUpdateGeometry:true,usedAttributes:
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
// 'filter',
|
|
8094
|
-
// 'shadowType',
|
|
8095
|
-
// 'fill',
|
|
8096
|
-
// 'stroke',
|
|
8097
|
-
'opacity','fillOpacity','strokeOpacity','transformOrigin','visibility','pointerEvents','lineWidth','lineCap','lineJoin','increasedLineWidthForHitTesting','fontSize','fontFamily','fontStyle','fontWeight','fontVariant','textAlign','textBaseline','textTransform']});// redraw at next frame
|
|
8098
|
-
renderable.dirty=true;};_proto.setAttribute=function setAttribute(name,value,force){if(force===void 0){force=false;}var _formatAttribute=formatAttribute(name,value),attributeName=_formatAttribute[0],attributeValue=_formatAttribute[1];// ignore undefined value
|
|
8099
|
-
if(isUndefined(value)){return;}if(force||attributeValue!==this.attributes[attributeName]){this.internalSetAttribute(attributeName,attributeValue);_Element.prototype.setAttribute.call(this,attributeName,attributeValue);}}/**
|
|
8833
|
+
runtime.styleValueRegistry.processProperties(this,attributes,{forceUpdateGeometry:true,usedAttributes:INHERITABLE_STYLE_PROPS});// redraw at next frame
|
|
8834
|
+
renderable.dirty=true;};_proto.setAttribute=function setAttribute(name,value,force){if(force===void 0){force=false;}var attributeName=formatAttributeName(name);// ignore undefined value
|
|
8835
|
+
if(isUndefined(value)){return;}if(force||value!==this.attributes[attributeName]){this.internalSetAttribute(attributeName,value);_Element.prototype.setAttribute.call(this,attributeName,value);}}/**
|
|
8100
8836
|
* called when attributes get changed or initialized
|
|
8101
8837
|
*/;_proto.internalSetAttribute=function internalSetAttribute(name,value,parseOptions){var _runtime$styleValueRe;if(parseOptions===void 0){parseOptions={};}var renderable=this.renderable;var oldValue=this.attributes[name];var oldParsedValue=this.parsedStyle[name];runtime.styleValueRegistry.processProperties(this,(_runtime$styleValueRe={},_runtime$styleValueRe[name]=value,_runtime$styleValueRe),parseOptions);// redraw at next frame
|
|
8102
|
-
renderable.dirty=true;var newParsedValue=this.parsedStyle[name];if(this.isConnected){mutationEvent.relatedNode=this;mutationEvent.prevValue=oldValue;mutationEvent.newValue=value;mutationEvent.attrName=name;mutationEvent.prevParsedValue=oldParsedValue;mutationEvent.newParsedValue=newParsedValue;this.dispatchEvent(mutationEvent);}if((this.isCustomElement&&this.isConnected||!this.isCustomElement)&&this.attributeChangedCallback){this.attributeChangedCallback(name,oldValue,value,oldParsedValue,newParsedValue);}}// #region transformable
|
|
8838
|
+
renderable.dirty=true;var newParsedValue=this.parsedStyle[name];if(this.isConnected){mutationEvent.relatedNode=this;mutationEvent.prevValue=oldValue;mutationEvent.newValue=value;mutationEvent.attrName=name;mutationEvent.prevParsedValue=oldParsedValue;mutationEvent.newParsedValue=newParsedValue;if(this.isMutationObserved){this.dispatchEvent(mutationEvent);}else {mutationEvent.target=this;this.ownerDocument.defaultView.dispatchEvent(mutationEvent,true);}}if((this.isCustomElement&&this.isConnected||!this.isCustomElement)&&this.attributeChangedCallback){this.attributeChangedCallback(name,oldValue,value,oldParsedValue,newParsedValue);}}// #region transformable
|
|
8103
8839
|
/**
|
|
8104
8840
|
* returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
|
|
8105
8841
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
|
|
@@ -8257,9 +8993,9 @@
|
|
|
8257
8993
|
* Also support for using marker.
|
|
8258
8994
|
*/var Line=/*#__PURE__*/function(_DisplayObject){_inheritsLoose(Line,_DisplayObject);function Line(_temp){var _this;var _ref=_temp===void 0?{}:_temp,style=_ref.style,rest=_objectWithoutPropertiesLoose(_ref,_excluded$6);_this=_DisplayObject.call(this,_extends({type:exports.Shape.LINE,style:_extends({x1:0,y1:0,x2:0,y2:0,z1:0,z2:0,isBillboard:false},style)},rest))||this;_this.markerStartAngle=0;_this.markerEndAngle=0;var _this$parsedStyle=_this.parsedStyle,markerStart=_this$parsedStyle.markerStart,markerEnd=_this$parsedStyle.markerEnd;if(markerStart&&markerStart instanceof DisplayObject){_this.markerStartAngle=markerStart.getLocalEulerAngles();_this.appendChild(markerStart);}if(markerEnd&&markerEnd instanceof DisplayObject){_this.markerEndAngle=markerEnd.getLocalEulerAngles();_this.appendChild(markerEnd);}_this.transformMarker(true);_this.transformMarker(false);return _this;}var _proto=Line.prototype;_proto.attributeChangedCallback=function attributeChangedCallback(attrName,oldValue,newValue,prevParsedValue,newParsedValue){if(attrName==='x1'||attrName==='y1'||attrName==='x2'||attrName==='y2'||attrName==='markerStartOffset'||attrName==='markerEndOffset'){this.transformMarker(true);this.transformMarker(false);}else if(attrName==='markerStart'){if(prevParsedValue&&prevParsedValue instanceof DisplayObject){this.markerStartAngle=0;prevParsedValue.remove();}// CSSKeyword 'unset'
|
|
8259
8995
|
if(newParsedValue&&newParsedValue instanceof DisplayObject){this.markerStartAngle=newParsedValue.getLocalEulerAngles();this.appendChild(newParsedValue);this.transformMarker(true);}}else if(attrName==='markerEnd'){if(prevParsedValue&&prevParsedValue instanceof DisplayObject){this.markerEndAngle=0;prevParsedValue.remove();}if(newParsedValue&&newParsedValue instanceof DisplayObject){this.markerEndAngle=newParsedValue.getLocalEulerAngles();this.appendChild(newParsedValue);this.transformMarker(false);}}};_proto.transformMarker=function transformMarker(isStart){var _this$parsedStyle2=this.parsedStyle,markerStart=_this$parsedStyle2.markerStart,markerEnd=_this$parsedStyle2.markerEnd,markerStartOffset=_this$parsedStyle2.markerStartOffset,markerEndOffset=_this$parsedStyle2.markerEndOffset,x1=_this$parsedStyle2.x1,x2=_this$parsedStyle2.x2,y1=_this$parsedStyle2.y1,y2=_this$parsedStyle2.y2,defX=_this$parsedStyle2.defX,defY=_this$parsedStyle2.defY;var marker=isStart?markerStart:markerEnd;if(!marker||!(marker instanceof DisplayObject)){return;}var rad=0;var x;var y;var ox;var oy;var offset;var originalAngle;if(isStart){ox=x1-defX;oy=y1-defY;x=x2-x1;y=y2-y1;offset=markerStartOffset||0;originalAngle=this.markerStartAngle;}else {ox=x2-defX;oy=y2-defY;x=x1-x2;y=y1-y2;offset=markerEndOffset||0;originalAngle=this.markerEndAngle;}rad=Math.atan2(y,x);// account for markerOffset
|
|
8260
|
-
marker.setLocalEulerAngles(rad*180/Math.PI+originalAngle);marker.setLocalPosition(ox+Math.cos(rad)*offset,oy+Math.sin(rad)*offset);};_proto.getPoint=function getPoint(ratio){// TODO: account for z1/z2 in 3D line
|
|
8261
|
-
var _this$parsedStyle3=this.parsedStyle,x1=_this$parsedStyle3.x1,y1=_this$parsedStyle3.y1,x2=_this$parsedStyle3.x2,y2=_this$parsedStyle3.y2,defX=_this$parsedStyle3.defX,defY=_this$parsedStyle3.defY;var _LineUtil$pointAt=line.pointAt(x1,y1,x2,y2,ratio),x=_LineUtil$pointAt.x,y=_LineUtil$pointAt.y;var transformed=transformMat4(create$2(),fromValues$2(x-defX,y-defY,0),this.getLocalTransform());// apply local transformation
|
|
8262
|
-
return new Point(transformed[0],transformed[1]);};_proto.getPointAtLength=function getPointAtLength(distance){return this.getPoint(distance/this.getTotalLength());};_proto.getTotalLength=function getTotalLength(){// TODO: account for z1/z2 in 3D line
|
|
8996
|
+
marker.setLocalEulerAngles(rad*180/Math.PI+originalAngle);marker.setLocalPosition(ox+Math.cos(rad)*offset,oy+Math.sin(rad)*offset);};_proto.getPoint=function getPoint(ratio,inWorldSpace){if(inWorldSpace===void 0){inWorldSpace=false;}// TODO: account for z1/z2 in 3D line
|
|
8997
|
+
var _this$parsedStyle3=this.parsedStyle,x1=_this$parsedStyle3.x1,y1=_this$parsedStyle3.y1,x2=_this$parsedStyle3.x2,y2=_this$parsedStyle3.y2,defX=_this$parsedStyle3.defX,defY=_this$parsedStyle3.defY;var _LineUtil$pointAt=line.pointAt(x1,y1,x2,y2,ratio),x=_LineUtil$pointAt.x,y=_LineUtil$pointAt.y;var transformed=transformMat4(create$2(),fromValues$2(x-defX,y-defY,0),inWorldSpace?this.getWorldTransform():this.getLocalTransform());// apply local transformation
|
|
8998
|
+
return new Point(transformed[0],transformed[1]);};_proto.getPointAtLength=function getPointAtLength(distance,inWorldSpace){if(inWorldSpace===void 0){inWorldSpace=false;}return this.getPoint(distance/this.getTotalLength(),inWorldSpace);};_proto.getTotalLength=function getTotalLength(){// TODO: account for z1/z2 in 3D line
|
|
8263
8999
|
var _this$parsedStyle4=this.parsedStyle,x1=_this$parsedStyle4.x1,y1=_this$parsedStyle4.y1,x2=_this$parsedStyle4.x2,y2=_this$parsedStyle4.y2;return line.length(x1,y1,x2,y2);};return Line;}(DisplayObject);var _excluded$7=["style"];var Path=/*#__PURE__*/function(_DisplayObject){_inheritsLoose(Path,_DisplayObject);/**
|
|
8264
9000
|
* markers placed at the mid
|
|
8265
9001
|
*/function Path(_temp){var _this;var _ref=_temp===void 0?{}:_temp,style=_ref.style,rest=_objectWithoutPropertiesLoose(_ref,_excluded$7);_this=_DisplayObject.call(this,_extends({type:exports.Shape.PATH,style:_extends({path:'',miterLimit:''},style)},rest))||this;_this.markerStartAngle=0;_this.markerEndAngle=0;_this.markerMidList=[];var _this$parsedStyle=_this.parsedStyle,markerStart=_this$parsedStyle.markerStart,markerEnd=_this$parsedStyle.markerEnd,markerMid=_this$parsedStyle.markerMid;if(markerStart&&markerStart instanceof DisplayObject){_this.markerStartAngle=markerStart.getLocalEulerAngles();_this.appendChild(markerStart);}if(markerMid&&markerMid instanceof DisplayObject){_this.placeMarkerMid(markerMid);}if(markerEnd&&markerEnd instanceof DisplayObject){_this.markerEndAngle=markerEnd.getLocalEulerAngles();_this.appendChild(markerEnd);}_this.transformMarker(true);_this.transformMarker(false);return _this;}var _proto=Path.prototype;_proto.attributeChangedCallback=function attributeChangedCallback(attrName,oldValue,newValue,prevParsedValue,newParsedValue){if(attrName==='path'){// recalc markers
|
|
@@ -8274,10 +9010,10 @@
|
|
|
8274
9010
|
*/;_proto.getTotalLength=function getTotalLength(){return getOrCalculatePathTotalLength(this);}/**
|
|
8275
9011
|
* Returns the point at a given distance along the path.
|
|
8276
9012
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength
|
|
8277
|
-
*/;_proto.getPointAtLength=function getPointAtLength$1(distance){var _this$parsedStyle4=this.parsedStyle,defX=_this$parsedStyle4.defX,defY=_this$parsedStyle4.defY,absolutePath=_this$parsedStyle4.path.absolutePath;var _getPointAtLength2=getPointAtLength(absolutePath,distance),x=_getPointAtLength2.x,y=_getPointAtLength2.y;var transformed=transformMat4(create$2(),fromValues$2(x-defX,y-defY,0),this.getLocalTransform());// apply local transformation
|
|
9013
|
+
*/;_proto.getPointAtLength=function getPointAtLength$1(distance,inWorldSpace){if(inWorldSpace===void 0){inWorldSpace=false;}var _this$parsedStyle4=this.parsedStyle,defX=_this$parsedStyle4.defX,defY=_this$parsedStyle4.defY,absolutePath=_this$parsedStyle4.path.absolutePath;var _getPointAtLength2=getPointAtLength(absolutePath,distance),x=_getPointAtLength2.x,y=_getPointAtLength2.y;var transformed=transformMat4(create$2(),fromValues$2(x-defX,y-defY,0),inWorldSpace?this.getWorldTransform():this.getLocalTransform());// apply local transformation
|
|
8278
9014
|
return new Point(transformed[0],transformed[1]);}/**
|
|
8279
9015
|
* Returns the point at a given ratio of the total length in path.
|
|
8280
|
-
*/;_proto.getPoint=function getPoint(ratio){return this.getPointAtLength(ratio*getOrCalculatePathTotalLength(this));}/**
|
|
9016
|
+
*/;_proto.getPoint=function getPoint(ratio,inWorldSpace){if(inWorldSpace===void 0){inWorldSpace=false;}return this.getPointAtLength(ratio*getOrCalculatePathTotalLength(this),inWorldSpace);}/**
|
|
8281
9017
|
* Get start tangent vector
|
|
8282
9018
|
*/;_proto.getStartTangent=function getStartTangent(){var segments=this.parsedStyle.path.segments;var result=[];if(segments.length>1){var startPoint=segments[0].currentPoint;var endPoint=segments[1].currentPoint;var tangent=segments[1].startTangent;result=[];if(tangent){result.push([startPoint[0]-tangent[0],startPoint[1]-tangent[1]]);result.push([startPoint[0],startPoint[1]]);}else {result.push([endPoint[0],endPoint[1]]);result.push([startPoint[0],startPoint[1]]);}}return result;}/**
|
|
8283
9019
|
* Get end tangent vector
|
|
@@ -8290,7 +9026,7 @@
|
|
|
8290
9026
|
this.markerMidList.forEach(function(marker){marker.remove();});this.markerMidList=[];if(marker&&marker instanceof DisplayObject){for(var i=1;i<(this.style.isClosed?points.length:points.length-1);i++){var ox=points[i][0]-defX;var oy=points[i][1]-defY;var cloned=i===1?marker:marker.cloneNode(true);this.markerMidList.push(cloned);this.appendChild(cloned);cloned.setLocalPosition(ox,oy);// TODO: orient of marker
|
|
8291
9027
|
}}};return Polygon;}(DisplayObject);var _excluded$9=["style"];/**
|
|
8292
9028
|
* Polyline inherits the marker-related capabilities of Polygon.
|
|
8293
|
-
*/var Polyline=/*#__PURE__*/function(_Polygon){_inheritsLoose(Polyline,_Polygon);function Polyline(_temp){var _ref=_temp===void 0?{}:_temp,style=_ref.style,rest=_objectWithoutPropertiesLoose(_ref,_excluded$9);return _Polygon.call(this,_extends({type:exports.Shape.POLYLINE,style:_extends({points:'',miterLimit:'',isClosed:false},style)},rest))||this;}var _proto=Polyline.prototype;_proto.getTotalLength=function getTotalLength(){return this.parsedStyle.points.totalLength;};_proto.getPointAtLength=function getPointAtLength(distance){return this.getPoint(distance/this.getTotalLength());};_proto.getPoint=function getPoint(ratio){var _this$parsedStyle=this.parsedStyle,defX=_this$parsedStyle.defX,defY=_this$parsedStyle.defY,_this$parsedStyle$poi=_this$parsedStyle.points,points=_this$parsedStyle$poi.points,segments=_this$parsedStyle$poi.segments;var subt=0;var index=0;segments.forEach(function(v,i){if(ratio>=v[0]&&ratio<=v[1]){subt=(ratio-v[0])/(v[1]-v[0]);index=i;}});var _LineUtil$pointAt=line.pointAt(points[index][0],points[index][1],points[index+1][0],points[index+1][1],subt),x=_LineUtil$pointAt.x,y=_LineUtil$pointAt.y;var transformed=transformMat4(create$2(),fromValues$2(x-defX,y-defY,0),this.getLocalTransform());// apply local transformation
|
|
9029
|
+
*/var Polyline=/*#__PURE__*/function(_Polygon){_inheritsLoose(Polyline,_Polygon);function Polyline(_temp){var _ref=_temp===void 0?{}:_temp,style=_ref.style,rest=_objectWithoutPropertiesLoose(_ref,_excluded$9);return _Polygon.call(this,_extends({type:exports.Shape.POLYLINE,style:_extends({points:'',miterLimit:'',isClosed:false},style)},rest))||this;}var _proto=Polyline.prototype;_proto.getTotalLength=function getTotalLength(){return this.parsedStyle.points.totalLength;};_proto.getPointAtLength=function getPointAtLength(distance,inWorldSpace){if(inWorldSpace===void 0){inWorldSpace=false;}return this.getPoint(distance/this.getTotalLength(),inWorldSpace);};_proto.getPoint=function getPoint(ratio,inWorldSpace){if(inWorldSpace===void 0){inWorldSpace=false;}var _this$parsedStyle=this.parsedStyle,defX=_this$parsedStyle.defX,defY=_this$parsedStyle.defY,_this$parsedStyle$poi=_this$parsedStyle.points,points=_this$parsedStyle$poi.points,segments=_this$parsedStyle$poi.segments;var subt=0;var index=0;segments.forEach(function(v,i){if(ratio>=v[0]&&ratio<=v[1]){subt=(ratio-v[0])/(v[1]-v[0]);index=i;}});var _LineUtil$pointAt=line.pointAt(points[index][0],points[index][1],points[index+1][0],points[index+1][1],subt),x=_LineUtil$pointAt.x,y=_LineUtil$pointAt.y;var transformed=transformMat4(create$2(),fromValues$2(x-defX,y-defY,0),inWorldSpace?this.getWorldTransform():this.getLocalTransform());// apply local transformation
|
|
8294
9030
|
return new Point(transformed[0],transformed[1]);};_proto.getStartTangent=function getStartTangent(){var points=this.parsedStyle.points.points;var result=[];result.push([points[1][0],points[1][1]]);result.push([points[0][0],points[0][1]]);return result;};_proto.getEndTangent=function getEndTangent(){var points=this.parsedStyle.points.points;var l=points.length-1;var result=[];result.push([points[l-1][0],points[l-1][1]]);result.push([points[l][0],points[l][1]]);return result;};return Polyline;}(Polygon);var _excluded$a=["style"];var Rect=/*#__PURE__*/function(_DisplayObject){_inheritsLoose(Rect,_DisplayObject);function Rect(_temp){var _ref=_temp===void 0?{}:_temp,style=_ref.style,rest=_objectWithoutPropertiesLoose(_ref,_excluded$a);return _DisplayObject.call(this,_extends({type:exports.Shape.RECT,style:_extends({x:'',y:'',width:'',height:'',radius:''},style)},rest))||this;}return Rect;}(DisplayObject);var _excluded$b=["style"];/**
|
|
8295
9031
|
* <text> @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement
|
|
8296
9032
|
*/var Text=/*#__PURE__*/function(_DisplayObject){_inheritsLoose(Text,_DisplayObject);/**
|
|
@@ -8407,11 +9143,11 @@
|
|
|
8407
9143
|
*/;_proto.setDistance=function setDistance(d){if(this.distance===d||d<0){return this;}this.distance=d;if(this.distance<MIN_DISTANCE){this.distance=MIN_DISTANCE;}this.dollyingStep=this.distance/100;var pos=create$2();d=this.distance;var n=this.forward;var f=this.focalPoint;pos[0]=d*n[0]+f[0];pos[1]=d*n[1]+f[1];pos[2]=d*n[2]+f[2];this._setPosition(pos);this.triggerUpdate();return this;};_proto.setMaxDistance=function setMaxDistance(d){this.maxDistance=d;return this;};_proto.setMinDistance=function setMinDistance(d){this.minDistance=d;return this;}/**
|
|
8408
9144
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
8409
9145
|
* the azimuth in degrees
|
|
8410
|
-
*/;_proto.setAzimuth=function setAzimuth(az){this.azimuth=getAngle(az);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getAzimuth=function getAzimuth(){return this.azimuth;}/**
|
|
9146
|
+
*/;_proto.setAzimuth=function setAzimuth(az){this.azimuth=getAngle$1(az);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getAzimuth=function getAzimuth(){return this.azimuth;}/**
|
|
8411
9147
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
8412
|
-
*/;_proto.setElevation=function setElevation(el){this.elevation=getAngle(el);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getElevation=function getElevation(){return this.elevation;}/**
|
|
9148
|
+
*/;_proto.setElevation=function setElevation(el){this.elevation=getAngle$1(el);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getElevation=function getElevation(){return this.elevation;}/**
|
|
8413
9149
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
8414
|
-
*/;_proto.setRoll=function setRoll(angle){this.roll=getAngle(angle);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getRoll=function getRoll(){return this.roll;}/**
|
|
9150
|
+
*/;_proto.setRoll=function setRoll(angle){this.roll=getAngle$1(angle);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getRoll=function getRoll(){return this.roll;}/**
|
|
8415
9151
|
* 根据相机矩阵重新计算各种相机参数
|
|
8416
9152
|
*/;_proto._update=function _update(){this._getAxes();this._getPosition();this._getDistance();this._getAngles();this._getOrthoMatrix();this.triggerUpdate();}/**
|
|
8417
9153
|
* 计算相机矩阵
|
|
@@ -8439,7 +9175,7 @@
|
|
|
8439
9175
|
var minX=Math.min.apply(Math,points.map(function(point){return point[0];}));var maxX=Math.max.apply(Math,points.map(function(point){return point[0];}));var minY=Math.min.apply(Math,points.map(function(point){return point[1];}));var maxY=Math.max.apply(Math,points.map(function(point){return point[1];}));var width=maxX-minX;var height=maxY-minY;return {width:width,height:height};};return PolylineUpdater;}();var RectUpdater=/*#__PURE__*/function(){function RectUpdater(){}var _proto=RectUpdater.prototype;_proto.update=function update(parsedStyle,object){var img=parsedStyle.img,_parsedStyle$width=parsedStyle.width,width=_parsedStyle$width===void 0?0:_parsedStyle$width,_parsedStyle$height=parsedStyle.height,height=_parsedStyle$height===void 0?0:_parsedStyle$height;var contentWidth=width;var contentHeight=height;// resize with HTMLImageElement's size
|
|
8440
9176
|
if(img&&!isString(img)){if(!contentWidth){contentWidth=img.width;parsedStyle.width=contentWidth;}if(!contentHeight){contentHeight=img.height;parsedStyle.height=contentHeight;}}return {width:contentWidth,height:contentHeight};};return RectUpdater;}();var TextUpdater=/*#__PURE__*/function(){function TextUpdater(globalRuntime){this.globalRuntime=void 0;this.globalRuntime=globalRuntime;}var _proto=TextUpdater.prototype;_proto.isReadyToMeasure=function isReadyToMeasure(parsedStyle,object){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;return text&&fontSize&&fontStyle&&fontWeight&&fontVariant&&textAlign&&textBaseline&&!isNil(lineWidth);};_proto.update=function update(parsedStyle,object){var _object$ownerDocument,_object$ownerDocument2;var text=parsedStyle.text,textAlign=parsedStyle.textAlign,lineWidth=parsedStyle.lineWidth,textBaseline=parsedStyle.textBaseline,dx=parsedStyle.dx,dy=parsedStyle.dy;var _ref=(object===null||object===void 0?void 0:(_object$ownerDocument=object.ownerDocument)===null||_object$ownerDocument===void 0?void 0:(_object$ownerDocument2=_object$ownerDocument.defaultView)===null||_object$ownerDocument2===void 0?void 0:_object$ownerDocument2.getConfig())||{},offscreenCanvas=_ref.offscreenCanvas;if(!this.isReadyToMeasure(parsedStyle,object)){parsedStyle.metrics={font:'',width:0,height:0,lines:[],lineWidths:[],lineHeight:0,maxLineWidth:0,fontProperties:{ascent:0,descent:0,fontSize:0},lineMetrics:[]};return {width:0,height:0,x:0,y:0,offsetX:0,offsetY:0};}var metrics=this.globalRuntime.textService.measureText(text,parsedStyle,offscreenCanvas);parsedStyle.metrics=metrics;var width=metrics.width,height=metrics.height,lineHeight=metrics.lineHeight,fontProperties=metrics.fontProperties;// anchor is left-top by default
|
|
8441
9177
|
var halfExtents=[width/2,height/2,0];// default 'left'
|
|
8442
|
-
var anchor=[0,1];var lineXOffset=0;if(textAlign==='center'){lineXOffset=lineWidth/2;anchor=[0.5,1];}else if(textAlign==='right'||textAlign==='end'){lineXOffset=lineWidth;anchor=[1,1];}var lineYOffset=0;if(textBaseline==='middle'){// eslint-disable-next-line prefer-destructuring
|
|
9178
|
+
var anchor=[0,1];var lineXOffset=0;if(textAlign==='center'||textAlign==='middle'){lineXOffset=lineWidth/2;anchor=[0.5,1];}else if(textAlign==='right'||textAlign==='end'){lineXOffset=lineWidth;anchor=[1,1];}var lineYOffset=0;if(textBaseline==='middle'){// eslint-disable-next-line prefer-destructuring
|
|
8443
9179
|
lineYOffset=halfExtents[1];}else if(textBaseline==='top'||textBaseline==='hanging'){lineYOffset=halfExtents[1]*2;}else if(textBaseline==='alphabetic'){lineYOffset=lineHeight-fontProperties.ascent;}else if(textBaseline==='bottom'||textBaseline==='ideographic'){lineYOffset=0;}// TODO: ideographic & bottom
|
|
8444
9180
|
if(dx){lineXOffset+=dx;}if(dy){lineYOffset+=dy;}// update anchor
|
|
8445
9181
|
parsedStyle.anchor=[anchor[0],anchor[1],0];return {width:halfExtents[0]*2,height:halfExtents[1]*2,offsetX:lineXOffset,offsetY:lineYOffset};};return TextUpdater;}();var PROPAGATION_LIMIT=2048;var EventService=/*#__PURE__*/function(){function EventService(globalRuntime,context){var _this=this;this.globalRuntime=void 0;this.context=void 0;this.rootTarget=void 0;this.emitter=new eventemitter3.EventEmitter();this.cursor='default';this.mappingTable={};this.mappingState={trackingData:{}};this.eventPool=new Map();this.pickHandler=void 0;this.tmpMatrix=create$1();this.tmpVec3=create$2();this.onPointerDown=/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(from){var e,isRightButton,trackingData;return _regeneratorRuntime().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(from instanceof FederatedPointerEvent){_context.next=2;break;}return _context.abrupt("return");case 2:_context.next=4;return _this.createPointerEvent(from);case 4:e=_context.sent;_this.dispatchEvent(e,'pointerdown');if(e.pointerType==='touch'){_this.dispatchEvent(e,'touchstart');}else if(e.pointerType==='mouse'||e.pointerType==='pen'){isRightButton=e.button===2;_this.dispatchEvent(e,isRightButton?'rightdown':'mousedown');}trackingData=_this.trackingData(from.pointerId);trackingData.pressTargetsByButton[from.button]=e.composedPath();_this.freeEvent(e);case 10:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}();this.onPointerUp=/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(from){var now,e,isRightButton,trackingData,pressTarget,clickTarget,currentTarget,_isRightButton,_e$detail,clickEvent,clickHistory;return _regeneratorRuntime().wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:if(from instanceof FederatedPointerEvent){_context2.next=2;break;}return _context2.abrupt("return");case 2:now=performance.now();_context2.next=5;return _this.createPointerEvent(from);case 5:e=_context2.sent;_this.dispatchEvent(e,'pointerup');if(e.pointerType==='touch'){_this.dispatchEvent(e,'touchend');}else if(e.pointerType==='mouse'||e.pointerType==='pen'){isRightButton=e.button===2;_this.dispatchEvent(e,isRightButton?'rightup':'mouseup');}trackingData=_this.trackingData(from.pointerId);pressTarget=_this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);clickTarget=pressTarget;// pointerupoutside only bubbles. It only bubbles upto the parent that doesn't contain
|
|
@@ -8466,7 +9202,9 @@
|
|
|
8466
9202
|
_this.notifyTarget(enterEvent,'mouseenter');}if(Node.isNode(enterEvent.target)){enterEvent.target=enterEvent.target.parentNode;}}trackingData.overTargets=e.composedPath();_this.freeEvent(e);_this.freeEvent(enterEvent);case 16:case"end":return _context5.stop();}}},_callee5);}));return function(_x5){return _ref5.apply(this,arguments);};}();this.onPointerUpOutside=/*#__PURE__*/function(){var _ref6=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(from){var trackingData,pressTarget,e,currentTarget;return _regeneratorRuntime().wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:if(from instanceof FederatedPointerEvent){_context6.next=2;break;}return _context6.abrupt("return");case 2:trackingData=_this.trackingData(from.pointerId);pressTarget=_this.findMountedTarget(trackingData.pressTargetsByButton[from.button]);_context6.next=6;return _this.createPointerEvent(from);case 6:e=_context6.sent;if(pressTarget){currentTarget=pressTarget;while(currentTarget){e.currentTarget=currentTarget;_this.notifyTarget(e,'pointerupoutside');if(e.pointerType==='touch');else if(e.pointerType==='mouse'||e.pointerType==='pen'){_this.notifyTarget(e,e.button===2?'rightupoutside':'mouseupoutside');}if(Node.isNode(currentTarget)){currentTarget=currentTarget.parentNode;}}delete trackingData.pressTargetsByButton[from.button];}_this.freeEvent(e);case 9:case"end":return _context6.stop();}}},_callee6);}));return function(_x6){return _ref6.apply(this,arguments);};}();this.onWheel=/*#__PURE__*/function(){var _ref7=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(from){var wheelEvent;return _regeneratorRuntime().wrap(function _callee7$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:if(from instanceof FederatedWheelEvent){_context7.next=2;break;}return _context7.abrupt("return");case 2:_context7.next=4;return _this.createWheelEvent(from);case 4:wheelEvent=_context7.sent;_this.dispatchEvent(wheelEvent);_this.freeEvent(wheelEvent);case 7:case"end":return _context7.stop();}}},_callee7);}));return function(_x7){return _ref7.apply(this,arguments);};}();this.globalRuntime=globalRuntime;this.context=context;}var _proto=EventService.prototype;_proto.init=function init(){this.rootTarget=this.context.renderingContext.root.parentNode;// document
|
|
8467
9203
|
this.addEventMapping('pointerdown',this.onPointerDown);this.addEventMapping('pointerup',this.onPointerUp);this.addEventMapping('pointermove',this.onPointerMove);this.addEventMapping('pointerout',this.onPointerOut);this.addEventMapping('pointerleave',this.onPointerOut);this.addEventMapping('pointerover',this.onPointerOver);this.addEventMapping('pointerupoutside',this.onPointerUpOutside);this.addEventMapping('wheel',this.onWheel);};_proto.client2Viewport=function client2Viewport(client){var bbox=this.context.contextService.getBoundingClientRect();return new Point(client.x-((bbox===null||bbox===void 0?void 0:bbox.left)||0),client.y-((bbox===null||bbox===void 0?void 0:bbox.top)||0));};_proto.viewport2Client=function viewport2Client(canvas){var bbox=this.context.contextService.getBoundingClientRect();return new Point(canvas.x+((bbox===null||bbox===void 0?void 0:bbox.left)||0),canvas.y+((bbox===null||bbox===void 0?void 0:bbox.top)||0));};_proto.viewport2Canvas=function viewport2Canvas(_ref8){var x=_ref8.x,y=_ref8.y;var canvas=this.rootTarget.defaultView;var camera=canvas.getCamera();var _this$context$config=this.context.config,width=_this$context$config.width,height=_this$context$config.height;var projectionMatrixInverse=camera.getPerspectiveInverse();var worldMatrix=camera.getWorldTransform();var vpMatrix=multiply(this.tmpMatrix,worldMatrix,projectionMatrixInverse);var viewport=set$1(this.tmpVec3,x/width*2-1,(1-y/height)*2-1,0);transformMat4(viewport,viewport,vpMatrix);return new Point(viewport[0],viewport[1]);};_proto.canvas2Viewport=function canvas2Viewport(canvasP){var canvas=this.rootTarget.defaultView;var camera=canvas.getCamera();// World -> Clip
|
|
8468
9204
|
var projectionMatrix=camera.getPerspective();var viewMatrix=camera.getViewTransform();var vpMatrix=multiply(this.tmpMatrix,projectionMatrix,viewMatrix);var clip=set$1(this.tmpVec3,canvasP.x,canvasP.y,0);transformMat4(this.tmpVec3,this.tmpVec3,vpMatrix);// Clip -> NDC -> Viewport, flip Y
|
|
8469
|
-
var _this$context$config2=this.context.config,width=_this$context$config2.width,height=_this$context$config2.height;return new Point((clip[0]+1)/2*width,(1-(clip[1]+1)/2)*height);};_proto.setPickHandler=function setPickHandler(pickHandler){this.pickHandler=pickHandler;};_proto.addEventMapping=function addEventMapping(type,fn){if(!this.mappingTable[type]){this.mappingTable[type]=[];}this.mappingTable[type].push({fn:fn,priority:0});this.mappingTable[type].sort(function(a,b){return a.priority-b.priority;});};_proto.mapEvent=function mapEvent(e){if(!this.rootTarget){return;}var mappers=this.mappingTable[e.type];if(mappers){for(var i=0,j=mappers.length;i<j;i++){mappers[i].fn(e);}}else {console.warn("[EventService]: Event mapping not defined for "+e.type);}};_proto.dispatchEvent=function dispatchEvent(e,type
|
|
9205
|
+
var _this$context$config2=this.context.config,width=_this$context$config2.width,height=_this$context$config2.height;return new Point((clip[0]+1)/2*width,(1-(clip[1]+1)/2)*height);};_proto.setPickHandler=function setPickHandler(pickHandler){this.pickHandler=pickHandler;};_proto.addEventMapping=function addEventMapping(type,fn){if(!this.mappingTable[type]){this.mappingTable[type]=[];}this.mappingTable[type].push({fn:fn,priority:0});this.mappingTable[type].sort(function(a,b){return a.priority-b.priority;});};_proto.mapEvent=function mapEvent(e){if(!this.rootTarget){return;}var mappers=this.mappingTable[e.type];if(mappers){for(var i=0,j=mappers.length;i<j;i++){mappers[i].fn(e);}}else {console.warn("[EventService]: Event mapping not defined for "+e.type);}};_proto.dispatchEvent=function dispatchEvent(e,type,skipPropagate){// Canvas should skip
|
|
9206
|
+
if(!skipPropagate){e.propagationStopped=false;e.propagationImmediatelyStopped=false;this.propagate(e,type);}else {// target phase
|
|
9207
|
+
e.eventPhase=e.AT_TARGET;var canvas=this.rootTarget.defaultView||null;e.currentTarget=canvas;this.notifyListeners(e,type);}this.emitter.emit(type||e.type,e);};_proto.propagate=function propagate(e,type){if(!e.target){return;}// [target, parent, root, Canvas]
|
|
8470
9208
|
var composedPath=e.composedPath();// event flow: capture -> target -> bubbling
|
|
8471
9209
|
// capture phase
|
|
8472
9210
|
e.eventPhase=e.CAPTURING_PHASE;for(var i=composedPath.length-1;i>=1;i--){e.currentTarget=composedPath[i];this.notifyTarget(e,type);if(e.propagationStopped||e.propagationImmediatelyStopped)return;}// target phase
|
|
@@ -8548,7 +9286,7 @@
|
|
|
8548
9286
|
// dirtycheck first
|
|
8549
9287
|
var objectChanged=enableDirtyCheck?this.hooks.dirtycheck.call(displayObject):displayObject;if(objectChanged){var objectToRender=enableCulling?this.hooks.cull.call(objectChanged,this.context.camera):objectChanged;if(objectToRender){this.stats.rendered++;renderingContext.renderListCurrentFrame.push(objectToRender);}}displayObject.renderable.dirty=false;displayObject.sortable.renderOrder=this.zIndexCounter++;this.stats.total++;// sort is very expensive, use cached result if posible
|
|
8550
9288
|
var sortable=displayObject.sortable;var renderOrderChanged=false;if(sortable.dirty){sortable.sorted=displayObject.childNodes.slice().sort(sortByZIndex);renderOrderChanged=true;sortable.dirty=false;}// recursive rendering its children
|
|
8551
|
-
(sortable.sorted||displayObject.childNodes).forEach(function(child){_this2.renderDisplayObject(child,canvasConfig,renderingContext);});if(renderOrderChanged){displayObject.forEach(function(child){_this2.renderOrderChangedEvent.detail={renderOrder:child.sortable.renderOrder};child.dispatchEvent(_this2.renderOrderChangedEvent);});}};_proto.destroy=function destroy(){this.inited=false;this.hooks.destroy.call();};_proto.dirtify=function dirtify(){// need re-render
|
|
9289
|
+
(sortable.sorted||displayObject.childNodes).forEach(function(child){_this2.renderDisplayObject(child,canvasConfig,renderingContext);});if(renderOrderChanged){displayObject.forEach(function(child){_this2.renderOrderChangedEvent.target=child;_this2.renderOrderChangedEvent.detail={renderOrder:child.sortable.renderOrder};child.ownerDocument.defaultView.dispatchEvent(_this2.renderOrderChangedEvent,true);});}};_proto.destroy=function destroy(){this.inited=false;this.hooks.destroy.call();};_proto.dirtify=function dirtify(){// need re-render
|
|
8552
9290
|
this.context.renderingContext.renderReasons.add(exports.RenderReason.DISPLAY_OBJECT_CHANGED);};return RenderingService;}();var ATTRIBUTE_REGEXP=/\[\s*(.*)=(.*)\s*\]/;/**
|
|
8553
9291
|
* support the following DOM API:
|
|
8554
9292
|
* * getElementById
|
|
@@ -8621,7 +9359,7 @@
|
|
|
8621
9359
|
*
|
|
8622
9360
|
* 对应 g 原版的 translate 2D
|
|
8623
9361
|
* @see https://github.com/antvis/g/blob/master/packages/g-base/src/abstract/element.ts#L665-L676
|
|
8624
|
-
*/;_proto.setLocalRotation=function setLocalRotation(element,rotation,y,z,w){if(typeof rotation==='number'){rotation=fromValues$4(rotation,y,z,w);}var transform=element.transformable;copy$3(transform.localRotation,rotation);this.dirtifyLocal(element,transform);};_proto.setLocalSkew=function setLocalSkew(element,skew,y){if(typeof skew==='number'){skew=fromValues$5(skew,y);}var transform=element.transformable;copy$4(transform.localSkew,skew);this.dirtifyLocal(element,transform);};_proto.dirtifyLocal=function dirtifyLocal(element,transform){if(!transform.localDirtyFlag){transform.localDirtyFlag=true;if(!transform.dirtyFlag){this.dirtifyWorld(element,transform);}}};_proto.dirtifyWorld=function dirtifyWorld(element,transform){if(!transform.dirtyFlag){this.unfreezeParentToRoot(element);}this.dirtifyWorldInternal(element,transform);this.dirtifyToRoot(element,true);};_proto.triggerPendingEvents=function triggerPendingEvents(){var _this2=this;var set=new Set();var trigger=function trigger(element,detail){if(
|
|
9362
|
+
*/;_proto.setLocalRotation=function setLocalRotation(element,rotation,y,z,w){if(typeof rotation==='number'){rotation=fromValues$4(rotation,y,z,w);}var transform=element.transformable;copy$3(transform.localRotation,rotation);this.dirtifyLocal(element,transform);};_proto.setLocalSkew=function setLocalSkew(element,skew,y){if(typeof skew==='number'){skew=fromValues$5(skew,y);}var transform=element.transformable;copy$4(transform.localSkew,skew);this.dirtifyLocal(element,transform);};_proto.dirtifyLocal=function dirtifyLocal(element,transform){if(!transform.localDirtyFlag){transform.localDirtyFlag=true;if(!transform.dirtyFlag){this.dirtifyWorld(element,transform);}}};_proto.dirtifyWorld=function dirtifyWorld(element,transform){if(!transform.dirtyFlag){this.unfreezeParentToRoot(element);}this.dirtifyWorldInternal(element,transform);this.dirtifyToRoot(element,true);};_proto.triggerPendingEvents=function triggerPendingEvents(){var _this2=this;var set=new Set();var trigger=function trigger(element,detail){if(element.isConnected&&!set.has(element.entity)){_this2.boundsChangedEvent.detail=detail;_this2.boundsChangedEvent.target=element;element.ownerDocument.defaultView.dispatchEvent(_this2.boundsChangedEvent,true);set.add(element.entity);}};this.pendingEvents.forEach(function(_ref){var element=_ref[0],detail=_ref[1];if(detail.affectChildren){element.forEach(function(e){trigger(e,detail);});}else {trigger(element,detail);}});this.pendingEvents=[];set.clear();};_proto.dirtifyToRoot=function dirtifyToRoot(element,affectChildren){if(affectChildren===void 0){affectChildren=false;}var p=element;// only need to re-render itself
|
|
8625
9363
|
if(p.renderable){p.renderable.dirty=true;}while(p){var renderable=p.renderable;if(renderable){renderable.renderBoundsDirty=true;renderable.boundsDirty=true;}p=p.parentNode;}// inform dependencies
|
|
8626
9364
|
this.informDependentDisplayObjects(element);// reuse the same custom event
|
|
8627
9365
|
this.pendingEvents.push([element,{affectChildren:affectChildren}]);};_proto.updateDisplayObjectDependency=function updateDisplayObjectDependency(name,oldPath,newPath,object){// clear ref to old clip path
|
|
@@ -8690,7 +9428,7 @@
|
|
|
8690
9428
|
// }
|
|
8691
9429
|
lineHeight+=leading;// handle vertical text baseline
|
|
8692
9430
|
var offsetY=0;if(textBaseline==='middle'){offsetY=-height/2;}else if(textBaseline==='bottom'||textBaseline==='alphabetic'||textBaseline==='ideographic'){offsetY=-height;}else if(textBaseline==='top'||textBaseline==='hanging'){offsetY=0;}return {font:font,width:_width,height:height,lines:lines,lineWidths:lineWidths,lineHeight:lineHeight,maxLineWidth:maxLineWidth,fontProperties:fontProperties,lineMetrics:lineWidths.map(function(width,i){var offsetX=0;// handle horizontal text align
|
|
8693
|
-
if(textAlign==='center'){offsetX-=width/2;}else if(textAlign==='right'||textAlign==='end'){offsetX-=width;}return new Rectangle(offsetX-lineWidth/2,offsetY+i*lineHeight,width+lineWidth,lineHeight);})};}};_proto.setGraphemeOnPath=function setGraphemeOnPath(){};_proto.wordWrap=function wordWrap(text,parsedStyle,offscreenCanvas){var _this2=this;var _parsedStyle$wordWrap=parsedStyle.wordWrapWidth,wordWrapWidth=_parsedStyle$wordWrap===void 0?0:_parsedStyle$wordWrap,letterSpacing=parsedStyle.letterSpacing,_parsedStyle$maxLines=parsedStyle.maxLines,maxLines=_parsedStyle$maxLines===void 0?Infinity:_parsedStyle$maxLines,textOverflow=parsedStyle.textOverflow;var context=this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);var maxWidth=wordWrapWidth+letterSpacing;var ellipsis='';if(textOverflow==='ellipsis'){ellipsis='...';}else if(textOverflow&&textOverflow!=='clip'){ellipsis=textOverflow;}var lines=[];var currentIndex=0;var currentWidth=0;var cache={};var calcWidth=function calcWidth(char){return _this2.getFromCache(char,letterSpacing,cache,context);};var ellipsisWidth=Array.from(ellipsis).reduce(function(prev,cur){return prev+calcWidth(cur);},0);var chars=Array.from(text);for(var i=0;i<chars.length;i++){var char=chars[i];var prevChar=text[i-1];var nextChar=text[i+1];var width=calcWidth(char);if(this.isNewline(char)){currentIndex++;currentWidth=0;lines[currentIndex]='';continue;}if(currentWidth>0&¤tWidth+width>maxWidth){if(currentIndex+1>=maxLines){parsedStyle.isOverflowing=true;// If there is not enough space to display the string itself, it is clipped.
|
|
9431
|
+
if(textAlign==='center'||textAlign==='middle'){offsetX-=width/2;}else if(textAlign==='right'||textAlign==='end'){offsetX-=width;}return new Rectangle(offsetX-lineWidth/2,offsetY+i*lineHeight,width+lineWidth,lineHeight);})};}};_proto.setGraphemeOnPath=function setGraphemeOnPath(){};_proto.wordWrap=function wordWrap(text,parsedStyle,offscreenCanvas){var _this2=this;var _parsedStyle$wordWrap=parsedStyle.wordWrapWidth,wordWrapWidth=_parsedStyle$wordWrap===void 0?0:_parsedStyle$wordWrap,letterSpacing=parsedStyle.letterSpacing,_parsedStyle$maxLines=parsedStyle.maxLines,maxLines=_parsedStyle$maxLines===void 0?Infinity:_parsedStyle$maxLines,textOverflow=parsedStyle.textOverflow;var context=this.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);var maxWidth=wordWrapWidth+letterSpacing;var ellipsis='';if(textOverflow==='ellipsis'){ellipsis='...';}else if(textOverflow&&textOverflow!=='clip'){ellipsis=textOverflow;}var lines=[];var currentIndex=0;var currentWidth=0;var cache={};var calcWidth=function calcWidth(char){return _this2.getFromCache(char,letterSpacing,cache,context);};var ellipsisWidth=Array.from(ellipsis).reduce(function(prev,cur){return prev+calcWidth(cur);},0);var chars=Array.from(text);for(var i=0;i<chars.length;i++){var char=chars[i];var prevChar=text[i-1];var nextChar=text[i+1];var width=calcWidth(char);if(this.isNewline(char)){currentIndex++;currentWidth=0;lines[currentIndex]='';continue;}if(currentWidth>0&¤tWidth+width>maxWidth){if(currentIndex+1>=maxLines){parsedStyle.isOverflowing=true;// If there is not enough space to display the string itself, it is clipped.
|
|
8694
9432
|
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
|
|
8695
9433
|
if(ellipsisWidth>0&&ellipsisWidth<=maxWidth){// Backspace from line's end.
|
|
8696
9434
|
var lastLineWidth=0;var lastLineIndex=0;for(var _i2=0;_i2<lines[currentIndex].length;_i2++){var _width2=calcWidth(lines[currentIndex][_i2]);if(lastLineWidth+_width2+ellipsisWidth>maxWidth){lastLineIndex=_i2;break;}lastLineWidth+=_width2;}lines[currentIndex]=(lines[currentIndex]||'').slice(0,lastLineIndex)+ellipsis;}break;}currentIndex++;currentWidth=0;lines[currentIndex]='';if(this.isBreakingSpace(char)){continue;}if(!this.canBreakInLastChar(char)){lines=this.trimToBreakable(lines);currentWidth=this.sumTextWidthByCache(lines[currentIndex]||'',cache);}if(this.shouldBreakByKinsokuShorui(char,nextChar)){lines=this.trimByKinsokuShorui(lines);currentWidth+=calcWidth(prevChar||'');}}currentWidth+=width;lines[currentIndex]=(lines[currentIndex]||'')+char;}return lines.join('\n');};_proto.isBreakingSpace=function isBreakingSpace(char){if(typeof char!=='string'){return false;}return TEXT_METRICS.BreakingSpaces.indexOf(char.charCodeAt(0))>=0;};_proto.isNewline=function isNewline(char){if(typeof char!=='string'){return false;}return TEXT_METRICS.Newlines.indexOf(char.charCodeAt(0))>=0;};_proto.trimToBreakable=function trimToBreakable(prev){var next=[].concat(prev);var prevLine=next[next.length-2];var index=this.findBreakableIndex(prevLine);if(index===-1||!prevLine)return next;var trimmedChar=prevLine.slice(index,index+1);var isTrimmedWithSpace=this.isBreakingSpace(trimmedChar);var trimFrom=index+1;var trimTo=index+(isTrimmedWithSpace?0:1);next[next.length-1]+=prevLine.slice(trimFrom,prevLine.length);next[next.length-2]=prevLine.slice(0,trimTo);return next;};_proto.canBreakInLastChar=function canBreakInLastChar(char){if(char&&LATIN_REGEX.test(char))return false;return true;};_proto.sumTextWidthByCache=function sumTextWidthByCache(text,cache){return text.split('').reduce(function(sum,c){if(!cache[c])throw Error('cannot count the word without cache');return sum+cache[c];},0);};_proto.findBreakableIndex=function findBreakableIndex(line){for(var i=line.length-1;i>=0;i--){if(!LATIN_REGEX.test(line[i]))return i;}return -1;};_proto.getFromCache=function getFromCache(key,letterSpacing,cache,context){var width=cache[key];if(typeof width!=='number'){var spacing=key.length*letterSpacing;width=context.measureText(key).width+spacing;cache[key]=width;}return width;};return TextService;}();var runtime={};/**
|
|
@@ -8769,25 +9507,26 @@
|
|
|
8769
9507
|
if(isShape2D&&(k===4||k===5)){continue;}// p-vertex n-vertex <-|plane p-vertex n-vertex
|
|
8770
9508
|
// 使用 p-vertex 和 n-vertex 加速,避免进行平面和 aabb 全部顶点的相交检测
|
|
8771
9509
|
var _planes$k=planes[k],normal=_planes$k.normal,distance=_planes$k.distance;if(dot(normal,aabb.getPositiveFarPoint(planes[k]))+distance<0){return exports.Mask.OUTSIDE;}if(dot(normal,aabb.getNegativeFarPoint(planes[k]))+distance<0){// 和当前面相交,对应位置为1,继续检测下一个面
|
|
8772
|
-
mask|=flag;}}return mask;};return FrustumCullingStrategy;}();var PrepareRendererPlugin=/*#__PURE__*/function(){function PrepareRendererPlugin(){this.rBush=void 0;this.toSync=new Set();}var _proto=PrepareRendererPlugin.prototype
|
|
8773
|
-
|
|
8774
|
-
|
|
9510
|
+
mask|=flag;}}return mask;};return FrustumCullingStrategy;}();var PrepareRendererPlugin=/*#__PURE__*/function(){function PrepareRendererPlugin(){this.rBush=void 0;this.toSync=new Set();}var _proto=PrepareRendererPlugin.prototype;// private isFirstTimeRendering = true;
|
|
9511
|
+
_proto.apply=function apply(context){var _this=this;var renderingService=context.renderingService,renderingContext=context.renderingContext,rBushRoot=context.rBushRoot;var canvas=renderingContext.root.ownerDocument.defaultView;this.rBush=rBushRoot;var handleAttributeChanged=function handleAttributeChanged(e){var object=e.target;object.renderable.dirty=true;renderingService.dirtify();};var handleBoundsChanged=function handleBoundsChanged(e){var affectChildren=e.detail.affectChildren;var object=e.target;if(affectChildren){object.forEach(function(node){_this.toSync.add(node);});}var p=object;while(p){if(p.renderable){_this.toSync.add(p);}p=p.parentElement;}// this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
|
|
9512
|
+
renderingService.dirtify();};var handleMounted=function handleMounted(e){var object=e.target;// recalc style values
|
|
9513
|
+
runtime.styleValueRegistry.recalc(object);runtime.sceneGraphService.dirtifyToRoot(object);renderingService.dirtify();};var handleUnmounted=function handleUnmounted(e){var object=e.target;var rBushNode=object.rBushNode;if(rBushNode.aabb){_this.rBush.remove(rBushNode.aabb);}_this.toSync.delete(object);runtime.sceneGraphService.dirtifyToRoot(object);renderingService.dirtify();};renderingService.hooks.init.tapPromise(PrepareRendererPlugin.tag,/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){return _regeneratorRuntime().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:canvas.addEventListener(exports.ElementEvent.MOUNTED,handleMounted);canvas.addEventListener(exports.ElementEvent.UNMOUNTED,handleUnmounted);canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED,handleAttributeChanged);canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED,handleBoundsChanged);case 4:case"end":return _context.stop();}}},_callee);})));renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag,function(){canvas.removeEventListener(exports.ElementEvent.MOUNTED,handleMounted);canvas.removeEventListener(exports.ElementEvent.UNMOUNTED,handleUnmounted);canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED,handleAttributeChanged);canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED,handleBoundsChanged);});renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag,function(){// if (this.isFirstTimeRendering) {
|
|
8775
9514
|
// // @see https://github.com/antvis/G/issues/1117
|
|
8776
9515
|
// setTimeout(() => this.syncRTree());
|
|
8777
9516
|
// this.isFirstTimeRendering = false;
|
|
8778
9517
|
// } else {
|
|
8779
9518
|
// this.syncRTree();
|
|
8780
9519
|
// }
|
|
8781
|
-
|
|
9520
|
+
_this.syncRTree();});};_proto.syncRTree=function syncRTree(){var _this2=this;// bounds changed, need re-inserting its children
|
|
8782
9521
|
var bulk=[];Array.from(this.toSync)// some objects may be removed since last frame
|
|
8783
9522
|
.filter(function(object){return object.isConnected;}).forEach(function(node){var rBushNode=node.rBushNode;// clear dirty node
|
|
8784
|
-
if(rBushNode&&rBushNode.aabb){
|
|
9523
|
+
if(rBushNode&&rBushNode.aabb){_this2.rBush.remove(rBushNode.aabb);}var renderBounds=node.getRenderBounds();if(renderBounds){var _renderBounds$getMin=renderBounds.getMin(),minX=_renderBounds$getMin[0],minY=_renderBounds$getMin[1];var _renderBounds$getMax=renderBounds.getMax(),maxX=_renderBounds$getMax[0],maxY=_renderBounds$getMax[1];if(!rBushNode.aabb){// @ts-ignore
|
|
8785
9524
|
rBushNode.aabb={};}rBushNode.aabb.id=node.entity;rBushNode.aabb.minX=minX;rBushNode.aabb.minY=minY;rBushNode.aabb.maxX=maxX;rBushNode.aabb.maxY=maxY;}if(rBushNode.aabb){// TODO: NaN occurs when width/height of Rect is 0
|
|
8786
9525
|
if(!isNaN(rBushNode.aabb.maxX)&&!isNaN(rBushNode.aabb.maxX)&&!isNaN(rBushNode.aabb.minX)&&!isNaN(rBushNode.aabb.minY)){bulk.push(rBushNode.aabb);}}});// use bulk inserting, which is ~2-3 times faster
|
|
8787
9526
|
// @see https://github.com/mourner/rbush#bulk-inserting-data
|
|
8788
9527
|
this.rBush.load(bulk);bulk.length=0;this.toSync.clear();};return PrepareRendererPlugin;}();PrepareRendererPlugin.tag='Prepare';(function(CanvasEvent){CanvasEvent["READY"]="ready";CanvasEvent["BEFORE_RENDER"]="beforerender";CanvasEvent["AFTER_RENDER"]="afterrender";CanvasEvent["BEFORE_DESTROY"]="beforedestroy";CanvasEvent["AFTER_DESTROY"]="afterdestroy";CanvasEvent["RESIZE"]="resize";CanvasEvent["DIRTY_RECTANGLE"]="dirtyrectangle";})(exports.CanvasEvent||(exports.CanvasEvent={}));var DEFAULT_CAMERA_Z=500;var DEFAULT_CAMERA_NEAR=0.1;var DEFAULT_CAMERA_FAR=1000;/**
|
|
8789
9528
|
* reuse custom event preventing from re-create them in every frame
|
|
8790
|
-
*/var
|
|
9529
|
+
*/var mountedEvent=new CustomEvent(exports.ElementEvent.MOUNTED);var unmountedEvent=new CustomEvent(exports.ElementEvent.UNMOUNTED);var beforeRenderEvent=new CustomEvent(exports.CanvasEvent.BEFORE_RENDER);var afterRenderEvent=new CustomEvent(exports.CanvasEvent.AFTER_RENDER);/**
|
|
8791
9530
|
* can be treated like Window in DOM
|
|
8792
9531
|
* provide some extra methods like `window`, such as:
|
|
8793
9532
|
* * `window.requestAnimationFrame`
|
|
@@ -8874,9 +9613,9 @@
|
|
|
8874
9613
|
this.destroy(false,true);// destroy all plugins, reverse will mutate origin array
|
|
8875
9614
|
[].concat(oldRenderer===null||oldRenderer===void 0?void 0:oldRenderer.getPlugins()).reverse().forEach(function(plugin){plugin.destroy();});_context3.next=9;return this.initRenderer(renderer);case 9:case"end":return _context3.stop();}}},_callee3,this);}));function setRenderer(_x2){return _setRenderer.apply(this,arguments);}return setRenderer;}();_proto.setCursor=function setCursor(cursor){var canvasConfig=this.getConfig();canvasConfig.cursor=cursor;this.getContextService().applyCursorStyle(cursor);};_proto.unmountChildren=function unmountChildren(parent){var _this5=this;if(this.inited){var path=[];parent.forEach(function(child){if(child.isConnected){path.push(child);}});// unmount from leaf to root
|
|
8876
9615
|
path.reverse().forEach(function(child){// trigger before unmounted
|
|
8877
|
-
if(child
|
|
8878
|
-
if(child!==_this5.document.documentElement){child.ownerDocument=null;}child.isConnected=false;});}};_proto.mountChildren=function mountChildren(parent){var _this6=this;if(this.inited){parent.forEach(function(child){if(!child.isConnected){child.ownerDocument=_this6.document;child.isConnected=true;child.dispatchEvent(
|
|
8879
|
-
if(child
|
|
9616
|
+
if(child.isCustomElement){if(child.disconnectedCallback){child.disconnectedCallback();}}if(child.isMutationObserved){child.dispatchEvent(unmountedEvent);}else {unmountedEvent.target=child;_this5.dispatchEvent(unmountedEvent,true);}// skip document.documentElement
|
|
9617
|
+
if(child!==_this5.document.documentElement){child.ownerDocument=null;}child.isConnected=false;});}};_proto.mountChildren=function mountChildren(parent){var _this6=this;if(this.inited){parent.forEach(function(child){if(!child.isConnected){child.ownerDocument=_this6.document;child.isConnected=true;if(child.isMutationObserved){child.dispatchEvent(mountedEvent);}else {mountedEvent.target=child;_this6.dispatchEvent(mountedEvent,true);}// trigger after mounted
|
|
9618
|
+
if(child.isCustomElement){if(child.connectedCallback){child.connectedCallback();}}}});}else {console.warn("[g]: You are trying to call `canvas.appendChild` before canvas' initialization finished. You can either await `canvas.ready` or listen to `CanvasEvent.READY` manually.",'appended child: ',parent.nodeName);}};_proto.client2Viewport=function client2Viewport(client){return this.getEventService().client2Viewport(client);};_proto.viewport2Client=function viewport2Client(canvas){return this.getEventService().viewport2Client(canvas);};_proto.viewport2Canvas=function viewport2Canvas(viewport){return this.getEventService().viewport2Canvas(viewport);};_proto.canvas2Viewport=function canvas2Viewport(canvas){return this.getEventService().canvas2Viewport(canvas);}/**
|
|
8880
9619
|
* @deprecated
|
|
8881
9620
|
* @alias client2Viewport
|
|
8882
9621
|
*/;_proto.getPointByClient=function getPointByClient(clientX,clientY){return this.client2Viewport({x:clientX,y:clientY});}/**
|
|
@@ -8884,6 +9623,40 @@
|
|
|
8884
9623
|
* @alias viewport2Client
|
|
8885
9624
|
*/;_proto.getClientByPoint=function getClientByPoint(x,y){return this.viewport2Client({x:x,y:y});};_createClass(Canvas,[{key:"ready",get:function get(){var _this7=this;if(!this.readyPromise){this.readyPromise=new Promise(function(resolve){_this7.resolveReadyPromise=function(){resolve(_this7);};});if(this.inited){this.resolveReadyPromise();}}return this.readyPromise;}}]);return Canvas;}(EventTarget);
|
|
8886
9625
|
|
|
9626
|
+
var toString$1 = {}.toString;
|
|
9627
|
+
var isType$1 = function (value, type) { return toString$1.call(value) === '[object ' + type + ']'; };
|
|
9628
|
+
|
|
9629
|
+
// isFinite,
|
|
9630
|
+
var isNil$1 = function (value) {
|
|
9631
|
+
/**
|
|
9632
|
+
* isNil(null) => true
|
|
9633
|
+
* isNil() => true
|
|
9634
|
+
*/
|
|
9635
|
+
return value === null || value === undefined;
|
|
9636
|
+
};
|
|
9637
|
+
|
|
9638
|
+
var isString$1 = (function (str) {
|
|
9639
|
+
return isType$1(str, 'String');
|
|
9640
|
+
});
|
|
9641
|
+
|
|
9642
|
+
var clamp$1 = function (a, min, max) {
|
|
9643
|
+
if (a < min) {
|
|
9644
|
+
return min;
|
|
9645
|
+
}
|
|
9646
|
+
else if (a > max) {
|
|
9647
|
+
return max;
|
|
9648
|
+
}
|
|
9649
|
+
return a;
|
|
9650
|
+
};
|
|
9651
|
+
|
|
9652
|
+
/**
|
|
9653
|
+
* 判断是否数字
|
|
9654
|
+
* @return {Boolean} 是否数字
|
|
9655
|
+
*/
|
|
9656
|
+
var isNumber$1 = function (value) {
|
|
9657
|
+
return isType$1(value, 'Number');
|
|
9658
|
+
};
|
|
9659
|
+
|
|
8887
9660
|
function _inheritsLoose$1(subClass, superClass) {
|
|
8888
9661
|
subClass.prototype = Object.create(superClass.prototype);
|
|
8889
9662
|
subClass.prototype.constructor = subClass;
|
|
@@ -8905,7 +9678,7 @@
|
|
|
8905
9678
|
// Configuration Constants
|
|
8906
9679
|
|
|
8907
9680
|
|
|
8908
|
-
var EPSILON$
|
|
9681
|
+
var EPSILON$2 = 0.000001;
|
|
8909
9682
|
var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
8910
9683
|
if (!Math.hypot) Math.hypot = function () {
|
|
8911
9684
|
var y = 0,
|
|
@@ -9670,7 +10443,7 @@
|
|
|
9670
10443
|
} // calculate coefficients
|
|
9671
10444
|
|
|
9672
10445
|
|
|
9673
|
-
if (1.0 - cosom > EPSILON$
|
|
10446
|
+
if (1.0 - cosom > EPSILON$2) {
|
|
9674
10447
|
// standard case (slerp)
|
|
9675
10448
|
omega = Math.acos(cosom);
|
|
9676
10449
|
sinom = Math.sin(omega);
|
|
@@ -9868,9 +10641,9 @@
|
|
|
9868
10641
|
*/
|
|
9869
10642
|
|
|
9870
10643
|
_proto.rotate = function rotate(azimuth, elevation, roll) {
|
|
9871
|
-
this.relElevation = getAngle(elevation);
|
|
9872
|
-
this.relAzimuth = getAngle(azimuth);
|
|
9873
|
-
this.relRoll = getAngle(roll);
|
|
10644
|
+
this.relElevation = getAngle$1(elevation);
|
|
10645
|
+
this.relAzimuth = getAngle$1(azimuth);
|
|
10646
|
+
this.relRoll = getAngle$1(roll);
|
|
9874
10647
|
this.elevation += this.relElevation;
|
|
9875
10648
|
this.azimuth += this.relAzimuth;
|
|
9876
10649
|
this.roll += this.relRoll;
|
|
@@ -9999,12 +10772,12 @@
|
|
|
9999
10772
|
options = {};
|
|
10000
10773
|
}
|
|
10001
10774
|
|
|
10002
|
-
var landmark = isString(name) ? this.landmarks.find(function (l) {
|
|
10775
|
+
var landmark = isString$1(name) ? this.landmarks.find(function (l) {
|
|
10003
10776
|
return l.name === name;
|
|
10004
10777
|
}) : name;
|
|
10005
10778
|
|
|
10006
10779
|
if (landmark) {
|
|
10007
|
-
var _ref = isNumber(options) ? {
|
|
10780
|
+
var _ref = isNumber$1(options) ? {
|
|
10008
10781
|
duration: options
|
|
10009
10782
|
} : options,
|
|
10010
10783
|
_ref$easing = _ref.easing,
|
|
@@ -12713,8 +13486,8 @@
|
|
|
12713
13486
|
amplitude = _params$ === void 0 ? 1 : _params$,
|
|
12714
13487
|
_params$2 = _params[1],
|
|
12715
13488
|
period = _params$2 === void 0 ? 0.5 : _params$2;
|
|
12716
|
-
var a = clamp(Number(amplitude), 1, 10);
|
|
12717
|
-
var p = clamp(Number(period), 0.1, 2);
|
|
13489
|
+
var a = clamp$1(Number(amplitude), 1, 10);
|
|
13490
|
+
var p = clamp$1(Number(period), 0.1, 2);
|
|
12718
13491
|
if (t === 0 || t === 1) return t;
|
|
12719
13492
|
return -a * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1 - p / (Math.PI * 2) * Math.asin(1 / a)) * (Math.PI * 2) / p);
|
|
12720
13493
|
};
|
|
@@ -12733,10 +13506,10 @@
|
|
|
12733
13506
|
damping = _params2$3 === void 0 ? 10 : _params2$3,
|
|
12734
13507
|
_params2$4 = _params2[3],
|
|
12735
13508
|
velocity = _params2$4 === void 0 ? 0 : _params2$4;
|
|
12736
|
-
mass = clamp(mass, 0.1, 1000);
|
|
12737
|
-
stiffness = clamp(stiffness, 0.1, 1000);
|
|
12738
|
-
damping = clamp(damping, 0.1, 1000);
|
|
12739
|
-
velocity = clamp(velocity, 0.1, 1000);
|
|
13509
|
+
mass = clamp$1(mass, 0.1, 1000);
|
|
13510
|
+
stiffness = clamp$1(stiffness, 0.1, 1000);
|
|
13511
|
+
damping = clamp$1(damping, 0.1, 1000);
|
|
13512
|
+
velocity = clamp$1(velocity, 0.1, 1000);
|
|
12740
13513
|
var w0 = Math.sqrt(stiffness / mass);
|
|
12741
13514
|
var zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
|
12742
13515
|
var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0;
|
|
@@ -12821,7 +13594,7 @@
|
|
|
12821
13594
|
steps = _params3$ === void 0 ? 10 : _params3$,
|
|
12822
13595
|
type = _params3[1];
|
|
12823
13596
|
var trunc = type == 'start' ? Math.ceil : Math.floor;
|
|
12824
|
-
return trunc(clamp(t, 0, 1) * steps) / steps;
|
|
13597
|
+
return trunc(clamp$1(t, 0, 1) * steps) / steps;
|
|
12825
13598
|
}; // @ts-ignore
|
|
12826
13599
|
|
|
12827
13600
|
|
|
@@ -13530,7 +14303,7 @@
|
|
|
13530
14303
|
for (var i = 0; i < keyframes.length; i++) {
|
|
13531
14304
|
var offset = keyframes[i].offset;
|
|
13532
14305
|
|
|
13533
|
-
if (!isNil(offset)) {
|
|
14306
|
+
if (!isNil$1(offset)) {
|
|
13534
14307
|
if (offset < previousOffset) {
|
|
13535
14308
|
throw new TypeError('Keyframes are not loosely sorted by offset. Sort or specify offsets.');
|
|
13536
14309
|
}
|
|
@@ -13563,7 +14336,7 @@
|
|
|
13563
14336
|
for (var _i = 1; _i < length; _i++) {
|
|
13564
14337
|
var _offset = keyframes[_i].computedOffset;
|
|
13565
14338
|
|
|
13566
|
-
if (!isNil(_offset) && !isNil(previousOffset)) {
|
|
14339
|
+
if (!isNil$1(_offset) && !isNil$1(previousOffset)) {
|
|
13567
14340
|
for (var j = 1; j < _i - previousIndex; j++) {
|
|
13568
14341
|
keyframes[previousIndex + j].computedOffset = previousOffset + (Number(_offset) - previousOffset) * j / (_i - previousIndex);
|
|
13569
14342
|
}
|
|
@@ -14066,7 +14839,8 @@
|
|
|
14066
14839
|
exports.deg2rad = deg2rad;
|
|
14067
14840
|
exports.deg2turn = deg2turn;
|
|
14068
14841
|
exports.findClosestClipPathTarget = findClosestClipPathTarget;
|
|
14069
|
-
exports.
|
|
14842
|
+
exports.fromRotationTranslationScale = fromRotationTranslationScale$1;
|
|
14843
|
+
exports.getAngle = getAngle$1;
|
|
14070
14844
|
exports.getEuler = getEuler;
|
|
14071
14845
|
exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;
|
|
14072
14846
|
exports.grad2deg = grad2deg;
|