@leafer-ui/node 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/node.cjs CHANGED
@@ -454,6 +454,7 @@ class Renderer {
454
454
  usePartRender: true,
455
455
  maxFPS: 120
456
456
  };
457
+ this.frames = [];
457
458
  this.target = target;
458
459
  this.canvas = canvas;
459
460
  if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
@@ -606,12 +607,15 @@ class Renderer {
606
607
  const target = this.target;
607
608
  if (this.requestTime || !target) return;
608
609
  if (target.parentApp) return target.parentApp.requestRender(false);
609
- const requestTime = this.requestTime = Date.now();
610
+ this.requestTime = this.frameTime || Date.now();
610
611
  const render = () => {
611
- const nowFPS = 1e3 / (Date.now() - requestTime);
612
+ const nowFPS = 1e3 / ((this.frameTime = Date.now()) - this.requestTime);
612
613
  const {maxFPS: maxFPS} = this.config;
613
- if (maxFPS && nowFPS > maxFPS - .5) return core.Platform.requestRender(render);
614
- this.FPS = Math.min(120, Math.ceil(nowFPS));
614
+ if (maxFPS && nowFPS > maxFPS) return core.Platform.requestRender(render);
615
+ const {frames: frames} = this;
616
+ if (frames.length > 30) frames.shift();
617
+ frames.push(nowFPS);
618
+ this.FPS = Math.round(frames.reduce((a, b) => a + b, 0) / frames.length);
615
619
  this.requestTime = 0;
616
620
  this.checkRender();
617
621
  };
@@ -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} = core.BoundsHelper;
1068
+ const {getSpread: getSpread, copyAndSpread: copyAndSpread, toOuterOf: toOuterOf, getOuterOf: getOuterOf, getByMove: getByMove, move: move$1, getIntersectData: getIntersectData} = core.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 (core.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, core.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 core.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 = core.getMatrixData();
1226
+ let origin = {}, tempMatrix$1 = core.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} = core.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} = core.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);
@@ -1566,17 +1583,15 @@ function checkImage(ui, canvas, paint, allowDraw) {
1566
1583
  if (allowDraw) {
1567
1584
  if (data.repeat) {
1568
1585
  allowDraw = false;
1569
- } else {
1570
- if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1571
- let {width: width, height: height} = data;
1572
- width *= scaleX * pixelRatio;
1573
- height *= scaleY * pixelRatio;
1574
- if (data.scaleX) {
1575
- width *= data.scaleX;
1576
- height *= data.scaleY;
1577
- }
1578
- allowDraw = width * height > core.Platform.image.maxCacheSize;
1586
+ } else if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1587
+ let {width: width, height: height} = data;
1588
+ width *= scaleX * pixelRatio;
1589
+ height *= scaleY * pixelRatio;
1590
+ if (data.scaleX) {
1591
+ width *= data.scaleX;
1592
+ height *= data.scaleY;
1579
1593
  }
1594
+ allowDraw = width * height > core.Platform.image.maxCacheSize;
1580
1595
  }
1581
1596
  }
1582
1597
  if (allowDraw) {
@@ -1756,20 +1771,20 @@ const PaintGradientModule = {
1756
1771
  getTransform: getTransform
1757
1772
  };
1758
1773
 
1759
- const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper;
1774
+ const {copy: copy, move: move, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper, {max: max} = Math;
1760
1775
 
1761
- const tempBounds = {};
1776
+ const tempBounds = {}, tempMatrix = new core.Matrix;
1762
1777
 
1763
1778
  const offsetOutBounds$1 = {};
1764
1779
 
1765
1780
  function shadow(ui, current, shape) {
1766
- let copyBounds, spreadScale;
1767
- const {__nowWorld: nowWorld, __layout: __layout} = ui;
1781
+ let copyBounds, transform;
1782
+ const {__nowWorld: nowWorld} = ui;
1768
1783
  const {shadow: shadow} = ui.__;
1769
- const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1784
+ const {worldCanvas: worldCanvas, bounds: bounds, renderBounds: renderBounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1770
1785
  const other = current.getSameCanvas();
1771
1786
  const end = shadow.length - 1;
1772
- toOffsetOutBounds$1(bounds, offsetOutBounds$1);
1787
+ toOffsetOutBounds$1(bounds, offsetOutBounds$1, renderBounds);
1773
1788
  shadow.forEach((item, index) => {
1774
1789
  let otherScale = 1;
1775
1790
  if (item.scaleFixed) {
@@ -1777,54 +1792,61 @@ function shadow(ui, current, shape) {
1777
1792
  if (sx > 1) otherScale = 1 / sx;
1778
1793
  }
1779
1794
  other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, draw.ColorConvert.string(item.color));
1780
- spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1781
- drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
1782
- copyBounds = bounds;
1795
+ transform = getShadowTransform(ui, other, shape, item, offsetOutBounds$1, otherScale);
1796
+ if (transform) other.setTransform(transform);
1797
+ drawWorldShadow(other, offsetOutBounds$1, shape);
1798
+ if (transform) other.resetTransform();
1799
+ copyBounds = renderBounds;
1783
1800
  if (item.box) {
1784
1801
  other.restore();
1785
1802
  other.save();
1786
1803
  if (worldCanvas) {
1787
- other.copyWorld(other, bounds, nowWorld, "copy");
1804
+ other.copyWorld(other, renderBounds, nowWorld, "copy");
1788
1805
  copyBounds = nowWorld;
1789
1806
  }
1790
1807
  worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
1791
1808
  }
1792
- if (draw.Effect.isTransformShadow(item)) draw.Effect.renderTransformShadow(ui, current, other, copyBounds, item); else core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1809
+ core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1793
1810
  if (end && index < end) other.clearWorld(copyBounds);
1794
1811
  });
1795
1812
  other.recycle(copyBounds);
1796
1813
  }
1797
1814
 
1798
- function getShadowSpread(_ui, shadow) {
1799
- let width = 0;
1800
- 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));
1801
- return width;
1815
+ function getShadowRenderSpread(_ui, shadow) {
1816
+ let top = 0, right = 0, bottom = 0, left = 0, x, y, spread, blur;
1817
+ shadow.forEach(item => {
1818
+ x = item.x || 0, y = item.y || 0, spread = item.spread || 0, blur = (item.blur || 0) * 1.5;
1819
+ top = max(top, spread + blur - y);
1820
+ right = max(right, spread + blur + x);
1821
+ bottom = max(bottom, spread + blur + y);
1822
+ left = max(left, spread + blur - x);
1823
+ });
1824
+ return top === right && right === bottom && bottom === left ? top : [ top, right, bottom, left ];
1802
1825
  }
1803
1826
 
1804
- function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1805
- const {bounds: bounds, shapeBounds: shapeBounds} = shape;
1827
+ function getShadowTransform(ui, canvas, _shape, shadow, outBounds, otherScale, isInnerShaodw) {
1828
+ if (shadow.spread) {
1829
+ const spreadScale = 1 + shadow.spread * 2 / ui.__layout.strokeBounds.width * otherScale * (isInnerShaodw ? -1 : 1);
1830
+ tempMatrix.set().scaleOfOuter({
1831
+ x: (outBounds.x + outBounds.width / 2) * canvas.pixelRatio,
1832
+ y: (outBounds.y + outBounds.height / 2) * canvas.pixelRatio
1833
+ }, spreadScale);
1834
+ return tempMatrix;
1835
+ }
1836
+ return undefined;
1837
+ }
1838
+
1839
+ function drawWorldShadow(canvas, outBounds, shape) {
1840
+ const {shapeBounds: shapeBounds} = shape;
1841
+ let from, to;
1806
1842
  if (core.Platform.fullImageShadow) {
1807
1843
  copy(tempBounds, canvas.bounds);
1808
- tempBounds.x += outBounds.x - shapeBounds.x;
1809
- tempBounds.y += outBounds.y - shapeBounds.y;
1810
- if (spreadScale) {
1811
- const {fitMatrix: fitMatrix} = shape;
1812
- tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1813
- tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1814
- tempBounds.width *= spreadScale;
1815
- tempBounds.height *= spreadScale;
1816
- }
1817
- canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
1844
+ move(tempBounds, outBounds.x - shapeBounds.x, outBounds.y - shapeBounds.y);
1845
+ from = canvas.bounds, to = tempBounds;
1818
1846
  } else {
1819
- if (spreadScale) {
1820
- copy(tempBounds, outBounds);
1821
- tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
1822
- tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
1823
- tempBounds.width *= spreadScale;
1824
- tempBounds.height *= spreadScale;
1825
- }
1826
- canvas.copyWorld(shape.canvas, shapeBounds, spreadScale ? tempBounds : outBounds);
1847
+ from = shapeBounds, to = outBounds;
1827
1848
  }
1849
+ canvas.copyWorld(shape.canvas, from, to);
1828
1850
  }
1829
1851
 
1830
1852
  const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
@@ -1832,13 +1854,13 @@ const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
1832
1854
  const offsetOutBounds = {};
1833
1855
 
1834
1856
  function innerShadow(ui, current, shape) {
1835
- let copyBounds, spreadScale;
1836
- const {__nowWorld: nowWorld, __layout: __layout} = ui;
1857
+ let copyBounds, transform;
1858
+ const {__nowWorld: nowWorld} = ui;
1837
1859
  const {innerShadow: innerShadow} = ui.__;
1838
- const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1860
+ const {worldCanvas: worldCanvas, bounds: bounds, renderBounds: renderBounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1839
1861
  const other = current.getSameCanvas();
1840
1862
  const end = innerShadow.length - 1;
1841
- toOffsetOutBounds(bounds, offsetOutBounds);
1863
+ toOffsetOutBounds(bounds, offsetOutBounds, renderBounds);
1842
1864
  innerShadow.forEach((item, index) => {
1843
1865
  let otherScale = 1;
1844
1866
  if (item.scaleFixed) {
@@ -1847,16 +1869,17 @@ function innerShadow(ui, current, shape) {
1847
1869
  }
1848
1870
  other.save();
1849
1871
  other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
1850
- spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1851
- drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
1872
+ transform = getShadowTransform(ui, other, shape, item, offsetOutBounds, otherScale, true);
1873
+ if (transform) other.setTransform(transform);
1874
+ drawWorldShadow(other, offsetOutBounds, shape);
1852
1875
  other.restore();
1853
1876
  if (worldCanvas) {
1854
- other.copyWorld(other, bounds, nowWorld, "copy");
1877
+ other.copyWorld(other, renderBounds, nowWorld, "copy");
1855
1878
  other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
1856
1879
  copyBounds = nowWorld;
1857
1880
  } else {
1858
1881
  other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
1859
- copyBounds = bounds;
1882
+ copyBounds = renderBounds;
1860
1883
  }
1861
1884
  other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), "source-in");
1862
1885
  core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
@@ -1865,6 +1888,8 @@ function innerShadow(ui, current, shape) {
1865
1888
  other.recycle(copyBounds);
1866
1889
  }
1867
1890
 
1891
+ const getInnerShadowSpread = getShadowRenderSpread;
1892
+
1868
1893
  function blur(ui, current, origin) {
1869
1894
  const {blur: blur} = ui.__;
1870
1895
  origin.setWorldBlur(blur * ui.__nowWorld.a);
@@ -1879,10 +1904,12 @@ const EffectModule = {
1879
1904
  innerShadow: innerShadow,
1880
1905
  blur: blur,
1881
1906
  backgroundBlur: backgroundBlur,
1882
- getShadowSpread: getShadowSpread,
1907
+ getShadowRenderSpread: getShadowRenderSpread,
1908
+ getShadowTransform: getShadowTransform,
1883
1909
  isTransformShadow(_shadow) {
1884
1910
  return undefined;
1885
- }
1911
+ },
1912
+ getInnerShadowSpread: getInnerShadowSpread
1886
1913
  };
1887
1914
 
1888
1915
  const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
@@ -1899,6 +1926,7 @@ draw.Group.prototype.__renderMask = function(canvas, options) {
1899
1926
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1900
1927
  maskCanvas = contentCanvas = null;
1901
1928
  }
1929
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1902
1930
  maskOpacity = child.__.opacity;
1903
1931
  usedGrayscaleAlpha = false;
1904
1932
  if (mask === "path" || mask === "clipping-path") {
@@ -1916,7 +1944,6 @@ draw.Group.prototype.__renderMask = function(canvas, options) {
1916
1944
  if (!contentCanvas) contentCanvas = getCanvas(canvas);
1917
1945
  child.__render(maskCanvas, options);
1918
1946
  }
1919
- if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1920
1947
  continue;
1921
1948
  }
1922
1949
  const childBlendMode = maskOpacity === 1 && child.__.__blendMode;