leafer-ui 2.0.0 → 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
@@ -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) {
@@ -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,12 @@ 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
+ }
1847
1892
  return true;
1848
1893
  }
1849
1894
 
@@ -1886,7 +1931,7 @@ function getPatternData(paint, box, image) {
1886
1931
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1887
1932
  if (paint.mode === "strench") paint.mode = "stretch";
1888
1933
  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;
1934
+ 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
1935
  const sameBox = box.width === width && box.height === height;
1891
1936
  const data = {
1892
1937
  mode: mode
@@ -1949,8 +1994,6 @@ function getPatternData(paint, box, image) {
1949
1994
  data.scaleX = scaleX;
1950
1995
  data.scaleY = scaleY;
1951
1996
  }
1952
- if (opacity && opacity < 1) data.opacity = opacity;
1953
- if (filters) data.filters = filters;
1954
1997
  if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1955
1998
  if (interlace) data.interlace = core.isNumber(interlace) || interlace.type === "percent" ? {
1956
1999
  type: "x",
@@ -1981,7 +2024,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
1981
2024
 
1982
2025
  function stretchMode(data, box, scaleX, scaleY) {
1983
2026
  const transform = get$2(), {x: x, y: y} = box;
1984
- if (x || y) translate(transform, x, y); else transform.onlyScale = true;
2027
+ if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
1985
2028
  scaleHelper(transform, scaleX, scaleY);
1986
2029
  data.transform = transform;
1987
2030
  }
@@ -2053,39 +2096,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
2053
2096
  translate(transform, box.x + x, box.y + y);
2054
2097
  }
2055
2098
 
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
2099
  const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
2090
2100
 
2091
2101
  const {getFloorScale: getFloorScale} = core.MathHelper, {abs: abs$1} = Math;
@@ -2103,10 +2113,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
2103
2113
  }
2104
2114
 
2105
2115
  function createPattern(paint, ui, canvas, renderOptions) {
2106
- let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
2116
+ let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
2107
2117
  if (paint.patternId !== id && !ui.destroyed) {
2108
2118
  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);
2119
+ const {image: image, data: data} = paint, {opacity: opacity, filters: filters} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
2110
2120
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
2111
2121
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
2112
2122
  width *= scaleX;
@@ -2122,7 +2132,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
2122
2132
  if (transform) copy$1(imageMatrix, transform);
2123
2133
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
2124
2134
  }
2125
- const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
2135
+ const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
2126
2136
  const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
2127
2137
  paint.style = pattern;
2128
2138
  paint.patternId = id;
@@ -2143,15 +2153,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
2143
2153
  }
2144
2154
 
2145
2155
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
2146
- const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
2156
+ const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
2147
2157
  const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
2148
- if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting || snapshot) {
2158
+ if (!data || paint.patternId === id && !exporting || snapshot) {
2149
2159
  return false;
2150
2160
  } else {
2151
2161
  if (drawImage) {
2152
2162
  if (data.repeat) {
2153
2163
  drawImage = false;
2154
- } else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
2164
+ } else if (!(originPaint.changeful || paint.film || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
2155
2165
  drawImage = core.Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
2156
2166
  }
2157
2167
  }
@@ -2169,20 +2179,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
2169
2179
  }
2170
2180
  }
2171
2181
 
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) {
2182
+ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
2183
+ const {data: data, image: image, complex: complex} = paint;
2184
+ let {width: width, height: height} = image;
2185
+ if (complex) {
2186
+ const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
2176
2187
  canvas.save();
2177
- clipUI && canvas.clipUI(ui);
2188
+ complex === 2 && canvas.clipUI(ui);
2178
2189
  blendMode && (canvas.blendMode = blendMode);
2179
2190
  opacity && (canvas.opacity *= opacity);
2180
2191
  transform && canvas.transform(transform);
2181
- canvas.drawImage(view, 0, 0, width, height);
2192
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
2182
2193
  canvas.restore();
2183
2194
  } else {
2184
2195
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
2185
- canvas.drawImage(view, 0, 0, width, height);
2196
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
2186
2197
  }
2187
2198
  }
2188
2199
 
@@ -2902,7 +2913,7 @@ function layoutText(drawData, style) {
2902
2913
  let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2903
2914
  let starY = __baseLine;
2904
2915
  if (__clipText && realHeight > height) {
2905
- realHeight = Math.max(height, __lineHeight);
2916
+ realHeight = Math.max(style.__autoHeight ? realHeight : height, __lineHeight);
2906
2917
  if (countRows > 1) drawData.overflow = countRows;
2907
2918
  } else if (height || autoSizeAlign) {
2908
2919
  switch (verticalAlign) {
@@ -2959,10 +2970,10 @@ function layoutText(drawData, style) {
2959
2970
  }
2960
2971
 
2961
2972
  function clipText(drawData, style, x, width) {
2962
- if (!width) return;
2963
2973
  const {rows: rows, overflow: overflow} = drawData;
2964
2974
  let {textOverflow: textOverflow} = style;
2965
- rows.splice(overflow);
2975
+ if (overflow) rows.splice(overflow);
2976
+ if (!width) return;
2966
2977
  if (textOverflow && textOverflow !== "show") {
2967
2978
  if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
2968
2979
  let char, charRight;
@@ -3127,6 +3138,13 @@ Object.assign(core.Creator, {
3127
3138
 
3128
3139
  useCanvas();
3129
3140
 
3141
+ Object.defineProperty(exports, "LeaferFilm", {
3142
+ enumerable: true,
3143
+ get: function() {
3144
+ return core.LeaferFilm;
3145
+ }
3146
+ });
3147
+
3130
3148
  Object.defineProperty(exports, "LeaferImage", {
3131
3149
  enumerable: true,
3132
3150
  get: function() {
@@ -3134,6 +3152,13 @@ Object.defineProperty(exports, "LeaferImage", {
3134
3152
  }
3135
3153
  });
3136
3154
 
3155
+ Object.defineProperty(exports, "LeaferVideo", {
3156
+ enumerable: true,
3157
+ get: function() {
3158
+ return core.LeaferVideo;
3159
+ }
3160
+ });
3161
+
3137
3162
  exports.Interaction = Interaction;
3138
3163
 
3139
3164
  exports.Layouter = Layouter;