@leafer-ui/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 +12 -12
package/dist/node.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, Plugin, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4 } from '@leafer/core';
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, Plugin, getMatrixData, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4 } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
4
|
import { writeFileSync } from 'fs';
|
|
@@ -869,9 +869,14 @@ function fills(fills, ui, canvas) {
|
|
|
869
869
|
}
|
|
870
870
|
}
|
|
871
871
|
canvas.fillStyle = item.style;
|
|
872
|
-
if (item.transform) {
|
|
872
|
+
if (item.transform || item.scaleFixed) {
|
|
873
873
|
canvas.save();
|
|
874
|
-
|
|
874
|
+
if (item.transform)
|
|
875
|
+
canvas.transform(item.transform);
|
|
876
|
+
if (item.scaleFixed) {
|
|
877
|
+
const { scaleX, scaleY } = ui.getRenderScaleData(true);
|
|
878
|
+
canvas.scale(1 / scaleX, 1 / scaleY);
|
|
879
|
+
}
|
|
875
880
|
if (item.blendMode)
|
|
876
881
|
canvas.blendMode = item.blendMode;
|
|
877
882
|
fillPathOrText(ui, canvas);
|
|
@@ -907,8 +912,13 @@ function strokeText(stroke, ui, canvas) {
|
|
|
907
912
|
}
|
|
908
913
|
function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
|
|
909
914
|
const data = ui.__;
|
|
910
|
-
|
|
911
|
-
|
|
915
|
+
if (typeof stroke === 'object') {
|
|
916
|
+
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
|
|
917
|
+
}
|
|
918
|
+
else {
|
|
919
|
+
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
920
|
+
drawTextStroke(ui, canvas);
|
|
921
|
+
}
|
|
912
922
|
}
|
|
913
923
|
function drawAlign(stroke, align, ui, canvas) {
|
|
914
924
|
const out = canvas.getSameCanvas(true, true);
|
|
@@ -917,15 +927,9 @@ function drawAlign(stroke, align, ui, canvas) {
|
|
|
917
927
|
out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
|
|
918
928
|
fillText(ui, out);
|
|
919
929
|
out.blendMode = 'normal';
|
|
920
|
-
|
|
930
|
+
LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
921
931
|
out.recycle(ui.__nowWorld);
|
|
922
932
|
}
|
|
923
|
-
function copyWorld(canvas, out, ui) {
|
|
924
|
-
if (ui.__worldFlipped || Platform.fullImageShadow)
|
|
925
|
-
canvas.copyWorldByReset(out, ui.__nowWorld);
|
|
926
|
-
else
|
|
927
|
-
canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
|
|
928
|
-
}
|
|
929
933
|
function drawTextStroke(ui, canvas) {
|
|
930
934
|
let row, data = ui.__.__textDrawData;
|
|
931
935
|
const { rows, decorationY } = data;
|
|
@@ -941,14 +945,21 @@ function drawTextStroke(ui, canvas) {
|
|
|
941
945
|
rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
942
946
|
}
|
|
943
947
|
}
|
|
944
|
-
function drawStrokesStyle(strokes, isText, ui, canvas) {
|
|
948
|
+
function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
945
949
|
let item;
|
|
950
|
+
const data = ui.__, { __hasMultiStrokeStyle } = data;
|
|
951
|
+
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
|
|
946
952
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
947
953
|
item = strokes[i];
|
|
948
954
|
if (item.image && PaintImage.checkImage(ui, canvas, item, false))
|
|
949
955
|
continue;
|
|
950
956
|
if (item.style) {
|
|
951
|
-
|
|
957
|
+
if (__hasMultiStrokeStyle) {
|
|
958
|
+
const { strokeStyle } = item;
|
|
959
|
+
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
|
|
960
|
+
}
|
|
961
|
+
else
|
|
962
|
+
canvas.strokeStyle = item.style;
|
|
952
963
|
if (item.blendMode) {
|
|
953
964
|
canvas.saveBlendMode(item.blendMode);
|
|
954
965
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
@@ -987,8 +998,13 @@ function strokes(strokes, ui, canvas) {
|
|
|
987
998
|
}
|
|
988
999
|
function drawCenter(stroke, strokeWidthScale, ui, canvas) {
|
|
989
1000
|
const data = ui.__;
|
|
990
|
-
|
|
991
|
-
|
|
1001
|
+
if (typeof stroke === 'object') {
|
|
1002
|
+
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
1006
|
+
canvas.stroke();
|
|
1007
|
+
}
|
|
992
1008
|
if (data.__useArrow)
|
|
993
1009
|
Paint.strokeArrow(stroke, ui, canvas);
|
|
994
1010
|
}
|
|
@@ -1010,7 +1026,7 @@ function drawOutside(stroke, ui, canvas) {
|
|
|
1010
1026
|
drawCenter(stroke, 2, ui, out);
|
|
1011
1027
|
out.clipUI(data);
|
|
1012
1028
|
out.clearWorld(renderBounds);
|
|
1013
|
-
|
|
1029
|
+
LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
1014
1030
|
out.recycle(ui.__nowWorld);
|
|
1015
1031
|
}
|
|
1016
1032
|
}
|
|
@@ -1065,8 +1081,16 @@ function compute(attrName, ui) {
|
|
|
1065
1081
|
if (!(paints instanceof Array))
|
|
1066
1082
|
paints = [paints];
|
|
1067
1083
|
recycleMap = PaintImage.recycleImage(attrName, data);
|
|
1084
|
+
let maxChildStrokeWidth;
|
|
1068
1085
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
1069
|
-
(item = getLeafPaint(attrName, paints[i], ui))
|
|
1086
|
+
if (item = getLeafPaint(attrName, paints[i], ui)) {
|
|
1087
|
+
leafPaints.push(item);
|
|
1088
|
+
if (item.strokeStyle) {
|
|
1089
|
+
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
1090
|
+
if (item.strokeStyle.strokeWidth)
|
|
1091
|
+
maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1070
1094
|
}
|
|
1071
1095
|
data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
1072
1096
|
if (leafPaints.length) {
|
|
@@ -1083,6 +1107,7 @@ function compute(attrName, ui) {
|
|
|
1083
1107
|
else {
|
|
1084
1108
|
stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
|
|
1085
1109
|
stintSet(data, '__isTransparentStroke', isTransparent);
|
|
1110
|
+
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
|
|
1086
1111
|
}
|
|
1087
1112
|
}
|
|
1088
1113
|
function getLeafPaint(attrName, paint, ui) {
|
|
@@ -1114,6 +1139,11 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
1114
1139
|
if (data) {
|
|
1115
1140
|
if (typeof data.style === 'string' && hasTransparent$1(data.style))
|
|
1116
1141
|
data.isTransparent = true;
|
|
1142
|
+
if (paint.style) {
|
|
1143
|
+
if (paint.style.strokeWidth === 0)
|
|
1144
|
+
return undefined;
|
|
1145
|
+
data.strokeStyle = paint.style;
|
|
1146
|
+
}
|
|
1117
1147
|
if (paint.blendMode)
|
|
1118
1148
|
data.blendMode = paint.blendMode;
|
|
1119
1149
|
}
|
|
@@ -1133,8 +1163,8 @@ const PaintModule = {
|
|
|
1133
1163
|
shape
|
|
1134
1164
|
};
|
|
1135
1165
|
|
|
1136
|
-
let origin = {};
|
|
1137
|
-
const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper;
|
|
1166
|
+
let origin = {}, tempMatrix = getMatrixData();
|
|
1167
|
+
const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper;
|
|
1138
1168
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1139
1169
|
const transform = get$3();
|
|
1140
1170
|
translate$1(transform, box.x + x, box.y + y);
|
|
@@ -1143,7 +1173,7 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
|
1143
1173
|
rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
|
|
1144
1174
|
data.transform = transform;
|
|
1145
1175
|
}
|
|
1146
|
-
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
1176
|
+
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1147
1177
|
const transform = get$3();
|
|
1148
1178
|
if (rotation)
|
|
1149
1179
|
rotate(transform, rotation);
|
|
@@ -1152,6 +1182,10 @@ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
|
1152
1182
|
if (scaleX)
|
|
1153
1183
|
scaleHelper(transform, scaleX, scaleY);
|
|
1154
1184
|
translate$1(transform, box.x + x, box.y + y);
|
|
1185
|
+
if (clipSize) {
|
|
1186
|
+
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1187
|
+
multiplyParent(transform, tempMatrix);
|
|
1188
|
+
}
|
|
1155
1189
|
data.transform = transform;
|
|
1156
1190
|
}
|
|
1157
1191
|
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
|
|
@@ -1188,13 +1222,15 @@ const tempBox = new Bounds();
|
|
|
1188
1222
|
const tempScaleData = {};
|
|
1189
1223
|
const tempImage = {};
|
|
1190
1224
|
function createData(leafPaint, image, paint, box) {
|
|
1191
|
-
const { changeful, sync, editing } = paint;
|
|
1225
|
+
const { changeful, sync, editing, scaleFixed } = paint;
|
|
1192
1226
|
if (changeful)
|
|
1193
1227
|
leafPaint.changeful = changeful;
|
|
1194
1228
|
if (sync)
|
|
1195
1229
|
leafPaint.sync = sync;
|
|
1196
1230
|
if (editing)
|
|
1197
1231
|
leafPaint.editing = editing;
|
|
1232
|
+
if (scaleFixed)
|
|
1233
|
+
leafPaint.scaleFixed = scaleFixed;
|
|
1198
1234
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1199
1235
|
}
|
|
1200
1236
|
function getPatternData(paint, box, image) {
|
|
@@ -1203,7 +1239,7 @@ function getPatternData(paint, box, image) {
|
|
|
1203
1239
|
if (paint.mode === 'strench')
|
|
1204
1240
|
paint.mode = 'stretch';
|
|
1205
1241
|
let { width, height } = image;
|
|
1206
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
|
|
1242
|
+
const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
|
|
1207
1243
|
const sameBox = box.width === width && box.height === height;
|
|
1208
1244
|
const data = { mode };
|
|
1209
1245
|
const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
|
|
@@ -1237,8 +1273,8 @@ function getPatternData(paint, box, image) {
|
|
|
1237
1273
|
break;
|
|
1238
1274
|
case 'normal':
|
|
1239
1275
|
case 'clip':
|
|
1240
|
-
if (tempImage.x || tempImage.y || scaleX || rotation || skew)
|
|
1241
|
-
clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
|
|
1276
|
+
if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew)
|
|
1277
|
+
clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
|
|
1242
1278
|
break;
|
|
1243
1279
|
case 'repeat':
|
|
1244
1280
|
if (!sameBox || scaleX || rotation)
|
|
@@ -1375,18 +1411,16 @@ function ignoreRender(ui, value) {
|
|
|
1375
1411
|
}
|
|
1376
1412
|
|
|
1377
1413
|
const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
|
|
1378
|
-
const { ceil, abs
|
|
1414
|
+
const { ceil, abs } = Math;
|
|
1379
1415
|
function createPattern(ui, paint, pixelRatio) {
|
|
1380
|
-
let { scaleX, scaleY } =
|
|
1416
|
+
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1381
1417
|
const id = scaleX + '-' + scaleY + '-' + pixelRatio;
|
|
1382
1418
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1383
|
-
scaleX = abs$1(scaleX);
|
|
1384
|
-
scaleY = abs$1(scaleY);
|
|
1385
1419
|
const { image, data } = paint;
|
|
1386
1420
|
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
1387
1421
|
if (sx) {
|
|
1388
|
-
sx = abs
|
|
1389
|
-
sy = abs
|
|
1422
|
+
sx = abs(sx);
|
|
1423
|
+
sy = abs(sy);
|
|
1390
1424
|
imageMatrix = get$1();
|
|
1391
1425
|
copy$1(imageMatrix, transform);
|
|
1392
1426
|
scale(imageMatrix, 1 / sx, 1 / sy);
|
|
@@ -1439,9 +1473,8 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1439
1473
|
}
|
|
1440
1474
|
}
|
|
1441
1475
|
|
|
1442
|
-
const { abs } = Math;
|
|
1443
1476
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1444
|
-
const { scaleX, scaleY } =
|
|
1477
|
+
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1445
1478
|
const { pixelRatio } = canvas, { data } = paint;
|
|
1446
1479
|
if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
|
|
1447
1480
|
return false;
|
|
@@ -1454,8 +1487,8 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1454
1487
|
else {
|
|
1455
1488
|
if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
|
|
1456
1489
|
let { width, height } = data;
|
|
1457
|
-
width *=
|
|
1458
|
-
height *=
|
|
1490
|
+
width *= scaleX * pixelRatio;
|
|
1491
|
+
height *= scaleY * pixelRatio;
|
|
1459
1492
|
if (data.scaleX) {
|
|
1460
1493
|
width *= data.scaleX;
|
|
1461
1494
|
height *= data.scaleY;
|
|
@@ -1465,6 +1498,10 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1465
1498
|
}
|
|
1466
1499
|
}
|
|
1467
1500
|
if (allowDraw) {
|
|
1501
|
+
if (ui.__.__isFastShadow) {
|
|
1502
|
+
canvas.fillStyle = paint.style || '#000';
|
|
1503
|
+
canvas.fill();
|
|
1504
|
+
}
|
|
1468
1505
|
drawImage(ui, canvas, paint, data);
|
|
1469
1506
|
return true;
|
|
1470
1507
|
}
|
|
@@ -1653,10 +1690,7 @@ function shadow(ui, current, shape) {
|
|
|
1653
1690
|
}
|
|
1654
1691
|
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
|
|
1655
1692
|
}
|
|
1656
|
-
|
|
1657
|
-
current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
|
|
1658
|
-
else
|
|
1659
|
-
current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
|
|
1693
|
+
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1660
1694
|
if (end && index < end)
|
|
1661
1695
|
other.clearWorld(copyBounds, true);
|
|
1662
1696
|
});
|
|
@@ -1715,10 +1749,7 @@ function innerShadow(ui, current, shape) {
|
|
|
1715
1749
|
copyBounds = bounds;
|
|
1716
1750
|
}
|
|
1717
1751
|
other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
|
|
1718
|
-
|
|
1719
|
-
current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
|
|
1720
|
-
else
|
|
1721
|
-
current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
|
|
1752
|
+
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1722
1753
|
if (end && index < end)
|
|
1723
1754
|
other.clearWorld(copyBounds, true);
|
|
1724
1755
|
});
|
|
@@ -1774,12 +1805,11 @@ Group.prototype.__renderMask = function (canvas, options) {
|
|
|
1774
1805
|
contentCanvas = getCanvas(canvas);
|
|
1775
1806
|
child.__render(maskCanvas, options);
|
|
1776
1807
|
}
|
|
1777
|
-
if (
|
|
1778
|
-
|
|
1779
|
-
}
|
|
1780
|
-
if (excludeRenderBounds(child, options))
|
|
1808
|
+
if (mask === 'clipping' || mask === 'clipping-path')
|
|
1809
|
+
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
1781
1810
|
continue;
|
|
1782
|
-
|
|
1811
|
+
}
|
|
1812
|
+
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
1783
1813
|
}
|
|
1784
1814
|
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
1785
1815
|
};
|
|
@@ -2373,123 +2403,131 @@ function getTrimBounds(canvas) {
|
|
|
2373
2403
|
index++;
|
|
2374
2404
|
}
|
|
2375
2405
|
const bounds = new Bounds$1();
|
|
2376
|
-
|
|
2377
|
-
|
|
2406
|
+
if (pointBounds) {
|
|
2407
|
+
toBounds(pointBounds, bounds);
|
|
2408
|
+
bounds.scale(1 / canvas.pixelRatio).ceil();
|
|
2409
|
+
}
|
|
2410
|
+
return bounds;
|
|
2378
2411
|
}
|
|
2379
2412
|
|
|
2380
2413
|
const ExportModule = {
|
|
2381
2414
|
syncExport(leaf, filename, options) {
|
|
2382
|
-
|
|
2415
|
+
Export.running = true;
|
|
2383
2416
|
let result;
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
else if (fileType === 'svg') {
|
|
2394
|
-
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2395
|
-
result = { data: isDownload ? true : leaf.toSVG() };
|
|
2396
|
-
}
|
|
2397
|
-
else {
|
|
2398
|
-
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2399
|
-
const { worldTransform, isLeafer, leafer, isFrame } = leaf;
|
|
2400
|
-
const { slice, clip, trim, screenshot, padding, onCanvas } = options;
|
|
2401
|
-
const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
|
|
2402
|
-
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2403
|
-
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2404
|
-
const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
2405
|
-
if (screenshot) {
|
|
2406
|
-
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2407
|
-
}
|
|
2408
|
-
else {
|
|
2409
|
-
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2410
|
-
scaleX = worldTransform.scaleX;
|
|
2411
|
-
scaleY = worldTransform.scaleY;
|
|
2412
|
-
switch (relative) {
|
|
2413
|
-
case 'inner':
|
|
2414
|
-
matrix.set(worldTransform);
|
|
2415
|
-
break;
|
|
2416
|
-
case 'local':
|
|
2417
|
-
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2418
|
-
scaleX /= leaf.scaleX;
|
|
2419
|
-
scaleY /= leaf.scaleY;
|
|
2420
|
-
break;
|
|
2421
|
-
case 'world':
|
|
2422
|
-
scaleX = 1;
|
|
2423
|
-
scaleY = 1;
|
|
2424
|
-
break;
|
|
2425
|
-
case 'page':
|
|
2426
|
-
relative = leafer || leaf;
|
|
2427
|
-
default:
|
|
2428
|
-
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2429
|
-
const l = relative.worldTransform;
|
|
2430
|
-
scaleX /= scaleX / l.scaleX;
|
|
2431
|
-
scaleY /= scaleY / l.scaleY;
|
|
2432
|
-
}
|
|
2433
|
-
renderBounds = leaf.getBounds('render', relative);
|
|
2434
|
-
}
|
|
2435
|
-
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2436
|
-
MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2437
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2438
|
-
let { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2439
|
-
if (clip)
|
|
2440
|
-
x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
2441
|
-
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) };
|
|
2442
|
-
let canvas = Creator$1.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
|
|
2443
|
-
let sliceLeaf;
|
|
2444
|
-
if (slice) {
|
|
2445
|
-
sliceLeaf = leaf;
|
|
2446
|
-
sliceLeaf.__worldOpacity = 0;
|
|
2447
|
-
leaf = leafer || leaf;
|
|
2448
|
-
renderOptions.bounds = canvas.bounds;
|
|
2417
|
+
try {
|
|
2418
|
+
const fileType = FileHelper$1.fileType(filename);
|
|
2419
|
+
const isDownload = filename.includes('.');
|
|
2420
|
+
options = FileHelper$1.getExportOptions(options);
|
|
2421
|
+
const { toURL } = Platform$1;
|
|
2422
|
+
const { download } = Platform$1.origin;
|
|
2423
|
+
if (fileType === 'json') {
|
|
2424
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2425
|
+
result = { data: isDownload ? true : leaf.toJSON(options.json) };
|
|
2449
2426
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
leaf.fill = '';
|
|
2454
|
-
leaf.__render(canvas, renderOptions);
|
|
2455
|
-
leaf.fill = oldFill;
|
|
2427
|
+
else if (fileType === 'svg') {
|
|
2428
|
+
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2429
|
+
result = { data: isDownload ? true : leaf.toSVG() };
|
|
2456
2430
|
}
|
|
2457
2431
|
else {
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2432
|
+
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2433
|
+
const { worldTransform, isLeafer, leafer, isFrame } = leaf;
|
|
2434
|
+
const { slice, clip, trim, screenshot, padding, onCanvas } = options;
|
|
2435
|
+
const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
|
|
2436
|
+
const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
|
|
2437
|
+
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2438
|
+
const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
2439
|
+
if (screenshot) {
|
|
2440
|
+
renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
|
|
2441
|
+
}
|
|
2442
|
+
else {
|
|
2443
|
+
let relative = options.relative || (isLeafer ? 'inner' : 'local');
|
|
2444
|
+
scaleX = worldTransform.scaleX;
|
|
2445
|
+
scaleY = worldTransform.scaleY;
|
|
2446
|
+
switch (relative) {
|
|
2447
|
+
case 'inner':
|
|
2448
|
+
matrix.set(worldTransform);
|
|
2449
|
+
break;
|
|
2450
|
+
case 'local':
|
|
2451
|
+
matrix.set(worldTransform).divide(leaf.localTransform);
|
|
2452
|
+
scaleX /= leaf.scaleX;
|
|
2453
|
+
scaleY /= leaf.scaleY;
|
|
2454
|
+
break;
|
|
2455
|
+
case 'world':
|
|
2456
|
+
scaleX = 1;
|
|
2457
|
+
scaleY = 1;
|
|
2458
|
+
break;
|
|
2459
|
+
case 'page':
|
|
2460
|
+
relative = leafer || leaf;
|
|
2461
|
+
default:
|
|
2462
|
+
matrix.set(worldTransform).divide(leaf.getTransform(relative));
|
|
2463
|
+
const l = relative.worldTransform;
|
|
2464
|
+
scaleX /= scaleX / l.scaleX;
|
|
2465
|
+
scaleY /= scaleY / l.scaleY;
|
|
2466
|
+
}
|
|
2467
|
+
renderBounds = leaf.getBounds('render', relative);
|
|
2468
|
+
}
|
|
2469
|
+
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2470
|
+
MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2471
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
2472
|
+
let { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2473
|
+
if (clip)
|
|
2474
|
+
x += clip.x, y += clip.y, width = clip.width, height = clip.height;
|
|
2475
|
+
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) };
|
|
2476
|
+
let canvas = Creator$1.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
|
|
2477
|
+
let sliceLeaf;
|
|
2478
|
+
if (slice) {
|
|
2479
|
+
sliceLeaf = leaf;
|
|
2480
|
+
sliceLeaf.__worldOpacity = 0;
|
|
2481
|
+
leaf = leafer || leaf;
|
|
2482
|
+
renderOptions.bounds = canvas.bounds;
|
|
2483
|
+
}
|
|
2484
|
+
canvas.save();
|
|
2485
|
+
if (isFrame && fill !== undefined) {
|
|
2486
|
+
const oldFill = leaf.get('fill');
|
|
2487
|
+
leaf.fill = '';
|
|
2488
|
+
leaf.__render(canvas, renderOptions);
|
|
2489
|
+
leaf.fill = oldFill;
|
|
2490
|
+
}
|
|
2491
|
+
else {
|
|
2492
|
+
leaf.__render(canvas, renderOptions);
|
|
2493
|
+
}
|
|
2494
|
+
canvas.restore();
|
|
2495
|
+
if (sliceLeaf)
|
|
2496
|
+
sliceLeaf.__updateWorldOpacity();
|
|
2497
|
+
if (trim) {
|
|
2498
|
+
trimBounds = getTrimBounds(canvas);
|
|
2499
|
+
const old = canvas, { width, height } = trimBounds;
|
|
2500
|
+
const config = { x: 0, y: 0, width, height, pixelRatio };
|
|
2501
|
+
canvas = Creator$1.canvas(config);
|
|
2502
|
+
canvas.copyWorld(old, trimBounds, config);
|
|
2503
|
+
}
|
|
2504
|
+
if (padding) {
|
|
2505
|
+
const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
|
|
2506
|
+
const old = canvas, { width, height } = old;
|
|
2507
|
+
canvas = Creator$1.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
|
|
2508
|
+
canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
|
|
2509
|
+
}
|
|
2510
|
+
if (needFill)
|
|
2511
|
+
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2512
|
+
if (onCanvas)
|
|
2513
|
+
onCanvas(canvas);
|
|
2514
|
+
const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
|
|
2515
|
+
result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
|
|
2475
2516
|
}
|
|
2476
|
-
if (needFill)
|
|
2477
|
-
canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
|
|
2478
|
-
if (onCanvas)
|
|
2479
|
-
onCanvas(canvas);
|
|
2480
|
-
const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
|
|
2481
|
-
result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
|
|
2482
2517
|
}
|
|
2483
|
-
|
|
2518
|
+
catch (error) {
|
|
2519
|
+
result = { data: '', error };
|
|
2520
|
+
}
|
|
2521
|
+
Export.running = false;
|
|
2484
2522
|
return result;
|
|
2485
2523
|
},
|
|
2486
2524
|
export(leaf, filename, options) {
|
|
2487
|
-
|
|
2525
|
+
Export.running = true;
|
|
2488
2526
|
return addTask((success) => new Promise((resolve) => {
|
|
2489
2527
|
const getResult = () => __awaiter(this, void 0, void 0, function* () {
|
|
2490
2528
|
if (!Resource.isComplete)
|
|
2491
2529
|
return Platform$1.requestRender(getResult);
|
|
2492
|
-
const result =
|
|
2530
|
+
const result = Export.syncExport(leaf, filename, options);
|
|
2493
2531
|
if (result.data instanceof Promise)
|
|
2494
2532
|
result.data = yield result.data;
|
|
2495
2533
|
success(result);
|