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.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,59 +8963,75 @@ 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
  }
9478
- draw() {
9479
- const ctx = this.parent.context;
9480
- if (this._src) {
9481
- const { width: imageWidth, height: imageHeight } = this._src;
9014
+ _getDrawOptions() {
9015
+ let textureTransform;
9016
+ let disableWrapMode = false;
9017
+ if (this._texture && this._texture.source instanceof ImageBitmap) {
9018
+ textureTransform = new Transform2D();
9019
+ const { width: imageWidth, height: imageHeight } = this._texture;
9482
9020
  const { width, height } = this.parent.size;
9483
- const transform = new Transform2D();
9484
- let disableWrapMode = false;
9485
- if (this.srcRect) {
9021
+ if (this.cropRect) {
9486
9022
  const {
9487
9023
  left = 0,
9488
9024
  top = 0,
9489
9025
  right = 0,
9490
9026
  bottom = 0
9491
- } = this.srcRect;
9027
+ } = this.cropRect;
9492
9028
  const w = Math.abs(1 + (left + right)) * width;
9493
9029
  const h = Math.abs(1 + (top + bottom)) * height;
9494
9030
  const sx = 1 / w;
9495
9031
  const sy = 1 / h;
9496
9032
  const tx = left * width * sx;
9497
9033
  const ty = top * height * sy;
9498
- transform.scale(sx, sy).translate(tx, ty);
9034
+ textureTransform.scale(sx, sy).translate(tx, ty);
9499
9035
  }
9500
9036
  if (this.tile) {
9501
9037
  const {
@@ -9506,30 +9042,30 @@ class BaseElement2DFill extends CoreObject {
9506
9042
  // flip, TODO
9507
9043
  // alignment, TODO
9508
9044
  } = this.tile;
9509
- transform.scale(1 / imageWidth, 1 / imageHeight).scale(1 / scaleX, 1 / scaleY).translate(-translateX / imageWidth, -translateY / imageHeight);
9045
+ textureTransform.scale(1 / imageWidth, 1 / imageHeight).scale(1 / scaleX, 1 / scaleY).translate(-translateX / imageWidth, -translateY / imageHeight);
9510
9046
  disableWrapMode = true;
9511
- } else if (this.stretch) {
9512
- const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretch.rect ?? {};
9047
+ } else if (this.stretchRect) {
9048
+ const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
9513
9049
  const w = Math.abs(1 + (-left + -right)) * width;
9514
9050
  const h = Math.abs(1 + (-top + -bottom)) * height;
9515
9051
  const scaleX = 1 / w;
9516
9052
  const scaleY = 1 / h;
9517
9053
  const translateX = -left * width * scaleX;
9518
9054
  const translateY = -top * height * scaleY;
9519
- transform.scale(scaleX, scaleY).translate(translateX, translateY);
9055
+ textureTransform.scale(scaleX, scaleY).translate(translateX, translateY);
9520
9056
  disableWrapMode = true;
9521
9057
  } else {
9522
- transform.scale(1 / width, 1 / height);
9058
+ textureTransform.scale(1 / width, 1 / height);
9523
9059
  }
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
9060
  }
9061
+ return { disableWrapMode, textureTransform };
9062
+ }
9063
+ draw() {
9064
+ const ctx = this.parent.context;
9065
+ const { textureTransform, disableWrapMode } = this._getDrawOptions();
9066
+ ctx.textureTransform = textureTransform;
9067
+ ctx.fillStyle = this._texture ?? this.color;
9068
+ ctx.fill({ disableWrapMode });
9533
9069
  }
9534
9070
  }
9535
9071
  __decorateClass$u([
@@ -9537,7 +9073,19 @@ __decorateClass$u([
9537
9073
  ], BaseElement2DFill.prototype, "color");
9538
9074
  __decorateClass$u([
9539
9075
  property()
9540
- ], BaseElement2DFill.prototype, "src");
9076
+ ], BaseElement2DFill.prototype, "image");
9077
+ __decorateClass$u([
9078
+ property()
9079
+ ], BaseElement2DFill.prototype, "linearGradient");
9080
+ __decorateClass$u([
9081
+ property()
9082
+ ], BaseElement2DFill.prototype, "radialGradient");
9083
+ __decorateClass$u([
9084
+ property()
9085
+ ], BaseElement2DFill.prototype, "cropRect");
9086
+ __decorateClass$u([
9087
+ property()
9088
+ ], BaseElement2DFill.prototype, "stretchRect");
9541
9089
  __decorateClass$u([
9542
9090
  property()
9543
9091
  ], BaseElement2DFill.prototype, "dpi");
@@ -9547,9 +9095,6 @@ __decorateClass$u([
9547
9095
  __decorateClass$u([
9548
9096
  property()
9549
9097
  ], BaseElement2DFill.prototype, "tile");
9550
- __decorateClass$u([
9551
- property()
9552
- ], BaseElement2DFill.prototype, "stretch");
9553
9098
  __decorateClass$u([
9554
9099
  property()
9555
9100
  ], BaseElement2DFill.prototype, "opacity");
@@ -9565,30 +9110,12 @@ var __decorateClass$t = (decorators, target, key, kind) => {
9565
9110
  };
9566
9111
  class BaseElement2DBackground extends BaseElement2DFill {
9567
9112
  setProperties(properties) {
9568
- return super.setProperties(normalizeBackground(properties));
9113
+ return super._setProperties(isNone(properties) ? void 0 : normalizeBackground(properties));
9569
9114
  }
9570
9115
  }
9571
9116
  __decorateClass$t([
9572
9117
  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");
9118
+ ], BaseElement2DBackground.prototype, "fillWithShape");
9592
9119
 
9593
9120
  var __defProp$l = Object.defineProperty;
9594
9121
  var __decorateClass$s = (decorators, target, key, kind) => {
@@ -9601,30 +9128,12 @@ var __decorateClass$s = (decorators, target, key, kind) => {
9601
9128
  };
9602
9129
  class BaseElement2DForeground extends BaseElement2DFill {
9603
9130
  setProperties(properties) {
9604
- return super.setProperties(normalizeForeground(properties));
9131
+ return super._setProperties(isNone(properties) ? void 0 : normalizeForeground(properties));
9605
9132
  }
9606
9133
  }
9607
9134
  __decorateClass$s([
9608
9135
  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");
9136
+ ], BaseElement2DForeground.prototype, "fillWithShape");
9628
9137
 
9629
9138
  var __defProp$k = Object.defineProperty;
9630
9139
  var __decorateClass$r = (decorators, target, key, kind) => {
@@ -9635,84 +9144,42 @@ var __decorateClass$r = (decorators, target, key, kind) => {
9635
9144
  if (result) __defProp$k(target, key, result);
9636
9145
  return result;
9637
9146
  };
9638
- class BaseElement2DGeometry extends CoreObject {
9639
- constructor(parent) {
9640
- super();
9641
- this.parent = parent;
9642
- this._updatePath2DSet();
9643
- }
9644
- _path2DSet = new Path2DSet();
9147
+ class BaseElement2DOutline extends BaseElement2DFill {
9645
9148
  setProperties(properties) {
9646
- return super.setProperties(normalizeGeometry(properties));
9149
+ return super._setProperties(isNone(properties) ? void 0 : normalizeOutline(properties));
9647
9150
  }
9648
9151
  _updateProperty(key, value, oldValue, declaration) {
9649
9152
  super._updateProperty(key, value, oldValue, declaration);
9650
9153
  switch (key) {
9651
- case "svg":
9652
- case "data":
9653
- case "viewBox":
9654
- this._updatePath2DSet();
9154
+ case "width":
9155
+ case "style":
9655
9156
  this.parent.requestRedraw();
9656
9157
  break;
9657
9158
  }
9658
9159
  }
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
- });
9160
+ canDraw() {
9161
+ return Boolean(
9162
+ this.width || super.canDraw()
9163
+ );
9679
9164
  }
9680
9165
  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
9166
  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
- }
9167
+ const { textureTransform, disableWrapMode } = this._getDrawOptions();
9168
+ ctx.lineWidth = this.width;
9169
+ ctx.textureTransform = textureTransform;
9170
+ ctx.strokeStyle = this._texture ?? this.color;
9171
+ ctx.stroke({ disableWrapMode });
9702
9172
  }
9703
9173
  }
9704
9174
  __decorateClass$r([
9705
- property()
9706
- ], BaseElement2DGeometry.prototype, "name");
9707
- __decorateClass$r([
9708
- property()
9709
- ], BaseElement2DGeometry.prototype, "svg");
9175
+ property({ default: 0 })
9176
+ ], BaseElement2DOutline.prototype, "color");
9710
9177
  __decorateClass$r([
9711
- property({ default: [0, 0, 1, 1] })
9712
- ], BaseElement2DGeometry.prototype, "viewBox");
9178
+ property({ default: 0 })
9179
+ ], BaseElement2DOutline.prototype, "width");
9713
9180
  __decorateClass$r([
9714
- property({ default: [] })
9715
- ], BaseElement2DGeometry.prototype, "data");
9181
+ property({ default: "solid" })
9182
+ ], BaseElement2DOutline.prototype, "style");
9716
9183
 
9717
9184
  var __defProp$j = Object.defineProperty;
9718
9185
  var __decorateClass$q = (decorators, target, key, kind) => {
@@ -9723,47 +9190,53 @@ var __decorateClass$q = (decorators, target, key, kind) => {
9723
9190
  if (result) __defProp$j(target, key, result);
9724
9191
  return result;
9725
9192
  };
9726
- class BaseElement2DOutline extends CoreObject {
9193
+ class BaseElement2DShadow extends CoreObject {
9727
9194
  constructor(parent) {
9728
9195
  super();
9729
9196
  this.parent = parent;
9730
9197
  }
9731
9198
  setProperties(properties) {
9732
- return super.setProperties(normalizeOutline(properties));
9199
+ return super.setProperties(isNone(properties) ? void 0 : normalizeShadow(properties));
9733
9200
  }
9734
9201
  _updateProperty(key, value, oldValue, declaration) {
9735
9202
  super._updateProperty(key, value, oldValue, declaration);
9736
9203
  switch (key) {
9737
9204
  case "color":
9738
- case "width":
9739
- case "style":
9740
- case "src":
9741
- case "opacity":
9742
- this.parent.requestRedraw();
9205
+ case "blur":
9206
+ case "offsetX":
9207
+ case "offsetY":
9208
+ this.updateEffect();
9743
9209
  break;
9744
9210
  }
9745
9211
  }
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();
9212
+ updateEffect() {
9213
+ const name = "__$shadow";
9214
+ let effect = this.parent.getNode(name);
9215
+ if (this.blur || this.offsetX || this.offsetY) {
9216
+ if (!effect) {
9217
+ effect = new DropShadowEffect({ name });
9218
+ this.parent.appendChild(effect, "back");
9219
+ }
9220
+ effect.setProperties(this.getProperties());
9221
+ } else {
9222
+ if (effect) {
9223
+ this.parent.removeChild(effect);
9224
+ }
9225
+ }
9756
9226
  }
9757
9227
  }
9228
+ __decorateClass$q([
9229
+ property({ default: "#000000" })
9230
+ ], BaseElement2DShadow.prototype, "color");
9758
9231
  __decorateClass$q([
9759
9232
  property({ default: 0 })
9760
- ], BaseElement2DOutline.prototype, "color");
9233
+ ], BaseElement2DShadow.prototype, "blur");
9761
9234
  __decorateClass$q([
9762
9235
  property({ default: 0 })
9763
- ], BaseElement2DOutline.prototype, "width");
9236
+ ], BaseElement2DShadow.prototype, "offsetY");
9764
9237
  __decorateClass$q([
9765
- property({ default: "solid" })
9766
- ], BaseElement2DOutline.prototype, "style");
9238
+ property({ default: 0 })
9239
+ ], BaseElement2DShadow.prototype, "offsetX");
9767
9240
 
9768
9241
  var __defProp$i = Object.defineProperty;
9769
9242
  var __decorateClass$p = (decorators, target, key, kind) => {
@@ -9774,53 +9247,84 @@ var __decorateClass$p = (decorators, target, key, kind) => {
9774
9247
  if (result) __defProp$i(target, key, result);
9775
9248
  return result;
9776
9249
  };
9777
- class BaseElement2DShadow extends CoreObject {
9250
+ class BaseElement2DShape extends CoreObject {
9778
9251
  constructor(parent) {
9779
9252
  super();
9780
9253
  this.parent = parent;
9254
+ this._updatePath2DSet();
9781
9255
  }
9256
+ _path2DSet = new Path2DSet();
9782
9257
  setProperties(properties) {
9783
- return super.setProperties(normalizeShadow(properties));
9258
+ return super.setProperties(isNone(properties) ? void 0 : normalizeShape(properties));
9784
9259
  }
9785
9260
  _updateProperty(key, value, oldValue, declaration) {
9786
9261
  super._updateProperty(key, value, oldValue, declaration);
9787
9262
  switch (key) {
9788
- case "color":
9789
- case "blur":
9790
- case "offsetX":
9791
- case "offsetY":
9792
- this.updateEffect();
9263
+ case "svg":
9264
+ case "data":
9265
+ case "viewBox":
9266
+ this._updatePath2DSet();
9267
+ this.parent.requestRedraw();
9793
9268
  break;
9794
9269
  }
9795
9270
  }
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());
9271
+ _updatePath2DSet() {
9272
+ let viewBox;
9273
+ if (this.svg) {
9274
+ const dom = svgToDOM(this.svg);
9275
+ this._path2DSet = svgToPath2DSet(dom);
9276
+ viewBox = this._path2DSet.viewBox ?? this.viewBox;
9805
9277
  } else {
9806
- if (effect) {
9807
- this.parent.removeChild(effect);
9278
+ viewBox = this.viewBox;
9279
+ this.data?.forEach((path, i) => {
9280
+ const { data, ...style } = path;
9281
+ const path2D = new Path2D();
9282
+ path2D.style = style;
9283
+ path2D.addData(data);
9284
+ this._path2DSet.paths[i] = path2D;
9285
+ });
9286
+ }
9287
+ const [x, y, w, h] = viewBox;
9288
+ this._path2DSet.paths.forEach((path) => {
9289
+ path.applyTransform(new Matrix3$1().translate(-x, -y).scale(1 / w, 1 / h));
9290
+ });
9291
+ }
9292
+ draw() {
9293
+ if (this._path2DSet.paths.length) {
9294
+ const ctx = this.parent.context;
9295
+ const { width, height } = this.parent.size;
9296
+ this._path2DSet.paths.forEach((path) => {
9297
+ ctx.addPath(path.clone().applyTransform(new Matrix3$1().scale(width, height)));
9298
+ });
9299
+ } else {
9300
+ this.drawRect();
9301
+ }
9302
+ }
9303
+ drawRect() {
9304
+ const ctx = this.parent.context;
9305
+ const { width, height } = this.parent.size;
9306
+ const { borderRadius } = this.parent.style;
9307
+ if (width && height) {
9308
+ if (borderRadius) {
9309
+ ctx.roundRect(0, 0, width, height, borderRadius);
9310
+ } else {
9311
+ ctx.rect(0, 0, width, height);
9808
9312
  }
9809
9313
  }
9810
9314
  }
9811
9315
  }
9812
9316
  __decorateClass$p([
9813
- property({ default: "#000000" })
9814
- ], BaseElement2DShadow.prototype, "color");
9317
+ property()
9318
+ ], BaseElement2DShape.prototype, "preset");
9815
9319
  __decorateClass$p([
9816
- property({ default: 0 })
9817
- ], BaseElement2DShadow.prototype, "blur");
9320
+ property()
9321
+ ], BaseElement2DShape.prototype, "svg");
9818
9322
  __decorateClass$p([
9819
- property({ default: 0 })
9820
- ], BaseElement2DShadow.prototype, "offsetY");
9323
+ property({ default: [0, 0, 1, 1] })
9324
+ ], BaseElement2DShape.prototype, "viewBox");
9821
9325
  __decorateClass$p([
9822
- property({ default: 0 })
9823
- ], BaseElement2DShadow.prototype, "offsetX");
9326
+ property({ default: [] })
9327
+ ], BaseElement2DShape.prototype, "data");
9824
9328
 
9825
9329
  class BaseElement2DStyle extends Resource {
9826
9330
  constructor(properties) {
@@ -9860,7 +9364,7 @@ class BaseElement2DText extends CoreObject {
9860
9364
  baseText = new Text();
9861
9365
  measureResult;
9862
9366
  setProperties(properties) {
9863
- return super.setProperties(normalizeText(properties));
9367
+ return super.setProperties(isNone(properties) ? void 0 : normalizeText(properties));
9864
9368
  }
9865
9369
  _updateProperty(key, value, oldValue, declaration) {
9866
9370
  super._updateProperty(key, value, oldValue, declaration);
@@ -10047,12 +9551,12 @@ let BaseElement2D = class extends Node2D {
10047
9551
  set background(value) {
10048
9552
  this._background.setProperties(value);
10049
9553
  }
10050
- _geometry = new BaseElement2DGeometry(this);
10051
- get geometry() {
10052
- return this._geometry;
9554
+ _shape = new BaseElement2DShape(this);
9555
+ get shape() {
9556
+ return this._shape;
10053
9557
  }
10054
- set geometry(value) {
10055
- this._geometry.setProperties(value);
9558
+ set shape(value) {
9559
+ this._shape.setProperties(value);
10056
9560
  }
10057
9561
  _fill = new BaseElement2DFill(this);
10058
9562
  get fill() {
@@ -10100,7 +9604,7 @@ let BaseElement2D = class extends Node2D {
10100
9604
  const {
10101
9605
  style,
10102
9606
  text,
10103
- geometry,
9607
+ shape,
10104
9608
  background,
10105
9609
  fill,
10106
9610
  outline,
@@ -10110,7 +9614,7 @@ let BaseElement2D = class extends Node2D {
10110
9614
  } = properties;
10111
9615
  style && this.style.setProperties(style);
10112
9616
  background && this.background.setProperties(background);
10113
- geometry && this.geometry.setProperties(geometry);
9617
+ shape && this.shape.setProperties(shape);
10114
9618
  fill && this.fill.setProperties(fill);
10115
9619
  outline && this.outline.setProperties(outline);
10116
9620
  text && this.text.setProperties(text);
@@ -10176,7 +9680,7 @@ let BaseElement2D = class extends Node2D {
10176
9680
  this.background.color = this.style.backgroundColor;
10177
9681
  break;
10178
9682
  case "backgroundImage":
10179
- this.background.src = this.style.backgroundImage;
9683
+ this.background.image = this.style.backgroundImage;
10180
9684
  break;
10181
9685
  case "borderStyle":
10182
9686
  case "outlineStyle":
@@ -10215,7 +9719,7 @@ let BaseElement2D = class extends Node2D {
10215
9719
  const offsetX = originX * width;
10216
9720
  const offsetY = originY * height;
10217
9721
  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);
9722
+ parseCSSTransform(this.style.transform ?? "", width, height, this.transform);
10219
9723
  this.transform.translate(this.position.x, this.position.y).translate(offsetX, offsetY);
10220
9724
  }
10221
9725
  _updateGlobalTransform() {
@@ -10268,33 +9772,33 @@ let BaseElement2D = class extends Node2D {
10268
9772
  }
10269
9773
  _draw() {
10270
9774
  super._draw();
10271
- if (this.text.canDraw()) {
10272
- this.text.updateMeasure();
9775
+ if (this._text.canDraw()) {
9776
+ this._text.updateMeasure();
10273
9777
  }
10274
- if (this.background.canDraw()) {
9778
+ if (this._background.canDraw()) {
10275
9779
  this._tree?.log(this.name, "draw background");
10276
- this.geometry.drawRect();
10277
- this.background.draw();
9780
+ this._shape.drawRect();
9781
+ this._background.draw();
10278
9782
  }
10279
- if (this.fill.canDraw()) {
9783
+ if (this._fill.canDraw()) {
10280
9784
  this._tree?.log(this.name, "draw fill");
10281
- this.geometry.draw();
10282
- this.fill.draw();
9785
+ this._shape.draw();
9786
+ this._fill.draw();
10283
9787
  }
10284
- if (this.outline.canDraw()) {
9788
+ if (this._outline.canDraw()) {
10285
9789
  this._tree?.log(this.name, "draw outline");
10286
- this.geometry.draw();
10287
- this.outline.draw();
9790
+ this._shape.draw();
9791
+ this._outline.draw();
10288
9792
  }
10289
- if (this.foreground.canDraw()) {
9793
+ if (this._foreground.canDraw()) {
10290
9794
  this._tree?.log(this.name, "draw foreground");
10291
- this.geometry.drawRect();
10292
- this.foreground.draw();
9795
+ this._shape.drawRect();
9796
+ this._foreground.draw();
10293
9797
  }
10294
- if (this.text.canDraw()) {
9798
+ if (this._text.canDraw()) {
10295
9799
  this._tree?.log(this.name, "draw text");
10296
- this.geometry.drawRect();
10297
- this.text.draw();
9800
+ this._shape.drawRect();
9801
+ this._text.draw();
10298
9802
  }
10299
9803
  this._drawContent();
10300
9804
  }
@@ -10355,7 +9859,7 @@ let BaseElement2D = class extends Node2D {
10355
9859
  ...json.props,
10356
9860
  style: this.style.toJSON(),
10357
9861
  background: this.background.toJSON(),
10358
- geometry: this.geometry.toJSON(),
9862
+ shape: this.shape.toJSON(),
10359
9863
  fill: this.fill.toJSON(),
10360
9864
  outline: this.outline.toJSON(),
10361
9865
  text: this.text.toJSON(),
@@ -11009,7 +10513,7 @@ let Image2D = class extends Element2D {
11009
10513
  const tx = left * width * sx;
11010
10514
  const ty = top * height * sy;
11011
10515
  this.context.textureTransform = new Transform2D().scale(sx, sy).translate(tx, ty);
11012
- this.geometry.draw();
10516
+ this.shape.draw();
11013
10517
  this.context.fill();
11014
10518
  }
11015
10519
  }
@@ -11052,7 +10556,7 @@ class TextureRect2D extends Element2D {
11052
10556
  1 / width,
11053
10557
  1 / height
11054
10558
  );
11055
- this.geometry.drawRect();
10559
+ this.shape.drawRect();
11056
10560
  this.context.fill();
11057
10561
  }
11058
10562
  }
@@ -11127,9 +10631,6 @@ var __decorateClass$g = (decorators, target, key, kind) => {
11127
10631
  };
11128
10632
  const textStyles = new Set(Object.keys(textDefaultStyle));
11129
10633
  let Text2D = class extends TextureRect2D {
11130
- effects;
11131
- measureDom;
11132
- fonts;
11133
10634
  texture = new CanvasTexture();
11134
10635
  base = new Text();
11135
10636
  measureResult;
@@ -14586,4 +14087,4 @@ async function render(options) {
14586
14087
  });
14587
14088
  }
14588
14089
 
14589
- 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 };
14090
+ 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 };