@leafer-ui/miniapp 1.7.0 → 1.9.0
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 +1227 -1090
- package/dist/miniapp.esm.js +1209 -1085
- 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 +5714 -5144
- package/dist/miniapp.module.min.js +1 -1
- package/dist/miniapp.module.min.js.map +1 -1
- package/package.json +12 -12
- package/src/core.ts +1 -1
package/dist/miniapp.esm.js
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { LeaferCanvasBase, Platform, canvasPatch, DataHelper, canvasSizeAttrs, ResizeEvent, FileHelper, Creator, LeaferImage, defineKey, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, BoundsHelper, Plugin, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4 } from
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
1
|
+
import { LeaferCanvasBase, isString, Platform, isNumber, canvasPatch, DataHelper, canvasSizeAttrs, isUndefined, ResizeEvent, FileHelper, Creator, LeaferImage, defineKey, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, BoundsHelper, Plugin, isObject, Matrix, getMatrixData, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4 } from "@leafer/core";
|
|
2
|
+
|
|
3
|
+
export * from "@leafer/core";
|
|
4
|
+
|
|
5
|
+
export { LeaferImage } from "@leafer/core";
|
|
6
|
+
|
|
7
|
+
import { InteractionHelper, InteractionBase, isUndefined as isUndefined$1, HitCanvasManager } from "@leafer-ui/core";
|
|
8
|
+
|
|
9
|
+
export * from "@leafer-ui/core";
|
|
10
|
+
|
|
11
|
+
import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Group, TextConvert, Effect, Leafer } from "@leafer-ui/draw";
|
|
7
12
|
|
|
8
13
|
class LeaferCanvas extends LeaferCanvasBase {
|
|
9
|
-
get allowBackgroundColor() {
|
|
14
|
+
get allowBackgroundColor() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
10
17
|
init() {
|
|
11
|
-
const { config
|
|
18
|
+
const {config: config} = this;
|
|
12
19
|
let view = config.view || config.canvas;
|
|
13
20
|
if (view) {
|
|
14
|
-
if (
|
|
15
|
-
if (view[0] !==
|
|
16
|
-
view = '#' + view;
|
|
21
|
+
if (isString(view)) {
|
|
22
|
+
if (view[0] !== "#") view = "#" + view;
|
|
17
23
|
this.viewSelect = Platform.miniapp.select(view);
|
|
18
|
-
}
|
|
19
|
-
else if (view.fields) {
|
|
24
|
+
} else if (view.fields) {
|
|
20
25
|
this.viewSelect = view;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
26
|
+
} else {
|
|
23
27
|
this.initView(view);
|
|
24
28
|
}
|
|
25
|
-
if (this.viewSelect)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
29
|
+
if (this.viewSelect) Platform.miniapp.getSizeView(this.viewSelect).then(sizeView => {
|
|
30
|
+
this.initView(sizeView);
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
31
33
|
this.initView();
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -35,20 +37,22 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
35
37
|
if (!view) {
|
|
36
38
|
view = {};
|
|
37
39
|
this.__createView();
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
+
} else {
|
|
40
41
|
this.view = view.view || view;
|
|
41
42
|
}
|
|
42
43
|
this.view.getContext ? this.__createContext() : this.unrealCanvas();
|
|
43
|
-
const { width, height, pixelRatio } = this.config;
|
|
44
|
-
const size = {
|
|
44
|
+
const {width: width, height: height, pixelRatio: pixelRatio} = this.config;
|
|
45
|
+
const size = {
|
|
46
|
+
width: width || view.width,
|
|
47
|
+
height: height || view.height,
|
|
48
|
+
pixelRatio: pixelRatio
|
|
49
|
+
};
|
|
45
50
|
this.resize(size);
|
|
46
51
|
if (this.context) {
|
|
47
|
-
if (this.viewSelect)
|
|
48
|
-
Platform.renderCanvas = this;
|
|
52
|
+
if (this.viewSelect) Platform.renderCanvas = this;
|
|
49
53
|
if (this.context.roundRect) {
|
|
50
|
-
this.roundRect = function
|
|
51
|
-
this.context.roundRect(x, y, width, height,
|
|
54
|
+
this.roundRect = function(x, y, width, height, radius) {
|
|
55
|
+
this.context.roundRect(x, y, width, height, isNumber(radius) ? [ radius ] : radius);
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
58
|
canvasPatch(this.context.__proto__);
|
|
@@ -58,17 +62,15 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
58
62
|
this.view = Platform.origin.createCanvas(1, 1);
|
|
59
63
|
}
|
|
60
64
|
updateViewSize() {
|
|
61
|
-
const { width, height, pixelRatio } = this;
|
|
65
|
+
const {width: width, height: height, pixelRatio: pixelRatio} = this;
|
|
62
66
|
this.view.width = Math.ceil(width * pixelRatio);
|
|
63
67
|
this.view.height = Math.ceil(height * pixelRatio);
|
|
64
68
|
}
|
|
65
69
|
updateClientBounds(callback) {
|
|
66
|
-
if (this.viewSelect)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
callback();
|
|
71
|
-
});
|
|
70
|
+
if (this.viewSelect) Platform.miniapp.getBounds(this.viewSelect).then(bounds => {
|
|
71
|
+
this.clientBounds = bounds;
|
|
72
|
+
if (callback) callback();
|
|
73
|
+
});
|
|
72
74
|
}
|
|
73
75
|
startAutoLayout(autoBounds, listener) {
|
|
74
76
|
this.resizeListener = listener;
|
|
@@ -81,11 +83,14 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
81
83
|
if (this.viewSelect) {
|
|
82
84
|
setTimeout(() => {
|
|
83
85
|
this.updateClientBounds(() => {
|
|
84
|
-
const { width, height } = this.clientBounds;
|
|
85
|
-
const { pixelRatio
|
|
86
|
-
const size = {
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
const {width: width, height: height} = this.clientBounds;
|
|
87
|
+
const {pixelRatio: pixelRatio} = this;
|
|
88
|
+
const size = {
|
|
89
|
+
width: width,
|
|
90
|
+
height: height,
|
|
91
|
+
pixelRatio: pixelRatio
|
|
92
|
+
};
|
|
93
|
+
if (!this.isSameSize(size)) this.emitResize(size);
|
|
89
94
|
});
|
|
90
95
|
}, 500);
|
|
91
96
|
}
|
|
@@ -102,49 +107,57 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
102
107
|
const oldSize = {};
|
|
103
108
|
DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
|
|
104
109
|
this.resize(size);
|
|
105
|
-
if (this.width
|
|
106
|
-
this.resizeListener(new ResizeEvent(size, oldSize));
|
|
110
|
+
if (!isUndefined(this.width)) this.resizeListener(new ResizeEvent(size, oldSize));
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
const { mineType, fileType } = FileHelper;
|
|
114
|
+
const {mineType: mineType, fileType: fileType} = FileHelper;
|
|
115
|
+
|
|
111
116
|
Object.assign(Creator, {
|
|
112
117
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
113
|
-
image:
|
|
118
|
+
image: options => new LeaferImage(options)
|
|
114
119
|
});
|
|
120
|
+
|
|
115
121
|
function useCanvas(_canvasType, app) {
|
|
116
122
|
Platform.origin = {
|
|
117
123
|
createCanvas: (width, height, _format) => {
|
|
118
|
-
const data = {
|
|
124
|
+
const data = {
|
|
125
|
+
type: "2d",
|
|
126
|
+
width: width,
|
|
127
|
+
height: height
|
|
128
|
+
};
|
|
119
129
|
return app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data);
|
|
120
130
|
},
|
|
121
131
|
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
|
|
122
|
-
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, {
|
|
132
|
+
canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, {
|
|
133
|
+
quality: quality
|
|
134
|
+
}),
|
|
123
135
|
canvasSaveAs: (canvas, filePath, quality) => {
|
|
124
136
|
let data = canvas.toDataURL(mineType(fileType(filePath)), quality);
|
|
125
|
-
data = data.substring(data.indexOf(
|
|
137
|
+
data = data.substring(data.indexOf("64,") + 3);
|
|
126
138
|
return Platform.origin.download(data, filePath);
|
|
127
139
|
},
|
|
128
140
|
download(data, filePath) {
|
|
129
141
|
return new Promise((resolve, reject) => {
|
|
130
142
|
let toAlbum;
|
|
131
|
-
if (!filePath.includes(
|
|
143
|
+
if (!filePath.includes("/")) {
|
|
132
144
|
filePath = `${app.env.USER_DATA_PATH}/` + filePath;
|
|
133
145
|
toAlbum = true;
|
|
134
146
|
}
|
|
135
147
|
const fs = app.getFileSystemManager();
|
|
136
148
|
fs.writeFile({
|
|
137
|
-
filePath,
|
|
138
|
-
data,
|
|
139
|
-
encoding:
|
|
149
|
+
filePath: filePath,
|
|
150
|
+
data: data,
|
|
151
|
+
encoding: "base64",
|
|
140
152
|
success() {
|
|
141
153
|
if (toAlbum) {
|
|
142
154
|
Platform.miniapp.saveToAlbum(filePath).then(() => {
|
|
143
|
-
fs.unlink({
|
|
155
|
+
fs.unlink({
|
|
156
|
+
filePath: filePath
|
|
157
|
+
});
|
|
144
158
|
resolve();
|
|
145
159
|
});
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
160
|
+
} else {
|
|
148
161
|
resolve();
|
|
149
162
|
}
|
|
150
163
|
},
|
|
@@ -157,53 +170,72 @@ function useCanvas(_canvasType, app) {
|
|
|
157
170
|
loadImage(src) {
|
|
158
171
|
return new Promise((resolve, reject) => {
|
|
159
172
|
const img = Platform.canvas.view.createImage();
|
|
160
|
-
img.onload = () => {
|
|
161
|
-
|
|
173
|
+
img.onload = () => {
|
|
174
|
+
resolve(img);
|
|
175
|
+
};
|
|
176
|
+
img.onerror = error => {
|
|
177
|
+
reject(error);
|
|
178
|
+
};
|
|
162
179
|
img.src = Platform.image.getRealURL(src);
|
|
163
180
|
});
|
|
164
181
|
},
|
|
165
|
-
noRepeat:
|
|
182
|
+
noRepeat: "repeat-x"
|
|
166
183
|
};
|
|
167
184
|
Platform.miniapp = {
|
|
168
185
|
select(name) {
|
|
169
186
|
return app.createSelectorQuery().select(name);
|
|
170
187
|
},
|
|
171
188
|
getBounds(select) {
|
|
172
|
-
return new Promise(
|
|
173
|
-
select.boundingClientRect().exec(
|
|
189
|
+
return new Promise(resolve => {
|
|
190
|
+
select.boundingClientRect().exec(res => {
|
|
174
191
|
const rect = res[1];
|
|
175
|
-
resolve({
|
|
192
|
+
resolve({
|
|
193
|
+
x: rect.top,
|
|
194
|
+
y: rect.left,
|
|
195
|
+
width: rect.width,
|
|
196
|
+
height: rect.height
|
|
197
|
+
});
|
|
176
198
|
});
|
|
177
199
|
});
|
|
178
200
|
},
|
|
179
201
|
getSizeView(select) {
|
|
180
|
-
return new Promise(
|
|
181
|
-
select.fields({
|
|
202
|
+
return new Promise(resolve => {
|
|
203
|
+
select.fields({
|
|
204
|
+
node: true,
|
|
205
|
+
size: true
|
|
206
|
+
}).exec(res => {
|
|
182
207
|
const data = res[0];
|
|
183
|
-
resolve({
|
|
208
|
+
resolve({
|
|
209
|
+
view: data.node,
|
|
210
|
+
width: data.width,
|
|
211
|
+
height: data.height
|
|
212
|
+
});
|
|
184
213
|
});
|
|
185
214
|
});
|
|
186
215
|
},
|
|
187
216
|
saveToAlbum(path) {
|
|
188
|
-
return new Promise(
|
|
217
|
+
return new Promise(resolve => {
|
|
189
218
|
app.getSetting({
|
|
190
|
-
success:
|
|
191
|
-
if (res.authSetting[
|
|
219
|
+
success: res => {
|
|
220
|
+
if (res.authSetting["scope.writePhotosAlbum"]) {
|
|
192
221
|
app.saveImageToPhotosAlbum({
|
|
193
222
|
filePath: path,
|
|
194
|
-
success() {
|
|
223
|
+
success() {
|
|
224
|
+
resolve(true);
|
|
225
|
+
}
|
|
195
226
|
});
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
227
|
+
} else {
|
|
198
228
|
app.authorize({
|
|
199
|
-
scope:
|
|
229
|
+
scope: "scope.writePhotosAlbum",
|
|
200
230
|
success: () => {
|
|
201
231
|
app.saveImageToPhotosAlbum({
|
|
202
232
|
filePath: path,
|
|
203
|
-
success() {
|
|
233
|
+
success() {
|
|
234
|
+
resolve(true);
|
|
235
|
+
}
|
|
204
236
|
});
|
|
205
237
|
},
|
|
206
|
-
fail: () => {
|
|
238
|
+
fail: () => {}
|
|
207
239
|
});
|
|
208
240
|
}
|
|
209
241
|
}
|
|
@@ -218,45 +250,52 @@ function useCanvas(_canvasType, app) {
|
|
|
218
250
|
}
|
|
219
251
|
};
|
|
220
252
|
Platform.event = {
|
|
221
|
-
stopDefault(_origin) {
|
|
222
|
-
stopNow(_origin) {
|
|
223
|
-
stop(_origin) {
|
|
253
|
+
stopDefault(_origin) {},
|
|
254
|
+
stopNow(_origin) {},
|
|
255
|
+
stop(_origin) {}
|
|
224
256
|
};
|
|
225
257
|
Platform.canvas = Creator.canvas();
|
|
226
258
|
Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient;
|
|
227
259
|
}
|
|
228
|
-
|
|
229
|
-
Platform.
|
|
230
|
-
|
|
260
|
+
|
|
261
|
+
Platform.name = "miniapp";
|
|
262
|
+
|
|
263
|
+
Platform.requestRender = function(render) {
|
|
264
|
+
const {view: view} = Platform.renderCanvas || Platform.canvas;
|
|
231
265
|
view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16);
|
|
232
266
|
};
|
|
233
|
-
|
|
267
|
+
|
|
268
|
+
defineKey(Platform, "devicePixelRatio", {
|
|
269
|
+
get() {
|
|
270
|
+
return Math.max(1, wx.getWindowInfo ? wx.getWindowInfo().pixelRatio : wx.getSystemInfoSync().pixelRatio);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
234
273
|
|
|
235
274
|
class Watcher {
|
|
236
|
-
get childrenChanged() {
|
|
275
|
+
get childrenChanged() {
|
|
276
|
+
return this.hasAdd || this.hasRemove || this.hasVisible;
|
|
277
|
+
}
|
|
237
278
|
get updatedList() {
|
|
238
279
|
if (this.hasRemove) {
|
|
239
|
-
const updatedList = new LeafList
|
|
240
|
-
this.__updatedList.list.forEach(item => {
|
|
241
|
-
updatedList.add(item);
|
|
280
|
+
const updatedList = new LeafList;
|
|
281
|
+
this.__updatedList.list.forEach(item => {
|
|
282
|
+
if (item.leafer) updatedList.add(item);
|
|
283
|
+
});
|
|
242
284
|
return updatedList;
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
285
|
+
} else {
|
|
245
286
|
return this.__updatedList;
|
|
246
287
|
}
|
|
247
288
|
}
|
|
248
289
|
constructor(target, userConfig) {
|
|
249
290
|
this.totalTimes = 0;
|
|
250
291
|
this.config = {};
|
|
251
|
-
this.__updatedList = new LeafList
|
|
292
|
+
this.__updatedList = new LeafList;
|
|
252
293
|
this.target = target;
|
|
253
|
-
if (userConfig)
|
|
254
|
-
this.config = DataHelper.default(userConfig, this.config);
|
|
294
|
+
if (userConfig) this.config = DataHelper.default(userConfig, this.config);
|
|
255
295
|
this.__listenEvents();
|
|
256
296
|
}
|
|
257
297
|
start() {
|
|
258
|
-
if (this.disabled)
|
|
259
|
-
return;
|
|
298
|
+
if (this.disabled) return;
|
|
260
299
|
this.running = true;
|
|
261
300
|
}
|
|
262
301
|
stop() {
|
|
@@ -269,8 +308,7 @@ class Watcher {
|
|
|
269
308
|
}
|
|
270
309
|
update() {
|
|
271
310
|
this.changed = true;
|
|
272
|
-
if (this.running)
|
|
273
|
-
this.target.emit(RenderEvent.REQUEST);
|
|
311
|
+
if (this.running) this.target.emit(RenderEvent.REQUEST);
|
|
274
312
|
}
|
|
275
313
|
__onAttrChange(event) {
|
|
276
314
|
this.__updatedList.add(event.target);
|
|
@@ -280,8 +318,7 @@ class Watcher {
|
|
|
280
318
|
if (event.type === ChildEvent.ADD) {
|
|
281
319
|
this.hasAdd = true;
|
|
282
320
|
this.__pushChild(event.child);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
321
|
+
} else {
|
|
285
322
|
this.hasRemove = true;
|
|
286
323
|
this.__updatedList.add(event.parent);
|
|
287
324
|
}
|
|
@@ -289,28 +326,22 @@ class Watcher {
|
|
|
289
326
|
}
|
|
290
327
|
__pushChild(child) {
|
|
291
328
|
this.__updatedList.add(child);
|
|
292
|
-
if (child.isBranch)
|
|
293
|
-
this.__loopChildren(child);
|
|
329
|
+
if (child.isBranch) this.__loopChildren(child);
|
|
294
330
|
}
|
|
295
331
|
__loopChildren(parent) {
|
|
296
|
-
const { children
|
|
297
|
-
for (let i = 0, len = children.length; i < len; i++)
|
|
298
|
-
this.__pushChild(children[i]);
|
|
332
|
+
const {children: children} = parent;
|
|
333
|
+
for (let i = 0, len = children.length; i < len; i++) this.__pushChild(children[i]);
|
|
299
334
|
}
|
|
300
335
|
__onRquestData() {
|
|
301
|
-
this.target.emitEvent(new WatchEvent(WatchEvent.DATA, {
|
|
302
|
-
|
|
336
|
+
this.target.emitEvent(new WatchEvent(WatchEvent.DATA, {
|
|
337
|
+
updatedList: this.updatedList
|
|
338
|
+
}));
|
|
339
|
+
this.__updatedList = new LeafList;
|
|
303
340
|
this.totalTimes++;
|
|
304
341
|
this.changed = this.hasVisible = this.hasRemove = this.hasAdd = false;
|
|
305
342
|
}
|
|
306
343
|
__listenEvents() {
|
|
307
|
-
this.__eventIds = [
|
|
308
|
-
this.target.on_([
|
|
309
|
-
[PropertyEvent.CHANGE, this.__onAttrChange, this],
|
|
310
|
-
[[ChildEvent.ADD, ChildEvent.REMOVE], this.__onChildEvent, this],
|
|
311
|
-
[WatchEvent.REQUEST, this.__onRquestData, this]
|
|
312
|
-
])
|
|
313
|
-
];
|
|
344
|
+
this.__eventIds = [ this.target.on_([ [ PropertyEvent.CHANGE, this.__onAttrChange, this ], [ [ ChildEvent.ADD, ChildEvent.REMOVE ], this.__onChildEvent, this ], [ WatchEvent.REQUEST, this.__onRquestData, this ] ]) ];
|
|
314
345
|
}
|
|
315
346
|
__removeListenEvents() {
|
|
316
347
|
this.target.off_(this.__eventIds);
|
|
@@ -324,8 +355,10 @@ class Watcher {
|
|
|
324
355
|
}
|
|
325
356
|
}
|
|
326
357
|
|
|
327
|
-
const {
|
|
328
|
-
|
|
358
|
+
const {updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange} = LeafHelper;
|
|
359
|
+
|
|
360
|
+
const {pushAllChildBranch: pushAllChildBranch, pushAllParent: pushAllParent} = BranchHelper;
|
|
361
|
+
|
|
329
362
|
function updateMatrix(updateList, levelList) {
|
|
330
363
|
let layout;
|
|
331
364
|
updateList.list.forEach(leaf => {
|
|
@@ -334,19 +367,17 @@ function updateMatrix(updateList, levelList) {
|
|
|
334
367
|
if (layout.matrixChanged) {
|
|
335
368
|
updateAllMatrix$1(leaf, true);
|
|
336
369
|
levelList.add(leaf);
|
|
337
|
-
if (leaf.isBranch)
|
|
338
|
-
pushAllChildBranch(leaf, levelList);
|
|
370
|
+
if (leaf.isBranch) pushAllChildBranch(leaf, levelList);
|
|
339
371
|
pushAllParent(leaf, levelList);
|
|
340
|
-
}
|
|
341
|
-
else if (layout.boundsChanged) {
|
|
372
|
+
} else if (layout.boundsChanged) {
|
|
342
373
|
levelList.add(leaf);
|
|
343
|
-
if (leaf.isBranch)
|
|
344
|
-
leaf.__tempNumber = 0;
|
|
374
|
+
if (leaf.isBranch) leaf.__tempNumber = 0;
|
|
345
375
|
pushAllParent(leaf, levelList);
|
|
346
376
|
}
|
|
347
377
|
}
|
|
348
378
|
});
|
|
349
379
|
}
|
|
380
|
+
|
|
350
381
|
function updateBounds(boundsList) {
|
|
351
382
|
let list, branch, children;
|
|
352
383
|
boundsList.sort(true);
|
|
@@ -366,18 +397,19 @@ function updateBounds(boundsList) {
|
|
|
366
397
|
}
|
|
367
398
|
});
|
|
368
399
|
}
|
|
400
|
+
|
|
369
401
|
function updateChange(updateList) {
|
|
370
402
|
updateList.list.forEach(updateOneChange);
|
|
371
403
|
}
|
|
372
404
|
|
|
373
|
-
const { worldBounds
|
|
405
|
+
const {worldBounds: worldBounds} = LeafBoundsHelper;
|
|
406
|
+
|
|
374
407
|
class LayoutBlockData {
|
|
375
408
|
constructor(list) {
|
|
376
|
-
this.updatedBounds = new Bounds
|
|
377
|
-
this.beforeBounds = new Bounds
|
|
378
|
-
this.afterBounds = new Bounds
|
|
379
|
-
if (list
|
|
380
|
-
list = new LeafList(list);
|
|
409
|
+
this.updatedBounds = new Bounds;
|
|
410
|
+
this.beforeBounds = new Bounds;
|
|
411
|
+
this.afterBounds = new Bounds;
|
|
412
|
+
if (isArray(list)) list = new LeafList(list);
|
|
381
413
|
this.updatedList = list;
|
|
382
414
|
}
|
|
383
415
|
setBefore() {
|
|
@@ -385,7 +417,7 @@ class LayoutBlockData {
|
|
|
385
417
|
}
|
|
386
418
|
setAfter() {
|
|
387
419
|
this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
388
|
-
this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
|
|
420
|
+
this.updatedBounds.setList([ this.beforeBounds, this.afterBounds ]);
|
|
389
421
|
}
|
|
390
422
|
merge(data) {
|
|
391
423
|
this.updatedList.addList(data.updatedList.list);
|
|
@@ -398,21 +430,21 @@ class LayoutBlockData {
|
|
|
398
430
|
}
|
|
399
431
|
}
|
|
400
432
|
|
|
401
|
-
const { updateAllMatrix, updateAllChange } = LeafHelper;
|
|
402
|
-
|
|
433
|
+
const {updateAllMatrix: updateAllMatrix, updateAllChange: updateAllChange} = LeafHelper;
|
|
434
|
+
|
|
435
|
+
const debug$1 = Debug.get("Layouter");
|
|
436
|
+
|
|
403
437
|
class Layouter {
|
|
404
438
|
constructor(target, userConfig) {
|
|
405
439
|
this.totalTimes = 0;
|
|
406
440
|
this.config = {};
|
|
407
|
-
this.__levelList = new LeafLevelList
|
|
441
|
+
this.__levelList = new LeafLevelList;
|
|
408
442
|
this.target = target;
|
|
409
|
-
if (userConfig)
|
|
410
|
-
this.config = DataHelper.default(userConfig, this.config);
|
|
443
|
+
if (userConfig) this.config = DataHelper.default(userConfig, this.config);
|
|
411
444
|
this.__listenEvents();
|
|
412
445
|
}
|
|
413
446
|
start() {
|
|
414
|
-
if (this.disabled)
|
|
415
|
-
return;
|
|
447
|
+
if (this.disabled) return;
|
|
416
448
|
this.running = true;
|
|
417
449
|
}
|
|
418
450
|
stop() {
|
|
@@ -424,16 +456,14 @@ class Layouter {
|
|
|
424
456
|
this.disabled = true;
|
|
425
457
|
}
|
|
426
458
|
layout() {
|
|
427
|
-
if (this.layouting || !this.running)
|
|
428
|
-
|
|
429
|
-
const { target } = this;
|
|
459
|
+
if (this.layouting || !this.running) return;
|
|
460
|
+
const {target: target} = this;
|
|
430
461
|
this.times = 0;
|
|
431
462
|
try {
|
|
432
463
|
target.emit(LayoutEvent.START);
|
|
433
464
|
this.layoutOnce();
|
|
434
465
|
target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
|
|
435
|
-
}
|
|
436
|
-
catch (e) {
|
|
466
|
+
} catch (e) {
|
|
437
467
|
debug$1.error(e);
|
|
438
468
|
}
|
|
439
469
|
this.layoutedBlocks = null;
|
|
@@ -441,24 +471,20 @@ class Layouter {
|
|
|
441
471
|
layoutAgain() {
|
|
442
472
|
if (this.layouting) {
|
|
443
473
|
this.waitAgain = true;
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
474
|
+
} else {
|
|
446
475
|
this.layoutOnce();
|
|
447
476
|
}
|
|
448
477
|
}
|
|
449
478
|
layoutOnce() {
|
|
450
|
-
if (this.layouting)
|
|
451
|
-
|
|
452
|
-
if (this.times > 3)
|
|
453
|
-
return debug$1.warn('layout max times');
|
|
479
|
+
if (this.layouting) return debug$1.warn("layouting");
|
|
480
|
+
if (this.times > 3) return debug$1.warn("layout max times");
|
|
454
481
|
this.times++;
|
|
455
482
|
this.totalTimes++;
|
|
456
483
|
this.layouting = true;
|
|
457
484
|
this.target.emit(WatchEvent.REQUEST);
|
|
458
485
|
if (this.totalTimes > 1) {
|
|
459
486
|
this.partLayout();
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
487
|
+
} else {
|
|
462
488
|
this.fullLayout();
|
|
463
489
|
}
|
|
464
490
|
this.layouting = false;
|
|
@@ -469,11 +495,10 @@ class Layouter {
|
|
|
469
495
|
}
|
|
470
496
|
partLayout() {
|
|
471
497
|
var _a;
|
|
472
|
-
if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
const {
|
|
476
|
-
const { BEFORE, LAYOUT, AFTER } = LayoutEvent;
|
|
498
|
+
if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length)) return;
|
|
499
|
+
const t = Run.start("PartLayout");
|
|
500
|
+
const {target: target, __updatedList: updateList} = this;
|
|
501
|
+
const {BEFORE: BEFORE, LAYOUT: LAYOUT, AFTER: AFTER} = LayoutEvent;
|
|
477
502
|
const blocks = this.getBlocks(updateList);
|
|
478
503
|
blocks.forEach(item => item.setBefore());
|
|
479
504
|
target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times));
|
|
@@ -482,8 +507,7 @@ class Layouter {
|
|
|
482
507
|
updateMatrix(updateList, this.__levelList);
|
|
483
508
|
updateBounds(this.__levelList);
|
|
484
509
|
updateChange(updateList);
|
|
485
|
-
if (this.extraBlock)
|
|
486
|
-
blocks.push(this.extraBlock);
|
|
510
|
+
if (this.extraBlock) blocks.push(this.extraBlock);
|
|
487
511
|
blocks.forEach(item => item.setAfter());
|
|
488
512
|
target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times));
|
|
489
513
|
target.emitEvent(new LayoutEvent(AFTER, blocks, this.times));
|
|
@@ -493,13 +517,15 @@ class Layouter {
|
|
|
493
517
|
Run.end(t);
|
|
494
518
|
}
|
|
495
519
|
fullLayout() {
|
|
496
|
-
const t = Run.start(
|
|
497
|
-
const { target
|
|
498
|
-
const { BEFORE, LAYOUT, AFTER } = LayoutEvent;
|
|
520
|
+
const t = Run.start("FullLayout");
|
|
521
|
+
const {target: target} = this;
|
|
522
|
+
const {BEFORE: BEFORE, LAYOUT: LAYOUT, AFTER: AFTER} = LayoutEvent;
|
|
499
523
|
const blocks = this.getBlocks(new LeafList(target));
|
|
500
524
|
target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times));
|
|
501
525
|
Layouter.fullLayout(target);
|
|
502
|
-
blocks.forEach(item => {
|
|
526
|
+
blocks.forEach(item => {
|
|
527
|
+
item.setAfter();
|
|
528
|
+
});
|
|
503
529
|
target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times));
|
|
504
530
|
target.emitEvent(new LayoutEvent(AFTER, blocks, this.times));
|
|
505
531
|
this.addBlocks(blocks);
|
|
@@ -507,15 +533,12 @@ class Layouter {
|
|
|
507
533
|
}
|
|
508
534
|
static fullLayout(target) {
|
|
509
535
|
updateAllMatrix(target, true);
|
|
510
|
-
if (target.isBranch)
|
|
511
|
-
BranchHelper.updateBounds(target);
|
|
512
|
-
else
|
|
513
|
-
LeafHelper.updateBounds(target);
|
|
536
|
+
if (target.isBranch) BranchHelper.updateBounds(target); else LeafHelper.updateBounds(target);
|
|
514
537
|
updateAllChange(target);
|
|
515
538
|
}
|
|
516
539
|
addExtra(leaf) {
|
|
517
540
|
if (!this.__updatedList.has(leaf)) {
|
|
518
|
-
const { updatedList, beforeBounds } = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
|
|
541
|
+
const {updatedList: updatedList, beforeBounds: beforeBounds} = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
|
|
519
542
|
updatedList.length ? beforeBounds.add(leaf.__world) : beforeBounds.set(leaf.__world);
|
|
520
543
|
updatedList.add(leaf);
|
|
521
544
|
}
|
|
@@ -524,7 +547,7 @@ class Layouter {
|
|
|
524
547
|
return new LayoutBlockData(data);
|
|
525
548
|
}
|
|
526
549
|
getBlocks(list) {
|
|
527
|
-
return [this.createBlock(list)];
|
|
550
|
+
return [ this.createBlock(list) ];
|
|
528
551
|
}
|
|
529
552
|
addBlocks(current) {
|
|
530
553
|
this.layoutedBlocks ? this.layoutedBlocks.push(...current) : this.layoutedBlocks = current;
|
|
@@ -533,13 +556,7 @@ class Layouter {
|
|
|
533
556
|
this.__updatedList = event.data.updatedList;
|
|
534
557
|
}
|
|
535
558
|
__listenEvents() {
|
|
536
|
-
this.__eventIds = [
|
|
537
|
-
this.target.on_([
|
|
538
|
-
[LayoutEvent.REQUEST, this.layout, this],
|
|
539
|
-
[LayoutEvent.AGAIN, this.layoutAgain, this],
|
|
540
|
-
[WatchEvent.DATA, this.__onReceiveWatchData, this]
|
|
541
|
-
])
|
|
542
|
-
];
|
|
559
|
+
this.__eventIds = [ this.target.on_([ [ LayoutEvent.REQUEST, this.layout, this ], [ LayoutEvent.AGAIN, this.layoutAgain, this ], [ WatchEvent.DATA, this.__onReceiveWatchData, this ] ]) ];
|
|
543
560
|
}
|
|
544
561
|
__removeListenEvents() {
|
|
545
562
|
this.target.off_(this.__eventIds);
|
|
@@ -553,9 +570,12 @@ class Layouter {
|
|
|
553
570
|
}
|
|
554
571
|
}
|
|
555
572
|
|
|
556
|
-
const debug = Debug.get(
|
|
573
|
+
const debug = Debug.get("Renderer");
|
|
574
|
+
|
|
557
575
|
class Renderer {
|
|
558
|
-
get needFill() {
|
|
576
|
+
get needFill() {
|
|
577
|
+
return !!(!this.canvas.allowBackgroundColor && this.config.fill);
|
|
578
|
+
}
|
|
559
579
|
constructor(target, canvas, userConfig) {
|
|
560
580
|
this.FPS = 60;
|
|
561
581
|
this.totalTimes = 0;
|
|
@@ -566,8 +586,7 @@ class Renderer {
|
|
|
566
586
|
};
|
|
567
587
|
this.target = target;
|
|
568
588
|
this.canvas = canvas;
|
|
569
|
-
if (userConfig)
|
|
570
|
-
this.config = DataHelper.default(userConfig, this.config);
|
|
589
|
+
if (userConfig) this.config = DataHelper.default(userConfig, this.config);
|
|
571
590
|
this.__listenEvents();
|
|
572
591
|
}
|
|
573
592
|
start() {
|
|
@@ -578,8 +597,7 @@ class Renderer {
|
|
|
578
597
|
this.running = false;
|
|
579
598
|
}
|
|
580
599
|
update(change = true) {
|
|
581
|
-
if (!this.changed)
|
|
582
|
-
this.changed = change;
|
|
600
|
+
if (!this.changed) this.changed = change;
|
|
583
601
|
this.__requestRender();
|
|
584
602
|
}
|
|
585
603
|
requestLayout() {
|
|
@@ -587,7 +605,7 @@ class Renderer {
|
|
|
587
605
|
}
|
|
588
606
|
checkRender() {
|
|
589
607
|
if (this.running) {
|
|
590
|
-
const { target
|
|
608
|
+
const {target: target} = this;
|
|
591
609
|
if (target.isApp) {
|
|
592
610
|
target.emit(RenderEvent.CHILD_START, target);
|
|
593
611
|
target.children.forEach(leafer => {
|
|
@@ -596,54 +614,47 @@ class Renderer {
|
|
|
596
614
|
});
|
|
597
615
|
target.emit(RenderEvent.CHILD_END, target);
|
|
598
616
|
}
|
|
599
|
-
if (this.changed && this.canvas.view)
|
|
600
|
-
this.render();
|
|
617
|
+
if (this.changed && this.canvas.view) this.render();
|
|
601
618
|
this.target.emit(RenderEvent.NEXT);
|
|
602
619
|
}
|
|
603
620
|
}
|
|
604
621
|
render(callback) {
|
|
605
|
-
if (!(this.running && this.canvas.view))
|
|
606
|
-
|
|
607
|
-
const { target } = this;
|
|
622
|
+
if (!(this.running && this.canvas.view)) return this.update();
|
|
623
|
+
const {target: target} = this;
|
|
608
624
|
this.times = 0;
|
|
609
|
-
this.totalBounds = new Bounds
|
|
610
|
-
debug.log(target.innerName,
|
|
625
|
+
this.totalBounds = new Bounds;
|
|
626
|
+
debug.log(target.innerName, "---\x3e");
|
|
611
627
|
try {
|
|
612
628
|
this.emitRender(RenderEvent.START);
|
|
613
629
|
this.renderOnce(callback);
|
|
614
630
|
this.emitRender(RenderEvent.END, this.totalBounds);
|
|
615
631
|
ImageManager.clearRecycled();
|
|
616
|
-
}
|
|
617
|
-
catch (e) {
|
|
632
|
+
} catch (e) {
|
|
618
633
|
this.rendering = false;
|
|
619
634
|
debug.error(e);
|
|
620
635
|
}
|
|
621
|
-
debug.log(
|
|
636
|
+
debug.log("-------------|");
|
|
622
637
|
}
|
|
623
638
|
renderAgain() {
|
|
624
639
|
if (this.rendering) {
|
|
625
640
|
this.waitAgain = true;
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
641
|
+
} else {
|
|
628
642
|
this.renderOnce();
|
|
629
643
|
}
|
|
630
644
|
}
|
|
631
645
|
renderOnce(callback) {
|
|
632
|
-
if (this.rendering)
|
|
633
|
-
|
|
634
|
-
if (this.times > 3)
|
|
635
|
-
return debug.warn('render max times');
|
|
646
|
+
if (this.rendering) return debug.warn("rendering");
|
|
647
|
+
if (this.times > 3) return debug.warn("render max times");
|
|
636
648
|
this.times++;
|
|
637
649
|
this.totalTimes++;
|
|
638
650
|
this.rendering = true;
|
|
639
651
|
this.changed = false;
|
|
640
|
-
this.renderBounds = new Bounds
|
|
652
|
+
this.renderBounds = new Bounds;
|
|
641
653
|
this.renderOptions = {};
|
|
642
654
|
if (callback) {
|
|
643
655
|
this.emitRender(RenderEvent.BEFORE);
|
|
644
656
|
callback();
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
657
|
+
} else {
|
|
647
658
|
this.requestLayout();
|
|
648
659
|
if (this.ignore) {
|
|
649
660
|
this.ignore = this.rendering = false;
|
|
@@ -652,8 +663,7 @@ class Renderer {
|
|
|
652
663
|
this.emitRender(RenderEvent.BEFORE);
|
|
653
664
|
if (this.config.usePartRender && this.totalTimes > 1) {
|
|
654
665
|
this.partRender();
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
666
|
+
} else {
|
|
657
667
|
this.fullRender();
|
|
658
668
|
}
|
|
659
669
|
}
|
|
@@ -667,16 +677,16 @@ class Renderer {
|
|
|
667
677
|
}
|
|
668
678
|
}
|
|
669
679
|
partRender() {
|
|
670
|
-
const { canvas, updateBlocks: list
|
|
671
|
-
if (!list)
|
|
672
|
-
return;
|
|
680
|
+
const {canvas: canvas, updateBlocks: list} = this;
|
|
681
|
+
if (!list) return;
|
|
673
682
|
this.mergeBlocks();
|
|
674
|
-
list.forEach(block => {
|
|
675
|
-
this.clipRender(block);
|
|
683
|
+
list.forEach(block => {
|
|
684
|
+
if (canvas.bounds.hit(block) && !block.isEmpty()) this.clipRender(block);
|
|
685
|
+
});
|
|
676
686
|
}
|
|
677
687
|
clipRender(block) {
|
|
678
|
-
const t = Run.start(
|
|
679
|
-
const { canvas
|
|
688
|
+
const t = Run.start("PartRender");
|
|
689
|
+
const {canvas: canvas} = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
|
|
680
690
|
canvas.save();
|
|
681
691
|
bounds.spread(Renderer.clipSpread).ceil();
|
|
682
692
|
canvas.clearWorld(bounds, true);
|
|
@@ -686,8 +696,8 @@ class Renderer {
|
|
|
686
696
|
Run.end(t);
|
|
687
697
|
}
|
|
688
698
|
fullRender() {
|
|
689
|
-
const t = Run.start(
|
|
690
|
-
const { canvas
|
|
699
|
+
const t = Run.start("FullRender");
|
|
700
|
+
const {canvas: canvas} = this;
|
|
691
701
|
canvas.save();
|
|
692
702
|
canvas.clear();
|
|
693
703
|
this.__render(canvas.bounds);
|
|
@@ -695,11 +705,14 @@ class Renderer {
|
|
|
695
705
|
Run.end(t);
|
|
696
706
|
}
|
|
697
707
|
__render(bounds, realBounds) {
|
|
698
|
-
const { canvas
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
708
|
+
const {canvas: canvas} = this, includes = bounds.includes(this.target.__world), options = includes ? {
|
|
709
|
+
includes: includes
|
|
710
|
+
} : {
|
|
711
|
+
bounds: bounds,
|
|
712
|
+
includes: includes
|
|
713
|
+
};
|
|
714
|
+
if (this.needFill) canvas.fillWorld(bounds, this.config.fill);
|
|
715
|
+
if (Debug.showRepaint) Debug.drawRepaint(canvas, bounds);
|
|
703
716
|
this.target.__render(canvas, options);
|
|
704
717
|
this.renderBounds = realBounds = realBounds || bounds;
|
|
705
718
|
this.renderOptions = options;
|
|
@@ -707,14 +720,13 @@ class Renderer {
|
|
|
707
720
|
canvas.updateRender(realBounds);
|
|
708
721
|
}
|
|
709
722
|
addBlock(block) {
|
|
710
|
-
if (!this.updateBlocks)
|
|
711
|
-
this.updateBlocks = [];
|
|
723
|
+
if (!this.updateBlocks) this.updateBlocks = [];
|
|
712
724
|
this.updateBlocks.push(block);
|
|
713
725
|
}
|
|
714
726
|
mergeBlocks() {
|
|
715
|
-
const {
|
|
727
|
+
const {updateBlocks: list} = this;
|
|
716
728
|
if (list) {
|
|
717
|
-
const bounds = new Bounds
|
|
729
|
+
const bounds = new Bounds;
|
|
718
730
|
bounds.setList(list);
|
|
719
731
|
list.length = 0;
|
|
720
732
|
list.push(bounds);
|
|
@@ -722,26 +734,23 @@ class Renderer {
|
|
|
722
734
|
}
|
|
723
735
|
__requestRender() {
|
|
724
736
|
const target = this.target;
|
|
725
|
-
if (this.requestTime || !target)
|
|
726
|
-
|
|
727
|
-
if (target.parentApp)
|
|
728
|
-
return target.parentApp.requestRender(false);
|
|
737
|
+
if (this.requestTime || !target) return;
|
|
738
|
+
if (target.parentApp) return target.parentApp.requestRender(false);
|
|
729
739
|
const requestTime = this.requestTime = Date.now();
|
|
730
740
|
Platform.requestRender(() => {
|
|
731
|
-
this.FPS = Math.min(60, Math.ceil(
|
|
741
|
+
this.FPS = Math.min(60, Math.ceil(1e3 / (Date.now() - requestTime)));
|
|
732
742
|
this.requestTime = 0;
|
|
733
743
|
this.checkRender();
|
|
734
744
|
});
|
|
735
745
|
}
|
|
736
746
|
__onResize(e) {
|
|
737
|
-
if (this.canvas.unreal)
|
|
738
|
-
return;
|
|
747
|
+
if (this.canvas.unreal) return;
|
|
739
748
|
if (e.bigger || !e.samePixelRatio) {
|
|
740
|
-
const { width, height } = e.old;
|
|
749
|
+
const {width: width, height: height} = e.old;
|
|
741
750
|
const bounds = new Bounds(0, 0, width, height);
|
|
742
751
|
if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
|
|
743
752
|
this.addBlock(this.canvas.bounds);
|
|
744
|
-
this.target.forceUpdate(
|
|
753
|
+
this.target.forceUpdate("surface");
|
|
745
754
|
return;
|
|
746
755
|
}
|
|
747
756
|
}
|
|
@@ -749,34 +758,24 @@ class Renderer {
|
|
|
749
758
|
this.update();
|
|
750
759
|
}
|
|
751
760
|
__onLayoutEnd(event) {
|
|
752
|
-
if (event.data)
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
762
|
-
}
|
|
763
|
-
return empty;
|
|
764
|
-
});
|
|
765
|
-
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
761
|
+
if (event.data) event.data.map(item => {
|
|
762
|
+
let empty;
|
|
763
|
+
if (item.updatedList) item.updatedList.list.some(leaf => {
|
|
764
|
+
empty = !leaf.__world.width || !leaf.__world.height;
|
|
765
|
+
if (empty) {
|
|
766
|
+
if (!leaf.isLeafer) debug.tip(leaf.innerName, ": empty");
|
|
767
|
+
empty = !leaf.isBranch || leaf.isBranchLeaf;
|
|
768
|
+
}
|
|
769
|
+
return empty;
|
|
766
770
|
});
|
|
771
|
+
this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
|
|
772
|
+
});
|
|
767
773
|
}
|
|
768
774
|
emitRender(type, bounds, options) {
|
|
769
775
|
this.target.emitEvent(new RenderEvent(type, this.times, bounds, options));
|
|
770
776
|
}
|
|
771
777
|
__listenEvents() {
|
|
772
|
-
this.__eventIds = [
|
|
773
|
-
this.target.on_([
|
|
774
|
-
[RenderEvent.REQUEST, this.update, this],
|
|
775
|
-
[LayoutEvent.END, this.__onLayoutEnd, this],
|
|
776
|
-
[RenderEvent.AGAIN, this.renderAgain, this],
|
|
777
|
-
[ResizeEvent.RESIZE, this.__onResize, this]
|
|
778
|
-
])
|
|
779
|
-
];
|
|
778
|
+
this.__eventIds = [ this.target.on_([ [ RenderEvent.REQUEST, this.update, this ], [ LayoutEvent.END, this.__onLayoutEnd, this ], [ RenderEvent.AGAIN, this.renderAgain, this ], [ ResizeEvent.RESIZE, this.__onResize, this ] ]) ];
|
|
780
779
|
}
|
|
781
780
|
__removeListenEvents() {
|
|
782
781
|
this.target.off_(this.__eventIds);
|
|
@@ -789,82 +788,104 @@ class Renderer {
|
|
|
789
788
|
}
|
|
790
789
|
}
|
|
791
790
|
}
|
|
791
|
+
|
|
792
792
|
Renderer.clipSpread = 10;
|
|
793
793
|
|
|
794
|
-
const { hitRadiusPoint
|
|
794
|
+
const {hitRadiusPoint: hitRadiusPoint} = BoundsHelper;
|
|
795
|
+
|
|
795
796
|
class Picker {
|
|
796
797
|
constructor(target, selector) {
|
|
797
798
|
this.target = target;
|
|
798
799
|
this.selector = selector;
|
|
799
800
|
}
|
|
800
801
|
getByPoint(hitPoint, hitRadius, options) {
|
|
801
|
-
if (!hitRadius)
|
|
802
|
-
|
|
803
|
-
if (!options)
|
|
804
|
-
options = {};
|
|
802
|
+
if (!hitRadius) hitRadius = 0;
|
|
803
|
+
if (!options) options = {};
|
|
805
804
|
const through = options.through || false;
|
|
806
805
|
const ignoreHittable = options.ignoreHittable || false;
|
|
807
806
|
const target = options.target || this.target;
|
|
808
807
|
this.exclude = options.exclude || null;
|
|
809
|
-
this.point = {
|
|
808
|
+
this.point = {
|
|
809
|
+
x: hitPoint.x,
|
|
810
|
+
y: hitPoint.y,
|
|
811
|
+
radiusX: hitRadius,
|
|
812
|
+
radiusY: hitRadius
|
|
813
|
+
};
|
|
810
814
|
this.findList = new LeafList(options.findList);
|
|
811
|
-
if (!options.findList)
|
|
812
|
-
|
|
813
|
-
|
|
815
|
+
if (!options.findList) this.hitBranch(target.isBranchLeaf ? {
|
|
816
|
+
children: [ target ]
|
|
817
|
+
} : target);
|
|
818
|
+
const {list: list} = this.findList;
|
|
814
819
|
const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable);
|
|
815
820
|
const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf);
|
|
816
821
|
this.clear();
|
|
817
|
-
return through ? {
|
|
822
|
+
return through ? {
|
|
823
|
+
path: path,
|
|
824
|
+
target: leaf,
|
|
825
|
+
throughPath: list.length ? this.getThroughPath(list) : path
|
|
826
|
+
} : {
|
|
827
|
+
path: path,
|
|
828
|
+
target: leaf
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
hitPoint(hitPoint, hitRadius, options) {
|
|
832
|
+
return !!this.getByPoint(hitPoint, hitRadius, options).target;
|
|
818
833
|
}
|
|
819
834
|
getBestMatchLeaf(list, bottomList, ignoreHittable) {
|
|
835
|
+
const findList = this.findList = new LeafList;
|
|
820
836
|
if (list.length) {
|
|
821
837
|
let find;
|
|
822
|
-
|
|
823
|
-
const
|
|
824
|
-
|
|
838
|
+
const {x: x, y: y} = this.point;
|
|
839
|
+
const point = {
|
|
840
|
+
x: x,
|
|
841
|
+
y: y,
|
|
842
|
+
radiusX: 0,
|
|
843
|
+
radiusY: 0
|
|
844
|
+
};
|
|
825
845
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
826
846
|
find = list[i];
|
|
827
847
|
if (ignoreHittable || LeafHelper.worldHittable(find)) {
|
|
828
848
|
this.hitChild(find, point);
|
|
829
|
-
if (
|
|
830
|
-
|
|
849
|
+
if (findList.length) {
|
|
850
|
+
if (find.isBranchLeaf && list.some(item => item !== find && LeafHelper.hasParent(item, find))) {
|
|
851
|
+
findList.reset();
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
return findList.list[0];
|
|
855
|
+
}
|
|
831
856
|
}
|
|
832
857
|
}
|
|
833
858
|
}
|
|
834
859
|
if (bottomList) {
|
|
835
860
|
for (let i = 0, len = bottomList.length; i < len; i++) {
|
|
836
861
|
this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy);
|
|
837
|
-
if (
|
|
838
|
-
return this.findList.list[0];
|
|
862
|
+
if (findList.length) return findList.list[0];
|
|
839
863
|
}
|
|
840
864
|
}
|
|
841
|
-
return list[0];
|
|
865
|
+
return ignoreHittable ? list[0] : list.find(item => LeafHelper.worldHittable(item));
|
|
842
866
|
}
|
|
843
867
|
getPath(leaf) {
|
|
844
|
-
const path = new LeafList
|
|
868
|
+
const path = new LeafList;
|
|
845
869
|
while (leaf) {
|
|
846
870
|
path.add(leaf);
|
|
847
871
|
leaf = leaf.parent;
|
|
848
872
|
}
|
|
849
|
-
if (this.target)
|
|
850
|
-
path.add(this.target);
|
|
873
|
+
if (this.target) path.add(this.target);
|
|
851
874
|
return path;
|
|
852
875
|
}
|
|
853
876
|
getHitablePath(leaf) {
|
|
854
877
|
const path = this.getPath(leaf && leaf.hittable ? leaf : null);
|
|
855
|
-
let item, hittablePath = new LeafList
|
|
878
|
+
let item, hittablePath = new LeafList;
|
|
856
879
|
for (let i = path.list.length - 1; i > -1; i--) {
|
|
857
880
|
item = path.list[i];
|
|
858
|
-
if (!item.__.hittable)
|
|
859
|
-
break;
|
|
881
|
+
if (!item.__.hittable) break;
|
|
860
882
|
hittablePath.addAt(item, 0);
|
|
861
|
-
if (!item.__.hitChildren)
|
|
862
|
-
break;
|
|
883
|
+
if (!item.__.hitChildren) break;
|
|
863
884
|
}
|
|
864
885
|
return hittablePath;
|
|
865
886
|
}
|
|
866
887
|
getThroughPath(list) {
|
|
867
|
-
const throughPath = new LeafList
|
|
888
|
+
const throughPath = new LeafList;
|
|
868
889
|
const pathList = [];
|
|
869
890
|
for (let i = list.length - 1; i > -1; i--) {
|
|
870
891
|
pathList.push(this.getPath(list[i]));
|
|
@@ -874,8 +895,7 @@ class Picker {
|
|
|
874
895
|
path = pathList[i], nextPath = pathList[i + 1];
|
|
875
896
|
for (let j = 0, jLen = path.length; j < jLen; j++) {
|
|
876
897
|
leaf = path.list[j];
|
|
877
|
-
if (nextPath && nextPath.has(leaf))
|
|
878
|
-
break;
|
|
898
|
+
if (nextPath && nextPath.has(leaf)) break;
|
|
879
899
|
throughPath.add(leaf);
|
|
880
900
|
}
|
|
881
901
|
}
|
|
@@ -886,32 +906,37 @@ class Picker {
|
|
|
886
906
|
}
|
|
887
907
|
eachFind(children, hitMask) {
|
|
888
908
|
let child, hit;
|
|
889
|
-
const { point
|
|
909
|
+
const {point: point} = this, len = children.length;
|
|
890
910
|
for (let i = len - 1; i > -1; i--) {
|
|
891
911
|
child = children[i];
|
|
892
|
-
if (!child.__.visible ||
|
|
893
|
-
continue;
|
|
912
|
+
if (!child.__.visible || hitMask && !child.__.mask) continue;
|
|
894
913
|
hit = child.__.hitRadius ? true : hitRadiusPoint(child.__world, point);
|
|
895
914
|
if (child.isBranch) {
|
|
896
915
|
if (hit || child.__ignoreHitWorld) {
|
|
897
916
|
this.eachFind(child.children, child.__onlyHitMask);
|
|
898
|
-
if (child.isBranchLeaf)
|
|
899
|
-
this.hitChild(child, point);
|
|
917
|
+
if (child.isBranchLeaf) this.hitChild(child, point);
|
|
900
918
|
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
if (hit)
|
|
904
|
-
this.hitChild(child, point);
|
|
919
|
+
} else {
|
|
920
|
+
if (hit) this.hitChild(child, point);
|
|
905
921
|
}
|
|
906
922
|
}
|
|
907
923
|
}
|
|
908
924
|
hitChild(child, point, proxy) {
|
|
909
|
-
if (this.exclude && this.exclude.has(child))
|
|
910
|
-
return;
|
|
925
|
+
if (this.exclude && this.exclude.has(child)) return;
|
|
911
926
|
if (child.__hitWorld(point)) {
|
|
912
|
-
const { parent
|
|
913
|
-
if (parent && parent.__hasMask && !child.__.mask
|
|
914
|
-
|
|
927
|
+
const {parent: parent} = child;
|
|
928
|
+
if (parent && parent.__hasMask && !child.__.mask) {
|
|
929
|
+
let findMasks = [], item;
|
|
930
|
+
const {children: children} = parent;
|
|
931
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
932
|
+
item = children[i];
|
|
933
|
+
if (item.__.mask) findMasks.push(item);
|
|
934
|
+
if (item === child) {
|
|
935
|
+
if (findMasks && !findMasks.every(value => value.__hitWorld(point))) return;
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
915
940
|
this.findList.add(proxy || child);
|
|
916
941
|
}
|
|
917
942
|
}
|
|
@@ -928,24 +953,24 @@ class Picker {
|
|
|
928
953
|
class Selector {
|
|
929
954
|
constructor(target, userConfig) {
|
|
930
955
|
this.config = {};
|
|
931
|
-
if (userConfig)
|
|
932
|
-
this.config = DataHelper.default(userConfig, this.config);
|
|
956
|
+
if (userConfig) this.config = DataHelper.default(userConfig, this.config);
|
|
933
957
|
this.picker = new Picker(this.target = target, this);
|
|
934
958
|
this.finder = Creator.finder && Creator.finder();
|
|
935
959
|
}
|
|
936
960
|
getByPoint(hitPoint, hitRadius, options) {
|
|
937
|
-
const { target, picker } = this;
|
|
938
|
-
if (Platform.backgrounder)
|
|
939
|
-
target && target.updateLayout();
|
|
961
|
+
const {target: target, picker: picker} = this;
|
|
962
|
+
if (Platform.backgrounder) target && target.updateLayout();
|
|
940
963
|
return picker.getByPoint(hitPoint, hitRadius, options);
|
|
941
964
|
}
|
|
965
|
+
hitPoint(hitPoint, hitRadius, options) {
|
|
966
|
+
return this.picker.hitPoint(hitPoint, hitRadius, options);
|
|
967
|
+
}
|
|
942
968
|
getBy(condition, branch, one, options) {
|
|
943
|
-
return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need(
|
|
969
|
+
return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need("find");
|
|
944
970
|
}
|
|
945
971
|
destroy() {
|
|
946
972
|
this.picker.destroy();
|
|
947
|
-
if (this.finder)
|
|
948
|
-
this.finder.destroy();
|
|
973
|
+
if (this.finder) this.finder.destroy();
|
|
949
974
|
}
|
|
950
975
|
}
|
|
951
976
|
|
|
@@ -955,13 +980,22 @@ Object.assign(Creator, {
|
|
|
955
980
|
renderer: (target, canvas, options) => new Renderer(target, canvas, options),
|
|
956
981
|
selector: (target, options) => new Selector(target, options)
|
|
957
982
|
});
|
|
983
|
+
|
|
958
984
|
Platform.layout = Layouter.fullLayout;
|
|
959
985
|
|
|
960
986
|
const PointerEventHelper = {
|
|
961
987
|
convertTouch(e, local) {
|
|
962
988
|
const touch = PointerEventHelper.getTouch(e);
|
|
963
989
|
const base = InteractionHelper.getBase(e);
|
|
964
|
-
return Object.assign(Object.assign({}, base), {
|
|
990
|
+
return Object.assign(Object.assign({}, base), {
|
|
991
|
+
x: local.x,
|
|
992
|
+
y: local.y,
|
|
993
|
+
width: 1,
|
|
994
|
+
height: 1,
|
|
995
|
+
pointerType: "touch",
|
|
996
|
+
multiTouch: e.touches.length > 1,
|
|
997
|
+
pressure: touch.force || 1
|
|
998
|
+
});
|
|
965
999
|
},
|
|
966
1000
|
getTouch(e) {
|
|
967
1001
|
return e.touches[0] || e.changedTouches[0];
|
|
@@ -971,31 +1005,31 @@ const PointerEventHelper = {
|
|
|
971
1005
|
class Interaction extends InteractionBase {
|
|
972
1006
|
__listenEvents() {
|
|
973
1007
|
super.__listenEvents();
|
|
974
|
-
if (this.config.eventer)
|
|
975
|
-
this.config.eventer.receiveEvent = this.receive.bind(this);
|
|
1008
|
+
if (this.config.eventer) this.config.eventer.receiveEvent = this.receive.bind(this);
|
|
976
1009
|
}
|
|
977
1010
|
receive(e) {
|
|
978
1011
|
switch (e.type) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1012
|
+
case "touchstart":
|
|
1013
|
+
this.onTouchStart(e);
|
|
1014
|
+
break;
|
|
1015
|
+
|
|
1016
|
+
case "touchmove":
|
|
1017
|
+
this.onTouchMove(e);
|
|
1018
|
+
break;
|
|
1019
|
+
|
|
1020
|
+
case "touchend":
|
|
1021
|
+
this.onTouchEnd(e);
|
|
1022
|
+
break;
|
|
1023
|
+
|
|
1024
|
+
case "touchcancel":
|
|
1025
|
+
this.onTouchCancel();
|
|
990
1026
|
}
|
|
991
1027
|
}
|
|
992
1028
|
getLocal(clientPoint, updateClient) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
return super.getLocal(clientPoint, updateClient);
|
|
998
|
-
}
|
|
1029
|
+
return isUndefined$1(clientPoint.x) ? super.getLocal(clientPoint, updateClient) : {
|
|
1030
|
+
x: clientPoint.x,
|
|
1031
|
+
y: clientPoint.y
|
|
1032
|
+
};
|
|
999
1033
|
}
|
|
1000
1034
|
getTouches(touches) {
|
|
1001
1035
|
return touches;
|
|
@@ -1007,8 +1041,7 @@ class Interaction extends InteractionBase {
|
|
|
1007
1041
|
}
|
|
1008
1042
|
onTouchMove(e) {
|
|
1009
1043
|
this.multiTouchMove(e);
|
|
1010
|
-
if (this.useMultiTouch)
|
|
1011
|
-
return;
|
|
1044
|
+
if (this.useMultiTouch) return;
|
|
1012
1045
|
const touch = PointerEventHelper.getTouch(e);
|
|
1013
1046
|
this.pointerMove(PointerEventHelper.convertTouch(e, this.getLocal(touch)));
|
|
1014
1047
|
}
|
|
@@ -1021,14 +1054,12 @@ class Interaction extends InteractionBase {
|
|
|
1021
1054
|
this.pointerCancel();
|
|
1022
1055
|
}
|
|
1023
1056
|
multiTouchStart(e) {
|
|
1024
|
-
this.useMultiTouch =
|
|
1057
|
+
this.useMultiTouch = e.touches.length > 1;
|
|
1025
1058
|
this.touches = this.useMultiTouch ? this.getTouches(e.touches) : undefined;
|
|
1026
|
-
if (this.useMultiTouch)
|
|
1027
|
-
this.pointerCancel();
|
|
1059
|
+
if (this.useMultiTouch) this.pointerCancel();
|
|
1028
1060
|
}
|
|
1029
1061
|
multiTouchMove(e) {
|
|
1030
|
-
if (!this.useMultiTouch)
|
|
1031
|
-
return;
|
|
1062
|
+
if (!this.useMultiTouch) return;
|
|
1032
1063
|
if (e.touches.length > 1) {
|
|
1033
1064
|
const touches = this.getTouches(e.touches);
|
|
1034
1065
|
const list = this.getKeepTouchList(this.touches, touches);
|
|
@@ -1048,8 +1079,10 @@ class Interaction extends InteractionBase {
|
|
|
1048
1079
|
const list = [];
|
|
1049
1080
|
old.forEach(from => {
|
|
1050
1081
|
to = touches.find(touch => touch.identifier === from.identifier);
|
|
1051
|
-
if (to)
|
|
1052
|
-
|
|
1082
|
+
if (to) list.push({
|
|
1083
|
+
from: this.getLocal(from),
|
|
1084
|
+
to: this.getLocal(to)
|
|
1085
|
+
});
|
|
1053
1086
|
});
|
|
1054
1087
|
return list;
|
|
1055
1088
|
}
|
|
@@ -1063,21 +1096,18 @@ class Interaction extends InteractionBase {
|
|
|
1063
1096
|
}
|
|
1064
1097
|
|
|
1065
1098
|
function fillText(ui, canvas) {
|
|
1066
|
-
const data = ui.__, { rows, decorationY } = data.__textDrawData;
|
|
1067
|
-
if (data.__isPlacehold && data.placeholderColor)
|
|
1068
|
-
canvas.fillStyle = data.placeholderColor;
|
|
1099
|
+
const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
|
|
1100
|
+
if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
|
|
1069
1101
|
let row;
|
|
1070
1102
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
1071
1103
|
row = rows[i];
|
|
1072
|
-
if (row.text)
|
|
1073
|
-
canvas.fillText(
|
|
1074
|
-
|
|
1075
|
-
row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
|
|
1104
|
+
if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
|
|
1105
|
+
canvas.fillText(charData.char, charData.x, row.y);
|
|
1106
|
+
});
|
|
1076
1107
|
}
|
|
1077
1108
|
if (decorationY) {
|
|
1078
|
-
const { decorationColor, decorationHeight } = data.__textDrawData;
|
|
1079
|
-
if (decorationColor)
|
|
1080
|
-
canvas.fillStyle = decorationColor;
|
|
1109
|
+
const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
|
|
1110
|
+
if (decorationColor) canvas.fillStyle = decorationColor;
|
|
1081
1111
|
rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
1082
1112
|
}
|
|
1083
1113
|
}
|
|
@@ -1086,106 +1116,112 @@ function fill(fill, ui, canvas) {
|
|
|
1086
1116
|
canvas.fillStyle = fill;
|
|
1087
1117
|
fillPathOrText(ui, canvas);
|
|
1088
1118
|
}
|
|
1119
|
+
|
|
1089
1120
|
function fills(fills, ui, canvas) {
|
|
1090
1121
|
let item;
|
|
1091
1122
|
for (let i = 0, len = fills.length; i < len; i++) {
|
|
1092
1123
|
item = fills[i];
|
|
1093
1124
|
if (item.image) {
|
|
1094
|
-
if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
|
|
1095
|
-
continue;
|
|
1125
|
+
if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue;
|
|
1096
1126
|
if (!item.style) {
|
|
1097
|
-
if (!i && item.image.isPlacehold)
|
|
1098
|
-
ui.drawImagePlaceholder(canvas, item.image);
|
|
1127
|
+
if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image);
|
|
1099
1128
|
continue;
|
|
1100
1129
|
}
|
|
1101
1130
|
}
|
|
1102
1131
|
canvas.fillStyle = item.style;
|
|
1103
|
-
if (item.transform) {
|
|
1132
|
+
if (item.transform || item.scaleFixed) {
|
|
1104
1133
|
canvas.save();
|
|
1105
|
-
canvas.transform(item.transform);
|
|
1106
|
-
if (item.
|
|
1107
|
-
|
|
1134
|
+
if (item.transform) canvas.transform(item.transform);
|
|
1135
|
+
if (item.scaleFixed) {
|
|
1136
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
|
|
1137
|
+
if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
|
|
1138
|
+
}
|
|
1139
|
+
if (item.blendMode) canvas.blendMode = item.blendMode;
|
|
1108
1140
|
fillPathOrText(ui, canvas);
|
|
1109
1141
|
canvas.restore();
|
|
1110
|
-
}
|
|
1111
|
-
else {
|
|
1142
|
+
} else {
|
|
1112
1143
|
if (item.blendMode) {
|
|
1113
1144
|
canvas.saveBlendMode(item.blendMode);
|
|
1114
1145
|
fillPathOrText(ui, canvas);
|
|
1115
1146
|
canvas.restoreBlendMode();
|
|
1116
|
-
}
|
|
1117
|
-
else
|
|
1118
|
-
fillPathOrText(ui, canvas);
|
|
1147
|
+
} else fillPathOrText(ui, canvas);
|
|
1119
1148
|
}
|
|
1120
1149
|
}
|
|
1121
1150
|
}
|
|
1151
|
+
|
|
1122
1152
|
function fillPathOrText(ui, canvas) {
|
|
1123
|
-
ui.__.__font ? fillText(ui, canvas) :
|
|
1153
|
+
ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
|
|
1124
1154
|
}
|
|
1125
1155
|
|
|
1126
1156
|
function strokeText(stroke, ui, canvas) {
|
|
1127
1157
|
switch (ui.__.strokeAlign) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1158
|
+
case "center":
|
|
1159
|
+
drawCenter$1(stroke, 1, ui, canvas);
|
|
1160
|
+
break;
|
|
1161
|
+
|
|
1162
|
+
case "inside":
|
|
1163
|
+
drawAlign(stroke, "inside", ui, canvas);
|
|
1164
|
+
break;
|
|
1165
|
+
|
|
1166
|
+
case "outside":
|
|
1167
|
+
ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, "outside", ui, canvas);
|
|
1168
|
+
break;
|
|
1137
1169
|
}
|
|
1138
1170
|
}
|
|
1171
|
+
|
|
1139
1172
|
function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
|
|
1140
1173
|
const data = ui.__;
|
|
1141
|
-
|
|
1142
|
-
|
|
1174
|
+
if (isObject(stroke)) {
|
|
1175
|
+
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
|
|
1176
|
+
} else {
|
|
1177
|
+
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
1178
|
+
drawTextStroke(ui, canvas);
|
|
1179
|
+
}
|
|
1143
1180
|
}
|
|
1181
|
+
|
|
1144
1182
|
function drawAlign(stroke, align, ui, canvas) {
|
|
1145
1183
|
const out = canvas.getSameCanvas(true, true);
|
|
1146
1184
|
out.font = ui.__.__font;
|
|
1147
1185
|
drawCenter$1(stroke, 2, ui, out);
|
|
1148
|
-
out.blendMode = align ===
|
|
1186
|
+
out.blendMode = align === "outside" ? "destination-out" : "destination-in";
|
|
1149
1187
|
fillText(ui, out);
|
|
1150
|
-
out.blendMode =
|
|
1151
|
-
|
|
1188
|
+
out.blendMode = "normal";
|
|
1189
|
+
LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
1152
1190
|
out.recycle(ui.__nowWorld);
|
|
1153
1191
|
}
|
|
1154
|
-
|
|
1155
|
-
if (ui.__worldFlipped || Platform.fullImageShadow)
|
|
1156
|
-
canvas.copyWorldByReset(out, ui.__nowWorld);
|
|
1157
|
-
else
|
|
1158
|
-
canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
|
|
1159
|
-
}
|
|
1192
|
+
|
|
1160
1193
|
function drawTextStroke(ui, canvas) {
|
|
1161
1194
|
let row, data = ui.__.__textDrawData;
|
|
1162
|
-
const { rows, decorationY } = data;
|
|
1195
|
+
const {rows: rows, decorationY: decorationY} = data;
|
|
1163
1196
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
1164
1197
|
row = rows[i];
|
|
1165
|
-
if (row.text)
|
|
1166
|
-
canvas.strokeText(
|
|
1167
|
-
|
|
1168
|
-
row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
|
|
1198
|
+
if (row.text) canvas.strokeText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
|
|
1199
|
+
canvas.strokeText(charData.char, charData.x, row.y);
|
|
1200
|
+
});
|
|
1169
1201
|
}
|
|
1170
1202
|
if (decorationY) {
|
|
1171
|
-
const { decorationHeight
|
|
1203
|
+
const {decorationHeight: decorationHeight} = data;
|
|
1172
1204
|
rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
1173
1205
|
}
|
|
1174
1206
|
}
|
|
1175
|
-
|
|
1207
|
+
|
|
1208
|
+
function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
1176
1209
|
let item;
|
|
1210
|
+
const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
|
|
1211
|
+
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
|
|
1177
1212
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
1178
1213
|
item = strokes[i];
|
|
1179
|
-
if (item.image && PaintImage.checkImage(ui, canvas, item, false))
|
|
1180
|
-
continue;
|
|
1214
|
+
if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue;
|
|
1181
1215
|
if (item.style) {
|
|
1182
|
-
|
|
1216
|
+
if (__hasMultiStrokeStyle) {
|
|
1217
|
+
const {strokeStyle: strokeStyle} = item;
|
|
1218
|
+
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
|
|
1219
|
+
} else canvas.strokeStyle = item.style;
|
|
1183
1220
|
if (item.blendMode) {
|
|
1184
1221
|
canvas.saveBlendMode(item.blendMode);
|
|
1185
1222
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
1186
1223
|
canvas.restoreBlendMode();
|
|
1187
|
-
}
|
|
1188
|
-
else {
|
|
1224
|
+
} else {
|
|
1189
1225
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
1190
1226
|
}
|
|
1191
1227
|
}
|
|
@@ -1194,77 +1230,81 @@ function drawStrokesStyle(strokes, isText, ui, canvas) {
|
|
|
1194
1230
|
|
|
1195
1231
|
function stroke(stroke, ui, canvas) {
|
|
1196
1232
|
const data = ui.__;
|
|
1197
|
-
if (!data.__strokeWidth)
|
|
1198
|
-
return;
|
|
1233
|
+
if (!data.__strokeWidth) return;
|
|
1199
1234
|
if (data.__font) {
|
|
1200
1235
|
strokeText(stroke, ui, canvas);
|
|
1201
|
-
}
|
|
1202
|
-
else {
|
|
1236
|
+
} else {
|
|
1203
1237
|
switch (data.strokeAlign) {
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1238
|
+
case "center":
|
|
1239
|
+
drawCenter(stroke, 1, ui, canvas);
|
|
1240
|
+
break;
|
|
1241
|
+
|
|
1242
|
+
case "inside":
|
|
1243
|
+
drawInside(stroke, ui, canvas);
|
|
1244
|
+
break;
|
|
1245
|
+
|
|
1246
|
+
case "outside":
|
|
1247
|
+
drawOutside(stroke, ui, canvas);
|
|
1248
|
+
break;
|
|
1213
1249
|
}
|
|
1214
1250
|
}
|
|
1215
1251
|
}
|
|
1252
|
+
|
|
1216
1253
|
function strokes(strokes, ui, canvas) {
|
|
1217
1254
|
stroke(strokes, ui, canvas);
|
|
1218
1255
|
}
|
|
1256
|
+
|
|
1219
1257
|
function drawCenter(stroke, strokeWidthScale, ui, canvas) {
|
|
1220
1258
|
const data = ui.__;
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1259
|
+
if (isObject(stroke)) {
|
|
1260
|
+
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
|
|
1261
|
+
} else {
|
|
1262
|
+
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
1263
|
+
canvas.stroke();
|
|
1264
|
+
}
|
|
1265
|
+
if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas);
|
|
1225
1266
|
}
|
|
1267
|
+
|
|
1226
1268
|
function drawInside(stroke, ui, canvas) {
|
|
1227
1269
|
canvas.save();
|
|
1228
1270
|
canvas.clipUI(ui);
|
|
1229
1271
|
drawCenter(stroke, 2, ui, canvas);
|
|
1230
1272
|
canvas.restore();
|
|
1231
1273
|
}
|
|
1274
|
+
|
|
1232
1275
|
function drawOutside(stroke, ui, canvas) {
|
|
1233
1276
|
const data = ui.__;
|
|
1234
1277
|
if (data.__fillAfterStroke) {
|
|
1235
1278
|
drawCenter(stroke, 2, ui, canvas);
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
const { renderBounds } = ui.__layout;
|
|
1279
|
+
} else {
|
|
1280
|
+
const {renderBounds: renderBounds} = ui.__layout;
|
|
1239
1281
|
const out = canvas.getSameCanvas(true, true);
|
|
1240
1282
|
ui.__drawRenderPath(out);
|
|
1241
1283
|
drawCenter(stroke, 2, ui, out);
|
|
1242
1284
|
out.clipUI(data);
|
|
1243
1285
|
out.clearWorld(renderBounds);
|
|
1244
|
-
|
|
1286
|
+
LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
1245
1287
|
out.recycle(ui.__nowWorld);
|
|
1246
1288
|
}
|
|
1247
1289
|
}
|
|
1248
1290
|
|
|
1249
|
-
const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
|
|
1291
|
+
const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = BoundsHelper;
|
|
1292
|
+
|
|
1250
1293
|
function shape(ui, current, options) {
|
|
1251
1294
|
const canvas = current.getSameCanvas();
|
|
1252
1295
|
const nowWorld = ui.__nowWorld;
|
|
1253
|
-
let bounds, fitMatrix, shapeBounds, worldCanvas;
|
|
1254
|
-
let { scaleX, scaleY } = nowWorld;
|
|
1255
|
-
if (scaleX < 0)
|
|
1256
|
-
|
|
1257
|
-
if (scaleY < 0)
|
|
1258
|
-
scaleY = -scaleY;
|
|
1296
|
+
let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
|
|
1297
|
+
let {scaleX: scaleX, scaleY: scaleY} = nowWorld;
|
|
1298
|
+
if (scaleX < 0) scaleX = -scaleX;
|
|
1299
|
+
if (scaleY < 0) scaleY = -scaleY;
|
|
1259
1300
|
if (current.bounds.includes(nowWorld)) {
|
|
1260
1301
|
worldCanvas = canvas;
|
|
1261
1302
|
bounds = shapeBounds = nowWorld;
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
const
|
|
1265
|
-
const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
|
|
1303
|
+
} else {
|
|
1304
|
+
const {renderShapeSpread: spread} = ui.__layout;
|
|
1305
|
+
const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : current.bounds, nowWorld);
|
|
1266
1306
|
fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
|
|
1267
|
-
let {
|
|
1307
|
+
let {a: fitScaleX, d: fitScaleY} = fitMatrix;
|
|
1268
1308
|
if (fitMatrix.a < 1) {
|
|
1269
1309
|
worldCanvas = current.getSameCanvas();
|
|
1270
1310
|
ui.__renderShape(worldCanvas, options);
|
|
@@ -1273,215 +1313,262 @@ function shape(ui, current, options) {
|
|
|
1273
1313
|
}
|
|
1274
1314
|
shapeBounds = getOuterOf(nowWorld, fitMatrix);
|
|
1275
1315
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
fitMatrix
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1316
|
+
const userMatrix = options.matrix;
|
|
1317
|
+
if (userMatrix) {
|
|
1318
|
+
matrix = new Matrix(fitMatrix);
|
|
1319
|
+
matrix.multiply(userMatrix);
|
|
1320
|
+
fitScaleX *= userMatrix.scaleX;
|
|
1321
|
+
fitScaleY *= userMatrix.scaleY;
|
|
1322
|
+
} else matrix = fitMatrix;
|
|
1323
|
+
matrix.withScale(fitScaleX, fitScaleY);
|
|
1324
|
+
options = Object.assign(Object.assign({}, options), {
|
|
1325
|
+
matrix: matrix
|
|
1326
|
+
});
|
|
1283
1327
|
}
|
|
1284
1328
|
ui.__renderShape(canvas, options);
|
|
1285
1329
|
return {
|
|
1286
|
-
canvas
|
|
1287
|
-
|
|
1330
|
+
canvas: canvas,
|
|
1331
|
+
matrix: matrix,
|
|
1332
|
+
fitMatrix: fitMatrix,
|
|
1333
|
+
bounds: bounds,
|
|
1334
|
+
worldCanvas: worldCanvas,
|
|
1335
|
+
shapeBounds: shapeBounds,
|
|
1336
|
+
scaleX: scaleX,
|
|
1337
|
+
scaleY: scaleY
|
|
1288
1338
|
};
|
|
1289
1339
|
}
|
|
1290
1340
|
|
|
1291
1341
|
let recycleMap;
|
|
1292
|
-
|
|
1342
|
+
|
|
1343
|
+
const {stintSet: stintSet} = DataHelper, {hasTransparent: hasTransparent$1} = ColorConvert;
|
|
1344
|
+
|
|
1293
1345
|
function compute(attrName, ui) {
|
|
1294
1346
|
const data = ui.__, leafPaints = [];
|
|
1295
1347
|
let paints = data.__input[attrName], isAlphaPixel, isTransparent;
|
|
1296
|
-
if (!(paints
|
|
1297
|
-
paints = [paints];
|
|
1348
|
+
if (!isArray(paints)) paints = [ paints ];
|
|
1298
1349
|
recycleMap = PaintImage.recycleImage(attrName, data);
|
|
1350
|
+
let maxChildStrokeWidth;
|
|
1299
1351
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
1300
|
-
(item = getLeafPaint(attrName, paints[i], ui))
|
|
1352
|
+
if (item = getLeafPaint(attrName, paints[i], ui)) {
|
|
1353
|
+
leafPaints.push(item);
|
|
1354
|
+
if (item.strokeStyle) {
|
|
1355
|
+
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
1356
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1301
1359
|
}
|
|
1302
|
-
data[
|
|
1360
|
+
data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
1303
1361
|
if (leafPaints.length) {
|
|
1304
1362
|
if (leafPaints.every(item => item.isTransparent)) {
|
|
1305
|
-
if (leafPaints.some(item => item.image))
|
|
1306
|
-
isAlphaPixel = true;
|
|
1363
|
+
if (leafPaints.some(item => item.image)) isAlphaPixel = true;
|
|
1307
1364
|
isTransparent = true;
|
|
1308
1365
|
}
|
|
1309
1366
|
}
|
|
1310
|
-
if (attrName ===
|
|
1311
|
-
stintSet(data,
|
|
1312
|
-
stintSet(data,
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
stintSet(data,
|
|
1316
|
-
stintSet(data,
|
|
1367
|
+
if (attrName === "fill") {
|
|
1368
|
+
stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
|
|
1369
|
+
stintSet(data, "__isTransparentFill", isTransparent);
|
|
1370
|
+
} else {
|
|
1371
|
+
stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
|
|
1372
|
+
stintSet(data, "__isTransparentStroke", isTransparent);
|
|
1373
|
+
stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
|
|
1317
1374
|
}
|
|
1318
1375
|
}
|
|
1376
|
+
|
|
1319
1377
|
function getLeafPaint(attrName, paint, ui) {
|
|
1320
|
-
if (
|
|
1321
|
-
return undefined;
|
|
1378
|
+
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
1322
1379
|
let data;
|
|
1323
|
-
const { boxBounds
|
|
1380
|
+
const {boxBounds: boxBounds} = ui.__layout;
|
|
1324
1381
|
switch (paint.type) {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1382
|
+
case "image":
|
|
1383
|
+
data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
|
|
1384
|
+
break;
|
|
1385
|
+
|
|
1386
|
+
case "linear":
|
|
1387
|
+
data = PaintGradient.linearGradient(paint, boxBounds);
|
|
1388
|
+
break;
|
|
1389
|
+
|
|
1390
|
+
case "radial":
|
|
1391
|
+
data = PaintGradient.radialGradient(paint, boxBounds);
|
|
1392
|
+
break;
|
|
1393
|
+
|
|
1394
|
+
case "angular":
|
|
1395
|
+
data = PaintGradient.conicGradient(paint, boxBounds);
|
|
1396
|
+
break;
|
|
1397
|
+
|
|
1398
|
+
case "solid":
|
|
1399
|
+
const {type: type, color: color, opacity: opacity} = paint;
|
|
1400
|
+
data = {
|
|
1401
|
+
type: type,
|
|
1402
|
+
style: ColorConvert.string(color, opacity)
|
|
1403
|
+
};
|
|
1404
|
+
break;
|
|
1405
|
+
|
|
1406
|
+
default:
|
|
1407
|
+
if (!isUndefined(paint.r)) data = {
|
|
1408
|
+
type: "solid",
|
|
1409
|
+
style: ColorConvert.string(paint)
|
|
1410
|
+
};
|
|
1344
1411
|
}
|
|
1345
1412
|
if (data) {
|
|
1346
|
-
if (
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
data.
|
|
1413
|
+
if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
|
|
1414
|
+
if (paint.style) {
|
|
1415
|
+
if (paint.style.strokeWidth === 0) return undefined;
|
|
1416
|
+
data.strokeStyle = paint.style;
|
|
1417
|
+
}
|
|
1418
|
+
if (paint.editing) data.editing = paint.editing;
|
|
1419
|
+
if (paint.blendMode) data.blendMode = paint.blendMode;
|
|
1350
1420
|
}
|
|
1351
1421
|
return data;
|
|
1352
1422
|
}
|
|
1353
1423
|
|
|
1354
1424
|
const PaintModule = {
|
|
1355
|
-
compute,
|
|
1356
|
-
fill,
|
|
1357
|
-
fills,
|
|
1358
|
-
fillPathOrText,
|
|
1359
|
-
fillText,
|
|
1360
|
-
stroke,
|
|
1361
|
-
strokes,
|
|
1362
|
-
strokeText,
|
|
1363
|
-
drawTextStroke,
|
|
1364
|
-
shape
|
|
1425
|
+
compute: compute,
|
|
1426
|
+
fill: fill,
|
|
1427
|
+
fills: fills,
|
|
1428
|
+
fillPathOrText: fillPathOrText,
|
|
1429
|
+
fillText: fillText,
|
|
1430
|
+
stroke: stroke,
|
|
1431
|
+
strokes: strokes,
|
|
1432
|
+
strokeText: strokeText,
|
|
1433
|
+
drawTextStroke: drawTextStroke,
|
|
1434
|
+
shape: shape
|
|
1365
1435
|
};
|
|
1366
1436
|
|
|
1367
|
-
let origin = {};
|
|
1368
|
-
|
|
1437
|
+
let origin = {}, tempMatrix = getMatrixData();
|
|
1438
|
+
|
|
1439
|
+
const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
|
|
1440
|
+
|
|
1369
1441
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1370
1442
|
const transform = get$3();
|
|
1371
1443
|
translate$1(transform, box.x + x, box.y + y);
|
|
1372
1444
|
scaleHelper(transform, scaleX, scaleY);
|
|
1373
|
-
if (rotation)
|
|
1374
|
-
|
|
1445
|
+
if (rotation) rotateOfOuter$1(transform, {
|
|
1446
|
+
x: box.x + box.width / 2,
|
|
1447
|
+
y: box.y + box.height / 2
|
|
1448
|
+
}, rotation);
|
|
1375
1449
|
data.transform = transform;
|
|
1376
1450
|
}
|
|
1377
|
-
|
|
1451
|
+
|
|
1452
|
+
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1378
1453
|
const transform = get$3();
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
scaleHelper(transform, scaleX, scaleY);
|
|
1385
|
-
translate$1(transform, box.x + x, box.y + y);
|
|
1454
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1455
|
+
if (clipSize) {
|
|
1456
|
+
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1457
|
+
multiplyParent(transform, tempMatrix);
|
|
1458
|
+
}
|
|
1386
1459
|
data.transform = transform;
|
|
1387
1460
|
}
|
|
1388
|
-
|
|
1461
|
+
|
|
1462
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
|
|
1389
1463
|
const transform = get$3();
|
|
1390
|
-
if (
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1464
|
+
if (freeTransform) {
|
|
1465
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1466
|
+
} else {
|
|
1467
|
+
if (rotation) {
|
|
1468
|
+
if (align === "center") {
|
|
1469
|
+
rotateOfOuter$1(transform, {
|
|
1470
|
+
x: width / 2,
|
|
1471
|
+
y: height / 2
|
|
1472
|
+
}, rotation);
|
|
1473
|
+
} else {
|
|
1474
|
+
rotate(transform, rotation);
|
|
1475
|
+
switch (rotation) {
|
|
1476
|
+
case 90:
|
|
1398
1477
|
translate$1(transform, height, 0);
|
|
1399
1478
|
break;
|
|
1400
|
-
|
|
1479
|
+
|
|
1480
|
+
case 180:
|
|
1401
1481
|
translate$1(transform, width, height);
|
|
1402
1482
|
break;
|
|
1403
|
-
|
|
1483
|
+
|
|
1484
|
+
case 270:
|
|
1404
1485
|
translate$1(transform, 0, width);
|
|
1405
1486
|
break;
|
|
1487
|
+
}
|
|
1406
1488
|
}
|
|
1407
1489
|
}
|
|
1490
|
+
origin.x = box.x + x;
|
|
1491
|
+
origin.y = box.y + y;
|
|
1492
|
+
translate$1(transform, origin.x, origin.y);
|
|
1493
|
+
if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1408
1494
|
}
|
|
1409
|
-
origin.x = box.x + x;
|
|
1410
|
-
origin.y = box.y + y;
|
|
1411
|
-
translate$1(transform, origin.x, origin.y);
|
|
1412
|
-
if (scaleX)
|
|
1413
|
-
scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1414
1495
|
data.transform = transform;
|
|
1415
1496
|
}
|
|
1416
1497
|
|
|
1417
|
-
|
|
1418
|
-
|
|
1498
|
+
function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
|
|
1499
|
+
if (rotation) rotate(transform, rotation);
|
|
1500
|
+
if (skew) skewHelper(transform, skew.x, skew.y);
|
|
1501
|
+
if (scaleX) scaleHelper(transform, scaleX, scaleY);
|
|
1502
|
+
translate$1(transform, box.x + x, box.y + y);
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
const {get: get$2, translate: translate} = MatrixHelper;
|
|
1506
|
+
|
|
1507
|
+
const tempBox = new Bounds;
|
|
1508
|
+
|
|
1419
1509
|
const tempScaleData = {};
|
|
1510
|
+
|
|
1420
1511
|
const tempImage = {};
|
|
1512
|
+
|
|
1421
1513
|
function createData(leafPaint, image, paint, box) {
|
|
1422
|
-
const { changeful, sync,
|
|
1423
|
-
if (changeful)
|
|
1424
|
-
|
|
1425
|
-
if (
|
|
1426
|
-
leafPaint.sync = sync;
|
|
1427
|
-
if (editing)
|
|
1428
|
-
leafPaint.editing = editing;
|
|
1514
|
+
const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
|
|
1515
|
+
if (changeful) leafPaint.changeful = changeful;
|
|
1516
|
+
if (sync) leafPaint.sync = sync;
|
|
1517
|
+
if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
|
|
1429
1518
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1430
1519
|
}
|
|
1520
|
+
|
|
1431
1521
|
function getPatternData(paint, box, image) {
|
|
1432
|
-
if (paint.padding)
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
let { width, height } = image;
|
|
1437
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
|
|
1522
|
+
if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
|
|
1523
|
+
if (paint.mode === "strench") paint.mode = "stretch";
|
|
1524
|
+
let {width: width, height: height} = image;
|
|
1525
|
+
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} = paint;
|
|
1438
1526
|
const sameBox = box.width === width && box.height === height;
|
|
1439
|
-
const data = {
|
|
1440
|
-
|
|
1527
|
+
const data = {
|
|
1528
|
+
mode: mode
|
|
1529
|
+
};
|
|
1530
|
+
const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
|
|
1441
1531
|
BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
|
|
1442
1532
|
let scaleX, scaleY;
|
|
1443
|
-
if (!mode || mode ===
|
|
1533
|
+
if (!mode || mode === "cover" || mode === "fit") {
|
|
1444
1534
|
if (!sameBox || rotation) {
|
|
1445
|
-
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !==
|
|
1535
|
+
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
|
|
1446
1536
|
BoundsHelper.put(box, image, align, scaleX, false, tempImage);
|
|
1447
1537
|
BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1448
1538
|
}
|
|
1449
|
-
}
|
|
1450
|
-
else {
|
|
1539
|
+
} else {
|
|
1451
1540
|
if (scale || size) {
|
|
1452
1541
|
MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1453
1542
|
scaleX = tempScaleData.scaleX;
|
|
1454
1543
|
scaleY = tempScaleData.scaleY;
|
|
1455
1544
|
}
|
|
1456
|
-
if (align) {
|
|
1457
|
-
if (scaleX)
|
|
1458
|
-
|
|
1459
|
-
AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1545
|
+
if (align || gap || repeat) {
|
|
1546
|
+
if (scaleX) BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1547
|
+
if (align) AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
|
|
1460
1548
|
}
|
|
1461
1549
|
}
|
|
1462
|
-
if (offset)
|
|
1463
|
-
PointHelper.move(tempImage, offset);
|
|
1550
|
+
if (offset) PointHelper.move(tempImage, offset);
|
|
1464
1551
|
switch (mode) {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1552
|
+
case "stretch":
|
|
1553
|
+
if (!sameBox) width = box.width, height = box.height;
|
|
1554
|
+
break;
|
|
1555
|
+
|
|
1556
|
+
case "normal":
|
|
1557
|
+
case "clip":
|
|
1558
|
+
if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
|
|
1559
|
+
break;
|
|
1560
|
+
|
|
1561
|
+
case "repeat":
|
|
1562
|
+
if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
|
|
1563
|
+
if (!repeat) data.repeat = "repeat";
|
|
1564
|
+
const count = isObject(repeat);
|
|
1565
|
+
if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
|
|
1566
|
+
break;
|
|
1567
|
+
|
|
1568
|
+
case "fit":
|
|
1569
|
+
case "cover":
|
|
1570
|
+
default:
|
|
1571
|
+
if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
|
|
1485
1572
|
}
|
|
1486
1573
|
if (!data.transform) {
|
|
1487
1574
|
if (box.x || box.y) {
|
|
@@ -1489,49 +1576,69 @@ function getPatternData(paint, box, image) {
|
|
|
1489
1576
|
translate(data.transform, box.x, box.y);
|
|
1490
1577
|
}
|
|
1491
1578
|
}
|
|
1492
|
-
if (scaleX && mode !==
|
|
1579
|
+
if (scaleX && mode !== "stretch") {
|
|
1493
1580
|
data.scaleX = scaleX;
|
|
1494
1581
|
data.scaleY = scaleY;
|
|
1495
1582
|
}
|
|
1496
1583
|
data.width = width;
|
|
1497
1584
|
data.height = height;
|
|
1498
|
-
if (opacity)
|
|
1499
|
-
|
|
1500
|
-
if (
|
|
1501
|
-
data.filters = filters;
|
|
1502
|
-
if (repeat)
|
|
1503
|
-
data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
|
|
1585
|
+
if (opacity) data.opacity = opacity;
|
|
1586
|
+
if (filters) data.filters = filters;
|
|
1587
|
+
if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
|
|
1504
1588
|
return data;
|
|
1505
1589
|
}
|
|
1506
1590
|
|
|
1507
|
-
|
|
1508
|
-
|
|
1591
|
+
function getGapData(gap, repeat, width, height, box) {
|
|
1592
|
+
let xGap, yGap;
|
|
1593
|
+
if (isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
|
|
1594
|
+
return {
|
|
1595
|
+
x: getGapValue(xGap, width, box.width, repeat && repeat.x),
|
|
1596
|
+
y: getGapValue(yGap, height, box.height, repeat && repeat.y)
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
function getGapValue(gap, size, totalSize, rows) {
|
|
1601
|
+
const auto = isString(gap) || rows;
|
|
1602
|
+
const remain = rows ? totalSize - rows * size : totalSize % size;
|
|
1603
|
+
const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
|
|
1604
|
+
return gap === "auto" ? value < 0 ? 0 : value : value;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
let cache, box = new Bounds;
|
|
1608
|
+
|
|
1609
|
+
const {isSame: isSame} = BoundsHelper;
|
|
1610
|
+
|
|
1509
1611
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1510
1612
|
let leafPaint, event;
|
|
1511
1613
|
const image = ImageManager.get(paint);
|
|
1512
1614
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1513
1615
|
leafPaint = cache.leafPaint;
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1616
|
+
} else {
|
|
1617
|
+
leafPaint = {
|
|
1618
|
+
type: paint.type,
|
|
1619
|
+
image: image
|
|
1620
|
+
};
|
|
1621
|
+
if (image.hasAlphaPixel) leafPaint.isTransparent = true;
|
|
1622
|
+
cache = image.use > 1 ? {
|
|
1623
|
+
leafPaint: leafPaint,
|
|
1624
|
+
paint: paint,
|
|
1625
|
+
boxBounds: box.set(boxBounds)
|
|
1626
|
+
} : null;
|
|
1627
|
+
}
|
|
1628
|
+
if (firstUse || image.loading) event = {
|
|
1629
|
+
image: image,
|
|
1630
|
+
attrName: attrName,
|
|
1631
|
+
attrValue: paint
|
|
1632
|
+
};
|
|
1523
1633
|
if (image.ready) {
|
|
1524
1634
|
checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
|
|
1525
1635
|
if (firstUse) {
|
|
1526
1636
|
onLoad(ui, event);
|
|
1527
1637
|
onLoadSuccess(ui, event);
|
|
1528
1638
|
}
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
onLoadError(ui, event, image.error);
|
|
1533
|
-
}
|
|
1534
|
-
else {
|
|
1639
|
+
} else if (image.error) {
|
|
1640
|
+
if (firstUse) onLoadError(ui, event, image.error);
|
|
1641
|
+
} else {
|
|
1535
1642
|
if (firstUse) {
|
|
1536
1643
|
ignoreRender(ui, true);
|
|
1537
1644
|
onLoad(ui, event);
|
|
@@ -1540,107 +1647,105 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1540
1647
|
ignoreRender(ui, false);
|
|
1541
1648
|
if (!ui.destroyed) {
|
|
1542
1649
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
1543
|
-
if (image.hasAlphaPixel)
|
|
1544
|
-
|
|
1545
|
-
ui.forceUpdate('surface');
|
|
1650
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
|
|
1651
|
+
ui.forceUpdate("surface");
|
|
1546
1652
|
}
|
|
1547
1653
|
onLoadSuccess(ui, event);
|
|
1548
1654
|
}
|
|
1549
1655
|
leafPaint.loadId = undefined;
|
|
1550
|
-
},
|
|
1656
|
+
}, error => {
|
|
1551
1657
|
ignoreRender(ui, false);
|
|
1552
1658
|
onLoadError(ui, event, error);
|
|
1553
1659
|
leafPaint.loadId = undefined;
|
|
1554
1660
|
});
|
|
1555
1661
|
if (ui.placeholderColor) {
|
|
1556
|
-
if (!ui.placeholderDelay)
|
|
1557
|
-
image.
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
ui.forceUpdate('surface');
|
|
1563
|
-
}
|
|
1564
|
-
}, ui.placeholderDelay);
|
|
1662
|
+
if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
|
|
1663
|
+
if (!image.ready) {
|
|
1664
|
+
image.isPlacehold = true;
|
|
1665
|
+
ui.forceUpdate("surface");
|
|
1666
|
+
}
|
|
1667
|
+
}, ui.placeholderDelay);
|
|
1565
1668
|
}
|
|
1566
1669
|
}
|
|
1567
1670
|
return leafPaint;
|
|
1568
1671
|
}
|
|
1672
|
+
|
|
1569
1673
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1570
|
-
if (attrName ===
|
|
1674
|
+
if (attrName === "fill" && !ui.__.__naturalWidth) {
|
|
1571
1675
|
const data = ui.__;
|
|
1572
1676
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1573
1677
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1574
1678
|
if (data.__autoSide) {
|
|
1575
|
-
ui.forceUpdate(
|
|
1679
|
+
ui.forceUpdate("width");
|
|
1576
1680
|
if (ui.__proxyData) {
|
|
1577
|
-
ui.setProxyAttr(
|
|
1578
|
-
ui.setProxyAttr(
|
|
1681
|
+
ui.setProxyAttr("width", data.width);
|
|
1682
|
+
ui.setProxyAttr("height", data.height);
|
|
1579
1683
|
}
|
|
1580
1684
|
return false;
|
|
1581
1685
|
}
|
|
1582
1686
|
}
|
|
1583
|
-
if (!leafPaint.data)
|
|
1584
|
-
createData(leafPaint, image, paint, boxBounds);
|
|
1687
|
+
if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
|
|
1585
1688
|
return true;
|
|
1586
1689
|
}
|
|
1690
|
+
|
|
1587
1691
|
function onLoad(ui, event) {
|
|
1588
1692
|
emit(ui, ImageEvent.LOAD, event);
|
|
1589
1693
|
}
|
|
1694
|
+
|
|
1590
1695
|
function onLoadSuccess(ui, event) {
|
|
1591
1696
|
emit(ui, ImageEvent.LOADED, event);
|
|
1592
1697
|
}
|
|
1698
|
+
|
|
1593
1699
|
function onLoadError(ui, event, error) {
|
|
1594
1700
|
event.error = error;
|
|
1595
|
-
ui.forceUpdate(
|
|
1701
|
+
ui.forceUpdate("surface");
|
|
1596
1702
|
emit(ui, ImageEvent.ERROR, event);
|
|
1597
1703
|
}
|
|
1704
|
+
|
|
1598
1705
|
function emit(ui, type, data) {
|
|
1599
|
-
if (ui.hasEvent(type))
|
|
1600
|
-
ui.emitEvent(new ImageEvent(type, data));
|
|
1706
|
+
if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
|
|
1601
1707
|
}
|
|
1708
|
+
|
|
1602
1709
|
function ignoreRender(ui, value) {
|
|
1603
|
-
const { leafer
|
|
1604
|
-
if (leafer && leafer.viewReady)
|
|
1605
|
-
leafer.renderer.ignore = value;
|
|
1710
|
+
const {leafer: leafer} = ui;
|
|
1711
|
+
if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
|
|
1606
1712
|
}
|
|
1607
1713
|
|
|
1608
|
-
const {
|
|
1609
|
-
|
|
1714
|
+
const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
|
|
1715
|
+
|
|
1716
|
+
const {floor: floor, max: max, abs: abs} = Math;
|
|
1717
|
+
|
|
1610
1718
|
function createPattern(ui, paint, pixelRatio) {
|
|
1611
|
-
let { scaleX, scaleY } =
|
|
1612
|
-
const id = scaleX +
|
|
1719
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1720
|
+
const id = scaleX + "-" + scaleY + "-" + pixelRatio;
|
|
1613
1721
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1614
|
-
|
|
1615
|
-
scaleY =
|
|
1616
|
-
|
|
1617
|
-
|
|
1722
|
+
const {image: image, data: data} = paint;
|
|
1723
|
+
let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
|
|
1724
|
+
scaleX *= pixelRatio;
|
|
1725
|
+
scaleY *= pixelRatio;
|
|
1726
|
+
const xGap = gap && gap.x * scaleX;
|
|
1727
|
+
const yGap = gap && gap.y * scaleY;
|
|
1618
1728
|
if (sx) {
|
|
1619
|
-
sx = abs
|
|
1620
|
-
sy = abs
|
|
1729
|
+
sx = abs(sx);
|
|
1730
|
+
sy = abs(sy);
|
|
1621
1731
|
imageMatrix = get$1();
|
|
1622
1732
|
copy$1(imageMatrix, transform);
|
|
1623
1733
|
scale(imageMatrix, 1 / sx, 1 / sy);
|
|
1624
1734
|
scaleX *= sx;
|
|
1625
1735
|
scaleY *= sy;
|
|
1626
1736
|
}
|
|
1627
|
-
scaleX *= pixelRatio;
|
|
1628
|
-
scaleY *= pixelRatio;
|
|
1629
1737
|
width *= scaleX;
|
|
1630
1738
|
height *= scaleY;
|
|
1631
1739
|
const size = width * height;
|
|
1632
1740
|
if (!repeat) {
|
|
1633
|
-
if (size > Platform.image.maxCacheSize)
|
|
1634
|
-
return false;
|
|
1741
|
+
if (size > Platform.image.maxCacheSize) return false;
|
|
1635
1742
|
}
|
|
1636
1743
|
let maxSize = Platform.image.maxPatternSize;
|
|
1637
1744
|
if (!image.isSVG) {
|
|
1638
1745
|
const imageSize = image.width * image.height;
|
|
1639
|
-
if (maxSize > imageSize)
|
|
1640
|
-
maxSize = imageSize;
|
|
1746
|
+
if (maxSize > imageSize) maxSize = imageSize;
|
|
1641
1747
|
}
|
|
1642
|
-
if (size > maxSize)
|
|
1643
|
-
imageScale = Math.sqrt(size / maxSize);
|
|
1748
|
+
if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
|
|
1644
1749
|
if (imageScale) {
|
|
1645
1750
|
scaleX /= imageScale;
|
|
1646
1751
|
scaleY /= imageScale;
|
|
@@ -1654,94 +1759,95 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1654
1759
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1655
1760
|
if (!imageMatrix) {
|
|
1656
1761
|
imageMatrix = get$1();
|
|
1657
|
-
if (transform)
|
|
1658
|
-
copy$1(imageMatrix, transform);
|
|
1762
|
+
if (transform) copy$1(imageMatrix, transform);
|
|
1659
1763
|
}
|
|
1660
1764
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1661
1765
|
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1766
|
+
if (imageMatrix) {
|
|
1767
|
+
const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
|
|
1768
|
+
scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
|
|
1769
|
+
}
|
|
1770
|
+
const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
|
|
1771
|
+
const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
|
|
1664
1772
|
paint.style = pattern;
|
|
1665
1773
|
paint.patternId = id;
|
|
1666
1774
|
return true;
|
|
1667
|
-
}
|
|
1668
|
-
else {
|
|
1775
|
+
} else {
|
|
1669
1776
|
return false;
|
|
1670
1777
|
}
|
|
1671
1778
|
}
|
|
1672
1779
|
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
function
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1780
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1781
|
+
function adopt(value) {
|
|
1782
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1783
|
+
resolve(value);
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1787
|
+
function fulfilled(value) {
|
|
1788
|
+
try {
|
|
1789
|
+
step(generator.next(value));
|
|
1790
|
+
} catch (e) {
|
|
1791
|
+
reject(e);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
function rejected(value) {
|
|
1795
|
+
try {
|
|
1796
|
+
step(generator["throw"](value));
|
|
1797
|
+
} catch (e) {
|
|
1798
|
+
reject(e);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
function step(result) {
|
|
1802
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1803
|
+
}
|
|
1804
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
1809
|
+
var e = new Error(message);
|
|
1810
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1703
1811
|
};
|
|
1704
1812
|
|
|
1705
|
-
const { abs } = Math;
|
|
1706
1813
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1707
|
-
const { scaleX, scaleY } =
|
|
1708
|
-
const { pixelRatio
|
|
1709
|
-
if (!data ||
|
|
1814
|
+
const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1815
|
+
const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
|
|
1816
|
+
if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !Export.running) {
|
|
1710
1817
|
return false;
|
|
1711
|
-
}
|
|
1712
|
-
else {
|
|
1818
|
+
} else {
|
|
1713
1819
|
if (allowDraw) {
|
|
1714
1820
|
if (data.repeat) {
|
|
1715
1821
|
allowDraw = false;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
height *= abs(scaleY) * pixelRatio;
|
|
1822
|
+
} else {
|
|
1823
|
+
if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
|
|
1824
|
+
let {width: width, height: height} = data;
|
|
1825
|
+
width *= scaleX * pixelRatio;
|
|
1826
|
+
height *= scaleY * pixelRatio;
|
|
1722
1827
|
if (data.scaleX) {
|
|
1723
1828
|
width *= data.scaleX;
|
|
1724
1829
|
height *= data.scaleY;
|
|
1725
1830
|
}
|
|
1726
|
-
allowDraw =
|
|
1831
|
+
allowDraw = width * height > Platform.image.maxCacheSize;
|
|
1727
1832
|
}
|
|
1728
1833
|
}
|
|
1729
1834
|
}
|
|
1730
1835
|
if (allowDraw) {
|
|
1836
|
+
if (ui.__.__isFastShadow) {
|
|
1837
|
+
canvas.fillStyle = paint.style || "#000";
|
|
1838
|
+
canvas.fill();
|
|
1839
|
+
}
|
|
1731
1840
|
drawImage(ui, canvas, paint, data);
|
|
1732
1841
|
return true;
|
|
1733
|
-
}
|
|
1734
|
-
else {
|
|
1842
|
+
} else {
|
|
1735
1843
|
if (!paint.style || paint.sync || Export.running) {
|
|
1736
1844
|
createPattern(ui, paint, pixelRatio);
|
|
1737
|
-
}
|
|
1738
|
-
else {
|
|
1845
|
+
} else {
|
|
1739
1846
|
if (!paint.patternTask) {
|
|
1740
|
-
paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*
|
|
1847
|
+
paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
|
|
1741
1848
|
paint.patternTask = null;
|
|
1742
|
-
if (canvas.bounds.hit(ui.__nowWorld))
|
|
1743
|
-
|
|
1744
|
-
ui.forceUpdate('surface');
|
|
1849
|
+
if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
|
|
1850
|
+
ui.forceUpdate("surface");
|
|
1745
1851
|
}), 300);
|
|
1746
1852
|
}
|
|
1747
1853
|
}
|
|
@@ -1749,39 +1855,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1749
1855
|
}
|
|
1750
1856
|
}
|
|
1751
1857
|
}
|
|
1858
|
+
|
|
1752
1859
|
function drawImage(ui, canvas, paint, data) {
|
|
1753
1860
|
canvas.save();
|
|
1754
1861
|
canvas.clipUI(ui);
|
|
1755
|
-
if (paint.blendMode)
|
|
1756
|
-
|
|
1757
|
-
if (data.
|
|
1758
|
-
canvas.opacity *= data.opacity;
|
|
1759
|
-
if (data.transform)
|
|
1760
|
-
canvas.transform(data.transform);
|
|
1862
|
+
if (paint.blendMode) canvas.blendMode = paint.blendMode;
|
|
1863
|
+
if (data.opacity) canvas.opacity *= data.opacity;
|
|
1864
|
+
if (data.transform) canvas.transform(data.transform);
|
|
1761
1865
|
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1762
1866
|
canvas.restore();
|
|
1763
1867
|
}
|
|
1764
1868
|
|
|
1765
1869
|
function recycleImage(attrName, data) {
|
|
1766
|
-
const paints = data[
|
|
1767
|
-
if (paints
|
|
1870
|
+
const paints = data["_" + attrName];
|
|
1871
|
+
if (isArray(paints)) {
|
|
1768
1872
|
let paint, image, recycleMap, input, url;
|
|
1769
1873
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1770
1874
|
paint = paints[i];
|
|
1771
1875
|
image = paint.image;
|
|
1772
1876
|
url = image && image.url;
|
|
1773
1877
|
if (url) {
|
|
1774
|
-
if (!recycleMap)
|
|
1775
|
-
recycleMap = {};
|
|
1878
|
+
if (!recycleMap) recycleMap = {};
|
|
1776
1879
|
recycleMap[url] = true;
|
|
1777
1880
|
ImageManager.recycle(image);
|
|
1778
1881
|
if (image.loading) {
|
|
1779
1882
|
if (!input) {
|
|
1780
|
-
input =
|
|
1781
|
-
if (!(input
|
|
1782
|
-
input = [input];
|
|
1883
|
+
input = data.__input && data.__input[attrName] || [];
|
|
1884
|
+
if (!isArray(input)) input = [ input ];
|
|
1783
1885
|
}
|
|
1784
|
-
image.unload(paints[i].loadId, !input.some(
|
|
1886
|
+
image.unload(paints[i].loadId, !input.some(item => item.url === url));
|
|
1785
1887
|
}
|
|
1786
1888
|
}
|
|
1787
1889
|
}
|
|
@@ -1791,75 +1893,85 @@ function recycleImage(attrName, data) {
|
|
|
1791
1893
|
}
|
|
1792
1894
|
|
|
1793
1895
|
const PaintImageModule = {
|
|
1794
|
-
image,
|
|
1795
|
-
checkImage,
|
|
1796
|
-
createPattern,
|
|
1797
|
-
recycleImage,
|
|
1798
|
-
createData,
|
|
1799
|
-
getPatternData,
|
|
1800
|
-
fillOrFitMode,
|
|
1801
|
-
clipMode,
|
|
1802
|
-
repeatMode
|
|
1896
|
+
image: image,
|
|
1897
|
+
checkImage: checkImage,
|
|
1898
|
+
createPattern: createPattern,
|
|
1899
|
+
recycleImage: recycleImage,
|
|
1900
|
+
createData: createData,
|
|
1901
|
+
getPatternData: getPatternData,
|
|
1902
|
+
fillOrFitMode: fillOrFitMode,
|
|
1903
|
+
clipMode: clipMode,
|
|
1904
|
+
repeatMode: repeatMode
|
|
1803
1905
|
};
|
|
1804
1906
|
|
|
1805
|
-
const {
|
|
1907
|
+
const {toPoint: toPoint$2} = AroundHelper, {hasTransparent: hasTransparent} = ColorConvert;
|
|
1908
|
+
|
|
1806
1909
|
const realFrom$2 = {};
|
|
1910
|
+
|
|
1807
1911
|
const realTo$2 = {};
|
|
1912
|
+
|
|
1808
1913
|
function linearGradient(paint, box) {
|
|
1809
|
-
let { from, to, type, opacity } = paint;
|
|
1810
|
-
toPoint$2(from ||
|
|
1811
|
-
toPoint$2(to ||
|
|
1914
|
+
let {from: from, to: to, type: type, opacity: opacity} = paint;
|
|
1915
|
+
toPoint$2(from || "top", box, realFrom$2);
|
|
1916
|
+
toPoint$2(to || "bottom", box, realTo$2);
|
|
1812
1917
|
const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1813
|
-
const data = {
|
|
1918
|
+
const data = {
|
|
1919
|
+
type: type,
|
|
1920
|
+
style: style
|
|
1921
|
+
};
|
|
1814
1922
|
applyStops(data, style, paint.stops, opacity);
|
|
1815
1923
|
return data;
|
|
1816
1924
|
}
|
|
1925
|
+
|
|
1817
1926
|
function applyStops(data, gradient, stops, opacity) {
|
|
1818
1927
|
if (stops) {
|
|
1819
1928
|
let stop, color, offset, isTransparent;
|
|
1820
1929
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1821
1930
|
stop = stops[i];
|
|
1822
|
-
if (
|
|
1823
|
-
|
|
1824
|
-
else
|
|
1825
|
-
offset = stop.offset, color = ColorConvert.string(stop.color, opacity);
|
|
1931
|
+
if (isString(stop)) offset = i / (len - 1), color = ColorConvert.string(stop, opacity); else offset = stop.offset,
|
|
1932
|
+
color = ColorConvert.string(stop.color, opacity);
|
|
1826
1933
|
gradient.addColorStop(offset, color);
|
|
1827
|
-
if (!isTransparent && hasTransparent(color))
|
|
1828
|
-
isTransparent = true;
|
|
1934
|
+
if (!isTransparent && hasTransparent(color)) isTransparent = true;
|
|
1829
1935
|
}
|
|
1830
|
-
if (isTransparent)
|
|
1831
|
-
data.isTransparent = true;
|
|
1936
|
+
if (isTransparent) data.isTransparent = true;
|
|
1832
1937
|
}
|
|
1833
1938
|
}
|
|
1834
1939
|
|
|
1835
|
-
const { getAngle, getDistance: getDistance$1
|
|
1836
|
-
|
|
1837
|
-
const {
|
|
1940
|
+
const {getAngle: getAngle, getDistance: getDistance$1} = PointHelper;
|
|
1941
|
+
|
|
1942
|
+
const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = MatrixHelper;
|
|
1943
|
+
|
|
1944
|
+
const {toPoint: toPoint$1} = AroundHelper;
|
|
1945
|
+
|
|
1838
1946
|
const realFrom$1 = {};
|
|
1947
|
+
|
|
1839
1948
|
const realTo$1 = {};
|
|
1949
|
+
|
|
1840
1950
|
function radialGradient(paint, box) {
|
|
1841
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1842
|
-
toPoint$1(from ||
|
|
1843
|
-
toPoint$1(to ||
|
|
1951
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1952
|
+
toPoint$1(from || "center", box, realFrom$1);
|
|
1953
|
+
toPoint$1(to || "bottom", box, realTo$1);
|
|
1844
1954
|
const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
|
|
1845
|
-
const data = {
|
|
1955
|
+
const data = {
|
|
1956
|
+
type: type,
|
|
1957
|
+
style: style
|
|
1958
|
+
};
|
|
1846
1959
|
applyStops(data, style, paint.stops, opacity);
|
|
1847
1960
|
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1848
|
-
if (transform)
|
|
1849
|
-
data.transform = transform;
|
|
1961
|
+
if (transform) data.transform = transform;
|
|
1850
1962
|
return data;
|
|
1851
1963
|
}
|
|
1964
|
+
|
|
1852
1965
|
function getTransform(box, from, to, stretch, rotate90) {
|
|
1853
1966
|
let transform;
|
|
1854
|
-
const { width, height } = box;
|
|
1967
|
+
const {width: width, height: height} = box;
|
|
1855
1968
|
if (width !== height || stretch) {
|
|
1856
1969
|
const angle = getAngle(from, to);
|
|
1857
1970
|
transform = get();
|
|
1858
1971
|
if (rotate90) {
|
|
1859
1972
|
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1860
1973
|
rotateOfOuter(transform, from, angle + 90);
|
|
1861
|
-
}
|
|
1862
|
-
else {
|
|
1974
|
+
} else {
|
|
1863
1975
|
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1864
1976
|
rotateOfOuter(transform, from, angle);
|
|
1865
1977
|
}
|
|
@@ -1867,84 +1979,94 @@ function getTransform(box, from, to, stretch, rotate90) {
|
|
|
1867
1979
|
return transform;
|
|
1868
1980
|
}
|
|
1869
1981
|
|
|
1870
|
-
const { getDistance
|
|
1871
|
-
|
|
1982
|
+
const {getDistance: getDistance} = PointHelper;
|
|
1983
|
+
|
|
1984
|
+
const {toPoint: toPoint} = AroundHelper;
|
|
1985
|
+
|
|
1872
1986
|
const realFrom = {};
|
|
1987
|
+
|
|
1873
1988
|
const realTo = {};
|
|
1989
|
+
|
|
1874
1990
|
function conicGradient(paint, box) {
|
|
1875
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1876
|
-
toPoint(from ||
|
|
1877
|
-
toPoint(to ||
|
|
1991
|
+
let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
|
|
1992
|
+
toPoint(from || "center", box, realFrom);
|
|
1993
|
+
toPoint(to || "bottom", box, realTo);
|
|
1878
1994
|
const style = Platform.conicGradientSupport ? Platform.canvas.createConicGradient(0, realFrom.x, realFrom.y) : Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo));
|
|
1879
|
-
const data = {
|
|
1995
|
+
const data = {
|
|
1996
|
+
type: type,
|
|
1997
|
+
style: style
|
|
1998
|
+
};
|
|
1880
1999
|
applyStops(data, style, paint.stops, opacity);
|
|
1881
2000
|
const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
|
|
1882
|
-
if (transform)
|
|
1883
|
-
data.transform = transform;
|
|
2001
|
+
if (transform) data.transform = transform;
|
|
1884
2002
|
return data;
|
|
1885
2003
|
}
|
|
1886
2004
|
|
|
1887
2005
|
const PaintGradientModule = {
|
|
1888
|
-
linearGradient,
|
|
1889
|
-
radialGradient,
|
|
1890
|
-
conicGradient,
|
|
1891
|
-
getTransform
|
|
2006
|
+
linearGradient: linearGradient,
|
|
2007
|
+
radialGradient: radialGradient,
|
|
2008
|
+
conicGradient: conicGradient,
|
|
2009
|
+
getTransform: getTransform
|
|
1892
2010
|
};
|
|
1893
2011
|
|
|
1894
|
-
const { copy, toOffsetOutBounds: toOffsetOutBounds$1
|
|
2012
|
+
const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
|
|
2013
|
+
|
|
1895
2014
|
const tempBounds = {};
|
|
2015
|
+
|
|
1896
2016
|
const offsetOutBounds$1 = {};
|
|
2017
|
+
|
|
1897
2018
|
function shadow(ui, current, shape) {
|
|
1898
2019
|
let copyBounds, spreadScale;
|
|
1899
|
-
const {
|
|
1900
|
-
const { shadow
|
|
1901
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
2020
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
2021
|
+
const {shadow: shadow} = ui.__;
|
|
2022
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1902
2023
|
const other = current.getSameCanvas();
|
|
1903
2024
|
const end = shadow.length - 1;
|
|
1904
2025
|
toOffsetOutBounds$1(bounds, offsetOutBounds$1);
|
|
1905
2026
|
shadow.forEach((item, index) => {
|
|
1906
|
-
|
|
1907
|
-
|
|
2027
|
+
let otherScale = 1;
|
|
2028
|
+
if (item.scaleFixed) {
|
|
2029
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
2030
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
2031
|
+
}
|
|
2032
|
+
other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, ColorConvert.string(item.color));
|
|
2033
|
+
spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1908
2034
|
drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
|
|
1909
2035
|
copyBounds = bounds;
|
|
1910
2036
|
if (item.box) {
|
|
1911
2037
|
other.restore();
|
|
1912
2038
|
other.save();
|
|
1913
2039
|
if (worldCanvas) {
|
|
1914
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
2040
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1915
2041
|
copyBounds = nowWorld;
|
|
1916
2042
|
}
|
|
1917
|
-
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
else
|
|
1922
|
-
current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
|
|
1923
|
-
if (end && index < end)
|
|
1924
|
-
other.clearWorld(copyBounds, true);
|
|
2043
|
+
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
2044
|
+
}
|
|
2045
|
+
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
2046
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1925
2047
|
});
|
|
1926
2048
|
other.recycle(copyBounds);
|
|
1927
2049
|
}
|
|
2050
|
+
|
|
1928
2051
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1929
|
-
const { bounds, shapeBounds } = shape;
|
|
2052
|
+
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1930
2053
|
if (Platform.fullImageShadow) {
|
|
1931
2054
|
copy(tempBounds, canvas.bounds);
|
|
1932
|
-
tempBounds.x +=
|
|
1933
|
-
tempBounds.y +=
|
|
2055
|
+
tempBounds.x += outBounds.x - shapeBounds.x;
|
|
2056
|
+
tempBounds.y += outBounds.y - shapeBounds.y;
|
|
1934
2057
|
if (spreadScale) {
|
|
1935
|
-
const {
|
|
1936
|
-
tempBounds.x -= (bounds.x + (
|
|
1937
|
-
tempBounds.y -= (bounds.y + (
|
|
2058
|
+
const {fitMatrix: fitMatrix} = shape;
|
|
2059
|
+
tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
|
|
2060
|
+
tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
|
|
1938
2061
|
tempBounds.width *= spreadScale;
|
|
1939
2062
|
tempBounds.height *= spreadScale;
|
|
1940
2063
|
}
|
|
1941
2064
|
canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
|
|
1942
|
-
}
|
|
1943
|
-
else {
|
|
2065
|
+
} else {
|
|
1944
2066
|
if (spreadScale) {
|
|
1945
2067
|
copy(tempBounds, outBounds);
|
|
1946
|
-
tempBounds.x -=
|
|
1947
|
-
tempBounds.y -=
|
|
2068
|
+
tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
|
|
2069
|
+
tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
|
|
1948
2070
|
tempBounds.width *= spreadScale;
|
|
1949
2071
|
tempBounds.height *= spreadScale;
|
|
1950
2072
|
}
|
|
@@ -1952,178 +2074,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
|
1952
2074
|
}
|
|
1953
2075
|
}
|
|
1954
2076
|
|
|
1955
|
-
const { toOffsetOutBounds
|
|
2077
|
+
const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
|
|
2078
|
+
|
|
1956
2079
|
const offsetOutBounds = {};
|
|
2080
|
+
|
|
1957
2081
|
function innerShadow(ui, current, shape) {
|
|
1958
2082
|
let copyBounds, spreadScale;
|
|
1959
|
-
const {
|
|
1960
|
-
const { innerShadow
|
|
1961
|
-
const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
|
|
2083
|
+
const {__nowWorld: nowWorld, __layout: __layout} = ui;
|
|
2084
|
+
const {innerShadow: innerShadow} = ui.__;
|
|
2085
|
+
const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
|
|
1962
2086
|
const other = current.getSameCanvas();
|
|
1963
2087
|
const end = innerShadow.length - 1;
|
|
1964
2088
|
toOffsetOutBounds(bounds, offsetOutBounds);
|
|
1965
2089
|
innerShadow.forEach((item, index) => {
|
|
2090
|
+
let otherScale = 1;
|
|
2091
|
+
if (item.scaleFixed) {
|
|
2092
|
+
const sx = Math.abs(nowWorld.scaleX);
|
|
2093
|
+
if (sx > 1) otherScale = 1 / sx;
|
|
2094
|
+
}
|
|
1966
2095
|
other.save();
|
|
1967
|
-
other.setWorldShadow(
|
|
1968
|
-
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
|
|
2096
|
+
other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
|
|
2097
|
+
spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
|
|
1969
2098
|
drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
|
|
1970
2099
|
other.restore();
|
|
1971
2100
|
if (worldCanvas) {
|
|
1972
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
1973
|
-
other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
2101
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
2102
|
+
other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
|
|
1974
2103
|
copyBounds = nowWorld;
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
|
|
2104
|
+
} else {
|
|
2105
|
+
other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
|
|
1978
2106
|
copyBounds = bounds;
|
|
1979
2107
|
}
|
|
1980
|
-
other.fillWorld(copyBounds, ColorConvert.string(item.color),
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
else
|
|
1984
|
-
current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
|
|
1985
|
-
if (end && index < end)
|
|
1986
|
-
other.clearWorld(copyBounds, true);
|
|
2108
|
+
other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
|
|
2109
|
+
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
2110
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1987
2111
|
});
|
|
1988
2112
|
other.recycle(copyBounds);
|
|
1989
2113
|
}
|
|
1990
2114
|
|
|
1991
2115
|
function blur(ui, current, origin) {
|
|
1992
|
-
const { blur
|
|
2116
|
+
const {blur: blur} = ui.__;
|
|
1993
2117
|
origin.setWorldBlur(blur * ui.__nowWorld.a);
|
|
1994
2118
|
origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
|
|
1995
|
-
origin.filter =
|
|
2119
|
+
origin.filter = "none";
|
|
1996
2120
|
}
|
|
1997
2121
|
|
|
1998
|
-
function backgroundBlur(_ui, _current, _shape) {
|
|
1999
|
-
}
|
|
2122
|
+
function backgroundBlur(_ui, _current, _shape) {}
|
|
2000
2123
|
|
|
2001
2124
|
const EffectModule = {
|
|
2002
|
-
shadow,
|
|
2003
|
-
innerShadow,
|
|
2004
|
-
blur,
|
|
2005
|
-
backgroundBlur
|
|
2125
|
+
shadow: shadow,
|
|
2126
|
+
innerShadow: innerShadow,
|
|
2127
|
+
blur: blur,
|
|
2128
|
+
backgroundBlur: backgroundBlur
|
|
2006
2129
|
};
|
|
2007
2130
|
|
|
2008
|
-
const { excludeRenderBounds
|
|
2009
|
-
|
|
2131
|
+
const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
|
|
2132
|
+
|
|
2133
|
+
let usedGrayscaleAlpha;
|
|
2134
|
+
|
|
2135
|
+
Group.prototype.__renderMask = function(canvas, options) {
|
|
2010
2136
|
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
2011
|
-
const { children
|
|
2137
|
+
const {children: children} = this;
|
|
2012
2138
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
2013
2139
|
child = children[i], mask = child.__.mask;
|
|
2014
2140
|
if (mask) {
|
|
2015
2141
|
if (currentMask) {
|
|
2016
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
2142
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
2017
2143
|
maskCanvas = contentCanvas = null;
|
|
2018
2144
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
currentMask = 'path';
|
|
2145
|
+
maskOpacity = child.__.opacity;
|
|
2146
|
+
usedGrayscaleAlpha = false;
|
|
2147
|
+
if (mask === "path" || mask === "clipping-path") {
|
|
2148
|
+
if (maskOpacity < 1) {
|
|
2149
|
+
currentMask = "opacity-path";
|
|
2150
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
2151
|
+
} else {
|
|
2152
|
+
currentMask = "path";
|
|
2028
2153
|
canvas.save();
|
|
2029
2154
|
}
|
|
2030
2155
|
child.__clip(contentCanvas || canvas, options);
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
if (!
|
|
2035
|
-
maskCanvas = getCanvas(canvas);
|
|
2036
|
-
if (!contentCanvas)
|
|
2037
|
-
contentCanvas = getCanvas(canvas);
|
|
2156
|
+
} else {
|
|
2157
|
+
currentMask = mask === "grayscale" ? "grayscale" : "alpha";
|
|
2158
|
+
if (!maskCanvas) maskCanvas = getCanvas(canvas);
|
|
2159
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
2038
2160
|
child.__render(maskCanvas, options);
|
|
2039
2161
|
}
|
|
2040
|
-
if (
|
|
2041
|
-
continue;
|
|
2042
|
-
}
|
|
2043
|
-
if (excludeRenderBounds(child, options))
|
|
2162
|
+
if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
2044
2163
|
continue;
|
|
2045
|
-
|
|
2164
|
+
}
|
|
2165
|
+
const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
|
|
2166
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
|
|
2167
|
+
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
2168
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
|
|
2046
2169
|
}
|
|
2047
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
2170
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
2048
2171
|
};
|
|
2049
|
-
|
|
2172
|
+
|
|
2173
|
+
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
|
|
2050
2174
|
switch (maskMode) {
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2175
|
+
case "grayscale":
|
|
2176
|
+
if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
|
|
2177
|
+
|
|
2178
|
+
case "alpha":
|
|
2179
|
+
usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
|
|
2180
|
+
break;
|
|
2181
|
+
|
|
2182
|
+
case "opacity-path":
|
|
2183
|
+
copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
|
|
2184
|
+
break;
|
|
2185
|
+
|
|
2186
|
+
case "path":
|
|
2187
|
+
if (recycle) canvas.restore();
|
|
2061
2188
|
}
|
|
2062
2189
|
}
|
|
2190
|
+
|
|
2063
2191
|
function getCanvas(canvas) {
|
|
2064
2192
|
return canvas.getSameCanvas(false, true);
|
|
2065
2193
|
}
|
|
2066
|
-
|
|
2194
|
+
|
|
2195
|
+
function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
|
|
2067
2196
|
const realBounds = leaf.__nowWorld;
|
|
2068
2197
|
content.resetTransform();
|
|
2069
2198
|
content.opacity = 1;
|
|
2070
2199
|
content.useMask(mask, realBounds);
|
|
2071
|
-
mask.recycle(realBounds);
|
|
2072
|
-
copyContent(leaf, canvas, content, 1);
|
|
2200
|
+
if (recycle) mask.recycle(realBounds);
|
|
2201
|
+
copyContent(leaf, canvas, content, 1, blendMode, recycle);
|
|
2073
2202
|
}
|
|
2074
|
-
|
|
2203
|
+
|
|
2204
|
+
function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
|
|
2075
2205
|
const realBounds = leaf.__nowWorld;
|
|
2076
2206
|
canvas.resetTransform();
|
|
2077
2207
|
canvas.opacity = maskOpacity;
|
|
2078
|
-
canvas.copyWorld(content, realBounds);
|
|
2079
|
-
content.recycle(realBounds);
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
const money =
|
|
2083
|
-
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
const
|
|
2087
|
-
|
|
2088
|
-
const
|
|
2089
|
-
|
|
2090
|
-
const
|
|
2091
|
-
|
|
2092
|
-
const
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
[0x31C0, 0x31EF],
|
|
2107
|
-
[0x3200, 0x32FF],
|
|
2108
|
-
[0x3300, 0x33FF],
|
|
2109
|
-
[0xF900, 0xFAFF],
|
|
2110
|
-
[0xFE30, 0xFE4F],
|
|
2111
|
-
[0x1F200, 0x1F2FF],
|
|
2112
|
-
[0x2F800, 0x2FA1F],
|
|
2113
|
-
];
|
|
2114
|
-
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'));
|
|
2208
|
+
canvas.copyWorld(content, realBounds, undefined, blendMode);
|
|
2209
|
+
recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
const money = "¥¥$€££¢¢";
|
|
2213
|
+
|
|
2214
|
+
const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
|
2215
|
+
|
|
2216
|
+
const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
|
|
2217
|
+
|
|
2218
|
+
const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
|
|
2219
|
+
|
|
2220
|
+
const langSymbol = "≮≯≈≠=…";
|
|
2221
|
+
|
|
2222
|
+
const langBreak$1 = "—/~|┆·";
|
|
2223
|
+
|
|
2224
|
+
const beforeChar = "{[(<'\"" + langBefore;
|
|
2225
|
+
|
|
2226
|
+
const afterChar = ">)]}%!?,.:;'\"" + langAfter;
|
|
2227
|
+
|
|
2228
|
+
const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
|
|
2229
|
+
|
|
2230
|
+
const breakChar = "- " + langBreak$1;
|
|
2231
|
+
|
|
2232
|
+
const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
|
|
2233
|
+
|
|
2234
|
+
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
|
|
2235
|
+
|
|
2115
2236
|
function mapChar(str) {
|
|
2116
2237
|
const map = {};
|
|
2117
|
-
str.split(
|
|
2238
|
+
str.split("").forEach(char => map[char] = true);
|
|
2118
2239
|
return map;
|
|
2119
2240
|
}
|
|
2241
|
+
|
|
2120
2242
|
const letterMap = mapChar(letter);
|
|
2243
|
+
|
|
2121
2244
|
const beforeMap = mapChar(beforeChar);
|
|
2245
|
+
|
|
2122
2246
|
const afterMap = mapChar(afterChar);
|
|
2247
|
+
|
|
2123
2248
|
const symbolMap = mapChar(symbolChar);
|
|
2249
|
+
|
|
2124
2250
|
const breakMap = mapChar(breakChar);
|
|
2251
|
+
|
|
2125
2252
|
var CharType;
|
|
2126
|
-
|
|
2253
|
+
|
|
2254
|
+
(function(CharType) {
|
|
2127
2255
|
CharType[CharType["Letter"] = 0] = "Letter";
|
|
2128
2256
|
CharType[CharType["Single"] = 1] = "Single";
|
|
2129
2257
|
CharType[CharType["Before"] = 2] = "Before";
|
|
@@ -2131,179 +2259,175 @@ var CharType;
|
|
|
2131
2259
|
CharType[CharType["Symbol"] = 4] = "Symbol";
|
|
2132
2260
|
CharType[CharType["Break"] = 5] = "Break";
|
|
2133
2261
|
})(CharType || (CharType = {}));
|
|
2134
|
-
|
|
2262
|
+
|
|
2263
|
+
const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
|
|
2264
|
+
|
|
2135
2265
|
function getCharType(char) {
|
|
2136
2266
|
if (letterMap[char]) {
|
|
2137
2267
|
return Letter$1;
|
|
2138
|
-
}
|
|
2139
|
-
else if (breakMap[char]) {
|
|
2268
|
+
} else if (breakMap[char]) {
|
|
2140
2269
|
return Break$1;
|
|
2141
|
-
}
|
|
2142
|
-
else if (beforeMap[char]) {
|
|
2270
|
+
} else if (beforeMap[char]) {
|
|
2143
2271
|
return Before$1;
|
|
2144
|
-
}
|
|
2145
|
-
else if (afterMap[char]) {
|
|
2272
|
+
} else if (afterMap[char]) {
|
|
2146
2273
|
return After$1;
|
|
2147
|
-
}
|
|
2148
|
-
else if (symbolMap[char]) {
|
|
2274
|
+
} else if (symbolMap[char]) {
|
|
2149
2275
|
return Symbol$1;
|
|
2150
|
-
}
|
|
2151
|
-
else if (cjkReg.test(char)) {
|
|
2276
|
+
} else if (cjkReg.test(char)) {
|
|
2152
2277
|
return Single$1;
|
|
2153
|
-
}
|
|
2154
|
-
else {
|
|
2278
|
+
} else {
|
|
2155
2279
|
return Letter$1;
|
|
2156
2280
|
}
|
|
2157
2281
|
}
|
|
2158
2282
|
|
|
2159
2283
|
const TextRowHelper = {
|
|
2160
2284
|
trimRight(row) {
|
|
2161
|
-
const { words
|
|
2285
|
+
const {words: words} = row;
|
|
2162
2286
|
let trimRight = 0, len = words.length, char;
|
|
2163
2287
|
for (let i = len - 1; i > -1; i--) {
|
|
2164
2288
|
char = words[i].data[0];
|
|
2165
|
-
if (char.char ===
|
|
2289
|
+
if (char.char === " ") {
|
|
2166
2290
|
trimRight++;
|
|
2167
2291
|
row.width -= char.width;
|
|
2168
|
-
}
|
|
2169
|
-
else {
|
|
2292
|
+
} else {
|
|
2170
2293
|
break;
|
|
2171
2294
|
}
|
|
2172
2295
|
}
|
|
2173
|
-
if (trimRight)
|
|
2174
|
-
words.splice(len - trimRight, trimRight);
|
|
2296
|
+
if (trimRight) words.splice(len - trimRight, trimRight);
|
|
2175
2297
|
}
|
|
2176
2298
|
};
|
|
2177
2299
|
|
|
2178
2300
|
function getTextCase(char, textCase, firstChar) {
|
|
2179
2301
|
switch (textCase) {
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2302
|
+
case "title":
|
|
2303
|
+
return firstChar ? char.toUpperCase() : char;
|
|
2304
|
+
|
|
2305
|
+
case "upper":
|
|
2306
|
+
return char.toUpperCase();
|
|
2307
|
+
|
|
2308
|
+
case "lower":
|
|
2309
|
+
return char.toLowerCase();
|
|
2310
|
+
|
|
2311
|
+
default:
|
|
2312
|
+
return char;
|
|
2188
2313
|
}
|
|
2189
2314
|
}
|
|
2190
2315
|
|
|
2191
|
-
const { trimRight
|
|
2192
|
-
|
|
2316
|
+
const {trimRight: trimRight} = TextRowHelper;
|
|
2317
|
+
|
|
2318
|
+
const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
|
|
2319
|
+
|
|
2193
2320
|
let word, row, wordWidth, rowWidth, realWidth;
|
|
2321
|
+
|
|
2194
2322
|
let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
|
|
2323
|
+
|
|
2195
2324
|
let textDrawData, rows = [], bounds, findMaxWidth;
|
|
2325
|
+
|
|
2196
2326
|
function createRows(drawData, content, style) {
|
|
2197
2327
|
textDrawData = drawData;
|
|
2198
2328
|
rows = drawData.rows;
|
|
2199
2329
|
bounds = drawData.bounds;
|
|
2200
2330
|
findMaxWidth = !bounds.width && !style.autoSizeAlign;
|
|
2201
|
-
const { __letterSpacing, paraIndent, textCase } = style;
|
|
2202
|
-
const { canvas
|
|
2203
|
-
const { width, height } = bounds;
|
|
2204
|
-
const charMode = width || height || __letterSpacing ||
|
|
2331
|
+
const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
|
|
2332
|
+
const {canvas: canvas} = Platform;
|
|
2333
|
+
const {width: width, height: height} = bounds;
|
|
2334
|
+
const charMode = width || height || __letterSpacing || textCase !== "none";
|
|
2205
2335
|
if (charMode) {
|
|
2206
|
-
const wrap = style.textWrap !==
|
|
2207
|
-
const breakAll = style.textWrap ===
|
|
2336
|
+
const wrap = style.textWrap !== "none";
|
|
2337
|
+
const breakAll = style.textWrap === "break";
|
|
2208
2338
|
paraStart = true;
|
|
2209
2339
|
lastCharType = null;
|
|
2210
2340
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
2211
|
-
word = {
|
|
2212
|
-
|
|
2213
|
-
|
|
2341
|
+
word = {
|
|
2342
|
+
data: []
|
|
2343
|
+
}, row = {
|
|
2344
|
+
words: []
|
|
2345
|
+
};
|
|
2346
|
+
if (__letterSpacing) content = [ ...content ];
|
|
2214
2347
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
2215
2348
|
char = content[i];
|
|
2216
|
-
if (char ===
|
|
2217
|
-
if (wordWidth)
|
|
2218
|
-
addWord();
|
|
2349
|
+
if (char === "\n") {
|
|
2350
|
+
if (wordWidth) addWord();
|
|
2219
2351
|
row.paraEnd = true;
|
|
2220
2352
|
addRow();
|
|
2221
2353
|
paraStart = true;
|
|
2222
|
-
}
|
|
2223
|
-
else {
|
|
2354
|
+
} else {
|
|
2224
2355
|
charType = getCharType(char);
|
|
2225
|
-
if (charType === Letter && textCase !==
|
|
2226
|
-
char = getTextCase(char, textCase, !wordWidth);
|
|
2356
|
+
if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
|
|
2227
2357
|
charWidth = canvas.measureText(char).width;
|
|
2228
2358
|
if (__letterSpacing) {
|
|
2229
|
-
if (__letterSpacing < 0)
|
|
2230
|
-
charSize = charWidth;
|
|
2359
|
+
if (__letterSpacing < 0) charSize = charWidth;
|
|
2231
2360
|
charWidth += __letterSpacing;
|
|
2232
2361
|
}
|
|
2233
|
-
langBreak =
|
|
2234
|
-
afterBreak = (
|
|
2362
|
+
langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
|
|
2363
|
+
afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
|
|
2235
2364
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
2236
2365
|
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
2237
2366
|
if (breakAll) {
|
|
2238
|
-
if (wordWidth)
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
if (wordWidth)
|
|
2248
|
-
addWord();
|
|
2249
|
-
if (rowWidth)
|
|
2250
|
-
addRow();
|
|
2251
|
-
}
|
|
2252
|
-
else {
|
|
2253
|
-
if (rowWidth)
|
|
2254
|
-
addRow();
|
|
2367
|
+
if (wordWidth) addWord();
|
|
2368
|
+
if (rowWidth) addRow();
|
|
2369
|
+
} else {
|
|
2370
|
+
if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
|
|
2371
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
|
|
2372
|
+
if (wordWidth) addWord();
|
|
2373
|
+
if (rowWidth) addRow();
|
|
2374
|
+
} else {
|
|
2375
|
+
if (rowWidth) addRow();
|
|
2255
2376
|
}
|
|
2256
2377
|
}
|
|
2257
2378
|
}
|
|
2258
|
-
if (char ===
|
|
2259
|
-
else {
|
|
2379
|
+
if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
|
|
2260
2380
|
if (charType === Break) {
|
|
2261
|
-
if (char ===
|
|
2262
|
-
addWord();
|
|
2381
|
+
if (char === " " && wordWidth) addWord();
|
|
2263
2382
|
addChar(char, charWidth);
|
|
2264
2383
|
addWord();
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
if (wordWidth)
|
|
2268
|
-
addWord();
|
|
2384
|
+
} else if (langBreak || afterBreak) {
|
|
2385
|
+
if (wordWidth) addWord();
|
|
2269
2386
|
addChar(char, charWidth);
|
|
2270
|
-
}
|
|
2271
|
-
else {
|
|
2387
|
+
} else {
|
|
2272
2388
|
addChar(char, charWidth);
|
|
2273
2389
|
}
|
|
2274
2390
|
}
|
|
2275
2391
|
lastCharType = charType;
|
|
2276
2392
|
}
|
|
2277
2393
|
}
|
|
2278
|
-
if (wordWidth)
|
|
2279
|
-
|
|
2280
|
-
if (rowWidth)
|
|
2281
|
-
addRow();
|
|
2394
|
+
if (wordWidth) addWord();
|
|
2395
|
+
if (rowWidth) addRow();
|
|
2282
2396
|
rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
content.split('\n').forEach(content => {
|
|
2397
|
+
} else {
|
|
2398
|
+
content.split("\n").forEach(content => {
|
|
2286
2399
|
textDrawData.paraNumber++;
|
|
2287
2400
|
rowWidth = canvas.measureText(content).width;
|
|
2288
|
-
rows.push({
|
|
2289
|
-
|
|
2290
|
-
|
|
2401
|
+
rows.push({
|
|
2402
|
+
x: paraIndent || 0,
|
|
2403
|
+
text: content,
|
|
2404
|
+
width: rowWidth,
|
|
2405
|
+
paraStart: true
|
|
2406
|
+
});
|
|
2407
|
+
if (findMaxWidth) setMaxWidth();
|
|
2291
2408
|
});
|
|
2292
2409
|
}
|
|
2293
2410
|
}
|
|
2411
|
+
|
|
2294
2412
|
function addChar(char, width) {
|
|
2295
|
-
if (charSize && !startCharSize)
|
|
2296
|
-
|
|
2297
|
-
|
|
2413
|
+
if (charSize && !startCharSize) startCharSize = charSize;
|
|
2414
|
+
word.data.push({
|
|
2415
|
+
char: char,
|
|
2416
|
+
width: width
|
|
2417
|
+
});
|
|
2298
2418
|
wordWidth += width;
|
|
2299
2419
|
}
|
|
2420
|
+
|
|
2300
2421
|
function addWord() {
|
|
2301
2422
|
rowWidth += wordWidth;
|
|
2302
2423
|
word.width = wordWidth;
|
|
2303
2424
|
row.words.push(word);
|
|
2304
|
-
word = {
|
|
2425
|
+
word = {
|
|
2426
|
+
data: []
|
|
2427
|
+
};
|
|
2305
2428
|
wordWidth = 0;
|
|
2306
2429
|
}
|
|
2430
|
+
|
|
2307
2431
|
function addRow() {
|
|
2308
2432
|
if (paraStart) {
|
|
2309
2433
|
textDrawData.paraNumber++;
|
|
@@ -2316,52 +2440,53 @@ function addRow() {
|
|
|
2316
2440
|
startCharSize = 0;
|
|
2317
2441
|
}
|
|
2318
2442
|
row.width = rowWidth;
|
|
2319
|
-
if (bounds.width)
|
|
2320
|
-
trimRight(row);
|
|
2321
|
-
else if (findMaxWidth)
|
|
2322
|
-
setMaxWidth();
|
|
2443
|
+
if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
|
|
2323
2444
|
rows.push(row);
|
|
2324
|
-
row = {
|
|
2445
|
+
row = {
|
|
2446
|
+
words: []
|
|
2447
|
+
};
|
|
2325
2448
|
rowWidth = 0;
|
|
2326
2449
|
}
|
|
2450
|
+
|
|
2327
2451
|
function setMaxWidth() {
|
|
2328
|
-
if (rowWidth > (textDrawData.maxWidth || 0))
|
|
2329
|
-
textDrawData.maxWidth = rowWidth;
|
|
2452
|
+
if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
|
|
2330
2453
|
}
|
|
2331
2454
|
|
|
2332
2455
|
const CharMode = 0;
|
|
2456
|
+
|
|
2333
2457
|
const WordMode = 1;
|
|
2458
|
+
|
|
2334
2459
|
const TextMode = 2;
|
|
2460
|
+
|
|
2335
2461
|
function layoutChar(drawData, style, width, _height) {
|
|
2336
|
-
const { rows
|
|
2337
|
-
const { textAlign, paraIndent, letterSpacing } = style;
|
|
2462
|
+
const {rows: rows} = drawData;
|
|
2463
|
+
const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
|
|
2338
2464
|
let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
|
|
2339
2465
|
rows.forEach(row => {
|
|
2340
2466
|
if (row.words) {
|
|
2341
2467
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
|
|
2342
|
-
addWordWidth =
|
|
2343
|
-
mode =
|
|
2344
|
-
if (row.isOverflow && !letterSpacing)
|
|
2345
|
-
row.textMode = true;
|
|
2468
|
+
addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
|
|
2469
|
+
mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
|
|
2470
|
+
if (row.isOverflow && !letterSpacing) row.textMode = true;
|
|
2346
2471
|
if (mode === TextMode) {
|
|
2347
2472
|
row.x += indentWidth;
|
|
2348
2473
|
toTextChar$1(row);
|
|
2349
|
-
}
|
|
2350
|
-
else {
|
|
2474
|
+
} else {
|
|
2351
2475
|
row.x += indentWidth;
|
|
2352
2476
|
charX = row.x;
|
|
2353
2477
|
row.data = [];
|
|
2354
2478
|
row.words.forEach((word, index) => {
|
|
2355
2479
|
if (mode === WordMode) {
|
|
2356
|
-
wordChar = {
|
|
2480
|
+
wordChar = {
|
|
2481
|
+
char: "",
|
|
2482
|
+
x: charX
|
|
2483
|
+
};
|
|
2357
2484
|
charX = toWordChar(word.data, charX, wordChar);
|
|
2358
|
-
if (row.isOverflow || wordChar.char !==
|
|
2359
|
-
|
|
2360
|
-
}
|
|
2361
|
-
else {
|
|
2485
|
+
if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
|
|
2486
|
+
} else {
|
|
2362
2487
|
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
2363
2488
|
}
|
|
2364
|
-
if (addWordWidth && (!row.paraEnd || textAlign ===
|
|
2489
|
+
if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
|
|
2365
2490
|
charX += addWordWidth;
|
|
2366
2491
|
row.width += addWordWidth;
|
|
2367
2492
|
}
|
|
@@ -2371,14 +2496,16 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
2371
2496
|
}
|
|
2372
2497
|
});
|
|
2373
2498
|
}
|
|
2499
|
+
|
|
2374
2500
|
function toTextChar$1(row) {
|
|
2375
|
-
row.text =
|
|
2501
|
+
row.text = "";
|
|
2376
2502
|
row.words.forEach(word => {
|
|
2377
2503
|
word.data.forEach(char => {
|
|
2378
2504
|
row.text += char.char;
|
|
2379
2505
|
});
|
|
2380
2506
|
});
|
|
2381
2507
|
}
|
|
2508
|
+
|
|
2382
2509
|
function toWordChar(data, charX, wordChar) {
|
|
2383
2510
|
data.forEach(char => {
|
|
2384
2511
|
wordChar.char += char.char;
|
|
@@ -2386,9 +2513,10 @@ function toWordChar(data, charX, wordChar) {
|
|
|
2386
2513
|
});
|
|
2387
2514
|
return charX;
|
|
2388
2515
|
}
|
|
2516
|
+
|
|
2389
2517
|
function toChar(data, charX, rowData, isOverflow) {
|
|
2390
2518
|
data.forEach(char => {
|
|
2391
|
-
if (isOverflow || char.char !==
|
|
2519
|
+
if (isOverflow || char.char !== " ") {
|
|
2392
2520
|
char.x = charX;
|
|
2393
2521
|
rowData.push(char);
|
|
2394
2522
|
}
|
|
@@ -2398,38 +2526,39 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
2398
2526
|
}
|
|
2399
2527
|
|
|
2400
2528
|
function layoutText(drawData, style) {
|
|
2401
|
-
const { rows, bounds } = drawData, countRows = rows.length;
|
|
2402
|
-
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
|
|
2403
|
-
let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2529
|
+
const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
|
|
2530
|
+
const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
|
|
2531
|
+
let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2404
2532
|
let starY = __baseLine;
|
|
2405
2533
|
if (__clipText && realHeight > height) {
|
|
2406
2534
|
realHeight = Math.max(height, __lineHeight);
|
|
2407
|
-
if (countRows > 1)
|
|
2408
|
-
|
|
2409
|
-
}
|
|
2410
|
-
else if (height || autoSizeAlign) {
|
|
2535
|
+
if (countRows > 1) drawData.overflow = countRows;
|
|
2536
|
+
} else if (height || autoSizeAlign) {
|
|
2411
2537
|
switch (verticalAlign) {
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2538
|
+
case "middle":
|
|
2539
|
+
y += (height - realHeight) / 2;
|
|
2540
|
+
break;
|
|
2541
|
+
|
|
2542
|
+
case "bottom":
|
|
2543
|
+
y += height - realHeight;
|
|
2416
2544
|
}
|
|
2417
2545
|
}
|
|
2418
2546
|
starY += y;
|
|
2419
|
-
let row, rowX, rowWidth, layoutWidth =
|
|
2547
|
+
let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
|
|
2420
2548
|
for (let i = 0, len = countRows; i < len; i++) {
|
|
2421
2549
|
row = rows[i];
|
|
2422
2550
|
row.x = x;
|
|
2423
|
-
if (row.width < width ||
|
|
2551
|
+
if (row.width < width || row.width > width && !__clipText) {
|
|
2424
2552
|
switch (textAlign) {
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2553
|
+
case "center":
|
|
2554
|
+
row.x += (layoutWidth - row.width) / 2;
|
|
2555
|
+
break;
|
|
2556
|
+
|
|
2557
|
+
case "right":
|
|
2558
|
+
row.x += layoutWidth - row.width;
|
|
2429
2559
|
}
|
|
2430
2560
|
}
|
|
2431
|
-
if (row.paraStart && paraSpacing && i > 0)
|
|
2432
|
-
starY += paraSpacing;
|
|
2561
|
+
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
|
|
2433
2562
|
row.y = starY;
|
|
2434
2563
|
starY += __lineHeight;
|
|
2435
2564
|
if (drawData.overflow > i && starY > realHeight) {
|
|
@@ -2443,19 +2572,15 @@ function layoutText(drawData, style) {
|
|
|
2443
2572
|
rowWidth = -row.width + style.fontSize + __letterSpacing;
|
|
2444
2573
|
rowX -= rowWidth;
|
|
2445
2574
|
rowWidth += style.fontSize;
|
|
2446
|
-
}
|
|
2447
|
-
else {
|
|
2575
|
+
} else {
|
|
2448
2576
|
rowWidth -= __letterSpacing;
|
|
2449
2577
|
}
|
|
2450
2578
|
}
|
|
2451
|
-
if (rowX < bounds.x)
|
|
2452
|
-
|
|
2453
|
-
if (rowWidth > bounds.width)
|
|
2454
|
-
bounds.width = rowWidth;
|
|
2579
|
+
if (rowX < bounds.x) bounds.x = rowX;
|
|
2580
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth;
|
|
2455
2581
|
if (__clipText && width && width < rowWidth) {
|
|
2456
2582
|
row.isOverflow = true;
|
|
2457
|
-
if (!drawData.overflow)
|
|
2458
|
-
drawData.overflow = rows.length;
|
|
2583
|
+
if (!drawData.overflow) drawData.overflow = rows.length;
|
|
2459
2584
|
}
|
|
2460
2585
|
}
|
|
2461
2586
|
bounds.y = y;
|
|
@@ -2463,20 +2588,16 @@ function layoutText(drawData, style) {
|
|
|
2463
2588
|
}
|
|
2464
2589
|
|
|
2465
2590
|
function clipText(drawData, style, x, width) {
|
|
2466
|
-
if (!width)
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
let { textOverflow } = style;
|
|
2591
|
+
if (!width) return;
|
|
2592
|
+
const {rows: rows, overflow: overflow} = drawData;
|
|
2593
|
+
let {textOverflow: textOverflow} = style;
|
|
2470
2594
|
rows.splice(overflow);
|
|
2471
|
-
if (textOverflow && textOverflow !==
|
|
2472
|
-
if (textOverflow ===
|
|
2473
|
-
textOverflow = '';
|
|
2474
|
-
else if (textOverflow === 'ellipsis')
|
|
2475
|
-
textOverflow = '...';
|
|
2595
|
+
if (textOverflow && textOverflow !== "show") {
|
|
2596
|
+
if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
|
|
2476
2597
|
let char, charRight;
|
|
2477
2598
|
const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
|
|
2478
2599
|
const right = x + width - ellipsisWidth;
|
|
2479
|
-
const list = style.textWrap ===
|
|
2600
|
+
const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
|
|
2480
2601
|
list.forEach(row => {
|
|
2481
2602
|
if (row.isOverflow && row.data) {
|
|
2482
2603
|
let end = row.data.length - 1;
|
|
@@ -2485,8 +2606,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2485
2606
|
charRight = char.x + char.width;
|
|
2486
2607
|
if (i === end && charRight < right) {
|
|
2487
2608
|
break;
|
|
2488
|
-
}
|
|
2489
|
-
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2609
|
+
} else if (charRight < right && char.char !== " " || !i) {
|
|
2490
2610
|
row.data.splice(i + 1);
|
|
2491
2611
|
row.width -= char.width;
|
|
2492
2612
|
break;
|
|
@@ -2494,15 +2614,18 @@ function clipText(drawData, style, x, width) {
|
|
|
2494
2614
|
row.width -= char.width;
|
|
2495
2615
|
}
|
|
2496
2616
|
row.width += ellipsisWidth;
|
|
2497
|
-
row.data.push({
|
|
2498
|
-
|
|
2499
|
-
|
|
2617
|
+
row.data.push({
|
|
2618
|
+
char: textOverflow,
|
|
2619
|
+
x: charRight
|
|
2620
|
+
});
|
|
2621
|
+
if (row.textMode) toTextChar(row);
|
|
2500
2622
|
}
|
|
2501
2623
|
});
|
|
2502
2624
|
}
|
|
2503
2625
|
}
|
|
2626
|
+
|
|
2504
2627
|
function toTextChar(row) {
|
|
2505
|
-
row.text =
|
|
2628
|
+
row.text = "";
|
|
2506
2629
|
row.data.forEach(char => {
|
|
2507
2630
|
row.text += char.char;
|
|
2508
2631
|
});
|
|
@@ -2511,129 +2634,130 @@ function toTextChar(row) {
|
|
|
2511
2634
|
|
|
2512
2635
|
function decorationText(drawData, style) {
|
|
2513
2636
|
let type;
|
|
2514
|
-
const { fontSize, textDecoration } = style;
|
|
2637
|
+
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2515
2638
|
drawData.decorationHeight = fontSize / 11;
|
|
2516
|
-
if (
|
|
2639
|
+
if (isObject(textDecoration)) {
|
|
2517
2640
|
type = textDecoration.type;
|
|
2518
|
-
if (textDecoration.color)
|
|
2519
|
-
|
|
2520
|
-
}
|
|
2521
|
-
else
|
|
2522
|
-
type = textDecoration;
|
|
2641
|
+
if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
|
|
2642
|
+
} else type = textDecoration;
|
|
2523
2643
|
switch (type) {
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2644
|
+
case "under":
|
|
2645
|
+
drawData.decorationY = [ fontSize * .15 ];
|
|
2646
|
+
break;
|
|
2647
|
+
|
|
2648
|
+
case "delete":
|
|
2649
|
+
drawData.decorationY = [ -fontSize * .35 ];
|
|
2650
|
+
break;
|
|
2651
|
+
|
|
2652
|
+
case "under-delete":
|
|
2653
|
+
drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
|
|
2532
2654
|
}
|
|
2533
2655
|
}
|
|
2534
2656
|
|
|
2535
|
-
const { top, right, bottom, left } = Direction4;
|
|
2657
|
+
const {top: top, right: right, bottom: bottom, left: left} = Direction4;
|
|
2658
|
+
|
|
2536
2659
|
function getDrawData(content, style) {
|
|
2537
|
-
if (
|
|
2538
|
-
content = String(content);
|
|
2660
|
+
if (!isString(content)) content = String(content);
|
|
2539
2661
|
let x = 0, y = 0;
|
|
2540
|
-
let width = style.__getInput(
|
|
2541
|
-
let height = style.__getInput(
|
|
2542
|
-
const { textDecoration, __font, __padding: padding
|
|
2662
|
+
let width = style.__getInput("width") || 0;
|
|
2663
|
+
let height = style.__getInput("height") || 0;
|
|
2664
|
+
const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
|
|
2543
2665
|
if (padding) {
|
|
2544
|
-
if (width)
|
|
2545
|
-
|
|
2546
|
-
else if (!style.autoSizeAlign)
|
|
2547
|
-
x = padding[left];
|
|
2548
|
-
if (height)
|
|
2549
|
-
y = padding[top], height -= (padding[top] + padding[bottom]);
|
|
2550
|
-
else if (!style.autoSizeAlign)
|
|
2551
|
-
y = padding[top];
|
|
2666
|
+
if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
|
|
2667
|
+
if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
|
|
2552
2668
|
}
|
|
2553
2669
|
const drawData = {
|
|
2554
|
-
bounds: {
|
|
2670
|
+
bounds: {
|
|
2671
|
+
x: x,
|
|
2672
|
+
y: y,
|
|
2673
|
+
width: width,
|
|
2674
|
+
height: height
|
|
2675
|
+
},
|
|
2555
2676
|
rows: [],
|
|
2556
2677
|
paraNumber: 0,
|
|
2557
2678
|
font: Platform.canvas.font = __font
|
|
2558
2679
|
};
|
|
2559
2680
|
createRows(drawData, content, style);
|
|
2560
|
-
if (padding)
|
|
2561
|
-
padAutoText(padding, drawData, style, width, height);
|
|
2681
|
+
if (padding) padAutoText(padding, drawData, style, width, height);
|
|
2562
2682
|
layoutText(drawData, style);
|
|
2563
2683
|
layoutChar(drawData, style, width);
|
|
2564
|
-
if (drawData.overflow)
|
|
2565
|
-
|
|
2566
|
-
if (textDecoration !== 'none')
|
|
2567
|
-
decorationText(drawData, style);
|
|
2684
|
+
if (drawData.overflow) clipText(drawData, style, x, width);
|
|
2685
|
+
if (textDecoration !== "none") decorationText(drawData, style);
|
|
2568
2686
|
return drawData;
|
|
2569
2687
|
}
|
|
2688
|
+
|
|
2570
2689
|
function padAutoText(padding, drawData, style, width, height) {
|
|
2571
2690
|
if (!width && style.autoSizeAlign) {
|
|
2572
2691
|
switch (style.textAlign) {
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2692
|
+
case "left":
|
|
2693
|
+
offsetText(drawData, "x", padding[left]);
|
|
2694
|
+
break;
|
|
2695
|
+
|
|
2696
|
+
case "right":
|
|
2697
|
+
offsetText(drawData, "x", -padding[right]);
|
|
2577
2698
|
}
|
|
2578
2699
|
}
|
|
2579
2700
|
if (!height && style.autoSizeAlign) {
|
|
2580
2701
|
switch (style.verticalAlign) {
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2702
|
+
case "top":
|
|
2703
|
+
offsetText(drawData, "y", padding[top]);
|
|
2704
|
+
break;
|
|
2705
|
+
|
|
2706
|
+
case "bottom":
|
|
2707
|
+
offsetText(drawData, "y", -padding[bottom]);
|
|
2585
2708
|
}
|
|
2586
2709
|
}
|
|
2587
2710
|
}
|
|
2711
|
+
|
|
2588
2712
|
function offsetText(drawData, attrName, value) {
|
|
2589
|
-
const { bounds, rows } = drawData;
|
|
2713
|
+
const {bounds: bounds, rows: rows} = drawData;
|
|
2590
2714
|
bounds[attrName] += value;
|
|
2591
|
-
for (let i = 0; i < rows.length; i++)
|
|
2592
|
-
rows[i][attrName] += value;
|
|
2715
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
|
|
2593
2716
|
}
|
|
2594
2717
|
|
|
2595
2718
|
const TextConvertModule = {
|
|
2596
|
-
getDrawData
|
|
2719
|
+
getDrawData: getDrawData
|
|
2597
2720
|
};
|
|
2598
2721
|
|
|
2599
2722
|
function string(color, opacity) {
|
|
2600
|
-
const doOpacity =
|
|
2601
|
-
if (
|
|
2602
|
-
if (doOpacity && ColorConvert.object)
|
|
2603
|
-
color = ColorConvert.object(color);
|
|
2604
|
-
else
|
|
2605
|
-
return color;
|
|
2723
|
+
const doOpacity = isNumber(opacity) && opacity < 1;
|
|
2724
|
+
if (isString(color)) {
|
|
2725
|
+
if (doOpacity && ColorConvert.object) color = ColorConvert.object(color); else return color;
|
|
2606
2726
|
}
|
|
2607
|
-
let a = color.a
|
|
2608
|
-
if (doOpacity)
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
|
|
2727
|
+
let a = isUndefined(color.a) ? 1 : color.a;
|
|
2728
|
+
if (doOpacity) a *= opacity;
|
|
2729
|
+
const rgb = color.r + "," + color.g + "," + color.b;
|
|
2730
|
+
return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
|
|
2612
2731
|
}
|
|
2613
2732
|
|
|
2614
2733
|
const ColorConvertModule = {
|
|
2615
|
-
string
|
|
2734
|
+
string: string
|
|
2616
2735
|
};
|
|
2617
2736
|
|
|
2618
2737
|
Object.assign(TextConvert, TextConvertModule);
|
|
2738
|
+
|
|
2619
2739
|
Object.assign(ColorConvert, ColorConvertModule);
|
|
2740
|
+
|
|
2620
2741
|
Object.assign(Paint, PaintModule);
|
|
2742
|
+
|
|
2621
2743
|
Object.assign(PaintImage, PaintImageModule);
|
|
2744
|
+
|
|
2622
2745
|
Object.assign(PaintGradient, PaintGradientModule);
|
|
2746
|
+
|
|
2623
2747
|
Object.assign(Effect, EffectModule);
|
|
2624
2748
|
|
|
2625
2749
|
Object.assign(Creator, {
|
|
2626
2750
|
interaction: (target, canvas, selector, options) => new Interaction(target, canvas, selector, options),
|
|
2627
2751
|
hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
2628
|
-
hitCanvasManager: () => new HitCanvasManager
|
|
2752
|
+
hitCanvasManager: () => new HitCanvasManager
|
|
2629
2753
|
});
|
|
2630
|
-
|
|
2754
|
+
|
|
2755
|
+
Leafer.prototype.receiveEvent = function(event) {
|
|
2631
2756
|
this.interaction && this.interaction.receive(event);
|
|
2632
2757
|
};
|
|
2758
|
+
|
|
2633
2759
|
try {
|
|
2634
|
-
if (wx)
|
|
2635
|
-
|
|
2636
|
-
}
|
|
2637
|
-
catch (_a) { }
|
|
2760
|
+
if (wx) useCanvas("miniapp", wx);
|
|
2761
|
+
} catch (_a) {}
|
|
2638
2762
|
|
|
2639
2763
|
export { Interaction, Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };
|