modern-canvas 0.4.39 → 0.4.42

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 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 this.regExp.test(value);
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(value, width, height) {
5185
+ constructor(gradient, width, height) {
5662
5186
  super(
5663
- LinearGradient.from(value).parse(width, height)
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
- _colorToTexture(color, width, height) {
7637
- if (color instanceof Texture2D) {
7638
- return color;
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(color);
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
- const { width, height } = path.getBoundingBox();
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
- const { width, height } = path.getBoundingBox();
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,59 +8969,75 @@ class BaseElement2DFill extends CoreObject {
9449
8969
  super();
9450
8970
  this.parent = parent;
9451
8971
  }
9452
- _src;
8972
+ _texture;
8973
+ _setProperties(properties) {
8974
+ return super.setProperties(properties);
8975
+ }
9453
8976
  setProperties(properties) {
9454
- return super.setProperties(modernIdoc.normalizeFill(properties));
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 "src":
9466
- this._updateSource();
8991
+ case "image":
8992
+ case "linearGradient":
8993
+ case "radialGradient":
8994
+ this._updateTexture();
9467
8995
  break;
9468
8996
  }
9469
8997
  }
9470
- async loadSource() {
9471
- if (this.src && this.src !== "none") {
9472
- return await assets.texture.load(this.src);
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 _updateSource() {
9476
- this._src = await this.loadSource();
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._src || this.color
9017
+ this._texture || this.color
9482
9018
  );
9483
9019
  }
9484
- draw() {
9485
- const ctx = this.parent.context;
9486
- if (this._src) {
9487
- const { width: imageWidth, height: imageHeight } = this._src;
9020
+ _getDrawOptions() {
9021
+ let textureTransform;
9022
+ let disableWrapMode = false;
9023
+ if (this._texture && this._texture.source instanceof ImageBitmap) {
9024
+ textureTransform = new Transform2D();
9025
+ const { width: imageWidth, height: imageHeight } = this._texture;
9488
9026
  const { width, height } = this.parent.size;
9489
- const transform = new Transform2D();
9490
- let disableWrapMode = false;
9491
- if (this.srcRect) {
9027
+ if (this.cropRect) {
9492
9028
  const {
9493
9029
  left = 0,
9494
9030
  top = 0,
9495
9031
  right = 0,
9496
9032
  bottom = 0
9497
- } = this.srcRect;
9033
+ } = this.cropRect;
9498
9034
  const w = Math.abs(1 + (left + right)) * width;
9499
9035
  const h = Math.abs(1 + (top + bottom)) * height;
9500
9036
  const sx = 1 / w;
9501
9037
  const sy = 1 / h;
9502
9038
  const tx = left * width * sx;
9503
9039
  const ty = top * height * sy;
9504
- transform.scale(sx, sy).translate(tx, ty);
9040
+ textureTransform.scale(sx, sy).translate(tx, ty);
9505
9041
  }
9506
9042
  if (this.tile) {
9507
9043
  const {
@@ -9512,30 +9048,30 @@ class BaseElement2DFill extends CoreObject {
9512
9048
  // flip, TODO
9513
9049
  // alignment, TODO
9514
9050
  } = this.tile;
9515
- transform.scale(1 / imageWidth, 1 / imageHeight).scale(1 / scaleX, 1 / scaleY).translate(-translateX / imageWidth, -translateY / imageHeight);
9051
+ textureTransform.scale(1 / imageWidth, 1 / imageHeight).scale(1 / scaleX, 1 / scaleY).translate(-translateX / imageWidth, -translateY / imageHeight);
9516
9052
  disableWrapMode = true;
9517
- } else if (this.stretch) {
9518
- const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretch.rect ?? {};
9053
+ } else if (this.stretchRect) {
9054
+ const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
9519
9055
  const w = Math.abs(1 + (-left + -right)) * width;
9520
9056
  const h = Math.abs(1 + (-top + -bottom)) * height;
9521
9057
  const scaleX = 1 / w;
9522
9058
  const scaleY = 1 / h;
9523
9059
  const translateX = -left * width * scaleX;
9524
9060
  const translateY = -top * height * scaleY;
9525
- transform.scale(scaleX, scaleY).translate(translateX, translateY);
9061
+ textureTransform.scale(scaleX, scaleY).translate(translateX, translateY);
9526
9062
  disableWrapMode = true;
9527
9063
  } else {
9528
- transform.scale(1 / width, 1 / height);
9064
+ textureTransform.scale(1 / width, 1 / height);
9529
9065
  }
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
9066
  }
9067
+ return { disableWrapMode, textureTransform };
9068
+ }
9069
+ draw() {
9070
+ const ctx = this.parent.context;
9071
+ const { textureTransform, disableWrapMode } = this._getDrawOptions();
9072
+ ctx.textureTransform = textureTransform;
9073
+ ctx.fillStyle = this._texture ?? this.color;
9074
+ ctx.fill({ disableWrapMode });
9539
9075
  }
9540
9076
  }
9541
9077
  __decorateClass$u([
@@ -9543,7 +9079,19 @@ __decorateClass$u([
9543
9079
  ], BaseElement2DFill.prototype, "color");
9544
9080
  __decorateClass$u([
9545
9081
  property()
9546
- ], BaseElement2DFill.prototype, "src");
9082
+ ], BaseElement2DFill.prototype, "image");
9083
+ __decorateClass$u([
9084
+ property()
9085
+ ], BaseElement2DFill.prototype, "linearGradient");
9086
+ __decorateClass$u([
9087
+ property()
9088
+ ], BaseElement2DFill.prototype, "radialGradient");
9089
+ __decorateClass$u([
9090
+ property()
9091
+ ], BaseElement2DFill.prototype, "cropRect");
9092
+ __decorateClass$u([
9093
+ property()
9094
+ ], BaseElement2DFill.prototype, "stretchRect");
9547
9095
  __decorateClass$u([
9548
9096
  property()
9549
9097
  ], BaseElement2DFill.prototype, "dpi");
@@ -9553,9 +9101,6 @@ __decorateClass$u([
9553
9101
  __decorateClass$u([
9554
9102
  property()
9555
9103
  ], BaseElement2DFill.prototype, "tile");
9556
- __decorateClass$u([
9557
- property()
9558
- ], BaseElement2DFill.prototype, "stretch");
9559
9104
  __decorateClass$u([
9560
9105
  property()
9561
9106
  ], BaseElement2DFill.prototype, "opacity");
@@ -9571,30 +9116,12 @@ var __decorateClass$t = (decorators, target, key, kind) => {
9571
9116
  };
9572
9117
  class BaseElement2DBackground extends BaseElement2DFill {
9573
9118
  setProperties(properties) {
9574
- return super.setProperties(modernIdoc.normalizeBackground(properties));
9119
+ return super._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeBackground(properties));
9575
9120
  }
9576
9121
  }
9577
9122
  __decorateClass$t([
9578
9123
  property()
9579
- ], BaseElement2DBackground.prototype, "color");
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");
9124
+ ], BaseElement2DBackground.prototype, "fillWithShape");
9598
9125
 
9599
9126
  var __defProp$l = Object.defineProperty;
9600
9127
  var __decorateClass$s = (decorators, target, key, kind) => {
@@ -9607,30 +9134,12 @@ var __decorateClass$s = (decorators, target, key, kind) => {
9607
9134
  };
9608
9135
  class BaseElement2DForeground extends BaseElement2DFill {
9609
9136
  setProperties(properties) {
9610
- return super.setProperties(modernIdoc.normalizeForeground(properties));
9137
+ return super._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeForeground(properties));
9611
9138
  }
9612
9139
  }
9613
9140
  __decorateClass$s([
9614
9141
  property()
9615
- ], BaseElement2DForeground.prototype, "color");
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");
9142
+ ], BaseElement2DForeground.prototype, "fillWithShape");
9634
9143
 
9635
9144
  var __defProp$k = Object.defineProperty;
9636
9145
  var __decorateClass$r = (decorators, target, key, kind) => {
@@ -9641,84 +9150,42 @@ var __decorateClass$r = (decorators, target, key, kind) => {
9641
9150
  if (result) __defProp$k(target, key, result);
9642
9151
  return result;
9643
9152
  };
9644
- class BaseElement2DGeometry extends CoreObject {
9645
- constructor(parent) {
9646
- super();
9647
- this.parent = parent;
9648
- this._updatePath2DSet();
9649
- }
9650
- _path2DSet = new modernPath2d.Path2DSet();
9153
+ class BaseElement2DOutline extends BaseElement2DFill {
9651
9154
  setProperties(properties) {
9652
- return super.setProperties(modernIdoc.normalizeGeometry(properties));
9155
+ return super._setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeOutline(properties));
9653
9156
  }
9654
9157
  _updateProperty(key, value, oldValue, declaration) {
9655
9158
  super._updateProperty(key, value, oldValue, declaration);
9656
9159
  switch (key) {
9657
- case "svg":
9658
- case "data":
9659
- case "viewBox":
9660
- this._updatePath2DSet();
9160
+ case "width":
9161
+ case "style":
9661
9162
  this.parent.requestRedraw();
9662
9163
  break;
9663
9164
  }
9664
9165
  }
9665
- _updatePath2DSet() {
9666
- let viewBox;
9667
- if (this.svg) {
9668
- const dom = modernPath2d.svgToDOM(this.svg);
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
- });
9166
+ canDraw() {
9167
+ return Boolean(
9168
+ this.width || super.canDraw()
9169
+ );
9685
9170
  }
9686
9171
  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
9172
  const ctx = this.parent.context;
9699
- const { width, height } = this.parent.size;
9700
- const { borderRadius } = this.parent.style;
9701
- if (width && height) {
9702
- if (borderRadius) {
9703
- ctx.roundRect(0, 0, width, height, borderRadius);
9704
- } else {
9705
- ctx.rect(0, 0, width, height);
9706
- }
9707
- }
9173
+ const { textureTransform, disableWrapMode } = this._getDrawOptions();
9174
+ ctx.lineWidth = this.width;
9175
+ ctx.textureTransform = textureTransform;
9176
+ ctx.strokeStyle = this._texture ?? this.color;
9177
+ ctx.stroke({ disableWrapMode });
9708
9178
  }
9709
9179
  }
9710
9180
  __decorateClass$r([
9711
- property()
9712
- ], BaseElement2DGeometry.prototype, "name");
9713
- __decorateClass$r([
9714
- property()
9715
- ], BaseElement2DGeometry.prototype, "svg");
9181
+ property({ default: 0 })
9182
+ ], BaseElement2DOutline.prototype, "color");
9716
9183
  __decorateClass$r([
9717
- property({ default: [0, 0, 1, 1] })
9718
- ], BaseElement2DGeometry.prototype, "viewBox");
9184
+ property({ default: 0 })
9185
+ ], BaseElement2DOutline.prototype, "width");
9719
9186
  __decorateClass$r([
9720
- property({ default: [] })
9721
- ], BaseElement2DGeometry.prototype, "data");
9187
+ property({ default: "solid" })
9188
+ ], BaseElement2DOutline.prototype, "style");
9722
9189
 
9723
9190
  var __defProp$j = Object.defineProperty;
9724
9191
  var __decorateClass$q = (decorators, target, key, kind) => {
@@ -9729,47 +9196,53 @@ var __decorateClass$q = (decorators, target, key, kind) => {
9729
9196
  if (result) __defProp$j(target, key, result);
9730
9197
  return result;
9731
9198
  };
9732
- class BaseElement2DOutline extends CoreObject {
9199
+ class BaseElement2DShadow extends CoreObject {
9733
9200
  constructor(parent) {
9734
9201
  super();
9735
9202
  this.parent = parent;
9736
9203
  }
9737
9204
  setProperties(properties) {
9738
- return super.setProperties(modernIdoc.normalizeOutline(properties));
9205
+ return super.setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeShadow(properties));
9739
9206
  }
9740
9207
  _updateProperty(key, value, oldValue, declaration) {
9741
9208
  super._updateProperty(key, value, oldValue, declaration);
9742
9209
  switch (key) {
9743
9210
  case "color":
9744
- case "width":
9745
- case "style":
9746
- case "src":
9747
- case "opacity":
9748
- this.parent.requestRedraw();
9211
+ case "blur":
9212
+ case "offsetX":
9213
+ case "offsetY":
9214
+ this.updateEffect();
9749
9215
  break;
9750
9216
  }
9751
9217
  }
9752
- canDraw() {
9753
- return Boolean(
9754
- this.width || this.color
9755
- );
9756
- }
9757
- draw() {
9758
- const ctx = this.parent.context;
9759
- ctx.lineWidth = this.width;
9760
- ctx.strokeStyle = this.color;
9761
- ctx.stroke();
9218
+ updateEffect() {
9219
+ const name = "__$shadow";
9220
+ let effect = this.parent.getNode(name);
9221
+ if (this.blur || this.offsetX || this.offsetY) {
9222
+ if (!effect) {
9223
+ effect = new exports.DropShadowEffect({ name });
9224
+ this.parent.appendChild(effect, "back");
9225
+ }
9226
+ effect.setProperties(this.getProperties());
9227
+ } else {
9228
+ if (effect) {
9229
+ this.parent.removeChild(effect);
9230
+ }
9231
+ }
9762
9232
  }
9763
9233
  }
9234
+ __decorateClass$q([
9235
+ property({ default: "#000000" })
9236
+ ], BaseElement2DShadow.prototype, "color");
9764
9237
  __decorateClass$q([
9765
9238
  property({ default: 0 })
9766
- ], BaseElement2DOutline.prototype, "color");
9239
+ ], BaseElement2DShadow.prototype, "blur");
9767
9240
  __decorateClass$q([
9768
9241
  property({ default: 0 })
9769
- ], BaseElement2DOutline.prototype, "width");
9242
+ ], BaseElement2DShadow.prototype, "offsetY");
9770
9243
  __decorateClass$q([
9771
- property({ default: "solid" })
9772
- ], BaseElement2DOutline.prototype, "style");
9244
+ property({ default: 0 })
9245
+ ], BaseElement2DShadow.prototype, "offsetX");
9773
9246
 
9774
9247
  var __defProp$i = Object.defineProperty;
9775
9248
  var __decorateClass$p = (decorators, target, key, kind) => {
@@ -9780,53 +9253,84 @@ var __decorateClass$p = (decorators, target, key, kind) => {
9780
9253
  if (result) __defProp$i(target, key, result);
9781
9254
  return result;
9782
9255
  };
9783
- class BaseElement2DShadow extends CoreObject {
9256
+ class BaseElement2DShape extends CoreObject {
9784
9257
  constructor(parent) {
9785
9258
  super();
9786
9259
  this.parent = parent;
9260
+ this._updatePath2DSet();
9787
9261
  }
9262
+ _path2DSet = new modernPath2d.Path2DSet();
9788
9263
  setProperties(properties) {
9789
- return super.setProperties(modernIdoc.normalizeShadow(properties));
9264
+ return super.setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeShape(properties));
9790
9265
  }
9791
9266
  _updateProperty(key, value, oldValue, declaration) {
9792
9267
  super._updateProperty(key, value, oldValue, declaration);
9793
9268
  switch (key) {
9794
- case "color":
9795
- case "blur":
9796
- case "offsetX":
9797
- case "offsetY":
9798
- this.updateEffect();
9269
+ case "svg":
9270
+ case "data":
9271
+ case "viewBox":
9272
+ this._updatePath2DSet();
9273
+ this.parent.requestRedraw();
9799
9274
  break;
9800
9275
  }
9801
9276
  }
9802
- updateEffect() {
9803
- const name = "__$shadow";
9804
- let effect = this.parent.getNode(name);
9805
- if (this.blur || this.offsetX || this.offsetY) {
9806
- if (!effect) {
9807
- effect = new exports.DropShadowEffect({ name });
9808
- this.parent.appendChild(effect, "back");
9809
- }
9810
- effect.setProperties(this.getProperties());
9277
+ _updatePath2DSet() {
9278
+ let viewBox;
9279
+ if (this.svg) {
9280
+ const dom = modernPath2d.svgToDOM(this.svg);
9281
+ this._path2DSet = modernPath2d.svgToPath2DSet(dom);
9282
+ viewBox = this._path2DSet.viewBox ?? this.viewBox;
9811
9283
  } else {
9812
- if (effect) {
9813
- this.parent.removeChild(effect);
9284
+ viewBox = this.viewBox;
9285
+ this.data?.forEach((path, i) => {
9286
+ const { data, ...style } = path;
9287
+ const path2D = new modernPath2d.Path2D();
9288
+ path2D.style = style;
9289
+ path2D.addData(data);
9290
+ this._path2DSet.paths[i] = path2D;
9291
+ });
9292
+ }
9293
+ const [x, y, w, h] = viewBox;
9294
+ this._path2DSet.paths.forEach((path) => {
9295
+ path.applyTransform(new modernPath2d.Matrix3().translate(-x, -y).scale(1 / w, 1 / h));
9296
+ });
9297
+ }
9298
+ draw() {
9299
+ if (this._path2DSet.paths.length) {
9300
+ const ctx = this.parent.context;
9301
+ const { width, height } = this.parent.size;
9302
+ this._path2DSet.paths.forEach((path) => {
9303
+ ctx.addPath(path.clone().applyTransform(new modernPath2d.Matrix3().scale(width, height)));
9304
+ });
9305
+ } else {
9306
+ this.drawRect();
9307
+ }
9308
+ }
9309
+ drawRect() {
9310
+ const ctx = this.parent.context;
9311
+ const { width, height } = this.parent.size;
9312
+ const { borderRadius } = this.parent.style;
9313
+ if (width && height) {
9314
+ if (borderRadius) {
9315
+ ctx.roundRect(0, 0, width, height, borderRadius);
9316
+ } else {
9317
+ ctx.rect(0, 0, width, height);
9814
9318
  }
9815
9319
  }
9816
9320
  }
9817
9321
  }
9818
9322
  __decorateClass$p([
9819
- property({ default: "#000000" })
9820
- ], BaseElement2DShadow.prototype, "color");
9323
+ property()
9324
+ ], BaseElement2DShape.prototype, "preset");
9821
9325
  __decorateClass$p([
9822
- property({ default: 0 })
9823
- ], BaseElement2DShadow.prototype, "blur");
9326
+ property()
9327
+ ], BaseElement2DShape.prototype, "svg");
9824
9328
  __decorateClass$p([
9825
- property({ default: 0 })
9826
- ], BaseElement2DShadow.prototype, "offsetY");
9329
+ property({ default: [0, 0, 1, 1] })
9330
+ ], BaseElement2DShape.prototype, "viewBox");
9827
9331
  __decorateClass$p([
9828
- property({ default: 0 })
9829
- ], BaseElement2DShadow.prototype, "offsetX");
9332
+ property({ default: [] })
9333
+ ], BaseElement2DShape.prototype, "data");
9830
9334
 
9831
9335
  class BaseElement2DStyle extends Resource {
9832
9336
  constructor(properties) {
@@ -9866,7 +9370,7 @@ class BaseElement2DText extends CoreObject {
9866
9370
  baseText = new modernText.Text();
9867
9371
  measureResult;
9868
9372
  setProperties(properties) {
9869
- return super.setProperties(modernIdoc.normalizeText(properties));
9373
+ return super.setProperties(modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeText(properties));
9870
9374
  }
9871
9375
  _updateProperty(key, value, oldValue, declaration) {
9872
9376
  super._updateProperty(key, value, oldValue, declaration);
@@ -10053,12 +9557,12 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10053
9557
  set background(value) {
10054
9558
  this._background.setProperties(value);
10055
9559
  }
10056
- _geometry = new BaseElement2DGeometry(this);
10057
- get geometry() {
10058
- return this._geometry;
9560
+ _shape = new BaseElement2DShape(this);
9561
+ get shape() {
9562
+ return this._shape;
10059
9563
  }
10060
- set geometry(value) {
10061
- this._geometry.setProperties(value);
9564
+ set shape(value) {
9565
+ this._shape.setProperties(value);
10062
9566
  }
10063
9567
  _fill = new BaseElement2DFill(this);
10064
9568
  get fill() {
@@ -10106,7 +9610,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10106
9610
  const {
10107
9611
  style,
10108
9612
  text,
10109
- geometry,
9613
+ shape,
10110
9614
  background,
10111
9615
  fill,
10112
9616
  outline,
@@ -10116,7 +9620,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10116
9620
  } = properties;
10117
9621
  style && this.style.setProperties(style);
10118
9622
  background && this.background.setProperties(background);
10119
- geometry && this.geometry.setProperties(geometry);
9623
+ shape && this.shape.setProperties(shape);
10120
9624
  fill && this.fill.setProperties(fill);
10121
9625
  outline && this.outline.setProperties(outline);
10122
9626
  text && this.text.setProperties(text);
@@ -10182,7 +9686,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10182
9686
  this.background.color = this.style.backgroundColor;
10183
9687
  break;
10184
9688
  case "backgroundImage":
10185
- this.background.src = this.style.backgroundImage;
9689
+ this.background.image = this.style.backgroundImage;
10186
9690
  break;
10187
9691
  case "borderStyle":
10188
9692
  case "outlineStyle":
@@ -10221,7 +9725,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10221
9725
  const offsetX = originX * width;
10222
9726
  const offsetY = originY * height;
10223
9727
  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);
9728
+ parseCSSTransform(this.style.transform ?? "", width, height, this.transform);
10225
9729
  this.transform.translate(this.position.x, this.position.y).translate(offsetX, offsetY);
10226
9730
  }
10227
9731
  _updateGlobalTransform() {
@@ -10274,33 +9778,33 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10274
9778
  }
10275
9779
  _draw() {
10276
9780
  super._draw();
10277
- if (this.text.canDraw()) {
10278
- this.text.updateMeasure();
9781
+ if (this._text.canDraw()) {
9782
+ this._text.updateMeasure();
10279
9783
  }
10280
- if (this.background.canDraw()) {
9784
+ if (this._background.canDraw()) {
10281
9785
  this._tree?.log(this.name, "draw background");
10282
- this.geometry.drawRect();
10283
- this.background.draw();
9786
+ this._shape.drawRect();
9787
+ this._background.draw();
10284
9788
  }
10285
- if (this.fill.canDraw()) {
9789
+ if (this._fill.canDraw()) {
10286
9790
  this._tree?.log(this.name, "draw fill");
10287
- this.geometry.draw();
10288
- this.fill.draw();
9791
+ this._shape.draw();
9792
+ this._fill.draw();
10289
9793
  }
10290
- if (this.outline.canDraw()) {
9794
+ if (this._outline.canDraw()) {
10291
9795
  this._tree?.log(this.name, "draw outline");
10292
- this.geometry.draw();
10293
- this.outline.draw();
9796
+ this._shape.draw();
9797
+ this._outline.draw();
10294
9798
  }
10295
- if (this.foreground.canDraw()) {
9799
+ if (this._foreground.canDraw()) {
10296
9800
  this._tree?.log(this.name, "draw foreground");
10297
- this.geometry.drawRect();
10298
- this.foreground.draw();
9801
+ this._shape.drawRect();
9802
+ this._foreground.draw();
10299
9803
  }
10300
- if (this.text.canDraw()) {
9804
+ if (this._text.canDraw()) {
10301
9805
  this._tree?.log(this.name, "draw text");
10302
- this.geometry.drawRect();
10303
- this.text.draw();
9806
+ this._shape.drawRect();
9807
+ this._text.draw();
10304
9808
  }
10305
9809
  this._drawContent();
10306
9810
  }
@@ -10361,7 +9865,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10361
9865
  ...json.props,
10362
9866
  style: this.style.toJSON(),
10363
9867
  background: this.background.toJSON(),
10364
- geometry: this.geometry.toJSON(),
9868
+ shape: this.shape.toJSON(),
10365
9869
  fill: this.fill.toJSON(),
10366
9870
  outline: this.outline.toJSON(),
10367
9871
  text: this.text.toJSON(),
@@ -11015,7 +10519,7 @@ exports.Image2D = class Image2D extends exports.Element2D {
11015
10519
  const tx = left * width * sx;
11016
10520
  const ty = top * height * sy;
11017
10521
  this.context.textureTransform = new Transform2D().scale(sx, sy).translate(tx, ty);
11018
- this.geometry.draw();
10522
+ this.shape.draw();
11019
10523
  this.context.fill();
11020
10524
  }
11021
10525
  }
@@ -11058,7 +10562,7 @@ class TextureRect2D extends exports.Element2D {
11058
10562
  1 / width,
11059
10563
  1 / height
11060
10564
  );
11061
- this.geometry.drawRect();
10565
+ this.shape.drawRect();
11062
10566
  this.context.fill();
11063
10567
  }
11064
10568
  }
@@ -11133,9 +10637,6 @@ var __decorateClass$g = (decorators, target, key, kind) => {
11133
10637
  };
11134
10638
  const textStyles = new Set(Object.keys(modernText.textDefaultStyle));
11135
10639
  exports.Text2D = class Text2D extends TextureRect2D {
11136
- effects;
11137
- measureDom;
11138
- fonts;
11139
10640
  texture = new CanvasTexture();
11140
10641
  base = new modernText.Text();
11141
10642
  measureResult;
@@ -14600,9 +14101,9 @@ exports.AudioSpectrum = AudioSpectrum;
14600
14101
  exports.BaseElement2DBackground = BaseElement2DBackground;
14601
14102
  exports.BaseElement2DFill = BaseElement2DFill;
14602
14103
  exports.BaseElement2DForeground = BaseElement2DForeground;
14603
- exports.BaseElement2DGeometry = BaseElement2DGeometry;
14604
14104
  exports.BaseElement2DOutline = BaseElement2DOutline;
14605
14105
  exports.BaseElement2DShadow = BaseElement2DShadow;
14106
+ exports.BaseElement2DShape = BaseElement2DShape;
14606
14107
  exports.BaseElement2DStyle = BaseElement2DStyle;
14607
14108
  exports.BaseElement2DText = BaseElement2DText;
14608
14109
  exports.CanvasContext = CanvasContext;
@@ -14633,7 +14134,6 @@ exports.IndexBuffer = IndexBuffer;
14633
14134
  exports.Input = Input;
14634
14135
  exports.InputEvent = InputEvent;
14635
14136
  exports.JSONLoader = JSONLoader;
14636
- exports.LinearGradient = LinearGradient;
14637
14137
  exports.Loader = Loader;
14638
14138
  exports.LottieLoader = LottieLoader;
14639
14139
  exports.MainLoop = MainLoop;
@@ -14651,7 +14151,6 @@ exports.Projection2D = Projection2D;
14651
14151
  exports.QuadGeometry = QuadGeometry;
14652
14152
  exports.QuadUvGeometry = QuadUvGeometry;
14653
14153
  exports.RAD_TO_DEG = RAD_TO_DEG;
14654
- exports.RadialGradient = RadialGradient;
14655
14154
  exports.RawWeakMap = RawWeakMap;
14656
14155
  exports.Rect2 = Rect2;
14657
14156
  exports.RefCounted = RefCounted;