@antv/g 5.1.8 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/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/properties/CSSPropertyColor.d.ts +5 -4
- package/dist/css/properties/CSSPropertyColor.d.ts.map +1 -1
- package/dist/dom/KeyframeList.d.ts.map +1 -1
- package/dist/index.esm.js +670 -215
- package/dist/index.js +674 -213
- package/dist/index.umd.js +1401 -265
- package/dist/index.umd.min.js +2 -2
- 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 -5
- 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.map +1 -1
- package/package.json +8 -5
package/dist/index.esm.js
CHANGED
|
@@ -8,6 +8,7 @@ import { vec3, mat3, mat4, quat, vec4 } from 'gl-matrix';
|
|
|
8
8
|
import { Cubic as Cubic$1, Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
|
|
9
9
|
import { EventEmitter } from 'eventemitter3';
|
|
10
10
|
import { color } from 'd3-color';
|
|
11
|
+
import memoize from 'lodash.memoize';
|
|
11
12
|
import { path2Absolute, path2Curve, path2Segments } from '@antv/util';
|
|
12
13
|
import { requestAnimationFrame as requestAnimationFrame$1, cancelAnimationFrame as cancelAnimationFrame$1 } from 'request-animation-frame-polyfill';
|
|
13
14
|
|
|
@@ -1686,6 +1687,379 @@ var TOUCH_TO_POINTER = {
|
|
|
1686
1687
|
touchcancel: 'pointercancel'
|
|
1687
1688
|
};
|
|
1688
1689
|
|
|
1690
|
+
/**
|
|
1691
|
+
* borrow from gradient-parser, but we delete some browser compatible prefix such as `-webkit-`
|
|
1692
|
+
* @see https://github.com/rafaelcaricio/gradient-parser
|
|
1693
|
+
*/
|
|
1694
|
+
function colorStopToString(colorStop) {
|
|
1695
|
+
var type = colorStop.type,
|
|
1696
|
+
value = colorStop.value;
|
|
1697
|
+
|
|
1698
|
+
if (type === 'hex') {
|
|
1699
|
+
return "#" + value;
|
|
1700
|
+
} else if (type === 'literal') {
|
|
1701
|
+
return value;
|
|
1702
|
+
} else if (type === 'rgb') {
|
|
1703
|
+
return "rgb(" + value.join(',') + ")";
|
|
1704
|
+
} else {
|
|
1705
|
+
return "rgba(" + value.join(',') + ")";
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
var parseGradient = function () {
|
|
1709
|
+
var tokens = {
|
|
1710
|
+
linearGradient: /^(linear\-gradient)/i,
|
|
1711
|
+
repeatingLinearGradient: /^(repeating\-linear\-gradient)/i,
|
|
1712
|
+
radialGradient: /^(radial\-gradient)/i,
|
|
1713
|
+
repeatingRadialGradient: /^(repeating\-radial\-gradient)/i,
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* @see https://projects.verou.me/conic-gradient/
|
|
1717
|
+
*/
|
|
1718
|
+
conicGradient: /^(conic\-gradient)/i,
|
|
1719
|
+
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
1720
|
+
extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
|
|
1721
|
+
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
1722
|
+
pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
|
|
1723
|
+
percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
|
|
1724
|
+
emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
|
|
1725
|
+
angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
|
|
1726
|
+
startCall: /^\(/,
|
|
1727
|
+
endCall: /^\)/,
|
|
1728
|
+
comma: /^,/,
|
|
1729
|
+
hexColor: /^\#([0-9a-fA-F]+)/,
|
|
1730
|
+
literalColor: /^([a-zA-Z]+)/,
|
|
1731
|
+
rgbColor: /^rgb/i,
|
|
1732
|
+
rgbaColor: /^rgba/i,
|
|
1733
|
+
number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
|
|
1734
|
+
};
|
|
1735
|
+
var input = '';
|
|
1736
|
+
|
|
1737
|
+
function error(msg) {
|
|
1738
|
+
throw new Error(input + ': ' + msg);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
function getAST() {
|
|
1742
|
+
var ast = matchListDefinitions();
|
|
1743
|
+
|
|
1744
|
+
if (input.length > 0) {
|
|
1745
|
+
error('Invalid input not EOF');
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
return ast;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
function matchListDefinitions() {
|
|
1752
|
+
return matchListing(matchDefinition);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
function matchDefinition() {
|
|
1756
|
+
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);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
function matchGradient(gradientType, pattern, orientationMatcher) {
|
|
1760
|
+
return matchCall(pattern, function (captures) {
|
|
1761
|
+
var orientation = orientationMatcher();
|
|
1762
|
+
|
|
1763
|
+
if (orientation) {
|
|
1764
|
+
if (!scan(tokens.comma)) {
|
|
1765
|
+
error('Missing comma before color stops');
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
return {
|
|
1770
|
+
type: gradientType,
|
|
1771
|
+
orientation: orientation,
|
|
1772
|
+
colorStops: matchListing(matchColorStop)
|
|
1773
|
+
};
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
function matchCall(pattern, callback) {
|
|
1778
|
+
var captures = scan(pattern);
|
|
1779
|
+
|
|
1780
|
+
if (captures) {
|
|
1781
|
+
if (!scan(tokens.startCall)) {
|
|
1782
|
+
error('Missing (');
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
var result = callback(captures);
|
|
1786
|
+
|
|
1787
|
+
if (!scan(tokens.endCall)) {
|
|
1788
|
+
error('Missing )');
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
return result;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
function matchLinearOrientation() {
|
|
1796
|
+
return matchSideOrCorner() || matchAngle();
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
function matchSideOrCorner() {
|
|
1800
|
+
return match('directional', tokens.sideOrCorner, 1);
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
function matchAngle() {
|
|
1804
|
+
return match('angular', tokens.angleValue, 1);
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
function matchListRadialOrientations() {
|
|
1808
|
+
var radialOrientations,
|
|
1809
|
+
radialOrientation = matchRadialOrientation(),
|
|
1810
|
+
lookaheadCache;
|
|
1811
|
+
|
|
1812
|
+
if (radialOrientation) {
|
|
1813
|
+
radialOrientations = [];
|
|
1814
|
+
radialOrientations.push(radialOrientation);
|
|
1815
|
+
lookaheadCache = input;
|
|
1816
|
+
|
|
1817
|
+
if (scan(tokens.comma)) {
|
|
1818
|
+
radialOrientation = matchRadialOrientation();
|
|
1819
|
+
|
|
1820
|
+
if (radialOrientation) {
|
|
1821
|
+
radialOrientations.push(radialOrientation);
|
|
1822
|
+
} else {
|
|
1823
|
+
input = lookaheadCache;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
return radialOrientations;
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
function matchRadialOrientation() {
|
|
1832
|
+
var radialType = matchCircle() || matchEllipse();
|
|
1833
|
+
|
|
1834
|
+
if (radialType) {
|
|
1835
|
+
// @ts-ignore
|
|
1836
|
+
radialType.at = matchAtPosition();
|
|
1837
|
+
} else {
|
|
1838
|
+
var extent = matchExtentKeyword();
|
|
1839
|
+
|
|
1840
|
+
if (extent) {
|
|
1841
|
+
radialType = extent;
|
|
1842
|
+
var positionAt = matchAtPosition();
|
|
1843
|
+
|
|
1844
|
+
if (positionAt) {
|
|
1845
|
+
// @ts-ignore
|
|
1846
|
+
radialType.at = positionAt;
|
|
1847
|
+
}
|
|
1848
|
+
} else {
|
|
1849
|
+
var defaultPosition = matchPositioning();
|
|
1850
|
+
|
|
1851
|
+
if (defaultPosition) {
|
|
1852
|
+
radialType = {
|
|
1853
|
+
type: 'default-radial',
|
|
1854
|
+
// @ts-ignore
|
|
1855
|
+
at: defaultPosition
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
return radialType;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function matchCircle() {
|
|
1865
|
+
var circle = match('shape', /^(circle)/i, 0);
|
|
1866
|
+
|
|
1867
|
+
if (circle) {
|
|
1868
|
+
// @ts-ignore
|
|
1869
|
+
circle.style = matchLength() || matchExtentKeyword();
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
return circle;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
function matchEllipse() {
|
|
1876
|
+
var ellipse = match('shape', /^(ellipse)/i, 0);
|
|
1877
|
+
|
|
1878
|
+
if (ellipse) {
|
|
1879
|
+
// @ts-ignore
|
|
1880
|
+
ellipse.style = matchDistance() || matchExtentKeyword();
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
return ellipse;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
function matchExtentKeyword() {
|
|
1887
|
+
return match('extent-keyword', tokens.extentKeywords, 1);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
function matchAtPosition() {
|
|
1891
|
+
if (match('position', /^at/, 0)) {
|
|
1892
|
+
var positioning = matchPositioning();
|
|
1893
|
+
|
|
1894
|
+
if (!positioning) {
|
|
1895
|
+
error('Missing positioning value');
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
return positioning;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
function matchPositioning() {
|
|
1903
|
+
var location = matchCoordinates();
|
|
1904
|
+
|
|
1905
|
+
if (location.x || location.y) {
|
|
1906
|
+
return {
|
|
1907
|
+
type: 'position',
|
|
1908
|
+
value: location
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
function matchCoordinates() {
|
|
1914
|
+
return {
|
|
1915
|
+
x: matchDistance(),
|
|
1916
|
+
y: matchDistance()
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
function matchListing(matcher) {
|
|
1921
|
+
var captures = matcher();
|
|
1922
|
+
var result = [];
|
|
1923
|
+
|
|
1924
|
+
if (captures) {
|
|
1925
|
+
result.push(captures);
|
|
1926
|
+
|
|
1927
|
+
while (scan(tokens.comma)) {
|
|
1928
|
+
captures = matcher();
|
|
1929
|
+
|
|
1930
|
+
if (captures) {
|
|
1931
|
+
result.push(captures);
|
|
1932
|
+
} else {
|
|
1933
|
+
error('One extra comma');
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
return result;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
function matchColorStop() {
|
|
1942
|
+
var color = matchColor();
|
|
1943
|
+
|
|
1944
|
+
if (!color) {
|
|
1945
|
+
error('Expected color definition');
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
color.length = matchDistance();
|
|
1949
|
+
return color;
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
function matchColor() {
|
|
1953
|
+
return matchHexColor() || matchRGBAColor() || matchRGBColor() || matchLiteralColor();
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
function matchLiteralColor() {
|
|
1957
|
+
return match('literal', tokens.literalColor, 0);
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
function matchHexColor() {
|
|
1961
|
+
return match('hex', tokens.hexColor, 1);
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
function matchRGBColor() {
|
|
1965
|
+
return matchCall(tokens.rgbColor, function () {
|
|
1966
|
+
return {
|
|
1967
|
+
type: 'rgb',
|
|
1968
|
+
value: matchListing(matchNumber)
|
|
1969
|
+
};
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
function matchRGBAColor() {
|
|
1974
|
+
return matchCall(tokens.rgbaColor, function () {
|
|
1975
|
+
return {
|
|
1976
|
+
type: 'rgba',
|
|
1977
|
+
value: matchListing(matchNumber)
|
|
1978
|
+
};
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
function matchNumber() {
|
|
1983
|
+
return scan(tokens.number)[1];
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
function matchDistance() {
|
|
1987
|
+
return match('%', tokens.percentageValue, 1) || matchPositionKeyword() || matchLength();
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
function matchPositionKeyword() {
|
|
1991
|
+
return match('position-keyword', tokens.positionKeywords, 1);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
function matchLength() {
|
|
1995
|
+
return match('px', tokens.pixelValue, 1) || match('em', tokens.emValue, 1);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
function match(type, pattern, captureIndex) {
|
|
1999
|
+
var captures = scan(pattern);
|
|
2000
|
+
|
|
2001
|
+
if (captures) {
|
|
2002
|
+
return {
|
|
2003
|
+
type: type,
|
|
2004
|
+
value: captures[captureIndex]
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
function scan(regexp) {
|
|
2010
|
+
var blankCaptures = /^[\n\r\t\s]+/.exec(input);
|
|
2011
|
+
|
|
2012
|
+
if (blankCaptures) {
|
|
2013
|
+
consume(blankCaptures[0].length);
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
var captures = regexp.exec(input);
|
|
2017
|
+
|
|
2018
|
+
if (captures) {
|
|
2019
|
+
consume(captures[0].length);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
return captures;
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
function consume(size) {
|
|
2026
|
+
input = input.substring(size);
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
return function (code) {
|
|
2030
|
+
input = code;
|
|
2031
|
+
return getAST();
|
|
2032
|
+
};
|
|
2033
|
+
}();
|
|
2034
|
+
function computeLinearGradient(width, height, angle) {
|
|
2035
|
+
var rad = angle * Math.PI / 180;
|
|
2036
|
+
var rx = 0;
|
|
2037
|
+
var ry = 0;
|
|
2038
|
+
var rcx = rx + width / 2;
|
|
2039
|
+
var rcy = ry + height / 2; // get the length of gradient line
|
|
2040
|
+
// @see https://observablehq.com/@danburzo/css-gradient-line
|
|
2041
|
+
|
|
2042
|
+
var length = Math.abs(width * Math.cos(rad)) + Math.abs(height * Math.sin(rad));
|
|
2043
|
+
var x1 = rcx - Math.cos(rad) * length / 2;
|
|
2044
|
+
var y1 = rcy - Math.sin(rad) * length / 2;
|
|
2045
|
+
var x2 = rcx + Math.cos(rad) * length / 2;
|
|
2046
|
+
var y2 = rcy + Math.sin(rad) * length / 2;
|
|
2047
|
+
return {
|
|
2048
|
+
x1: x1,
|
|
2049
|
+
y1: y1,
|
|
2050
|
+
x2: x2,
|
|
2051
|
+
y2: y2
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
function computeRadialGradient(width, height, cx, cy) {
|
|
2055
|
+
var r = Math.sqrt(width * width + height * height) / 2;
|
|
2056
|
+
return {
|
|
2057
|
+
x: cx * width,
|
|
2058
|
+
y: cy * height,
|
|
2059
|
+
r: r
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
|
|
1689
2063
|
/**
|
|
1690
2064
|
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type
|
|
1691
2065
|
*/
|
|
@@ -2504,7 +2878,11 @@ function rectToCommands(width, height, x, y, radius) {
|
|
|
2504
2878
|
trr = radius[1],
|
|
2505
2879
|
brr = radius[2],
|
|
2506
2880
|
blr = radius[3];
|
|
2507
|
-
|
|
2881
|
+
var signX = width > 0 ? 1 : -1;
|
|
2882
|
+
var signY = height > 0 ? 1 : -1; // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
|
|
2883
|
+
|
|
2884
|
+
var sweepFlag = signX + signY !== 0 ? 1 : 0;
|
|
2885
|
+
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
2886
|
return command;
|
|
2509
2887
|
});
|
|
2510
2888
|
}
|
|
@@ -2574,7 +2952,7 @@ function convertToPath(object, applyLocalTransform) {
|
|
|
2574
2952
|
return r.value !== 0;
|
|
2575
2953
|
});
|
|
2576
2954
|
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));
|
|
2955
|
+
return clamp(r.value, 0, Math.min(Math.abs(width.value) / 2, Math.abs(height.value) / 2));
|
|
2578
2956
|
}));
|
|
2579
2957
|
break;
|
|
2580
2958
|
|
|
@@ -6655,14 +7033,13 @@ var CSSRGB = /*#__PURE__*/function (_CSSColorValue) {
|
|
|
6655
7033
|
return CSSRGB;
|
|
6656
7034
|
}(CSSColorValue);
|
|
6657
7035
|
|
|
6658
|
-
var
|
|
7036
|
+
var GradientType;
|
|
6659
7037
|
|
|
6660
|
-
(function (
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
})(GradientPatternType || (GradientPatternType = {}));
|
|
7038
|
+
(function (GradientType) {
|
|
7039
|
+
GradientType[GradientType["Constant"] = 0] = "Constant";
|
|
7040
|
+
GradientType[GradientType["LinearGradient"] = 1] = "LinearGradient";
|
|
7041
|
+
GradientType[GradientType["RadialGradient"] = 2] = "RadialGradient";
|
|
7042
|
+
})(GradientType || (GradientType = {}));
|
|
6666
7043
|
|
|
6667
7044
|
var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
|
|
6668
7045
|
_inheritsLoose(CSSGradientValue, _CSSStyleValue);
|
|
@@ -6685,21 +7062,7 @@ var CSSGradientValue = /*#__PURE__*/function (_CSSStyleValue) {
|
|
|
6685
7062
|
};
|
|
6686
7063
|
|
|
6687
7064
|
_proto.buildCSSText = function buildCSSText(n, p, result) {
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
if (this.type === GradientPatternType.LinearGradient) {
|
|
6691
|
-
text = "linear-gradient(" + this.value.steps.map(function (step) {
|
|
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 + ")";
|
|
6700
|
-
}
|
|
6701
|
-
|
|
6702
|
-
return result += text;
|
|
7065
|
+
return result;
|
|
6703
7066
|
};
|
|
6704
7067
|
|
|
6705
7068
|
_proto.getType = function getType() {
|
|
@@ -6713,31 +7076,192 @@ var regexLG = /^l\s*\(\s*([\d.]+)\s*\)\s*(.*)/i;
|
|
|
6713
7076
|
var regexRG = /^r\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)\s*(.*)/i;
|
|
6714
7077
|
var regexPR = /^p\s*\(\s*([axyn])\s*\)\s*(.*)/i;
|
|
6715
7078
|
var regexColorStop = /[\d.]+:(#[^\s]+|[^\)]+\))/gi;
|
|
6716
|
-
/**
|
|
6717
|
-
* @see https://github.com/WebKit/WebKit/blob/main/Source/WebCore/css/parser/CSSParser.cpp#L97
|
|
6718
|
-
*/
|
|
6719
7079
|
|
|
6720
|
-
function
|
|
6721
|
-
|
|
6722
|
-
|
|
7080
|
+
function spaceColorStops(colorStops) {
|
|
7081
|
+
var _colorStops$length;
|
|
7082
|
+
|
|
7083
|
+
var length = colorStops.length;
|
|
7084
|
+
colorStops[length - 1].length = (_colorStops$length = colorStops[length - 1].length) !== null && _colorStops$length !== void 0 ? _colorStops$length : {
|
|
7085
|
+
type: '%',
|
|
7086
|
+
value: '100'
|
|
7087
|
+
};
|
|
7088
|
+
|
|
7089
|
+
if (length > 1) {
|
|
7090
|
+
var _colorStops$0$length;
|
|
7091
|
+
|
|
7092
|
+
colorStops[0].length = (_colorStops$0$length = colorStops[0].length) !== null && _colorStops$0$length !== void 0 ? _colorStops$0$length : {
|
|
7093
|
+
type: '%',
|
|
7094
|
+
value: '0'
|
|
7095
|
+
};
|
|
6723
7096
|
}
|
|
6724
7097
|
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
7098
|
+
var previousIndex = 0;
|
|
7099
|
+
var previousOffset = Number(colorStops[0].length.value);
|
|
7100
|
+
|
|
7101
|
+
for (var i = 1; i < length; i++) {
|
|
7102
|
+
var _colorStops$i$length;
|
|
7103
|
+
|
|
7104
|
+
var offset = (_colorStops$i$length = colorStops[i].length) === null || _colorStops$i$length === void 0 ? void 0 : _colorStops$i$length.value;
|
|
7105
|
+
|
|
7106
|
+
if (!isNil(offset) && !isNil(previousOffset)) {
|
|
7107
|
+
for (var j = 1; j < i - previousIndex; j++) {
|
|
7108
|
+
colorStops[previousIndex + j].length = {
|
|
7109
|
+
type: '%',
|
|
7110
|
+
value: "" + (previousOffset + (Number(offset) - previousOffset) * j / (i - previousIndex))
|
|
7111
|
+
};
|
|
7112
|
+
}
|
|
7113
|
+
|
|
7114
|
+
previousIndex = i;
|
|
7115
|
+
previousOffset = Number(offset);
|
|
7116
|
+
}
|
|
7117
|
+
}
|
|
7118
|
+
} // The position of the gradient line's starting point.
|
|
7119
|
+
// different from CSS side(to top) @see https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient#values
|
|
7120
|
+
|
|
7121
|
+
|
|
7122
|
+
var SideOrCornerToDegMap = {
|
|
7123
|
+
left: 270 - 90,
|
|
7124
|
+
top: 0 - 90,
|
|
7125
|
+
bottom: 180 - 90,
|
|
7126
|
+
right: 90 - 90,
|
|
7127
|
+
'left top': 315 - 90,
|
|
7128
|
+
'top left': 315 - 90,
|
|
7129
|
+
'left bottom': 225 - 90,
|
|
7130
|
+
'bottom left': 225 - 90,
|
|
7131
|
+
'right top': 45 - 90,
|
|
7132
|
+
'top right': 45 - 90,
|
|
7133
|
+
'right bottom': 135 - 90,
|
|
7134
|
+
'bottom right': 135 - 90
|
|
7135
|
+
};
|
|
7136
|
+
var angleToDeg = memoize(function (orientation) {
|
|
7137
|
+
var angle;
|
|
7138
|
+
|
|
7139
|
+
if (orientation.type === 'angular') {
|
|
7140
|
+
angle = Number(orientation.value);
|
|
7141
|
+
} else {
|
|
7142
|
+
angle = SideOrCornerToDegMap[orientation.value] || 0;
|
|
7143
|
+
}
|
|
7144
|
+
|
|
7145
|
+
return angle;
|
|
7146
|
+
});
|
|
7147
|
+
var positonToPercentage = memoize(function (position) {
|
|
7148
|
+
var cx = 0.5;
|
|
7149
|
+
var cy = 0.5;
|
|
7150
|
+
|
|
7151
|
+
if ((position === null || position === void 0 ? void 0 : position.type) === 'position') {
|
|
7152
|
+
var _position$value = position.value,
|
|
7153
|
+
x = _position$value.x,
|
|
7154
|
+
y = _position$value.y;
|
|
7155
|
+
|
|
7156
|
+
if ((x === null || x === void 0 ? void 0 : x.type) === 'position-keyword') {
|
|
7157
|
+
if (x.value === 'left') {
|
|
7158
|
+
cx = 0;
|
|
7159
|
+
} else if (x.value === 'center') {
|
|
7160
|
+
cx = 0.5;
|
|
7161
|
+
} else if (x.value === 'right') {
|
|
7162
|
+
cx = 1;
|
|
7163
|
+
} else if (x.value === 'top') {
|
|
7164
|
+
cy = 0;
|
|
7165
|
+
} else if (x.value === 'bottom') {
|
|
7166
|
+
cy = 1;
|
|
7167
|
+
}
|
|
7168
|
+
}
|
|
7169
|
+
|
|
7170
|
+
if ((y === null || y === void 0 ? void 0 : y.type) === 'position-keyword') {
|
|
7171
|
+
if (y.value === 'left') {
|
|
7172
|
+
cx = 0;
|
|
7173
|
+
} else if (y.value === 'center') {
|
|
7174
|
+
cy = 0.5;
|
|
7175
|
+
} else if (y.value === 'right') {
|
|
7176
|
+
cx = 1;
|
|
7177
|
+
} else if (y.value === 'top') {
|
|
7178
|
+
cy = 0;
|
|
7179
|
+
} else if (y.value === 'bottom') {
|
|
7180
|
+
cy = 1;
|
|
7181
|
+
}
|
|
7182
|
+
}
|
|
7183
|
+
|
|
7184
|
+
if ((x === null || x === void 0 ? void 0 : x.type) === '%') {
|
|
7185
|
+
cx = Number(x.value) / 100;
|
|
7186
|
+
}
|
|
7187
|
+
|
|
7188
|
+
if ((y === null || y === void 0 ? void 0 : y.type) === '%') {
|
|
7189
|
+
cy = Number(x.value) / 100;
|
|
7190
|
+
}
|
|
6731
7191
|
}
|
|
6732
7192
|
|
|
7193
|
+
return {
|
|
7194
|
+
cx: cx,
|
|
7195
|
+
cy: cy
|
|
7196
|
+
};
|
|
7197
|
+
});
|
|
7198
|
+
var parseGradient$1 = memoize(function (colorStr) {
|
|
7199
|
+
if (colorStr.indexOf('linear') > -1 || colorStr.indexOf('radial') > -1) {
|
|
7200
|
+
var ast = parseGradient(colorStr);
|
|
7201
|
+
return ast.map(function (_ref) {
|
|
7202
|
+
var type = _ref.type,
|
|
7203
|
+
orientation = _ref.orientation,
|
|
7204
|
+
colorStops = _ref.colorStops;
|
|
7205
|
+
spaceColorStops(colorStops);
|
|
7206
|
+
var steps = colorStops.map(function (colorStop) {
|
|
7207
|
+
// TODO: only support % for now, should calc percentage of axis length when using px/em
|
|
7208
|
+
return [Number(colorStop.length.value) / 100, colorStopToString(colorStop)];
|
|
7209
|
+
});
|
|
7210
|
+
|
|
7211
|
+
if (type === 'linear-gradient') {
|
|
7212
|
+
return new CSSGradientValue(GradientType.LinearGradient, {
|
|
7213
|
+
angle: orientation ? angleToDeg(orientation) : 0,
|
|
7214
|
+
steps: steps,
|
|
7215
|
+
hash: colorStr
|
|
7216
|
+
});
|
|
7217
|
+
} else if (type === 'radial-gradient') {
|
|
7218
|
+
if (!orientation) {
|
|
7219
|
+
orientation = [{
|
|
7220
|
+
type: 'shape',
|
|
7221
|
+
value: 'circle'
|
|
7222
|
+
}];
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
if (orientation[0].type === 'shape' && orientation[0].value === 'circle') {
|
|
7226
|
+
var _positonToPercentage = positonToPercentage(orientation[0].at),
|
|
7227
|
+
cx = _positonToPercentage.cx,
|
|
7228
|
+
cy = _positonToPercentage.cy;
|
|
7229
|
+
|
|
7230
|
+
return new CSSGradientValue(GradientType.RadialGradient, {
|
|
7231
|
+
cx: cx,
|
|
7232
|
+
cy: cy,
|
|
7233
|
+
steps: steps,
|
|
7234
|
+
hash: colorStr
|
|
7235
|
+
});
|
|
7236
|
+
} // } else if (type === 'repeating-linear-gradient') {
|
|
7237
|
+
// } else if (type === 'repeating-radial-gradient') {
|
|
7238
|
+
|
|
7239
|
+
}
|
|
7240
|
+
});
|
|
7241
|
+
} // legacy format, should be deprecated later
|
|
7242
|
+
|
|
7243
|
+
|
|
6733
7244
|
var type = colorStr[0];
|
|
6734
7245
|
|
|
6735
7246
|
if (colorStr[1] === '(' || colorStr[2] === '(') {
|
|
6736
7247
|
if (type === 'l') {
|
|
6737
|
-
var
|
|
6738
|
-
|
|
6739
|
-
if (
|
|
6740
|
-
|
|
7248
|
+
var arr = regexLG.exec(colorStr);
|
|
7249
|
+
|
|
7250
|
+
if (arr) {
|
|
7251
|
+
var _arr$2$match;
|
|
7252
|
+
|
|
7253
|
+
var steps = ((_arr$2$match = arr[2].match(regexColorStop)) === null || _arr$2$match === void 0 ? void 0 : _arr$2$match.map(function (stop) {
|
|
7254
|
+
return stop.split(':');
|
|
7255
|
+
})) || [];
|
|
7256
|
+
return [new CSSGradientValue(GradientType.LinearGradient, {
|
|
7257
|
+
angle: parseFloat(arr[1]),
|
|
7258
|
+
steps: steps.map(function (_ref2) {
|
|
7259
|
+
var offset = _ref2[0],
|
|
7260
|
+
color = _ref2[1];
|
|
7261
|
+
return [Number(offset), color];
|
|
7262
|
+
}),
|
|
7263
|
+
hash: colorStr
|
|
7264
|
+
})];
|
|
6741
7265
|
}
|
|
6742
7266
|
} else if (type === 'r') {
|
|
6743
7267
|
var parsedRadialGradient = parseRadialGradient(colorStr);
|
|
@@ -6746,57 +7270,37 @@ function parseColor(colorStr) {
|
|
|
6746
7270
|
if (isString(parsedRadialGradient)) {
|
|
6747
7271
|
colorStr = parsedRadialGradient;
|
|
6748
7272
|
} else {
|
|
6749
|
-
return new CSSGradientValue(
|
|
7273
|
+
return [new CSSGradientValue(GradientType.RadialGradient, parsedRadialGradient)];
|
|
6750
7274
|
}
|
|
6751
7275
|
}
|
|
6752
7276
|
} else if (type === 'p') {
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
if (pattern) {
|
|
6756
|
-
return new CSSGradientValue(GradientPatternType.Pattern, pattern);
|
|
6757
|
-
}
|
|
7277
|
+
return parsePattern(colorStr);
|
|
6758
7278
|
}
|
|
6759
|
-
} // constants
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
var color$1 = color(colorStr);
|
|
6763
|
-
var rgba = [0, 0, 0, 0];
|
|
6764
|
-
|
|
6765
|
-
if (color$1 !== null) {
|
|
6766
|
-
rgba[0] = color$1.r || 0;
|
|
6767
|
-
rgba[1] = color$1.g || 0;
|
|
6768
|
-
rgba[2] = color$1.b || 0;
|
|
6769
|
-
rgba[3] = color$1.opacity;
|
|
6770
7279
|
}
|
|
7280
|
+
});
|
|
6771
7281
|
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
// value: rgba,
|
|
6775
|
-
// formatted:
|
|
6776
|
-
// // rgba(255,255,255,0) -> [NaN, NaN, NaN, 0]
|
|
6777
|
-
// // @see https://github.com/d3/d3-color/issues/52
|
|
6778
|
-
// (color && `rgba(${color.r || 0},${color.g || 0},${color.b || 0},${color.opacity})`) ||
|
|
6779
|
-
// 'rgba(0,0,0,0)',
|
|
6780
|
-
// };
|
|
6781
|
-
}
|
|
6782
|
-
function mergeColors(left, right) {
|
|
6783
|
-
// only support constant value, exclude gradient & pattern
|
|
6784
|
-
if (!(left instanceof CSSRGB) || !(right instanceof CSSRGB)) {
|
|
6785
|
-
return;
|
|
6786
|
-
}
|
|
7282
|
+
function parseRadialGradient(gradientStr) {
|
|
7283
|
+
var arr = regexRG.exec(gradientStr);
|
|
6787
7284
|
|
|
6788
|
-
|
|
6789
|
-
var
|
|
7285
|
+
if (arr) {
|
|
7286
|
+
var _arr$4$match;
|
|
6790
7287
|
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
7288
|
+
var steps = ((_arr$4$match = arr[4].match(regexColorStop)) === null || _arr$4$match === void 0 ? void 0 : _arr$4$match.map(function (stop) {
|
|
7289
|
+
return stop.split(':');
|
|
7290
|
+
})) || [];
|
|
7291
|
+
return {
|
|
7292
|
+
cx: 0.5,
|
|
7293
|
+
cy: 0.5,
|
|
7294
|
+
steps: steps.map(function (_ref3) {
|
|
7295
|
+
var offset = _ref3[0],
|
|
7296
|
+
color = _ref3[1];
|
|
7297
|
+
return [Number(offset), color];
|
|
7298
|
+
}),
|
|
7299
|
+
hash: gradientStr
|
|
7300
|
+
};
|
|
7301
|
+
}
|
|
6796
7302
|
|
|
6797
|
-
|
|
6798
|
-
return "rgba(" + rgba.join(',') + ")";
|
|
6799
|
-
}];
|
|
7303
|
+
return null;
|
|
6800
7304
|
}
|
|
6801
7305
|
|
|
6802
7306
|
function parsePattern(patternStr) {
|
|
@@ -6828,118 +7332,87 @@ function parsePattern(patternStr) {
|
|
|
6828
7332
|
}
|
|
6829
7333
|
|
|
6830
7334
|
return {
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
7335
|
+
image: src,
|
|
7336
|
+
// @ts-ignore
|
|
7337
|
+
repetition: repetition
|
|
6834
7338
|
};
|
|
6835
7339
|
}
|
|
6836
7340
|
|
|
6837
7341
|
return null;
|
|
6838
7342
|
}
|
|
6839
7343
|
|
|
6840
|
-
function
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
7344
|
+
function isPattern(object) {
|
|
7345
|
+
return isObject(object) && !!object.image;
|
|
7346
|
+
}
|
|
7347
|
+
/**
|
|
7348
|
+
* @see https://github.com/WebKit/WebKit/blob/main/Source/WebCore/css/parser/CSSParser.cpp#L97
|
|
7349
|
+
*/
|
|
6845
7350
|
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
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
|
-
}
|
|
7351
|
+
var parseColor = memoize(function (colorStr) {
|
|
7352
|
+
if (isPattern(colorStr)) {
|
|
7353
|
+
return _extends({
|
|
7354
|
+
repetition: 'repeat'
|
|
7355
|
+
}, colorStr);
|
|
7356
|
+
}
|
|
6894
7357
|
|
|
6895
|
-
|
|
6896
|
-
|
|
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
|
-
};
|
|
7358
|
+
if (isNil(colorStr)) {
|
|
7359
|
+
colorStr = '';
|
|
6907
7360
|
}
|
|
6908
7361
|
|
|
6909
|
-
|
|
6910
|
-
|
|
7362
|
+
if (colorStr === 'transparent') {
|
|
7363
|
+
// transparent black
|
|
7364
|
+
return new CSSRGB(0, 0, 0, 0);
|
|
7365
|
+
} else if (colorStr === 'currentColor') {
|
|
7366
|
+
// @see https://github.com/adobe-webplatform/Snap.svg/issues/526
|
|
7367
|
+
colorStr = 'black';
|
|
7368
|
+
} // support CSS gradient syntax
|
|
6911
7369
|
|
|
6912
|
-
function parseRadialGradient(gradientStr) {
|
|
6913
|
-
var arr = regexRG.exec(gradientStr);
|
|
6914
7370
|
|
|
6915
|
-
|
|
6916
|
-
var _arr$4$match;
|
|
7371
|
+
var g = parseGradient$1(colorStr);
|
|
6917
7372
|
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
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时,默认无渐变,取渐变序列的最后一个颜色
|
|
7373
|
+
if (g) {
|
|
7374
|
+
return g;
|
|
7375
|
+
} // constants
|
|
6924
7376
|
|
|
6925
|
-
if (fr === 0) {
|
|
6926
|
-
var colors = arr[4].match(regexColorStop);
|
|
6927
|
-
return colors[colors.length - 1].split(':')[1];
|
|
6928
|
-
}
|
|
6929
7377
|
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
hash: gradientStr
|
|
6939
|
-
};
|
|
7378
|
+
var color$1 = color(colorStr);
|
|
7379
|
+
var rgba = [0, 0, 0, 0];
|
|
7380
|
+
|
|
7381
|
+
if (color$1 !== null) {
|
|
7382
|
+
rgba[0] = color$1.r || 0;
|
|
7383
|
+
rgba[1] = color$1.g || 0;
|
|
7384
|
+
rgba[2] = color$1.b || 0;
|
|
7385
|
+
rgba[3] = color$1.opacity;
|
|
6940
7386
|
}
|
|
6941
7387
|
|
|
6942
|
-
return
|
|
7388
|
+
return _construct(CSSRGB, rgba); // return {
|
|
7389
|
+
// type: PARSED_COLOR_TYPE.Constant,
|
|
7390
|
+
// value: rgba,
|
|
7391
|
+
// formatted:
|
|
7392
|
+
// // rgba(255,255,255,0) -> [NaN, NaN, NaN, 0]
|
|
7393
|
+
// // @see https://github.com/d3/d3-color/issues/52
|
|
7394
|
+
// (color && `rgba(${color.r || 0},${color.g || 0},${color.b || 0},${color.opacity})`) ||
|
|
7395
|
+
// 'rgba(0,0,0,0)',
|
|
7396
|
+
// };
|
|
7397
|
+
});
|
|
7398
|
+
function mergeColors(left, right) {
|
|
7399
|
+
// only support constant value, exclude gradient & pattern
|
|
7400
|
+
if (!(left instanceof CSSRGB) || !(right instanceof CSSRGB)) {
|
|
7401
|
+
return;
|
|
7402
|
+
}
|
|
7403
|
+
|
|
7404
|
+
return [[Number(left.r), Number(left.g), Number(left.b), Number(left.alpha)], [Number(right.r), Number(right.g), Number(right.b), Number(right.alpha)], function (color) {
|
|
7405
|
+
var rgba = color.slice();
|
|
7406
|
+
|
|
7407
|
+
if (rgba[3]) {
|
|
7408
|
+
for (var i = 0; i < 3; i++) {
|
|
7409
|
+
rgba[i] = Math.round(clamp(rgba[i], 0, 255));
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
|
|
7413
|
+
rgba[3] = clamp(rgba[3], 0, 1);
|
|
7414
|
+
return "rgba(" + rgba.join(',') + ")";
|
|
7415
|
+
}];
|
|
6943
7416
|
}
|
|
6944
7417
|
|
|
6945
7418
|
/**
|
|
@@ -7657,8 +8130,7 @@ function convertPercentUnit(valueWithUnit, vec3Index, target) {
|
|
|
7657
8130
|
if (valueWithUnit.unit === UnitType.kPixels) {
|
|
7658
8131
|
return Number(valueWithUnit.value);
|
|
7659
8132
|
} else if (valueWithUnit.unit === UnitType.kPercentage && target) {
|
|
7660
|
-
|
|
7661
|
-
var bounds = target.getGeometryBounds();
|
|
8133
|
+
var bounds = target.nodeName === Shape.GROUP ? target.getLocalBounds() : target.getGeometryBounds();
|
|
7662
8134
|
var size = 0;
|
|
7663
8135
|
|
|
7664
8136
|
if (!AABB.isEmpty(bounds)) {
|
|
@@ -13261,6 +13733,7 @@ function dispatchCallbacks() {
|
|
|
13261
13733
|
scale: [1, 10],
|
|
13262
13734
|
}
|
|
13263
13735
|
*/
|
|
13736
|
+
|
|
13264
13737
|
function convertToArrayForm(effectInput) {
|
|
13265
13738
|
var normalizedEffectInput = [];
|
|
13266
13739
|
|
|
@@ -13373,7 +13846,7 @@ function normalizeKeyframes(effectInput, timing) {
|
|
|
13373
13846
|
for (var i = 0; i < keyframes.length; i++) {
|
|
13374
13847
|
var offset = keyframes[i].offset;
|
|
13375
13848
|
|
|
13376
|
-
if (offset
|
|
13849
|
+
if (!isNil(offset)) {
|
|
13377
13850
|
if (offset < previousOffset) {
|
|
13378
13851
|
throw new TypeError('Keyframes are not loosely sorted by offset. Sort or specify offsets.');
|
|
13379
13852
|
}
|
|
@@ -13404,15 +13877,15 @@ function normalizeKeyframes(effectInput, timing) {
|
|
|
13404
13877
|
var previousOffset = Number(keyframes[0].computedOffset);
|
|
13405
13878
|
|
|
13406
13879
|
for (var _i = 1; _i < length; _i++) {
|
|
13407
|
-
var _offset =
|
|
13880
|
+
var _offset = keyframes[_i].computedOffset;
|
|
13408
13881
|
|
|
13409
|
-
if (_offset
|
|
13882
|
+
if (!isNil(_offset) && !isNil(previousOffset)) {
|
|
13410
13883
|
for (var j = 1; j < _i - previousIndex; j++) {
|
|
13411
|
-
keyframes[previousIndex + j].computedOffset = previousOffset + (_offset - previousOffset) * j / (_i - previousIndex);
|
|
13884
|
+
keyframes[previousIndex + j].computedOffset = previousOffset + (Number(_offset) - previousOffset) * j / (_i - previousIndex);
|
|
13412
13885
|
}
|
|
13413
13886
|
|
|
13414
13887
|
previousIndex = _i;
|
|
13415
|
-
previousOffset = _offset;
|
|
13888
|
+
previousOffset = Number(_offset);
|
|
13416
13889
|
}
|
|
13417
13890
|
}
|
|
13418
13891
|
}
|
|
@@ -18883,28 +19356,6 @@ CSSPropertyZIndex = __decorate([singleton({
|
|
|
18883
19356
|
}
|
|
18884
19357
|
})], CSSPropertyZIndex);
|
|
18885
19358
|
|
|
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
19359
|
/**
|
|
18909
19360
|
* Blink used them in code generation(css_properties.json5)
|
|
18910
19361
|
*/
|
|
@@ -19670,10 +20121,14 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
19670
20121
|
_geometryUpdater$upda4 = _geometryUpdater$upda.offsetY,
|
|
19671
20122
|
offsetY = _geometryUpdater$upda4 === void 0 ? 0 : _geometryUpdater$upda4,
|
|
19672
20123
|
_geometryUpdater$upda5 = _geometryUpdater$upda.offsetZ,
|
|
19673
|
-
offsetZ = _geometryUpdater$upda5 === void 0 ? 0 : _geometryUpdater$upda5; //
|
|
20124
|
+
offsetZ = _geometryUpdater$upda5 === void 0 ? 0 : _geometryUpdater$upda5; // account for negative width / height of Rect
|
|
20125
|
+
// @see https://github.com/antvis/g/issues/957
|
|
20126
|
+
|
|
19674
20127
|
|
|
20128
|
+
var flipY = width < 0;
|
|
20129
|
+
var flipX = height < 0; // init with content box
|
|
19675
20130
|
|
|
19676
|
-
var halfExtents = vec3.fromValues(width / 2, height / 2, depth / 2); // anchor is center by default, don't account for lineWidth here
|
|
20131
|
+
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
20132
|
|
|
19678
20133
|
var lineWidth = parsedStyle.lineWidth,
|
|
19679
20134
|
increasedLineWidthForHitTesting = parsedStyle.increasedLineWidthForHitTesting,
|
|
@@ -19687,7 +20142,7 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
19687
20142
|
delete parsedStyle.anchor;
|
|
19688
20143
|
}
|
|
19689
20144
|
|
|
19690
|
-
var center = vec3.fromValues((1 - (anchor && anchor[0].value || 0) * 2) *
|
|
20145
|
+
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
|
|
19691
20146
|
|
|
19692
20147
|
geometry.contentBounds.update(center, halfExtents);
|
|
19693
20148
|
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
|
|
@@ -19749,10 +20204,10 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
|
|
|
19749
20204
|
});
|
|
19750
20205
|
anchor = parsedStyle.anchor; // set transform origin
|
|
19751
20206
|
|
|
19752
|
-
var usedOriginXValue = convertPercentUnit(transformOrigin[0], 0, object);
|
|
19753
|
-
var usedOriginYValue = convertPercentUnit(transformOrigin[1], 1, object);
|
|
19754
|
-
usedOriginXValue
|
|
19755
|
-
usedOriginYValue
|
|
20207
|
+
var usedOriginXValue = (flipY ? -1 : 1) * convertPercentUnit(transformOrigin[0], 0, object);
|
|
20208
|
+
var usedOriginYValue = (flipX ? -1 : 1) * convertPercentUnit(transformOrigin[1], 1, object);
|
|
20209
|
+
usedOriginXValue = usedOriginXValue - (flipY ? -1 : 1) * (anchor && anchor[0].value || 0) * geometry.contentBounds.halfExtents[0] * 2;
|
|
20210
|
+
usedOriginYValue = usedOriginYValue - (flipX ? -1 : 1) * (anchor && anchor[1].value || 0) * geometry.contentBounds.halfExtents[1] * 2;
|
|
19756
20211
|
object.setOrigin(usedOriginXValue, usedOriginYValue);
|
|
19757
20212
|
object.dispatchEvent(new CustomEvent(ElementEvent.GEOMETRY_BOUNDS_CHANGED));
|
|
19758
20213
|
dirtifyToRoot(object);
|
|
@@ -21313,7 +21768,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
21313
21768
|
}
|
|
21314
21769
|
});
|
|
21315
21770
|
} else {
|
|
21316
|
-
console.
|
|
21771
|
+
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
21772
|
}
|
|
21318
21773
|
};
|
|
21319
21774
|
|
|
@@ -21385,4 +21840,4 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
|
|
|
21385
21840
|
GlobalContainer.load(containerModule);
|
|
21386
21841
|
var layoutEngine = GlobalContainer.get(LayoutEngine);
|
|
21387
21842
|
|
|
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,
|
|
21843
|
+
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, clonePath, colorStopToString, compareAnimations, computeLinearGradient, computeRadialGradient, convertAngleUnit, convertEffectInput, convertPercentUnit, convertToDash, convertToPath, createVec3, decompose, deg2rad, deg2turn, dirtifyToRoot, equalSet, equalizeSegments, formatAttribute, fromRotationTranslationScale, getAngle, getDrawDirection, getEasingFunction, getEuler, getHeight, getPathArea, getRotatedCurve, getRotationInRadians, getScaling, getStyle, getTranslation, getWidth, grad2deg, 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, rad2deg, reverseCurve, setDOMSize, sortByZIndex, toFontString, turn2deg, typeCheck, unitTypeToBaseType };
|