@leafer-draw/node 1.6.7 → 1.8.0

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
@@ -710,9 +710,14 @@ function fills(fills, ui, canvas) {
710
710
  }
711
711
  }
712
712
  canvas.fillStyle = item.style;
713
- if (item.transform) {
713
+ if (item.transform || item.scaleFixed) {
714
714
  canvas.save();
715
- canvas.transform(item.transform);
715
+ if (item.transform)
716
+ canvas.transform(item.transform);
717
+ if (item.scaleFixed) {
718
+ const { scaleX, scaleY } = ui.getRenderScaleData(true);
719
+ canvas.scale(1 / scaleX, 1 / scaleY);
720
+ }
716
721
  if (item.blendMode)
717
722
  canvas.blendMode = item.blendMode;
718
723
  fillPathOrText(ui, canvas);
@@ -748,8 +753,13 @@ function strokeText(stroke, ui, canvas) {
748
753
  }
749
754
  function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
750
755
  const data = ui.__;
751
- canvas.setStroke(!data.__isStrokes && stroke, data.strokeWidth * strokeWidthScale, data);
752
- data.__isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
756
+ if (typeof stroke === 'object') {
757
+ drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
758
+ }
759
+ else {
760
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
761
+ drawTextStroke(ui, canvas);
762
+ }
753
763
  }
754
764
  function drawAlign(stroke, align, ui, canvas) {
755
765
  const out = canvas.getSameCanvas(true, true);
@@ -758,15 +768,9 @@ function drawAlign(stroke, align, ui, canvas) {
758
768
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
759
769
  fillText(ui, out);
760
770
  out.blendMode = 'normal';
761
- copyWorld(canvas, out, ui);
771
+ core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
762
772
  out.recycle(ui.__nowWorld);
763
773
  }
764
- function copyWorld(canvas, out, ui) {
765
- if (ui.__worldFlipped || core.Platform.fullImageShadow)
766
- canvas.copyWorldByReset(out, ui.__nowWorld);
767
- else
768
- canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
769
- }
770
774
  function drawTextStroke(ui, canvas) {
771
775
  let row, data = ui.__.__textDrawData;
772
776
  const { rows, decorationY } = data;
@@ -782,14 +786,21 @@ function drawTextStroke(ui, canvas) {
782
786
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
783
787
  }
784
788
  }
785
- function drawStrokesStyle(strokes, isText, ui, canvas) {
789
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
786
790
  let item;
791
+ const data = ui.__, { __hasMultiStrokeStyle } = data;
792
+ __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
787
793
  for (let i = 0, len = strokes.length; i < len; i++) {
788
794
  item = strokes[i];
789
795
  if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false))
790
796
  continue;
791
797
  if (item.style) {
792
- canvas.strokeStyle = item.style;
798
+ if (__hasMultiStrokeStyle) {
799
+ const { strokeStyle } = item;
800
+ strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
801
+ }
802
+ else
803
+ canvas.strokeStyle = item.style;
793
804
  if (item.blendMode) {
794
805
  canvas.saveBlendMode(item.blendMode);
795
806
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
@@ -828,8 +839,13 @@ function strokes(strokes, ui, canvas) {
828
839
  }
829
840
  function drawCenter(stroke, strokeWidthScale, ui, canvas) {
830
841
  const data = ui.__;
831
- canvas.setStroke(!data.__isStrokes && stroke, data.__strokeWidth * strokeWidthScale, data);
832
- data.__isStrokes ? drawStrokesStyle(stroke, false, ui, canvas) : canvas.stroke();
842
+ if (typeof stroke === 'object') {
843
+ drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
844
+ }
845
+ else {
846
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
847
+ canvas.stroke();
848
+ }
833
849
  if (data.__useArrow)
834
850
  draw.Paint.strokeArrow(stroke, ui, canvas);
835
851
  }
@@ -851,7 +867,7 @@ function drawOutside(stroke, ui, canvas) {
851
867
  drawCenter(stroke, 2, ui, out);
852
868
  out.clipUI(data);
853
869
  out.clearWorld(renderBounds);
854
- copyWorld(canvas, out, ui);
870
+ core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
855
871
  out.recycle(ui.__nowWorld);
856
872
  }
857
873
  }
@@ -906,8 +922,16 @@ function compute(attrName, ui) {
906
922
  if (!(paints instanceof Array))
907
923
  paints = [paints];
908
924
  recycleMap = draw.PaintImage.recycleImage(attrName, data);
925
+ let maxChildStrokeWidth;
909
926
  for (let i = 0, len = paints.length, item; i < len; i++) {
910
- (item = getLeafPaint(attrName, paints[i], ui)) && leafPaints.push(item);
927
+ if (item = getLeafPaint(attrName, paints[i], ui)) {
928
+ leafPaints.push(item);
929
+ if (item.strokeStyle) {
930
+ maxChildStrokeWidth || (maxChildStrokeWidth = 1);
931
+ if (item.strokeStyle.strokeWidth)
932
+ maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
933
+ }
934
+ }
911
935
  }
912
936
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
913
937
  if (leafPaints.length) {
@@ -924,6 +948,7 @@ function compute(attrName, ui) {
924
948
  else {
925
949
  stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
926
950
  stintSet(data, '__isTransparentStroke', isTransparent);
951
+ stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
927
952
  }
928
953
  }
929
954
  function getLeafPaint(attrName, paint, ui) {
@@ -955,6 +980,11 @@ function getLeafPaint(attrName, paint, ui) {
955
980
  if (data) {
956
981
  if (typeof data.style === 'string' && hasTransparent$1(data.style))
957
982
  data.isTransparent = true;
983
+ if (paint.style) {
984
+ if (paint.style.strokeWidth === 0)
985
+ return undefined;
986
+ data.strokeStyle = paint.style;
987
+ }
958
988
  if (paint.blendMode)
959
989
  data.blendMode = paint.blendMode;
960
990
  }
@@ -974,8 +1004,8 @@ const PaintModule = {
974
1004
  shape
975
1005
  };
976
1006
 
977
- let origin = {};
978
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate } = core.MatrixHelper;
1007
+ let origin = {}, tempMatrix = core.getMatrixData();
1008
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent, scale: scaleHelper, rotate, skew: skewHelper } = core.MatrixHelper;
979
1009
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
980
1010
  const transform = get$3();
981
1011
  translate$1(transform, box.x + x, box.y + y);
@@ -984,13 +1014,19 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
984
1014
  rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
985
1015
  data.transform = transform;
986
1016
  }
987
- function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
1017
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
988
1018
  const transform = get$3();
989
- translate$1(transform, box.x + x, box.y + y);
990
- if (scaleX)
991
- scaleHelper(transform, scaleX, scaleY);
992
1019
  if (rotation)
993
1020
  rotate(transform, rotation);
1021
+ if (skew)
1022
+ skewHelper(transform, skew.x, skew.y);
1023
+ if (scaleX)
1024
+ scaleHelper(transform, scaleX, scaleY);
1025
+ translate$1(transform, box.x + x, box.y + y);
1026
+ if (clipSize) {
1027
+ tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1028
+ multiplyParent(transform, tempMatrix);
1029
+ }
994
1030
  data.transform = transform;
995
1031
  }
996
1032
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
@@ -1027,11 +1063,15 @@ const tempBox = new core.Bounds();
1027
1063
  const tempScaleData = {};
1028
1064
  const tempImage = {};
1029
1065
  function createData(leafPaint, image, paint, box) {
1030
- const { changeful, sync } = paint;
1066
+ const { changeful, sync, editing, scaleFixed } = paint;
1031
1067
  if (changeful)
1032
1068
  leafPaint.changeful = changeful;
1033
1069
  if (sync)
1034
1070
  leafPaint.sync = sync;
1071
+ if (editing)
1072
+ leafPaint.editing = editing;
1073
+ if (scaleFixed)
1074
+ leafPaint.scaleFixed = scaleFixed;
1035
1075
  leafPaint.data = getPatternData(paint, box, image);
1036
1076
  }
1037
1077
  function getPatternData(paint, box, image) {
@@ -1040,7 +1080,7 @@ function getPatternData(paint, box, image) {
1040
1080
  if (paint.mode === 'strench')
1041
1081
  paint.mode = 'stretch';
1042
1082
  let { width, height } = image;
1043
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
1083
+ const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
1044
1084
  const sameBox = box.width === width && box.height === height;
1045
1085
  const data = { mode };
1046
1086
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -1074,8 +1114,8 @@ function getPatternData(paint, box, image) {
1074
1114
  break;
1075
1115
  case 'normal':
1076
1116
  case 'clip':
1077
- if (tempImage.x || tempImage.y || scaleX || rotation)
1078
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1117
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew)
1118
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1079
1119
  break;
1080
1120
  case 'repeat':
1081
1121
  if (!sameBox || scaleX || rotation)
@@ -1152,11 +1192,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1152
1192
  }
1153
1193
  onLoadSuccess(ui, event);
1154
1194
  }
1155
- leafPaint.loadId = null;
1195
+ leafPaint.loadId = undefined;
1156
1196
  }, (error) => {
1157
1197
  ignoreRender(ui, false);
1158
1198
  onLoadError(ui, event, error);
1159
- leafPaint.loadId = null;
1199
+ leafPaint.loadId = undefined;
1160
1200
  });
1161
1201
  if (ui.placeholderColor) {
1162
1202
  if (!ui.placeholderDelay)
@@ -1212,16 +1252,16 @@ function ignoreRender(ui, value) {
1212
1252
  }
1213
1253
 
1214
1254
  const { get: get$1, scale, copy: copy$1 } = core.MatrixHelper;
1215
- const { ceil, abs: abs$1 } = Math;
1255
+ const { ceil, abs } = Math;
1216
1256
  function createPattern(ui, paint, pixelRatio) {
1217
- let { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1257
+ let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
1218
1258
  const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1219
1259
  if (paint.patternId !== id && !ui.destroyed) {
1220
- scaleX = abs$1(scaleX);
1221
- scaleY = abs$1(scaleY);
1222
1260
  const { image, data } = paint;
1223
1261
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1224
1262
  if (sx) {
1263
+ sx = abs(sx);
1264
+ sy = abs(sy);
1225
1265
  imageMatrix = get$1();
1226
1266
  copy$1(imageMatrix, transform);
1227
1267
  scale(imageMatrix, 1 / sx, 1 / sy);
@@ -1274,9 +1314,8 @@ function createPattern(ui, paint, pixelRatio) {
1274
1314
  }
1275
1315
  }
1276
1316
 
1277
- const { abs } = Math;
1278
1317
  function checkImage(ui, canvas, paint, allowDraw) {
1279
- const { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1318
+ const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
1280
1319
  const { pixelRatio } = canvas, { data } = paint;
1281
1320
  if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1282
1321
  return false;
@@ -1289,8 +1328,8 @@ function checkImage(ui, canvas, paint, allowDraw) {
1289
1328
  else {
1290
1329
  if (!(paint.changeful || core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1291
1330
  let { width, height } = data;
1292
- width *= abs(scaleX) * pixelRatio;
1293
- height *= abs(scaleY) * pixelRatio;
1331
+ width *= scaleX * pixelRatio;
1332
+ height *= scaleY * pixelRatio;
1294
1333
  if (data.scaleX) {
1295
1334
  width *= data.scaleX;
1296
1335
  height *= data.scaleY;
@@ -1300,6 +1339,10 @@ function checkImage(ui, canvas, paint, allowDraw) {
1300
1339
  }
1301
1340
  }
1302
1341
  if (allowDraw) {
1342
+ if (ui.__.__isFastShadow) {
1343
+ canvas.fillStyle = paint.style || '#000';
1344
+ canvas.fill();
1345
+ }
1303
1346
  drawImage(ui, canvas, paint, data);
1304
1347
  return true;
1305
1348
  }
@@ -1488,10 +1531,7 @@ function shadow(ui, current, shape) {
1488
1531
  }
1489
1532
  worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
1490
1533
  }
1491
- if (ui.__worldFlipped)
1492
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1493
- else
1494
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
1534
+ core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1495
1535
  if (end && index < end)
1496
1536
  other.clearWorld(copyBounds, true);
1497
1537
  });
@@ -1550,10 +1590,7 @@ function innerShadow(ui, current, shape) {
1550
1590
  copyBounds = bounds;
1551
1591
  }
1552
1592
  other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), 'source-in');
1553
- if (ui.__worldFlipped)
1554
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1555
- else
1556
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
1593
+ core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1557
1594
  if (end && index < end)
1558
1595
  other.clearWorld(copyBounds, true);
1559
1596
  });
@@ -1609,12 +1646,11 @@ draw.Group.prototype.__renderMask = function (canvas, options) {
1609
1646
  contentCanvas = getCanvas(canvas);
1610
1647
  child.__render(maskCanvas, options);
1611
1648
  }
1612
- if (!(mask === 'clipping' || mask === 'clipping-path'))
1613
- continue;
1614
- }
1615
- if (excludeRenderBounds(child, options))
1649
+ if (mask === 'clipping' || mask === 'clipping-path')
1650
+ excludeRenderBounds(child, options) || child.__render(canvas, options);
1616
1651
  continue;
1617
- child.__render(contentCanvas || canvas, options);
1652
+ }
1653
+ excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
1618
1654
  }
1619
1655
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1620
1656
  };
@@ -2208,123 +2244,131 @@ function getTrimBounds(canvas) {
2208
2244
  index++;
2209
2245
  }
2210
2246
  const bounds = new draw.Bounds();
2211
- toBounds(pointBounds, bounds);
2212
- return bounds.scale(1 / canvas.pixelRatio).ceil();
2247
+ if (pointBounds) {
2248
+ toBounds(pointBounds, bounds);
2249
+ bounds.scale(1 / canvas.pixelRatio).ceil();
2250
+ }
2251
+ return bounds;
2213
2252
  }
2214
2253
 
2215
2254
  const ExportModule = {
2216
2255
  syncExport(leaf, filename, options) {
2217
- this.running = true;
2256
+ draw.Export.running = true;
2218
2257
  let result;
2219
- const fileType = draw.FileHelper.fileType(filename);
2220
- const isDownload = filename.includes('.');
2221
- options = draw.FileHelper.getExportOptions(options);
2222
- const { toURL } = draw.Platform;
2223
- const { download } = draw.Platform.origin;
2224
- if (fileType === 'json') {
2225
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2226
- result = { data: isDownload ? true : leaf.toJSON(options.json) };
2227
- }
2228
- else if (fileType === 'svg') {
2229
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
2230
- result = { data: isDownload ? true : leaf.toSVG() };
2231
- }
2232
- else {
2233
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2234
- const { worldTransform, isLeafer, leafer, isFrame } = leaf;
2235
- const { slice, clip, trim, screenshot, padding, onCanvas } = options;
2236
- const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
2237
- const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
2238
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
2239
- const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix();
2240
- if (screenshot) {
2241
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2242
- }
2243
- else {
2244
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
2245
- scaleX = worldTransform.scaleX;
2246
- scaleY = worldTransform.scaleY;
2247
- switch (relative) {
2248
- case 'inner':
2249
- matrix.set(worldTransform);
2250
- break;
2251
- case 'local':
2252
- matrix.set(worldTransform).divide(leaf.localTransform);
2253
- scaleX /= leaf.scaleX;
2254
- scaleY /= leaf.scaleY;
2255
- break;
2256
- case 'world':
2257
- scaleX = 1;
2258
- scaleY = 1;
2259
- break;
2260
- case 'page':
2261
- relative = leafer || leaf;
2262
- default:
2263
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
2264
- const l = relative.worldTransform;
2265
- scaleX /= scaleX / l.scaleX;
2266
- scaleY /= scaleY / l.scaleY;
2267
- }
2268
- renderBounds = leaf.getBounds('render', relative);
2258
+ try {
2259
+ const fileType = draw.FileHelper.fileType(filename);
2260
+ const isDownload = filename.includes('.');
2261
+ options = draw.FileHelper.getExportOptions(options);
2262
+ const { toURL } = draw.Platform;
2263
+ const { download } = draw.Platform.origin;
2264
+ if (fileType === 'json') {
2265
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2266
+ result = { data: isDownload ? true : leaf.toJSON(options.json) };
2269
2267
  }
2270
- const scaleData = { scaleX: 1, scaleY: 1 };
2271
- draw.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
2272
- let pixelRatio = options.pixelRatio || 1;
2273
- let { x, y, width, height } = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2274
- if (clip)
2275
- x += clip.x, y += clip.y, width = clip.width, height = clip.height;
2276
- const renderOptions = { exporting: true, matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
2277
- let canvas = draw.Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
2278
- let sliceLeaf;
2279
- if (slice) {
2280
- sliceLeaf = leaf;
2281
- sliceLeaf.__worldOpacity = 0;
2282
- leaf = leafer || leaf;
2283
- renderOptions.bounds = canvas.bounds;
2284
- }
2285
- canvas.save();
2286
- if (isFrame && fill !== undefined) {
2287
- const oldFill = leaf.get('fill');
2288
- leaf.fill = '';
2289
- leaf.__render(canvas, renderOptions);
2290
- leaf.fill = oldFill;
2268
+ else if (fileType === 'svg') {
2269
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
2270
+ result = { data: isDownload ? true : leaf.toSVG() };
2291
2271
  }
2292
2272
  else {
2293
- leaf.__render(canvas, renderOptions);
2294
- }
2295
- canvas.restore();
2296
- if (sliceLeaf)
2297
- sliceLeaf.__updateWorldOpacity();
2298
- if (trim) {
2299
- trimBounds = getTrimBounds(canvas);
2300
- const old = canvas, { width, height } = trimBounds;
2301
- const config = { x: 0, y: 0, width, height, pixelRatio };
2302
- canvas = draw.Creator.canvas(config);
2303
- canvas.copyWorld(old, trimBounds, config);
2304
- }
2305
- if (padding) {
2306
- const [top, right, bottom, left] = draw.MathHelper.fourNumber(padding);
2307
- const old = canvas, { width, height } = old;
2308
- canvas = draw.Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
2309
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
2273
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2274
+ const { worldTransform, isLeafer, leafer, isFrame } = leaf;
2275
+ const { slice, clip, trim, screenshot, padding, onCanvas } = options;
2276
+ const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
2277
+ const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
2278
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
2279
+ const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix();
2280
+ if (screenshot) {
2281
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2282
+ }
2283
+ else {
2284
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
2285
+ scaleX = worldTransform.scaleX;
2286
+ scaleY = worldTransform.scaleY;
2287
+ switch (relative) {
2288
+ case 'inner':
2289
+ matrix.set(worldTransform);
2290
+ break;
2291
+ case 'local':
2292
+ matrix.set(worldTransform).divide(leaf.localTransform);
2293
+ scaleX /= leaf.scaleX;
2294
+ scaleY /= leaf.scaleY;
2295
+ break;
2296
+ case 'world':
2297
+ scaleX = 1;
2298
+ scaleY = 1;
2299
+ break;
2300
+ case 'page':
2301
+ relative = leafer || leaf;
2302
+ default:
2303
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
2304
+ const l = relative.worldTransform;
2305
+ scaleX /= scaleX / l.scaleX;
2306
+ scaleY /= scaleY / l.scaleY;
2307
+ }
2308
+ renderBounds = leaf.getBounds('render', relative);
2309
+ }
2310
+ const scaleData = { scaleX: 1, scaleY: 1 };
2311
+ draw.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
2312
+ let pixelRatio = options.pixelRatio || 1;
2313
+ let { x, y, width, height } = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2314
+ if (clip)
2315
+ x += clip.x, y += clip.y, width = clip.width, height = clip.height;
2316
+ const renderOptions = { exporting: true, matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
2317
+ let canvas = draw.Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
2318
+ let sliceLeaf;
2319
+ if (slice) {
2320
+ sliceLeaf = leaf;
2321
+ sliceLeaf.__worldOpacity = 0;
2322
+ leaf = leafer || leaf;
2323
+ renderOptions.bounds = canvas.bounds;
2324
+ }
2325
+ canvas.save();
2326
+ if (isFrame && fill !== undefined) {
2327
+ const oldFill = leaf.get('fill');
2328
+ leaf.fill = '';
2329
+ leaf.__render(canvas, renderOptions);
2330
+ leaf.fill = oldFill;
2331
+ }
2332
+ else {
2333
+ leaf.__render(canvas, renderOptions);
2334
+ }
2335
+ canvas.restore();
2336
+ if (sliceLeaf)
2337
+ sliceLeaf.__updateWorldOpacity();
2338
+ if (trim) {
2339
+ trimBounds = getTrimBounds(canvas);
2340
+ const old = canvas, { width, height } = trimBounds;
2341
+ const config = { x: 0, y: 0, width, height, pixelRatio };
2342
+ canvas = draw.Creator.canvas(config);
2343
+ canvas.copyWorld(old, trimBounds, config);
2344
+ }
2345
+ if (padding) {
2346
+ const [top, right, bottom, left] = draw.MathHelper.fourNumber(padding);
2347
+ const old = canvas, { width, height } = old;
2348
+ canvas = draw.Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
2349
+ canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
2350
+ }
2351
+ if (needFill)
2352
+ canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
2353
+ if (onCanvas)
2354
+ onCanvas(canvas);
2355
+ const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
2356
+ result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
2310
2357
  }
2311
- if (needFill)
2312
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
2313
- if (onCanvas)
2314
- onCanvas(canvas);
2315
- const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
2316
- result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
2317
2358
  }
2318
- this.running = false;
2359
+ catch (error) {
2360
+ result = { data: '', error };
2361
+ }
2362
+ draw.Export.running = false;
2319
2363
  return result;
2320
2364
  },
2321
2365
  export(leaf, filename, options) {
2322
- this.running = true;
2366
+ draw.Export.running = true;
2323
2367
  return addTask((success) => new Promise((resolve) => {
2324
2368
  const getResult = () => __awaiter(this, void 0, void 0, function* () {
2325
2369
  if (!draw.Resource.isComplete)
2326
2370
  return draw.Platform.requestRender(getResult);
2327
- const result = ExportModule.syncExport(leaf, filename, options);
2371
+ const result = draw.Export.syncExport(leaf, filename, options);
2328
2372
  if (result.data instanceof Promise)
2329
2373
  result.data = yield result.data;
2330
2374
  success(result);