leafer-draw 1.9.7 → 1.9.8

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/web.esm.js CHANGED
@@ -1,10 +1,10 @@
1
- import { Debug, LeaferCanvasBase, Platform, isString, isUndefined, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, LeafLevelList, LayoutEvent, Run, ImageManager, isObject, BoundsHelper, Matrix, getMatrixData, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4, isNumber } from "@leafer/core";
1
+ import { Debug, LeaferCanvasBase, Platform, isString, isUndefined, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, LeafLevelList, LayoutEvent, Run, ImageManager, isObject, BoundsHelper, FourNumberHelper, Matrix, getMatrixData, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4, isNumber } from "@leafer/core";
2
2
 
3
3
  export * from "@leafer/core";
4
4
 
5
5
  export { LeaferImage } from "@leafer/core";
6
6
 
7
- import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Effect, Group, TextConvert } from "@leafer-ui/draw";
7
+ import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Group, TextConvert, Effect } from "@leafer-ui/draw";
8
8
 
9
9
  export * from "@leafer-ui/draw";
10
10
 
@@ -41,7 +41,7 @@ class LeaferCanvas extends LeaferCanvasBase {
41
41
  }
42
42
  if (Platform.syncDomFont && !this.parentView) {
43
43
  style.display = "none";
44
- document.body.appendChild(this.view);
44
+ if (document.body) document.body.appendChild(this.view);
45
45
  }
46
46
  this.__createContext();
47
47
  if (!this.autoLayout) this.resize(config);
@@ -637,6 +637,7 @@ class Renderer {
637
637
  usePartRender: true,
638
638
  maxFPS: 120
639
639
  };
640
+ this.frames = [];
640
641
  this.target = target;
641
642
  this.canvas = canvas;
642
643
  if (userConfig) this.config = DataHelper.default(userConfig, this.config);
@@ -789,12 +790,15 @@ class Renderer {
789
790
  const target = this.target;
790
791
  if (this.requestTime || !target) return;
791
792
  if (target.parentApp) return target.parentApp.requestRender(false);
792
- const requestTime = this.requestTime = Date.now();
793
+ this.requestTime = this.frameTime || Date.now();
793
794
  const render = () => {
794
- const nowFPS = 1e3 / (Date.now() - requestTime);
795
+ const nowFPS = 1e3 / ((this.frameTime = Date.now()) - this.requestTime);
795
796
  const {maxFPS: maxFPS} = this.config;
796
- if (maxFPS && nowFPS > maxFPS - .5) return Platform.requestRender(render);
797
- this.FPS = Math.min(120, Math.ceil(nowFPS));
797
+ if (maxFPS && nowFPS > maxFPS) return Platform.requestRender(render);
798
+ const {frames: frames} = this;
799
+ if (frames.length > 30) frames.shift();
800
+ frames.push(nowFPS);
801
+ this.FPS = Math.round(frames.reduce((a, b) => a + b, 0) / frames.length);
798
802
  this.requestTime = 0;
799
803
  this.checkRender();
800
804
  };
@@ -1061,24 +1065,29 @@ function drawOutside(stroke, ui, canvas) {
1061
1065
  }
1062
1066
  }
1063
1067
 
1064
- const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = BoundsHelper;
1068
+ const {getSpread: getSpread, copyAndSpread: copyAndSpread, toOuterOf: toOuterOf, getOuterOf: getOuterOf, getByMove: getByMove, move: move$1, getIntersectData: getIntersectData} = BoundsHelper;
1069
+
1070
+ const tempBounds$1 = {};
1065
1071
 
1066
1072
  function shape(ui, current, options) {
1067
1073
  const canvas = current.getSameCanvas();
1068
- const nowWorld = ui.__nowWorld, currentBounds = current.bounds;
1069
- let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1074
+ const currentBounds = current.bounds, nowWorld = ui.__nowWorld, layout = ui.__layout;
1075
+ const nowWorldShapeBounds = ui.__nowWorldShapeBounds || (ui.__nowWorldShapeBounds = {});
1076
+ toOuterOf(layout.strokeSpread ? (copyAndSpread(tempBounds$1, layout.boxBounds, layout.strokeSpread),
1077
+ tempBounds$1) : layout.boxBounds, nowWorld, nowWorldShapeBounds);
1078
+ let bounds, renderBounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1070
1079
  let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
1071
- if (currentBounds.includes(nowWorld)) {
1080
+ if (currentBounds.includes(nowWorldShapeBounds)) {
1072
1081
  worldCanvas = canvas;
1073
- bounds = shapeBounds = nowWorld;
1082
+ bounds = shapeBounds = nowWorldShapeBounds;
1083
+ renderBounds = nowWorld;
1074
1084
  } else {
1075
- const {renderShapeSpread: spread} = ui.__layout;
1076
1085
  let worldClipBounds;
1077
1086
  if (Platform.fullImageShadow) {
1078
- worldClipBounds = nowWorld;
1087
+ worldClipBounds = nowWorldShapeBounds;
1079
1088
  } else {
1080
- const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : currentBounds;
1081
- worldClipBounds = getIntersectData(spreadBounds, nowWorld);
1089
+ const spreadBounds = layout.renderShapeSpread ? getSpread(currentBounds, FourNumberHelper.swapAndScale(layout.renderShapeSpread, scaleX, scaleY)) : currentBounds;
1090
+ worldClipBounds = getIntersectData(spreadBounds, nowWorldShapeBounds);
1082
1091
  }
1083
1092
  fitMatrix = currentBounds.getFitMatrix(worldClipBounds);
1084
1093
  let {a: fitScaleX, d: fitScaleY} = fitMatrix;
@@ -1088,8 +1097,10 @@ function shape(ui, current, options) {
1088
1097
  scaleX *= fitScaleX;
1089
1098
  scaleY *= fitScaleY;
1090
1099
  }
1091
- shapeBounds = getOuterOf(nowWorld, fitMatrix);
1100
+ shapeBounds = getOuterOf(nowWorldShapeBounds, fitMatrix);
1092
1101
  bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
1102
+ renderBounds = getOuterOf(nowWorld, fitMatrix);
1103
+ move$1(renderBounds, -fitMatrix.e, -fitMatrix.f);
1093
1104
  const userMatrix = options.matrix;
1094
1105
  if (userMatrix) {
1095
1106
  matrix = new Matrix(fitMatrix);
@@ -1108,6 +1119,7 @@ function shape(ui, current, options) {
1108
1119
  matrix: matrix,
1109
1120
  fitMatrix: fitMatrix,
1110
1121
  bounds: bounds,
1122
+ renderBounds: renderBounds,
1111
1123
  worldCanvas: worldCanvas,
1112
1124
  shapeBounds: shapeBounds,
1113
1125
  scaleX: scaleX,
@@ -1211,7 +1223,7 @@ const PaintModule = {
1211
1223
  shape: shape
1212
1224
  };
1213
1225
 
1214
- let origin = {}, tempMatrix = getMatrixData();
1226
+ let origin = {}, tempMatrix$1 = getMatrixData();
1215
1227
 
1216
1228
  const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
1217
1229
 
@@ -1226,12 +1238,12 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1226
1238
  data.transform = transform;
1227
1239
  }
1228
1240
 
1229
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
1241
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
1230
1242
  const transform = get$3();
1231
1243
  layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1232
- if (clipSize) {
1233
- tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1234
- multiplyParent(transform, tempMatrix);
1244
+ if (clipScaleX) {
1245
+ tempMatrix$1.a = clipScaleX, tempMatrix$1.d = clipScaleY;
1246
+ multiplyParent(transform, tempMatrix$1);
1235
1247
  }
1236
1248
  data.transform = transform;
1237
1249
  }
@@ -1332,7 +1344,12 @@ function getPatternData(paint, box, image) {
1332
1344
 
1333
1345
  case "normal":
1334
1346
  case "clip":
1335
- if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1347
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) {
1348
+ let clipScaleX, clipScaleY;
1349
+ if (clipSize) clipScaleX = box.width / clipSize.width, clipScaleY = box.height / clipSize.height;
1350
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
1351
+ if (clipScaleX) scaleX = scaleX ? scaleX * clipScaleX : scaleX, scaleY = scaleY ? scaleY * clipScaleY : clipScaleY;
1352
+ }
1336
1353
  break;
1337
1354
 
1338
1355
  case "repeat":
@@ -1490,7 +1507,7 @@ function ignoreRender(ui, value) {
1490
1507
 
1491
1508
  const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
1492
1509
 
1493
- const {floor: floor, ceil: ceil, max: max, abs: abs} = Math;
1510
+ const {floor: floor, ceil: ceil, max: max$1, abs: abs} = Math;
1494
1511
 
1495
1512
  function createPattern(ui, paint, pixelRatio) {
1496
1513
  let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
@@ -1539,8 +1556,8 @@ function createPattern(ui, paint, pixelRatio) {
1539
1556
  if (transform || scaleX !== 1 || scaleY !== 1) {
1540
1557
  const canvasWidth = width + (xGap || 0);
1541
1558
  const canvasHeight = height + (yGap || 0);
1542
- scaleX /= canvasWidth / max(floor(canvasWidth), 1);
1543
- scaleY /= canvasHeight / max(floor(canvasHeight), 1);
1559
+ scaleX /= canvasWidth / max$1(floor(canvasWidth), 1);
1560
+ scaleY /= canvasHeight / max$1(floor(canvasHeight), 1);
1544
1561
  if (!imageMatrix) {
1545
1562
  imageMatrix = get$1();
1546
1563
  if (transform) copy$1(imageMatrix, transform);
@@ -1599,17 +1616,15 @@ function checkImage(ui, canvas, paint, allowDraw) {
1599
1616
  if (allowDraw) {
1600
1617
  if (data.repeat) {
1601
1618
  allowDraw = false;
1602
- } else {
1603
- if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
1604
- let {width: width, height: height} = data;
1605
- width *= scaleX * pixelRatio;
1606
- height *= scaleY * pixelRatio;
1607
- if (data.scaleX) {
1608
- width *= data.scaleX;
1609
- height *= data.scaleY;
1610
- }
1611
- allowDraw = width * height > Platform.image.maxCacheSize;
1619
+ } else if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
1620
+ let {width: width, height: height} = data;
1621
+ width *= scaleX * pixelRatio;
1622
+ height *= scaleY * pixelRatio;
1623
+ if (data.scaleX) {
1624
+ width *= data.scaleX;
1625
+ height *= data.scaleY;
1612
1626
  }
1627
+ allowDraw = width * height > Platform.image.maxCacheSize;
1613
1628
  }
1614
1629
  }
1615
1630
  if (allowDraw) {
@@ -1789,20 +1804,20 @@ const PaintGradientModule = {
1789
1804
  getTransform: getTransform
1790
1805
  };
1791
1806
 
1792
- const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
1807
+ const {copy: copy, move: move, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper, {max: max} = Math;
1793
1808
 
1794
- const tempBounds = {};
1809
+ const tempBounds = {}, tempMatrix = new Matrix;
1795
1810
 
1796
1811
  const offsetOutBounds$1 = {};
1797
1812
 
1798
1813
  function shadow(ui, current, shape) {
1799
- let copyBounds, spreadScale;
1800
- const {__nowWorld: nowWorld, __layout: __layout} = ui;
1814
+ let copyBounds, transform;
1815
+ const {__nowWorld: nowWorld} = ui;
1801
1816
  const {shadow: shadow} = ui.__;
1802
- const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1817
+ const {worldCanvas: worldCanvas, bounds: bounds, renderBounds: renderBounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1803
1818
  const other = current.getSameCanvas();
1804
1819
  const end = shadow.length - 1;
1805
- toOffsetOutBounds$1(bounds, offsetOutBounds$1);
1820
+ toOffsetOutBounds$1(bounds, offsetOutBounds$1, renderBounds);
1806
1821
  shadow.forEach((item, index) => {
1807
1822
  let otherScale = 1;
1808
1823
  if (item.scaleFixed) {
@@ -1810,54 +1825,61 @@ function shadow(ui, current, shape) {
1810
1825
  if (sx > 1) otherScale = 1 / sx;
1811
1826
  }
1812
1827
  other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, ColorConvert.string(item.color));
1813
- spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1814
- drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
1815
- copyBounds = bounds;
1828
+ transform = getShadowTransform(ui, other, shape, item, offsetOutBounds$1, otherScale);
1829
+ if (transform) other.setTransform(transform);
1830
+ drawWorldShadow(other, offsetOutBounds$1, shape);
1831
+ if (transform) other.resetTransform();
1832
+ copyBounds = renderBounds;
1816
1833
  if (item.box) {
1817
1834
  other.restore();
1818
1835
  other.save();
1819
1836
  if (worldCanvas) {
1820
- other.copyWorld(other, bounds, nowWorld, "copy");
1837
+ other.copyWorld(other, renderBounds, nowWorld, "copy");
1821
1838
  copyBounds = nowWorld;
1822
1839
  }
1823
1840
  worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
1824
1841
  }
1825
- if (Effect.isTransformShadow(item)) Effect.renderTransformShadow(ui, current, other, copyBounds, item); else LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1842
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1826
1843
  if (end && index < end) other.clearWorld(copyBounds);
1827
1844
  });
1828
1845
  other.recycle(copyBounds);
1829
1846
  }
1830
1847
 
1831
- function getShadowSpread(_ui, shadow) {
1832
- let width = 0;
1833
- shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
1834
- return width;
1848
+ function getShadowRenderSpread(_ui, shadow) {
1849
+ let top = 0, right = 0, bottom = 0, left = 0, x, y, spread, blur;
1850
+ shadow.forEach(item => {
1851
+ x = item.x || 0, y = item.y || 0, spread = item.spread || 0, blur = (item.blur || 0) * 1.5;
1852
+ top = max(top, spread + blur - y);
1853
+ right = max(right, spread + blur + x);
1854
+ bottom = max(bottom, spread + blur + y);
1855
+ left = max(left, spread + blur - x);
1856
+ });
1857
+ return top === right && right === bottom && bottom === left ? top : [ top, right, bottom, left ];
1858
+ }
1859
+
1860
+ function getShadowTransform(ui, canvas, _shape, shadow, outBounds, otherScale, isInnerShaodw) {
1861
+ if (shadow.spread) {
1862
+ const spreadScale = 1 + shadow.spread * 2 / ui.__layout.strokeBounds.width * otherScale * (isInnerShaodw ? -1 : 1);
1863
+ tempMatrix.set().scaleOfOuter({
1864
+ x: (outBounds.x + outBounds.width / 2) * canvas.pixelRatio,
1865
+ y: (outBounds.y + outBounds.height / 2) * canvas.pixelRatio
1866
+ }, spreadScale);
1867
+ return tempMatrix;
1868
+ }
1869
+ return undefined;
1835
1870
  }
1836
1871
 
1837
- function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1838
- const {bounds: bounds, shapeBounds: shapeBounds} = shape;
1872
+ function drawWorldShadow(canvas, outBounds, shape) {
1873
+ const {shapeBounds: shapeBounds} = shape;
1874
+ let from, to;
1839
1875
  if (Platform.fullImageShadow) {
1840
1876
  copy(tempBounds, canvas.bounds);
1841
- tempBounds.x += outBounds.x - shapeBounds.x;
1842
- tempBounds.y += outBounds.y - shapeBounds.y;
1843
- if (spreadScale) {
1844
- const {fitMatrix: fitMatrix} = shape;
1845
- tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1846
- tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1847
- tempBounds.width *= spreadScale;
1848
- tempBounds.height *= spreadScale;
1849
- }
1850
- canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
1877
+ move(tempBounds, outBounds.x - shapeBounds.x, outBounds.y - shapeBounds.y);
1878
+ from = canvas.bounds, to = tempBounds;
1851
1879
  } else {
1852
- if (spreadScale) {
1853
- copy(tempBounds, outBounds);
1854
- tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
1855
- tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
1856
- tempBounds.width *= spreadScale;
1857
- tempBounds.height *= spreadScale;
1858
- }
1859
- canvas.copyWorld(shape.canvas, shapeBounds, spreadScale ? tempBounds : outBounds);
1880
+ from = shapeBounds, to = outBounds;
1860
1881
  }
1882
+ canvas.copyWorld(shape.canvas, from, to);
1861
1883
  }
1862
1884
 
1863
1885
  const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
@@ -1865,13 +1887,13 @@ const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
1865
1887
  const offsetOutBounds = {};
1866
1888
 
1867
1889
  function innerShadow(ui, current, shape) {
1868
- let copyBounds, spreadScale;
1869
- const {__nowWorld: nowWorld, __layout: __layout} = ui;
1890
+ let copyBounds, transform;
1891
+ const {__nowWorld: nowWorld} = ui;
1870
1892
  const {innerShadow: innerShadow} = ui.__;
1871
- const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1893
+ const {worldCanvas: worldCanvas, bounds: bounds, renderBounds: renderBounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1872
1894
  const other = current.getSameCanvas();
1873
1895
  const end = innerShadow.length - 1;
1874
- toOffsetOutBounds(bounds, offsetOutBounds);
1896
+ toOffsetOutBounds(bounds, offsetOutBounds, renderBounds);
1875
1897
  innerShadow.forEach((item, index) => {
1876
1898
  let otherScale = 1;
1877
1899
  if (item.scaleFixed) {
@@ -1880,16 +1902,17 @@ function innerShadow(ui, current, shape) {
1880
1902
  }
1881
1903
  other.save();
1882
1904
  other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
1883
- spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1884
- drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
1905
+ transform = getShadowTransform(ui, other, shape, item, offsetOutBounds, otherScale, true);
1906
+ if (transform) other.setTransform(transform);
1907
+ drawWorldShadow(other, offsetOutBounds, shape);
1885
1908
  other.restore();
1886
1909
  if (worldCanvas) {
1887
- other.copyWorld(other, bounds, nowWorld, "copy");
1910
+ other.copyWorld(other, renderBounds, nowWorld, "copy");
1888
1911
  other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
1889
1912
  copyBounds = nowWorld;
1890
1913
  } else {
1891
1914
  other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
1892
- copyBounds = bounds;
1915
+ copyBounds = renderBounds;
1893
1916
  }
1894
1917
  other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
1895
1918
  LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
@@ -1898,6 +1921,8 @@ function innerShadow(ui, current, shape) {
1898
1921
  other.recycle(copyBounds);
1899
1922
  }
1900
1923
 
1924
+ const getInnerShadowSpread = getShadowRenderSpread;
1925
+
1901
1926
  function blur(ui, current, origin) {
1902
1927
  const {blur: blur} = ui.__;
1903
1928
  origin.setWorldBlur(blur * ui.__nowWorld.a);
@@ -1912,10 +1937,12 @@ const EffectModule = {
1912
1937
  innerShadow: innerShadow,
1913
1938
  blur: blur,
1914
1939
  backgroundBlur: backgroundBlur,
1915
- getShadowSpread: getShadowSpread,
1940
+ getShadowRenderSpread: getShadowRenderSpread,
1941
+ getShadowTransform: getShadowTransform,
1916
1942
  isTransformShadow(_shadow) {
1917
1943
  return undefined;
1918
- }
1944
+ },
1945
+ getInnerShadowSpread: getInnerShadowSpread
1919
1946
  };
1920
1947
 
1921
1948
  const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
@@ -1932,6 +1959,7 @@ Group.prototype.__renderMask = function(canvas, options) {
1932
1959
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1933
1960
  maskCanvas = contentCanvas = null;
1934
1961
  }
1962
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1935
1963
  maskOpacity = child.__.opacity;
1936
1964
  usedGrayscaleAlpha = false;
1937
1965
  if (mask === "path" || mask === "clipping-path") {
@@ -1949,7 +1977,6 @@ Group.prototype.__renderMask = function(canvas, options) {
1949
1977
  if (!contentCanvas) contentCanvas = getCanvas(canvas);
1950
1978
  child.__render(maskCanvas, options);
1951
1979
  }
1952
- if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1953
1980
  continue;
1954
1981
  }
1955
1982
  const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
@@ -1,2 +1,2 @@
1
- import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,isUndefined as n,DataHelper as a,canvasSizeAttrs as o,ResizeEvent as r,canvasPatch as l,FileHelper as d,Creator as h,LeaferImage as c,defineKey as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as S,LayoutEvent as k,Run as B,ImageManager as R,isObject as E,BoundsHelper as L,Matrix as A,getMatrixData as C,MatrixHelper as O,MathHelper as T,AlignHelper as W,PointHelper as M,ImageEvent as D,AroundHelper as P,Direction4 as I,isNumber as z}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as F,Paint as U,ColorConvert as V,PaintGradient as Y,Export as G,Effect as N,Group as X,TextConvert as j}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const q=t.get("LeaferCanvas");class H extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else q.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;if(this.unreal){const{config:t,autoWidthStr:e,autoHeightStr:i}=this;t.width?(n(e)&&(this.autoWidthStr=s.width||""),s.width=t.width+"px"):n(e)||(s.width=e),t.height?(n(i)&&(this.autoHeightStr=s.height||""),s.height=t.height+"px"):n(i)||(s.height=i)}else s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),q.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:o}=this.autoBounds.getBoundsFrom(t),r={width:a,height:o,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};a.copyAttrs(e,this,o),this.resize(t),this.resizeListener&&!n(this.width)&&this.resizeListener(new r(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),this.stopListenPixelRatio(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype);const{mineType:Q,fileType:Z}=d;function $(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=Q(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,Q(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q(Z(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise(i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()}),loadImage:t=>new Promise((e,s)=>{const n=new i.origin.Image,{crossOrigin:a}=i.image;a&&(n.setAttribute("crossOrigin",a),n.crossOrigin=a),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}),Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=h.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(h,{canvas:(t,e)=>new H(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},u(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:J}=navigator;J.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),J.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):J.indexOf("Mac")>-1?i.os="Mac":J.indexOf("Linux")>-1&&(i.os="Linux");class K{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new f;return this.__updatedList.list.forEach(e=>{e.leafer&&t.add(e)}),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new f,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(p.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===g.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:tt,updateBounds:et,updateChange:it}=m,{pushAllChildBranch:st,pushAllParent:nt}=y;const{worldBounds:at}=v;class ot{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,at)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,at),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:rt,updateAllChange:lt}=m,dt=t.get("Layouter");class ht{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new S,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(k.START),this.layoutOnce(),t.emitEvent(new k(k.END,this.layoutedBlocks,this.times))}catch(t){dt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?dt.warn("layouting"):this.times>3?dt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=B.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:a,AFTER:o}=k,r=this.getBlocks(s);r.forEach(t=>t.setBefore()),i.emitEvent(new k(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach(t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(t,e)))})}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach(n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||et(s[t])}et(i)}})}(this.__levelList),function(t){t.list.forEach(it)}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach(t=>t.setAfter()),i.emitEvent(new k(a,r,this.times)),i.emitEvent(new k(o,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,B.end(e)}fullLayout(){const t=B.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=k,a=this.getBlocks(new f(e));e.emitEvent(new k(i,a,this.times)),ht.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new k(s,a,this.times)),e.emitEvent(new k(n,a,this.times)),this.addBlocks(a),B.end(t)}static fullLayout(t){rt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),lt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ot([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ot(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[k.REQUEST,this.layout,this],[k.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ct=t.get("Renderer");class ut{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:120},this.target=t,this.canvas=e,i&&(this.config=a.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(k.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ct.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ct.error(t)}ct.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ct.warn("rendering");if(this.times>3)return ct.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=B.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ut.clipSpread).ceil(),i.clearWorld(s),i.clipWorld(s),this.__render(s,n),i.restore(),B.end(e)}fullRender(){const t=B.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),B.end(t)}__render(e,s){const{canvas:n}=this,a=e.includes(this.target.__world),o=a?{includes:a}:{bounds:e,includes:a};this.needFill&&n.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(n,e),i.render(this.target,n,o),this.renderBounds=s=s||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),n.updateRender(s)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);const e=this.requestTime=Date.now(),s=()=>{const t=1e3/(Date.now()-e),{maxFPS:n}=this.config;if(n&&t>n-.5)return i.requestRender(s);this.FPS=Math.min(120,Math.ceil(t)),this.requestTime=0,this.checkRender()};i.requestRender(s)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new x(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map(t=>{let e;t.updatedList&&t.updatedList.list.some(t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||ct.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e)),this.addBlock(e?this.canvas.bounds:t.updatedBounds)})}emitRender(t,e,i){this.target.emitEvent(new p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[k.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[r.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function ft(t,e){const i=t.__,{rows:s,decorationY:n}=i.__textDrawData;let a;i.__isPlacehold&&i.placeholderColor&&(e.fillStyle=i.placeholderColor);for(let t=0,i=s.length;t<i;t++)a=s[t],a.text?e.fillText(a.text,a.x,a.y):a.data&&a.data.forEach(t=>{e.fillText(t.char,t.x,a.y)});if(n){const{decorationColor:t,decorationHeight:a}=i.__textDrawData;t&&(e.fillStyle=t),s.forEach(t=>n.forEach(i=>e.fillRect(t.x,t.y+i,t.width,a)))}}function pt(t,e){t.__.__font?ft(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function gt(t,e,i){switch(e.__.strokeAlign){case"center":_t(t,1,e,i);break;case"inside":wt(t,"inside",e,i);break;case"outside":e.__.__fillAfterStroke?_t(t,2,e,i):wt(t,"outside",e,i)}}function _t(t,e,i,s){const n=i.__;E(t)?yt(t,e,!0,i,s):(s.setStroke(t,n.__strokeWidth*e,n),mt(i,s))}function wt(t,e,i,s){const n=s.getSameCanvas(!0,!0);n.font=i.__.__font,_t(t,2,i,n),n.blendMode="outside"===e?"destination-out":"destination-in",ft(i,n),n.blendMode="normal",m.copyCanvasByWorld(i,s,n),n.recycle(i.__nowWorld)}function mt(t,e){let i,s=t.__.__textDrawData;const{rows:n,decorationY:a}=s;for(let t=0,s=n.length;t<s;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach(t=>{e.strokeText(t.char,t.x,i.y)});if(a){const{decorationHeight:t}=s;n.forEach(i=>a.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}}function yt(t,e,i,s,n){let a;const o=s.__,{__hasMultiStrokeStyle:r}=o;r||n.setStroke(void 0,o.__strokeWidth*e,o);for(let l=0,d=t.length;l<d;l++)if(a=t[l],(!a.image||!F.checkImage(s,n,a,!1))&&a.style){if(r){const{strokeStyle:t}=a;t?n.setStroke(a.style,o.__getRealStrokeWidth(t)*e,o,t):n.setStroke(a.style,o.__strokeWidth*e,o)}else n.strokeStyle=a.style;a.blendMode?(n.saveBlendMode(a.blendMode),i?mt(s,n):n.stroke(),n.restoreBlendMode()):i?mt(s,n):n.stroke()}}function vt(t,e,i){const s=e.__;if(s.__strokeWidth)if(s.__font)gt(t,e,i);else switch(s.strokeAlign){case"center":xt(t,1,e,i);break;case"inside":!function(t,e,i){i.save(),i.clipUI(e),xt(t,2,e,i),i.restore()}(t,e,i);break;case"outside":!function(t,e,i){const s=e.__;if(s.__fillAfterStroke)xt(t,2,e,i);else{const{renderBounds:n}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),xt(t,2,e,a),a.clipUI(s),a.clearWorld(n),m.copyCanvasByWorld(e,i,a),a.recycle(e.__nowWorld)}}(t,e,i)}}function xt(t,e,i,s){const n=i.__;E(t)?yt(t,e,!1,i,s):(s.setStroke(t,n.__strokeWidth*e,n),s.stroke()),n.__useArrow&&U.strokeArrow(t,i,s)}ut.clipSpread=10,Object.assign(h,{watcher:(t,e)=>new K(t,e),layouter:(t,e)=>new ht(t,e),renderer:(t,e,i)=>new ut(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=ht.fullLayout,i.render=function(t,e,i){const s=Object.assign(Object.assign({},i),{topRendering:!0});i.topList=new f,t.__render(e,i),i.topList.length&&i.topList.forEach(t=>t.__render(e,s))};const{getSpread:bt,getOuterOf:St,getByMove:kt,getIntersectData:Bt}=L;let Rt;const{stintSet:Et}=a,{hasTransparent:Lt}=V;function At(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let a;const{boxBounds:o}=i.__layout;switch(e.type){case"image":a=F.image(i,t,e,o,!Rt||!Rt[e.url]);break;case"linear":a=Y.linearGradient(e,o);break;case"radial":a=Y.radialGradient(e,o);break;case"angular":a=Y.conicGradient(e,o);break;case"solid":const{type:s,color:r,opacity:l}=e;a={type:s,style:V.string(r,l)};break;default:n(e.r)||(a={type:"solid",style:V.string(e)})}if(a){if(s(a.style)&&Lt(a.style)&&(a.isTransparent=!0),e.style){if(0===e.style.strokeWidth)return;a.strokeStyle=e.style}e.editing&&(a.editing=e.editing),e.blendMode&&(a.blendMode=e.blendMode)}return a}const Ct={compute:function(t,e){const i=e.__,s=[];let n,a,o,r=i.__input[t];b(r)||(r=[r]),Rt=F.recycleImage(t,i);for(let i,n=0,a=r.length;n<a;n++)(i=At(t,r[n],e))&&(s.push(i),i.strokeStyle&&(o||(o=1),i.strokeStyle.strokeWidth&&(o=Math.max(o,i.strokeStyle.strokeWidth))));i["_"+t]=s.length?s:void 0,s.length&&s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Et(i,"__isAlphaPixelFill",n),Et(i,"__isTransparentFill",a)):(Et(i,"__isAlphaPixelStroke",n),Et(i,"__isTransparentStroke",a),Et(i,"__hasMultiStrokeStyle",o))},fill:function(t,e,i){i.fillStyle=t,pt(e,i)},fills:function(t,e,i){let s;for(let n=0,a=t.length;n<a;n++){if(s=t[n],s.image){if(F.checkImage(e,i,s,!e.__.__font))continue;if(!s.style){!n&&s.image.isPlacehold&&e.drawImagePlaceholder(i,s.image);continue}}if(i.fillStyle=s.style,s.transform||s.scaleFixed){if(i.save(),s.transform&&i.transform(s.transform),s.scaleFixed){const{scaleX:t,scaleY:n}=e.getRenderScaleData(!0);(!0===s.scaleFixed||"zoom-in"===s.scaleFixed&&t>1&&n>1)&&i.scale(1/t,1/n)}s.blendMode&&(i.blendMode=s.blendMode),pt(e,i),i.restore()}else s.blendMode?(i.saveBlendMode(s.blendMode),pt(e,i),i.restoreBlendMode()):pt(e,i)}},fillPathOrText:pt,fillText:ft,stroke:vt,strokes:function(t,e,i){vt(t,e,i)},strokeText:gt,drawTextStroke:mt,shape:function(t,e,s){const n=e.getSameCanvas(),a=t.__nowWorld,o=e.bounds;let r,l,d,h,c,{scaleX:u,scaleY:f}=t.getRenderScaleData(!0);if(o.includes(a))c=n,r=h=a;else{const{renderShapeSpread:n}=t.__layout;let p;if(i.fullImageShadow)p=a;else{const t=n?bt(o,u===f?n*u:[n*f,n*u]):o;p=Bt(t,a)}d=o.getFitMatrix(p);let{a:g,d:_}=d;d.a<1&&(c=e.getSameCanvas(),t.__renderShape(c,s),u*=g,f*=_),h=St(a,d),r=kt(h,-d.e,-d.f);const w=s.matrix;w?(l=new A(d),l.multiply(w),g*=w.scaleX,_*=w.scaleY):l=d,l.withScale(g,_),s=Object.assign(Object.assign({},s),{matrix:l})}return t.__renderShape(n,s),{canvas:n,matrix:l,fitMatrix:d,bounds:r,worldCanvas:c,shapeBounds:h,scaleX:u,scaleY:f}}};let Ot={},Tt=C();const{get:Wt,rotateOfOuter:Mt,translate:Dt,scaleOfOuter:Pt,multiplyParent:It,scale:zt,rotate:Ft,skew:Ut}=O;function Vt(t,e,i,s,n,a,o){const r=Wt();Dt(r,e.x+i,e.y+s),zt(r,n,a),o&&Mt(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r}function Yt(t,e,i,s,n,a,o,r,l){const d=Wt();Nt(d,e,i,s,n,a,o,r),l&&(Tt.a=e.width/l.width,Tt.d=e.height/l.height,It(d,Tt)),t.transform=d}function Gt(t,e,i,s,n,a,o,r,l,d,h,c){const u=Wt();if(c)Nt(u,e,n,a,o,r,l,d);else{if(l)if("center"===h)Mt(u,{x:i/2,y:s/2},l);else switch(Ft(u,l),l){case 90:Dt(u,s,0);break;case 180:Dt(u,i,s);break;case 270:Dt(u,0,i)}Ot.x=e.x+n,Ot.y=e.y+a,Dt(u,Ot.x,Ot.y),o&&Pt(u,Ot,o,r)}t.transform=u}function Nt(t,e,i,s,n,a,o,r){o&&Ft(t,o),r&&Ut(t,r.x,r.y),n&&zt(t,n,a),Dt(t,e.x+i,e.y+s)}const{get:Xt,translate:jt}=O,qt=new x,Ht={},Qt={};function Zt(t,e,i,s){const{changeful:n,sync:a,scaleFixed:o}=i;n&&(t.changeful=n),a&&(t.sync=a),o&&(t.scaleFixed=o),t.data=$t(i,s,e)}function $t(t,e,i){t.padding&&(e=qt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");let{width:n,height:a}=i;const{opacity:o,mode:r,align:l,offset:d,scale:h,size:c,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:w}=t,m=e.width===n&&e.height===a,y={mode:r},v="center"!==l&&(u||0)%180==90;let x,b;switch(L.set(Qt,0,0,v?a:n,v?n:a),r&&"cover"!==r&&"fit"!==r?((h||c)&&(T.getScaleData(h,c,i,Ht),x=Ht.scaleX,b=Ht.scaleY),(l||_||g)&&(x&&L.scale(Qt,x,b,!0),l&&W.toPoint(l,Qt,e,Qt,!0,!0))):m&&!u||(x=b=L.getFitScale(e,Qt,"fit"!==r),L.put(e,i,l,x,!1,Qt),L.scale(Qt,x,b,!0)),d&&M.move(Qt,d),r){case"stretch":m||(n=e.width,a=e.height);break;case"normal":case"clip":(Qt.x||Qt.y||x||p||u||f)&&Yt(y,e,Qt.x,Qt.y,x,b,u,f,t.clipSize);break;case"repeat":(!m||x||u||f)&&Gt(y,e,n,a,Qt.x,Qt.y,x,b,u,f,l,t.freeTransform),g||(y.repeat="repeat");const i=E(g);(_||i)&&(y.gap=function(t,e,i,s,n){let a,o;E(t)?(a=t.x,o=t.y):a=o=t;return{x:Jt(a,i,n.width,e&&e.x),y:Jt(o,s,n.height,e&&e.y)}}(_,i&&g,Qt.width,Qt.height,e));break;default:x&&Vt(y,e,Qt.x,Qt.y,x,b,u)}return y.transform||(e.x||e.y)&&(y.transform=Xt(),jt(y.transform,e.x,e.y)),x&&"stretch"!==r&&(y.scaleX=x,y.scaleY=b),y.width=n,y.height=a,o&&(y.opacity=o),w&&(y.filters=w),g&&(y.repeat=s(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),y}function Jt(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let Kt,te=new x;const{isSame:ee}=L;function ie(t,e,i,s,n,a){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Zt(n,s,i,a),!0}function se(t,e){oe(t,D.LOAD,e)}function ne(t,e){oe(t,D.LOADED,e)}function ae(t,e,i){e.error=i,t.forceUpdate("surface"),oe(t,D.ERROR,e)}function oe(t,e,i){t.hasEvent(e)&&t.emitEvent(new D(e,i))}function re(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:le,scale:de,copy:he}=O,{floor:ce,ceil:ue,max:fe,abs:pe}=Math;function ge(t,e,s){let{scaleX:n,scaleY:a}=t.getRenderScaleData(!0,e.scaleFixed);const o=n+"-"+a+"-"+s;if(e.patternId===o||t.destroyed)return!1;{const{image:r,data:l}=e;let d,h,{width:c,height:u,scaleX:f,scaleY:p,transform:g,repeat:_,gap:w}=l;n*=s,a*=s,f&&(f=pe(f),p=pe(p),h=le(),he(h,g),de(h,1/f,1/p),n*=f,a*=p),c*=n,u*=a;const m=c*u;if(!_&&m>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(r.isSVG){const t=c/r.width;t>1&&(d=t/ue(t))}else{const t=r.width*r.height;y>t&&(y=t)}m>y&&(d=Math.sqrt(m/y)),d&&(n/=d,a/=d,c/=d,u/=d),f&&(n/=f,a/=p);const v=w&&w.x*n,x=w&&w.y*a;if(g||1!==n||1!==a){const t=c+(v||0),e=u+(x||0);n/=t/fe(ce(t),1),a/=e/fe(ce(e),1),h||(h=le(),g&&he(h,g)),de(h,1/n,1/a)}const b=r.getCanvas(c,u,l.opacity,l.filters,v,x,t.leafer&&t.leafer.config.smooth),S=r.getPattern(b,_||i.origin.noRepeat||"no-repeat",h,e);return e.style=S,e.patternId=o,!0}}function _e(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const we={image:function(t,e,i,s,n){let a,o;const r=R.get(i);return Kt&&i===Kt.paint&&ee(s,Kt.boxBounds)?a=Kt.leafPaint:(a={type:i.type,image:r},r.hasAlphaPixel&&(a.isTransparent=!0),Kt=r.use>1?{leafPaint:a,paint:i,boxBounds:te.set(s)}:null),(n||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(ie(t,e,i,r,a,s),n&&(se(t,o),ne(t,o))):r.error?n&&ae(t,o,r.error):(n&&(re(t,!0),se(t,o)),a.loadId=r.load(()=>{re(t,!1),t.destroyed||(ie(t,e,i,r,a,s)&&(r.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),ne(t,o)),a.loadId=void 0},e=>{re(t,!1),ae(t,o,e),a.loadId=void 0}),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{r.ready||(r.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):r.isPlacehold=!0)),a},checkImage:function(t,e,s,n){const{scaleX:a,scaleY:o}=t.getRenderScaleData(!0,s.scaleFixed),{pixelRatio:l}=e,{data:d}=s;if(!d||s.patternId===a+"-"+o+"-"+l&&!G.running)return!1;if(n)if(d.repeat)n=!1;else if(!(s.changeful||"miniapp"===i.name&&r.isResizing(t)||G.running)){let{width:t,height:e}=d;t*=a*l,e*=o*l,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),n=t*e>i.image.maxCacheSize}return n?(t.__.__isFastShadow&&(e.fillStyle=s.style||"#000",e.fill()),function(t,e,i,s){e.save(),e.clipUI(t),i.blendMode&&(e.blendMode=i.blendMode);s.opacity&&(e.opacity*=s.opacity);s.transform&&e.transform(s.transform);e.drawImage(i.image.getFull(s.filters),0,0,s.width,s.height),e.restore()}(t,e,s,d),!0):(!s.style||s.sync||G.running?ge(t,s,l):s.patternTask||(s.patternTask=R.patternTasker.add(()=>_e(this,void 0,void 0,function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ge(t,s,l),t.forceUpdate("surface")}),300)),!1)},createPattern:ge,recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,o,r;for(let l=0,d=i.length;l<d;l++)s=i[l],n=s.image,r=n&&n.url,r&&(a||(a={}),a[r]=!0,R.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],b(o)||(o=[o])),n.unload(i[l].loadId,!o.some(t=>t.url===r))));return a}return null},createData:Zt,getPatternData:$t,fillOrFitMode:Vt,clipMode:Yt,repeatMode:Gt},{toPoint:me}=P,{hasTransparent:ye}=V,ve={},xe={};function be(t,e,i,n){if(i){let a,o,r,l;for(let t=0,d=i.length;t<d;t++)a=i[t],s(a)?(r=t/(d-1),o=V.string(a,n)):(r=a.offset,o=V.string(a.color,n)),e.addColorStop(r,o),!l&&ye(o)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:Se,getDistance:ke}=M,{get:Be,rotateOfOuter:Re,scaleOfOuter:Ee}=O,{toPoint:Le}=P,Ae={},Ce={};function Oe(t,e,i,s,n){let a;const{width:o,height:r}=t;if(o!==r||s){const t=Se(e,i);a=Be(),n?(Ee(a,e,o/r*(s||1),1),Re(a,e,t+90)):(Ee(a,e,1,o/r*(s||1)),Re(a,e,t))}return a}const{getDistance:Te}=M,{toPoint:We}=P,Me={},De={};const Pe={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:o}=t;me(s||"top",e,ve),me(n||"bottom",e,xe);const r=i.canvas.createLinearGradient(ve.x,ve.y,xe.x,xe.y),l={type:a,style:r};return be(l,r,t.stops,o),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;Le(s||"center",e,Ae),Le(n||"bottom",e,Ce);const l=i.canvas.createRadialGradient(Ae.x,Ae.y,0,Ae.x,Ae.y,ke(Ae,Ce)),d={type:a,style:l};be(d,l,t.stops,o);const h=Oe(e,Ae,Ce,r,!0);return h&&(d.transform=h),d},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;We(s||"center",e,Me),We(n||"bottom",e,De);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Me.x,Me.y):i.canvas.createRadialGradient(Me.x,Me.y,0,Me.x,Me.y,Te(Me,De)),d={type:a,style:l};be(d,l,t.stops,o);const h=Oe(e,Me,De,r||1,i.conicGradientRotate90);return h&&(d.transform=h),d},getTransform:Oe},{copy:Ie,toOffsetOutBounds:ze}=L,Fe={},Ue={};function Ve(t,e,s,n){const{bounds:a,shapeBounds:o}=n;if(i.fullImageShadow){if(Ie(Fe,t.bounds),Fe.x+=e.x-o.x,Fe.y+=e.y-o.y,s){const{fitMatrix:t}=n;Fe.x-=(a.x+(t?t.e:0)+a.width/2)*(s-1),Fe.y-=(a.y+(t?t.f:0)+a.height/2)*(s-1),Fe.width*=s,Fe.height*=s}t.copyWorld(n.canvas,t.bounds,Fe)}else s&&(Ie(Fe,e),Fe.x-=e.width/2*(s-1),Fe.y-=e.height/2*(s-1),Fe.width*=s,Fe.height*=s),t.copyWorld(n.canvas,o,s?Fe:e)}const{toOffsetOutBounds:Ye}=L,Ge={};const Ne={shadow:function(t,e,i){let s,n;const{__nowWorld:a,__layout:o}=t,{shadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ze(d,Ue),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(Ue.offsetX+r.x*c*_,Ue.offsetY+r.y*u*_,r.blur*c*_,V.string(r.color)),n=r.spread?1+2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0))*_:0,Ve(f,Ue,n,i),s=d,r.box&&(f.restore(),f.save(),l&&(f.copyWorld(f,d,a,"copy"),s=a),l?f.copyWorld(l,a,a,"destination-out"):f.copyWorld(i.canvas,h,d,"destination-out")),N.isTransformShadow(r)?N.renderTransformShadow(t,e,f,s,r):m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a,__layout:o}=t,{innerShadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Ye(d,Ge),r.forEach((r,g)=>{let _=1;if(r.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ge.offsetX+r.x*c*_,Ge.offsetY+r.y*u*_,r.blur*c*_),n=r.spread?1-2*r.spread/(o.boxBounds.width+2*(o.strokeBoxSpread||0))*_:0,Ve(f,Ge,n,i),f.restore(),l?(f.copyWorld(f,d,a,"copy"),f.copyWorld(l,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,h,d,"source-out"),s=d),f.fillWorld(s,V.string(r.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,r.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){},getShadowSpread:function(t,e){let i=0;return e.forEach(t=>i=Math.max(i,Math.max(Math.abs(t.y),Math.abs(t.x))+(t.spread>0?t.spread:0)+1.5*t.blur)),i},isTransformShadow(t){}},{excludeRenderBounds:Xe}=v;let je;function qe(t,e,i,s,n,a,o,r){switch(e){case"grayscale":je||(je=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const o=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,o),a&&s.recycle(o);Qe(t,e,i,1,n,a)}(t,i,s,n,o,r);break;case"opacity-path":Qe(t,i,s,a,o,r);break;case"path":r&&i.restore()}}function He(t){return t.getSameCanvas(!1,!0)}function Qe(t,e,i,s,n,a){const o=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,o,void 0,n),a?i.recycle(o):i.clearWorld(o)}X.prototype.__renderMask=function(t,e){let i,s,n,a,o,r;const{children:l}=this;for(let d=0,h=l.length;d<h;d++){if(i=l[d],r=i.__.mask,r){o&&(qe(this,o,t,n,s,a,void 0,!0),s=n=null),a=i.__.opacity,je=!1,"path"===r||"clipping-path"===r?(a<1?(o="opacity-path",n||(n=He(t))):(o="path",t.save()),i.__clip(n||t,e)):(o="grayscale"===r?"grayscale":"alpha",s||(s=He(t)),n||(n=He(t)),i.__render(s,e)),"clipping"!==r&&"clipping-path"!==r||Xe(i,e)||i.__render(t,e);continue}const h=1===a&&i.__.__blendMode;h&&qe(this,o,t,n,s,a,void 0,!1),Xe(i,e)||i.__render(n||t,e),h&&qe(this,o,t,n,s,a,h,!1)}qe(this,o,t,n,s,a,void 0,!0)};const Ze=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",$e=Ze+"_#~&*+\\=|≮≯≈≠=…",Je=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map(([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`).join("|"));function Ke(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const ti=Ke("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ei=Ke("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ii=Ke(Ze),si=Ke($e),ni=Ke("- —/~|┆·");var ai;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(ai||(ai={}));const{Letter:oi,Single:ri,Before:li,After:di,Symbol:hi,Break:ci}=ai;function ui(t){return ti[t]?oi:ni[t]?ci:ei[t]?li:ii[t]?di:si[t]?hi:Je.test(t)?ri:oi}const fi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function pi(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:gi}=fi,{Letter:_i,Single:wi,Before:mi,After:yi,Symbol:vi,Break:xi}=ai;let bi,Si,ki,Bi,Ri,Ei,Li,Ai,Ci,Oi,Ti,Wi,Mi,Di,Pi,Ii,zi,Fi=[];function Ui(t,e){Ci&&!Ai&&(Ai=Ci),bi.data.push({char:t,width:e}),ki+=e}function Vi(){Bi+=ki,bi.width=ki,Si.words.push(bi),bi={data:[]},ki=0}function Yi(){Di&&(Pi.paraNumber++,Si.paraStart=!0,Di=!1),Ci&&(Si.startCharSize=Ai,Si.endCharSize=Ci,Ai=0),Si.width=Bi,Ii.width?gi(Si):zi&&Gi(),Fi.push(Si),Si={words:[]},Bi=0}function Gi(){Bi>(Pi.maxWidth||0)&&(Pi.maxWidth=Bi)}const{top:Ni,right:Xi,bottom:ji,left:qi}=I;function Hi(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Qi={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:l,__font:d,__padding:h}=e;h&&(o?(n=h[qi],o-=h[Xi]+h[qi]):e.autoSizeAlign||(n=h[qi]),r?(a=h[Ni],r-=h[Ni]+h[ji]):e.autoSizeAlign||(a=h[Ni]));const c={bounds:{x:n,y:a,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,s){Pi=t,Fi=t.rows,Ii=t.bounds,zi=!Ii.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:o}=s,{canvas:r}=i,{width:l,height:d}=Ii;if(l||d||n||"none"!==o){const t="none"!==s.textWrap,i="break"===s.textWrap;Di=!0,Ti=null,Ai=Li=Ci=ki=Bi=0,bi={data:[]},Si={words:[]},n&&(e=[...e]);for(let s=0,d=e.length;s<d;s++)Ei=e[s],"\n"===Ei?(ki&&Vi(),Si.paraEnd=!0,Yi(),Di=!0):(Oi=ui(Ei),Oi===_i&&"none"!==o&&(Ei=pi(Ei,o,!ki)),Li=r.measureText(Ei).width,n&&(n<0&&(Ci=Li),Li+=n),Wi=Oi===wi&&(Ti===wi||Ti===_i)||Ti===wi&&Oi!==yi,Mi=!(Oi!==mi&&Oi!==wi||Ti!==vi&&Ti!==yi),Ri=Di&&a?l-a:l,t&&l&&Bi+ki+Li>Ri&&(i?(ki&&Vi(),Bi&&Yi()):(Mi||(Mi=Oi===_i&&Ti==yi),Wi||Mi||Oi===xi||Oi===mi||Oi===wi||ki+Li>Ri?(ki&&Vi(),Bi&&Yi()):Bi&&Yi()))," "===Ei&&!0!==Di&&Bi+ki===0||(Oi===xi?(" "===Ei&&ki&&Vi(),Ui(Ei,Li),Vi()):Wi||Mi?(ki&&Vi(),Ui(Ei,Li)):Ui(Ei,Li)),Ti=Oi);ki&&Vi(),Bi&&Yi(),Fi.length>0&&(Fi[Fi.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{Pi.paraNumber++,Bi=r.measureText(t).width,Fi.push({x:a||0,text:t,width:Bi,paraStart:!0}),zi&&Gi()})}(c,t,e),h&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":Hi(e,"x",t[qi]);break;case"right":Hi(e,"x",-t[Xi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Hi(e,"y",t[Ni]);break;case"bottom":Hi(e,"y",-t[ji])}}(h,c,e,o,r),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:o,__letterSpacing:r,__clipText:l,textAlign:d,verticalAlign:h,paraSpacing:c,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(c?c*(t.paraNumber-1):0),m=o;if(l&&w>_)w=Math.max(_,a),n>1&&(t.overflow=n);else if(_||u)switch(h){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let o=0,h=n;o<h;o++){if(y=i[o],y.x=f,y.width<g||y.width>g&&!l)switch(d){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&c&&o>0&&(m+=c),y.y=m,m+=a,t.overflow>o&&m>w&&(y.isOverflow=!0,t.overflow=o+1),v=y.x,x=y.width,r<0&&(y.width<0?(x=-y.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(c,e),function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,letterSpacing:o}=e;let r,l,d,h,c,u;s.forEach(t=>{t.words&&(d=a&&t.paraStart?a:0,u=t.words.length,l=i&&("justify"===n||"both"===n)&&u>1?(i-t.width-d)/(u-1):0,h=o||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!o&&(t.textMode=!0),2===h?(t.x+=d,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=d,r=t.x,t.data=[],t.words.forEach((e,i)=>{1===h?(c={char:"",x:r},r=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,r,c),(t.isOverflow||" "!==c.char)&&t.data.push(c)):r=function(t,e,i,s){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width}),e}(e.data,r,t.data,t.isOverflow),!l||t.paraEnd&&"both"!==n||i===u-1||(r+=l,t.width+=l)})),t.words=null)})}(c,e,o),c.overflow&&function(t,e,s,n){if(!n)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=e;if(a.splice(o),r&&"show"!==r){let t,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?i.canvas.measureText(r).width:0,h=s+n-d;("none"===e.textWrap?a:[a[o-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<h));s--){if(l<h&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=d,e.data.push({char:r,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(c,e,n,o),"none"!==l&&function(t,e){let i,s=0;const{fontSize:n,textDecoration:a}=e;switch(t.decorationHeight=n/11,E(a)?(i=a.type,a.color&&(t.decorationColor=V.string(a.color)),a.offset&&(s=Math.min(.3*n,Math.max(a.offset,.15*-n)))):i=a,i){case"under":t.decorationY=[.15*n+s];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n+s,.35*-n]}}(c,e),c}};const Zi={string:function(t,e){const i=z(e)&&e<1;if(s(t)){if(!i||!V.object)return t;t=V.object(t)}let a=n(t.a)?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}};Object.assign(j,Qi),Object.assign(V,Zi),Object.assign(U,Ct),Object.assign(F,we),Object.assign(Y,Pe),Object.assign(N,Ne),$();export{ht as Layouter,H as LeaferCanvas,ut as Renderer,K as Watcher,$ as useCanvas};
1
+ import{Debug as t,LeaferCanvasBase as e,Platform as i,isString as s,isUndefined as n,DataHelper as a,canvasSizeAttrs as o,ResizeEvent as r,canvasPatch as l,FileHelper as d,Creator as h,LeaferImage as c,defineKey as u,LeafList as f,RenderEvent as p,ChildEvent as g,WatchEvent as _,PropertyEvent as w,LeafHelper as m,BranchHelper as y,LeafBoundsHelper as v,Bounds as x,isArray as b,LeafLevelList as S,LayoutEvent as B,Run as k,ImageManager as R,isObject as E,BoundsHelper as L,FourNumberHelper as A,Matrix as O,getMatrixData as C,MatrixHelper as T,MathHelper as W,AlignHelper as D,PointHelper as P,ImageEvent as M,AroundHelper as I,Direction4 as z,isNumber as F}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as U,Paint as V,ColorConvert as Y,PaintGradient as G,Export as N,Group as X,TextConvert as q,Effect as j}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const H=t.get("LeaferCanvas");class Q extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.display="none",document.body&&document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e=s(t)?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else H.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;if(this.unreal){const{config:t,autoWidthStr:e,autoHeightStr:i}=this;t.width?(n(e)&&(this.autoWidthStr=s.width||""),s.width=t.width+"px"):n(e)||(s.width=e),t.height?(n(i)&&(this.autoHeightStr=s.height||""),s.height=t.height+"px"):n(i)||(s.height=i)}else s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){if(this.autoBounds=t,this.resizeObserver)return;try{this.resizeObserver=new ResizeObserver(t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)});const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),H.warn("no parent"))}catch(t){this.imitateResizeObserver()}this.stopListenPixelRatio()}else this.listenPixelRatio(),this.unreal&&this.updateViewSize()}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}listenPixelRatio(){this.windowListener||window.addEventListener("resize",this.windowListener=()=>{const t=i.devicePixelRatio;if(!this.config.pixelRatio&&this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}})}stopListenPixelRatio(){this.windowListener&&(window.removeEventListener("resize",this.windowListener),this.windowListener=null)}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:a,height:o}=this.autoBounds.getBoundsFrom(t),r={width:a,height:o,pixelRatio:this.config.pixelRatio?this.pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeObserver&&this.resizeObserver.disconnect(),this.resizeListener=this.resizeObserver=null}emitResize(t){const e={};a.copyAttrs(e,this,o),this.resize(t),this.resizeListener&&!n(this.width)&&this.resizeListener(new r(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),this.stopListenPixelRatio(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}l(CanvasRenderingContext2D.prototype),l(Path2D.prototype);const{mineType:Z,fileType:$}=d;function J(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>{const s=Z(e),n=t.toDataURL(s,i);return"image/bmp"===s?n.replace("image/png;","image/bmp;"):n},canvasToBolb:(t,e,i)=>new Promise(s=>t.toBlob(s,Z(e),i)),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Z($(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise(i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()}),loadImage:t=>new Promise((e,s)=>{const n=new i.origin.Image,{crossOrigin:a}=i.image;a&&(n.setAttribute("crossOrigin",a),n.crossOrigin=a),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}),Image:Image,PointerEvent:PointerEvent,DragEvent:DragEvent},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=h.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(h,{canvas:(t,e)=>new Q(t,e),image:t=>new c(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},u(i,"devicePixelRatio",{get:()=>devicePixelRatio});const{userAgent:K}=navigator;K.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):(/iPhone|iPad|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent))&&(i.fullImageShadow=!0),K.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):K.indexOf("Mac")>-1?i.os="Mac":K.indexOf("Linux")>-1&&(i.os="Linux");class tt{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new f;return this.__updatedList.list.forEach(e=>{e.leafer&&t.add(e)}),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new f,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(p.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===g.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new _(_.DATA,{updatedList:this.updatedList})),this.__updatedList=new f,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[w.CHANGE,this.__onAttrChange,this],[[g.ADD,g.REMOVE],this.__onChildEvent,this],[_.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:et,updateBounds:it,updateChange:st}=m,{pushAllChildBranch:nt,pushAllParent:at}=y;const{worldBounds:ot}=v;class rt{constructor(t){this.updatedBounds=new x,this.beforeBounds=new x,this.afterBounds=new x,b(t)&&(t=new f(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,ot)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,ot),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:lt,updateAllChange:dt}=m,ht=t.get("Layouter");class ct{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new S,this.target=t,e&&(this.config=a.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:t}=this;this.times=0;try{t.emit(B.START),this.layoutOnce(),t.emitEvent(new B(B.END,this.layoutedBlocks,this.times))}catch(t){ht.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ht.warn("layouting"):this.times>3?ht.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(_.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=k.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:a,AFTER:o}=B,r=this.getBlocks(s);r.forEach(t=>t.setBefore()),i.emitEvent(new B(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach(t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),at(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),at(t,e)))})}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach(n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||it(s[t])}it(i)}})}(this.__levelList),function(t){t.list.forEach(st)}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach(t=>t.setAfter()),i.emitEvent(new B(a,r,this.times)),i.emitEvent(new B(o,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,k.end(e)}fullLayout(){const t=k.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=B,a=this.getBlocks(new f(e));e.emitEvent(new B(i,a,this.times)),ct.fullLayout(e),a.forEach(t=>{t.setAfter()}),e.emitEvent(new B(s,a,this.times)),e.emitEvent(new B(n,a,this.times)),this.addBlocks(a),k.end(t)}static fullLayout(t){lt(t,!0),t.isBranch?y.updateBounds(t):m.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new rt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new rt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[B.REQUEST,this.layout,this],[B.AGAIN,this.layoutAgain,this],[_.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ut=t.get("Renderer");class ft{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:120},this.frames=[],this.target=t,this.canvas=e,i&&(this.config=a.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(B.REQUEST)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(p.CHILD_START,t),t.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),t.emit(p.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(p.NEXT)}}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new x,ut.log(e.innerName,"---\x3e");try{this.emitRender(p.START),this.renderOnce(t),this.emitRender(p.END,this.totalBounds),R.clearRecycled()}catch(t){this.rendering=!1,ut.error(t)}ut.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ut.warn("rendering");if(this.times>3)return ut.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new x,this.renderOptions={},t)this.emitRender(p.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(p.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(p.RENDER,this.renderBounds,this.renderOptions),this.emitRender(p.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=k.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=new x(s);i.save(),s.spread(ft.clipSpread).ceil(),i.clearWorld(s),i.clipWorld(s),this.__render(s,n),i.restore(),k.end(e)}fullRender(){const t=k.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),k.end(t)}__render(e,s){const{canvas:n}=this,a=e.includes(this.target.__world),o=a?{includes:a}:{bounds:e,includes:a};this.needFill&&n.fillWorld(e,this.config.fill),t.showRepaint&&t.drawRepaint(n,e),i.render(this.target,n,o),this.renderBounds=s=s||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),n.updateRender(s)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new x;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);this.requestTime=this.frameTime||Date.now();const e=()=>{const t=1e3/((this.frameTime=Date.now())-this.requestTime),{maxFPS:s}=this.config;if(s&&t>s)return i.requestRender(e);const{frames:n}=this;n.length>30&&n.shift(),n.push(t),this.FPS=Math.round(n.reduce((t,e)=>t+e,0)/n.length),this.requestTime=0,this.checkRender()};i.requestRender(e)}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new x(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new x(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map(t=>{let e;t.updatedList&&t.updatedList.list.some(t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||ut.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e)),this.addBlock(e?this.canvas.bounds:t.updatedBounds)})}emitRender(t,e,i){this.target.emitEvent(new p(t,this.times,e,i))}__listenEvents(){this.__eventIds=[this.target.on_([[p.REQUEST,this.update,this],[B.END,this.__onLayoutEnd,this],[p.AGAIN,this.renderAgain,this],[r.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.config={},this.target=this.canvas=null)}}function pt(t,e){const i=t.__,{rows:s,decorationY:n}=i.__textDrawData;let a;i.__isPlacehold&&i.placeholderColor&&(e.fillStyle=i.placeholderColor);for(let t=0,i=s.length;t<i;t++)a=s[t],a.text?e.fillText(a.text,a.x,a.y):a.data&&a.data.forEach(t=>{e.fillText(t.char,t.x,a.y)});if(n){const{decorationColor:t,decorationHeight:a}=i.__textDrawData;t&&(e.fillStyle=t),s.forEach(t=>n.forEach(i=>e.fillRect(t.x,t.y+i,t.width,a)))}}function gt(t,e){t.__.__font?pt(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function _t(t,e,i){switch(e.__.strokeAlign){case"center":wt(t,1,e,i);break;case"inside":mt(t,"inside",e,i);break;case"outside":e.__.__fillAfterStroke?wt(t,2,e,i):mt(t,"outside",e,i)}}function wt(t,e,i,s){const n=i.__;E(t)?vt(t,e,!0,i,s):(s.setStroke(t,n.__strokeWidth*e,n),yt(i,s))}function mt(t,e,i,s){const n=s.getSameCanvas(!0,!0);n.font=i.__.__font,wt(t,2,i,n),n.blendMode="outside"===e?"destination-out":"destination-in",pt(i,n),n.blendMode="normal",m.copyCanvasByWorld(i,s,n),n.recycle(i.__nowWorld)}function yt(t,e){let i,s=t.__.__textDrawData;const{rows:n,decorationY:a}=s;for(let t=0,s=n.length;t<s;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach(t=>{e.strokeText(t.char,t.x,i.y)});if(a){const{decorationHeight:t}=s;n.forEach(i=>a.forEach(s=>e.strokeRect(i.x,i.y+s,i.width,t)))}}function vt(t,e,i,s,n){let a;const o=s.__,{__hasMultiStrokeStyle:r}=o;r||n.setStroke(void 0,o.__strokeWidth*e,o);for(let l=0,d=t.length;l<d;l++)if(a=t[l],(!a.image||!U.checkImage(s,n,a,!1))&&a.style){if(r){const{strokeStyle:t}=a;t?n.setStroke(a.style,o.__getRealStrokeWidth(t)*e,o,t):n.setStroke(a.style,o.__strokeWidth*e,o)}else n.strokeStyle=a.style;a.blendMode?(n.saveBlendMode(a.blendMode),i?yt(s,n):n.stroke(),n.restoreBlendMode()):i?yt(s,n):n.stroke()}}function xt(t,e,i){const s=e.__;if(s.__strokeWidth)if(s.__font)_t(t,e,i);else switch(s.strokeAlign){case"center":bt(t,1,e,i);break;case"inside":!function(t,e,i){i.save(),i.clipUI(e),bt(t,2,e,i),i.restore()}(t,e,i);break;case"outside":!function(t,e,i){const s=e.__;if(s.__fillAfterStroke)bt(t,2,e,i);else{const{renderBounds:n}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),bt(t,2,e,a),a.clipUI(s),a.clearWorld(n),m.copyCanvasByWorld(e,i,a),a.recycle(e.__nowWorld)}}(t,e,i)}}function bt(t,e,i,s){const n=i.__;E(t)?vt(t,e,!1,i,s):(s.setStroke(t,n.__strokeWidth*e,n),s.stroke()),n.__useArrow&&V.strokeArrow(t,i,s)}ft.clipSpread=10,Object.assign(h,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ct(t,e),renderer:(t,e,i)=>new ft(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=ct.fullLayout,i.render=function(t,e,i){const s=Object.assign(Object.assign({},i),{topRendering:!0});i.topList=new f,t.__render(e,i),i.topList.length&&i.topList.forEach(t=>t.__render(e,s))};const{getSpread:St,copyAndSpread:Bt,toOuterOf:kt,getOuterOf:Rt,getByMove:Et,move:Lt,getIntersectData:At}=L,Ot={};let Ct;const{stintSet:Tt}=a,{hasTransparent:Wt}=Y;function Dt(t,e,i){if(!E(e)||!1===e.visible||0===e.opacity)return;let a;const{boxBounds:o}=i.__layout;switch(e.type){case"image":a=U.image(i,t,e,o,!Ct||!Ct[e.url]);break;case"linear":a=G.linearGradient(e,o);break;case"radial":a=G.radialGradient(e,o);break;case"angular":a=G.conicGradient(e,o);break;case"solid":const{type:s,color:r,opacity:l}=e;a={type:s,style:Y.string(r,l)};break;default:n(e.r)||(a={type:"solid",style:Y.string(e)})}if(a){if(s(a.style)&&Wt(a.style)&&(a.isTransparent=!0),e.style){if(0===e.style.strokeWidth)return;a.strokeStyle=e.style}e.editing&&(a.editing=e.editing),e.blendMode&&(a.blendMode=e.blendMode)}return a}const Pt={compute:function(t,e){const i=e.__,s=[];let n,a,o,r=i.__input[t];b(r)||(r=[r]),Ct=U.recycleImage(t,i);for(let i,n=0,a=r.length;n<a;n++)(i=Dt(t,r[n],e))&&(s.push(i),i.strokeStyle&&(o||(o=1),i.strokeStyle.strokeWidth&&(o=Math.max(o,i.strokeStyle.strokeWidth))));i["_"+t]=s.length?s:void 0,s.length&&s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(n=!0),a=!0),"fill"===t?(Tt(i,"__isAlphaPixelFill",n),Tt(i,"__isTransparentFill",a)):(Tt(i,"__isAlphaPixelStroke",n),Tt(i,"__isTransparentStroke",a),Tt(i,"__hasMultiStrokeStyle",o))},fill:function(t,e,i){i.fillStyle=t,gt(e,i)},fills:function(t,e,i){let s;for(let n=0,a=t.length;n<a;n++){if(s=t[n],s.image){if(U.checkImage(e,i,s,!e.__.__font))continue;if(!s.style){!n&&s.image.isPlacehold&&e.drawImagePlaceholder(i,s.image);continue}}if(i.fillStyle=s.style,s.transform||s.scaleFixed){if(i.save(),s.transform&&i.transform(s.transform),s.scaleFixed){const{scaleX:t,scaleY:n}=e.getRenderScaleData(!0);(!0===s.scaleFixed||"zoom-in"===s.scaleFixed&&t>1&&n>1)&&i.scale(1/t,1/n)}s.blendMode&&(i.blendMode=s.blendMode),gt(e,i),i.restore()}else s.blendMode?(i.saveBlendMode(s.blendMode),gt(e,i),i.restoreBlendMode()):gt(e,i)}},fillPathOrText:gt,fillText:pt,stroke:xt,strokes:function(t,e,i){xt(t,e,i)},strokeText:_t,drawTextStroke:yt,shape:function(t,e,s){const n=e.getSameCanvas(),a=e.bounds,o=t.__nowWorld,r=t.__layout,l=t.__nowWorldShapeBounds||(t.__nowWorldShapeBounds={});let d,h,c,u,f,p;kt(r.strokeSpread?(Bt(Ot,r.boxBounds,r.strokeSpread),Ot):r.boxBounds,o,l);let{scaleX:g,scaleY:_}=t.getRenderScaleData(!0);if(a.includes(l))p=n,d=f=l,h=o;else{let n;if(i.fullImageShadow)n=l;else{const t=r.renderShapeSpread?St(a,A.swapAndScale(r.renderShapeSpread,g,_)):a;n=At(t,l)}u=a.getFitMatrix(n);let{a:w,d:m}=u;u.a<1&&(p=e.getSameCanvas(),t.__renderShape(p,s),g*=w,_*=m),f=Rt(l,u),d=Et(f,-u.e,-u.f),h=Rt(o,u),Lt(h,-u.e,-u.f);const y=s.matrix;y?(c=new O(u),c.multiply(y),w*=y.scaleX,m*=y.scaleY):c=u,c.withScale(w,m),s=Object.assign(Object.assign({},s),{matrix:c})}return t.__renderShape(n,s),{canvas:n,matrix:c,fitMatrix:u,bounds:d,renderBounds:h,worldCanvas:p,shapeBounds:f,scaleX:g,scaleY:_}}};let Mt={},It=C();const{get:zt,rotateOfOuter:Ft,translate:Ut,scaleOfOuter:Vt,multiplyParent:Yt,scale:Gt,rotate:Nt,skew:Xt}=T;function qt(t,e,i,s,n,a,o){const r=zt();Ut(r,e.x+i,e.y+s),Gt(r,n,a),o&&Ft(r,{x:e.x+e.width/2,y:e.y+e.height/2},o),t.transform=r}function jt(t,e,i,s,n,a,o,r,l,d){const h=zt();Qt(h,e,i,s,n,a,o,r),l&&(It.a=l,It.d=d,Yt(h,It)),t.transform=h}function Ht(t,e,i,s,n,a,o,r,l,d,h,c){const u=zt();if(c)Qt(u,e,n,a,o,r,l,d);else{if(l)if("center"===h)Ft(u,{x:i/2,y:s/2},l);else switch(Nt(u,l),l){case 90:Ut(u,s,0);break;case 180:Ut(u,i,s);break;case 270:Ut(u,0,i)}Mt.x=e.x+n,Mt.y=e.y+a,Ut(u,Mt.x,Mt.y),o&&Vt(u,Mt,o,r)}t.transform=u}function Qt(t,e,i,s,n,a,o,r){o&&Nt(t,o),r&&Xt(t,r.x,r.y),n&&Gt(t,n,a),Ut(t,e.x+i,e.y+s)}const{get:Zt,translate:$t}=T,Jt=new x,Kt={},te={};function ee(t,e,i,s){const{changeful:n,sync:a,scaleFixed:o}=i;n&&(t.changeful=n),a&&(t.sync=a),o&&(t.scaleFixed=o),t.data=ie(i,s,e)}function ie(t,e,i){t.padding&&(e=Jt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");let{width:n,height:a}=i;const{opacity:o,mode:r,align:l,offset:d,scale:h,size:c,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:w}=t,m=e.width===n&&e.height===a,y={mode:r},v="center"!==l&&(u||0)%180==90;let x,b;switch(L.set(te,0,0,v?a:n,v?n:a),r&&"cover"!==r&&"fit"!==r?((h||c)&&(W.getScaleData(h,c,i,Kt),x=Kt.scaleX,b=Kt.scaleY),(l||_||g)&&(x&&L.scale(te,x,b,!0),l&&D.toPoint(l,te,e,te,!0,!0))):m&&!u||(x=b=L.getFitScale(e,te,"fit"!==r),L.put(e,i,l,x,!1,te),L.scale(te,x,b,!0)),d&&P.move(te,d),r){case"stretch":m||(n=e.width,a=e.height);break;case"normal":case"clip":if(te.x||te.y||x||p||u||f){let t,i;p&&(t=e.width/p.width,i=e.height/p.height),jt(y,e,te.x,te.y,x,b,u,f,t,i),t&&(x=x?x*t:x,b=b?b*i:i)}break;case"repeat":(!m||x||u||f)&&Ht(y,e,n,a,te.x,te.y,x,b,u,f,l,t.freeTransform),g||(y.repeat="repeat");const i=E(g);(_||i)&&(y.gap=function(t,e,i,s,n){let a,o;E(t)?(a=t.x,o=t.y):a=o=t;return{x:se(a,i,n.width,e&&e.x),y:se(o,s,n.height,e&&e.y)}}(_,i&&g,te.width,te.height,e));break;default:x&&qt(y,e,te.x,te.y,x,b,u)}return y.transform||(e.x||e.y)&&(y.transform=Zt(),$t(y.transform,e.x,e.y)),x&&"stretch"!==r&&(y.scaleX=x,y.scaleY=b),y.width=n,y.height=a,o&&(y.opacity=o),w&&(y.filters=w),g&&(y.repeat=s(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),y}function se(t,e,i,n){const a=s(t)||n?(n?i-n*e:i%e)/((n||Math.floor(i/e))-1):t;return"auto"===t&&a<0?0:a}let ne,ae=new x;const{isSame:oe}=L;function re(t,e,i,s,n,a){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||ee(n,s,i,a),!0}function le(t,e){ce(t,M.LOAD,e)}function de(t,e){ce(t,M.LOADED,e)}function he(t,e,i){e.error=i,t.forceUpdate("surface"),ce(t,M.ERROR,e)}function ce(t,e,i){t.hasEvent(e)&&t.emitEvent(new M(e,i))}function ue(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:fe,scale:pe,copy:ge}=T,{floor:_e,ceil:we,max:me,abs:ye}=Math;function ve(t,e,s){let{scaleX:n,scaleY:a}=t.getRenderScaleData(!0,e.scaleFixed);const o=n+"-"+a+"-"+s;if(e.patternId===o||t.destroyed)return!1;{const{image:r,data:l}=e;let d,h,{width:c,height:u,scaleX:f,scaleY:p,transform:g,repeat:_,gap:w}=l;n*=s,a*=s,f&&(f=ye(f),p=ye(p),h=fe(),ge(h,g),pe(h,1/f,1/p),n*=f,a*=p),c*=n,u*=a;const m=c*u;if(!_&&m>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(r.isSVG){const t=c/r.width;t>1&&(d=t/we(t))}else{const t=r.width*r.height;y>t&&(y=t)}m>y&&(d=Math.sqrt(m/y)),d&&(n/=d,a/=d,c/=d,u/=d),f&&(n/=f,a/=p);const v=w&&w.x*n,x=w&&w.y*a;if(g||1!==n||1!==a){const t=c+(v||0),e=u+(x||0);n/=t/me(_e(t),1),a/=e/me(_e(e),1),h||(h=fe(),g&&ge(h,g)),pe(h,1/n,1/a)}const b=r.getCanvas(c,u,l.opacity,l.filters,v,x,t.leafer&&t.leafer.config.smooth),S=r.getPattern(b,_||i.origin.noRepeat||"no-repeat",h,e);return e.style=S,e.patternId=o,!0}}function xe(t,e,i,s){return new(i||(i=Promise))(function(n,a){function o(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((s=s.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const be={image:function(t,e,i,s,n){let a,o;const r=R.get(i);return ne&&i===ne.paint&&oe(s,ne.boxBounds)?a=ne.leafPaint:(a={type:i.type,image:r},r.hasAlphaPixel&&(a.isTransparent=!0),ne=r.use>1?{leafPaint:a,paint:i,boxBounds:ae.set(s)}:null),(n||r.loading)&&(o={image:r,attrName:e,attrValue:i}),r.ready?(re(t,e,i,r,a,s),n&&(le(t,o),de(t,o))):r.error?n&&he(t,o,r.error):(n&&(ue(t,!0),le(t,o)),a.loadId=r.load(()=>{ue(t,!1),t.destroyed||(re(t,e,i,r,a,s)&&(r.hasAlphaPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),de(t,o)),a.loadId=void 0},e=>{ue(t,!1),he(t,o,e),a.loadId=void 0}),t.placeholderColor&&(t.placeholderDelay?setTimeout(()=>{r.ready||(r.isPlacehold=!0,t.forceUpdate("surface"))},t.placeholderDelay):r.isPlacehold=!0)),a},checkImage:function(t,e,s,n){const{scaleX:a,scaleY:o}=t.getRenderScaleData(!0,s.scaleFixed),{pixelRatio:l}=e,{data:d}=s;if(!d||s.patternId===a+"-"+o+"-"+l&&!N.running)return!1;if(n)if(d.repeat)n=!1;else if(!(s.changeful||"miniapp"===i.name&&r.isResizing(t)||N.running)){let{width:t,height:e}=d;t*=a*l,e*=o*l,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),n=t*e>i.image.maxCacheSize}return n?(t.__.__isFastShadow&&(e.fillStyle=s.style||"#000",e.fill()),function(t,e,i,s){e.save(),e.clipUI(t),i.blendMode&&(e.blendMode=i.blendMode);s.opacity&&(e.opacity*=s.opacity);s.transform&&e.transform(s.transform);e.drawImage(i.image.getFull(s.filters),0,0,s.width,s.height),e.restore()}(t,e,s,d),!0):(!s.style||s.sync||N.running?ve(t,s,l):s.patternTask||(s.patternTask=R.patternTasker.add(()=>xe(this,void 0,void 0,function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ve(t,s,l),t.forceUpdate("surface")}),300)),!1)},createPattern:ve,recycleImage:function(t,e){const i=e["_"+t];if(b(i)){let s,n,a,o,r;for(let l=0,d=i.length;l<d;l++)s=i[l],n=s.image,r=n&&n.url,r&&(a||(a={}),a[r]=!0,R.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],b(o)||(o=[o])),n.unload(i[l].loadId,!o.some(t=>t.url===r))));return a}return null},createData:ee,getPatternData:ie,fillOrFitMode:qt,clipMode:jt,repeatMode:Ht},{toPoint:Se}=I,{hasTransparent:Be}=Y,ke={},Re={};function Ee(t,e,i,n){if(i){let a,o,r,l;for(let t=0,d=i.length;t<d;t++)a=i[t],s(a)?(r=t/(d-1),o=Y.string(a,n)):(r=a.offset,o=Y.string(a.color,n)),e.addColorStop(r,o),!l&&Be(o)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:Le,getDistance:Ae}=P,{get:Oe,rotateOfOuter:Ce,scaleOfOuter:Te}=T,{toPoint:We}=I,De={},Pe={};function Me(t,e,i,s,n){let a;const{width:o,height:r}=t;if(o!==r||s){const t=Le(e,i);a=Oe(),n?(Te(a,e,o/r*(s||1),1),Ce(a,e,t+90)):(Te(a,e,1,o/r*(s||1)),Ce(a,e,t))}return a}const{getDistance:Ie}=P,{toPoint:ze}=I,Fe={},Ue={};const Ve={linearGradient:function(t,e){let{from:s,to:n,type:a,opacity:o}=t;Se(s||"top",e,ke),Se(n||"bottom",e,Re);const r=i.canvas.createLinearGradient(ke.x,ke.y,Re.x,Re.y),l={type:a,style:r};return Ee(l,r,t.stops,o),l},radialGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;We(s||"center",e,De),We(n||"bottom",e,Pe);const l=i.canvas.createRadialGradient(De.x,De.y,0,De.x,De.y,Ae(De,Pe)),d={type:a,style:l};Ee(d,l,t.stops,o);const h=Me(e,De,Pe,r,!0);return h&&(d.transform=h),d},conicGradient:function(t,e){let{from:s,to:n,type:a,opacity:o,stretch:r}=t;ze(s||"center",e,Fe),ze(n||"bottom",e,Ue);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Fe.x,Fe.y):i.canvas.createRadialGradient(Fe.x,Fe.y,0,Fe.x,Fe.y,Ie(Fe,Ue)),d={type:a,style:l};Ee(d,l,t.stops,o);const h=Me(e,Fe,Ue,r||1,i.conicGradientRotate90);return h&&(d.transform=h),d},getTransform:Me},{copy:Ye,move:Ge,toOffsetOutBounds:Ne}=L,{max:Xe}=Math,qe={},je=new O,He={};function Qe(t,e){let i,s,n,a,o=0,r=0,l=0,d=0;return e.forEach(t=>{i=t.x||0,s=t.y||0,n=t.spread||0,a=1.5*(t.blur||0),o=Xe(o,n+a-s),r=Xe(r,n+a+i),l=Xe(l,n+a+s),d=Xe(d,n+a-i)}),o===r&&r===l&&l===d?o:[o,r,l,d]}function Ze(t,e,i,s,n,a,o){if(s.spread){const i=1+2*s.spread/t.__layout.strokeBounds.width*a*(o?-1:1);return je.set().scaleOfOuter({x:(n.x+n.width/2)*e.pixelRatio,y:(n.y+n.height/2)*e.pixelRatio},i),je}}function $e(t,e,s){const{shapeBounds:n}=s;let a,o;i.fullImageShadow?(Ye(qe,t.bounds),Ge(qe,e.x-n.x,e.y-n.y),a=t.bounds,o=qe):(a=n,o=e),t.copyWorld(s.canvas,a,o)}const{toOffsetOutBounds:Je}=L,Ke={};const ti=Qe;const ei={shadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{shadow:o}=t.__,{worldCanvas:r,bounds:l,renderBounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=o.length-1;Ne(l,He,d),o.forEach((o,g)=>{let _=1;if(o.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.setWorldShadow(He.offsetX+o.x*c*_,He.offsetY+o.y*u*_,o.blur*c*_,Y.string(o.color)),n=Ze(t,f,i,o,He,_),n&&f.setTransform(n),$e(f,He,i),n&&f.resetTransform(),s=d,o.box&&(f.restore(),f.save(),r&&(f.copyWorld(f,d,a,"copy"),s=a),r?f.copyWorld(r,a,a,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),m.copyCanvasByWorld(t,e,f,s,o.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:a}=t,{innerShadow:o}=t.__,{worldCanvas:r,bounds:l,renderBounds:d,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=o.length-1;Je(l,Ke,d),o.forEach((o,g)=>{let _=1;if(o.scaleFixed){const t=Math.abs(a.scaleX);t>1&&(_=1/t)}f.save(),f.setWorldShadow(Ke.offsetX+o.x*c*_,Ke.offsetY+o.y*u*_,o.blur*c*_),n=Ze(t,f,0,o,Ke,_,!0),n&&f.setTransform(n),$e(f,Ke,i),f.restore(),r?(f.copyWorld(f,d,a,"copy"),f.copyWorld(r,a,a,"source-out"),s=a):(f.copyWorld(i.canvas,h,l,"source-out"),s=d),f.fillWorld(s,Y.string(o.color),"source-in"),m.copyCanvasByWorld(t,e,f,s,o.blendMode),p&&g<p&&f.clearWorld(s)}),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){},getShadowRenderSpread:Qe,getShadowTransform:Ze,isTransformShadow(t){},getInnerShadowSpread:ti},{excludeRenderBounds:ii}=v;let si;function ni(t,e,i,s,n,a,o,r){switch(e){case"grayscale":si||(si=!0,n.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,i,s,n,a){const o=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,o),a&&s.recycle(o);oi(t,e,i,1,n,a)}(t,i,s,n,o,r);break;case"opacity-path":oi(t,i,s,a,o,r);break;case"path":r&&i.restore()}}function ai(t){return t.getSameCanvas(!1,!0)}function oi(t,e,i,s,n,a){const o=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,o,void 0,n),a?i.recycle(o):i.clearWorld(o)}X.prototype.__renderMask=function(t,e){let i,s,n,a,o,r;const{children:l}=this;for(let d=0,h=l.length;d<h;d++){if(i=l[d],r=i.__.mask,r){o&&(ni(this,o,t,n,s,a,void 0,!0),s=n=null),"clipping"!==r&&"clipping-path"!==r||ii(i,e)||i.__render(t,e),a=i.__.opacity,si=!1,"path"===r||"clipping-path"===r?(a<1?(o="opacity-path",n||(n=ai(t))):(o="path",t.save()),i.__clip(n||t,e)):(o="grayscale"===r?"grayscale":"alpha",s||(s=ai(t)),n||(n=ai(t)),i.__render(s,e));continue}const h=1===a&&i.__.__blendMode;h&&ni(this,o,t,n,s,a,void 0,!1),ii(i,e)||i.__render(n||t,e),h&&ni(this,o,t,n,s,a,h,!1)}ni(this,o,t,n,s,a,void 0,!0)};const ri=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",li=ri+"_#~&*+\\=|≮≯≈≠=…",di=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map(([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`).join("|"));function hi(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const ci=hi("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ui=hi("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),fi=hi(ri),pi=hi(li),gi=hi("- —/~|┆·");var _i;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(_i||(_i={}));const{Letter:wi,Single:mi,Before:yi,After:vi,Symbol:xi,Break:bi}=_i;function Si(t){return ci[t]?wi:gi[t]?bi:ui[t]?yi:fi[t]?vi:pi[t]?xi:di.test(t)?mi:wi}const Bi={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let a=n-1;a>-1&&(i=e[a].data[0]," "===i.char);a--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function ki(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Ri}=Bi,{Letter:Ei,Single:Li,Before:Ai,After:Oi,Symbol:Ci,Break:Ti}=_i;let Wi,Di,Pi,Mi,Ii,zi,Fi,Ui,Vi,Yi,Gi,Ni,Xi,qi,ji,Hi,Qi,Zi=[];function $i(t,e){Vi&&!Ui&&(Ui=Vi),Wi.data.push({char:t,width:e}),Pi+=e}function Ji(){Mi+=Pi,Wi.width=Pi,Di.words.push(Wi),Wi={data:[]},Pi=0}function Ki(){qi&&(ji.paraNumber++,Di.paraStart=!0,qi=!1),Vi&&(Di.startCharSize=Ui,Di.endCharSize=Vi,Ui=0),Di.width=Mi,Hi.width?Ri(Di):Qi&&ts(),Zi.push(Di),Di={words:[]},Mi=0}function ts(){Mi>(ji.maxWidth||0)&&(ji.maxWidth=Mi)}const{top:es,right:is,bottom:ss,left:ns}=z;function as(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const os={getDrawData:function(t,e){s(t)||(t=String(t));let n=0,a=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:l,__font:d,__padding:h}=e;h&&(o?(n=h[ns],o-=h[is]+h[ns]):e.autoSizeAlign||(n=h[ns]),r?(a=h[es],r-=h[es]+h[ss]):e.autoSizeAlign||(a=h[es]));const c={bounds:{x:n,y:a,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,s){ji=t,Zi=t.rows,Hi=t.bounds,Qi=!Hi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:a,textCase:o}=s,{canvas:r}=i,{width:l,height:d}=Hi;if(l||d||n||"none"!==o){const t="none"!==s.textWrap,i="break"===s.textWrap;qi=!0,Gi=null,Ui=Fi=Vi=Pi=Mi=0,Wi={data:[]},Di={words:[]},n&&(e=[...e]);for(let s=0,d=e.length;s<d;s++)zi=e[s],"\n"===zi?(Pi&&Ji(),Di.paraEnd=!0,Ki(),qi=!0):(Yi=Si(zi),Yi===Ei&&"none"!==o&&(zi=ki(zi,o,!Pi)),Fi=r.measureText(zi).width,n&&(n<0&&(Vi=Fi),Fi+=n),Ni=Yi===Li&&(Gi===Li||Gi===Ei)||Gi===Li&&Yi!==Oi,Xi=!(Yi!==Ai&&Yi!==Li||Gi!==Ci&&Gi!==Oi),Ii=qi&&a?l-a:l,t&&l&&Mi+Pi+Fi>Ii&&(i?(Pi&&Ji(),Mi&&Ki()):(Xi||(Xi=Yi===Ei&&Gi==Oi),Ni||Xi||Yi===Ti||Yi===Ai||Yi===Li||Pi+Fi>Ii?(Pi&&Ji(),Mi&&Ki()):Mi&&Ki()))," "===zi&&!0!==qi&&Mi+Pi===0||(Yi===Ti?(" "===zi&&Pi&&Ji(),$i(zi,Fi),Ji()):Ni||Xi?(Pi&&Ji(),$i(zi,Fi)):$i(zi,Fi)),Gi=Yi);Pi&&Ji(),Mi&&Ki(),Zi.length>0&&(Zi[Zi.length-1].paraEnd=!0)}else e.split("\n").forEach(t=>{ji.paraNumber++,Mi=r.measureText(t).width,Zi.push({x:a||0,text:t,width:Mi,paraStart:!0}),Qi&&ts()})}(c,t,e),h&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":as(e,"x",t[ns]);break;case"right":as(e,"x",-t[is])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":as(e,"y",t[es]);break;case"bottom":as(e,"y",-t[ss])}}(h,c,e,o,r),function(t,e){const{rows:i,bounds:s}=t,n=i.length,{__lineHeight:a,__baseLine:o,__letterSpacing:r,__clipText:l,textAlign:d,verticalAlign:h,paraSpacing:c,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=s,w=a*n+(c?c*(t.paraNumber-1):0),m=o;if(l&&w>_)w=Math.max(_,a),n>1&&(t.overflow=n);else if(_||u)switch(h){case"middle":p+=(_-w)/2;break;case"bottom":p+=_-w}m+=p;let y,v,x,b=g||u?g:t.maxWidth;for(let o=0,h=n;o<h;o++){if(y=i[o],y.x=f,y.width<g||y.width>g&&!l)switch(d){case"center":y.x+=(b-y.width)/2;break;case"right":y.x+=b-y.width}y.paraStart&&c&&o>0&&(m+=c),y.y=m,m+=a,t.overflow>o&&m>w&&(y.isOverflow=!0,t.overflow=o+1),v=y.x,x=y.width,r<0&&(y.width<0?(x=-y.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<s.x&&(s.x=v),x>s.width&&(s.width=x),l&&g&&g<x&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=w}(c,e),function(t,e,i){const{rows:s}=t,{textAlign:n,paraIndent:a,letterSpacing:o}=e;let r,l,d,h,c,u;s.forEach(t=>{t.words&&(d=a&&t.paraStart?a:0,u=t.words.length,l=i&&("justify"===n||"both"===n)&&u>1?(i-t.width-d)/(u-1):0,h=o||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!o&&(t.textMode=!0),2===h?(t.x+=d,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=d,r=t.x,t.data=[],t.words.forEach((e,i)=>{1===h?(c={char:"",x:r},r=function(t,e,i){return t.forEach(t=>{i.char+=t.char,e+=t.width}),e}(e.data,r,c),(t.isOverflow||" "!==c.char)&&t.data.push(c)):r=function(t,e,i,s){return t.forEach(t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width}),e}(e.data,r,t.data,t.isOverflow),!l||t.paraEnd&&"both"!==n||i===u-1||(r+=l,t.width+=l)})),t.words=null)})}(c,e,o),c.overflow&&function(t,e,s,n){if(!n)return;const{rows:a,overflow:o}=t;let{textOverflow:r}=e;if(a.splice(o),r&&"show"!==r){let t,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?i.canvas.measureText(r).width:0,h=s+n-d;("none"===e.textWrap?a:[a[o-1]]).forEach(e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],l=t.x+t.width,!(s===i&&l<h));s--){if(l<h&&" "!==t.char||!s){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=d,e.data.push({char:r,x:l}),e.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(e)}})}}(c,e,n,o),"none"!==l&&function(t,e){let i,s=0;const{fontSize:n,textDecoration:a}=e;switch(t.decorationHeight=n/11,E(a)?(i=a.type,a.color&&(t.decorationColor=Y.string(a.color)),a.offset&&(s=Math.min(.3*n,Math.max(a.offset,.15*-n)))):i=a,i){case"under":t.decorationY=[.15*n+s];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n+s,.35*-n]}}(c,e),c}};const rs={string:function(t,e){const i=F(e)&&e<1;if(s(t)){if(!i||!Y.object)return t;t=Y.object(t)}let a=n(t.a)?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}};Object.assign(q,os),Object.assign(Y,rs),Object.assign(V,Pt),Object.assign(U,be),Object.assign(G,Ve),Object.assign(j,ei),J();export{ct as Layouter,Q as LeaferCanvas,ft as Renderer,tt as Watcher,J as useCanvas};
2
2
  //# sourceMappingURL=web.esm.min.js.map