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