@idraw/core 0.2.0-alpha.22 → 0.2.0-alpha.26

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.es.js CHANGED
@@ -84,7 +84,7 @@ function createUUID$4() {
84
84
  function str4() {
85
85
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
86
86
  }
87
- return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
87
+ return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
88
88
  }
89
89
  function deepClone$6(target) {
90
90
  function _clone(t) {
@@ -200,7 +200,7 @@ function __generator$3(thisArg, body) {
200
200
  function parseHTMLToDataURL$2(html, opts) {
201
201
  var width = opts.width, height = opts.height;
202
202
  return new Promise(function (resolve, reject) {
203
- 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 ";
203
+ 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 ");
204
204
  var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
205
205
  var reader = new FileReader();
206
206
  reader.readAsDataURL(blob);
@@ -422,11 +422,11 @@ var Context$1$1 = (function () {
422
422
  Context.prototype.setFont = function (opts) {
423
423
  var strList = [];
424
424
  if (opts.fontWeight === 'bold') {
425
- strList.push("" + opts.fontWeight);
425
+ strList.push("".concat(opts.fontWeight));
426
426
  }
427
- strList.push(this._doSize(opts.fontSize || 12) + "px");
428
- strList.push("" + (opts.fontFamily || 'sans-serif'));
429
- this._ctx.font = "" + strList.join(' ');
427
+ strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
428
+ strList.push("".concat(opts.fontFamily || 'sans-serif'));
429
+ this._ctx.font = "".concat(strList.join(' '));
430
430
  };
431
431
  Context.prototype.setTextBaseline = function (baseline) {
432
432
  this._ctx.textBaseline = baseline;
@@ -501,16 +501,16 @@ function color$5(value) {
501
501
  return isColorStr$4(value);
502
502
  }
503
503
  function imageURL$3(value) {
504
- return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
504
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
505
505
  }
506
506
  function imageBase64$3(value) {
507
- return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
507
+ return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
508
508
  }
509
509
  function imageSrc$3(value) {
510
510
  return (imageBase64$3(value) || imageURL$3(value));
511
511
  }
512
512
  function svg$3(value) {
513
- return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
513
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
514
514
  }
515
515
  function html$3(value) {
516
516
  var result = false;
@@ -828,19 +828,24 @@ var ScreenWatcher = (function () {
828
828
  this._initParentEvent();
829
829
  };
830
830
  ScreenWatcher.prototype._initParentEvent = function () {
831
- var target = window;
832
- var targetOrigin = target.origin;
833
- while (target.self !== target.top) {
834
- if (target.self !== target.parent) {
835
- if (target.origin === targetOrigin) {
836
- target.parent.window.addEventListener('mousemove', this._listSameOriginParentWindow.bind(this), false);
831
+ try {
832
+ var target = window;
833
+ var targetOrigin = target.origin;
834
+ while (target.self !== target.top) {
835
+ if (target.self !== target.parent) {
836
+ if (target.origin === targetOrigin) {
837
+ target.parent.window.addEventListener('mousemove', this._listSameOriginParentWindow.bind(this), false);
838
+ }
839
+ }
840
+ target = target.parent;
841
+ if (!target) {
842
+ break;
837
843
  }
838
- }
839
- target = target.parent;
840
- if (!target) {
841
- break;
842
844
  }
843
845
  }
846
+ catch (err) {
847
+ console.warn(err);
848
+ }
844
849
  };
845
850
  ScreenWatcher.prototype._listenHover = function (e) {
846
851
  e.preventDefault();
@@ -1017,7 +1022,7 @@ function setStyle(dom, style) {
1017
1022
  var keys = Object.keys(_style);
1018
1023
  var styleStr = '';
1019
1024
  keys.forEach(function (key) {
1020
- styleStr += key + ":" + (_style[key] || '') + ";";
1025
+ styleStr += "".concat(key, ":").concat(_style[key] || '', ";");
1021
1026
  });
1022
1027
  dom.setAttribute('style', styleStr);
1023
1028
  }
@@ -1474,8 +1479,8 @@ var Board = (function () {
1474
1479
  this[_displayCanvas].width = width * devicePixelRatio;
1475
1480
  this[_displayCanvas].height = height * devicePixelRatio;
1476
1481
  setStyle(this[_displayCanvas], {
1477
- width: width + "px",
1478
- height: height + "px",
1482
+ width: "".concat(width, "px"),
1483
+ height: "".concat(height, "px"),
1479
1484
  });
1480
1485
  };
1481
1486
  Board.prototype[_parsePrivateOptions] = function (opts) {
@@ -1623,7 +1628,7 @@ function createUUID$3() {
1623
1628
  function str4() {
1624
1629
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1625
1630
  }
1626
- return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
1631
+ return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
1627
1632
  }
1628
1633
  function deepClone$5(target) {
1629
1634
  function _clone(t) {
@@ -1739,7 +1744,7 @@ function __generator$2(thisArg, body) {
1739
1744
  function parseHTMLToDataURL$1(html, opts) {
1740
1745
  var width = opts.width, height = opts.height;
1741
1746
  return new Promise(function (resolve, reject) {
1742
- 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 ";
1747
+ 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 ");
1743
1748
  var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
1744
1749
  var reader = new FileReader();
1745
1750
  reader.readAsDataURL(blob);
@@ -1961,11 +1966,11 @@ var Context$2 = (function () {
1961
1966
  Context.prototype.setFont = function (opts) {
1962
1967
  var strList = [];
1963
1968
  if (opts.fontWeight === 'bold') {
1964
- strList.push("" + opts.fontWeight);
1969
+ strList.push("".concat(opts.fontWeight));
1965
1970
  }
1966
- strList.push(this._doSize(opts.fontSize || 12) + "px");
1967
- strList.push("" + (opts.fontFamily || 'sans-serif'));
1968
- this._ctx.font = "" + strList.join(' ');
1971
+ strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
1972
+ strList.push("".concat(opts.fontFamily || 'sans-serif'));
1973
+ this._ctx.font = "".concat(strList.join(' '));
1969
1974
  };
1970
1975
  Context.prototype.setTextBaseline = function (baseline) {
1971
1976
  this._ctx.textBaseline = baseline;
@@ -2040,16 +2045,16 @@ function color$4(value) {
2040
2045
  return isColorStr$3(value);
2041
2046
  }
2042
2047
  function imageURL$2(value) {
2043
- return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
2048
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
2044
2049
  }
2045
2050
  function imageBase64$2(value) {
2046
- return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
2051
+ return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
2047
2052
  }
2048
2053
  function imageSrc$2(value) {
2049
2054
  return (imageBase64$2(value) || imageURL$2(value));
2050
2055
  }
2051
2056
  function svg$2(value) {
2052
- return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
2057
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
2053
2058
  }
2054
2059
  function html$2(value) {
2055
2060
  var result = false;
@@ -2376,7 +2381,7 @@ function createUUID$1$1() {
2376
2381
  function str4() {
2377
2382
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
2378
2383
  }
2379
- return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
2384
+ return "".concat(str4()).concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4(), "-").concat(str4()).concat(str4()).concat(str4());
2380
2385
  }
2381
2386
  function deepClone$2$1(target) {
2382
2387
  function _clone(t) {
@@ -2492,7 +2497,7 @@ function __generator(thisArg, body) {
2492
2497
  function parseHTMLToDataURL(html, opts) {
2493
2498
  var width = opts.width, height = opts.height;
2494
2499
  return new Promise(function (resolve, reject) {
2495
- 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 ";
2500
+ 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 ");
2496
2501
  var blob = new Blob([_svg], { type: 'image/svg+xml;charset=utf-8' });
2497
2502
  var reader = new FileReader();
2498
2503
  reader.readAsDataURL(blob);
@@ -2714,11 +2719,11 @@ var Context$1 = (function () {
2714
2719
  Context.prototype.setFont = function (opts) {
2715
2720
  var strList = [];
2716
2721
  if (opts.fontWeight === 'bold') {
2717
- strList.push("" + opts.fontWeight);
2722
+ strList.push("".concat(opts.fontWeight));
2718
2723
  }
2719
- strList.push(this._doSize(opts.fontSize || 12) + "px");
2720
- strList.push("" + (opts.fontFamily || 'sans-serif'));
2721
- this._ctx.font = "" + strList.join(' ');
2724
+ strList.push("".concat(this._doSize(opts.fontSize || 12), "px"));
2725
+ strList.push("".concat(opts.fontFamily || 'sans-serif'));
2726
+ this._ctx.font = "".concat(strList.join(' '));
2722
2727
  };
2723
2728
  Context.prototype.setTextBaseline = function (baseline) {
2724
2729
  this._ctx.textBaseline = baseline;
@@ -2793,16 +2798,16 @@ function color$2(value) {
2793
2798
  return isColorStr$1(value);
2794
2799
  }
2795
2800
  function imageURL$1(value) {
2796
- return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
2801
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
2797
2802
  }
2798
2803
  function imageBase64$1(value) {
2799
- return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
2804
+ return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
2800
2805
  }
2801
2806
  function imageSrc$1(value) {
2802
2807
  return (imageBase64$1(value) || imageURL$1(value));
2803
2808
  }
2804
2809
  function svg$1(value) {
2805
- return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
2810
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
2806
2811
  }
2807
2812
  function html$1(value) {
2808
2813
  var result = false;
@@ -3168,34 +3173,45 @@ function drawText(ctx, elem, loader) {
3168
3173
  var fontHeight = desc.lineHeight || desc.fontSize;
3169
3174
  var descTextList = descText.split('\n');
3170
3175
  var lines = [];
3171
- descTextList.forEach(function (tempText) {
3176
+ var lineNum = 0;
3177
+ descTextList.forEach(function (tempText, idx) {
3172
3178
  var lineText = '';
3173
- var lineNum = 0;
3174
- for (var i = 0; i < tempText.length; i++) {
3175
- if (ctx.measureText(lineText + (tempText[i] || '')).width < ctx.calcDeviceNum(elem.w)) {
3176
- lineText += (tempText[i] || '');
3177
- }
3178
- else {
3179
- lines.push({
3180
- text: lineText,
3181
- width: ctx.calcScreenNum(ctx.measureText(lineText).width),
3182
- });
3183
- lineText = (tempText[i] || '');
3184
- lineNum++;
3185
- }
3186
- if ((lineNum + 1) * fontHeight > elem.h) {
3187
- break;
3188
- }
3189
- if (lineText && tempText.length - 1 === i) {
3190
- if ((lineNum + 1) * fontHeight < elem.h) {
3179
+ if (tempText.length > 0) {
3180
+ for (var i = 0; i < tempText.length; i++) {
3181
+ if (ctx.measureText(lineText + (tempText[i] || '')).width < ctx.calcDeviceNum(elem.w)) {
3182
+ lineText += (tempText[i] || '');
3183
+ }
3184
+ else {
3191
3185
  lines.push({
3192
3186
  text: lineText,
3193
3187
  width: ctx.calcScreenNum(ctx.measureText(lineText).width),
3194
3188
  });
3189
+ lineText = (tempText[i] || '');
3190
+ lineNum++;
3191
+ }
3192
+ if ((lineNum + 1) * fontHeight > elem.h) {
3195
3193
  break;
3196
3194
  }
3195
+ if (tempText.length - 1 === i) {
3196
+ if ((lineNum + 1) * fontHeight < elem.h) {
3197
+ lines.push({
3198
+ text: lineText,
3199
+ width: ctx.calcScreenNum(ctx.measureText(lineText).width),
3200
+ });
3201
+ if (idx < descTextList.length - 1) {
3202
+ lineNum++;
3203
+ }
3204
+ break;
3205
+ }
3206
+ }
3197
3207
  }
3198
3208
  }
3209
+ else {
3210
+ lines.push({
3211
+ text: '',
3212
+ width: 0,
3213
+ });
3214
+ }
3199
3215
  });
3200
3216
  {
3201
3217
  var _y_1 = elem.y;
@@ -3848,16 +3864,16 @@ function color(value) {
3848
3864
  return isColorStr(value);
3849
3865
  }
3850
3866
  function imageURL(value) {
3851
- return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
3867
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("".concat(value)));
3852
3868
  }
3853
3869
  function imageBase64(value) {
3854
- return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
3870
+ return (typeof value === 'string' && /^(data:image\/)/.test("".concat(value)));
3855
3871
  }
3856
3872
  function imageSrc(value) {
3857
3873
  return (imageBase64(value) || imageURL(value));
3858
3874
  }
3859
3875
  function svg(value) {
3860
- return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
3876
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test("".concat(value).trim()) && /<\/[\s]{0,}svg>$/i.test("".concat(value).trim()));
3861
3877
  }
3862
3878
  function html(value) {
3863
3879
  var result = false;
@@ -4949,48 +4965,50 @@ var Helper = (function () {
4949
4965
  if (typeof elem.angle === 'number' && Math.abs(elem.angle) > limitQbliqueAngle) {
4950
4966
  hideObliqueDirection = true;
4951
4967
  }
4968
+ var controllerOffset = lineWidth;
4952
4969
  var wrapper = {
4953
4970
  uuid: elem.uuid,
4954
4971
  controllerSize: controllerSize,
4972
+ controllerOffset: controllerOffset,
4955
4973
  lock: ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.lock) === true,
4956
4974
  controllers: {
4957
4975
  topLeft: {
4958
- x: elem.x - controllerSize - bw,
4959
- y: elem.y - controllerSize - bw,
4976
+ x: elem.x - controllerOffset - bw,
4977
+ y: elem.y - controllerOffset - bw,
4960
4978
  invisible: hideObliqueDirection || ((_c = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _c === void 0 ? void 0 : _c.disbaleScale) === true,
4961
4979
  },
4962
4980
  top: {
4963
4981
  x: elem.x + elem.w / 2,
4964
- y: elem.y - controllerSize - bw,
4982
+ y: elem.y - controllerOffset - bw,
4965
4983
  invisible: ((_d = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _d === void 0 ? void 0 : _d.disbaleScale) === true,
4966
4984
  },
4967
4985
  topRight: {
4968
- x: elem.x + elem.w + controllerSize + bw,
4969
- y: elem.y - controllerSize - bw,
4986
+ x: elem.x + elem.w + controllerOffset + bw,
4987
+ y: elem.y - controllerOffset - bw,
4970
4988
  invisible: hideObliqueDirection || ((_e = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _e === void 0 ? void 0 : _e.disbaleScale) === true,
4971
4989
  },
4972
4990
  right: {
4973
- x: elem.x + elem.w + controllerSize + bw,
4991
+ x: elem.x + elem.w + controllerOffset + bw,
4974
4992
  y: elem.y + elem.h / 2,
4975
4993
  invisible: ((_f = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _f === void 0 ? void 0 : _f.disbaleScale) === true
4976
4994
  },
4977
4995
  bottomRight: {
4978
- x: elem.x + elem.w + controllerSize + bw,
4979
- y: elem.y + elem.h + controllerSize + bw,
4996
+ x: elem.x + elem.w + controllerOffset + bw,
4997
+ y: elem.y + elem.h + controllerOffset + bw,
4980
4998
  invisible: hideObliqueDirection || ((_g = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _g === void 0 ? void 0 : _g.disbaleScale) === true,
4981
4999
  },
4982
5000
  bottom: {
4983
5001
  x: elem.x + elem.w / 2,
4984
- y: elem.y + elem.h + controllerSize + bw,
5002
+ y: elem.y + elem.h + controllerOffset + bw,
4985
5003
  invisible: ((_h = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _h === void 0 ? void 0 : _h.disbaleScale) === true,
4986
5004
  },
4987
5005
  bottomLeft: {
4988
- x: elem.x - controllerSize - bw,
4989
- y: elem.y + elem.h + controllerSize + bw,
5006
+ x: elem.x - controllerOffset - bw,
5007
+ y: elem.y + elem.h + controllerOffset + bw,
4990
5008
  invisible: hideObliqueDirection || ((_j = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _j === void 0 ? void 0 : _j.disbaleScale) === true,
4991
5009
  },
4992
5010
  left: {
4993
- x: elem.x - controllerSize - bw,
5011
+ x: elem.x - controllerOffset - bw,
4994
5012
  y: elem.y + elem.h / 2,
4995
5013
  invisible: ((_k = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _k === void 0 ? void 0 : _k.disbaleScale) === true
4996
5014
  },