@leafer-ui/miniapp 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/miniapp.cjs +65 -35
- package/dist/miniapp.esm.js +53 -37
- package/dist/miniapp.esm.min.js +1 -1
- package/dist/miniapp.esm.min.js.map +1 -1
- package/dist/miniapp.min.cjs +1 -1
- package/dist/miniapp.min.cjs.map +1 -1
- package/dist/miniapp.module.js +206 -96
- package/dist/miniapp.module.min.js +1 -1
- package/dist/miniapp.module.min.js.map +1 -1
- package/package.json +10 -12
- package/src/index.ts +2 -2
- package/types/index.d.ts +1 -8
- package/src/core.ts +0 -143
package/dist/miniapp.cjs
CHANGED
|
@@ -118,8 +118,6 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const {mineType: mineType, fileType: fileType} = core.FileHelper;
|
|
122
|
-
|
|
123
121
|
Object.assign(core.Creator, {
|
|
124
122
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
125
123
|
image: options => new core.LeaferImage(options)
|
|
@@ -135,12 +133,12 @@ function useCanvas(_canvasType, app) {
|
|
|
135
133
|
};
|
|
136
134
|
return app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
|
|
137
135
|
},
|
|
138
|
-
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(
|
|
136
|
+
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(core.FileHelper.mimeType(type), quality),
|
|
139
137
|
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, {
|
|
140
138
|
quality: quality
|
|
141
139
|
}),
|
|
142
140
|
canvasSaveAs: (canvas, filePath, quality) => {
|
|
143
|
-
let data = canvas.toDataURL(
|
|
141
|
+
let data = canvas.toDataURL(core.FileHelper.mimeType(core.FileHelper.fileType(filePath)), quality);
|
|
144
142
|
data = data.substring(data.indexOf("64,") + 3);
|
|
145
143
|
return core.Platform.origin.download(data, filePath);
|
|
146
144
|
},
|
|
@@ -174,7 +172,7 @@ function useCanvas(_canvasType, app) {
|
|
|
174
172
|
});
|
|
175
173
|
});
|
|
176
174
|
},
|
|
177
|
-
loadImage(src) {
|
|
175
|
+
loadImage(src, _crossOrigin, _leaferImage) {
|
|
178
176
|
return new Promise((resolve, reject) => {
|
|
179
177
|
const img = core.Platform.canvas.view.createImage();
|
|
180
178
|
img.onload = () => {
|
|
@@ -186,6 +184,14 @@ function useCanvas(_canvasType, app) {
|
|
|
186
184
|
img.src = core.Platform.image.getRealURL(src);
|
|
187
185
|
});
|
|
188
186
|
},
|
|
187
|
+
loadContent(url, responseType = "text") {
|
|
188
|
+
return new Promise((resolve, reject) => app.request({
|
|
189
|
+
url: url,
|
|
190
|
+
responseType: responseType === "arrayBuffer" ? "arraybuffer" : "text",
|
|
191
|
+
success: res => resolve(responseType === "json" && typeof res.data === "string" ? JSON.parse(res.data) : res.data),
|
|
192
|
+
fail: reject
|
|
193
|
+
}));
|
|
194
|
+
},
|
|
189
195
|
noRepeat: "repeat-x"
|
|
190
196
|
};
|
|
191
197
|
core.Platform.miniapp = {
|
|
@@ -737,7 +743,7 @@ class Renderer {
|
|
|
737
743
|
getCellList() {
|
|
738
744
|
return undefined;
|
|
739
745
|
}
|
|
740
|
-
addBlock(block) {
|
|
746
|
+
addBlock(block, _leafList) {
|
|
741
747
|
if (!this.updateBlocks) this.updateBlocks = [];
|
|
742
748
|
this.updateBlocks.push(block);
|
|
743
749
|
}
|
|
@@ -785,7 +791,8 @@ class Renderer {
|
|
|
785
791
|
__onLayoutEnd(event) {
|
|
786
792
|
if (event.data) event.data.map(item => {
|
|
787
793
|
let empty;
|
|
788
|
-
|
|
794
|
+
const {updatedList: updatedList} = item;
|
|
795
|
+
if (updatedList) updatedList.list.some(leaf => {
|
|
789
796
|
empty = !leaf.__world.width || !leaf.__world.height;
|
|
790
797
|
if (empty) {
|
|
791
798
|
if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
|
|
@@ -793,7 +800,7 @@ class Renderer {
|
|
|
793
800
|
}
|
|
794
801
|
return empty;
|
|
795
802
|
});
|
|
796
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
803
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
|
|
797
804
|
});
|
|
798
805
|
}
|
|
799
806
|
emitRender(type, bounds, options) {
|
|
@@ -999,7 +1006,7 @@ class Selector {
|
|
|
999
1006
|
this.config = {};
|
|
1000
1007
|
if (userConfig) this.config = core.DataHelper.default(userConfig, this.config);
|
|
1001
1008
|
this.picker = new Picker(this.target = target, this);
|
|
1002
|
-
this.finder = core.Creator.finder && core.Creator.finder();
|
|
1009
|
+
this.finder = core.Creator.finder && core.Creator.finder(target, this.config);
|
|
1003
1010
|
}
|
|
1004
1011
|
getByPoint(hitPoint, hitRadius, options) {
|
|
1005
1012
|
const {target: target, picker: picker} = this;
|
|
@@ -1170,8 +1177,8 @@ function fills(fills, ui, canvas, renderOptions) {
|
|
|
1170
1177
|
canvas.save();
|
|
1171
1178
|
if (item.transform) canvas.transform(item.transform);
|
|
1172
1179
|
if (originPaint.scaleFixed) {
|
|
1173
|
-
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
|
|
1174
|
-
if (
|
|
1180
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, originPaint.scaleFixed, false);
|
|
1181
|
+
if (scaleX !== 1) canvas.scale(scaleX, scaleY);
|
|
1175
1182
|
}
|
|
1176
1183
|
if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
|
|
1177
1184
|
fillPathOrText(ui, canvas, renderOptions);
|
|
@@ -1445,11 +1452,14 @@ function compute(attrName, ui) {
|
|
|
1445
1452
|
function getLeafPaint(attrName, paint, ui) {
|
|
1446
1453
|
if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
1447
1454
|
let leafPaint;
|
|
1448
|
-
const {boxBounds: boxBounds} = ui.__layout;
|
|
1449
|
-
switch (
|
|
1455
|
+
const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
|
|
1456
|
+
switch (type) {
|
|
1450
1457
|
case "image":
|
|
1458
|
+
case "film":
|
|
1459
|
+
case "video":
|
|
1451
1460
|
if (!paint.url) return undefined;
|
|
1452
1461
|
leafPaint = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
1462
|
+
if (type !== "image") draw.PaintImage[type](leafPaint);
|
|
1453
1463
|
break;
|
|
1454
1464
|
|
|
1455
1465
|
case "linear":
|
|
@@ -1465,7 +1475,7 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
1465
1475
|
break;
|
|
1466
1476
|
|
|
1467
1477
|
case "solid":
|
|
1468
|
-
const {
|
|
1478
|
+
const {color: color, opacity: opacity} = paint;
|
|
1469
1479
|
leafPaint = {
|
|
1470
1480
|
type: type,
|
|
1471
1481
|
style: draw.ColorConvert.string(color, opacity)
|
|
@@ -1509,7 +1519,7 @@ const {isSame: isSame} = core.BoundsHelper;
|
|
|
1509
1519
|
|
|
1510
1520
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1511
1521
|
let leafPaint, event;
|
|
1512
|
-
const image = core.ImageManager.get(paint);
|
|
1522
|
+
const image = core.ImageManager.get(paint, paint.type);
|
|
1513
1523
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1514
1524
|
leafPaint = cache.leafPaint;
|
|
1515
1525
|
} else {
|
|
@@ -1570,8 +1580,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1570
1580
|
}
|
|
1571
1581
|
|
|
1572
1582
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1573
|
-
|
|
1574
|
-
|
|
1583
|
+
const data = ui.__;
|
|
1584
|
+
if (attrName === "fill" && !data.__naturalWidth) {
|
|
1575
1585
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1576
1586
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1577
1587
|
if (data.__autoSide) {
|
|
@@ -1583,7 +1593,13 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
|
|
|
1583
1593
|
return false;
|
|
1584
1594
|
}
|
|
1585
1595
|
}
|
|
1586
|
-
if (!leafPaint.data)
|
|
1596
|
+
if (!leafPaint.data) {
|
|
1597
|
+
draw.PaintImage.createData(leafPaint, image, paint, boxBounds);
|
|
1598
|
+
const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
|
|
1599
|
+
const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
|
|
1600
|
+
if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
|
|
1601
|
+
}
|
|
1602
|
+
if (paint.filter) draw.PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
|
|
1587
1603
|
return true;
|
|
1588
1604
|
}
|
|
1589
1605
|
|
|
@@ -1626,7 +1642,7 @@ function getPatternData(paint, box, image) {
|
|
|
1626
1642
|
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1627
1643
|
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1628
1644
|
const {width: width, height: height} = image;
|
|
1629
|
-
const {
|
|
1645
|
+
const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
|
|
1630
1646
|
const sameBox = box.width === width && box.height === height;
|
|
1631
1647
|
const data = {
|
|
1632
1648
|
mode: mode
|
|
@@ -1689,8 +1705,6 @@ function getPatternData(paint, box, image) {
|
|
|
1689
1705
|
data.scaleX = scaleX;
|
|
1690
1706
|
data.scaleY = scaleY;
|
|
1691
1707
|
}
|
|
1692
|
-
if (opacity && opacity < 1) data.opacity = opacity;
|
|
1693
|
-
if (filters) data.filters = filters;
|
|
1694
1708
|
if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1695
1709
|
if (interlace) data.interlace = core.isNumber(interlace) || interlace.type === "percent" ? {
|
|
1696
1710
|
type: "x",
|
|
@@ -1721,7 +1735,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
|
|
|
1721
1735
|
|
|
1722
1736
|
function stretchMode(data, box, scaleX, scaleY) {
|
|
1723
1737
|
const transform = get$2(), {x: x, y: y} = box;
|
|
1724
|
-
if (x || y) translate(transform, x, y); else transform.onlyScale = true;
|
|
1738
|
+
if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
|
|
1725
1739
|
scaleHelper(transform, scaleX, scaleY);
|
|
1726
1740
|
data.transform = transform;
|
|
1727
1741
|
}
|
|
@@ -1843,10 +1857,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
|
|
|
1843
1857
|
}
|
|
1844
1858
|
|
|
1845
1859
|
function createPattern(paint, ui, canvas, renderOptions) {
|
|
1846
|
-
let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
|
|
1860
|
+
let {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1847
1861
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1848
1862
|
if (!(core.Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
|
|
1849
|
-
const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1863
|
+
const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = draw.PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1850
1864
|
let imageMatrix, xGap, yGap, {width: width, height: height} = image;
|
|
1851
1865
|
if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
|
|
1852
1866
|
width *= scaleX;
|
|
@@ -1862,7 +1876,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
|
|
|
1862
1876
|
if (transform) copy$1(imageMatrix, transform);
|
|
1863
1877
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1864
1878
|
}
|
|
1865
|
-
const imageCanvas = image.getCanvas(width, height,
|
|
1879
|
+
const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
|
|
1866
1880
|
const pattern = image.getPattern(imageCanvas, data.repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1867
1881
|
paint.style = pattern;
|
|
1868
1882
|
paint.patternId = id;
|
|
@@ -1883,15 +1897,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
|
|
|
1883
1897
|
}
|
|
1884
1898
|
|
|
1885
1899
|
function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
1886
|
-
const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
|
|
1900
|
+
const {scaleX: scaleX, scaleY: scaleY} = draw.PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1887
1901
|
const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
|
|
1888
|
-
if (!data || paint.patternId ===
|
|
1902
|
+
if (!data || paint.patternId === id && !exporting || snapshot) {
|
|
1889
1903
|
return false;
|
|
1890
1904
|
} else {
|
|
1891
1905
|
if (drawImage) {
|
|
1892
1906
|
if (data.repeat) {
|
|
1893
1907
|
drawImage = false;
|
|
1894
|
-
} else if (!(originPaint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
|
|
1908
|
+
} else if (!(originPaint.changeful || paint.film || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || exporting)) {
|
|
1895
1909
|
drawImage = core.Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
|
|
1896
1910
|
}
|
|
1897
1911
|
}
|
|
@@ -1909,20 +1923,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
|
1909
1923
|
}
|
|
1910
1924
|
}
|
|
1911
1925
|
|
|
1912
|
-
function drawImage(paint,
|
|
1913
|
-
const {data: data, image: image
|
|
1914
|
-
let {width: width, height: height} = image
|
|
1915
|
-
if (
|
|
1926
|
+
function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
|
|
1927
|
+
const {data: data, image: image, complex: complex} = paint;
|
|
1928
|
+
let {width: width, height: height} = image;
|
|
1929
|
+
if (complex) {
|
|
1930
|
+
const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
|
|
1916
1931
|
canvas.save();
|
|
1917
|
-
|
|
1932
|
+
complex === 2 && canvas.clipUI(ui);
|
|
1918
1933
|
blendMode && (canvas.blendMode = blendMode);
|
|
1919
1934
|
opacity && (canvas.opacity *= opacity);
|
|
1920
1935
|
transform && canvas.transform(transform);
|
|
1921
|
-
|
|
1936
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1922
1937
|
canvas.restore();
|
|
1923
1938
|
} else {
|
|
1924
1939
|
if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
|
|
1925
|
-
|
|
1940
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1926
1941
|
}
|
|
1927
1942
|
}
|
|
1928
1943
|
|
|
@@ -1952,6 +1967,7 @@ function recycleImage(attrName, data) {
|
|
|
1952
1967
|
if (!recycleMap) recycleMap = {};
|
|
1953
1968
|
recycleMap[url] = true;
|
|
1954
1969
|
core.ImageManager.recyclePaint(paint);
|
|
1970
|
+
if (data.__willDestroy && image.parent) draw.PaintImage.recycleFilter(image, data.__leaf);
|
|
1955
1971
|
if (image.loading) {
|
|
1956
1972
|
if (!input) {
|
|
1957
1973
|
input = data.__input && data.__input[attrName] || [];
|
|
@@ -2873,6 +2889,13 @@ try {
|
|
|
2873
2889
|
if (wx) useCanvas("miniapp", wx);
|
|
2874
2890
|
} catch (_a) {}
|
|
2875
2891
|
|
|
2892
|
+
Object.defineProperty(exports, "LeaferFilm", {
|
|
2893
|
+
enumerable: true,
|
|
2894
|
+
get: function() {
|
|
2895
|
+
return core.LeaferFilm;
|
|
2896
|
+
}
|
|
2897
|
+
});
|
|
2898
|
+
|
|
2876
2899
|
Object.defineProperty(exports, "LeaferImage", {
|
|
2877
2900
|
enumerable: true,
|
|
2878
2901
|
get: function() {
|
|
@@ -2880,6 +2903,13 @@ Object.defineProperty(exports, "LeaferImage", {
|
|
|
2880
2903
|
}
|
|
2881
2904
|
});
|
|
2882
2905
|
|
|
2906
|
+
Object.defineProperty(exports, "LeaferVideo", {
|
|
2907
|
+
enumerable: true,
|
|
2908
|
+
get: function() {
|
|
2909
|
+
return core.LeaferVideo;
|
|
2910
|
+
}
|
|
2911
|
+
});
|
|
2912
|
+
|
|
2883
2913
|
exports.Interaction = Interaction;
|
|
2884
2914
|
|
|
2885
2915
|
exports.Layouter = Layouter;
|
package/dist/miniapp.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { LeaferCanvasBase, isString, Platform, isNumber, canvasPatch, DataHelper, canvasSizeAttrs, isUndefined, ResizeEvent,
|
|
1
|
+
import { LeaferCanvasBase, isString, Platform, isNumber, canvasPatch, DataHelper, canvasSizeAttrs, isUndefined, ResizeEvent, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, PointHelper, BoundsHelper, Plugin, isObject, FourNumberHelper, Matrix, ImageEvent, MatrixHelper, MathHelper, AlignHelper, 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, isUndefined as isUndefined$1, HitCanvasManager } from "@leafer-ui/core";
|
|
8
8
|
|
|
@@ -122,8 +122,6 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
const {mineType: mineType, fileType: fileType} = FileHelper;
|
|
126
|
-
|
|
127
125
|
Object.assign(Creator, {
|
|
128
126
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
129
127
|
image: options => new LeaferImage(options)
|
|
@@ -139,12 +137,12 @@ function useCanvas(_canvasType, app) {
|
|
|
139
137
|
};
|
|
140
138
|
return app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
|
|
141
139
|
},
|
|
142
|
-
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(
|
|
140
|
+
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(FileHelper.mimeType(type), quality),
|
|
143
141
|
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, {
|
|
144
142
|
quality: quality
|
|
145
143
|
}),
|
|
146
144
|
canvasSaveAs: (canvas, filePath, quality) => {
|
|
147
|
-
let data = canvas.toDataURL(
|
|
145
|
+
let data = canvas.toDataURL(FileHelper.mimeType(FileHelper.fileType(filePath)), quality);
|
|
148
146
|
data = data.substring(data.indexOf("64,") + 3);
|
|
149
147
|
return Platform.origin.download(data, filePath);
|
|
150
148
|
},
|
|
@@ -178,7 +176,7 @@ function useCanvas(_canvasType, app) {
|
|
|
178
176
|
});
|
|
179
177
|
});
|
|
180
178
|
},
|
|
181
|
-
loadImage(src) {
|
|
179
|
+
loadImage(src, _crossOrigin, _leaferImage) {
|
|
182
180
|
return new Promise((resolve, reject) => {
|
|
183
181
|
const img = Platform.canvas.view.createImage();
|
|
184
182
|
img.onload = () => {
|
|
@@ -190,6 +188,14 @@ function useCanvas(_canvasType, app) {
|
|
|
190
188
|
img.src = Platform.image.getRealURL(src);
|
|
191
189
|
});
|
|
192
190
|
},
|
|
191
|
+
loadContent(url, responseType = "text") {
|
|
192
|
+
return new Promise((resolve, reject) => app.request({
|
|
193
|
+
url: url,
|
|
194
|
+
responseType: responseType === "arrayBuffer" ? "arraybuffer" : "text",
|
|
195
|
+
success: res => resolve(responseType === "json" && typeof res.data === "string" ? JSON.parse(res.data) : res.data),
|
|
196
|
+
fail: reject
|
|
197
|
+
}));
|
|
198
|
+
},
|
|
193
199
|
noRepeat: "repeat-x"
|
|
194
200
|
};
|
|
195
201
|
Platform.miniapp = {
|
|
@@ -741,7 +747,7 @@ class Renderer {
|
|
|
741
747
|
getCellList() {
|
|
742
748
|
return undefined;
|
|
743
749
|
}
|
|
744
|
-
addBlock(block) {
|
|
750
|
+
addBlock(block, _leafList) {
|
|
745
751
|
if (!this.updateBlocks) this.updateBlocks = [];
|
|
746
752
|
this.updateBlocks.push(block);
|
|
747
753
|
}
|
|
@@ -789,7 +795,8 @@ class Renderer {
|
|
|
789
795
|
__onLayoutEnd(event) {
|
|
790
796
|
if (event.data) event.data.map(item => {
|
|
791
797
|
let empty;
|
|
792
|
-
|
|
798
|
+
const {updatedList: updatedList} = item;
|
|
799
|
+
if (updatedList) updatedList.list.some(leaf => {
|
|
793
800
|
empty = !leaf.__world.width || !leaf.__world.height;
|
|
794
801
|
if (empty) {
|
|
795
802
|
if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
|
|
@@ -797,7 +804,7 @@ class Renderer {
|
|
|
797
804
|
}
|
|
798
805
|
return empty;
|
|
799
806
|
});
|
|
800
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
807
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds, updatedList);
|
|
801
808
|
});
|
|
802
809
|
}
|
|
803
810
|
emitRender(type, bounds, options) {
|
|
@@ -1003,7 +1010,7 @@ class Selector {
|
|
|
1003
1010
|
this.config = {};
|
|
1004
1011
|
if (userConfig) this.config = DataHelper.default(userConfig, this.config);
|
|
1005
1012
|
this.picker = new Picker(this.target = target, this);
|
|
1006
|
-
this.finder = Creator.finder && Creator.finder();
|
|
1013
|
+
this.finder = Creator.finder && Creator.finder(target, this.config);
|
|
1007
1014
|
}
|
|
1008
1015
|
getByPoint(hitPoint, hitRadius, options) {
|
|
1009
1016
|
const {target: target, picker: picker} = this;
|
|
@@ -1174,8 +1181,8 @@ function fills(fills, ui, canvas, renderOptions) {
|
|
|
1174
1181
|
canvas.save();
|
|
1175
1182
|
if (item.transform) canvas.transform(item.transform);
|
|
1176
1183
|
if (originPaint.scaleFixed) {
|
|
1177
|
-
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
|
|
1178
|
-
if (
|
|
1184
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, originPaint.scaleFixed, false);
|
|
1185
|
+
if (scaleX !== 1) canvas.scale(scaleX, scaleY);
|
|
1179
1186
|
}
|
|
1180
1187
|
if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
|
|
1181
1188
|
fillPathOrText(ui, canvas, renderOptions);
|
|
@@ -1449,11 +1456,14 @@ function compute(attrName, ui) {
|
|
|
1449
1456
|
function getLeafPaint(attrName, paint, ui) {
|
|
1450
1457
|
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
1451
1458
|
let leafPaint;
|
|
1452
|
-
const {boxBounds: boxBounds} = ui.__layout;
|
|
1453
|
-
switch (
|
|
1459
|
+
const {boxBounds: boxBounds} = ui.__layout, {type: type} = paint;
|
|
1460
|
+
switch (type) {
|
|
1454
1461
|
case "image":
|
|
1462
|
+
case "film":
|
|
1463
|
+
case "video":
|
|
1455
1464
|
if (!paint.url) return undefined;
|
|
1456
1465
|
leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
1466
|
+
if (type !== "image") PaintImage[type](leafPaint);
|
|
1457
1467
|
break;
|
|
1458
1468
|
|
|
1459
1469
|
case "linear":
|
|
@@ -1469,7 +1479,7 @@ function getLeafPaint(attrName, paint, ui) {
|
|
|
1469
1479
|
break;
|
|
1470
1480
|
|
|
1471
1481
|
case "solid":
|
|
1472
|
-
const {
|
|
1482
|
+
const {color: color, opacity: opacity} = paint;
|
|
1473
1483
|
leafPaint = {
|
|
1474
1484
|
type: type,
|
|
1475
1485
|
style: ColorConvert.string(color, opacity)
|
|
@@ -1513,7 +1523,7 @@ const {isSame: isSame} = BoundsHelper;
|
|
|
1513
1523
|
|
|
1514
1524
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1515
1525
|
let leafPaint, event;
|
|
1516
|
-
const image = ImageManager.get(paint);
|
|
1526
|
+
const image = ImageManager.get(paint, paint.type);
|
|
1517
1527
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1518
1528
|
leafPaint = cache.leafPaint;
|
|
1519
1529
|
} else {
|
|
@@ -1574,8 +1584,8 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1574
1584
|
}
|
|
1575
1585
|
|
|
1576
1586
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1577
|
-
|
|
1578
|
-
|
|
1587
|
+
const data = ui.__;
|
|
1588
|
+
if (attrName === "fill" && !data.__naturalWidth) {
|
|
1579
1589
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1580
1590
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1581
1591
|
if (data.__autoSide) {
|
|
@@ -1587,7 +1597,13 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
|
|
|
1587
1597
|
return false;
|
|
1588
1598
|
}
|
|
1589
1599
|
}
|
|
1590
|
-
if (!leafPaint.data)
|
|
1600
|
+
if (!leafPaint.data) {
|
|
1601
|
+
PaintImage.createData(leafPaint, image, paint, boxBounds);
|
|
1602
|
+
const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
|
|
1603
|
+
const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
|
|
1604
|
+
if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
|
|
1605
|
+
}
|
|
1606
|
+
if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
|
|
1591
1607
|
return true;
|
|
1592
1608
|
}
|
|
1593
1609
|
|
|
@@ -1630,7 +1646,7 @@ function getPatternData(paint, box, image) {
|
|
|
1630
1646
|
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1631
1647
|
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1632
1648
|
const {width: width, height: height} = image;
|
|
1633
|
-
const {
|
|
1649
|
+
const {mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, interlace: interlace} = paint;
|
|
1634
1650
|
const sameBox = box.width === width && box.height === height;
|
|
1635
1651
|
const data = {
|
|
1636
1652
|
mode: mode
|
|
@@ -1693,8 +1709,6 @@ function getPatternData(paint, box, image) {
|
|
|
1693
1709
|
data.scaleX = scaleX;
|
|
1694
1710
|
data.scaleY = scaleY;
|
|
1695
1711
|
}
|
|
1696
|
-
if (opacity && opacity < 1) data.opacity = opacity;
|
|
1697
|
-
if (filters) data.filters = filters;
|
|
1698
1712
|
if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1699
1713
|
if (interlace) data.interlace = isNumber(interlace) || interlace.type === "percent" ? {
|
|
1700
1714
|
type: "x",
|
|
@@ -1725,7 +1739,7 @@ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translat
|
|
|
1725
1739
|
|
|
1726
1740
|
function stretchMode(data, box, scaleX, scaleY) {
|
|
1727
1741
|
const transform = get$2(), {x: x, y: y} = box;
|
|
1728
|
-
if (x || y) translate(transform, x, y); else transform.onlyScale = true;
|
|
1742
|
+
if (x || y) translate(transform, x, y); else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true;
|
|
1729
1743
|
scaleHelper(transform, scaleX, scaleY);
|
|
1730
1744
|
data.transform = transform;
|
|
1731
1745
|
}
|
|
@@ -1847,10 +1861,10 @@ function createPatternTask(paint, ui, canvas, renderOptions) {
|
|
|
1847
1861
|
}
|
|
1848
1862
|
|
|
1849
1863
|
function createPattern(paint, ui, canvas, renderOptions) {
|
|
1850
|
-
let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
|
|
1864
|
+
let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1851
1865
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1852
1866
|
if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
|
|
1853
|
-
const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1867
|
+
const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
|
|
1854
1868
|
let imageMatrix, xGap, yGap, {width: width, height: height} = image;
|
|
1855
1869
|
if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
|
|
1856
1870
|
width *= scaleX;
|
|
@@ -1866,7 +1880,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
|
|
|
1866
1880
|
if (transform) copy$1(imageMatrix, transform);
|
|
1867
1881
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1868
1882
|
}
|
|
1869
|
-
const imageCanvas = image.getCanvas(width, height,
|
|
1883
|
+
const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
|
|
1870
1884
|
const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1871
1885
|
paint.style = pattern;
|
|
1872
1886
|
paint.patternId = id;
|
|
@@ -1887,15 +1901,15 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
|
|
|
1887
1901
|
}
|
|
1888
1902
|
|
|
1889
1903
|
function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
1890
|
-
const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
|
|
1904
|
+
const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
|
|
1891
1905
|
const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
|
|
1892
|
-
if (!data || paint.patternId ===
|
|
1906
|
+
if (!data || paint.patternId === id && !exporting || snapshot) {
|
|
1893
1907
|
return false;
|
|
1894
1908
|
} else {
|
|
1895
1909
|
if (drawImage) {
|
|
1896
1910
|
if (data.repeat) {
|
|
1897
1911
|
drawImage = false;
|
|
1898
|
-
} else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
|
|
1912
|
+
} else if (!(originPaint.changeful || paint.film || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
|
|
1899
1913
|
drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096;
|
|
1900
1914
|
}
|
|
1901
1915
|
}
|
|
@@ -1913,20 +1927,21 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
|
|
|
1913
1927
|
}
|
|
1914
1928
|
}
|
|
1915
1929
|
|
|
1916
|
-
function drawImage(paint,
|
|
1917
|
-
const {data: data, image: image
|
|
1918
|
-
let {width: width, height: height} = image
|
|
1919
|
-
if (
|
|
1930
|
+
function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
|
|
1931
|
+
const {data: data, image: image, complex: complex} = paint;
|
|
1932
|
+
let {width: width, height: height} = image;
|
|
1933
|
+
if (complex) {
|
|
1934
|
+
const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
|
|
1920
1935
|
canvas.save();
|
|
1921
|
-
|
|
1936
|
+
complex === 2 && canvas.clipUI(ui);
|
|
1922
1937
|
blendMode && (canvas.blendMode = blendMode);
|
|
1923
1938
|
opacity && (canvas.opacity *= opacity);
|
|
1924
1939
|
transform && canvas.transform(transform);
|
|
1925
|
-
|
|
1940
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1926
1941
|
canvas.restore();
|
|
1927
1942
|
} else {
|
|
1928
1943
|
if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
|
|
1929
|
-
|
|
1944
|
+
image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
|
|
1930
1945
|
}
|
|
1931
1946
|
}
|
|
1932
1947
|
|
|
@@ -1956,6 +1971,7 @@ function recycleImage(attrName, data) {
|
|
|
1956
1971
|
if (!recycleMap) recycleMap = {};
|
|
1957
1972
|
recycleMap[url] = true;
|
|
1958
1973
|
ImageManager.recyclePaint(paint);
|
|
1974
|
+
if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
|
|
1959
1975
|
if (image.loading) {
|
|
1960
1976
|
if (!input) {
|
|
1961
1977
|
input = data.__input && data.__input[attrName] || [];
|