@idraw/renderer 0.2.0-alpha.24 → 0.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,18 +116,18 @@ function toColorHexNum(color) {
116
116
  function toColorHexStr(color) {
117
117
  return '#' + color.toString(16);
118
118
  }
119
- function isColorStr$1(color) {
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$1() {
122
+ function createUUID() {
123
123
  function str4() {
124
124
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
125
125
  }
126
- return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
126
+ return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
127
127
  }
128
- function deepClone$2(target) {
128
+ function deepClone(target) {
129
129
  function _clone(t) {
130
- var type = is$1$1(t);
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$1(data) {
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$1 = {
160
+ var istype = {
161
161
  type: function (data, lowerCase) {
162
162
  var result = parsePrototype(data);
163
163
  return lowerCase === true ? result.toLocaleLowerCase() : result;
@@ -239,7 +239,7 @@ function __generator(thisArg, body) {
239
239
  function parseHTMLToDataURL(html, opts) {
240
240
  var width = opts.width, height = opts.height;
241
241
  return new Promise(function (resolve, reject) {
242
- var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + (width || '') + "\" height = \"" + (height || '') + "\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n " + html + "\n </div>\n </foreignObject>\n </svg>\n ";
242
+ var _svg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(width || '', "\" height = \"").concat(height || '', "\">\n <foreignObject width=\"100%\" height=\"100%\">\n <div xmlns = \"http://www.w3.org/1999/xhtml\">\n ").concat(html, "\n </div>\n </foreignObject>\n </svg>\n ");
243
243
  var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
244
244
  var reader = new FileReader();
245
245
  reader.readAsDataURL(blob);
@@ -270,7 +270,7 @@ function parseSVGToDataURL(svg) {
270
270
  });
271
271
  }
272
272
  var Image = window.Image;
273
- function loadImage$1(src) {
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$1(svg) {
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$1(dataURL)];
292
+ return [4, loadImage(dataURL)];
293
293
  case 2:
294
294
  image = _a.sent();
295
295
  return [2, image];
@@ -297,7 +297,7 @@ function loadSVG$1(svg) {
297
297
  });
298
298
  });
299
299
  }
300
- function loadHTML$1(html, opts) {
300
+ function loadHTML(html, opts) {
301
301
  return __awaiter(this, void 0, void 0, function () {
302
302
  var dataURL, image;
303
303
  return __generator(this, function (_a) {
@@ -305,7 +305,7 @@ function loadHTML$1(html, opts) {
305
305
  case 0: return [4, parseHTMLToDataURL(html, opts)];
306
306
  case 1:
307
307
  dataURL = _a.sent();
308
- return [4, loadImage$1(dataURL)];
308
+ return [4, loadImage(dataURL)];
309
309
  case 2:
310
310
  image = _a.sent();
311
311
  return [2, image];
@@ -313,7 +313,7 @@ function loadHTML$1(html, opts) {
313
313
  });
314
314
  });
315
315
  }
316
- var Context$1 = (function () {
316
+ var Context = (function () {
317
317
  function Context(ctx, opts) {
318
318
  this._opts = opts;
319
319
  this._ctx = ctx;
@@ -461,11 +461,11 @@ var Context$1 = (function () {
461
461
  Context.prototype.setFont = function (opts) {
462
462
  var strList = [];
463
463
  if (opts.fontWeight === 'bold') {
464
- strList.push("" + opts.fontWeight);
464
+ strList.push("".concat(opts.fontWeight));
465
465
  }
466
- strList.push(this._doSize(opts.fontSize || 12) + "px");
467
- strList.push("" + (opts.fontFamily || 'sans-serif'));
468
- this._ctx.font = "" + strList.join(' ');
466
+ strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
467
+ strList.push("".concat(opts.fontFamily || 'sans-serif'));
468
+ this._ctx.font = "".concat(strList.join(' '));
469
469
  };
470
470
  Context.prototype.setTextBaseline = function (baseline) {
471
471
  this._ctx.textBaseline = baseline;
@@ -536,20 +536,20 @@ function borderWidth(value) {
536
536
  function borderRadius(value) {
537
537
  return number(value) && value >= 0;
538
538
  }
539
- function color$2(value) {
540
- return isColorStr$1(value);
539
+ function color(value) {
540
+ return isColorStr(value);
541
541
  }
542
542
  function imageURL(value) {
543
- return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
543
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
544
544
  }
545
545
  function imageBase64(value) {
546
- return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
546
+ return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
547
547
  }
548
548
  function imageSrc(value) {
549
549
  return (imageBase64(value) || imageURL(value));
550
550
  }
551
551
  function svg(value) {
552
- return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
552
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
553
553
  }
554
554
  function html(value) {
555
555
  var result = false;
@@ -584,7 +584,7 @@ function fontFamily(value) {
584
584
  function fontWeight(value) {
585
585
  return ['bold'].includes(value);
586
586
  }
587
- var is$2 = {
587
+ var is = {
588
588
  x: x,
589
589
  y: y,
590
590
  w: w,
@@ -593,7 +593,7 @@ var is$2 = {
593
593
  number: number,
594
594
  borderWidth: borderWidth,
595
595
  borderRadius: borderRadius,
596
- color: color$2,
596
+ color: color,
597
597
  imageSrc: imageSrc,
598
598
  imageURL: imageURL,
599
599
  imageBase64: imageBase64,
@@ -609,7 +609,7 @@ var is$2 = {
609
609
  };
610
610
  function attrs(attrs) {
611
611
  var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
612
- if (!(is$2.x(x) && is$2.y(y) && is$2.w(w) && is$2.h(h) && is$2.angle(angle))) {
612
+ if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
613
613
  return false;
614
614
  }
615
615
  if (!(angle >= -360 && angle <= 360)) {
@@ -620,20 +620,20 @@ function attrs(attrs) {
620
620
  function box(desc) {
621
621
  if (desc === void 0) { desc = {}; }
622
622
  var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
623
- if (desc.hasOwnProperty('borderColor') && !is$2.color(borderColor)) {
623
+ if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
624
624
  return false;
625
625
  }
626
- if (desc.hasOwnProperty('borderRadius') && !is$2.number(borderRadius)) {
626
+ if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
627
627
  return false;
628
628
  }
629
- if (desc.hasOwnProperty('borderWidth') && !is$2.number(borderWidth)) {
629
+ if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
630
630
  return false;
631
631
  }
632
632
  return true;
633
633
  }
634
634
  function rectDesc(desc) {
635
635
  var bgColor = desc.bgColor;
636
- if (desc.hasOwnProperty('bgColor') && !is$2.color(bgColor)) {
636
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
637
637
  return false;
638
638
  }
639
639
  if (!box(desc)) {
@@ -643,68 +643,68 @@ function rectDesc(desc) {
643
643
  }
644
644
  function circleDesc(desc) {
645
645
  var bgColor = desc.bgColor, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
646
- if (desc.hasOwnProperty('bgColor') && !is$2.color(bgColor)) {
646
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
647
647
  return false;
648
648
  }
649
- if (desc.hasOwnProperty('borderColor') && !is$2.color(borderColor)) {
649
+ if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
650
650
  return false;
651
651
  }
652
- if (desc.hasOwnProperty('borderWidth') && !is$2.number(borderWidth)) {
652
+ if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
653
653
  return false;
654
654
  }
655
655
  return true;
656
656
  }
657
657
  function imageDesc(desc) {
658
658
  var src = desc.src;
659
- if (!is$2.imageSrc(src)) {
659
+ if (!is.imageSrc(src)) {
660
660
  return false;
661
661
  }
662
662
  return true;
663
663
  }
664
664
  function svgDesc(desc) {
665
665
  var svg = desc.svg;
666
- if (!is$2.svg(svg)) {
666
+ if (!is.svg(svg)) {
667
667
  return false;
668
668
  }
669
669
  return true;
670
670
  }
671
671
  function htmlDesc(desc) {
672
672
  var html = desc.html;
673
- if (!is$2.html(html)) {
673
+ if (!is.html(html)) {
674
674
  return false;
675
675
  }
676
676
  return true;
677
677
  }
678
678
  function textDesc(desc) {
679
679
  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$2.text(text)) {
680
+ if (!is.text(text)) {
681
681
  return false;
682
682
  }
683
- if (!is$2.color(color)) {
683
+ if (!is.color(color)) {
684
684
  return false;
685
685
  }
686
- if (!is$2.fontSize(fontSize)) {
686
+ if (!is.fontSize(fontSize)) {
687
687
  return false;
688
688
  }
689
- if (desc.hasOwnProperty('bgColor') && !is$2.color(bgColor)) {
689
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
690
690
  return false;
691
691
  }
692
- if (desc.hasOwnProperty('fontWeight') && !is$2.fontWeight(fontWeight)) {
692
+ if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
693
693
  return false;
694
694
  }
695
- if (desc.hasOwnProperty('lineHeight') && !is$2.lineHeight(lineHeight)) {
695
+ if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
696
696
  return false;
697
697
  }
698
- if (desc.hasOwnProperty('fontFamily') && !is$2.fontFamily(fontFamily)) {
698
+ if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
699
699
  return false;
700
700
  }
701
- if (desc.hasOwnProperty('textAlign') && !is$2.textAlign(textAlign)) {
701
+ if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
702
702
  return false;
703
703
  }
704
- if (desc.hasOwnProperty('strokeWidth') && !is$2.strokeWidth(strokeWidth)) {
704
+ if (desc.hasOwnProperty('strokeWidth') && !is.strokeWidth(strokeWidth)) {
705
705
  return false;
706
706
  }
707
- if (desc.hasOwnProperty('strokeColor') && !is$2.color(strokeColor)) {
707
+ if (desc.hasOwnProperty('strokeColor') && !is.color(strokeColor)) {
708
708
  return false;
709
709
  }
710
710
  if (!box(desc)) {
@@ -721,36 +721,25 @@ var check = {
721
721
  svgDesc: svgDesc,
722
722
  htmlDesc: htmlDesc,
723
723
  };
724
- var index = {
725
- is: is$2,
726
- check: check,
727
- time: {
728
- delay: delay,
729
- compose: compose,
730
- throttle: throttle,
731
- },
732
- loader: {
733
- loadImage: loadImage$1,
734
- loadSVG: loadSVG$1,
735
- loadHTML: loadHTML$1,
736
- },
737
- file: {
738
- downloadImageFromCanvas: downloadImageFromCanvas,
739
- },
740
- color: {
741
- toColorHexStr: toColorHexStr,
742
- toColorHexNum: toColorHexNum,
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
- };
724
+ Object.freeze({
725
+ __proto__: null,
726
+ is: is,
727
+ check: check,
728
+ delay: delay,
729
+ compose: compose,
730
+ throttle: throttle,
731
+ loadImage: loadImage,
732
+ loadSVG: loadSVG,
733
+ loadHTML: loadHTML,
734
+ downloadImageFromCanvas: downloadImageFromCanvas,
735
+ toColorHexStr: toColorHexStr,
736
+ toColorHexNum: toColorHexNum,
737
+ isColorStr: isColorStr,
738
+ createUUID: createUUID,
739
+ istype: istype,
740
+ deepClone: deepClone,
741
+ Context: Context
742
+ });
754
743
 
755
744
  function parseAngleToRadian(angle) {
756
745
  return angle / 180 * Math.PI;
@@ -782,7 +771,6 @@ function rotateContext(ctx, center, radian, callback) {
782
771
  }
783
772
  }
784
773
 
785
- var is$1 = index.is, istype = index.istype, color$1 = index.color;
786
774
  function clearContext(ctx) {
787
775
  ctx.setFillStyle('#000000');
788
776
  ctx.setStrokeStyle('#000000');
@@ -833,7 +821,7 @@ function drawBoxBorder(ctx, elem) {
833
821
  }
834
822
  var bw = elem.desc.borderWidth;
835
823
  var borderColor = '#000000';
836
- if (color$1.isColorStr(elem.desc.borderColor) === true) {
824
+ if (isColorStr(elem.desc.borderColor) === true) {
837
825
  borderColor = elem.desc.borderColor;
838
826
  }
839
827
  var x = elem.x - bw / 2;
@@ -846,16 +834,16 @@ function drawBoxBorder(ctx, elem) {
846
834
  r = r + bw / 2;
847
835
  }
848
836
  var desc = elem.desc;
849
- if (desc.shadowColor !== undefined && color$1.isColorStr(desc.shadowColor)) {
837
+ if (desc.shadowColor !== undefined && isColorStr(desc.shadowColor)) {
850
838
  ctx.setShadowColor(desc.shadowColor);
851
839
  }
852
- if (desc.shadowOffsetX !== undefined && is$1.number(desc.shadowOffsetX)) {
840
+ if (desc.shadowOffsetX !== undefined && is.number(desc.shadowOffsetX)) {
853
841
  ctx.setShadowOffsetX(desc.shadowOffsetX);
854
842
  }
855
- if (desc.shadowOffsetY !== undefined && is$1.number(desc.shadowOffsetY)) {
843
+ if (desc.shadowOffsetY !== undefined && is.number(desc.shadowOffsetY)) {
856
844
  ctx.setShadowOffsetY(desc.shadowOffsetY);
857
845
  }
858
- if (desc.shadowBlur !== undefined && is$1.number(desc.shadowBlur)) {
846
+ if (desc.shadowBlur !== undefined && is.number(desc.shadowBlur)) {
859
847
  ctx.setShadowBlur(desc.shadowBlur);
860
848
  }
861
849
  ctx.beginPath();
@@ -902,7 +890,6 @@ function drawHTML(ctx, elem, loader) {
902
890
  });
903
891
  }
904
892
 
905
- var is = index.is, color = index.color;
906
893
  function drawText(ctx, elem, loader) {
907
894
  clearContext(ctx);
908
895
  drawBox(ctx, elem, elem.desc.bgColor || 'transparent');
@@ -923,41 +910,52 @@ function drawText(ctx, elem, loader) {
923
910
  var fontHeight = desc.lineHeight || desc.fontSize;
924
911
  var descTextList = descText.split('\n');
925
912
  var lines = [];
926
- descTextList.forEach(function (tempText) {
913
+ var lineNum = 0;
914
+ descTextList.forEach(function (tempText, idx) {
927
915
  var lineText = '';
928
- var lineNum = 0;
929
- for (var i = 0; i < tempText.length; i++) {
930
- if (ctx.measureText(lineText + (tempText[i] || '')).width < ctx.calcDeviceNum(elem.w)) {
931
- lineText += (tempText[i] || '');
932
- }
933
- else {
934
- lines.push({
935
- text: lineText,
936
- width: ctx.calcScreenNum(ctx.measureText(lineText).width),
937
- });
938
- lineText = (tempText[i] || '');
939
- lineNum++;
940
- }
941
- if ((lineNum + 1) * fontHeight > elem.h) {
942
- break;
943
- }
944
- if (lineText && tempText.length - 1 === i) {
945
- if ((lineNum + 1) * fontHeight < elem.h) {
916
+ if (tempText.length > 0) {
917
+ for (var i = 0; i < tempText.length; i++) {
918
+ if (ctx.measureText(lineText + (tempText[i] || '')).width < ctx.calcDeviceNum(elem.w)) {
919
+ lineText += (tempText[i] || '');
920
+ }
921
+ else {
946
922
  lines.push({
947
923
  text: lineText,
948
924
  width: ctx.calcScreenNum(ctx.measureText(lineText).width),
949
925
  });
926
+ lineText = (tempText[i] || '');
927
+ lineNum++;
928
+ }
929
+ if ((lineNum + 1) * fontHeight > elem.h) {
950
930
  break;
951
931
  }
932
+ if (tempText.length - 1 === i) {
933
+ if ((lineNum + 1) * fontHeight < elem.h) {
934
+ lines.push({
935
+ text: lineText,
936
+ width: ctx.calcScreenNum(ctx.measureText(lineText).width),
937
+ });
938
+ if (idx < descTextList.length - 1) {
939
+ lineNum++;
940
+ }
941
+ break;
942
+ }
943
+ }
952
944
  }
953
945
  }
946
+ else {
947
+ lines.push({
948
+ text: '',
949
+ width: 0,
950
+ });
951
+ }
954
952
  });
955
953
  {
956
954
  var _y_1 = elem.y;
957
955
  if (lines.length * fontHeight < elem.h) {
958
956
  _y_1 += ((elem.h - lines.length * fontHeight) / 2);
959
957
  }
960
- if (desc.textShadowColor !== undefined && color.isColorStr(desc.textShadowColor)) {
958
+ if (desc.textShadowColor !== undefined && isColorStr(desc.textShadowColor)) {
961
959
  ctx.setShadowColor(desc.textShadowColor);
962
960
  }
963
961
  if (desc.textShadowOffsetX !== undefined && is.number(desc.textShadowOffsetX)) {
@@ -981,7 +979,7 @@ function drawText(ctx, elem, loader) {
981
979
  });
982
980
  clearContext(ctx);
983
981
  }
984
- if (color.isColorStr(desc.strokeColor) && desc.strokeWidth !== undefined && desc.strokeWidth > 0) {
982
+ if (isColorStr(desc.strokeColor) && desc.strokeWidth !== undefined && desc.strokeWidth > 0) {
985
983
  var _y_2 = elem.y;
986
984
  if (lines.length * fontHeight < elem.h) {
987
985
  _y_2 += ((elem.h - lines.length * fontHeight) / 2);
@@ -1033,7 +1031,6 @@ function drawCircle(ctx, elem) {
1033
1031
  });
1034
1032
  }
1035
1033
 
1036
- var isColorStr = index.color.isColorStr;
1037
1034
  function drawContext(ctx, data, loader) {
1038
1035
  var _a;
1039
1036
  clearContext(ctx);
@@ -1135,8 +1132,6 @@ function filterScript(html) {
1135
1132
  return html.replace(/<script[\s\S]*?<\/script>/ig, '');
1136
1133
  }
1137
1134
 
1138
- var _a$1 = index.loader, loadImage = _a$1.loadImage, loadSVG = _a$1.loadSVG, loadHTML = _a$1.loadHTML;
1139
- var deepClone$1 = index.data.deepClone;
1140
1135
  var LoaderStatus;
1141
1136
  (function (LoaderStatus) {
1142
1137
  LoaderStatus["FREE"] = "free";
@@ -1232,7 +1227,7 @@ var Loader = (function () {
1232
1227
  source: source,
1233
1228
  elemW: elemW,
1234
1229
  elemH: elemH,
1235
- element: deepClone$1(elem),
1230
+ element: deepClone(elem),
1236
1231
  };
1237
1232
  };
1238
1233
  Loader.prototype._loadTask = function () {
@@ -1445,9 +1440,6 @@ var _retainQueueOneItem = Symbol('_retainQueueOneItem');
1445
1440
 
1446
1441
  var _a, _b, _c;
1447
1442
  var requestAnimationFrame = window.requestAnimationFrame;
1448
- var createUUID = index.uuid.createUUID;
1449
- var deepClone = index.data.deepClone;
1450
- var Context = index.Context;
1451
1443
  var DrawStatus;
1452
1444
  (function (DrawStatus) {
1453
1445
  DrawStatus["NULL"] = "null";
@@ -1582,4 +1574,9 @@ var Renderer = (function (_super) {
1582
1574
  return Renderer;
1583
1575
  }(RendererEvent));
1584
1576
 
1585
- export { Renderer as default };
1577
+ var default_1 = /*#__PURE__*/Object.freeze({
1578
+ __proto__: null,
1579
+ Renderer: Renderer
1580
+ });
1581
+
1582
+ export { Renderer, default_1 as default };