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