@leafer-ui/miniapp 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/miniapp.cjs CHANGED
@@ -582,6 +582,7 @@ class Renderer {
582
582
  usePartRender: true,
583
583
  maxFPS: 120
584
584
  };
585
+ this.frames = [];
585
586
  this.target = target;
586
587
  this.canvas = canvas;
587
588
  if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
@@ -734,12 +735,15 @@ class Renderer {
734
735
  const target = this.target;
735
736
  if (this.requestTime || !target) return;
736
737
  if (target.parentApp) return target.parentApp.requestRender(false);
737
- const requestTime = this.requestTime = Date.now();
738
+ this.requestTime = this.frameTime || Date.now();
738
739
  const render = () => {
739
- const nowFPS = 1e3 / (Date.now() - requestTime);
740
+ const nowFPS = 1e3 / ((this.frameTime = Date.now()) - this.requestTime);
740
741
  const {maxFPS: maxFPS} = this.config;
741
- if (maxFPS && nowFPS > maxFPS - .5) return core.Platform.requestRender(render);
742
- this.FPS = Math.min(120, Math.ceil(nowFPS));
742
+ if (maxFPS && nowFPS > maxFPS) return core.Platform.requestRender(render);
743
+ const {frames: frames} = this;
744
+ if (frames.length > 30) frames.shift();
745
+ frames.push(nowFPS);
746
+ this.FPS = Math.round(frames.reduce((a, b) => a + b, 0) / frames.length);
743
747
  this.requestTime = 0;
744
748
  this.checkRender();
745
749
  };
@@ -1301,24 +1305,29 @@ function drawOutside(stroke, ui, canvas) {
1301
1305
  }
1302
1306
  }
1303
1307
 
1304
- const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = core.BoundsHelper;
1308
+ const {getSpread: getSpread, copyAndSpread: copyAndSpread, toOuterOf: toOuterOf, getOuterOf: getOuterOf, getByMove: getByMove, move: move$1, getIntersectData: getIntersectData} = core.BoundsHelper;
1309
+
1310
+ const tempBounds$1 = {};
1305
1311
 
1306
1312
  function shape(ui, current, options) {
1307
1313
  const canvas = current.getSameCanvas();
1308
- const nowWorld = ui.__nowWorld, currentBounds = current.bounds;
1309
- let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1314
+ const currentBounds = current.bounds, nowWorld = ui.__nowWorld, layout = ui.__layout;
1315
+ const nowWorldShapeBounds = ui.__nowWorldShapeBounds || (ui.__nowWorldShapeBounds = {});
1316
+ toOuterOf(layout.strokeSpread ? (copyAndSpread(tempBounds$1, layout.boxBounds, layout.strokeSpread),
1317
+ tempBounds$1) : layout.boxBounds, nowWorld, nowWorldShapeBounds);
1318
+ let bounds, renderBounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1310
1319
  let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
1311
- if (currentBounds.includes(nowWorld)) {
1320
+ if (currentBounds.includes(nowWorldShapeBounds)) {
1312
1321
  worldCanvas = canvas;
1313
- bounds = shapeBounds = nowWorld;
1322
+ bounds = shapeBounds = nowWorldShapeBounds;
1323
+ renderBounds = nowWorld;
1314
1324
  } else {
1315
- const {renderShapeSpread: spread} = ui.__layout;
1316
1325
  let worldClipBounds;
1317
1326
  if (core.Platform.fullImageShadow) {
1318
- worldClipBounds = nowWorld;
1327
+ worldClipBounds = nowWorldShapeBounds;
1319
1328
  } else {
1320
- const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : currentBounds;
1321
- worldClipBounds = getIntersectData(spreadBounds, nowWorld);
1329
+ const spreadBounds = layout.renderShapeSpread ? getSpread(currentBounds, core.FourNumberHelper.swapAndScale(layout.renderShapeSpread, scaleX, scaleY)) : currentBounds;
1330
+ worldClipBounds = getIntersectData(spreadBounds, nowWorldShapeBounds);
1322
1331
  }
1323
1332
  fitMatrix = currentBounds.getFitMatrix(worldClipBounds);
1324
1333
  let {a: fitScaleX, d: fitScaleY} = fitMatrix;
@@ -1328,8 +1337,10 @@ function shape(ui, current, options) {
1328
1337
  scaleX *= fitScaleX;
1329
1338
  scaleY *= fitScaleY;
1330
1339
  }
1331
- shapeBounds = getOuterOf(nowWorld, fitMatrix);
1340
+ shapeBounds = getOuterOf(nowWorldShapeBounds, fitMatrix);
1332
1341
  bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
1342
+ renderBounds = getOuterOf(nowWorld, fitMatrix);
1343
+ move$1(renderBounds, -fitMatrix.e, -fitMatrix.f);
1333
1344
  const userMatrix = options.matrix;
1334
1345
  if (userMatrix) {
1335
1346
  matrix = new core.Matrix(fitMatrix);
@@ -1348,6 +1359,7 @@ function shape(ui, current, options) {
1348
1359
  matrix: matrix,
1349
1360
  fitMatrix: fitMatrix,
1350
1361
  bounds: bounds,
1362
+ renderBounds: renderBounds,
1351
1363
  worldCanvas: worldCanvas,
1352
1364
  shapeBounds: shapeBounds,
1353
1365
  scaleX: scaleX,
@@ -1451,7 +1463,7 @@ const PaintModule = {
1451
1463
  shape: shape
1452
1464
  };
1453
1465
 
1454
- let origin = {}, tempMatrix = core.getMatrixData();
1466
+ let origin = {}, tempMatrix$1 = core.getMatrixData();
1455
1467
 
1456
1468
  const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
1457
1469
 
@@ -1466,12 +1478,12 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1466
1478
  data.transform = transform;
1467
1479
  }
1468
1480
 
1469
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
1481
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
1470
1482
  const transform = get$3();
1471
1483
  layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1472
- if (clipSize) {
1473
- tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1474
- multiplyParent(transform, tempMatrix);
1484
+ if (clipScaleX) {
1485
+ tempMatrix$1.a = clipScaleX, tempMatrix$1.d = clipScaleY;
1486
+ multiplyParent(transform, tempMatrix$1);
1475
1487
  }
1476
1488
  data.transform = transform;
1477
1489
  }
@@ -1572,7 +1584,12 @@ function getPatternData(paint, box, image) {
1572
1584
 
1573
1585
  case "normal":
1574
1586
  case "clip":
1575
- if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1587
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) {
1588
+ let clipScaleX, clipScaleY;
1589
+ if (clipSize) clipScaleX = box.width / clipSize.width, clipScaleY = box.height / clipSize.height;
1590
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
1591
+ if (clipScaleX) scaleX = scaleX ? scaleX * clipScaleX : scaleX, scaleY = scaleY ? scaleY * clipScaleY : clipScaleY;
1592
+ }
1576
1593
  break;
1577
1594
 
1578
1595
  case "repeat":
@@ -1730,7 +1747,7 @@ function ignoreRender(ui, value) {
1730
1747
 
1731
1748
  const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1732
1749
 
1733
- const {floor: floor, ceil: ceil, max: max, abs: abs} = Math;
1750
+ const {floor: floor, ceil: ceil, max: max$1, abs: abs} = Math;
1734
1751
 
1735
1752
  function createPattern(ui, paint, pixelRatio) {
1736
1753
  let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
@@ -1779,8 +1796,8 @@ function createPattern(ui, paint, pixelRatio) {
1779
1796
  if (transform || scaleX !== 1 || scaleY !== 1) {
1780
1797
  const canvasWidth = width + (xGap || 0);
1781
1798
  const canvasHeight = height + (yGap || 0);
1782
- scaleX /= canvasWidth / max(floor(canvasWidth), 1);
1783
- scaleY /= canvasHeight / max(floor(canvasHeight), 1);
1799
+ scaleX /= canvasWidth / max$1(floor(canvasWidth), 1);
1800
+ scaleY /= canvasHeight / max$1(floor(canvasHeight), 1);
1784
1801
  if (!imageMatrix) {
1785
1802
  imageMatrix = get$1();
1786
1803
  if (transform) copy$1(imageMatrix, transform);
@@ -1839,17 +1856,15 @@ function checkImage(ui, canvas, paint, allowDraw) {
1839
1856
  if (allowDraw) {
1840
1857
  if (data.repeat) {
1841
1858
  allowDraw = false;
1842
- } else {
1843
- if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1844
- let {width: width, height: height} = data;
1845
- width *= scaleX * pixelRatio;
1846
- height *= scaleY * pixelRatio;
1847
- if (data.scaleX) {
1848
- width *= data.scaleX;
1849
- height *= data.scaleY;
1850
- }
1851
- allowDraw = width * height > core.Platform.image.maxCacheSize;
1859
+ } else if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1860
+ let {width: width, height: height} = data;
1861
+ width *= scaleX * pixelRatio;
1862
+ height *= scaleY * pixelRatio;
1863
+ if (data.scaleX) {
1864
+ width *= data.scaleX;
1865
+ height *= data.scaleY;
1852
1866
  }
1867
+ allowDraw = width * height > core.Platform.image.maxCacheSize;
1853
1868
  }
1854
1869
  }
1855
1870
  if (allowDraw) {
@@ -2029,20 +2044,20 @@ const PaintGradientModule = {
2029
2044
  getTransform: getTransform
2030
2045
  };
2031
2046
 
2032
- const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper;
2047
+ const {copy: copy, move: move, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper, {max: max} = Math;
2033
2048
 
2034
- const tempBounds = {};
2049
+ const tempBounds = {}, tempMatrix = new core.Matrix;
2035
2050
 
2036
2051
  const offsetOutBounds$1 = {};
2037
2052
 
2038
2053
  function shadow(ui, current, shape) {
2039
- let copyBounds, spreadScale;
2040
- const {__nowWorld: nowWorld, __layout: __layout} = ui;
2054
+ let copyBounds, transform;
2055
+ const {__nowWorld: nowWorld} = ui;
2041
2056
  const {shadow: shadow} = ui.__;
2042
- const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
2057
+ const {worldCanvas: worldCanvas, bounds: bounds, renderBounds: renderBounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
2043
2058
  const other = current.getSameCanvas();
2044
2059
  const end = shadow.length - 1;
2045
- toOffsetOutBounds$1(bounds, offsetOutBounds$1);
2060
+ toOffsetOutBounds$1(bounds, offsetOutBounds$1, renderBounds);
2046
2061
  shadow.forEach((item, index) => {
2047
2062
  let otherScale = 1;
2048
2063
  if (item.scaleFixed) {
@@ -2050,54 +2065,61 @@ function shadow(ui, current, shape) {
2050
2065
  if (sx > 1) otherScale = 1 / sx;
2051
2066
  }
2052
2067
  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));
2053
- spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
2054
- drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
2055
- copyBounds = bounds;
2068
+ transform = getShadowTransform(ui, other, shape, item, offsetOutBounds$1, otherScale);
2069
+ if (transform) other.setTransform(transform);
2070
+ drawWorldShadow(other, offsetOutBounds$1, shape);
2071
+ if (transform) other.resetTransform();
2072
+ copyBounds = renderBounds;
2056
2073
  if (item.box) {
2057
2074
  other.restore();
2058
2075
  other.save();
2059
2076
  if (worldCanvas) {
2060
- other.copyWorld(other, bounds, nowWorld, "copy");
2077
+ other.copyWorld(other, renderBounds, nowWorld, "copy");
2061
2078
  copyBounds = nowWorld;
2062
2079
  }
2063
2080
  worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
2064
2081
  }
2065
- if (draw.Effect.isTransformShadow(item)) draw.Effect.renderTransformShadow(ui, current, other, copyBounds, item); else core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
2082
+ core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
2066
2083
  if (end && index < end) other.clearWorld(copyBounds);
2067
2084
  });
2068
2085
  other.recycle(copyBounds);
2069
2086
  }
2070
2087
 
2071
- function getShadowSpread(_ui, shadow) {
2072
- let width = 0;
2073
- 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));
2074
- return width;
2088
+ function getShadowRenderSpread(_ui, shadow) {
2089
+ let top = 0, right = 0, bottom = 0, left = 0, x, y, spread, blur;
2090
+ shadow.forEach(item => {
2091
+ x = item.x || 0, y = item.y || 0, spread = item.spread || 0, blur = (item.blur || 0) * 1.5;
2092
+ top = max(top, spread + blur - y);
2093
+ right = max(right, spread + blur + x);
2094
+ bottom = max(bottom, spread + blur + y);
2095
+ left = max(left, spread + blur - x);
2096
+ });
2097
+ return top === right && right === bottom && bottom === left ? top : [ top, right, bottom, left ];
2075
2098
  }
2076
2099
 
2077
- function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
2078
- const {bounds: bounds, shapeBounds: shapeBounds} = shape;
2100
+ function getShadowTransform(ui, canvas, _shape, shadow, outBounds, otherScale, isInnerShaodw) {
2101
+ if (shadow.spread) {
2102
+ const spreadScale = 1 + shadow.spread * 2 / ui.__layout.strokeBounds.width * otherScale * (isInnerShaodw ? -1 : 1);
2103
+ tempMatrix.set().scaleOfOuter({
2104
+ x: (outBounds.x + outBounds.width / 2) * canvas.pixelRatio,
2105
+ y: (outBounds.y + outBounds.height / 2) * canvas.pixelRatio
2106
+ }, spreadScale);
2107
+ return tempMatrix;
2108
+ }
2109
+ return undefined;
2110
+ }
2111
+
2112
+ function drawWorldShadow(canvas, outBounds, shape) {
2113
+ const {shapeBounds: shapeBounds} = shape;
2114
+ let from, to;
2079
2115
  if (core.Platform.fullImageShadow) {
2080
2116
  copy(tempBounds, canvas.bounds);
2081
- tempBounds.x += outBounds.x - shapeBounds.x;
2082
- tempBounds.y += outBounds.y - shapeBounds.y;
2083
- if (spreadScale) {
2084
- const {fitMatrix: fitMatrix} = shape;
2085
- tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
2086
- tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
2087
- tempBounds.width *= spreadScale;
2088
- tempBounds.height *= spreadScale;
2089
- }
2090
- canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
2117
+ move(tempBounds, outBounds.x - shapeBounds.x, outBounds.y - shapeBounds.y);
2118
+ from = canvas.bounds, to = tempBounds;
2091
2119
  } else {
2092
- if (spreadScale) {
2093
- copy(tempBounds, outBounds);
2094
- tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
2095
- tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
2096
- tempBounds.width *= spreadScale;
2097
- tempBounds.height *= spreadScale;
2098
- }
2099
- canvas.copyWorld(shape.canvas, shapeBounds, spreadScale ? tempBounds : outBounds);
2120
+ from = shapeBounds, to = outBounds;
2100
2121
  }
2122
+ canvas.copyWorld(shape.canvas, from, to);
2101
2123
  }
2102
2124
 
2103
2125
  const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
@@ -2105,13 +2127,13 @@ const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
2105
2127
  const offsetOutBounds = {};
2106
2128
 
2107
2129
  function innerShadow(ui, current, shape) {
2108
- let copyBounds, spreadScale;
2109
- const {__nowWorld: nowWorld, __layout: __layout} = ui;
2130
+ let copyBounds, transform;
2131
+ const {__nowWorld: nowWorld} = ui;
2110
2132
  const {innerShadow: innerShadow} = ui.__;
2111
- const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
2133
+ const {worldCanvas: worldCanvas, bounds: bounds, renderBounds: renderBounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
2112
2134
  const other = current.getSameCanvas();
2113
2135
  const end = innerShadow.length - 1;
2114
- toOffsetOutBounds(bounds, offsetOutBounds);
2136
+ toOffsetOutBounds(bounds, offsetOutBounds, renderBounds);
2115
2137
  innerShadow.forEach((item, index) => {
2116
2138
  let otherScale = 1;
2117
2139
  if (item.scaleFixed) {
@@ -2120,16 +2142,17 @@ function innerShadow(ui, current, shape) {
2120
2142
  }
2121
2143
  other.save();
2122
2144
  other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
2123
- spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
2124
- drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
2145
+ transform = getShadowTransform(ui, other, shape, item, offsetOutBounds, otherScale, true);
2146
+ if (transform) other.setTransform(transform);
2147
+ drawWorldShadow(other, offsetOutBounds, shape);
2125
2148
  other.restore();
2126
2149
  if (worldCanvas) {
2127
- other.copyWorld(other, bounds, nowWorld, "copy");
2150
+ other.copyWorld(other, renderBounds, nowWorld, "copy");
2128
2151
  other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
2129
2152
  copyBounds = nowWorld;
2130
2153
  } else {
2131
2154
  other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
2132
- copyBounds = bounds;
2155
+ copyBounds = renderBounds;
2133
2156
  }
2134
2157
  other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), "source-in");
2135
2158
  core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
@@ -2138,6 +2161,8 @@ function innerShadow(ui, current, shape) {
2138
2161
  other.recycle(copyBounds);
2139
2162
  }
2140
2163
 
2164
+ const getInnerShadowSpread = getShadowRenderSpread;
2165
+
2141
2166
  function blur(ui, current, origin) {
2142
2167
  const {blur: blur} = ui.__;
2143
2168
  origin.setWorldBlur(blur * ui.__nowWorld.a);
@@ -2152,10 +2177,12 @@ const EffectModule = {
2152
2177
  innerShadow: innerShadow,
2153
2178
  blur: blur,
2154
2179
  backgroundBlur: backgroundBlur,
2155
- getShadowSpread: getShadowSpread,
2180
+ getShadowRenderSpread: getShadowRenderSpread,
2181
+ getShadowTransform: getShadowTransform,
2156
2182
  isTransformShadow(_shadow) {
2157
2183
  return undefined;
2158
- }
2184
+ },
2185
+ getInnerShadowSpread: getInnerShadowSpread
2159
2186
  };
2160
2187
 
2161
2188
  const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
@@ -2172,6 +2199,7 @@ draw.Group.prototype.__renderMask = function(canvas, options) {
2172
2199
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
2173
2200
  maskCanvas = contentCanvas = null;
2174
2201
  }
2202
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
2175
2203
  maskOpacity = child.__.opacity;
2176
2204
  usedGrayscaleAlpha = false;
2177
2205
  if (mask === "path" || mask === "clipping-path") {
@@ -2189,7 +2217,6 @@ draw.Group.prototype.__renderMask = function(canvas, options) {
2189
2217
  if (!contentCanvas) contentCanvas = getCanvas(canvas);
2190
2218
  child.__render(maskCanvas, options);
2191
2219
  }
2192
- if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
2193
2220
  continue;
2194
2221
  }
2195
2222
  const childBlendMode = maskOpacity === 1 && child.__.__blendMode;