leafer-ui 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 +94 -69
- package/dist/web.esm.js +82 -71
- package/dist/web.esm.min.js +1 -1
- package/dist/web.esm.min.js.map +1 -1
- package/dist/web.js +142 -90
- package/dist/web.min.cjs +1 -1
- package/dist/web.min.cjs.map +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.min.js.map +1 -1
- package/dist/web.module.js +147 -95
- package/dist/web.module.min.js +1 -1
- package/dist/web.module.min.js.map +1 -1
- package/package.json +11 -11
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 =
|
|
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,
|
|
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(
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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 {
|
|
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
|
-
|
|
1834
|
-
|
|
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)
|
|
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 {
|
|
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,
|
|
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 ===
|
|
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,
|
|
2173
|
-
const {data: data, image: image
|
|
2174
|
-
let {width: width, height: height} = image
|
|
2175
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2196
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
2186
2197
|
}
|
|
2187
2198
|
}
|
|
2188
2199
|
|
|
@@ -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;
|
package/dist/web.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Debug, LeaferCanvasBase, Platform, isString, DataHelper, canvasSizeAttrs, isUndefined, ResizeEvent, canvasPatch,
|
|
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, PointHelper, BoundsHelper, Plugin, MathHelper, isObject, FourNumberHelper, Matrix, ImageEvent, MatrixHelper, AlignHelper, 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 { InteractionHelper, InteractionBase, Cursor, HitCanvasManager } from "@leafer-ui/core";
|
|
8
8
|
|
|
@@ -19,6 +19,39 @@ var PathNodeHandleType;
|
|
|
19
19
|
PathNodeHandleType[PathNodeHandleType["mirror"] = 4] = "mirror";
|
|
20
20
|
})(PathNodeHandleType || (PathNodeHandleType = {}));
|
|
21
21
|
|
|
22
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
23
|
+
function adopt(value) {
|
|
24
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
25
|
+
resolve(value);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
29
|
+
function fulfilled(value) {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.next(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function rejected(value) {
|
|
37
|
+
try {
|
|
38
|
+
step(generator["throw"](value));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
reject(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function step(result) {
|
|
44
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
45
|
+
}
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
51
|
+
var e = new Error(message);
|
|
52
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
53
|
+
};
|
|
54
|
+
|
|
22
55
|
const debug$2 = Debug.get("LeaferCanvas");
|
|
23
56
|
|
|
24
57
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
@@ -222,8 +255,6 @@ canvasPatch(CanvasRenderingContext2D.prototype);
|
|
|
222
255
|
|
|
223
256
|
canvasPatch(Path2D.prototype);
|
|
224
257
|
|
|
225
|
-
const {mineType: mineType, fileType: fileType} = FileHelper;
|
|
226
|
-
|
|
227
258
|
Object.assign(Creator, {
|
|
228
259
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
229
260
|
image: options => new LeaferImage(options)
|
|
@@ -238,29 +269,27 @@ function useCanvas(_canvasType, _power) {
|
|
|
238
269
|
return canvas;
|
|
239
270
|
},
|
|
240
271
|
canvasToDataURL: (canvas, type, quality) => {
|
|
241
|
-
const imageType =
|
|
272
|
+
const imageType = FileHelper.mimeType(type), url = canvas.toDataURL(imageType, quality);
|
|
242
273
|
return imageType === "image/bmp" ? url.replace("image/png;", "image/bmp;") : url;
|
|
243
274
|
},
|
|
244
|
-
canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve,
|
|
275
|
+
canvasToBolb: (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, FileHelper.mimeType(type), quality)),
|
|
245
276
|
canvasSaveAs: (canvas, filename, quality) => {
|
|
246
|
-
const url = canvas.toDataURL(
|
|
277
|
+
const url = canvas.toDataURL(FileHelper.mimeType(FileHelper.fileType(filename)), quality);
|
|
247
278
|
return Platform.origin.download(url, filename);
|
|
248
279
|
},
|
|
249
280
|
download(url, filename) {
|
|
250
|
-
return
|
|
281
|
+
return __awaiter(this, void 0, void 0, function*() {
|
|
251
282
|
let el = document.createElement("a");
|
|
252
283
|
el.href = url;
|
|
253
284
|
el.download = filename;
|
|
254
285
|
document.body.appendChild(el);
|
|
255
286
|
el.click();
|
|
256
287
|
document.body.removeChild(el);
|
|
257
|
-
resolve();
|
|
258
288
|
});
|
|
259
289
|
},
|
|
260
|
-
loadImage(src) {
|
|
290
|
+
loadImage(src, crossOrigin, _leaferImage) {
|
|
261
291
|
return new Promise((resolve, reject) => {
|
|
262
292
|
const img = new Platform.origin.Image;
|
|
263
|
-
const {crossOrigin: crossOrigin} = Platform.image;
|
|
264
293
|
if (crossOrigin) {
|
|
265
294
|
img.setAttribute("crossOrigin", crossOrigin);
|
|
266
295
|
img.crossOrigin = crossOrigin;
|
|
@@ -274,6 +303,13 @@ function useCanvas(_canvasType, _power) {
|
|
|
274
303
|
img.src = Platform.image.getRealURL(src);
|
|
275
304
|
});
|
|
276
305
|
},
|
|
306
|
+
loadContent(url_1) {
|
|
307
|
+
return __awaiter(this, arguments, void 0, function*(url, responseType = "text") {
|
|
308
|
+
const response = yield fetch(url);
|
|
309
|
+
if (!response.ok) throw new Error(`${response.status}`);
|
|
310
|
+
return yield response[responseType]();
|
|
311
|
+
});
|
|
312
|
+
},
|
|
277
313
|
Image: Image,
|
|
278
314
|
PointerEvent: PointerEvent,
|
|
279
315
|
DragEvent: DragEvent
|
|
@@ -785,7 +821,7 @@ class Renderer {
|
|
|
785
821
|
getCellList() {
|
|
786
822
|
return undefined;
|
|
787
823
|
}
|
|
788
|
-
addBlock(block) {
|
|
824
|
+
addBlock(block, _leafList) {
|
|
789
825
|
if (!this.updateBlocks) this.updateBlocks = [];
|
|
790
826
|
this.updateBlocks.push(block);
|
|
791
827
|
}
|
|
@@ -833,7 +869,8 @@ class Renderer {
|
|
|
833
869
|
__onLayoutEnd(event) {
|
|
834
870
|
if (event.data) event.data.map(item => {
|
|
835
871
|
let empty;
|
|
836
|
-
|
|
872
|
+
const {updatedList: updatedList} = item;
|
|
873
|
+
if (updatedList) updatedList.list.some(leaf => {
|
|
837
874
|
empty = !leaf.__world.width || !leaf.__world.height;
|
|
838
875
|
if (empty) {
|
|
839
876
|
if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
|
|
@@ -841,7 +878,7 @@ class Renderer {
|
|
|
841
878
|
}
|
|
842
879
|
return empty;
|
|
843
880
|
});
|
|
844
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
881
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
|
|
845
882
|
});
|
|
846
883
|
}
|
|
847
884
|
emitRender(type, bounds, options) {
|
|
@@ -1709,11 +1746,14 @@ function compute(attrName, ui) {
|
|
|
1709
1746
|
function getLeafPaint(attrName, paint, ui) {
|
|
1710
1747
|
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
1711
1748
|
let leafPaint;
|
|
1712
|
-
const {boxBounds: boxBounds} = ui.__layout;
|
|
1713
|
-
switch (
|
|
1749
|
+
const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
|
|
1750
|
+
switch (type) {
|
|
1714
1751
|
case "image":
|
|
1752
|
+
case "film":
|
|
1753
|
+
case "video":
|
|
1715
1754
|
if (!paint.url) return undefined;
|
|
1716
1755
|
leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
1756
|
+
if (type !== "image") PaintImage[type](leafPaint);
|
|
1717
1757
|
break;
|
|
1718
1758
|
|
|
1719
1759
|
case "linear":
|
|
@@ -1729,7 +1769,7 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
1729
1769
|
break;
|
|
1730
1770
|
|
|
1731
1771
|
case "solid":
|
|
1732
|
-
const {
|
|
1772
|
+
const {color: color, opacity: opacity} = paint;
|
|
1733
1773
|
leafPaint = {
|
|
1734
1774
|
type: type,
|
|
1735
1775
|
style: ColorConvert.string(color, opacity)
|
|
@@ -1773,7 +1813,7 @@ const {isSame: isSame} = BoundsHelper;
|
|
|
1773
1813
|
|
|
1774
1814
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1775
1815
|
let leafPaint, event;
|
|
1776
|
-
const image = ImageManager.get(paint);
|
|
1816
|
+
const image = ImageManager.get(paint, paint.type);
|
|
1777
1817
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1778
1818
|
leafPaint = cache.leafPaint;
|
|
1779
1819
|
} else {
|
|
@@ -1834,8 +1874,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1834
1874
|
}
|
|
1835
1875
|
|
|
1836
1876
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1837
|
-
|
|
1838
|
-
|
|
1877
|
+
const data = ui.__;
|
|
1878
|
+
if (attrName === "fill" && !data.__naturalWidth) {
|
|
1839
1879
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1840
1880
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1841
1881
|
if (data.__autoSide) {
|
|
@@ -1847,7 +1887,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
|
|
|
1847
1887
|
return false;
|
|
1848
1888
|
}
|
|
1849
1889
|
}
|
|
1850
|
-
if (!leafPaint.data)
|
|
1890
|
+
if (!leafPaint.data) {
|
|
1891
|
+
PaintImage.createData(leafPaint, image, paint, boxBounds);
|
|
1892
|
+
const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
|
|
1893
|
+
const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
|
|
1894
|
+
if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
|
|
1895
|
+
}
|
|
1851
1896
|
return true;
|
|
1852
1897
|
}
|
|
1853
1898
|
|
|
@@ -1890,7 +1935,7 @@ function getPatternData(paint, box, image) {
|
|
|
1890
1935
|
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1891
1936
|
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1892
1937
|
const {width: width, height: height} = image;
|
|
1893
|
-
const {
|
|
1938
|
+
const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
|
|
1894
1939
|
const sameBox = box.width === width && box.height === height;
|
|
1895
1940
|
const data = {
|
|
1896
1941
|
mode: mode
|
|
@@ -1953,8 +1998,6 @@ function getPatternData(paint, box, image) {
|
|
|
1953
1998
|
data.scaleX = scaleX;
|
|
1954
1999
|
data.scaleY = scaleY;
|
|
1955
2000
|
}
|
|
1956
|
-
if (opacity && opacity < 1) data.opacity = opacity;
|
|
1957
|
-
if (filters) data.filters = filters;
|
|
1958
2001
|
if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1959
2002
|
if (interlace) data.interlace = isNumber(interlace) || interlace.type === "percent" ? {
|
|
1960
2003
|
type: "x",
|
|
@@ -1985,7 +2028,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
|
|
|
1985
2028
|
|
|
1986
2029
|
function stretchMode(data, box, scaleX, scaleY) {
|
|
1987
2030
|
const transform = get$2(), {x: x, y: y} = box;
|
|
1988
|
-
if (x || y) translate(transform, x, y); else transform.onlyScale = true;
|
|
2031
|
+
if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
|
|
1989
2032
|
scaleHelper(transform, scaleX, scaleY);
|
|
1990
2033
|
data.transform = transform;
|
|
1991
2034
|
}
|
|
@@ -2057,39 +2100,6 @@ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
|
2057
2100
|
translate(transform, box.x + x, box.y + y);
|
|
2058
2101
|
}
|
|
2059
2102
|
|
|
2060
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
2061
|
-
function adopt(value) {
|
|
2062
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
2063
|
-
resolve(value);
|
|
2064
|
-
});
|
|
2065
|
-
}
|
|
2066
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
2067
|
-
function fulfilled(value) {
|
|
2068
|
-
try {
|
|
2069
|
-
step(generator.next(value));
|
|
2070
|
-
} catch (e) {
|
|
2071
|
-
reject(e);
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
function rejected(value) {
|
|
2075
|
-
try {
|
|
2076
|
-
step(generator["throw"](value));
|
|
2077
|
-
} catch (e) {
|
|
2078
|
-
reject(e);
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
function step(result) {
|
|
2082
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
2083
|
-
}
|
|
2084
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2085
|
-
});
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
|
-
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
2089
|
-
var e = new Error(message);
|
|
2090
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
2091
|
-
};
|
|
2092
|
-
|
|
2093
2103
|
const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
|
|
2094
2104
|
|
|
2095
2105
|
const {getFloorScale: getFloorScale} = MathHelper, {abs: abs$1} = Math;
|
|
@@ -2107,10 +2117,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
|
|
|
2107
2117
|
}
|
|
2108
2118
|
|
|
2109
2119
|
function createPattern(paint, ui, canvas, renderOptions) {
|
|
2110
|
-
let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
|
|
2120
|
+
let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
2111
2121
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
2112
2122
|
if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
|
|
2113
|
-
const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
2123
|
+
const {image: image, data: data} = paint, {opacity: opacity, filters: filters} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
2114
2124
|
let imageMatrix, xGap, yGap, {width: width, height: height} = image;
|
|
2115
2125
|
if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
|
|
2116
2126
|
width *= scaleX;
|
|
@@ -2126,7 +2136,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
|
|
|
2126
2136
|
if (transform) copy$1(imageMatrix, transform);
|
|
2127
2137
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
2128
2138
|
}
|
|
2129
|
-
const imageCanvas = image.getCanvas(width, height,
|
|
2139
|
+
const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
|
|
2130
2140
|
const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
2131
2141
|
paint.style = pattern;
|
|
2132
2142
|
paint.patternId = id;
|
|
@@ -2147,15 +2157,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
|
|
|
2147
2157
|
}
|
|
2148
2158
|
|
|
2149
2159
|
function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
2150
|
-
const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
|
|
2160
|
+
const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
2151
2161
|
const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
|
|
2152
|
-
if (!data || paint.patternId ===
|
|
2162
|
+
if (!data || paint.patternId === id && !exporting || snapshot) {
|
|
2153
2163
|
return false;
|
|
2154
2164
|
} else {
|
|
2155
2165
|
if (drawImage) {
|
|
2156
2166
|
if (data.repeat) {
|
|
2157
2167
|
drawImage = false;
|
|
2158
|
-
} else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
|
|
2168
|
+
} else if (!(originPaint.changeful || paint.film || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
|
|
2159
2169
|
drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
|
|
2160
2170
|
}
|
|
2161
2171
|
}
|
|
@@ -2173,20 +2183,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
|
2173
2183
|
}
|
|
2174
2184
|
}
|
|
2175
2185
|
|
|
2176
|
-
function drawImage(paint,
|
|
2177
|
-
const {data: data, image: image
|
|
2178
|
-
let {width: width, height: height} = image
|
|
2179
|
-
if (
|
|
2186
|
+
function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
|
|
2187
|
+
const {data: data, image: image, complex: complex} = paint;
|
|
2188
|
+
let {width: width, height: height} = image;
|
|
2189
|
+
if (complex) {
|
|
2190
|
+
const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
|
|
2180
2191
|
canvas.save();
|
|
2181
|
-
|
|
2192
|
+
complex === 2 && canvas.clipUI(ui);
|
|
2182
2193
|
blendMode && (canvas.blendMode = blendMode);
|
|
2183
2194
|
opacity && (canvas.opacity *= opacity);
|
|
2184
2195
|
transform && canvas.transform(transform);
|
|
2185
|
-
|
|
2196
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
2186
2197
|
canvas.restore();
|
|
2187
2198
|
} else {
|
|
2188
2199
|
if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
|
|
2189
|
-
|
|
2200
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
2190
2201
|
}
|
|
2191
2202
|
}
|
|
2192
2203
|
|