@idraw/renderer 0.4.0-beta.9 → 0.4.0

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