@idraw/renderer 0.4.0-beta.2 → 0.4.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/esm/draw/box.d.ts +15 -4
- package/dist/esm/draw/box.js +25 -27
- package/dist/esm/draw/circle.js +50 -31
- package/dist/esm/draw/elements.js +9 -3
- package/dist/esm/draw/group.js +17 -8
- package/dist/esm/draw/html.js +7 -7
- package/dist/esm/draw/image.js +8 -8
- package/dist/esm/draw/index.d.ts +1 -0
- package/dist/esm/draw/index.js +1 -0
- package/dist/esm/draw/layout.d.ts +2 -0
- package/dist/esm/draw/layout.js +44 -0
- package/dist/esm/draw/path.js +4 -3
- package/dist/esm/draw/rect.js +4 -3
- package/dist/esm/draw/svg.js +7 -7
- package/dist/esm/draw/text.js +10 -7
- package/dist/esm/index.d.ts +9 -3
- package/dist/esm/index.js +66 -19
- package/dist/esm/loader.d.ts +6 -11
- package/dist/esm/loader.js +120 -83
- package/dist/index.global.js +450 -203
- package/dist/index.global.min.js +1 -1
- package/package.json +3 -3
package/dist/index.global.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
var iDrawRenderer = function(exports) {
|
|
2
|
-
"use strict";
|
|
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;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var _loadFuncMap, _currentLoadItemMap, _storageLoadItemMap, _hasDestroyed, _registerLoadFunc, registerLoadFunc_fn, _getLoadElementSource, getLoadElementSource_fn, _createLoadItem, createLoadItem_fn, _emitLoad, emitLoad_fn, _emitError, emitError_fn, _loadResource, loadResource_fn, _isExistingErrorStorage, isExistingErrorStorage_fn, _opts, _loader, _hasDestroyed2, _init, init_fn;
|
|
3
26
|
function isColorStr(color2) {
|
|
4
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));
|
|
5
28
|
}
|
|
@@ -77,6 +100,9 @@ var iDrawRenderer = function(exports) {
|
|
|
77
100
|
asyncFunction(data) {
|
|
78
101
|
return parsePrototype(data) === "AsyncFunction";
|
|
79
102
|
},
|
|
103
|
+
boolean(data) {
|
|
104
|
+
return parsePrototype(data) === "Boolean";
|
|
105
|
+
},
|
|
80
106
|
string(data) {
|
|
81
107
|
return parsePrototype(data) === "String";
|
|
82
108
|
},
|
|
@@ -310,22 +336,40 @@ var iDrawRenderer = function(exports) {
|
|
|
310
336
|
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
311
337
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
312
338
|
});
|
|
339
|
+
var __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
340
|
+
if (kind === "m")
|
|
341
|
+
throw new TypeError("Private method is not writable");
|
|
342
|
+
if (kind === "a" && !f)
|
|
343
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
344
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
345
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
346
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
347
|
+
};
|
|
348
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
349
|
+
if (kind === "a" && !f)
|
|
350
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
351
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
352
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
353
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
354
|
+
};
|
|
355
|
+
var _EventEmitter_listeners;
|
|
313
356
|
class EventEmitter {
|
|
314
357
|
constructor() {
|
|
315
|
-
this
|
|
358
|
+
_EventEmitter_listeners.set(this, void 0);
|
|
359
|
+
__classPrivateFieldSet(this, _EventEmitter_listeners, /* @__PURE__ */ new Map(), "f");
|
|
316
360
|
}
|
|
317
361
|
on(eventKey, callback) {
|
|
318
|
-
if (this.
|
|
319
|
-
const callbacks = this.
|
|
362
|
+
if (__classPrivateFieldGet(this, _EventEmitter_listeners, "f").has(eventKey)) {
|
|
363
|
+
const callbacks = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(eventKey) || [];
|
|
320
364
|
callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
|
|
321
|
-
this.
|
|
365
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(eventKey, callbacks);
|
|
322
366
|
} else {
|
|
323
|
-
this.
|
|
367
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(eventKey, [callback]);
|
|
324
368
|
}
|
|
325
369
|
}
|
|
326
370
|
off(eventKey, callback) {
|
|
327
|
-
if (this.
|
|
328
|
-
const callbacks = this.
|
|
371
|
+
if (__classPrivateFieldGet(this, _EventEmitter_listeners, "f").has(eventKey)) {
|
|
372
|
+
const callbacks = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(eventKey);
|
|
329
373
|
if (Array.isArray(callbacks)) {
|
|
330
374
|
for (let i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
|
|
331
375
|
if (callbacks[i] === callback) {
|
|
@@ -334,11 +378,11 @@ var iDrawRenderer = function(exports) {
|
|
|
334
378
|
}
|
|
335
379
|
}
|
|
336
380
|
}
|
|
337
|
-
this.
|
|
381
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(eventKey, callbacks || []);
|
|
338
382
|
}
|
|
339
383
|
}
|
|
340
384
|
trigger(eventKey, e) {
|
|
341
|
-
const callbacks = this.
|
|
385
|
+
const callbacks = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(eventKey);
|
|
342
386
|
if (Array.isArray(callbacks)) {
|
|
343
387
|
callbacks.forEach((cb) => {
|
|
344
388
|
cb(e);
|
|
@@ -349,15 +393,38 @@ var iDrawRenderer = function(exports) {
|
|
|
349
393
|
}
|
|
350
394
|
}
|
|
351
395
|
has(name) {
|
|
352
|
-
if (this.
|
|
353
|
-
const list = this.
|
|
396
|
+
if (__classPrivateFieldGet(this, _EventEmitter_listeners, "f").has(name)) {
|
|
397
|
+
const list = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(name);
|
|
354
398
|
if (Array.isArray(list) && list.length > 0) {
|
|
355
399
|
return true;
|
|
356
400
|
}
|
|
357
401
|
}
|
|
358
402
|
return false;
|
|
359
403
|
}
|
|
404
|
+
destroy() {
|
|
405
|
+
this.clear();
|
|
406
|
+
}
|
|
407
|
+
clear() {
|
|
408
|
+
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").clear();
|
|
409
|
+
}
|
|
360
410
|
}
|
|
411
|
+
_EventEmitter_listeners = /* @__PURE__ */ new WeakMap();
|
|
412
|
+
(function(receiver, state, value, kind, f) {
|
|
413
|
+
if (kind === "m")
|
|
414
|
+
throw new TypeError("Private method is not writable");
|
|
415
|
+
if (kind === "a" && !f)
|
|
416
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
417
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
418
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
419
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
420
|
+
});
|
|
421
|
+
(function(receiver, state, kind, f) {
|
|
422
|
+
if (kind === "a" && !f)
|
|
423
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
424
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
425
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
426
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
427
|
+
});
|
|
361
428
|
function parseAngleToRadian(angle2) {
|
|
362
429
|
return angle2 / 180 * Math.PI;
|
|
363
430
|
}
|
|
@@ -388,6 +455,19 @@ var iDrawRenderer = function(exports) {
|
|
|
388
455
|
};
|
|
389
456
|
return p;
|
|
390
457
|
}
|
|
458
|
+
function calcViewElementSize(size, opts) {
|
|
459
|
+
const { viewScaleInfo } = opts;
|
|
460
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = size;
|
|
461
|
+
const { scale, offsetTop, offsetLeft } = viewScaleInfo;
|
|
462
|
+
const newSize = {
|
|
463
|
+
x: x2 * scale + offsetLeft,
|
|
464
|
+
y: y2 * scale + offsetTop,
|
|
465
|
+
w: w2 * scale,
|
|
466
|
+
h: h2 * scale,
|
|
467
|
+
angle: angle2
|
|
468
|
+
};
|
|
469
|
+
return newSize;
|
|
470
|
+
}
|
|
391
471
|
function generateSVGPath(commands) {
|
|
392
472
|
let path = "";
|
|
393
473
|
commands.forEach((item) => {
|
|
@@ -411,7 +491,6 @@ var iDrawRenderer = function(exports) {
|
|
|
411
491
|
textAlign: "left",
|
|
412
492
|
verticalAlign: "top",
|
|
413
493
|
fontSize: 16,
|
|
414
|
-
lineHeight: 20,
|
|
415
494
|
fontFamily: "sans-serif",
|
|
416
495
|
fontWeight: 400,
|
|
417
496
|
overflow: "hidden"
|
|
@@ -422,8 +501,9 @@ var iDrawRenderer = function(exports) {
|
|
|
422
501
|
function calcViewBoxSize(viewElem, opts) {
|
|
423
502
|
const { viewScaleInfo } = opts;
|
|
424
503
|
const { scale } = viewScaleInfo;
|
|
425
|
-
let { borderRadius: borderRadius2
|
|
426
|
-
|
|
504
|
+
let { borderRadius: borderRadius2 } = viewElem.detail;
|
|
505
|
+
const { boxSizing = defaultElemConfig$1.boxSizing, borderWidth: borderWidth2 } = viewElem.detail;
|
|
506
|
+
if (Array.isArray(borderWidth2)) {
|
|
427
507
|
borderRadius2 = 0;
|
|
428
508
|
}
|
|
429
509
|
let { x: x2, y: y2, w: w2, h: h2 } = viewElem;
|
|
@@ -511,30 +591,35 @@ var iDrawRenderer = function(exports) {
|
|
|
511
591
|
return "#000000";
|
|
512
592
|
}
|
|
513
593
|
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
594
|
+
function getOpacity(elem) {
|
|
595
|
+
var _a, _b, _c, _d;
|
|
596
|
+
let opacity = 1;
|
|
597
|
+
if (((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = elem == null ? void 0 : elem.detail) == null ? void 0 : _b.opacity) >= 0 && ((_c = elem == null ? void 0 : elem.detail) == null ? void 0 : _c.opacity) <= 1) {
|
|
598
|
+
opacity = (_d = elem == null ? void 0 : elem.detail) == null ? void 0 : _d.opacity;
|
|
599
|
+
}
|
|
600
|
+
return opacity;
|
|
601
|
+
}
|
|
514
602
|
function drawBox(ctx, viewElem, opts) {
|
|
515
603
|
const { pattern, renderContent, originElem, calcElemSize, viewScaleInfo, viewSizeInfo } = opts || {};
|
|
604
|
+
const { parentOpacity } = opts;
|
|
605
|
+
const opacity = getOpacity(originElem) * parentOpacity;
|
|
516
606
|
drawClipPath(ctx, viewElem, {
|
|
517
607
|
originElem,
|
|
518
608
|
calcElemSize,
|
|
519
609
|
viewScaleInfo,
|
|
520
610
|
viewSizeInfo,
|
|
521
611
|
renderContent: () => {
|
|
522
|
-
|
|
523
|
-
if (((_a = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _b.opacity) >= 0) {
|
|
524
|
-
ctx.globalAlpha = viewElem.detail.opacity;
|
|
525
|
-
} else {
|
|
526
|
-
ctx.globalAlpha = 1;
|
|
527
|
-
}
|
|
612
|
+
ctx.globalAlpha = opacity;
|
|
528
613
|
drawBoxBackground(ctx, viewElem, { pattern, viewScaleInfo, viewSizeInfo });
|
|
529
614
|
renderContent == null ? void 0 : renderContent();
|
|
530
615
|
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
531
|
-
ctx.globalAlpha =
|
|
616
|
+
ctx.globalAlpha = parentOpacity;
|
|
532
617
|
}
|
|
533
618
|
});
|
|
534
619
|
}
|
|
535
620
|
function drawClipPath(ctx, viewElem, opts) {
|
|
536
|
-
const { renderContent, originElem, calcElemSize,
|
|
537
|
-
const totalScale =
|
|
621
|
+
const { renderContent, originElem, calcElemSize, viewSizeInfo } = opts;
|
|
622
|
+
const totalScale = viewSizeInfo.devicePixelRatio;
|
|
538
623
|
const { clipPath } = (originElem == null ? void 0 : originElem.detail) || {};
|
|
539
624
|
if (clipPath && calcElemSize && clipPath.commands) {
|
|
540
625
|
const { x: x2, y: y2, w: w2, h: h2 } = calcElemSize;
|
|
@@ -543,8 +628,8 @@ var iDrawRenderer = function(exports) {
|
|
|
543
628
|
const scaleH = h2 / originH;
|
|
544
629
|
const viewOriginX = originX * scaleW;
|
|
545
630
|
const viewOriginY = originY * scaleH;
|
|
546
|
-
|
|
547
|
-
|
|
631
|
+
const internalX = x2 - viewOriginX;
|
|
632
|
+
const internalY = y2 - viewOriginY;
|
|
548
633
|
ctx.save();
|
|
549
634
|
ctx.translate(internalX, internalY);
|
|
550
635
|
ctx.scale(totalScale * scaleW, totalScale * scaleH);
|
|
@@ -564,8 +649,7 @@ var iDrawRenderer = function(exports) {
|
|
|
564
649
|
function drawBoxBackground(ctx, viewElem, opts) {
|
|
565
650
|
var _a, _b;
|
|
566
651
|
const { pattern, viewScaleInfo, viewSizeInfo } = opts;
|
|
567
|
-
|
|
568
|
-
viewElem.detail;
|
|
652
|
+
const transform = [];
|
|
569
653
|
if (viewElem.detail.background || pattern) {
|
|
570
654
|
const { x: x2, y: y2, w: w2, h: h2, radiusList } = calcViewBoxSize(viewElem, {
|
|
571
655
|
viewScaleInfo,
|
|
@@ -618,18 +702,12 @@ var iDrawRenderer = function(exports) {
|
|
|
618
702
|
}
|
|
619
703
|
}
|
|
620
704
|
function drawBoxBorder(ctx, viewElem, opts) {
|
|
621
|
-
var _a, _b;
|
|
622
705
|
if (viewElem.detail.borderWidth === 0) {
|
|
623
706
|
return;
|
|
624
707
|
}
|
|
625
708
|
if (!isColorStr(viewElem.detail.borderColor)) {
|
|
626
709
|
return;
|
|
627
710
|
}
|
|
628
|
-
if (((_a = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _a.opacity) !== void 0 && ((_b = viewElem == null ? void 0 : viewElem.detail) == null ? void 0 : _b.opacity) >= 0) {
|
|
629
|
-
ctx.globalAlpha = viewElem.detail.opacity;
|
|
630
|
-
} else {
|
|
631
|
-
ctx.globalAlpha = 1;
|
|
632
|
-
}
|
|
633
711
|
const { viewScaleInfo } = opts;
|
|
634
712
|
const { scale } = viewScaleInfo;
|
|
635
713
|
let borderColor = defaultElemConfig.borderColor;
|
|
@@ -753,7 +831,6 @@ var iDrawRenderer = function(exports) {
|
|
|
753
831
|
ctx.arcTo(x2, y2, x2 + w2, y2, radiusList[0]);
|
|
754
832
|
ctx.closePath();
|
|
755
833
|
ctx.stroke();
|
|
756
|
-
ctx.globalAlpha = 1;
|
|
757
834
|
}
|
|
758
835
|
ctx.setLineDash([]);
|
|
759
836
|
}
|
|
@@ -770,58 +847,81 @@ var iDrawRenderer = function(exports) {
|
|
|
770
847
|
renderContent();
|
|
771
848
|
ctx.restore();
|
|
772
849
|
} else {
|
|
850
|
+
ctx.save();
|
|
851
|
+
ctx.shadowColor = "transparent";
|
|
852
|
+
ctx.shadowOffsetX = 0;
|
|
853
|
+
ctx.shadowOffsetY = 0;
|
|
854
|
+
ctx.shadowBlur = 0;
|
|
773
855
|
renderContent();
|
|
856
|
+
ctx.restore();
|
|
774
857
|
}
|
|
775
858
|
}
|
|
776
859
|
function drawCircle(ctx, elem, opts) {
|
|
777
860
|
const { detail, angle: angle2 } = elem;
|
|
778
|
-
const {
|
|
779
|
-
const {
|
|
780
|
-
|
|
861
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
862
|
+
const { background = "#000000", borderColor = "#000000", boxSizing, borderWidth: borderWidth2 = 0 } = detail;
|
|
863
|
+
let bw = 0;
|
|
864
|
+
if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
|
|
865
|
+
bw = borderWidth2;
|
|
866
|
+
} else if (Array.isArray(borderWidth2) && typeof borderWidth2[0] === "number" && borderWidth2[0] > 0) {
|
|
867
|
+
bw = borderWidth2[0];
|
|
868
|
+
}
|
|
869
|
+
bw = bw * viewScaleInfo.scale;
|
|
870
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
781
871
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
782
872
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
783
873
|
drawBoxShadow(ctx, viewElem, {
|
|
784
874
|
viewScaleInfo,
|
|
785
875
|
viewSizeInfo,
|
|
786
876
|
renderContent: () => {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
const b = h2 / 2;
|
|
877
|
+
let a = w2 / 2;
|
|
878
|
+
let b = h2 / 2;
|
|
790
879
|
const centerX = x2 + a;
|
|
791
880
|
const centerY = y2 + b;
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
881
|
+
if (bw > 0) {
|
|
882
|
+
if (boxSizing === "border-box") {
|
|
883
|
+
a = a - bw;
|
|
884
|
+
b = b - bw;
|
|
885
|
+
} else if (boxSizing === "center-line") {
|
|
886
|
+
a = a - bw / 2;
|
|
887
|
+
b = b - bw / 2;
|
|
888
|
+
} else {
|
|
889
|
+
a = a - bw;
|
|
890
|
+
b = b - bw;
|
|
891
|
+
}
|
|
796
892
|
}
|
|
797
|
-
if (
|
|
798
|
-
const
|
|
799
|
-
|
|
893
|
+
if (a >= 0 && b >= 0) {
|
|
894
|
+
const opacity = getOpacity(viewElem) * parentOpacity;
|
|
895
|
+
ctx.globalAlpha = opacity;
|
|
896
|
+
if (typeof bw === "number" && bw > 0) {
|
|
897
|
+
const ba = bw / 2 + a;
|
|
898
|
+
const bb = bw / 2 + b;
|
|
899
|
+
ctx.beginPath();
|
|
900
|
+
ctx.strokeStyle = borderColor;
|
|
901
|
+
ctx.lineWidth = bw;
|
|
902
|
+
ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
|
|
903
|
+
ctx.closePath();
|
|
904
|
+
ctx.stroke();
|
|
905
|
+
}
|
|
800
906
|
ctx.beginPath();
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
907
|
+
const fillStyle = createColorStyle(ctx, background, {
|
|
908
|
+
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
909
|
+
viewScaleInfo,
|
|
910
|
+
opacity: ctx.globalAlpha
|
|
911
|
+
});
|
|
912
|
+
ctx.fillStyle = fillStyle;
|
|
913
|
+
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
|
|
804
914
|
ctx.closePath();
|
|
805
|
-
ctx.
|
|
915
|
+
ctx.fill();
|
|
916
|
+
ctx.globalAlpha = parentOpacity;
|
|
806
917
|
}
|
|
807
|
-
ctx.beginPath();
|
|
808
|
-
const fillStyle = createColorStyle(ctx, background, {
|
|
809
|
-
viewElementSize: { x: x2, y: y2, w: w2, h: h2 },
|
|
810
|
-
viewScaleInfo,
|
|
811
|
-
opacity: ctx.globalAlpha
|
|
812
|
-
});
|
|
813
|
-
ctx.fillStyle = fillStyle;
|
|
814
|
-
ctx.circle(centerX, centerY, a, b, 0, 0, 2 * Math.PI);
|
|
815
|
-
ctx.closePath();
|
|
816
|
-
ctx.fill();
|
|
817
|
-
ctx.globalAlpha = 1;
|
|
818
918
|
}
|
|
819
919
|
});
|
|
820
920
|
});
|
|
821
921
|
}
|
|
822
922
|
function drawRect(ctx, elem, opts) {
|
|
823
|
-
const {
|
|
824
|
-
|
|
923
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
924
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
825
925
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
826
926
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
827
927
|
drawBoxShadow(ctx, viewElem, {
|
|
@@ -833,6 +933,7 @@ var iDrawRenderer = function(exports) {
|
|
|
833
933
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
834
934
|
viewScaleInfo,
|
|
835
935
|
viewSizeInfo,
|
|
936
|
+
parentOpacity,
|
|
836
937
|
renderContent: () => {
|
|
837
938
|
}
|
|
838
939
|
});
|
|
@@ -842,8 +943,8 @@ var iDrawRenderer = function(exports) {
|
|
|
842
943
|
}
|
|
843
944
|
function drawImage(ctx, elem, opts) {
|
|
844
945
|
const content = opts.loader.getContent(elem);
|
|
845
|
-
const {
|
|
846
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } =
|
|
946
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
947
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
847
948
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
848
949
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
849
950
|
drawBoxShadow(ctx, viewElem, {
|
|
@@ -855,13 +956,13 @@ var iDrawRenderer = function(exports) {
|
|
|
855
956
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
856
957
|
viewScaleInfo,
|
|
857
958
|
viewSizeInfo,
|
|
959
|
+
parentOpacity,
|
|
858
960
|
renderContent: () => {
|
|
859
|
-
if (!content) {
|
|
961
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
860
962
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
861
963
|
}
|
|
862
964
|
if (elem.type === "image" && content) {
|
|
863
|
-
|
|
864
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
965
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
865
966
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
866
967
|
viewScaleInfo,
|
|
867
968
|
viewSizeInfo
|
|
@@ -878,7 +979,7 @@ var iDrawRenderer = function(exports) {
|
|
|
878
979
|
ctx.fill();
|
|
879
980
|
ctx.clip();
|
|
880
981
|
ctx.drawImage(content, x22, y22, w22, h22);
|
|
881
|
-
ctx.globalAlpha =
|
|
982
|
+
ctx.globalAlpha = parentOpacity;
|
|
882
983
|
ctx.restore();
|
|
883
984
|
}
|
|
884
985
|
}
|
|
@@ -889,40 +990,38 @@ var iDrawRenderer = function(exports) {
|
|
|
889
990
|
}
|
|
890
991
|
function drawSVG(ctx, elem, opts) {
|
|
891
992
|
const content = opts.loader.getContent(elem);
|
|
892
|
-
const {
|
|
893
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } =
|
|
993
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
994
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
894
995
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
895
|
-
if (!content) {
|
|
996
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
896
997
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
897
998
|
}
|
|
898
999
|
if (elem.type === "svg" && content) {
|
|
899
|
-
|
|
900
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1000
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
901
1001
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
902
|
-
ctx.globalAlpha =
|
|
1002
|
+
ctx.globalAlpha = parentOpacity;
|
|
903
1003
|
}
|
|
904
1004
|
});
|
|
905
1005
|
}
|
|
906
1006
|
function drawHTML(ctx, elem, opts) {
|
|
907
1007
|
const content = opts.loader.getContent(elem);
|
|
908
|
-
const {
|
|
909
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } =
|
|
1008
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1009
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
910
1010
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
911
|
-
if (!content) {
|
|
1011
|
+
if (!content && !opts.loader.isDestroyed()) {
|
|
912
1012
|
opts.loader.load(elem, opts.elementAssets || {});
|
|
913
1013
|
}
|
|
914
1014
|
if (elem.type === "html" && content) {
|
|
915
|
-
|
|
916
|
-
ctx.globalAlpha = opacity ? opacity : 1;
|
|
1015
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
917
1016
|
ctx.drawImage(content, x2, y2, w2, h2);
|
|
918
|
-
ctx.globalAlpha =
|
|
1017
|
+
ctx.globalAlpha = parentOpacity;
|
|
919
1018
|
}
|
|
920
1019
|
});
|
|
921
1020
|
}
|
|
922
1021
|
const detailConfig = getDefaultElementDetailConfig();
|
|
923
1022
|
function drawText(ctx, elem, opts) {
|
|
924
|
-
const {
|
|
925
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } =
|
|
1023
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1024
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
|
|
926
1025
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
927
1026
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
928
1027
|
drawBox(ctx, viewElem, {
|
|
@@ -930,13 +1029,16 @@ var iDrawRenderer = function(exports) {
|
|
|
930
1029
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
931
1030
|
viewScaleInfo,
|
|
932
1031
|
viewSizeInfo,
|
|
1032
|
+
parentOpacity,
|
|
933
1033
|
renderContent: () => {
|
|
934
1034
|
const detail = {
|
|
935
1035
|
...detailConfig,
|
|
936
1036
|
...elem.detail
|
|
937
1037
|
};
|
|
938
|
-
const
|
|
939
|
-
const
|
|
1038
|
+
const originFontSize = detail.fontSize || detailConfig.fontSize;
|
|
1039
|
+
const fontSize2 = originFontSize * viewScaleInfo.scale;
|
|
1040
|
+
const originLineHeight = detail.lineHeight || originFontSize;
|
|
1041
|
+
const lineHeight2 = originLineHeight * viewScaleInfo.scale;
|
|
940
1042
|
ctx.fillStyle = elem.detail.color || detailConfig.color;
|
|
941
1043
|
ctx.textBaseline = "top";
|
|
942
1044
|
ctx.$setFont({
|
|
@@ -953,7 +1055,7 @@ var iDrawRenderer = function(exports) {
|
|
|
953
1055
|
let lineText = "";
|
|
954
1056
|
if (tempText.length > 0) {
|
|
955
1057
|
for (let i = 0; i < tempText.length; i++) {
|
|
956
|
-
if (ctx.measureText(lineText + (tempText[i] || "")).width
|
|
1058
|
+
if (ctx.measureText(lineText + (tempText[i] || "")).width <= ctx.$doPixelRatio(w2)) {
|
|
957
1059
|
lineText += tempText[i] || "";
|
|
958
1060
|
} else {
|
|
959
1061
|
lines.push({
|
|
@@ -967,7 +1069,7 @@ var iDrawRenderer = function(exports) {
|
|
|
967
1069
|
break;
|
|
968
1070
|
}
|
|
969
1071
|
if (tempText.length - 1 === i) {
|
|
970
|
-
if ((lineNum + 1) * fontHeight
|
|
1072
|
+
if ((lineNum + 1) * fontHeight <= h2) {
|
|
971
1073
|
lines.push({
|
|
972
1074
|
text: lineText,
|
|
973
1075
|
width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
|
|
@@ -1027,8 +1129,8 @@ var iDrawRenderer = function(exports) {
|
|
|
1027
1129
|
function drawPath(ctx, elem, opts) {
|
|
1028
1130
|
const { detail } = elem;
|
|
1029
1131
|
const { originX, originY, originW, originH } = detail;
|
|
1030
|
-
const {
|
|
1031
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } =
|
|
1132
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1133
|
+
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
1032
1134
|
const scaleW = w2 / originW;
|
|
1033
1135
|
const scaleH = h2 / originH;
|
|
1034
1136
|
const viewOriginX = originX * scaleW;
|
|
@@ -1043,6 +1145,7 @@ var iDrawRenderer = function(exports) {
|
|
|
1043
1145
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1044
1146
|
viewScaleInfo,
|
|
1045
1147
|
viewSizeInfo,
|
|
1148
|
+
parentOpacity,
|
|
1046
1149
|
renderContent: () => {
|
|
1047
1150
|
drawBoxShadow(ctx, viewElem, {
|
|
1048
1151
|
viewScaleInfo,
|
|
@@ -1076,6 +1179,11 @@ var iDrawRenderer = function(exports) {
|
|
|
1076
1179
|
if (((_a = elem == null ? void 0 : elem.operations) == null ? void 0 : _a.invisible) === true) {
|
|
1077
1180
|
return;
|
|
1078
1181
|
}
|
|
1182
|
+
const { w: w2, h: h2 } = elem;
|
|
1183
|
+
const { scale } = opts.viewScaleInfo;
|
|
1184
|
+
if (scale < 1 && (w2 * scale < 1 || h2 * scale < 1) || opts.parentOpacity === 0) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1079
1187
|
try {
|
|
1080
1188
|
switch (elem.type) {
|
|
1081
1189
|
case "rect": {
|
|
@@ -1126,10 +1234,11 @@ var iDrawRenderer = function(exports) {
|
|
|
1126
1234
|
}
|
|
1127
1235
|
}
|
|
1128
1236
|
function drawGroup(ctx, elem, opts) {
|
|
1129
|
-
const {
|
|
1130
|
-
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } =
|
|
1237
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1238
|
+
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, viewSizeInfo }) || elem;
|
|
1131
1239
|
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1132
1240
|
rotateElement(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
|
|
1241
|
+
ctx.globalAlpha = getOpacity(elem) * parentOpacity;
|
|
1133
1242
|
drawBoxShadow(ctx, viewElem, {
|
|
1134
1243
|
viewScaleInfo,
|
|
1135
1244
|
viewSizeInfo,
|
|
@@ -1139,6 +1248,7 @@ var iDrawRenderer = function(exports) {
|
|
|
1139
1248
|
calcElemSize: { x: x2, y: y2, w: w2, h: h2, angle: angle2 },
|
|
1140
1249
|
viewScaleInfo,
|
|
1141
1250
|
viewSizeInfo,
|
|
1251
|
+
parentOpacity,
|
|
1142
1252
|
renderContent: () => {
|
|
1143
1253
|
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem, {
|
|
1144
1254
|
viewScaleInfo,
|
|
@@ -1166,7 +1276,7 @@ var iDrawRenderer = function(exports) {
|
|
|
1166
1276
|
h: elem.h || parentSize.h,
|
|
1167
1277
|
angle: elem.angle
|
|
1168
1278
|
};
|
|
1169
|
-
const { calculator
|
|
1279
|
+
const { calculator } = opts;
|
|
1170
1280
|
for (let i = 0; i < elem.detail.children.length; i++) {
|
|
1171
1281
|
let child = elem.detail.children[i];
|
|
1172
1282
|
child = {
|
|
@@ -1176,29 +1286,33 @@ var iDrawRenderer = function(exports) {
|
|
|
1176
1286
|
y: newParentSize.y + child.y
|
|
1177
1287
|
}
|
|
1178
1288
|
};
|
|
1179
|
-
if (
|
|
1180
|
-
|
|
1289
|
+
if (opts.forceDrawAll !== true) {
|
|
1290
|
+
if (!(calculator == null ? void 0 : calculator.needRender(child))) {
|
|
1291
|
+
continue;
|
|
1292
|
+
}
|
|
1181
1293
|
}
|
|
1182
1294
|
try {
|
|
1183
|
-
drawElement(ctx, child, { ...opts });
|
|
1295
|
+
drawElement(ctx, child, { ...opts, ...{ parentOpacity: parentOpacity * getOpacity(elem) } });
|
|
1184
1296
|
} catch (err) {
|
|
1185
1297
|
console.error(err);
|
|
1186
1298
|
}
|
|
1187
1299
|
}
|
|
1188
1300
|
}
|
|
1189
1301
|
if (elem.detail.overflow === "hidden") {
|
|
1190
|
-
ctx.globalAlpha = 1;
|
|
1191
1302
|
ctx.restore();
|
|
1192
1303
|
}
|
|
1193
1304
|
}
|
|
1194
1305
|
});
|
|
1195
1306
|
}
|
|
1196
1307
|
});
|
|
1308
|
+
ctx.globalAlpha = parentOpacity;
|
|
1197
1309
|
});
|
|
1198
1310
|
}
|
|
1199
1311
|
const defaultDetail = getDefaultElementDetailConfig();
|
|
1200
1312
|
function drawElementList(ctx, data, opts) {
|
|
1313
|
+
var _a;
|
|
1201
1314
|
const { elements = [] } = data;
|
|
1315
|
+
const { parentOpacity } = opts;
|
|
1202
1316
|
for (let i = 0; i < elements.length; i++) {
|
|
1203
1317
|
const element = elements[i];
|
|
1204
1318
|
const elem = {
|
|
@@ -1210,16 +1324,65 @@ var iDrawRenderer = function(exports) {
|
|
|
1210
1324
|
}
|
|
1211
1325
|
}
|
|
1212
1326
|
};
|
|
1213
|
-
if (
|
|
1214
|
-
|
|
1327
|
+
if (opts.forceDrawAll !== true) {
|
|
1328
|
+
if (!((_a = opts.calculator) == null ? void 0 : _a.needRender(elem))) {
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1215
1331
|
}
|
|
1216
1332
|
try {
|
|
1217
|
-
drawElement(ctx, elem,
|
|
1333
|
+
drawElement(ctx, elem, {
|
|
1334
|
+
...opts,
|
|
1335
|
+
...{
|
|
1336
|
+
parentOpacity
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1218
1339
|
} catch (err) {
|
|
1219
1340
|
console.error(err);
|
|
1220
1341
|
}
|
|
1221
1342
|
}
|
|
1222
1343
|
}
|
|
1344
|
+
function drawLayout(ctx, layout, opts, renderContent) {
|
|
1345
|
+
const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
|
|
1346
|
+
const elem = { uuid: "layout", type: "group", ...layout };
|
|
1347
|
+
const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
|
|
1348
|
+
const angle2 = 0;
|
|
1349
|
+
const viewElem = { ...elem, ...{ x: x2, y: y2, w: w2, h: h2, angle: angle2 } };
|
|
1350
|
+
ctx.globalAlpha = 1;
|
|
1351
|
+
drawBoxShadow(ctx, viewElem, {
|
|
1352
|
+
viewScaleInfo,
|
|
1353
|
+
viewSizeInfo,
|
|
1354
|
+
renderContent: () => {
|
|
1355
|
+
drawBoxBackground(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
if (layout.detail.overflow === "hidden") {
|
|
1359
|
+
const { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 } = opts;
|
|
1360
|
+
const elem2 = { uuid: "layout", type: "group", ...layout };
|
|
1361
|
+
const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 }) || elem2;
|
|
1362
|
+
const viewElem2 = { ...elem2, ...viewElemSize };
|
|
1363
|
+
const { x: x22, y: y22, w: w22, h: h22, radiusList } = calcViewBoxSize(viewElem2, {
|
|
1364
|
+
viewScaleInfo: viewScaleInfo2,
|
|
1365
|
+
viewSizeInfo: viewSizeInfo2
|
|
1366
|
+
});
|
|
1367
|
+
ctx.save();
|
|
1368
|
+
ctx.fillStyle = "transparent";
|
|
1369
|
+
ctx.beginPath();
|
|
1370
|
+
ctx.moveTo(x22 + radiusList[0], y22);
|
|
1371
|
+
ctx.arcTo(x22 + w22, y22, x22 + w22, y22 + h22, radiusList[1]);
|
|
1372
|
+
ctx.arcTo(x22 + w22, y22 + h22, x22, y22 + h22, radiusList[2]);
|
|
1373
|
+
ctx.arcTo(x22, y22 + h22, x22, y22, radiusList[3]);
|
|
1374
|
+
ctx.arcTo(x22, y22, x22 + w22, y22, radiusList[0]);
|
|
1375
|
+
ctx.closePath();
|
|
1376
|
+
ctx.fill();
|
|
1377
|
+
ctx.clip();
|
|
1378
|
+
}
|
|
1379
|
+
renderContent(ctx);
|
|
1380
|
+
if (layout.detail.overflow === "hidden") {
|
|
1381
|
+
ctx.restore();
|
|
1382
|
+
}
|
|
1383
|
+
drawBoxBorder(ctx, viewElem, { viewScaleInfo, viewSizeInfo });
|
|
1384
|
+
ctx.globalAlpha = parentOpacity;
|
|
1385
|
+
}
|
|
1223
1386
|
const supportElementTypes = ["image", "svg", "html"];
|
|
1224
1387
|
const getAssetIdFromElement = (element) => {
|
|
1225
1388
|
var _a, _b, _c;
|
|
@@ -1242,10 +1405,18 @@ var iDrawRenderer = function(exports) {
|
|
|
1242
1405
|
class Loader extends EventEmitter {
|
|
1243
1406
|
constructor() {
|
|
1244
1407
|
super();
|
|
1245
|
-
this
|
|
1246
|
-
this
|
|
1247
|
-
this
|
|
1248
|
-
this
|
|
1408
|
+
__privateAdd(this, _registerLoadFunc);
|
|
1409
|
+
__privateAdd(this, _getLoadElementSource);
|
|
1410
|
+
__privateAdd(this, _createLoadItem);
|
|
1411
|
+
__privateAdd(this, _emitLoad);
|
|
1412
|
+
__privateAdd(this, _emitError);
|
|
1413
|
+
__privateAdd(this, _loadResource);
|
|
1414
|
+
__privateAdd(this, _isExistingErrorStorage);
|
|
1415
|
+
__privateAdd(this, _loadFuncMap, {});
|
|
1416
|
+
__privateAdd(this, _currentLoadItemMap, {});
|
|
1417
|
+
__privateAdd(this, _storageLoadItemMap, {});
|
|
1418
|
+
__privateAdd(this, _hasDestroyed, false);
|
|
1419
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "image", async (elem, assets) => {
|
|
1249
1420
|
var _a;
|
|
1250
1421
|
const src = ((_a = assets[elem.detail.src]) == null ? void 0 : _a.value) || elem.detail.src;
|
|
1251
1422
|
const content = await loadImage(src);
|
|
@@ -1255,12 +1426,12 @@ var iDrawRenderer = function(exports) {
|
|
|
1255
1426
|
content
|
|
1256
1427
|
};
|
|
1257
1428
|
});
|
|
1258
|
-
this.
|
|
1429
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "html", async (elem, assets) => {
|
|
1259
1430
|
var _a;
|
|
1260
1431
|
const html2 = ((_a = assets[elem.detail.html]) == null ? void 0 : _a.value) || elem.detail.html;
|
|
1261
1432
|
const content = await loadHTML(html2, {
|
|
1262
|
-
width: elem.detail.
|
|
1263
|
-
height: elem.detail.
|
|
1433
|
+
width: elem.detail.originW || elem.w,
|
|
1434
|
+
height: elem.detail.originH || elem.h
|
|
1264
1435
|
});
|
|
1265
1436
|
return {
|
|
1266
1437
|
uuid: elem.uuid,
|
|
@@ -1268,7 +1439,7 @@ var iDrawRenderer = function(exports) {
|
|
|
1268
1439
|
content
|
|
1269
1440
|
};
|
|
1270
1441
|
});
|
|
1271
|
-
this.
|
|
1442
|
+
__privateMethod(this, _registerLoadFunc, registerLoadFunc_fn).call(this, "svg", async (elem, assets) => {
|
|
1272
1443
|
var _a;
|
|
1273
1444
|
const svg2 = ((_a = assets[elem.detail.svg]) == null ? void 0 : _a.value) || elem.detail.svg;
|
|
1274
1445
|
const content = await loadSVG(svg2);
|
|
@@ -1279,127 +1450,169 @@ var iDrawRenderer = function(exports) {
|
|
|
1279
1450
|
};
|
|
1280
1451
|
});
|
|
1281
1452
|
}
|
|
1282
|
-
|
|
1283
|
-
this
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1453
|
+
isDestroyed() {
|
|
1454
|
+
return __privateGet(this, _hasDestroyed);
|
|
1455
|
+
}
|
|
1456
|
+
destroy() {
|
|
1457
|
+
__privateSet(this, _hasDestroyed, true);
|
|
1458
|
+
this.clear();
|
|
1459
|
+
__privateSet(this, _loadFuncMap, null);
|
|
1460
|
+
__privateSet(this, _currentLoadItemMap, null);
|
|
1461
|
+
__privateSet(this, _storageLoadItemMap, null);
|
|
1462
|
+
}
|
|
1463
|
+
load(element, assets) {
|
|
1464
|
+
if (__privateGet(this, _hasDestroyed) === true) {
|
|
1465
|
+
return;
|
|
1294
1466
|
}
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
element,
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1467
|
+
if (__privateMethod(this, _isExistingErrorStorage, isExistingErrorStorage_fn).call(this, element)) {
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
if (supportElementTypes.includes(element.type)) {
|
|
1471
|
+
__privateMethod(this, _loadResource, loadResource_fn).call(this, element, assets);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
getContent(element) {
|
|
1475
|
+
var _a, _b;
|
|
1476
|
+
const assetId = getAssetIdFromElement(element);
|
|
1477
|
+
return ((_b = (_a = __privateGet(this, _storageLoadItemMap)) == null ? void 0 : _a[assetId]) == null ? void 0 : _b.content) || null;
|
|
1478
|
+
}
|
|
1479
|
+
getLoadItemMap() {
|
|
1480
|
+
return __privateGet(this, _storageLoadItemMap);
|
|
1481
|
+
}
|
|
1482
|
+
setLoadItemMap(itemMap) {
|
|
1483
|
+
__privateSet(this, _storageLoadItemMap, itemMap);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
_loadFuncMap = new WeakMap();
|
|
1487
|
+
_currentLoadItemMap = new WeakMap();
|
|
1488
|
+
_storageLoadItemMap = new WeakMap();
|
|
1489
|
+
_hasDestroyed = new WeakMap();
|
|
1490
|
+
_registerLoadFunc = new WeakSet();
|
|
1491
|
+
registerLoadFunc_fn = function(type, func) {
|
|
1492
|
+
__privateGet(this, _loadFuncMap)[type] = func;
|
|
1493
|
+
};
|
|
1494
|
+
_getLoadElementSource = new WeakSet();
|
|
1495
|
+
getLoadElementSource_fn = function(element) {
|
|
1496
|
+
var _a, _b, _c;
|
|
1497
|
+
let source = null;
|
|
1498
|
+
if (element.type === "image") {
|
|
1499
|
+
source = ((_a = element == null ? void 0 : element.detail) == null ? void 0 : _a.src) || null;
|
|
1500
|
+
} else if (element.type === "svg") {
|
|
1501
|
+
source = ((_b = element == null ? void 0 : element.detail) == null ? void 0 : _b.svg) || null;
|
|
1502
|
+
} else if (element.type === "html") {
|
|
1503
|
+
source = ((_c = element == null ? void 0 : element.detail) == null ? void 0 : _c.html) || null;
|
|
1307
1504
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1505
|
+
return source;
|
|
1506
|
+
};
|
|
1507
|
+
_createLoadItem = new WeakSet();
|
|
1508
|
+
createLoadItem_fn = function(element) {
|
|
1509
|
+
return {
|
|
1510
|
+
element,
|
|
1511
|
+
status: "null",
|
|
1512
|
+
content: null,
|
|
1513
|
+
error: null,
|
|
1514
|
+
startTime: -1,
|
|
1515
|
+
endTime: -1,
|
|
1516
|
+
source: __privateMethod(this, _getLoadElementSource, getLoadElementSource_fn).call(this, element)
|
|
1517
|
+
};
|
|
1518
|
+
};
|
|
1519
|
+
_emitLoad = new WeakSet();
|
|
1520
|
+
emitLoad_fn = function(item) {
|
|
1521
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
1522
|
+
const storageItem = __privateGet(this, _storageLoadItemMap)[assetId];
|
|
1523
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
1311
1524
|
if (storageItem) {
|
|
1312
1525
|
if (storageItem.startTime < item.startTime) {
|
|
1313
|
-
this
|
|
1526
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1314
1527
|
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1315
1528
|
}
|
|
1316
1529
|
} else {
|
|
1317
|
-
this
|
|
1530
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1318
1531
|
this.trigger("load", { ...item, countTime: item.endTime - item.startTime });
|
|
1319
1532
|
}
|
|
1320
1533
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1534
|
+
};
|
|
1535
|
+
_emitError = new WeakSet();
|
|
1536
|
+
emitError_fn = function(item) {
|
|
1537
|
+
var _a;
|
|
1538
|
+
const assetId = getAssetIdFromElement(item.element);
|
|
1539
|
+
const storageItem = (_a = __privateGet(this, _storageLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
1540
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
1324
1541
|
if (storageItem) {
|
|
1325
1542
|
if (storageItem.startTime < item.startTime) {
|
|
1326
|
-
this
|
|
1543
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1327
1544
|
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1328
1545
|
}
|
|
1329
1546
|
} else {
|
|
1330
|
-
this
|
|
1547
|
+
__privateGet(this, _storageLoadItemMap)[assetId] = item;
|
|
1331
1548
|
this.trigger("error", { ...item, countTime: item.endTime - item.startTime });
|
|
1332
1549
|
}
|
|
1333
1550
|
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1551
|
+
};
|
|
1552
|
+
_loadResource = new WeakSet();
|
|
1553
|
+
loadResource_fn = function(element, assets) {
|
|
1554
|
+
const item = __privateMethod(this, _createLoadItem, createLoadItem_fn).call(this, element);
|
|
1555
|
+
const assetId = getAssetIdFromElement(element);
|
|
1556
|
+
if (__privateGet(this, _currentLoadItemMap)[assetId]) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
__privateGet(this, _currentLoadItemMap)[assetId] = item;
|
|
1560
|
+
const loadFunc = __privateGet(this, _loadFuncMap)[element.type];
|
|
1561
|
+
if (typeof loadFunc === "function" && !__privateGet(this, _hasDestroyed)) {
|
|
1562
|
+
item.startTime = Date.now();
|
|
1563
|
+
loadFunc(element, assets).then((result) => {
|
|
1564
|
+
if (!__privateGet(this, _hasDestroyed)) {
|
|
1342
1565
|
item.content = result.content;
|
|
1343
1566
|
item.endTime = Date.now();
|
|
1344
1567
|
item.status = "load";
|
|
1345
|
-
this.
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
_isExistingErrorStorage(element) {
|
|
1356
|
-
var _a;
|
|
1357
|
-
const assetId = getAssetIdFromElement(element);
|
|
1358
|
-
const existItem = (_a = this._currentLoadItemMap) == null ? void 0 : _a[assetId];
|
|
1359
|
-
if (existItem && existItem.status === "error" && existItem.source && existItem.source === this._getLoadElementSource(element)) {
|
|
1360
|
-
return true;
|
|
1361
|
-
}
|
|
1362
|
-
return false;
|
|
1363
|
-
}
|
|
1364
|
-
load(element, assets) {
|
|
1365
|
-
if (this._isExistingErrorStorage(element)) {
|
|
1366
|
-
return;
|
|
1367
|
-
}
|
|
1368
|
-
if (supportElementTypes.includes(element.type)) {
|
|
1369
|
-
this._loadResource(element, assets);
|
|
1370
|
-
}
|
|
1568
|
+
__privateMethod(this, _emitLoad, emitLoad_fn).call(this, item);
|
|
1569
|
+
}
|
|
1570
|
+
}).catch((err) => {
|
|
1571
|
+
console.warn(`Load element source "${item.source}" fail`, err, element);
|
|
1572
|
+
item.endTime = Date.now();
|
|
1573
|
+
item.status = "error";
|
|
1574
|
+
item.error = err;
|
|
1575
|
+
__privateMethod(this, _emitError, emitError_fn).call(this, item);
|
|
1576
|
+
});
|
|
1371
1577
|
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1578
|
+
};
|
|
1579
|
+
_isExistingErrorStorage = new WeakSet();
|
|
1580
|
+
isExistingErrorStorage_fn = function(element) {
|
|
1581
|
+
var _a;
|
|
1582
|
+
const assetId = getAssetIdFromElement(element);
|
|
1583
|
+
const existItem = (_a = __privateGet(this, _currentLoadItemMap)) == null ? void 0 : _a[assetId];
|
|
1584
|
+
if (existItem && existItem.status === "error" && existItem.source && existItem.source === __privateMethod(this, _getLoadElementSource, getLoadElementSource_fn).call(this, element)) {
|
|
1585
|
+
return true;
|
|
1376
1586
|
}
|
|
1377
|
-
|
|
1587
|
+
return false;
|
|
1588
|
+
};
|
|
1378
1589
|
class Renderer extends EventEmitter {
|
|
1379
|
-
// private _draftContextTop: CanvasRenderingContext2D;
|
|
1380
|
-
// private _draftContextMiddle: CanvasRenderingContext2D;
|
|
1381
|
-
// private _draftContextBottom: CanvasRenderingContext2D;
|
|
1382
1590
|
constructor(opts) {
|
|
1383
1591
|
super();
|
|
1384
|
-
this
|
|
1385
|
-
this
|
|
1386
|
-
this
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1592
|
+
__privateAdd(this, _init);
|
|
1593
|
+
__privateAdd(this, _opts, void 0);
|
|
1594
|
+
__privateAdd(this, _loader, new Loader());
|
|
1595
|
+
__privateAdd(this, _hasDestroyed2, false);
|
|
1596
|
+
__privateSet(this, _opts, opts);
|
|
1597
|
+
__privateMethod(this, _init, init_fn).call(this);
|
|
1598
|
+
}
|
|
1599
|
+
isDestroyed() {
|
|
1600
|
+
return __privateGet(this, _hasDestroyed2);
|
|
1601
|
+
}
|
|
1602
|
+
destroy() {
|
|
1603
|
+
this.clear();
|
|
1604
|
+
__privateSet(this, _opts, null);
|
|
1605
|
+
__privateGet(this, _loader).destroy();
|
|
1606
|
+
__privateSet(this, _loader, null);
|
|
1607
|
+
__privateSet(this, _hasDestroyed2, true);
|
|
1395
1608
|
}
|
|
1396
1609
|
updateOptions(opts) {
|
|
1397
|
-
this
|
|
1610
|
+
__privateSet(this, _opts, opts);
|
|
1398
1611
|
}
|
|
1399
1612
|
drawData(data, opts) {
|
|
1400
|
-
const
|
|
1401
|
-
const { calculator } = this
|
|
1402
|
-
const
|
|
1613
|
+
const loader = __privateGet(this, _loader);
|
|
1614
|
+
const { calculator } = __privateGet(this, _opts);
|
|
1615
|
+
const viewContext = __privateGet(this, _opts).viewContext;
|
|
1403
1616
|
viewContext.clearRect(0, 0, viewContext.canvas.width, viewContext.canvas.height);
|
|
1404
1617
|
const parentElementSize = {
|
|
1405
1618
|
x: 0,
|
|
@@ -1407,16 +1620,27 @@ var iDrawRenderer = function(exports) {
|
|
|
1407
1620
|
w: opts.viewSizeInfo.width,
|
|
1408
1621
|
h: opts.viewSizeInfo.height
|
|
1409
1622
|
};
|
|
1410
|
-
|
|
1623
|
+
const drawOpts = {
|
|
1411
1624
|
loader,
|
|
1412
1625
|
calculator,
|
|
1413
1626
|
parentElementSize,
|
|
1414
1627
|
elementAssets: data.assets,
|
|
1628
|
+
parentOpacity: 1,
|
|
1415
1629
|
...opts
|
|
1416
|
-
}
|
|
1630
|
+
};
|
|
1631
|
+
if (data.layout) {
|
|
1632
|
+
drawLayout(viewContext, data.layout, drawOpts, () => {
|
|
1633
|
+
drawElementList(viewContext, data, drawOpts);
|
|
1634
|
+
});
|
|
1635
|
+
} else {
|
|
1636
|
+
drawElementList(viewContext, data, drawOpts);
|
|
1637
|
+
}
|
|
1417
1638
|
}
|
|
1418
1639
|
scale(num) {
|
|
1419
|
-
const { sharer } = this
|
|
1640
|
+
const { sharer } = __privateGet(this, _opts);
|
|
1641
|
+
if (!sharer) {
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1420
1644
|
const { data, offsetTop, offsetBottom, offsetLeft, offsetRight, width, height, contextHeight, contextWidth, devicePixelRatio } = sharer.getActiveStoreSnapshot();
|
|
1421
1645
|
if (data) {
|
|
1422
1646
|
this.drawData(data, {
|
|
@@ -1437,8 +1661,31 @@ var iDrawRenderer = function(exports) {
|
|
|
1437
1661
|
});
|
|
1438
1662
|
}
|
|
1439
1663
|
}
|
|
1664
|
+
setLoadItemMap(itemMap) {
|
|
1665
|
+
__privateGet(this, _loader).setLoadItemMap(itemMap);
|
|
1666
|
+
}
|
|
1667
|
+
getLoadItemMap() {
|
|
1668
|
+
return __privateGet(this, _loader).getLoadItemMap();
|
|
1669
|
+
}
|
|
1670
|
+
getLoader() {
|
|
1671
|
+
return __privateGet(this, _loader);
|
|
1672
|
+
}
|
|
1440
1673
|
}
|
|
1674
|
+
_opts = new WeakMap();
|
|
1675
|
+
_loader = new WeakMap();
|
|
1676
|
+
_hasDestroyed2 = new WeakMap();
|
|
1677
|
+
_init = new WeakSet();
|
|
1678
|
+
init_fn = function() {
|
|
1679
|
+
const loader = __privateGet(this, _loader);
|
|
1680
|
+
loader.on("load", (e) => {
|
|
1681
|
+
this.trigger("load", e);
|
|
1682
|
+
});
|
|
1683
|
+
loader.on("error", (e) => {
|
|
1684
|
+
console.error(e);
|
|
1685
|
+
});
|
|
1686
|
+
};
|
|
1441
1687
|
exports.Renderer = Renderer;
|
|
1688
|
+
exports.drawRect = drawRect;
|
|
1442
1689
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1443
1690
|
return exports;
|
|
1444
1691
|
}({});
|