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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { extend } from 'colord';
2
2
  import namesPlugin from 'colord/plugins/names';
3
- import { parseColor, normalizeFill, normalizeBackground, normalizeForeground, normalizeGeometry, normalizeOutline, normalizeShadow, getDefaultStyle, normalizeText } from 'modern-idoc';
3
+ import { parseColor, isGradient, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
4
4
  import { Path2D, Path2DSet, svgToDOM, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
5
5
  import { Text, textDefaultStyle } from 'modern-text';
6
6
  import { loadYoga, BoxSizing, PositionType, Edge, Overflow, Gutter, Justify, Wrap, FlexDirection, Display, Direction, Align } from 'yoga-layout/load';
@@ -1737,468 +1737,6 @@ class ColorMatrix extends Matrix {
1737
1737
  }
1738
1738
  }
1739
1739
 
1740
- var GradientParser = GradientParser || {};
1741
- GradientParser.parse = /* @__PURE__ */ function() {
1742
- const tokens = {
1743
- linearGradient: /^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,
1744
- repeatingLinearGradient: /^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,
1745
- radialGradient: /^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,
1746
- repeatingRadialGradient: /^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,
1747
- sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
1748
- extentKeywords: /^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,
1749
- positionKeywords: /^(left|center|right|top|bottom)/i,
1750
- pixelValue: /^(-?((\d*\.\d+)|(\d+\.?)))px/,
1751
- percentageValue: /^(-?((\d*\.\d+)|(\d+\.?)))%/,
1752
- emValue: /^(-?((\d*\.\d+)|(\d+\.?)))em/,
1753
- angleValue: /^(-?((\d*\.\d+)|(\d+\.?)))deg/,
1754
- radianValue: /^(-?((\d*\.\d+)|(\d+\.?)))rad/,
1755
- startCall: /^\(/,
1756
- endCall: /^\)/,
1757
- comma: /^,/,
1758
- hexColor: /^#([0-9a-f]+)/i,
1759
- literalColor: /^([a-z]+)/i,
1760
- rgbColor: /^rgb/i,
1761
- rgbaColor: /^rgba/i,
1762
- varColor: /^var/i,
1763
- calcValue: /^calc/i,
1764
- variableName: /^(--[a-z0-9-,\s#]+)/i,
1765
- number: /^((\d*\.\d+)|(\d+\.?))/,
1766
- hslColor: /^hsl/i,
1767
- hslaColor: /^hsla/i
1768
- };
1769
- let input = "";
1770
- function error(msg) {
1771
- const err = new Error(`${input}: ${msg}`);
1772
- err.source = input;
1773
- throw err;
1774
- }
1775
- function getAST() {
1776
- const ast = matchListDefinitions();
1777
- if (input.length > 0) {
1778
- error("Invalid input not EOF");
1779
- }
1780
- return ast;
1781
- }
1782
- function matchListDefinitions() {
1783
- return matchListing(matchDefinition);
1784
- }
1785
- function matchDefinition() {
1786
- return matchGradient(
1787
- "linear-gradient",
1788
- tokens.linearGradient,
1789
- matchLinearOrientation
1790
- ) || matchGradient(
1791
- "repeating-linear-gradient",
1792
- tokens.repeatingLinearGradient,
1793
- matchLinearOrientation
1794
- ) || matchGradient(
1795
- "radial-gradient",
1796
- tokens.radialGradient,
1797
- matchListRadialOrientations
1798
- ) || matchGradient(
1799
- "repeating-radial-gradient",
1800
- tokens.repeatingRadialGradient,
1801
- matchListRadialOrientations
1802
- );
1803
- }
1804
- function matchGradient(gradientType, pattern, orientationMatcher) {
1805
- return matchCall(pattern, (captures) => {
1806
- const orientation = orientationMatcher();
1807
- if (orientation) {
1808
- if (!scan(tokens.comma)) {
1809
- error("Missing comma before color stops");
1810
- }
1811
- }
1812
- return {
1813
- type: gradientType,
1814
- orientation,
1815
- colorStops: matchListing(matchColorStop)
1816
- };
1817
- });
1818
- }
1819
- function matchCall(pattern, callback) {
1820
- const captures = scan(pattern);
1821
- if (captures) {
1822
- if (!scan(tokens.startCall)) {
1823
- error("Missing (");
1824
- }
1825
- const result = callback(captures);
1826
- if (!scan(tokens.endCall)) {
1827
- error("Missing )");
1828
- }
1829
- return result;
1830
- }
1831
- }
1832
- function matchLinearOrientation() {
1833
- const sideOrCorner = matchSideOrCorner();
1834
- if (sideOrCorner) {
1835
- return sideOrCorner;
1836
- }
1837
- const legacyDirection = match("position-keyword", tokens.positionKeywords, 1);
1838
- if (legacyDirection) {
1839
- return {
1840
- type: "directional",
1841
- value: legacyDirection.value
1842
- };
1843
- }
1844
- return matchAngle();
1845
- }
1846
- function matchSideOrCorner() {
1847
- return match("directional", tokens.sideOrCorner, 1);
1848
- }
1849
- function matchAngle() {
1850
- return match("angular", tokens.angleValue, 1) || match("angular", tokens.radianValue, 1);
1851
- }
1852
- function matchListRadialOrientations() {
1853
- let radialOrientations;
1854
- let radialOrientation = matchRadialOrientation();
1855
- let lookaheadCache;
1856
- if (radialOrientation) {
1857
- radialOrientations = [];
1858
- radialOrientations.push(radialOrientation);
1859
- lookaheadCache = input;
1860
- if (scan(tokens.comma)) {
1861
- radialOrientation = matchRadialOrientation();
1862
- if (radialOrientation) {
1863
- radialOrientations.push(radialOrientation);
1864
- } else {
1865
- input = lookaheadCache;
1866
- }
1867
- }
1868
- }
1869
- return radialOrientations;
1870
- }
1871
- function matchRadialOrientation() {
1872
- let radialType = matchCircle() || matchEllipse();
1873
- if (radialType) {
1874
- radialType.at = matchAtPosition();
1875
- } else {
1876
- const extent = matchExtentKeyword();
1877
- if (extent) {
1878
- radialType = extent;
1879
- const positionAt = matchAtPosition();
1880
- if (positionAt) {
1881
- radialType.at = positionAt;
1882
- }
1883
- } else {
1884
- const atPosition = matchAtPosition();
1885
- if (atPosition) {
1886
- radialType = {
1887
- type: "default-radial",
1888
- at: atPosition
1889
- };
1890
- } else {
1891
- const defaultPosition = matchPositioning();
1892
- if (defaultPosition) {
1893
- radialType = {
1894
- type: "default-radial",
1895
- at: defaultPosition
1896
- };
1897
- }
1898
- }
1899
- }
1900
- }
1901
- return radialType;
1902
- }
1903
- function matchCircle() {
1904
- const circle = match("shape", /^(circle)/i, 0);
1905
- if (circle) {
1906
- circle.style = matchLength() || matchExtentKeyword();
1907
- }
1908
- return circle;
1909
- }
1910
- function matchEllipse() {
1911
- const ellipse = match("shape", /^(ellipse)/i, 0);
1912
- if (ellipse) {
1913
- ellipse.style = matchPositioning() || matchDistance() || matchExtentKeyword();
1914
- }
1915
- return ellipse;
1916
- }
1917
- function matchExtentKeyword() {
1918
- return match("extent-keyword", tokens.extentKeywords, 1);
1919
- }
1920
- function matchAtPosition() {
1921
- if (match("position", /^at/, 0)) {
1922
- const positioning = matchPositioning();
1923
- if (!positioning) {
1924
- error("Missing positioning value");
1925
- }
1926
- return positioning;
1927
- }
1928
- }
1929
- function matchPositioning() {
1930
- const location = matchCoordinates();
1931
- if (location.x || location.y) {
1932
- return {
1933
- type: "position",
1934
- value: location
1935
- };
1936
- }
1937
- }
1938
- function matchCoordinates() {
1939
- return {
1940
- x: matchDistance(),
1941
- y: matchDistance()
1942
- };
1943
- }
1944
- function matchListing(matcher) {
1945
- let captures = matcher();
1946
- const result = [];
1947
- if (captures) {
1948
- result.push(captures);
1949
- while (scan(tokens.comma)) {
1950
- captures = matcher();
1951
- if (captures) {
1952
- result.push(captures);
1953
- } else {
1954
- error("One extra comma");
1955
- }
1956
- }
1957
- }
1958
- return result;
1959
- }
1960
- function matchColorStop() {
1961
- const color = matchColor();
1962
- if (!color) {
1963
- error("Expected color definition");
1964
- }
1965
- color.length = matchDistance();
1966
- return color;
1967
- }
1968
- function matchColor() {
1969
- return matchHexColor() || matchHSLAColor() || matchHSLColor() || matchRGBAColor() || matchRGBColor() || matchVarColor() || matchLiteralColor();
1970
- }
1971
- function matchLiteralColor() {
1972
- return match("literal", tokens.literalColor, 0);
1973
- }
1974
- function matchHexColor() {
1975
- return match("hex", tokens.hexColor, 1);
1976
- }
1977
- function matchRGBColor() {
1978
- return matchCall(tokens.rgbColor, () => {
1979
- return {
1980
- type: "rgb",
1981
- value: matchListing(matchNumber)
1982
- };
1983
- });
1984
- }
1985
- function matchRGBAColor() {
1986
- return matchCall(tokens.rgbaColor, () => {
1987
- return {
1988
- type: "rgba",
1989
- value: matchListing(matchNumber)
1990
- };
1991
- });
1992
- }
1993
- function matchVarColor() {
1994
- return matchCall(tokens.varColor, () => {
1995
- return {
1996
- type: "var",
1997
- value: matchVariableName()
1998
- };
1999
- });
2000
- }
2001
- function matchHSLColor() {
2002
- return matchCall(tokens.hslColor, () => {
2003
- const lookahead = scan(tokens.percentageValue);
2004
- if (lookahead) {
2005
- error("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");
2006
- }
2007
- const hue = matchNumber();
2008
- scan(tokens.comma);
2009
- let captures = scan(tokens.percentageValue);
2010
- const sat = captures ? captures[1] : null;
2011
- scan(tokens.comma);
2012
- captures = scan(tokens.percentageValue);
2013
- const light = captures ? captures[1] : null;
2014
- if (!sat || !light) {
2015
- error("Expected percentage value for saturation and lightness in HSL");
2016
- }
2017
- return {
2018
- type: "hsl",
2019
- value: [hue, sat, light]
2020
- };
2021
- });
2022
- }
2023
- function matchHSLAColor() {
2024
- return matchCall(tokens.hslaColor, () => {
2025
- const hue = matchNumber();
2026
- scan(tokens.comma);
2027
- let captures = scan(tokens.percentageValue);
2028
- const sat = captures ? captures[1] : null;
2029
- scan(tokens.comma);
2030
- captures = scan(tokens.percentageValue);
2031
- const light = captures ? captures[1] : null;
2032
- scan(tokens.comma);
2033
- const alpha = matchNumber();
2034
- if (!sat || !light) {
2035
- error("Expected percentage value for saturation and lightness in HSLA");
2036
- }
2037
- return {
2038
- type: "hsla",
2039
- value: [hue, sat, light, alpha]
2040
- };
2041
- });
2042
- }
2043
- function matchVariableName() {
2044
- return scan(tokens.variableName)[1];
2045
- }
2046
- function matchNumber() {
2047
- return scan(tokens.number)[1];
2048
- }
2049
- function matchDistance() {
2050
- return match("%", tokens.percentageValue, 1) || matchPositionKeyword() || matchCalc() || matchLength();
2051
- }
2052
- function matchPositionKeyword() {
2053
- return match("position-keyword", tokens.positionKeywords, 1);
2054
- }
2055
- function matchCalc() {
2056
- return matchCall(tokens.calcValue, () => {
2057
- let openParenCount = 1;
2058
- let i = 0;
2059
- while (openParenCount > 0 && i < input.length) {
2060
- const char = input.charAt(i);
2061
- if (char === "(") {
2062
- openParenCount++;
2063
- } else if (char === ")") {
2064
- openParenCount--;
2065
- }
2066
- i++;
2067
- }
2068
- if (openParenCount > 0) {
2069
- error("Missing closing parenthesis in calc() expression");
2070
- }
2071
- const calcContent = input.substring(0, i - 1);
2072
- consume(i - 1);
2073
- return {
2074
- type: "calc",
2075
- value: calcContent
2076
- };
2077
- });
2078
- }
2079
- function matchLength() {
2080
- return match("px", tokens.pixelValue, 1) || match("em", tokens.emValue, 1);
2081
- }
2082
- function match(type, pattern, captureIndex) {
2083
- const captures = scan(pattern);
2084
- if (captures) {
2085
- return {
2086
- type,
2087
- value: captures[captureIndex]
2088
- };
2089
- }
2090
- }
2091
- function scan(regexp) {
2092
- let captures, blankCaptures;
2093
- blankCaptures = /^\s+/.exec(input);
2094
- if (blankCaptures) {
2095
- consume(blankCaptures[0].length);
2096
- }
2097
- captures = regexp.exec(input);
2098
- if (captures) {
2099
- consume(captures[0].length);
2100
- }
2101
- return captures;
2102
- }
2103
- function consume(size) {
2104
- input = input.substr(size);
2105
- }
2106
- return function(code) {
2107
- input = code.toString().trim();
2108
- if (input.endsWith(";")) {
2109
- input = input.slice(0, -1);
2110
- }
2111
- return getAST();
2112
- };
2113
- }();
2114
- const parseGradient = GradientParser.parse.bind(GradientParser);
2115
-
2116
- class LinearGradient {
2117
- constructor(x0, y0, x1, y1, stops) {
2118
- this.x0 = x0;
2119
- this.y0 = y0;
2120
- this.x1 = x1;
2121
- this.y1 = y1;
2122
- this.stops = stops;
2123
- }
2124
- static from(css) {
2125
- let angleDeg = 0;
2126
- const stops = [];
2127
- const ast = parseGradient(css)[0];
2128
- if (ast.type === "linear-gradient") {
2129
- switch (ast?.orientation?.type) {
2130
- case "angular":
2131
- angleDeg = Number(ast.orientation.value);
2132
- break;
2133
- }
2134
- ast.colorStops.forEach((stop) => {
2135
- let offset = 0;
2136
- let color = "rgba(0, 0, 0, 0)";
2137
- switch (stop.type) {
2138
- case "rgb":
2139
- color = `rgb(${stop.value[0]}, ${stop.value[1]}, ${stop.value[2]})`;
2140
- break;
2141
- case "rgba":
2142
- color = `rgba(${stop.value[0]}, ${stop.value[1]}, ${stop.value[2]}, ${stop.value[3]})`;
2143
- break;
2144
- case "literal":
2145
- color = stop.value;
2146
- break;
2147
- case "hex":
2148
- color = stop.value;
2149
- break;
2150
- }
2151
- switch (stop.length?.type) {
2152
- case "%":
2153
- offset = Number(stop.length.value) / 100;
2154
- break;
2155
- }
2156
- stops.push({ offset, color });
2157
- });
2158
- }
2159
- const angleRad = (angleDeg + 90) * Math.PI / 180;
2160
- const width = 1;
2161
- const height = 1;
2162
- const halfWidth = width / 2;
2163
- const halfHeight = height / 2;
2164
- const length = Math.sqrt(width * width + height * height) / 2;
2165
- const x0 = halfWidth + length * Math.cos(angleRad + Math.PI);
2166
- const y0 = halfHeight + length * Math.sin(angleRad + Math.PI);
2167
- const x1 = halfWidth + length * Math.cos(angleRad);
2168
- const y1 = halfHeight + length * Math.sin(angleRad);
2169
- return new LinearGradient(x0, y0, x1, y1, stops);
2170
- }
2171
- parse(width, height) {
2172
- return this._parseByCanvas(width, height);
2173
- }
2174
- _parseByCanvas(width, height) {
2175
- const canvas = document.createElement("canvas");
2176
- canvas.width = width;
2177
- canvas.height = height;
2178
- const ctx = canvas.getContext("2d");
2179
- if (!ctx) {
2180
- throw new Error("Failed to parse linear gradient, get canvas context is null.");
2181
- }
2182
- const gradient = ctx.createLinearGradient(
2183
- this.x0 * width,
2184
- this.y0 * height,
2185
- this.x1 * width,
2186
- this.y1 * height
2187
- );
2188
- this.stops.forEach((stop) => {
2189
- gradient.addColorStop(stop.offset, stop.color);
2190
- });
2191
- ctx.fillStyle = gradient;
2192
- ctx.fillRect(0, 0, canvas.width, canvas.height);
2193
- const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
2194
- return {
2195
- width: imageData.width,
2196
- height: imageData.height,
2197
- pixels: new Uint8Array(imageData.data.buffer)
2198
- };
2199
- }
2200
- }
2201
-
2202
1740
  class Matrix2 extends Matrix {
2203
1741
  constructor(array) {
2204
1742
  super(2, 2, array);
@@ -2303,47 +1841,6 @@ class Projection2D extends Matrix3 {
2303
1841
  }
2304
1842
  }
2305
1843
 
2306
- class RadialGradient {
2307
- constructor(x0, y0, r0, x1, y1, r1, stops) {
2308
- this.x0 = x0;
2309
- this.y0 = y0;
2310
- this.r0 = r0;
2311
- this.x1 = x1;
2312
- this.y1 = y1;
2313
- this.r1 = r1;
2314
- this.stops = stops;
2315
- }
2316
- parse(width, height) {
2317
- return this._parseByCanvas(width, height);
2318
- }
2319
- _parseByCanvas(width, height) {
2320
- const canvas = document.createElement("canvas");
2321
- const ctx = canvas.getContext("2d");
2322
- if (!ctx) {
2323
- throw new Error("Failed to parse radial gradient, get canvas context is null.");
2324
- }
2325
- const gradient = ctx.createRadialGradient(
2326
- this.x0 * width,
2327
- this.y0 * height,
2328
- this.r0,
2329
- this.x1 * width,
2330
- this.y1 * height,
2331
- this.r1
2332
- );
2333
- this.stops.forEach((stop) => {
2334
- gradient.addColorStop(stop.offset, stop.color);
2335
- });
2336
- ctx.fillStyle = gradient;
2337
- ctx.fillRect(0, 0, canvas.width, canvas.height);
2338
- const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
2339
- return {
2340
- width: imageData.width,
2341
- height: imageData.height,
2342
- pixels: new Uint8Array(imageData.data.buffer)
2343
- };
2344
- }
2345
- }
2346
-
2347
1844
  class Vector2 extends Vector {
2348
1845
  get x() {
2349
1846
  return this._array[0];
@@ -5647,14 +5144,41 @@ class ColorTexture extends Texture2D {
5647
5144
  }
5648
5145
 
5649
5146
  class GradientTexture extends Texture2D {
5650
- // |(radial-gradient)
5651
- static regExp = /(linear-gradient)/;
5652
5147
  static test(value) {
5653
- return this.regExp.test(value);
5148
+ return isGradient(value);
5149
+ }
5150
+ static linearGradient(linearGradient, width, height) {
5151
+ const canvas = document.createElement("canvas");
5152
+ canvas.width = width;
5153
+ canvas.height = height;
5154
+ const ctx = canvas.getContext("2d");
5155
+ if (!ctx) {
5156
+ throw new Error("Failed to parse linear gradient, get canvas context is null.");
5157
+ }
5158
+ const { angle, stops } = linearGradient;
5159
+ const halfWidth = width / 2;
5160
+ const halfHeight = height / 2;
5161
+ const length = Math.sqrt(width * width + height * height) / 2;
5162
+ const x0 = halfWidth + length * Math.cos(angle + Math.PI);
5163
+ const y0 = halfHeight + length * Math.sin(angle + Math.PI);
5164
+ const x1 = halfWidth + length * Math.cos(angle);
5165
+ const y1 = halfHeight + length * Math.sin(angle);
5166
+ const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
5167
+ stops.forEach((stop) => {
5168
+ gradient.addColorStop(stop.offset, stop.color);
5169
+ });
5170
+ ctx.fillStyle = gradient;
5171
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
5172
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
5173
+ return {
5174
+ width: imageData.width,
5175
+ height: imageData.height,
5176
+ pixels: new Uint8Array(imageData.data.buffer)
5177
+ };
5654
5178
  }
5655
- constructor(value, width, height) {
5179
+ constructor(gradient, width, height) {
5656
5180
  super(
5657
- LinearGradient.from(value).parse(width, height)
5181
+ GradientTexture.linearGradient(gradient, width, height)
5658
5182
  );
5659
5183
  }
5660
5184
  }
@@ -7627,21 +7151,18 @@ class CanvasContext extends Path2D {
7627
7151
  miterLimit;
7628
7152
  _defaultStyle = Texture2D.EMPTY;
7629
7153
  _draws = [];
7630
- _colorToTexture(color, width, height) {
7631
- if (color instanceof Texture2D) {
7632
- return color;
7633
- } else if (typeof color === "string" && GradientTexture.test(color)) {
7634
- return new GradientTexture(color, width, height);
7154
+ _toTexture(source) {
7155
+ if (source instanceof Texture2D) {
7156
+ return source;
7635
7157
  } else {
7636
- return new ColorTexture(color);
7158
+ return new ColorTexture(source);
7637
7159
  }
7638
7160
  }
7639
7161
  stroke(options) {
7640
7162
  const path = new Path2D(this);
7641
7163
  let texture = this._defaultStyle;
7642
7164
  if (this.strokeStyle) {
7643
- const { width, height } = path.getBoundingBox();
7644
- texture = this._colorToTexture(this.strokeStyle, width, height);
7165
+ texture = this._toTexture(this.strokeStyle);
7645
7166
  }
7646
7167
  if (this.curves.length) {
7647
7168
  this._draws.push({
@@ -7671,8 +7192,7 @@ class CanvasContext extends Path2D {
7671
7192
  const path = new Path2D(this);
7672
7193
  let texture = this._defaultStyle;
7673
7194
  if (this.fillStyle) {
7674
- const { width, height } = path.getBoundingBox();
7675
- texture = this._colorToTexture(this.fillStyle, width, height);
7195
+ texture = this._toTexture(this.fillStyle);
7676
7196
  }
7677
7197
  this._draws.push({
7678
7198
  ...options,
@@ -9443,93 +8963,98 @@ class BaseElement2DFill extends CoreObject {
9443
8963
  super();
9444
8964
  this.parent = parent;
9445
8965
  }
9446
- _src;
8966
+ _texture;
8967
+ _setProperties(properties) {
8968
+ return super.setProperties(properties);
8969
+ }
9447
8970
  setProperties(properties) {
9448
- return super.setProperties(normalizeFill(properties));
8971
+ return this._setProperties(isNone(properties) ? void 0 : normalizeFill(properties));
9449
8972
  }
9450
8973
  _updateProperty(key, value, oldValue, declaration) {
9451
8974
  super._updateProperty(key, value, oldValue, declaration);
9452
8975
  switch (key) {
9453
8976
  case "color":
8977
+ case "cropRect":
8978
+ case "stretchRect":
9454
8979
  case "dpi":
9455
8980
  case "rotateWithShape":
9456
8981
  case "tile":
8982
+ case "opacity":
9457
8983
  this.parent.requestRedraw();
9458
8984
  break;
9459
- case "src":
9460
- this._updateSource();
8985
+ case "image":
8986
+ case "linearGradient":
8987
+ case "radialGradient":
8988
+ this._updateTexture();
9461
8989
  break;
9462
8990
  }
9463
8991
  }
9464
- async loadSource() {
9465
- if (this.src && this.src !== "none") {
9466
- return await assets.texture.load(this.src);
8992
+ async loadTexture() {
8993
+ if (this.linearGradient || this.radialGradient) {
8994
+ return new GradientTexture(
8995
+ this.linearGradient ?? this.radialGradient,
8996
+ this.parent.size.width,
8997
+ this.parent.size.height
8998
+ );
8999
+ } else if (!isNone(this.image)) {
9000
+ return await assets.texture.load(this.image);
9001
+ } else {
9002
+ return void 0;
9467
9003
  }
9468
9004
  }
9469
- async _updateSource() {
9470
- this._src = await this.loadSource();
9005
+ async _updateTexture() {
9006
+ this._texture = await this.loadTexture();
9471
9007
  this.parent.requestRedraw();
9472
9008
  }
9473
9009
  canDraw() {
9474
9010
  return Boolean(
9475
- this._src || this.color
9011
+ this._texture || this.color
9476
9012
  );
9477
9013
  }
9014
+ _getDrawOptions() {
9015
+ let disableWrapMode = false;
9016
+ const { width, height } = this.parent.size;
9017
+ const textureTransform = new Transform2D().scale(1 / width, 1 / height);
9018
+ if (this.cropRect) {
9019
+ const {
9020
+ left = 0,
9021
+ top = 0,
9022
+ right = 0,
9023
+ bottom = 0
9024
+ } = this.cropRect;
9025
+ textureTransform.scale(
9026
+ Math.abs(1 - (left + right)),
9027
+ Math.abs(1 - (top + bottom))
9028
+ ).translate(left, top);
9029
+ disableWrapMode = true;
9030
+ }
9031
+ if (this.tile) {
9032
+ const {
9033
+ translateX = 0,
9034
+ translateY = 0,
9035
+ scaleX = 1,
9036
+ scaleY = 1
9037
+ // flip, TODO
9038
+ // alignment, TODO
9039
+ } = this.tile;
9040
+ textureTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
9041
+ disableWrapMode = true;
9042
+ } else if (this.stretchRect) {
9043
+ const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
9044
+ textureTransform.scale(
9045
+ Math.abs(1 - (-left + -right)),
9046
+ Math.abs(1 - (-top + -bottom))
9047
+ ).translate(-left, -top);
9048
+ disableWrapMode = true;
9049
+ }
9050
+ return { disableWrapMode, textureTransform };
9051
+ }
9478
9052
  draw() {
9479
9053
  const ctx = this.parent.context;
9480
- if (this._src) {
9481
- const { width: imageWidth, height: imageHeight } = this._src;
9482
- const { width, height } = this.parent.size;
9483
- const transform = new Transform2D();
9484
- let disableWrapMode = false;
9485
- if (this.srcRect) {
9486
- const {
9487
- left = 0,
9488
- top = 0,
9489
- right = 0,
9490
- bottom = 0
9491
- } = this.srcRect;
9492
- const w = Math.abs(1 + (left + right)) * width;
9493
- const h = Math.abs(1 + (top + bottom)) * height;
9494
- const sx = 1 / w;
9495
- const sy = 1 / h;
9496
- const tx = left * width * sx;
9497
- const ty = top * height * sy;
9498
- transform.scale(sx, sy).translate(tx, ty);
9499
- }
9500
- if (this.tile) {
9501
- const {
9502
- translateX = 0,
9503
- translateY = 0,
9504
- scaleX = 1,
9505
- scaleY = 1
9506
- // flip, TODO
9507
- // alignment, TODO
9508
- } = this.tile;
9509
- transform.scale(1 / imageWidth, 1 / imageHeight).scale(1 / scaleX, 1 / scaleY).translate(-translateX / imageWidth, -translateY / imageHeight);
9510
- disableWrapMode = true;
9511
- } else if (this.stretch) {
9512
- const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretch.rect ?? {};
9513
- const w = Math.abs(1 + (-left + -right)) * width;
9514
- const h = Math.abs(1 + (-top + -bottom)) * height;
9515
- const scaleX = 1 / w;
9516
- const scaleY = 1 / h;
9517
- const translateX = -left * width * scaleX;
9518
- const translateY = -top * height * scaleY;
9519
- transform.scale(scaleX, scaleY).translate(translateX, translateY);
9520
- disableWrapMode = true;
9521
- } else {
9522
- transform.scale(1 / width, 1 / height);
9523
- }
9524
- ctx.textureTransform = transform;
9525
- ctx.fillStyle = this._src;
9526
- ctx.fill({
9527
- disableWrapMode
9528
- });
9529
- } else {
9530
- ctx.fillStyle = this.color;
9531
- ctx.fill();
9532
- }
9054
+ const { textureTransform, disableWrapMode } = this._getDrawOptions();
9055
+ ctx.textureTransform = textureTransform;
9056
+ ctx.fillStyle = this._texture ?? this.color;
9057
+ ctx.fill({ disableWrapMode });
9533
9058
  }
9534
9059
  }
9535
9060
  __decorateClass$u([
@@ -9537,7 +9062,19 @@ __decorateClass$u([
9537
9062
  ], BaseElement2DFill.prototype, "color");
9538
9063
  __decorateClass$u([
9539
9064
  property()
9540
- ], BaseElement2DFill.prototype, "src");
9065
+ ], BaseElement2DFill.prototype, "image");
9066
+ __decorateClass$u([
9067
+ property()
9068
+ ], BaseElement2DFill.prototype, "linearGradient");
9069
+ __decorateClass$u([
9070
+ property()
9071
+ ], BaseElement2DFill.prototype, "radialGradient");
9072
+ __decorateClass$u([
9073
+ property()
9074
+ ], BaseElement2DFill.prototype, "cropRect");
9075
+ __decorateClass$u([
9076
+ property()
9077
+ ], BaseElement2DFill.prototype, "stretchRect");
9541
9078
  __decorateClass$u([
9542
9079
  property()
9543
9080
  ], BaseElement2DFill.prototype, "dpi");
@@ -9547,9 +9084,6 @@ __decorateClass$u([
9547
9084
  __decorateClass$u([
9548
9085
  property()
9549
9086
  ], BaseElement2DFill.prototype, "tile");
9550
- __decorateClass$u([
9551
- property()
9552
- ], BaseElement2DFill.prototype, "stretch");
9553
9087
  __decorateClass$u([
9554
9088
  property()
9555
9089
  ], BaseElement2DFill.prototype, "opacity");
@@ -9565,30 +9099,12 @@ var __decorateClass$t = (decorators, target, key, kind) => {
9565
9099
  };
9566
9100
  class BaseElement2DBackground extends BaseElement2DFill {
9567
9101
  setProperties(properties) {
9568
- return super.setProperties(normalizeBackground(properties));
9102
+ return super._setProperties(isNone(properties) ? void 0 : normalizeBackground(properties));
9569
9103
  }
9570
9104
  }
9571
9105
  __decorateClass$t([
9572
9106
  property()
9573
- ], BaseElement2DBackground.prototype, "color");
9574
- __decorateClass$t([
9575
- property()
9576
- ], BaseElement2DBackground.prototype, "src");
9577
- __decorateClass$t([
9578
- property()
9579
- ], BaseElement2DBackground.prototype, "dpi");
9580
- __decorateClass$t([
9581
- property()
9582
- ], BaseElement2DBackground.prototype, "rotateWithShape");
9583
- __decorateClass$t([
9584
- property()
9585
- ], BaseElement2DBackground.prototype, "tile");
9586
- __decorateClass$t([
9587
- property()
9588
- ], BaseElement2DBackground.prototype, "stretch");
9589
- __decorateClass$t([
9590
- property()
9591
- ], BaseElement2DBackground.prototype, "opacity");
9107
+ ], BaseElement2DBackground.prototype, "fillWithShape");
9592
9108
 
9593
9109
  var __defProp$l = Object.defineProperty;
9594
9110
  var __decorateClass$s = (decorators, target, key, kind) => {
@@ -9601,30 +9117,12 @@ var __decorateClass$s = (decorators, target, key, kind) => {
9601
9117
  };
9602
9118
  class BaseElement2DForeground extends BaseElement2DFill {
9603
9119
  setProperties(properties) {
9604
- return super.setProperties(normalizeForeground(properties));
9120
+ return super._setProperties(isNone(properties) ? void 0 : normalizeForeground(properties));
9605
9121
  }
9606
9122
  }
9607
9123
  __decorateClass$s([
9608
9124
  property()
9609
- ], BaseElement2DForeground.prototype, "color");
9610
- __decorateClass$s([
9611
- property()
9612
- ], BaseElement2DForeground.prototype, "src");
9613
- __decorateClass$s([
9614
- property()
9615
- ], BaseElement2DForeground.prototype, "dpi");
9616
- __decorateClass$s([
9617
- property()
9618
- ], BaseElement2DForeground.prototype, "rotateWithShape");
9619
- __decorateClass$s([
9620
- property()
9621
- ], BaseElement2DForeground.prototype, "tile");
9622
- __decorateClass$s([
9623
- property()
9624
- ], BaseElement2DForeground.prototype, "stretch");
9625
- __decorateClass$s([
9626
- property()
9627
- ], BaseElement2DForeground.prototype, "opacity");
9125
+ ], BaseElement2DForeground.prototype, "fillWithShape");
9628
9126
 
9629
9127
  var __defProp$k = Object.defineProperty;
9630
9128
  var __decorateClass$r = (decorators, target, key, kind) => {
@@ -9635,84 +9133,42 @@ var __decorateClass$r = (decorators, target, key, kind) => {
9635
9133
  if (result) __defProp$k(target, key, result);
9636
9134
  return result;
9637
9135
  };
9638
- class BaseElement2DGeometry extends CoreObject {
9639
- constructor(parent) {
9640
- super();
9641
- this.parent = parent;
9642
- this._updatePath2DSet();
9643
- }
9644
- _path2DSet = new Path2DSet();
9136
+ class BaseElement2DOutline extends BaseElement2DFill {
9645
9137
  setProperties(properties) {
9646
- return super.setProperties(normalizeGeometry(properties));
9138
+ return super._setProperties(isNone(properties) ? void 0 : normalizeOutline(properties));
9647
9139
  }
9648
9140
  _updateProperty(key, value, oldValue, declaration) {
9649
9141
  super._updateProperty(key, value, oldValue, declaration);
9650
9142
  switch (key) {
9651
- case "svg":
9652
- case "data":
9653
- case "viewBox":
9654
- this._updatePath2DSet();
9143
+ case "width":
9144
+ case "style":
9655
9145
  this.parent.requestRedraw();
9656
9146
  break;
9657
9147
  }
9658
9148
  }
9659
- _updatePath2DSet() {
9660
- let viewBox;
9661
- if (this.svg) {
9662
- const dom = svgToDOM(this.svg);
9663
- this._path2DSet = svgToPath2DSet(dom);
9664
- viewBox = this._path2DSet.viewBox ?? this.viewBox;
9665
- } else {
9666
- viewBox = this.viewBox;
9667
- this.data.forEach((path, i) => {
9668
- const { data, ...style } = path;
9669
- const path2D = new Path2D();
9670
- path2D.style = style;
9671
- path2D.addData(data);
9672
- this._path2DSet.paths[i] = path2D;
9673
- });
9674
- }
9675
- const [x, y, w, h] = viewBox;
9676
- this._path2DSet.paths.forEach((path) => {
9677
- path.applyTransform(new Matrix3$1().translate(-x, -y).scale(1 / w, 1 / h));
9678
- });
9149
+ canDraw() {
9150
+ return Boolean(
9151
+ this.width || super.canDraw()
9152
+ );
9679
9153
  }
9680
9154
  draw() {
9681
- if (this._path2DSet.paths.length) {
9682
- const ctx = this.parent.context;
9683
- const { width, height } = this.parent.size;
9684
- this._path2DSet.paths.forEach((path) => {
9685
- ctx.addPath(path.clone().applyTransform(new Matrix3$1().scale(width, height)));
9686
- });
9687
- } else {
9688
- this.drawRect();
9689
- }
9690
- }
9691
- drawRect() {
9692
9155
  const ctx = this.parent.context;
9693
- const { width, height } = this.parent.size;
9694
- const { borderRadius } = this.parent.style;
9695
- if (width && height) {
9696
- if (borderRadius) {
9697
- ctx.roundRect(0, 0, width, height, borderRadius);
9698
- } else {
9699
- ctx.rect(0, 0, width, height);
9700
- }
9701
- }
9156
+ const { textureTransform, disableWrapMode } = this._getDrawOptions();
9157
+ ctx.lineWidth = this.width;
9158
+ ctx.textureTransform = textureTransform;
9159
+ ctx.strokeStyle = this._texture ?? this.color;
9160
+ ctx.stroke({ disableWrapMode });
9702
9161
  }
9703
9162
  }
9704
9163
  __decorateClass$r([
9705
- property()
9706
- ], BaseElement2DGeometry.prototype, "name");
9707
- __decorateClass$r([
9708
- property()
9709
- ], BaseElement2DGeometry.prototype, "svg");
9164
+ property({ default: 0 })
9165
+ ], BaseElement2DOutline.prototype, "color");
9710
9166
  __decorateClass$r([
9711
- property({ default: [0, 0, 1, 1] })
9712
- ], BaseElement2DGeometry.prototype, "viewBox");
9167
+ property({ default: 0 })
9168
+ ], BaseElement2DOutline.prototype, "width");
9713
9169
  __decorateClass$r([
9714
- property({ default: [] })
9715
- ], BaseElement2DGeometry.prototype, "data");
9170
+ property({ default: "solid" })
9171
+ ], BaseElement2DOutline.prototype, "style");
9716
9172
 
9717
9173
  var __defProp$j = Object.defineProperty;
9718
9174
  var __decorateClass$q = (decorators, target, key, kind) => {
@@ -9723,47 +9179,53 @@ var __decorateClass$q = (decorators, target, key, kind) => {
9723
9179
  if (result) __defProp$j(target, key, result);
9724
9180
  return result;
9725
9181
  };
9726
- class BaseElement2DOutline extends CoreObject {
9182
+ class BaseElement2DShadow extends CoreObject {
9727
9183
  constructor(parent) {
9728
9184
  super();
9729
9185
  this.parent = parent;
9730
9186
  }
9731
9187
  setProperties(properties) {
9732
- return super.setProperties(normalizeOutline(properties));
9188
+ return super.setProperties(isNone(properties) ? void 0 : normalizeShadow(properties));
9733
9189
  }
9734
9190
  _updateProperty(key, value, oldValue, declaration) {
9735
9191
  super._updateProperty(key, value, oldValue, declaration);
9736
9192
  switch (key) {
9737
9193
  case "color":
9738
- case "width":
9739
- case "style":
9740
- case "src":
9741
- case "opacity":
9742
- this.parent.requestRedraw();
9194
+ case "blur":
9195
+ case "offsetX":
9196
+ case "offsetY":
9197
+ this.updateEffect();
9743
9198
  break;
9744
9199
  }
9745
9200
  }
9746
- canDraw() {
9747
- return Boolean(
9748
- this.width || this.color
9749
- );
9750
- }
9751
- draw() {
9752
- const ctx = this.parent.context;
9753
- ctx.lineWidth = this.width;
9754
- ctx.strokeStyle = this.color;
9755
- ctx.stroke();
9201
+ updateEffect() {
9202
+ const name = "__$shadow";
9203
+ let effect = this.parent.getNode(name);
9204
+ if (this.blur || this.offsetX || this.offsetY) {
9205
+ if (!effect) {
9206
+ effect = new DropShadowEffect({ name });
9207
+ this.parent.appendChild(effect, "back");
9208
+ }
9209
+ effect.setProperties(this.getProperties());
9210
+ } else {
9211
+ if (effect) {
9212
+ this.parent.removeChild(effect);
9213
+ }
9214
+ }
9756
9215
  }
9757
9216
  }
9217
+ __decorateClass$q([
9218
+ property({ default: "#000000" })
9219
+ ], BaseElement2DShadow.prototype, "color");
9758
9220
  __decorateClass$q([
9759
9221
  property({ default: 0 })
9760
- ], BaseElement2DOutline.prototype, "color");
9222
+ ], BaseElement2DShadow.prototype, "blur");
9761
9223
  __decorateClass$q([
9762
9224
  property({ default: 0 })
9763
- ], BaseElement2DOutline.prototype, "width");
9225
+ ], BaseElement2DShadow.prototype, "offsetY");
9764
9226
  __decorateClass$q([
9765
- property({ default: "solid" })
9766
- ], BaseElement2DOutline.prototype, "style");
9227
+ property({ default: 0 })
9228
+ ], BaseElement2DShadow.prototype, "offsetX");
9767
9229
 
9768
9230
  var __defProp$i = Object.defineProperty;
9769
9231
  var __decorateClass$p = (decorators, target, key, kind) => {
@@ -9774,53 +9236,84 @@ var __decorateClass$p = (decorators, target, key, kind) => {
9774
9236
  if (result) __defProp$i(target, key, result);
9775
9237
  return result;
9776
9238
  };
9777
- class BaseElement2DShadow extends CoreObject {
9239
+ class BaseElement2DShape extends CoreObject {
9778
9240
  constructor(parent) {
9779
9241
  super();
9780
9242
  this.parent = parent;
9243
+ this._updatePath2DSet();
9781
9244
  }
9245
+ _path2DSet = new Path2DSet();
9782
9246
  setProperties(properties) {
9783
- return super.setProperties(normalizeShadow(properties));
9247
+ return super.setProperties(isNone(properties) ? void 0 : normalizeShape(properties));
9784
9248
  }
9785
9249
  _updateProperty(key, value, oldValue, declaration) {
9786
9250
  super._updateProperty(key, value, oldValue, declaration);
9787
9251
  switch (key) {
9788
- case "color":
9789
- case "blur":
9790
- case "offsetX":
9791
- case "offsetY":
9792
- this.updateEffect();
9252
+ case "svg":
9253
+ case "data":
9254
+ case "viewBox":
9255
+ this._updatePath2DSet();
9256
+ this.parent.requestRedraw();
9793
9257
  break;
9794
9258
  }
9795
9259
  }
9796
- updateEffect() {
9797
- const name = "__$shadow";
9798
- let effect = this.parent.getNode(name);
9799
- if (this.blur || this.offsetX || this.offsetY) {
9800
- if (!effect) {
9801
- effect = new DropShadowEffect({ name });
9802
- this.parent.appendChild(effect, "back");
9803
- }
9804
- effect.setProperties(this.getProperties());
9260
+ _updatePath2DSet() {
9261
+ let viewBox;
9262
+ if (this.svg) {
9263
+ const dom = svgToDOM(this.svg);
9264
+ this._path2DSet = svgToPath2DSet(dom);
9265
+ viewBox = this._path2DSet.viewBox ?? this.viewBox;
9805
9266
  } else {
9806
- if (effect) {
9807
- this.parent.removeChild(effect);
9267
+ viewBox = this.viewBox;
9268
+ this.data?.forEach((path, i) => {
9269
+ const { data, ...style } = path;
9270
+ const path2D = new Path2D();
9271
+ path2D.style = style;
9272
+ path2D.addData(data);
9273
+ this._path2DSet.paths[i] = path2D;
9274
+ });
9275
+ }
9276
+ const [x, y, w, h] = viewBox;
9277
+ this._path2DSet.paths.forEach((path) => {
9278
+ path.applyTransform(new Matrix3$1().translate(-x, -y).scale(1 / w, 1 / h));
9279
+ });
9280
+ }
9281
+ draw() {
9282
+ if (this._path2DSet.paths.length) {
9283
+ const ctx = this.parent.context;
9284
+ const { width, height } = this.parent.size;
9285
+ this._path2DSet.paths.forEach((path) => {
9286
+ ctx.addPath(path.clone().applyTransform(new Matrix3$1().scale(width, height)));
9287
+ });
9288
+ } else {
9289
+ this.drawRect();
9290
+ }
9291
+ }
9292
+ drawRect() {
9293
+ const ctx = this.parent.context;
9294
+ const { width, height } = this.parent.size;
9295
+ const { borderRadius } = this.parent.style;
9296
+ if (width && height) {
9297
+ if (borderRadius) {
9298
+ ctx.roundRect(0, 0, width, height, borderRadius);
9299
+ } else {
9300
+ ctx.rect(0, 0, width, height);
9808
9301
  }
9809
9302
  }
9810
9303
  }
9811
9304
  }
9812
9305
  __decorateClass$p([
9813
- property({ default: "#000000" })
9814
- ], BaseElement2DShadow.prototype, "color");
9306
+ property()
9307
+ ], BaseElement2DShape.prototype, "preset");
9815
9308
  __decorateClass$p([
9816
- property({ default: 0 })
9817
- ], BaseElement2DShadow.prototype, "blur");
9309
+ property()
9310
+ ], BaseElement2DShape.prototype, "svg");
9818
9311
  __decorateClass$p([
9819
- property({ default: 0 })
9820
- ], BaseElement2DShadow.prototype, "offsetY");
9312
+ property({ default: [0, 0, 1, 1] })
9313
+ ], BaseElement2DShape.prototype, "viewBox");
9821
9314
  __decorateClass$p([
9822
- property({ default: 0 })
9823
- ], BaseElement2DShadow.prototype, "offsetX");
9315
+ property({ default: [] })
9316
+ ], BaseElement2DShape.prototype, "data");
9824
9317
 
9825
9318
  class BaseElement2DStyle extends Resource {
9826
9319
  constructor(properties) {
@@ -9860,7 +9353,7 @@ class BaseElement2DText extends CoreObject {
9860
9353
  baseText = new Text();
9861
9354
  measureResult;
9862
9355
  setProperties(properties) {
9863
- return super.setProperties(normalizeText(properties));
9356
+ return super.setProperties(isNone(properties) ? void 0 : normalizeText(properties));
9864
9357
  }
9865
9358
  _updateProperty(key, value, oldValue, declaration) {
9866
9359
  super._updateProperty(key, value, oldValue, declaration);
@@ -10047,12 +9540,12 @@ let BaseElement2D = class extends Node2D {
10047
9540
  set background(value) {
10048
9541
  this._background.setProperties(value);
10049
9542
  }
10050
- _geometry = new BaseElement2DGeometry(this);
10051
- get geometry() {
10052
- return this._geometry;
9543
+ _shape = new BaseElement2DShape(this);
9544
+ get shape() {
9545
+ return this._shape;
10053
9546
  }
10054
- set geometry(value) {
10055
- this._geometry.setProperties(value);
9547
+ set shape(value) {
9548
+ this._shape.setProperties(value);
10056
9549
  }
10057
9550
  _fill = new BaseElement2DFill(this);
10058
9551
  get fill() {
@@ -10100,7 +9593,7 @@ let BaseElement2D = class extends Node2D {
10100
9593
  const {
10101
9594
  style,
10102
9595
  text,
10103
- geometry,
9596
+ shape,
10104
9597
  background,
10105
9598
  fill,
10106
9599
  outline,
@@ -10110,7 +9603,7 @@ let BaseElement2D = class extends Node2D {
10110
9603
  } = properties;
10111
9604
  style && this.style.setProperties(style);
10112
9605
  background && this.background.setProperties(background);
10113
- geometry && this.geometry.setProperties(geometry);
9606
+ shape && this.shape.setProperties(shape);
10114
9607
  fill && this.fill.setProperties(fill);
10115
9608
  outline && this.outline.setProperties(outline);
10116
9609
  text && this.text.setProperties(text);
@@ -10176,7 +9669,7 @@ let BaseElement2D = class extends Node2D {
10176
9669
  this.background.color = this.style.backgroundColor;
10177
9670
  break;
10178
9671
  case "backgroundImage":
10179
- this.background.src = this.style.backgroundImage;
9672
+ this.background.image = this.style.backgroundImage;
10180
9673
  break;
10181
9674
  case "borderStyle":
10182
9675
  case "outlineStyle":
@@ -10215,7 +9708,7 @@ let BaseElement2D = class extends Node2D {
10215
9708
  const offsetX = originX * width;
10216
9709
  const offsetY = originY * height;
10217
9710
  this.transform.identity().translate(-offsetX, -offsetY).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
10218
- parseCSSTransform(this.style.transform, width, height, this.transform);
9711
+ parseCSSTransform(this.style.transform ?? "", width, height, this.transform);
10219
9712
  this.transform.translate(this.position.x, this.position.y).translate(offsetX, offsetY);
10220
9713
  }
10221
9714
  _updateGlobalTransform() {
@@ -10268,33 +9761,33 @@ let BaseElement2D = class extends Node2D {
10268
9761
  }
10269
9762
  _draw() {
10270
9763
  super._draw();
10271
- if (this.text.canDraw()) {
10272
- this.text.updateMeasure();
9764
+ if (this._text.canDraw()) {
9765
+ this._text.updateMeasure();
10273
9766
  }
10274
- if (this.background.canDraw()) {
9767
+ if (this._background.canDraw()) {
10275
9768
  this._tree?.log(this.name, "draw background");
10276
- this.geometry.drawRect();
10277
- this.background.draw();
9769
+ this._shape.drawRect();
9770
+ this._background.draw();
10278
9771
  }
10279
- if (this.fill.canDraw()) {
9772
+ if (this._fill.canDraw()) {
10280
9773
  this._tree?.log(this.name, "draw fill");
10281
- this.geometry.draw();
10282
- this.fill.draw();
9774
+ this._shape.draw();
9775
+ this._fill.draw();
10283
9776
  }
10284
- if (this.outline.canDraw()) {
9777
+ if (this._outline.canDraw()) {
10285
9778
  this._tree?.log(this.name, "draw outline");
10286
- this.geometry.draw();
10287
- this.outline.draw();
9779
+ this._shape.draw();
9780
+ this._outline.draw();
10288
9781
  }
10289
- if (this.foreground.canDraw()) {
9782
+ if (this._foreground.canDraw()) {
10290
9783
  this._tree?.log(this.name, "draw foreground");
10291
- this.geometry.drawRect();
10292
- this.foreground.draw();
9784
+ this._shape.drawRect();
9785
+ this._foreground.draw();
10293
9786
  }
10294
- if (this.text.canDraw()) {
9787
+ if (this._text.canDraw()) {
10295
9788
  this._tree?.log(this.name, "draw text");
10296
- this.geometry.drawRect();
10297
- this.text.draw();
9789
+ this._shape.drawRect();
9790
+ this._text.draw();
10298
9791
  }
10299
9792
  this._drawContent();
10300
9793
  }
@@ -10355,7 +9848,7 @@ let BaseElement2D = class extends Node2D {
10355
9848
  ...json.props,
10356
9849
  style: this.style.toJSON(),
10357
9850
  background: this.background.toJSON(),
10358
- geometry: this.geometry.toJSON(),
9851
+ shape: this.shape.toJSON(),
10359
9852
  fill: this.fill.toJSON(),
10360
9853
  outline: this.outline.toJSON(),
10361
9854
  text: this.text.toJSON(),
@@ -11009,7 +10502,7 @@ let Image2D = class extends Element2D {
11009
10502
  const tx = left * width * sx;
11010
10503
  const ty = top * height * sy;
11011
10504
  this.context.textureTransform = new Transform2D().scale(sx, sy).translate(tx, ty);
11012
- this.geometry.draw();
10505
+ this.shape.draw();
11013
10506
  this.context.fill();
11014
10507
  }
11015
10508
  }
@@ -11052,7 +10545,7 @@ class TextureRect2D extends Element2D {
11052
10545
  1 / width,
11053
10546
  1 / height
11054
10547
  );
11055
- this.geometry.drawRect();
10548
+ this.shape.drawRect();
11056
10549
  this.context.fill();
11057
10550
  }
11058
10551
  }
@@ -14583,4 +14076,4 @@ async function render(options) {
14583
14076
  });
14584
14077
  }
14585
14078
 
14586
- export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DGeometry, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DStyle, BaseElement2DText, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, EventEmitter, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, Graphics2D, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, ImageTexture, IndexBuffer, Input, InputEvent, JSONLoader, KawaseBlurEffect, KawaseTransition, LeftEraseTransition, LinearGradient, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, OutlineEffect, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, RadialGradient, Range, RawWeakMap, Rect2, RefCounted, Renderer, Resource, Ruler, SUPPORTS_AUDIO_CONTEXT, SUPPORTS_CLICK_EVENTS, SUPPORTS_CREATE_IMAGE_BITMAP, SUPPORTS_IMAGE_BITMAP, SUPPORTS_MOUSE_EVENTS, SUPPORTS_OFFLINE_AUDIO_CONTEXT, SUPPORTS_POINTER_EVENTS, SUPPORTS_RESIZE_OBSERVER, SUPPORTS_TOUCH_EVENTS, SUPPORTS_WEBGL2, SUPPORTS_WEBKIT_AUDIO_CONTEXT, SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT, SUPPORTS_WEB_AUDIO, SUPPORTS_WHEEL_EVENTS, Scaler, SceneTree, ScrollBar, Text2D, TextLoader, Texture2D, TextureLoader, TextureRect2D, Ticker, TiltShiftTransition, Timeline, TimelineNode, Transform2D, TransformRect2D, Transition, TwistTransition, UvGeometry, UvMaterial, Vector, Vector2, Vector3, Vector4, VertexAttribute, VertexBuffer, Video2D, VideoLoader, VideoTexture, Viewport, ViewportTexture, WebAudio, WebAudioContext, WebGLBatch2DModule, WebGLBlendMode, WebGLBufferModule, WebGLFramebufferModule, WebGLMaskModule, WebGLModule, WebGLProgramModule, WebGLRenderer, WebGLScissorModule, WebGLState, WebGLStateModule, WebGLStencilModule, WebGLTextureModule, WebGLVertexArrayModule, WebGLViewportModule, WebSound, WheelInputEvent, XScrollBar, YScrollBar, ZoomBlurEffect, assets, clamp, clampFrag, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, defineProperty, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, frag$1 as frag, getDeclarations, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCSSFilter, parseCSSTransform, parseCSSTransformOrigin, parseCssFunctions, parseCssProperty, property, protectedProperty, render, timingFunctions, uid };
14079
+ export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, EventEmitter, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, Graphics2D, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, ImageTexture, IndexBuffer, Input, InputEvent, JSONLoader, KawaseBlurEffect, KawaseTransition, LeftEraseTransition, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, OutlineEffect, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Range, RawWeakMap, Rect2, RefCounted, Renderer, Resource, Ruler, SUPPORTS_AUDIO_CONTEXT, SUPPORTS_CLICK_EVENTS, SUPPORTS_CREATE_IMAGE_BITMAP, SUPPORTS_IMAGE_BITMAP, SUPPORTS_MOUSE_EVENTS, SUPPORTS_OFFLINE_AUDIO_CONTEXT, SUPPORTS_POINTER_EVENTS, SUPPORTS_RESIZE_OBSERVER, SUPPORTS_TOUCH_EVENTS, SUPPORTS_WEBGL2, SUPPORTS_WEBKIT_AUDIO_CONTEXT, SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT, SUPPORTS_WEB_AUDIO, SUPPORTS_WHEEL_EVENTS, Scaler, SceneTree, ScrollBar, Text2D, TextLoader, Texture2D, TextureLoader, TextureRect2D, Ticker, TiltShiftTransition, Timeline, TimelineNode, Transform2D, TransformRect2D, Transition, TwistTransition, UvGeometry, UvMaterial, Vector, Vector2, Vector3, Vector4, VertexAttribute, VertexBuffer, Video2D, VideoLoader, VideoTexture, Viewport, ViewportTexture, WebAudio, WebAudioContext, WebGLBatch2DModule, WebGLBlendMode, WebGLBufferModule, WebGLFramebufferModule, WebGLMaskModule, WebGLModule, WebGLProgramModule, WebGLRenderer, WebGLScissorModule, WebGLState, WebGLStateModule, WebGLStencilModule, WebGLTextureModule, WebGLVertexArrayModule, WebGLViewportModule, WebSound, WheelInputEvent, XScrollBar, YScrollBar, ZoomBlurEffect, assets, clamp, clampFrag, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, defineProperty, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, frag$1 as frag, getDeclarations, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCSSFilter, parseCSSTransform, parseCSSTransformOrigin, parseCssFunctions, parseCssProperty, property, protectedProperty, render, timingFunctions, uid };