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