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