@leafer-ui/miniapp 1.8.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 +1182 -1075
- package/dist/miniapp.esm.js +1164 -1070
- 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 +5613 -5139
- 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, getMatrixData, 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,117 +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
1132
|
if (item.transform || item.scaleFixed) {
|
|
1104
1133
|
canvas.save();
|
|
1105
|
-
if (item.transform)
|
|
1106
|
-
canvas.transform(item.transform);
|
|
1134
|
+
if (item.transform) canvas.transform(item.transform);
|
|
1107
1135
|
if (item.scaleFixed) {
|
|
1108
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true);
|
|
1109
|
-
canvas.scale(1 / scaleX, 1 / scaleY);
|
|
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);
|
|
1110
1138
|
}
|
|
1111
|
-
if (item.blendMode)
|
|
1112
|
-
canvas.blendMode = item.blendMode;
|
|
1139
|
+
if (item.blendMode) canvas.blendMode = item.blendMode;
|
|
1113
1140
|
fillPathOrText(ui, canvas);
|
|
1114
1141
|
canvas.restore();
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1142
|
+
} else {
|
|
1117
1143
|
if (item.blendMode) {
|
|
1118
1144
|
canvas.saveBlendMode(item.blendMode);
|
|
1119
1145
|
fillPathOrText(ui, canvas);
|
|
1120
1146
|
canvas.restoreBlendMode();
|
|
1121
|
-
}
|
|
1122
|
-
else
|
|
1123
|
-
fillPathOrText(ui, canvas);
|
|
1147
|
+
} else fillPathOrText(ui, canvas);
|
|
1124
1148
|
}
|
|
1125
1149
|
}
|
|
1126
1150
|
}
|
|
1151
|
+
|
|
1127
1152
|
function fillPathOrText(ui, canvas) {
|
|
1128
|
-
ui.__.__font ? fillText(ui, canvas) :
|
|
1153
|
+
ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
|
|
1129
1154
|
}
|
|
1130
1155
|
|
|
1131
1156
|
function strokeText(stroke, ui, canvas) {
|
|
1132
1157
|
switch (ui.__.strokeAlign) {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
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;
|
|
1142
1169
|
}
|
|
1143
1170
|
}
|
|
1171
|
+
|
|
1144
1172
|
function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
|
|
1145
1173
|
const data = ui.__;
|
|
1146
|
-
if (
|
|
1174
|
+
if (isObject(stroke)) {
|
|
1147
1175
|
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
|
|
1148
|
-
}
|
|
1149
|
-
else {
|
|
1176
|
+
} else {
|
|
1150
1177
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
1151
1178
|
drawTextStroke(ui, canvas);
|
|
1152
1179
|
}
|
|
1153
1180
|
}
|
|
1181
|
+
|
|
1154
1182
|
function drawAlign(stroke, align, ui, canvas) {
|
|
1155
1183
|
const out = canvas.getSameCanvas(true, true);
|
|
1156
1184
|
out.font = ui.__.__font;
|
|
1157
1185
|
drawCenter$1(stroke, 2, ui, out);
|
|
1158
|
-
out.blendMode = align ===
|
|
1186
|
+
out.blendMode = align === "outside" ? "destination-out" : "destination-in";
|
|
1159
1187
|
fillText(ui, out);
|
|
1160
|
-
out.blendMode =
|
|
1188
|
+
out.blendMode = "normal";
|
|
1161
1189
|
LeafHelper.copyCanvasByWorld(ui, canvas, out);
|
|
1162
1190
|
out.recycle(ui.__nowWorld);
|
|
1163
1191
|
}
|
|
1192
|
+
|
|
1164
1193
|
function drawTextStroke(ui, canvas) {
|
|
1165
1194
|
let row, data = ui.__.__textDrawData;
|
|
1166
|
-
const { rows, decorationY } = data;
|
|
1195
|
+
const {rows: rows, decorationY: decorationY} = data;
|
|
1167
1196
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
1168
1197
|
row = rows[i];
|
|
1169
|
-
if (row.text)
|
|
1170
|
-
canvas.strokeText(
|
|
1171
|
-
|
|
1172
|
-
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
|
+
});
|
|
1173
1201
|
}
|
|
1174
1202
|
if (decorationY) {
|
|
1175
|
-
const { decorationHeight
|
|
1203
|
+
const {decorationHeight: decorationHeight} = data;
|
|
1176
1204
|
rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
|
|
1177
1205
|
}
|
|
1178
1206
|
}
|
|
1207
|
+
|
|
1179
1208
|
function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
1180
1209
|
let item;
|
|
1181
|
-
const data = ui.__, { __hasMultiStrokeStyle
|
|
1210
|
+
const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
|
|
1182
1211
|
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
|
|
1183
1212
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
1184
1213
|
item = strokes[i];
|
|
1185
|
-
if (item.image && PaintImage.checkImage(ui, canvas, item, false))
|
|
1186
|
-
continue;
|
|
1214
|
+
if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue;
|
|
1187
1215
|
if (item.style) {
|
|
1188
1216
|
if (__hasMultiStrokeStyle) {
|
|
1189
|
-
const { strokeStyle
|
|
1217
|
+
const {strokeStyle: strokeStyle} = item;
|
|
1190
1218
|
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
|
|
1191
|
-
}
|
|
1192
|
-
else
|
|
1193
|
-
canvas.strokeStyle = item.style;
|
|
1219
|
+
} else canvas.strokeStyle = item.style;
|
|
1194
1220
|
if (item.blendMode) {
|
|
1195
1221
|
canvas.saveBlendMode(item.blendMode);
|
|
1196
1222
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
1197
1223
|
canvas.restoreBlendMode();
|
|
1198
|
-
}
|
|
1199
|
-
else {
|
|
1224
|
+
} else {
|
|
1200
1225
|
isText ? drawTextStroke(ui, canvas) : canvas.stroke();
|
|
1201
1226
|
}
|
|
1202
1227
|
}
|
|
@@ -1205,53 +1230,54 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
|
|
|
1205
1230
|
|
|
1206
1231
|
function stroke(stroke, ui, canvas) {
|
|
1207
1232
|
const data = ui.__;
|
|
1208
|
-
if (!data.__strokeWidth)
|
|
1209
|
-
return;
|
|
1233
|
+
if (!data.__strokeWidth) return;
|
|
1210
1234
|
if (data.__font) {
|
|
1211
1235
|
strokeText(stroke, ui, canvas);
|
|
1212
|
-
}
|
|
1213
|
-
else {
|
|
1236
|
+
} else {
|
|
1214
1237
|
switch (data.strokeAlign) {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
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;
|
|
1224
1249
|
}
|
|
1225
1250
|
}
|
|
1226
1251
|
}
|
|
1252
|
+
|
|
1227
1253
|
function strokes(strokes, ui, canvas) {
|
|
1228
1254
|
stroke(strokes, ui, canvas);
|
|
1229
1255
|
}
|
|
1256
|
+
|
|
1230
1257
|
function drawCenter(stroke, strokeWidthScale, ui, canvas) {
|
|
1231
1258
|
const data = ui.__;
|
|
1232
|
-
if (
|
|
1259
|
+
if (isObject(stroke)) {
|
|
1233
1260
|
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
|
|
1234
|
-
}
|
|
1235
|
-
else {
|
|
1261
|
+
} else {
|
|
1236
1262
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
|
|
1237
1263
|
canvas.stroke();
|
|
1238
1264
|
}
|
|
1239
|
-
if (data.__useArrow)
|
|
1240
|
-
Paint.strokeArrow(stroke, ui, canvas);
|
|
1265
|
+
if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas);
|
|
1241
1266
|
}
|
|
1267
|
+
|
|
1242
1268
|
function drawInside(stroke, ui, canvas) {
|
|
1243
1269
|
canvas.save();
|
|
1244
1270
|
canvas.clipUI(ui);
|
|
1245
1271
|
drawCenter(stroke, 2, ui, canvas);
|
|
1246
1272
|
canvas.restore();
|
|
1247
1273
|
}
|
|
1274
|
+
|
|
1248
1275
|
function drawOutside(stroke, ui, canvas) {
|
|
1249
1276
|
const data = ui.__;
|
|
1250
1277
|
if (data.__fillAfterStroke) {
|
|
1251
1278
|
drawCenter(stroke, 2, ui, canvas);
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
const { renderBounds } = ui.__layout;
|
|
1279
|
+
} else {
|
|
1280
|
+
const {renderBounds: renderBounds} = ui.__layout;
|
|
1255
1281
|
const out = canvas.getSameCanvas(true, true);
|
|
1256
1282
|
ui.__drawRenderPath(out);
|
|
1257
1283
|
drawCenter(stroke, 2, ui, out);
|
|
@@ -1262,25 +1288,23 @@ function drawOutside(stroke, ui, canvas) {
|
|
|
1262
1288
|
}
|
|
1263
1289
|
}
|
|
1264
1290
|
|
|
1265
|
-
const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
|
|
1291
|
+
const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = BoundsHelper;
|
|
1292
|
+
|
|
1266
1293
|
function shape(ui, current, options) {
|
|
1267
1294
|
const canvas = current.getSameCanvas();
|
|
1268
1295
|
const nowWorld = ui.__nowWorld;
|
|
1269
|
-
let bounds, fitMatrix, shapeBounds, worldCanvas;
|
|
1270
|
-
let { scaleX, scaleY } = nowWorld;
|
|
1271
|
-
if (scaleX < 0)
|
|
1272
|
-
|
|
1273
|
-
if (scaleY < 0)
|
|
1274
|
-
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;
|
|
1275
1300
|
if (current.bounds.includes(nowWorld)) {
|
|
1276
1301
|
worldCanvas = canvas;
|
|
1277
1302
|
bounds = shapeBounds = nowWorld;
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
const
|
|
1281
|
-
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);
|
|
1282
1306
|
fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
|
|
1283
|
-
let {
|
|
1307
|
+
let {a: fitScaleX, d: fitScaleY} = fitMatrix;
|
|
1284
1308
|
if (fitMatrix.a < 1) {
|
|
1285
1309
|
worldCanvas = current.getSameCanvas();
|
|
1286
1310
|
ui.__renderShape(worldCanvas, options);
|
|
@@ -1289,28 +1313,39 @@ function shape(ui, current, options) {
|
|
|
1289
1313
|
}
|
|
1290
1314
|
shapeBounds = getOuterOf(nowWorld, fitMatrix);
|
|
1291
1315
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
fitMatrix
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
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
|
+
});
|
|
1299
1327
|
}
|
|
1300
1328
|
ui.__renderShape(canvas, options);
|
|
1301
1329
|
return {
|
|
1302
|
-
canvas
|
|
1303
|
-
|
|
1330
|
+
canvas: canvas,
|
|
1331
|
+
matrix: matrix,
|
|
1332
|
+
fitMatrix: fitMatrix,
|
|
1333
|
+
bounds: bounds,
|
|
1334
|
+
worldCanvas: worldCanvas,
|
|
1335
|
+
shapeBounds: shapeBounds,
|
|
1336
|
+
scaleX: scaleX,
|
|
1337
|
+
scaleY: scaleY
|
|
1304
1338
|
};
|
|
1305
1339
|
}
|
|
1306
1340
|
|
|
1307
1341
|
let recycleMap;
|
|
1308
|
-
|
|
1342
|
+
|
|
1343
|
+
const {stintSet: stintSet} = DataHelper, {hasTransparent: hasTransparent$1} = ColorConvert;
|
|
1344
|
+
|
|
1309
1345
|
function compute(attrName, ui) {
|
|
1310
1346
|
const data = ui.__, leafPaints = [];
|
|
1311
1347
|
let paints = data.__input[attrName], isAlphaPixel, isTransparent;
|
|
1312
|
-
if (!(paints
|
|
1313
|
-
paints = [paints];
|
|
1348
|
+
if (!isArray(paints)) paints = [ paints ];
|
|
1314
1349
|
recycleMap = PaintImage.recycleImage(attrName, data);
|
|
1315
1350
|
let maxChildStrokeWidth;
|
|
1316
1351
|
for (let i = 0, len = paints.length, item; i < len; i++) {
|
|
@@ -1318,206 +1353,222 @@ function compute(attrName, ui) {
|
|
|
1318
1353
|
leafPaints.push(item);
|
|
1319
1354
|
if (item.strokeStyle) {
|
|
1320
1355
|
maxChildStrokeWidth || (maxChildStrokeWidth = 1);
|
|
1321
|
-
if (item.strokeStyle.strokeWidth)
|
|
1322
|
-
maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
1356
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
|
|
1323
1357
|
}
|
|
1324
1358
|
}
|
|
1325
1359
|
}
|
|
1326
|
-
data[
|
|
1360
|
+
data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
|
|
1327
1361
|
if (leafPaints.length) {
|
|
1328
1362
|
if (leafPaints.every(item => item.isTransparent)) {
|
|
1329
|
-
if (leafPaints.some(item => item.image))
|
|
1330
|
-
isAlphaPixel = true;
|
|
1363
|
+
if (leafPaints.some(item => item.image)) isAlphaPixel = true;
|
|
1331
1364
|
isTransparent = true;
|
|
1332
1365
|
}
|
|
1333
1366
|
}
|
|
1334
|
-
if (attrName ===
|
|
1335
|
-
stintSet(data,
|
|
1336
|
-
stintSet(data,
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
stintSet(data,
|
|
1340
|
-
stintSet(data,
|
|
1341
|
-
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
|
|
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);
|
|
1342
1374
|
}
|
|
1343
1375
|
}
|
|
1376
|
+
|
|
1344
1377
|
function getLeafPaint(attrName, paint, ui) {
|
|
1345
|
-
if (
|
|
1346
|
-
return undefined;
|
|
1378
|
+
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
|
|
1347
1379
|
let data;
|
|
1348
|
-
const { boxBounds
|
|
1380
|
+
const {boxBounds: boxBounds} = ui.__layout;
|
|
1349
1381
|
switch (paint.type) {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
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
|
+
};
|
|
1369
1411
|
}
|
|
1370
1412
|
if (data) {
|
|
1371
|
-
if (
|
|
1372
|
-
data.isTransparent = true;
|
|
1413
|
+
if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
|
|
1373
1414
|
if (paint.style) {
|
|
1374
|
-
if (paint.style.strokeWidth === 0)
|
|
1375
|
-
return undefined;
|
|
1415
|
+
if (paint.style.strokeWidth === 0) return undefined;
|
|
1376
1416
|
data.strokeStyle = paint.style;
|
|
1377
1417
|
}
|
|
1378
|
-
if (paint.
|
|
1379
|
-
|
|
1418
|
+
if (paint.editing) data.editing = paint.editing;
|
|
1419
|
+
if (paint.blendMode) data.blendMode = paint.blendMode;
|
|
1380
1420
|
}
|
|
1381
1421
|
return data;
|
|
1382
1422
|
}
|
|
1383
1423
|
|
|
1384
1424
|
const PaintModule = {
|
|
1385
|
-
compute,
|
|
1386
|
-
fill,
|
|
1387
|
-
fills,
|
|
1388
|
-
fillPathOrText,
|
|
1389
|
-
fillText,
|
|
1390
|
-
stroke,
|
|
1391
|
-
strokes,
|
|
1392
|
-
strokeText,
|
|
1393
|
-
drawTextStroke,
|
|
1394
|
-
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
|
|
1395
1435
|
};
|
|
1396
1436
|
|
|
1397
1437
|
let origin = {}, tempMatrix = getMatrixData();
|
|
1398
|
-
|
|
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
|
+
|
|
1399
1441
|
function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
|
|
1400
1442
|
const transform = get$3();
|
|
1401
1443
|
translate$1(transform, box.x + x, box.y + y);
|
|
1402
1444
|
scaleHelper(transform, scaleX, scaleY);
|
|
1403
|
-
if (rotation)
|
|
1404
|
-
|
|
1445
|
+
if (rotation) rotateOfOuter$1(transform, {
|
|
1446
|
+
x: box.x + box.width / 2,
|
|
1447
|
+
y: box.y + box.height / 2
|
|
1448
|
+
}, rotation);
|
|
1405
1449
|
data.transform = transform;
|
|
1406
1450
|
}
|
|
1451
|
+
|
|
1407
1452
|
function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
|
|
1408
1453
|
const transform = get$3();
|
|
1409
|
-
|
|
1410
|
-
rotate(transform, rotation);
|
|
1411
|
-
if (skew)
|
|
1412
|
-
skewHelper(transform, skew.x, skew.y);
|
|
1413
|
-
if (scaleX)
|
|
1414
|
-
scaleHelper(transform, scaleX, scaleY);
|
|
1415
|
-
translate$1(transform, box.x + x, box.y + y);
|
|
1454
|
+
layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
|
|
1416
1455
|
if (clipSize) {
|
|
1417
1456
|
tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
|
|
1418
1457
|
multiplyParent(transform, tempMatrix);
|
|
1419
1458
|
}
|
|
1420
1459
|
data.transform = transform;
|
|
1421
1460
|
}
|
|
1422
|
-
|
|
1461
|
+
|
|
1462
|
+
function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
|
|
1423
1463
|
const transform = get$3();
|
|
1424
|
-
if (
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
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:
|
|
1432
1477
|
translate$1(transform, height, 0);
|
|
1433
1478
|
break;
|
|
1434
|
-
|
|
1479
|
+
|
|
1480
|
+
case 180:
|
|
1435
1481
|
translate$1(transform, width, height);
|
|
1436
1482
|
break;
|
|
1437
|
-
|
|
1483
|
+
|
|
1484
|
+
case 270:
|
|
1438
1485
|
translate$1(transform, 0, width);
|
|
1439
1486
|
break;
|
|
1487
|
+
}
|
|
1440
1488
|
}
|
|
1441
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);
|
|
1442
1494
|
}
|
|
1443
|
-
origin.x = box.x + x;
|
|
1444
|
-
origin.y = box.y + y;
|
|
1445
|
-
translate$1(transform, origin.x, origin.y);
|
|
1446
|
-
if (scaleX)
|
|
1447
|
-
scaleOfOuter$1(transform, origin, scaleX, scaleY);
|
|
1448
1495
|
data.transform = transform;
|
|
1449
1496
|
}
|
|
1450
1497
|
|
|
1451
|
-
|
|
1452
|
-
|
|
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
|
+
|
|
1453
1509
|
const tempScaleData = {};
|
|
1510
|
+
|
|
1454
1511
|
const tempImage = {};
|
|
1512
|
+
|
|
1455
1513
|
function createData(leafPaint, image, paint, box) {
|
|
1456
|
-
const { changeful, sync
|
|
1457
|
-
if (changeful)
|
|
1458
|
-
|
|
1459
|
-
if (
|
|
1460
|
-
leafPaint.sync = sync;
|
|
1461
|
-
if (editing)
|
|
1462
|
-
leafPaint.editing = editing;
|
|
1463
|
-
if (scaleFixed)
|
|
1464
|
-
leafPaint.scaleFixed = scaleFixed;
|
|
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;
|
|
1465
1518
|
leafPaint.data = getPatternData(paint, box, image);
|
|
1466
1519
|
}
|
|
1520
|
+
|
|
1467
1521
|
function getPatternData(paint, box, image) {
|
|
1468
|
-
if (paint.padding)
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
let { width, height } = image;
|
|
1473
|
-
const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, 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;
|
|
1474
1526
|
const sameBox = box.width === width && box.height === height;
|
|
1475
|
-
const data = {
|
|
1476
|
-
|
|
1527
|
+
const data = {
|
|
1528
|
+
mode: mode
|
|
1529
|
+
};
|
|
1530
|
+
const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
|
|
1477
1531
|
BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
|
|
1478
1532
|
let scaleX, scaleY;
|
|
1479
|
-
if (!mode || mode ===
|
|
1533
|
+
if (!mode || mode === "cover" || mode === "fit") {
|
|
1480
1534
|
if (!sameBox || rotation) {
|
|
1481
|
-
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !==
|
|
1535
|
+
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
|
|
1482
1536
|
BoundsHelper.put(box, image, align, scaleX, false, tempImage);
|
|
1483
1537
|
BoundsHelper.scale(tempImage, scaleX, scaleY, true);
|
|
1484
1538
|
}
|
|
1485
|
-
}
|
|
1486
|
-
else {
|
|
1539
|
+
} else {
|
|
1487
1540
|
if (scale || size) {
|
|
1488
1541
|
MathHelper.getScaleData(scale, size, image, tempScaleData);
|
|
1489
1542
|
scaleX = tempScaleData.scaleX;
|
|
1490
1543
|
scaleY = tempScaleData.scaleY;
|
|
1491
1544
|
}
|
|
1492
|
-
if (align) {
|
|
1493
|
-
if (scaleX)
|
|
1494
|
-
|
|
1495
|
-
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);
|
|
1496
1548
|
}
|
|
1497
1549
|
}
|
|
1498
|
-
if (offset)
|
|
1499
|
-
PointHelper.move(tempImage, offset);
|
|
1550
|
+
if (offset) PointHelper.move(tempImage, offset);
|
|
1500
1551
|
switch (mode) {
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
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);
|
|
1521
1572
|
}
|
|
1522
1573
|
if (!data.transform) {
|
|
1523
1574
|
if (box.x || box.y) {
|
|
@@ -1525,49 +1576,69 @@ function getPatternData(paint, box, image) {
|
|
|
1525
1576
|
translate(data.transform, box.x, box.y);
|
|
1526
1577
|
}
|
|
1527
1578
|
}
|
|
1528
|
-
if (scaleX && mode !==
|
|
1579
|
+
if (scaleX && mode !== "stretch") {
|
|
1529
1580
|
data.scaleX = scaleX;
|
|
1530
1581
|
data.scaleY = scaleY;
|
|
1531
1582
|
}
|
|
1532
1583
|
data.width = width;
|
|
1533
1584
|
data.height = height;
|
|
1534
|
-
if (opacity)
|
|
1535
|
-
|
|
1536
|
-
if (
|
|
1537
|
-
data.filters = filters;
|
|
1538
|
-
if (repeat)
|
|
1539
|
-
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";
|
|
1540
1588
|
return data;
|
|
1541
1589
|
}
|
|
1542
1590
|
|
|
1543
|
-
|
|
1544
|
-
|
|
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
|
+
|
|
1545
1611
|
function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
1546
1612
|
let leafPaint, event;
|
|
1547
1613
|
const image = ImageManager.get(paint);
|
|
1548
1614
|
if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
|
|
1549
1615
|
leafPaint = cache.leafPaint;
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
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
|
+
};
|
|
1559
1633
|
if (image.ready) {
|
|
1560
1634
|
checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
|
|
1561
1635
|
if (firstUse) {
|
|
1562
1636
|
onLoad(ui, event);
|
|
1563
1637
|
onLoadSuccess(ui, event);
|
|
1564
1638
|
}
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
onLoadError(ui, event, image.error);
|
|
1569
|
-
}
|
|
1570
|
-
else {
|
|
1639
|
+
} else if (image.error) {
|
|
1640
|
+
if (firstUse) onLoadError(ui, event, image.error);
|
|
1641
|
+
} else {
|
|
1571
1642
|
if (firstUse) {
|
|
1572
1643
|
ignoreRender(ui, true);
|
|
1573
1644
|
onLoad(ui, event);
|
|
@@ -1576,79 +1647,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
|
|
|
1576
1647
|
ignoreRender(ui, false);
|
|
1577
1648
|
if (!ui.destroyed) {
|
|
1578
1649
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
1579
|
-
if (image.hasAlphaPixel)
|
|
1580
|
-
|
|
1581
|
-
ui.forceUpdate('surface');
|
|
1650
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
|
|
1651
|
+
ui.forceUpdate("surface");
|
|
1582
1652
|
}
|
|
1583
1653
|
onLoadSuccess(ui, event);
|
|
1584
1654
|
}
|
|
1585
1655
|
leafPaint.loadId = undefined;
|
|
1586
|
-
},
|
|
1656
|
+
}, error => {
|
|
1587
1657
|
ignoreRender(ui, false);
|
|
1588
1658
|
onLoadError(ui, event, error);
|
|
1589
1659
|
leafPaint.loadId = undefined;
|
|
1590
1660
|
});
|
|
1591
1661
|
if (ui.placeholderColor) {
|
|
1592
|
-
if (!ui.placeholderDelay)
|
|
1593
|
-
image.
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
ui.forceUpdate('surface');
|
|
1599
|
-
}
|
|
1600
|
-
}, 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);
|
|
1601
1668
|
}
|
|
1602
1669
|
}
|
|
1603
1670
|
return leafPaint;
|
|
1604
1671
|
}
|
|
1672
|
+
|
|
1605
1673
|
function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
|
|
1606
|
-
if (attrName ===
|
|
1674
|
+
if (attrName === "fill" && !ui.__.__naturalWidth) {
|
|
1607
1675
|
const data = ui.__;
|
|
1608
1676
|
data.__naturalWidth = image.width / data.pixelRatio;
|
|
1609
1677
|
data.__naturalHeight = image.height / data.pixelRatio;
|
|
1610
1678
|
if (data.__autoSide) {
|
|
1611
|
-
ui.forceUpdate(
|
|
1679
|
+
ui.forceUpdate("width");
|
|
1612
1680
|
if (ui.__proxyData) {
|
|
1613
|
-
ui.setProxyAttr(
|
|
1614
|
-
ui.setProxyAttr(
|
|
1681
|
+
ui.setProxyAttr("width", data.width);
|
|
1682
|
+
ui.setProxyAttr("height", data.height);
|
|
1615
1683
|
}
|
|
1616
1684
|
return false;
|
|
1617
1685
|
}
|
|
1618
1686
|
}
|
|
1619
|
-
if (!leafPaint.data)
|
|
1620
|
-
createData(leafPaint, image, paint, boxBounds);
|
|
1687
|
+
if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
|
|
1621
1688
|
return true;
|
|
1622
1689
|
}
|
|
1690
|
+
|
|
1623
1691
|
function onLoad(ui, event) {
|
|
1624
1692
|
emit(ui, ImageEvent.LOAD, event);
|
|
1625
1693
|
}
|
|
1694
|
+
|
|
1626
1695
|
function onLoadSuccess(ui, event) {
|
|
1627
1696
|
emit(ui, ImageEvent.LOADED, event);
|
|
1628
1697
|
}
|
|
1698
|
+
|
|
1629
1699
|
function onLoadError(ui, event, error) {
|
|
1630
1700
|
event.error = error;
|
|
1631
|
-
ui.forceUpdate(
|
|
1701
|
+
ui.forceUpdate("surface");
|
|
1632
1702
|
emit(ui, ImageEvent.ERROR, event);
|
|
1633
1703
|
}
|
|
1704
|
+
|
|
1634
1705
|
function emit(ui, type, data) {
|
|
1635
|
-
if (ui.hasEvent(type))
|
|
1636
|
-
ui.emitEvent(new ImageEvent(type, data));
|
|
1706
|
+
if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
|
|
1637
1707
|
}
|
|
1708
|
+
|
|
1638
1709
|
function ignoreRender(ui, value) {
|
|
1639
|
-
const { leafer
|
|
1640
|
-
if (leafer && leafer.viewReady)
|
|
1641
|
-
leafer.renderer.ignore = value;
|
|
1710
|
+
const {leafer: leafer} = ui;
|
|
1711
|
+
if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
|
|
1642
1712
|
}
|
|
1643
1713
|
|
|
1644
|
-
const {
|
|
1645
|
-
|
|
1714
|
+
const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
|
|
1715
|
+
|
|
1716
|
+
const {floor: floor, max: max, abs: abs} = Math;
|
|
1717
|
+
|
|
1646
1718
|
function createPattern(ui, paint, pixelRatio) {
|
|
1647
|
-
let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1648
|
-
const id = scaleX +
|
|
1719
|
+
let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1720
|
+
const id = scaleX + "-" + scaleY + "-" + pixelRatio;
|
|
1649
1721
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1650
|
-
const { image, data } = paint;
|
|
1651
|
-
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
|
|
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;
|
|
1652
1728
|
if (sx) {
|
|
1653
1729
|
sx = abs(sx);
|
|
1654
1730
|
sy = abs(sy);
|
|
@@ -1658,23 +1734,18 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1658
1734
|
scaleX *= sx;
|
|
1659
1735
|
scaleY *= sy;
|
|
1660
1736
|
}
|
|
1661
|
-
scaleX *= pixelRatio;
|
|
1662
|
-
scaleY *= pixelRatio;
|
|
1663
1737
|
width *= scaleX;
|
|
1664
1738
|
height *= scaleY;
|
|
1665
1739
|
const size = width * height;
|
|
1666
1740
|
if (!repeat) {
|
|
1667
|
-
if (size > Platform.image.maxCacheSize)
|
|
1668
|
-
return false;
|
|
1741
|
+
if (size > Platform.image.maxCacheSize) return false;
|
|
1669
1742
|
}
|
|
1670
1743
|
let maxSize = Platform.image.maxPatternSize;
|
|
1671
1744
|
if (!image.isSVG) {
|
|
1672
1745
|
const imageSize = image.width * image.height;
|
|
1673
|
-
if (maxSize > imageSize)
|
|
1674
|
-
maxSize = imageSize;
|
|
1746
|
+
if (maxSize > imageSize) maxSize = imageSize;
|
|
1675
1747
|
}
|
|
1676
|
-
if (size > maxSize)
|
|
1677
|
-
imageScale = Math.sqrt(size / maxSize);
|
|
1748
|
+
if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
|
|
1678
1749
|
if (imageScale) {
|
|
1679
1750
|
scaleX /= imageScale;
|
|
1680
1751
|
scaleY /= imageScale;
|
|
@@ -1688,97 +1759,95 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1688
1759
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1689
1760
|
if (!imageMatrix) {
|
|
1690
1761
|
imageMatrix = get$1();
|
|
1691
|
-
if (transform)
|
|
1692
|
-
copy$1(imageMatrix, transform);
|
|
1762
|
+
if (transform) copy$1(imageMatrix, transform);
|
|
1693
1763
|
}
|
|
1694
1764
|
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1695
1765
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
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);
|
|
1698
1772
|
paint.style = pattern;
|
|
1699
1773
|
paint.patternId = id;
|
|
1700
1774
|
return true;
|
|
1701
|
-
}
|
|
1702
|
-
else {
|
|
1775
|
+
} else {
|
|
1703
1776
|
return false;
|
|
1704
1777
|
}
|
|
1705
1778
|
}
|
|
1706
1779
|
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
function
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
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;
|
|
1737
1811
|
};
|
|
1738
1812
|
|
|
1739
1813
|
function checkImage(ui, canvas, paint, allowDraw) {
|
|
1740
|
-
const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
|
|
1741
|
-
const { pixelRatio
|
|
1742
|
-
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) {
|
|
1743
1817
|
return false;
|
|
1744
|
-
}
|
|
1745
|
-
else {
|
|
1818
|
+
} else {
|
|
1746
1819
|
if (allowDraw) {
|
|
1747
1820
|
if (data.repeat) {
|
|
1748
1821
|
allowDraw = false;
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
let { width, height } = data;
|
|
1822
|
+
} else {
|
|
1823
|
+
if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
|
|
1824
|
+
let {width: width, height: height} = data;
|
|
1753
1825
|
width *= scaleX * pixelRatio;
|
|
1754
1826
|
height *= scaleY * pixelRatio;
|
|
1755
1827
|
if (data.scaleX) {
|
|
1756
1828
|
width *= data.scaleX;
|
|
1757
1829
|
height *= data.scaleY;
|
|
1758
1830
|
}
|
|
1759
|
-
allowDraw =
|
|
1831
|
+
allowDraw = width * height > Platform.image.maxCacheSize;
|
|
1760
1832
|
}
|
|
1761
1833
|
}
|
|
1762
1834
|
}
|
|
1763
1835
|
if (allowDraw) {
|
|
1764
1836
|
if (ui.__.__isFastShadow) {
|
|
1765
|
-
canvas.fillStyle = paint.style ||
|
|
1837
|
+
canvas.fillStyle = paint.style || "#000";
|
|
1766
1838
|
canvas.fill();
|
|
1767
1839
|
}
|
|
1768
1840
|
drawImage(ui, canvas, paint, data);
|
|
1769
1841
|
return true;
|
|
1770
|
-
}
|
|
1771
|
-
else {
|
|
1842
|
+
} else {
|
|
1772
1843
|
if (!paint.style || paint.sync || Export.running) {
|
|
1773
1844
|
createPattern(ui, paint, pixelRatio);
|
|
1774
|
-
}
|
|
1775
|
-
else {
|
|
1845
|
+
} else {
|
|
1776
1846
|
if (!paint.patternTask) {
|
|
1777
|
-
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*() {
|
|
1778
1848
|
paint.patternTask = null;
|
|
1779
|
-
if (canvas.bounds.hit(ui.__nowWorld))
|
|
1780
|
-
|
|
1781
|
-
ui.forceUpdate('surface');
|
|
1849
|
+
if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
|
|
1850
|
+
ui.forceUpdate("surface");
|
|
1782
1851
|
}), 300);
|
|
1783
1852
|
}
|
|
1784
1853
|
}
|
|
@@ -1786,39 +1855,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
|
|
|
1786
1855
|
}
|
|
1787
1856
|
}
|
|
1788
1857
|
}
|
|
1858
|
+
|
|
1789
1859
|
function drawImage(ui, canvas, paint, data) {
|
|
1790
1860
|
canvas.save();
|
|
1791
1861
|
canvas.clipUI(ui);
|
|
1792
|
-
if (paint.blendMode)
|
|
1793
|
-
|
|
1794
|
-
if (data.
|
|
1795
|
-
canvas.opacity *= data.opacity;
|
|
1796
|
-
if (data.transform)
|
|
1797
|
-
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);
|
|
1798
1865
|
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
|
|
1799
1866
|
canvas.restore();
|
|
1800
1867
|
}
|
|
1801
1868
|
|
|
1802
1869
|
function recycleImage(attrName, data) {
|
|
1803
|
-
const paints = data[
|
|
1804
|
-
if (paints
|
|
1870
|
+
const paints = data["_" + attrName];
|
|
1871
|
+
if (isArray(paints)) {
|
|
1805
1872
|
let paint, image, recycleMap, input, url;
|
|
1806
1873
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1807
1874
|
paint = paints[i];
|
|
1808
1875
|
image = paint.image;
|
|
1809
1876
|
url = image && image.url;
|
|
1810
1877
|
if (url) {
|
|
1811
|
-
if (!recycleMap)
|
|
1812
|
-
recycleMap = {};
|
|
1878
|
+
if (!recycleMap) recycleMap = {};
|
|
1813
1879
|
recycleMap[url] = true;
|
|
1814
1880
|
ImageManager.recycle(image);
|
|
1815
1881
|
if (image.loading) {
|
|
1816
1882
|
if (!input) {
|
|
1817
|
-
input =
|
|
1818
|
-
if (!(input
|
|
1819
|
-
input = [input];
|
|
1883
|
+
input = data.__input && data.__input[attrName] || [];
|
|
1884
|
+
if (!isArray(input)) input = [ input ];
|
|
1820
1885
|
}
|
|
1821
|
-
image.unload(paints[i].loadId, !input.some(
|
|
1886
|
+
image.unload(paints[i].loadId, !input.some(item => item.url === url));
|
|
1822
1887
|
}
|
|
1823
1888
|
}
|
|
1824
1889
|
}
|
|
@@ -1828,75 +1893,85 @@ function recycleImage(attrName, data) {
|
|
|
1828
1893
|
}
|
|
1829
1894
|
|
|
1830
1895
|
const PaintImageModule = {
|
|
1831
|
-
image,
|
|
1832
|
-
checkImage,
|
|
1833
|
-
createPattern,
|
|
1834
|
-
recycleImage,
|
|
1835
|
-
createData,
|
|
1836
|
-
getPatternData,
|
|
1837
|
-
fillOrFitMode,
|
|
1838
|
-
clipMode,
|
|
1839
|
-
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
|
|
1840
1905
|
};
|
|
1841
1906
|
|
|
1842
|
-
const {
|
|
1907
|
+
const {toPoint: toPoint$2} = AroundHelper, {hasTransparent: hasTransparent} = ColorConvert;
|
|
1908
|
+
|
|
1843
1909
|
const realFrom$2 = {};
|
|
1910
|
+
|
|
1844
1911
|
const realTo$2 = {};
|
|
1912
|
+
|
|
1845
1913
|
function linearGradient(paint, box) {
|
|
1846
|
-
let { from, to, type, opacity } = paint;
|
|
1847
|
-
toPoint$2(from ||
|
|
1848
|
-
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);
|
|
1849
1917
|
const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
|
|
1850
|
-
const data = {
|
|
1918
|
+
const data = {
|
|
1919
|
+
type: type,
|
|
1920
|
+
style: style
|
|
1921
|
+
};
|
|
1851
1922
|
applyStops(data, style, paint.stops, opacity);
|
|
1852
1923
|
return data;
|
|
1853
1924
|
}
|
|
1925
|
+
|
|
1854
1926
|
function applyStops(data, gradient, stops, opacity) {
|
|
1855
1927
|
if (stops) {
|
|
1856
1928
|
let stop, color, offset, isTransparent;
|
|
1857
1929
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
1858
1930
|
stop = stops[i];
|
|
1859
|
-
if (
|
|
1860
|
-
|
|
1861
|
-
else
|
|
1862
|
-
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);
|
|
1863
1933
|
gradient.addColorStop(offset, color);
|
|
1864
|
-
if (!isTransparent && hasTransparent(color))
|
|
1865
|
-
isTransparent = true;
|
|
1934
|
+
if (!isTransparent && hasTransparent(color)) isTransparent = true;
|
|
1866
1935
|
}
|
|
1867
|
-
if (isTransparent)
|
|
1868
|
-
data.isTransparent = true;
|
|
1936
|
+
if (isTransparent) data.isTransparent = true;
|
|
1869
1937
|
}
|
|
1870
1938
|
}
|
|
1871
1939
|
|
|
1872
|
-
const { getAngle, getDistance: getDistance$1
|
|
1873
|
-
|
|
1874
|
-
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
|
+
|
|
1875
1946
|
const realFrom$1 = {};
|
|
1947
|
+
|
|
1876
1948
|
const realTo$1 = {};
|
|
1949
|
+
|
|
1877
1950
|
function radialGradient(paint, box) {
|
|
1878
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1879
|
-
toPoint$1(from ||
|
|
1880
|
-
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);
|
|
1881
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));
|
|
1882
|
-
const data = {
|
|
1955
|
+
const data = {
|
|
1956
|
+
type: type,
|
|
1957
|
+
style: style
|
|
1958
|
+
};
|
|
1883
1959
|
applyStops(data, style, paint.stops, opacity);
|
|
1884
1960
|
const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
|
|
1885
|
-
if (transform)
|
|
1886
|
-
data.transform = transform;
|
|
1961
|
+
if (transform) data.transform = transform;
|
|
1887
1962
|
return data;
|
|
1888
1963
|
}
|
|
1964
|
+
|
|
1889
1965
|
function getTransform(box, from, to, stretch, rotate90) {
|
|
1890
1966
|
let transform;
|
|
1891
|
-
const { width, height } = box;
|
|
1967
|
+
const {width: width, height: height} = box;
|
|
1892
1968
|
if (width !== height || stretch) {
|
|
1893
1969
|
const angle = getAngle(from, to);
|
|
1894
1970
|
transform = get();
|
|
1895
1971
|
if (rotate90) {
|
|
1896
1972
|
scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
|
|
1897
1973
|
rotateOfOuter(transform, from, angle + 90);
|
|
1898
|
-
}
|
|
1899
|
-
else {
|
|
1974
|
+
} else {
|
|
1900
1975
|
scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
|
|
1901
1976
|
rotateOfOuter(transform, from, angle);
|
|
1902
1977
|
}
|
|
@@ -1904,81 +1979,94 @@ function getTransform(box, from, to, stretch, rotate90) {
|
|
|
1904
1979
|
return transform;
|
|
1905
1980
|
}
|
|
1906
1981
|
|
|
1907
|
-
const { getDistance
|
|
1908
|
-
|
|
1982
|
+
const {getDistance: getDistance} = PointHelper;
|
|
1983
|
+
|
|
1984
|
+
const {toPoint: toPoint} = AroundHelper;
|
|
1985
|
+
|
|
1909
1986
|
const realFrom = {};
|
|
1987
|
+
|
|
1910
1988
|
const realTo = {};
|
|
1989
|
+
|
|
1911
1990
|
function conicGradient(paint, box) {
|
|
1912
|
-
let { from, to, type, opacity, stretch } = paint;
|
|
1913
|
-
toPoint(from ||
|
|
1914
|
-
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);
|
|
1915
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));
|
|
1916
|
-
const data = {
|
|
1995
|
+
const data = {
|
|
1996
|
+
type: type,
|
|
1997
|
+
style: style
|
|
1998
|
+
};
|
|
1917
1999
|
applyStops(data, style, paint.stops, opacity);
|
|
1918
2000
|
const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
|
|
1919
|
-
if (transform)
|
|
1920
|
-
data.transform = transform;
|
|
2001
|
+
if (transform) data.transform = transform;
|
|
1921
2002
|
return data;
|
|
1922
2003
|
}
|
|
1923
2004
|
|
|
1924
2005
|
const PaintGradientModule = {
|
|
1925
|
-
linearGradient,
|
|
1926
|
-
radialGradient,
|
|
1927
|
-
conicGradient,
|
|
1928
|
-
getTransform
|
|
2006
|
+
linearGradient: linearGradient,
|
|
2007
|
+
radialGradient: radialGradient,
|
|
2008
|
+
conicGradient: conicGradient,
|
|
2009
|
+
getTransform: getTransform
|
|
1929
2010
|
};
|
|
1930
2011
|
|
|
1931
|
-
const { copy, toOffsetOutBounds: toOffsetOutBounds$1
|
|
2012
|
+
const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
|
|
2013
|
+
|
|
1932
2014
|
const tempBounds = {};
|
|
2015
|
+
|
|
1933
2016
|
const offsetOutBounds$1 = {};
|
|
2017
|
+
|
|
1934
2018
|
function shadow(ui, current, shape) {
|
|
1935
2019
|
let copyBounds, spreadScale;
|
|
1936
|
-
const {
|
|
1937
|
-
const { shadow
|
|
1938
|
-
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;
|
|
1939
2023
|
const other = current.getSameCanvas();
|
|
1940
2024
|
const end = shadow.length - 1;
|
|
1941
2025
|
toOffsetOutBounds$1(bounds, offsetOutBounds$1);
|
|
1942
2026
|
shadow.forEach((item, index) => {
|
|
1943
|
-
|
|
1944
|
-
|
|
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;
|
|
1945
2034
|
drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
|
|
1946
2035
|
copyBounds = bounds;
|
|
1947
2036
|
if (item.box) {
|
|
1948
2037
|
other.restore();
|
|
1949
2038
|
other.save();
|
|
1950
2039
|
if (worldCanvas) {
|
|
1951
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
2040
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
1952
2041
|
copyBounds = nowWorld;
|
|
1953
2042
|
}
|
|
1954
|
-
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
2043
|
+
worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
|
|
1955
2044
|
}
|
|
1956
2045
|
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
1957
|
-
if (end && index < end)
|
|
1958
|
-
other.clearWorld(copyBounds, true);
|
|
2046
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
1959
2047
|
});
|
|
1960
2048
|
other.recycle(copyBounds);
|
|
1961
2049
|
}
|
|
2050
|
+
|
|
1962
2051
|
function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
1963
|
-
const { bounds, shapeBounds } = shape;
|
|
2052
|
+
const {bounds: bounds, shapeBounds: shapeBounds} = shape;
|
|
1964
2053
|
if (Platform.fullImageShadow) {
|
|
1965
2054
|
copy(tempBounds, canvas.bounds);
|
|
1966
|
-
tempBounds.x +=
|
|
1967
|
-
tempBounds.y +=
|
|
2055
|
+
tempBounds.x += outBounds.x - shapeBounds.x;
|
|
2056
|
+
tempBounds.y += outBounds.y - shapeBounds.y;
|
|
1968
2057
|
if (spreadScale) {
|
|
1969
|
-
const {
|
|
1970
|
-
tempBounds.x -= (bounds.x + (
|
|
1971
|
-
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);
|
|
1972
2061
|
tempBounds.width *= spreadScale;
|
|
1973
2062
|
tempBounds.height *= spreadScale;
|
|
1974
2063
|
}
|
|
1975
2064
|
canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
|
|
1976
|
-
}
|
|
1977
|
-
else {
|
|
2065
|
+
} else {
|
|
1978
2066
|
if (spreadScale) {
|
|
1979
2067
|
copy(tempBounds, outBounds);
|
|
1980
|
-
tempBounds.x -=
|
|
1981
|
-
tempBounds.y -=
|
|
2068
|
+
tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
|
|
2069
|
+
tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
|
|
1982
2070
|
tempBounds.width *= spreadScale;
|
|
1983
2071
|
tempBounds.height *= spreadScale;
|
|
1984
2072
|
}
|
|
@@ -1986,174 +2074,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
|
|
|
1986
2074
|
}
|
|
1987
2075
|
}
|
|
1988
2076
|
|
|
1989
|
-
const { toOffsetOutBounds
|
|
2077
|
+
const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
|
|
2078
|
+
|
|
1990
2079
|
const offsetOutBounds = {};
|
|
2080
|
+
|
|
1991
2081
|
function innerShadow(ui, current, shape) {
|
|
1992
2082
|
let copyBounds, spreadScale;
|
|
1993
|
-
const {
|
|
1994
|
-
const { innerShadow
|
|
1995
|
-
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;
|
|
1996
2086
|
const other = current.getSameCanvas();
|
|
1997
2087
|
const end = innerShadow.length - 1;
|
|
1998
2088
|
toOffsetOutBounds(bounds, offsetOutBounds);
|
|
1999
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
|
+
}
|
|
2000
2095
|
other.save();
|
|
2001
|
-
other.setWorldShadow(
|
|
2002
|
-
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;
|
|
2003
2098
|
drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
|
|
2004
2099
|
other.restore();
|
|
2005
2100
|
if (worldCanvas) {
|
|
2006
|
-
other.copyWorld(other, bounds, nowWorld,
|
|
2007
|
-
other.copyWorld(worldCanvas, nowWorld, nowWorld,
|
|
2101
|
+
other.copyWorld(other, bounds, nowWorld, "copy");
|
|
2102
|
+
other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
|
|
2008
2103
|
copyBounds = nowWorld;
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
|
|
2104
|
+
} else {
|
|
2105
|
+
other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
|
|
2012
2106
|
copyBounds = bounds;
|
|
2013
2107
|
}
|
|
2014
|
-
other.fillWorld(copyBounds, ColorConvert.string(item.color),
|
|
2108
|
+
other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
|
|
2015
2109
|
LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
|
|
2016
|
-
if (end && index < end)
|
|
2017
|
-
other.clearWorld(copyBounds, true);
|
|
2110
|
+
if (end && index < end) other.clearWorld(copyBounds, true);
|
|
2018
2111
|
});
|
|
2019
2112
|
other.recycle(copyBounds);
|
|
2020
2113
|
}
|
|
2021
2114
|
|
|
2022
2115
|
function blur(ui, current, origin) {
|
|
2023
|
-
const { blur
|
|
2116
|
+
const {blur: blur} = ui.__;
|
|
2024
2117
|
origin.setWorldBlur(blur * ui.__nowWorld.a);
|
|
2025
2118
|
origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
|
|
2026
|
-
origin.filter =
|
|
2119
|
+
origin.filter = "none";
|
|
2027
2120
|
}
|
|
2028
2121
|
|
|
2029
|
-
function backgroundBlur(_ui, _current, _shape) {
|
|
2030
|
-
}
|
|
2122
|
+
function backgroundBlur(_ui, _current, _shape) {}
|
|
2031
2123
|
|
|
2032
2124
|
const EffectModule = {
|
|
2033
|
-
shadow,
|
|
2034
|
-
innerShadow,
|
|
2035
|
-
blur,
|
|
2036
|
-
backgroundBlur
|
|
2125
|
+
shadow: shadow,
|
|
2126
|
+
innerShadow: innerShadow,
|
|
2127
|
+
blur: blur,
|
|
2128
|
+
backgroundBlur: backgroundBlur
|
|
2037
2129
|
};
|
|
2038
2130
|
|
|
2039
|
-
const { excludeRenderBounds
|
|
2040
|
-
|
|
2131
|
+
const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
|
|
2132
|
+
|
|
2133
|
+
let usedGrayscaleAlpha;
|
|
2134
|
+
|
|
2135
|
+
Group.prototype.__renderMask = function(canvas, options) {
|
|
2041
2136
|
let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
|
|
2042
|
-
const { children
|
|
2137
|
+
const {children: children} = this;
|
|
2043
2138
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
2044
2139
|
child = children[i], mask = child.__.mask;
|
|
2045
2140
|
if (mask) {
|
|
2046
2141
|
if (currentMask) {
|
|
2047
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
2142
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
2048
2143
|
maskCanvas = contentCanvas = null;
|
|
2049
2144
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
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";
|
|
2059
2153
|
canvas.save();
|
|
2060
2154
|
}
|
|
2061
2155
|
child.__clip(contentCanvas || canvas, options);
|
|
2062
|
-
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
if (!
|
|
2066
|
-
maskCanvas = getCanvas(canvas);
|
|
2067
|
-
if (!contentCanvas)
|
|
2068
|
-
contentCanvas = getCanvas(canvas);
|
|
2156
|
+
} else {
|
|
2157
|
+
currentMask = mask === "grayscale" ? "grayscale" : "alpha";
|
|
2158
|
+
if (!maskCanvas) maskCanvas = getCanvas(canvas);
|
|
2159
|
+
if (!contentCanvas) contentCanvas = getCanvas(canvas);
|
|
2069
2160
|
child.__render(maskCanvas, options);
|
|
2070
2161
|
}
|
|
2071
|
-
if (mask ===
|
|
2072
|
-
excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
2162
|
+
if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
|
|
2073
2163
|
continue;
|
|
2074
2164
|
}
|
|
2165
|
+
const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
|
|
2166
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
|
|
2075
2167
|
excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
|
|
2168
|
+
if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
|
|
2076
2169
|
}
|
|
2077
|
-
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
|
|
2170
|
+
maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
|
|
2078
2171
|
};
|
|
2079
|
-
|
|
2172
|
+
|
|
2173
|
+
function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
|
|
2080
2174
|
switch (maskMode) {
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
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();
|
|
2091
2188
|
}
|
|
2092
2189
|
}
|
|
2190
|
+
|
|
2093
2191
|
function getCanvas(canvas) {
|
|
2094
2192
|
return canvas.getSameCanvas(false, true);
|
|
2095
2193
|
}
|
|
2096
|
-
|
|
2194
|
+
|
|
2195
|
+
function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
|
|
2097
2196
|
const realBounds = leaf.__nowWorld;
|
|
2098
2197
|
content.resetTransform();
|
|
2099
2198
|
content.opacity = 1;
|
|
2100
2199
|
content.useMask(mask, realBounds);
|
|
2101
|
-
mask.recycle(realBounds);
|
|
2102
|
-
copyContent(leaf, canvas, content, 1);
|
|
2200
|
+
if (recycle) mask.recycle(realBounds);
|
|
2201
|
+
copyContent(leaf, canvas, content, 1, blendMode, recycle);
|
|
2103
2202
|
}
|
|
2104
|
-
|
|
2203
|
+
|
|
2204
|
+
function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
|
|
2105
2205
|
const realBounds = leaf.__nowWorld;
|
|
2106
2206
|
canvas.resetTransform();
|
|
2107
2207
|
canvas.opacity = maskOpacity;
|
|
2108
|
-
canvas.copyWorld(content, realBounds);
|
|
2109
|
-
content.recycle(realBounds);
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
const money =
|
|
2113
|
-
|
|
2114
|
-
const
|
|
2115
|
-
|
|
2116
|
-
const
|
|
2117
|
-
|
|
2118
|
-
const
|
|
2119
|
-
|
|
2120
|
-
const
|
|
2121
|
-
|
|
2122
|
-
const
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
[0x31C0, 0x31EF],
|
|
2137
|
-
[0x3200, 0x32FF],
|
|
2138
|
-
[0x3300, 0x33FF],
|
|
2139
|
-
[0xF900, 0xFAFF],
|
|
2140
|
-
[0xFE30, 0xFE4F],
|
|
2141
|
-
[0x1F200, 0x1F2FF],
|
|
2142
|
-
[0x2F800, 0x2FA1F],
|
|
2143
|
-
];
|
|
2144
|
-
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
|
+
|
|
2145
2236
|
function mapChar(str) {
|
|
2146
2237
|
const map = {};
|
|
2147
|
-
str.split(
|
|
2238
|
+
str.split("").forEach(char => map[char] = true);
|
|
2148
2239
|
return map;
|
|
2149
2240
|
}
|
|
2241
|
+
|
|
2150
2242
|
const letterMap = mapChar(letter);
|
|
2243
|
+
|
|
2151
2244
|
const beforeMap = mapChar(beforeChar);
|
|
2245
|
+
|
|
2152
2246
|
const afterMap = mapChar(afterChar);
|
|
2247
|
+
|
|
2153
2248
|
const symbolMap = mapChar(symbolChar);
|
|
2249
|
+
|
|
2154
2250
|
const breakMap = mapChar(breakChar);
|
|
2251
|
+
|
|
2155
2252
|
var CharType;
|
|
2156
|
-
|
|
2253
|
+
|
|
2254
|
+
(function(CharType) {
|
|
2157
2255
|
CharType[CharType["Letter"] = 0] = "Letter";
|
|
2158
2256
|
CharType[CharType["Single"] = 1] = "Single";
|
|
2159
2257
|
CharType[CharType["Before"] = 2] = "Before";
|
|
@@ -2161,179 +2259,175 @@ var CharType;
|
|
|
2161
2259
|
CharType[CharType["Symbol"] = 4] = "Symbol";
|
|
2162
2260
|
CharType[CharType["Break"] = 5] = "Break";
|
|
2163
2261
|
})(CharType || (CharType = {}));
|
|
2164
|
-
|
|
2262
|
+
|
|
2263
|
+
const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
|
|
2264
|
+
|
|
2165
2265
|
function getCharType(char) {
|
|
2166
2266
|
if (letterMap[char]) {
|
|
2167
2267
|
return Letter$1;
|
|
2168
|
-
}
|
|
2169
|
-
else if (breakMap[char]) {
|
|
2268
|
+
} else if (breakMap[char]) {
|
|
2170
2269
|
return Break$1;
|
|
2171
|
-
}
|
|
2172
|
-
else if (beforeMap[char]) {
|
|
2270
|
+
} else if (beforeMap[char]) {
|
|
2173
2271
|
return Before$1;
|
|
2174
|
-
}
|
|
2175
|
-
else if (afterMap[char]) {
|
|
2272
|
+
} else if (afterMap[char]) {
|
|
2176
2273
|
return After$1;
|
|
2177
|
-
}
|
|
2178
|
-
else if (symbolMap[char]) {
|
|
2274
|
+
} else if (symbolMap[char]) {
|
|
2179
2275
|
return Symbol$1;
|
|
2180
|
-
}
|
|
2181
|
-
else if (cjkReg.test(char)) {
|
|
2276
|
+
} else if (cjkReg.test(char)) {
|
|
2182
2277
|
return Single$1;
|
|
2183
|
-
}
|
|
2184
|
-
else {
|
|
2278
|
+
} else {
|
|
2185
2279
|
return Letter$1;
|
|
2186
2280
|
}
|
|
2187
2281
|
}
|
|
2188
2282
|
|
|
2189
2283
|
const TextRowHelper = {
|
|
2190
2284
|
trimRight(row) {
|
|
2191
|
-
const { words
|
|
2285
|
+
const {words: words} = row;
|
|
2192
2286
|
let trimRight = 0, len = words.length, char;
|
|
2193
2287
|
for (let i = len - 1; i > -1; i--) {
|
|
2194
2288
|
char = words[i].data[0];
|
|
2195
|
-
if (char.char ===
|
|
2289
|
+
if (char.char === " ") {
|
|
2196
2290
|
trimRight++;
|
|
2197
2291
|
row.width -= char.width;
|
|
2198
|
-
}
|
|
2199
|
-
else {
|
|
2292
|
+
} else {
|
|
2200
2293
|
break;
|
|
2201
2294
|
}
|
|
2202
2295
|
}
|
|
2203
|
-
if (trimRight)
|
|
2204
|
-
words.splice(len - trimRight, trimRight);
|
|
2296
|
+
if (trimRight) words.splice(len - trimRight, trimRight);
|
|
2205
2297
|
}
|
|
2206
2298
|
};
|
|
2207
2299
|
|
|
2208
2300
|
function getTextCase(char, textCase, firstChar) {
|
|
2209
2301
|
switch (textCase) {
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
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;
|
|
2218
2313
|
}
|
|
2219
2314
|
}
|
|
2220
2315
|
|
|
2221
|
-
const { trimRight
|
|
2222
|
-
|
|
2316
|
+
const {trimRight: trimRight} = TextRowHelper;
|
|
2317
|
+
|
|
2318
|
+
const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
|
|
2319
|
+
|
|
2223
2320
|
let word, row, wordWidth, rowWidth, realWidth;
|
|
2321
|
+
|
|
2224
2322
|
let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
|
|
2323
|
+
|
|
2225
2324
|
let textDrawData, rows = [], bounds, findMaxWidth;
|
|
2325
|
+
|
|
2226
2326
|
function createRows(drawData, content, style) {
|
|
2227
2327
|
textDrawData = drawData;
|
|
2228
2328
|
rows = drawData.rows;
|
|
2229
2329
|
bounds = drawData.bounds;
|
|
2230
2330
|
findMaxWidth = !bounds.width && !style.autoSizeAlign;
|
|
2231
|
-
const { __letterSpacing, paraIndent, textCase } = style;
|
|
2232
|
-
const { canvas
|
|
2233
|
-
const { width, height } = bounds;
|
|
2234
|
-
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";
|
|
2235
2335
|
if (charMode) {
|
|
2236
|
-
const wrap = style.textWrap !==
|
|
2237
|
-
const breakAll = style.textWrap ===
|
|
2336
|
+
const wrap = style.textWrap !== "none";
|
|
2337
|
+
const breakAll = style.textWrap === "break";
|
|
2238
2338
|
paraStart = true;
|
|
2239
2339
|
lastCharType = null;
|
|
2240
2340
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
2241
|
-
word = {
|
|
2242
|
-
|
|
2243
|
-
|
|
2341
|
+
word = {
|
|
2342
|
+
data: []
|
|
2343
|
+
}, row = {
|
|
2344
|
+
words: []
|
|
2345
|
+
};
|
|
2346
|
+
if (__letterSpacing) content = [ ...content ];
|
|
2244
2347
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
2245
2348
|
char = content[i];
|
|
2246
|
-
if (char ===
|
|
2247
|
-
if (wordWidth)
|
|
2248
|
-
addWord();
|
|
2349
|
+
if (char === "\n") {
|
|
2350
|
+
if (wordWidth) addWord();
|
|
2249
2351
|
row.paraEnd = true;
|
|
2250
2352
|
addRow();
|
|
2251
2353
|
paraStart = true;
|
|
2252
|
-
}
|
|
2253
|
-
else {
|
|
2354
|
+
} else {
|
|
2254
2355
|
charType = getCharType(char);
|
|
2255
|
-
if (charType === Letter && textCase !==
|
|
2256
|
-
char = getTextCase(char, textCase, !wordWidth);
|
|
2356
|
+
if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
|
|
2257
2357
|
charWidth = canvas.measureText(char).width;
|
|
2258
2358
|
if (__letterSpacing) {
|
|
2259
|
-
if (__letterSpacing < 0)
|
|
2260
|
-
charSize = charWidth;
|
|
2359
|
+
if (__letterSpacing < 0) charSize = charWidth;
|
|
2261
2360
|
charWidth += __letterSpacing;
|
|
2262
2361
|
}
|
|
2263
|
-
langBreak =
|
|
2264
|
-
afterBreak = (
|
|
2362
|
+
langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
|
|
2363
|
+
afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
|
|
2265
2364
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
2266
2365
|
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
2267
2366
|
if (breakAll) {
|
|
2268
|
-
if (wordWidth)
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
if (wordWidth)
|
|
2278
|
-
addWord();
|
|
2279
|
-
if (rowWidth)
|
|
2280
|
-
addRow();
|
|
2281
|
-
}
|
|
2282
|
-
else {
|
|
2283
|
-
if (rowWidth)
|
|
2284
|
-
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();
|
|
2285
2376
|
}
|
|
2286
2377
|
}
|
|
2287
2378
|
}
|
|
2288
|
-
if (char ===
|
|
2289
|
-
else {
|
|
2379
|
+
if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
|
|
2290
2380
|
if (charType === Break) {
|
|
2291
|
-
if (char ===
|
|
2292
|
-
addWord();
|
|
2381
|
+
if (char === " " && wordWidth) addWord();
|
|
2293
2382
|
addChar(char, charWidth);
|
|
2294
2383
|
addWord();
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
if (wordWidth)
|
|
2298
|
-
addWord();
|
|
2384
|
+
} else if (langBreak || afterBreak) {
|
|
2385
|
+
if (wordWidth) addWord();
|
|
2299
2386
|
addChar(char, charWidth);
|
|
2300
|
-
}
|
|
2301
|
-
else {
|
|
2387
|
+
} else {
|
|
2302
2388
|
addChar(char, charWidth);
|
|
2303
2389
|
}
|
|
2304
2390
|
}
|
|
2305
2391
|
lastCharType = charType;
|
|
2306
2392
|
}
|
|
2307
2393
|
}
|
|
2308
|
-
if (wordWidth)
|
|
2309
|
-
|
|
2310
|
-
if (rowWidth)
|
|
2311
|
-
addRow();
|
|
2394
|
+
if (wordWidth) addWord();
|
|
2395
|
+
if (rowWidth) addRow();
|
|
2312
2396
|
rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
content.split('\n').forEach(content => {
|
|
2397
|
+
} else {
|
|
2398
|
+
content.split("\n").forEach(content => {
|
|
2316
2399
|
textDrawData.paraNumber++;
|
|
2317
2400
|
rowWidth = canvas.measureText(content).width;
|
|
2318
|
-
rows.push({
|
|
2319
|
-
|
|
2320
|
-
|
|
2401
|
+
rows.push({
|
|
2402
|
+
x: paraIndent || 0,
|
|
2403
|
+
text: content,
|
|
2404
|
+
width: rowWidth,
|
|
2405
|
+
paraStart: true
|
|
2406
|
+
});
|
|
2407
|
+
if (findMaxWidth) setMaxWidth();
|
|
2321
2408
|
});
|
|
2322
2409
|
}
|
|
2323
2410
|
}
|
|
2411
|
+
|
|
2324
2412
|
function addChar(char, width) {
|
|
2325
|
-
if (charSize && !startCharSize)
|
|
2326
|
-
|
|
2327
|
-
|
|
2413
|
+
if (charSize && !startCharSize) startCharSize = charSize;
|
|
2414
|
+
word.data.push({
|
|
2415
|
+
char: char,
|
|
2416
|
+
width: width
|
|
2417
|
+
});
|
|
2328
2418
|
wordWidth += width;
|
|
2329
2419
|
}
|
|
2420
|
+
|
|
2330
2421
|
function addWord() {
|
|
2331
2422
|
rowWidth += wordWidth;
|
|
2332
2423
|
word.width = wordWidth;
|
|
2333
2424
|
row.words.push(word);
|
|
2334
|
-
word = {
|
|
2425
|
+
word = {
|
|
2426
|
+
data: []
|
|
2427
|
+
};
|
|
2335
2428
|
wordWidth = 0;
|
|
2336
2429
|
}
|
|
2430
|
+
|
|
2337
2431
|
function addRow() {
|
|
2338
2432
|
if (paraStart) {
|
|
2339
2433
|
textDrawData.paraNumber++;
|
|
@@ -2346,52 +2440,53 @@ function addRow() {
|
|
|
2346
2440
|
startCharSize = 0;
|
|
2347
2441
|
}
|
|
2348
2442
|
row.width = rowWidth;
|
|
2349
|
-
if (bounds.width)
|
|
2350
|
-
trimRight(row);
|
|
2351
|
-
else if (findMaxWidth)
|
|
2352
|
-
setMaxWidth();
|
|
2443
|
+
if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
|
|
2353
2444
|
rows.push(row);
|
|
2354
|
-
row = {
|
|
2445
|
+
row = {
|
|
2446
|
+
words: []
|
|
2447
|
+
};
|
|
2355
2448
|
rowWidth = 0;
|
|
2356
2449
|
}
|
|
2450
|
+
|
|
2357
2451
|
function setMaxWidth() {
|
|
2358
|
-
if (rowWidth > (textDrawData.maxWidth || 0))
|
|
2359
|
-
textDrawData.maxWidth = rowWidth;
|
|
2452
|
+
if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
|
|
2360
2453
|
}
|
|
2361
2454
|
|
|
2362
2455
|
const CharMode = 0;
|
|
2456
|
+
|
|
2363
2457
|
const WordMode = 1;
|
|
2458
|
+
|
|
2364
2459
|
const TextMode = 2;
|
|
2460
|
+
|
|
2365
2461
|
function layoutChar(drawData, style, width, _height) {
|
|
2366
|
-
const { rows
|
|
2367
|
-
const { textAlign, paraIndent, letterSpacing } = style;
|
|
2462
|
+
const {rows: rows} = drawData;
|
|
2463
|
+
const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
|
|
2368
2464
|
let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
|
|
2369
2465
|
rows.forEach(row => {
|
|
2370
2466
|
if (row.words) {
|
|
2371
2467
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
|
|
2372
|
-
addWordWidth =
|
|
2373
|
-
mode =
|
|
2374
|
-
if (row.isOverflow && !letterSpacing)
|
|
2375
|
-
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;
|
|
2376
2471
|
if (mode === TextMode) {
|
|
2377
2472
|
row.x += indentWidth;
|
|
2378
2473
|
toTextChar$1(row);
|
|
2379
|
-
}
|
|
2380
|
-
else {
|
|
2474
|
+
} else {
|
|
2381
2475
|
row.x += indentWidth;
|
|
2382
2476
|
charX = row.x;
|
|
2383
2477
|
row.data = [];
|
|
2384
2478
|
row.words.forEach((word, index) => {
|
|
2385
2479
|
if (mode === WordMode) {
|
|
2386
|
-
wordChar = {
|
|
2480
|
+
wordChar = {
|
|
2481
|
+
char: "",
|
|
2482
|
+
x: charX
|
|
2483
|
+
};
|
|
2387
2484
|
charX = toWordChar(word.data, charX, wordChar);
|
|
2388
|
-
if (row.isOverflow || wordChar.char !==
|
|
2389
|
-
|
|
2390
|
-
}
|
|
2391
|
-
else {
|
|
2485
|
+
if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
|
|
2486
|
+
} else {
|
|
2392
2487
|
charX = toChar(word.data, charX, row.data, row.isOverflow);
|
|
2393
2488
|
}
|
|
2394
|
-
if (addWordWidth && (!row.paraEnd || textAlign ===
|
|
2489
|
+
if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
|
|
2395
2490
|
charX += addWordWidth;
|
|
2396
2491
|
row.width += addWordWidth;
|
|
2397
2492
|
}
|
|
@@ -2401,14 +2496,16 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
2401
2496
|
}
|
|
2402
2497
|
});
|
|
2403
2498
|
}
|
|
2499
|
+
|
|
2404
2500
|
function toTextChar$1(row) {
|
|
2405
|
-
row.text =
|
|
2501
|
+
row.text = "";
|
|
2406
2502
|
row.words.forEach(word => {
|
|
2407
2503
|
word.data.forEach(char => {
|
|
2408
2504
|
row.text += char.char;
|
|
2409
2505
|
});
|
|
2410
2506
|
});
|
|
2411
2507
|
}
|
|
2508
|
+
|
|
2412
2509
|
function toWordChar(data, charX, wordChar) {
|
|
2413
2510
|
data.forEach(char => {
|
|
2414
2511
|
wordChar.char += char.char;
|
|
@@ -2416,9 +2513,10 @@ function toWordChar(data, charX, wordChar) {
|
|
|
2416
2513
|
});
|
|
2417
2514
|
return charX;
|
|
2418
2515
|
}
|
|
2516
|
+
|
|
2419
2517
|
function toChar(data, charX, rowData, isOverflow) {
|
|
2420
2518
|
data.forEach(char => {
|
|
2421
|
-
if (isOverflow || char.char !==
|
|
2519
|
+
if (isOverflow || char.char !== " ") {
|
|
2422
2520
|
char.x = charX;
|
|
2423
2521
|
rowData.push(char);
|
|
2424
2522
|
}
|
|
@@ -2428,38 +2526,39 @@ function toChar(data, charX, rowData, isOverflow) {
|
|
|
2428
2526
|
}
|
|
2429
2527
|
|
|
2430
2528
|
function layoutText(drawData, style) {
|
|
2431
|
-
const { rows, bounds } = drawData, countRows = rows.length;
|
|
2432
|
-
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
|
|
2433
|
-
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);
|
|
2434
2532
|
let starY = __baseLine;
|
|
2435
2533
|
if (__clipText && realHeight > height) {
|
|
2436
2534
|
realHeight = Math.max(height, __lineHeight);
|
|
2437
|
-
if (countRows > 1)
|
|
2438
|
-
|
|
2439
|
-
}
|
|
2440
|
-
else if (height || autoSizeAlign) {
|
|
2535
|
+
if (countRows > 1) drawData.overflow = countRows;
|
|
2536
|
+
} else if (height || autoSizeAlign) {
|
|
2441
2537
|
switch (verticalAlign) {
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2538
|
+
case "middle":
|
|
2539
|
+
y += (height - realHeight) / 2;
|
|
2540
|
+
break;
|
|
2541
|
+
|
|
2542
|
+
case "bottom":
|
|
2543
|
+
y += height - realHeight;
|
|
2446
2544
|
}
|
|
2447
2545
|
}
|
|
2448
2546
|
starY += y;
|
|
2449
|
-
let row, rowX, rowWidth, layoutWidth =
|
|
2547
|
+
let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
|
|
2450
2548
|
for (let i = 0, len = countRows; i < len; i++) {
|
|
2451
2549
|
row = rows[i];
|
|
2452
2550
|
row.x = x;
|
|
2453
|
-
if (row.width < width ||
|
|
2551
|
+
if (row.width < width || row.width > width && !__clipText) {
|
|
2454
2552
|
switch (textAlign) {
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2553
|
+
case "center":
|
|
2554
|
+
row.x += (layoutWidth - row.width) / 2;
|
|
2555
|
+
break;
|
|
2556
|
+
|
|
2557
|
+
case "right":
|
|
2558
|
+
row.x += layoutWidth - row.width;
|
|
2459
2559
|
}
|
|
2460
2560
|
}
|
|
2461
|
-
if (row.paraStart && paraSpacing && i > 0)
|
|
2462
|
-
starY += paraSpacing;
|
|
2561
|
+
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
|
|
2463
2562
|
row.y = starY;
|
|
2464
2563
|
starY += __lineHeight;
|
|
2465
2564
|
if (drawData.overflow > i && starY > realHeight) {
|
|
@@ -2473,19 +2572,15 @@ function layoutText(drawData, style) {
|
|
|
2473
2572
|
rowWidth = -row.width + style.fontSize + __letterSpacing;
|
|
2474
2573
|
rowX -= rowWidth;
|
|
2475
2574
|
rowWidth += style.fontSize;
|
|
2476
|
-
}
|
|
2477
|
-
else {
|
|
2575
|
+
} else {
|
|
2478
2576
|
rowWidth -= __letterSpacing;
|
|
2479
2577
|
}
|
|
2480
2578
|
}
|
|
2481
|
-
if (rowX < bounds.x)
|
|
2482
|
-
|
|
2483
|
-
if (rowWidth > bounds.width)
|
|
2484
|
-
bounds.width = rowWidth;
|
|
2579
|
+
if (rowX < bounds.x) bounds.x = rowX;
|
|
2580
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth;
|
|
2485
2581
|
if (__clipText && width && width < rowWidth) {
|
|
2486
2582
|
row.isOverflow = true;
|
|
2487
|
-
if (!drawData.overflow)
|
|
2488
|
-
drawData.overflow = rows.length;
|
|
2583
|
+
if (!drawData.overflow) drawData.overflow = rows.length;
|
|
2489
2584
|
}
|
|
2490
2585
|
}
|
|
2491
2586
|
bounds.y = y;
|
|
@@ -2493,20 +2588,16 @@ function layoutText(drawData, style) {
|
|
|
2493
2588
|
}
|
|
2494
2589
|
|
|
2495
2590
|
function clipText(drawData, style, x, width) {
|
|
2496
|
-
if (!width)
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
let { textOverflow } = style;
|
|
2591
|
+
if (!width) return;
|
|
2592
|
+
const {rows: rows, overflow: overflow} = drawData;
|
|
2593
|
+
let {textOverflow: textOverflow} = style;
|
|
2500
2594
|
rows.splice(overflow);
|
|
2501
|
-
if (textOverflow && textOverflow !==
|
|
2502
|
-
if (textOverflow ===
|
|
2503
|
-
textOverflow = '';
|
|
2504
|
-
else if (textOverflow === 'ellipsis')
|
|
2505
|
-
textOverflow = '...';
|
|
2595
|
+
if (textOverflow && textOverflow !== "show") {
|
|
2596
|
+
if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
|
|
2506
2597
|
let char, charRight;
|
|
2507
2598
|
const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
|
|
2508
2599
|
const right = x + width - ellipsisWidth;
|
|
2509
|
-
const list = style.textWrap ===
|
|
2600
|
+
const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
|
|
2510
2601
|
list.forEach(row => {
|
|
2511
2602
|
if (row.isOverflow && row.data) {
|
|
2512
2603
|
let end = row.data.length - 1;
|
|
@@ -2515,8 +2606,7 @@ function clipText(drawData, style, x, width) {
|
|
|
2515
2606
|
charRight = char.x + char.width;
|
|
2516
2607
|
if (i === end && charRight < right) {
|
|
2517
2608
|
break;
|
|
2518
|
-
}
|
|
2519
|
-
else if ((charRight < right && char.char !== ' ') || !i) {
|
|
2609
|
+
} else if (charRight < right && char.char !== " " || !i) {
|
|
2520
2610
|
row.data.splice(i + 1);
|
|
2521
2611
|
row.width -= char.width;
|
|
2522
2612
|
break;
|
|
@@ -2524,15 +2614,18 @@ function clipText(drawData, style, x, width) {
|
|
|
2524
2614
|
row.width -= char.width;
|
|
2525
2615
|
}
|
|
2526
2616
|
row.width += ellipsisWidth;
|
|
2527
|
-
row.data.push({
|
|
2528
|
-
|
|
2529
|
-
|
|
2617
|
+
row.data.push({
|
|
2618
|
+
char: textOverflow,
|
|
2619
|
+
x: charRight
|
|
2620
|
+
});
|
|
2621
|
+
if (row.textMode) toTextChar(row);
|
|
2530
2622
|
}
|
|
2531
2623
|
});
|
|
2532
2624
|
}
|
|
2533
2625
|
}
|
|
2626
|
+
|
|
2534
2627
|
function toTextChar(row) {
|
|
2535
|
-
row.text =
|
|
2628
|
+
row.text = "";
|
|
2536
2629
|
row.data.forEach(char => {
|
|
2537
2630
|
row.text += char.char;
|
|
2538
2631
|
});
|
|
@@ -2541,129 +2634,130 @@ function toTextChar(row) {
|
|
|
2541
2634
|
|
|
2542
2635
|
function decorationText(drawData, style) {
|
|
2543
2636
|
let type;
|
|
2544
|
-
const { fontSize, textDecoration } = style;
|
|
2637
|
+
const {fontSize: fontSize, textDecoration: textDecoration} = style;
|
|
2545
2638
|
drawData.decorationHeight = fontSize / 11;
|
|
2546
|
-
if (
|
|
2639
|
+
if (isObject(textDecoration)) {
|
|
2547
2640
|
type = textDecoration.type;
|
|
2548
|
-
if (textDecoration.color)
|
|
2549
|
-
|
|
2550
|
-
}
|
|
2551
|
-
else
|
|
2552
|
-
type = textDecoration;
|
|
2641
|
+
if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
|
|
2642
|
+
} else type = textDecoration;
|
|
2553
2643
|
switch (type) {
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
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 ];
|
|
2562
2654
|
}
|
|
2563
2655
|
}
|
|
2564
2656
|
|
|
2565
|
-
const { top, right, bottom, left } = Direction4;
|
|
2657
|
+
const {top: top, right: right, bottom: bottom, left: left} = Direction4;
|
|
2658
|
+
|
|
2566
2659
|
function getDrawData(content, style) {
|
|
2567
|
-
if (
|
|
2568
|
-
content = String(content);
|
|
2660
|
+
if (!isString(content)) content = String(content);
|
|
2569
2661
|
let x = 0, y = 0;
|
|
2570
|
-
let width = style.__getInput(
|
|
2571
|
-
let height = style.__getInput(
|
|
2572
|
-
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;
|
|
2573
2665
|
if (padding) {
|
|
2574
|
-
if (width)
|
|
2575
|
-
|
|
2576
|
-
else if (!style.autoSizeAlign)
|
|
2577
|
-
x = padding[left];
|
|
2578
|
-
if (height)
|
|
2579
|
-
y = padding[top], height -= (padding[top] + padding[bottom]);
|
|
2580
|
-
else if (!style.autoSizeAlign)
|
|
2581
|
-
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];
|
|
2582
2668
|
}
|
|
2583
2669
|
const drawData = {
|
|
2584
|
-
bounds: {
|
|
2670
|
+
bounds: {
|
|
2671
|
+
x: x,
|
|
2672
|
+
y: y,
|
|
2673
|
+
width: width,
|
|
2674
|
+
height: height
|
|
2675
|
+
},
|
|
2585
2676
|
rows: [],
|
|
2586
2677
|
paraNumber: 0,
|
|
2587
2678
|
font: Platform.canvas.font = __font
|
|
2588
2679
|
};
|
|
2589
2680
|
createRows(drawData, content, style);
|
|
2590
|
-
if (padding)
|
|
2591
|
-
padAutoText(padding, drawData, style, width, height);
|
|
2681
|
+
if (padding) padAutoText(padding, drawData, style, width, height);
|
|
2592
2682
|
layoutText(drawData, style);
|
|
2593
2683
|
layoutChar(drawData, style, width);
|
|
2594
|
-
if (drawData.overflow)
|
|
2595
|
-
|
|
2596
|
-
if (textDecoration !== 'none')
|
|
2597
|
-
decorationText(drawData, style);
|
|
2684
|
+
if (drawData.overflow) clipText(drawData, style, x, width);
|
|
2685
|
+
if (textDecoration !== "none") decorationText(drawData, style);
|
|
2598
2686
|
return drawData;
|
|
2599
2687
|
}
|
|
2688
|
+
|
|
2600
2689
|
function padAutoText(padding, drawData, style, width, height) {
|
|
2601
2690
|
if (!width && style.autoSizeAlign) {
|
|
2602
2691
|
switch (style.textAlign) {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2692
|
+
case "left":
|
|
2693
|
+
offsetText(drawData, "x", padding[left]);
|
|
2694
|
+
break;
|
|
2695
|
+
|
|
2696
|
+
case "right":
|
|
2697
|
+
offsetText(drawData, "x", -padding[right]);
|
|
2607
2698
|
}
|
|
2608
2699
|
}
|
|
2609
2700
|
if (!height && style.autoSizeAlign) {
|
|
2610
2701
|
switch (style.verticalAlign) {
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2702
|
+
case "top":
|
|
2703
|
+
offsetText(drawData, "y", padding[top]);
|
|
2704
|
+
break;
|
|
2705
|
+
|
|
2706
|
+
case "bottom":
|
|
2707
|
+
offsetText(drawData, "y", -padding[bottom]);
|
|
2615
2708
|
}
|
|
2616
2709
|
}
|
|
2617
2710
|
}
|
|
2711
|
+
|
|
2618
2712
|
function offsetText(drawData, attrName, value) {
|
|
2619
|
-
const { bounds, rows } = drawData;
|
|
2713
|
+
const {bounds: bounds, rows: rows} = drawData;
|
|
2620
2714
|
bounds[attrName] += value;
|
|
2621
|
-
for (let i = 0; i < rows.length; i++)
|
|
2622
|
-
rows[i][attrName] += value;
|
|
2715
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
|
|
2623
2716
|
}
|
|
2624
2717
|
|
|
2625
2718
|
const TextConvertModule = {
|
|
2626
|
-
getDrawData
|
|
2719
|
+
getDrawData: getDrawData
|
|
2627
2720
|
};
|
|
2628
2721
|
|
|
2629
2722
|
function string(color, opacity) {
|
|
2630
|
-
const doOpacity =
|
|
2631
|
-
if (
|
|
2632
|
-
if (doOpacity && ColorConvert.object)
|
|
2633
|
-
color = ColorConvert.object(color);
|
|
2634
|
-
else
|
|
2635
|
-
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;
|
|
2636
2726
|
}
|
|
2637
|
-
let a = color.a
|
|
2638
|
-
if (doOpacity)
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
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 + ")";
|
|
2642
2731
|
}
|
|
2643
2732
|
|
|
2644
2733
|
const ColorConvertModule = {
|
|
2645
|
-
string
|
|
2734
|
+
string: string
|
|
2646
2735
|
};
|
|
2647
2736
|
|
|
2648
2737
|
Object.assign(TextConvert, TextConvertModule);
|
|
2738
|
+
|
|
2649
2739
|
Object.assign(ColorConvert, ColorConvertModule);
|
|
2740
|
+
|
|
2650
2741
|
Object.assign(Paint, PaintModule);
|
|
2742
|
+
|
|
2651
2743
|
Object.assign(PaintImage, PaintImageModule);
|
|
2744
|
+
|
|
2652
2745
|
Object.assign(PaintGradient, PaintGradientModule);
|
|
2746
|
+
|
|
2653
2747
|
Object.assign(Effect, EffectModule);
|
|
2654
2748
|
|
|
2655
2749
|
Object.assign(Creator, {
|
|
2656
2750
|
interaction: (target, canvas, selector, options) => new Interaction(target, canvas, selector, options),
|
|
2657
2751
|
hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
2658
|
-
hitCanvasManager: () => new HitCanvasManager
|
|
2752
|
+
hitCanvasManager: () => new HitCanvasManager
|
|
2659
2753
|
});
|
|
2660
|
-
|
|
2754
|
+
|
|
2755
|
+
Leafer.prototype.receiveEvent = function(event) {
|
|
2661
2756
|
this.interaction && this.interaction.receive(event);
|
|
2662
2757
|
};
|
|
2758
|
+
|
|
2663
2759
|
try {
|
|
2664
|
-
if (wx)
|
|
2665
|
-
|
|
2666
|
-
}
|
|
2667
|
-
catch (_a) { }
|
|
2760
|
+
if (wx) useCanvas("miniapp", wx);
|
|
2761
|
+
} catch (_a) {}
|
|
2668
2762
|
|
|
2669
2763
|
export { Interaction, Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };
|