@leafer-ui/miniapp 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/miniapp.cjs CHANGED
@@ -932,6 +932,7 @@ class Picker {
932
932
  hit = child.__.hitRadius ? true : hitRadiusPoint(child.__world, point);
933
933
  if (child.isBranch) {
934
934
  if (hit || child.__ignoreHitWorld) {
935
+ if (child.isBranchLeaf && child.__.__clipAfterFill && !child.__hitWorld(point)) continue;
935
936
  if (child.topChildren) this.eachFind(child.topChildren, false);
936
937
  this.eachFind(child.children, child.__onlyHitMask);
937
938
  if (child.isBranchLeaf) this.hitChild(child, point);
@@ -1124,102 +1125,163 @@ class Interaction extends core$1.InteractionBase {
1124
1125
  }
1125
1126
  }
1126
1127
 
1127
- function fillText(ui, canvas) {
1128
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
1129
- if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
1130
- let row;
1131
- for (let i = 0, len = rows.length; i < len; i++) {
1132
- row = rows[i];
1133
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
1134
- canvas.fillText(charData.char, charData.x, row.y);
1135
- });
1136
- }
1137
- if (decorationY) {
1138
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
1139
- if (decorationColor) canvas.fillStyle = decorationColor;
1140
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
1141
- }
1142
- }
1143
-
1144
- function fill(fill, ui, canvas) {
1128
+ function fill(fill, ui, canvas, renderOptions) {
1145
1129
  canvas.fillStyle = fill;
1146
- fillPathOrText(ui, canvas);
1130
+ fillPathOrText(ui, canvas, renderOptions);
1147
1131
  }
1148
1132
 
1149
- function fills(fills, ui, canvas) {
1150
- let item;
1133
+ function fills(fills, ui, canvas, renderOptions) {
1134
+ let item, originPaint, countImage;
1151
1135
  for (let i = 0, len = fills.length; i < len; i++) {
1152
- item = fills[i];
1136
+ item = fills[i], originPaint = item.originPaint;
1153
1137
  if (item.image) {
1154
- if (draw.PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue;
1138
+ countImage ? countImage++ : countImage = 1;
1139
+ if (draw.PaintImage.checkImage(item, !ui.__.__font, ui, canvas, renderOptions)) continue;
1155
1140
  if (!item.style) {
1156
- if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image);
1141
+ if (countImage === 1 && item.image.isPlacehold) ui.drawImagePlaceholder(item, canvas, renderOptions);
1157
1142
  continue;
1158
1143
  }
1159
1144
  }
1160
1145
  canvas.fillStyle = item.style;
1161
- if (item.transform || item.scaleFixed) {
1146
+ if (item.transform || originPaint.scaleFixed) {
1162
1147
  canvas.save();
1163
1148
  if (item.transform) canvas.transform(item.transform);
1164
- if (item.scaleFixed) {
1149
+ if (originPaint.scaleFixed) {
1165
1150
  const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
1166
- if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
1151
+ if (originPaint.scaleFixed === true || originPaint.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
1167
1152
  }
1168
- if (item.blendMode) canvas.blendMode = item.blendMode;
1169
- fillPathOrText(ui, canvas);
1153
+ if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
1154
+ fillPathOrText(ui, canvas, renderOptions);
1170
1155
  canvas.restore();
1171
1156
  } else {
1172
- if (item.blendMode) {
1173
- canvas.saveBlendMode(item.blendMode);
1174
- fillPathOrText(ui, canvas);
1157
+ if (originPaint.blendMode) {
1158
+ canvas.saveBlendMode(originPaint.blendMode);
1159
+ fillPathOrText(ui, canvas, renderOptions);
1175
1160
  canvas.restoreBlendMode();
1176
- } else fillPathOrText(ui, canvas);
1161
+ } else fillPathOrText(ui, canvas, renderOptions);
1177
1162
  }
1178
1163
  }
1179
1164
  }
1180
1165
 
1181
- function fillPathOrText(ui, canvas) {
1182
- ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
1166
+ function fillPathOrText(ui, canvas, renderOptions) {
1167
+ ui.__.__font ? draw.Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
1183
1168
  }
1184
1169
 
1185
- function strokeText(stroke, ui, canvas) {
1170
+ function fillText(ui, canvas, _renderOptions) {
1171
+ const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
1172
+ if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
1173
+ let row;
1174
+ for (let i = 0, len = rows.length; i < len; i++) {
1175
+ row = rows[i];
1176
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
1177
+ canvas.fillText(charData.char, charData.x, row.y);
1178
+ });
1179
+ }
1180
+ if (decorationY) {
1181
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
1182
+ if (decorationColor) canvas.fillStyle = decorationColor;
1183
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
1184
+ }
1185
+ }
1186
+
1187
+ function stroke(stroke, ui, canvas, renderOptions) {
1188
+ const data = ui.__;
1189
+ if (!data.__strokeWidth) return;
1190
+ if (data.__font) {
1191
+ draw.Paint.strokeText(stroke, ui, canvas, renderOptions);
1192
+ } else {
1193
+ switch (data.strokeAlign) {
1194
+ case "center":
1195
+ drawCenter$1(stroke, 1, ui, canvas, renderOptions);
1196
+ break;
1197
+
1198
+ case "inside":
1199
+ drawInside(stroke, ui, canvas, renderOptions);
1200
+ break;
1201
+
1202
+ case "outside":
1203
+ drawOutside(stroke, ui, canvas, renderOptions);
1204
+ break;
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ function strokes(strokes, ui, canvas, renderOptions) {
1210
+ draw.Paint.stroke(strokes, ui, canvas, renderOptions);
1211
+ }
1212
+
1213
+ function drawCenter$1(stroke, strokeWidthScale, ui, canvas, renderOptions) {
1214
+ const data = ui.__;
1215
+ if (core.isObject(stroke)) {
1216
+ draw.Paint.drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas, renderOptions);
1217
+ } else {
1218
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
1219
+ canvas.stroke();
1220
+ }
1221
+ if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas, renderOptions);
1222
+ }
1223
+
1224
+ function drawInside(stroke, ui, canvas, renderOptions) {
1225
+ canvas.save();
1226
+ canvas.clipUI(ui);
1227
+ drawCenter$1(stroke, 2, ui, canvas, renderOptions);
1228
+ canvas.restore();
1229
+ }
1230
+
1231
+ function drawOutside(stroke, ui, canvas, renderOptions) {
1232
+ const data = ui.__;
1233
+ if (data.__fillAfterStroke) {
1234
+ drawCenter$1(stroke, 2, ui, canvas, renderOptions);
1235
+ } else {
1236
+ const {renderBounds: renderBounds} = ui.__layout;
1237
+ const out = canvas.getSameCanvas(true, true);
1238
+ ui.__drawRenderPath(out);
1239
+ drawCenter$1(stroke, 2, ui, out, renderOptions);
1240
+ out.clipUI(data);
1241
+ out.clearWorld(renderBounds);
1242
+ core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
1243
+ out.recycle(ui.__nowWorld);
1244
+ }
1245
+ }
1246
+
1247
+ function strokeText(stroke, ui, canvas, renderOptions) {
1186
1248
  switch (ui.__.strokeAlign) {
1187
1249
  case "center":
1188
- drawCenter$1(stroke, 1, ui, canvas);
1250
+ drawCenter(stroke, 1, ui, canvas, renderOptions);
1189
1251
  break;
1190
1252
 
1191
1253
  case "inside":
1192
- drawAlign(stroke, "inside", ui, canvas);
1254
+ drawAlign(stroke, "inside", ui, canvas, renderOptions);
1193
1255
  break;
1194
1256
 
1195
1257
  case "outside":
1196
- ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, "outside", ui, canvas);
1258
+ ui.__.__fillAfterStroke ? drawCenter(stroke, 2, ui, canvas, renderOptions) : drawAlign(stroke, "outside", ui, canvas, renderOptions);
1197
1259
  break;
1198
1260
  }
1199
1261
  }
1200
1262
 
1201
- function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
1263
+ function drawCenter(stroke, strokeWidthScale, ui, canvas, renderOptions) {
1202
1264
  const data = ui.__;
1203
1265
  if (core.isObject(stroke)) {
1204
- drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
1266
+ draw.Paint.drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas, renderOptions);
1205
1267
  } else {
1206
1268
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
1207
- drawTextStroke(ui, canvas);
1269
+ draw.Paint.drawTextStroke(ui, canvas, renderOptions);
1208
1270
  }
1209
1271
  }
1210
1272
 
1211
- function drawAlign(stroke, align, ui, canvas) {
1273
+ function drawAlign(stroke, align, ui, canvas, renderOptions) {
1212
1274
  const out = canvas.getSameCanvas(true, true);
1213
1275
  out.font = ui.__.__font;
1214
- drawCenter$1(stroke, 2, ui, out);
1276
+ drawCenter(stroke, 2, ui, out, renderOptions);
1215
1277
  out.blendMode = align === "outside" ? "destination-out" : "destination-in";
1216
- fillText(ui, out);
1278
+ draw.Paint.fillText(ui, out, renderOptions);
1217
1279
  out.blendMode = "normal";
1218
1280
  core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
1219
1281
  out.recycle(ui.__nowWorld);
1220
1282
  }
1221
1283
 
1222
- function drawTextStroke(ui, canvas) {
1284
+ function drawTextStroke(ui, canvas, _renderOptions) {
1223
1285
  let row, data = ui.__.__textDrawData;
1224
1286
  const {rows: rows, decorationY: decorationY} = data;
1225
1287
  for (let i = 0, len = rows.length; i < len; i++) {
@@ -1234,89 +1296,29 @@ function drawTextStroke(ui, canvas) {
1234
1296
  }
1235
1297
  }
1236
1298
 
1237
- function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
1299
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas, renderOptions) {
1238
1300
  let item;
1239
1301
  const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
1240
1302
  __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
1241
1303
  for (let i = 0, len = strokes.length; i < len; i++) {
1242
1304
  item = strokes[i];
1243
- if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false)) continue;
1305
+ if (item.image && draw.PaintImage.checkImage(item, false, ui, canvas, renderOptions)) continue;
1244
1306
  if (item.style) {
1245
1307
  if (__hasMultiStrokeStyle) {
1246
1308
  const {strokeStyle: strokeStyle} = item;
1247
1309
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
1248
1310
  } else canvas.strokeStyle = item.style;
1249
- if (item.blendMode) {
1250
- canvas.saveBlendMode(item.blendMode);
1251
- isText ? drawTextStroke(ui, canvas) : canvas.stroke();
1311
+ if (item.originPaint.blendMode) {
1312
+ canvas.saveBlendMode(item.originPaint.blendMode);
1313
+ isText ? draw.Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
1252
1314
  canvas.restoreBlendMode();
1253
1315
  } else {
1254
- isText ? drawTextStroke(ui, canvas) : canvas.stroke();
1316
+ isText ? draw.Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
1255
1317
  }
1256
1318
  }
1257
1319
  }
1258
1320
  }
1259
1321
 
1260
- function stroke(stroke, ui, canvas) {
1261
- const data = ui.__;
1262
- if (!data.__strokeWidth) return;
1263
- if (data.__font) {
1264
- strokeText(stroke, ui, canvas);
1265
- } else {
1266
- switch (data.strokeAlign) {
1267
- case "center":
1268
- drawCenter(stroke, 1, ui, canvas);
1269
- break;
1270
-
1271
- case "inside":
1272
- drawInside(stroke, ui, canvas);
1273
- break;
1274
-
1275
- case "outside":
1276
- drawOutside(stroke, ui, canvas);
1277
- break;
1278
- }
1279
- }
1280
- }
1281
-
1282
- function strokes(strokes, ui, canvas) {
1283
- stroke(strokes, ui, canvas);
1284
- }
1285
-
1286
- function drawCenter(stroke, strokeWidthScale, ui, canvas) {
1287
- const data = ui.__;
1288
- if (core.isObject(stroke)) {
1289
- drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
1290
- } else {
1291
- canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
1292
- canvas.stroke();
1293
- }
1294
- if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas);
1295
- }
1296
-
1297
- function drawInside(stroke, ui, canvas) {
1298
- canvas.save();
1299
- canvas.clipUI(ui);
1300
- drawCenter(stroke, 2, ui, canvas);
1301
- canvas.restore();
1302
- }
1303
-
1304
- function drawOutside(stroke, ui, canvas) {
1305
- const data = ui.__;
1306
- if (data.__fillAfterStroke) {
1307
- drawCenter(stroke, 2, ui, canvas);
1308
- } else {
1309
- const {renderBounds: renderBounds} = ui.__layout;
1310
- const out = canvas.getSameCanvas(true, true);
1311
- ui.__drawRenderPath(out);
1312
- drawCenter(stroke, 2, ui, out);
1313
- out.clipUI(data);
1314
- out.clearWorld(renderBounds);
1315
- core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
1316
- out.recycle(ui.__nowWorld);
1317
- }
1318
- }
1319
-
1320
1322
  const {getSpread: getSpread, copyAndSpread: copyAndSpread, toOuterOf: toOuterOf, getOuterOf: getOuterOf, getByMove: getByMove, move: move$1, getIntersectData: getIntersectData} = core.BoundsHelper;
1321
1323
 
1322
1324
  const tempBounds$1 = {};
@@ -1404,62 +1406,63 @@ function compute(attrName, ui) {
1404
1406
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1405
1407
  isTransparent = true;
1406
1408
  }
1407
- }
1408
- if (attrName === "fill") {
1409
- stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1410
- stintSet(data, "__isTransparentFill", isTransparent);
1409
+ if (attrName === "fill") {
1410
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1411
+ stintSet(data, "__isTransparentFill", isTransparent);
1412
+ } else {
1413
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1414
+ stintSet(data, "__isTransparentStroke", isTransparent);
1415
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1416
+ }
1411
1417
  } else {
1412
- stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1413
- stintSet(data, "__isTransparentStroke", isTransparent);
1414
- stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1418
+ data.__removePaint(attrName, false);
1415
1419
  }
1416
1420
  }
1417
1421
 
1418
1422
  function getLeafPaint(attrName, paint, ui) {
1419
1423
  if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1420
- let data;
1424
+ let leafPaint;
1421
1425
  const {boxBounds: boxBounds} = ui.__layout;
1422
1426
  switch (paint.type) {
1423
1427
  case "image":
1424
- data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1428
+ leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1425
1429
  break;
1426
1430
 
1427
1431
  case "linear":
1428
- data = draw.PaintGradient.linearGradient(paint, boxBounds);
1432
+ leafPaint = draw.PaintGradient.linearGradient(paint, boxBounds);
1429
1433
  break;
1430
1434
 
1431
1435
  case "radial":
1432
- data = draw.PaintGradient.radialGradient(paint, boxBounds);
1436
+ leafPaint = draw.PaintGradient.radialGradient(paint, boxBounds);
1433
1437
  break;
1434
1438
 
1435
1439
  case "angular":
1436
- data = draw.PaintGradient.conicGradient(paint, boxBounds);
1440
+ leafPaint = draw.PaintGradient.conicGradient(paint, boxBounds);
1437
1441
  break;
1438
1442
 
1439
1443
  case "solid":
1440
1444
  const {type: type, color: color, opacity: opacity} = paint;
1441
- data = {
1445
+ leafPaint = {
1442
1446
  type: type,
1443
1447
  style: draw.ColorConvert.string(color, opacity)
1444
1448
  };
1445
1449
  break;
1446
1450
 
1447
1451
  default:
1448
- if (!core.isUndefined(paint.r)) data = {
1452
+ if (!core.isUndefined(paint.r)) leafPaint = {
1449
1453
  type: "solid",
1450
1454
  style: draw.ColorConvert.string(paint)
1451
1455
  };
1452
1456
  }
1453
- if (data) {
1454
- if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1457
+ if (leafPaint) {
1458
+ leafPaint.originPaint = paint;
1459
+ if (core.isString(leafPaint.style) && hasTransparent$1(leafPaint.style)) leafPaint.isTransparent = true;
1455
1460
  if (paint.style) {
1456
1461
  if (paint.style.strokeWidth === 0) return undefined;
1457
- data.strokeStyle = paint.style;
1462
+ leafPaint.strokeStyle = paint.style;
1458
1463
  }
1459
- if (paint.editing) data.editing = paint.editing;
1460
- if (paint.blendMode) data.blendMode = paint.blendMode;
1461
1464
  }
1462
- return data;
1465
+ return leafPaint;
1463
1466
  }
1464
1467
 
1465
1468
  const PaintModule = {
@@ -1472,88 +1475,118 @@ const PaintModule = {
1472
1475
  strokes: strokes,
1473
1476
  strokeText: strokeText,
1474
1477
  drawTextStroke: drawTextStroke,
1478
+ drawStrokesStyle: drawStrokesStyle,
1475
1479
  shape: shape
1476
1480
  };
1477
1481
 
1478
- let origin = {}, tempMatrix$1 = core.getMatrixData();
1482
+ let cache, box = new core.Bounds;
1479
1483
 
1480
- 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;
1484
+ const {isSame: isSame} = core.BoundsHelper;
1481
1485
 
1482
- function stretchMode(data, box, scaleX, scaleY) {
1483
- const transform = get$3();
1484
- translate$1(transform, box.x, box.y);
1485
- if (scaleX) scaleHelper(transform, scaleX, scaleY);
1486
- data.transform = transform;
1486
+ function image(ui, attrName, paint, boxBounds, firstUse) {
1487
+ let leafPaint, event;
1488
+ const image = core.ImageManager.get(paint);
1489
+ if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1490
+ leafPaint = cache.leafPaint;
1491
+ } else {
1492
+ leafPaint = {
1493
+ type: paint.type,
1494
+ image: image
1495
+ };
1496
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1497
+ cache = image.use > 1 ? {
1498
+ leafPaint: leafPaint,
1499
+ paint: paint,
1500
+ boxBounds: box.set(boxBounds)
1501
+ } : null;
1502
+ }
1503
+ if (firstUse || image.loading) event = {
1504
+ image: image,
1505
+ attrName: attrName,
1506
+ attrValue: paint
1507
+ };
1508
+ if (image.ready) {
1509
+ checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1510
+ if (firstUse) {
1511
+ onLoad(ui, event);
1512
+ onLoadSuccess(ui, event);
1513
+ }
1514
+ } else if (image.error) {
1515
+ if (firstUse) onLoadError(ui, event, image.error);
1516
+ } else {
1517
+ if (firstUse) {
1518
+ ignoreRender(ui, true);
1519
+ onLoad(ui, event);
1520
+ }
1521
+ leafPaint.loadId = image.load(() => {
1522
+ ignoreRender(ui, false);
1523
+ if (!ui.destroyed) {
1524
+ if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1525
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1526
+ ui.forceUpdate("surface");
1527
+ }
1528
+ onLoadSuccess(ui, event);
1529
+ }
1530
+ leafPaint.loadId = undefined;
1531
+ }, error => {
1532
+ ignoreRender(ui, false);
1533
+ onLoadError(ui, event, error);
1534
+ leafPaint.loadId = undefined;
1535
+ });
1536
+ if (ui.placeholderColor) {
1537
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1538
+ if (!image.ready) {
1539
+ image.isPlacehold = true;
1540
+ ui.forceUpdate("surface");
1541
+ }
1542
+ }, ui.placeholderDelay);
1543
+ }
1544
+ }
1545
+ return leafPaint;
1487
1546
  }
1488
1547
 
1489
- function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1490
- const transform = get$3();
1491
- translate$1(transform, box.x + x, box.y + y);
1492
- scaleHelper(transform, scaleX, scaleY);
1493
- if (rotation) rotateOfOuter$1(transform, {
1494
- x: box.x + box.width / 2,
1495
- y: box.y + box.height / 2
1496
- }, rotation);
1497
- data.transform = transform;
1548
+ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1549
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
1550
+ const data = ui.__;
1551
+ data.__naturalWidth = image.width / data.pixelRatio;
1552
+ data.__naturalHeight = image.height / data.pixelRatio;
1553
+ if (data.__autoSide) {
1554
+ ui.forceUpdate("width");
1555
+ if (ui.__proxyData) {
1556
+ ui.setProxyAttr("width", data.width);
1557
+ ui.setProxyAttr("height", data.height);
1558
+ }
1559
+ return false;
1560
+ }
1561
+ }
1562
+ if (!leafPaint.data) draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
1563
+ return true;
1498
1564
  }
1499
1565
 
1500
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
1501
- const transform = get$3();
1502
- layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1503
- if (clipScaleX) {
1504
- if (rotation || skew) {
1505
- set(tempMatrix$1);
1506
- scaleOfOuter$1(tempMatrix$1, box, clipScaleX, clipScaleY);
1507
- multiplyParent(transform, tempMatrix$1);
1508
- } else scaleOfOuter$1(transform, box, clipScaleX, clipScaleY);
1509
- }
1510
- data.transform = transform;
1566
+ function onLoad(ui, event) {
1567
+ emit(ui, core.ImageEvent.LOAD, event);
1511
1568
  }
1512
1569
 
1513
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1514
- const transform = get$3();
1515
- if (freeTransform) {
1516
- layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1517
- } else {
1518
- if (rotation) {
1519
- if (align === "center") {
1520
- rotateOfOuter$1(transform, {
1521
- x: width / 2,
1522
- y: height / 2
1523
- }, rotation);
1524
- } else {
1525
- rotate(transform, rotation);
1526
- switch (rotation) {
1527
- case 90:
1528
- translate$1(transform, height, 0);
1529
- break;
1570
+ function onLoadSuccess(ui, event) {
1571
+ emit(ui, core.ImageEvent.LOADED, event);
1572
+ }
1530
1573
 
1531
- case 180:
1532
- translate$1(transform, width, height);
1533
- break;
1574
+ function onLoadError(ui, event, error) {
1575
+ event.error = error;
1576
+ ui.forceUpdate("surface");
1577
+ emit(ui, core.ImageEvent.ERROR, event);
1578
+ }
1534
1579
 
1535
- case 270:
1536
- translate$1(transform, 0, width);
1537
- break;
1538
- }
1539
- }
1540
- }
1541
- origin.x = box.x + x;
1542
- origin.y = box.y + y;
1543
- translate$1(transform, origin.x, origin.y);
1544
- if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1545
- }
1546
- data.transform = transform;
1580
+ function emit(ui, type, data) {
1581
+ if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
1547
1582
  }
1548
1583
 
1549
- function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1550
- if (rotation) rotate(transform, rotation);
1551
- if (skew) skewHelper(transform, skew.x, skew.y);
1552
- if (scaleX) scaleHelper(transform, scaleX, scaleY);
1553
- translate$1(transform, box.x + x, box.y + y);
1584
+ function ignoreRender(ui, value) {
1585
+ const {leafer: leafer} = ui;
1586
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1554
1587
  }
1555
1588
 
1556
- const {get: get$2, translate: translate} = core.MatrixHelper;
1589
+ const {get: get$3, translate: translate$1} = core.MatrixHelper;
1557
1590
 
1558
1591
  const tempBox = new core.Bounds;
1559
1592
 
@@ -1562,17 +1595,13 @@ const tempScaleData = {};
1562
1595
  const tempImage = {};
1563
1596
 
1564
1597
  function createData(leafPaint, image, paint, box) {
1565
- const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1566
- if (changeful) leafPaint.changeful = changeful;
1567
- if (sync) leafPaint.sync = sync;
1568
- if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1569
- leafPaint.data = getPatternData(paint, box, image);
1598
+ leafPaint.data = draw.PaintImage.getPatternData(paint, box, image);
1570
1599
  }
1571
1600
 
1572
1601
  function getPatternData(paint, box, image) {
1573
1602
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1574
1603
  if (paint.mode === "strench") paint.mode = "stretch";
1575
- let {width: width, height: height} = image;
1604
+ const {width: width, height: height} = image;
1576
1605
  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;
1577
1606
  const sameBox = box.width === width && box.height === height;
1578
1607
  const data = {
@@ -1603,8 +1632,8 @@ function getPatternData(paint, box, image) {
1603
1632
  case "stretch":
1604
1633
  if (!sameBox) {
1605
1634
  scaleX = box.width / width, scaleY = box.height / height;
1606
- stretchMode(data, box, scaleX, scaleY);
1607
- }
1635
+ draw.PaintImage.stretchMode(data, box, scaleX, scaleY);
1636
+ } else if (scaleX) scaleX = scaleY = undefined;
1608
1637
  break;
1609
1638
 
1610
1639
  case "normal":
@@ -1612,13 +1641,13 @@ function getPatternData(paint, box, image) {
1612
1641
  if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) {
1613
1642
  let clipScaleX, clipScaleY;
1614
1643
  if (clipSize) clipScaleX = box.width / clipSize.width, clipScaleY = box.height / clipSize.height;
1615
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
1644
+ draw.PaintImage.clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
1616
1645
  if (clipScaleX) scaleX = scaleX ? scaleX * clipScaleX : clipScaleX, scaleY = scaleY ? scaleY * clipScaleY : clipScaleY;
1617
1646
  }
1618
1647
  break;
1619
1648
 
1620
1649
  case "repeat":
1621
- if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1650
+ if (!sameBox || scaleX || rotation || skew) draw.PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1622
1651
  if (!repeat) data.repeat = "repeat";
1623
1652
  const count = core.isObject(repeat);
1624
1653
  if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
@@ -1627,18 +1656,16 @@ function getPatternData(paint, box, image) {
1627
1656
  case "fit":
1628
1657
  case "cover":
1629
1658
  default:
1630
- if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1659
+ if (scaleX) draw.PaintImage.fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1631
1660
  }
1632
1661
  if (!data.transform) {
1633
- if (box.x || box.y) translate(data.transform = get$2(), box.x, box.y);
1662
+ if (box.x || box.y) translate$1(data.transform = get$3(), box.x, box.y);
1634
1663
  }
1635
- data.width = width;
1636
- data.height = height;
1637
1664
  if (scaleX) {
1638
1665
  data.scaleX = scaleX;
1639
1666
  data.scaleY = scaleY;
1640
1667
  }
1641
- if (opacity) data.opacity = opacity;
1668
+ if (opacity && opacity < 1) data.opacity = opacity;
1642
1669
  if (filters) data.filters = filters;
1643
1670
  if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1644
1671
  return data;
@@ -1660,180 +1687,82 @@ function getGapValue(gap, size, totalSize, rows) {
1660
1687
  return gap === "auto" ? value < 0 ? 0 : value : value;
1661
1688
  }
1662
1689
 
1663
- let cache, box = new core.Bounds;
1664
-
1665
- const {isSame: isSame} = core.BoundsHelper;
1666
-
1667
- function image(ui, attrName, paint, boxBounds, firstUse) {
1668
- let leafPaint, event;
1669
- const image = core.ImageManager.get(paint);
1670
- if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1671
- leafPaint = cache.leafPaint;
1672
- } else {
1673
- leafPaint = {
1674
- type: paint.type,
1675
- image: image
1676
- };
1677
- if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1678
- cache = image.use > 1 ? {
1679
- leafPaint: leafPaint,
1680
- paint: paint,
1681
- boxBounds: box.set(boxBounds)
1682
- } : null;
1683
- }
1684
- if (firstUse || image.loading) event = {
1685
- image: image,
1686
- attrName: attrName,
1687
- attrValue: paint
1688
- };
1689
- if (image.ready) {
1690
- checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1691
- if (firstUse) {
1692
- onLoad(ui, event);
1693
- onLoadSuccess(ui, event);
1694
- }
1695
- } else if (image.error) {
1696
- if (firstUse) onLoadError(ui, event, image.error);
1697
- } else {
1698
- if (firstUse) {
1699
- ignoreRender(ui, true);
1700
- onLoad(ui, event);
1701
- }
1702
- leafPaint.loadId = image.load(() => {
1703
- ignoreRender(ui, false);
1704
- if (!ui.destroyed) {
1705
- if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1706
- if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1707
- ui.forceUpdate("surface");
1708
- }
1709
- onLoadSuccess(ui, event);
1710
- }
1711
- leafPaint.loadId = undefined;
1712
- }, error => {
1713
- ignoreRender(ui, false);
1714
- onLoadError(ui, event, error);
1715
- leafPaint.loadId = undefined;
1716
- });
1717
- if (ui.placeholderColor) {
1718
- if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1719
- if (!image.ready) {
1720
- image.isPlacehold = true;
1721
- ui.forceUpdate("surface");
1722
- }
1723
- }, ui.placeholderDelay);
1724
- }
1725
- }
1726
- return leafPaint;
1727
- }
1728
-
1729
- function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1730
- if (attrName === "fill" && !ui.__.__naturalWidth) {
1731
- const data = ui.__;
1732
- data.__naturalWidth = image.width / data.pixelRatio;
1733
- data.__naturalHeight = image.height / data.pixelRatio;
1734
- if (data.__autoSide) {
1735
- ui.forceUpdate("width");
1736
- if (ui.__proxyData) {
1737
- ui.setProxyAttr("width", data.width);
1738
- ui.setProxyAttr("height", data.height);
1739
- }
1740
- return false;
1741
- }
1742
- }
1743
- if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
1744
- return true;
1745
- }
1746
-
1747
- function onLoad(ui, event) {
1748
- emit(ui, core.ImageEvent.LOAD, event);
1749
- }
1690
+ let origin = {}, tempMatrix$1 = core.getMatrixData();
1750
1691
 
1751
- function onLoadSuccess(ui, event) {
1752
- emit(ui, core.ImageEvent.LOADED, event);
1753
- }
1692
+ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translate, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
1754
1693
 
1755
- function onLoadError(ui, event, error) {
1756
- event.error = error;
1757
- ui.forceUpdate("surface");
1758
- emit(ui, core.ImageEvent.ERROR, event);
1694
+ function stretchMode(data, box, scaleX, scaleY) {
1695
+ const transform = get$2(), {x: x, y: y} = box;
1696
+ if (x || y) translate(transform, x, y); else transform.onlyScale = true;
1697
+ scaleHelper(transform, scaleX, scaleY);
1698
+ data.transform = transform;
1759
1699
  }
1760
1700
 
1761
- function emit(ui, type, data) {
1762
- if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
1701
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1702
+ const transform = get$2();
1703
+ translate(transform, box.x + x, box.y + y);
1704
+ scaleHelper(transform, scaleX, scaleY);
1705
+ if (rotation) rotateOfOuter$1(transform, {
1706
+ x: box.x + box.width / 2,
1707
+ y: box.y + box.height / 2
1708
+ }, rotation);
1709
+ data.transform = transform;
1763
1710
  }
1764
1711
 
1765
- function ignoreRender(ui, value) {
1766
- const {leafer: leafer} = ui;
1767
- if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1712
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
1713
+ const transform = get$2();
1714
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1715
+ if (clipScaleX) {
1716
+ if (rotation || skew) {
1717
+ set(tempMatrix$1);
1718
+ scaleOfOuter$1(tempMatrix$1, box, clipScaleX, clipScaleY);
1719
+ multiplyParent(transform, tempMatrix$1);
1720
+ } else scaleOfOuter$1(transform, box, clipScaleX, clipScaleY);
1721
+ }
1722
+ data.transform = transform;
1768
1723
  }
1769
1724
 
1770
- const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1725
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1726
+ const transform = get$2();
1727
+ if (freeTransform) {
1728
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1729
+ } else {
1730
+ if (rotation) {
1731
+ if (align === "center") {
1732
+ rotateOfOuter$1(transform, {
1733
+ x: width / 2,
1734
+ y: height / 2
1735
+ }, rotation);
1736
+ } else {
1737
+ rotate(transform, rotation);
1738
+ switch (rotation) {
1739
+ case 90:
1740
+ translate(transform, height, 0);
1741
+ break;
1771
1742
 
1772
- const {floor: floor, ceil: ceil, max: max$1, abs: abs$1} = Math;
1743
+ case 180:
1744
+ translate(transform, width, height);
1745
+ break;
1773
1746
 
1774
- function createPattern(ui, paint, pixelRatio) {
1775
- let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1776
- const id = scaleX + "-" + scaleY + "-" + pixelRatio;
1777
- if (paint.patternId !== id && !ui.destroyed) {
1778
- const {image: image, data: data} = paint;
1779
- let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
1780
- scaleX *= pixelRatio;
1781
- scaleY *= pixelRatio;
1782
- if (sx) {
1783
- sx = abs$1(sx);
1784
- sy = abs$1(sy);
1785
- imageMatrix = get$1();
1786
- copy$1(imageMatrix, transform);
1787
- scale(imageMatrix, 1 / sx, 1 / sy);
1788
- scaleX *= sx;
1789
- scaleY *= sy;
1790
- }
1791
- width *= scaleX;
1792
- height *= scaleY;
1793
- const size = width * height;
1794
- if (!repeat) {
1795
- if (size > core.Platform.image.maxCacheSize) return false;
1796
- }
1797
- let maxSize = core.Platform.image.maxPatternSize;
1798
- if (image.isSVG) {
1799
- const ws = width / image.width;
1800
- if (ws > 1) imageScale = ws / ceil(ws);
1801
- } else {
1802
- const imageSize = image.width * image.height;
1803
- if (maxSize > imageSize) maxSize = imageSize;
1804
- }
1805
- if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
1806
- if (imageScale) {
1807
- scaleX /= imageScale;
1808
- scaleY /= imageScale;
1809
- width /= imageScale;
1810
- height /= imageScale;
1811
- }
1812
- if (sx) {
1813
- scaleX /= sx;
1814
- scaleY /= sy;
1815
- }
1816
- const xGap = gap && gap.x * scaleX;
1817
- const yGap = gap && gap.y * scaleY;
1818
- if (transform || scaleX !== 1 || scaleY !== 1) {
1819
- const canvasWidth = width + (xGap || 0);
1820
- const canvasHeight = height + (yGap || 0);
1821
- scaleX /= canvasWidth / max$1(floor(canvasWidth), 1);
1822
- scaleY /= canvasHeight / max$1(floor(canvasHeight), 1);
1823
- if (!imageMatrix) {
1824
- imageMatrix = get$1();
1825
- if (transform) copy$1(imageMatrix, transform);
1747
+ case 270:
1748
+ translate(transform, 0, width);
1749
+ break;
1750
+ }
1826
1751
  }
1827
- scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1828
1752
  }
1829
- const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
1830
- const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1831
- paint.style = pattern;
1832
- paint.patternId = id;
1833
- return true;
1834
- } else {
1835
- return false;
1753
+ origin.x = box.x + x;
1754
+ origin.y = box.y + y;
1755
+ translate(transform, origin.x, origin.y);
1756
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1836
1757
  }
1758
+ data.transform = transform;
1759
+ }
1760
+
1761
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1762
+ if (rotation) rotate(transform, rotation);
1763
+ if (skew) skewHelper(transform, skew.x, skew.y);
1764
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
1765
+ translate(transform, box.x + x, box.y + y);
1837
1766
  }
1838
1767
 
1839
1768
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -1869,58 +1798,116 @@ typeof SuppressedError === "function" ? SuppressedError : function(error, suppre
1869
1798
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1870
1799
  };
1871
1800
 
1872
- function checkImage(ui, canvas, paint, allowDraw) {
1873
- const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1874
- const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
1875
- if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !draw.Export.running) {
1801
+ const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1802
+
1803
+ const {getFloorScale: getFloorScale} = core.MathHelper, {abs: abs$1} = Math;
1804
+
1805
+ function createPatternTask(paint, ui, canvas, renderOptions) {
1806
+ if (!paint.patternTask) {
1807
+ paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1808
+ paint.patternTask = null;
1809
+ if (canvas.bounds.hit(ui.__nowWorld)) draw.PaintImage.createPattern(paint, ui, canvas, renderOptions);
1810
+ ui.forceUpdate("surface");
1811
+ }), 300);
1812
+ }
1813
+ }
1814
+
1815
+ function createPattern(paint, ui, canvas, renderOptions) {
1816
+ let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
1817
+ if (paint.patternId !== id && !ui.destroyed) {
1818
+ if (!(core.Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
1819
+ const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
1820
+ let imageMatrix, xGap, yGap, {width: width, height: height} = image;
1821
+ if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
1822
+ width *= scaleX;
1823
+ height *= scaleY;
1824
+ if (gap) {
1825
+ xGap = gap.x * scaleX / abs$1(data.scaleX || 1);
1826
+ yGap = gap.y * scaleY / abs$1(data.scaleY || 1);
1827
+ }
1828
+ if (transform || scaleX !== 1 || scaleY !== 1) {
1829
+ scaleX *= getFloorScale(width + (xGap || 0));
1830
+ scaleY *= getFloorScale(height + (yGap || 0));
1831
+ imageMatrix = get$1();
1832
+ if (transform) copy$1(imageMatrix, transform);
1833
+ scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1834
+ }
1835
+ const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
1836
+ const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1837
+ paint.style = pattern;
1838
+ paint.patternId = id;
1839
+ }
1840
+ }
1841
+ }
1842
+
1843
+ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
1844
+ const {image: image} = paint;
1845
+ let fixScale, maxSize = core.Platform.image.maxPatternSize, imageSize = image.width * image.height;
1846
+ if (image.isSVG) {
1847
+ if (imageScaleX > 1) fixScale = Math.ceil(imageScaleX) / imageScaleX;
1848
+ } else {
1849
+ if (maxSize > imageSize) maxSize = imageSize;
1850
+ }
1851
+ if ((imageSize *= imageScaleX * imageScaleY) > maxSize) fixScale = Math.sqrt(maxSize / imageSize);
1852
+ return fixScale;
1853
+ }
1854
+
1855
+ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1856
+ const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
1857
+ const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting} = renderOptions;
1858
+ if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting) {
1876
1859
  return false;
1877
1860
  } else {
1878
- if (allowDraw) {
1861
+ if (drawImage) {
1879
1862
  if (data.repeat) {
1880
- allowDraw = false;
1881
- } else if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1882
- let {width: width, height: height} = data;
1883
- width *= scaleX * pixelRatio;
1884
- height *= scaleY * pixelRatio;
1885
- if (data.scaleX) {
1886
- width *= data.scaleX;
1887
- height *= data.scaleY;
1888
- }
1889
- allowDraw = width * height > core.Platform.image.maxCacheSize;
1863
+ drawImage = false;
1864
+ } else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
1865
+ drawImage = core.Platform.image.isLarge(image, scaleX, scaleY);
1890
1866
  }
1891
1867
  }
1892
- if (allowDraw) {
1868
+ if (drawImage) {
1893
1869
  if (ui.__.__isFastShadow) {
1894
1870
  canvas.fillStyle = paint.style || "#000";
1895
1871
  canvas.fill();
1896
1872
  }
1897
- drawImage(ui, canvas, paint, data);
1873
+ draw.PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
1898
1874
  return true;
1899
1875
  } else {
1900
- if (!paint.style || paint.sync || draw.Export.running) {
1901
- createPattern(ui, paint, pixelRatio);
1902
- } else {
1903
- if (!paint.patternTask) {
1904
- paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1905
- paint.patternTask = null;
1906
- if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
1907
- ui.forceUpdate("surface");
1908
- }), 300);
1909
- }
1910
- }
1876
+ if (!paint.style || originPaint.sync || exporting) draw.PaintImage.createPattern(paint, ui, canvas, renderOptions); else draw.PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
1911
1877
  return false;
1912
1878
  }
1913
1879
  }
1914
1880
  }
1915
1881
 
1916
- function drawImage(ui, canvas, paint, data) {
1917
- canvas.save();
1918
- canvas.clipUI(ui);
1919
- if (paint.blendMode) canvas.blendMode = paint.blendMode;
1920
- if (data.opacity) canvas.opacity *= data.opacity;
1921
- if (data.transform) canvas.transform(data.transform);
1922
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1923
- canvas.restore();
1882
+ function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
1883
+ const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1884
+ let {width: width, height: height} = image, clipUI;
1885
+ if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
1886
+ canvas.save();
1887
+ clipUI && canvas.clipUI(ui);
1888
+ blendMode && (canvas.blendMode = blendMode);
1889
+ opacity && (canvas.opacity *= opacity);
1890
+ transform && canvas.transform(transform);
1891
+ canvas.drawImage(view, 0, 0, width, height);
1892
+ canvas.restore();
1893
+ } else {
1894
+ if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
1895
+ canvas.drawImage(view, 0, 0, width, height);
1896
+ }
1897
+ }
1898
+
1899
+ function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
1900
+ const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
1901
+ if (canvas) {
1902
+ const {pixelRatio: pixelRatio} = canvas;
1903
+ scaleData.scaleX *= pixelRatio;
1904
+ scaleData.scaleY *= pixelRatio;
1905
+ }
1906
+ if (data && data.scaleX) {
1907
+ scaleData.scaleX *= Math.abs(data.scaleX);
1908
+ scaleData.scaleY *= Math.abs(data.scaleY);
1909
+ }
1910
+ return scaleData;
1924
1911
  }
1925
1912
 
1926
1913
  function recycleImage(attrName, data) {
@@ -1952,8 +1939,12 @@ function recycleImage(attrName, data) {
1952
1939
  const PaintImageModule = {
1953
1940
  image: image,
1954
1941
  checkImage: checkImage,
1955
- createPattern: createPattern,
1942
+ drawImage: drawImage,
1943
+ getImageRenderScaleData: getImageRenderScaleData,
1956
1944
  recycleImage: recycleImage,
1945
+ createPatternTask: createPatternTask,
1946
+ createPattern: createPattern,
1947
+ getPatternFixScale: getPatternFixScale,
1957
1948
  createData: createData,
1958
1949
  getPatternData: getPatternData,
1959
1950
  stretchMode: stretchMode,
@@ -2409,10 +2400,8 @@ function createRows(drawData, content, style) {
2409
2400
  bounds = drawData.bounds;
2410
2401
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
2411
2402
  const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
2412
- const {canvas: canvas} = core.Platform;
2413
- const {width: width, height: height} = bounds;
2414
- const charMode = width || height || __letterSpacing || textCase !== "none";
2415
- if (charMode) {
2403
+ const {canvas: canvas} = core.Platform, {width: width} = bounds;
2404
+ if (style.__isCharMode) {
2416
2405
  const wrap = style.textWrap !== "none";
2417
2406
  const breakAll = style.textWrap === "break";
2418
2407
  paraStart = true;
@@ -2541,12 +2530,19 @@ const TextMode = 2;
2541
2530
  function layoutChar(drawData, style, width, _height) {
2542
2531
  const {rows: rows} = drawData;
2543
2532
  const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
2544
- let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2533
+ const justifyLast = width && textAlign.includes("both");
2534
+ const justify = justifyLast || width && textAlign.includes("justify");
2535
+ const justifyLetter = justify && textAlign.includes("letter");
2536
+ let charX, remainingWidth, addWordWidth, addLetterWidth, indentWidth, mode, wordChar, wordsLength, isLastWord, canJustify;
2545
2537
  rows.forEach(row => {
2546
2538
  if (row.words) {
2547
2539
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2548
- addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2549
- mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
2540
+ if (justify) {
2541
+ canJustify = !row.paraEnd || justifyLast;
2542
+ remainingWidth = width - row.width - indentWidth;
2543
+ if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
2544
+ }
2545
+ mode = letterSpacing || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
2550
2546
  if (row.isOverflow && !letterSpacing) row.textMode = true;
2551
2547
  if (mode === TextMode) {
2552
2548
  row.x += indentWidth;
@@ -2564,11 +2560,15 @@ function layoutChar(drawData, style, width, _height) {
2564
2560
  charX = toWordChar(word.data, charX, wordChar);
2565
2561
  if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
2566
2562
  } else {
2567
- charX = toChar(word.data, charX, row.data, row.isOverflow);
2563
+ charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
2568
2564
  }
2569
- if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
2570
- charX += addWordWidth;
2571
- row.width += addWordWidth;
2565
+ if (canJustify) {
2566
+ isLastWord = index === wordsLength - 1;
2567
+ if (addWordWidth) {
2568
+ if (!isLastWord) charX += addWordWidth, row.width += addWordWidth;
2569
+ } else if (addLetterWidth) {
2570
+ row.width += addLetterWidth * (word.data.length - (isLastWord ? 1 : 0));
2571
+ }
2572
2572
  }
2573
2573
  });
2574
2574
  }
@@ -2594,13 +2594,14 @@ function toWordChar(data, charX, wordChar) {
2594
2594
  return charX;
2595
2595
  }
2596
2596
 
2597
- function toChar(data, charX, rowData, isOverflow) {
2597
+ function toChar(data, charX, rowData, isOverflow, addLetterWidth) {
2598
2598
  data.forEach(char => {
2599
2599
  if (isOverflow || char.char !== " ") {
2600
2600
  char.x = charX;
2601
2601
  rowData.push(char);
2602
2602
  }
2603
2603
  charX += char.width;
2604
+ addLetterWidth && (charX += addLetterWidth);
2604
2605
  });
2605
2606
  return charX;
2606
2607
  }
@@ -2742,10 +2743,10 @@ function getDrawData(content, style) {
2742
2743
  let x = 0, y = 0;
2743
2744
  let width = style.__getInput("width") || 0;
2744
2745
  let height = style.__getInput("height") || 0;
2745
- const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
2746
+ const {__padding: padding} = style;
2746
2747
  if (padding) {
2747
- if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
2748
- if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
2748
+ if (width) x = padding[left], width -= padding[right] + padding[left], !width && (width = .01); else if (!style.autoSizeAlign) x = padding[left];
2749
+ if (height) y = padding[top], height -= padding[top] + padding[bottom], !height && (height = .01); else if (!style.autoSizeAlign) y = padding[top];
2749
2750
  }
2750
2751
  const drawData = {
2751
2752
  bounds: {
@@ -2756,14 +2757,14 @@ function getDrawData(content, style) {
2756
2757
  },
2757
2758
  rows: [],
2758
2759
  paraNumber: 0,
2759
- font: core.Platform.canvas.font = __font
2760
+ font: core.Platform.canvas.font = style.__font
2760
2761
  };
2761
2762
  createRows(drawData, content, style);
2762
2763
  if (padding) padAutoText(padding, drawData, style, width, height);
2763
2764
  layoutText(drawData, style);
2764
- layoutChar(drawData, style, width);
2765
+ if (style.__isCharMode) layoutChar(drawData, style, width);
2765
2766
  if (drawData.overflow) clipText(drawData, style, x, width);
2766
- if (textDecoration !== "none") decorationText(drawData, style);
2767
+ if (style.textDecoration !== "none") decorationText(drawData, style);
2767
2768
  return drawData;
2768
2769
  }
2769
2770