leafer-ui 2.0.1 → 2.0.3

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
@@ -15,6 +15,39 @@ exports.PathNodeHandleType = void 0;
15
15
  PathNodeHandleType[PathNodeHandleType["mirror"] = 4] = "mirror";
16
16
  })(exports.PathNodeHandleType || (exports.PathNodeHandleType = {}));
17
17
 
18
+ function __awaiter(thisArg, _arguments, P, generator) {
19
+ function adopt(value) {
20
+ return value instanceof P ? value : new P(function(resolve) {
21
+ resolve(value);
22
+ });
23
+ }
24
+ return new (P || (P = Promise))(function(resolve, reject) {
25
+ function fulfilled(value) {
26
+ try {
27
+ step(generator.next(value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ }
32
+ function rejected(value) {
33
+ try {
34
+ step(generator["throw"](value));
35
+ } catch (e) {
36
+ reject(e);
37
+ }
38
+ }
39
+ function step(result) {
40
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
41
+ }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ }
45
+
46
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
47
+ var e = new Error(message);
48
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
49
+ };
50
+
18
51
  const debug$2 = core.Debug.get("LeaferCanvas");
19
52
 
20
53
  class LeaferCanvas extends core.LeaferCanvasBase {
@@ -218,8 +251,6 @@ core.canvasPatch(CanvasRenderingContext2D.prototype);
218
251
 
219
252
  core.canvasPatch(Path2D.prototype);
220
253
 
221
- const {mineType: mineType, fileType: fileType} = core.FileHelper;
222
-
223
254
  Object.assign(core.Creator, {
224
255
  canvas: (options, manager) => new LeaferCanvas(options, manager),
225
256
  image: options => new core.LeaferImage(options)
@@ -234,29 +265,27 @@ function useCanvas(_canvasType, _power) {
234
265
  return canvas;
235
266
  },
236
267
  canvasToDataURL: (canvas, type, quality) => {
237
- const imageType = mineType(type), url = canvas.toDataURL(imageType, quality);
268
+ const imageType = core.FileHelper.mimeType(type), url = canvas.toDataURL(imageType, quality);
238
269
  return imageType === "image/bmp" ? url.replace("image/png;", "image/bmp;") : url;
239
270
  },
240
- canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, mineType(type), quality)),
271
+ canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, core.FileHelper.mimeType(type), quality)),
241
272
  canvasSaveAs: (canvas, filename, quality) => {
242
- const url = canvas.toDataURL(mineType(fileType(filename)), quality);
273
+ const url = canvas.toDataURL(core.FileHelper.mimeType(core.FileHelper.fileType(filename)), quality);
243
274
  return core.Platform.origin.download(url, filename);
244
275
  },
245
276
  download(url, filename) {
246
- return new Promise(resolve => {
277
+ return __awaiter(this, void 0, void 0, function*() {
247
278
  let el = document.createElement("a");
248
279
  el.href = url;
249
280
  el.download = filename;
250
281
  document.body.appendChild(el);
251
282
  el.click();
252
283
  document.body.removeChild(el);
253
- resolve();
254
284
  });
255
285
  },
256
- loadImage(src) {
286
+ loadImage(src, crossOrigin, _leaferImage) {
257
287
  return new Promise((resolve, reject) => {
258
288
  const img = new core.Platform.origin.Image;
259
- const {crossOrigin: crossOrigin} = core.Platform.image;
260
289
  if (crossOrigin) {
261
290
  img.setAttribute("crossOrigin", crossOrigin);
262
291
  img.crossOrigin = crossOrigin;
@@ -270,6 +299,13 @@ function useCanvas(_canvasType, _power) {
270
299
  img.src = core.Platform.image.getRealURL(src);
271
300
  });
272
301
  },
302
+ loadContent(url_1) {
303
+ return __awaiter(this, arguments, void 0, function*(url, responseType = "text") {
304
+ const response = yield fetch(url);
305
+ if (!response.ok) throw new Error(`${response.status}`);
306
+ return yield response[responseType]();
307
+ });
308
+ },
273
309
  Image: Image,
274
310
  PointerEvent: PointerEvent,
275
311
  DragEvent: DragEvent
@@ -781,7 +817,7 @@ class Renderer {
781
817
  getCellList() {
782
818
  return undefined;
783
819
  }
784
- addBlock(block) {
820
+ addBlock(block, _leafList) {
785
821
  if (!this.updateBlocks) this.updateBlocks = [];
786
822
  this.updateBlocks.push(block);
787
823
  }
@@ -829,7 +865,8 @@ class Renderer {
829
865
  __onLayoutEnd(event) {
830
866
  if (event.data) event.data.map(item => {
831
867
  let empty;
832
- if (item.updatedList) item.updatedList.list.some(leaf => {
868
+ const {updatedList: updatedList} = item;
869
+ if (updatedList) updatedList.list.some(leaf => {
833
870
  empty = !leaf.__world.width || !leaf.__world.height;
834
871
  if (empty) {
835
872
  if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
@@ -837,7 +874,7 @@ class Renderer {
837
874
  }
838
875
  return empty;
839
876
  });
840
- this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
877
+ this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
841
878
  });
842
879
  }
843
880
  emitRender(type, bounds, options) {
@@ -1043,7 +1080,7 @@ class Selector {
1043
1080
  this.config = {};
1044
1081
  if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
1045
1082
  this.picker = new Picker(this.target = target, this);
1046
- this.finder = core.Creator.finder && core.Creator.finder();
1083
+ this.finder = core.Creator.finder && core.Creator.finder(target, this.config);
1047
1084
  }
1048
1085
  getByPoint(hitPoint, hitRadius, options) {
1049
1086
  const {target: target, picker: picker} = this;
@@ -1430,8 +1467,8 @@ function fills(fills, ui, canvas, renderOptions) {
1430
1467
  canvas.save();
1431
1468
  if (item.transform) canvas.transform(item.transform);
1432
1469
  if (originPaint.scaleFixed) {
1433
- const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
1434
- if (originPaint.scaleFixed === true || originPaint.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
1470
+ const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, originPaint.scaleFixed, false);
1471
+ if (scaleX !== 1) canvas.scale(scaleX, scaleY);
1435
1472
  }
1436
1473
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
1437
1474
  fillPathOrText(ui, canvas, renderOptions);
@@ -1705,11 +1742,14 @@ function compute(attrName, ui) {
1705
1742
  function getLeafPaint(attrName, paint, ui) {
1706
1743
  if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1707
1744
  let leafPaint;
1708
- const {boxBounds: boxBounds} = ui.__layout;
1709
- switch (paint.type) {
1745
+ const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
1746
+ switch (type) {
1710
1747
  case "image":
1748
+ case "film":
1749
+ case "video":
1711
1750
  if (!paint.url) return undefined;
1712
1751
  leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1752
+ if (type !== "image") draw.PaintImage[type](leafPaint);
1713
1753
  break;
1714
1754
 
1715
1755
  case "linear":
@@ -1725,7 +1765,7 @@ function getLeafPaint(attrName, paint, ui) {
1725
1765
  break;
1726
1766
 
1727
1767
  case "solid":
1728
- const {type: type, color: color, opacity: opacity} = paint;
1768
+ const {color: color, opacity: opacity} = paint;
1729
1769
  leafPaint = {
1730
1770
  type: type,
1731
1771
  style: draw.ColorConvert.string(color, opacity)
@@ -1769,7 +1809,7 @@ const {isSame: isSame} = core.BoundsHelper;
1769
1809
 
1770
1810
  function image(ui, attrName, paint, boxBounds, firstUse) {
1771
1811
  let leafPaint, event;
1772
- const image = core.ImageManager.get(paint);
1812
+ const image = core.ImageManager.get(paint, paint.type);
1773
1813
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1774
1814
  leafPaint = cache.leafPaint;
1775
1815
  } else {
@@ -1830,8 +1870,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1830
1870
  }
1831
1871
 
1832
1872
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1833
- if (attrName === "fill" && !ui.__.__naturalWidth) {
1834
- const data = ui.__;
1873
+ const data = ui.__;
1874
+ if (attrName === "fill" && !data.__naturalWidth) {
1835
1875
  data.__naturalWidth = image.width / data.pixelRatio;
1836
1876
  data.__naturalHeight = image.height / data.pixelRatio;
1837
1877
  if (data.__autoSide) {
@@ -1843,7 +1883,13 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
1843
1883
  return false;
1844
1884
  }
1845
1885
  }
1846
- if (!leafPaint.data) draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
1886
+ if (!leafPaint.data) {
1887
+ draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
1888
+ const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
1889
+ const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
1890
+ if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
1891
+ }
1892
+ if (paint.filter) draw.PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
1847
1893
  return true;
1848
1894
  }
1849
1895
 
@@ -1886,7 +1932,7 @@ function getPatternData(paint, box, image) {
1886
1932
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1887
1933
  if (paint.mode === "strench") paint.mode = "stretch";
1888
1934
  const {width: width, height: height} = image;
1889
- 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;
1935
+ const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
1890
1936
  const sameBox = box.width === width && box.height === height;
1891
1937
  const data = {
1892
1938
  mode: mode
@@ -1949,8 +1995,6 @@ function getPatternData(paint, box, image) {
1949
1995
  data.scaleX = scaleX;
1950
1996
  data.scaleY = scaleY;
1951
1997
  }
1952
- if (opacity && opacity < 1) data.opacity = opacity;
1953
- if (filters) data.filters = filters;
1954
1998
  if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1955
1999
  if (interlace) data.interlace = core.isNumber(interlace) || interlace.type === "percent" ? {
1956
2000
  type: "x",
@@ -1981,7 +2025,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
1981
2025
 
1982
2026
  function stretchMode(data, box, scaleX, scaleY) {
1983
2027
  const transform = get$2(), {x: x, y: y} = box;
1984
- if (x || y) translate(transform, x, y); else transform.onlyScale = true;
2028
+ if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
1985
2029
  scaleHelper(transform, scaleX, scaleY);
1986
2030
  data.transform = transform;
1987
2031
  }
@@ -2053,39 +2097,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
2053
2097
  translate(transform, box.x + x, box.y + y);
2054
2098
  }
2055
2099
 
2056
- function __awaiter(thisArg, _arguments, P, generator) {
2057
- function adopt(value) {
2058
- return value instanceof P ? value : new P(function(resolve) {
2059
- resolve(value);
2060
- });
2061
- }
2062
- return new (P || (P = Promise))(function(resolve, reject) {
2063
- function fulfilled(value) {
2064
- try {
2065
- step(generator.next(value));
2066
- } catch (e) {
2067
- reject(e);
2068
- }
2069
- }
2070
- function rejected(value) {
2071
- try {
2072
- step(generator["throw"](value));
2073
- } catch (e) {
2074
- reject(e);
2075
- }
2076
- }
2077
- function step(result) {
2078
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
2079
- }
2080
- step((generator = generator.apply(thisArg, _arguments || [])).next());
2081
- });
2082
- }
2083
-
2084
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
2085
- var e = new Error(message);
2086
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2087
- };
2088
-
2089
2100
  const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
2090
2101
 
2091
2102
  const {getFloorScale: getFloorScale} = core.MathHelper, {abs: abs$1} = Math;
@@ -2103,10 +2114,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
2103
2114
  }
2104
2115
 
2105
2116
  function createPattern(paint, ui, canvas, renderOptions) {
2106
- let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
2117
+ let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
2107
2118
  if (paint.patternId !== id && !ui.destroyed) {
2108
2119
  if (!(core.Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
2109
- const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
2120
+ const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
2110
2121
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
2111
2122
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
2112
2123
  width *= scaleX;
@@ -2122,7 +2133,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
2122
2133
  if (transform) copy$1(imageMatrix, transform);
2123
2134
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
2124
2135
  }
2125
- const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
2136
+ const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
2126
2137
  const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
2127
2138
  paint.style = pattern;
2128
2139
  paint.patternId = id;
@@ -2143,15 +2154,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
2143
2154
  }
2144
2155
 
2145
2156
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
2146
- const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
2157
+ const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
2147
2158
  const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
2148
- if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting || snapshot) {
2159
+ if (!data || paint.patternId === id && !exporting || snapshot) {
2149
2160
  return false;
2150
2161
  } else {
2151
2162
  if (drawImage) {
2152
2163
  if (data.repeat) {
2153
2164
  drawImage = false;
2154
- } else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
2165
+ } else if (!(originPaint.changeful || paint.film || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
2155
2166
  drawImage = core.Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
2156
2167
  }
2157
2168
  }
@@ -2169,20 +2180,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
2169
2180
  }
2170
2181
  }
2171
2182
 
2172
- function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
2173
- const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
2174
- let {width: width, height: height} = image, clipUI;
2175
- if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
2183
+ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
2184
+ const {data: data, image: image, complex: complex} = paint;
2185
+ let {width: width, height: height} = image;
2186
+ if (complex) {
2187
+ const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
2176
2188
  canvas.save();
2177
- clipUI && canvas.clipUI(ui);
2189
+ complex === 2 && canvas.clipUI(ui);
2178
2190
  blendMode && (canvas.blendMode = blendMode);
2179
2191
  opacity && (canvas.opacity *= opacity);
2180
2192
  transform && canvas.transform(transform);
2181
- canvas.drawImage(view, 0, 0, width, height);
2193
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
2182
2194
  canvas.restore();
2183
2195
  } else {
2184
2196
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
2185
- canvas.drawImage(view, 0, 0, width, height);
2197
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
2186
2198
  }
2187
2199
  }
2188
2200
 
@@ -2212,6 +2224,7 @@ function recycleImage(attrName, data) {
2212
2224
  if (!recycleMap) recycleMap = {};
2213
2225
  recycleMap[url] = true;
2214
2226
  core.ImageManager.recyclePaint(paint);
2227
+ if (data.__willDestroy && image.parent) draw.PaintImage.recycleFilter(image, data.__leaf);
2215
2228
  if (image.loading) {
2216
2229
  if (!input) {
2217
2230
  input = data.__input && data.__input[attrName] || [];
@@ -3127,6 +3140,13 @@ Object.assign(core.Creator, {
3127
3140
 
3128
3141
  useCanvas();
3129
3142
 
3143
+ Object.defineProperty(exports, "LeaferFilm", {
3144
+ enumerable: true,
3145
+ get: function() {
3146
+ return core.LeaferFilm;
3147
+ }
3148
+ });
3149
+
3130
3150
  Object.defineProperty(exports, "LeaferImage", {
3131
3151
  enumerable: true,
3132
3152
  get: function() {
@@ -3134,6 +3154,13 @@ Object.defineProperty(exports, "LeaferImage", {
3134
3154
  }
3135
3155
  });
3136
3156
 
3157
+ Object.defineProperty(exports, "LeaferVideo", {
3158
+ enumerable: true,
3159
+ get: function() {
3160
+ return core.LeaferVideo;
3161
+ }
3162
+ });
3163
+
3137
3164
  exports.Interaction = Interaction;
3138
3165
 
3139
3166
  exports.Layouter = Layouter;