@idraw/renderer 0.4.0-beta.4 → 0.4.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/esm/calculator.d.ts +44 -0
- package/dist/esm/calculator.js +180 -0
- package/dist/esm/draw/box.d.ts +17 -3
- package/dist/esm/draw/box.js +104 -51
- package/dist/esm/draw/circle.js +55 -31
- package/dist/esm/draw/elements.js +5 -2
- package/dist/esm/draw/global.d.ts +2 -0
- package/dist/esm/draw/global.js +9 -0
- package/dist/esm/draw/group.js +22 -10
- package/dist/esm/draw/html.js +7 -7
- package/dist/esm/draw/image.js +52 -11
- package/dist/esm/draw/index.d.ts +3 -0
- package/dist/esm/draw/index.js +3 -0
- package/dist/esm/draw/layout.d.ts +2 -0
- package/dist/esm/draw/layout.js +44 -0
- package/dist/esm/draw/path.js +50 -8
- package/dist/esm/draw/rect.js +4 -3
- package/dist/esm/draw/svg.js +7 -7
- package/dist/esm/draw/text.js +34 -84
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +48 -7
- package/dist/esm/loader.d.ts +2 -0
- package/dist/esm/loader.js +50 -26
- package/dist/esm/view-visible/index.d.ts +22 -0
- package/dist/esm/view-visible/index.js +63 -0
- package/dist/esm/virtual-flat/index.d.ts +7 -0
- package/dist/esm/virtual-flat/index.js +45 -0
- package/dist/esm/virtual-flat/text.d.ts +2 -0
- package/dist/esm/virtual-flat/text.js +151 -0
- package/dist/index.global.js +1535 -339
- package/dist/index.global.min.js +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
var iDrawRenderer = function(exports) {
|
|
2
|
-
"use strict";var
|
|
3
|
-
|
|
4
|
-
throw TypeError("Cannot " + msg);
|
|
5
|
-
};
|
|
6
|
-
var __privateGet = (obj, member, getter) => {
|
|
7
|
-
__accessCheck(obj, member, "read from private field");
|
|
8
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
9
|
-
};
|
|
10
|
-
var __privateAdd = (obj, member, value) => {
|
|
11
|
-
if (member.has(obj))
|
|
12
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
13
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
14
|
-
};
|
|
15
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
16
|
-
__accessCheck(obj, member, "write to private field");
|
|
17
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
18
|
-
return value;
|
|
19
|
-
};
|
|
20
|
-
var __privateMethod = (obj, member, method) => {
|
|
21
|
-
__accessCheck(obj, member, "access private method");
|
|
22
|
-
return method;
|
|
2
|
+
"use strict";var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
23
4
|
};
|
|
5
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
6
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
7
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
8
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
9
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
24
10
|
|
|
25
|
-
var _loadFuncMap, _currentLoadItemMap, _storageLoadItemMap,
|
|
11
|
+
var _loadFuncMap, _currentLoadItemMap, _storageLoadItemMap, _hasDestroyed, _Loader_instances, registerLoadFunc_fn, getLoadElementSource_fn, createLoadItem_fn, emitLoad_fn, emitError_fn, loadResource_fn, isExistingErrorStorage_fn, _opts, _store, _opts2, _loader, _calculator, _hasDestroyed2, _Renderer_instances, init_fn;
|
|
26
12
|
function isColorStr(color2) {
|
|
27
|
-
return typeof color2 === "string" && (
|
|
13
|
+
return typeof color2 === "string" && (/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color2) || /^[a-z]{1,}$/i.test(color2));
|
|
28
14
|
}
|
|
29
15
|
function mergeHexColorAlpha(hex, alpha) {
|
|
30
16
|
if (alpha === 1) {
|
|
31
17
|
return hex;
|
|
32
18
|
}
|
|
33
19
|
let hexAlpha = 1;
|
|
34
|
-
const regHex1 =
|
|
35
|
-
const regHex2 =
|
|
20
|
+
const regHex1 = /^#[0-9a-f]{6,6}$/i;
|
|
21
|
+
const regHex2 = /^#[0-9a-f]{8,8}$/i;
|
|
36
22
|
let result = hex;
|
|
37
23
|
if (regHex1.test(hex)) {
|
|
38
|
-
hexAlpha = parseInt(hex.substring(5, 7).replace(
|
|
24
|
+
hexAlpha = parseInt(hex.substring(5, 7).replace(/^#/, "0x"));
|
|
39
25
|
} else if (regHex2.test(hex)) {
|
|
40
|
-
hexAlpha = parseInt(hex.substring(7, 9).replace(
|
|
26
|
+
hexAlpha = parseInt(hex.substring(7, 9).replace(/^#/, "0x"));
|
|
41
27
|
result = hex.substring(0, 7);
|
|
42
28
|
}
|
|
43
29
|
hexAlpha = hexAlpha * alpha;
|
|
@@ -47,36 +33,90 @@ var __privateMethod = (obj, member, method) => {
|
|
|
47
33
|
}
|
|
48
34
|
return result;
|
|
49
35
|
}
|
|
36
|
+
function generate32Base36Hash(str) {
|
|
37
|
+
const hash256 = generate256BitHash(str);
|
|
38
|
+
return bigIntToBase36(hash256).padStart(32, "0").slice(0, 32);
|
|
39
|
+
}
|
|
40
|
+
function generate256BitHash(str) {
|
|
41
|
+
let h1 = 0xcbf29ce484222325n, h2 = 0x84222325cbf29ce4n;
|
|
42
|
+
let h3 = 0x1b3n * h1, h4 = 0x1000000n * h2;
|
|
43
|
+
const prime = 0x100000001b3n;
|
|
44
|
+
const chunkSize = 4096;
|
|
45
|
+
for (let i = 0; i < str.length; i += chunkSize) {
|
|
46
|
+
const chunk = str.slice(i, i + chunkSize);
|
|
47
|
+
for (let j = 0; j < chunk.length; j++) {
|
|
48
|
+
const code = BigInt(chunk.charCodeAt(j) + i + j);
|
|
49
|
+
h1 = (h1 ^ code) * prime;
|
|
50
|
+
h2 = (h2 ^ h1) * prime ^ h3;
|
|
51
|
+
h3 = (h3 ^ h2) * prime + h4;
|
|
52
|
+
h4 = (h4 ^ h3) * prime | 0x1234567890abcdefn;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return h1 << 192n | h2 << 128n | h3 << 64n | h4;
|
|
56
|
+
}
|
|
57
|
+
function bigIntToBase36(num) {
|
|
58
|
+
const chars = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
59
|
+
if (num === 0n)
|
|
60
|
+
return "0";
|
|
61
|
+
let result = "";
|
|
62
|
+
while (num > 0n) {
|
|
63
|
+
const rem = num % 36n;
|
|
64
|
+
result = chars[Number(rem)] + result;
|
|
65
|
+
num = num / 36n;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
50
69
|
function createUUID() {
|
|
51
70
|
function _createStr() {
|
|
52
71
|
return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
53
72
|
}
|
|
54
73
|
return `${_createStr()}${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}-${_createStr()}${_createStr()}${_createStr()}`;
|
|
55
74
|
}
|
|
56
|
-
function limitHexStr(str) {
|
|
57
|
-
let count = 0;
|
|
58
|
-
for (let i = 0; i < str.length; i++) {
|
|
59
|
-
count += str.charCodeAt(i) * str.charCodeAt(i) * i * i;
|
|
60
|
-
}
|
|
61
|
-
return count.toString(16).substring(0, 4);
|
|
62
|
-
}
|
|
63
75
|
function createAssetId(assetStr) {
|
|
64
|
-
|
|
65
|
-
const mid = Math.floor(len / 2);
|
|
66
|
-
const start4 = assetStr.substring(0, 4).padEnd(4, "0");
|
|
67
|
-
const end4 = assetStr.substring(0, 4).padEnd(4, "0");
|
|
68
|
-
const str1 = limitHexStr(len.toString(16).padEnd(4, start4));
|
|
69
|
-
const str2 = limitHexStr(assetStr.substring(mid - 4, mid).padEnd(4, start4)).padEnd(4, "f");
|
|
70
|
-
const str3 = limitHexStr(assetStr.substring(mid - 8, mid - 4).padEnd(4, start4)).padEnd(4, "f");
|
|
71
|
-
const str4 = limitHexStr(assetStr.substring(mid - 12, mid - 8).padEnd(4, start4)).padEnd(4, "f");
|
|
72
|
-
const str5 = limitHexStr(assetStr.substring(mid - 16, mid - 12).padEnd(4, end4)).padEnd(4, "f");
|
|
73
|
-
const str6 = limitHexStr(assetStr.substring(mid, mid + 4).padEnd(4, end4)).padEnd(4, "f");
|
|
74
|
-
const str7 = limitHexStr(assetStr.substring(mid + 4, mid + 8).padEnd(4, end4)).padEnd(4, "f");
|
|
75
|
-
const str8 = limitHexStr(end4.padEnd(4, start4).padEnd(4, end4));
|
|
76
|
-
return `@assets/${str1}${str2}-${str3}-${str4}-${str5}-${str6}${str7}${str8}`;
|
|
76
|
+
return `@assets/${generate32Base36Hash(assetStr)}`;
|
|
77
77
|
}
|
|
78
78
|
function isAssetId(id) {
|
|
79
|
-
return /^@assets\/[0-9a-z
|
|
79
|
+
return /^@assets\/[0-9a-z-]{0,}$/.test(`${id}`);
|
|
80
|
+
}
|
|
81
|
+
(function(s, e) {
|
|
82
|
+
var t = {};
|
|
83
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
84
|
+
t[p] = s[p];
|
|
85
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
86
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
87
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
88
|
+
t[p[i]] = s[p[i]];
|
|
89
|
+
}
|
|
90
|
+
return t;
|
|
91
|
+
});
|
|
92
|
+
function deepClone(target) {
|
|
93
|
+
function _clone(t) {
|
|
94
|
+
const type = is$1(t);
|
|
95
|
+
if (["Null", "Number", "String", "Boolean", "Undefined"].indexOf(type) >= 0) {
|
|
96
|
+
return t;
|
|
97
|
+
} else if (type === "Array") {
|
|
98
|
+
const arr = [];
|
|
99
|
+
t.forEach((item) => {
|
|
100
|
+
arr.push(_clone(item));
|
|
101
|
+
});
|
|
102
|
+
return arr;
|
|
103
|
+
} else if (type === "Object") {
|
|
104
|
+
const obj = {};
|
|
105
|
+
const keys = Object.keys(t);
|
|
106
|
+
keys.forEach((key) => {
|
|
107
|
+
obj[key] = _clone(t[key]);
|
|
108
|
+
});
|
|
109
|
+
const symbolKeys = Object.getOwnPropertySymbols(t);
|
|
110
|
+
symbolKeys.forEach((key) => {
|
|
111
|
+
obj[key] = _clone(t[key]);
|
|
112
|
+
});
|
|
113
|
+
return obj;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return _clone(target);
|
|
117
|
+
}
|
|
118
|
+
function is$1(target) {
|
|
119
|
+
return Object.prototype.toString.call(target).replace(/[\]|\[]{1,1}/gi, "").split(" ")[1];
|
|
80
120
|
}
|
|
81
121
|
function parsePrototype(data) {
|
|
82
122
|
const typeStr = Object.prototype.toString.call(data) || "";
|
|
@@ -100,6 +140,9 @@ var __privateMethod = (obj, member, method) => {
|
|
|
100
140
|
asyncFunction(data) {
|
|
101
141
|
return parsePrototype(data) === "AsyncFunction";
|
|
102
142
|
},
|
|
143
|
+
boolean(data) {
|
|
144
|
+
return parsePrototype(data) === "Boolean";
|
|
145
|
+
},
|
|
103
146
|
string(data) {
|
|
104
147
|
return parsePrototype(data) === "String";
|
|
105
148
|
},
|
|
@@ -218,6 +261,9 @@ var __privateMethod = (obj, member, method) => {
|
|
|
218
261
|
return image;
|
|
219
262
|
});
|
|
220
263
|
}
|
|
264
|
+
function positiveNum(value) {
|
|
265
|
+
return typeof value === "number" && value >= 0;
|
|
266
|
+
}
|
|
221
267
|
function number(value) {
|
|
222
268
|
return typeof value === "number" && (value > 0 || value <= 0);
|
|
223
269
|
}
|
|
@@ -228,19 +274,19 @@ var __privateMethod = (obj, member, method) => {
|
|
|
228
274
|
return number(value);
|
|
229
275
|
}
|
|
230
276
|
function w(value) {
|
|
231
|
-
return
|
|
277
|
+
return positiveNum(value);
|
|
232
278
|
}
|
|
233
279
|
function h(value) {
|
|
234
|
-
return
|
|
280
|
+
return positiveNum(value);
|
|
235
281
|
}
|
|
236
282
|
function angle(value) {
|
|
237
283
|
return typeof value === "number" && value >= -360 && value <= 360;
|
|
238
284
|
}
|
|
239
285
|
function borderWidth(value) {
|
|
240
|
-
return
|
|
286
|
+
return positiveNum(value) || Array.isArray(value) && positiveNum(value[0]) && positiveNum(value[1]) && positiveNum(value[2]) && positiveNum(value[3]);
|
|
241
287
|
}
|
|
242
288
|
function borderRadius(value) {
|
|
243
|
-
return
|
|
289
|
+
return positiveNum(value) || Array.isArray(value) && positiveNum(value[0]) && positiveNum(value[1]) && positiveNum(value[2]) && positiveNum(value[3]);
|
|
244
290
|
}
|
|
245
291
|
function color(value) {
|
|
246
292
|
return isColorStr(value);
|
|
@@ -294,6 +340,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
294
340
|
return /^(-?\d+(?:\.\d+)?)$/.test(`${value}`);
|
|
295
341
|
}
|
|
296
342
|
const is = {
|
|
343
|
+
positiveNum,
|
|
297
344
|
x,
|
|
298
345
|
y,
|
|
299
346
|
w,
|
|
@@ -318,37 +365,45 @@ var __privateMethod = (obj, member, method) => {
|
|
|
318
365
|
strokeWidth
|
|
319
366
|
};
|
|
320
367
|
(function(receiver, state, value, kind, f) {
|
|
321
|
-
if (kind === "m")
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
throw new TypeError("Private accessor was defined without a setter");
|
|
325
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
326
|
-
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
368
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
369
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
370
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
327
371
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
328
372
|
});
|
|
329
373
|
(function(receiver, state, kind, f) {
|
|
330
|
-
if (kind === "a" && !f)
|
|
331
|
-
|
|
332
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
333
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
374
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
375
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
334
376
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
335
377
|
});
|
|
378
|
+
var __classPrivateFieldSet$1 = function(receiver, state, value, kind, f) {
|
|
379
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
380
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
381
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
382
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
383
|
+
};
|
|
384
|
+
var __classPrivateFieldGet$1 = function(receiver, state, kind, f) {
|
|
385
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
386
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
387
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
388
|
+
};
|
|
389
|
+
var _EventEmitter_listeners;
|
|
336
390
|
class EventEmitter {
|
|
337
391
|
constructor() {
|
|
338
|
-
this
|
|
392
|
+
_EventEmitter_listeners.set(this, void 0);
|
|
393
|
+
__classPrivateFieldSet$1(this, _EventEmitter_listeners, /* @__PURE__ */ new Map(), "f");
|
|
339
394
|
}
|
|
340
395
|
on(eventKey, callback) {
|
|
341
|
-
if (this.
|
|
342
|
-
const callbacks = this.
|
|
396
|
+
if (__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").has(eventKey)) {
|
|
397
|
+
const callbacks = __classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").get(eventKey) || [];
|
|
343
398
|
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
344
|
-
this.
|
|
399
|
+
__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").set(eventKey, callbacks);
|
|
345
400
|
} else {
|
|
346
|
-
this.
|
|
401
|
+
__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").set(eventKey, [callback]);
|
|
347
402
|
}
|
|
348
403
|
}
|
|
349
404
|
off(eventKey, callback) {
|
|
350
|
-
if (this.
|
|
351
|
-
const callbacks = this.
|
|
405
|
+
if (__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").has(eventKey)) {
|
|
406
|
+
const callbacks = __classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").get(eventKey);
|
|
352
407
|
if (Array.isArray(callbacks)) {
|
|
353
408
|
for (let i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
354
409
|
if (callbacks[i] === callback) {
|
|
@@ -357,11 +412,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
357
412
|
}
|
|
358
413
|
}
|
|
359
414
|
}
|
|
360
|
-
this.
|
|
415
|
+
__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").set(eventKey, callbacks || []);
|
|
361
416
|
}
|
|
362
417
|
}
|
|
363
418
|
trigger(eventKey, e) {
|
|
364
|
-
const callbacks = this.
|
|
419
|
+
const callbacks = __classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").get(eventKey);
|
|
365
420
|
if (Array.isArray(callbacks)) {
|
|
366
421
|
callbacks.forEach((cb) => {
|
|
367
422
|
cb(e);
|
|
@@ -372,15 +427,83 @@ var __privateMethod = (obj, member, method) => {
|
|
|
372
427
|
}
|
|
373
428
|
}
|
|
374
429
|
has(name) {
|
|
375
|
-
if (this.
|
|
376
|
-
const list = this.
|
|
430
|
+
if (__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").has(name)) {
|
|
431
|
+
const list = __classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").get(name);
|
|
377
432
|
if (Array.isArray(list) && list.length > 0) {
|
|
378
433
|
return true;
|
|
379
434
|
}
|
|
380
435
|
}
|
|
381
436
|
return false;
|
|
382
437
|
}
|
|
438
|
+
destroy() {
|
|
439
|
+
this.clear();
|
|
440
|
+
}
|
|
441
|
+
clear() {
|
|
442
|
+
__classPrivateFieldGet$1(this, _EventEmitter_listeners, "f").clear();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
_EventEmitter_listeners = /* @__PURE__ */ new WeakMap();
|
|
446
|
+
function calcDistance(start, end) {
|
|
447
|
+
const distance = (start.x - end.x) * (start.x - end.x) + (start.y - end.y) * (start.y - end.y);
|
|
448
|
+
return distance === 0 ? distance : Math.sqrt(distance);
|
|
383
449
|
}
|
|
450
|
+
function getCenterFromTwoPoints(p1, p2) {
|
|
451
|
+
return {
|
|
452
|
+
x: p1.x + (p2.x - p1.x) / 2,
|
|
453
|
+
y: p1.y + (p2.y - p1.y) / 2
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
457
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
458
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
459
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
460
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
461
|
+
};
|
|
462
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
463
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
464
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
465
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
466
|
+
};
|
|
467
|
+
var _Store_instances, _Store_temp, _Store_backUpDefaultStorage, _Store_static, _Store_createTempStorage;
|
|
468
|
+
class Store {
|
|
469
|
+
constructor(opts) {
|
|
470
|
+
_Store_instances.add(this);
|
|
471
|
+
_Store_temp.set(this, void 0);
|
|
472
|
+
_Store_backUpDefaultStorage.set(this, void 0);
|
|
473
|
+
_Store_static.set(this, void 0);
|
|
474
|
+
__classPrivateFieldSet(this, _Store_backUpDefaultStorage, deepClone(opts.defaultStorage), "f");
|
|
475
|
+
__classPrivateFieldSet(this, _Store_temp, __classPrivateFieldGet(this, _Store_instances, "m", _Store_createTempStorage).call(this), "f");
|
|
476
|
+
__classPrivateFieldSet(this, _Store_static, opts.defaultStatic || {}, "f");
|
|
477
|
+
}
|
|
478
|
+
set(name, value) {
|
|
479
|
+
__classPrivateFieldGet(this, _Store_temp, "f")[name] = value;
|
|
480
|
+
}
|
|
481
|
+
get(name) {
|
|
482
|
+
return __classPrivateFieldGet(this, _Store_temp, "f")[name];
|
|
483
|
+
}
|
|
484
|
+
setStatic(name, value) {
|
|
485
|
+
__classPrivateFieldGet(this, _Store_static, "f")[name] = value;
|
|
486
|
+
}
|
|
487
|
+
getStatic(name) {
|
|
488
|
+
return __classPrivateFieldGet(this, _Store_static, "f")[name];
|
|
489
|
+
}
|
|
490
|
+
getSnapshot(opts) {
|
|
491
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.deepClone) === true) {
|
|
492
|
+
return deepClone(__classPrivateFieldGet(this, _Store_temp, "f"));
|
|
493
|
+
}
|
|
494
|
+
return Object.assign({}, __classPrivateFieldGet(this, _Store_temp, "f"));
|
|
495
|
+
}
|
|
496
|
+
clear() {
|
|
497
|
+
__classPrivateFieldSet(this, _Store_temp, __classPrivateFieldGet(this, _Store_instances, "m", _Store_createTempStorage).call(this), "f");
|
|
498
|
+
}
|
|
499
|
+
destroy() {
|
|
500
|
+
__classPrivateFieldSet(this, _Store_temp, null, "f");
|
|
501
|
+
__classPrivateFieldSet(this, _Store_static, null, "f");
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
_Store_temp = /* @__PURE__ */ new WeakMap(), _Store_backUpDefaultStorage = /* @__PURE__ */ new WeakMap(), _Store_static = /* @__PURE__ */ new WeakMap(), _Store_instances = /* @__PURE__ */ new WeakSet(), _Store_createTempStorage = function _Store_createTempStorage2() {
|
|
505
|
+
return deepClone(__classPrivateFieldGet(this, _Store_backUpDefaultStorage, "f"));
|
|
506
|
+
};
|
|
384
507
|
function parseAngleToRadian(angle2) {
|
|
385
508
|
return angle2 / 180 * Math.PI;
|
|
386
509
|
}
|
|
@@ -411,6 +534,404 @@ var __privateMethod = (obj, member, method) => {
|
|
|
411
534
|
};
|
|
412
535
|
return p;
|
|
413
536
|
}
|
|
537
|
+
function calcElementCenterFromVertexes(ves) {
|
|
538
|
+
const startX = Math.min(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
|
|
539
|
+
const startY = Math.min(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
|
|
540
|
+
const endX = Math.max(ves[0].x, ves[1].x, ves[2].x, ves[3].x);
|
|
541
|
+
const endY = Math.max(ves[0].y, ves[1].y, ves[2].y, ves[3].y);
|
|
542
|
+
const elemSize = {
|
|
543
|
+
x: startX,
|
|
544
|
+
y: startY,
|
|
545
|
+
w: endX - startX,
|
|
546
|
+
h: endY - startY
|
|
547
|
+
};
|
|
548
|
+
return calcElementCenter(elemSize);
|
|
549
|
+
}
|
|
550
|
+
function calcLineRadian(center, p) {
|
|
551
|
+
const x2 = p.x - center.x;
|
|
552
|
+
const y2 = p.y - center.y;
|
|
553
|
+
if (x2 === 0) {
|
|
554
|
+
if (y2 < 0) {
|
|
555
|
+
return 0;
|
|
556
|
+
} else if (y2 > 0) {
|
|
557
|
+
return Math.PI;
|
|
558
|
+
}
|
|
559
|
+
} else if (y2 === 0) {
|
|
560
|
+
if (x2 < 0) {
|
|
561
|
+
return Math.PI * 3 / 2;
|
|
562
|
+
} else if (x2 > 0) {
|
|
563
|
+
return Math.PI / 2;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (x2 > 0 && y2 < 0) {
|
|
567
|
+
return Math.atan(Math.abs(x2) / Math.abs(y2));
|
|
568
|
+
} else if (x2 > 0 && y2 > 0) {
|
|
569
|
+
return Math.PI - Math.atan(Math.abs(x2) / Math.abs(y2));
|
|
570
|
+
} else if (x2 < 0 && y2 > 0) {
|
|
571
|
+
return Math.PI + Math.atan(Math.abs(x2) / Math.abs(y2));
|
|
572
|
+
} else if (x2 < 0 && y2 < 0) {
|
|
573
|
+
return 2 * Math.PI - Math.atan(Math.abs(x2) / Math.abs(y2));
|
|
574
|
+
}
|
|
575
|
+
return 0;
|
|
576
|
+
}
|
|
577
|
+
function rotatePoint(center, start, radian) {
|
|
578
|
+
const startRadian = calcLineRadian(center, start);
|
|
579
|
+
const rotateRadian = radian;
|
|
580
|
+
let endRadian = startRadian + rotateRadian;
|
|
581
|
+
if (endRadian > Math.PI * 2) {
|
|
582
|
+
endRadian = endRadian - Math.PI * 2;
|
|
583
|
+
} else if (endRadian < 0 - Math.PI * 2) {
|
|
584
|
+
endRadian = endRadian + Math.PI * 2;
|
|
585
|
+
}
|
|
586
|
+
if (endRadian < 0) {
|
|
587
|
+
endRadian = endRadian + Math.PI * 2;
|
|
588
|
+
}
|
|
589
|
+
const length = calcDistance(center, start);
|
|
590
|
+
let x2 = 0;
|
|
591
|
+
let y2 = 0;
|
|
592
|
+
if (endRadian === 0) {
|
|
593
|
+
x2 = 0;
|
|
594
|
+
y2 = 0 - length;
|
|
595
|
+
} else if (endRadian > 0 && endRadian < Math.PI / 2) {
|
|
596
|
+
x2 = Math.sin(endRadian) * length;
|
|
597
|
+
y2 = 0 - Math.cos(endRadian) * length;
|
|
598
|
+
} else if (endRadian === Math.PI / 2) {
|
|
599
|
+
x2 = length;
|
|
600
|
+
y2 = 0;
|
|
601
|
+
} else if (endRadian > Math.PI / 2 && endRadian < Math.PI) {
|
|
602
|
+
x2 = Math.sin(Math.PI - endRadian) * length;
|
|
603
|
+
y2 = Math.cos(Math.PI - endRadian) * length;
|
|
604
|
+
} else if (endRadian === Math.PI) {
|
|
605
|
+
x2 = 0;
|
|
606
|
+
y2 = length;
|
|
607
|
+
} else if (endRadian > Math.PI && endRadian < 3 / 2 * Math.PI) {
|
|
608
|
+
x2 = 0 - Math.sin(endRadian - Math.PI) * length;
|
|
609
|
+
y2 = Math.cos(endRadian - Math.PI) * length;
|
|
610
|
+
} else if (endRadian === 3 / 2 * Math.PI) {
|
|
611
|
+
x2 = 0 - length;
|
|
612
|
+
y2 = 0;
|
|
613
|
+
} else if (endRadian > 3 / 2 * Math.PI && endRadian < 2 * Math.PI) {
|
|
614
|
+
x2 = 0 - Math.sin(2 * Math.PI - endRadian) * length;
|
|
615
|
+
y2 = 0 - Math.cos(2 * Math.PI - endRadian) * length;
|
|
616
|
+
} else if (endRadian === 2 * Math.PI) {
|
|
617
|
+
x2 = 0;
|
|
618
|
+
y2 = 0 - length;
|
|
619
|
+
}
|
|
620
|
+
x2 += center.x;
|
|
621
|
+
y2 += center.y;
|
|
622
|
+
return { x: x2, y: y2 };
|
|
623
|
+
}
|
|
624
|
+
function getElementRotateVertexes(elemSize, center, angle2) {
|
|
625
|
+
const { x: x2, y: y2, w: w2, h: h2 } = elemSize;
|
|
626
|
+
let p1 = { x: x2, y: y2 };
|
|
627
|
+
let p2 = { x: x2 + w2, y: y2 };
|
|
628
|
+
let p3 = { x: x2 + w2, y: y2 + h2 };
|
|
629
|
+
let p4 = { x: x2, y: y2 + h2 };
|
|
630
|
+
if (angle2 && (angle2 > 0 || angle2 < 0)) {
|
|
631
|
+
const radian = parseAngleToRadian(limitAngle(angle2));
|
|
632
|
+
p1 = rotatePoint(center, p1, radian);
|
|
633
|
+
p2 = rotatePoint(center, p2, radian);
|
|
634
|
+
p3 = rotatePoint(center, p3, radian);
|
|
635
|
+
p4 = rotatePoint(center, p4, radian);
|
|
636
|
+
}
|
|
637
|
+
return [p1, p2, p3, p4];
|
|
638
|
+
}
|
|
639
|
+
function rotateElementVertexes(elemSize) {
|
|
640
|
+
const { angle: angle2 = 0 } = elemSize;
|
|
641
|
+
const center = calcElementCenter(elemSize);
|
|
642
|
+
return getElementRotateVertexes(elemSize, center, angle2);
|
|
643
|
+
}
|
|
644
|
+
function rotateVertexes(center, ves, radian) {
|
|
645
|
+
return [
|
|
646
|
+
rotatePoint(center, { x: ves[0].x, y: ves[0].y }, radian),
|
|
647
|
+
rotatePoint(center, { x: ves[1].x, y: ves[1].y }, radian),
|
|
648
|
+
rotatePoint(center, { x: ves[2].x, y: ves[2].y }, radian),
|
|
649
|
+
rotatePoint(center, { x: ves[3].x, y: ves[3].y }, radian)
|
|
650
|
+
];
|
|
651
|
+
}
|
|
652
|
+
function limitAngle(angle2) {
|
|
653
|
+
if (!(angle2 > 0 || angle2 < 0) || angle2 === 0 || angle2 === 360) {
|
|
654
|
+
return 0;
|
|
655
|
+
}
|
|
656
|
+
let num = angle2 % 360;
|
|
657
|
+
if (num < 0) {
|
|
658
|
+
num += 360;
|
|
659
|
+
} else if (angle2 === 360) {
|
|
660
|
+
num = 0;
|
|
661
|
+
}
|
|
662
|
+
return num;
|
|
663
|
+
}
|
|
664
|
+
function getGroupQueueByElementPosition(elements, position) {
|
|
665
|
+
var _a;
|
|
666
|
+
const groupQueue = [];
|
|
667
|
+
let currentElements = elements;
|
|
668
|
+
if (position.length > 1) {
|
|
669
|
+
for (let i = 0; i < position.length - 1; i++) {
|
|
670
|
+
const index = position[i];
|
|
671
|
+
const group = currentElements[index];
|
|
672
|
+
if ((group === null || group === void 0 ? void 0 : group.type) === "group" && Array.isArray((_a = group === null || group === void 0 ? void 0 : group.detail) === null || _a === void 0 ? void 0 : _a.children)) {
|
|
673
|
+
groupQueue.push(group);
|
|
674
|
+
currentElements = group.detail.children;
|
|
675
|
+
} else {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return groupQueue;
|
|
681
|
+
}
|
|
682
|
+
function findElementFromListByPosition(position, list) {
|
|
683
|
+
let result = null;
|
|
684
|
+
let tempList = list;
|
|
685
|
+
for (let i = 0; i < position.length; i++) {
|
|
686
|
+
const pos = position[i];
|
|
687
|
+
const item = tempList[pos];
|
|
688
|
+
if (i < position.length - 1 && (item === null || item === void 0 ? void 0 : item.type) === "group") {
|
|
689
|
+
tempList = item.detail.children;
|
|
690
|
+
} else if (i === position.length - 1) {
|
|
691
|
+
result = item;
|
|
692
|
+
} else {
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return result;
|
|
697
|
+
}
|
|
698
|
+
function getElementVertexes(elemSize) {
|
|
699
|
+
const { x: x2, y: y2, h: h2, w: w2 } = elemSize;
|
|
700
|
+
return [
|
|
701
|
+
{ x: x2, y: y2 },
|
|
702
|
+
{ x: x2 + w2, y: y2 },
|
|
703
|
+
{ x: x2 + w2, y: y2 + h2 },
|
|
704
|
+
{ x: x2, y: y2 + h2 }
|
|
705
|
+
];
|
|
706
|
+
}
|
|
707
|
+
function calcElementVertexes(elemSize) {
|
|
708
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemSize;
|
|
709
|
+
if (angle2 === 0) {
|
|
710
|
+
return getElementVertexes(elemSize);
|
|
711
|
+
}
|
|
712
|
+
return getElementRotateVertexes(elemSize, calcElementCenter({ x: x2, y: y2, w: w2, h: h2 }), angle2);
|
|
713
|
+
}
|
|
714
|
+
function calcElementQueueVertexesQueueInGroup(groupQueue) {
|
|
715
|
+
const vesList = [];
|
|
716
|
+
let totalX = 0;
|
|
717
|
+
let totalY = 0;
|
|
718
|
+
const rotateActionList = [];
|
|
719
|
+
const elemQueue = [...groupQueue];
|
|
720
|
+
for (let i = 0; i < elemQueue.length; i++) {
|
|
721
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 = 0 } = elemQueue[i];
|
|
722
|
+
totalX += x2;
|
|
723
|
+
totalY += y2;
|
|
724
|
+
let ves;
|
|
725
|
+
if (i === 0) {
|
|
726
|
+
const elemSize = { x: totalX, y: totalY, w: w2, h: h2 };
|
|
727
|
+
ves = calcElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
728
|
+
rotateActionList.push({
|
|
729
|
+
center: calcElementCenter(elemSize),
|
|
730
|
+
angle: angle2,
|
|
731
|
+
radian: parseAngleToRadian(angle2)
|
|
732
|
+
});
|
|
733
|
+
} else {
|
|
734
|
+
const elemSize = { x: totalX, y: totalY, w: w2, h: h2 };
|
|
735
|
+
ves = getElementVertexes(elemSize);
|
|
736
|
+
for (let aIdx = 0; aIdx < rotateActionList.length; aIdx++) {
|
|
737
|
+
const { center, radian } = rotateActionList[aIdx];
|
|
738
|
+
ves = rotateVertexes(center, ves, radian);
|
|
739
|
+
}
|
|
740
|
+
const vesCenter = calcElementCenterFromVertexes(ves);
|
|
741
|
+
if (angle2 > 0 || angle2 < 0) {
|
|
742
|
+
const radian = parseAngleToRadian(angle2);
|
|
743
|
+
ves = rotateVertexes(vesCenter, ves, radian);
|
|
744
|
+
}
|
|
745
|
+
rotateActionList.push({
|
|
746
|
+
center: vesCenter,
|
|
747
|
+
angle: angle2,
|
|
748
|
+
radian: parseAngleToRadian(angle2)
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
vesList.push(ves);
|
|
752
|
+
}
|
|
753
|
+
return vesList;
|
|
754
|
+
}
|
|
755
|
+
function calcElementVertexesQueueInGroup(targetElem, opts) {
|
|
756
|
+
const { groupQueue } = opts;
|
|
757
|
+
if (!(groupQueue.length > 0)) {
|
|
758
|
+
return [calcElementVertexes(targetElem)];
|
|
759
|
+
}
|
|
760
|
+
const elemQueue = [...groupQueue, ...[targetElem]];
|
|
761
|
+
const vesList = calcElementQueueVertexesQueueInGroup(elemQueue);
|
|
762
|
+
return vesList;
|
|
763
|
+
}
|
|
764
|
+
function calcElementVertexesInGroup(targetElem, opts) {
|
|
765
|
+
const vesList = calcElementVertexesQueueInGroup(targetElem, opts);
|
|
766
|
+
const ves = vesList.pop();
|
|
767
|
+
return ves || null;
|
|
768
|
+
}
|
|
769
|
+
function calcViewElementSize(size, opts) {
|
|
770
|
+
const { viewScaleInfo } = opts;
|
|
771
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = size;
|
|
772
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
773
|
+
const newSize = {
|
|
774
|
+
x: x2 * scale + offsetLeft,
|
|
775
|
+
y: y2 * scale + offsetTop,
|
|
776
|
+
w: w2 * scale,
|
|
777
|
+
h: h2 * scale,
|
|
778
|
+
angle: angle2
|
|
779
|
+
};
|
|
780
|
+
return newSize;
|
|
781
|
+
}
|
|
782
|
+
function calcViewPointSize(size, opts) {
|
|
783
|
+
const { viewScaleInfo } = opts;
|
|
784
|
+
const { x: x2, y: y2 } = size;
|
|
785
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
786
|
+
const newSize = {
|
|
787
|
+
x: x2 * scale + offsetLeft,
|
|
788
|
+
y: y2 * scale + offsetTop
|
|
789
|
+
};
|
|
790
|
+
return newSize;
|
|
791
|
+
}
|
|
792
|
+
function isViewPointInElement(p, opts) {
|
|
793
|
+
const { context2d: ctx, element: elem, viewScaleInfo } = opts;
|
|
794
|
+
const { angle: angle2 = 0 } = elem;
|
|
795
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
|
|
796
|
+
const vertexes = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
|
|
797
|
+
if (vertexes.length >= 2) {
|
|
798
|
+
ctx.beginPath();
|
|
799
|
+
ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
|
800
|
+
for (let i = 1; i < vertexes.length; i++) {
|
|
801
|
+
ctx.lineTo(vertexes[i].x, vertexes[i].y);
|
|
802
|
+
}
|
|
803
|
+
ctx.closePath();
|
|
804
|
+
}
|
|
805
|
+
if (ctx.isPointInPath(p.x, p.y)) {
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
function getViewPointAtElement(p, opts) {
|
|
811
|
+
var _a, _b, _c;
|
|
812
|
+
const { context2d: ctx, data, viewScaleInfo, groupQueue } = opts;
|
|
813
|
+
const result = {
|
|
814
|
+
index: -1,
|
|
815
|
+
element: null,
|
|
816
|
+
groupQueueIndex: -1
|
|
817
|
+
};
|
|
818
|
+
if (groupQueue && Array.isArray(groupQueue) && (groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
|
|
819
|
+
for (let gIdx = groupQueue.length - 1; gIdx >= 0; gIdx--) {
|
|
820
|
+
let totalX = 0;
|
|
821
|
+
let totalY = 0;
|
|
822
|
+
let totalAngle = 0;
|
|
823
|
+
for (let i = 0; i <= gIdx; i++) {
|
|
824
|
+
totalX += groupQueue[i].x;
|
|
825
|
+
totalY += groupQueue[i].y;
|
|
826
|
+
totalAngle += groupQueue[i].angle || 0;
|
|
827
|
+
}
|
|
828
|
+
const lastGroup = groupQueue[gIdx];
|
|
829
|
+
if (lastGroup && lastGroup.type === "group" && Array.isArray((_a = lastGroup.detail) === null || _a === void 0 ? void 0 : _a.children)) {
|
|
830
|
+
for (let i = 0; i < lastGroup.detail.children.length; i++) {
|
|
831
|
+
const child = lastGroup.detail.children[i];
|
|
832
|
+
if (((_b = child === null || child === void 0 ? void 0 : child.operations) === null || _b === void 0 ? void 0 : _b.invisible) === true) {
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (child) {
|
|
836
|
+
const elemSize = {
|
|
837
|
+
x: totalX + child.x,
|
|
838
|
+
y: totalY + child.y,
|
|
839
|
+
w: child.w,
|
|
840
|
+
h: child.h,
|
|
841
|
+
angle: totalAngle + (child.angle || 0)
|
|
842
|
+
};
|
|
843
|
+
if (isViewPointInElement(p, { context2d: ctx, element: elemSize, viewScaleInfo })) {
|
|
844
|
+
result.element = child;
|
|
845
|
+
if (gIdx < groupQueue.length - 1 || child.type !== "group") {
|
|
846
|
+
result.groupQueueIndex = gIdx;
|
|
847
|
+
}
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
} else {
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (result.element) {
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (result.element) {
|
|
861
|
+
return result;
|
|
862
|
+
}
|
|
863
|
+
for (let i = data.elements.length - 1; i >= 0; i--) {
|
|
864
|
+
const elem = data.elements[i];
|
|
865
|
+
if (((_c = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _c === void 0 ? void 0 : _c.invisible) === true) {
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
if (isViewPointInElement(p, { context2d: ctx, element: elem, viewScaleInfo })) {
|
|
869
|
+
result.index = i;
|
|
870
|
+
result.element = elem;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return result;
|
|
875
|
+
}
|
|
876
|
+
function calcElementOriginRectInfo(elemSize, opts) {
|
|
877
|
+
const { groupQueue } = opts;
|
|
878
|
+
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
|
|
879
|
+
const top = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
880
|
+
const right = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
881
|
+
const bottom = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
|
882
|
+
const left = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
|
|
883
|
+
const topLeft = vertexes[0];
|
|
884
|
+
const topRight = vertexes[1];
|
|
885
|
+
const bottomRight = vertexes[2];
|
|
886
|
+
const bottomLeft = vertexes[3];
|
|
887
|
+
const maxX = Math.max(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
|
|
888
|
+
const maxY = Math.max(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
889
|
+
const minX = Math.min(topLeft.x, topRight.x, bottomRight.x, bottomLeft.x);
|
|
890
|
+
const minY = Math.min(topLeft.y, topRight.y, bottomRight.y, bottomLeft.y);
|
|
891
|
+
const center = {
|
|
892
|
+
x: (maxX + minX) / 2,
|
|
893
|
+
y: (maxY + minY) / 2
|
|
894
|
+
};
|
|
895
|
+
const rectInfo = {
|
|
896
|
+
center,
|
|
897
|
+
topLeft,
|
|
898
|
+
topRight,
|
|
899
|
+
bottomLeft,
|
|
900
|
+
bottomRight,
|
|
901
|
+
top,
|
|
902
|
+
right,
|
|
903
|
+
left,
|
|
904
|
+
bottom
|
|
905
|
+
};
|
|
906
|
+
return rectInfo;
|
|
907
|
+
}
|
|
908
|
+
function originRectInfoToRangeRectInfo(originRectInfo) {
|
|
909
|
+
const rangeMaxX = Math.max(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
|
|
910
|
+
const rangeMaxY = Math.max(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
|
|
911
|
+
const rangeMinX = Math.min(originRectInfo.topLeft.x, originRectInfo.topRight.x, originRectInfo.bottomRight.x, originRectInfo.bottomLeft.x);
|
|
912
|
+
const rangeMinY = Math.min(originRectInfo.topLeft.y, originRectInfo.topRight.y, originRectInfo.bottomRight.y, originRectInfo.bottomLeft.y);
|
|
913
|
+
const rangeCenter = { x: originRectInfo.center.x, y: originRectInfo.center.y };
|
|
914
|
+
const rangeTopLeft = { x: rangeMinX, y: rangeMinY };
|
|
915
|
+
const rangeTopRight = { x: rangeMaxX, y: rangeMinY };
|
|
916
|
+
const rangeBottomRight = { x: rangeMaxX, y: rangeMaxY };
|
|
917
|
+
const rangeBottomLeft = { x: rangeMinX, y: rangeMaxY };
|
|
918
|
+
const rangeTop = getCenterFromTwoPoints(rangeTopLeft, rangeTopRight);
|
|
919
|
+
const rangeBottom = getCenterFromTwoPoints(rangeBottomLeft, rangeBottomRight);
|
|
920
|
+
const rangeLeft = getCenterFromTwoPoints(rangeTopLeft, rangeBottomLeft);
|
|
921
|
+
const rangeRight = getCenterFromTwoPoints(rangeTopRight, rangeBottomRight);
|
|
922
|
+
const rangeRectInfo = {
|
|
923
|
+
center: rangeCenter,
|
|
924
|
+
topLeft: rangeTopLeft,
|
|
925
|
+
topRight: rangeTopRight,
|
|
926
|
+
bottomLeft: rangeBottomLeft,
|
|
927
|
+
bottomRight: rangeBottomRight,
|
|
928
|
+
top: rangeTop,
|
|
929
|
+
right: rangeRight,
|
|
930
|
+
left: rangeLeft,
|
|
931
|
+
bottom: rangeBottom
|
|
932
|
+
};
|
|
933
|
+
return rangeRectInfo;
|
|
934
|
+
}
|
|
414
935
|
function generateSVGPath(commands) {
|
|
415
936
|
let path = "";
|
|
416
937
|
commands.forEach((item) => {
|
|
@@ -434,9 +955,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
434
955
|
textAlign: "left",
|
|
435
956
|
verticalAlign: "top",
|
|
436
957
|
fontSize: 16,
|
|
437
|
-
lineHeight: 20,
|
|
438
958
|
fontFamily: "sans-serif",
|
|
439
959
|
fontWeight: 400,
|
|
960
|
+
minInlineSize: "auto",
|
|
961
|
+
wordBreak: "break-all",
|
|
440
962
|
overflow: "hidden"
|
|
441
963
|
};
|
|
442
964
|
return config;
|
|
@@ -446,8 +968,10 @@ var __privateMethod = (obj, member, method) => {
|
|
|
446
968
|
const { viewScaleInfo } = opts;
|
|
447
969
|
const { scale } = viewScaleInfo;
|
|
448
970
|
let { borderRadius: borderRadius2 } = viewElem.detail;
|
|
971
|
+
const { borderDash } = viewElem.detail;
|
|
972
|
+
const hasBorderDash = Array.isArray(borderDash) && borderDash.length > 0;
|
|
449
973
|
const { boxSizing = defaultElemConfig$1.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
|
|
450
|
-
if (
|
|
974
|
+
if (Array.isArray(borderWidth2)) {
|
|
451
975
|
borderRadius2 = 0;
|
|
452
976
|
}
|
|
453
977
|
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
@@ -462,7 +986,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
462
986
|
if (typeof borderWidth2 === "number") {
|
|
463
987
|
bw = (borderWidth2 || 0) * scale;
|
|
464
988
|
}
|
|
465
|
-
if (boxSizing === "border-box") {
|
|
989
|
+
if (boxSizing === "border-box" && !hasBorderDash) {
|
|
466
990
|
x2 = viewElem.x + bw / 2;
|
|
467
991
|
y2 = viewElem.y + bw / 2;
|
|
468
992
|
w2 = viewElem.w - bw;
|
|
@@ -491,6 +1015,21 @@ var __privateMethod = (obj, member, method) => {
|
|
|
491
1015
|
radiusList
|
|
492
1016
|
};
|
|
493
1017
|
}
|
|
1018
|
+
const baseFontFamilyList = ["-apple-system", '"system-ui"', ' "Segoe UI"', " Roboto", '"Helvetica Neue"', "Arial", '"Noto Sans"', " sans-serif"];
|
|
1019
|
+
function enhanceFontFamliy(fontFamily2) {
|
|
1020
|
+
return [fontFamily2, ...baseFontFamilyList].join(", ");
|
|
1021
|
+
}
|
|
1022
|
+
(function(s, e) {
|
|
1023
|
+
var t = {};
|
|
1024
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1025
|
+
t[p] = s[p];
|
|
1026
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1027
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1028
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1029
|
+
t[p[i]] = s[p[i]];
|
|
1030
|
+
}
|
|
1031
|
+
return t;
|
|
1032
|
+
});
|
|
494
1033
|
function createColorStyle(ctx, color2, opts) {
|
|
495
1034
|
if (typeof color2 === "string") {
|
|
496
1035
|
return color2;
|
|
@@ -535,30 +1074,50 @@ var __privateMethod = (obj, member, method) => {
|
|
|
535
1074
|
return "#000000";
|
|
536
1075
|
}
|
|
537
1076
|
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
1077
|
+
function getOpacity(elem) {
|
|
1078
|
+
var _a, _b, _c, _d;
|
|
1079
|
+
let opacity = 1;
|
|
1080
|
+
if (((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = elem == null ? void 0 : elem.detail) == null ? void 0 : _b.opacity) >= 0 && ((_c = elem == null ? void 0 : elem.detail) == null ? void 0 : _c.opacity) <= 1) {
|
|
1081
|
+
opacity = (_d = elem == null ? void 0 : elem.detail) == null ? void 0 : _d.opacity;
|
|
1082
|
+
}
|
|
1083
|
+
return opacity;
|
|
1084
|
+
}
|
|
538
1085
|
function drawBox(ctx, viewElem, opts) {
|
|
539
1086
|
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
1087
|
+
const { parentOpacity } = opts;
|
|
1088
|
+
const opacity = getOpacity(originElem) * parentOpacity;
|
|
1089
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = originElem.detail;
|
|
1090
|
+
const mainRender = () => {
|
|
1091
|
+
ctx.globalAlpha = opacity;
|
|
1092
|
+
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
1093
|
+
renderContent == null ? void 0 : renderContent();
|
|
1094
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo });
|
|
1095
|
+
ctx.globalAlpha = parentOpacity;
|
|
1096
|
+
};
|
|
1097
|
+
if (clipPath) {
|
|
1098
|
+
drawClipPath(ctx, viewElem, {
|
|
1099
|
+
originElem,
|
|
1100
|
+
calcElemSize,
|
|
1101
|
+
viewSizeInfo,
|
|
1102
|
+
renderContent: () => {
|
|
1103
|
+
mainRender();
|
|
551
1104
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
1105
|
+
});
|
|
1106
|
+
if (typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
1107
|
+
drawClipPathStroke(ctx, viewElem, {
|
|
1108
|
+
originElem,
|
|
1109
|
+
calcElemSize,
|
|
1110
|
+
viewSizeInfo,
|
|
1111
|
+
parentOpacity
|
|
1112
|
+
});
|
|
556
1113
|
}
|
|
557
|
-
}
|
|
1114
|
+
} else {
|
|
1115
|
+
mainRender();
|
|
1116
|
+
}
|
|
558
1117
|
}
|
|
559
1118
|
function drawClipPath(ctx, viewElem, opts) {
|
|
560
|
-
const { renderContent, originElem, calcElemSize,
|
|
561
|
-
const totalScale =
|
|
1119
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
|
|
1120
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
562
1121
|
const { clipPath } = (originElem == null ? void 0 : originElem.detail) || {};
|
|
563
1122
|
if (clipPath && calcElemSize && clipPath.commands) {
|
|
564
1123
|
const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
|
|
@@ -574,7 +1133,39 @@ var __privateMethod = (obj, member, method) => {
|
|
|
574
1133
|
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
575
1134
|
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
576
1135
|
const path2d = new Path2D(pathStr);
|
|
577
|
-
ctx.clip(path2d);
|
|
1136
|
+
ctx.clip(path2d, "nonzero");
|
|
1137
|
+
ctx.translate(0 - internalX, 0 - internalY);
|
|
1138
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1139
|
+
rotateElement(ctx, { ...viewElem }, () => {
|
|
1140
|
+
renderContent == null ? void 0 : renderContent();
|
|
1141
|
+
});
|
|
1142
|
+
ctx.restore();
|
|
1143
|
+
} else {
|
|
1144
|
+
renderContent == null ? void 0 : renderContent();
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
function drawClipPathStroke(ctx, viewElem, opts) {
|
|
1148
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo, parentOpacity } = opts;
|
|
1149
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
1150
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth } = (originElem == null ? void 0 : originElem.detail) || {};
|
|
1151
|
+
if (clipPath && calcElemSize && clipPath.commands && typeof clipPathStrokeWidth === "number" && clipPathStrokeWidth > 0 && clipPathStrokeColor) {
|
|
1152
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
|
|
1153
|
+
const { originW, originH, originX, originY } = clipPath;
|
|
1154
|
+
const scaleW = w2 / originW;
|
|
1155
|
+
const scaleH = h2 / originH;
|
|
1156
|
+
const viewOriginX = originX * scaleW;
|
|
1157
|
+
const viewOriginY = originY * scaleH;
|
|
1158
|
+
const internalX = x2 - viewOriginX;
|
|
1159
|
+
const internalY = y2 - viewOriginY;
|
|
1160
|
+
ctx.save();
|
|
1161
|
+
ctx.globalAlpha = parentOpacity;
|
|
1162
|
+
ctx.translate(internalX, internalY);
|
|
1163
|
+
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
1164
|
+
const pathStr = generateSVGPath(clipPath.commands || []);
|
|
1165
|
+
const path2d = new Path2D(pathStr);
|
|
1166
|
+
ctx.strokeStyle = clipPathStrokeColor;
|
|
1167
|
+
ctx.lineWidth = clipPathStrokeWidth;
|
|
1168
|
+
ctx.stroke(path2d);
|
|
578
1169
|
ctx.translate(0 - internalX, 0 - internalY);
|
|
579
1170
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
580
1171
|
rotateElement(ctx, { ...viewElem }, () => {
|
|
@@ -589,12 +1180,9 @@ var __privateMethod = (obj, member, method) => {
|
|
|
589
1180
|
var _a, _b;
|
|
590
1181
|
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
591
1182
|
const transform = [];
|
|
592
|
-
viewElem.detail;
|
|
593
|
-
viewElem.detail;
|
|
594
1183
|
if (viewElem.detail.background || pattern) {
|
|
595
1184
|
const { x: x2, y: y2, w: w2, h: h2, radiusList } = calcViewBoxSize(viewElem, {
|
|
596
|
-
viewScaleInfo
|
|
597
|
-
viewSizeInfo
|
|
1185
|
+
viewScaleInfo
|
|
598
1186
|
});
|
|
599
1187
|
ctx.beginPath();
|
|
600
1188
|
ctx.moveTo(x2 + radiusList[0], y2);
|
|
@@ -636,37 +1224,35 @@ var __privateMethod = (obj, member, method) => {
|
|
|
636
1224
|
}
|
|
637
1225
|
}
|
|
638
1226
|
}
|
|
639
|
-
ctx.fill();
|
|
1227
|
+
ctx.fill("nonzero");
|
|
640
1228
|
if (transform && transform.length > 0) {
|
|
641
1229
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
642
1230
|
}
|
|
643
1231
|
}
|
|
644
1232
|
}
|
|
645
1233
|
function drawBoxBorder(ctx, viewElem, opts) {
|
|
646
|
-
var _a, _b;
|
|
647
1234
|
if (viewElem.detail.borderWidth === 0) {
|
|
648
1235
|
return;
|
|
649
1236
|
}
|
|
650
1237
|
if (!isColorStr(viewElem.detail.borderColor)) {
|
|
651
1238
|
return;
|
|
652
1239
|
}
|
|
653
|
-
if (((_a = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _b.opacity) >= 0) {
|
|
654
|
-
ctx.globalAlpha = viewElem.detail.opacity;
|
|
655
|
-
} else {
|
|
656
|
-
ctx.globalAlpha = 1;
|
|
657
|
-
}
|
|
658
1240
|
const { viewScaleInfo } = opts;
|
|
659
1241
|
const { scale } = viewScaleInfo;
|
|
660
1242
|
let borderColor = defaultElemConfig.borderColor;
|
|
661
1243
|
if (isColorStr(viewElem.detail.borderColor) === true) {
|
|
662
1244
|
borderColor = viewElem.detail.borderColor;
|
|
663
1245
|
}
|
|
664
|
-
const { borderWidth: borderWidth2, borderRadius: borderRadius2,
|
|
665
|
-
let
|
|
666
|
-
if (
|
|
667
|
-
|
|
1246
|
+
const { borderDash, borderWidth: borderWidth2, borderRadius: borderRadius2, boxSizing = defaultElemConfig.boxSizing } = viewElem.detail;
|
|
1247
|
+
let viewBorderDash = [];
|
|
1248
|
+
if (Array.isArray(borderDash) && borderDash.length > 0) {
|
|
1249
|
+
viewBorderDash = borderDash.map((num) => Math.ceil(num * scale));
|
|
1250
|
+
}
|
|
1251
|
+
if (viewBorderDash.length > 0) {
|
|
1252
|
+
ctx.lineCap = "butt";
|
|
1253
|
+
} else {
|
|
1254
|
+
ctx.lineCap = "square";
|
|
668
1255
|
}
|
|
669
|
-
bw = bw * scale;
|
|
670
1256
|
let radiusList = [0, 0, 0, 0];
|
|
671
1257
|
if (typeof borderRadius2 === "number") {
|
|
672
1258
|
const br = borderRadius2 * scale;
|
|
@@ -674,11 +1260,12 @@ var __privateMethod = (obj, member, method) => {
|
|
|
674
1260
|
} else if (Array.isArray(borderRadius2) && (borderRadius2 == null ? void 0 : borderRadius2.length) === 4) {
|
|
675
1261
|
radiusList = [borderRadius2[0] * scale, borderRadius2[1] * scale, borderRadius2[2] * scale, borderRadius2[3] * scale];
|
|
676
1262
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
viewBorderDash = borderDash.map((num) => Math.ceil(num * scale));
|
|
1263
|
+
let bw = 0;
|
|
1264
|
+
if (typeof borderWidth2 === "number") {
|
|
1265
|
+
bw = borderWidth2 || 1;
|
|
681
1266
|
}
|
|
1267
|
+
bw = bw * scale;
|
|
1268
|
+
ctx.strokeStyle = borderColor;
|
|
682
1269
|
let borderTop = 0;
|
|
683
1270
|
let borderRight = 0;
|
|
684
1271
|
let borderBottom = 0;
|
|
@@ -758,11 +1345,6 @@ var __privateMethod = (obj, member, method) => {
|
|
|
758
1345
|
w2 = viewElem.w;
|
|
759
1346
|
h2 = viewElem.h;
|
|
760
1347
|
}
|
|
761
|
-
if (viewBorderDash.length > 0) {
|
|
762
|
-
ctx.lineCap = "butt";
|
|
763
|
-
} else {
|
|
764
|
-
ctx.lineCap = "square";
|
|
765
|
-
}
|
|
766
1348
|
w2 = Math.max(w2, 1);
|
|
767
1349
|
h2 = Math.max(h2, 1);
|
|
768
1350
|
radiusList = radiusList.map((r) => {
|
|
@@ -778,7 +1360,6 @@ var __privateMethod = (obj, member, method) => {
|
|
|
778
1360
|
ctx.arcTo(x2, y2, x2 + w2, y2, radiusList[0]);
|
|
779
1361
|
ctx.closePath();
|
|
780
1362
|
ctx.stroke();
|
|
781
|
-
ctx.globalAlpha = 1;
|
|
782
1363
|
}
|
|
783
1364
|
ctx.setLineDash([]);
|
|
784
1365
|
}
|
|
@@ -795,69 +1376,96 @@ var __privateMethod = (obj, member, method) => {
|
|
|
795
1376
|
renderContent();
|
|
796
1377
|
ctx.restore();
|
|
797
1378
|
} else {
|
|
1379
|
+
ctx.save();
|
|
1380
|
+
ctx.shadowColor = "transparent";
|
|
1381
|
+
ctx.shadowOffsetX = 0;
|
|
1382
|
+
ctx.shadowOffsetY = 0;
|
|
1383
|
+
ctx.shadowBlur = 0;
|
|
798
1384
|
renderContent();
|
|
1385
|
+
ctx.restore();
|
|
799
1386
|
}
|
|
800
1387
|
}
|
|
801
1388
|
function drawCircle(ctx, elem, opts) {
|
|
802
1389
|
const { detail, angle: angle2 } = elem;
|
|
803
|
-
const {
|
|
804
|
-
const {
|
|
805
|
-
|
|
1390
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1391
|
+
const { background = "#000000", borderColor = "#000000", boxSizing, borderWidth: borderWidth2 = 0, borderDash } = detail;
|
|
1392
|
+
let bw = 0;
|
|
1393
|
+
if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
|
|
1394
|
+
bw = borderWidth2;
|
|
1395
|
+
} else if (Array.isArray(borderWidth2) && typeof borderWidth2[0] === "number" && borderWidth2[0] > 0) {
|
|
1396
|
+
bw = borderWidth2[0];
|
|
1397
|
+
}
|
|
1398
|
+
bw = bw * viewScaleInfo.scale;
|
|
1399
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, { viewScaleInfo }) || elem;
|
|
806
1400
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
807
1401
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
808
1402
|
drawBoxShadow(ctx, viewElem, {
|
|
809
1403
|
viewScaleInfo,
|
|
810
|
-
viewSizeInfo,
|
|
811
1404
|
renderContent: () => {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
const b = h2 / 2;
|
|
1405
|
+
let a = w2 / 2;
|
|
1406
|
+
let b = h2 / 2;
|
|
815
1407
|
const centerX = x2 + a;
|
|
816
1408
|
const centerY = y2 + b;
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1409
|
+
const radiusA = a;
|
|
1410
|
+
const radiusB = b;
|
|
1411
|
+
if (bw > 0) {
|
|
1412
|
+
if (boxSizing === "content-box") ;
|
|
1413
|
+
else if (boxSizing === "center-line") {
|
|
1414
|
+
a = a - bw / 2;
|
|
1415
|
+
b = b - bw / 2;
|
|
1416
|
+
} else {
|
|
1417
|
+
a = a - bw;
|
|
1418
|
+
b = b - bw;
|
|
1419
|
+
}
|
|
821
1420
|
}
|
|
822
|
-
if (
|
|
823
|
-
const
|
|
824
|
-
|
|
1421
|
+
if (a >= 0 && b >= 0) {
|
|
1422
|
+
const opacity = getOpacity(viewElem) * parentOpacity;
|
|
1423
|
+
ctx.globalAlpha = opacity;
|
|
825
1424
|
ctx.beginPath();
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
1425
|
+
const fillStyle = createColorStyle(ctx, background, {
|
|
1426
|
+
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
1427
|
+
viewScaleInfo,
|
|
1428
|
+
opacity: ctx.globalAlpha
|
|
1429
|
+
});
|
|
1430
|
+
ctx.fillStyle = fillStyle;
|
|
1431
|
+
ctx.circle(centerX, centerY, radiusA, radiusB, 0, 0, 2 * Math.PI);
|
|
829
1432
|
ctx.closePath();
|
|
830
|
-
ctx.
|
|
1433
|
+
ctx.fill("nonzero");
|
|
1434
|
+
ctx.globalAlpha = parentOpacity;
|
|
1435
|
+
if (typeof bw === "number" && bw > 0) {
|
|
1436
|
+
const ba = bw / 2 + a;
|
|
1437
|
+
const bb = bw / 2 + b;
|
|
1438
|
+
ctx.beginPath();
|
|
1439
|
+
if (borderDash) {
|
|
1440
|
+
const lineDash = borderDash.map((n) => n * viewScaleInfo.scale);
|
|
1441
|
+
ctx.setLineDash(lineDash);
|
|
1442
|
+
}
|
|
1443
|
+
ctx.strokeStyle = borderColor;
|
|
1444
|
+
ctx.lineWidth = bw;
|
|
1445
|
+
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
|
|
1446
|
+
ctx.closePath();
|
|
1447
|
+
ctx.stroke();
|
|
1448
|
+
ctx.setLineDash([]);
|
|
1449
|
+
}
|
|
831
1450
|
}
|
|
832
|
-
ctx.beginPath();
|
|
833
|
-
const fillStyle = createColorStyle(ctx, background, {
|
|
834
|
-
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
835
|
-
viewScaleInfo,
|
|
836
|
-
opacity: ctx.globalAlpha
|
|
837
|
-
});
|
|
838
|
-
ctx.fillStyle = fillStyle;
|
|
839
|
-
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
|
|
840
|
-
ctx.closePath();
|
|
841
|
-
ctx.fill();
|
|
842
|
-
ctx.globalAlpha = 1;
|
|
843
1451
|
}
|
|
844
1452
|
});
|
|
845
1453
|
});
|
|
846
1454
|
}
|
|
847
1455
|
function drawRect(ctx, elem, opts) {
|
|
848
|
-
const {
|
|
849
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1456
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1457
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
850
1458
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
851
1459
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
852
1460
|
drawBoxShadow(ctx, viewElem, {
|
|
853
1461
|
viewScaleInfo,
|
|
854
|
-
viewSizeInfo,
|
|
855
1462
|
renderContent: () => {
|
|
856
1463
|
drawBox(ctx, viewElem, {
|
|
857
1464
|
originElem: elem,
|
|
858
1465
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
859
1466
|
viewScaleInfo,
|
|
860
1467
|
viewSizeInfo,
|
|
1468
|
+
parentOpacity,
|
|
861
1469
|
renderContent: () => {
|
|
862
1470
|
}
|
|
863
1471
|
});
|
|
@@ -867,30 +1475,32 @@ var __privateMethod = (obj, member, method) => {
|
|
|
867
1475
|
}
|
|
868
1476
|
function drawImage(ctx, elem, opts) {
|
|
869
1477
|
const content = opts.loader.getContent(elem);
|
|
870
|
-
const {
|
|
871
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1478
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1479
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
872
1480
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
873
1481
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
874
1482
|
drawBoxShadow(ctx, viewElem, {
|
|
875
1483
|
viewScaleInfo,
|
|
876
|
-
viewSizeInfo,
|
|
877
1484
|
renderContent: () => {
|
|
878
1485
|
drawBox(ctx, viewElem, {
|
|
879
1486
|
originElem: elem,
|
|
880
1487
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
881
1488
|
viewScaleInfo,
|
|
882
1489
|
viewSizeInfo,
|
|
1490
|
+
parentOpacity,
|
|
883
1491
|
renderContent: () => {
|
|
884
|
-
if (!content) {
|
|
1492
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
885
1493
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
886
1494
|
}
|
|
887
1495
|
if (elem.type === "image" && content) {
|
|
888
|
-
|
|
889
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1496
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
890
1497
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
891
|
-
viewScaleInfo
|
|
892
|
-
viewSizeInfo
|
|
1498
|
+
viewScaleInfo
|
|
893
1499
|
});
|
|
1500
|
+
const { detail } = elem;
|
|
1501
|
+
const { scaleMode, originW = 0, originH = 0 } = detail;
|
|
1502
|
+
const imageW = ctx.$undoPixelRatio(originW);
|
|
1503
|
+
const imageH = ctx.$undoPixelRatio(originH);
|
|
894
1504
|
ctx.save();
|
|
895
1505
|
ctx.fillStyle = "transparent";
|
|
896
1506
|
ctx.beginPath();
|
|
@@ -900,10 +1510,44 @@ var __privateMethod = (obj, member, method) => {
|
|
|
900
1510
|
ctx.arcTo(x22, y22 + h22, x22, y22, radiusList[3]);
|
|
901
1511
|
ctx.arcTo(x22, y22, x22 + w22, y22, radiusList[0]);
|
|
902
1512
|
ctx.closePath();
|
|
903
|
-
ctx.fill();
|
|
904
|
-
ctx.clip();
|
|
905
|
-
|
|
906
|
-
|
|
1513
|
+
ctx.fill("nonzero");
|
|
1514
|
+
ctx.clip("nonzero");
|
|
1515
|
+
if (scaleMode && originH && originW) {
|
|
1516
|
+
let sx = 0;
|
|
1517
|
+
let sy = 0;
|
|
1518
|
+
let sWidth = imageW;
|
|
1519
|
+
let sHeight = imageH;
|
|
1520
|
+
const dx = x22;
|
|
1521
|
+
const dy = y22;
|
|
1522
|
+
const dWidth = w22;
|
|
1523
|
+
const dHeight = h22;
|
|
1524
|
+
if (imageW > elem.w || imageH > elem.h) {
|
|
1525
|
+
if (scaleMode === "fill") {
|
|
1526
|
+
const sourceScale = Math.max(elem.w / imageW, elem.h / imageH);
|
|
1527
|
+
const newImageWidth = imageW * sourceScale;
|
|
1528
|
+
const newImageHeight = imageH * sourceScale;
|
|
1529
|
+
sx = (newImageWidth - elem.w) / 2 / sourceScale;
|
|
1530
|
+
sy = (newImageHeight - elem.h) / 2 / sourceScale;
|
|
1531
|
+
sWidth = elem.w / sourceScale;
|
|
1532
|
+
sHeight = elem.h / sourceScale;
|
|
1533
|
+
} else if (scaleMode === "tile") {
|
|
1534
|
+
sx = 0;
|
|
1535
|
+
sy = 0;
|
|
1536
|
+
sWidth = elem.w;
|
|
1537
|
+
sHeight = elem.h;
|
|
1538
|
+
} else if (scaleMode === "fit") {
|
|
1539
|
+
const sourceScale = Math.min(elem.w / imageW, elem.h / imageH);
|
|
1540
|
+
sx = (imageW - elem.w / sourceScale) / 2;
|
|
1541
|
+
sy = (imageH - elem.h / sourceScale) / 2;
|
|
1542
|
+
sWidth = elem.w / sourceScale;
|
|
1543
|
+
sHeight = elem.h / sourceScale;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
ctx.drawImage(content, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
|
1547
|
+
} else {
|
|
1548
|
+
ctx.drawImage(content, x22, y22, w22, h22);
|
|
1549
|
+
}
|
|
1550
|
+
ctx.globalAlpha = parentOpacity;
|
|
907
1551
|
ctx.restore();
|
|
908
1552
|
}
|
|
909
1553
|
}
|
|
@@ -914,115 +1558,73 @@ var __privateMethod = (obj, member, method) => {
|
|
|
914
1558
|
}
|
|
915
1559
|
function drawSVG(ctx, elem, opts) {
|
|
916
1560
|
const content = opts.loader.getContent(elem);
|
|
917
|
-
const {
|
|
918
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1561
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1562
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
919
1563
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
920
|
-
if (!content) {
|
|
1564
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
921
1565
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
922
1566
|
}
|
|
923
1567
|
if (elem.type === "svg" && content) {
|
|
924
|
-
|
|
925
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1568
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
926
1569
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
927
|
-
ctx.globalAlpha =
|
|
1570
|
+
ctx.globalAlpha = parentOpacity;
|
|
928
1571
|
}
|
|
929
1572
|
});
|
|
930
1573
|
}
|
|
931
1574
|
function drawHTML(ctx, elem, opts) {
|
|
932
1575
|
const content = opts.loader.getContent(elem);
|
|
933
|
-
const {
|
|
934
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1576
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1577
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
935
1578
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
936
|
-
if (!content) {
|
|
1579
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
937
1580
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
938
1581
|
}
|
|
939
1582
|
if (elem.type === "html" && content) {
|
|
940
|
-
|
|
941
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1583
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
942
1584
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
943
|
-
ctx.globalAlpha =
|
|
1585
|
+
ctx.globalAlpha = parentOpacity;
|
|
944
1586
|
}
|
|
945
1587
|
});
|
|
946
1588
|
}
|
|
947
|
-
const detailConfig = getDefaultElementDetailConfig();
|
|
1589
|
+
const detailConfig$1 = getDefaultElementDetailConfig();
|
|
948
1590
|
function drawText(ctx, elem, opts) {
|
|
949
|
-
const {
|
|
950
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1591
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity, calculator } = opts;
|
|
1592
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
951
1593
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
952
1594
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1595
|
+
var _a, _b;
|
|
1596
|
+
drawBoxShadow(ctx, viewElem, {
|
|
956
1597
|
viewScaleInfo,
|
|
957
|
-
viewSizeInfo,
|
|
958
1598
|
renderContent: () => {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
966
|
-
ctx.textBaseline = "top";
|
|
967
|
-
ctx.$setFont({
|
|
968
|
-
fontWeight: detail.fontWeight,
|
|
969
|
-
fontSize: fontSize2,
|
|
970
|
-
fontFamily: detail.fontFamily
|
|
971
|
-
});
|
|
972
|
-
const detailText = detail.text.replace(/\r\n/gi, "\n");
|
|
973
|
-
const fontHeight = lineHeight2;
|
|
974
|
-
const detailTextList = detailText.split("\n");
|
|
975
|
-
const lines = [];
|
|
976
|
-
let lineNum = 0;
|
|
977
|
-
detailTextList.forEach((tempText, idx) => {
|
|
978
|
-
let lineText = "";
|
|
979
|
-
if (tempText.length > 0) {
|
|
980
|
-
for (let i = 0; i < tempText.length; i++) {
|
|
981
|
-
if (ctx.measureText(lineText + (tempText[i] || "")).width < ctx.$doPixelRatio(w2)) {
|
|
982
|
-
lineText += tempText[i] || "";
|
|
983
|
-
} else {
|
|
984
|
-
lines.push({
|
|
985
|
-
text: lineText,
|
|
986
|
-
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
987
|
-
});
|
|
988
|
-
lineText = tempText[i] || "";
|
|
989
|
-
lineNum++;
|
|
990
|
-
}
|
|
991
|
-
if ((lineNum + 1) * fontHeight > h2) {
|
|
992
|
-
break;
|
|
993
|
-
}
|
|
994
|
-
if (tempText.length - 1 === i) {
|
|
995
|
-
if ((lineNum + 1) * fontHeight < h2) {
|
|
996
|
-
lines.push({
|
|
997
|
-
text: lineText,
|
|
998
|
-
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
999
|
-
});
|
|
1000
|
-
if (idx < detailTextList.length - 1) {
|
|
1001
|
-
lineNum++;
|
|
1002
|
-
}
|
|
1003
|
-
break;
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
} else {
|
|
1008
|
-
lines.push({
|
|
1009
|
-
text: "",
|
|
1010
|
-
width: 0
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1599
|
+
drawBox(ctx, viewElem, {
|
|
1600
|
+
originElem: elem,
|
|
1601
|
+
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1602
|
+
viewScaleInfo,
|
|
1603
|
+
viewSizeInfo,
|
|
1604
|
+
parentOpacity
|
|
1013
1605
|
});
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
{
|
|
1609
|
+
const detail = {
|
|
1610
|
+
...detailConfig$1,
|
|
1611
|
+
...elem.detail
|
|
1612
|
+
};
|
|
1613
|
+
const originFontSize = detail.fontSize || detailConfig$1.fontSize;
|
|
1614
|
+
const fontSize2 = originFontSize * viewScaleInfo.scale;
|
|
1615
|
+
if (fontSize2 < 2) {
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
ctx.fillStyle = elem.detail.color || detailConfig$1.color;
|
|
1619
|
+
ctx.textBaseline = "top";
|
|
1620
|
+
ctx.$setFont({
|
|
1621
|
+
fontWeight: detail.fontWeight,
|
|
1622
|
+
fontSize: fontSize2,
|
|
1623
|
+
fontFamily: enhanceFontFamliy(detail.fontFamily)
|
|
1624
|
+
});
|
|
1625
|
+
{
|
|
1626
|
+
const virtualTextDetail = calculator.getVirtualFlatItem(elem.uuid);
|
|
1627
|
+
if (Array.isArray(virtualTextDetail == null ? void 0 : virtualTextDetail.textLines) && ((_a = virtualTextDetail == null ? void 0 : virtualTextDetail.textLines) == null ? void 0 : _a.length) > 0) {
|
|
1026
1628
|
if (detail.textShadowColor !== void 0 && isColorStr(detail.textShadowColor)) {
|
|
1027
1629
|
ctx.shadowColor = detail.textShadowColor;
|
|
1028
1630
|
}
|
|
@@ -1035,43 +1637,64 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1035
1637
|
if (detail.textShadowBlur !== void 0 && is.number(detail.textShadowBlur)) {
|
|
1036
1638
|
ctx.shadowBlur = detail.textShadowBlur;
|
|
1037
1639
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
if (detail.textAlign === "center") {
|
|
1041
|
-
_x = x2 + (w2 - line.width) / 2;
|
|
1042
|
-
} else if (detail.textAlign === "right") {
|
|
1043
|
-
_x = x2 + (w2 - line.width);
|
|
1044
|
-
}
|
|
1045
|
-
ctx.fillText(line.text, _x, _y + fontHeight * i);
|
|
1640
|
+
(_b = virtualTextDetail == null ? void 0 : virtualTextDetail.textLines) == null ? void 0 : _b.forEach((line) => {
|
|
1641
|
+
ctx.fillText(line.text, x2 + line.x * viewScaleInfo.scale, y2 + line.y * viewScaleInfo.scale);
|
|
1046
1642
|
});
|
|
1047
1643
|
}
|
|
1048
1644
|
}
|
|
1049
|
-
}
|
|
1645
|
+
}
|
|
1050
1646
|
});
|
|
1051
1647
|
}
|
|
1052
1648
|
function drawPath(ctx, elem, opts) {
|
|
1649
|
+
var _a, _b;
|
|
1053
1650
|
const { detail } = elem;
|
|
1054
|
-
const { originX, originY, originW, originH } = detail;
|
|
1055
|
-
const {
|
|
1056
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1651
|
+
const { originX, originY, originW, originH, fillRule } = detail;
|
|
1652
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1653
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
1057
1654
|
const scaleW = w2 / originW;
|
|
1058
1655
|
const scaleH = h2 / originH;
|
|
1059
1656
|
const viewOriginX = originX * scaleW;
|
|
1060
1657
|
const viewOriginY = originY * scaleH;
|
|
1061
1658
|
const internalX = x2 - viewOriginX;
|
|
1062
1659
|
const internalY = y2 - viewOriginY;
|
|
1660
|
+
const { clipPath, clipPathStrokeColor, clipPathStrokeWidth, ...restDetail } = elem.detail;
|
|
1063
1661
|
const scaleNum = viewScaleInfo.scale * viewSizeInfo.devicePixelRatio;
|
|
1064
1662
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1663
|
+
let boxViewElem = { ...viewElem };
|
|
1664
|
+
boxViewElem.detail = restDetail;
|
|
1665
|
+
let boxOriginElem = { ...elem };
|
|
1666
|
+
boxOriginElem.detail = restDetail;
|
|
1667
|
+
if (detail.fill && detail.fill !== "string" && ((_b = (_a = detail.fill) == null ? void 0 : _a.type) == null ? void 0 : _b.includes("gradient"))) {
|
|
1668
|
+
boxViewElem = {
|
|
1669
|
+
...viewElem,
|
|
1670
|
+
...{
|
|
1671
|
+
detail: {
|
|
1672
|
+
...viewElem.detail,
|
|
1673
|
+
...{
|
|
1674
|
+
background: detail.fill,
|
|
1675
|
+
clipPath: {
|
|
1676
|
+
commands: detail.commands,
|
|
1677
|
+
originX,
|
|
1678
|
+
originY,
|
|
1679
|
+
originW,
|
|
1680
|
+
originH
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
boxOriginElem.detail = { ...boxViewElem.detail };
|
|
1687
|
+
}
|
|
1065
1688
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1066
|
-
drawBox(ctx,
|
|
1067
|
-
originElem:
|
|
1689
|
+
drawBox(ctx, boxViewElem, {
|
|
1690
|
+
originElem: boxOriginElem,
|
|
1068
1691
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1069
1692
|
viewScaleInfo,
|
|
1070
1693
|
viewSizeInfo,
|
|
1694
|
+
parentOpacity,
|
|
1071
1695
|
renderContent: () => {
|
|
1072
1696
|
drawBoxShadow(ctx, viewElem, {
|
|
1073
1697
|
viewScaleInfo,
|
|
1074
|
-
viewSizeInfo,
|
|
1075
1698
|
renderContent: () => {
|
|
1076
1699
|
ctx.save();
|
|
1077
1700
|
ctx.translate(internalX, internalY);
|
|
@@ -1079,8 +1702,14 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1079
1702
|
const pathStr = generateSVGPath(detail.commands || []);
|
|
1080
1703
|
const path2d = new Path2D(pathStr);
|
|
1081
1704
|
if (detail.fill) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1705
|
+
if (typeof detail.fill === "string") {
|
|
1706
|
+
ctx.fillStyle = detail.fill;
|
|
1707
|
+
} else {
|
|
1708
|
+
ctx.fillStyle = "transparent";
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
if (detail.fill) {
|
|
1712
|
+
ctx.fill(path2d, fillRule || "nonzero");
|
|
1084
1713
|
}
|
|
1085
1714
|
if (detail.stroke && detail.strokeWidth !== 0) {
|
|
1086
1715
|
ctx.strokeStyle = detail.stroke;
|
|
@@ -1096,11 +1725,21 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1096
1725
|
});
|
|
1097
1726
|
});
|
|
1098
1727
|
}
|
|
1728
|
+
const visiableMinSize = 0.4;
|
|
1099
1729
|
function drawElement(ctx, elem, opts) {
|
|
1100
|
-
var _a;
|
|
1730
|
+
var _a, _b, _c;
|
|
1101
1731
|
if (((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) === true) {
|
|
1102
1732
|
return;
|
|
1103
1733
|
}
|
|
1734
|
+
const { w: w2, h: h2 } = elem;
|
|
1735
|
+
const { scale } = opts.viewScaleInfo;
|
|
1736
|
+
if (scale < 1 && (w2 * scale < visiableMinSize || h2 * scale < visiableMinSize) || opts.parentOpacity === 0) {
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
const { overrideElementMap } = opts;
|
|
1740
|
+
if ((_c = (_b = overrideElementMap == null ? void 0 : overrideElementMap[elem.uuid]) == null ? void 0 : _b.operations) == null ? void 0 : _c.invisible) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1104
1743
|
try {
|
|
1105
1744
|
switch (elem.type) {
|
|
1106
1745
|
case "rect": {
|
|
@@ -1151,23 +1790,23 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1151
1790
|
}
|
|
1152
1791
|
}
|
|
1153
1792
|
function drawGroup(ctx, elem, opts) {
|
|
1154
|
-
const {
|
|
1155
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = (
|
|
1793
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1794
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h, angle: elem.angle }, { viewScaleInfo }) || elem;
|
|
1156
1795
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1157
1796
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1797
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
1158
1798
|
drawBoxShadow(ctx, viewElem, {
|
|
1159
1799
|
viewScaleInfo,
|
|
1160
|
-
viewSizeInfo,
|
|
1161
1800
|
renderContent: () => {
|
|
1162
1801
|
drawBox(ctx, viewElem, {
|
|
1163
1802
|
originElem: elem,
|
|
1164
1803
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1165
1804
|
viewScaleInfo,
|
|
1166
1805
|
viewSizeInfo,
|
|
1806
|
+
parentOpacity,
|
|
1167
1807
|
renderContent: () => {
|
|
1168
1808
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
1169
|
-
viewScaleInfo
|
|
1170
|
-
viewSizeInfo
|
|
1809
|
+
viewScaleInfo
|
|
1171
1810
|
});
|
|
1172
1811
|
if (elem.detail.overflow === "hidden") {
|
|
1173
1812
|
ctx.save();
|
|
@@ -1179,8 +1818,8 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1179
1818
|
ctx.arcTo(x22, y22 + h22, x22, y22, radiusList[3]);
|
|
1180
1819
|
ctx.arcTo(x22, y22, x22 + w22, y22, radiusList[0]);
|
|
1181
1820
|
ctx.closePath();
|
|
1182
|
-
ctx.fill();
|
|
1183
|
-
ctx.clip();
|
|
1821
|
+
ctx.fill("nonzero");
|
|
1822
|
+
ctx.clip("nonzero");
|
|
1184
1823
|
}
|
|
1185
1824
|
if (Array.isArray(elem.detail.children)) {
|
|
1186
1825
|
const { parentElementSize: parentSize } = opts;
|
|
@@ -1191,7 +1830,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1191
1830
|
h: elem.h || parentSize.h,
|
|
1192
1831
|
angle: elem.angle
|
|
1193
1832
|
};
|
|
1194
|
-
const { calculator
|
|
1833
|
+
const { calculator } = opts;
|
|
1195
1834
|
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
1196
1835
|
let child = elem.detail.children[i];
|
|
1197
1836
|
child = {
|
|
@@ -1202,31 +1841,32 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1202
1841
|
}
|
|
1203
1842
|
};
|
|
1204
1843
|
if (opts.forceDrawAll !== true) {
|
|
1205
|
-
if (!(
|
|
1844
|
+
if (!(calculator == null ? void 0 : calculator.needRender(child))) {
|
|
1206
1845
|
continue;
|
|
1207
1846
|
}
|
|
1208
1847
|
}
|
|
1209
1848
|
try {
|
|
1210
|
-
drawElement(ctx, child, { ...opts });
|
|
1849
|
+
drawElement(ctx, child, { ...opts, ...{ parentOpacity: parentOpacity * getOpacity(elem) } });
|
|
1211
1850
|
} catch (err) {
|
|
1212
1851
|
console.error(err);
|
|
1213
1852
|
}
|
|
1214
1853
|
}
|
|
1215
1854
|
}
|
|
1216
1855
|
if (elem.detail.overflow === "hidden") {
|
|
1217
|
-
ctx.globalAlpha = 1;
|
|
1218
1856
|
ctx.restore();
|
|
1219
1857
|
}
|
|
1220
1858
|
}
|
|
1221
1859
|
});
|
|
1222
1860
|
}
|
|
1223
1861
|
});
|
|
1862
|
+
ctx.globalAlpha = parentOpacity;
|
|
1224
1863
|
});
|
|
1225
1864
|
}
|
|
1226
1865
|
const defaultDetail = getDefaultElementDetailConfig();
|
|
1227
1866
|
function drawElementList(ctx, data, opts) {
|
|
1228
1867
|
var _a;
|
|
1229
1868
|
const { elements = [] } = data;
|
|
1869
|
+
const { parentOpacity } = opts;
|
|
1230
1870
|
for (let i = 0; i < elements.length; i++) {
|
|
1231
1871
|
const element = elements[i];
|
|
1232
1872
|
const elem = {
|
|
@@ -1239,17 +1879,71 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1239
1879
|
}
|
|
1240
1880
|
};
|
|
1241
1881
|
if (opts.forceDrawAll !== true) {
|
|
1242
|
-
if (!((_a = opts.calculator) == null ? void 0 : _a.
|
|
1882
|
+
if (!((_a = opts.calculator) == null ? void 0 : _a.needRender(elem))) {
|
|
1243
1883
|
continue;
|
|
1244
1884
|
}
|
|
1245
1885
|
}
|
|
1246
1886
|
try {
|
|
1247
|
-
drawElement(ctx, elem,
|
|
1887
|
+
drawElement(ctx, elem, {
|
|
1888
|
+
...opts,
|
|
1889
|
+
...{
|
|
1890
|
+
parentOpacity
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1248
1893
|
} catch (err) {
|
|
1249
1894
|
console.error(err);
|
|
1250
1895
|
}
|
|
1251
1896
|
}
|
|
1252
1897
|
}
|
|
1898
|
+
function drawLayout(ctx, layout, opts, renderContent) {
|
|
1899
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1900
|
+
const elem = { uuid: "layout", type: "group", ...layout };
|
|
1901
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
1902
|
+
const angle2 = 0;
|
|
1903
|
+
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1904
|
+
ctx.globalAlpha = 1;
|
|
1905
|
+
drawBoxShadow(ctx, viewElem, {
|
|
1906
|
+
viewScaleInfo,
|
|
1907
|
+
renderContent: () => {
|
|
1908
|
+
drawBoxBackground(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
if (layout.detail.overflow === "hidden") {
|
|
1912
|
+
const { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 } = opts;
|
|
1913
|
+
const elem2 = { uuid: "layout", type: "group", ...layout };
|
|
1914
|
+
const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2 }) || elem2;
|
|
1915
|
+
const viewElem2 = { ...elem2, ...viewElemSize };
|
|
1916
|
+
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem2, {
|
|
1917
|
+
viewScaleInfo: viewScaleInfo2
|
|
1918
|
+
});
|
|
1919
|
+
ctx.save();
|
|
1920
|
+
ctx.fillStyle = "transparent";
|
|
1921
|
+
ctx.beginPath();
|
|
1922
|
+
ctx.moveTo(x22 + radiusList[0], y22);
|
|
1923
|
+
ctx.arcTo(x22 + w22, y22, x22 + w22, y22 + h22, radiusList[1]);
|
|
1924
|
+
ctx.arcTo(x22 + w22, y22 + h22, x22, y22 + h22, radiusList[2]);
|
|
1925
|
+
ctx.arcTo(x22, y22 + h22, x22, y22, radiusList[3]);
|
|
1926
|
+
ctx.arcTo(x22, y22, x22 + w22, y22, radiusList[0]);
|
|
1927
|
+
ctx.closePath();
|
|
1928
|
+
ctx.fill("nonzero");
|
|
1929
|
+
ctx.clip("nonzero");
|
|
1930
|
+
}
|
|
1931
|
+
renderContent(ctx);
|
|
1932
|
+
if (layout.detail.overflow === "hidden") {
|
|
1933
|
+
ctx.restore();
|
|
1934
|
+
}
|
|
1935
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo });
|
|
1936
|
+
ctx.globalAlpha = parentOpacity;
|
|
1937
|
+
}
|
|
1938
|
+
function drawGlobalBackground(ctx, global, opts) {
|
|
1939
|
+
if (typeof (global == null ? void 0 : global.background) === "string") {
|
|
1940
|
+
const { viewSizeInfo } = opts;
|
|
1941
|
+
const { width, height } = viewSizeInfo;
|
|
1942
|
+
ctx.globalAlpha = 1;
|
|
1943
|
+
ctx.fillStyle = global.background;
|
|
1944
|
+
ctx.fillRect(0, 0, width, height);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1253
1947
|
const supportElementTypes = ["image", "svg", "html"];
|
|
1254
1948
|
const getAssetIdFromElement = (element) => {
|
|
1255
1949
|
var _a, _b, _c;
|
|
@@ -1272,17 +1966,12 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1272
1966
|
class Loader extends EventEmitter {
|
|
1273
1967
|
constructor() {
|
|
1274
1968
|
super();
|
|
1275
|
-
__privateAdd(this,
|
|
1276
|
-
__privateAdd(this, _getLoadElementSource);
|
|
1277
|
-
__privateAdd(this, _createLoadItem);
|
|
1278
|
-
__privateAdd(this, _emitLoad);
|
|
1279
|
-
__privateAdd(this, _emitError);
|
|
1280
|
-
__privateAdd(this, _loadResource);
|
|
1281
|
-
__privateAdd(this, _isExistingErrorStorage);
|
|
1969
|
+
__privateAdd(this, _Loader_instances);
|
|
1282
1970
|
__privateAdd(this, _loadFuncMap, {});
|
|
1283
1971
|
__privateAdd(this, _currentLoadItemMap, {});
|
|
1284
1972
|
__privateAdd(this, _storageLoadItemMap, {});
|
|
1285
|
-
|
|
1973
|
+
__privateAdd(this, _hasDestroyed, false);
|
|
1974
|
+
__privateMethod(this, _Loader_instances, registerLoadFunc_fn).call(this, "image", async (elem, assets) => {
|
|
1286
1975
|
var _a;
|
|
1287
1976
|
const src = ((_a = assets[elem.detail.src]) == null ? void 0 : _a.value) || elem.detail.src;
|
|
1288
1977
|
const content = await loadImage(src);
|
|
@@ -1292,12 +1981,12 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1292
1981
|
content
|
|
1293
1982
|
};
|
|
1294
1983
|
});
|
|
1295
|
-
__privateMethod(this,
|
|
1984
|
+
__privateMethod(this, _Loader_instances, registerLoadFunc_fn).call(this, "html", async (elem, assets) => {
|
|
1296
1985
|
var _a;
|
|
1297
1986
|
const html2 = ((_a = assets[elem.detail.html]) == null ? void 0 : _a.value) || elem.detail.html;
|
|
1298
1987
|
const content = await loadHTML(html2, {
|
|
1299
|
-
width: elem.detail.
|
|
1300
|
-
height: elem.detail.
|
|
1988
|
+
width: elem.detail.originW || elem.w,
|
|
1989
|
+
height: elem.detail.originH || elem.h
|
|
1301
1990
|
});
|
|
1302
1991
|
return {
|
|
1303
1992
|
uuid: elem.uuid,
|
|
@@ -1305,7 +1994,7 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1305
1994
|
content
|
|
1306
1995
|
};
|
|
1307
1996
|
});
|
|
1308
|
-
__privateMethod(this,
|
|
1997
|
+
__privateMethod(this, _Loader_instances, registerLoadFunc_fn).call(this, "svg", async (elem, assets) => {
|
|
1309
1998
|
var _a;
|
|
1310
1999
|
const svg2 = ((_a = assets[elem.detail.svg]) == null ? void 0 : _a.value) || elem.detail.svg;
|
|
1311
2000
|
const content = await loadSVG(svg2);
|
|
@@ -1316,12 +2005,25 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1316
2005
|
};
|
|
1317
2006
|
});
|
|
1318
2007
|
}
|
|
2008
|
+
isDestroyed() {
|
|
2009
|
+
return __privateGet(this, _hasDestroyed);
|
|
2010
|
+
}
|
|
2011
|
+
destroy() {
|
|
2012
|
+
__privateSet(this, _hasDestroyed, true);
|
|
2013
|
+
this.clear();
|
|
2014
|
+
__privateSet(this, _loadFuncMap, null);
|
|
2015
|
+
__privateSet(this, _currentLoadItemMap, null);
|
|
2016
|
+
__privateSet(this, _storageLoadItemMap, null);
|
|
2017
|
+
}
|
|
1319
2018
|
load(element, assets) {
|
|
1320
|
-
if (
|
|
2019
|
+
if (__privateGet(this, _hasDestroyed) === true) {
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
if (__privateMethod(this, _Loader_instances, isExistingErrorStorage_fn).call(this, element)) {
|
|
1321
2023
|
return;
|
|
1322
2024
|
}
|
|
1323
2025
|
if (supportElementTypes.includes(element.type)) {
|
|
1324
|
-
__privateMethod(this,
|
|
2026
|
+
__privateMethod(this, _Loader_instances, loadResource_fn).call(this, element, assets);
|
|
1325
2027
|
}
|
|
1326
2028
|
}
|
|
1327
2029
|
getContent(element) {
|
|
@@ -1339,11 +2041,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1339
2041
|
_loadFuncMap = new WeakMap();
|
|
1340
2042
|
_currentLoadItemMap = new WeakMap();
|
|
1341
2043
|
_storageLoadItemMap = new WeakMap();
|
|
1342
|
-
|
|
2044
|
+
_hasDestroyed = new WeakMap();
|
|
2045
|
+
_Loader_instances = new WeakSet();
|
|
1343
2046
|
registerLoadFunc_fn = function(type, func) {
|
|
1344
2047
|
__privateGet(this, _loadFuncMap)[type] = func;
|
|
1345
2048
|
};
|
|
1346
|
-
_getLoadElementSource = new WeakSet();
|
|
1347
2049
|
getLoadElementSource_fn = function(element) {
|
|
1348
2050
|
var _a, _b, _c;
|
|
1349
2051
|
let source = null;
|
|
@@ -1356,7 +2058,6 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1356
2058
|
}
|
|
1357
2059
|
return source;
|
|
1358
2060
|
};
|
|
1359
|
-
_createLoadItem = new WeakSet();
|
|
1360
2061
|
createLoadItem_fn = function(element) {
|
|
1361
2062
|
return {
|
|
1362
2063
|
element,
|
|
@@ -1365,88 +2066,535 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1365
2066
|
error: null,
|
|
1366
2067
|
startTime: -1,
|
|
1367
2068
|
endTime: -1,
|
|
1368
|
-
source: __privateMethod(this,
|
|
2069
|
+
source: __privateMethod(this, _Loader_instances, getLoadElementSource_fn).call(this, element)
|
|
1369
2070
|
};
|
|
1370
2071
|
};
|
|
1371
|
-
_emitLoad = new WeakSet();
|
|
1372
2072
|
emitLoad_fn = function(item) {
|
|
1373
2073
|
const assetId = getAssetIdFromElement(item.element);
|
|
1374
2074
|
const storageItem = __privateGet(this, _storageLoadItemMap)[assetId];
|
|
1375
|
-
if (
|
|
1376
|
-
if (storageItem
|
|
2075
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
2076
|
+
if (storageItem) {
|
|
2077
|
+
if (storageItem.startTime < item.startTime) {
|
|
2078
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
2079
|
+
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
2080
|
+
}
|
|
2081
|
+
} else {
|
|
1377
2082
|
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1378
2083
|
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1379
2084
|
}
|
|
1380
|
-
} else {
|
|
1381
|
-
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1382
|
-
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1383
2085
|
}
|
|
1384
2086
|
};
|
|
1385
|
-
_emitError = new WeakSet();
|
|
1386
2087
|
emitError_fn = function(item) {
|
|
2088
|
+
var _a;
|
|
1387
2089
|
const assetId = getAssetIdFromElement(item.element);
|
|
1388
|
-
const storageItem = __privateGet(this, _storageLoadItemMap)[assetId];
|
|
1389
|
-
if (
|
|
1390
|
-
if (storageItem
|
|
2090
|
+
const storageItem = (_a = __privateGet(this, _storageLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
2091
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
2092
|
+
if (storageItem) {
|
|
2093
|
+
if (storageItem.startTime < item.startTime) {
|
|
2094
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
2095
|
+
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
2096
|
+
}
|
|
2097
|
+
} else {
|
|
1391
2098
|
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1392
2099
|
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1393
2100
|
}
|
|
1394
|
-
} else {
|
|
1395
|
-
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1396
|
-
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1397
2101
|
}
|
|
1398
2102
|
};
|
|
1399
|
-
_loadResource = new WeakSet();
|
|
1400
2103
|
loadResource_fn = function(element, assets) {
|
|
1401
|
-
const item = __privateMethod(this,
|
|
2104
|
+
const item = __privateMethod(this, _Loader_instances, createLoadItem_fn).call(this, element);
|
|
1402
2105
|
const assetId = getAssetIdFromElement(element);
|
|
2106
|
+
if (__privateGet(this, _currentLoadItemMap)[assetId]) {
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
1403
2109
|
__privateGet(this, _currentLoadItemMap)[assetId] = item;
|
|
1404
2110
|
const loadFunc = __privateGet(this, _loadFuncMap)[element.type];
|
|
1405
|
-
if (typeof loadFunc === "function") {
|
|
2111
|
+
if (typeof loadFunc === "function" && !__privateGet(this, _hasDestroyed)) {
|
|
1406
2112
|
item.startTime = Date.now();
|
|
1407
2113
|
loadFunc(element, assets).then((result) => {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
2114
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
2115
|
+
item.content = result.content;
|
|
2116
|
+
item.endTime = Date.now();
|
|
2117
|
+
item.status = "load";
|
|
2118
|
+
__privateMethod(this, _Loader_instances, emitLoad_fn).call(this, item);
|
|
2119
|
+
}
|
|
1412
2120
|
}).catch((err) => {
|
|
1413
2121
|
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
1414
2122
|
item.endTime = Date.now();
|
|
1415
2123
|
item.status = "error";
|
|
1416
2124
|
item.error = err;
|
|
1417
|
-
__privateMethod(this,
|
|
2125
|
+
__privateMethod(this, _Loader_instances, emitError_fn).call(this, item);
|
|
1418
2126
|
});
|
|
1419
2127
|
}
|
|
1420
2128
|
};
|
|
1421
|
-
_isExistingErrorStorage = new WeakSet();
|
|
1422
2129
|
isExistingErrorStorage_fn = function(element) {
|
|
1423
2130
|
var _a;
|
|
1424
2131
|
const assetId = getAssetIdFromElement(element);
|
|
1425
2132
|
const existItem = (_a = __privateGet(this, _currentLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
1426
|
-
if (existItem && existItem.status === "error" && existItem.source && existItem.source === __privateMethod(this,
|
|
2133
|
+
if (existItem && existItem.status === "error" && existItem.source && existItem.source === __privateMethod(this, _Loader_instances, getLoadElementSource_fn).call(this, element)) {
|
|
1427
2134
|
return true;
|
|
1428
2135
|
}
|
|
1429
2136
|
return false;
|
|
1430
2137
|
};
|
|
2138
|
+
const detailConfig = getDefaultElementDetailConfig();
|
|
2139
|
+
function isTextWidthWithinErrorRange(w0, w1, scale) {
|
|
2140
|
+
return w0 >= w1;
|
|
2141
|
+
}
|
|
2142
|
+
function calcVirtualTextDetail(elem, opts) {
|
|
2143
|
+
const { w: w2, h: h2 } = elem;
|
|
2144
|
+
const x2 = 0;
|
|
2145
|
+
const y2 = 0;
|
|
2146
|
+
const ctx = opts.tempContext;
|
|
2147
|
+
const lines = [];
|
|
2148
|
+
const detail = {
|
|
2149
|
+
...detailConfig,
|
|
2150
|
+
...elem.detail
|
|
2151
|
+
};
|
|
2152
|
+
const originFontSize = detail.fontSize || detailConfig.fontSize;
|
|
2153
|
+
const fontSize2 = originFontSize;
|
|
2154
|
+
if (fontSize2 < 2) {
|
|
2155
|
+
return {};
|
|
2156
|
+
}
|
|
2157
|
+
const originLineHeight = detail.lineHeight || originFontSize;
|
|
2158
|
+
const lineHeight2 = originLineHeight;
|
|
2159
|
+
ctx.textBaseline = "top";
|
|
2160
|
+
ctx.$setFont({
|
|
2161
|
+
fontWeight: detail.fontWeight,
|
|
2162
|
+
fontSize: fontSize2,
|
|
2163
|
+
fontFamily: enhanceFontFamliy(detail.fontFamily)
|
|
2164
|
+
});
|
|
2165
|
+
let detailText = detail.text.replace(/\r\n/gi, "\n");
|
|
2166
|
+
if (detail.textTransform === "lowercase") {
|
|
2167
|
+
detailText = detailText.toLowerCase();
|
|
2168
|
+
} else if (detail.textTransform === "uppercase") {
|
|
2169
|
+
detailText = detailText.toUpperCase();
|
|
2170
|
+
}
|
|
2171
|
+
const fontHeight = lineHeight2;
|
|
2172
|
+
const detailTextList = detailText.split("\n");
|
|
2173
|
+
let lineNum = 0;
|
|
2174
|
+
detailTextList.forEach((itemText, idx) => {
|
|
2175
|
+
if (detail.minInlineSize === "maxContent") {
|
|
2176
|
+
lines.push({
|
|
2177
|
+
x: x2,
|
|
2178
|
+
y: 0,
|
|
2179
|
+
// TODO
|
|
2180
|
+
text: itemText,
|
|
2181
|
+
width: ctx.$undoPixelRatio(ctx.measureText(itemText).width)
|
|
2182
|
+
});
|
|
2183
|
+
} else {
|
|
2184
|
+
let lineText = "";
|
|
2185
|
+
let splitStr = "";
|
|
2186
|
+
let tempStrList = itemText.split(splitStr);
|
|
2187
|
+
if (detail.wordBreak === "normal") {
|
|
2188
|
+
splitStr = " ";
|
|
2189
|
+
const wordList = itemText.split(splitStr);
|
|
2190
|
+
tempStrList = [];
|
|
2191
|
+
wordList.forEach((word, idx2) => {
|
|
2192
|
+
tempStrList.push(word);
|
|
2193
|
+
if (idx2 < wordList.length - 1) {
|
|
2194
|
+
tempStrList.push(splitStr);
|
|
2195
|
+
}
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
if (tempStrList.length === 1 && detail.overflow === "visible") {
|
|
2199
|
+
lines.push({
|
|
2200
|
+
x: x2,
|
|
2201
|
+
y: 0,
|
|
2202
|
+
// TODO
|
|
2203
|
+
text: tempStrList[0],
|
|
2204
|
+
width: ctx.$undoPixelRatio(ctx.measureText(tempStrList[0]).width)
|
|
2205
|
+
});
|
|
2206
|
+
} else if (tempStrList.length > 0) {
|
|
2207
|
+
for (let i = 0; i < tempStrList.length; i++) {
|
|
2208
|
+
if (isTextWidthWithinErrorRange(ctx.$doPixelRatio(w2), ctx.measureText(lineText + tempStrList[i]).width)) {
|
|
2209
|
+
lineText += tempStrList[i] || "";
|
|
2210
|
+
} else {
|
|
2211
|
+
lines.push({
|
|
2212
|
+
x: x2,
|
|
2213
|
+
y: 0,
|
|
2214
|
+
// TODO
|
|
2215
|
+
text: lineText,
|
|
2216
|
+
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
2217
|
+
});
|
|
2218
|
+
lineText = tempStrList[i] || "";
|
|
2219
|
+
lineNum++;
|
|
2220
|
+
}
|
|
2221
|
+
if ((lineNum + 1) * fontHeight > h2 && detail.overflow === "hidden") {
|
|
2222
|
+
break;
|
|
2223
|
+
}
|
|
2224
|
+
if (tempStrList.length - 1 === i) {
|
|
2225
|
+
if ((lineNum + 1) * fontHeight <= h2) {
|
|
2226
|
+
lines.push({
|
|
2227
|
+
x: x2,
|
|
2228
|
+
y: 0,
|
|
2229
|
+
// TODO
|
|
2230
|
+
text: lineText,
|
|
2231
|
+
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
2232
|
+
});
|
|
2233
|
+
if (idx < detailTextList.length - 1) {
|
|
2234
|
+
lineNum++;
|
|
2235
|
+
}
|
|
2236
|
+
break;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
} else {
|
|
2241
|
+
lines.push({
|
|
2242
|
+
x: x2,
|
|
2243
|
+
y: 0,
|
|
2244
|
+
// TODO
|
|
2245
|
+
text: "",
|
|
2246
|
+
width: 0
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
});
|
|
2251
|
+
let startY = 0;
|
|
2252
|
+
let eachLineStartY = 0;
|
|
2253
|
+
if (fontHeight > fontSize2) {
|
|
2254
|
+
eachLineStartY = (fontHeight - fontSize2) / 2;
|
|
2255
|
+
}
|
|
2256
|
+
if (lines.length * fontHeight < h2) {
|
|
2257
|
+
if (detail.verticalAlign === "top") {
|
|
2258
|
+
startY = 0;
|
|
2259
|
+
} else if (detail.verticalAlign === "bottom") {
|
|
2260
|
+
startY += h2 - lines.length * fontHeight;
|
|
2261
|
+
} else {
|
|
2262
|
+
startY += (h2 - lines.length * fontHeight) / 2;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
{
|
|
2266
|
+
const _y = y2 + startY;
|
|
2267
|
+
lines.forEach((line, i) => {
|
|
2268
|
+
let _x = x2;
|
|
2269
|
+
if (detail.textAlign === "center") {
|
|
2270
|
+
_x = x2 + (w2 - line.width) / 2;
|
|
2271
|
+
} else if (detail.textAlign === "right") {
|
|
2272
|
+
_x = x2 + (w2 - line.width);
|
|
2273
|
+
}
|
|
2274
|
+
lines[i].x = _x;
|
|
2275
|
+
lines[i].y = _y + fontHeight * i + eachLineStartY;
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
const virtualTextDetail = {
|
|
2279
|
+
textLines: lines
|
|
2280
|
+
};
|
|
2281
|
+
return virtualTextDetail;
|
|
2282
|
+
}
|
|
2283
|
+
function calcVirtualFlatDetail(elem, opts) {
|
|
2284
|
+
let virtualDetail = {};
|
|
2285
|
+
if (elem.type === "text") {
|
|
2286
|
+
virtualDetail = calcVirtualTextDetail(elem, opts);
|
|
2287
|
+
}
|
|
2288
|
+
return virtualDetail;
|
|
2289
|
+
}
|
|
2290
|
+
function elementsToVirtualFlatMap(elements, opts) {
|
|
2291
|
+
const virtualFlatMap = {};
|
|
2292
|
+
const currentPosition = [];
|
|
2293
|
+
const _walk = (elem) => {
|
|
2294
|
+
const baseInfo = {
|
|
2295
|
+
type: elem.type,
|
|
2296
|
+
isVisibleInView: true,
|
|
2297
|
+
position: [...currentPosition]
|
|
2298
|
+
};
|
|
2299
|
+
let originRectInfo = null;
|
|
2300
|
+
const groupQueue = getGroupQueueByElementPosition(elements, currentPosition);
|
|
2301
|
+
originRectInfo = calcElementOriginRectInfo(elem, {
|
|
2302
|
+
groupQueue: groupQueue || []
|
|
2303
|
+
});
|
|
2304
|
+
const virtualItem = {
|
|
2305
|
+
...baseInfo,
|
|
2306
|
+
...{
|
|
2307
|
+
originRectInfo,
|
|
2308
|
+
rangeRectInfo: is.angle(elem.angle) ? originRectInfoToRangeRectInfo(originRectInfo) : originRectInfo
|
|
2309
|
+
},
|
|
2310
|
+
...calcVirtualFlatDetail(elem, opts)
|
|
2311
|
+
};
|
|
2312
|
+
virtualFlatMap[elem.uuid] = virtualItem;
|
|
2313
|
+
if (elem.type === "group") {
|
|
2314
|
+
elem.detail.children.forEach((ele, i) => {
|
|
2315
|
+
currentPosition.push(i);
|
|
2316
|
+
_walk(ele);
|
|
2317
|
+
currentPosition.pop();
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
elements.forEach((elem, index) => {
|
|
2322
|
+
currentPosition.push(index);
|
|
2323
|
+
_walk(elem);
|
|
2324
|
+
currentPosition.pop();
|
|
2325
|
+
});
|
|
2326
|
+
return virtualFlatMap;
|
|
2327
|
+
}
|
|
2328
|
+
function sortElementsViewVisiableInfoMap(elements, opts) {
|
|
2329
|
+
const { viewScaleInfo, viewSizeInfo, tempContext } = opts;
|
|
2330
|
+
const visibleInfoMap = elementsToVirtualFlatMap(elements, { tempContext });
|
|
2331
|
+
return updateVirtualFlatItemMapStatus(visibleInfoMap, { viewScaleInfo, viewSizeInfo });
|
|
2332
|
+
}
|
|
2333
|
+
function isRangeRectInfoCollide(info1, info2) {
|
|
2334
|
+
const rect1MinX = Math.min(info1.topLeft.x, info1.topRight.x, info1.bottomLeft.x, info1.bottomRight.x);
|
|
2335
|
+
const rect1MaxX = Math.max(info1.topLeft.x, info1.topRight.x, info1.bottomLeft.x, info1.bottomRight.x);
|
|
2336
|
+
const rect1MinY = Math.min(info1.topLeft.y, info1.topRight.y, info1.bottomLeft.y, info1.bottomRight.y);
|
|
2337
|
+
const rect1MaxY = Math.max(info1.topLeft.y, info1.topRight.y, info1.bottomLeft.y, info1.bottomRight.y);
|
|
2338
|
+
const rect2MinX = Math.min(info2.topLeft.x, info2.topRight.x, info2.bottomLeft.x, info2.bottomRight.x);
|
|
2339
|
+
const rect2MaxX = Math.max(info2.topLeft.x, info2.topRight.x, info2.bottomLeft.x, info2.bottomRight.x);
|
|
2340
|
+
const rect2MinY = Math.min(info2.topLeft.y, info2.topRight.y, info2.bottomLeft.y, info2.bottomRight.y);
|
|
2341
|
+
const rect2MaxY = Math.max(info2.topLeft.y, info2.topRight.y, info2.bottomLeft.y, info2.bottomRight.y);
|
|
2342
|
+
if (rect1MinX <= rect2MaxX && rect1MaxX >= rect2MinX && rect1MinY <= rect2MaxY && rect1MaxY >= rect2MinY || rect2MaxX <= rect1MaxY && rect2MaxX >= rect1MaxY && rect2MaxX <= rect1MaxY && rect2MaxX >= rect1MaxY) {
|
|
2343
|
+
return true;
|
|
2344
|
+
}
|
|
2345
|
+
return false;
|
|
2346
|
+
}
|
|
2347
|
+
function updateVirtualFlatItemMapStatus(virtualFlatItemMap, opts) {
|
|
2348
|
+
const canvasRectInfo = calcVisibleOriginCanvasRectInfo(opts);
|
|
2349
|
+
let visibleCount = 0;
|
|
2350
|
+
let invisibleCount = 0;
|
|
2351
|
+
Object.keys(virtualFlatItemMap).forEach((uuid) => {
|
|
2352
|
+
const info = virtualFlatItemMap[uuid];
|
|
2353
|
+
info.isVisibleInView = isRangeRectInfoCollide(info.rangeRectInfo, canvasRectInfo);
|
|
2354
|
+
info.isVisibleInView ? visibleCount++ : invisibleCount++;
|
|
2355
|
+
});
|
|
2356
|
+
return { virtualFlatItemMap, visibleCount, invisibleCount };
|
|
2357
|
+
}
|
|
2358
|
+
function calcVisibleOriginCanvasRectInfo(opts) {
|
|
2359
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
2360
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
2361
|
+
const { width, height } = viewSizeInfo;
|
|
2362
|
+
const x2 = 0 - offsetLeft / scale;
|
|
2363
|
+
const y2 = 0 - offsetTop / scale;
|
|
2364
|
+
const w2 = width / scale;
|
|
2365
|
+
const h2 = height / scale;
|
|
2366
|
+
const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
|
|
2367
|
+
const topLeft = { x: x2, y: y2 };
|
|
2368
|
+
const topRight = { x: x2 + w2, y: y2 };
|
|
2369
|
+
const bottomLeft = { x: x2, y: y2 + h2 };
|
|
2370
|
+
const bottomRight = { x: x2 + w2, y: y2 + h2 };
|
|
2371
|
+
const left = { x: x2, y: center.y };
|
|
2372
|
+
const top = { x: center.x, y: y2 };
|
|
2373
|
+
const right = { x: x2 + w2, y: center.y };
|
|
2374
|
+
const bottom = { x: center.x, y: y2 + h2 };
|
|
2375
|
+
const rectInfo = {
|
|
2376
|
+
center,
|
|
2377
|
+
topLeft,
|
|
2378
|
+
topRight,
|
|
2379
|
+
bottomLeft,
|
|
2380
|
+
bottomRight,
|
|
2381
|
+
left,
|
|
2382
|
+
top,
|
|
2383
|
+
right,
|
|
2384
|
+
bottom
|
|
2385
|
+
};
|
|
2386
|
+
return rectInfo;
|
|
2387
|
+
}
|
|
2388
|
+
class Calculator {
|
|
2389
|
+
constructor(opts) {
|
|
2390
|
+
__privateAdd(this, _opts);
|
|
2391
|
+
__privateAdd(this, _store);
|
|
2392
|
+
__privateSet(this, _opts, opts);
|
|
2393
|
+
__privateSet(this, _store, new Store({
|
|
2394
|
+
defaultStorage: {
|
|
2395
|
+
virtualFlatItemMap: {},
|
|
2396
|
+
visibleCount: 0,
|
|
2397
|
+
invisibleCount: 0
|
|
2398
|
+
}
|
|
2399
|
+
}));
|
|
2400
|
+
}
|
|
2401
|
+
toGridNum(num, opts) {
|
|
2402
|
+
if ((opts == null ? void 0 : opts.ignore) === true) {
|
|
2403
|
+
return num;
|
|
2404
|
+
}
|
|
2405
|
+
return Math.round(num);
|
|
2406
|
+
}
|
|
2407
|
+
destroy() {
|
|
2408
|
+
__privateSet(this, _opts, null);
|
|
2409
|
+
}
|
|
2410
|
+
needRender(elem) {
|
|
2411
|
+
const virtualFlatItemMap = __privateGet(this, _store).get("virtualFlatItemMap");
|
|
2412
|
+
const info = virtualFlatItemMap[elem.uuid];
|
|
2413
|
+
if (!info) {
|
|
2414
|
+
return true;
|
|
2415
|
+
}
|
|
2416
|
+
return info.isVisibleInView;
|
|
2417
|
+
}
|
|
2418
|
+
getPointElement(p, opts) {
|
|
2419
|
+
const context2d = __privateGet(this, _opts).tempContext;
|
|
2420
|
+
return getViewPointAtElement(p, { ...opts, ...{ context2d } });
|
|
2421
|
+
}
|
|
2422
|
+
resetVirtualFlatItemMap(data, opts) {
|
|
2423
|
+
if (data) {
|
|
2424
|
+
const { virtualFlatItemMap, invisibleCount, visibleCount } = sortElementsViewVisiableInfoMap(data.elements, {
|
|
2425
|
+
...opts,
|
|
2426
|
+
...{
|
|
2427
|
+
tempContext: __privateGet(this, _opts).tempContext
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
__privateGet(this, _store).set("virtualFlatItemMap", virtualFlatItemMap);
|
|
2431
|
+
__privateGet(this, _store).set("invisibleCount", invisibleCount);
|
|
2432
|
+
__privateGet(this, _store).set("visibleCount", visibleCount);
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
updateVisiableStatus(opts) {
|
|
2436
|
+
const { virtualFlatItemMap, invisibleCount, visibleCount } = updateVirtualFlatItemMapStatus(
|
|
2437
|
+
__privateGet(this, _store).get("virtualFlatItemMap"),
|
|
2438
|
+
opts
|
|
2439
|
+
);
|
|
2440
|
+
__privateGet(this, _store).set("virtualFlatItemMap", virtualFlatItemMap);
|
|
2441
|
+
__privateGet(this, _store).set("invisibleCount", invisibleCount);
|
|
2442
|
+
__privateGet(this, _store).set("visibleCount", visibleCount);
|
|
2443
|
+
}
|
|
2444
|
+
calcViewRectInfoFromOrigin(uuid, opts) {
|
|
2445
|
+
const infoData = __privateGet(this, _store).get("virtualFlatItemMap")[uuid];
|
|
2446
|
+
if (!(infoData == null ? void 0 : infoData.originRectInfo)) {
|
|
2447
|
+
return null;
|
|
2448
|
+
}
|
|
2449
|
+
const { checkVisible, viewScaleInfo, viewSizeInfo } = opts;
|
|
2450
|
+
const { center, left, right, bottom, top, topLeft, topRight, bottomLeft, bottomRight } = infoData.originRectInfo;
|
|
2451
|
+
if (checkVisible === true && infoData.isVisibleInView === false) {
|
|
2452
|
+
return null;
|
|
2453
|
+
}
|
|
2454
|
+
const calcOpts = { viewScaleInfo };
|
|
2455
|
+
const viewRectInfo = {
|
|
2456
|
+
center: calcViewPointSize(center, calcOpts),
|
|
2457
|
+
left: calcViewPointSize(left, calcOpts),
|
|
2458
|
+
right: calcViewPointSize(right, calcOpts),
|
|
2459
|
+
bottom: calcViewPointSize(bottom, calcOpts),
|
|
2460
|
+
top: calcViewPointSize(top, calcOpts),
|
|
2461
|
+
topLeft: calcViewPointSize(topLeft, calcOpts),
|
|
2462
|
+
topRight: calcViewPointSize(topRight, calcOpts),
|
|
2463
|
+
bottomLeft: calcViewPointSize(bottomLeft, calcOpts),
|
|
2464
|
+
bottomRight: calcViewPointSize(bottomRight, calcOpts)
|
|
2465
|
+
};
|
|
2466
|
+
return viewRectInfo;
|
|
2467
|
+
}
|
|
2468
|
+
calcViewRectInfoFromRange(uuid, opts) {
|
|
2469
|
+
const infoData = __privateGet(this, _store).get("virtualFlatItemMap")[uuid];
|
|
2470
|
+
if (!(infoData == null ? void 0 : infoData.originRectInfo)) {
|
|
2471
|
+
return null;
|
|
2472
|
+
}
|
|
2473
|
+
const { checkVisible, viewScaleInfo, viewSizeInfo } = opts;
|
|
2474
|
+
const { center, left, right, bottom, top, topLeft, topRight, bottomLeft, bottomRight } = infoData.rangeRectInfo;
|
|
2475
|
+
if (checkVisible === true && infoData.isVisibleInView === false) {
|
|
2476
|
+
return null;
|
|
2477
|
+
}
|
|
2478
|
+
const calcOpts = { viewScaleInfo };
|
|
2479
|
+
const viewRectInfo = {
|
|
2480
|
+
center: calcViewPointSize(center, calcOpts),
|
|
2481
|
+
left: calcViewPointSize(left, calcOpts),
|
|
2482
|
+
right: calcViewPointSize(right, calcOpts),
|
|
2483
|
+
bottom: calcViewPointSize(bottom, calcOpts),
|
|
2484
|
+
top: calcViewPointSize(top, calcOpts),
|
|
2485
|
+
topLeft: calcViewPointSize(topLeft, calcOpts),
|
|
2486
|
+
topRight: calcViewPointSize(topRight, calcOpts),
|
|
2487
|
+
bottomLeft: calcViewPointSize(bottomLeft, calcOpts),
|
|
2488
|
+
bottomRight: calcViewPointSize(bottomRight, calcOpts)
|
|
2489
|
+
};
|
|
2490
|
+
return viewRectInfo;
|
|
2491
|
+
}
|
|
2492
|
+
modifyText(element) {
|
|
2493
|
+
const virtualFlatItemMap = __privateGet(this, _store).get("virtualFlatItemMap");
|
|
2494
|
+
const flatItem = virtualFlatItemMap[element.uuid];
|
|
2495
|
+
if (element && element.type === "text") {
|
|
2496
|
+
const newVirtualFlatItem = {
|
|
2497
|
+
...flatItem,
|
|
2498
|
+
...calcVirtualTextDetail(element, {
|
|
2499
|
+
tempContext: __privateGet(this, _opts).tempContext
|
|
2500
|
+
})
|
|
2501
|
+
};
|
|
2502
|
+
virtualFlatItemMap[element.uuid] = newVirtualFlatItem;
|
|
2503
|
+
__privateGet(this, _store).set("virtualFlatItemMap", virtualFlatItemMap);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
modifyVirtualFlatItemMap(data, opts) {
|
|
2507
|
+
const { modifyInfo, viewScaleInfo, viewSizeInfo } = opts;
|
|
2508
|
+
const { type, content } = modifyInfo;
|
|
2509
|
+
const list = data.elements;
|
|
2510
|
+
const virtualFlatItemMap = __privateGet(this, _store).get("virtualFlatItemMap");
|
|
2511
|
+
if (type === "deleteElement") {
|
|
2512
|
+
const { element } = content;
|
|
2513
|
+
const uuids = [];
|
|
2514
|
+
const _walk = (e) => {
|
|
2515
|
+
uuids.push(e.uuid);
|
|
2516
|
+
if (e.type === "group" && Array.isArray(e.detail.children)) {
|
|
2517
|
+
e.detail.children.forEach((child) => {
|
|
2518
|
+
_walk(child);
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
_walk(element);
|
|
2523
|
+
uuids.forEach((uuid) => {
|
|
2524
|
+
delete virtualFlatItemMap[uuid];
|
|
2525
|
+
});
|
|
2526
|
+
__privateGet(this, _store).set("virtualFlatItemMap", virtualFlatItemMap);
|
|
2527
|
+
} else if (type === "addElement" || type === "updateElement") {
|
|
2528
|
+
const { position } = content;
|
|
2529
|
+
const element = findElementFromListByPosition(position, data.elements);
|
|
2530
|
+
const groupQueue = getGroupQueueByElementPosition(list, position);
|
|
2531
|
+
if (element) {
|
|
2532
|
+
if (type === "updateElement" && element.type === "group") {
|
|
2533
|
+
this.resetVirtualFlatItemMap(data, { viewScaleInfo, viewSizeInfo });
|
|
2534
|
+
} else {
|
|
2535
|
+
const originRectInfo = calcElementOriginRectInfo(element, {
|
|
2536
|
+
groupQueue: groupQueue || []
|
|
2537
|
+
});
|
|
2538
|
+
const newVirtualFlatItem = {
|
|
2539
|
+
type: element.type,
|
|
2540
|
+
originRectInfo,
|
|
2541
|
+
rangeRectInfo: is.angle(element.angle) ? originRectInfoToRangeRectInfo(originRectInfo) : originRectInfo,
|
|
2542
|
+
isVisibleInView: true,
|
|
2543
|
+
position: [...position],
|
|
2544
|
+
...calcVirtualFlatDetail(element, {
|
|
2545
|
+
tempContext: __privateGet(this, _opts).tempContext
|
|
2546
|
+
})
|
|
2547
|
+
};
|
|
2548
|
+
virtualFlatItemMap[element.uuid] = newVirtualFlatItem;
|
|
2549
|
+
__privateGet(this, _store).set("virtualFlatItemMap", virtualFlatItemMap);
|
|
2550
|
+
if (type === "updateElement") {
|
|
2551
|
+
this.updateVisiableStatus({ viewScaleInfo, viewSizeInfo });
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
} else if (type === "moveElement") {
|
|
2556
|
+
this.resetVirtualFlatItemMap(data, { viewScaleInfo, viewSizeInfo });
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
getVirtualFlatItem(uuid) {
|
|
2560
|
+
const itemMap = __privateGet(this, _store).get("virtualFlatItemMap");
|
|
2561
|
+
return itemMap[uuid] || null;
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
_opts = new WeakMap();
|
|
2565
|
+
_store = new WeakMap();
|
|
1431
2566
|
class Renderer extends EventEmitter {
|
|
1432
|
-
// private _draftContextTop: CanvasRenderingContext2D;
|
|
1433
|
-
// private _draftContextMiddle: CanvasRenderingContext2D;
|
|
1434
|
-
// private _draftContextBottom: CanvasRenderingContext2D;
|
|
1435
2567
|
constructor(opts) {
|
|
1436
2568
|
super();
|
|
1437
|
-
__privateAdd(this,
|
|
1438
|
-
__privateAdd(this,
|
|
2569
|
+
__privateAdd(this, _Renderer_instances);
|
|
2570
|
+
__privateAdd(this, _opts2);
|
|
1439
2571
|
__privateAdd(this, _loader, new Loader());
|
|
1440
|
-
|
|
1441
|
-
|
|
2572
|
+
__privateAdd(this, _calculator);
|
|
2573
|
+
__privateAdd(this, _hasDestroyed2, false);
|
|
2574
|
+
__privateSet(this, _opts2, opts);
|
|
2575
|
+
__privateSet(this, _calculator, new Calculator({
|
|
2576
|
+
tempContext: opts.tempContext
|
|
2577
|
+
}));
|
|
2578
|
+
__privateMethod(this, _Renderer_instances, init_fn).call(this);
|
|
2579
|
+
}
|
|
2580
|
+
isDestroyed() {
|
|
2581
|
+
return __privateGet(this, _hasDestroyed2);
|
|
2582
|
+
}
|
|
2583
|
+
destroy() {
|
|
2584
|
+
this.clear();
|
|
2585
|
+
__privateSet(this, _opts2, null);
|
|
2586
|
+
__privateGet(this, _loader).destroy();
|
|
2587
|
+
__privateSet(this, _loader, null);
|
|
2588
|
+
__privateSet(this, _hasDestroyed2, true);
|
|
1442
2589
|
}
|
|
1443
2590
|
updateOptions(opts) {
|
|
1444
|
-
__privateSet(this,
|
|
2591
|
+
__privateSet(this, _opts2, opts);
|
|
1445
2592
|
}
|
|
1446
2593
|
drawData(data, opts) {
|
|
1447
2594
|
const loader = __privateGet(this, _loader);
|
|
1448
|
-
const
|
|
1449
|
-
const
|
|
2595
|
+
const calculator = __privateGet(this, _calculator);
|
|
2596
|
+
const { sharer } = __privateGet(this, _opts2);
|
|
2597
|
+
const viewContext = __privateGet(this, _opts2).viewContext;
|
|
1450
2598
|
viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
|
|
1451
2599
|
const parentElementSize = {
|
|
1452
2600
|
x: 0,
|
|
@@ -1454,20 +2602,47 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1454
2602
|
w: opts.viewSizeInfo.width,
|
|
1455
2603
|
h: opts.viewSizeInfo.height
|
|
1456
2604
|
};
|
|
1457
|
-
|
|
2605
|
+
if (opts.forceDrawAll === true) {
|
|
2606
|
+
__privateGet(this, _calculator).resetVirtualFlatItemMap(data, {
|
|
2607
|
+
viewScaleInfo: opts.viewScaleInfo,
|
|
2608
|
+
viewSizeInfo: opts.viewSizeInfo
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
const drawOpts = {
|
|
1458
2612
|
loader,
|
|
1459
2613
|
calculator,
|
|
1460
2614
|
parentElementSize,
|
|
1461
2615
|
elementAssets: data.assets,
|
|
2616
|
+
parentOpacity: 1,
|
|
2617
|
+
overrideElementMap: sharer == null ? void 0 : sharer.getActiveOverrideElemenentMap(),
|
|
1462
2618
|
...opts
|
|
1463
|
-
}
|
|
2619
|
+
};
|
|
2620
|
+
drawGlobalBackground(viewContext, data.global, drawOpts);
|
|
2621
|
+
if (data.layout) {
|
|
2622
|
+
drawLayout(viewContext, data.layout, drawOpts, () => {
|
|
2623
|
+
drawElementList(viewContext, data, drawOpts);
|
|
2624
|
+
});
|
|
2625
|
+
} else {
|
|
2626
|
+
drawElementList(viewContext, data, drawOpts);
|
|
2627
|
+
}
|
|
1464
2628
|
}
|
|
1465
2629
|
scale(num) {
|
|
1466
|
-
const { sharer } = __privateGet(this,
|
|
2630
|
+
const { sharer } = __privateGet(this, _opts2);
|
|
1467
2631
|
if (!sharer) {
|
|
1468
2632
|
return;
|
|
1469
2633
|
}
|
|
1470
|
-
const {
|
|
2634
|
+
const {
|
|
2635
|
+
data,
|
|
2636
|
+
offsetTop,
|
|
2637
|
+
offsetBottom,
|
|
2638
|
+
offsetLeft,
|
|
2639
|
+
offsetRight,
|
|
2640
|
+
width,
|
|
2641
|
+
height,
|
|
2642
|
+
contextHeight,
|
|
2643
|
+
contextWidth,
|
|
2644
|
+
devicePixelRatio
|
|
2645
|
+
} = sharer.getActiveStoreSnapshot();
|
|
1471
2646
|
if (data) {
|
|
1472
2647
|
this.drawData(data, {
|
|
1473
2648
|
viewScaleInfo: {
|
|
@@ -1493,19 +2668,40 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1493
2668
|
getLoadItemMap() {
|
|
1494
2669
|
return __privateGet(this, _loader).getLoadItemMap();
|
|
1495
2670
|
}
|
|
2671
|
+
getLoader() {
|
|
2672
|
+
return __privateGet(this, _loader);
|
|
2673
|
+
}
|
|
2674
|
+
getCalculator() {
|
|
2675
|
+
return __privateGet(this, _calculator);
|
|
2676
|
+
}
|
|
1496
2677
|
}
|
|
1497
|
-
|
|
2678
|
+
_opts2 = new WeakMap();
|
|
1498
2679
|
_loader = new WeakMap();
|
|
1499
|
-
|
|
2680
|
+
_calculator = new WeakMap();
|
|
2681
|
+
_hasDestroyed2 = new WeakMap();
|
|
2682
|
+
_Renderer_instances = new WeakSet();
|
|
1500
2683
|
init_fn = function() {
|
|
1501
2684
|
const loader = __privateGet(this, _loader);
|
|
1502
2685
|
loader.on("load", (e) => {
|
|
1503
2686
|
this.trigger("load", e);
|
|
1504
2687
|
});
|
|
1505
|
-
loader.on("error", () => {
|
|
2688
|
+
loader.on("error", (e) => {
|
|
2689
|
+
console.error(e);
|
|
1506
2690
|
});
|
|
1507
2691
|
};
|
|
2692
|
+
exports.Calculator = Calculator;
|
|
1508
2693
|
exports.Renderer = Renderer;
|
|
2694
|
+
exports.drawCircle = drawCircle;
|
|
2695
|
+
exports.drawElement = drawElement;
|
|
2696
|
+
exports.drawElementList = drawElementList;
|
|
2697
|
+
exports.drawGlobalBackground = drawGlobalBackground;
|
|
2698
|
+
exports.drawGroup = drawGroup;
|
|
2699
|
+
exports.drawHTML = drawHTML;
|
|
2700
|
+
exports.drawImage = drawImage;
|
|
2701
|
+
exports.drawLayout = drawLayout;
|
|
2702
|
+
exports.drawRect = drawRect;
|
|
2703
|
+
exports.drawSVG = drawSVG;
|
|
2704
|
+
exports.drawText = drawText;
|
|
1509
2705
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1510
2706
|
return exports;
|
|
1511
2707
|
}({});
|