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