@antv/g 5.1.8 → 5.2.2
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/css/StyleValueRegistry.d.ts.map +1 -1
- package/dist/css/cssom/CSSGradientValue.d.ts +10 -23
- package/dist/css/cssom/CSSGradientValue.d.ts.map +1 -1
- package/dist/css/cssom/CSSNumericValue.d.ts +1 -1
- package/dist/css/parser/color.d.ts +12 -3
- package/dist/css/parser/color.d.ts.map +1 -1
- package/dist/css/parser/dimension.d.ts.map +1 -1
- package/dist/css/parser/gradient.d.ts +4 -0
- package/dist/css/parser/gradient.d.ts.map +1 -0
- package/dist/css/parser/path.d.ts +2 -2
- package/dist/css/parser/path.d.ts.map +1 -1
- package/dist/css/properties/CSSPropertyColor.d.ts +5 -4
- package/dist/css/properties/CSSPropertyColor.d.ts.map +1 -1
- package/dist/css/properties/CSSPropertyPath.d.ts +3 -3
- package/dist/css/properties/CSSPropertyPath.d.ts.map +1 -1
- package/dist/display-objects/Path.d.ts +8 -8
- package/dist/display-objects/Path.d.ts.map +1 -1
- package/dist/dom/KeyframeList.d.ts.map +1 -1
- package/dist/index.esm.js +841 -756
- package/dist/index.js +849 -762
- package/dist/index.umd.js +5782 -4335
- package/dist/index.umd.min.js +2 -2
- package/dist/services/aabb/PathUpdater.d.ts +1 -1
- package/dist/services/aabb/PathUpdater.d.ts.map +1 -1
- package/dist/services/aabb/RectUpdater.d.ts +1 -1
- package/dist/services/aabb/RectUpdater.d.ts.map +1 -1
- package/dist/types.d.ts +5 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/gradient.d.ts +106 -0
- package/dist/utils/gradient.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/path.d.ts +11 -7
- package/dist/utils/path.d.ts.map +1 -1
- package/package.json +9 -6
package/dist/index.esm.js
CHANGED
|
@@ -5,10 +5,11 @@ export { default as RBush } from 'rbush';
|
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import { __decorate, __param, __metadata } from 'tslib';
|
|
7
7
|
import { vec3, mat3, mat4, quat, vec4 } from 'gl-matrix';
|
|
8
|
-
import { Cubic as Cubic$1, Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
|
|
9
8
|
import { EventEmitter } from 'eventemitter3';
|
|
10
9
|
import { color } from 'd3-color';
|
|
11
|
-
import {
|
|
10
|
+
import { memoize } from 'lodash-es';
|
|
11
|
+
import { normalizePath, path2Curve, getPathBBoxTotalLength, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, getPointAtLength } from '@antv/util';
|
|
12
|
+
import { Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
|
|
12
13
|
import { requestAnimationFrame as requestAnimationFrame$1, cancelAnimationFrame as cancelAnimationFrame$1 } from 'request-animation-frame-polyfill';
|
|
13
14
|
|
|
14
15
|
function _regeneratorRuntime() {
|
|
@@ -412,7 +413,7 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
function _extends() {
|
|
415
|
-
_extends = Object.assign
|
|
416
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
416
417
|
for (var i = 1; i < arguments.length; i++) {
|
|
417
418
|
var source = arguments[i];
|
|
418
419
|
|
|
@@ -425,7 +426,6 @@ function _extends() {
|
|
|
425
426
|
|
|
426
427
|
return target;
|
|
427
428
|
};
|
|
428
|
-
|
|
429
429
|
return _extends.apply(this, arguments);
|
|
430
430
|
}
|
|
431
431
|
|
|
@@ -437,11 +437,10 @@ function _inheritsLoose(subClass, superClass) {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
function _setPrototypeOf(o, p) {
|
|
440
|
-
_setPrototypeOf = Object.setPrototypeOf
|
|
440
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
441
441
|
o.__proto__ = p;
|
|
442
442
|
return o;
|
|
443
443
|
};
|
|
444
|
-
|
|
445
444
|
return _setPrototypeOf(o, p);
|
|
446
445
|
}
|
|
447
446
|
|
|
@@ -460,7 +459,7 @@ function _isNativeReflectConstruct() {
|
|
|
460
459
|
|
|
461
460
|
function _construct(Parent, args, Class) {
|
|
462
461
|
if (_isNativeReflectConstruct()) {
|
|
463
|
-
_construct = Reflect.construct;
|
|
462
|
+
_construct = Reflect.construct.bind();
|
|
464
463
|
} else {
|
|
465
464
|
_construct = function _construct(Parent, args, Class) {
|
|
466
465
|
var a = [null];
|
|
@@ -1686,6 +1685,379 @@ var TOUCH_TO_POINTER = {
|
|
|
1686
1685
|
touchcancel: 'pointercancel'
|
|
1687
1686
|
};
|
|
1688
1687
|
|
|
1688
|
+
/**
|
|
1689
|
+
* borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
|
|
1690
|
+
* @see https://github.com/rafaelcaricio/gradient-parser
|
|
1691
|
+
*/
|
|
1692
|
+
function colorStopToString(colorStop) {
|
|
1693
|
+
var type = colorStop.type,
|
|
1694
|
+
value = colorStop.value;
|
|
1695
|
+
|
|
1696
|
+
if (type === 'hex') {
|
|
1697
|
+
return "#" + value;
|
|
1698
|
+
} else if (type === 'literal') {
|
|
1699
|
+
return value;
|
|
1700
|
+
} else if (type === 'rgb') {
|
|
1701
|
+
return "rgb(" + value.join(',') + ")";
|
|
1702
|
+
} else {
|
|
1703
|
+
return "rgba(" + value.join(',') + ")";
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
var parseGradient = function () {
|
|
1707
|
+
var tokens = {
|
|
1708
|
+
linearGradient: /^(linear\-gradient)/i,
|
|
1709
|
+
repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
|
|
1710
|
+
radialGradient: /^(radial\-gradient)/i,
|
|
1711
|
+
repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* @see https://projects.verou.me/conic-gradient/
|
|
1715
|
+
*/
|
|
1716
|
+
conicGradient: /^(conic\-gradient)/i,
|
|
1717
|
+
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
1718
|
+
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
|
1719
|
+
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
1720
|
+
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
|
1721
|
+
percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
|
|
1722
|
+
emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
|
|
1723
|
+
angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
|
|
1724
|
+
startCall: /^\(/,
|
|
1725
|
+
endCall: /^\)/,
|
|
1726
|
+
comma: /^,/,
|
|
1727
|
+
hexColor: /^\#([0-9a-fA-F]+)/,
|
|
1728
|
+
literalColor: /^([a-zA-Z]+)/,
|
|
1729
|
+
rgbColor: /^rgb/i,
|
|
1730
|
+
rgbaColor: /^rgba/i,
|
|
1731
|
+
number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
|
|
1732
|
+
};
|
|
1733
|
+
var input = '';
|
|
1734
|
+
|
|
1735
|
+
function error(msg) {
|
|
1736
|
+
throw new Error(input + ': ' + msg);
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
function getAST() {
|
|
1740
|
+
var ast = matchListDefinitions();
|
|
1741
|
+
|
|
1742
|
+
if (input.length > 0) {
|
|
1743
|
+
error('Invalid input not EOF');
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
return ast;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
function matchListDefinitions() {
|
|
1750
|
+
return matchListing(matchDefinition);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
function matchDefinition() {
|
|
1754
|
+
return matchGradient('linear-gradient', tokens.linearGradient, matchLinearOrientation) || matchGradient('repeating-linear-gradient', tokens.repeatingLinearGradient, matchLinearOrientation) || matchGradient('radial-gradient', tokens.radialGradient, matchListRadialOrientations) || matchGradient('repeating-radial-gradient', tokens.repeatingRadialGradient, matchListRadialOrientations) || matchGradient('conic-gradient', tokens.conicGradient, matchListRadialOrientations);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
function matchGradient(gradientType, pattern, orientationMatcher) {
|
|
1758
|
+
return matchCall(pattern, function (captures) {
|
|
1759
|
+
var orientation = orientationMatcher();
|
|
1760
|
+
|
|
1761
|
+
if (orientation) {
|
|
1762
|
+
if (!scan(tokens.comma)) {
|
|
1763
|
+
error('Missing comma before color stops');
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
return {
|
|
1768
|
+
type: gradientType,
|
|
1769
|
+
orientation: orientation,
|
|
1770
|
+
colorStops: matchListing(matchColorStop)
|
|
1771
|
+
};
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
function matchCall(pattern, callback) {
|
|
1776
|
+
var captures = scan(pattern);
|
|
1777
|
+
|
|
1778
|
+
if (captures) {
|
|
1779
|
+
if (!scan(tokens.startCall)) {
|
|
1780
|
+
error('Missing (');
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
var result = callback(captures);
|
|
1784
|
+
|
|
1785
|
+
if (!scan(tokens.endCall)) {
|
|
1786
|
+
error('Missing )');
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
return result;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
function matchLinearOrientation() {
|
|
1794
|
+
return matchSideOrCorner() || matchAngle();
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
function matchSideOrCorner() {
|
|
1798
|
+
return match('directional', tokens.sideOrCorner, 1);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
function matchAngle() {
|
|
1802
|
+
return match('angular', tokens.angleValue, 1);
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
function matchListRadialOrientations() {
|
|
1806
|
+
var radialOrientations,
|
|
1807
|
+
radialOrientation = matchRadialOrientation(),
|
|
1808
|
+
lookaheadCache;
|
|
1809
|
+
|
|
1810
|
+
if (radialOrientation) {
|
|
1811
|
+
radialOrientations = [];
|
|
1812
|
+
radialOrientations.push(radialOrientation);
|
|
1813
|
+
lookaheadCache = input;
|
|
1814
|
+
|
|
1815
|
+
if (scan(tokens.comma)) {
|
|
1816
|
+
radialOrientation = matchRadialOrientation();
|
|
1817
|
+
|
|
1818
|
+
if (radialOrientation) {
|
|
1819
|
+
radialOrientations.push(radialOrientation);
|
|
1820
|
+
} else {
|
|
1821
|
+
input = lookaheadCache;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
return radialOrientations;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
function matchRadialOrientation() {
|
|
1830
|
+
var radialType = matchCircle() || matchEllipse();
|
|
1831
|
+
|
|
1832
|
+
if (radialType) {
|
|
1833
|
+
// @ts-ignore
|
|
1834
|
+
radialType.at = matchAtPosition();
|
|
1835
|
+
} else {
|
|
1836
|
+
var extent = matchExtentKeyword();
|
|
1837
|
+
|
|
1838
|
+
if (extent) {
|
|
1839
|
+
radialType = extent;
|
|
1840
|
+
var positionAt = matchAtPosition();
|
|
1841
|
+
|
|
1842
|
+
if (positionAt) {
|
|
1843
|
+
// @ts-ignore
|
|
1844
|
+
radialType.at = positionAt;
|
|
1845
|
+
}
|
|
1846
|
+
} else {
|
|
1847
|
+
var defaultPosition = matchPositioning();
|
|
1848
|
+
|
|
1849
|
+
if (defaultPosition) {
|
|
1850
|
+
radialType = {
|
|
1851
|
+
type: 'default-radial',
|
|
1852
|
+
// @ts-ignore
|
|
1853
|
+
at: defaultPosition
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
return radialType;
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
function matchCircle() {
|
|
1863
|
+
var circle = match('shape', /^(circle)/i, 0);
|
|
1864
|
+
|
|
1865
|
+
if (circle) {
|
|
1866
|
+
// @ts-ignore
|
|
1867
|
+
circle.style = matchLength() || matchExtentKeyword();
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
return circle;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
function matchEllipse() {
|
|
1874
|
+
var ellipse = match('shape', /^(ellipse)/i, 0);
|
|
1875
|
+
|
|
1876
|
+
if (ellipse) {
|
|
1877
|
+
// @ts-ignore
|
|
1878
|
+
ellipse.style = matchDistance() || matchExtentKeyword();
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
return ellipse;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
function matchExtentKeyword() {
|
|
1885
|
+
return match('extent-keyword', tokens.extentKeywords, 1);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
function matchAtPosition() {
|
|
1889
|
+
if (match('position', /^at/, 0)) {
|
|
1890
|
+
var positioning = matchPositioning();
|
|
1891
|
+
|
|
1892
|
+
if (!positioning) {
|
|
1893
|
+
error('Missing positioning value');
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
return positioning;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
function matchPositioning() {
|
|
1901
|
+
var location = matchCoordinates();
|
|
1902
|
+
|
|
1903
|
+
if (location.x || location.y) {
|
|
1904
|
+
return {
|
|
1905
|
+
type: 'position',
|
|
1906
|
+
value: location
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
function matchCoordinates() {
|
|
1912
|
+
return {
|
|
1913
|
+
x: matchDistance(),
|
|
1914
|
+
y: matchDistance()
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
function matchListing(matcher) {
|
|
1919
|
+
var captures = matcher();
|
|
1920
|
+
var result = [];
|
|
1921
|
+
|
|
1922
|
+
if (captures) {
|
|
1923
|
+
result.push(captures);
|
|
1924
|
+
|
|
1925
|
+
while (scan(tokens.comma)) {
|
|
1926
|
+
captures = matcher();
|
|
1927
|
+
|
|
1928
|
+
if (captures) {
|
|
1929
|
+
result.push(captures);
|
|
1930
|
+
} else {
|
|
1931
|
+
error('One extra comma');
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
return result;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
function matchColorStop() {
|
|
1940
|
+
var color = matchColor();
|
|
1941
|
+
|
|
1942
|
+
if (!color) {
|
|
1943
|
+
error('Expected color definition');
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
color.length = matchDistance();
|
|
1947
|
+
return color;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
function matchColor() {
|
|
1951
|
+
return matchHexColor() || matchRGBAColor() || matchRGBColor() || matchLiteralColor();
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
function matchLiteralColor() {
|
|
1955
|
+
return match('literal', tokens.literalColor, 0);
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
function matchHexColor() {
|
|
1959
|
+
return match('hex', tokens.hexColor, 1);
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
function matchRGBColor() {
|
|
1963
|
+
return matchCall(tokens.rgbColor, function () {
|
|
1964
|
+
return {
|
|
1965
|
+
type: 'rgb',
|
|
1966
|
+
value: matchListing(matchNumber)
|
|
1967
|
+
};
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
function matchRGBAColor() {
|
|
1972
|
+
return matchCall(tokens.rgbaColor, function () {
|
|
1973
|
+
return {
|
|
1974
|
+
type: 'rgba',
|
|
1975
|
+
value: matchListing(matchNumber)
|
|
1976
|
+
};
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
function matchNumber() {
|
|
1981
|
+
return scan(tokens.number)[1];
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
function matchDistance() {
|
|
1985
|
+
return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
function matchPositionKeyword() {
|
|
1989
|
+
return match('position-keyword', tokens.positionKeywords, 1);
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
function matchLength() {
|
|
1993
|
+
return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
function match(type, pattern, captureIndex) {
|
|
1997
|
+
var captures = scan(pattern);
|
|
1998
|
+
|
|
1999
|
+
if (captures) {
|
|
2000
|
+
return {
|
|
2001
|
+
type: type,
|
|
2002
|
+
value: captures[captureIndex]
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
function scan(regexp) {
|
|
2008
|
+
var blankCaptures = /^[\n\r\t\s]+/.exec(input);
|
|
2009
|
+
|
|
2010
|
+
if (blankCaptures) {
|
|
2011
|
+
consume(blankCaptures[0].length);
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
var captures = regexp.exec(input);
|
|
2015
|
+
|
|
2016
|
+
if (captures) {
|
|
2017
|
+
consume(captures[0].length);
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
return captures;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
function consume(size) {
|
|
2024
|
+
input = input.substring(size);
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
return function (code) {
|
|
2028
|
+
input = code;
|
|
2029
|
+
return getAST();
|
|
2030
|
+
};
|
|
2031
|
+
}();
|
|
2032
|
+
function computeLinearGradient(width, height, angle) {
|
|
2033
|
+
var rad = angle * Math.PI / 180;
|
|
2034
|
+
var rx = 0;
|
|
2035
|
+
var ry = 0;
|
|
2036
|
+
var rcx = rx + width / 2;
|
|
2037
|
+
var rcy = ry + height / 2; // get the length of gradient line
|
|
2038
|
+
// @see https://observablehq.com/@danburzo/css-gradient-line
|
|
2039
|
+
|
|
2040
|
+
var length = Math.abs(width * Math.cos(rad)) + Math.abs(height * Math.sin(rad));
|
|
2041
|
+
var x1 = rcx - Math.cos(rad) * length / 2;
|
|
2042
|
+
var y1 = rcy - Math.sin(rad) * length / 2;
|
|
2043
|
+
var x2 = rcx + Math.cos(rad) * length / 2;
|
|
2044
|
+
var y2 = rcy + Math.sin(rad) * length / 2;
|
|
2045
|
+
return {
|
|
2046
|
+
x1: x1,
|
|
2047
|
+
y1: y1,
|
|
2048
|
+
x2: x2,
|
|
2049
|
+
y2: y2
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
function computeRadialGradient(width, height, cx, cy) {
|
|
2053
|
+
var r = Math.sqrt(width * width + height * height) / 2;
|
|
2054
|
+
return {
|
|
2055
|
+
x: cx * width,
|
|
2056
|
+
y: cy * height,
|
|
2057
|
+
r: r
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
|
|
1689
2061
|
/**
|
|
1690
2062
|
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
|
|
1691
2063
|
*/
|
|
@@ -2209,210 +2581,134 @@ var Shape;
|
|
|
2209
2581
|
|
|
2210
2582
|
var CanvasConfig = Syringe.defineToken('CanvasConfig');
|
|
2211
2583
|
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
*/
|
|
2584
|
+
function hasArcOrBezier(path) {
|
|
2585
|
+
var hasArc = false;
|
|
2586
|
+
var count = path.length;
|
|
2216
2587
|
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2588
|
+
for (var i = 0; i < count; i++) {
|
|
2589
|
+
var params = path[i];
|
|
2590
|
+
var cmd = params[0];
|
|
2591
|
+
|
|
2592
|
+
if (cmd === 'C' || cmd === 'A' || cmd === 'Q') {
|
|
2593
|
+
hasArc = true;
|
|
2594
|
+
break;
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2224
2597
|
|
|
2225
|
-
|
|
2226
|
-
if (t === void 0) {
|
|
2227
|
-
t = 0.5;
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
var p0 = pts.slice(0, 2);
|
|
2231
|
-
var p1 = pts.slice(2, 4);
|
|
2232
|
-
var p2 = pts.slice(4, 6);
|
|
2233
|
-
var p3 = pts.slice(6, 8);
|
|
2234
|
-
var p4 = midPoint(p0, p1, t);
|
|
2235
|
-
var p5 = midPoint(p1, p2, t);
|
|
2236
|
-
var p6 = midPoint(p2, p3, t);
|
|
2237
|
-
var p7 = midPoint(p4, p5, t);
|
|
2238
|
-
var p8 = midPoint(p5, p6, t);
|
|
2239
|
-
var p9 = midPoint(p7, p8, t);
|
|
2240
|
-
return [// @ts-ignore
|
|
2241
|
-
['C'].concat(p4, p7, p9), // @ts-ignore
|
|
2242
|
-
['C'].concat(p8, p6, p3)];
|
|
2598
|
+
return hasArc;
|
|
2243
2599
|
}
|
|
2600
|
+
function extractPolygons(pathArray) {
|
|
2601
|
+
var polygons = [];
|
|
2602
|
+
var polylines = [];
|
|
2603
|
+
var points = []; // 防止第一个命令不是 'M'
|
|
2244
2604
|
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2605
|
+
for (var i = 0; i < pathArray.length; i++) {
|
|
2606
|
+
var params = pathArray[i];
|
|
2607
|
+
var cmd = params[0];
|
|
2608
|
+
|
|
2609
|
+
if (cmd === 'M') {
|
|
2610
|
+
// 遇到 'M' 判定是否是新数组,新数组中没有点
|
|
2611
|
+
if (points.length) {
|
|
2612
|
+
// 如果存在点,则说明没有遇到 'Z',开始了一个新的多边形
|
|
2613
|
+
polylines.push(points);
|
|
2614
|
+
points = []; // 创建新的点
|
|
2615
|
+
}
|
|
2249
2616
|
|
|
2250
|
-
|
|
2251
|
-
|
|
2617
|
+
points.push([params[1], params[2]]);
|
|
2618
|
+
} else if (cmd === 'Z') {
|
|
2619
|
+
if (points.length) {
|
|
2620
|
+
// 存在点
|
|
2621
|
+
polygons.push(points);
|
|
2622
|
+
points = []; // 开始新的点集合
|
|
2623
|
+
} // 如果不存在点,同时 'Z',则说明是错误,不处理
|
|
2252
2624
|
|
|
2253
|
-
if (i) {
|
|
2254
|
-
// must be [segment,segment]
|
|
2255
|
-
subsegs = curveLength ? splitCubic(segmentData) : [segment, segment];
|
|
2256
2625
|
} else {
|
|
2257
|
-
|
|
2626
|
+
points.push([params[1], params[2]]);
|
|
2258
2627
|
}
|
|
2628
|
+
} // 说明 points 未放入 polygons 或者 polyline
|
|
2629
|
+
// 仅当只有一个 M,没有 Z 时会发生这种情况
|
|
2259
2630
|
|
|
2260
|
-
return {
|
|
2261
|
-
s: segment,
|
|
2262
|
-
ss: subsegs,
|
|
2263
|
-
l: curveLength
|
|
2264
|
-
};
|
|
2265
|
-
});
|
|
2266
|
-
}
|
|
2267
2631
|
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
}
|
|
2276
|
-
var l2 = c2.filter(function (x) {
|
|
2277
|
-
return x.l;
|
|
2278
|
-
}).length;
|
|
2279
|
-
var m1 = c1.filter(function (x) {
|
|
2280
|
-
return x.l;
|
|
2281
|
-
}).reduce(function (a, _ref) {
|
|
2282
|
-
var l = _ref.l;
|
|
2283
|
-
return a + l;
|
|
2284
|
-
}, 0) / l1 || 0;
|
|
2285
|
-
var m2 = c2.filter(function (x) {
|
|
2286
|
-
return x.l;
|
|
2287
|
-
}).reduce(function (a, _ref2) {
|
|
2288
|
-
var l = _ref2.l;
|
|
2289
|
-
return a + l;
|
|
2290
|
-
}, 0) / l2 || 0;
|
|
2291
|
-
var tl = TL || Math.max(L1, L2);
|
|
2292
|
-
var mm = [m1, m2];
|
|
2293
|
-
var dif = [tl - L1, tl - L2];
|
|
2294
|
-
var canSplit = 0;
|
|
2295
|
-
var result = [c1, c2].map(function (x, i) {
|
|
2296
|
-
return (// @ts-ignore
|
|
2297
|
-
x.l === tl ? x.map(function (y) {
|
|
2298
|
-
return y.s;
|
|
2299
|
-
}) : x.map(function (y, j) {
|
|
2300
|
-
canSplit = j && dif[i] && y.l >= mm[i];
|
|
2301
|
-
dif[i] -= canSplit ? 1 : 0;
|
|
2302
|
-
return canSplit ? y.ss : [y.s];
|
|
2303
|
-
}).flat()
|
|
2304
|
-
);
|
|
2305
|
-
});
|
|
2306
|
-
return result[0].length === result[1].length ? result : equalizeSegments(result[0], result[1], tl);
|
|
2307
|
-
}
|
|
2308
|
-
function getDrawDirection(pathArray) {
|
|
2309
|
-
return getPathArea(pathArray) >= 0;
|
|
2632
|
+
if (points.length > 0) {
|
|
2633
|
+
polylines.push(points);
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
return {
|
|
2637
|
+
polygons: polygons,
|
|
2638
|
+
polylines: polylines
|
|
2639
|
+
};
|
|
2310
2640
|
}
|
|
2311
2641
|
|
|
2312
|
-
function
|
|
2313
|
-
|
|
2314
|
-
return 3 * ((y3 - y0) * (x1 + x2) - (x3 - x0) * (y1 + y2) + y1 * (x0 - x2) - x1 * (y0 - y2) + y3 * (x2 + x0 / 3) - x3 * (y2 + y0 / 3)) / 20;
|
|
2642
|
+
function isSamePoint(point1, point2) {
|
|
2643
|
+
return point1[0] === point2[0] && point1[1] === point2[1];
|
|
2315
2644
|
}
|
|
2316
2645
|
|
|
2317
|
-
function
|
|
2318
|
-
var
|
|
2319
|
-
var
|
|
2320
|
-
|
|
2321
|
-
var
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2646
|
+
function path2Segments(path) {
|
|
2647
|
+
var segments = [];
|
|
2648
|
+
var currentPoint = null; // 当前图形
|
|
2649
|
+
|
|
2650
|
+
var nextParams = null; // 下一节点的 path 参数
|
|
2651
|
+
// let startMovePoint = null; // 开始 M 的点,可能会有多个
|
|
2652
|
+
|
|
2653
|
+
var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
|
|
2654
|
+
|
|
2655
|
+
var count = path.length;
|
|
2656
|
+
|
|
2657
|
+
for (var i = 0; i < count; i++) {
|
|
2658
|
+
var params = path[i];
|
|
2659
|
+
nextParams = path[i + 1];
|
|
2660
|
+
var command = params[0]; // 数学定义上的参数,便于后面的计算
|
|
2661
|
+
|
|
2662
|
+
var segment = {
|
|
2663
|
+
command: command,
|
|
2664
|
+
prePoint: currentPoint,
|
|
2665
|
+
params: params,
|
|
2666
|
+
startTangent: null,
|
|
2667
|
+
endTangent: null
|
|
2668
|
+
};
|
|
2669
|
+
|
|
2670
|
+
switch (command) {
|
|
2325
2671
|
case 'M':
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
y = my;
|
|
2331
|
-
return 0;
|
|
2672
|
+
// startMovePoint = [params[1], params[2]];
|
|
2673
|
+
lastStartMovePointIndex = i;
|
|
2674
|
+
break;
|
|
2675
|
+
}
|
|
2332
2676
|
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
len = getCubicSegArea.apply(0, [x, y].concat(seg.slice(1)));
|
|
2336
|
-
|
|
2337
|
-
var _seg$slice = seg.slice(-2);
|
|
2338
|
-
|
|
2339
|
-
x = _seg$slice[0];
|
|
2340
|
-
y = _seg$slice[1];
|
|
2341
|
-
return len;
|
|
2342
|
-
}
|
|
2343
|
-
}).reduce(function (a, b) {
|
|
2344
|
-
return a + b;
|
|
2345
|
-
}, 0);
|
|
2346
|
-
} // reverse CURVE based pathArray segments only
|
|
2347
|
-
|
|
2348
|
-
function reverseCurve(pathArray) {
|
|
2349
|
-
var rotatedCurve = pathArray.slice(1).map(function (x, i, curveOnly) {
|
|
2350
|
-
return (// @ts-ignore
|
|
2351
|
-
!i ? pathArray[0].slice(1).concat(x.slice(1)) : curveOnly[i - 1].slice(-2).concat(x.slice(1))
|
|
2352
|
-
);
|
|
2353
|
-
}) // @ts-ignore
|
|
2354
|
-
.map(function (x) {
|
|
2355
|
-
return x.map(function (y, i) {
|
|
2356
|
-
return x[x.length - i - 2 * (1 - i % 2)];
|
|
2357
|
-
});
|
|
2358
|
-
}).reverse(); // @ts-ignore
|
|
2677
|
+
var len = params.length;
|
|
2678
|
+
currentPoint = [params[len - 2], params[len - 1]]; // @ts-ignore
|
|
2359
2679
|
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
function clonePath(pathArray) {
|
|
2365
|
-
// @ts-ignore
|
|
2366
|
-
return pathArray.map(function (x) {
|
|
2367
|
-
if (Array.isArray(x)) {
|
|
2368
|
-
// @ts-ignore
|
|
2369
|
-
return clonePath(x);
|
|
2680
|
+
segment.currentPoint = currentPoint; // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
|
|
2681
|
+
|
|
2682
|
+
if (segments[lastStartMovePointIndex] && isSamePoint(currentPoint, segments[lastStartMovePointIndex].currentPoint)) {
|
|
2683
|
+
segments[lastStartMovePointIndex].prePoint = segment.prePoint;
|
|
2370
2684
|
}
|
|
2371
2685
|
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2686
|
+
var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null; // @ts-ignore
|
|
2687
|
+
|
|
2688
|
+
segment.nextPoint = nextPoint; // Add startTangent and endTangent
|
|
2375
2689
|
|
|
2376
|
-
|
|
2377
|
-
var segCount = a.length;
|
|
2378
|
-
var pointCount = segCount - 1;
|
|
2379
|
-
return a.map(function (f, idx) {
|
|
2380
|
-
return a.map(function (p, i) {
|
|
2381
|
-
var oldSegIdx = idx + i;
|
|
2382
|
-
var seg;
|
|
2690
|
+
var prePoint = segment.prePoint;
|
|
2383
2691
|
|
|
2384
|
-
|
|
2385
|
-
|
|
2692
|
+
if (command === 'C') {
|
|
2693
|
+
// 三次贝塞尔曲线有两个控制点
|
|
2694
|
+
var cp1 = [params[1], params[2]];
|
|
2695
|
+
var cp2 = [params[3], params[4]];
|
|
2696
|
+
segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
|
|
2697
|
+
segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]]; // horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
|
|
2386
2698
|
|
|
2387
|
-
|
|
2699
|
+
if (segment.startTangent[0] === 0 && segment.startTangent[1] === 0) {
|
|
2700
|
+
segment.startTangent = [cp1[0] - cp2[0], cp1[1] - cp2[1]];
|
|
2388
2701
|
}
|
|
2389
2702
|
|
|
2390
|
-
if (
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
}
|
|
2703
|
+
if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
|
|
2704
|
+
segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2395
2707
|
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
}
|
|
2708
|
+
segments.push(segment);
|
|
2709
|
+
}
|
|
2399
2710
|
|
|
2400
|
-
|
|
2401
|
-
var segCount = a.length - 1;
|
|
2402
|
-
var lineLengths = [];
|
|
2403
|
-
var computedIndex = 0;
|
|
2404
|
-
var sumLensSqrd = 0;
|
|
2405
|
-
var rotations = getRotations(a);
|
|
2406
|
-
rotations.forEach(function (r, i) {
|
|
2407
|
-
a.slice(1).forEach(function (s, j) {
|
|
2408
|
-
// @ts-ignore
|
|
2409
|
-
sumLensSqrd += distanceSquareRoot(a[(i + j) % segCount].slice(-2), b[j % segCount].slice(-2));
|
|
2410
|
-
});
|
|
2411
|
-
lineLengths[i] = sumLensSqrd;
|
|
2412
|
-
sumLensSqrd = 0;
|
|
2413
|
-
});
|
|
2414
|
-
computedIndex = lineLengths.indexOf(Math.min.apply(null, lineLengths));
|
|
2415
|
-
return rotations[computedIndex];
|
|
2711
|
+
return segments;
|
|
2416
2712
|
}
|
|
2417
2713
|
|
|
2418
2714
|
function commandsToPathString(commands, object, applyLocalTransform) {
|
|
@@ -2504,7 +2800,11 @@ function rectToCommands(width, height, x, y, radius) {
|
|
|
2504
2800
|
trr = radius[1],
|
|
2505
2801
|
brr = radius[2],
|
|
2506
2802
|
blr = radius[3];
|
|
2507
|
-
|
|
2803
|
+
var signX = width > 0 ? 1 : -1;
|
|
2804
|
+
var signY = height > 0 ? 1 : -1; // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
|
|
2805
|
+
|
|
2806
|
+
var sweepFlag = signX + signY !== 0 ? 1 : 0;
|
|
2807
|
+
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) {
|
|
2508
2808
|
return command;
|
|
2509
2809
|
});
|
|
2510
2810
|
}
|
|
@@ -2574,7 +2874,7 @@ function convertToPath(object, applyLocalTransform) {
|
|
|
2574
2874
|
return r.value !== 0;
|
|
2575
2875
|
});
|
|
2576
2876
|
commands = rectToCommands(width.value, height.value, x.value, y.value, hasRadius && radius.map(function (r) {
|
|
2577
|
-
return clamp(r.value, 0, Math.min(width.value / 2, height.value / 2));
|
|
2877
|
+
return clamp(r.value, 0, Math.min(Math.abs(width.value) / 2, Math.abs(height.value) / 2));
|
|
2578
2878
|
}));
|
|
2579
2879
|
break;
|
|
2580
2880
|
|
|
@@ -6655,14 +6955,13 @@ var CSSRGB = /*#__PURE__*/function (_CSSColorValue) {
|
|
|
6655
6955
|
return CSSRGB;
|
|
6656
6956
|
}(CSSColorValue);
|
|
6657
6957
|
|
|
6658
|
-
var
|
|
6958
|
+
var GradientType;
|
|
6659
6959
|
|
|
6660
|
-
(function (
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
})(GradientPatternType || (GradientPatternType = {}));
|
|
6960
|
+
(function (GradientType) {
|
|
6961
|
+
GradientType[GradientType["Constant"] = 0] = "Constant";
|
|
6962
|
+
GradientType[GradientType["LinearGradient"] = 1] = "LinearGradient";
|
|
6963
|
+
GradientType[GradientType["RadialGradient"] = 2] = "RadialGradient";
|
|
6964
|
+
})(GradientType || (GradientType = {}));
|
|
6666
6965
|
|
|
6667
6966
|
var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
|
|
6668
6967
|
_inheritsLoose(CSSGradientValue, _CSSStyleValue);
|
|
@@ -6685,39 +6984,299 @@ var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
|
|
|
6685
6984
|
};
|
|
6686
6985
|
|
|
6687
6986
|
_proto.buildCSSText = function buildCSSText(n, p, result) {
|
|
6688
|
-
|
|
6987
|
+
return result;
|
|
6988
|
+
};
|
|
6989
|
+
|
|
6990
|
+
_proto.getType = function getType() {
|
|
6991
|
+
return CSSStyleValueType.kColorType;
|
|
6992
|
+
};
|
|
6993
|
+
|
|
6994
|
+
return CSSGradientValue;
|
|
6995
|
+
}(CSSStyleValue);
|
|
6996
|
+
|
|
6997
|
+
var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
|
|
6998
|
+
var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
|
|
6999
|
+
var regexPR = /^p\s*\(\s*([axyn])\s*\)\s*(.*)/i;
|
|
7000
|
+
var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
|
|
7001
|
+
|
|
7002
|
+
function spaceColorStops(colorStops) {
|
|
7003
|
+
var _colorStops$length;
|
|
7004
|
+
|
|
7005
|
+
var length = colorStops.length;
|
|
7006
|
+
colorStops[length - 1].length = (_colorStops$length = colorStops[length - 1].length) !== null && _colorStops$length !== void 0 ? _colorStops$length : {
|
|
7007
|
+
type: '%',
|
|
7008
|
+
value: '100'
|
|
7009
|
+
};
|
|
7010
|
+
|
|
7011
|
+
if (length > 1) {
|
|
7012
|
+
var _colorStops$0$length;
|
|
7013
|
+
|
|
7014
|
+
colorStops[0].length = (_colorStops$0$length = colorStops[0].length) !== null && _colorStops$0$length !== void 0 ? _colorStops$0$length : {
|
|
7015
|
+
type: '%',
|
|
7016
|
+
value: '0'
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
7019
|
+
|
|
7020
|
+
var previousIndex = 0;
|
|
7021
|
+
var previousOffset = Number(colorStops[0].length.value);
|
|
7022
|
+
|
|
7023
|
+
for (var i = 1; i < length; i++) {
|
|
7024
|
+
var _colorStops$i$length;
|
|
7025
|
+
|
|
7026
|
+
var offset = (_colorStops$i$length = colorStops[i].length) === null || _colorStops$i$length === void 0 ? void 0 : _colorStops$i$length.value;
|
|
7027
|
+
|
|
7028
|
+
if (!isNil(offset) && !isNil(previousOffset)) {
|
|
7029
|
+
for (var j = 1; j < i - previousIndex; j++) {
|
|
7030
|
+
colorStops[previousIndex + j].length = {
|
|
7031
|
+
type: '%',
|
|
7032
|
+
value: "" + (previousOffset + (Number(offset) - previousOffset) * j / (i - previousIndex))
|
|
7033
|
+
};
|
|
7034
|
+
}
|
|
7035
|
+
|
|
7036
|
+
previousIndex = i;
|
|
7037
|
+
previousOffset = Number(offset);
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
} // The position of the gradient line's starting point.
|
|
7041
|
+
// different from CSS side(to top) @see https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient#values
|
|
7042
|
+
|
|
7043
|
+
|
|
7044
|
+
var SideOrCornerToDegMap = {
|
|
7045
|
+
left: 270 - 90,
|
|
7046
|
+
top: 0 - 90,
|
|
7047
|
+
bottom: 180 - 90,
|
|
7048
|
+
right: 90 - 90,
|
|
7049
|
+
'left top': 315 - 90,
|
|
7050
|
+
'top left': 315 - 90,
|
|
7051
|
+
'left bottom': 225 - 90,
|
|
7052
|
+
'bottom left': 225 - 90,
|
|
7053
|
+
'right top': 45 - 90,
|
|
7054
|
+
'top right': 45 - 90,
|
|
7055
|
+
'right bottom': 135 - 90,
|
|
7056
|
+
'bottom right': 135 - 90
|
|
7057
|
+
};
|
|
7058
|
+
var angleToDeg = memoize(function (orientation) {
|
|
7059
|
+
var angle;
|
|
7060
|
+
|
|
7061
|
+
if (orientation.type === 'angular') {
|
|
7062
|
+
angle = Number(orientation.value);
|
|
7063
|
+
} else {
|
|
7064
|
+
angle = SideOrCornerToDegMap[orientation.value] || 0;
|
|
7065
|
+
}
|
|
7066
|
+
|
|
7067
|
+
return angle;
|
|
7068
|
+
});
|
|
7069
|
+
var positonToPercentage = memoize(function (position) {
|
|
7070
|
+
var cx = 0.5;
|
|
7071
|
+
var cy = 0.5;
|
|
7072
|
+
|
|
7073
|
+
if ((position === null || position === void 0 ? void 0 : position.type) === 'position') {
|
|
7074
|
+
var _position$value = position.value,
|
|
7075
|
+
x = _position$value.x,
|
|
7076
|
+
y = _position$value.y;
|
|
7077
|
+
|
|
7078
|
+
if ((x === null || x === void 0 ? void 0 : x.type) === 'position-keyword') {
|
|
7079
|
+
if (x.value === 'left') {
|
|
7080
|
+
cx = 0;
|
|
7081
|
+
} else if (x.value === 'center') {
|
|
7082
|
+
cx = 0.5;
|
|
7083
|
+
} else if (x.value === 'right') {
|
|
7084
|
+
cx = 1;
|
|
7085
|
+
} else if (x.value === 'top') {
|
|
7086
|
+
cy = 0;
|
|
7087
|
+
} else if (x.value === 'bottom') {
|
|
7088
|
+
cy = 1;
|
|
7089
|
+
}
|
|
7090
|
+
}
|
|
7091
|
+
|
|
7092
|
+
if ((y === null || y === void 0 ? void 0 : y.type) === 'position-keyword') {
|
|
7093
|
+
if (y.value === 'left') {
|
|
7094
|
+
cx = 0;
|
|
7095
|
+
} else if (y.value === 'center') {
|
|
7096
|
+
cy = 0.5;
|
|
7097
|
+
} else if (y.value === 'right') {
|
|
7098
|
+
cx = 1;
|
|
7099
|
+
} else if (y.value === 'top') {
|
|
7100
|
+
cy = 0;
|
|
7101
|
+
} else if (y.value === 'bottom') {
|
|
7102
|
+
cy = 1;
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
|
|
7106
|
+
if ((x === null || x === void 0 ? void 0 : x.type) === '%') {
|
|
7107
|
+
cx = Number(x.value) / 100;
|
|
7108
|
+
}
|
|
7109
|
+
|
|
7110
|
+
if ((y === null || y === void 0 ? void 0 : y.type) === '%') {
|
|
7111
|
+
cy = Number(x.value) / 100;
|
|
7112
|
+
}
|
|
7113
|
+
}
|
|
7114
|
+
|
|
7115
|
+
return {
|
|
7116
|
+
cx: cx,
|
|
7117
|
+
cy: cy
|
|
7118
|
+
};
|
|
7119
|
+
});
|
|
7120
|
+
var parseGradient$1 = memoize(function (colorStr) {
|
|
7121
|
+
if (colorStr.indexOf('linear') > -1 || colorStr.indexOf('radial') > -1) {
|
|
7122
|
+
var ast = parseGradient(colorStr);
|
|
7123
|
+
return ast.map(function (_ref) {
|
|
7124
|
+
var type = _ref.type,
|
|
7125
|
+
orientation = _ref.orientation,
|
|
7126
|
+
colorStops = _ref.colorStops;
|
|
7127
|
+
spaceColorStops(colorStops);
|
|
7128
|
+
var steps = colorStops.map(function (colorStop) {
|
|
7129
|
+
// TODO: only support % for now, should calc percentage of axis length when using px/em
|
|
7130
|
+
return [Number(colorStop.length.value) / 100, colorStopToString(colorStop)];
|
|
7131
|
+
});
|
|
7132
|
+
|
|
7133
|
+
if (type === 'linear-gradient') {
|
|
7134
|
+
return new CSSGradientValue(GradientType.LinearGradient, {
|
|
7135
|
+
angle: orientation ? angleToDeg(orientation) : 0,
|
|
7136
|
+
steps: steps,
|
|
7137
|
+
hash: colorStr
|
|
7138
|
+
});
|
|
7139
|
+
} else if (type === 'radial-gradient') {
|
|
7140
|
+
if (!orientation) {
|
|
7141
|
+
orientation = [{
|
|
7142
|
+
type: 'shape',
|
|
7143
|
+
value: 'circle'
|
|
7144
|
+
}];
|
|
7145
|
+
}
|
|
7146
|
+
|
|
7147
|
+
if (orientation[0].type === 'shape' && orientation[0].value === 'circle') {
|
|
7148
|
+
var _positonToPercentage = positonToPercentage(orientation[0].at),
|
|
7149
|
+
cx = _positonToPercentage.cx,
|
|
7150
|
+
cy = _positonToPercentage.cy;
|
|
7151
|
+
|
|
7152
|
+
return new CSSGradientValue(GradientType.RadialGradient, {
|
|
7153
|
+
cx: cx,
|
|
7154
|
+
cy: cy,
|
|
7155
|
+
steps: steps,
|
|
7156
|
+
hash: colorStr
|
|
7157
|
+
});
|
|
7158
|
+
} // } else if (type === 'repeating-linear-gradient') {
|
|
7159
|
+
// } else if (type === 'repeating-radial-gradient') {
|
|
7160
|
+
|
|
7161
|
+
}
|
|
7162
|
+
});
|
|
7163
|
+
} // legacy format, should be deprecated later
|
|
7164
|
+
|
|
7165
|
+
|
|
7166
|
+
var type = colorStr[0];
|
|
7167
|
+
|
|
7168
|
+
if (colorStr[1] === '(' || colorStr[2] === '(') {
|
|
7169
|
+
if (type === 'l') {
|
|
7170
|
+
var arr = regexLG.exec(colorStr);
|
|
7171
|
+
|
|
7172
|
+
if (arr) {
|
|
7173
|
+
var _arr$2$match;
|
|
7174
|
+
|
|
7175
|
+
var steps = ((_arr$2$match = arr[2].match(regexColorStop)) === null || _arr$2$match === void 0 ? void 0 : _arr$2$match.map(function (stop) {
|
|
7176
|
+
return stop.split(':');
|
|
7177
|
+
})) || [];
|
|
7178
|
+
return [new CSSGradientValue(GradientType.LinearGradient, {
|
|
7179
|
+
angle: parseFloat(arr[1]),
|
|
7180
|
+
steps: steps.map(function (_ref2) {
|
|
7181
|
+
var offset = _ref2[0],
|
|
7182
|
+
color = _ref2[1];
|
|
7183
|
+
return [Number(offset), color];
|
|
7184
|
+
}),
|
|
7185
|
+
hash: colorStr
|
|
7186
|
+
})];
|
|
7187
|
+
}
|
|
7188
|
+
} else if (type === 'r') {
|
|
7189
|
+
var parsedRadialGradient = parseRadialGradient(colorStr);
|
|
7190
|
+
|
|
7191
|
+
if (parsedRadialGradient) {
|
|
7192
|
+
if (isString(parsedRadialGradient)) {
|
|
7193
|
+
colorStr = parsedRadialGradient;
|
|
7194
|
+
} else {
|
|
7195
|
+
return [new CSSGradientValue(GradientType.RadialGradient, parsedRadialGradient)];
|
|
7196
|
+
}
|
|
7197
|
+
}
|
|
7198
|
+
} else if (type === 'p') {
|
|
7199
|
+
return parsePattern(colorStr);
|
|
7200
|
+
}
|
|
7201
|
+
}
|
|
7202
|
+
});
|
|
7203
|
+
|
|
7204
|
+
function parseRadialGradient(gradientStr) {
|
|
7205
|
+
var arr = regexRG.exec(gradientStr);
|
|
7206
|
+
|
|
7207
|
+
if (arr) {
|
|
7208
|
+
var _arr$4$match;
|
|
7209
|
+
|
|
7210
|
+
var steps = ((_arr$4$match = arr[4].match(regexColorStop)) === null || _arr$4$match === void 0 ? void 0 : _arr$4$match.map(function (stop) {
|
|
7211
|
+
return stop.split(':');
|
|
7212
|
+
})) || [];
|
|
7213
|
+
return {
|
|
7214
|
+
cx: 0.5,
|
|
7215
|
+
cy: 0.5,
|
|
7216
|
+
steps: steps.map(function (_ref3) {
|
|
7217
|
+
var offset = _ref3[0],
|
|
7218
|
+
color = _ref3[1];
|
|
7219
|
+
return [Number(offset), color];
|
|
7220
|
+
}),
|
|
7221
|
+
hash: gradientStr
|
|
7222
|
+
};
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
return null;
|
|
7226
|
+
}
|
|
7227
|
+
|
|
7228
|
+
function parsePattern(patternStr) {
|
|
7229
|
+
var arr = regexPR.exec(patternStr);
|
|
7230
|
+
|
|
7231
|
+
if (arr) {
|
|
7232
|
+
var repetition = arr[1];
|
|
7233
|
+
var src = arr[2];
|
|
7234
|
+
|
|
7235
|
+
switch (repetition) {
|
|
7236
|
+
case 'a':
|
|
7237
|
+
repetition = 'repeat';
|
|
7238
|
+
break;
|
|
7239
|
+
|
|
7240
|
+
case 'x':
|
|
7241
|
+
repetition = 'repeat-x';
|
|
7242
|
+
break;
|
|
7243
|
+
|
|
7244
|
+
case 'y':
|
|
7245
|
+
repetition = 'repeat-y';
|
|
7246
|
+
break;
|
|
7247
|
+
|
|
7248
|
+
case 'n':
|
|
7249
|
+
repetition = 'no-repeat';
|
|
7250
|
+
break;
|
|
6689
7251
|
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
return step.join(',');
|
|
6693
|
-
}).join(',') + ")";
|
|
6694
|
-
} else if (this.type === GradientPatternType.RadialGradient) {
|
|
6695
|
-
text = "radial-gradient(" + this.value.steps.map(function (step) {
|
|
6696
|
-
return step.join(',');
|
|
6697
|
-
}).join(',') + ")";
|
|
6698
|
-
} else if (this.type === GradientPatternType.Pattern) {
|
|
6699
|
-
text = "url(" + this.value.src + ")";
|
|
7252
|
+
default:
|
|
7253
|
+
repetition = 'no-repeat';
|
|
6700
7254
|
}
|
|
6701
7255
|
|
|
6702
|
-
return
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
}
|
|
7256
|
+
return {
|
|
7257
|
+
image: src,
|
|
7258
|
+
// @ts-ignore
|
|
7259
|
+
repetition: repetition
|
|
7260
|
+
};
|
|
7261
|
+
}
|
|
6708
7262
|
|
|
6709
|
-
return
|
|
6710
|
-
}
|
|
7263
|
+
return null;
|
|
7264
|
+
}
|
|
6711
7265
|
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
|
|
7266
|
+
function isPattern(object) {
|
|
7267
|
+
return isObject(object) && !!object.image;
|
|
7268
|
+
}
|
|
6716
7269
|
/**
|
|
6717
7270
|
* @see https://github.com/WebKit/WebKit/blob/main/Source/WebCore/css/parser/CSSParser.cpp#L97
|
|
6718
7271
|
*/
|
|
6719
7272
|
|
|
6720
|
-
|
|
7273
|
+
var parseColor = memoize(function (colorStr) {
|
|
7274
|
+
if (isPattern(colorStr)) {
|
|
7275
|
+
return _extends({
|
|
7276
|
+
repetition: 'repeat'
|
|
7277
|
+
}, colorStr);
|
|
7278
|
+
}
|
|
7279
|
+
|
|
6721
7280
|
if (isNil(colorStr)) {
|
|
6722
7281
|
colorStr = '';
|
|
6723
7282
|
}
|
|
@@ -6728,34 +7287,13 @@ function parseColor(colorStr) {
|
|
|
6728
7287
|
} else if (colorStr === 'currentColor') {
|
|
6729
7288
|
// @see https://github.com/adobe-webplatform/Snap.svg/issues/526
|
|
6730
7289
|
colorStr = 'black';
|
|
6731
|
-
}
|
|
6732
|
-
|
|
6733
|
-
var type = colorStr[0];
|
|
7290
|
+
} // support CSS gradient syntax
|
|
6734
7291
|
|
|
6735
|
-
if (colorStr[1] === '(' || colorStr[2] === '(') {
|
|
6736
|
-
if (type === 'l') {
|
|
6737
|
-
var parsedLineGradient = parseLineGradient(colorStr);
|
|
6738
|
-
|
|
6739
|
-
if (parsedLineGradient) {
|
|
6740
|
-
return new CSSGradientValue(GradientPatternType.LinearGradient, parsedLineGradient);
|
|
6741
|
-
}
|
|
6742
|
-
} else if (type === 'r') {
|
|
6743
|
-
var parsedRadialGradient = parseRadialGradient(colorStr);
|
|
6744
7292
|
|
|
6745
|
-
|
|
6746
|
-
if (isString(parsedRadialGradient)) {
|
|
6747
|
-
colorStr = parsedRadialGradient;
|
|
6748
|
-
} else {
|
|
6749
|
-
return new CSSGradientValue(GradientPatternType.RadialGradient, parsedRadialGradient);
|
|
6750
|
-
}
|
|
6751
|
-
}
|
|
6752
|
-
} else if (type === 'p') {
|
|
6753
|
-
var pattern = parsePattern(colorStr);
|
|
7293
|
+
var g = parseGradient$1(colorStr);
|
|
6754
7294
|
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
}
|
|
6758
|
-
}
|
|
7295
|
+
if (g) {
|
|
7296
|
+
return g;
|
|
6759
7297
|
} // constants
|
|
6760
7298
|
|
|
6761
7299
|
|
|
@@ -6778,7 +7316,7 @@ function parseColor(colorStr) {
|
|
|
6778
7316
|
// (color && `rgba(${color.r || 0},${color.g || 0},${color.b || 0},${color.opacity})`) ||
|
|
6779
7317
|
// 'rgba(0,0,0,0)',
|
|
6780
7318
|
// };
|
|
6781
|
-
}
|
|
7319
|
+
});
|
|
6782
7320
|
function mergeColors(left, right) {
|
|
6783
7321
|
// only support constant value, exclude gradient & pattern
|
|
6784
7322
|
if (!(left instanceof CSSRGB) || !(right instanceof CSSRGB)) {
|
|
@@ -6799,149 +7337,6 @@ function mergeColors(left, right) {
|
|
|
6799
7337
|
}];
|
|
6800
7338
|
}
|
|
6801
7339
|
|
|
6802
|
-
function parsePattern(patternStr) {
|
|
6803
|
-
var arr = regexPR.exec(patternStr);
|
|
6804
|
-
|
|
6805
|
-
if (arr) {
|
|
6806
|
-
var repetition = arr[1];
|
|
6807
|
-
var src = arr[2];
|
|
6808
|
-
|
|
6809
|
-
switch (repetition) {
|
|
6810
|
-
case 'a':
|
|
6811
|
-
repetition = 'repeat';
|
|
6812
|
-
break;
|
|
6813
|
-
|
|
6814
|
-
case 'x':
|
|
6815
|
-
repetition = 'repeat-x';
|
|
6816
|
-
break;
|
|
6817
|
-
|
|
6818
|
-
case 'y':
|
|
6819
|
-
repetition = 'repeat-y';
|
|
6820
|
-
break;
|
|
6821
|
-
|
|
6822
|
-
case 'n':
|
|
6823
|
-
repetition = 'no-repeat';
|
|
6824
|
-
break;
|
|
6825
|
-
|
|
6826
|
-
default:
|
|
6827
|
-
repetition = 'no-repeat';
|
|
6828
|
-
}
|
|
6829
|
-
|
|
6830
|
-
return {
|
|
6831
|
-
src: src,
|
|
6832
|
-
repetition: repetition,
|
|
6833
|
-
hash: patternStr
|
|
6834
|
-
};
|
|
6835
|
-
}
|
|
6836
|
-
|
|
6837
|
-
return null;
|
|
6838
|
-
}
|
|
6839
|
-
|
|
6840
|
-
function parseLineGradient(gradientStr) {
|
|
6841
|
-
var arr = regexLG.exec(gradientStr);
|
|
6842
|
-
|
|
6843
|
-
if (arr) {
|
|
6844
|
-
var _arr$2$match;
|
|
6845
|
-
|
|
6846
|
-
var angle = parseFloat(arr[1]) % 360 * (Math.PI / 180);
|
|
6847
|
-
var steps = ((_arr$2$match = arr[2].match(regexColorStop)) === null || _arr$2$match === void 0 ? void 0 : _arr$2$match.map(function (stop) {
|
|
6848
|
-
return stop.split(':');
|
|
6849
|
-
})) || [];
|
|
6850
|
-
var maxX = 1,
|
|
6851
|
-
maxY = 1;
|
|
6852
|
-
var minX = 0,
|
|
6853
|
-
minY = 0;
|
|
6854
|
-
var start;
|
|
6855
|
-
var end;
|
|
6856
|
-
|
|
6857
|
-
if (angle >= 0 && angle < 1 / 2 * Math.PI) {
|
|
6858
|
-
start = {
|
|
6859
|
-
x: minX,
|
|
6860
|
-
y: minY
|
|
6861
|
-
};
|
|
6862
|
-
end = {
|
|
6863
|
-
x: maxX,
|
|
6864
|
-
y: maxY
|
|
6865
|
-
};
|
|
6866
|
-
} else if (1 / 2 * Math.PI <= angle && angle < Math.PI) {
|
|
6867
|
-
start = {
|
|
6868
|
-
x: maxX,
|
|
6869
|
-
y: minY
|
|
6870
|
-
};
|
|
6871
|
-
end = {
|
|
6872
|
-
x: minX,
|
|
6873
|
-
y: maxY
|
|
6874
|
-
};
|
|
6875
|
-
} else if (Math.PI <= angle && angle < 3 / 2 * Math.PI) {
|
|
6876
|
-
start = {
|
|
6877
|
-
x: maxX,
|
|
6878
|
-
y: maxY
|
|
6879
|
-
};
|
|
6880
|
-
end = {
|
|
6881
|
-
x: minX,
|
|
6882
|
-
y: minY
|
|
6883
|
-
};
|
|
6884
|
-
} else {
|
|
6885
|
-
start = {
|
|
6886
|
-
x: minX,
|
|
6887
|
-
y: maxY
|
|
6888
|
-
};
|
|
6889
|
-
end = {
|
|
6890
|
-
x: maxX,
|
|
6891
|
-
y: minY
|
|
6892
|
-
};
|
|
6893
|
-
}
|
|
6894
|
-
|
|
6895
|
-
var tanTheta = Math.tan(angle);
|
|
6896
|
-
var tanTheta2 = tanTheta * tanTheta;
|
|
6897
|
-
var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
|
|
6898
|
-
var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
|
|
6899
|
-
return {
|
|
6900
|
-
x0: start.x,
|
|
6901
|
-
y0: start.y,
|
|
6902
|
-
x1: x,
|
|
6903
|
-
y1: y,
|
|
6904
|
-
steps: steps,
|
|
6905
|
-
hash: gradientStr
|
|
6906
|
-
};
|
|
6907
|
-
}
|
|
6908
|
-
|
|
6909
|
-
return null;
|
|
6910
|
-
}
|
|
6911
|
-
|
|
6912
|
-
function parseRadialGradient(gradientStr) {
|
|
6913
|
-
var arr = regexRG.exec(gradientStr);
|
|
6914
|
-
|
|
6915
|
-
if (arr) {
|
|
6916
|
-
var _arr$4$match;
|
|
6917
|
-
|
|
6918
|
-
var fx = parseFloat(arr[1]);
|
|
6919
|
-
var fy = parseFloat(arr[2]);
|
|
6920
|
-
var fr = parseFloat(arr[3]);
|
|
6921
|
-
var steps = ((_arr$4$match = arr[4].match(regexColorStop)) === null || _arr$4$match === void 0 ? void 0 : _arr$4$match.map(function (stop) {
|
|
6922
|
-
return stop.split(':');
|
|
6923
|
-
})) || []; // 环半径为0时,默认无渐变,取渐变序列的最后一个颜色
|
|
6924
|
-
|
|
6925
|
-
if (fr === 0) {
|
|
6926
|
-
var colors = arr[4].match(regexColorStop);
|
|
6927
|
-
return colors[colors.length - 1].split(':')[1];
|
|
6928
|
-
}
|
|
6929
|
-
|
|
6930
|
-
return {
|
|
6931
|
-
x0: fx,
|
|
6932
|
-
y0: fy,
|
|
6933
|
-
r0: 0,
|
|
6934
|
-
x1: 0.5,
|
|
6935
|
-
y1: 0.5,
|
|
6936
|
-
r1: fr,
|
|
6937
|
-
steps: steps,
|
|
6938
|
-
hash: gradientStr
|
|
6939
|
-
};
|
|
6940
|
-
}
|
|
6941
|
-
|
|
6942
|
-
return null;
|
|
6943
|
-
}
|
|
6944
|
-
|
|
6945
7340
|
/**
|
|
6946
7341
|
* Axis-Aligned Bounding Box
|
|
6947
7342
|
* 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
|
|
@@ -7657,8 +8052,7 @@ function convertPercentUnit(valueWithUnit, vec3Index, target) {
|
|
|
7657
8052
|
if (valueWithUnit.unit === UnitType.kPixels) {
|
|
7658
8053
|
return Number(valueWithUnit.value);
|
|
7659
8054
|
} else if (valueWithUnit.unit === UnitType.kPercentage && target) {
|
|
7660
|
-
|
|
7661
|
-
var bounds = target.getGeometryBounds();
|
|
8055
|
+
var bounds = target.nodeName === Shape.GROUP ? target.getLocalBounds() : target.getGeometryBounds();
|
|
7662
8056
|
var size = 0;
|
|
7663
8057
|
|
|
7664
8058
|
if (!AABB.isEmpty(bounds)) {
|
|
@@ -7733,31 +8127,40 @@ function mergeNumberLists(left, right) {
|
|
|
7733
8127
|
}
|
|
7734
8128
|
|
|
7735
8129
|
function parsePath(path, object) {
|
|
7736
|
-
var absolutePath
|
|
8130
|
+
var absolutePath;
|
|
8131
|
+
|
|
8132
|
+
try {
|
|
8133
|
+
absolutePath = normalizePath(path);
|
|
8134
|
+
} catch (e) {
|
|
8135
|
+
absolutePath = normalizePath('');
|
|
8136
|
+
console.error("[g]: Invalid SVG Path definition: " + path);
|
|
8137
|
+
}
|
|
8138
|
+
|
|
7737
8139
|
var hasArc = hasArcOrBezier(absolutePath);
|
|
7738
|
-
var clonedAbsolutePath = absolutePath.slice();
|
|
7739
8140
|
|
|
7740
|
-
var _extractPolygons = extractPolygons(
|
|
8141
|
+
var _extractPolygons = extractPolygons(absolutePath),
|
|
7741
8142
|
polygons = _extractPolygons.polygons,
|
|
7742
8143
|
polylines = _extractPolygons.polylines; // convert to curves to do morphing & picking later
|
|
7743
8144
|
// @see http://thednp.github.io/kute.js/svgCubicMorph.html
|
|
7744
8145
|
|
|
7745
8146
|
|
|
7746
|
-
var _path2Curve = path2Curve(
|
|
8147
|
+
var _path2Curve = path2Curve(absolutePath, true),
|
|
7747
8148
|
curve = _path2Curve[0],
|
|
7748
|
-
zCommandIndexes = _path2Curve[1];
|
|
8149
|
+
zCommandIndexes = _path2Curve[1]; // for later use
|
|
7749
8150
|
|
|
7750
|
-
var segments = path2Segments(clonedAbsolutePath);
|
|
7751
8151
|
|
|
7752
|
-
var
|
|
7753
|
-
totalLength = _calcLength.totalLength,
|
|
7754
|
-
curveSegments = _calcLength.curveSegments;
|
|
8152
|
+
var segments = path2Segments(curve);
|
|
7755
8153
|
|
|
7756
|
-
var
|
|
8154
|
+
var _getPathBBoxTotalLeng = getPathBBoxTotalLength(absolutePath),
|
|
8155
|
+
x = _getPathBBoxTotalLeng.x,
|
|
8156
|
+
y = _getPathBBoxTotalLeng.y,
|
|
8157
|
+
width = _getPathBBoxTotalLeng.width,
|
|
8158
|
+
height = _getPathBBoxTotalLeng.height,
|
|
8159
|
+
length = _getPathBBoxTotalLeng.length;
|
|
7757
8160
|
|
|
7758
8161
|
if (object) {
|
|
7759
|
-
object.parsedStyle.defX =
|
|
7760
|
-
object.parsedStyle.defY =
|
|
8162
|
+
object.parsedStyle.defX = x;
|
|
8163
|
+
object.parsedStyle.defY = y;
|
|
7761
8164
|
}
|
|
7762
8165
|
|
|
7763
8166
|
return {
|
|
@@ -7767,158 +8170,11 @@ function parsePath(path, object) {
|
|
|
7767
8170
|
polygons: polygons,
|
|
7768
8171
|
polylines: polylines,
|
|
7769
8172
|
curve: curve,
|
|
7770
|
-
totalLength:
|
|
7771
|
-
curveSegments: curveSegments,
|
|
8173
|
+
totalLength: length,
|
|
7772
8174
|
zCommandIndexes: zCommandIndexes,
|
|
7773
|
-
rect:
|
|
7774
|
-
};
|
|
7775
|
-
}
|
|
7776
|
-
|
|
7777
|
-
function hasArcOrBezier(path) {
|
|
7778
|
-
var hasArc = false;
|
|
7779
|
-
var count = path.length;
|
|
7780
|
-
|
|
7781
|
-
for (var i = 0; i < count; i++) {
|
|
7782
|
-
var params = path[i];
|
|
7783
|
-
var cmd = params[0];
|
|
7784
|
-
|
|
7785
|
-
if (cmd === 'C' || cmd === 'A' || cmd === 'Q') {
|
|
7786
|
-
hasArc = true;
|
|
7787
|
-
break;
|
|
7788
|
-
}
|
|
7789
|
-
}
|
|
7790
|
-
|
|
7791
|
-
return hasArc;
|
|
7792
|
-
}
|
|
7793
|
-
|
|
7794
|
-
function extractPolygons(pathArray) {
|
|
7795
|
-
var polygons = [];
|
|
7796
|
-
var polylines = [];
|
|
7797
|
-
var points = []; // 防止第一个命令不是 'M'
|
|
7798
|
-
|
|
7799
|
-
for (var i = 0; i < pathArray.length; i++) {
|
|
7800
|
-
var params = pathArray[i];
|
|
7801
|
-
var cmd = params[0];
|
|
7802
|
-
|
|
7803
|
-
if (cmd === 'M') {
|
|
7804
|
-
// 遇到 'M' 判定是否是新数组,新数组中没有点
|
|
7805
|
-
if (points.length) {
|
|
7806
|
-
// 如果存在点,则说明没有遇到 'Z',开始了一个新的多边形
|
|
7807
|
-
polylines.push(points);
|
|
7808
|
-
points = []; // 创建新的点
|
|
7809
|
-
}
|
|
7810
|
-
|
|
7811
|
-
points.push([params[1], params[2]]);
|
|
7812
|
-
} else if (cmd === 'Z') {
|
|
7813
|
-
if (points.length) {
|
|
7814
|
-
// 存在点
|
|
7815
|
-
polygons.push(points);
|
|
7816
|
-
points = []; // 开始新的点集合
|
|
7817
|
-
} // 如果不存在点,同时 'Z',则说明是错误,不处理
|
|
7818
|
-
|
|
7819
|
-
} else {
|
|
7820
|
-
points.push([params[1], params[2]]);
|
|
7821
|
-
}
|
|
7822
|
-
} // 说明 points 未放入 polygons 或者 polyline
|
|
7823
|
-
// 仅当只有一个 M,没有 Z 时会发生这种情况
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
if (points.length > 0) {
|
|
7827
|
-
polylines.push(points);
|
|
7828
|
-
}
|
|
7829
|
-
|
|
7830
|
-
return {
|
|
7831
|
-
polygons: polygons,
|
|
7832
|
-
polylines: polylines
|
|
7833
|
-
};
|
|
7834
|
-
}
|
|
7835
|
-
|
|
7836
|
-
function calcLength(curve) {
|
|
7837
|
-
var totalLength = 0;
|
|
7838
|
-
var tempLength = 0; // 每段 curve 对应起止点的长度比例列表,形如: [[0, 0.25], [0.25, 0.6]. [0.6, 0.9], [0.9, 1]]
|
|
7839
|
-
|
|
7840
|
-
var curveSegments = [];
|
|
7841
|
-
var segmentT;
|
|
7842
|
-
var segmentL;
|
|
7843
|
-
var segmentN;
|
|
7844
|
-
var l;
|
|
7845
|
-
|
|
7846
|
-
if (!curve) {
|
|
7847
|
-
return {
|
|
7848
|
-
curveSegments: [],
|
|
7849
|
-
totalLength: totalLength
|
|
7850
|
-
};
|
|
7851
|
-
}
|
|
7852
|
-
|
|
7853
|
-
curve.forEach(function (segment, i) {
|
|
7854
|
-
segmentN = curve[i + 1];
|
|
7855
|
-
l = segment.length;
|
|
7856
|
-
|
|
7857
|
-
if (segmentN) {
|
|
7858
|
-
totalLength += Cubic$1.length(segment[l - 2], segment[l - 1], segmentN[1], segmentN[2], segmentN[3], segmentN[4], segmentN[5], segmentN[6]) || 0;
|
|
7859
|
-
}
|
|
7860
|
-
});
|
|
7861
|
-
|
|
7862
|
-
if (totalLength === 0) {
|
|
7863
|
-
return {
|
|
7864
|
-
curveSegments: [],
|
|
7865
|
-
totalLength: totalLength
|
|
7866
|
-
};
|
|
7867
|
-
}
|
|
7868
|
-
|
|
7869
|
-
curve.forEach(function (segment, i) {
|
|
7870
|
-
segmentN = curve[i + 1];
|
|
7871
|
-
l = segment.length;
|
|
7872
|
-
|
|
7873
|
-
if (segmentN) {
|
|
7874
|
-
segmentT = [];
|
|
7875
|
-
segmentT[0] = tempLength / totalLength;
|
|
7876
|
-
segmentL = Cubic$1.length(segment[l - 2], segment[l - 1], segmentN[1], segmentN[2], segmentN[3], segmentN[4], segmentN[5], segmentN[6]); // 当 path 不连续时,segmentL 可能为空,为空时需要作为 0 处理
|
|
7877
|
-
|
|
7878
|
-
tempLength += segmentL || 0;
|
|
7879
|
-
segmentT[1] = tempLength / totalLength;
|
|
7880
|
-
curveSegments.push(segmentT);
|
|
7881
|
-
}
|
|
7882
|
-
});
|
|
7883
|
-
return {
|
|
7884
|
-
curveSegments: curveSegments,
|
|
7885
|
-
totalLength: totalLength
|
|
8175
|
+
rect: new Rectangle(x, y, width, height)
|
|
7886
8176
|
};
|
|
7887
8177
|
}
|
|
7888
|
-
|
|
7889
|
-
function getPathBBox(segments) {
|
|
7890
|
-
var x = 0;
|
|
7891
|
-
var y = 0;
|
|
7892
|
-
var X = [];
|
|
7893
|
-
var Y = [];
|
|
7894
|
-
segments.forEach(function (segment) {
|
|
7895
|
-
var _segment$slice = segment.slice(-2),
|
|
7896
|
-
s1 = _segment$slice[0],
|
|
7897
|
-
s2 = _segment$slice[1];
|
|
7898
|
-
|
|
7899
|
-
if (segment[0] === 'M') {
|
|
7900
|
-
x = s1;
|
|
7901
|
-
y = s2;
|
|
7902
|
-
X.push(s1);
|
|
7903
|
-
Y.push(s2);
|
|
7904
|
-
} else if (segment[0] === 'C') {
|
|
7905
|
-
// @ts-ignore
|
|
7906
|
-
var dim = Cubic$1.box.apply(Cubic$1, [x, y].concat(segment.slice(1)));
|
|
7907
|
-
X = X.concat(dim.x, dim.x + dim.width);
|
|
7908
|
-
Y = Y.concat(dim.y, dim.y + dim.height);
|
|
7909
|
-
x = s1;
|
|
7910
|
-
y = s2;
|
|
7911
|
-
}
|
|
7912
|
-
});
|
|
7913
|
-
var xTop = Math.min.apply(0, X);
|
|
7914
|
-
var yTop = Math.min.apply(0, Y);
|
|
7915
|
-
var xBot = Math.max.apply(0, X);
|
|
7916
|
-
var yBot = Math.max.apply(0, Y);
|
|
7917
|
-
var width = xBot - xTop;
|
|
7918
|
-
var height = yBot - yTop;
|
|
7919
|
-
return new Rectangle(xTop, yTop, width, height);
|
|
7920
|
-
}
|
|
7921
|
-
|
|
7922
8178
|
function mergePaths(left, right, object) {
|
|
7923
8179
|
var curve1 = left.curve;
|
|
7924
8180
|
var curve2 = right.curve;
|
|
@@ -11856,37 +12112,13 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
|
|
|
11856
12112
|
;
|
|
11857
12113
|
|
|
11858
12114
|
_proto.getPoint = function getPoint(ratio) {
|
|
11859
|
-
var
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
if (!this.parsedStyle.path.curveSegments.length) {
|
|
11864
|
-
if (curve) {
|
|
11865
|
-
return new Point(curve[0][1], curve[0][2]);
|
|
11866
|
-
}
|
|
12115
|
+
var _this$parsedStyle$pat = this.parsedStyle.path,
|
|
12116
|
+
totalLength = _this$parsedStyle$pat.totalLength,
|
|
12117
|
+
absolutePath = _this$parsedStyle$pat.absolutePath;
|
|
11867
12118
|
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
|
|
11871
|
-
this.parsedStyle.path.curveSegments.forEach(function (v, i) {
|
|
11872
|
-
if (ratio >= v[0] && ratio <= v[1]) {
|
|
11873
|
-
subt = (ratio - v[0]) / (v[1] - v[0]);
|
|
11874
|
-
index = i;
|
|
11875
|
-
}
|
|
11876
|
-
});
|
|
11877
|
-
var seg = curve[index];
|
|
11878
|
-
|
|
11879
|
-
if (isNil(seg) || isNil(index)) {
|
|
11880
|
-
return null;
|
|
11881
|
-
}
|
|
11882
|
-
|
|
11883
|
-
var l = seg.length;
|
|
11884
|
-
var nextSeg = curve[index + 1];
|
|
11885
|
-
|
|
11886
|
-
var _CubicUtil$pointAt = Cubic$1.pointAt( // @ts-ignore
|
|
11887
|
-
seg[l - 2], seg[l - 1], nextSeg[1], nextSeg[2], nextSeg[3], nextSeg[4], nextSeg[5], nextSeg[6], subt),
|
|
11888
|
-
x = _CubicUtil$pointAt.x,
|
|
11889
|
-
y = _CubicUtil$pointAt.y;
|
|
12119
|
+
var _getPointAtLength = getPointAtLength(absolutePath, ratio * totalLength),
|
|
12120
|
+
x = _getPointAtLength.x,
|
|
12121
|
+
y = _getPointAtLength.y;
|
|
11890
12122
|
|
|
11891
12123
|
return new Point(x, y);
|
|
11892
12124
|
}
|
|
@@ -13261,6 +13493,7 @@ function dispatchCallbacks() {
|
|
|
13261
13493
|
scale: [1, 10],
|
|
13262
13494
|
}
|
|
13263
13495
|
*/
|
|
13496
|
+
|
|
13264
13497
|
function convertToArrayForm(effectInput) {
|
|
13265
13498
|
var normalizedEffectInput = [];
|
|
13266
13499
|
|
|
@@ -13373,7 +13606,7 @@ function normalizeKeyframes(effectInput, timing) {
|
|
|
13373
13606
|
for (var i = 0; i < keyframes.length; i++) {
|
|
13374
13607
|
var offset = keyframes[i].offset;
|
|
13375
13608
|
|
|
13376
|
-
if (offset
|
|
13609
|
+
if (!isNil(offset)) {
|
|
13377
13610
|
if (offset < previousOffset) {
|
|
13378
13611
|
throw new TypeError('Keyframes are not loosely sorted by offset. Sort or specify offsets.');
|
|
13379
13612
|
}
|
|
@@ -13404,15 +13637,15 @@ function normalizeKeyframes(effectInput, timing) {
|
|
|
13404
13637
|
var previousOffset = Number(keyframes[0].computedOffset);
|
|
13405
13638
|
|
|
13406
13639
|
for (var _i = 1; _i < length; _i++) {
|
|
13407
|
-
var _offset =
|
|
13640
|
+
var _offset = keyframes[_i].computedOffset;
|
|
13408
13641
|
|
|
13409
|
-
if (_offset
|
|
13642
|
+
if (!isNil(_offset) && !isNil(previousOffset)) {
|
|
13410
13643
|
for (var j = 1; j < _i - previousIndex; j++) {
|
|
13411
|
-
keyframes[previousIndex + j].computedOffset = previousOffset + (_offset - previousOffset) * j / (_i - previousIndex);
|
|
13644
|
+
keyframes[previousIndex + j].computedOffset = previousOffset + (Number(_offset) - previousOffset) * j / (_i - previousIndex);
|
|
13412
13645
|
}
|
|
13413
13646
|
|
|
13414
13647
|
previousIndex = _i;
|
|
13415
|
-
previousOffset = _offset;
|
|
13648
|
+
previousOffset = Number(_offset);
|
|
13416
13649
|
}
|
|
13417
13650
|
}
|
|
13418
13651
|
}
|
|
@@ -17953,143 +18186,6 @@ PathUpdater = __decorate([singleton({
|
|
|
17953
18186
|
named: Shape.PATH
|
|
17954
18187
|
}
|
|
17955
18188
|
})], PathUpdater);
|
|
17956
|
-
// let xArr = [];
|
|
17957
|
-
// let yArr = [];
|
|
17958
|
-
// const segmentsWithAngle = [];
|
|
17959
|
-
// for (let i = 0; i < segments.length; i++) {
|
|
17960
|
-
// const segment = segments[i];
|
|
17961
|
-
// const { currentPoint, params, prePoint } = segment;
|
|
17962
|
-
// let box;
|
|
17963
|
-
// switch (segment.command) {
|
|
17964
|
-
// case 'Q':
|
|
17965
|
-
// box = QuadUtil.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
|
|
17966
|
-
// break;
|
|
17967
|
-
// case 'C':
|
|
17968
|
-
// box = CubicUtil.box(
|
|
17969
|
-
// prePoint[0],
|
|
17970
|
-
// prePoint[1],
|
|
17971
|
-
// params[1],
|
|
17972
|
-
// params[2],
|
|
17973
|
-
// params[3],
|
|
17974
|
-
// params[4],
|
|
17975
|
-
// params[5],
|
|
17976
|
-
// params[6],
|
|
17977
|
-
// );
|
|
17978
|
-
// break;
|
|
17979
|
-
// case 'A':
|
|
17980
|
-
// // eslint-disable-next-line no-case-declarations
|
|
17981
|
-
// const { arcParams } = segment;
|
|
17982
|
-
// box = EllipseArcUtil.box(
|
|
17983
|
-
// arcParams.cx,
|
|
17984
|
-
// arcParams.cy,
|
|
17985
|
-
// arcParams.rx,
|
|
17986
|
-
// arcParams.ry,
|
|
17987
|
-
// arcParams.xRotation,
|
|
17988
|
-
// arcParams.startAngle,
|
|
17989
|
-
// arcParams.endAngle,
|
|
17990
|
-
// );
|
|
17991
|
-
// break;
|
|
17992
|
-
// default:
|
|
17993
|
-
// xArr.push(currentPoint[0]);
|
|
17994
|
-
// yArr.push(currentPoint[1]);
|
|
17995
|
-
// break;
|
|
17996
|
-
// }
|
|
17997
|
-
// if (box) {
|
|
17998
|
-
// segment.box = box;
|
|
17999
|
-
// xArr.push(box.x, box.x + box.width);
|
|
18000
|
-
// yArr.push(box.y, box.y + box.height);
|
|
18001
|
-
// }
|
|
18002
|
-
// if (
|
|
18003
|
-
// lineWidth &&
|
|
18004
|
-
// (segment.command === 'L' || segment.command === 'M') &&
|
|
18005
|
-
// segment.prePoint &&
|
|
18006
|
-
// segment.nextPoint
|
|
18007
|
-
// ) {
|
|
18008
|
-
// segmentsWithAngle.push(segment);
|
|
18009
|
-
// }
|
|
18010
|
-
// }
|
|
18011
|
-
// // bbox calculation should ignore NaN for path attribute
|
|
18012
|
-
// // ref: https://github.com/antvis/g/issues/210
|
|
18013
|
-
// xArr = xArr.filter((item) => !Number.isNaN(item));
|
|
18014
|
-
// yArr = yArr.filter((item) => !Number.isNaN(item));
|
|
18015
|
-
// let minX = min(xArr);
|
|
18016
|
-
// let minY = min(yArr);
|
|
18017
|
-
// let maxX = max(xArr);
|
|
18018
|
-
// let maxY = max(yArr);
|
|
18019
|
-
// if (segmentsWithAngle.length === 0) {
|
|
18020
|
-
// return {
|
|
18021
|
-
// x: minX,
|
|
18022
|
-
// y: minY,
|
|
18023
|
-
// width: maxX - minX,
|
|
18024
|
-
// height: maxY - minY,
|
|
18025
|
-
// };
|
|
18026
|
-
// }
|
|
18027
|
-
// for (let i = 0; i < segmentsWithAngle.length; i++) {
|
|
18028
|
-
// const segment = segmentsWithAngle[i];
|
|
18029
|
-
// const { currentPoint } = segment;
|
|
18030
|
-
// let extra;
|
|
18031
|
-
// if (currentPoint[0] === minX) {
|
|
18032
|
-
// extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
|
18033
|
-
// minX -= extra.xExtra;
|
|
18034
|
-
// } else if (currentPoint[0] === maxX) {
|
|
18035
|
-
// extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
|
18036
|
-
// maxX += extra.xExtra;
|
|
18037
|
-
// }
|
|
18038
|
-
// if (currentPoint[1] === minY) {
|
|
18039
|
-
// extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
|
18040
|
-
// minY -= extra.yExtra;
|
|
18041
|
-
// } else if (currentPoint[1] === maxY) {
|
|
18042
|
-
// extra = getExtraFromSegmentWithAngle(segment, lineWidth);
|
|
18043
|
-
// maxY += extra.yExtra;
|
|
18044
|
-
// }
|
|
18045
|
-
// }
|
|
18046
|
-
// return {
|
|
18047
|
-
// x: minX,
|
|
18048
|
-
// y: minY,
|
|
18049
|
-
// width: maxX - minX,
|
|
18050
|
-
// height: maxY - minY,
|
|
18051
|
-
// };
|
|
18052
|
-
// }
|
|
18053
|
-
// function getExtraFromSegmentWithAngle(segment: any, lineWidth: number) {
|
|
18054
|
-
// const { prePoint, currentPoint, nextPoint } = segment;
|
|
18055
|
-
// const currentAndPre =
|
|
18056
|
-
// Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
|
|
18057
|
-
// const currentAndNext =
|
|
18058
|
-
// Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
|
|
18059
|
-
// const preAndNext =
|
|
18060
|
-
// Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2);
|
|
18061
|
-
// // 以 currentPoint 为顶点的夹角
|
|
18062
|
-
// const currentAngle = Math.acos(
|
|
18063
|
-
// (currentAndPre + currentAndNext - preAndNext) /
|
|
18064
|
-
// (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext)),
|
|
18065
|
-
// );
|
|
18066
|
-
// // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
|
|
18067
|
-
// // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
|
|
18068
|
-
// if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
|
|
18069
|
-
// return {
|
|
18070
|
-
// xExtra: 0,
|
|
18071
|
-
// yExtra: 0,
|
|
18072
|
-
// };
|
|
18073
|
-
// }
|
|
18074
|
-
// let xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
|
|
18075
|
-
// let yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1]));
|
|
18076
|
-
// // 将夹角转为锐角
|
|
18077
|
-
// xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
|
|
18078
|
-
// yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle;
|
|
18079
|
-
// // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
|
|
18080
|
-
// // 由于上层统一加减了二分之一线宽,这里需要进行弥补
|
|
18081
|
-
// const extra = {
|
|
18082
|
-
// // 水平方向投影
|
|
18083
|
-
// xExtra:
|
|
18084
|
-
// Math.cos(currentAngle / 2 - xAngle) * ((lineWidth / 2) * (1 / Math.sin(currentAngle / 2))) -
|
|
18085
|
-
// lineWidth / 2 || 0,
|
|
18086
|
-
// // 垂直方向投影
|
|
18087
|
-
// yExtra:
|
|
18088
|
-
// Math.cos(yAngle - currentAngle / 2) * ((lineWidth / 2) * (1 / Math.sin(currentAngle / 2))) -
|
|
18089
|
-
// lineWidth / 2 || 0,
|
|
18090
|
-
// };
|
|
18091
|
-
// return extra;
|
|
18092
|
-
// }
|
|
18093
18189
|
|
|
18094
18190
|
/**
|
|
18095
18191
|
* @see /zh/docs/api/basic/display-object#clippath
|
|
@@ -18542,7 +18638,6 @@ var CSSPropertyPath = /*#__PURE__*/function () {
|
|
|
18542
18638
|
polylines: [],
|
|
18543
18639
|
curve: [],
|
|
18544
18640
|
totalLength: 0,
|
|
18545
|
-
curveSegments: [],
|
|
18546
18641
|
zCommandIndexes: [],
|
|
18547
18642
|
rect: new Rectangle(0, 0, 0, 0)
|
|
18548
18643
|
};
|
|
@@ -18883,28 +18978,6 @@ CSSPropertyZIndex = __decorate([singleton({
|
|
|
18883
18978
|
}
|
|
18884
18979
|
})], CSSPropertyZIndex);
|
|
18885
18980
|
|
|
18886
|
-
// [PropertySyntax.COORDINATE]: CSSPropertyLocalPosition,
|
|
18887
|
-
// [PropertySyntax.ANGLE]: CSSPropertyAngle,
|
|
18888
|
-
// [PropertySyntax.COLOR]: CSSPropertyColor,
|
|
18889
|
-
// [PropertySyntax.PAINT]: CSSPropertyColor,
|
|
18890
|
-
// [PropertySyntax.OPACITY_VALUE]: CSSPropertyOpacity,
|
|
18891
|
-
// [PropertySyntax.LENGTH_PERCENTAGE]: CSSPropertyLengthOrPercentage,
|
|
18892
|
-
// [PropertySyntax.LENGTH_PERCENTAGE_12]: CSSPropertyLengthOrPercentage12,
|
|
18893
|
-
// [PropertySyntax.LENGTH_PERCENTAGE_14]: CSSPropertyLengthOrPercentage14,
|
|
18894
|
-
// [PropertySyntax.SHADOW_BLUR]: CSSPropertyShadowBlur,
|
|
18895
|
-
// [PropertySyntax.LIST_OF_POINTS]: CSSPropertyPoints,
|
|
18896
|
-
// [PropertySyntax.PATH]: CSSPropertyPath,
|
|
18897
|
-
// [PropertySyntax.FILTER]: CSSPropertyFilter,
|
|
18898
|
-
// [PropertySyntax.Z_INDEX]: CSSPropertyZIndex,
|
|
18899
|
-
// [PropertySyntax.OFFSET_PATH]: CSSPropertyOffsetPath,
|
|
18900
|
-
// [PropertySyntax.OFFSET_DISTANCE]: CSSPropertyOffsetDistance,
|
|
18901
|
-
// [PropertySyntax.CLIP_PATH]: CSSPropertyClipPath,
|
|
18902
|
-
// [PropertySyntax.TRANSFORM]: CSSPropertyTransform,
|
|
18903
|
-
// [PropertySyntax.TRANSFORM_ORIGIN]: CSSPropertyTransformOrigin,
|
|
18904
|
-
// [PropertySyntax.TEXT]: CSSPropertyText,
|
|
18905
|
-
// [PropertySyntax.TEXT_TRANSFORM]: CSSPropertyTextTransform,
|
|
18906
|
-
// };
|
|
18907
|
-
|
|
18908
18981
|
/**
|
|
18909
18982
|
* Blink used them in code generation(css_properties.json5)
|
|
18910
18983
|
*/
|
|
@@ -19670,10 +19743,14 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
19670
19743
|
_geometryUpdater$upda4 = _geometryUpdater$upda.offsetY,
|
|
19671
19744
|
offsetY = _geometryUpdater$upda4 === void 0 ? 0 : _geometryUpdater$upda4,
|
|
19672
19745
|
_geometryUpdater$upda5 = _geometryUpdater$upda.offsetZ,
|
|
19673
|
-
offsetZ = _geometryUpdater$upda5 === void 0 ? 0 : _geometryUpdater$upda5; //
|
|
19746
|
+
offsetZ = _geometryUpdater$upda5 === void 0 ? 0 : _geometryUpdater$upda5; // account for negative width / height of Rect
|
|
19747
|
+
// @see https://github.com/antvis/g/issues/957
|
|
19748
|
+
|
|
19674
19749
|
|
|
19750
|
+
var flipY = width < 0;
|
|
19751
|
+
var flipX = height < 0; // init with content box
|
|
19675
19752
|
|
|
19676
|
-
var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
19753
|
+
var halfExtents = vec3.fromValues(Math.abs(width) / 2, Math.abs(height) / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
19677
19754
|
|
|
19678
19755
|
var lineWidth = parsedStyle.lineWidth,
|
|
19679
19756
|
increasedLineWidthForHitTesting = parsedStyle.increasedLineWidthForHitTesting,
|
|
@@ -19687,10 +19764,18 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
19687
19764
|
delete parsedStyle.anchor;
|
|
19688
19765
|
}
|
|
19689
19766
|
|
|
19690
|
-
var center = vec3.fromValues((1 - (anchor && anchor[0].value || 0) * 2) *
|
|
19767
|
+
var center = vec3.fromValues((1 - (anchor && anchor[0].value || 0) * 2) * width / 2 + offsetX, (1 - (anchor && anchor[1].value || 0) * 2) * height / 2 + offsetY, (1 - (anchor && ((_anchor$ = anchor[2]) === null || _anchor$ === void 0 ? void 0 : _anchor$.value) || 0) * 2) * halfExtents[2] + offsetZ); // update geometry's AABB
|
|
19768
|
+
|
|
19769
|
+
geometry.contentBounds.update(center, halfExtents); // @see https://github.molgen.mpg.de/git-mirror/cairo/blob/master/src/cairo-stroke-style.c#L97..L128
|
|
19770
|
+
|
|
19771
|
+
var expansion = object.nodeName === Shape.POLYLINE || object.nodeName === Shape.POLYGON || object.nodeName === Shape.PATH ? Math.SQRT2 : 0.5; // if (lineCap?.value === 'square') {
|
|
19772
|
+
// expansion = Math.SQRT1_2;
|
|
19773
|
+
// }
|
|
19774
|
+
// if (lineJoin?.value === 'miter' && expansion < Math.SQRT2 * miterLimit) {
|
|
19775
|
+
// expansion = Math.SQRT1_2 * miterLimit;
|
|
19776
|
+
// }
|
|
19691
19777
|
|
|
19692
|
-
|
|
19693
|
-
var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2; // append border
|
|
19778
|
+
var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) * expansion; // append border
|
|
19694
19779
|
|
|
19695
19780
|
vec3.add(halfExtents, halfExtents, vec3.fromValues(halfLineWidth, halfLineWidth, 0));
|
|
19696
19781
|
geometry.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
|
|
@@ -19749,10 +19834,10 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
19749
19834
|
});
|
|
19750
19835
|
anchor = parsedStyle.anchor; // set transform origin
|
|
19751
19836
|
|
|
19752
|
-
var usedOriginXValue = convertPercentUnit(transformOrigin[0], 0, object);
|
|
19753
|
-
var usedOriginYValue = convertPercentUnit(transformOrigin[1], 1, object);
|
|
19754
|
-
usedOriginXValue
|
|
19755
|
-
usedOriginYValue
|
|
19837
|
+
var usedOriginXValue = (flipY ? -1 : 1) * convertPercentUnit(transformOrigin[0], 0, object);
|
|
19838
|
+
var usedOriginYValue = (flipX ? -1 : 1) * convertPercentUnit(transformOrigin[1], 1, object);
|
|
19839
|
+
usedOriginXValue = usedOriginXValue - (flipY ? -1 : 1) * (anchor && anchor[0].value || 0) * geometry.contentBounds.halfExtents[0] * 2;
|
|
19840
|
+
usedOriginYValue = usedOriginYValue - (flipX ? -1 : 1) * (anchor && anchor[1].value || 0) * geometry.contentBounds.halfExtents[1] * 2;
|
|
19756
19841
|
object.setOrigin(usedOriginXValue, usedOriginYValue);
|
|
19757
19842
|
object.dispatchEvent(new CustomEvent(ElementEvent.GEOMETRY_BOUNDS_CHANGED));
|
|
19758
19843
|
dirtifyToRoot(object);
|
|
@@ -21313,7 +21398,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
21313
21398
|
}
|
|
21314
21399
|
});
|
|
21315
21400
|
} else {
|
|
21316
|
-
console.
|
|
21401
|
+
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);
|
|
21317
21402
|
}
|
|
21318
21403
|
};
|
|
21319
21404
|
|
|
@@ -21385,4 +21470,4 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
21385
21470
|
GlobalContainer.load(containerModule);
|
|
21386
21471
|
var layoutEngine = GlobalContainer.get(LayoutEngine);
|
|
21387
21472
|
|
|
21388
|
-
export { AABB, AbstractLayoutDefinition, AbstractRenderer, Animation, AnimationEffectTiming, AnimationEvent, AnimationTimeline, AsyncParallelHook, AsyncSeriesWaterfallHook, BUILT_IN_PROPERTIES, BaseType, BoundingSphere, CSS, CSSColorValue, CSSGradientValue, CSSKeywordValue, CSSMathInvert, CSSMathMax, CSSMathMin, CSSMathNegate, CSSMathOperator, CSSMathProduct, CSSMathSum, CSSMathValue, CSSMathVariadic, CSSNumericValue, CSSNumericValueType, CSSProperty, CSSPropertyAngle, CSSPropertyClipPath, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLengthOrPercentage12, CSSPropertyLengthOrPercentage14, CSSPropertyLocalPosition, CSSPropertyOffsetDistance, CSSPropertyOffsetPath, CSSPropertyOpacity, CSSPropertyPath, CSSPropertyPoints, CSSPropertyShadowBlur, CSSPropertySyntaxFactory, CSSPropertyText, CSSPropertyTextTransform, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyZIndex, CSSRGB, CSSStyleValue, CSSStyleValueType, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasConfig, CanvasEvent, Circle, CircleUpdater, ContextNode, ContextService, Cullable, CustomElement, CustomElementRegistry, CustomEvent, DCHECK, DCHECK_EQ, DCHECK_NE, DELEGATION_SPLITTER, DefaultCamera, DefaultSceneGraphSelector, DefaultSceneGraphService, DefaultStyleValueRegistry, Deferred, DisplayObject, DisplayObjectPool, Document, EasingFunctions, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, FragmentResult, FragmentResultFactory, FragmentResultOptions, Frustum, Geometry, GeometryAABBUpdater, GeometryUpdaterFactory,
|
|
21473
|
+
export { AABB, AbstractLayoutDefinition, AbstractRenderer, Animation, AnimationEffectTiming, AnimationEvent, AnimationTimeline, AsyncParallelHook, AsyncSeriesWaterfallHook, BUILT_IN_PROPERTIES, BaseType, BoundingSphere, CSS, CSSColorValue, CSSGradientValue, CSSKeywordValue, CSSMathInvert, CSSMathMax, CSSMathMin, CSSMathNegate, CSSMathOperator, CSSMathProduct, CSSMathSum, CSSMathValue, CSSMathVariadic, CSSNumericValue, CSSNumericValueType, CSSProperty, CSSPropertyAngle, CSSPropertyClipPath, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLengthOrPercentage12, CSSPropertyLengthOrPercentage14, CSSPropertyLocalPosition, CSSPropertyOffsetDistance, CSSPropertyOffsetPath, CSSPropertyOpacity, CSSPropertyPath, CSSPropertyPoints, CSSPropertyShadowBlur, CSSPropertySyntaxFactory, CSSPropertyText, CSSPropertyTextTransform, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyZIndex, CSSRGB, CSSStyleValue, CSSStyleValueType, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasConfig, CanvasEvent, Circle, CircleUpdater, ContextNode, ContextService, Cullable, CustomElement, CustomElementRegistry, CustomEvent, DCHECK, DCHECK_EQ, DCHECK_NE, DELEGATION_SPLITTER, DefaultCamera, DefaultSceneGraphSelector, DefaultSceneGraphService, DefaultStyleValueRegistry, Deferred, DisplayObject, DisplayObjectPool, Document, EasingFunctions, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, FragmentResult, FragmentResultFactory, FragmentResultOptions, Frustum, Geometry, GeometryAABBUpdater, GeometryUpdaterFactory, GradientType, Group, HTML, Image, KeyframeEffect, LayoutChildren, LayoutChildrenFactory, LayoutChildrenOptions, LayoutContext, LayoutContextFactory, LayoutContextOptions, LayoutEdges, LayoutEdgesFactory, LayoutEdgesOptions, LayoutEngine, LayoutFragment, LayoutFragmentFactory, LayoutFragmentOptions, LayoutObject, LayoutRegistry, LayoutTaskType, Line, LineUpdater, MOUSE_POINTER_ID, Mask, MutationEvent, MutationObserver, MutationRecord, Nested, Node, ObjectTyped, Odeg, OffscreenCanvasCreator, Opx, ParenLess, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertyName, PropertySyntax, RBushNode, RBushRoot, Ray, Rect, RectUpdater, Rectangle, Registration, RenderReason, Renderable, RenderingContext, RenderingPluginContribution, RenderingService, SceneGraphSelector, SceneGraphSelectorFactory, SceneGraphService, Shape, Sortable, Strategy, StyleValueRegistry, SyncHook, SyncWaterfallHook, TOUCH_TO_POINTER, Text, TextService, TextUpdater, Transform, UnitCategory, UnitType, ValueRange, baseTypeToString, camelCase, clamp, clampedMergeNumbers, cleanExistedCanvas, colorStopToString, compareAnimations, computeLinearGradient, computeRadialGradient, convertAngleUnit, convertEffectInput, convertPercentUnit, convertToDash, convertToPath, createVec3, decompose, deg2rad, deg2turn, dirtifyToRoot, equalSet, extractPolygons, formatAttribute, fromRotationTranslationScale, getAngle, getEasingFunction, getEuler, getHeight, getRotationInRadians, getScaling, getStyle, getTranslation, getWidth, grad2deg, hasArcOrBezier, isBoolean, isBrowser, isComparison, isFunction, isNil, isNumber, isObject, isPattern, isString, isUndefined, layoutEngine, makePerspective, makeQuerablePromise, makeTiming, mergeColors, mergeDimensionList, mergeDimensions, mergeNumberLists, mergeNumbers, mergePaths, mergeTransforms, normalizeKeyframes, normalizeTimingInput, numberToString, numericTimingToObject, parseAngle, parseColor, parseDimension, parseDimensionArray, parseFilter, parseGradient, parseLength, parseLengthOrPercentage, parseNumber, parseNumberList, parseParam, parsePath, parsePoints, parseTransform, parseTransformOrigin, parserPercentage, path2Segments, rad2deg, setDOMSize, sortByZIndex, toFontString, turn2deg, typeCheck, unitTypeToBaseType };
|