@idraw/renderer 0.2.0-alpha.26 → 0.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +76 -85
- package/dist/index.d.ts +1 -2
- package/dist/{index.es.js → index.esm.js} +76 -85
- package/dist/index.global.js +76 -85
- package/dist/index.global.min.js +1 -1
- package/esm/default.d.ts +1 -0
- package/esm/default.js +2 -0
- package/esm/esm.d.ts +2 -0
- package/esm/esm.js +3 -0
- package/esm/index.js +136 -0
- package/esm/names.d.ts +9 -0
- package/esm/names.js +9 -0
- package/package.json +8 -6
package/dist/index.global.js
CHANGED
|
@@ -119,18 +119,18 @@ var iDrawRenderer = (function () {
|
|
|
119
119
|
function toColorHexStr(color) {
|
|
120
120
|
return '#' + color.toString(16);
|
|
121
121
|
}
|
|
122
|
-
function isColorStr
|
|
122
|
+
function isColorStr(color) {
|
|
123
123
|
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
124
124
|
}
|
|
125
|
-
function createUUID
|
|
125
|
+
function createUUID() {
|
|
126
126
|
function str4() {
|
|
127
127
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
128
128
|
}
|
|
129
129
|
return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
|
|
130
130
|
}
|
|
131
|
-
function deepClone
|
|
131
|
+
function deepClone(target) {
|
|
132
132
|
function _clone(t) {
|
|
133
|
-
var type = is$1
|
|
133
|
+
var type = is$1(t);
|
|
134
134
|
if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
|
|
135
135
|
return t;
|
|
136
136
|
}
|
|
@@ -152,7 +152,7 @@ var iDrawRenderer = (function () {
|
|
|
152
152
|
}
|
|
153
153
|
return _clone(target);
|
|
154
154
|
}
|
|
155
|
-
function is$1
|
|
155
|
+
function is$1(data) {
|
|
156
156
|
return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
|
|
157
157
|
}
|
|
158
158
|
function parsePrototype(data) {
|
|
@@ -160,7 +160,7 @@ var iDrawRenderer = (function () {
|
|
|
160
160
|
var result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
161
161
|
return result;
|
|
162
162
|
}
|
|
163
|
-
var istype
|
|
163
|
+
var istype = {
|
|
164
164
|
type: function (data, lowerCase) {
|
|
165
165
|
var result = parsePrototype(data);
|
|
166
166
|
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
@@ -273,7 +273,7 @@ var iDrawRenderer = (function () {
|
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
var Image = window.Image;
|
|
276
|
-
function loadImage
|
|
276
|
+
function loadImage(src) {
|
|
277
277
|
return new Promise(function (resolve, reject) {
|
|
278
278
|
var img = new Image;
|
|
279
279
|
img.onload = function () {
|
|
@@ -284,7 +284,7 @@ var iDrawRenderer = (function () {
|
|
|
284
284
|
img.src = src;
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
|
-
function loadSVG
|
|
287
|
+
function loadSVG(svg) {
|
|
288
288
|
return __awaiter(this, void 0, void 0, function () {
|
|
289
289
|
var dataURL, image;
|
|
290
290
|
return __generator(this, function (_a) {
|
|
@@ -292,7 +292,7 @@ var iDrawRenderer = (function () {
|
|
|
292
292
|
case 0: return [4, parseSVGToDataURL(svg)];
|
|
293
293
|
case 1:
|
|
294
294
|
dataURL = _a.sent();
|
|
295
|
-
return [4, loadImage
|
|
295
|
+
return [4, loadImage(dataURL)];
|
|
296
296
|
case 2:
|
|
297
297
|
image = _a.sent();
|
|
298
298
|
return [2, image];
|
|
@@ -300,15 +300,20 @@ var iDrawRenderer = (function () {
|
|
|
300
300
|
});
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
-
function
|
|
303
|
+
function filterAmpersand(str) {
|
|
304
|
+
return str.replace(/\&/ig, '&');
|
|
305
|
+
}
|
|
306
|
+
function loadHTML(html, opts) {
|
|
304
307
|
return __awaiter(this, void 0, void 0, function () {
|
|
305
308
|
var dataURL, image;
|
|
306
309
|
return __generator(this, function (_a) {
|
|
307
310
|
switch (_a.label) {
|
|
308
|
-
case 0:
|
|
311
|
+
case 0:
|
|
312
|
+
html = filterAmpersand(html);
|
|
313
|
+
return [4, parseHTMLToDataURL(html, opts)];
|
|
309
314
|
case 1:
|
|
310
315
|
dataURL = _a.sent();
|
|
311
|
-
return [4, loadImage
|
|
316
|
+
return [4, loadImage(dataURL)];
|
|
312
317
|
case 2:
|
|
313
318
|
image = _a.sent();
|
|
314
319
|
return [2, image];
|
|
@@ -316,7 +321,7 @@ var iDrawRenderer = (function () {
|
|
|
316
321
|
});
|
|
317
322
|
});
|
|
318
323
|
}
|
|
319
|
-
var Context
|
|
324
|
+
var Context = (function () {
|
|
320
325
|
function Context(ctx, opts) {
|
|
321
326
|
this._opts = opts;
|
|
322
327
|
this._ctx = ctx;
|
|
@@ -539,8 +544,8 @@ var iDrawRenderer = (function () {
|
|
|
539
544
|
function borderRadius(value) {
|
|
540
545
|
return number(value) && value >= 0;
|
|
541
546
|
}
|
|
542
|
-
function color
|
|
543
|
-
return isColorStr
|
|
547
|
+
function color(value) {
|
|
548
|
+
return isColorStr(value);
|
|
544
549
|
}
|
|
545
550
|
function imageURL(value) {
|
|
546
551
|
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
|
|
@@ -587,7 +592,7 @@ var iDrawRenderer = (function () {
|
|
|
587
592
|
function fontWeight(value) {
|
|
588
593
|
return ['bold'].includes(value);
|
|
589
594
|
}
|
|
590
|
-
var is
|
|
595
|
+
var is = {
|
|
591
596
|
x: x,
|
|
592
597
|
y: y,
|
|
593
598
|
w: w,
|
|
@@ -596,7 +601,7 @@ var iDrawRenderer = (function () {
|
|
|
596
601
|
number: number,
|
|
597
602
|
borderWidth: borderWidth,
|
|
598
603
|
borderRadius: borderRadius,
|
|
599
|
-
color: color
|
|
604
|
+
color: color,
|
|
600
605
|
imageSrc: imageSrc,
|
|
601
606
|
imageURL: imageURL,
|
|
602
607
|
imageBase64: imageBase64,
|
|
@@ -612,7 +617,7 @@ var iDrawRenderer = (function () {
|
|
|
612
617
|
};
|
|
613
618
|
function attrs(attrs) {
|
|
614
619
|
var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
|
|
615
|
-
if (!(is
|
|
620
|
+
if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
|
|
616
621
|
return false;
|
|
617
622
|
}
|
|
618
623
|
if (!(angle >= -360 && angle <= 360)) {
|
|
@@ -623,20 +628,20 @@ var iDrawRenderer = (function () {
|
|
|
623
628
|
function box(desc) {
|
|
624
629
|
if (desc === void 0) { desc = {}; }
|
|
625
630
|
var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
|
|
626
|
-
if (desc.hasOwnProperty('borderColor') && !is
|
|
631
|
+
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
627
632
|
return false;
|
|
628
633
|
}
|
|
629
|
-
if (desc.hasOwnProperty('borderRadius') && !is
|
|
634
|
+
if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
|
|
630
635
|
return false;
|
|
631
636
|
}
|
|
632
|
-
if (desc.hasOwnProperty('borderWidth') && !is
|
|
637
|
+
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
633
638
|
return false;
|
|
634
639
|
}
|
|
635
640
|
return true;
|
|
636
641
|
}
|
|
637
642
|
function rectDesc(desc) {
|
|
638
643
|
var bgColor = desc.bgColor;
|
|
639
|
-
if (desc.hasOwnProperty('bgColor') && !is
|
|
644
|
+
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
640
645
|
return false;
|
|
641
646
|
}
|
|
642
647
|
if (!box(desc)) {
|
|
@@ -646,68 +651,68 @@ var iDrawRenderer = (function () {
|
|
|
646
651
|
}
|
|
647
652
|
function circleDesc(desc) {
|
|
648
653
|
var bgColor = desc.bgColor, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
|
|
649
|
-
if (desc.hasOwnProperty('bgColor') && !is
|
|
654
|
+
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
650
655
|
return false;
|
|
651
656
|
}
|
|
652
|
-
if (desc.hasOwnProperty('borderColor') && !is
|
|
657
|
+
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
653
658
|
return false;
|
|
654
659
|
}
|
|
655
|
-
if (desc.hasOwnProperty('borderWidth') && !is
|
|
660
|
+
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
656
661
|
return false;
|
|
657
662
|
}
|
|
658
663
|
return true;
|
|
659
664
|
}
|
|
660
665
|
function imageDesc(desc) {
|
|
661
666
|
var src = desc.src;
|
|
662
|
-
if (!is
|
|
667
|
+
if (!is.imageSrc(src)) {
|
|
663
668
|
return false;
|
|
664
669
|
}
|
|
665
670
|
return true;
|
|
666
671
|
}
|
|
667
672
|
function svgDesc(desc) {
|
|
668
673
|
var svg = desc.svg;
|
|
669
|
-
if (!is
|
|
674
|
+
if (!is.svg(svg)) {
|
|
670
675
|
return false;
|
|
671
676
|
}
|
|
672
677
|
return true;
|
|
673
678
|
}
|
|
674
679
|
function htmlDesc(desc) {
|
|
675
680
|
var html = desc.html;
|
|
676
|
-
if (!is
|
|
681
|
+
if (!is.html(html)) {
|
|
677
682
|
return false;
|
|
678
683
|
}
|
|
679
684
|
return true;
|
|
680
685
|
}
|
|
681
686
|
function textDesc(desc) {
|
|
682
687
|
var text = desc.text, color = desc.color, fontSize = desc.fontSize, lineHeight = desc.lineHeight, fontFamily = desc.fontFamily, textAlign = desc.textAlign, fontWeight = desc.fontWeight, bgColor = desc.bgColor, strokeWidth = desc.strokeWidth, strokeColor = desc.strokeColor;
|
|
683
|
-
if (!is
|
|
688
|
+
if (!is.text(text)) {
|
|
684
689
|
return false;
|
|
685
690
|
}
|
|
686
|
-
if (!is
|
|
691
|
+
if (!is.color(color)) {
|
|
687
692
|
return false;
|
|
688
693
|
}
|
|
689
|
-
if (!is
|
|
694
|
+
if (!is.fontSize(fontSize)) {
|
|
690
695
|
return false;
|
|
691
696
|
}
|
|
692
|
-
if (desc.hasOwnProperty('bgColor') && !is
|
|
697
|
+
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
693
698
|
return false;
|
|
694
699
|
}
|
|
695
|
-
if (desc.hasOwnProperty('fontWeight') && !is
|
|
700
|
+
if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
|
|
696
701
|
return false;
|
|
697
702
|
}
|
|
698
|
-
if (desc.hasOwnProperty('lineHeight') && !is
|
|
703
|
+
if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
|
|
699
704
|
return false;
|
|
700
705
|
}
|
|
701
|
-
if (desc.hasOwnProperty('fontFamily') && !is
|
|
706
|
+
if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
|
|
702
707
|
return false;
|
|
703
708
|
}
|
|
704
|
-
if (desc.hasOwnProperty('textAlign') && !is
|
|
709
|
+
if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
|
|
705
710
|
return false;
|
|
706
711
|
}
|
|
707
|
-
if (desc.hasOwnProperty('strokeWidth') && !is
|
|
712
|
+
if (desc.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
|
|
708
713
|
return false;
|
|
709
714
|
}
|
|
710
|
-
if (desc.hasOwnProperty('strokeColor') && !is
|
|
715
|
+
if (desc.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
|
|
711
716
|
return false;
|
|
712
717
|
}
|
|
713
718
|
if (!box(desc)) {
|
|
@@ -724,36 +729,25 @@ var iDrawRenderer = (function () {
|
|
|
724
729
|
svgDesc: svgDesc,
|
|
725
730
|
htmlDesc: htmlDesc,
|
|
726
731
|
};
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
isColorStr: isColorStr$1,
|
|
747
|
-
},
|
|
748
|
-
uuid: {
|
|
749
|
-
createUUID: createUUID$1
|
|
750
|
-
},
|
|
751
|
-
istype: istype$1,
|
|
752
|
-
data: {
|
|
753
|
-
deepClone: deepClone$2,
|
|
754
|
-
},
|
|
755
|
-
Context: Context$1,
|
|
756
|
-
};
|
|
732
|
+
Object.freeze({
|
|
733
|
+
__proto__: null,
|
|
734
|
+
is: is,
|
|
735
|
+
check: check,
|
|
736
|
+
delay: delay,
|
|
737
|
+
compose: compose,
|
|
738
|
+
throttle: throttle,
|
|
739
|
+
loadImage: loadImage,
|
|
740
|
+
loadSVG: loadSVG,
|
|
741
|
+
loadHTML: loadHTML,
|
|
742
|
+
downloadImageFromCanvas: downloadImageFromCanvas,
|
|
743
|
+
toColorHexStr: toColorHexStr,
|
|
744
|
+
toColorHexNum: toColorHexNum,
|
|
745
|
+
isColorStr: isColorStr,
|
|
746
|
+
createUUID: createUUID,
|
|
747
|
+
istype: istype,
|
|
748
|
+
deepClone: deepClone,
|
|
749
|
+
Context: Context
|
|
750
|
+
});
|
|
757
751
|
|
|
758
752
|
function parseAngleToRadian(angle) {
|
|
759
753
|
return angle / 180 * Math.PI;
|
|
@@ -785,7 +779,6 @@ var iDrawRenderer = (function () {
|
|
|
785
779
|
}
|
|
786
780
|
}
|
|
787
781
|
|
|
788
|
-
var is$1 = index.is, istype = index.istype, color$1 = index.color;
|
|
789
782
|
function clearContext(ctx) {
|
|
790
783
|
ctx.setFillStyle('#000000');
|
|
791
784
|
ctx.setStrokeStyle('#000000');
|
|
@@ -836,7 +829,7 @@ var iDrawRenderer = (function () {
|
|
|
836
829
|
}
|
|
837
830
|
var bw = elem.desc.borderWidth;
|
|
838
831
|
var borderColor = '#000000';
|
|
839
|
-
if (
|
|
832
|
+
if (isColorStr(elem.desc.borderColor) === true) {
|
|
840
833
|
borderColor = elem.desc.borderColor;
|
|
841
834
|
}
|
|
842
835
|
var x = elem.x - bw / 2;
|
|
@@ -849,16 +842,16 @@ var iDrawRenderer = (function () {
|
|
|
849
842
|
r = r + bw / 2;
|
|
850
843
|
}
|
|
851
844
|
var desc = elem.desc;
|
|
852
|
-
if (desc.shadowColor !== undefined &&
|
|
845
|
+
if (desc.shadowColor !== undefined && isColorStr(desc.shadowColor)) {
|
|
853
846
|
ctx.setShadowColor(desc.shadowColor);
|
|
854
847
|
}
|
|
855
|
-
if (desc.shadowOffsetX !== undefined && is
|
|
848
|
+
if (desc.shadowOffsetX !== undefined && is.number(desc.shadowOffsetX)) {
|
|
856
849
|
ctx.setShadowOffsetX(desc.shadowOffsetX);
|
|
857
850
|
}
|
|
858
|
-
if (desc.shadowOffsetY !== undefined && is
|
|
851
|
+
if (desc.shadowOffsetY !== undefined && is.number(desc.shadowOffsetY)) {
|
|
859
852
|
ctx.setShadowOffsetY(desc.shadowOffsetY);
|
|
860
853
|
}
|
|
861
|
-
if (desc.shadowBlur !== undefined && is
|
|
854
|
+
if (desc.shadowBlur !== undefined && is.number(desc.shadowBlur)) {
|
|
862
855
|
ctx.setShadowBlur(desc.shadowBlur);
|
|
863
856
|
}
|
|
864
857
|
ctx.beginPath();
|
|
@@ -905,7 +898,6 @@ var iDrawRenderer = (function () {
|
|
|
905
898
|
});
|
|
906
899
|
}
|
|
907
900
|
|
|
908
|
-
var is = index.is, color = index.color;
|
|
909
901
|
function drawText(ctx, elem, loader) {
|
|
910
902
|
clearContext(ctx);
|
|
911
903
|
drawBox(ctx, elem, elem.desc.bgColor || 'transparent');
|
|
@@ -971,7 +963,7 @@ var iDrawRenderer = (function () {
|
|
|
971
963
|
if (lines.length * fontHeight < elem.h) {
|
|
972
964
|
_y_1 += ((elem.h - lines.length * fontHeight) / 2);
|
|
973
965
|
}
|
|
974
|
-
if (desc.textShadowColor !== undefined &&
|
|
966
|
+
if (desc.textShadowColor !== undefined && isColorStr(desc.textShadowColor)) {
|
|
975
967
|
ctx.setShadowColor(desc.textShadowColor);
|
|
976
968
|
}
|
|
977
969
|
if (desc.textShadowOffsetX !== undefined && is.number(desc.textShadowOffsetX)) {
|
|
@@ -995,7 +987,7 @@ var iDrawRenderer = (function () {
|
|
|
995
987
|
});
|
|
996
988
|
clearContext(ctx);
|
|
997
989
|
}
|
|
998
|
-
if (
|
|
990
|
+
if (isColorStr(desc.strokeColor) && desc.strokeWidth !== undefined && desc.strokeWidth > 0) {
|
|
999
991
|
var _y_2 = elem.y;
|
|
1000
992
|
if (lines.length * fontHeight < elem.h) {
|
|
1001
993
|
_y_2 += ((elem.h - lines.length * fontHeight) / 2);
|
|
@@ -1047,7 +1039,6 @@ var iDrawRenderer = (function () {
|
|
|
1047
1039
|
});
|
|
1048
1040
|
}
|
|
1049
1041
|
|
|
1050
|
-
var isColorStr = index.color.isColorStr;
|
|
1051
1042
|
function drawContext(ctx, data, loader) {
|
|
1052
1043
|
var _a;
|
|
1053
1044
|
clearContext(ctx);
|
|
@@ -1149,8 +1140,6 @@ var iDrawRenderer = (function () {
|
|
|
1149
1140
|
return html.replace(/<script[\s\S]*?<\/script>/ig, '');
|
|
1150
1141
|
}
|
|
1151
1142
|
|
|
1152
|
-
var _a$1 = index.loader, loadImage = _a$1.loadImage, loadSVG = _a$1.loadSVG, loadHTML = _a$1.loadHTML;
|
|
1153
|
-
var deepClone$1 = index.data.deepClone;
|
|
1154
1143
|
var LoaderStatus;
|
|
1155
1144
|
(function (LoaderStatus) {
|
|
1156
1145
|
LoaderStatus["FREE"] = "free";
|
|
@@ -1246,7 +1235,7 @@ var iDrawRenderer = (function () {
|
|
|
1246
1235
|
source: source,
|
|
1247
1236
|
elemW: elemW,
|
|
1248
1237
|
elemH: elemH,
|
|
1249
|
-
element: deepClone
|
|
1238
|
+
element: deepClone(elem),
|
|
1250
1239
|
};
|
|
1251
1240
|
};
|
|
1252
1241
|
Loader.prototype._loadTask = function () {
|
|
@@ -1459,9 +1448,6 @@ var iDrawRenderer = (function () {
|
|
|
1459
1448
|
|
|
1460
1449
|
var _a, _b, _c;
|
|
1461
1450
|
var requestAnimationFrame = window.requestAnimationFrame;
|
|
1462
|
-
var createUUID = index.uuid.createUUID;
|
|
1463
|
-
var deepClone = index.data.deepClone;
|
|
1464
|
-
var Context = index.Context;
|
|
1465
1451
|
var DrawStatus;
|
|
1466
1452
|
(function (DrawStatus) {
|
|
1467
1453
|
DrawStatus["NULL"] = "null";
|
|
@@ -1596,6 +1582,11 @@ var iDrawRenderer = (function () {
|
|
|
1596
1582
|
return Renderer;
|
|
1597
1583
|
}(RendererEvent));
|
|
1598
1584
|
|
|
1599
|
-
|
|
1585
|
+
var default_1 = /*#__PURE__*/Object.freeze({
|
|
1586
|
+
__proto__: null,
|
|
1587
|
+
Renderer: Renderer
|
|
1588
|
+
});
|
|
1589
|
+
|
|
1590
|
+
return default_1;
|
|
1600
1591
|
|
|
1601
1592
|
})();
|
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawRenderer=function(){'use strict';var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};var e=function(){return e=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},e.apply(this,arguments)};function o(t,e,o,r){return new(o||(o=Promise))((function(n,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))}function r(t,e){var o,r,n,i,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;a;)try{if(o=1,r&&(n=2&i[0]?r.return:i[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,i[1])).done)return n;switch(r=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){a.label=i[1];break}if(6===i[0]&&a.label<n[1]){a.label=n[1],n=i;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(i);break}n[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{o=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function n(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function i(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var a={type:function(t,e){var o=i(t);return!0===e?o.toLocaleLowerCase():o},array:function(t){return'Array'===i(t)},json:function(t){return'Object'===i(t)},function:function(t){return'Function'===i(t)},asyncFunction:function(t){return'AsyncFunction'===i(t)},string:function(t){return'String'===i(t)},number:function(t){return'Number'===i(t)},undefined:function(t){return'Undefined'===i(t)},null:function(t){return'Null'===i(t)},promise:function(t){return'Promise'===i(t)}},s=function(){return s=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},s.apply(this,arguments)};function u(t,e,o,r){return new(o||(o=Promise))((function(n,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))}function c(t,e){var o,r,n,i,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;a;)try{if(o=1,r&&(n=2&i[0]?r.return:i[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,i[1])).done)return n;switch(r=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){a.label=i[1];break}if(6===i[0]&&a.label<n[1]){a.label=n[1],n=i;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(i);break}n[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{o=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function l(t,e){var o=e.width,r=e.height;return new Promise((function(e,n){var i="\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(o||'',"\" height = \"").concat(r||'',"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n ").concat(t,"\n </div>\n </foreignObject>\n </svg>\n "),a=new Blob([i],{type:'image/svg+xml;charset=utf-8'}),s=new FileReader;s.readAsDataURL(a),s.onload=function(t){var o,r=null===(o=null==t?void 0:t.target)||void 0===o?void 0:o.result;e(r)},s.onerror=function(t){n(t)}}))}function h(t){return new Promise((function(e,o){var r=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),n=new FileReader;n.readAsDataURL(r),n.onload=function(t){var o,r=null===(o=null==t?void 0:t.target)||void 0===o?void 0:o.result;e(r)},n.onerror=function(t){o(t)}}))}var f=window.Image;function d(t){return new Promise((function(e,o){var r=new f;r.onload=function(){e(r)},r.onabort=o,r.onerror=o,r.src=t}))}var p=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.getContext=function(){return this._ctx},t.prototype.resetSize=function(t){this._opts=s(s({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=s(s({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,o,r,n,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(o),r,n,i)},t.prototype.rect=function(t,e,o,r){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(r))},t.prototype.fillRect=function(t,e,o,r){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(r))},t.prototype.clearRect=function(t,e,o,r){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(r))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,o,r,n){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(r),this._doSize(n))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var o=t[0],r=t[1],n=t[2],i=t[3],a=t[4],s=t[t.length-4],u=t[t.length-3],c=t[t.length-2],l=t[t.length-1];return 9===t.length?this._ctx.drawImage(o,this._doSize(r),this._doSize(n),this._doSize(i),this._doSize(a),this._doSize(s),this._doSize(u),this._doSize(c),this._doSize(l)):this._ctx.drawImage(o,this._doSize(s),this._doSize(u),this._doSize(c),this._doSize(l))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,o,r){return void 0!==r?this._ctx.fillText(t,this._doSize(e),this._doSize(o),this._doSize(r)):this._ctx.fillText(t,this._doSize(e),this._doSize(o))},t.prototype.strokeText=function(t,e,o,r){return void 0!==r?this._ctx.strokeText(t,this._doSize(e),this._doSize(o),this._doSize(r)):this._ctx.strokeText(t,this._doSize(e),this._doSize(o))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push("".concat(t.fontWeight)),e.push("".concat(this._doSize(t.fontSize||12),"px")),e.push("".concat(t.fontFamily||'sans-serif')),this._ctx.font="".concat(e.join(' '))},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,o,r,n,i,a,s){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(r),n,i,a,s)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,o=e.scale,r=(t-e.scrollX)/o;return this._doSize(r)},t.prototype._doY=function(t){var e=this._transform,o=e.scale,r=(t-e.scrollY)/o;return this._doSize(r)},t}();function g(t){return'number'==typeof t&&(t>0||t<=0)}function v(t){return'number'==typeof t&&t>=0}function _(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(t))}function y(t){return'string'==typeof t&&/^(data:image\/)/.test("".concat(t))}var m={x:function(t){return g(t)},y:function(t){return g(t)},w:v,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:g,borderWidth:function(t){return v(t)},borderRadius:function(t){return g(t)&&t>=0},color:function(t){return n(t)},imageSrc:function(t){return y(t)||_(t)},imageURL:_,imageBase64:y,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test("".concat(t).trim())&&/<\/[\s]{0,}svg>$/i.test("".concat(t).trim())},html:function(t){var e=!1;if('string'==typeof t){var o=document.createElement('div');o.innerHTML=t,o.children.length>0&&(e=!0),o=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return g(t)&&t>0},lineHeight:function(t){return g(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return g(t)&&t>0}};function w(t){void 0===t&&(t={});var e=t.borderColor,o=t.borderRadius,r=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!m.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!m.number(o))&&!(t.hasOwnProperty('borderWidth')&&!m.number(r)))}var x={attrs:function(t){var e=t.x,o=t.y,r=t.w,n=t.h,i=t.angle;return!!(m.x(e)&&m.y(o)&&m.w(r)&&m.h(n)&&m.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,o=t.color,r=t.fontSize,n=t.lineHeight,i=t.fontFamily,a=t.textAlign,s=t.fontWeight,u=t.bgColor,c=t.strokeWidth,l=t.strokeColor;return!!m.text(e)&&(!!m.color(o)&&(!!m.fontSize(r)&&(!(t.hasOwnProperty('bgColor')&&!m.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!m.fontWeight(s))&&(!(t.hasOwnProperty('lineHeight')&&!m.lineHeight(n))&&(!(t.hasOwnProperty('fontFamily')&&!m.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!m.textAlign(a))&&(!(t.hasOwnProperty('strokeWidth')&&!m.strokeWidth(c))&&(!(t.hasOwnProperty('strokeColor')&&!m.color(l))&&!!w(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!m.color(e))&&!!w(t)},circleDesc:function(t){var e=t.bgColor,o=t.borderColor,r=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!m.color(e))&&(!(t.hasOwnProperty('borderColor')&&!m.color(o))&&!(t.hasOwnProperty('borderWidth')&&!m.number(r)))},imageDesc:function(t){var e=t.src;return!!m.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!m.svg(e)},htmlDesc:function(t){var e=t.html;return!!m.html(e)}},S={is:m,check:x,time:{delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,o){return function r(n){var i=t[n];n===t.length&&o&&(i=o);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,r.bind(null,n+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var o=-1;return function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];o>0||(o=setTimeout((function(){t.apply(void 0,r),o=-1}),e))}}},loader:{loadImage:d,loadSVG:function(t){return u(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return[4,h(t)];case 1:return[4,d(e.sent())];case 2:return[2,e.sent()]}}))}))},loadHTML:function(t,e){return u(this,void 0,void 0,(function(){return c(this,(function(o){switch(o.label){case 0:return[4,l(t,e)];case 1:return[4,d(o.sent())];case 2:return[2,o.sent()]}}))}))}},file:{downloadImageFromCanvas:function(t,e){var o=e.filename,r=e.type,n=void 0===r?'image/jpeg':r,i=t.toDataURL(n),a=document.createElement('a');a.href=i,a.download=o;var s=document.createEvent('MouseEvents');s.initEvent('click',!0,!1),a.dispatchEvent(s)}},color:{toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:n},uuid:{createUUID:function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return"".concat(t()).concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t()).concat(t()).concat(t())}},istype:a,data:{deepClone:function(t){return function t(e){var o,r=(o=e,Object.prototype.toString.call(o).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(r)>=0)return e;if('Array'===r){var n=[];return e.forEach((function(e){n.push(t(e))})),n}if('Object'===r){var i={};return Object.keys(e).forEach((function(o){i[o]=t(e[o])})),i}}(t)}},Context:p};function b(t,e,o){var r=function(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}(e),n=function(t){return t/180*Math.PI}(e.angle||0);return function(t,e,o,r){e&&(o>0||o<0)&&(t.translate(e.x,e.y),t.rotate(o),t.translate(-e.x,-e.y));r(t),e&&(o>0||o<0)&&(t.translate(e.x,e.y),t.rotate(-o),t.translate(-e.x,-e.y))}(t,r,n||0,o)}var z=S.is,L=S.istype,D=S.color;function E(t){t.setFillStyle('#000000'),t.setStrokeStyle('#000000'),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor('#00000000'),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}function C(t,e,o){E(t),function(t,e){E(t),b(t,e,(function(){if(e.desc.borderWidth&&e.desc.borderWidth>0){var o=e.desc.borderWidth,r='#000000';!0===D.isColorStr(e.desc.borderColor)&&(r=e.desc.borderColor);var n=e.x-o/2,i=e.y-o/2,a=e.w+o,s=e.h+o,u=e.desc.borderRadius||0;(u=Math.min(u,a/2,s/2))<a/2&&u<s/2&&(u+=o/2);var c=e.desc;void 0!==c.shadowColor&&D.isColorStr(c.shadowColor)&&t.setShadowColor(c.shadowColor),void 0!==c.shadowOffsetX&&z.number(c.shadowOffsetX)&&t.setShadowOffsetX(c.shadowOffsetX),void 0!==c.shadowOffsetY&&z.number(c.shadowOffsetY)&&t.setShadowOffsetY(c.shadowOffsetY),void 0!==c.shadowBlur&&z.number(c.shadowBlur)&&t.setShadowBlur(c.shadowBlur),t.beginPath(),t.setLineWidth(o),t.setStrokeStyle(r),t.moveTo(n+u,i),t.arcTo(n+a,i,n+a,i+s,u),t.arcTo(n+a,i+s,n,i+s,u),t.arcTo(n,i+s,n,i,u),t.arcTo(n,i,n+a,i,u),t.closePath(),t.stroke()}}))}(t,e),E(t),b(t,e,(function(){var r=e.x,n=e.y,i=e.w,a=e.h,s=e.desc.borderRadius||0;(i<2*(s=Math.min(s,i/2,a/2))||a<2*s)&&(s=0),t.beginPath(),t.moveTo(r+s,n),t.arcTo(r+i,n,r+i,n+a,s),t.arcTo(r+i,n+a,r,n+a,s),t.arcTo(r,n+a,r,n,s),t.arcTo(r,n,r+i,n,s),t.closePath(),('string'==typeof o||['CanvasPattern'].includes(L.type(o)))&&t.setFillStyle(o),t.fill()}))}function O(t,e){C(t,e,e.desc.bgColor)}function P(t,e,o){var r=o.getContent(e.uuid);b(t,e,(function(){r&&t.drawImage(r,e.x,e.y,e.w,e.h)}))}function k(t,e,o){var r=o.getContent(e.uuid);b(t,e,(function(){r&&t.drawImage(r,e.x,e.y,e.w,e.h)}))}function T(t,e,o){var r=o.getContent(e.uuid);b(t,e,(function(){r&&t.drawImage(r,e.x,e.y,e.w,e.h)}))}var W=S.is,R=S.color;function F(t,o,r){E(t),C(t,o,o.desc.bgColor||'transparent'),b(t,o,(function(){var r=e({fontSize:12,fontFamily:'sans-serif',textAlign:'center'},o.desc);t.setFillStyle(o.desc.color),t.setTextBaseline('top'),t.setFont({fontWeight:r.fontWeight,fontSize:r.fontSize,fontFamily:r.fontFamily});var n=r.text.replace(/\r\n/gi,'\n'),i=r.lineHeight||r.fontSize,a=n.split('\n'),s=[],u=0;a.forEach((function(e,r){var n='';if(e.length>0){for(var c=0;c<e.length&&(t.measureText(n+(e[c]||'')).width<t.calcDeviceNum(o.w)?n+=e[c]||'':(s.push({text:n,width:t.calcScreenNum(t.measureText(n).width)}),n=e[c]||'',u++),!((u+1)*i>o.h));c++)if(e.length-1===c&&(u+1)*i<o.h){s.push({text:n,width:t.calcScreenNum(t.measureText(n).width)}),r<a.length-1&&u++;break}}else s.push({text:'',width:0})}));var c=o.y;if(s.length*i<o.h&&(c+=(o.h-s.length*i)/2),void 0!==r.textShadowColor&&R.isColorStr(r.textShadowColor)&&t.setShadowColor(r.textShadowColor),void 0!==r.textShadowOffsetX&&W.number(r.textShadowOffsetX)&&t.setShadowOffsetX(r.textShadowOffsetX),void 0!==r.textShadowOffsetY&&W.number(r.textShadowOffsetY)&&t.setShadowOffsetY(r.textShadowOffsetY),void 0!==r.textShadowBlur&&W.number(r.textShadowBlur)&&t.setShadowBlur(r.textShadowBlur),s.forEach((function(e,n){var a=o.x;'center'===r.textAlign?a=o.x+(o.w-e.width)/2:'right'===r.textAlign&&(a=o.x+(o.w-e.width)),t.fillText(e.text,a,c+i*n)})),E(t),R.isColorStr(r.strokeColor)&&void 0!==r.strokeWidth&&r.strokeWidth>0){var l=o.y;s.length*i<o.h&&(l+=(o.h-s.length*i)/2),s.forEach((function(e,n){var a=o.x;'center'===r.textAlign?a=o.x+(o.w-e.width)/2:'right'===r.textAlign&&(a=o.x+(o.w-e.width)),void 0!==r.strokeColor&&t.setStrokeStyle(r.strokeColor),void 0!==r.strokeWidth&&r.strokeWidth>0&&t.setLineWidth(r.strokeWidth),t.strokeText(e.text,a,l+i*n)}))}}))}function A(t,e){E(t),b(t,e,(function(t){var o=e.x,r=e.y,n=e.w,i=e.h,a=e.desc,s=a.bgColor,u=void 0===s?'#000000':s,c=a.borderColor,l=void 0===c?'#000000':c,h=a.borderWidth,f=void 0===h?0:h,d=n/2,p=i/2,g=o+d,v=r+p;if(f&&f>0){var _=f/2+d,y=f/2+p;t.beginPath(),t.setStrokeStyle(l),t.setLineWidth(f),t.ellipse(g,v,_,y,0,0,2*Math.PI),t.closePath(),t.stroke()}t.beginPath(),t.setFillStyle(u),t.ellipse(g,v,d,p,0,0,2*Math.PI),t.closePath(),t.fill()}))}var I=S.color.isColorStr;function H(t,e,o){var r;E(t);var n=t.getSize();if(t.clearRect(0,0,n.contextWidth,n.contextHeight),'string'==typeof e.bgColor&&I(e.bgColor)&&function(t,e){var o=t.getSize();t.setFillStyle(e),t.fillRect(0,0,o.contextWidth,o.contextHeight)}(t,e.bgColor),e.elements.length>0)for(var i=0;i<e.elements.length;i++){var a=e.elements[i];if(!0!==(null===(r=null==a?void 0:a.operation)||void 0===r?void 0:r.invisible))switch(a.type){case'rect':O(t,a);break;case'text':F(t,a);break;case'image':P(t,a,o);break;case'svg':k(t,a,o);break;case'html':T(t,a,o);break;case'circle':A(t,a)}}}var U=function(){function t(){this._listeners=new Map}return t.prototype.on=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);null==o||o.push(e),this._listeners.set(t,o||[])}else this._listeners.set(t,[e])},t.prototype.off=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);if(Array.isArray(o))for(var r=0;r<(null==o?void 0:o.length);r++)if(o[r]===e){o.splice(r,1);break}this._listeners.set(t,o||[])}},t.prototype.trigger=function(t,e){var o=this._listeners.get(t);return!!Array.isArray(o)&&(o.forEach((function(t){t(e)})),!0)},t.prototype.has=function(t){if(this._listeners.has(t)){var e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1},t}();var j,N=S.loader,B=N.loadImage,M=N.loadSVG,X=N.loadHTML,Y=S.data.deepClone;!function(t){t.FREE="free",t.LOADING="loading",t.COMPLETE="complete"}(j||(j={}));var Q,G,Z,q,V=function(){function t(t){this._currentLoadData={},this._currentUUIDQueue=[],this._storageLoadData={},this._status=j.FREE,this._waitingLoadQueue=[],this._opts=t,this._event=new U,this._waitingLoadQueue=[]}return t.prototype.load=function(t,e){var o=this._resetLoadData(t,e),r=o[0],n=o[1];this._status===j.FREE||this._status===j.COMPLETE?(this._currentUUIDQueue=r,this._currentLoadData=n,this._loadTask()):this._status===j.LOADING&&r.length>0&&this._waitingLoadQueue.push({uuidQueue:r,loadData:n})},t.prototype.on=function(t,e){this._event.on(t,e)},t.prototype.off=function(t,e){this._event.off(t,e)},t.prototype.isComplete=function(){return this._status===j.COMPLETE},t.prototype.getContent=function(t){var e;return'loaded'===(null===(e=this._storageLoadData[t])||void 0===e?void 0:e.status)?this._storageLoadData[t].content:null},t.prototype._resetLoadData=function(t,e){for(var o={},r=[],n=this._storageLoadData,i=t.elements.length-1;i>=0;i--){var a=t.elements[i];['image','svg','html'].includes(a.type)&&(n[a.uuid]?e.includes(a.uuid)&&(o[a.uuid]=this._createEmptyLoadItem(a),r.push(a.uuid)):(o[a.uuid]=this._createEmptyLoadItem(a),r.push(a.uuid)))}return[r,o]},t.prototype._createEmptyLoadItem=function(t){var e='',o=t.type,r=t.w,n=t.h;if('image'===t.type)e=(i=t).desc.src||'';else if('svg'===t.type){e=(i=t).desc.svg||''}else if('html'===t.type){var i;e=function(t){return t.replace(/<script[\s\S]*?<\/script>/gi,'')}((i=t).desc.html||''),r=i.desc.width||t.w,n=i.desc.height||t.h}return{uuid:t.uuid,type:o,status:'null',content:null,source:e,elemW:r,elemH:n,element:Y(t)}},t.prototype._loadTask=function(){var t=this;if(this._status!==j.LOADING){if(this._status=j.LOADING,0===this._currentUUIDQueue.length){if(0===this._waitingLoadQueue.length)return this._status=j.COMPLETE,void this._event.trigger('complete',void 0);var e=this._waitingLoadQueue.shift();if(e){var o=e.uuidQueue,r=e.loadData;this._currentLoadData=r,this._currentUUIDQueue=o}}var n=this._opts.maxParallelNum,i=this._currentUUIDQueue.splice(0,n),a={};i.forEach((function(t,e){a[t]=e}));var s=[],u=function(){if(s.length>=n)return!1;if(0===i.length)return!0;for(var e=function(e){var o=i.shift();if(void 0===o)return"break";s.push(o),t._loadElementSource(t._currentLoadData[o]).then((function(e){var r,n;s.splice(s.indexOf(o),1);var a=u();t._storageLoadData[o]={uuid:o,type:t._currentLoadData[o].type,status:'loaded',content:e,source:t._currentLoadData[o].source,elemW:t._currentLoadData[o].elemW,elemH:t._currentLoadData[o].elemH,element:t._currentLoadData[o].element},0===s.length&&0===i.length&&!0===a&&(t._status=j.FREE,t._loadTask()),t._event.trigger('load',{uuid:null===(r=t._storageLoadData[o])||void 0===r?void 0:r.uuid,type:t._storageLoadData[o].type,status:t._storageLoadData[o].status,content:t._storageLoadData[o].content,source:t._storageLoadData[o].source,elemW:t._storageLoadData[o].elemW,elemH:t._storageLoadData[o].elemH,element:null===(n=t._storageLoadData[o])||void 0===n?void 0:n.element})})).catch((function(e){var r,n,a,c,l,h,f,d,p,g,v,_;console.warn(e),s.splice(s.indexOf(o),1);var y=u();t._currentLoadData[o]&&(t._storageLoadData[o]={uuid:o,type:null===(r=t._currentLoadData[o])||void 0===r?void 0:r.type,status:'fail',content:null,error:e,source:null===(n=t._currentLoadData[o])||void 0===n?void 0:n.source,elemW:null===(a=t._currentLoadData[o])||void 0===a?void 0:a.elemW,elemH:null===(c=t._currentLoadData[o])||void 0===c?void 0:c.elemH,element:null===(l=t._currentLoadData[o])||void 0===l?void 0:l.element}),0===s.length&&0===i.length&&!0===y&&(t._status=j.FREE,t._loadTask()),t._currentLoadData[o]&&t._event.trigger('error',{uuid:o,type:null===(h=t._storageLoadData[o])||void 0===h?void 0:h.type,status:null===(f=t._storageLoadData[o])||void 0===f?void 0:f.status,content:null===(d=t._storageLoadData[o])||void 0===d?void 0:d.content,source:null===(p=t._storageLoadData[o])||void 0===p?void 0:p.source,elemW:null===(g=t._storageLoadData[o])||void 0===g?void 0:g.elemW,elemH:null===(v=t._storageLoadData[o])||void 0===v?void 0:v.elemH,element:null===(_=t._storageLoadData[o])||void 0===_?void 0:_.element})}))},o=s.length;o<n;o++){if("break"===e())break}return!1};u()}},t.prototype._loadElementSource=function(t){return o(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return t&&'image'===t.type?[4,B(t.source)]:[3,2];case 1:case 3:case 5:return[2,e.sent()];case 2:return t&&'svg'===t.type?[4,M(t.source)]:[3,4];case 4:return t&&'html'===t.type?[4,X(t.source,{width:t.elemW,height:t.elemH})]:[3,6];case 6:throw Error('Element\'s source is not support!')}}))}))},t}(),$=function(){function t(){this._listeners=new Map}return t.prototype.on=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);null==o||o.push(e),this._listeners.set(t,o||[])}else this._listeners.set(t,[e])},t.prototype.off=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);if(Array.isArray(o))for(var r=0;r<(null==o?void 0:o.length);r++)if(o[r]===e){o.splice(r,1);break}this._listeners.set(t,o||[])}},t.prototype.trigger=function(t,e){var o=this._listeners.get(t);return!!Array.isArray(o)&&(o.forEach((function(t){t(e)})),!0)},t.prototype.has=function(t){if(this._listeners.has(t)){var e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1},t}(),J=Symbol('_queue'),K=Symbol('_ctx'),tt=Symbol('_status'),et=Symbol('_loader'),ot=Symbol('_opts'),rt=Symbol('_freeze'),nt=Symbol('_drawFrame'),it=Symbol('_retainQueueOneItem'),at=window.requestAnimationFrame,st=S.uuid.createUUID,ut=S.data.deepClone,ct=S.Context;return function(t){t.NULL="null",t.FREE="free",t.DRAWING="drawing",t.FREEZE="freeze"}(q||(q={})),function(e){function o(t){var o=e.call(this)||this;return o[Q]=[],o[G]=null,o[Z]=q.NULL,o[ot]=t,o[et]=new V({maxParallelNum:6}),o[et].on('load',(function(t){o[nt](),o.trigger('load',{element:t.element})})),o[et].on('error',(function(t){o.trigger('error',{element:t.element,error:t.error})})),o[et].on('complete',(function(){o.trigger('loadComplete',{t:Date.now()})})),o}return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function r(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}(o,e),o.prototype.render=function(t,e,o){var r=(o||{}).changeResourceUUIDs,n=void 0===r?[]:r;this[tt]=q.FREE;var i=ut(e);if(Array.isArray(i.elements)&&i.elements.forEach((function(t){'string'==typeof t.uuid&&t.uuid||(t.uuid=st())})),!this[K])if(this[ot]&&'[object HTMLCanvasElement]'===Object.prototype.toString.call(t)){var a=this[ot],s=a.width,u=a.height,c=a.contextWidth,l=a.contextHeight,h=a.devicePixelRatio,f=t;f.width=s*h,f.height=u*h;var d=f.getContext('2d');this[K]=new ct(d,{width:s,height:u,contextWidth:c||s,contextHeight:l||u,devicePixelRatio:h})}else t&&(this[K]=t);if(![q.FREEZE].includes(this[tt])){var p=ut({data:i});this[J].push(p),this[nt](),this[et].load(i,n||[])}},o.prototype.getContext=function(){return this[K]},o.prototype.thaw=function(){this[tt]=q.FREE},o.prototype[(Q=J,G=K,Z=tt,rt)]=function(){this[tt]=q.FREEZE},o.prototype[nt]=function(){var t=this;this[tt]!==q.FREEZE&&at((function(){if(t[tt]!==q.FREEZE){var e=t[K],o=t[J][0],r=!1;t[J].length>1?o=t[J].shift():r=!0,!0!==t[et].isComplete()?(t[nt](),o&&e&&H(e,o.data,t[et])):o&&e?(H(e,o.data,t[et]),t[it](),r?t[tt]=q.FREE:t[nt]()):t[tt]=q.FREE,t.trigger('drawFrame',{t:Date.now()}),!0===t[et].isComplete()&&1===t[J].length&&t[tt]===q.FREE&&(e&&t[J][0]&&t[J][0].data&&H(e,t[J][0].data,t[et]),t.trigger('drawFrameComplete',{t:Date.now()}),t[rt]())}}))},o.prototype[it]=function(){if(!(this[J].length<=1)){var t=ut(this[J][this[J].length-1]);this[J]=[t]}},o}($)}();
|
|
1
|
+
var iDrawRenderer=function(){'use strict';var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};var e=function(){return e=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},e.apply(this,arguments)};function o(t,e,o,n){return new(o||(o=Promise))((function(r,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function n(t,e){var o,n,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(r=2&i[0]?n.return:i[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,i[1])).done)return r;switch(n=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{o=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function r(t){return'string'==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function i(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return"".concat(t()).concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t(),"-").concat(t()).concat(t()).concat(t())}function s(t){return function t(e){var o,n=(o=e,Object.prototype.toString.call(o).replace(/[\]|\[]{1,1}/gi,'').split(' ')[1]);if(['Null','Number','String','Boolean','Undefined'].indexOf(n)>=0)return e;if('Array'===n){var r=[];return e.forEach((function(e){r.push(t(e))})),r}if('Object'===n){var i={};return Object.keys(e).forEach((function(o){i[o]=t(e[o])})),i}}(t)}function a(t){return(Object.prototype.toString.call(t)||'').replace(/(\[object|\])/gi,'').trim()}var u={type:function(t,e){var o=a(t);return!0===e?o.toLocaleLowerCase():o},array:function(t){return'Array'===a(t)},json:function(t){return'Object'===a(t)},function:function(t){return'Function'===a(t)},asyncFunction:function(t){return'AsyncFunction'===a(t)},string:function(t){return'String'===a(t)},number:function(t){return'Number'===a(t)},undefined:function(t){return'Undefined'===a(t)},null:function(t){return'Null'===a(t)},promise:function(t){return'Promise'===a(t)}},c=function(){return c=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},c.apply(this,arguments)};function l(t,e,o,n){return new(o||(o=Promise))((function(r,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))}function h(t,e){var o,n,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(r=2&i[0]?n.return:i[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,i[1])).done)return r;switch(n=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{o=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function f(t,e){var o=e.width,n=e.height;return new Promise((function(e,r){var i="\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(o||'',"\" height = \"").concat(n||'',"\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n ").concat(t,"\n </div>\n </foreignObject>\n </svg>\n "),s=new Blob([i],{type:'image/svg+xml;charset=utf-8'}),a=new FileReader;a.readAsDataURL(s),a.onload=function(t){var o,n=null===(o=null==t?void 0:t.target)||void 0===o?void 0:o.result;e(n)},a.onerror=function(t){r(t)}}))}function d(t){return new Promise((function(e,o){var n=new Blob([t],{type:'image/svg+xml;charset=utf-8'}),r=new FileReader;r.readAsDataURL(n),r.onload=function(t){var o,n=null===(o=null==t?void 0:t.target)||void 0===o?void 0:o.result;e(n)},r.onerror=function(t){o(t)}}))}var p=window.Image;function g(t){return new Promise((function(e,o){var n=new p;n.onload=function(){e(n)},n.onabort=o,n.onerror=o,n.src=t}))}function _(t){return l(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,d(t)];case 1:return[4,g(e.sent())];case 2:return[2,e.sent()]}}))}))}function v(t,e){return l(this,void 0,void 0,(function(){return h(this,(function(o){switch(o.label){case 0:return[4,f(t=t.replace(/\&/gi,'&'),e)];case 1:return[4,g(o.sent())];case 2:return[2,o.sent()]}}))}))}var y=function(){function t(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}return t.prototype.getContext=function(){return this._ctx},t.prototype.resetSize=function(t){this._opts=c(c({},this._opts),t)},t.prototype.calcDeviceNum=function(t){return t*this._opts.devicePixelRatio},t.prototype.calcScreenNum=function(t){return t/this._opts.devicePixelRatio},t.prototype.getSize=function(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}},t.prototype.setTransform=function(t){this._transform=c(c({},this._transform),t)},t.prototype.getTransform=function(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}},t.prototype.setFillStyle=function(t){this._ctx.fillStyle=t},t.prototype.fill=function(t){return this._ctx.fill(t||'nonzero')},t.prototype.arc=function(t,e,o,n,r,i){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(o),n,r,i)},t.prototype.rect=function(t,e,o,n){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(n))},t.prototype.fillRect=function(t,e,o,n){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(n))},t.prototype.clearRect=function(t,e,o,n){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(n))},t.prototype.beginPath=function(){return this._ctx.beginPath()},t.prototype.closePath=function(){return this._ctx.closePath()},t.prototype.lineTo=function(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))},t.prototype.moveTo=function(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))},t.prototype.arcTo=function(t,e,o,n,r){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(n),this._doSize(r))},t.prototype.setLineWidth=function(t){return this._ctx.lineWidth=this._doSize(t)},t.prototype.setLineDash=function(t){var e=this;return this._ctx.setLineDash(t.map((function(t){return e._doSize(t)})))},t.prototype.isPointInPath=function(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))},t.prototype.isPointInPathWithoutScroll=function(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))},t.prototype.setStrokeStyle=function(t){this._ctx.strokeStyle=t},t.prototype.stroke=function(){return this._ctx.stroke()},t.prototype.translate=function(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))},t.prototype.rotate=function(t){return this._ctx.rotate(t)},t.prototype.drawImage=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var o=t[0],n=t[1],r=t[2],i=t[3],s=t[4],a=t[t.length-4],u=t[t.length-3],c=t[t.length-2],l=t[t.length-1];return 9===t.length?this._ctx.drawImage(o,this._doSize(n),this._doSize(r),this._doSize(i),this._doSize(s),this._doSize(a),this._doSize(u),this._doSize(c),this._doSize(l)):this._ctx.drawImage(o,this._doSize(a),this._doSize(u),this._doSize(c),this._doSize(l))},t.prototype.createPattern=function(t,e){return this._ctx.createPattern(t,e)},t.prototype.measureText=function(t){return this._ctx.measureText(t)},t.prototype.setTextAlign=function(t){this._ctx.textAlign=t},t.prototype.fillText=function(t,e,o,n){return void 0!==n?this._ctx.fillText(t,this._doSize(e),this._doSize(o),this._doSize(n)):this._ctx.fillText(t,this._doSize(e),this._doSize(o))},t.prototype.strokeText=function(t,e,o,n){return void 0!==n?this._ctx.strokeText(t,this._doSize(e),this._doSize(o),this._doSize(n)):this._ctx.strokeText(t,this._doSize(e),this._doSize(o))},t.prototype.setFont=function(t){var e=[];'bold'===t.fontWeight&&e.push("".concat(t.fontWeight)),e.push("".concat(this._doSize(t.fontSize||12),"px")),e.push("".concat(t.fontFamily||'sans-serif')),this._ctx.font="".concat(e.join(' '))},t.prototype.setTextBaseline=function(t){this._ctx.textBaseline=t},t.prototype.setGlobalAlpha=function(t){this._ctx.globalAlpha=t},t.prototype.save=function(){this._ctx.save()},t.prototype.restore=function(){this._ctx.restore()},t.prototype.scale=function(t,e){this._ctx.scale(t,e)},t.prototype.setShadowColor=function(t){this._ctx.shadowColor=t},t.prototype.setShadowOffsetX=function(t){this._ctx.shadowOffsetX=this._doSize(t)},t.prototype.setShadowOffsetY=function(t){this._ctx.shadowOffsetY=this._doSize(t)},t.prototype.setShadowBlur=function(t){this._ctx.shadowBlur=this._doSize(t)},t.prototype.ellipse=function(t,e,o,n,r,i,s,a){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(o),this._doSize(n),r,i,s,a)},t.prototype._doSize=function(t){return this._opts.devicePixelRatio*t},t.prototype._doX=function(t){var e=this._transform,o=e.scale,n=(t-e.scrollX)/o;return this._doSize(n)},t.prototype._doY=function(t){var e=this._transform,o=e.scale,n=(t-e.scrollY)/o;return this._doSize(n)},t}();function m(t){return'number'==typeof t&&(t>0||t<=0)}function w(t){return'number'==typeof t&&t>=0}function x(t){return'string'==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(t))}function S(t){return'string'==typeof t&&/^(data:image\/)/.test("".concat(t))}var b={x:function(t){return m(t)},y:function(t){return m(t)},w:w,h:function(t){return'number'==typeof t&&t>=0},angle:function(t){return'number'==typeof t&&t>=-360&&t<=360},number:m,borderWidth:function(t){return w(t)},borderRadius:function(t){return m(t)&&t>=0},color:function(t){return r(t)},imageSrc:function(t){return S(t)||x(t)},imageURL:x,imageBase64:S,svg:function(t){return'string'==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test("".concat(t).trim())&&/<\/[\s]{0,}svg>$/i.test("".concat(t).trim())},html:function(t){var e=!1;if('string'==typeof t){var o=document.createElement('div');o.innerHTML=t,o.children.length>0&&(e=!0),o=null}return e},text:function(t){return'string'==typeof t},fontSize:function(t){return m(t)&&t>0},lineHeight:function(t){return m(t)&&t>0},textAlign:function(t){return['center','left','right'].includes(t)},fontFamily:function(t){return'string'==typeof t&&t.length>0},fontWeight:function(t){return['bold'].includes(t)},strokeWidth:function(t){return m(t)&&t>0}};function z(t){void 0===t&&(t={});var e=t.borderColor,o=t.borderRadius,n=t.borderWidth;return!(t.hasOwnProperty('borderColor')&&!b.color(e))&&(!(t.hasOwnProperty('borderRadius')&&!b.number(o))&&!(t.hasOwnProperty('borderWidth')&&!b.number(n)))}var L={attrs:function(t){var e=t.x,o=t.y,n=t.w,r=t.h,i=t.angle;return!!(b.x(e)&&b.y(o)&&b.w(n)&&b.h(r)&&b.angle(i))&&(i>=-360&&i<=360)},textDesc:function(t){var e=t.text,o=t.color,n=t.fontSize,r=t.lineHeight,i=t.fontFamily,s=t.textAlign,a=t.fontWeight,u=t.bgColor,c=t.strokeWidth,l=t.strokeColor;return!!b.text(e)&&(!!b.color(o)&&(!!b.fontSize(n)&&(!(t.hasOwnProperty('bgColor')&&!b.color(u))&&(!(t.hasOwnProperty('fontWeight')&&!b.fontWeight(a))&&(!(t.hasOwnProperty('lineHeight')&&!b.lineHeight(r))&&(!(t.hasOwnProperty('fontFamily')&&!b.fontFamily(i))&&(!(t.hasOwnProperty('textAlign')&&!b.textAlign(s))&&(!(t.hasOwnProperty('strokeWidth')&&!b.strokeWidth(c))&&(!(t.hasOwnProperty('strokeColor')&&!b.color(l))&&!!z(t))))))))))},rectDesc:function(t){var e=t.bgColor;return!(t.hasOwnProperty('bgColor')&&!b.color(e))&&!!z(t)},circleDesc:function(t){var e=t.bgColor,o=t.borderColor,n=t.borderWidth;return!(t.hasOwnProperty('bgColor')&&!b.color(e))&&(!(t.hasOwnProperty('borderColor')&&!b.color(o))&&!(t.hasOwnProperty('borderWidth')&&!b.number(n)))},imageDesc:function(t){var e=t.src;return!!b.imageSrc(e)},svgDesc:function(t){var e=t.svg;return!!b.svg(e)},htmlDesc:function(t){var e=t.html;return!!b.html(e)}};function D(t,e,o){var n=function(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}(e),r=function(t){return t/180*Math.PI}(e.angle||0);return function(t,e,o,n){e&&(o>0||o<0)&&(t.translate(e.x,e.y),t.rotate(o),t.translate(-e.x,-e.y));n(t),e&&(o>0||o<0)&&(t.translate(e.x,e.y),t.rotate(-o),t.translate(-e.x,-e.y))}(t,n,r||0,o)}function E(t){t.setFillStyle('#000000'),t.setStrokeStyle('#000000'),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor('#00000000'),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}function O(t,e,o){E(t),function(t,e){E(t),D(t,e,(function(){if(e.desc.borderWidth&&e.desc.borderWidth>0){var o=e.desc.borderWidth,n='#000000';!0===r(e.desc.borderColor)&&(n=e.desc.borderColor);var i=e.x-o/2,s=e.y-o/2,a=e.w+o,u=e.h+o,c=e.desc.borderRadius||0;(c=Math.min(c,a/2,u/2))<a/2&&c<u/2&&(c+=o/2);var l=e.desc;void 0!==l.shadowColor&&r(l.shadowColor)&&t.setShadowColor(l.shadowColor),void 0!==l.shadowOffsetX&&b.number(l.shadowOffsetX)&&t.setShadowOffsetX(l.shadowOffsetX),void 0!==l.shadowOffsetY&&b.number(l.shadowOffsetY)&&t.setShadowOffsetY(l.shadowOffsetY),void 0!==l.shadowBlur&&b.number(l.shadowBlur)&&t.setShadowBlur(l.shadowBlur),t.beginPath(),t.setLineWidth(o),t.setStrokeStyle(n),t.moveTo(i+c,s),t.arcTo(i+a,s,i+a,s+u,c),t.arcTo(i+a,s+u,i,s+u,c),t.arcTo(i,s+u,i,s,c),t.arcTo(i,s,i+a,s,c),t.closePath(),t.stroke()}}))}(t,e),E(t),D(t,e,(function(){var n=e.x,r=e.y,i=e.w,s=e.h,a=e.desc.borderRadius||0;(i<2*(a=Math.min(a,i/2,s/2))||s<2*a)&&(a=0),t.beginPath(),t.moveTo(n+a,r),t.arcTo(n+i,r,n+i,r+s,a),t.arcTo(n+i,r+s,n,r+s,a),t.arcTo(n,r+s,n,r,a),t.arcTo(n,r,n+i,r,a),t.closePath(),('string'==typeof o||['CanvasPattern'].includes(u.type(o)))&&t.setFillStyle(o),t.fill()}))}function P(t,e){O(t,e,e.desc.bgColor)}function C(t,e,o){var n=o.getContent(e.uuid);D(t,e,(function(){n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function k(t,e,o){var n=o.getContent(e.uuid);D(t,e,(function(){n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function T(t,e,o){var n=o.getContent(e.uuid);D(t,e,(function(){n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function W(t,o,n){E(t),O(t,o,o.desc.bgColor||'transparent'),D(t,o,(function(){var n=e({fontSize:12,fontFamily:'sans-serif',textAlign:'center'},o.desc);t.setFillStyle(o.desc.color),t.setTextBaseline('top'),t.setFont({fontWeight:n.fontWeight,fontSize:n.fontSize,fontFamily:n.fontFamily});var i=n.text.replace(/\r\n/gi,'\n'),s=n.lineHeight||n.fontSize,a=i.split('\n'),u=[],c=0;a.forEach((function(e,n){var r='';if(e.length>0){for(var i=0;i<e.length&&(t.measureText(r+(e[i]||'')).width<t.calcDeviceNum(o.w)?r+=e[i]||'':(u.push({text:r,width:t.calcScreenNum(t.measureText(r).width)}),r=e[i]||'',c++),!((c+1)*s>o.h));i++)if(e.length-1===i&&(c+1)*s<o.h){u.push({text:r,width:t.calcScreenNum(t.measureText(r).width)}),n<a.length-1&&c++;break}}else u.push({text:'',width:0})}));var l=o.y;if(u.length*s<o.h&&(l+=(o.h-u.length*s)/2),void 0!==n.textShadowColor&&r(n.textShadowColor)&&t.setShadowColor(n.textShadowColor),void 0!==n.textShadowOffsetX&&b.number(n.textShadowOffsetX)&&t.setShadowOffsetX(n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&b.number(n.textShadowOffsetY)&&t.setShadowOffsetY(n.textShadowOffsetY),void 0!==n.textShadowBlur&&b.number(n.textShadowBlur)&&t.setShadowBlur(n.textShadowBlur),u.forEach((function(e,r){var i=o.x;'center'===n.textAlign?i=o.x+(o.w-e.width)/2:'right'===n.textAlign&&(i=o.x+(o.w-e.width)),t.fillText(e.text,i,l+s*r)})),E(t),r(n.strokeColor)&&void 0!==n.strokeWidth&&n.strokeWidth>0){var h=o.y;u.length*s<o.h&&(h+=(o.h-u.length*s)/2),u.forEach((function(e,r){var i=o.x;'center'===n.textAlign?i=o.x+(o.w-e.width)/2:'right'===n.textAlign&&(i=o.x+(o.w-e.width)),void 0!==n.strokeColor&&t.setStrokeStyle(n.strokeColor),void 0!==n.strokeWidth&&n.strokeWidth>0&&t.setLineWidth(n.strokeWidth),t.strokeText(e.text,i,h+s*r)}))}}))}function R(t,e){E(t),D(t,e,(function(t){var o=e.x,n=e.y,r=e.w,i=e.h,s=e.desc,a=s.bgColor,u=void 0===a?'#000000':a,c=s.borderColor,l=void 0===c?'#000000':c,h=s.borderWidth,f=void 0===h?0:h,d=r/2,p=i/2,g=o+d,_=n+p;if(f&&f>0){var v=f/2+d,y=f/2+p;t.beginPath(),t.setStrokeStyle(l),t.setLineWidth(f),t.ellipse(g,_,v,y,0,0,2*Math.PI),t.closePath(),t.stroke()}t.beginPath(),t.setFillStyle(u),t.ellipse(g,_,d,p,0,0,2*Math.PI),t.closePath(),t.fill()}))}function F(t,e,o){var n;E(t);var i=t.getSize();if(t.clearRect(0,0,i.contextWidth,i.contextHeight),'string'==typeof e.bgColor&&r(e.bgColor)&&function(t,e){var o=t.getSize();t.setFillStyle(e),t.fillRect(0,0,o.contextWidth,o.contextHeight)}(t,e.bgColor),e.elements.length>0)for(var s=0;s<e.elements.length;s++){var a=e.elements[s];if(!0!==(null===(n=null==a?void 0:a.operation)||void 0===n?void 0:n.invisible))switch(a.type){case'rect':P(t,a);break;case'text':W(t,a);break;case'image':C(t,a,o);break;case'svg':k(t,a,o);break;case'html':T(t,a,o);break;case'circle':R(t,a)}}}Object.freeze({__proto__:null,is:b,check:L,delay:function(t){return new Promise((function(e){setTimeout((function(){e()}),t)}))},compose:function(t){return function(e,o){return function n(r){var i=t[r];r===t.length&&o&&(i=o);if(!i)return Promise.resolve();try{return Promise.resolve(i(e,n.bind(null,r+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:function(t,e){var o=-1;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];o>0||(o=setTimeout((function(){t.apply(void 0,n),o=-1}),e))}},loadImage:g,loadSVG:_,loadHTML:v,downloadImageFromCanvas:function(t,e){var o=e.filename,n=e.type,r=void 0===n?'image/jpeg':n,i=t.toDataURL(r),s=document.createElement('a');s.href=i,s.download=o;var a=document.createEvent('MouseEvents');a.initEvent('click',!0,!1),s.dispatchEvent(a)},toColorHexStr:function(t){return'#'+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,'0x'))},isColorStr:r,createUUID:i,istype:u,deepClone:s,Context:y});var A,I=function(){function t(){this._listeners=new Map}return t.prototype.on=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);null==o||o.push(e),this._listeners.set(t,o||[])}else this._listeners.set(t,[e])},t.prototype.off=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);if(Array.isArray(o))for(var n=0;n<(null==o?void 0:o.length);n++)if(o[n]===e){o.splice(n,1);break}this._listeners.set(t,o||[])}},t.prototype.trigger=function(t,e){var o=this._listeners.get(t);return!!Array.isArray(o)&&(o.forEach((function(t){t(e)})),!0)},t.prototype.has=function(t){if(this._listeners.has(t)){var e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1},t}();!function(t){t.FREE="free",t.LOADING="loading",t.COMPLETE="complete"}(A||(A={}));var H,j,U,N,B=function(){function t(t){this._currentLoadData={},this._currentUUIDQueue=[],this._storageLoadData={},this._status=A.FREE,this._waitingLoadQueue=[],this._opts=t,this._event=new I,this._waitingLoadQueue=[]}return t.prototype.load=function(t,e){var o=this._resetLoadData(t,e),n=o[0],r=o[1];this._status===A.FREE||this._status===A.COMPLETE?(this._currentUUIDQueue=n,this._currentLoadData=r,this._loadTask()):this._status===A.LOADING&&n.length>0&&this._waitingLoadQueue.push({uuidQueue:n,loadData:r})},t.prototype.on=function(t,e){this._event.on(t,e)},t.prototype.off=function(t,e){this._event.off(t,e)},t.prototype.isComplete=function(){return this._status===A.COMPLETE},t.prototype.getContent=function(t){var e;return'loaded'===(null===(e=this._storageLoadData[t])||void 0===e?void 0:e.status)?this._storageLoadData[t].content:null},t.prototype._resetLoadData=function(t,e){for(var o={},n=[],r=this._storageLoadData,i=t.elements.length-1;i>=0;i--){var s=t.elements[i];['image','svg','html'].includes(s.type)&&(r[s.uuid]?e.includes(s.uuid)&&(o[s.uuid]=this._createEmptyLoadItem(s),n.push(s.uuid)):(o[s.uuid]=this._createEmptyLoadItem(s),n.push(s.uuid)))}return[n,o]},t.prototype._createEmptyLoadItem=function(t){var e='',o=t.type,n=t.w,r=t.h;if('image'===t.type)e=(i=t).desc.src||'';else if('svg'===t.type){e=(i=t).desc.svg||''}else if('html'===t.type){var i;e=function(t){return t.replace(/<script[\s\S]*?<\/script>/gi,'')}((i=t).desc.html||''),n=i.desc.width||t.w,r=i.desc.height||t.h}return{uuid:t.uuid,type:o,status:'null',content:null,source:e,elemW:n,elemH:r,element:s(t)}},t.prototype._loadTask=function(){var t=this;if(this._status!==A.LOADING){if(this._status=A.LOADING,0===this._currentUUIDQueue.length){if(0===this._waitingLoadQueue.length)return this._status=A.COMPLETE,void this._event.trigger('complete',void 0);var e=this._waitingLoadQueue.shift();if(e){var o=e.uuidQueue,n=e.loadData;this._currentLoadData=n,this._currentUUIDQueue=o}}var r=this._opts.maxParallelNum,i=this._currentUUIDQueue.splice(0,r),s={};i.forEach((function(t,e){s[t]=e}));var a=[],u=function(){if(a.length>=r)return!1;if(0===i.length)return!0;for(var e=function(e){var o=i.shift();if(void 0===o)return"break";a.push(o),t._loadElementSource(t._currentLoadData[o]).then((function(e){var n,r;a.splice(a.indexOf(o),1);var s=u();t._storageLoadData[o]={uuid:o,type:t._currentLoadData[o].type,status:'loaded',content:e,source:t._currentLoadData[o].source,elemW:t._currentLoadData[o].elemW,elemH:t._currentLoadData[o].elemH,element:t._currentLoadData[o].element},0===a.length&&0===i.length&&!0===s&&(t._status=A.FREE,t._loadTask()),t._event.trigger('load',{uuid:null===(n=t._storageLoadData[o])||void 0===n?void 0:n.uuid,type:t._storageLoadData[o].type,status:t._storageLoadData[o].status,content:t._storageLoadData[o].content,source:t._storageLoadData[o].source,elemW:t._storageLoadData[o].elemW,elemH:t._storageLoadData[o].elemH,element:null===(r=t._storageLoadData[o])||void 0===r?void 0:r.element})})).catch((function(e){var n,r,s,c,l,h,f,d,p,g,_,v;console.warn(e),a.splice(a.indexOf(o),1);var y=u();t._currentLoadData[o]&&(t._storageLoadData[o]={uuid:o,type:null===(n=t._currentLoadData[o])||void 0===n?void 0:n.type,status:'fail',content:null,error:e,source:null===(r=t._currentLoadData[o])||void 0===r?void 0:r.source,elemW:null===(s=t._currentLoadData[o])||void 0===s?void 0:s.elemW,elemH:null===(c=t._currentLoadData[o])||void 0===c?void 0:c.elemH,element:null===(l=t._currentLoadData[o])||void 0===l?void 0:l.element}),0===a.length&&0===i.length&&!0===y&&(t._status=A.FREE,t._loadTask()),t._currentLoadData[o]&&t._event.trigger('error',{uuid:o,type:null===(h=t._storageLoadData[o])||void 0===h?void 0:h.type,status:null===(f=t._storageLoadData[o])||void 0===f?void 0:f.status,content:null===(d=t._storageLoadData[o])||void 0===d?void 0:d.content,source:null===(p=t._storageLoadData[o])||void 0===p?void 0:p.source,elemW:null===(g=t._storageLoadData[o])||void 0===g?void 0:g.elemW,elemH:null===(_=t._storageLoadData[o])||void 0===_?void 0:_.elemH,element:null===(v=t._storageLoadData[o])||void 0===v?void 0:v.element})}))},o=a.length;o<r;o++){if("break"===e())break}return!1};u()}},t.prototype._loadElementSource=function(t){return o(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return t&&'image'===t.type?[4,g(t.source)]:[3,2];case 1:case 3:case 5:return[2,e.sent()];case 2:return t&&'svg'===t.type?[4,_(t.source)]:[3,4];case 4:return t&&'html'===t.type?[4,v(t.source,{width:t.elemW,height:t.elemH})]:[3,6];case 6:throw Error('Element\'s source is not support!')}}))}))},t}(),X=function(){function t(){this._listeners=new Map}return t.prototype.on=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);null==o||o.push(e),this._listeners.set(t,o||[])}else this._listeners.set(t,[e])},t.prototype.off=function(t,e){if(this._listeners.has(t)){var o=this._listeners.get(t);if(Array.isArray(o))for(var n=0;n<(null==o?void 0:o.length);n++)if(o[n]===e){o.splice(n,1);break}this._listeners.set(t,o||[])}},t.prototype.trigger=function(t,e){var o=this._listeners.get(t);return!!Array.isArray(o)&&(o.forEach((function(t){t(e)})),!0)},t.prototype.has=function(t){if(this._listeners.has(t)){var e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1},t}(),Y=Symbol('_queue'),M=Symbol('_ctx'),Q=Symbol('_status'),G=Symbol('_loader'),Z=Symbol('_opts'),q=Symbol('_freeze'),$=Symbol('_drawFrame'),V=Symbol('_retainQueueOneItem'),J=window.requestAnimationFrame;!function(t){t.NULL="null",t.FREE="free",t.DRAWING="drawing",t.FREEZE="freeze"}(N||(N={}));var K=function(e){function o(t){var o=e.call(this)||this;return o[H]=[],o[j]=null,o[U]=N.NULL,o[Z]=t,o[G]=new B({maxParallelNum:6}),o[G].on('load',(function(t){o[$](),o.trigger('load',{element:t.element})})),o[G].on('error',(function(t){o.trigger('error',{element:t.element,error:t.error})})),o[G].on('complete',(function(){o.trigger('loadComplete',{t:Date.now()})})),o}return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}(o,e),o.prototype.render=function(t,e,o){var n=(o||{}).changeResourceUUIDs,r=void 0===n?[]:n;this[Q]=N.FREE;var a=s(e);if(Array.isArray(a.elements)&&a.elements.forEach((function(t){'string'==typeof t.uuid&&t.uuid||(t.uuid=i())})),!this[M])if(this[Z]&&'[object HTMLCanvasElement]'===Object.prototype.toString.call(t)){var u=this[Z],c=u.width,l=u.height,h=u.contextWidth,f=u.contextHeight,d=u.devicePixelRatio,p=t;p.width=c*d,p.height=l*d;var g=p.getContext('2d');this[M]=new y(g,{width:c,height:l,contextWidth:h||c,contextHeight:f||l,devicePixelRatio:d})}else t&&(this[M]=t);if(![N.FREEZE].includes(this[Q])){var _=s({data:a});this[Y].push(_),this[$](),this[G].load(a,r||[])}},o.prototype.getContext=function(){return this[M]},o.prototype.thaw=function(){this[Q]=N.FREE},o.prototype[(H=Y,j=M,U=Q,q)]=function(){this[Q]=N.FREEZE},o.prototype[$]=function(){var t=this;this[Q]!==N.FREEZE&&J((function(){if(t[Q]!==N.FREEZE){var e=t[M],o=t[Y][0],n=!1;t[Y].length>1?o=t[Y].shift():n=!0,!0!==t[G].isComplete()?(t[$](),o&&e&&F(e,o.data,t[G])):o&&e?(F(e,o.data,t[G]),t[V](),n?t[Q]=N.FREE:t[$]()):t[Q]=N.FREE,t.trigger('drawFrame',{t:Date.now()}),!0===t[G].isComplete()&&1===t[Y].length&&t[Q]===N.FREE&&(e&&t[Y][0]&&t[Y][0].data&&F(e,t[Y][0].data,t[G]),t.trigger('drawFrameComplete',{t:Date.now()}),t[q]())}}))},o.prototype[V]=function(){if(!(this[Y].length<=1)){var t=s(this[Y][this[Y].length-1]);this[Y]=[t]}},o}(X);return Object.freeze({__proto__:null,Renderer:K})}();
|
package/esm/default.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as default from './index';
|
package/esm/default.js
ADDED
package/esm/esm.d.ts
ADDED
package/esm/esm.js
ADDED