@leafer-draw/node 1.7.0 → 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 +185 -147
- package/dist/node.esm.js +186 -148
- package/dist/node.esm.min.js +1 -1
- package/dist/node.esm.min.js.map +1 -1
- package/dist/node.min.cjs +1 -1
- package/dist/node.min.cjs.map +1 -1
- package/package.json +10 -10
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
|
-
|
|
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
|
-
|
|
752
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
832
|
-
|
|
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
|
-
|
|
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))
|
|
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, skew: skewHelper } = 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,7 +1014,7 @@ 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, skew) {
|
|
1017
|
+
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
988
1018
|
const transform = get$3();
|
|
989
1019
|
if (rotation)
|
|
990
1020
|
rotate(transform, rotation);
|
|
@@ -993,6 +1023,10 @@ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
|
993
1023
|
if (scaleX)
|
|
994
1024
|
scaleHelper(transform, scaleX, scaleY);
|
|
995
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
|
+
}
|
|
996
1030
|
data.transform = transform;
|
|
997
1031
|
}
|
|
998
1032
|
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
|
|
@@ -1029,13 +1063,15 @@ const tempBox = new core.Bounds();
|
|
|
1029
1063
|
const tempScaleData = {};
|
|
1030
1064
|
const tempImage = {};
|
|
1031
1065
|
function createData(leafPaint, image, paint, box) {
|
|
1032
|
-
const { changeful, sync, editing } = paint;
|
|
1066
|
+
const { changeful, sync, editing, scaleFixed } = paint;
|
|
1033
1067
|
if (changeful)
|
|
1034
1068
|
leafPaint.changeful = changeful;
|
|
1035
1069
|
if (sync)
|
|
1036
1070
|
leafPaint.sync = sync;
|
|
1037
1071
|
if (editing)
|
|
1038
1072
|
leafPaint.editing = editing;
|
|
1073
|
+
if (scaleFixed)
|
|
1074
|
+
leafPaint.scaleFixed = scaleFixed;
|
|
1039
1075
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1040
1076
|
}
|
|
1041
1077
|
function getPatternData(paint, box, image) {
|
|
@@ -1044,7 +1080,7 @@ function getPatternData(paint, box, image) {
|
|
|
1044
1080
|
if (paint.mode === 'strench')
|
|
1045
1081
|
paint.mode = 'stretch';
|
|
1046
1082
|
let { width, height } = image;
|
|
1047
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
|
|
1083
|
+
const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
|
|
1048
1084
|
const sameBox = box.width === width && box.height === height;
|
|
1049
1085
|
const data = { mode };
|
|
1050
1086
|
const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
|
|
@@ -1078,8 +1114,8 @@ function getPatternData(paint, box, image) {
|
|
|
1078
1114
|
break;
|
|
1079
1115
|
case 'normal':
|
|
1080
1116
|
case 'clip':
|
|
1081
|
-
if (tempImage.x || tempImage.y || scaleX || rotation || skew)
|
|
1082
|
-
clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
|
|
1117
|
+
if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew)
|
|
1118
|
+
clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
|
|
1083
1119
|
break;
|
|
1084
1120
|
case 'repeat':
|
|
1085
1121
|
if (!sameBox || scaleX || rotation)
|
|
@@ -1216,18 +1252,16 @@ function ignoreRender(ui, value) {
|
|
|
1216
1252
|
}
|
|
1217
1253
|
|
|
1218
1254
|
const { get: get$1, scale, copy: copy$1 } = core.MatrixHelper;
|
|
1219
|
-
const { ceil, abs
|
|
1255
|
+
const { ceil, abs } = Math;
|
|
1220
1256
|
function createPattern(ui, paint, pixelRatio) {
|
|
1221
|
-
let { scaleX, scaleY } =
|
|
1257
|
+
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1222
1258
|
const id = scaleX + '-' + scaleY + '-' + pixelRatio;
|
|
1223
1259
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1224
|
-
scaleX = abs$1(scaleX);
|
|
1225
|
-
scaleY = abs$1(scaleY);
|
|
1226
1260
|
const { image, data } = paint;
|
|
1227
1261
|
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
1228
1262
|
if (sx) {
|
|
1229
|
-
sx = abs
|
|
1230
|
-
sy = abs
|
|
1263
|
+
sx = abs(sx);
|
|
1264
|
+
sy = abs(sy);
|
|
1231
1265
|
imageMatrix = get$1();
|
|
1232
1266
|
copy$1(imageMatrix, transform);
|
|
1233
1267
|
scale(imageMatrix, 1 / sx, 1 / sy);
|
|
@@ -1280,9 +1314,8 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1280
1314
|
}
|
|
1281
1315
|
}
|
|
1282
1316
|
|
|
1283
|
-
const { abs } = Math;
|
|
1284
1317
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1285
|
-
const { scaleX, scaleY } =
|
|
1318
|
+
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1286
1319
|
const { pixelRatio } = canvas, { data } = paint;
|
|
1287
1320
|
if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
|
|
1288
1321
|
return false;
|
|
@@ -1295,8 +1328,8 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1295
1328
|
else {
|
|
1296
1329
|
if (!(paint.changeful || core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
|
|
1297
1330
|
let { width, height } = data;
|
|
1298
|
-
width *=
|
|
1299
|
-
height *=
|
|
1331
|
+
width *= scaleX * pixelRatio;
|
|
1332
|
+
height *= scaleY * pixelRatio;
|
|
1300
1333
|
if (data.scaleX) {
|
|
1301
1334
|
width *= data.scaleX;
|
|
1302
1335
|
height *= data.scaleY;
|
|
@@ -1306,6 +1339,10 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1306
1339
|
}
|
|
1307
1340
|
}
|
|
1308
1341
|
if (allowDraw) {
|
|
1342
|
+
if (ui.__.__isFastShadow) {
|
|
1343
|
+
canvas.fillStyle = paint.style || '#000';
|
|
1344
|
+
canvas.fill();
|
|
1345
|
+
}
|
|
1309
1346
|
drawImage(ui, canvas, paint, data);
|
|
1310
1347
|
return true;
|
|
1311
1348
|
}
|
|
@@ -1494,10 +1531,7 @@ function shadow(ui, current, shape) {
|
|
|
1494
1531
|
}
|
|
1495
1532
|
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
|
|
1496
1533
|
}
|
|
1497
|
-
|
|
1498
|
-
current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
|
|
1499
|
-
else
|
|
1500
|
-
current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
|
|
1534
|
+
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1501
1535
|
if (end && index < end)
|
|
1502
1536
|
other.clearWorld(copyBounds, true);
|
|
1503
1537
|
});
|
|
@@ -1556,10 +1590,7 @@ function innerShadow(ui, current, shape) {
|
|
|
1556
1590
|
copyBounds = bounds;
|
|
1557
1591
|
}
|
|
1558
1592
|
other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), 'source-in');
|
|
1559
|
-
|
|
1560
|
-
current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
|
|
1561
|
-
else
|
|
1562
|
-
current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
|
|
1593
|
+
core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1563
1594
|
if (end && index < end)
|
|
1564
1595
|
other.clearWorld(copyBounds, true);
|
|
1565
1596
|
});
|
|
@@ -1615,12 +1646,11 @@ draw.Group.prototype.__renderMask = function (canvas, options) {
|
|
|
1615
1646
|
contentCanvas = getCanvas(canvas);
|
|
1616
1647
|
child.__render(maskCanvas, options);
|
|
1617
1648
|
}
|
|
1618
|
-
if (
|
|
1619
|
-
|
|
1620
|
-
}
|
|
1621
|
-
if (excludeRenderBounds(child, options))
|
|
1649
|
+
if (mask === 'clipping' || mask === 'clipping-path')
|
|
1650
|
+
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1622
1651
|
continue;
|
|
1623
|
-
|
|
1652
|
+
}
|
|
1653
|
+
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
1624
1654
|
}
|
|
1625
1655
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1626
1656
|
};
|
|
@@ -2214,123 +2244,131 @@ function getTrimBounds(canvas) {
|
|
|
2214
2244
|
index++;
|
|
2215
2245
|
}
|
|
2216
2246
|
const bounds = new draw.Bounds();
|
|
2217
|
-
|
|
2218
|
-
|
|
2247
|
+
if (pointBounds) {
|
|
2248
|
+
toBounds(pointBounds, bounds);
|
|
2249
|
+
bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
2250
|
+
}
|
|
2251
|
+
return bounds;
|
|
2219
2252
|
}
|
|
2220
2253
|
|
|
2221
2254
|
const ExportModule = {
|
|
2222
2255
|
syncExport(leaf, filename, options) {
|
|
2223
|
-
|
|
2256
|
+
draw.Export.running = true;
|
|
2224
2257
|
let result;
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
else if (fileType === 'svg') {
|
|
2235
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2236
|
-
result = { data: isDownload ? true : leaf.toSVG() };
|
|
2237
|
-
}
|
|
2238
|
-
else {
|
|
2239
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2240
|
-
const { worldTransform, isLeafer, leafer, isFrame } = leaf;
|
|
2241
|
-
const { slice, clip, trim, screenshot, padding, onCanvas } = options;
|
|
2242
|
-
const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
|
|
2243
|
-
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2244
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2245
|
-
const needFill = draw.FileHelper.isOpaqueImage(filename) || fill, matrix = new draw.Matrix();
|
|
2246
|
-
if (screenshot) {
|
|
2247
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2248
|
-
}
|
|
2249
|
-
else {
|
|
2250
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2251
|
-
scaleX = worldTransform.scaleX;
|
|
2252
|
-
scaleY = worldTransform.scaleY;
|
|
2253
|
-
switch (relative) {
|
|
2254
|
-
case 'inner':
|
|
2255
|
-
matrix.set(worldTransform);
|
|
2256
|
-
break;
|
|
2257
|
-
case 'local':
|
|
2258
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2259
|
-
scaleX /= leaf.scaleX;
|
|
2260
|
-
scaleY /= leaf.scaleY;
|
|
2261
|
-
break;
|
|
2262
|
-
case 'world':
|
|
2263
|
-
scaleX = 1;
|
|
2264
|
-
scaleY = 1;
|
|
2265
|
-
break;
|
|
2266
|
-
case 'page':
|
|
2267
|
-
relative = leafer || leaf;
|
|
2268
|
-
default:
|
|
2269
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2270
|
-
const l = relative.worldTransform;
|
|
2271
|
-
scaleX /= scaleX / l.scaleX;
|
|
2272
|
-
scaleY /= scaleY / l.scaleY;
|
|
2273
|
-
}
|
|
2274
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
2275
|
-
}
|
|
2276
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2277
|
-
draw.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2278
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2279
|
-
let { x, y, width, height } = new draw.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2280
|
-
if (clip)
|
|
2281
|
-
x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
2282
|
-
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) };
|
|
2283
|
-
let canvas = draw.Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
|
|
2284
|
-
let sliceLeaf;
|
|
2285
|
-
if (slice) {
|
|
2286
|
-
sliceLeaf = leaf;
|
|
2287
|
-
sliceLeaf.__worldOpacity = 0;
|
|
2288
|
-
leaf = leafer || leaf;
|
|
2289
|
-
renderOptions.bounds = canvas.bounds;
|
|
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) };
|
|
2290
2267
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
leaf.fill = '';
|
|
2295
|
-
leaf.__render(canvas, renderOptions);
|
|
2296
|
-
leaf.fill = oldFill;
|
|
2268
|
+
else if (fileType === 'svg') {
|
|
2269
|
+
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2270
|
+
result = { data: isDownload ? true : leaf.toSVG() };
|
|
2297
2271
|
}
|
|
2298
2272
|
else {
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
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 };
|
|
2316
2357
|
}
|
|
2317
|
-
if (needFill)
|
|
2318
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2319
|
-
if (onCanvas)
|
|
2320
|
-
onCanvas(canvas);
|
|
2321
|
-
const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
|
|
2322
|
-
result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
|
|
2323
2358
|
}
|
|
2324
|
-
|
|
2359
|
+
catch (error) {
|
|
2360
|
+
result = { data: '', error };
|
|
2361
|
+
}
|
|
2362
|
+
draw.Export.running = false;
|
|
2325
2363
|
return result;
|
|
2326
2364
|
},
|
|
2327
2365
|
export(leaf, filename, options) {
|
|
2328
|
-
|
|
2366
|
+
draw.Export.running = true;
|
|
2329
2367
|
return addTask((success) => new Promise((resolve) => {
|
|
2330
2368
|
const getResult = () => __awaiter(this, void 0, void 0, function* () {
|
|
2331
2369
|
if (!draw.Resource.isComplete)
|
|
2332
2370
|
return draw.Platform.requestRender(getResult);
|
|
2333
|
-
const result =
|
|
2371
|
+
const result = draw.Export.syncExport(leaf, filename, options);
|
|
2334
2372
|
if (result.data instanceof Promise)
|
|
2335
2373
|
result.data = yield result.data;
|
|
2336
2374
|
success(result);
|