@leafer-ui/worker 1.9.12 → 1.10.1

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/worker.cjs CHANGED
@@ -779,6 +779,7 @@ class Picker {
779
779
  hit = child.__.hitRadius ? true : hitRadiusPoint(child.__world, point);
780
780
  if (child.isBranch) {
781
781
  if (hit || child.__ignoreHitWorld) {
782
+ if (child.isBranchLeaf && child.__.__clipAfterFill && !child.__hitWorld(point)) continue;
782
783
  if (child.topChildren) this.eachFind(child.topChildren, false);
783
784
  this.eachFind(child.children, child.__onlyHitMask);
784
785
  if (child.isBranchLeaf) this.hitChild(child, point);
@@ -859,102 +860,163 @@ core.Platform.render = function(target, canvas, options) {
859
860
  if (options.topList.length) options.topList.forEach(item => item.__render(canvas, topOptions));
860
861
  };
861
862
 
862
- function fillText(ui, canvas) {
863
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
864
- if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
865
- let row;
866
- for (let i = 0, len = rows.length; i < len; i++) {
867
- row = rows[i];
868
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
869
- canvas.fillText(charData.char, charData.x, row.y);
870
- });
871
- }
872
- if (decorationY) {
873
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
874
- if (decorationColor) canvas.fillStyle = decorationColor;
875
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
876
- }
877
- }
878
-
879
- function fill(fill, ui, canvas) {
863
+ function fill(fill, ui, canvas, renderOptions) {
880
864
  canvas.fillStyle = fill;
881
- fillPathOrText(ui, canvas);
865
+ fillPathOrText(ui, canvas, renderOptions);
882
866
  }
883
867
 
884
- function fills(fills, ui, canvas) {
885
- let item;
868
+ function fills(fills, ui, canvas, renderOptions) {
869
+ let item, originPaint, countImage;
886
870
  for (let i = 0, len = fills.length; i < len; i++) {
887
- item = fills[i];
871
+ item = fills[i], originPaint = item.originPaint;
888
872
  if (item.image) {
889
- if (draw.PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue;
873
+ countImage ? countImage++ : countImage = 1;
874
+ if (draw.PaintImage.checkImage(item, !ui.__.__font, ui, canvas, renderOptions)) continue;
890
875
  if (!item.style) {
891
- if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image);
876
+ if (countImage === 1 && item.image.isPlacehold) ui.drawImagePlaceholder(item, canvas, renderOptions);
892
877
  continue;
893
878
  }
894
879
  }
895
880
  canvas.fillStyle = item.style;
896
- if (item.transform || item.scaleFixed) {
881
+ if (item.transform || originPaint.scaleFixed) {
897
882
  canvas.save();
898
883
  if (item.transform) canvas.transform(item.transform);
899
- if (item.scaleFixed) {
884
+ if (originPaint.scaleFixed) {
900
885
  const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
901
- if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
886
+ if (originPaint.scaleFixed === true || originPaint.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
902
887
  }
903
- if (item.blendMode) canvas.blendMode = item.blendMode;
904
- fillPathOrText(ui, canvas);
888
+ if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
889
+ fillPathOrText(ui, canvas, renderOptions);
905
890
  canvas.restore();
906
891
  } else {
907
- if (item.blendMode) {
908
- canvas.saveBlendMode(item.blendMode);
909
- fillPathOrText(ui, canvas);
892
+ if (originPaint.blendMode) {
893
+ canvas.saveBlendMode(originPaint.blendMode);
894
+ fillPathOrText(ui, canvas, renderOptions);
910
895
  canvas.restoreBlendMode();
911
- } else fillPathOrText(ui, canvas);
896
+ } else fillPathOrText(ui, canvas, renderOptions);
912
897
  }
913
898
  }
914
899
  }
915
900
 
916
- function fillPathOrText(ui, canvas) {
917
- ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
901
+ function fillPathOrText(ui, canvas, renderOptions) {
902
+ ui.__.__font ? draw.Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
903
+ }
904
+
905
+ function fillText(ui, canvas, _renderOptions) {
906
+ const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
907
+ if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
908
+ let row;
909
+ for (let i = 0, len = rows.length; i < len; i++) {
910
+ row = rows[i];
911
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
912
+ canvas.fillText(charData.char, charData.x, row.y);
913
+ });
914
+ }
915
+ if (decorationY) {
916
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
917
+ if (decorationColor) canvas.fillStyle = decorationColor;
918
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
919
+ }
920
+ }
921
+
922
+ function stroke(stroke, ui, canvas, renderOptions) {
923
+ const data = ui.__;
924
+ if (!data.__strokeWidth) return;
925
+ if (data.__font) {
926
+ draw.Paint.strokeText(stroke, ui, canvas, renderOptions);
927
+ } else {
928
+ switch (data.strokeAlign) {
929
+ case "center":
930
+ drawCenter$1(stroke, 1, ui, canvas, renderOptions);
931
+ break;
932
+
933
+ case "inside":
934
+ drawInside(stroke, ui, canvas, renderOptions);
935
+ break;
936
+
937
+ case "outside":
938
+ drawOutside(stroke, ui, canvas, renderOptions);
939
+ break;
940
+ }
941
+ }
942
+ }
943
+
944
+ function strokes(strokes, ui, canvas, renderOptions) {
945
+ draw.Paint.stroke(strokes, ui, canvas, renderOptions);
946
+ }
947
+
948
+ function drawCenter$1(stroke, strokeWidthScale, ui, canvas, renderOptions) {
949
+ const data = ui.__;
950
+ if (core.isObject(stroke)) {
951
+ draw.Paint.drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas, renderOptions);
952
+ } else {
953
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
954
+ canvas.stroke();
955
+ }
956
+ if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas, renderOptions);
957
+ }
958
+
959
+ function drawInside(stroke, ui, canvas, renderOptions) {
960
+ canvas.save();
961
+ canvas.clipUI(ui);
962
+ drawCenter$1(stroke, 2, ui, canvas, renderOptions);
963
+ canvas.restore();
964
+ }
965
+
966
+ function drawOutside(stroke, ui, canvas, renderOptions) {
967
+ const data = ui.__;
968
+ if (data.__fillAfterStroke) {
969
+ drawCenter$1(stroke, 2, ui, canvas, renderOptions);
970
+ } else {
971
+ const {renderBounds: renderBounds} = ui.__layout;
972
+ const out = canvas.getSameCanvas(true, true);
973
+ ui.__drawRenderPath(out);
974
+ drawCenter$1(stroke, 2, ui, out, renderOptions);
975
+ out.clipUI(data);
976
+ out.clearWorld(renderBounds);
977
+ core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
978
+ out.recycle(ui.__nowWorld);
979
+ }
918
980
  }
919
981
 
920
- function strokeText(stroke, ui, canvas) {
982
+ function strokeText(stroke, ui, canvas, renderOptions) {
921
983
  switch (ui.__.strokeAlign) {
922
984
  case "center":
923
- drawCenter$1(stroke, 1, ui, canvas);
985
+ drawCenter(stroke, 1, ui, canvas, renderOptions);
924
986
  break;
925
987
 
926
988
  case "inside":
927
- drawAlign(stroke, "inside", ui, canvas);
989
+ drawAlign(stroke, "inside", ui, canvas, renderOptions);
928
990
  break;
929
991
 
930
992
  case "outside":
931
- ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, "outside", ui, canvas);
993
+ ui.__.__fillAfterStroke ? drawCenter(stroke, 2, ui, canvas, renderOptions) : drawAlign(stroke, "outside", ui, canvas, renderOptions);
932
994
  break;
933
995
  }
934
996
  }
935
997
 
936
- function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
998
+ function drawCenter(stroke, strokeWidthScale, ui, canvas, renderOptions) {
937
999
  const data = ui.__;
938
1000
  if (core.isObject(stroke)) {
939
- drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
1001
+ draw.Paint.drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas, renderOptions);
940
1002
  } else {
941
1003
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
942
- drawTextStroke(ui, canvas);
1004
+ draw.Paint.drawTextStroke(ui, canvas, renderOptions);
943
1005
  }
944
1006
  }
945
1007
 
946
- function drawAlign(stroke, align, ui, canvas) {
1008
+ function drawAlign(stroke, align, ui, canvas, renderOptions) {
947
1009
  const out = canvas.getSameCanvas(true, true);
948
1010
  out.font = ui.__.__font;
949
- drawCenter$1(stroke, 2, ui, out);
1011
+ drawCenter(stroke, 2, ui, out, renderOptions);
950
1012
  out.blendMode = align === "outside" ? "destination-out" : "destination-in";
951
- fillText(ui, out);
1013
+ draw.Paint.fillText(ui, out, renderOptions);
952
1014
  out.blendMode = "normal";
953
1015
  core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
954
1016
  out.recycle(ui.__nowWorld);
955
1017
  }
956
1018
 
957
- function drawTextStroke(ui, canvas) {
1019
+ function drawTextStroke(ui, canvas, _renderOptions) {
958
1020
  let row, data = ui.__.__textDrawData;
959
1021
  const {rows: rows, decorationY: decorationY} = data;
960
1022
  for (let i = 0, len = rows.length; i < len; i++) {
@@ -969,89 +1031,29 @@ function drawTextStroke(ui, canvas) {
969
1031
  }
970
1032
  }
971
1033
 
972
- function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
1034
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas, renderOptions) {
973
1035
  let item;
974
1036
  const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
975
1037
  __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
976
1038
  for (let i = 0, len = strokes.length; i < len; i++) {
977
1039
  item = strokes[i];
978
- if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false)) continue;
1040
+ if (item.image && draw.PaintImage.checkImage(item, false, ui, canvas, renderOptions)) continue;
979
1041
  if (item.style) {
980
1042
  if (__hasMultiStrokeStyle) {
981
1043
  const {strokeStyle: strokeStyle} = item;
982
1044
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
983
1045
  } else canvas.strokeStyle = item.style;
984
- if (item.blendMode) {
985
- canvas.saveBlendMode(item.blendMode);
986
- isText ? drawTextStroke(ui, canvas) : canvas.stroke();
1046
+ if (item.originPaint.blendMode) {
1047
+ canvas.saveBlendMode(item.originPaint.blendMode);
1048
+ isText ? draw.Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
987
1049
  canvas.restoreBlendMode();
988
1050
  } else {
989
- isText ? drawTextStroke(ui, canvas) : canvas.stroke();
1051
+ isText ? draw.Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
990
1052
  }
991
1053
  }
992
1054
  }
993
1055
  }
994
1056
 
995
- function stroke(stroke, ui, canvas) {
996
- const data = ui.__;
997
- if (!data.__strokeWidth) return;
998
- if (data.__font) {
999
- strokeText(stroke, ui, canvas);
1000
- } else {
1001
- switch (data.strokeAlign) {
1002
- case "center":
1003
- drawCenter(stroke, 1, ui, canvas);
1004
- break;
1005
-
1006
- case "inside":
1007
- drawInside(stroke, ui, canvas);
1008
- break;
1009
-
1010
- case "outside":
1011
- drawOutside(stroke, ui, canvas);
1012
- break;
1013
- }
1014
- }
1015
- }
1016
-
1017
- function strokes(strokes, ui, canvas) {
1018
- stroke(strokes, ui, canvas);
1019
- }
1020
-
1021
- function drawCenter(stroke, strokeWidthScale, ui, canvas) {
1022
- const data = ui.__;
1023
- if (core.isObject(stroke)) {
1024
- drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
1025
- } else {
1026
- canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
1027
- canvas.stroke();
1028
- }
1029
- if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas);
1030
- }
1031
-
1032
- function drawInside(stroke, ui, canvas) {
1033
- canvas.save();
1034
- canvas.clipUI(ui);
1035
- drawCenter(stroke, 2, ui, canvas);
1036
- canvas.restore();
1037
- }
1038
-
1039
- function drawOutside(stroke, ui, canvas) {
1040
- const data = ui.__;
1041
- if (data.__fillAfterStroke) {
1042
- drawCenter(stroke, 2, ui, canvas);
1043
- } else {
1044
- const {renderBounds: renderBounds} = ui.__layout;
1045
- const out = canvas.getSameCanvas(true, true);
1046
- ui.__drawRenderPath(out);
1047
- drawCenter(stroke, 2, ui, out);
1048
- out.clipUI(data);
1049
- out.clearWorld(renderBounds);
1050
- core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
1051
- out.recycle(ui.__nowWorld);
1052
- }
1053
- }
1054
-
1055
1057
  const {getSpread: getSpread, copyAndSpread: copyAndSpread, toOuterOf: toOuterOf, getOuterOf: getOuterOf, getByMove: getByMove, move: move$1, getIntersectData: getIntersectData} = core.BoundsHelper;
1056
1058
 
1057
1059
  const tempBounds$1 = {};
@@ -1139,62 +1141,63 @@ function compute(attrName, ui) {
1139
1141
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1140
1142
  isTransparent = true;
1141
1143
  }
1142
- }
1143
- if (attrName === "fill") {
1144
- stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1145
- stintSet(data, "__isTransparentFill", isTransparent);
1144
+ if (attrName === "fill") {
1145
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1146
+ stintSet(data, "__isTransparentFill", isTransparent);
1147
+ } else {
1148
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1149
+ stintSet(data, "__isTransparentStroke", isTransparent);
1150
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1151
+ }
1146
1152
  } else {
1147
- stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1148
- stintSet(data, "__isTransparentStroke", isTransparent);
1149
- stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1153
+ data.__removePaint(attrName, false);
1150
1154
  }
1151
1155
  }
1152
1156
 
1153
1157
  function getLeafPaint(attrName, paint, ui) {
1154
1158
  if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1155
- let data;
1159
+ let leafPaint;
1156
1160
  const {boxBounds: boxBounds} = ui.__layout;
1157
1161
  switch (paint.type) {
1158
1162
  case "image":
1159
- data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1163
+ leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1160
1164
  break;
1161
1165
 
1162
1166
  case "linear":
1163
- data = draw.PaintGradient.linearGradient(paint, boxBounds);
1167
+ leafPaint = draw.PaintGradient.linearGradient(paint, boxBounds);
1164
1168
  break;
1165
1169
 
1166
1170
  case "radial":
1167
- data = draw.PaintGradient.radialGradient(paint, boxBounds);
1171
+ leafPaint = draw.PaintGradient.radialGradient(paint, boxBounds);
1168
1172
  break;
1169
1173
 
1170
1174
  case "angular":
1171
- data = draw.PaintGradient.conicGradient(paint, boxBounds);
1175
+ leafPaint = draw.PaintGradient.conicGradient(paint, boxBounds);
1172
1176
  break;
1173
1177
 
1174
1178
  case "solid":
1175
1179
  const {type: type, color: color, opacity: opacity} = paint;
1176
- data = {
1180
+ leafPaint = {
1177
1181
  type: type,
1178
1182
  style: draw.ColorConvert.string(color, opacity)
1179
1183
  };
1180
1184
  break;
1181
1185
 
1182
1186
  default:
1183
- if (!core.isUndefined(paint.r)) data = {
1187
+ if (!core.isUndefined(paint.r)) leafPaint = {
1184
1188
  type: "solid",
1185
1189
  style: draw.ColorConvert.string(paint)
1186
1190
  };
1187
1191
  }
1188
- if (data) {
1189
- if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1192
+ if (leafPaint) {
1193
+ leafPaint.originPaint = paint;
1194
+ if (core.isString(leafPaint.style) && hasTransparent$1(leafPaint.style)) leafPaint.isTransparent = true;
1190
1195
  if (paint.style) {
1191
1196
  if (paint.style.strokeWidth === 0) return undefined;
1192
- data.strokeStyle = paint.style;
1197
+ leafPaint.strokeStyle = paint.style;
1193
1198
  }
1194
- if (paint.editing) data.editing = paint.editing;
1195
- if (paint.blendMode) data.blendMode = paint.blendMode;
1196
1199
  }
1197
- return data;
1200
+ return leafPaint;
1198
1201
  }
1199
1202
 
1200
1203
  const PaintModule = {
@@ -1207,88 +1210,118 @@ const PaintModule = {
1207
1210
  strokes: strokes,
1208
1211
  strokeText: strokeText,
1209
1212
  drawTextStroke: drawTextStroke,
1213
+ drawStrokesStyle: drawStrokesStyle,
1210
1214
  shape: shape
1211
1215
  };
1212
1216
 
1213
- let origin = {}, tempMatrix$1 = core.getMatrixData();
1217
+ let cache, box = new core.Bounds;
1214
1218
 
1215
- const {get: get$3, set: set, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
1219
+ const {isSame: isSame} = core.BoundsHelper;
1216
1220
 
1217
- function stretchMode(data, box, scaleX, scaleY) {
1218
- const transform = get$3();
1219
- translate$1(transform, box.x, box.y);
1220
- if (scaleX) scaleHelper(transform, scaleX, scaleY);
1221
- data.transform = transform;
1221
+ function image(ui, attrName, paint, boxBounds, firstUse) {
1222
+ let leafPaint, event;
1223
+ const image = core.ImageManager.get(paint);
1224
+ if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1225
+ leafPaint = cache.leafPaint;
1226
+ } else {
1227
+ leafPaint = {
1228
+ type: paint.type,
1229
+ image: image
1230
+ };
1231
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1232
+ cache = image.use > 1 ? {
1233
+ leafPaint: leafPaint,
1234
+ paint: paint,
1235
+ boxBounds: box.set(boxBounds)
1236
+ } : null;
1237
+ }
1238
+ if (firstUse || image.loading) event = {
1239
+ image: image,
1240
+ attrName: attrName,
1241
+ attrValue: paint
1242
+ };
1243
+ if (image.ready) {
1244
+ checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1245
+ if (firstUse) {
1246
+ onLoad(ui, event);
1247
+ onLoadSuccess(ui, event);
1248
+ }
1249
+ } else if (image.error) {
1250
+ if (firstUse) onLoadError(ui, event, image.error);
1251
+ } else {
1252
+ if (firstUse) {
1253
+ ignoreRender(ui, true);
1254
+ onLoad(ui, event);
1255
+ }
1256
+ leafPaint.loadId = image.load(() => {
1257
+ ignoreRender(ui, false);
1258
+ if (!ui.destroyed) {
1259
+ if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1260
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1261
+ ui.forceUpdate("surface");
1262
+ }
1263
+ onLoadSuccess(ui, event);
1264
+ }
1265
+ leafPaint.loadId = undefined;
1266
+ }, error => {
1267
+ ignoreRender(ui, false);
1268
+ onLoadError(ui, event, error);
1269
+ leafPaint.loadId = undefined;
1270
+ });
1271
+ if (ui.placeholderColor) {
1272
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1273
+ if (!image.ready) {
1274
+ image.isPlacehold = true;
1275
+ ui.forceUpdate("surface");
1276
+ }
1277
+ }, ui.placeholderDelay);
1278
+ }
1279
+ }
1280
+ return leafPaint;
1222
1281
  }
1223
1282
 
1224
- function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1225
- const transform = get$3();
1226
- translate$1(transform, box.x + x, box.y + y);
1227
- scaleHelper(transform, scaleX, scaleY);
1228
- if (rotation) rotateOfOuter$1(transform, {
1229
- x: box.x + box.width / 2,
1230
- y: box.y + box.height / 2
1231
- }, rotation);
1232
- data.transform = transform;
1283
+ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1284
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
1285
+ const data = ui.__;
1286
+ data.__naturalWidth = image.width / data.pixelRatio;
1287
+ data.__naturalHeight = image.height / data.pixelRatio;
1288
+ if (data.__autoSide) {
1289
+ ui.forceUpdate("width");
1290
+ if (ui.__proxyData) {
1291
+ ui.setProxyAttr("width", data.width);
1292
+ ui.setProxyAttr("height", data.height);
1293
+ }
1294
+ return false;
1295
+ }
1296
+ }
1297
+ if (!leafPaint.data) draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
1298
+ return true;
1233
1299
  }
1234
1300
 
1235
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
1236
- const transform = get$3();
1237
- layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1238
- if (clipScaleX) {
1239
- if (rotation || skew) {
1240
- set(tempMatrix$1);
1241
- scaleOfOuter$1(tempMatrix$1, box, clipScaleX, clipScaleY);
1242
- multiplyParent(transform, tempMatrix$1);
1243
- } else scaleOfOuter$1(transform, box, clipScaleX, clipScaleY);
1244
- }
1245
- data.transform = transform;
1301
+ function onLoad(ui, event) {
1302
+ emit(ui, core.ImageEvent.LOAD, event);
1246
1303
  }
1247
1304
 
1248
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1249
- const transform = get$3();
1250
- if (freeTransform) {
1251
- layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1252
- } else {
1253
- if (rotation) {
1254
- if (align === "center") {
1255
- rotateOfOuter$1(transform, {
1256
- x: width / 2,
1257
- y: height / 2
1258
- }, rotation);
1259
- } else {
1260
- rotate(transform, rotation);
1261
- switch (rotation) {
1262
- case 90:
1263
- translate$1(transform, height, 0);
1264
- break;
1305
+ function onLoadSuccess(ui, event) {
1306
+ emit(ui, core.ImageEvent.LOADED, event);
1307
+ }
1265
1308
 
1266
- case 180:
1267
- translate$1(transform, width, height);
1268
- break;
1309
+ function onLoadError(ui, event, error) {
1310
+ event.error = error;
1311
+ ui.forceUpdate("surface");
1312
+ emit(ui, core.ImageEvent.ERROR, event);
1313
+ }
1269
1314
 
1270
- case 270:
1271
- translate$1(transform, 0, width);
1272
- break;
1273
- }
1274
- }
1275
- }
1276
- origin.x = box.x + x;
1277
- origin.y = box.y + y;
1278
- translate$1(transform, origin.x, origin.y);
1279
- if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1280
- }
1281
- data.transform = transform;
1315
+ function emit(ui, type, data) {
1316
+ if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
1282
1317
  }
1283
1318
 
1284
- function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1285
- if (rotation) rotate(transform, rotation);
1286
- if (skew) skewHelper(transform, skew.x, skew.y);
1287
- if (scaleX) scaleHelper(transform, scaleX, scaleY);
1288
- translate$1(transform, box.x + x, box.y + y);
1319
+ function ignoreRender(ui, value) {
1320
+ const {leafer: leafer} = ui;
1321
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1289
1322
  }
1290
1323
 
1291
- const {get: get$2, translate: translate} = core.MatrixHelper;
1324
+ const {get: get$3, translate: translate$1} = core.MatrixHelper;
1292
1325
 
1293
1326
  const tempBox = new core.Bounds;
1294
1327
 
@@ -1297,17 +1330,13 @@ const tempScaleData = {};
1297
1330
  const tempImage = {};
1298
1331
 
1299
1332
  function createData(leafPaint, image, paint, box) {
1300
- const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1301
- if (changeful) leafPaint.changeful = changeful;
1302
- if (sync) leafPaint.sync = sync;
1303
- if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1304
- leafPaint.data = getPatternData(paint, box, image);
1333
+ leafPaint.data = draw.PaintImage.getPatternData(paint, box, image);
1305
1334
  }
1306
1335
 
1307
1336
  function getPatternData(paint, box, image) {
1308
1337
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1309
1338
  if (paint.mode === "strench") paint.mode = "stretch";
1310
- let {width: width, height: height} = image;
1339
+ const {width: width, height: height} = image;
1311
1340
  const {opacity: opacity, mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, filters: filters} = paint;
1312
1341
  const sameBox = box.width === width && box.height === height;
1313
1342
  const data = {
@@ -1338,8 +1367,8 @@ function getPatternData(paint, box, image) {
1338
1367
  case "stretch":
1339
1368
  if (!sameBox) {
1340
1369
  scaleX = box.width / width, scaleY = box.height / height;
1341
- stretchMode(data, box, scaleX, scaleY);
1342
- }
1370
+ draw.PaintImage.stretchMode(data, box, scaleX, scaleY);
1371
+ } else if (scaleX) scaleX = scaleY = undefined;
1343
1372
  break;
1344
1373
 
1345
1374
  case "normal":
@@ -1347,13 +1376,13 @@ function getPatternData(paint, box, image) {
1347
1376
  if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) {
1348
1377
  let clipScaleX, clipScaleY;
1349
1378
  if (clipSize) clipScaleX = box.width / clipSize.width, clipScaleY = box.height / clipSize.height;
1350
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
1379
+ draw.PaintImage.clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
1351
1380
  if (clipScaleX) scaleX = scaleX ? scaleX * clipScaleX : clipScaleX, scaleY = scaleY ? scaleY * clipScaleY : clipScaleY;
1352
1381
  }
1353
1382
  break;
1354
1383
 
1355
1384
  case "repeat":
1356
- if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1385
+ if (!sameBox || scaleX || rotation || skew) draw.PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1357
1386
  if (!repeat) data.repeat = "repeat";
1358
1387
  const count = core.isObject(repeat);
1359
1388
  if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
@@ -1362,18 +1391,16 @@ function getPatternData(paint, box, image) {
1362
1391
  case "fit":
1363
1392
  case "cover":
1364
1393
  default:
1365
- if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1394
+ if (scaleX) draw.PaintImage.fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1366
1395
  }
1367
1396
  if (!data.transform) {
1368
- if (box.x || box.y) translate(data.transform = get$2(), box.x, box.y);
1397
+ if (box.x || box.y) translate$1(data.transform = get$3(), box.x, box.y);
1369
1398
  }
1370
- data.width = width;
1371
- data.height = height;
1372
1399
  if (scaleX) {
1373
1400
  data.scaleX = scaleX;
1374
1401
  data.scaleY = scaleY;
1375
1402
  }
1376
- if (opacity) data.opacity = opacity;
1403
+ if (opacity && opacity < 1) data.opacity = opacity;
1377
1404
  if (filters) data.filters = filters;
1378
1405
  if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1379
1406
  return data;
@@ -1395,180 +1422,82 @@ function getGapValue(gap, size, totalSize, rows) {
1395
1422
  return gap === "auto" ? value < 0 ? 0 : value : value;
1396
1423
  }
1397
1424
 
1398
- let cache, box = new core.Bounds;
1399
-
1400
- const {isSame: isSame} = core.BoundsHelper;
1401
-
1402
- function image(ui, attrName, paint, boxBounds, firstUse) {
1403
- let leafPaint, event;
1404
- const image = core.ImageManager.get(paint);
1405
- if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1406
- leafPaint = cache.leafPaint;
1407
- } else {
1408
- leafPaint = {
1409
- type: paint.type,
1410
- image: image
1411
- };
1412
- if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1413
- cache = image.use > 1 ? {
1414
- leafPaint: leafPaint,
1415
- paint: paint,
1416
- boxBounds: box.set(boxBounds)
1417
- } : null;
1418
- }
1419
- if (firstUse || image.loading) event = {
1420
- image: image,
1421
- attrName: attrName,
1422
- attrValue: paint
1423
- };
1424
- if (image.ready) {
1425
- checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1426
- if (firstUse) {
1427
- onLoad(ui, event);
1428
- onLoadSuccess(ui, event);
1429
- }
1430
- } else if (image.error) {
1431
- if (firstUse) onLoadError(ui, event, image.error);
1432
- } else {
1433
- if (firstUse) {
1434
- ignoreRender(ui, true);
1435
- onLoad(ui, event);
1436
- }
1437
- leafPaint.loadId = image.load(() => {
1438
- ignoreRender(ui, false);
1439
- if (!ui.destroyed) {
1440
- if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1441
- if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1442
- ui.forceUpdate("surface");
1443
- }
1444
- onLoadSuccess(ui, event);
1445
- }
1446
- leafPaint.loadId = undefined;
1447
- }, error => {
1448
- ignoreRender(ui, false);
1449
- onLoadError(ui, event, error);
1450
- leafPaint.loadId = undefined;
1451
- });
1452
- if (ui.placeholderColor) {
1453
- if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1454
- if (!image.ready) {
1455
- image.isPlacehold = true;
1456
- ui.forceUpdate("surface");
1457
- }
1458
- }, ui.placeholderDelay);
1459
- }
1460
- }
1461
- return leafPaint;
1462
- }
1463
-
1464
- function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1465
- if (attrName === "fill" && !ui.__.__naturalWidth) {
1466
- const data = ui.__;
1467
- data.__naturalWidth = image.width / data.pixelRatio;
1468
- data.__naturalHeight = image.height / data.pixelRatio;
1469
- if (data.__autoSide) {
1470
- ui.forceUpdate("width");
1471
- if (ui.__proxyData) {
1472
- ui.setProxyAttr("width", data.width);
1473
- ui.setProxyAttr("height", data.height);
1474
- }
1475
- return false;
1476
- }
1477
- }
1478
- if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
1479
- return true;
1480
- }
1481
-
1482
- function onLoad(ui, event) {
1483
- emit(ui, core.ImageEvent.LOAD, event);
1484
- }
1425
+ let origin = {}, tempMatrix$1 = core.getMatrixData();
1485
1426
 
1486
- function onLoadSuccess(ui, event) {
1487
- emit(ui, core.ImageEvent.LOADED, event);
1488
- }
1427
+ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translate, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
1489
1428
 
1490
- function onLoadError(ui, event, error) {
1491
- event.error = error;
1492
- ui.forceUpdate("surface");
1493
- emit(ui, core.ImageEvent.ERROR, event);
1429
+ function stretchMode(data, box, scaleX, scaleY) {
1430
+ const transform = get$2(), {x: x, y: y} = box;
1431
+ if (x || y) translate(transform, x, y); else transform.onlyScale = true;
1432
+ scaleHelper(transform, scaleX, scaleY);
1433
+ data.transform = transform;
1494
1434
  }
1495
1435
 
1496
- function emit(ui, type, data) {
1497
- if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
1436
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1437
+ const transform = get$2();
1438
+ translate(transform, box.x + x, box.y + y);
1439
+ scaleHelper(transform, scaleX, scaleY);
1440
+ if (rotation) rotateOfOuter$1(transform, {
1441
+ x: box.x + box.width / 2,
1442
+ y: box.y + box.height / 2
1443
+ }, rotation);
1444
+ data.transform = transform;
1498
1445
  }
1499
1446
 
1500
- function ignoreRender(ui, value) {
1501
- const {leafer: leafer} = ui;
1502
- if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1447
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
1448
+ const transform = get$2();
1449
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1450
+ if (clipScaleX) {
1451
+ if (rotation || skew) {
1452
+ set(tempMatrix$1);
1453
+ scaleOfOuter$1(tempMatrix$1, box, clipScaleX, clipScaleY);
1454
+ multiplyParent(transform, tempMatrix$1);
1455
+ } else scaleOfOuter$1(transform, box, clipScaleX, clipScaleY);
1456
+ }
1457
+ data.transform = transform;
1503
1458
  }
1504
1459
 
1505
- const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1460
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1461
+ const transform = get$2();
1462
+ if (freeTransform) {
1463
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1464
+ } else {
1465
+ if (rotation) {
1466
+ if (align === "center") {
1467
+ rotateOfOuter$1(transform, {
1468
+ x: width / 2,
1469
+ y: height / 2
1470
+ }, rotation);
1471
+ } else {
1472
+ rotate(transform, rotation);
1473
+ switch (rotation) {
1474
+ case 90:
1475
+ translate(transform, height, 0);
1476
+ break;
1506
1477
 
1507
- const {floor: floor, ceil: ceil, max: max$1, abs: abs$1} = Math;
1478
+ case 180:
1479
+ translate(transform, width, height);
1480
+ break;
1508
1481
 
1509
- function createPattern(ui, paint, pixelRatio) {
1510
- let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1511
- const id = scaleX + "-" + scaleY + "-" + pixelRatio;
1512
- if (paint.patternId !== id && !ui.destroyed) {
1513
- const {image: image, data: data} = paint;
1514
- let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
1515
- scaleX *= pixelRatio;
1516
- scaleY *= pixelRatio;
1517
- if (sx) {
1518
- sx = abs$1(sx);
1519
- sy = abs$1(sy);
1520
- imageMatrix = get$1();
1521
- copy$1(imageMatrix, transform);
1522
- scale(imageMatrix, 1 / sx, 1 / sy);
1523
- scaleX *= sx;
1524
- scaleY *= sy;
1525
- }
1526
- width *= scaleX;
1527
- height *= scaleY;
1528
- const size = width * height;
1529
- if (!repeat) {
1530
- if (size > core.Platform.image.maxCacheSize) return false;
1531
- }
1532
- let maxSize = core.Platform.image.maxPatternSize;
1533
- if (image.isSVG) {
1534
- const ws = width / image.width;
1535
- if (ws > 1) imageScale = ws / ceil(ws);
1536
- } else {
1537
- const imageSize = image.width * image.height;
1538
- if (maxSize > imageSize) maxSize = imageSize;
1539
- }
1540
- if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
1541
- if (imageScale) {
1542
- scaleX /= imageScale;
1543
- scaleY /= imageScale;
1544
- width /= imageScale;
1545
- height /= imageScale;
1546
- }
1547
- if (sx) {
1548
- scaleX /= sx;
1549
- scaleY /= sy;
1550
- }
1551
- const xGap = gap && gap.x * scaleX;
1552
- const yGap = gap && gap.y * scaleY;
1553
- if (transform || scaleX !== 1 || scaleY !== 1) {
1554
- const canvasWidth = width + (xGap || 0);
1555
- const canvasHeight = height + (yGap || 0);
1556
- scaleX /= canvasWidth / max$1(floor(canvasWidth), 1);
1557
- scaleY /= canvasHeight / max$1(floor(canvasHeight), 1);
1558
- if (!imageMatrix) {
1559
- imageMatrix = get$1();
1560
- if (transform) copy$1(imageMatrix, transform);
1482
+ case 270:
1483
+ translate(transform, 0, width);
1484
+ break;
1485
+ }
1561
1486
  }
1562
- scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1563
1487
  }
1564
- const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
1565
- const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1566
- paint.style = pattern;
1567
- paint.patternId = id;
1568
- return true;
1569
- } else {
1570
- return false;
1488
+ origin.x = box.x + x;
1489
+ origin.y = box.y + y;
1490
+ translate(transform, origin.x, origin.y);
1491
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1571
1492
  }
1493
+ data.transform = transform;
1494
+ }
1495
+
1496
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1497
+ if (rotation) rotate(transform, rotation);
1498
+ if (skew) skewHelper(transform, skew.x, skew.y);
1499
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
1500
+ translate(transform, box.x + x, box.y + y);
1572
1501
  }
1573
1502
 
1574
1503
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -1604,58 +1533,116 @@ typeof SuppressedError === "function" ? SuppressedError : function(error, suppre
1604
1533
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1605
1534
  };
1606
1535
 
1607
- function checkImage(ui, canvas, paint, allowDraw) {
1608
- const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1609
- const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
1610
- if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !draw.Export.running) {
1536
+ const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1537
+
1538
+ const {getFloorScale: getFloorScale} = core.MathHelper, {abs: abs$1} = Math;
1539
+
1540
+ function createPatternTask(paint, ui, canvas, renderOptions) {
1541
+ if (!paint.patternTask) {
1542
+ paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1543
+ paint.patternTask = null;
1544
+ if (canvas.bounds.hit(ui.__nowWorld)) draw.PaintImage.createPattern(paint, ui, canvas, renderOptions);
1545
+ ui.forceUpdate("surface");
1546
+ }), 300);
1547
+ }
1548
+ }
1549
+
1550
+ function createPattern(paint, ui, canvas, renderOptions) {
1551
+ let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
1552
+ if (paint.patternId !== id && !ui.destroyed) {
1553
+ if (!(core.Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
1554
+ const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
1555
+ let imageMatrix, xGap, yGap, {width: width, height: height} = image;
1556
+ if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
1557
+ width *= scaleX;
1558
+ height *= scaleY;
1559
+ if (gap) {
1560
+ xGap = gap.x * scaleX / abs$1(data.scaleX || 1);
1561
+ yGap = gap.y * scaleY / abs$1(data.scaleY || 1);
1562
+ }
1563
+ if (transform || scaleX !== 1 || scaleY !== 1) {
1564
+ scaleX *= getFloorScale(width + (xGap || 0));
1565
+ scaleY *= getFloorScale(height + (yGap || 0));
1566
+ imageMatrix = get$1();
1567
+ if (transform) copy$1(imageMatrix, transform);
1568
+ scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1569
+ }
1570
+ const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
1571
+ const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1572
+ paint.style = pattern;
1573
+ paint.patternId = id;
1574
+ }
1575
+ }
1576
+ }
1577
+
1578
+ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
1579
+ const {image: image} = paint;
1580
+ let fixScale, maxSize = core.Platform.image.maxPatternSize, imageSize = image.width * image.height;
1581
+ if (image.isSVG) {
1582
+ if (imageScaleX > 1) fixScale = Math.ceil(imageScaleX) / imageScaleX;
1583
+ } else {
1584
+ if (maxSize > imageSize) maxSize = imageSize;
1585
+ }
1586
+ if ((imageSize *= imageScaleX * imageScaleY) > maxSize) fixScale = Math.sqrt(maxSize / imageSize);
1587
+ return fixScale;
1588
+ }
1589
+
1590
+ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1591
+ const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
1592
+ const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting} = renderOptions;
1593
+ if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting) {
1611
1594
  return false;
1612
1595
  } else {
1613
- if (allowDraw) {
1596
+ if (drawImage) {
1614
1597
  if (data.repeat) {
1615
- allowDraw = false;
1616
- } else if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1617
- let {width: width, height: height} = data;
1618
- width *= scaleX * pixelRatio;
1619
- height *= scaleY * pixelRatio;
1620
- if (data.scaleX) {
1621
- width *= data.scaleX;
1622
- height *= data.scaleY;
1623
- }
1624
- allowDraw = width * height > core.Platform.image.maxCacheSize;
1598
+ drawImage = false;
1599
+ } else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
1600
+ drawImage = core.Platform.image.isLarge(image, scaleX, scaleY);
1625
1601
  }
1626
1602
  }
1627
- if (allowDraw) {
1603
+ if (drawImage) {
1628
1604
  if (ui.__.__isFastShadow) {
1629
1605
  canvas.fillStyle = paint.style || "#000";
1630
1606
  canvas.fill();
1631
1607
  }
1632
- drawImage(ui, canvas, paint, data);
1608
+ draw.PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
1633
1609
  return true;
1634
1610
  } else {
1635
- if (!paint.style || paint.sync || draw.Export.running) {
1636
- createPattern(ui, paint, pixelRatio);
1637
- } else {
1638
- if (!paint.patternTask) {
1639
- paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1640
- paint.patternTask = null;
1641
- if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
1642
- ui.forceUpdate("surface");
1643
- }), 300);
1644
- }
1645
- }
1611
+ if (!paint.style || originPaint.sync || exporting) draw.PaintImage.createPattern(paint, ui, canvas, renderOptions); else draw.PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
1646
1612
  return false;
1647
1613
  }
1648
1614
  }
1649
1615
  }
1650
1616
 
1651
- function drawImage(ui, canvas, paint, data) {
1652
- canvas.save();
1653
- canvas.clipUI(ui);
1654
- if (paint.blendMode) canvas.blendMode = paint.blendMode;
1655
- if (data.opacity) canvas.opacity *= data.opacity;
1656
- if (data.transform) canvas.transform(data.transform);
1657
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1658
- canvas.restore();
1617
+ function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
1618
+ const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1619
+ let {width: width, height: height} = image, clipUI;
1620
+ if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
1621
+ canvas.save();
1622
+ clipUI && canvas.clipUI(ui);
1623
+ blendMode && (canvas.blendMode = blendMode);
1624
+ opacity && (canvas.opacity *= opacity);
1625
+ transform && canvas.transform(transform);
1626
+ canvas.drawImage(view, 0, 0, width, height);
1627
+ canvas.restore();
1628
+ } else {
1629
+ if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
1630
+ canvas.drawImage(view, 0, 0, width, height);
1631
+ }
1632
+ }
1633
+
1634
+ function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
1635
+ const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
1636
+ if (canvas) {
1637
+ const {pixelRatio: pixelRatio} = canvas;
1638
+ scaleData.scaleX *= pixelRatio;
1639
+ scaleData.scaleY *= pixelRatio;
1640
+ }
1641
+ if (data && data.scaleX) {
1642
+ scaleData.scaleX *= Math.abs(data.scaleX);
1643
+ scaleData.scaleY *= Math.abs(data.scaleY);
1644
+ }
1645
+ return scaleData;
1659
1646
  }
1660
1647
 
1661
1648
  function recycleImage(attrName, data) {
@@ -1687,8 +1674,12 @@ function recycleImage(attrName, data) {
1687
1674
  const PaintImageModule = {
1688
1675
  image: image,
1689
1676
  checkImage: checkImage,
1690
- createPattern: createPattern,
1677
+ drawImage: drawImage,
1678
+ getImageRenderScaleData: getImageRenderScaleData,
1691
1679
  recycleImage: recycleImage,
1680
+ createPatternTask: createPatternTask,
1681
+ createPattern: createPattern,
1682
+ getPatternFixScale: getPatternFixScale,
1692
1683
  createData: createData,
1693
1684
  getPatternData: getPatternData,
1694
1685
  stretchMode: stretchMode,
@@ -2144,10 +2135,8 @@ function createRows(drawData, content, style) {
2144
2135
  bounds = drawData.bounds;
2145
2136
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
2146
2137
  const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
2147
- const {canvas: canvas} = core.Platform;
2148
- const {width: width, height: height} = bounds;
2149
- const charMode = width || height || __letterSpacing || textCase !== "none";
2150
- if (charMode) {
2138
+ const {canvas: canvas} = core.Platform, {width: width} = bounds;
2139
+ if (style.__isCharMode) {
2151
2140
  const wrap = style.textWrap !== "none";
2152
2141
  const breakAll = style.textWrap === "break";
2153
2142
  paraStart = true;
@@ -2276,12 +2265,19 @@ const TextMode = 2;
2276
2265
  function layoutChar(drawData, style, width, _height) {
2277
2266
  const {rows: rows} = drawData;
2278
2267
  const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
2279
- let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2268
+ const justifyLast = width && textAlign.includes("both");
2269
+ const justify = justifyLast || width && textAlign.includes("justify");
2270
+ const justifyLetter = justify && textAlign.includes("letter");
2271
+ let charX, remainingWidth, addWordWidth, addLetterWidth, indentWidth, mode, wordChar, wordsLength, isLastWord, canJustify;
2280
2272
  rows.forEach(row => {
2281
2273
  if (row.words) {
2282
2274
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2283
- addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2284
- mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
2275
+ if (justify) {
2276
+ canJustify = !row.paraEnd || justifyLast;
2277
+ remainingWidth = width - row.width - indentWidth;
2278
+ if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
2279
+ }
2280
+ mode = letterSpacing || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
2285
2281
  if (row.isOverflow && !letterSpacing) row.textMode = true;
2286
2282
  if (mode === TextMode) {
2287
2283
  row.x += indentWidth;
@@ -2299,11 +2295,15 @@ function layoutChar(drawData, style, width, _height) {
2299
2295
  charX = toWordChar(word.data, charX, wordChar);
2300
2296
  if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
2301
2297
  } else {
2302
- charX = toChar(word.data, charX, row.data, row.isOverflow);
2298
+ charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
2303
2299
  }
2304
- if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
2305
- charX += addWordWidth;
2306
- row.width += addWordWidth;
2300
+ if (canJustify) {
2301
+ isLastWord = index === wordsLength - 1;
2302
+ if (addWordWidth) {
2303
+ if (!isLastWord) charX += addWordWidth, row.width += addWordWidth;
2304
+ } else if (addLetterWidth) {
2305
+ row.width += addLetterWidth * (word.data.length - (isLastWord ? 1 : 0));
2306
+ }
2307
2307
  }
2308
2308
  });
2309
2309
  }
@@ -2329,13 +2329,14 @@ function toWordChar(data, charX, wordChar) {
2329
2329
  return charX;
2330
2330
  }
2331
2331
 
2332
- function toChar(data, charX, rowData, isOverflow) {
2332
+ function toChar(data, charX, rowData, isOverflow, addLetterWidth) {
2333
2333
  data.forEach(char => {
2334
2334
  if (isOverflow || char.char !== " ") {
2335
2335
  char.x = charX;
2336
2336
  rowData.push(char);
2337
2337
  }
2338
2338
  charX += char.width;
2339
+ addLetterWidth && (charX += addLetterWidth);
2339
2340
  });
2340
2341
  return charX;
2341
2342
  }
@@ -2477,10 +2478,10 @@ function getDrawData(content, style) {
2477
2478
  let x = 0, y = 0;
2478
2479
  let width = style.__getInput("width") || 0;
2479
2480
  let height = style.__getInput("height") || 0;
2480
- const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
2481
+ const {__padding: padding} = style;
2481
2482
  if (padding) {
2482
- if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
2483
- if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
2483
+ if (width) x = padding[left], width -= padding[right] + padding[left], !width && (width = .01); else if (!style.autoSizeAlign) x = padding[left];
2484
+ if (height) y = padding[top], height -= padding[top] + padding[bottom], !height && (height = .01); else if (!style.autoSizeAlign) y = padding[top];
2484
2485
  }
2485
2486
  const drawData = {
2486
2487
  bounds: {
@@ -2491,14 +2492,14 @@ function getDrawData(content, style) {
2491
2492
  },
2492
2493
  rows: [],
2493
2494
  paraNumber: 0,
2494
- font: core.Platform.canvas.font = __font
2495
+ font: core.Platform.canvas.font = style.__font
2495
2496
  };
2496
2497
  createRows(drawData, content, style);
2497
2498
  if (padding) padAutoText(padding, drawData, style, width, height);
2498
2499
  layoutText(drawData, style);
2499
- layoutChar(drawData, style, width);
2500
+ if (style.__isCharMode) layoutChar(drawData, style, width);
2500
2501
  if (drawData.overflow) clipText(drawData, style, x, width);
2501
- if (textDecoration !== "none") decorationText(drawData, style);
2502
+ if (style.textDecoration !== "none") decorationText(drawData, style);
2502
2503
  return drawData;
2503
2504
  }
2504
2505