leafer-draw 2.0.1 → 2.0.2

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/web.cjs CHANGED
@@ -13,6 +13,39 @@ exports.PathNodeHandleType = void 0;
13
13
  PathNodeHandleType[PathNodeHandleType["mirror"] = 4] = "mirror";
14
14
  })(exports.PathNodeHandleType || (exports.PathNodeHandleType = {}));
15
15
 
16
+ function __awaiter(thisArg, _arguments, P, generator) {
17
+ function adopt(value) {
18
+ return value instanceof P ? value : new P(function(resolve) {
19
+ resolve(value);
20
+ });
21
+ }
22
+ return new (P || (P = Promise))(function(resolve, reject) {
23
+ function fulfilled(value) {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ }
30
+ function rejected(value) {
31
+ try {
32
+ step(generator["throw"](value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ }
37
+ function step(result) {
38
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
39
+ }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ }
43
+
44
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
45
+ var e = new Error(message);
46
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
47
+ };
48
+
16
49
  const debug$2 = core.Debug.get("LeaferCanvas");
17
50
 
18
51
  class LeaferCanvas extends core.LeaferCanvasBase {
@@ -216,8 +249,6 @@ core.canvasPatch(CanvasRenderingContext2D.prototype);
216
249
 
217
250
  core.canvasPatch(Path2D.prototype);
218
251
 
219
- const {mineType: mineType, fileType: fileType} = core.FileHelper;
220
-
221
252
  Object.assign(core.Creator, {
222
253
  canvas: (options, manager) => new LeaferCanvas(options, manager),
223
254
  image: options => new core.LeaferImage(options)
@@ -232,29 +263,27 @@ function useCanvas(_canvasType, _power) {
232
263
  return canvas;
233
264
  },
234
265
  canvasToDataURL: (canvas, type, quality) => {
235
- const imageType = mineType(type), url = canvas.toDataURL(imageType, quality);
266
+ const imageType = core.FileHelper.mimeType(type), url = canvas.toDataURL(imageType, quality);
236
267
  return imageType === "image/bmp" ? url.replace("image/png;", "image/bmp;") : url;
237
268
  },
238
- canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, mineType(type), quality)),
269
+ canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, core.FileHelper.mimeType(type), quality)),
239
270
  canvasSaveAs: (canvas, filename, quality) => {
240
- const url = canvas.toDataURL(mineType(fileType(filename)), quality);
271
+ const url = canvas.toDataURL(core.FileHelper.mimeType(core.FileHelper.fileType(filename)), quality);
241
272
  return core.Platform.origin.download(url, filename);
242
273
  },
243
274
  download(url, filename) {
244
- return new Promise(resolve => {
275
+ return __awaiter(this, void 0, void 0, function*() {
245
276
  let el = document.createElement("a");
246
277
  el.href = url;
247
278
  el.download = filename;
248
279
  document.body.appendChild(el);
249
280
  el.click();
250
281
  document.body.removeChild(el);
251
- resolve();
252
282
  });
253
283
  },
254
- loadImage(src) {
284
+ loadImage(src, crossOrigin, _leaferImage) {
255
285
  return new Promise((resolve, reject) => {
256
286
  const img = new core.Platform.origin.Image;
257
- const {crossOrigin: crossOrigin} = core.Platform.image;
258
287
  if (crossOrigin) {
259
288
  img.setAttribute("crossOrigin", crossOrigin);
260
289
  img.crossOrigin = crossOrigin;
@@ -268,6 +297,13 @@ function useCanvas(_canvasType, _power) {
268
297
  img.src = core.Platform.image.getRealURL(src);
269
298
  });
270
299
  },
300
+ loadContent(url_1) {
301
+ return __awaiter(this, arguments, void 0, function*(url, responseType = "text") {
302
+ const response = yield fetch(url);
303
+ if (!response.ok) throw new Error(`${response.status}`);
304
+ return yield response[responseType]();
305
+ });
306
+ },
271
307
  Image: Image,
272
308
  PointerEvent: PointerEvent,
273
309
  DragEvent: DragEvent
@@ -779,7 +815,7 @@ class Renderer {
779
815
  getCellList() {
780
816
  return undefined;
781
817
  }
782
- addBlock(block) {
818
+ addBlock(block, _leafList) {
783
819
  if (!this.updateBlocks) this.updateBlocks = [];
784
820
  this.updateBlocks.push(block);
785
821
  }
@@ -827,7 +863,8 @@ class Renderer {
827
863
  __onLayoutEnd(event) {
828
864
  if (event.data) event.data.map(item => {
829
865
  let empty;
830
- if (item.updatedList) item.updatedList.list.some(leaf => {
866
+ const {updatedList: updatedList} = item;
867
+ if (updatedList) updatedList.list.some(leaf => {
831
868
  empty = !leaf.__world.width || !leaf.__world.height;
832
869
  if (empty) {
833
870
  if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
@@ -835,7 +872,7 @@ class Renderer {
835
872
  }
836
873
  return empty;
837
874
  });
838
- this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
875
+ this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
839
876
  });
840
877
  }
841
878
  emitRender(type, bounds, options) {
@@ -1175,11 +1212,14 @@ function compute(attrName, ui) {
1175
1212
  function getLeafPaint(attrName, paint, ui) {
1176
1213
  if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1177
1214
  let leafPaint;
1178
- const {boxBounds: boxBounds} = ui.__layout;
1179
- switch (paint.type) {
1215
+ const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
1216
+ switch (type) {
1180
1217
  case "image":
1218
+ case "film":
1219
+ case "video":
1181
1220
  if (!paint.url) return undefined;
1182
1221
  leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1222
+ if (type !== "image") draw.PaintImage[type](leafPaint);
1183
1223
  break;
1184
1224
 
1185
1225
  case "linear":
@@ -1195,7 +1235,7 @@ function getLeafPaint(attrName, paint, ui) {
1195
1235
  break;
1196
1236
 
1197
1237
  case "solid":
1198
- const {type: type, color: color, opacity: opacity} = paint;
1238
+ const {color: color, opacity: opacity} = paint;
1199
1239
  leafPaint = {
1200
1240
  type: type,
1201
1241
  style: draw.ColorConvert.string(color, opacity)
@@ -1239,7 +1279,7 @@ const {isSame: isSame} = core.BoundsHelper;
1239
1279
 
1240
1280
  function image(ui, attrName, paint, boxBounds, firstUse) {
1241
1281
  let leafPaint, event;
1242
- const image = core.ImageManager.get(paint);
1282
+ const image = core.ImageManager.get(paint, paint.type);
1243
1283
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1244
1284
  leafPaint = cache.leafPaint;
1245
1285
  } else {
@@ -1300,8 +1340,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1300
1340
  }
1301
1341
 
1302
1342
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1303
- if (attrName === "fill" && !ui.__.__naturalWidth) {
1304
- const data = ui.__;
1343
+ const data = ui.__;
1344
+ if (attrName === "fill" && !data.__naturalWidth) {
1305
1345
  data.__naturalWidth = image.width / data.pixelRatio;
1306
1346
  data.__naturalHeight = image.height / data.pixelRatio;
1307
1347
  if (data.__autoSide) {
@@ -1313,7 +1353,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
1313
1353
  return false;
1314
1354
  }
1315
1355
  }
1316
- if (!leafPaint.data) draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
1356
+ if (!leafPaint.data) {
1357
+ draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
1358
+ const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
1359
+ const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
1360
+ if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
1361
+ }
1317
1362
  return true;
1318
1363
  }
1319
1364
 
@@ -1356,7 +1401,7 @@ function getPatternData(paint, box, image) {
1356
1401
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1357
1402
  if (paint.mode === "strench") paint.mode = "stretch";
1358
1403
  const {width: width, height: height} = image;
1359
- 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, interlace: interlace} = paint;
1404
+ const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
1360
1405
  const sameBox = box.width === width && box.height === height;
1361
1406
  const data = {
1362
1407
  mode: mode
@@ -1419,8 +1464,6 @@ function getPatternData(paint, box, image) {
1419
1464
  data.scaleX = scaleX;
1420
1465
  data.scaleY = scaleY;
1421
1466
  }
1422
- if (opacity && opacity < 1) data.opacity = opacity;
1423
- if (filters) data.filters = filters;
1424
1467
  if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1425
1468
  if (interlace) data.interlace = core.isNumber(interlace) || interlace.type === "percent" ? {
1426
1469
  type: "x",
@@ -1451,7 +1494,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
1451
1494
 
1452
1495
  function stretchMode(data, box, scaleX, scaleY) {
1453
1496
  const transform = get$2(), {x: x, y: y} = box;
1454
- if (x || y) translate(transform, x, y); else transform.onlyScale = true;
1497
+ if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
1455
1498
  scaleHelper(transform, scaleX, scaleY);
1456
1499
  data.transform = transform;
1457
1500
  }
@@ -1523,39 +1566,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1523
1566
  translate(transform, box.x + x, box.y + y);
1524
1567
  }
1525
1568
 
1526
- function __awaiter(thisArg, _arguments, P, generator) {
1527
- function adopt(value) {
1528
- return value instanceof P ? value : new P(function(resolve) {
1529
- resolve(value);
1530
- });
1531
- }
1532
- return new (P || (P = Promise))(function(resolve, reject) {
1533
- function fulfilled(value) {
1534
- try {
1535
- step(generator.next(value));
1536
- } catch (e) {
1537
- reject(e);
1538
- }
1539
- }
1540
- function rejected(value) {
1541
- try {
1542
- step(generator["throw"](value));
1543
- } catch (e) {
1544
- reject(e);
1545
- }
1546
- }
1547
- function step(result) {
1548
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1549
- }
1550
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1551
- });
1552
- }
1553
-
1554
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
1555
- var e = new Error(message);
1556
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1557
- };
1558
-
1559
1569
  const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1560
1570
 
1561
1571
  const {getFloorScale: getFloorScale} = core.MathHelper, {abs: abs$1} = Math;
@@ -1573,10 +1583,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
1573
1583
  }
1574
1584
 
1575
1585
  function createPattern(paint, ui, canvas, renderOptions) {
1576
- let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
1586
+ let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
1577
1587
  if (paint.patternId !== id && !ui.destroyed) {
1578
1588
  if (!(core.Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
1579
- const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
1589
+ const {image: image, data: data} = paint, {opacity: opacity, filters: filters} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
1580
1590
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
1581
1591
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
1582
1592
  width *= scaleX;
@@ -1592,7 +1602,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
1592
1602
  if (transform) copy$1(imageMatrix, transform);
1593
1603
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1594
1604
  }
1595
- const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
1605
+ const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
1596
1606
  const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1597
1607
  paint.style = pattern;
1598
1608
  paint.patternId = id;
@@ -1613,15 +1623,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
1613
1623
  }
1614
1624
 
1615
1625
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1616
- const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
1626
+ const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
1617
1627
  const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
1618
- if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting || snapshot) {
1628
+ if (!data || paint.patternId === id && !exporting || snapshot) {
1619
1629
  return false;
1620
1630
  } else {
1621
1631
  if (drawImage) {
1622
1632
  if (data.repeat) {
1623
1633
  drawImage = false;
1624
- } else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
1634
+ } else if (!(originPaint.changeful || paint.film || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
1625
1635
  drawImage = core.Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
1626
1636
  }
1627
1637
  }
@@ -1639,20 +1649,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1639
1649
  }
1640
1650
  }
1641
1651
 
1642
- function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
1643
- const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1644
- let {width: width, height: height} = image, clipUI;
1645
- if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
1652
+ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
1653
+ const {data: data, image: image, complex: complex} = paint;
1654
+ let {width: width, height: height} = image;
1655
+ if (complex) {
1656
+ const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
1646
1657
  canvas.save();
1647
- clipUI && canvas.clipUI(ui);
1658
+ complex === 2 && canvas.clipUI(ui);
1648
1659
  blendMode && (canvas.blendMode = blendMode);
1649
1660
  opacity && (canvas.opacity *= opacity);
1650
1661
  transform && canvas.transform(transform);
1651
- canvas.drawImage(view, 0, 0, width, height);
1662
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
1652
1663
  canvas.restore();
1653
1664
  } else {
1654
1665
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
1655
- canvas.drawImage(view, 0, 0, width, height);
1666
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
1656
1667
  }
1657
1668
  }
1658
1669
 
@@ -2591,6 +2602,13 @@ Object.assign(draw.Effect, EffectModule);
2591
2602
 
2592
2603
  useCanvas();
2593
2604
 
2605
+ Object.defineProperty(exports, "LeaferFilm", {
2606
+ enumerable: true,
2607
+ get: function() {
2608
+ return core.LeaferFilm;
2609
+ }
2610
+ });
2611
+
2594
2612
  Object.defineProperty(exports, "LeaferImage", {
2595
2613
  enumerable: true,
2596
2614
  get: function() {
@@ -2598,6 +2616,13 @@ Object.defineProperty(exports, "LeaferImage", {
2598
2616
  }
2599
2617
  });
2600
2618
 
2619
+ Object.defineProperty(exports, "LeaferVideo", {
2620
+ enumerable: true,
2621
+ get: function() {
2622
+ return core.LeaferVideo;
2623
+ }
2624
+ });
2625
+
2601
2626
  exports.Layouter = Layouter;
2602
2627
 
2603
2628
  exports.LeaferCanvas = LeaferCanvas;
package/dist/web.esm.js CHANGED
@@ -1,8 +1,8 @@
1
- import { Debug, LeaferCanvasBase, Platform, isString, DataHelper, canvasSizeAttrs, isUndefined, ResizeEvent, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, LeafLevelList, LayoutEvent, Run, ImageManager, isObject, BoundsHelper, FourNumberHelper, Matrix, ImageEvent, MatrixHelper, MathHelper, AlignHelper, PointHelper, isNumber, getMatrixData, AroundHelper, Direction4 } from "@leafer/core";
1
+ import { Debug, LeaferCanvasBase, Platform, isString, DataHelper, canvasSizeAttrs, isUndefined, ResizeEvent, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, LeafLevelList, LayoutEvent, Run, ImageManager, isObject, BoundsHelper, FourNumberHelper, Matrix, ImageEvent, MatrixHelper, MathHelper, AlignHelper, PointHelper, isNumber, getMatrixData, AroundHelper, Direction4 } from "@leafer/core";
2
2
 
3
3
  export * from "@leafer/core";
4
4
 
5
- export { LeaferImage } from "@leafer/core";
5
+ export { LeaferFilm, LeaferImage, LeaferVideo } from "@leafer/core";
6
6
 
7
7
  import { Paint, PaintImage, ColorConvert, PaintGradient, Effect, Group, TextConvert } from "@leafer-ui/draw";
8
8
 
@@ -17,6 +17,39 @@ var PathNodeHandleType;
17
17
  PathNodeHandleType[PathNodeHandleType["mirror"] = 4] = "mirror";
18
18
  })(PathNodeHandleType || (PathNodeHandleType = {}));
19
19
 
20
+ function __awaiter(thisArg, _arguments, P, generator) {
21
+ function adopt(value) {
22
+ return value instanceof P ? value : new P(function(resolve) {
23
+ resolve(value);
24
+ });
25
+ }
26
+ return new (P || (P = Promise))(function(resolve, reject) {
27
+ function fulfilled(value) {
28
+ try {
29
+ step(generator.next(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ }
34
+ function rejected(value) {
35
+ try {
36
+ step(generator["throw"](value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ }
41
+ function step(result) {
42
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
43
+ }
44
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
45
+ });
46
+ }
47
+
48
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
49
+ var e = new Error(message);
50
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
51
+ };
52
+
20
53
  const debug$2 = Debug.get("LeaferCanvas");
21
54
 
22
55
  class LeaferCanvas extends LeaferCanvasBase {
@@ -220,8 +253,6 @@ canvasPatch(CanvasRenderingContext2D.prototype);
220
253
 
221
254
  canvasPatch(Path2D.prototype);
222
255
 
223
- const {mineType: mineType, fileType: fileType} = FileHelper;
224
-
225
256
  Object.assign(Creator, {
226
257
  canvas: (options, manager) => new LeaferCanvas(options, manager),
227
258
  image: options => new LeaferImage(options)
@@ -236,29 +267,27 @@ function useCanvas(_canvasType, _power) {
236
267
  return canvas;
237
268
  },
238
269
  canvasToDataURL: (canvas, type, quality) => {
239
- const imageType = mineType(type), url = canvas.toDataURL(imageType, quality);
270
+ const imageType = FileHelper.mimeType(type), url = canvas.toDataURL(imageType, quality);
240
271
  return imageType === "image/bmp" ? url.replace("image/png;", "image/bmp;") : url;
241
272
  },
242
- canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, mineType(type), quality)),
273
+ canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, FileHelper.mimeType(type), quality)),
243
274
  canvasSaveAs: (canvas, filename, quality) => {
244
- const url = canvas.toDataURL(mineType(fileType(filename)), quality);
275
+ const url = canvas.toDataURL(FileHelper.mimeType(FileHelper.fileType(filename)), quality);
245
276
  return Platform.origin.download(url, filename);
246
277
  },
247
278
  download(url, filename) {
248
- return new Promise(resolve => {
279
+ return __awaiter(this, void 0, void 0, function*() {
249
280
  let el = document.createElement("a");
250
281
  el.href = url;
251
282
  el.download = filename;
252
283
  document.body.appendChild(el);
253
284
  el.click();
254
285
  document.body.removeChild(el);
255
- resolve();
256
286
  });
257
287
  },
258
- loadImage(src) {
288
+ loadImage(src, crossOrigin, _leaferImage) {
259
289
  return new Promise((resolve, reject) => {
260
290
  const img = new Platform.origin.Image;
261
- const {crossOrigin: crossOrigin} = Platform.image;
262
291
  if (crossOrigin) {
263
292
  img.setAttribute("crossOrigin", crossOrigin);
264
293
  img.crossOrigin = crossOrigin;
@@ -272,6 +301,13 @@ function useCanvas(_canvasType, _power) {
272
301
  img.src = Platform.image.getRealURL(src);
273
302
  });
274
303
  },
304
+ loadContent(url_1) {
305
+ return __awaiter(this, arguments, void 0, function*(url, responseType = "text") {
306
+ const response = yield fetch(url);
307
+ if (!response.ok) throw new Error(`${response.status}`);
308
+ return yield response[responseType]();
309
+ });
310
+ },
275
311
  Image: Image,
276
312
  PointerEvent: PointerEvent,
277
313
  DragEvent: DragEvent
@@ -783,7 +819,7 @@ class Renderer {
783
819
  getCellList() {
784
820
  return undefined;
785
821
  }
786
- addBlock(block) {
822
+ addBlock(block, _leafList) {
787
823
  if (!this.updateBlocks) this.updateBlocks = [];
788
824
  this.updateBlocks.push(block);
789
825
  }
@@ -831,7 +867,8 @@ class Renderer {
831
867
  __onLayoutEnd(event) {
832
868
  if (event.data) event.data.map(item => {
833
869
  let empty;
834
- if (item.updatedList) item.updatedList.list.some(leaf => {
870
+ const {updatedList: updatedList} = item;
871
+ if (updatedList) updatedList.list.some(leaf => {
835
872
  empty = !leaf.__world.width || !leaf.__world.height;
836
873
  if (empty) {
837
874
  if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
@@ -839,7 +876,7 @@ class Renderer {
839
876
  }
840
877
  return empty;
841
878
  });
842
- this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
879
+ this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
843
880
  });
844
881
  }
845
882
  emitRender(type, bounds, options) {
@@ -1179,11 +1216,14 @@ function compute(attrName, ui) {
1179
1216
  function getLeafPaint(attrName, paint, ui) {
1180
1217
  if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1181
1218
  let leafPaint;
1182
- const {boxBounds: boxBounds} = ui.__layout;
1183
- switch (paint.type) {
1219
+ const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
1220
+ switch (type) {
1184
1221
  case "image":
1222
+ case "film":
1223
+ case "video":
1185
1224
  if (!paint.url) return undefined;
1186
1225
  leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1226
+ if (type !== "image") PaintImage[type](leafPaint);
1187
1227
  break;
1188
1228
 
1189
1229
  case "linear":
@@ -1199,7 +1239,7 @@ function getLeafPaint(attrName, paint, ui) {
1199
1239
  break;
1200
1240
 
1201
1241
  case "solid":
1202
- const {type: type, color: color, opacity: opacity} = paint;
1242
+ const {color: color, opacity: opacity} = paint;
1203
1243
  leafPaint = {
1204
1244
  type: type,
1205
1245
  style: ColorConvert.string(color, opacity)
@@ -1243,7 +1283,7 @@ const {isSame: isSame} = BoundsHelper;
1243
1283
 
1244
1284
  function image(ui, attrName, paint, boxBounds, firstUse) {
1245
1285
  let leafPaint, event;
1246
- const image = ImageManager.get(paint);
1286
+ const image = ImageManager.get(paint, paint.type);
1247
1287
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1248
1288
  leafPaint = cache.leafPaint;
1249
1289
  } else {
@@ -1304,8 +1344,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1304
1344
  }
1305
1345
 
1306
1346
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1307
- if (attrName === "fill" && !ui.__.__naturalWidth) {
1308
- const data = ui.__;
1347
+ const data = ui.__;
1348
+ if (attrName === "fill" && !data.__naturalWidth) {
1309
1349
  data.__naturalWidth = image.width / data.pixelRatio;
1310
1350
  data.__naturalHeight = image.height / data.pixelRatio;
1311
1351
  if (data.__autoSide) {
@@ -1317,7 +1357,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
1317
1357
  return false;
1318
1358
  }
1319
1359
  }
1320
- if (!leafPaint.data) PaintImage.createData(leafPaint, image, paint, boxBounds);
1360
+ if (!leafPaint.data) {
1361
+ PaintImage.createData(leafPaint, image, paint, boxBounds);
1362
+ const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
1363
+ const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
1364
+ if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
1365
+ }
1321
1366
  return true;
1322
1367
  }
1323
1368
 
@@ -1360,7 +1405,7 @@ function getPatternData(paint, box, image) {
1360
1405
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1361
1406
  if (paint.mode === "strench") paint.mode = "stretch";
1362
1407
  const {width: width, height: height} = image;
1363
- 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, interlace: interlace} = paint;
1408
+ const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
1364
1409
  const sameBox = box.width === width && box.height === height;
1365
1410
  const data = {
1366
1411
  mode: mode
@@ -1423,8 +1468,6 @@ function getPatternData(paint, box, image) {
1423
1468
  data.scaleX = scaleX;
1424
1469
  data.scaleY = scaleY;
1425
1470
  }
1426
- if (opacity && opacity < 1) data.opacity = opacity;
1427
- if (filters) data.filters = filters;
1428
1471
  if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1429
1472
  if (interlace) data.interlace = isNumber(interlace) || interlace.type === "percent" ? {
1430
1473
  type: "x",
@@ -1455,7 +1498,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
1455
1498
 
1456
1499
  function stretchMode(data, box, scaleX, scaleY) {
1457
1500
  const transform = get$2(), {x: x, y: y} = box;
1458
- if (x || y) translate(transform, x, y); else transform.onlyScale = true;
1501
+ if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
1459
1502
  scaleHelper(transform, scaleX, scaleY);
1460
1503
  data.transform = transform;
1461
1504
  }
@@ -1527,39 +1570,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1527
1570
  translate(transform, box.x + x, box.y + y);
1528
1571
  }
1529
1572
 
1530
- function __awaiter(thisArg, _arguments, P, generator) {
1531
- function adopt(value) {
1532
- return value instanceof P ? value : new P(function(resolve) {
1533
- resolve(value);
1534
- });
1535
- }
1536
- return new (P || (P = Promise))(function(resolve, reject) {
1537
- function fulfilled(value) {
1538
- try {
1539
- step(generator.next(value));
1540
- } catch (e) {
1541
- reject(e);
1542
- }
1543
- }
1544
- function rejected(value) {
1545
- try {
1546
- step(generator["throw"](value));
1547
- } catch (e) {
1548
- reject(e);
1549
- }
1550
- }
1551
- function step(result) {
1552
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1553
- }
1554
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1555
- });
1556
- }
1557
-
1558
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
1559
- var e = new Error(message);
1560
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1561
- };
1562
-
1563
1573
  const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
1564
1574
 
1565
1575
  const {getFloorScale: getFloorScale} = MathHelper, {abs: abs$1} = Math;
@@ -1577,10 +1587,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
1577
1587
  }
1578
1588
 
1579
1589
  function createPattern(paint, ui, canvas, renderOptions) {
1580
- let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
1590
+ let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
1581
1591
  if (paint.patternId !== id && !ui.destroyed) {
1582
1592
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
1583
- const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
1593
+ const {image: image, data: data} = paint, {opacity: opacity, filters: filters} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
1584
1594
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
1585
1595
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
1586
1596
  width *= scaleX;
@@ -1596,7 +1606,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
1596
1606
  if (transform) copy$1(imageMatrix, transform);
1597
1607
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1598
1608
  }
1599
- const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
1609
+ const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
1600
1610
  const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1601
1611
  paint.style = pattern;
1602
1612
  paint.patternId = id;
@@ -1617,15 +1627,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
1617
1627
  }
1618
1628
 
1619
1629
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1620
- const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
1630
+ const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
1621
1631
  const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
1622
- if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting || snapshot) {
1632
+ if (!data || paint.patternId === id && !exporting || snapshot) {
1623
1633
  return false;
1624
1634
  } else {
1625
1635
  if (drawImage) {
1626
1636
  if (data.repeat) {
1627
1637
  drawImage = false;
1628
- } else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
1638
+ } else if (!(originPaint.changeful || paint.film || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
1629
1639
  drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
1630
1640
  }
1631
1641
  }
@@ -1643,20 +1653,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
1643
1653
  }
1644
1654
  }
1645
1655
 
1646
- function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
1647
- const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
1648
- let {width: width, height: height} = image, clipUI;
1649
- if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
1656
+ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
1657
+ const {data: data, image: image, complex: complex} = paint;
1658
+ let {width: width, height: height} = image;
1659
+ if (complex) {
1660
+ const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
1650
1661
  canvas.save();
1651
- clipUI && canvas.clipUI(ui);
1662
+ complex === 2 && canvas.clipUI(ui);
1652
1663
  blendMode && (canvas.blendMode = blendMode);
1653
1664
  opacity && (canvas.opacity *= opacity);
1654
1665
  transform && canvas.transform(transform);
1655
- canvas.drawImage(view, 0, 0, width, height);
1666
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
1656
1667
  canvas.restore();
1657
1668
  } else {
1658
1669
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
1659
- canvas.drawImage(view, 0, 0, width, height);
1670
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
1660
1671
  }
1661
1672
  }
1662
1673