modern-canvas 0.4.40 → 0.4.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +257 -766
- package/dist/index.d.cts +76 -116
- package/dist/index.d.mts +76 -116
- package/dist/index.d.ts +76 -116
- package/dist/index.js +41 -41
- package/dist/index.mjs +258 -765
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1743,468 +1743,6 @@ class ColorMatrix extends Matrix {
|
|
|
1743
1743
|
}
|
|
1744
1744
|
}
|
|
1745
1745
|
|
|
1746
|
-
var GradientParser = GradientParser || {};
|
|
1747
|
-
GradientParser.parse = /* @__PURE__ */ function() {
|
|
1748
|
-
const tokens = {
|
|
1749
|
-
linearGradient: /^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,
|
|
1750
|
-
repeatingLinearGradient: /^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,
|
|
1751
|
-
radialGradient: /^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,
|
|
1752
|
-
repeatingRadialGradient: /^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,
|
|
1753
|
-
sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
|
|
1754
|
-
extentKeywords: /^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,
|
|
1755
|
-
positionKeywords: /^(left|center|right|top|bottom)/i,
|
|
1756
|
-
pixelValue: /^(-?((\d*\.\d+)|(\d+\.?)))px/,
|
|
1757
|
-
percentageValue: /^(-?((\d*\.\d+)|(\d+\.?)))%/,
|
|
1758
|
-
emValue: /^(-?((\d*\.\d+)|(\d+\.?)))em/,
|
|
1759
|
-
angleValue: /^(-?((\d*\.\d+)|(\d+\.?)))deg/,
|
|
1760
|
-
radianValue: /^(-?((\d*\.\d+)|(\d+\.?)))rad/,
|
|
1761
|
-
startCall: /^\(/,
|
|
1762
|
-
endCall: /^\)/,
|
|
1763
|
-
comma: /^,/,
|
|
1764
|
-
hexColor: /^#([0-9a-f]+)/i,
|
|
1765
|
-
literalColor: /^([a-z]+)/i,
|
|
1766
|
-
rgbColor: /^rgb/i,
|
|
1767
|
-
rgbaColor: /^rgba/i,
|
|
1768
|
-
varColor: /^var/i,
|
|
1769
|
-
calcValue: /^calc/i,
|
|
1770
|
-
variableName: /^(--[a-z0-9-,\s#]+)/i,
|
|
1771
|
-
number: /^((\d*\.\d+)|(\d+\.?))/,
|
|
1772
|
-
hslColor: /^hsl/i,
|
|
1773
|
-
hslaColor: /^hsla/i
|
|
1774
|
-
};
|
|
1775
|
-
let input = "";
|
|
1776
|
-
function error(msg) {
|
|
1777
|
-
const err = new Error(`${input}: ${msg}`);
|
|
1778
|
-
err.source = input;
|
|
1779
|
-
throw err;
|
|
1780
|
-
}
|
|
1781
|
-
function getAST() {
|
|
1782
|
-
const ast = matchListDefinitions();
|
|
1783
|
-
if (input.length > 0) {
|
|
1784
|
-
error("Invalid input not EOF");
|
|
1785
|
-
}
|
|
1786
|
-
return ast;
|
|
1787
|
-
}
|
|
1788
|
-
function matchListDefinitions() {
|
|
1789
|
-
return matchListing(matchDefinition);
|
|
1790
|
-
}
|
|
1791
|
-
function matchDefinition() {
|
|
1792
|
-
return matchGradient(
|
|
1793
|
-
"linear-gradient",
|
|
1794
|
-
tokens.linearGradient,
|
|
1795
|
-
matchLinearOrientation
|
|
1796
|
-
) || matchGradient(
|
|
1797
|
-
"repeating-linear-gradient",
|
|
1798
|
-
tokens.repeatingLinearGradient,
|
|
1799
|
-
matchLinearOrientation
|
|
1800
|
-
) || matchGradient(
|
|
1801
|
-
"radial-gradient",
|
|
1802
|
-
tokens.radialGradient,
|
|
1803
|
-
matchListRadialOrientations
|
|
1804
|
-
) || matchGradient(
|
|
1805
|
-
"repeating-radial-gradient",
|
|
1806
|
-
tokens.repeatingRadialGradient,
|
|
1807
|
-
matchListRadialOrientations
|
|
1808
|
-
);
|
|
1809
|
-
}
|
|
1810
|
-
function matchGradient(gradientType, pattern, orientationMatcher) {
|
|
1811
|
-
return matchCall(pattern, (captures) => {
|
|
1812
|
-
const orientation = orientationMatcher();
|
|
1813
|
-
if (orientation) {
|
|
1814
|
-
if (!scan(tokens.comma)) {
|
|
1815
|
-
error("Missing comma before color stops");
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
return {
|
|
1819
|
-
type: gradientType,
|
|
1820
|
-
orientation,
|
|
1821
|
-
colorStops: matchListing(matchColorStop)
|
|
1822
|
-
};
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
function matchCall(pattern, callback) {
|
|
1826
|
-
const captures = scan(pattern);
|
|
1827
|
-
if (captures) {
|
|
1828
|
-
if (!scan(tokens.startCall)) {
|
|
1829
|
-
error("Missing (");
|
|
1830
|
-
}
|
|
1831
|
-
const result = callback(captures);
|
|
1832
|
-
if (!scan(tokens.endCall)) {
|
|
1833
|
-
error("Missing )");
|
|
1834
|
-
}
|
|
1835
|
-
return result;
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
function matchLinearOrientation() {
|
|
1839
|
-
const sideOrCorner = matchSideOrCorner();
|
|
1840
|
-
if (sideOrCorner) {
|
|
1841
|
-
return sideOrCorner;
|
|
1842
|
-
}
|
|
1843
|
-
const legacyDirection = match("position-keyword", tokens.positionKeywords, 1);
|
|
1844
|
-
if (legacyDirection) {
|
|
1845
|
-
return {
|
|
1846
|
-
type: "directional",
|
|
1847
|
-
value: legacyDirection.value
|
|
1848
|
-
};
|
|
1849
|
-
}
|
|
1850
|
-
return matchAngle();
|
|
1851
|
-
}
|
|
1852
|
-
function matchSideOrCorner() {
|
|
1853
|
-
return match("directional", tokens.sideOrCorner, 1);
|
|
1854
|
-
}
|
|
1855
|
-
function matchAngle() {
|
|
1856
|
-
return match("angular", tokens.angleValue, 1) || match("angular", tokens.radianValue, 1);
|
|
1857
|
-
}
|
|
1858
|
-
function matchListRadialOrientations() {
|
|
1859
|
-
let radialOrientations;
|
|
1860
|
-
let radialOrientation = matchRadialOrientation();
|
|
1861
|
-
let lookaheadCache;
|
|
1862
|
-
if (radialOrientation) {
|
|
1863
|
-
radialOrientations = [];
|
|
1864
|
-
radialOrientations.push(radialOrientation);
|
|
1865
|
-
lookaheadCache = input;
|
|
1866
|
-
if (scan(tokens.comma)) {
|
|
1867
|
-
radialOrientation = matchRadialOrientation();
|
|
1868
|
-
if (radialOrientation) {
|
|
1869
|
-
radialOrientations.push(radialOrientation);
|
|
1870
|
-
} else {
|
|
1871
|
-
input = lookaheadCache;
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
return radialOrientations;
|
|
1876
|
-
}
|
|
1877
|
-
function matchRadialOrientation() {
|
|
1878
|
-
let radialType = matchCircle() || matchEllipse();
|
|
1879
|
-
if (radialType) {
|
|
1880
|
-
radialType.at = matchAtPosition();
|
|
1881
|
-
} else {
|
|
1882
|
-
const extent = matchExtentKeyword();
|
|
1883
|
-
if (extent) {
|
|
1884
|
-
radialType = extent;
|
|
1885
|
-
const positionAt = matchAtPosition();
|
|
1886
|
-
if (positionAt) {
|
|
1887
|
-
radialType.at = positionAt;
|
|
1888
|
-
}
|
|
1889
|
-
} else {
|
|
1890
|
-
const atPosition = matchAtPosition();
|
|
1891
|
-
if (atPosition) {
|
|
1892
|
-
radialType = {
|
|
1893
|
-
type: "default-radial",
|
|
1894
|
-
at: atPosition
|
|
1895
|
-
};
|
|
1896
|
-
} else {
|
|
1897
|
-
const defaultPosition = matchPositioning();
|
|
1898
|
-
if (defaultPosition) {
|
|
1899
|
-
radialType = {
|
|
1900
|
-
type: "default-radial",
|
|
1901
|
-
at: defaultPosition
|
|
1902
|
-
};
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
return radialType;
|
|
1908
|
-
}
|
|
1909
|
-
function matchCircle() {
|
|
1910
|
-
const circle = match("shape", /^(circle)/i, 0);
|
|
1911
|
-
if (circle) {
|
|
1912
|
-
circle.style = matchLength() || matchExtentKeyword();
|
|
1913
|
-
}
|
|
1914
|
-
return circle;
|
|
1915
|
-
}
|
|
1916
|
-
function matchEllipse() {
|
|
1917
|
-
const ellipse = match("shape", /^(ellipse)/i, 0);
|
|
1918
|
-
if (ellipse) {
|
|
1919
|
-
ellipse.style = matchPositioning() || matchDistance() || matchExtentKeyword();
|
|
1920
|
-
}
|
|
1921
|
-
return ellipse;
|
|
1922
|
-
}
|
|
1923
|
-
function matchExtentKeyword() {
|
|
1924
|
-
return match("extent-keyword", tokens.extentKeywords, 1);
|
|
1925
|
-
}
|
|
1926
|
-
function matchAtPosition() {
|
|
1927
|
-
if (match("position", /^at/, 0)) {
|
|
1928
|
-
const positioning = matchPositioning();
|
|
1929
|
-
if (!positioning) {
|
|
1930
|
-
error("Missing positioning value");
|
|
1931
|
-
}
|
|
1932
|
-
return positioning;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
function matchPositioning() {
|
|
1936
|
-
const location = matchCoordinates();
|
|
1937
|
-
if (location.x || location.y) {
|
|
1938
|
-
return {
|
|
1939
|
-
type: "position",
|
|
1940
|
-
value: location
|
|
1941
|
-
};
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
function matchCoordinates() {
|
|
1945
|
-
return {
|
|
1946
|
-
x: matchDistance(),
|
|
1947
|
-
y: matchDistance()
|
|
1948
|
-
};
|
|
1949
|
-
}
|
|
1950
|
-
function matchListing(matcher) {
|
|
1951
|
-
let captures = matcher();
|
|
1952
|
-
const result = [];
|
|
1953
|
-
if (captures) {
|
|
1954
|
-
result.push(captures);
|
|
1955
|
-
while (scan(tokens.comma)) {
|
|
1956
|
-
captures = matcher();
|
|
1957
|
-
if (captures) {
|
|
1958
|
-
result.push(captures);
|
|
1959
|
-
} else {
|
|
1960
|
-
error("One extra comma");
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
return result;
|
|
1965
|
-
}
|
|
1966
|
-
function matchColorStop() {
|
|
1967
|
-
const color = matchColor();
|
|
1968
|
-
if (!color) {
|
|
1969
|
-
error("Expected color definition");
|
|
1970
|
-
}
|
|
1971
|
-
color.length = matchDistance();
|
|
1972
|
-
return color;
|
|
1973
|
-
}
|
|
1974
|
-
function matchColor() {
|
|
1975
|
-
return matchHexColor() || matchHSLAColor() || matchHSLColor() || matchRGBAColor() || matchRGBColor() || matchVarColor() || matchLiteralColor();
|
|
1976
|
-
}
|
|
1977
|
-
function matchLiteralColor() {
|
|
1978
|
-
return match("literal", tokens.literalColor, 0);
|
|
1979
|
-
}
|
|
1980
|
-
function matchHexColor() {
|
|
1981
|
-
return match("hex", tokens.hexColor, 1);
|
|
1982
|
-
}
|
|
1983
|
-
function matchRGBColor() {
|
|
1984
|
-
return matchCall(tokens.rgbColor, () => {
|
|
1985
|
-
return {
|
|
1986
|
-
type: "rgb",
|
|
1987
|
-
value: matchListing(matchNumber)
|
|
1988
|
-
};
|
|
1989
|
-
});
|
|
1990
|
-
}
|
|
1991
|
-
function matchRGBAColor() {
|
|
1992
|
-
return matchCall(tokens.rgbaColor, () => {
|
|
1993
|
-
return {
|
|
1994
|
-
type: "rgba",
|
|
1995
|
-
value: matchListing(matchNumber)
|
|
1996
|
-
};
|
|
1997
|
-
});
|
|
1998
|
-
}
|
|
1999
|
-
function matchVarColor() {
|
|
2000
|
-
return matchCall(tokens.varColor, () => {
|
|
2001
|
-
return {
|
|
2002
|
-
type: "var",
|
|
2003
|
-
value: matchVariableName()
|
|
2004
|
-
};
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
function matchHSLColor() {
|
|
2008
|
-
return matchCall(tokens.hslColor, () => {
|
|
2009
|
-
const lookahead = scan(tokens.percentageValue);
|
|
2010
|
-
if (lookahead) {
|
|
2011
|
-
error("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");
|
|
2012
|
-
}
|
|
2013
|
-
const hue = matchNumber();
|
|
2014
|
-
scan(tokens.comma);
|
|
2015
|
-
let captures = scan(tokens.percentageValue);
|
|
2016
|
-
const sat = captures ? captures[1] : null;
|
|
2017
|
-
scan(tokens.comma);
|
|
2018
|
-
captures = scan(tokens.percentageValue);
|
|
2019
|
-
const light = captures ? captures[1] : null;
|
|
2020
|
-
if (!sat || !light) {
|
|
2021
|
-
error("Expected percentage value for saturation and lightness in HSL");
|
|
2022
|
-
}
|
|
2023
|
-
return {
|
|
2024
|
-
type: "hsl",
|
|
2025
|
-
value: [hue, sat, light]
|
|
2026
|
-
};
|
|
2027
|
-
});
|
|
2028
|
-
}
|
|
2029
|
-
function matchHSLAColor() {
|
|
2030
|
-
return matchCall(tokens.hslaColor, () => {
|
|
2031
|
-
const hue = matchNumber();
|
|
2032
|
-
scan(tokens.comma);
|
|
2033
|
-
let captures = scan(tokens.percentageValue);
|
|
2034
|
-
const sat = captures ? captures[1] : null;
|
|
2035
|
-
scan(tokens.comma);
|
|
2036
|
-
captures = scan(tokens.percentageValue);
|
|
2037
|
-
const light = captures ? captures[1] : null;
|
|
2038
|
-
scan(tokens.comma);
|
|
2039
|
-
const alpha = matchNumber();
|
|
2040
|
-
if (!sat || !light) {
|
|
2041
|
-
error("Expected percentage value for saturation and lightness in HSLA");
|
|
2042
|
-
}
|
|
2043
|
-
return {
|
|
2044
|
-
type: "hsla",
|
|
2045
|
-
value: [hue, sat, light, alpha]
|
|
2046
|
-
};
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
function matchVariableName() {
|
|
2050
|
-
return scan(tokens.variableName)[1];
|
|
2051
|
-
}
|
|
2052
|
-
function matchNumber() {
|
|
2053
|
-
return scan(tokens.number)[1];
|
|
2054
|
-
}
|
|
2055
|
-
function matchDistance() {
|
|
2056
|
-
return match("%", tokens.percentageValue, 1) || matchPositionKeyword() || matchCalc() || matchLength();
|
|
2057
|
-
}
|
|
2058
|
-
function matchPositionKeyword() {
|
|
2059
|
-
return match("position-keyword", tokens.positionKeywords, 1);
|
|
2060
|
-
}
|
|
2061
|
-
function matchCalc() {
|
|
2062
|
-
return matchCall(tokens.calcValue, () => {
|
|
2063
|
-
let openParenCount = 1;
|
|
2064
|
-
let i = 0;
|
|
2065
|
-
while (openParenCount > 0 && i < input.length) {
|
|
2066
|
-
const char = input.charAt(i);
|
|
2067
|
-
if (char === "(") {
|
|
2068
|
-
openParenCount++;
|
|
2069
|
-
} else if (char === ")") {
|
|
2070
|
-
openParenCount--;
|
|
2071
|
-
}
|
|
2072
|
-
i++;
|
|
2073
|
-
}
|
|
2074
|
-
if (openParenCount > 0) {
|
|
2075
|
-
error("Missing closing parenthesis in calc() expression");
|
|
2076
|
-
}
|
|
2077
|
-
const calcContent = input.substring(0, i - 1);
|
|
2078
|
-
consume(i - 1);
|
|
2079
|
-
return {
|
|
2080
|
-
type: "calc",
|
|
2081
|
-
value: calcContent
|
|
2082
|
-
};
|
|
2083
|
-
});
|
|
2084
|
-
}
|
|
2085
|
-
function matchLength() {
|
|
2086
|
-
return match("px", tokens.pixelValue, 1) || match("em", tokens.emValue, 1);
|
|
2087
|
-
}
|
|
2088
|
-
function match(type, pattern, captureIndex) {
|
|
2089
|
-
const captures = scan(pattern);
|
|
2090
|
-
if (captures) {
|
|
2091
|
-
return {
|
|
2092
|
-
type,
|
|
2093
|
-
value: captures[captureIndex]
|
|
2094
|
-
};
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
function scan(regexp) {
|
|
2098
|
-
let captures, blankCaptures;
|
|
2099
|
-
blankCaptures = /^\s+/.exec(input);
|
|
2100
|
-
if (blankCaptures) {
|
|
2101
|
-
consume(blankCaptures[0].length);
|
|
2102
|
-
}
|
|
2103
|
-
captures = regexp.exec(input);
|
|
2104
|
-
if (captures) {
|
|
2105
|
-
consume(captures[0].length);
|
|
2106
|
-
}
|
|
2107
|
-
return captures;
|
|
2108
|
-
}
|
|
2109
|
-
function consume(size) {
|
|
2110
|
-
input = input.substr(size);
|
|
2111
|
-
}
|
|
2112
|
-
return function(code) {
|
|
2113
|
-
input = code.toString().trim();
|
|
2114
|
-
if (input.endsWith(";")) {
|
|
2115
|
-
input = input.slice(0, -1);
|
|
2116
|
-
}
|
|
2117
|
-
return getAST();
|
|
2118
|
-
};
|
|
2119
|
-
}();
|
|
2120
|
-
const parseGradient = GradientParser.parse.bind(GradientParser);
|
|
2121
|
-
|
|
2122
|
-
class LinearGradient {
|
|
2123
|
-
constructor(x0, y0, x1, y1, stops) {
|
|
2124
|
-
this.x0 = x0;
|
|
2125
|
-
this.y0 = y0;
|
|
2126
|
-
this.x1 = x1;
|
|
2127
|
-
this.y1 = y1;
|
|
2128
|
-
this.stops = stops;
|
|
2129
|
-
}
|
|
2130
|
-
static from(css) {
|
|
2131
|
-
let angleDeg = 0;
|
|
2132
|
-
const stops = [];
|
|
2133
|
-
const ast = parseGradient(css)[0];
|
|
2134
|
-
if (ast.type === "linear-gradient") {
|
|
2135
|
-
switch (ast?.orientation?.type) {
|
|
2136
|
-
case "angular":
|
|
2137
|
-
angleDeg = Number(ast.orientation.value);
|
|
2138
|
-
break;
|
|
2139
|
-
}
|
|
2140
|
-
ast.colorStops.forEach((stop) => {
|
|
2141
|
-
let offset = 0;
|
|
2142
|
-
let color = "rgba(0, 0, 0, 0)";
|
|
2143
|
-
switch (stop.type) {
|
|
2144
|
-
case "rgb":
|
|
2145
|
-
color = `rgb(${stop.value[0]}, ${stop.value[1]}, ${stop.value[2]})`;
|
|
2146
|
-
break;
|
|
2147
|
-
case "rgba":
|
|
2148
|
-
color = `rgba(${stop.value[0]}, ${stop.value[1]}, ${stop.value[2]}, ${stop.value[3]})`;
|
|
2149
|
-
break;
|
|
2150
|
-
case "literal":
|
|
2151
|
-
color = stop.value;
|
|
2152
|
-
break;
|
|
2153
|
-
case "hex":
|
|
2154
|
-
color = stop.value;
|
|
2155
|
-
break;
|
|
2156
|
-
}
|
|
2157
|
-
switch (stop.length?.type) {
|
|
2158
|
-
case "%":
|
|
2159
|
-
offset = Number(stop.length.value) / 100;
|
|
2160
|
-
break;
|
|
2161
|
-
}
|
|
2162
|
-
stops.push({ offset, color });
|
|
2163
|
-
});
|
|
2164
|
-
}
|
|
2165
|
-
const angleRad = (angleDeg + 90) * Math.PI / 180;
|
|
2166
|
-
const width = 1;
|
|
2167
|
-
const height = 1;
|
|
2168
|
-
const halfWidth = width / 2;
|
|
2169
|
-
const halfHeight = height / 2;
|
|
2170
|
-
const length = Math.sqrt(width * width + height * height) / 2;
|
|
2171
|
-
const x0 = halfWidth + length * Math.cos(angleRad + Math.PI);
|
|
2172
|
-
const y0 = halfHeight + length * Math.sin(angleRad + Math.PI);
|
|
2173
|
-
const x1 = halfWidth + length * Math.cos(angleRad);
|
|
2174
|
-
const y1 = halfHeight + length * Math.sin(angleRad);
|
|
2175
|
-
return new LinearGradient(x0, y0, x1, y1, stops);
|
|
2176
|
-
}
|
|
2177
|
-
parse(width, height) {
|
|
2178
|
-
return this._parseByCanvas(width, height);
|
|
2179
|
-
}
|
|
2180
|
-
_parseByCanvas(width, height) {
|
|
2181
|
-
const canvas = document.createElement("canvas");
|
|
2182
|
-
canvas.width = width;
|
|
2183
|
-
canvas.height = height;
|
|
2184
|
-
const ctx = canvas.getContext("2d");
|
|
2185
|
-
if (!ctx) {
|
|
2186
|
-
throw new Error("Failed to parse linear gradient, get canvas context is null.");
|
|
2187
|
-
}
|
|
2188
|
-
const gradient = ctx.createLinearGradient(
|
|
2189
|
-
this.x0 * width,
|
|
2190
|
-
this.y0 * height,
|
|
2191
|
-
this.x1 * width,
|
|
2192
|
-
this.y1 * height
|
|
2193
|
-
);
|
|
2194
|
-
this.stops.forEach((stop) => {
|
|
2195
|
-
gradient.addColorStop(stop.offset, stop.color);
|
|
2196
|
-
});
|
|
2197
|
-
ctx.fillStyle = gradient;
|
|
2198
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
2199
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
2200
|
-
return {
|
|
2201
|
-
width: imageData.width,
|
|
2202
|
-
height: imageData.height,
|
|
2203
|
-
pixels: new Uint8Array(imageData.data.buffer)
|
|
2204
|
-
};
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
1746
|
class Matrix2 extends Matrix {
|
|
2209
1747
|
constructor(array) {
|
|
2210
1748
|
super(2, 2, array);
|
|
@@ -2309,47 +1847,6 @@ class Projection2D extends Matrix3 {
|
|
|
2309
1847
|
}
|
|
2310
1848
|
}
|
|
2311
1849
|
|
|
2312
|
-
class RadialGradient {
|
|
2313
|
-
constructor(x0, y0, r0, x1, y1, r1, stops) {
|
|
2314
|
-
this.x0 = x0;
|
|
2315
|
-
this.y0 = y0;
|
|
2316
|
-
this.r0 = r0;
|
|
2317
|
-
this.x1 = x1;
|
|
2318
|
-
this.y1 = y1;
|
|
2319
|
-
this.r1 = r1;
|
|
2320
|
-
this.stops = stops;
|
|
2321
|
-
}
|
|
2322
|
-
parse(width, height) {
|
|
2323
|
-
return this._parseByCanvas(width, height);
|
|
2324
|
-
}
|
|
2325
|
-
_parseByCanvas(width, height) {
|
|
2326
|
-
const canvas = document.createElement("canvas");
|
|
2327
|
-
const ctx = canvas.getContext("2d");
|
|
2328
|
-
if (!ctx) {
|
|
2329
|
-
throw new Error("Failed to parse radial gradient, get canvas context is null.");
|
|
2330
|
-
}
|
|
2331
|
-
const gradient = ctx.createRadialGradient(
|
|
2332
|
-
this.x0 * width,
|
|
2333
|
-
this.y0 * height,
|
|
2334
|
-
this.r0,
|
|
2335
|
-
this.x1 * width,
|
|
2336
|
-
this.y1 * height,
|
|
2337
|
-
this.r1
|
|
2338
|
-
);
|
|
2339
|
-
this.stops.forEach((stop) => {
|
|
2340
|
-
gradient.addColorStop(stop.offset, stop.color);
|
|
2341
|
-
});
|
|
2342
|
-
ctx.fillStyle = gradient;
|
|
2343
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
2344
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
2345
|
-
return {
|
|
2346
|
-
width: imageData.width,
|
|
2347
|
-
height: imageData.height,
|
|
2348
|
-
pixels: new Uint8Array(imageData.data.buffer)
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
1850
|
class Vector2 extends Vector {
|
|
2354
1851
|
get x() {
|
|
2355
1852
|
return this._array[0];
|
|
@@ -5653,14 +5150,41 @@ class ColorTexture extends Texture2D {
|
|
|
5653
5150
|
}
|
|
5654
5151
|
|
|
5655
5152
|
class GradientTexture extends Texture2D {
|
|
5656
|
-
// |(radial-gradient)
|
|
5657
|
-
static regExp = /(linear-gradient)/;
|
|
5658
5153
|
static test(value) {
|
|
5659
|
-
return
|
|
5154
|
+
return modernIdoc.isGradient(value);
|
|
5155
|
+
}
|
|
5156
|
+
static linearGradient(linearGradient, width, height) {
|
|
5157
|
+
const canvas = document.createElement("canvas");
|
|
5158
|
+
canvas.width = width;
|
|
5159
|
+
canvas.height = height;
|
|
5160
|
+
const ctx = canvas.getContext("2d");
|
|
5161
|
+
if (!ctx) {
|
|
5162
|
+
throw new Error("Failed to parse linear gradient, get canvas context is null.");
|
|
5163
|
+
}
|
|
5164
|
+
const { angle, stops } = linearGradient;
|
|
5165
|
+
const halfWidth = width / 2;
|
|
5166
|
+
const halfHeight = height / 2;
|
|
5167
|
+
const length = Math.sqrt(width * width + height * height) / 2;
|
|
5168
|
+
const x0 = halfWidth + length * Math.cos(angle + Math.PI);
|
|
5169
|
+
const y0 = halfHeight + length * Math.sin(angle + Math.PI);
|
|
5170
|
+
const x1 = halfWidth + length * Math.cos(angle);
|
|
5171
|
+
const y1 = halfHeight + length * Math.sin(angle);
|
|
5172
|
+
const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
5173
|
+
stops.forEach((stop) => {
|
|
5174
|
+
gradient.addColorStop(stop.offset, stop.color);
|
|
5175
|
+
});
|
|
5176
|
+
ctx.fillStyle = gradient;
|
|
5177
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
5178
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
5179
|
+
return {
|
|
5180
|
+
width: imageData.width,
|
|
5181
|
+
height: imageData.height,
|
|
5182
|
+
pixels: new Uint8Array(imageData.data.buffer)
|
|
5183
|
+
};
|
|
5660
5184
|
}
|
|
5661
|
-
constructor(
|
|
5185
|
+
constructor(gradient, width, height) {
|
|
5662
5186
|
super(
|
|
5663
|
-
|
|
5187
|
+
GradientTexture.linearGradient(gradient, width, height)
|
|
5664
5188
|
);
|
|
5665
5189
|
}
|
|
5666
5190
|
}
|
|
@@ -7633,21 +7157,18 @@ class CanvasContext extends modernPath2d.Path2D {
|
|
|
7633
7157
|
miterLimit;
|
|
7634
7158
|
_defaultStyle = Texture2D.EMPTY;
|
|
7635
7159
|
_draws = [];
|
|
7636
|
-
|
|
7637
|
-
if (
|
|
7638
|
-
return
|
|
7639
|
-
} else if (typeof color === "string" && GradientTexture.test(color)) {
|
|
7640
|
-
return new GradientTexture(color, width, height);
|
|
7160
|
+
_toTexture(source) {
|
|
7161
|
+
if (source instanceof Texture2D) {
|
|
7162
|
+
return source;
|
|
7641
7163
|
} else {
|
|
7642
|
-
return new ColorTexture(
|
|
7164
|
+
return new ColorTexture(source);
|
|
7643
7165
|
}
|
|
7644
7166
|
}
|
|
7645
7167
|
stroke(options) {
|
|
7646
7168
|
const path = new modernPath2d.Path2D(this);
|
|
7647
7169
|
let texture = this._defaultStyle;
|
|
7648
7170
|
if (this.strokeStyle) {
|
|
7649
|
-
|
|
7650
|
-
texture = this._colorToTexture(this.strokeStyle, width, height);
|
|
7171
|
+
texture = this._toTexture(this.strokeStyle);
|
|
7651
7172
|
}
|
|
7652
7173
|
if (this.curves.length) {
|
|
7653
7174
|
this._draws.push({
|
|
@@ -7677,8 +7198,7 @@ class CanvasContext extends modernPath2d.Path2D {
|
|
|
7677
7198
|
const path = new modernPath2d.Path2D(this);
|
|
7678
7199
|
let texture = this._defaultStyle;
|
|
7679
7200
|
if (this.fillStyle) {
|
|
7680
|
-
|
|
7681
|
-
texture = this._colorToTexture(this.fillStyle, width, height);
|
|
7201
|
+
texture = this._toTexture(this.fillStyle);
|
|
7682
7202
|
}
|
|
7683
7203
|
this._draws.push({
|
|
7684
7204
|
...options,
|
|
@@ -9449,93 +8969,98 @@ class BaseElement2DFill extends CoreObject {
|
|
|
9449
8969
|
super();
|
|
9450
8970
|
this.parent = parent;
|
|
9451
8971
|
}
|
|
9452
|
-
|
|
8972
|
+
_texture;
|
|
8973
|
+
_setProperties(properties) {
|
|
8974
|
+
return super.setProperties(properties);
|
|
8975
|
+
}
|
|
9453
8976
|
setProperties(properties) {
|
|
9454
|
-
return
|
|
8977
|
+
return this._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeFill(properties));
|
|
9455
8978
|
}
|
|
9456
8979
|
_updateProperty(key, value, oldValue, declaration) {
|
|
9457
8980
|
super._updateProperty(key, value, oldValue, declaration);
|
|
9458
8981
|
switch (key) {
|
|
9459
8982
|
case "color":
|
|
8983
|
+
case "cropRect":
|
|
8984
|
+
case "stretchRect":
|
|
9460
8985
|
case "dpi":
|
|
9461
8986
|
case "rotateWithShape":
|
|
9462
8987
|
case "tile":
|
|
8988
|
+
case "opacity":
|
|
9463
8989
|
this.parent.requestRedraw();
|
|
9464
8990
|
break;
|
|
9465
|
-
case "
|
|
9466
|
-
|
|
8991
|
+
case "image":
|
|
8992
|
+
case "linearGradient":
|
|
8993
|
+
case "radialGradient":
|
|
8994
|
+
this._updateTexture();
|
|
9467
8995
|
break;
|
|
9468
8996
|
}
|
|
9469
8997
|
}
|
|
9470
|
-
async
|
|
9471
|
-
if (this.
|
|
9472
|
-
return
|
|
8998
|
+
async loadTexture() {
|
|
8999
|
+
if (this.linearGradient || this.radialGradient) {
|
|
9000
|
+
return new GradientTexture(
|
|
9001
|
+
this.linearGradient ?? this.radialGradient,
|
|
9002
|
+
this.parent.size.width,
|
|
9003
|
+
this.parent.size.height
|
|
9004
|
+
);
|
|
9005
|
+
} else if (!modernIdoc.isNone(this.image)) {
|
|
9006
|
+
return await assets.texture.load(this.image);
|
|
9007
|
+
} else {
|
|
9008
|
+
return void 0;
|
|
9473
9009
|
}
|
|
9474
9010
|
}
|
|
9475
|
-
async
|
|
9476
|
-
this.
|
|
9011
|
+
async _updateTexture() {
|
|
9012
|
+
this._texture = await this.loadTexture();
|
|
9477
9013
|
this.parent.requestRedraw();
|
|
9478
9014
|
}
|
|
9479
9015
|
canDraw() {
|
|
9480
9016
|
return Boolean(
|
|
9481
|
-
this.
|
|
9017
|
+
this._texture || this.color
|
|
9482
9018
|
);
|
|
9483
9019
|
}
|
|
9020
|
+
_getDrawOptions() {
|
|
9021
|
+
let disableWrapMode = false;
|
|
9022
|
+
const { width, height } = this.parent.size;
|
|
9023
|
+
const textureTransform = new Transform2D().scale(1 / width, 1 / height);
|
|
9024
|
+
if (this.cropRect) {
|
|
9025
|
+
const {
|
|
9026
|
+
left = 0,
|
|
9027
|
+
top = 0,
|
|
9028
|
+
right = 0,
|
|
9029
|
+
bottom = 0
|
|
9030
|
+
} = this.cropRect;
|
|
9031
|
+
textureTransform.scale(
|
|
9032
|
+
Math.abs(1 - (left + right)),
|
|
9033
|
+
Math.abs(1 - (top + bottom))
|
|
9034
|
+
).translate(left, top);
|
|
9035
|
+
disableWrapMode = true;
|
|
9036
|
+
}
|
|
9037
|
+
if (this.tile) {
|
|
9038
|
+
const {
|
|
9039
|
+
translateX = 0,
|
|
9040
|
+
translateY = 0,
|
|
9041
|
+
scaleX = 1,
|
|
9042
|
+
scaleY = 1
|
|
9043
|
+
// flip, TODO
|
|
9044
|
+
// alignment, TODO
|
|
9045
|
+
} = this.tile;
|
|
9046
|
+
textureTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
|
|
9047
|
+
disableWrapMode = true;
|
|
9048
|
+
} else if (this.stretchRect) {
|
|
9049
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
|
|
9050
|
+
textureTransform.scale(
|
|
9051
|
+
Math.abs(1 - (-left + -right)),
|
|
9052
|
+
Math.abs(1 - (-top + -bottom))
|
|
9053
|
+
).translate(-left, -top);
|
|
9054
|
+
disableWrapMode = true;
|
|
9055
|
+
}
|
|
9056
|
+
return { disableWrapMode, textureTransform };
|
|
9057
|
+
}
|
|
9484
9058
|
draw() {
|
|
9485
9059
|
const ctx = this.parent.context;
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
let disableWrapMode = false;
|
|
9491
|
-
if (this.srcRect) {
|
|
9492
|
-
const {
|
|
9493
|
-
left = 0,
|
|
9494
|
-
top = 0,
|
|
9495
|
-
right = 0,
|
|
9496
|
-
bottom = 0
|
|
9497
|
-
} = this.srcRect;
|
|
9498
|
-
const w = Math.abs(1 + (left + right)) * width;
|
|
9499
|
-
const h = Math.abs(1 + (top + bottom)) * height;
|
|
9500
|
-
const sx = 1 / w;
|
|
9501
|
-
const sy = 1 / h;
|
|
9502
|
-
const tx = left * width * sx;
|
|
9503
|
-
const ty = top * height * sy;
|
|
9504
|
-
transform.scale(sx, sy).translate(tx, ty);
|
|
9505
|
-
}
|
|
9506
|
-
if (this.tile) {
|
|
9507
|
-
const {
|
|
9508
|
-
translateX = 0,
|
|
9509
|
-
translateY = 0,
|
|
9510
|
-
scaleX = 1,
|
|
9511
|
-
scaleY = 1
|
|
9512
|
-
// flip, TODO
|
|
9513
|
-
// alignment, TODO
|
|
9514
|
-
} = this.tile;
|
|
9515
|
-
transform.scale(1 / imageWidth, 1 / imageHeight).scale(1 / scaleX, 1 / scaleY).translate(-translateX / imageWidth, -translateY / imageHeight);
|
|
9516
|
-
disableWrapMode = true;
|
|
9517
|
-
} else if (this.stretch) {
|
|
9518
|
-
const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretch.rect ?? {};
|
|
9519
|
-
const w = Math.abs(1 + (-left + -right)) * width;
|
|
9520
|
-
const h = Math.abs(1 + (-top + -bottom)) * height;
|
|
9521
|
-
const scaleX = 1 / w;
|
|
9522
|
-
const scaleY = 1 / h;
|
|
9523
|
-
const translateX = -left * width * scaleX;
|
|
9524
|
-
const translateY = -top * height * scaleY;
|
|
9525
|
-
transform.scale(scaleX, scaleY).translate(translateX, translateY);
|
|
9526
|
-
disableWrapMode = true;
|
|
9527
|
-
} else {
|
|
9528
|
-
transform.scale(1 / width, 1 / height);
|
|
9529
|
-
}
|
|
9530
|
-
ctx.textureTransform = transform;
|
|
9531
|
-
ctx.fillStyle = this._src;
|
|
9532
|
-
ctx.fill({
|
|
9533
|
-
disableWrapMode
|
|
9534
|
-
});
|
|
9535
|
-
} else {
|
|
9536
|
-
ctx.fillStyle = this.color;
|
|
9537
|
-
ctx.fill();
|
|
9538
|
-
}
|
|
9060
|
+
const { textureTransform, disableWrapMode } = this._getDrawOptions();
|
|
9061
|
+
ctx.textureTransform = textureTransform;
|
|
9062
|
+
ctx.fillStyle = this._texture ?? this.color;
|
|
9063
|
+
ctx.fill({ disableWrapMode });
|
|
9539
9064
|
}
|
|
9540
9065
|
}
|
|
9541
9066
|
__decorateClass$u([
|
|
@@ -9543,7 +9068,19 @@ __decorateClass$u([
|
|
|
9543
9068
|
], BaseElement2DFill.prototype, "color");
|
|
9544
9069
|
__decorateClass$u([
|
|
9545
9070
|
property()
|
|
9546
|
-
], BaseElement2DFill.prototype, "
|
|
9071
|
+
], BaseElement2DFill.prototype, "image");
|
|
9072
|
+
__decorateClass$u([
|
|
9073
|
+
property()
|
|
9074
|
+
], BaseElement2DFill.prototype, "linearGradient");
|
|
9075
|
+
__decorateClass$u([
|
|
9076
|
+
property()
|
|
9077
|
+
], BaseElement2DFill.prototype, "radialGradient");
|
|
9078
|
+
__decorateClass$u([
|
|
9079
|
+
property()
|
|
9080
|
+
], BaseElement2DFill.prototype, "cropRect");
|
|
9081
|
+
__decorateClass$u([
|
|
9082
|
+
property()
|
|
9083
|
+
], BaseElement2DFill.prototype, "stretchRect");
|
|
9547
9084
|
__decorateClass$u([
|
|
9548
9085
|
property()
|
|
9549
9086
|
], BaseElement2DFill.prototype, "dpi");
|
|
@@ -9553,9 +9090,6 @@ __decorateClass$u([
|
|
|
9553
9090
|
__decorateClass$u([
|
|
9554
9091
|
property()
|
|
9555
9092
|
], BaseElement2DFill.prototype, "tile");
|
|
9556
|
-
__decorateClass$u([
|
|
9557
|
-
property()
|
|
9558
|
-
], BaseElement2DFill.prototype, "stretch");
|
|
9559
9093
|
__decorateClass$u([
|
|
9560
9094
|
property()
|
|
9561
9095
|
], BaseElement2DFill.prototype, "opacity");
|
|
@@ -9571,30 +9105,12 @@ var __decorateClass$t = (decorators, target, key, kind) => {
|
|
|
9571
9105
|
};
|
|
9572
9106
|
class BaseElement2DBackground extends BaseElement2DFill {
|
|
9573
9107
|
setProperties(properties) {
|
|
9574
|
-
return super.
|
|
9108
|
+
return super._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeBackground(properties));
|
|
9575
9109
|
}
|
|
9576
9110
|
}
|
|
9577
9111
|
__decorateClass$t([
|
|
9578
9112
|
property()
|
|
9579
|
-
], BaseElement2DBackground.prototype, "
|
|
9580
|
-
__decorateClass$t([
|
|
9581
|
-
property()
|
|
9582
|
-
], BaseElement2DBackground.prototype, "src");
|
|
9583
|
-
__decorateClass$t([
|
|
9584
|
-
property()
|
|
9585
|
-
], BaseElement2DBackground.prototype, "dpi");
|
|
9586
|
-
__decorateClass$t([
|
|
9587
|
-
property()
|
|
9588
|
-
], BaseElement2DBackground.prototype, "rotateWithShape");
|
|
9589
|
-
__decorateClass$t([
|
|
9590
|
-
property()
|
|
9591
|
-
], BaseElement2DBackground.prototype, "tile");
|
|
9592
|
-
__decorateClass$t([
|
|
9593
|
-
property()
|
|
9594
|
-
], BaseElement2DBackground.prototype, "stretch");
|
|
9595
|
-
__decorateClass$t([
|
|
9596
|
-
property()
|
|
9597
|
-
], BaseElement2DBackground.prototype, "opacity");
|
|
9113
|
+
], BaseElement2DBackground.prototype, "fillWithShape");
|
|
9598
9114
|
|
|
9599
9115
|
var __defProp$l = Object.defineProperty;
|
|
9600
9116
|
var __decorateClass$s = (decorators, target, key, kind) => {
|
|
@@ -9607,30 +9123,12 @@ var __decorateClass$s = (decorators, target, key, kind) => {
|
|
|
9607
9123
|
};
|
|
9608
9124
|
class BaseElement2DForeground extends BaseElement2DFill {
|
|
9609
9125
|
setProperties(properties) {
|
|
9610
|
-
return super.
|
|
9126
|
+
return super._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeForeground(properties));
|
|
9611
9127
|
}
|
|
9612
9128
|
}
|
|
9613
9129
|
__decorateClass$s([
|
|
9614
9130
|
property()
|
|
9615
|
-
], BaseElement2DForeground.prototype, "
|
|
9616
|
-
__decorateClass$s([
|
|
9617
|
-
property()
|
|
9618
|
-
], BaseElement2DForeground.prototype, "src");
|
|
9619
|
-
__decorateClass$s([
|
|
9620
|
-
property()
|
|
9621
|
-
], BaseElement2DForeground.prototype, "dpi");
|
|
9622
|
-
__decorateClass$s([
|
|
9623
|
-
property()
|
|
9624
|
-
], BaseElement2DForeground.prototype, "rotateWithShape");
|
|
9625
|
-
__decorateClass$s([
|
|
9626
|
-
property()
|
|
9627
|
-
], BaseElement2DForeground.prototype, "tile");
|
|
9628
|
-
__decorateClass$s([
|
|
9629
|
-
property()
|
|
9630
|
-
], BaseElement2DForeground.prototype, "stretch");
|
|
9631
|
-
__decorateClass$s([
|
|
9632
|
-
property()
|
|
9633
|
-
], BaseElement2DForeground.prototype, "opacity");
|
|
9131
|
+
], BaseElement2DForeground.prototype, "fillWithShape");
|
|
9634
9132
|
|
|
9635
9133
|
var __defProp$k = Object.defineProperty;
|
|
9636
9134
|
var __decorateClass$r = (decorators, target, key, kind) => {
|
|
@@ -9641,84 +9139,42 @@ var __decorateClass$r = (decorators, target, key, kind) => {
|
|
|
9641
9139
|
if (result) __defProp$k(target, key, result);
|
|
9642
9140
|
return result;
|
|
9643
9141
|
};
|
|
9644
|
-
class
|
|
9645
|
-
constructor(parent) {
|
|
9646
|
-
super();
|
|
9647
|
-
this.parent = parent;
|
|
9648
|
-
this._updatePath2DSet();
|
|
9649
|
-
}
|
|
9650
|
-
_path2DSet = new modernPath2d.Path2DSet();
|
|
9142
|
+
class BaseElement2DOutline extends BaseElement2DFill {
|
|
9651
9143
|
setProperties(properties) {
|
|
9652
|
-
return super.
|
|
9144
|
+
return super._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeOutline(properties));
|
|
9653
9145
|
}
|
|
9654
9146
|
_updateProperty(key, value, oldValue, declaration) {
|
|
9655
9147
|
super._updateProperty(key, value, oldValue, declaration);
|
|
9656
9148
|
switch (key) {
|
|
9657
|
-
case "
|
|
9658
|
-
case "
|
|
9659
|
-
case "viewBox":
|
|
9660
|
-
this._updatePath2DSet();
|
|
9149
|
+
case "width":
|
|
9150
|
+
case "style":
|
|
9661
9151
|
this.parent.requestRedraw();
|
|
9662
9152
|
break;
|
|
9663
9153
|
}
|
|
9664
9154
|
}
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
this._path2DSet = modernPath2d.svgToPath2DSet(dom);
|
|
9670
|
-
viewBox = this._path2DSet.viewBox ?? this.viewBox;
|
|
9671
|
-
} else {
|
|
9672
|
-
viewBox = this.viewBox;
|
|
9673
|
-
this.data.forEach((path, i) => {
|
|
9674
|
-
const { data, ...style } = path;
|
|
9675
|
-
const path2D = new modernPath2d.Path2D();
|
|
9676
|
-
path2D.style = style;
|
|
9677
|
-
path2D.addData(data);
|
|
9678
|
-
this._path2DSet.paths[i] = path2D;
|
|
9679
|
-
});
|
|
9680
|
-
}
|
|
9681
|
-
const [x, y, w, h] = viewBox;
|
|
9682
|
-
this._path2DSet.paths.forEach((path) => {
|
|
9683
|
-
path.applyTransform(new modernPath2d.Matrix3().translate(-x, -y).scale(1 / w, 1 / h));
|
|
9684
|
-
});
|
|
9155
|
+
canDraw() {
|
|
9156
|
+
return Boolean(
|
|
9157
|
+
this.width || super.canDraw()
|
|
9158
|
+
);
|
|
9685
9159
|
}
|
|
9686
9160
|
draw() {
|
|
9687
|
-
if (this._path2DSet.paths.length) {
|
|
9688
|
-
const ctx = this.parent.context;
|
|
9689
|
-
const { width, height } = this.parent.size;
|
|
9690
|
-
this._path2DSet.paths.forEach((path) => {
|
|
9691
|
-
ctx.addPath(path.clone().applyTransform(new modernPath2d.Matrix3().scale(width, height)));
|
|
9692
|
-
});
|
|
9693
|
-
} else {
|
|
9694
|
-
this.drawRect();
|
|
9695
|
-
}
|
|
9696
|
-
}
|
|
9697
|
-
drawRect() {
|
|
9698
9161
|
const ctx = this.parent.context;
|
|
9699
|
-
const {
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
} else {
|
|
9705
|
-
ctx.rect(0, 0, width, height);
|
|
9706
|
-
}
|
|
9707
|
-
}
|
|
9162
|
+
const { textureTransform, disableWrapMode } = this._getDrawOptions();
|
|
9163
|
+
ctx.lineWidth = this.width;
|
|
9164
|
+
ctx.textureTransform = textureTransform;
|
|
9165
|
+
ctx.strokeStyle = this._texture ?? this.color;
|
|
9166
|
+
ctx.stroke({ disableWrapMode });
|
|
9708
9167
|
}
|
|
9709
9168
|
}
|
|
9710
9169
|
__decorateClass$r([
|
|
9711
|
-
property()
|
|
9712
|
-
],
|
|
9713
|
-
__decorateClass$r([
|
|
9714
|
-
property()
|
|
9715
|
-
], BaseElement2DGeometry.prototype, "svg");
|
|
9170
|
+
property({ default: 0 })
|
|
9171
|
+
], BaseElement2DOutline.prototype, "color");
|
|
9716
9172
|
__decorateClass$r([
|
|
9717
|
-
property({ default:
|
|
9718
|
-
],
|
|
9173
|
+
property({ default: 0 })
|
|
9174
|
+
], BaseElement2DOutline.prototype, "width");
|
|
9719
9175
|
__decorateClass$r([
|
|
9720
|
-
property({ default:
|
|
9721
|
-
],
|
|
9176
|
+
property({ default: "solid" })
|
|
9177
|
+
], BaseElement2DOutline.prototype, "style");
|
|
9722
9178
|
|
|
9723
9179
|
var __defProp$j = Object.defineProperty;
|
|
9724
9180
|
var __decorateClass$q = (decorators, target, key, kind) => {
|
|
@@ -9729,47 +9185,53 @@ var __decorateClass$q = (decorators, target, key, kind) => {
|
|
|
9729
9185
|
if (result) __defProp$j(target, key, result);
|
|
9730
9186
|
return result;
|
|
9731
9187
|
};
|
|
9732
|
-
class
|
|
9188
|
+
class BaseElement2DShadow extends CoreObject {
|
|
9733
9189
|
constructor(parent) {
|
|
9734
9190
|
super();
|
|
9735
9191
|
this.parent = parent;
|
|
9736
9192
|
}
|
|
9737
9193
|
setProperties(properties) {
|
|
9738
|
-
return super.setProperties(modernIdoc.
|
|
9194
|
+
return super.setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeShadow(properties));
|
|
9739
9195
|
}
|
|
9740
9196
|
_updateProperty(key, value, oldValue, declaration) {
|
|
9741
9197
|
super._updateProperty(key, value, oldValue, declaration);
|
|
9742
9198
|
switch (key) {
|
|
9743
9199
|
case "color":
|
|
9744
|
-
case "
|
|
9745
|
-
case "
|
|
9746
|
-
case "
|
|
9747
|
-
|
|
9748
|
-
this.parent.requestRedraw();
|
|
9200
|
+
case "blur":
|
|
9201
|
+
case "offsetX":
|
|
9202
|
+
case "offsetY":
|
|
9203
|
+
this.updateEffect();
|
|
9749
9204
|
break;
|
|
9750
9205
|
}
|
|
9751
9206
|
}
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
)
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9207
|
+
updateEffect() {
|
|
9208
|
+
const name = "__$shadow";
|
|
9209
|
+
let effect = this.parent.getNode(name);
|
|
9210
|
+
if (this.blur || this.offsetX || this.offsetY) {
|
|
9211
|
+
if (!effect) {
|
|
9212
|
+
effect = new exports.DropShadowEffect({ name });
|
|
9213
|
+
this.parent.appendChild(effect, "back");
|
|
9214
|
+
}
|
|
9215
|
+
effect.setProperties(this.getProperties());
|
|
9216
|
+
} else {
|
|
9217
|
+
if (effect) {
|
|
9218
|
+
this.parent.removeChild(effect);
|
|
9219
|
+
}
|
|
9220
|
+
}
|
|
9762
9221
|
}
|
|
9763
9222
|
}
|
|
9223
|
+
__decorateClass$q([
|
|
9224
|
+
property({ default: "#000000" })
|
|
9225
|
+
], BaseElement2DShadow.prototype, "color");
|
|
9764
9226
|
__decorateClass$q([
|
|
9765
9227
|
property({ default: 0 })
|
|
9766
|
-
],
|
|
9228
|
+
], BaseElement2DShadow.prototype, "blur");
|
|
9767
9229
|
__decorateClass$q([
|
|
9768
9230
|
property({ default: 0 })
|
|
9769
|
-
],
|
|
9231
|
+
], BaseElement2DShadow.prototype, "offsetY");
|
|
9770
9232
|
__decorateClass$q([
|
|
9771
|
-
property({ default:
|
|
9772
|
-
],
|
|
9233
|
+
property({ default: 0 })
|
|
9234
|
+
], BaseElement2DShadow.prototype, "offsetX");
|
|
9773
9235
|
|
|
9774
9236
|
var __defProp$i = Object.defineProperty;
|
|
9775
9237
|
var __decorateClass$p = (decorators, target, key, kind) => {
|
|
@@ -9780,53 +9242,84 @@ var __decorateClass$p = (decorators, target, key, kind) => {
|
|
|
9780
9242
|
if (result) __defProp$i(target, key, result);
|
|
9781
9243
|
return result;
|
|
9782
9244
|
};
|
|
9783
|
-
class
|
|
9245
|
+
class BaseElement2DShape extends CoreObject {
|
|
9784
9246
|
constructor(parent) {
|
|
9785
9247
|
super();
|
|
9786
9248
|
this.parent = parent;
|
|
9249
|
+
this._updatePath2DSet();
|
|
9787
9250
|
}
|
|
9251
|
+
_path2DSet = new modernPath2d.Path2DSet();
|
|
9788
9252
|
setProperties(properties) {
|
|
9789
|
-
return super.setProperties(modernIdoc.
|
|
9253
|
+
return super.setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeShape(properties));
|
|
9790
9254
|
}
|
|
9791
9255
|
_updateProperty(key, value, oldValue, declaration) {
|
|
9792
9256
|
super._updateProperty(key, value, oldValue, declaration);
|
|
9793
9257
|
switch (key) {
|
|
9794
|
-
case "
|
|
9795
|
-
case "
|
|
9796
|
-
case "
|
|
9797
|
-
|
|
9798
|
-
this.
|
|
9258
|
+
case "svg":
|
|
9259
|
+
case "data":
|
|
9260
|
+
case "viewBox":
|
|
9261
|
+
this._updatePath2DSet();
|
|
9262
|
+
this.parent.requestRedraw();
|
|
9799
9263
|
break;
|
|
9800
9264
|
}
|
|
9801
9265
|
}
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
this.parent.appendChild(effect, "back");
|
|
9809
|
-
}
|
|
9810
|
-
effect.setProperties(this.getProperties());
|
|
9266
|
+
_updatePath2DSet() {
|
|
9267
|
+
let viewBox;
|
|
9268
|
+
if (this.svg) {
|
|
9269
|
+
const dom = modernPath2d.svgToDOM(this.svg);
|
|
9270
|
+
this._path2DSet = modernPath2d.svgToPath2DSet(dom);
|
|
9271
|
+
viewBox = this._path2DSet.viewBox ?? this.viewBox;
|
|
9811
9272
|
} else {
|
|
9812
|
-
|
|
9813
|
-
|
|
9273
|
+
viewBox = this.viewBox;
|
|
9274
|
+
this.data?.forEach((path, i) => {
|
|
9275
|
+
const { data, ...style } = path;
|
|
9276
|
+
const path2D = new modernPath2d.Path2D();
|
|
9277
|
+
path2D.style = style;
|
|
9278
|
+
path2D.addData(data);
|
|
9279
|
+
this._path2DSet.paths[i] = path2D;
|
|
9280
|
+
});
|
|
9281
|
+
}
|
|
9282
|
+
const [x, y, w, h] = viewBox;
|
|
9283
|
+
this._path2DSet.paths.forEach((path) => {
|
|
9284
|
+
path.applyTransform(new modernPath2d.Matrix3().translate(-x, -y).scale(1 / w, 1 / h));
|
|
9285
|
+
});
|
|
9286
|
+
}
|
|
9287
|
+
draw() {
|
|
9288
|
+
if (this._path2DSet.paths.length) {
|
|
9289
|
+
const ctx = this.parent.context;
|
|
9290
|
+
const { width, height } = this.parent.size;
|
|
9291
|
+
this._path2DSet.paths.forEach((path) => {
|
|
9292
|
+
ctx.addPath(path.clone().applyTransform(new modernPath2d.Matrix3().scale(width, height)));
|
|
9293
|
+
});
|
|
9294
|
+
} else {
|
|
9295
|
+
this.drawRect();
|
|
9296
|
+
}
|
|
9297
|
+
}
|
|
9298
|
+
drawRect() {
|
|
9299
|
+
const ctx = this.parent.context;
|
|
9300
|
+
const { width, height } = this.parent.size;
|
|
9301
|
+
const { borderRadius } = this.parent.style;
|
|
9302
|
+
if (width && height) {
|
|
9303
|
+
if (borderRadius) {
|
|
9304
|
+
ctx.roundRect(0, 0, width, height, borderRadius);
|
|
9305
|
+
} else {
|
|
9306
|
+
ctx.rect(0, 0, width, height);
|
|
9814
9307
|
}
|
|
9815
9308
|
}
|
|
9816
9309
|
}
|
|
9817
9310
|
}
|
|
9818
9311
|
__decorateClass$p([
|
|
9819
|
-
property(
|
|
9820
|
-
],
|
|
9312
|
+
property()
|
|
9313
|
+
], BaseElement2DShape.prototype, "preset");
|
|
9821
9314
|
__decorateClass$p([
|
|
9822
|
-
property(
|
|
9823
|
-
],
|
|
9315
|
+
property()
|
|
9316
|
+
], BaseElement2DShape.prototype, "svg");
|
|
9824
9317
|
__decorateClass$p([
|
|
9825
|
-
property({ default: 0 })
|
|
9826
|
-
],
|
|
9318
|
+
property({ default: [0, 0, 1, 1] })
|
|
9319
|
+
], BaseElement2DShape.prototype, "viewBox");
|
|
9827
9320
|
__decorateClass$p([
|
|
9828
|
-
property({ default:
|
|
9829
|
-
],
|
|
9321
|
+
property({ default: [] })
|
|
9322
|
+
], BaseElement2DShape.prototype, "data");
|
|
9830
9323
|
|
|
9831
9324
|
class BaseElement2DStyle extends Resource {
|
|
9832
9325
|
constructor(properties) {
|
|
@@ -9866,7 +9359,7 @@ class BaseElement2DText extends CoreObject {
|
|
|
9866
9359
|
baseText = new modernText.Text();
|
|
9867
9360
|
measureResult;
|
|
9868
9361
|
setProperties(properties) {
|
|
9869
|
-
return super.setProperties(modernIdoc.normalizeText(properties));
|
|
9362
|
+
return super.setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeText(properties));
|
|
9870
9363
|
}
|
|
9871
9364
|
_updateProperty(key, value, oldValue, declaration) {
|
|
9872
9365
|
super._updateProperty(key, value, oldValue, declaration);
|
|
@@ -10053,12 +9546,12 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10053
9546
|
set background(value) {
|
|
10054
9547
|
this._background.setProperties(value);
|
|
10055
9548
|
}
|
|
10056
|
-
|
|
10057
|
-
get
|
|
10058
|
-
return this.
|
|
9549
|
+
_shape = new BaseElement2DShape(this);
|
|
9550
|
+
get shape() {
|
|
9551
|
+
return this._shape;
|
|
10059
9552
|
}
|
|
10060
|
-
set
|
|
10061
|
-
this.
|
|
9553
|
+
set shape(value) {
|
|
9554
|
+
this._shape.setProperties(value);
|
|
10062
9555
|
}
|
|
10063
9556
|
_fill = new BaseElement2DFill(this);
|
|
10064
9557
|
get fill() {
|
|
@@ -10106,7 +9599,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10106
9599
|
const {
|
|
10107
9600
|
style,
|
|
10108
9601
|
text,
|
|
10109
|
-
|
|
9602
|
+
shape,
|
|
10110
9603
|
background,
|
|
10111
9604
|
fill,
|
|
10112
9605
|
outline,
|
|
@@ -10116,7 +9609,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10116
9609
|
} = properties;
|
|
10117
9610
|
style && this.style.setProperties(style);
|
|
10118
9611
|
background && this.background.setProperties(background);
|
|
10119
|
-
|
|
9612
|
+
shape && this.shape.setProperties(shape);
|
|
10120
9613
|
fill && this.fill.setProperties(fill);
|
|
10121
9614
|
outline && this.outline.setProperties(outline);
|
|
10122
9615
|
text && this.text.setProperties(text);
|
|
@@ -10182,7 +9675,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10182
9675
|
this.background.color = this.style.backgroundColor;
|
|
10183
9676
|
break;
|
|
10184
9677
|
case "backgroundImage":
|
|
10185
|
-
this.background.
|
|
9678
|
+
this.background.image = this.style.backgroundImage;
|
|
10186
9679
|
break;
|
|
10187
9680
|
case "borderStyle":
|
|
10188
9681
|
case "outlineStyle":
|
|
@@ -10221,7 +9714,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10221
9714
|
const offsetX = originX * width;
|
|
10222
9715
|
const offsetY = originY * height;
|
|
10223
9716
|
this.transform.identity().translate(-offsetX, -offsetY).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
|
|
10224
|
-
parseCSSTransform(this.style.transform, width, height, this.transform);
|
|
9717
|
+
parseCSSTransform(this.style.transform ?? "", width, height, this.transform);
|
|
10225
9718
|
this.transform.translate(this.position.x, this.position.y).translate(offsetX, offsetY);
|
|
10226
9719
|
}
|
|
10227
9720
|
_updateGlobalTransform() {
|
|
@@ -10274,33 +9767,33 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10274
9767
|
}
|
|
10275
9768
|
_draw() {
|
|
10276
9769
|
super._draw();
|
|
10277
|
-
if (this.
|
|
10278
|
-
this.
|
|
9770
|
+
if (this._text.canDraw()) {
|
|
9771
|
+
this._text.updateMeasure();
|
|
10279
9772
|
}
|
|
10280
|
-
if (this.
|
|
9773
|
+
if (this._background.canDraw()) {
|
|
10281
9774
|
this._tree?.log(this.name, "draw background");
|
|
10282
|
-
this.
|
|
10283
|
-
this.
|
|
9775
|
+
this._shape.drawRect();
|
|
9776
|
+
this._background.draw();
|
|
10284
9777
|
}
|
|
10285
|
-
if (this.
|
|
9778
|
+
if (this._fill.canDraw()) {
|
|
10286
9779
|
this._tree?.log(this.name, "draw fill");
|
|
10287
|
-
this.
|
|
10288
|
-
this.
|
|
9780
|
+
this._shape.draw();
|
|
9781
|
+
this._fill.draw();
|
|
10289
9782
|
}
|
|
10290
|
-
if (this.
|
|
9783
|
+
if (this._outline.canDraw()) {
|
|
10291
9784
|
this._tree?.log(this.name, "draw outline");
|
|
10292
|
-
this.
|
|
10293
|
-
this.
|
|
9785
|
+
this._shape.draw();
|
|
9786
|
+
this._outline.draw();
|
|
10294
9787
|
}
|
|
10295
|
-
if (this.
|
|
9788
|
+
if (this._foreground.canDraw()) {
|
|
10296
9789
|
this._tree?.log(this.name, "draw foreground");
|
|
10297
|
-
this.
|
|
10298
|
-
this.
|
|
9790
|
+
this._shape.drawRect();
|
|
9791
|
+
this._foreground.draw();
|
|
10299
9792
|
}
|
|
10300
|
-
if (this.
|
|
9793
|
+
if (this._text.canDraw()) {
|
|
10301
9794
|
this._tree?.log(this.name, "draw text");
|
|
10302
|
-
this.
|
|
10303
|
-
this.
|
|
9795
|
+
this._shape.drawRect();
|
|
9796
|
+
this._text.draw();
|
|
10304
9797
|
}
|
|
10305
9798
|
this._drawContent();
|
|
10306
9799
|
}
|
|
@@ -10361,7 +9854,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
|
|
|
10361
9854
|
...json.props,
|
|
10362
9855
|
style: this.style.toJSON(),
|
|
10363
9856
|
background: this.background.toJSON(),
|
|
10364
|
-
|
|
9857
|
+
shape: this.shape.toJSON(),
|
|
10365
9858
|
fill: this.fill.toJSON(),
|
|
10366
9859
|
outline: this.outline.toJSON(),
|
|
10367
9860
|
text: this.text.toJSON(),
|
|
@@ -11015,7 +10508,7 @@ exports.Image2D = class Image2D extends exports.Element2D {
|
|
|
11015
10508
|
const tx = left * width * sx;
|
|
11016
10509
|
const ty = top * height * sy;
|
|
11017
10510
|
this.context.textureTransform = new Transform2D().scale(sx, sy).translate(tx, ty);
|
|
11018
|
-
this.
|
|
10511
|
+
this.shape.draw();
|
|
11019
10512
|
this.context.fill();
|
|
11020
10513
|
}
|
|
11021
10514
|
}
|
|
@@ -11058,7 +10551,7 @@ class TextureRect2D extends exports.Element2D {
|
|
|
11058
10551
|
1 / width,
|
|
11059
10552
|
1 / height
|
|
11060
10553
|
);
|
|
11061
|
-
this.
|
|
10554
|
+
this.shape.drawRect();
|
|
11062
10555
|
this.context.fill();
|
|
11063
10556
|
}
|
|
11064
10557
|
}
|
|
@@ -14597,9 +14090,9 @@ exports.AudioSpectrum = AudioSpectrum;
|
|
|
14597
14090
|
exports.BaseElement2DBackground = BaseElement2DBackground;
|
|
14598
14091
|
exports.BaseElement2DFill = BaseElement2DFill;
|
|
14599
14092
|
exports.BaseElement2DForeground = BaseElement2DForeground;
|
|
14600
|
-
exports.BaseElement2DGeometry = BaseElement2DGeometry;
|
|
14601
14093
|
exports.BaseElement2DOutline = BaseElement2DOutline;
|
|
14602
14094
|
exports.BaseElement2DShadow = BaseElement2DShadow;
|
|
14095
|
+
exports.BaseElement2DShape = BaseElement2DShape;
|
|
14603
14096
|
exports.BaseElement2DStyle = BaseElement2DStyle;
|
|
14604
14097
|
exports.BaseElement2DText = BaseElement2DText;
|
|
14605
14098
|
exports.CanvasContext = CanvasContext;
|
|
@@ -14630,7 +14123,6 @@ exports.IndexBuffer = IndexBuffer;
|
|
|
14630
14123
|
exports.Input = Input;
|
|
14631
14124
|
exports.InputEvent = InputEvent;
|
|
14632
14125
|
exports.JSONLoader = JSONLoader;
|
|
14633
|
-
exports.LinearGradient = LinearGradient;
|
|
14634
14126
|
exports.Loader = Loader;
|
|
14635
14127
|
exports.LottieLoader = LottieLoader;
|
|
14636
14128
|
exports.MainLoop = MainLoop;
|
|
@@ -14648,7 +14140,6 @@ exports.Projection2D = Projection2D;
|
|
|
14648
14140
|
exports.QuadGeometry = QuadGeometry;
|
|
14649
14141
|
exports.QuadUvGeometry = QuadUvGeometry;
|
|
14650
14142
|
exports.RAD_TO_DEG = RAD_TO_DEG;
|
|
14651
|
-
exports.RadialGradient = RadialGradient;
|
|
14652
14143
|
exports.RawWeakMap = RawWeakMap;
|
|
14653
14144
|
exports.Rect2 = Rect2;
|
|
14654
14145
|
exports.RefCounted = RefCounted;
|