@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
|
@@ -116,18 +116,18 @@ function toColorHexNum(color) {
|
|
|
116
116
|
function toColorHexStr(color) {
|
|
117
117
|
return '#' + color.toString(16);
|
|
118
118
|
}
|
|
119
|
-
function isColorStr
|
|
119
|
+
function isColorStr(color) {
|
|
120
120
|
return typeof color === 'string' && /^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color);
|
|
121
121
|
}
|
|
122
|
-
function createUUID
|
|
122
|
+
function createUUID() {
|
|
123
123
|
function str4() {
|
|
124
124
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
125
125
|
}
|
|
126
126
|
return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
|
|
127
127
|
}
|
|
128
|
-
function deepClone
|
|
128
|
+
function deepClone(target) {
|
|
129
129
|
function _clone(t) {
|
|
130
|
-
var type = is$1
|
|
130
|
+
var type = is$1(t);
|
|
131
131
|
if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
|
|
132
132
|
return t;
|
|
133
133
|
}
|
|
@@ -149,7 +149,7 @@ function deepClone$2(target) {
|
|
|
149
149
|
}
|
|
150
150
|
return _clone(target);
|
|
151
151
|
}
|
|
152
|
-
function is$1
|
|
152
|
+
function is$1(data) {
|
|
153
153
|
return Object.prototype.toString.call(data).replace(/[\]|\[]{1,1}/ig, '').split(' ')[1];
|
|
154
154
|
}
|
|
155
155
|
function parsePrototype(data) {
|
|
@@ -157,7 +157,7 @@ function parsePrototype(data) {
|
|
|
157
157
|
var result = typeStr.replace(/(\[object|\])/ig, '').trim();
|
|
158
158
|
return result;
|
|
159
159
|
}
|
|
160
|
-
var istype
|
|
160
|
+
var istype = {
|
|
161
161
|
type: function (data, lowerCase) {
|
|
162
162
|
var result = parsePrototype(data);
|
|
163
163
|
return lowerCase === true ? result.toLocaleLowerCase() : result;
|
|
@@ -270,7 +270,7 @@ function parseSVGToDataURL(svg) {
|
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
272
|
var Image = window.Image;
|
|
273
|
-
function loadImage
|
|
273
|
+
function loadImage(src) {
|
|
274
274
|
return new Promise(function (resolve, reject) {
|
|
275
275
|
var img = new Image;
|
|
276
276
|
img.onload = function () {
|
|
@@ -281,7 +281,7 @@ function loadImage$1(src) {
|
|
|
281
281
|
img.src = src;
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
function loadSVG
|
|
284
|
+
function loadSVG(svg) {
|
|
285
285
|
return __awaiter(this, void 0, void 0, function () {
|
|
286
286
|
var dataURL, image;
|
|
287
287
|
return __generator(this, function (_a) {
|
|
@@ -289,7 +289,7 @@ function loadSVG$1(svg) {
|
|
|
289
289
|
case 0: return [4, parseSVGToDataURL(svg)];
|
|
290
290
|
case 1:
|
|
291
291
|
dataURL = _a.sent();
|
|
292
|
-
return [4, loadImage
|
|
292
|
+
return [4, loadImage(dataURL)];
|
|
293
293
|
case 2:
|
|
294
294
|
image = _a.sent();
|
|
295
295
|
return [2, image];
|
|
@@ -297,15 +297,20 @@ function loadSVG$1(svg) {
|
|
|
297
297
|
});
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
|
-
function
|
|
300
|
+
function filterAmpersand(str) {
|
|
301
|
+
return str.replace(/\&/ig, '&');
|
|
302
|
+
}
|
|
303
|
+
function loadHTML(html, opts) {
|
|
301
304
|
return __awaiter(this, void 0, void 0, function () {
|
|
302
305
|
var dataURL, image;
|
|
303
306
|
return __generator(this, function (_a) {
|
|
304
307
|
switch (_a.label) {
|
|
305
|
-
case 0:
|
|
308
|
+
case 0:
|
|
309
|
+
html = filterAmpersand(html);
|
|
310
|
+
return [4, parseHTMLToDataURL(html, opts)];
|
|
306
311
|
case 1:
|
|
307
312
|
dataURL = _a.sent();
|
|
308
|
-
return [4, loadImage
|
|
313
|
+
return [4, loadImage(dataURL)];
|
|
309
314
|
case 2:
|
|
310
315
|
image = _a.sent();
|
|
311
316
|
return [2, image];
|
|
@@ -313,7 +318,7 @@ function loadHTML$1(html, opts) {
|
|
|
313
318
|
});
|
|
314
319
|
});
|
|
315
320
|
}
|
|
316
|
-
var Context
|
|
321
|
+
var Context = (function () {
|
|
317
322
|
function Context(ctx, opts) {
|
|
318
323
|
this._opts = opts;
|
|
319
324
|
this._ctx = ctx;
|
|
@@ -536,8 +541,8 @@ function borderWidth(value) {
|
|
|
536
541
|
function borderRadius(value) {
|
|
537
542
|
return number(value) && value >= 0;
|
|
538
543
|
}
|
|
539
|
-
function color
|
|
540
|
-
return isColorStr
|
|
544
|
+
function color(value) {
|
|
545
|
+
return isColorStr(value);
|
|
541
546
|
}
|
|
542
547
|
function imageURL(value) {
|
|
543
548
|
return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
|
|
@@ -584,7 +589,7 @@ function fontFamily(value) {
|
|
|
584
589
|
function fontWeight(value) {
|
|
585
590
|
return ['bold'].includes(value);
|
|
586
591
|
}
|
|
587
|
-
var is
|
|
592
|
+
var is = {
|
|
588
593
|
x: x,
|
|
589
594
|
y: y,
|
|
590
595
|
w: w,
|
|
@@ -593,7 +598,7 @@ var is$2 = {
|
|
|
593
598
|
number: number,
|
|
594
599
|
borderWidth: borderWidth,
|
|
595
600
|
borderRadius: borderRadius,
|
|
596
|
-
color: color
|
|
601
|
+
color: color,
|
|
597
602
|
imageSrc: imageSrc,
|
|
598
603
|
imageURL: imageURL,
|
|
599
604
|
imageBase64: imageBase64,
|
|
@@ -609,7 +614,7 @@ var is$2 = {
|
|
|
609
614
|
};
|
|
610
615
|
function attrs(attrs) {
|
|
611
616
|
var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
|
|
612
|
-
if (!(is
|
|
617
|
+
if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
|
|
613
618
|
return false;
|
|
614
619
|
}
|
|
615
620
|
if (!(angle >= -360 && angle <= 360)) {
|
|
@@ -620,20 +625,20 @@ function attrs(attrs) {
|
|
|
620
625
|
function box(desc) {
|
|
621
626
|
if (desc === void 0) { desc = {}; }
|
|
622
627
|
var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
|
|
623
|
-
if (desc.hasOwnProperty('borderColor') && !is
|
|
628
|
+
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
624
629
|
return false;
|
|
625
630
|
}
|
|
626
|
-
if (desc.hasOwnProperty('borderRadius') && !is
|
|
631
|
+
if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
|
|
627
632
|
return false;
|
|
628
633
|
}
|
|
629
|
-
if (desc.hasOwnProperty('borderWidth') && !is
|
|
634
|
+
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
630
635
|
return false;
|
|
631
636
|
}
|
|
632
637
|
return true;
|
|
633
638
|
}
|
|
634
639
|
function rectDesc(desc) {
|
|
635
640
|
var bgColor = desc.bgColor;
|
|
636
|
-
if (desc.hasOwnProperty('bgColor') && !is
|
|
641
|
+
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
637
642
|
return false;
|
|
638
643
|
}
|
|
639
644
|
if (!box(desc)) {
|
|
@@ -643,68 +648,68 @@ function rectDesc(desc) {
|
|
|
643
648
|
}
|
|
644
649
|
function circleDesc(desc) {
|
|
645
650
|
var bgColor = desc.bgColor, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
|
|
646
|
-
if (desc.hasOwnProperty('bgColor') && !is
|
|
651
|
+
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
647
652
|
return false;
|
|
648
653
|
}
|
|
649
|
-
if (desc.hasOwnProperty('borderColor') && !is
|
|
654
|
+
if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
|
|
650
655
|
return false;
|
|
651
656
|
}
|
|
652
|
-
if (desc.hasOwnProperty('borderWidth') && !is
|
|
657
|
+
if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
|
|
653
658
|
return false;
|
|
654
659
|
}
|
|
655
660
|
return true;
|
|
656
661
|
}
|
|
657
662
|
function imageDesc(desc) {
|
|
658
663
|
var src = desc.src;
|
|
659
|
-
if (!is
|
|
664
|
+
if (!is.imageSrc(src)) {
|
|
660
665
|
return false;
|
|
661
666
|
}
|
|
662
667
|
return true;
|
|
663
668
|
}
|
|
664
669
|
function svgDesc(desc) {
|
|
665
670
|
var svg = desc.svg;
|
|
666
|
-
if (!is
|
|
671
|
+
if (!is.svg(svg)) {
|
|
667
672
|
return false;
|
|
668
673
|
}
|
|
669
674
|
return true;
|
|
670
675
|
}
|
|
671
676
|
function htmlDesc(desc) {
|
|
672
677
|
var html = desc.html;
|
|
673
|
-
if (!is
|
|
678
|
+
if (!is.html(html)) {
|
|
674
679
|
return false;
|
|
675
680
|
}
|
|
676
681
|
return true;
|
|
677
682
|
}
|
|
678
683
|
function textDesc(desc) {
|
|
679
684
|
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;
|
|
680
|
-
if (!is
|
|
685
|
+
if (!is.text(text)) {
|
|
681
686
|
return false;
|
|
682
687
|
}
|
|
683
|
-
if (!is
|
|
688
|
+
if (!is.color(color)) {
|
|
684
689
|
return false;
|
|
685
690
|
}
|
|
686
|
-
if (!is
|
|
691
|
+
if (!is.fontSize(fontSize)) {
|
|
687
692
|
return false;
|
|
688
693
|
}
|
|
689
|
-
if (desc.hasOwnProperty('bgColor') && !is
|
|
694
|
+
if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
|
|
690
695
|
return false;
|
|
691
696
|
}
|
|
692
|
-
if (desc.hasOwnProperty('fontWeight') && !is
|
|
697
|
+
if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
|
|
693
698
|
return false;
|
|
694
699
|
}
|
|
695
|
-
if (desc.hasOwnProperty('lineHeight') && !is
|
|
700
|
+
if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
|
|
696
701
|
return false;
|
|
697
702
|
}
|
|
698
|
-
if (desc.hasOwnProperty('fontFamily') && !is
|
|
703
|
+
if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
|
|
699
704
|
return false;
|
|
700
705
|
}
|
|
701
|
-
if (desc.hasOwnProperty('textAlign') && !is
|
|
706
|
+
if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
|
|
702
707
|
return false;
|
|
703
708
|
}
|
|
704
|
-
if (desc.hasOwnProperty('strokeWidth') && !is
|
|
709
|
+
if (desc.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
|
|
705
710
|
return false;
|
|
706
711
|
}
|
|
707
|
-
if (desc.hasOwnProperty('strokeColor') && !is
|
|
712
|
+
if (desc.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
|
|
708
713
|
return false;
|
|
709
714
|
}
|
|
710
715
|
if (!box(desc)) {
|
|
@@ -721,36 +726,25 @@ var check = {
|
|
|
721
726
|
svgDesc: svgDesc,
|
|
722
727
|
htmlDesc: htmlDesc,
|
|
723
728
|
};
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
isColorStr: isColorStr$1,
|
|
744
|
-
},
|
|
745
|
-
uuid: {
|
|
746
|
-
createUUID: createUUID$1
|
|
747
|
-
},
|
|
748
|
-
istype: istype$1,
|
|
749
|
-
data: {
|
|
750
|
-
deepClone: deepClone$2,
|
|
751
|
-
},
|
|
752
|
-
Context: Context$1,
|
|
753
|
-
};
|
|
729
|
+
Object.freeze({
|
|
730
|
+
__proto__: null,
|
|
731
|
+
is: is,
|
|
732
|
+
check: check,
|
|
733
|
+
delay: delay,
|
|
734
|
+
compose: compose,
|
|
735
|
+
throttle: throttle,
|
|
736
|
+
loadImage: loadImage,
|
|
737
|
+
loadSVG: loadSVG,
|
|
738
|
+
loadHTML: loadHTML,
|
|
739
|
+
downloadImageFromCanvas: downloadImageFromCanvas,
|
|
740
|
+
toColorHexStr: toColorHexStr,
|
|
741
|
+
toColorHexNum: toColorHexNum,
|
|
742
|
+
isColorStr: isColorStr,
|
|
743
|
+
createUUID: createUUID,
|
|
744
|
+
istype: istype,
|
|
745
|
+
deepClone: deepClone,
|
|
746
|
+
Context: Context
|
|
747
|
+
});
|
|
754
748
|
|
|
755
749
|
function parseAngleToRadian(angle) {
|
|
756
750
|
return angle / 180 * Math.PI;
|
|
@@ -782,7 +776,6 @@ function rotateContext(ctx, center, radian, callback) {
|
|
|
782
776
|
}
|
|
783
777
|
}
|
|
784
778
|
|
|
785
|
-
var is$1 = index.is, istype = index.istype, color$1 = index.color;
|
|
786
779
|
function clearContext(ctx) {
|
|
787
780
|
ctx.setFillStyle('#000000');
|
|
788
781
|
ctx.setStrokeStyle('#000000');
|
|
@@ -833,7 +826,7 @@ function drawBoxBorder(ctx, elem) {
|
|
|
833
826
|
}
|
|
834
827
|
var bw = elem.desc.borderWidth;
|
|
835
828
|
var borderColor = '#000000';
|
|
836
|
-
if (
|
|
829
|
+
if (isColorStr(elem.desc.borderColor) === true) {
|
|
837
830
|
borderColor = elem.desc.borderColor;
|
|
838
831
|
}
|
|
839
832
|
var x = elem.x - bw / 2;
|
|
@@ -846,16 +839,16 @@ function drawBoxBorder(ctx, elem) {
|
|
|
846
839
|
r = r + bw / 2;
|
|
847
840
|
}
|
|
848
841
|
var desc = elem.desc;
|
|
849
|
-
if (desc.shadowColor !== undefined &&
|
|
842
|
+
if (desc.shadowColor !== undefined && isColorStr(desc.shadowColor)) {
|
|
850
843
|
ctx.setShadowColor(desc.shadowColor);
|
|
851
844
|
}
|
|
852
|
-
if (desc.shadowOffsetX !== undefined && is
|
|
845
|
+
if (desc.shadowOffsetX !== undefined && is.number(desc.shadowOffsetX)) {
|
|
853
846
|
ctx.setShadowOffsetX(desc.shadowOffsetX);
|
|
854
847
|
}
|
|
855
|
-
if (desc.shadowOffsetY !== undefined && is
|
|
848
|
+
if (desc.shadowOffsetY !== undefined && is.number(desc.shadowOffsetY)) {
|
|
856
849
|
ctx.setShadowOffsetY(desc.shadowOffsetY);
|
|
857
850
|
}
|
|
858
|
-
if (desc.shadowBlur !== undefined && is
|
|
851
|
+
if (desc.shadowBlur !== undefined && is.number(desc.shadowBlur)) {
|
|
859
852
|
ctx.setShadowBlur(desc.shadowBlur);
|
|
860
853
|
}
|
|
861
854
|
ctx.beginPath();
|
|
@@ -902,7 +895,6 @@ function drawHTML(ctx, elem, loader) {
|
|
|
902
895
|
});
|
|
903
896
|
}
|
|
904
897
|
|
|
905
|
-
var is = index.is, color = index.color;
|
|
906
898
|
function drawText(ctx, elem, loader) {
|
|
907
899
|
clearContext(ctx);
|
|
908
900
|
drawBox(ctx, elem, elem.desc.bgColor || 'transparent');
|
|
@@ -968,7 +960,7 @@ function drawText(ctx, elem, loader) {
|
|
|
968
960
|
if (lines.length * fontHeight < elem.h) {
|
|
969
961
|
_y_1 += ((elem.h - lines.length * fontHeight) / 2);
|
|
970
962
|
}
|
|
971
|
-
if (desc.textShadowColor !== undefined &&
|
|
963
|
+
if (desc.textShadowColor !== undefined && isColorStr(desc.textShadowColor)) {
|
|
972
964
|
ctx.setShadowColor(desc.textShadowColor);
|
|
973
965
|
}
|
|
974
966
|
if (desc.textShadowOffsetX !== undefined && is.number(desc.textShadowOffsetX)) {
|
|
@@ -992,7 +984,7 @@ function drawText(ctx, elem, loader) {
|
|
|
992
984
|
});
|
|
993
985
|
clearContext(ctx);
|
|
994
986
|
}
|
|
995
|
-
if (
|
|
987
|
+
if (isColorStr(desc.strokeColor) && desc.strokeWidth !== undefined && desc.strokeWidth > 0) {
|
|
996
988
|
var _y_2 = elem.y;
|
|
997
989
|
if (lines.length * fontHeight < elem.h) {
|
|
998
990
|
_y_2 += ((elem.h - lines.length * fontHeight) / 2);
|
|
@@ -1044,7 +1036,6 @@ function drawCircle(ctx, elem) {
|
|
|
1044
1036
|
});
|
|
1045
1037
|
}
|
|
1046
1038
|
|
|
1047
|
-
var isColorStr = index.color.isColorStr;
|
|
1048
1039
|
function drawContext(ctx, data, loader) {
|
|
1049
1040
|
var _a;
|
|
1050
1041
|
clearContext(ctx);
|
|
@@ -1146,8 +1137,6 @@ function filterScript(html) {
|
|
|
1146
1137
|
return html.replace(/<script[\s\S]*?<\/script>/ig, '');
|
|
1147
1138
|
}
|
|
1148
1139
|
|
|
1149
|
-
var _a$1 = index.loader, loadImage = _a$1.loadImage, loadSVG = _a$1.loadSVG, loadHTML = _a$1.loadHTML;
|
|
1150
|
-
var deepClone$1 = index.data.deepClone;
|
|
1151
1140
|
var LoaderStatus;
|
|
1152
1141
|
(function (LoaderStatus) {
|
|
1153
1142
|
LoaderStatus["FREE"] = "free";
|
|
@@ -1243,7 +1232,7 @@ var Loader = (function () {
|
|
|
1243
1232
|
source: source,
|
|
1244
1233
|
elemW: elemW,
|
|
1245
1234
|
elemH: elemH,
|
|
1246
|
-
element: deepClone
|
|
1235
|
+
element: deepClone(elem),
|
|
1247
1236
|
};
|
|
1248
1237
|
};
|
|
1249
1238
|
Loader.prototype._loadTask = function () {
|
|
@@ -1456,9 +1445,6 @@ var _retainQueueOneItem = Symbol('_retainQueueOneItem');
|
|
|
1456
1445
|
|
|
1457
1446
|
var _a, _b, _c;
|
|
1458
1447
|
var requestAnimationFrame = window.requestAnimationFrame;
|
|
1459
|
-
var createUUID = index.uuid.createUUID;
|
|
1460
|
-
var deepClone = index.data.deepClone;
|
|
1461
|
-
var Context = index.Context;
|
|
1462
1448
|
var DrawStatus;
|
|
1463
1449
|
(function (DrawStatus) {
|
|
1464
1450
|
DrawStatus["NULL"] = "null";
|
|
@@ -1593,4 +1579,9 @@ var Renderer = (function (_super) {
|
|
|
1593
1579
|
return Renderer;
|
|
1594
1580
|
}(RendererEvent));
|
|
1595
1581
|
|
|
1596
|
-
|
|
1582
|
+
var default_1 = /*#__PURE__*/Object.freeze({
|
|
1583
|
+
__proto__: null,
|
|
1584
|
+
Renderer: Renderer
|
|
1585
|
+
});
|
|
1586
|
+
|
|
1587
|
+
export { Renderer, default_1 as default };
|