@leafer-ui/miniapp 1.0.0 → 1.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/miniapp.cjs +2941 -0
- package/dist/miniapp.esm.js +203 -190
- package/dist/miniapp.esm.min.js +1 -1
- package/dist/miniapp.min.cjs +1 -0
- package/dist/miniapp.module.js +429 -297
- package/dist/miniapp.module.min.js +1 -1
- package/package.json +18 -10
- package/src/index.ts +6 -1
package/dist/miniapp.esm.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, Answer, MatrixHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
1
|
+
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, Creator, LeaferImage, defineKey, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, Answer, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
|
-
import { InteractionHelper, InteractionBase, HitCanvasManager
|
|
4
|
+
import { InteractionHelper, InteractionBase, HitCanvasManager } from '@leafer-ui/core';
|
|
5
5
|
export * from '@leafer-ui/core';
|
|
6
|
-
import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect } from '@leafer-ui/draw';
|
|
6
|
+
import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect, Leafer } from '@leafer-ui/draw';
|
|
7
7
|
|
|
8
8
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
9
9
|
get allowBackgroundColor() { return false; }
|
|
10
10
|
init() {
|
|
11
|
-
|
|
11
|
+
const { config } = this;
|
|
12
|
+
let view = config.view || config.canvas;
|
|
12
13
|
if (view) {
|
|
13
14
|
if (typeof view === 'string') {
|
|
14
15
|
if (view[0] !== '#')
|
|
@@ -38,16 +39,20 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
38
39
|
else {
|
|
39
40
|
this.view = view.view || view;
|
|
40
41
|
}
|
|
41
|
-
this.__createContext();
|
|
42
|
+
this.view.getContext ? this.__createContext() : this.unrealCanvas();
|
|
42
43
|
const { width, height, pixelRatio } = this.config;
|
|
43
44
|
const size = { width: width || view.width, height: height || view.height, pixelRatio };
|
|
44
45
|
this.resize(size);
|
|
45
|
-
if (this.context
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if (this.context) {
|
|
47
|
+
if (this.viewSelect)
|
|
48
|
+
Platform.renderCanvas = this;
|
|
49
|
+
if (this.context.roundRect) {
|
|
50
|
+
this.roundRect = function (x, y, width, height, radius) {
|
|
51
|
+
this.context.roundRect(x, y, width, height, typeof radius === 'number' ? [radius] : radius);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
canvasPatch(this.context.__proto__);
|
|
49
55
|
}
|
|
50
|
-
canvasPatch(this.context.__proto__);
|
|
51
56
|
}
|
|
52
57
|
__createView() {
|
|
53
58
|
this.view = Platform.origin.createCanvas(1, 1);
|
|
@@ -65,10 +70,12 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
65
70
|
callback();
|
|
66
71
|
});
|
|
67
72
|
}
|
|
68
|
-
startAutoLayout(
|
|
73
|
+
startAutoLayout(autoBounds, listener) {
|
|
69
74
|
this.resizeListener = listener;
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
if (autoBounds) {
|
|
76
|
+
this.checkSize = this.checkSize.bind(this);
|
|
77
|
+
Platform.miniapp.onWindowResize(this.checkSize);
|
|
78
|
+
}
|
|
72
79
|
}
|
|
73
80
|
checkSize() {
|
|
74
81
|
if (this.viewSelect) {
|
|
@@ -77,13 +84,8 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
77
84
|
const { width, height } = this.clientBounds;
|
|
78
85
|
const { pixelRatio } = this;
|
|
79
86
|
const size = { width, height, pixelRatio };
|
|
80
|
-
if (!this.isSameSize(size))
|
|
81
|
-
|
|
82
|
-
DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
|
|
83
|
-
this.resize(size);
|
|
84
|
-
if (this.width !== undefined)
|
|
85
|
-
this.resizeListener(new ResizeEvent(size, oldSize));
|
|
86
|
-
}
|
|
87
|
+
if (!this.isSameSize(size))
|
|
88
|
+
this.emitResize(size);
|
|
87
89
|
});
|
|
88
90
|
}, 500);
|
|
89
91
|
}
|
|
@@ -93,6 +95,16 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
93
95
|
this.resizeListener = null;
|
|
94
96
|
Platform.miniapp.offWindowResize(this.checkSize);
|
|
95
97
|
}
|
|
98
|
+
unrealCanvas() {
|
|
99
|
+
this.unreal = true;
|
|
100
|
+
}
|
|
101
|
+
emitResize(size) {
|
|
102
|
+
const oldSize = {};
|
|
103
|
+
DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
|
|
104
|
+
this.resize(size);
|
|
105
|
+
if (this.width !== undefined)
|
|
106
|
+
this.resizeListener(new ResizeEvent(size, oldSize));
|
|
107
|
+
}
|
|
96
108
|
}
|
|
97
109
|
|
|
98
110
|
const { mineType, fileType } = FileHelper;
|
|
@@ -101,120 +113,121 @@ Object.assign(Creator, {
|
|
|
101
113
|
image: (options) => new LeaferImage(options)
|
|
102
114
|
});
|
|
103
115
|
function useCanvas(_canvasType, app) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
fs.unlink({ filePath });
|
|
130
|
-
resolve();
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
116
|
+
Platform.origin = {
|
|
117
|
+
createCanvas: (width, height, _format) => app.createOffscreenCanvas({ type: '2d', width, height }),
|
|
118
|
+
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
|
|
119
|
+
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
|
|
120
|
+
canvasSaveAs: (canvas, filePath, quality) => {
|
|
121
|
+
let data = canvas.toDataURL(mineType(fileType(filePath)), quality);
|
|
122
|
+
data = data.substring(data.indexOf('64,') + 3);
|
|
123
|
+
return Platform.origin.download(data, filePath);
|
|
124
|
+
},
|
|
125
|
+
download(data, filePath) {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
let toAlbum;
|
|
128
|
+
if (!filePath.includes('/')) {
|
|
129
|
+
filePath = `${app.env.USER_DATA_PATH}/` + filePath;
|
|
130
|
+
toAlbum = true;
|
|
131
|
+
}
|
|
132
|
+
const fs = app.getFileSystemManager();
|
|
133
|
+
fs.writeFile({
|
|
134
|
+
filePath,
|
|
135
|
+
data,
|
|
136
|
+
encoding: 'base64',
|
|
137
|
+
success() {
|
|
138
|
+
if (toAlbum) {
|
|
139
|
+
Platform.miniapp.saveToAlbum(filePath).then(() => {
|
|
140
|
+
fs.unlink({ filePath });
|
|
134
141
|
resolve();
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
fail(error) {
|
|
138
|
-
reject(error);
|
|
142
|
+
});
|
|
139
143
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
img.onerror = (error) => { reject(error); };
|
|
148
|
-
img.src = Platform.image.getRealURL(src);
|
|
144
|
+
else {
|
|
145
|
+
resolve();
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
fail(error) {
|
|
149
|
+
reject(error);
|
|
150
|
+
}
|
|
149
151
|
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
loadImage(src) {
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
const img = Platform.canvas.view.createImage();
|
|
157
|
+
img.onload = () => { resolve(img); };
|
|
158
|
+
img.onerror = (error) => { reject(error); };
|
|
159
|
+
img.src = Platform.image.getRealURL(src);
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
noRepeat: 'repeat-x'
|
|
163
|
+
};
|
|
164
|
+
Platform.miniapp = {
|
|
165
|
+
select(name) {
|
|
166
|
+
return app.createSelectorQuery().select(name);
|
|
167
|
+
},
|
|
168
|
+
getBounds(select) {
|
|
169
|
+
return new Promise((resolve) => {
|
|
170
|
+
select.boundingClientRect().exec((res) => {
|
|
171
|
+
const rect = res[1];
|
|
172
|
+
resolve({ x: rect.top, y: rect.left, width: rect.width, height: rect.height });
|
|
163
173
|
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
getSizeView(select) {
|
|
177
|
+
return new Promise((resolve) => {
|
|
178
|
+
select.fields({ node: true, size: true }).exec((res) => {
|
|
179
|
+
const data = res[0];
|
|
180
|
+
resolve({ view: data.node, width: data.width, height: data.height });
|
|
171
181
|
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
app.authorize({
|
|
185
|
-
scope: 'scope.writePhotosAlbum',
|
|
186
|
-
success: () => {
|
|
187
|
-
app.saveImageToPhotosAlbum({
|
|
188
|
-
filePath: path,
|
|
189
|
-
success() { resolve(true); }
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
fail: () => { }
|
|
193
|
-
});
|
|
194
|
-
}
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
saveToAlbum(path) {
|
|
185
|
+
return new Promise((resolve) => {
|
|
186
|
+
app.getSetting({
|
|
187
|
+
success: (res) => {
|
|
188
|
+
if (res.authSetting['scope.writePhotosAlbum']) {
|
|
189
|
+
app.saveImageToPhotosAlbum({
|
|
190
|
+
filePath: path,
|
|
191
|
+
success() { resolve(true); }
|
|
192
|
+
});
|
|
195
193
|
}
|
|
196
|
-
|
|
194
|
+
else {
|
|
195
|
+
app.authorize({
|
|
196
|
+
scope: 'scope.writePhotosAlbum',
|
|
197
|
+
success: () => {
|
|
198
|
+
app.saveImageToPhotosAlbum({
|
|
199
|
+
filePath: path,
|
|
200
|
+
success() { resolve(true); }
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
fail: () => { }
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
197
207
|
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
onWindowResize(fun) {
|
|
211
|
+
app.onWindowResize(fun);
|
|
212
|
+
},
|
|
213
|
+
offWindowResize(fun) {
|
|
214
|
+
app.offWindowResize(fun);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
Platform.event = {
|
|
218
|
+
stopDefault(_origin) { },
|
|
219
|
+
stopNow(_origin) { },
|
|
220
|
+
stop(_origin) { }
|
|
221
|
+
};
|
|
222
|
+
Platform.canvas = Creator.canvas();
|
|
223
|
+
Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient;
|
|
214
224
|
}
|
|
215
225
|
Platform.name = 'miniapp';
|
|
216
|
-
Platform.requestRender = function (render) {
|
|
217
|
-
Platform.
|
|
226
|
+
Platform.requestRender = function (render) {
|
|
227
|
+
const { view } = (Platform.renderCanvas || Platform.canvas);
|
|
228
|
+
view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16);
|
|
229
|
+
};
|
|
230
|
+
defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, wx.getSystemInfoSync().pixelRatio); } });
|
|
218
231
|
|
|
219
232
|
class Watcher {
|
|
220
233
|
get childrenChanged() { return this.hasAdd || this.hasRemove || this.hasVisible; }
|
|
@@ -692,14 +705,14 @@ class Renderer {
|
|
|
692
705
|
if (Debug.showRepaint)
|
|
693
706
|
this.canvas.strokeWorld(bounds, 'red');
|
|
694
707
|
this.target.__render(this.canvas, options);
|
|
695
|
-
this.renderBounds = realBounds || bounds;
|
|
708
|
+
this.renderBounds = realBounds = realBounds || bounds;
|
|
696
709
|
this.renderOptions = options;
|
|
697
|
-
this.totalBounds.isEmpty() ? this.totalBounds =
|
|
710
|
+
this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
|
|
698
711
|
if (Debug.showHitView)
|
|
699
712
|
this.renderHitView(options);
|
|
700
713
|
if (Debug.showBoundsView)
|
|
701
714
|
this.renderBoundsView(options);
|
|
702
|
-
this.canvas.updateRender();
|
|
715
|
+
this.canvas.updateRender(realBounds);
|
|
703
716
|
}
|
|
704
717
|
renderHitView(_options) { }
|
|
705
718
|
renderBoundsView(_options) { }
|
|
@@ -1071,7 +1084,7 @@ const PointerEventHelper = {
|
|
|
1071
1084
|
convertTouch(e, local) {
|
|
1072
1085
|
const touch = PointerEventHelper.getTouch(e);
|
|
1073
1086
|
const base = InteractionHelper.getBase(e);
|
|
1074
|
-
return Object.assign(Object.assign({}, base), { x: local.x, y: local.y, width: 1, height: 1, pointerType: 'touch', pressure: touch.force || 1 });
|
|
1087
|
+
return Object.assign(Object.assign({}, base), { x: local.x, y: local.y, width: 1, height: 1, pointerType: 'touch', multiTouch: e.touches.length > 1, pressure: touch.force || 1 });
|
|
1075
1088
|
},
|
|
1076
1089
|
getTouch(e) {
|
|
1077
1090
|
return e.touches[0] || e.changedTouches[0];
|
|
@@ -1131,7 +1144,7 @@ class Interaction extends InteractionBase {
|
|
|
1131
1144
|
this.pointerCancel();
|
|
1132
1145
|
}
|
|
1133
1146
|
multiTouchStart(e) {
|
|
1134
|
-
this.useMultiTouch = (e.touches.length
|
|
1147
|
+
this.useMultiTouch = (e.touches.length > 1);
|
|
1135
1148
|
this.touches = this.useMultiTouch ? this.getTouches(e.touches) : undefined;
|
|
1136
1149
|
if (this.useMultiTouch)
|
|
1137
1150
|
this.pointerCancel();
|
|
@@ -1523,10 +1536,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
|
|
|
1523
1536
|
const { get: get$2, translate } = MatrixHelper;
|
|
1524
1537
|
const tempBox = new Bounds();
|
|
1525
1538
|
const tempPoint = {};
|
|
1539
|
+
const tempScaleData = {};
|
|
1526
1540
|
function createData(leafPaint, image, paint, box) {
|
|
1527
|
-
const { blendMode } = paint;
|
|
1541
|
+
const { blendMode, sync } = paint;
|
|
1528
1542
|
if (blendMode)
|
|
1529
1543
|
leafPaint.blendMode = blendMode;
|
|
1544
|
+
if (sync)
|
|
1545
|
+
leafPaint.sync = sync;
|
|
1530
1546
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1531
1547
|
}
|
|
1532
1548
|
function getPatternData(paint, box, image) {
|
|
@@ -1546,13 +1562,10 @@ function getPatternData(paint, box, image) {
|
|
|
1546
1562
|
x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
|
|
1547
1563
|
}
|
|
1548
1564
|
}
|
|
1549
|
-
else if (size) {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
else if (scale) {
|
|
1554
|
-
scaleX = typeof scale === 'number' ? scale : scale.x;
|
|
1555
|
-
scaleY = typeof scale === 'number' ? scale : scale.y;
|
|
1565
|
+
else if (scale || size) {
|
|
1566
|
+
MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1567
|
+
scaleX = tempScaleData.scaleX;
|
|
1568
|
+
scaleY = tempScaleData.scaleY;
|
|
1556
1569
|
}
|
|
1557
1570
|
if (align) {
|
|
1558
1571
|
const imageBounds = { x, y, width: swapWidth, height: swapHeight };
|
|
@@ -1789,7 +1802,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1789
1802
|
const { abs } = Math;
|
|
1790
1803
|
function checkImage(ui, canvas, paint, allowPaint) {
|
|
1791
1804
|
const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
|
|
1792
|
-
if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
|
|
1805
|
+
if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
|
|
1793
1806
|
return false;
|
|
1794
1807
|
}
|
|
1795
1808
|
else {
|
|
@@ -1823,7 +1836,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1823
1836
|
return true;
|
|
1824
1837
|
}
|
|
1825
1838
|
else {
|
|
1826
|
-
if (!paint.style || Export.running) {
|
|
1839
|
+
if (!paint.style || paint.sync || Export.running) {
|
|
1827
1840
|
createPattern(ui, paint, canvas.pixelRatio);
|
|
1828
1841
|
}
|
|
1829
1842
|
else {
|
|
@@ -2693,6 +2706,7 @@ const ExportModule = {
|
|
|
2693
2706
|
export(leaf, filename, options) {
|
|
2694
2707
|
this.running = true;
|
|
2695
2708
|
const fileType = FileHelper.fileType(filename);
|
|
2709
|
+
const isDownload = filename.includes('.');
|
|
2696
2710
|
options = FileHelper.getExportOptions(options);
|
|
2697
2711
|
return addTask((success) => new Promise((resolve) => {
|
|
2698
2712
|
const over = (result) => {
|
|
@@ -2702,19 +2716,13 @@ const ExportModule = {
|
|
|
2702
2716
|
};
|
|
2703
2717
|
const { toURL } = Platform;
|
|
2704
2718
|
const { download } = Platform.origin;
|
|
2705
|
-
if (
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
else if (fileType === 'json') {
|
|
2709
|
-
download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2710
|
-
return over({ data: true });
|
|
2719
|
+
if (fileType === 'json') {
|
|
2720
|
+
isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
|
|
2721
|
+
return over({ data: isDownload ? true : leaf.toJSON(options.json) });
|
|
2711
2722
|
}
|
|
2712
|
-
if (
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
else if (fileType === 'svg') {
|
|
2716
|
-
download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2717
|
-
return over({ data: true });
|
|
2723
|
+
if (fileType === 'svg') {
|
|
2724
|
+
isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
|
|
2725
|
+
return over({ data: isDownload ? true : leaf.toSVG() });
|
|
2718
2726
|
}
|
|
2719
2727
|
const { leafer } = leaf;
|
|
2720
2728
|
if (leafer) {
|
|
@@ -2723,14 +2731,8 @@ const ExportModule = {
|
|
|
2723
2731
|
let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
|
|
2724
2732
|
const { worldTransform, isLeafer, isFrame } = leaf;
|
|
2725
2733
|
const { slice, trim, onCanvas } = options;
|
|
2726
|
-
let scale = options.scale || 1;
|
|
2727
|
-
let pixelRatio = options.pixelRatio || 1;
|
|
2728
2734
|
const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
|
|
2729
2735
|
const contextSettings = options.contextSettings || leafer.config.contextSettings;
|
|
2730
|
-
if (leaf.isApp) {
|
|
2731
|
-
scale *= pixelRatio;
|
|
2732
|
-
pixelRatio = leaf.app.pixelRatio;
|
|
2733
|
-
}
|
|
2734
2736
|
const screenshot = options.screenshot || leaf.isApp;
|
|
2735
2737
|
const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
|
|
2736
2738
|
const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
|
|
@@ -2764,10 +2766,21 @@ const ExportModule = {
|
|
|
2764
2766
|
}
|
|
2765
2767
|
renderBounds = leaf.getBounds('render', relative);
|
|
2766
2768
|
}
|
|
2767
|
-
const {
|
|
2769
|
+
const scaleData = { scaleX: 1, scaleY: 1 };
|
|
2770
|
+
MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
|
|
2771
|
+
let pixelRatio = options.pixelRatio || 1;
|
|
2772
|
+
if (leaf.isApp) {
|
|
2773
|
+
scaleData.scaleX *= pixelRatio;
|
|
2774
|
+
scaleData.scaleY *= pixelRatio;
|
|
2775
|
+
pixelRatio = leaf.app.pixelRatio;
|
|
2776
|
+
}
|
|
2777
|
+
const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
|
|
2778
|
+
const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
|
|
2768
2779
|
let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
|
|
2769
|
-
|
|
2780
|
+
let sliceLeaf;
|
|
2770
2781
|
if (slice) {
|
|
2782
|
+
sliceLeaf = leaf;
|
|
2783
|
+
sliceLeaf.__worldOpacity = 0;
|
|
2771
2784
|
leaf = leafer;
|
|
2772
2785
|
renderOptions.bounds = canvas.bounds;
|
|
2773
2786
|
}
|
|
@@ -2782,6 +2795,8 @@ const ExportModule = {
|
|
|
2782
2795
|
leaf.__render(canvas, renderOptions);
|
|
2783
2796
|
}
|
|
2784
2797
|
canvas.restore();
|
|
2798
|
+
if (sliceLeaf)
|
|
2799
|
+
sliceLeaf.__updateWorldOpacity();
|
|
2785
2800
|
if (trim) {
|
|
2786
2801
|
trimBounds = getTrimBounds(canvas);
|
|
2787
2802
|
const old = canvas, { width, height } = trimBounds;
|
|
@@ -2869,39 +2884,37 @@ Object.assign(Creator, {
|
|
|
2869
2884
|
hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
2870
2885
|
hitCanvasManager: () => new HitCanvasManager()
|
|
2871
2886
|
});
|
|
2887
|
+
Leafer.prototype.receiveEvent = function (event) {
|
|
2888
|
+
this.interaction && this.interaction.receive(event);
|
|
2889
|
+
};
|
|
2872
2890
|
try {
|
|
2873
|
-
|
|
2891
|
+
if (wx)
|
|
2892
|
+
useCanvas('miniapp', wx);
|
|
2874
2893
|
}
|
|
2875
2894
|
catch (_a) { }
|
|
2876
2895
|
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
this.
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
}
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
view.height = height * pixelRatio;
|
|
2901
|
-
if (testView) {
|
|
2902
|
-
testView.width = view.width;
|
|
2903
|
-
testView.height = view.height;
|
|
2904
|
-
}
|
|
2905
|
-
};
|
|
2896
|
+
const systemInfo = wx.getSystemInfoSync();
|
|
2897
|
+
const platform = systemInfo.platform;
|
|
2898
|
+
if (platform === 'ios') {
|
|
2899
|
+
LeaferImage.prototype.getPattern = function (canvas, repeat, transform, paint) {
|
|
2900
|
+
const pattern = Platform.canvas.createPattern(this.view, repeat);
|
|
2901
|
+
const { width, height } = canvas;
|
|
2902
|
+
if (this.width !== width || this.height !== height) {
|
|
2903
|
+
if (!transform)
|
|
2904
|
+
transform = MatrixHelper.get();
|
|
2905
|
+
MatrixHelper.scale(transform, width / this.width, height / this.height);
|
|
2906
|
+
}
|
|
2907
|
+
try {
|
|
2908
|
+
if (transform && pattern.setTransform) {
|
|
2909
|
+
pattern.setTransform(transform);
|
|
2910
|
+
transform = null;
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
catch (_a) { }
|
|
2914
|
+
if (paint)
|
|
2915
|
+
paint.transform = transform;
|
|
2916
|
+
return pattern;
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2906
2919
|
|
|
2907
2920
|
export { Interaction, Layouter, LeaferCanvas, Renderer, Selector, Watcher, useCanvas };
|