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