@idraw/core 0.1.13 → 0.2.0-alpha.3

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
@@ -122,7 +122,7 @@ function createUUID$3() {
122
122
  }
123
123
  return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
124
124
  }
125
- function deepClone$5(target) {
125
+ function deepClone$6(target) {
126
126
  function _clone(t) {
127
127
  var type = is$2(t);
128
128
  if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
@@ -270,7 +270,7 @@ var index$1 = {
270
270
  },
271
271
  istype: istype$2,
272
272
  data: {
273
- deepClone: deepClone$5,
273
+ deepClone: deepClone$6,
274
274
  }
275
275
  };
276
276
  var BoardEvent = (function () {
@@ -914,7 +914,7 @@ var _watcher = Symbol('_watcher');
914
914
  var _render = Symbol('_render');
915
915
  var _parsePrivateOptions = Symbol('_parsePrivateOptions');
916
916
  var _scroller = Symbol('_scroller');
917
- var _initEvent$1 = Symbol('_initEvent');
917
+ var _initEvent = Symbol('_initEvent');
918
918
  var _doScrollX = Symbol('_doScrollX');
919
919
  var _doScrollY = Symbol('_doScrollY');
920
920
  var _doMoveScroll = Symbol('_doMoveScroll');
@@ -1043,7 +1043,7 @@ var Board = (function () {
1043
1043
  return;
1044
1044
  }
1045
1045
  this[_resetContext]();
1046
- this[_initEvent$1]();
1046
+ this[_initEvent]();
1047
1047
  this[_hasRendered] = true;
1048
1048
  };
1049
1049
  Board.prototype[_resetContext] = function () {
@@ -1063,7 +1063,7 @@ var Board = (function () {
1063
1063
  };
1064
1064
  return __assign(__assign({}, defaultOpts), opts);
1065
1065
  };
1066
- Board.prototype[_initEvent$1] = function () {
1066
+ Board.prototype[_initEvent] = function () {
1067
1067
  var _this = this;
1068
1068
  if (this[_hasRendered] === true) {
1069
1069
  return;
@@ -1204,7 +1204,7 @@ function createUUID$2() {
1204
1204
  }
1205
1205
  return "" + str4() + str4() + "-" + str4() + "-" + str4() + "-" + str4() + "-" + str4() + str4() + str4();
1206
1206
  }
1207
- function deepClone$4(target) {
1207
+ function deepClone$5(target) {
1208
1208
  function _clone(t) {
1209
1209
  var type = is$1(t);
1210
1210
  if (['Null', 'Number', 'String', 'Boolean', 'Undefined'].indexOf(type) >= 0) {
@@ -1352,10 +1352,212 @@ var index = {
1352
1352
  },
1353
1353
  istype: istype$1,
1354
1354
  data: {
1355
- deepClone: deepClone$4,
1355
+ deepClone: deepClone$5,
1356
1356
  }
1357
1357
  };
1358
1358
 
1359
+ var isColorStr$1 = index.color.isColorStr;
1360
+ function number(value) {
1361
+ return (typeof value === 'number' && (value > 0 || value <= 0));
1362
+ }
1363
+ function x(value) {
1364
+ return number(value);
1365
+ }
1366
+ function y(value) {
1367
+ return number(value);
1368
+ }
1369
+ function w(value) {
1370
+ return (typeof value === 'number' && value >= 0);
1371
+ }
1372
+ function h(value) {
1373
+ return (typeof value === 'number' && value >= 0);
1374
+ }
1375
+ function angle(value) {
1376
+ return (typeof value === 'number' && value >= -360 && value <= 360);
1377
+ }
1378
+ function borderWidth(value) {
1379
+ return w(value);
1380
+ }
1381
+ function borderRadius(value) {
1382
+ return number(value) && value >= 0;
1383
+ }
1384
+ function color$1(value) {
1385
+ return isColorStr$1(value);
1386
+ }
1387
+ function imageURL(value) {
1388
+ return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
1389
+ }
1390
+ function imageBase64(value) {
1391
+ return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
1392
+ }
1393
+ function imageSrc(value) {
1394
+ return (imageBase64(value) || imageURL(value));
1395
+ }
1396
+ function svg(value) {
1397
+ return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
1398
+ }
1399
+ function html(value) {
1400
+ var result = false;
1401
+ if (typeof value === 'string') {
1402
+ var div = document.createElement('div');
1403
+ div.innerHTML = value;
1404
+ if (div.children.length > 0) {
1405
+ result = true;
1406
+ }
1407
+ div = null;
1408
+ }
1409
+ return result;
1410
+ }
1411
+ function text(value) {
1412
+ return typeof value === 'string';
1413
+ }
1414
+ function fontSize(value) {
1415
+ return number(value) && value > 0;
1416
+ }
1417
+ function lineHeight(value) {
1418
+ return number(value) && value > 0;
1419
+ }
1420
+ function textAlign(value) {
1421
+ return ['center', 'left', 'right'].includes(value);
1422
+ }
1423
+ function fontFamily(value) {
1424
+ return typeof value === 'string' && value.length > 0;
1425
+ }
1426
+ function fontWeight(value) {
1427
+ return ['bold'].includes(value);
1428
+ }
1429
+ var is = {
1430
+ x: x,
1431
+ y: y,
1432
+ w: w,
1433
+ h: h,
1434
+ angle: angle,
1435
+ number: number,
1436
+ borderWidth: borderWidth,
1437
+ borderRadius: borderRadius,
1438
+ color: color$1,
1439
+ imageSrc: imageSrc,
1440
+ imageURL: imageURL,
1441
+ imageBase64: imageBase64,
1442
+ svg: svg,
1443
+ html: html,
1444
+ text: text,
1445
+ fontSize: fontSize,
1446
+ lineHeight: lineHeight,
1447
+ textAlign: textAlign,
1448
+ fontFamily: fontFamily,
1449
+ fontWeight: fontWeight,
1450
+ };
1451
+
1452
+ function attrs(attrs) {
1453
+ var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
1454
+ if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
1455
+ return false;
1456
+ }
1457
+ if (!(angle >= -360 && angle <= 360)) {
1458
+ return false;
1459
+ }
1460
+ return true;
1461
+ }
1462
+ function box(desc) {
1463
+ if (desc === void 0) { desc = {}; }
1464
+ var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
1465
+ if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
1466
+ return false;
1467
+ }
1468
+ if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
1469
+ return false;
1470
+ }
1471
+ if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
1472
+ return false;
1473
+ }
1474
+ return true;
1475
+ }
1476
+ function rectDesc(desc) {
1477
+ var bgColor = desc.bgColor;
1478
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
1479
+ return false;
1480
+ }
1481
+ if (!box(desc)) {
1482
+ return false;
1483
+ }
1484
+ return true;
1485
+ }
1486
+ function circleDesc(desc) {
1487
+ var bgColor = desc.bgColor, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
1488
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
1489
+ return false;
1490
+ }
1491
+ if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
1492
+ return false;
1493
+ }
1494
+ if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
1495
+ return false;
1496
+ }
1497
+ return true;
1498
+ }
1499
+ function imageDesc(desc) {
1500
+ var src = desc.src;
1501
+ if (!is.imageSrc(src)) {
1502
+ return false;
1503
+ }
1504
+ return true;
1505
+ }
1506
+ function svgDesc(desc) {
1507
+ var svg = desc.svg;
1508
+ if (!is.svg(svg)) {
1509
+ return false;
1510
+ }
1511
+ return true;
1512
+ }
1513
+ function htmlDesc(desc) {
1514
+ var html = desc.html;
1515
+ if (!is.html(html)) {
1516
+ return false;
1517
+ }
1518
+ return true;
1519
+ }
1520
+ function textDesc(desc) {
1521
+ 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;
1522
+ if (!is.text(text)) {
1523
+ return false;
1524
+ }
1525
+ if (!is.color(color)) {
1526
+ return false;
1527
+ }
1528
+ if (!is.fontSize(fontSize)) {
1529
+ return false;
1530
+ }
1531
+ if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
1532
+ return false;
1533
+ }
1534
+ if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
1535
+ return false;
1536
+ }
1537
+ if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
1538
+ return false;
1539
+ }
1540
+ if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
1541
+ return false;
1542
+ }
1543
+ if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
1544
+ return false;
1545
+ }
1546
+ if (!box(desc)) {
1547
+ return false;
1548
+ }
1549
+ return true;
1550
+ }
1551
+ var check = {
1552
+ attrs: attrs,
1553
+ textDesc: textDesc,
1554
+ rectDesc: rectDesc,
1555
+ circleDesc: circleDesc,
1556
+ imageDesc: imageDesc,
1557
+ svgDesc: svgDesc,
1558
+ htmlDesc: htmlDesc,
1559
+ };
1560
+
1359
1561
  function parseRadianToAngle(radian) {
1360
1562
  return radian / Math.PI * 180;
1361
1563
  }
@@ -1440,7 +1642,7 @@ function rotateContext(ctx, center, radian, callback) {
1440
1642
  }
1441
1643
  }
1442
1644
 
1443
- var istype = index.istype, color$1 = index.color;
1645
+ var istype = index.istype, color = index.color;
1444
1646
  function clearContext(ctx) {
1445
1647
  ctx.setFillStyle('#000000');
1446
1648
  ctx.setStrokeStyle('#000000');
@@ -1486,7 +1688,7 @@ function drawBoxBorder(ctx, elem) {
1486
1688
  }
1487
1689
  var bw = elem.desc.borderWidth;
1488
1690
  var borderColor = '#000000';
1489
- if (color$1.isColorStr(elem.desc.borderColor) === true) {
1691
+ if (color.isColorStr(elem.desc.borderColor) === true) {
1490
1692
  borderColor = elem.desc.borderColor;
1491
1693
  }
1492
1694
  var x = elem.x - bw / 2;
@@ -1512,7 +1714,7 @@ function drawBoxBorder(ctx, elem) {
1512
1714
  }
1513
1715
 
1514
1716
  function drawRect(ctx, elem) {
1515
- drawBox(ctx, elem, elem.desc.color);
1717
+ drawBox(ctx, elem, elem.desc.bgColor);
1516
1718
  }
1517
1719
 
1518
1720
  function drawImage(ctx, elem, loader) {
@@ -1611,7 +1813,7 @@ function drawText(ctx, elem, loader, helperConfig) {
1611
1813
  function drawCircle(ctx, elem) {
1612
1814
  rotateElement(ctx, elem, function (ctx) {
1613
1815
  var x = elem.x, y = elem.y, w = elem.w, h = elem.h, desc = elem.desc;
1614
- var _a = desc.color, color = _a === void 0 ? '#000000' : _a, _b = desc.borderColor, borderColor = _b === void 0 ? '#000000' : _b, borderWidth = desc.borderWidth;
1816
+ var _a = desc.bgColor, bgColor = _a === void 0 ? '#000000' : _a, _b = desc.borderColor, borderColor = _b === void 0 ? '#000000' : _b, borderWidth = desc.borderWidth;
1615
1817
  var a = w / 2;
1616
1818
  var b = h / 2;
1617
1819
  var centerX = x + a;
@@ -1631,7 +1833,7 @@ function drawCircle(ctx, elem) {
1631
1833
  ctx.stroke();
1632
1834
  }
1633
1835
  ctx.beginPath();
1634
- ctx.setFillStyle(color);
1836
+ ctx.setFillStyle(bgColor);
1635
1837
  ctx.moveTo(centerX + a, centerY);
1636
1838
  for (var i = 0; i < 2 * Math.PI; i += unit) {
1637
1839
  ctx.lineTo(centerX + a * Math.cos(i), centerY + b * Math.sin(i));
@@ -1774,13 +1976,13 @@ function drawElementListWrappers(ctx, config) {
1774
1976
  });
1775
1977
  }
1776
1978
 
1777
- var isColorStr$1 = index.color.isColorStr;
1979
+ var isColorStr = index.color.isColorStr;
1778
1980
  function drawContext(ctx, data, helperConfig, loader) {
1779
1981
  var _a;
1780
1982
  clearContext(ctx);
1781
1983
  var size = ctx.getSize();
1782
1984
  ctx.clearRect(0, 0, size.contextWidth, size.contextHeight);
1783
- if (typeof data.bgColor === 'string' && isColorStr$1(data.bgColor)) {
1985
+ if (typeof data.bgColor === 'string' && isColorStr(data.bgColor)) {
1784
1986
  drawBgColor(ctx, data.bgColor);
1785
1987
  }
1786
1988
  if (!(data.elements.length > 0)) {
@@ -1823,11 +2025,30 @@ function drawContext(ctx, data, helperConfig, loader) {
1823
2025
  drawElementListWrappers(ctx, helperConfig);
1824
2026
  }
1825
2027
 
1826
- var LoaderEvent = (function () {
1827
- function LoaderEvent() {
2028
+ var defaultConfig = {
2029
+ elementWrapper: {
2030
+ color: '#2ab6f1',
2031
+ lockColor: '#aaaaaa',
2032
+ dotSize: 6,
2033
+ lineWidth: 1,
2034
+ lineDash: [4, 3],
2035
+ }
2036
+ };
2037
+ function mergeConfig(config) {
2038
+ var result = index.data.deepClone(defaultConfig);
2039
+ if (config) {
2040
+ if (config.elementWrapper) {
2041
+ result.elementWrapper = __assign$1(__assign$1({}, result.elementWrapper), config.elementWrapper);
2042
+ }
2043
+ }
2044
+ return result;
2045
+ }
2046
+
2047
+ var CoreEvent = (function () {
2048
+ function CoreEvent() {
1828
2049
  this._listeners = new Map();
1829
2050
  }
1830
- LoaderEvent.prototype.on = function (eventKey, callback) {
2051
+ CoreEvent.prototype.on = function (eventKey, callback) {
1831
2052
  if (this._listeners.has(eventKey)) {
1832
2053
  var callbacks = this._listeners.get(eventKey);
1833
2054
  callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
@@ -1837,7 +2058,7 @@ var LoaderEvent = (function () {
1837
2058
  this._listeners.set(eventKey, [callback]);
1838
2059
  }
1839
2060
  };
1840
- LoaderEvent.prototype.off = function (eventKey, callback) {
2061
+ CoreEvent.prototype.off = function (eventKey, callback) {
1841
2062
  if (this._listeners.has(eventKey)) {
1842
2063
  var callbacks = this._listeners.get(eventKey);
1843
2064
  if (Array.isArray(callbacks)) {
@@ -1851,7 +2072,7 @@ var LoaderEvent = (function () {
1851
2072
  this._listeners.set(eventKey, callbacks || []);
1852
2073
  }
1853
2074
  };
1854
- LoaderEvent.prototype.trigger = function (eventKey, arg) {
2075
+ CoreEvent.prototype.trigger = function (eventKey, arg) {
1855
2076
  var callbacks = this._listeners.get(eventKey);
1856
2077
  if (Array.isArray(callbacks)) {
1857
2078
  callbacks.forEach(function (cb) {
@@ -1863,7 +2084,7 @@ var LoaderEvent = (function () {
1863
2084
  return false;
1864
2085
  }
1865
2086
  };
1866
- LoaderEvent.prototype.has = function (name) {
2087
+ CoreEvent.prototype.has = function (name) {
1867
2088
  if (this._listeners.has(name)) {
1868
2089
  var list = this._listeners.get(name);
1869
2090
  if (Array.isArray(list) && list.length > 0) {
@@ -1872,327 +2093,87 @@ var LoaderEvent = (function () {
1872
2093
  }
1873
2094
  return false;
1874
2095
  };
1875
- return LoaderEvent;
2096
+ return CoreEvent;
1876
2097
  }());
1877
2098
 
1878
- function filterScript(html) {
1879
- return html.replace(/<script[\s\S]*?<\/script>/ig, '');
1880
- }
1881
-
1882
- var _a = index.loader, loadImage = _a.loadImage, loadSVG = _a.loadSVG, loadHTML = _a.loadHTML;
1883
- var LoaderStatus;
1884
- (function (LoaderStatus) {
1885
- LoaderStatus["FREE"] = "free";
1886
- LoaderStatus["LOADING"] = "loading";
1887
- LoaderStatus["COMPLETE"] = "complete";
1888
- })(LoaderStatus || (LoaderStatus = {}));
1889
- var Loader = (function () {
1890
- function Loader(opts) {
1891
- this._currentLoadData = {};
1892
- this._currentUUIDQueue = [];
1893
- this._storageLoadData = {};
1894
- this._status = LoaderStatus.FREE;
1895
- this._waitingLoadQueue = [];
1896
- this._opts = opts;
1897
- this._event = new LoaderEvent();
1898
- this._waitingLoadQueue = [];
1899
- }
1900
- Loader.prototype.load = function (data, changeResourceUUIDs) {
1901
- var _a = this._resetLoadData(data, changeResourceUUIDs), uuidQueue = _a[0], loadData = _a[1];
1902
- if (this._status === LoaderStatus.FREE || this._status === LoaderStatus.COMPLETE) {
1903
- this._currentUUIDQueue = uuidQueue;
1904
- this._currentLoadData = loadData;
1905
- this._loadTask();
1906
- }
1907
- else if (this._status === LoaderStatus.LOADING && uuidQueue.length > 0) {
1908
- this._waitingLoadQueue.push({
1909
- uuidQueue: uuidQueue,
1910
- loadData: loadData,
1911
- });
1912
- }
1913
- };
1914
- Loader.prototype.on = function (name, callback) {
1915
- this._event.on(name, callback);
1916
- };
1917
- Loader.prototype.off = function (name, callback) {
1918
- this._event.off(name, callback);
1919
- };
1920
- Loader.prototype.isComplete = function () {
1921
- return this._status === LoaderStatus.COMPLETE;
1922
- };
1923
- Loader.prototype.getContent = function (uuid) {
1924
- var _a;
1925
- if (((_a = this._storageLoadData[uuid]) === null || _a === void 0 ? void 0 : _a.status) === 'loaded') {
1926
- return this._storageLoadData[uuid].content;
1927
- }
1928
- return null;
1929
- };
1930
- Loader.prototype._resetLoadData = function (data, changeResourceUUIDs) {
1931
- var loadData = {};
1932
- var uuidQueue = [];
1933
- var storageLoadData = this._storageLoadData;
1934
- for (var i = data.elements.length - 1; i >= 0; i--) {
1935
- var elem = data.elements[i];
1936
- if (['image', 'svg', 'html',].includes(elem.type)) {
1937
- if (!storageLoadData[elem.uuid]) {
1938
- loadData[elem.uuid] = this._createEmptyLoadItem(elem);
1939
- uuidQueue.push(elem.uuid);
1940
- }
1941
- else {
1942
- if (changeResourceUUIDs.includes(elem.uuid)) {
1943
- loadData[elem.uuid] = this._createEmptyLoadItem(elem);
1944
- uuidQueue.push(elem.uuid);
1945
- }
1946
- }
1947
- }
1948
- }
1949
- return [uuidQueue, loadData];
1950
- };
1951
- Loader.prototype._createEmptyLoadItem = function (elem) {
1952
- var source = '';
1953
- var type = elem.type;
1954
- var elemW = elem.w;
1955
- var elemH = elem.h;
1956
- if (elem.type === 'image') {
1957
- var _elem = elem;
1958
- source = _elem.desc.src || '';
1959
- }
1960
- else if (elem.type === 'svg') {
1961
- var _elem = elem;
1962
- source = _elem.desc.svg || '';
1963
- }
1964
- else if (elem.type === 'html') {
1965
- var _elem = elem;
1966
- source = filterScript(_elem.desc.html || '');
1967
- elemW = _elem.desc.width || elem.w;
1968
- elemH = _elem.desc.height || elem.h;
2099
+ function isChangeImageElementResource(before, after) {
2100
+ var _a, _b;
2101
+ return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.src) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.src));
2102
+ }
2103
+ function isChangeSVGElementResource(before, after) {
2104
+ var _a, _b;
2105
+ return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.svg) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.svg));
2106
+ }
2107
+ function isChangeHTMLElementResource(before, after) {
2108
+ var _a, _b, _c, _d, _e, _f;
2109
+ return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.html) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.html)
2110
+ || ((_c = before === null || before === void 0 ? void 0 : before.desc) === null || _c === void 0 ? void 0 : _c.width) !== ((_d = after === null || after === void 0 ? void 0 : after.desc) === null || _d === void 0 ? void 0 : _d.width)
2111
+ || ((_e = before === null || before === void 0 ? void 0 : before.desc) === null || _e === void 0 ? void 0 : _e.height) !== ((_f = after === null || after === void 0 ? void 0 : after.desc) === null || _f === void 0 ? void 0 : _f.height));
2112
+ }
2113
+ function diffElementResourceChange(before, after) {
2114
+ var result = null;
2115
+ var isChange = false;
2116
+ switch (after.type) {
2117
+ case 'image': {
2118
+ isChange = isChangeImageElementResource(before, after);
2119
+ break;
1969
2120
  }
1970
- return {
1971
- type: type,
1972
- status: 'null',
1973
- content: null,
1974
- source: source,
1975
- elemW: elemW,
1976
- elemH: elemH,
1977
- };
1978
- };
1979
- Loader.prototype._loadTask = function () {
1980
- var _this = this;
1981
- if (this._status === LoaderStatus.LOADING) {
1982
- return;
2121
+ case 'svg': {
2122
+ isChange = isChangeSVGElementResource(before, after);
2123
+ break;
1983
2124
  }
1984
- this._status = LoaderStatus.LOADING;
1985
- if (this._currentUUIDQueue.length === 0) {
1986
- if (this._waitingLoadQueue.length === 0) {
1987
- this._status = LoaderStatus.COMPLETE;
1988
- this._event.trigger('complete', undefined);
1989
- return;
1990
- }
1991
- else {
1992
- var waitingItem = this._waitingLoadQueue.shift();
1993
- if (waitingItem) {
1994
- var uuidQueue = waitingItem.uuidQueue, loadData = waitingItem.loadData;
1995
- this._currentLoadData = loadData;
1996
- this._currentUUIDQueue = uuidQueue;
1997
- }
1998
- }
2125
+ case 'html': {
2126
+ isChange = isChangeHTMLElementResource(before, after);
2127
+ break;
1999
2128
  }
2000
- var maxParallelNum = this._opts.maxParallelNum;
2001
- var uuids = this._currentUUIDQueue.splice(0, maxParallelNum);
2002
- var uuidMap = {};
2003
- uuids.forEach(function (url, i) {
2004
- uuidMap[url] = i;
2005
- });
2006
- var loadUUIDList = [];
2007
- var _loadAction = function () {
2008
- if (loadUUIDList.length >= maxParallelNum) {
2009
- return false;
2010
- }
2011
- if (uuids.length === 0) {
2012
- return true;
2013
- }
2014
- var _loop_1 = function (i) {
2015
- var uuid = uuids.shift();
2016
- if (uuid === undefined) {
2017
- return "break";
2018
- }
2019
- loadUUIDList.push(uuid);
2020
- _this._loadElementSource(_this._currentLoadData[uuid]).then(function (image) {
2021
- loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
2022
- var status = _loadAction();
2023
- _this._storageLoadData[uuid] = {
2024
- type: _this._currentLoadData[uuid].type,
2025
- status: 'loaded',
2026
- content: image,
2027
- source: _this._currentLoadData[uuid].source,
2028
- elemW: _this._currentLoadData[uuid].elemW,
2029
- elemH: _this._currentLoadData[uuid].elemH,
2030
- };
2031
- if (loadUUIDList.length === 0 && uuids.length === 0 && status === true) {
2032
- _this._status = LoaderStatus.FREE;
2033
- _this._loadTask();
2034
- }
2035
- _this._event.trigger('load', {
2036
- type: _this._storageLoadData[uuid].type,
2037
- status: _this._storageLoadData[uuid].status,
2038
- content: _this._storageLoadData[uuid].content,
2039
- source: _this._storageLoadData[uuid].source,
2040
- elemW: _this._storageLoadData[uuid].elemW,
2041
- elemH: _this._storageLoadData[uuid].elemH,
2042
- });
2043
- }).catch(function (err) {
2044
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2045
- console.warn(err);
2046
- loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
2047
- var status = _loadAction();
2048
- if (_this._currentLoadData[uuid]) {
2049
- _this._storageLoadData[uuid] = {
2050
- type: (_a = _this._currentLoadData[uuid]) === null || _a === void 0 ? void 0 : _a.type,
2051
- status: 'fail',
2052
- content: null,
2053
- error: err,
2054
- source: (_b = _this._currentLoadData[uuid]) === null || _b === void 0 ? void 0 : _b.source,
2055
- elemW: (_c = _this._currentLoadData[uuid]) === null || _c === void 0 ? void 0 : _c.elemW,
2056
- elemH: (_d = _this._currentLoadData[uuid]) === null || _d === void 0 ? void 0 : _d.elemH,
2057
- };
2058
- }
2059
- if (loadUUIDList.length === 0 && uuids.length === 0 && status === true) {
2060
- _this._status = LoaderStatus.FREE;
2061
- _this._loadTask();
2062
- }
2063
- if (_this._currentLoadData[uuid]) {
2064
- _this._event.trigger('error', {
2065
- type: (_e = _this._storageLoadData[uuid]) === null || _e === void 0 ? void 0 : _e.type,
2066
- status: (_f = _this._storageLoadData[uuid]) === null || _f === void 0 ? void 0 : _f.status,
2067
- content: (_g = _this._storageLoadData[uuid]) === null || _g === void 0 ? void 0 : _g.content,
2068
- source: (_h = _this._storageLoadData[uuid]) === null || _h === void 0 ? void 0 : _h.source,
2069
- elemW: (_j = _this._storageLoadData[uuid]) === null || _j === void 0 ? void 0 : _j.elemW,
2070
- elemH: (_k = _this._storageLoadData[uuid]) === null || _k === void 0 ? void 0 : _k.elemH,
2071
- });
2072
- }
2073
- });
2074
- };
2075
- for (var i = loadUUIDList.length; i < maxParallelNum; i++) {
2076
- var state_1 = _loop_1();
2077
- if (state_1 === "break")
2078
- break;
2079
- }
2080
- return false;
2081
- };
2082
- _loadAction();
2083
- };
2084
- Loader.prototype._loadElementSource = function (params) {
2085
- return __awaiter(this, void 0, void 0, function () {
2086
- var image, image, image;
2087
- return __generator(this, function (_a) {
2088
- switch (_a.label) {
2089
- case 0:
2090
- if (!(params && params.type === 'image')) return [3, 2];
2091
- return [4, loadImage(params.source)];
2092
- case 1:
2093
- image = _a.sent();
2094
- return [2, image];
2095
- case 2:
2096
- if (!(params && params.type === 'svg')) return [3, 4];
2097
- return [4, loadSVG(params.source)];
2098
- case 3:
2099
- image = _a.sent();
2100
- return [2, image];
2101
- case 4:
2102
- if (!(params && params.type === 'html')) return [3, 6];
2103
- return [4, loadHTML(params.source, {
2104
- width: params.elemW, height: params.elemH
2105
- })];
2106
- case 5:
2107
- image = _a.sent();
2108
- return [2, image];
2109
- case 6: throw Error('Element\'s source is not support!');
2110
- }
2111
- });
2112
- });
2113
- };
2114
- return Loader;
2115
- }());
2116
-
2117
- var requestAnimationFrame = window.requestAnimationFrame;
2118
- var deepClone$3 = index.data.deepClone;
2119
- var DrawStatus;
2120
- (function (DrawStatus) {
2121
- DrawStatus["FREE"] = "free";
2122
- DrawStatus["DRAWING"] = "drawing";
2123
- })(DrawStatus || (DrawStatus = {}));
2124
- var Renderer = (function () {
2125
- function Renderer(board) {
2126
- var _this = this;
2127
- this._queue = [];
2128
- this._status = DrawStatus.FREE;
2129
- this._board = board;
2130
- this._loader = new Loader({
2131
- board: board,
2132
- maxParallelNum: 6
2133
- });
2134
- this._loader.on('load', function (res) {
2135
- _this._drawFrame();
2136
- });
2137
- this._loader.on('error', function (res) {
2138
- console.log('Loader Error: ', res);
2139
- });
2140
- this._loader.on('complete', function (res) {
2141
- });
2142
2129
  }
2143
- Renderer.prototype.render = function (data, helper, changeResourceUUIDs) {
2144
- var _data = deepClone$3({ data: data, helper: helper });
2145
- this._queue.push(_data);
2146
- if (this._status !== DrawStatus.DRAWING) {
2147
- this._status = DrawStatus.DRAWING;
2148
- this._drawFrame();
2130
+ if (isChange === true) {
2131
+ result = after.uuid;
2132
+ }
2133
+ return result;
2134
+ }
2135
+ function diffElementResourceChangeList(before, after) {
2136
+ var _a;
2137
+ var uuids = [];
2138
+ var beforeMap = parseDataElementMap(before);
2139
+ var afterMap = parseDataElementMap(after);
2140
+ for (var uuid in afterMap) {
2141
+ if (['image', 'svg', 'html'].includes((_a = afterMap[uuid]) === null || _a === void 0 ? void 0 : _a.type) !== true) {
2142
+ continue;
2149
2143
  }
2150
- this._loader.load(data, changeResourceUUIDs);
2151
- };
2152
- Renderer.prototype._drawFrame = function () {
2153
- var _this = this;
2154
- requestAnimationFrame(function () {
2155
- var ctx = _this._board.getContext();
2156
- var item = _this._queue[0];
2157
- var isLastFrame = false;
2158
- if (_this._queue.length > 1) {
2159
- item = _this._queue.shift();
2160
- }
2161
- else {
2162
- isLastFrame = true;
2163
- }
2164
- if (_this._loader.isComplete() !== true) {
2165
- _this._drawFrame();
2166
- if (item) {
2167
- drawContext(ctx, item.data, item.helper, _this._loader);
2168
- _this._board.draw();
2144
+ if (beforeMap[uuid]) {
2145
+ var isChange = false;
2146
+ switch (beforeMap[uuid].type) {
2147
+ case 'image': {
2148
+ isChange = isChangeImageElementResource(beforeMap[uuid], afterMap[uuid]);
2149
+ break;
2169
2150
  }
2170
- }
2171
- else if (item) {
2172
- drawContext(ctx, item.data, item.helper, _this._loader);
2173
- _this._board.draw();
2174
- _this._retainQueueOneItem();
2175
- if (!isLastFrame) {
2176
- _this._drawFrame();
2151
+ case 'svg': {
2152
+ isChange = isChangeSVGElementResource(beforeMap[uuid], afterMap[uuid]);
2153
+ break;
2177
2154
  }
2178
- else {
2179
- _this._status = DrawStatus.FREE;
2155
+ case 'html': {
2156
+ isChange = isChangeHTMLElementResource(beforeMap[uuid], afterMap[uuid]);
2157
+ break;
2180
2158
  }
2181
2159
  }
2182
- else {
2183
- _this._status = DrawStatus.FREE;
2160
+ if (isChange === true) {
2161
+ uuids.push(uuid);
2184
2162
  }
2185
- });
2186
- };
2187
- Renderer.prototype._retainQueueOneItem = function () {
2188
- if (this._queue.length <= 1) {
2189
- return;
2190
2163
  }
2191
- var lastOne = deepClone$3(this._queue[this._queue.length - 1]);
2192
- this._queue = [lastOne];
2193
- };
2194
- return Renderer;
2195
- }());
2164
+ else {
2165
+ uuids.push(uuid);
2166
+ }
2167
+ }
2168
+ return uuids;
2169
+ }
2170
+ function parseDataElementMap(data) {
2171
+ var elemMap = {};
2172
+ data.elements.forEach(function (elem) {
2173
+ elemMap[elem.uuid] = elem;
2174
+ });
2175
+ return elemMap;
2176
+ }
2196
2177
 
2197
2178
  function limitNum(num) {
2198
2179
  var numStr = num.toFixed(2);
@@ -2367,7 +2348,7 @@ var Element = (function () {
2367
2348
  return Element;
2368
2349
  }());
2369
2350
 
2370
- var deepClone$2 = index.data.deepClone;
2351
+ var deepClone$4 = index.data.deepClone;
2371
2352
  var Helper = (function () {
2372
2353
  function Helper(board, config) {
2373
2354
  this._areaStart = { x: 0, y: 0 };
@@ -2385,7 +2366,7 @@ var Helper = (function () {
2385
2366
  this._updateSelectedElementListWrapper(data, opts);
2386
2367
  };
2387
2368
  Helper.prototype.getConfig = function () {
2388
- return deepClone$2(this._helperConfig);
2369
+ return deepClone$4(this._helperConfig);
2389
2370
  };
2390
2371
  Helper.prototype.getElementIndexByUUID = function (uuid) {
2391
2372
  var index = this._helperConfig.elementIndexMap[uuid];
@@ -2394,25 +2375,71 @@ var Helper = (function () {
2394
2375
  }
2395
2376
  return null;
2396
2377
  };
2397
- Helper.prototype.isPointInElementWrapperDot = function (p) {
2378
+ Helper.prototype.isPointInElementWrapperDot = function (p, data) {
2398
2379
  var _a, _b;
2399
2380
  var ctx = this._ctx;
2400
- var uuid = (_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid;
2381
+ var uuid = ((_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid) || null;
2382
+ var directIdx = null;
2401
2383
  var direction = null;
2402
2384
  if (!this._helperConfig.selectedElementWrapper) {
2403
- return [null, null];
2385
+ return [uuid, direction, directIdx];
2404
2386
  }
2405
2387
  var wrapper = this._helperConfig.selectedElementWrapper;
2406
2388
  var dots = [
2407
- wrapper.dots.topLeft, wrapper.dots.top, wrapper.dots.topRight, wrapper.dots.right,
2408
- wrapper.dots.bottomRight, wrapper.dots.bottom, wrapper.dots.bottomLeft, wrapper.dots.left,
2409
- wrapper.dots.rotate,
2389
+ wrapper.dots.right,
2390
+ wrapper.dots.topRight,
2391
+ wrapper.dots.top,
2392
+ wrapper.dots.topLeft,
2393
+ wrapper.dots.left,
2394
+ wrapper.dots.bottomLeft,
2395
+ wrapper.dots.bottom,
2396
+ wrapper.dots.bottomRight,
2410
2397
  ];
2411
2398
  var directionNames = [
2412
- 'top-left', 'top', 'top-right', 'right',
2413
- 'bottom-right', 'bottom', 'bottom-left', 'left',
2414
- 'rotate',
2399
+ 'right',
2400
+ 'top-right',
2401
+ 'top',
2402
+ 'top-left',
2403
+ 'left',
2404
+ 'bottom-left',
2405
+ 'bottom',
2406
+ 'bottom-right',
2415
2407
  ];
2408
+ var angleMoveNum = 0;
2409
+ if (data && uuid) {
2410
+ var elemIdx = this.getElementIndexByUUID(uuid);
2411
+ if (elemIdx !== null && elemIdx >= 0) {
2412
+ var elem = data.elements[elemIdx];
2413
+ var angle = elem.angle;
2414
+ if (angle < 0) {
2415
+ angle += 360;
2416
+ }
2417
+ if (angle < 45) {
2418
+ angleMoveNum = 0;
2419
+ }
2420
+ else if (angle < 90) {
2421
+ angleMoveNum = 1;
2422
+ }
2423
+ else if (angle < 135) {
2424
+ angleMoveNum = 2;
2425
+ }
2426
+ else if (angle < 180) {
2427
+ angleMoveNum = 3;
2428
+ }
2429
+ else if (angle < 225) {
2430
+ angleMoveNum = 4;
2431
+ }
2432
+ else if (angle < 270) {
2433
+ angleMoveNum = 5;
2434
+ }
2435
+ else if (angle < 315) {
2436
+ angleMoveNum = 6;
2437
+ }
2438
+ }
2439
+ }
2440
+ if (angleMoveNum > 0) {
2441
+ directionNames = directionNames.slice(-angleMoveNum).concat(directionNames.slice(0, -angleMoveNum));
2442
+ }
2416
2443
  rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2417
2444
  for (var i = 0; i < dots.length; i++) {
2418
2445
  var dot = dots[i];
@@ -2423,11 +2450,23 @@ var Helper = (function () {
2423
2450
  direction = directionNames[i];
2424
2451
  }
2425
2452
  if (direction) {
2453
+ directIdx = i;
2426
2454
  break;
2427
2455
  }
2428
2456
  }
2429
2457
  });
2430
- return [uuid, direction];
2458
+ if (direction === null) {
2459
+ rotateContext(ctx, wrapper.translate, wrapper.radian || 0, function () {
2460
+ var dot = wrapper.dots.rotate;
2461
+ ctx.beginPath();
2462
+ ctx.arc(dot.x, dot.y, wrapper.dotSize, 0, Math.PI * 2);
2463
+ ctx.closePath();
2464
+ if (ctx.isPointInPath(p.x, p.y)) {
2465
+ direction = 'rotate';
2466
+ }
2467
+ });
2468
+ }
2469
+ return [uuid, direction, directIdx];
2431
2470
  };
2432
2471
  Helper.prototype.isPointInElementList = function (p, data) {
2433
2472
  var _a, _b;
@@ -2571,70 +2610,361 @@ var Helper = (function () {
2571
2610
  wrapperList.push(wrapper);
2572
2611
  }
2573
2612
  });
2574
- this._helperConfig.selectedElementListWrappers = wrapperList;
2575
- };
2576
- Helper.prototype._createSelectedElementWrapper = function (elem, opts) {
2577
- var _a, _b, _c;
2578
- var scale = opts.scale;
2579
- var elemWrapper = this._coreConfig.elementWrapper;
2580
- var dotSize = elemWrapper.dotSize / scale;
2581
- var lineWidth = elemWrapper.lineWidth / scale;
2582
- var lineDash = elemWrapper.lineDash.map(function (n) { return (n / scale); });
2583
- var rotateLimit = 12;
2584
- var bw = ((_a = elem.desc) === null || _a === void 0 ? void 0 : _a.borderWidth) || 0;
2585
- var wrapper = {
2586
- uuid: elem.uuid,
2587
- dotSize: dotSize,
2588
- lock: ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.lock) === true,
2589
- dots: {
2590
- topLeft: {
2591
- x: elem.x - dotSize - bw,
2592
- y: elem.y - dotSize - bw,
2593
- },
2594
- top: {
2595
- x: elem.x + elem.w / 2,
2596
- y: elem.y - dotSize - bw,
2597
- },
2598
- topRight: {
2599
- x: elem.x + elem.w + dotSize + bw,
2600
- y: elem.y - dotSize - bw,
2601
- },
2602
- right: {
2603
- x: elem.x + elem.w + dotSize + bw,
2604
- y: elem.y + elem.h / 2,
2605
- },
2606
- bottomRight: {
2607
- x: elem.x + elem.w + dotSize + bw,
2608
- y: elem.y + elem.h + dotSize + bw,
2609
- },
2610
- bottom: {
2611
- x: elem.x + elem.w / 2,
2612
- y: elem.y + elem.h + dotSize + bw,
2613
- },
2614
- bottomLeft: {
2615
- x: elem.x - dotSize - bw,
2616
- y: elem.y + elem.h + dotSize + bw,
2617
- },
2618
- left: {
2619
- x: elem.x - dotSize - bw,
2620
- y: elem.y + elem.h / 2,
2621
- },
2622
- rotate: {
2623
- x: elem.x + elem.w / 2,
2624
- y: elem.y - dotSize - (dotSize * 2 + rotateLimit) - bw,
2613
+ this._helperConfig.selectedElementListWrappers = wrapperList;
2614
+ };
2615
+ Helper.prototype._createSelectedElementWrapper = function (elem, opts) {
2616
+ var _a, _b, _c;
2617
+ var scale = opts.scale;
2618
+ var elemWrapper = this._coreConfig.elementWrapper;
2619
+ var dotSize = elemWrapper.dotSize / scale;
2620
+ var lineWidth = elemWrapper.lineWidth / scale;
2621
+ var lineDash = elemWrapper.lineDash.map(function (n) { return (n / scale); });
2622
+ var rotateLimit = 12;
2623
+ var bw = ((_a = elem.desc) === null || _a === void 0 ? void 0 : _a.borderWidth) || 0;
2624
+ var wrapper = {
2625
+ uuid: elem.uuid,
2626
+ dotSize: dotSize,
2627
+ lock: ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.lock) === true,
2628
+ dots: {
2629
+ topLeft: {
2630
+ x: elem.x - dotSize - bw,
2631
+ y: elem.y - dotSize - bw,
2632
+ },
2633
+ top: {
2634
+ x: elem.x + elem.w / 2,
2635
+ y: elem.y - dotSize - bw,
2636
+ },
2637
+ topRight: {
2638
+ x: elem.x + elem.w + dotSize + bw,
2639
+ y: elem.y - dotSize - bw,
2640
+ },
2641
+ right: {
2642
+ x: elem.x + elem.w + dotSize + bw,
2643
+ y: elem.y + elem.h / 2,
2644
+ },
2645
+ bottomRight: {
2646
+ x: elem.x + elem.w + dotSize + bw,
2647
+ y: elem.y + elem.h + dotSize + bw,
2648
+ },
2649
+ bottom: {
2650
+ x: elem.x + elem.w / 2,
2651
+ y: elem.y + elem.h + dotSize + bw,
2652
+ },
2653
+ bottomLeft: {
2654
+ x: elem.x - dotSize - bw,
2655
+ y: elem.y + elem.h + dotSize + bw,
2656
+ },
2657
+ left: {
2658
+ x: elem.x - dotSize - bw,
2659
+ y: elem.y + elem.h / 2,
2660
+ },
2661
+ rotate: {
2662
+ x: elem.x + elem.w / 2,
2663
+ y: elem.y - dotSize - (dotSize * 2 + rotateLimit) - bw,
2664
+ }
2665
+ },
2666
+ lineWidth: lineWidth,
2667
+ lineDash: lineDash,
2668
+ color: ((_c = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _c === void 0 ? void 0 : _c.lock) === true ? elemWrapper.lockColor : elemWrapper.color,
2669
+ };
2670
+ if (typeof elem.angle === 'number' && (elem.angle > 0 || elem.angle < 0)) {
2671
+ wrapper.radian = parseAngleToRadian(elem.angle);
2672
+ wrapper.translate = calcElementCenter(elem);
2673
+ }
2674
+ return wrapper;
2675
+ };
2676
+ return Helper;
2677
+ }());
2678
+
2679
+ var LoaderEvent = (function () {
2680
+ function LoaderEvent() {
2681
+ this._listeners = new Map();
2682
+ }
2683
+ LoaderEvent.prototype.on = function (eventKey, callback) {
2684
+ if (this._listeners.has(eventKey)) {
2685
+ var callbacks = this._listeners.get(eventKey);
2686
+ callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
2687
+ this._listeners.set(eventKey, callbacks || []);
2688
+ }
2689
+ else {
2690
+ this._listeners.set(eventKey, [callback]);
2691
+ }
2692
+ };
2693
+ LoaderEvent.prototype.off = function (eventKey, callback) {
2694
+ if (this._listeners.has(eventKey)) {
2695
+ var callbacks = this._listeners.get(eventKey);
2696
+ if (Array.isArray(callbacks)) {
2697
+ for (var i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
2698
+ if (callbacks[i] === callback) {
2699
+ callbacks.splice(i, 1);
2700
+ break;
2701
+ }
2702
+ }
2703
+ }
2704
+ this._listeners.set(eventKey, callbacks || []);
2705
+ }
2706
+ };
2707
+ LoaderEvent.prototype.trigger = function (eventKey, arg) {
2708
+ var callbacks = this._listeners.get(eventKey);
2709
+ if (Array.isArray(callbacks)) {
2710
+ callbacks.forEach(function (cb) {
2711
+ cb(arg);
2712
+ });
2713
+ return true;
2714
+ }
2715
+ else {
2716
+ return false;
2717
+ }
2718
+ };
2719
+ LoaderEvent.prototype.has = function (name) {
2720
+ if (this._listeners.has(name)) {
2721
+ var list = this._listeners.get(name);
2722
+ if (Array.isArray(list) && list.length > 0) {
2723
+ return true;
2724
+ }
2725
+ }
2726
+ return false;
2727
+ };
2728
+ return LoaderEvent;
2729
+ }());
2730
+
2731
+ function filterScript(html) {
2732
+ return html.replace(/<script[\s\S]*?<\/script>/ig, '');
2733
+ }
2734
+
2735
+ var _a = index.loader, loadImage = _a.loadImage, loadSVG = _a.loadSVG, loadHTML = _a.loadHTML;
2736
+ var LoaderStatus;
2737
+ (function (LoaderStatus) {
2738
+ LoaderStatus["FREE"] = "free";
2739
+ LoaderStatus["LOADING"] = "loading";
2740
+ LoaderStatus["COMPLETE"] = "complete";
2741
+ })(LoaderStatus || (LoaderStatus = {}));
2742
+ var Loader = (function () {
2743
+ function Loader(opts) {
2744
+ this._currentLoadData = {};
2745
+ this._currentUUIDQueue = [];
2746
+ this._storageLoadData = {};
2747
+ this._status = LoaderStatus.FREE;
2748
+ this._waitingLoadQueue = [];
2749
+ this._opts = opts;
2750
+ this._event = new LoaderEvent();
2751
+ this._waitingLoadQueue = [];
2752
+ }
2753
+ Loader.prototype.load = function (data, changeResourceUUIDs) {
2754
+ var _a = this._resetLoadData(data, changeResourceUUIDs), uuidQueue = _a[0], loadData = _a[1];
2755
+ if (this._status === LoaderStatus.FREE || this._status === LoaderStatus.COMPLETE) {
2756
+ this._currentUUIDQueue = uuidQueue;
2757
+ this._currentLoadData = loadData;
2758
+ this._loadTask();
2759
+ }
2760
+ else if (this._status === LoaderStatus.LOADING && uuidQueue.length > 0) {
2761
+ this._waitingLoadQueue.push({
2762
+ uuidQueue: uuidQueue,
2763
+ loadData: loadData,
2764
+ });
2765
+ }
2766
+ };
2767
+ Loader.prototype.on = function (name, callback) {
2768
+ this._event.on(name, callback);
2769
+ };
2770
+ Loader.prototype.off = function (name, callback) {
2771
+ this._event.off(name, callback);
2772
+ };
2773
+ Loader.prototype.isComplete = function () {
2774
+ return this._status === LoaderStatus.COMPLETE;
2775
+ };
2776
+ Loader.prototype.getContent = function (uuid) {
2777
+ var _a;
2778
+ if (((_a = this._storageLoadData[uuid]) === null || _a === void 0 ? void 0 : _a.status) === 'loaded') {
2779
+ return this._storageLoadData[uuid].content;
2780
+ }
2781
+ return null;
2782
+ };
2783
+ Loader.prototype._resetLoadData = function (data, changeResourceUUIDs) {
2784
+ var loadData = {};
2785
+ var uuidQueue = [];
2786
+ var storageLoadData = this._storageLoadData;
2787
+ for (var i = data.elements.length - 1; i >= 0; i--) {
2788
+ var elem = data.elements[i];
2789
+ if (['image', 'svg', 'html',].includes(elem.type)) {
2790
+ if (!storageLoadData[elem.uuid]) {
2791
+ loadData[elem.uuid] = this._createEmptyLoadItem(elem);
2792
+ uuidQueue.push(elem.uuid);
2793
+ }
2794
+ else {
2795
+ if (changeResourceUUIDs.includes(elem.uuid)) {
2796
+ loadData[elem.uuid] = this._createEmptyLoadItem(elem);
2797
+ uuidQueue.push(elem.uuid);
2798
+ }
2799
+ }
2800
+ }
2801
+ }
2802
+ return [uuidQueue, loadData];
2803
+ };
2804
+ Loader.prototype._createEmptyLoadItem = function (elem) {
2805
+ var source = '';
2806
+ var type = elem.type;
2807
+ var elemW = elem.w;
2808
+ var elemH = elem.h;
2809
+ if (elem.type === 'image') {
2810
+ var _elem = elem;
2811
+ source = _elem.desc.src || '';
2812
+ }
2813
+ else if (elem.type === 'svg') {
2814
+ var _elem = elem;
2815
+ source = _elem.desc.svg || '';
2816
+ }
2817
+ else if (elem.type === 'html') {
2818
+ var _elem = elem;
2819
+ source = filterScript(_elem.desc.html || '');
2820
+ elemW = _elem.desc.width || elem.w;
2821
+ elemH = _elem.desc.height || elem.h;
2822
+ }
2823
+ return {
2824
+ type: type,
2825
+ status: 'null',
2826
+ content: null,
2827
+ source: source,
2828
+ elemW: elemW,
2829
+ elemH: elemH,
2830
+ };
2831
+ };
2832
+ Loader.prototype._loadTask = function () {
2833
+ var _this = this;
2834
+ if (this._status === LoaderStatus.LOADING) {
2835
+ return;
2836
+ }
2837
+ this._status = LoaderStatus.LOADING;
2838
+ if (this._currentUUIDQueue.length === 0) {
2839
+ if (this._waitingLoadQueue.length === 0) {
2840
+ this._status = LoaderStatus.COMPLETE;
2841
+ this._event.trigger('complete', undefined);
2842
+ return;
2843
+ }
2844
+ else {
2845
+ var waitingItem = this._waitingLoadQueue.shift();
2846
+ if (waitingItem) {
2847
+ var uuidQueue = waitingItem.uuidQueue, loadData = waitingItem.loadData;
2848
+ this._currentLoadData = loadData;
2849
+ this._currentUUIDQueue = uuidQueue;
2850
+ }
2851
+ }
2852
+ }
2853
+ var maxParallelNum = this._opts.maxParallelNum;
2854
+ var uuids = this._currentUUIDQueue.splice(0, maxParallelNum);
2855
+ var uuidMap = {};
2856
+ uuids.forEach(function (url, i) {
2857
+ uuidMap[url] = i;
2858
+ });
2859
+ var loadUUIDList = [];
2860
+ var _loadAction = function () {
2861
+ if (loadUUIDList.length >= maxParallelNum) {
2862
+ return false;
2863
+ }
2864
+ if (uuids.length === 0) {
2865
+ return true;
2866
+ }
2867
+ var _loop_1 = function (i) {
2868
+ var uuid = uuids.shift();
2869
+ if (uuid === undefined) {
2870
+ return "break";
2625
2871
  }
2626
- },
2627
- lineWidth: lineWidth,
2628
- lineDash: lineDash,
2629
- color: ((_c = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _c === void 0 ? void 0 : _c.lock) === true ? elemWrapper.lockColor : elemWrapper.color,
2872
+ loadUUIDList.push(uuid);
2873
+ _this._loadElementSource(_this._currentLoadData[uuid]).then(function (image) {
2874
+ loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
2875
+ var status = _loadAction();
2876
+ _this._storageLoadData[uuid] = {
2877
+ type: _this._currentLoadData[uuid].type,
2878
+ status: 'loaded',
2879
+ content: image,
2880
+ source: _this._currentLoadData[uuid].source,
2881
+ elemW: _this._currentLoadData[uuid].elemW,
2882
+ elemH: _this._currentLoadData[uuid].elemH,
2883
+ };
2884
+ if (loadUUIDList.length === 0 && uuids.length === 0 && status === true) {
2885
+ _this._status = LoaderStatus.FREE;
2886
+ _this._loadTask();
2887
+ }
2888
+ _this._event.trigger('load', {
2889
+ type: _this._storageLoadData[uuid].type,
2890
+ status: _this._storageLoadData[uuid].status,
2891
+ content: _this._storageLoadData[uuid].content,
2892
+ source: _this._storageLoadData[uuid].source,
2893
+ elemW: _this._storageLoadData[uuid].elemW,
2894
+ elemH: _this._storageLoadData[uuid].elemH,
2895
+ });
2896
+ }).catch(function (err) {
2897
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2898
+ console.warn(err);
2899
+ loadUUIDList.splice(loadUUIDList.indexOf(uuid), 1);
2900
+ var status = _loadAction();
2901
+ if (_this._currentLoadData[uuid]) {
2902
+ _this._storageLoadData[uuid] = {
2903
+ type: (_a = _this._currentLoadData[uuid]) === null || _a === void 0 ? void 0 : _a.type,
2904
+ status: 'fail',
2905
+ content: null,
2906
+ error: err,
2907
+ source: (_b = _this._currentLoadData[uuid]) === null || _b === void 0 ? void 0 : _b.source,
2908
+ elemW: (_c = _this._currentLoadData[uuid]) === null || _c === void 0 ? void 0 : _c.elemW,
2909
+ elemH: (_d = _this._currentLoadData[uuid]) === null || _d === void 0 ? void 0 : _d.elemH,
2910
+ };
2911
+ }
2912
+ if (loadUUIDList.length === 0 && uuids.length === 0 && status === true) {
2913
+ _this._status = LoaderStatus.FREE;
2914
+ _this._loadTask();
2915
+ }
2916
+ if (_this._currentLoadData[uuid]) {
2917
+ _this._event.trigger('error', {
2918
+ type: (_e = _this._storageLoadData[uuid]) === null || _e === void 0 ? void 0 : _e.type,
2919
+ status: (_f = _this._storageLoadData[uuid]) === null || _f === void 0 ? void 0 : _f.status,
2920
+ content: (_g = _this._storageLoadData[uuid]) === null || _g === void 0 ? void 0 : _g.content,
2921
+ source: (_h = _this._storageLoadData[uuid]) === null || _h === void 0 ? void 0 : _h.source,
2922
+ elemW: (_j = _this._storageLoadData[uuid]) === null || _j === void 0 ? void 0 : _j.elemW,
2923
+ elemH: (_k = _this._storageLoadData[uuid]) === null || _k === void 0 ? void 0 : _k.elemH,
2924
+ });
2925
+ }
2926
+ });
2927
+ };
2928
+ for (var i = loadUUIDList.length; i < maxParallelNum; i++) {
2929
+ var state_1 = _loop_1();
2930
+ if (state_1 === "break")
2931
+ break;
2932
+ }
2933
+ return false;
2630
2934
  };
2631
- if (typeof elem.angle === 'number' && (elem.angle > 0 || elem.angle < 0)) {
2632
- wrapper.radian = parseAngleToRadian(elem.angle);
2633
- wrapper.translate = calcElementCenter(elem);
2634
- }
2635
- return wrapper;
2935
+ _loadAction();
2636
2936
  };
2637
- return Helper;
2937
+ Loader.prototype._loadElementSource = function (params) {
2938
+ return __awaiter(this, void 0, void 0, function () {
2939
+ var image, image, image;
2940
+ return __generator(this, function (_a) {
2941
+ switch (_a.label) {
2942
+ case 0:
2943
+ if (!(params && params.type === 'image')) return [3, 2];
2944
+ return [4, loadImage(params.source)];
2945
+ case 1:
2946
+ image = _a.sent();
2947
+ return [2, image];
2948
+ case 2:
2949
+ if (!(params && params.type === 'svg')) return [3, 4];
2950
+ return [4, loadSVG(params.source)];
2951
+ case 3:
2952
+ image = _a.sent();
2953
+ return [2, image];
2954
+ case 4:
2955
+ if (!(params && params.type === 'html')) return [3, 6];
2956
+ return [4, loadHTML(params.source, {
2957
+ width: params.elemW, height: params.elemH
2958
+ })];
2959
+ case 5:
2960
+ image = _a.sent();
2961
+ return [2, image];
2962
+ case 6: throw Error('Element\'s source is not support!');
2963
+ }
2964
+ });
2965
+ });
2966
+ };
2967
+ return Loader;
2638
2968
  }());
2639
2969
 
2640
2970
  var _board$1 = Symbol('_displayCtx');
@@ -2662,9 +2992,13 @@ var Mapper = (function () {
2662
2992
  if (!this.isEffectivePoint(p)) {
2663
2993
  return { cursor: cursor, elementUUID: elementUUID };
2664
2994
  }
2665
- var _a = this[_helper$1].isPointInElementWrapperDot(p), uuid = _a[0], direction = _a[1];
2995
+ var _a = this[_helper$1].isPointInElementWrapperDot(p, data), uuid = _a[0], direction = _a[1];
2666
2996
  if (uuid && direction) {
2667
2997
  switch (direction) {
2998
+ case 'top-right': {
2999
+ cursor = 'ne-resize';
3000
+ break;
3001
+ }
2668
3002
  case 'top-left': {
2669
3003
  cursor = 'nw-resize';
2670
3004
  break;
@@ -2673,10 +3007,6 @@ var Mapper = (function () {
2673
3007
  cursor = 'n-resize';
2674
3008
  break;
2675
3009
  }
2676
- case 'top-right': {
2677
- cursor = 'ne-resize';
2678
- break;
2679
- }
2680
3010
  case 'right': {
2681
3011
  cursor = 'e-resize';
2682
3012
  break;
@@ -2697,101 +3027,30 @@ var Mapper = (function () {
2697
3027
  cursor = 'w-resize';
2698
3028
  break;
2699
3029
  }
2700
- case 'rotate': {
2701
- cursor = 'grab';
2702
- break;
2703
- }
2704
- }
2705
- if (uuid) {
2706
- elementUUID = uuid;
2707
- }
2708
- }
2709
- else {
2710
- var _b = this[_element$1].isPointInElement(p, data), index = _b[0], uuid_1 = _b[1];
2711
- if (index >= 0) {
2712
- cursor = 'move';
2713
- }
2714
- if (uuid_1) {
2715
- elementUUID = uuid_1;
2716
- }
2717
- }
2718
- return {
2719
- cursor: cursor,
2720
- elementUUID: elementUUID,
2721
- };
2722
- };
2723
- return Mapper;
2724
- }());
2725
-
2726
- var defaultConfig = {
2727
- elementWrapper: {
2728
- color: '#2ab6f1',
2729
- lockColor: '#aaaaaa',
2730
- dotSize: 6,
2731
- lineWidth: 1,
2732
- lineDash: [4, 3],
2733
- }
2734
- };
2735
- function mergeConfig(config) {
2736
- var result = index.data.deepClone(defaultConfig);
2737
- if (config) {
2738
- if (config.elementWrapper) {
2739
- result.elementWrapper = __assign$1(__assign$1({}, result.elementWrapper), config.elementWrapper);
2740
- }
2741
- }
2742
- return result;
2743
- }
2744
-
2745
- var CoreEvent = (function () {
2746
- function CoreEvent() {
2747
- this._listeners = new Map();
2748
- }
2749
- CoreEvent.prototype.on = function (eventKey, callback) {
2750
- if (this._listeners.has(eventKey)) {
2751
- var callbacks = this._listeners.get(eventKey);
2752
- callbacks === null || callbacks === void 0 ? void 0 : callbacks.push(callback);
2753
- this._listeners.set(eventKey, callbacks || []);
2754
- }
2755
- else {
2756
- this._listeners.set(eventKey, [callback]);
2757
- }
2758
- };
2759
- CoreEvent.prototype.off = function (eventKey, callback) {
2760
- if (this._listeners.has(eventKey)) {
2761
- var callbacks = this._listeners.get(eventKey);
2762
- if (Array.isArray(callbacks)) {
2763
- for (var i = 0; i < (callbacks === null || callbacks === void 0 ? void 0 : callbacks.length); i++) {
2764
- if (callbacks[i] === callback) {
2765
- callbacks.splice(i, 1);
2766
- break;
2767
- }
2768
- }
3030
+ case 'rotate': {
3031
+ cursor = 'grab';
3032
+ break;
3033
+ }
3034
+ }
3035
+ if (uuid) {
3036
+ elementUUID = uuid;
2769
3037
  }
2770
- this._listeners.set(eventKey, callbacks || []);
2771
- }
2772
- };
2773
- CoreEvent.prototype.trigger = function (eventKey, arg) {
2774
- var callbacks = this._listeners.get(eventKey);
2775
- if (Array.isArray(callbacks)) {
2776
- callbacks.forEach(function (cb) {
2777
- cb(arg);
2778
- });
2779
- return true;
2780
3038
  }
2781
3039
  else {
2782
- return false;
2783
- }
2784
- };
2785
- CoreEvent.prototype.has = function (name) {
2786
- if (this._listeners.has(name)) {
2787
- var list = this._listeners.get(name);
2788
- if (Array.isArray(list) && list.length > 0) {
2789
- return true;
3040
+ var _b = this[_element$1].isPointInElement(p, data), index = _b[0], uuid_1 = _b[1];
3041
+ if (index >= 0) {
3042
+ cursor = 'move';
3043
+ }
3044
+ if (uuid_1) {
3045
+ elementUUID = uuid_1;
2790
3046
  }
2791
3047
  }
2792
- return false;
3048
+ return {
3049
+ cursor: cursor,
3050
+ elementUUID: elementUUID,
3051
+ };
2793
3052
  };
2794
- return CoreEvent;
3053
+ return Mapper;
2795
3054
  }());
2796
3055
 
2797
3056
  var elementTypes = {
@@ -2834,215 +3093,116 @@ function isNumber(num) {
2834
3093
  return (num >= 0 || num < 0);
2835
3094
  }
2836
3095
 
2837
- var isColorStr = index.color.isColorStr;
2838
- function number(value) {
2839
- return (typeof value === 'number' && (value > 0 || value <= 0));
2840
- }
2841
- function x(value) {
2842
- return number(value);
2843
- }
2844
- function y(value) {
2845
- return number(value);
2846
- }
2847
- function w(value) {
2848
- return (typeof value === 'number' && value >= 0);
2849
- }
2850
- function h(value) {
2851
- return (typeof value === 'number' && value >= 0);
2852
- }
2853
- function angle(value) {
2854
- return (typeof value === 'number' && value >= -360 && value <= 360);
2855
- }
2856
- function borderWidth(value) {
2857
- return w(value);
2858
- }
2859
- function borderRadius(value) {
2860
- return number(value) && value >= 0;
2861
- }
2862
- function color(value) {
2863
- return isColorStr(value);
2864
- }
2865
- function imageURL(value) {
2866
- return (typeof value === 'string' && /^(http:\/\/|https:\/\/|\.\/|\/)/.test("" + value));
2867
- }
2868
- function imageBase64(value) {
2869
- return (typeof value === 'string' && /^(data:image\/)/.test("" + value));
2870
- }
2871
- function imageSrc(value) {
2872
- return (imageBase64(value) || imageURL(value));
2873
- }
2874
- function svg(value) {
2875
- return (typeof value === 'string' && /^(<svg[\s]{1,}|<svg>)/i.test(("" + value).trim()) && /<\/[\s]{0,}svg>$/i.test(("" + value).trim()));
2876
- }
2877
- function html(value) {
2878
- var result = false;
2879
- if (typeof value === 'string') {
2880
- var div = document.createElement('div');
2881
- div.innerHTML = value;
2882
- if (div.children.length > 0) {
2883
- result = true;
2884
- }
2885
- div = null;
2886
- }
2887
- return result;
2888
- }
2889
- function text(value) {
2890
- return typeof value === 'string';
2891
- }
2892
- function fontSize(value) {
2893
- return number(value) && value > 0;
2894
- }
2895
- function lineHeight(value) {
2896
- return number(value) && value > 0;
2897
- }
2898
- function textAlign(value) {
2899
- return ['center', 'left', 'right'].includes(value);
2900
- }
2901
- function fontFamily(value) {
2902
- return typeof value === 'string' && value.length > 0;
2903
- }
2904
- function fontWeight(value) {
2905
- return ['bold'].includes(value);
2906
- }
2907
- var is = {
2908
- x: x,
2909
- y: y,
2910
- w: w,
2911
- h: h,
2912
- angle: angle,
2913
- number: number,
2914
- borderWidth: borderWidth,
2915
- borderRadius: borderRadius,
2916
- color: color,
2917
- imageSrc: imageSrc,
2918
- imageURL: imageURL,
2919
- imageBase64: imageBase64,
2920
- svg: svg,
2921
- html: html,
2922
- text: text,
2923
- fontSize: fontSize,
2924
- lineHeight: lineHeight,
2925
- textAlign: textAlign,
2926
- fontFamily: fontFamily,
2927
- fontWeight: fontWeight,
2928
- };
2929
-
2930
- function attrs(attrs) {
2931
- var x = attrs.x, y = attrs.y, w = attrs.w, h = attrs.h, angle = attrs.angle;
2932
- if (!(is.x(x) && is.y(y) && is.w(w) && is.h(h) && is.angle(angle))) {
2933
- return false;
2934
- }
2935
- if (!(angle >= -360 && angle <= 360)) {
2936
- return false;
2937
- }
2938
- return true;
2939
- }
2940
- function box(desc) {
2941
- if (desc === void 0) { desc = {}; }
2942
- var borderColor = desc.borderColor, borderRadius = desc.borderRadius, borderWidth = desc.borderWidth;
2943
- if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
2944
- return false;
2945
- }
2946
- if (desc.hasOwnProperty('borderRadius') && !is.number(borderRadius)) {
2947
- return false;
2948
- }
2949
- if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
2950
- return false;
2951
- }
2952
- return true;
2953
- }
2954
- function rectDesc(desc) {
2955
- var color = desc.color;
2956
- if (desc.hasOwnProperty('color') && !is.color(color)) {
2957
- return false;
2958
- }
2959
- if (!box(desc)) {
2960
- return false;
2961
- }
2962
- return true;
2963
- }
2964
- function circleDesc(desc) {
2965
- var color = desc.color, borderColor = desc.borderColor, borderWidth = desc.borderWidth;
2966
- if (desc.hasOwnProperty('color') && !is.color(color)) {
2967
- return false;
2968
- }
2969
- if (desc.hasOwnProperty('borderColor') && !is.color(borderColor)) {
2970
- return false;
2971
- }
2972
- if (desc.hasOwnProperty('borderWidth') && !is.number(borderWidth)) {
2973
- return false;
2974
- }
2975
- return true;
2976
- }
2977
- function imageDesc(desc) {
2978
- var src = desc.src;
2979
- if (!is.imageSrc(src)) {
2980
- return false;
2981
- }
2982
- return true;
2983
- }
2984
- function svgDesc(desc) {
2985
- var svg = desc.svg;
2986
- if (!is.svg(svg)) {
2987
- return false;
2988
- }
2989
- return true;
2990
- }
2991
- function htmlDesc(desc) {
2992
- var html = desc.html;
2993
- if (!is.html(html)) {
2994
- return false;
2995
- }
2996
- return true;
2997
- }
2998
- function textDesc(desc) {
2999
- 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;
3000
- if (!is.text(text)) {
3001
- return false;
3002
- }
3003
- if (!is.color(color)) {
3004
- return false;
3005
- }
3006
- if (!is.fontSize(fontSize)) {
3007
- return false;
3008
- }
3009
- if (desc.hasOwnProperty('bgColor') && !is.color(bgColor)) {
3010
- return false;
3011
- }
3012
- if (desc.hasOwnProperty('fontWeight') && !is.fontWeight(fontWeight)) {
3013
- return false;
3014
- }
3015
- if (desc.hasOwnProperty('lineHeight') && !is.lineHeight(lineHeight)) {
3016
- return false;
3017
- }
3018
- if (desc.hasOwnProperty('fontFamily') && !is.fontFamily(fontFamily)) {
3019
- return false;
3020
- }
3021
- if (desc.hasOwnProperty('textAlign') && !is.textAlign(textAlign)) {
3022
- return false;
3023
- }
3024
- if (!box(desc)) {
3025
- return false;
3096
+ var requestAnimationFrame = window.requestAnimationFrame;
3097
+ var deepClone$3 = index.data.deepClone;
3098
+ var DrawStatus;
3099
+ (function (DrawStatus) {
3100
+ DrawStatus["FREE"] = "free";
3101
+ DrawStatus["DRAWING"] = "drawing";
3102
+ })(DrawStatus || (DrawStatus = {}));
3103
+ var Renderer = (function () {
3104
+ function Renderer(board) {
3105
+ var _this = this;
3106
+ this._queue = [];
3107
+ this._status = DrawStatus.FREE;
3108
+ this._board = board;
3109
+ this._loader = new Loader({
3110
+ board: board,
3111
+ maxParallelNum: 6
3112
+ });
3113
+ this._loader.on('load', function (res) {
3114
+ _this._drawFrame();
3115
+ });
3116
+ this._loader.on('error', function (res) {
3117
+ console.log('Loader Error: ', res);
3118
+ });
3119
+ this._loader.on('complete', function (res) {
3120
+ });
3026
3121
  }
3027
- return true;
3028
- }
3029
- var check = {
3030
- attrs: attrs,
3031
- textDesc: textDesc,
3032
- rectDesc: rectDesc,
3033
- circleDesc: circleDesc,
3034
- imageDesc: imageDesc,
3035
- svgDesc: svgDesc,
3036
- htmlDesc: htmlDesc,
3037
- };
3122
+ Renderer.prototype.render = function (data, helper, changeResourceUUIDs) {
3123
+ var _data = deepClone$3({ data: data, helper: helper });
3124
+ this._queue.push(_data);
3125
+ if (this._status !== DrawStatus.DRAWING) {
3126
+ this._status = DrawStatus.DRAWING;
3127
+ this._drawFrame();
3128
+ }
3129
+ this._loader.load(data, changeResourceUUIDs);
3130
+ };
3131
+ Renderer.prototype._drawFrame = function () {
3132
+ var _this = this;
3133
+ requestAnimationFrame(function () {
3134
+ var ctx = _this._board.getContext();
3135
+ var item = _this._queue[0];
3136
+ var isLastFrame = false;
3137
+ if (_this._queue.length > 1) {
3138
+ item = _this._queue.shift();
3139
+ }
3140
+ else {
3141
+ isLastFrame = true;
3142
+ }
3143
+ if (_this._loader.isComplete() !== true) {
3144
+ _this._drawFrame();
3145
+ if (item) {
3146
+ drawContext(ctx, item.data, item.helper, _this._loader);
3147
+ _this._board.draw();
3148
+ }
3149
+ }
3150
+ else if (item) {
3151
+ drawContext(ctx, item.data, item.helper, _this._loader);
3152
+ _this._board.draw();
3153
+ _this._retainQueueOneItem();
3154
+ if (!isLastFrame) {
3155
+ _this._drawFrame();
3156
+ }
3157
+ else {
3158
+ _this._status = DrawStatus.FREE;
3159
+ }
3160
+ }
3161
+ else {
3162
+ _this._status = DrawStatus.FREE;
3163
+ }
3164
+ });
3165
+ };
3166
+ Renderer.prototype._retainQueueOneItem = function () {
3167
+ if (this._queue.length <= 1) {
3168
+ return;
3169
+ }
3170
+ var lastOne = deepClone$3(this._queue[this._queue.length - 1]);
3171
+ this._queue = [lastOne];
3172
+ };
3173
+ return Renderer;
3174
+ }());
3175
+
3176
+ var Mode;
3177
+ (function (Mode) {
3178
+ Mode["NULL"] = "null";
3179
+ Mode["SELECT_ELEMENT"] = "select-element";
3180
+ Mode["SELECT_ELEMENT_LIST"] = "select-element-list";
3181
+ Mode["SELECT_ELEMENT_WRAPPER_DOT"] = "select-element-wrapper-dot";
3182
+ Mode["SELECT_AREA"] = "select-area";
3183
+ })(Mode || (Mode = {}));
3184
+ var CursorStatus;
3185
+ (function (CursorStatus) {
3186
+ CursorStatus["DRAGGING"] = "dragging";
3187
+ CursorStatus["NULL"] = "null";
3188
+ })(CursorStatus || (CursorStatus = {}));
3038
3189
 
3190
+ function createData() {
3191
+ return {
3192
+ onlyRender: false,
3193
+ hasInited: false,
3194
+ mode: Mode.NULL,
3195
+ cursorStatus: CursorStatus.NULL,
3196
+ selectedUUID: null,
3197
+ selectedUUIDList: [],
3198
+ hoverUUID: null,
3199
+ selectedDotDirection: null,
3200
+ prevPoint: null,
3201
+ };
3202
+ }
3039
3203
  var TempData = (function () {
3040
3204
  function TempData() {
3041
- this._temp = {
3042
- selectedUUID: null,
3043
- selectedUUIDList: [],
3044
- hoverUUID: null,
3045
- };
3205
+ this._temp = createData();
3046
3206
  }
3047
3207
  TempData.prototype.set = function (name, value) {
3048
3208
  this._temp[name] = value;
@@ -3051,11 +3211,7 @@ var TempData = (function () {
3051
3211
  return this._temp[name];
3052
3212
  };
3053
3213
  TempData.prototype.clear = function () {
3054
- this._temp = {
3055
- selectedUUID: null,
3056
- hoverUUID: null,
3057
- selectedUUIDList: [],
3058
- };
3214
+ this._temp = createData();
3059
3215
  };
3060
3216
  return TempData;
3061
3217
  }());
@@ -3067,185 +3223,431 @@ var _config = Symbol('_config');
3067
3223
  var _renderer = Symbol('_renderer');
3068
3224
  var _element = Symbol('_element');
3069
3225
  var _helper = Symbol('_helper');
3070
- var _hasInited = Symbol('_hasInited');
3071
- var _mode = Symbol('_mode');
3072
3226
  var _tempData = Symbol('_tempData');
3073
- var _prevPoint = Symbol('_prevPoint');
3074
3227
  var _draw = Symbol('_draw');
3075
- var _selectedDotDirection = Symbol('_selectedDotDirection');
3076
3228
  var _coreEvent = Symbol('_coreEvent');
3077
3229
  var _mapper = Symbol('_mapper');
3078
- var _initEvent = Symbol('_initEvent');
3079
- var _handleClick = Symbol('_handleClick');
3080
- var _handleDoubleClick = Symbol('_handleDoubleClick');
3081
- var _handlePoint = Symbol('_handlePoint');
3082
- var _handleMoveStart = Symbol('_handleMoveStart');
3083
- var _handleMove = Symbol('_handleMove');
3084
- var _handleMoveEnd = Symbol('_handleMoveEnd');
3085
- var _handleHover = Symbol('_handleHover');
3086
- var _handleLeave = Symbol('_handleLeave');
3087
- var _dragElements = Symbol('_dragElements');
3088
- var _transfromElement = Symbol('_transfromElement');
3089
3230
  var _emitChangeScreen = Symbol('_emitChangeScreen');
3090
3231
  var _emitChangeData = Symbol('_emitChangeData');
3091
- var _onlyRender = Symbol('_onlyRender');
3092
- var _cursorStatus = Symbol('_cursorStatus');
3093
-
3094
- var Mode;
3095
- (function (Mode) {
3096
- Mode["NULL"] = "null";
3097
- Mode["SELECT_ELEMENT"] = "select-element";
3098
- Mode["SELECT_ELEMENT_LIST"] = "select-element-list";
3099
- Mode["SELECT_ELEMENT_WRAPPER_DOT"] = "select-element-wrapper-dot";
3100
- Mode["SELECT_AREA"] = "select-area";
3101
- })(Mode || (Mode = {}));
3102
- var CursorStatus;
3103
- (function (CursorStatus) {
3104
- CursorStatus["DRAGGING"] = "dragging";
3105
- CursorStatus["NULL"] = "null";
3106
- })(CursorStatus || (CursorStatus = {}));
3232
+ var _todo = Symbol('_todo');
3107
3233
 
3108
- function isChangeImageElementResource(before, after) {
3109
- var _a, _b;
3110
- return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.src) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.src));
3234
+ var deepClone$2 = index.data.deepClone;
3235
+ var createUUID = index.uuid.createUUID;
3236
+ function getSelectedElements(core) {
3237
+ var elems = [];
3238
+ var list = [];
3239
+ var uuid = core[_tempData].get('selectedUUID');
3240
+ if (typeof uuid === 'string' && uuid) {
3241
+ list.push(uuid);
3242
+ }
3243
+ else {
3244
+ list = core[_tempData].get('selectedUUIDList');
3245
+ }
3246
+ list.forEach(function (uuid) {
3247
+ var _a;
3248
+ var index = core[_helper].getElementIndexByUUID(uuid);
3249
+ if (index !== null && index >= 0) {
3250
+ var elem = (_a = core[_data]) === null || _a === void 0 ? void 0 : _a.elements[index];
3251
+ if (elem)
3252
+ elems.push(elem);
3253
+ }
3254
+ });
3255
+ return deepClone$2(elems);
3111
3256
  }
3112
- function isChangeSVGElementResource(before, after) {
3113
- var _a, _b;
3114
- return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.svg) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.svg));
3257
+ function getElement(core, uuid) {
3258
+ var elem = null;
3259
+ var index = core[_helper].getElementIndexByUUID(uuid);
3260
+ if (index !== null && core[_data].elements[index]) {
3261
+ elem = deepClone$2(core[_data].elements[index]);
3262
+ }
3263
+ return elem;
3115
3264
  }
3116
- function isChangeHTMLElementResource(before, after) {
3117
- var _a, _b, _c, _d, _e, _f;
3118
- return (((_a = before === null || before === void 0 ? void 0 : before.desc) === null || _a === void 0 ? void 0 : _a.html) !== ((_b = after === null || after === void 0 ? void 0 : after.desc) === null || _b === void 0 ? void 0 : _b.html)
3119
- || ((_c = before === null || before === void 0 ? void 0 : before.desc) === null || _c === void 0 ? void 0 : _c.width) !== ((_d = after === null || after === void 0 ? void 0 : after.desc) === null || _d === void 0 ? void 0 : _d.width)
3120
- || ((_e = before === null || before === void 0 ? void 0 : before.desc) === null || _e === void 0 ? void 0 : _e.height) !== ((_f = after === null || after === void 0 ? void 0 : after.desc) === null || _f === void 0 ? void 0 : _f.height));
3265
+ function getElementByIndex(core, index) {
3266
+ var elem = null;
3267
+ if (index >= 0 && core[_data].elements[index]) {
3268
+ elem = deepClone$2(core[_data].elements[index]);
3269
+ }
3270
+ return elem;
3121
3271
  }
3122
- function diffElementResourceChange(before, after) {
3123
- var result = null;
3124
- var isChange = false;
3125
- switch (after.type) {
3126
- case 'image': {
3127
- isChange = isChangeImageElementResource(before, after);
3272
+ function updateElement(core, elem) {
3273
+ var _a;
3274
+ var _elem = deepClone$2(elem);
3275
+ var data = core[_data];
3276
+ var resourceChangeUUIDs = [];
3277
+ for (var i = 0; i < data.elements.length; i++) {
3278
+ if (_elem.uuid === ((_a = data.elements[i]) === null || _a === void 0 ? void 0 : _a.uuid)) {
3279
+ var result = diffElementResourceChange(data.elements[i], _elem);
3280
+ if (typeof result === 'string') {
3281
+ resourceChangeUUIDs.push(result);
3282
+ }
3283
+ data.elements[i] = _elem;
3128
3284
  break;
3129
3285
  }
3130
- case 'svg': {
3131
- isChange = isChangeSVGElementResource(before, after);
3132
- break;
3286
+ }
3287
+ core[_emitChangeData]();
3288
+ core[_draw]({ resourceChangeUUIDs: resourceChangeUUIDs });
3289
+ }
3290
+ function selectElementByIndex(core, index, opts) {
3291
+ if (core[_tempData].get('onlyRender') === true)
3292
+ return;
3293
+ if (core[_data].elements[index]) {
3294
+ var uuid = core[_data].elements[index].uuid;
3295
+ if ((opts === null || opts === void 0 ? void 0 : opts.useMode) === true) {
3296
+ core[_tempData].set('mode', Mode.SELECT_ELEMENT);
3133
3297
  }
3134
- case 'html': {
3135
- isChange = isChangeHTMLElementResource(before, after);
3136
- break;
3298
+ else {
3299
+ core[_tempData].set('mode', Mode.NULL);
3137
3300
  }
3301
+ if (typeof uuid === 'string') {
3302
+ core[_tempData].set('selectedUUID', uuid);
3303
+ core[_tempData].set('selectedUUIDList', []);
3304
+ }
3305
+ core[_draw]();
3138
3306
  }
3139
- if (isChange === true) {
3140
- result = after.uuid;
3307
+ }
3308
+ function selectElement(core, uuid, opts) {
3309
+ if (core[_tempData].get('onlyRender') === true)
3310
+ return;
3311
+ var index = core[_helper].getElementIndexByUUID(uuid);
3312
+ if (typeof index === 'number' && index >= 0) {
3313
+ core.selectElementByIndex(index, opts);
3141
3314
  }
3142
- return result;
3143
3315
  }
3144
- function diffElementResourceChangeList(before, after) {
3145
- var _a;
3146
- var uuids = [];
3147
- var beforeMap = parseDataElementMap(before);
3148
- var afterMap = parseDataElementMap(after);
3149
- for (var uuid in afterMap) {
3150
- if (['image', 'svg', 'html'].includes((_a = afterMap[uuid]) === null || _a === void 0 ? void 0 : _a.type) !== true) {
3151
- continue;
3316
+ function moveUpElement(core, uuid) {
3317
+ var index = core[_helper].getElementIndexByUUID(uuid);
3318
+ if (typeof index === 'number' && index >= 0 && index < core[_data].elements.length - 1) {
3319
+ var temp = core[_data].elements[index];
3320
+ core[_data].elements[index] = core[_data].elements[index + 1];
3321
+ core[_data].elements[index + 1] = temp;
3322
+ }
3323
+ core[_emitChangeData]();
3324
+ core[_draw]();
3325
+ }
3326
+ function moveDownElement(core, uuid) {
3327
+ var index = core[_helper].getElementIndexByUUID(uuid);
3328
+ if (typeof index === 'number' && index > 0 && index < core[_data].elements.length) {
3329
+ var temp = core[_data].elements[index];
3330
+ core[_data].elements[index] = core[_data].elements[index - 1];
3331
+ core[_data].elements[index - 1] = temp;
3332
+ }
3333
+ core[_emitChangeData]();
3334
+ core[_draw]();
3335
+ }
3336
+ function addElement(core, elem) {
3337
+ var _elem = deepClone$2(elem);
3338
+ _elem.uuid = createUUID();
3339
+ core[_data].elements.push(_elem);
3340
+ core[_emitChangeData]();
3341
+ core[_draw]();
3342
+ return _elem.uuid;
3343
+ }
3344
+ function deleteElement(core, uuid) {
3345
+ var index = core[_element].getElementIndex(core[_data], uuid);
3346
+ if (index >= 0) {
3347
+ core[_data].elements.splice(index, 1);
3348
+ core[_emitChangeData]();
3349
+ core[_draw]();
3350
+ }
3351
+ }
3352
+ function insertElementBefore(core, elem, beforeUUID) {
3353
+ var index = core[_helper].getElementIndexByUUID(beforeUUID);
3354
+ if (index !== null) {
3355
+ return core.insertElementBeforeIndex(elem, index);
3356
+ }
3357
+ return null;
3358
+ }
3359
+ function insertElementBeforeIndex(core, elem, index) {
3360
+ var _elem = deepClone$2(elem);
3361
+ _elem.uuid = createUUID();
3362
+ if (index >= 0) {
3363
+ core[_data].elements.splice(index, 0, _elem);
3364
+ core[_emitChangeData]();
3365
+ core[_draw]();
3366
+ return _elem.uuid;
3367
+ }
3368
+ return null;
3369
+ }
3370
+ function insertElementAfter(core, elem, beforeUUID) {
3371
+ var index = core[_helper].getElementIndexByUUID(beforeUUID);
3372
+ if (index !== null) {
3373
+ return core.insertElementAfterIndex(elem, index);
3374
+ }
3375
+ return null;
3376
+ }
3377
+ function insertElementAfterIndex(core, elem, index) {
3378
+ var _elem = deepClone$2(elem);
3379
+ _elem.uuid = createUUID();
3380
+ if (index >= 0) {
3381
+ core[_data].elements.splice(index + 1, 0, _elem);
3382
+ core[_emitChangeData]();
3383
+ core[_draw]();
3384
+ return _elem.uuid;
3385
+ }
3386
+ return null;
3387
+ }
3388
+
3389
+ var time = index.time;
3390
+ var deepClone$1 = index.data.deepClone;
3391
+ function initEvent(core) {
3392
+ if (core[_tempData].get('hasInited') === true) {
3393
+ return;
3394
+ }
3395
+ core[_board].on('hover', time.throttle(handleHover(core), 32));
3396
+ core[_board].on('leave', time.throttle(handleLeave(core), 32));
3397
+ core[_board].on('point', time.throttle(handleClick(core), 16));
3398
+ core[_board].on('doubleClick', handleDoubleClick(core));
3399
+ if (core[_tempData].get('onlyRender') === true) {
3400
+ return;
3401
+ }
3402
+ core[_board].on('point', handlePoint(core));
3403
+ core[_board].on('moveStart', handleMoveStart(core));
3404
+ core[_board].on('move', time.throttle(handleMove(core), 16));
3405
+ core[_board].on('moveEnd', handleMoveEnd(core));
3406
+ core[_tempData].set('hasInited', true);
3407
+ }
3408
+ function handleDoubleClick(core) {
3409
+ return function (point) {
3410
+ var _a, _b, _c;
3411
+ var _d = core[_element].isPointInElement(point, core[_data]), index = _d[0], uuid = _d[1];
3412
+ if (index >= 0 && uuid) {
3413
+ var elem = deepClone$1((_a = core[_data].elements) === null || _a === void 0 ? void 0 : _a[index]);
3414
+ if (((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.invisible) !== true) {
3415
+ core[_coreEvent].trigger('screenDoubleClickElement', { index: index, uuid: uuid, element: deepClone$1((_c = core[_data].elements) === null || _c === void 0 ? void 0 : _c[index]) });
3416
+ }
3152
3417
  }
3153
- if (beforeMap[uuid]) {
3154
- var isChange = false;
3155
- switch (beforeMap[uuid].type) {
3156
- case 'image': {
3157
- isChange = isChangeImageElementResource(beforeMap[uuid], afterMap[uuid]);
3158
- break;
3418
+ core[_draw]();
3419
+ };
3420
+ }
3421
+ function handlePoint(core) {
3422
+ return function (point) {
3423
+ var _a, _b, _c;
3424
+ if (!core[_mapper].isEffectivePoint(point)) {
3425
+ return;
3426
+ }
3427
+ if (core[_helper].isPointInElementList(point, core[_data])) {
3428
+ core[_tempData].set('mode', Mode.SELECT_ELEMENT_LIST);
3429
+ }
3430
+ else {
3431
+ var _d = core[_helper].isPointInElementWrapperDot(point, core[_data]), uuid = _d[0], direction = _d[1];
3432
+ if (uuid && direction) {
3433
+ core[_tempData].set('mode', Mode.SELECT_ELEMENT_WRAPPER_DOT);
3434
+ core[_tempData].set('selectedDotDirection', direction);
3435
+ core[_tempData].set('selectedUUID', uuid);
3436
+ }
3437
+ else {
3438
+ var _e = core[_element].isPointInElement(point, core[_data]), index = _e[0], uuid_1 = _e[1];
3439
+ if (index >= 0 && ((_b = (_a = core[_data].elements[index]) === null || _a === void 0 ? void 0 : _a.operation) === null || _b === void 0 ? void 0 : _b.invisible) !== true) {
3440
+ core.selectElementByIndex(index, { useMode: true });
3441
+ if (typeof uuid_1 === 'string' && core[_coreEvent].has('screenSelectElement')) {
3442
+ core[_coreEvent].trigger('screenSelectElement', { index: index, uuid: uuid_1, element: deepClone$1((_c = core[_data].elements) === null || _c === void 0 ? void 0 : _c[index]) });
3443
+ core[_emitChangeScreen]();
3444
+ }
3445
+ core[_tempData].set('mode', Mode.SELECT_ELEMENT);
3159
3446
  }
3160
- case 'svg': {
3161
- isChange = isChangeSVGElementResource(beforeMap[uuid], afterMap[uuid]);
3162
- break;
3447
+ else {
3448
+ core[_tempData].set('selectedUUIDList', []);
3449
+ core[_tempData].set('mode', Mode.SELECT_AREA);
3450
+ }
3451
+ }
3452
+ }
3453
+ core[_draw]();
3454
+ };
3455
+ }
3456
+ function handleClick(core) {
3457
+ return function (point) {
3458
+ var _a;
3459
+ var _b = core[_element].isPointInElement(point, core[_data]), index = _b[0], uuid = _b[1];
3460
+ if (index >= 0 && uuid) {
3461
+ core[_coreEvent].trigger('screenClickElement', { index: index, uuid: uuid, element: deepClone$1((_a = core[_data].elements) === null || _a === void 0 ? void 0 : _a[index]) });
3462
+ }
3463
+ core[_draw]();
3464
+ };
3465
+ }
3466
+ function handleMoveStart(core) {
3467
+ return function (point) {
3468
+ core[_tempData].set('prevPoint', point);
3469
+ var uuid = core[_tempData].get('selectedUUID');
3470
+ if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT_LIST) ;
3471
+ else if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT) {
3472
+ if (typeof uuid === 'string' && core[_coreEvent].has('screenMoveElementStart')) {
3473
+ core[_coreEvent].trigger('screenMoveElementStart', {
3474
+ index: core[_element].getElementIndex(core[_data], uuid),
3475
+ uuid: uuid,
3476
+ x: point.x,
3477
+ y: point.y
3478
+ });
3479
+ }
3480
+ }
3481
+ else if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
3482
+ core[_helper].startSelectArea(point);
3483
+ }
3484
+ };
3485
+ }
3486
+ function handleMove(core) {
3487
+ return function (point) {
3488
+ if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT_LIST) {
3489
+ dragElements(core, core[_tempData].get('selectedUUIDList'), point, core[_tempData].get('prevPoint'));
3490
+ core[_draw]();
3491
+ core[_tempData].set('cursorStatus', CursorStatus.DRAGGING);
3492
+ }
3493
+ else if (typeof core[_tempData].get('selectedUUID') === 'string') {
3494
+ if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT) {
3495
+ dragElements(core, [core[_tempData].get('selectedUUID')], point, core[_tempData].get('prevPoint'));
3496
+ core[_draw]();
3497
+ core[_tempData].set('cursorStatus', CursorStatus.DRAGGING);
3498
+ }
3499
+ else if (core[_tempData].get('mode') === Mode.SELECT_ELEMENT_WRAPPER_DOT && core[_tempData].get('selectedDotDirection')) {
3500
+ transfromElement(core, core[_tempData].get('selectedUUID'), point, core[_tempData].get('prevPoint'), core[_tempData].get('selectedDotDirection'));
3501
+ core[_tempData].set('cursorStatus', CursorStatus.DRAGGING);
3502
+ }
3503
+ }
3504
+ else if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
3505
+ core[_helper].changeSelectArea(point);
3506
+ core[_draw]();
3507
+ }
3508
+ core[_tempData].set('prevPoint', point);
3509
+ };
3510
+ }
3511
+ function dragElements(core, uuids, point, prevPoint) {
3512
+ if (!prevPoint) {
3513
+ return;
3514
+ }
3515
+ uuids.forEach(function (uuid) {
3516
+ var _a, _b;
3517
+ var idx = core[_helper].getElementIndexByUUID(uuid);
3518
+ if (idx === null)
3519
+ return;
3520
+ var elem = core[_data].elements[idx];
3521
+ if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.lock) !== true && ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.invisible) !== true) {
3522
+ core[_element].dragElement(core[_data], uuid, point, prevPoint, core[_board].getContext().getTransform().scale);
3523
+ }
3524
+ });
3525
+ core[_draw]();
3526
+ }
3527
+ function handleMoveEnd(core) {
3528
+ return function (point) {
3529
+ var uuid = core[_tempData].get('selectedUUID');
3530
+ if (typeof uuid === 'string') {
3531
+ var index = core[_element].getElementIndex(core[_data], uuid);
3532
+ var elem = core[_data].elements[index];
3533
+ if (elem) {
3534
+ if (core[_coreEvent].has('screenMoveElementEnd')) {
3535
+ core[_coreEvent].trigger('screenMoveElementEnd', {
3536
+ index: index,
3537
+ uuid: uuid,
3538
+ x: point.x,
3539
+ y: point.y
3540
+ });
3163
3541
  }
3164
- case 'html': {
3165
- isChange = isChangeHTMLElementResource(beforeMap[uuid], afterMap[uuid]);
3166
- break;
3542
+ if (core[_coreEvent].has('screenChangeElement')) {
3543
+ core[_coreEvent].trigger('screenChangeElement', {
3544
+ index: index,
3545
+ uuid: uuid,
3546
+ width: elem.w,
3547
+ height: elem.h,
3548
+ angle: elem.angle || 0
3549
+ });
3167
3550
  }
3551
+ core[_emitChangeData]();
3168
3552
  }
3169
- if (isChange === true) {
3170
- uuids.push(uuid);
3553
+ }
3554
+ else if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
3555
+ var uuids = core[_helper].calcSelectedElements(core[_data]);
3556
+ if (uuids.length > 0) {
3557
+ core[_tempData].set('selectedUUIDList', uuids);
3558
+ core[_tempData].set('selectedUUID', null);
3171
3559
  }
3560
+ else {
3561
+ core[_tempData].set('mode', Mode.NULL);
3562
+ }
3563
+ core[_helper].clearSelectedArea();
3564
+ core[_draw]();
3172
3565
  }
3173
- else {
3174
- uuids.push(uuid);
3566
+ if (core[_tempData].get('mode') !== Mode.SELECT_ELEMENT) {
3567
+ core[_tempData].set('selectedUUID', null);
3175
3568
  }
3176
- }
3177
- return uuids;
3569
+ core[_tempData].set('cursorStatus', CursorStatus.NULL);
3570
+ core[_tempData].set('mode', Mode.NULL);
3571
+ };
3178
3572
  }
3179
- function parseDataElementMap(data) {
3180
- var elemMap = {};
3181
- data.elements.forEach(function (elem) {
3182
- elemMap[elem.uuid] = elem;
3183
- });
3184
- return elemMap;
3185
- }
3186
-
3187
- var deepClone$1 = index.data.deepClone;
3188
- function getSelectedElements(core) {
3189
- var elems = [];
3190
- var list = [];
3191
- var uuid = core[_tempData].get('selectedUUID');
3192
- if (typeof uuid === 'string' && uuid) {
3193
- list.push(uuid);
3194
- }
3195
- else {
3196
- list = core[_tempData].get('selectedUUIDList');
3197
- }
3198
- list.forEach(function (uuid) {
3199
- var _a;
3200
- var index = core[_helper].getElementIndexByUUID(uuid);
3201
- if (index !== null && index >= 0) {
3202
- var elem = (_a = core[_data]) === null || _a === void 0 ? void 0 : _a.elements[index];
3203
- if (elem)
3204
- elems.push(elem);
3573
+ function handleHover(core) {
3574
+ return function (point) {
3575
+ var _a, _b;
3576
+ var isMouseOverElement = false;
3577
+ if (core[_tempData].get('mode') === Mode.SELECT_AREA) {
3578
+ if (core[_tempData].get('onlyRender') !== true)
3579
+ core[_board].resetCursor();
3580
+ }
3581
+ else if (core[_tempData].get('cursorStatus') === CursorStatus.NULL) {
3582
+ var _c = core[_mapper].judgePointCursor(point, core[_data]), cursor = _c.cursor, elementUUID = _c.elementUUID;
3583
+ if (core[_tempData].get('onlyRender') !== true)
3584
+ core[_board].setCursor(cursor);
3585
+ if (elementUUID) {
3586
+ var index = core[_helper].getElementIndexByUUID(elementUUID);
3587
+ if (index !== null && index >= 0) {
3588
+ var elem = core[_data].elements[index];
3589
+ if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.lock) === true || ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.invisible) === true) {
3590
+ core[_board].resetCursor();
3591
+ return;
3592
+ }
3593
+ if (core[_tempData].get('hoverUUID') !== elem.uuid) {
3594
+ var preIndex = core[_helper].getElementIndexByUUID(core[_tempData].get('hoverUUID') || '');
3595
+ if (preIndex !== null && core[_data].elements[preIndex]) {
3596
+ core[_coreEvent].trigger('mouseLeaveElement', {
3597
+ uuid: core[_tempData].get('hoverUUID'),
3598
+ index: preIndex,
3599
+ element: core[_data].elements[preIndex]
3600
+ });
3601
+ }
3602
+ }
3603
+ if (elem) {
3604
+ core[_coreEvent].trigger('mouseOverElement', { uuid: elem.uuid, index: index, element: elem, });
3605
+ core[_tempData].set('hoverUUID', elem.uuid);
3606
+ isMouseOverElement = true;
3607
+ }
3608
+ }
3609
+ }
3205
3610
  }
3206
- });
3207
- return elems;
3611
+ if (isMouseOverElement !== true && core[_tempData].get('hoverUUID') !== null) {
3612
+ var uuid = core[_tempData].get('hoverUUID');
3613
+ var index = core[_helper].getElementIndexByUUID(uuid || '');
3614
+ if (index !== null)
3615
+ core[_coreEvent].trigger('mouseLeaveElement', { uuid: uuid, index: index, element: core[_data].elements[index] });
3616
+ core[_tempData].set('hoverUUID', null);
3617
+ }
3618
+ if (core[_coreEvent].has('mouseOverScreen'))
3619
+ core[_coreEvent].trigger('mouseOverScreen', point);
3620
+ };
3208
3621
  }
3209
- function updateElement(core, elem) {
3210
- var _a;
3211
- var _elem = deepClone$1(elem);
3212
- var data = core[_data];
3213
- var resourceChangeUUIDs = [];
3214
- for (var i = 0; i < data.elements.length; i++) {
3215
- if (_elem.uuid === ((_a = data.elements[i]) === null || _a === void 0 ? void 0 : _a.uuid)) {
3216
- var result = diffElementResourceChange(data.elements[i], _elem);
3217
- if (typeof result === 'string') {
3218
- resourceChangeUUIDs.push(result);
3219
- }
3220
- data.elements[i] = _elem;
3221
- break;
3622
+ function handleLeave(core) {
3623
+ return function () {
3624
+ if (core[_coreEvent].has('mouseLeaveScreen')) {
3625
+ core[_coreEvent].trigger('mouseLeaveScreen', undefined);
3222
3626
  }
3627
+ };
3628
+ }
3629
+ function transfromElement(core, uuid, point, prevPoint, direction) {
3630
+ if (!prevPoint) {
3631
+ return null;
3223
3632
  }
3224
- core[_emitChangeData]();
3225
- core[_draw]({ resourceChangeUUIDs: resourceChangeUUIDs });
3633
+ var result = core[_element].transformElement(core[_data], uuid, point, prevPoint, core[_board].getContext().getTransform().scale, direction);
3634
+ core[_draw]();
3635
+ return result;
3226
3636
  }
3227
3637
 
3228
- var time = index.time;
3229
3638
  var deepClone = index.data.deepClone;
3230
- var createUUID = index.uuid.createUUID;
3231
3639
  var Core = (function () {
3232
3640
  function Core(mount, opts, config) {
3233
- var _h, _j, _k;
3234
- this[_a] = false;
3235
- this[_b] = Mode.NULL;
3236
- this[_c] = new CoreEvent();
3237
- this[_d] = null;
3238
- this[_e] = null;
3239
- this[_f] = false;
3240
- this[_g] = CursorStatus.NULL;
3641
+ var _c, _d, _e;
3642
+ this[_a] = new CoreEvent();
3643
+ this[_b] = new TempData();
3241
3644
  this[_data] = { elements: [] };
3242
3645
  this[_opts] = opts;
3243
- this[_onlyRender] = opts.onlyRender === true;
3646
+ this[_tempData].set('onlyRender', opts.onlyRender === true);
3244
3647
  this[_config] = mergeConfig(config || {});
3245
- this[_tempData] = new TempData();
3246
- this[_board] = new Board(mount, __assign$1(__assign$1({}, this[_opts]), { canScroll: (_h = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _h === void 0 ? void 0 : _h.use, scrollConfig: {
3247
- color: ((_j = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _j === void 0 ? void 0 : _j.color) || '#a0a0a0',
3248
- lineWidth: ((_k = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _k === void 0 ? void 0 : _k.lineWidth) || 12,
3648
+ this[_board] = new Board(mount, __assign$1(__assign$1({}, this[_opts]), { canScroll: (_c = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _c === void 0 ? void 0 : _c.use, scrollConfig: {
3649
+ color: ((_d = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _d === void 0 ? void 0 : _d.color) || '#a0a0a0',
3650
+ lineWidth: ((_e = config === null || config === void 0 ? void 0 : config.scrollWrapper) === null || _e === void 0 ? void 0 : _e.lineWidth) || 12,
3249
3651
  } }));
3250
3652
  this[_renderer] = new Renderer(this[_board]);
3251
3653
  this[_element] = new Element(this[_board].getContext());
@@ -3255,16 +3657,15 @@ var Core = (function () {
3255
3657
  helper: this[_helper],
3256
3658
  element: this[_element]
3257
3659
  });
3258
- this[_initEvent]();
3259
- this[_hasInited] = true;
3660
+ initEvent(this);
3260
3661
  }
3261
- Core.prototype[(_a = _hasInited, _b = _mode, _c = _coreEvent, _d = _prevPoint, _e = _selectedDotDirection, _f = _onlyRender, _g = _cursorStatus, _draw)] = function (opts) {
3262
- var _h, _j;
3662
+ Core.prototype[(_a = _coreEvent, _b = _tempData, _draw)] = function (opts) {
3663
+ var _c, _d;
3263
3664
  var transfrom = this[_board].getTransform();
3264
3665
  this[_helper].updateConfig(this[_data], {
3265
3666
  width: this[_opts].width,
3266
3667
  height: this[_opts].height,
3267
- canScroll: ((_j = (_h = this[_config]) === null || _h === void 0 ? void 0 : _h.scrollWrapper) === null || _j === void 0 ? void 0 : _j.use) === true,
3668
+ canScroll: ((_d = (_c = this[_config]) === null || _c === void 0 ? void 0 : _c.scrollWrapper) === null || _d === void 0 ? void 0 : _d.use) === true,
3268
3669
  selectedUUID: this[_tempData].get('selectedUUID'),
3269
3670
  selectedUUIDList: this[_tempData].get('selectedUUIDList'),
3270
3671
  devicePixelRatio: this[_opts].devicePixelRatio,
@@ -3274,55 +3675,51 @@ var Core = (function () {
3274
3675
  });
3275
3676
  this[_renderer].render(this[_data], this[_helper].getConfig(), (opts === null || opts === void 0 ? void 0 : opts.resourceChangeUUIDs) || []);
3276
3677
  };
3277
- Core.prototype.resetSize = function (opts) {
3278
- this[_opts] = __assign$1(__assign$1({}, this[_opts]), opts);
3279
- this[_board].resetSize(opts);
3280
- this[_draw]();
3678
+ Core.prototype.getElement = function (uuid) {
3679
+ return getElement(this, uuid);
3680
+ };
3681
+ Core.prototype.getElementByIndex = function (index) {
3682
+ return getElementByIndex(this, index);
3281
3683
  };
3282
3684
  Core.prototype.selectElementByIndex = function (index, opts) {
3283
- if (this[_onlyRender] === true)
3284
- return;
3285
- if (this[_data].elements[index]) {
3286
- var uuid = this[_data].elements[index].uuid;
3287
- if ((opts === null || opts === void 0 ? void 0 : opts.useMode) === true) {
3288
- this[_mode] = Mode.SELECT_ELEMENT;
3289
- }
3290
- else {
3291
- this[_mode] = Mode.NULL;
3292
- }
3293
- if (typeof uuid === 'string') {
3294
- this[_tempData].set('selectedUUID', uuid);
3295
- this[_tempData].set('selectedUUIDList', []);
3296
- }
3297
- this[_draw]();
3298
- }
3685
+ return selectElementByIndex(this, index, opts);
3299
3686
  };
3300
3687
  Core.prototype.selectElement = function (uuid, opts) {
3301
- if (this[_onlyRender] === true)
3302
- return;
3303
- var index = this[_helper].getElementIndexByUUID(uuid);
3304
- if (typeof index === 'number' && index >= 0) {
3305
- this.selectElementByIndex(index, opts);
3306
- }
3688
+ return selectElement(this, uuid, opts);
3307
3689
  };
3308
3690
  Core.prototype.moveUpElement = function (uuid) {
3309
- var index = this[_helper].getElementIndexByUUID(uuid);
3310
- if (typeof index === 'number' && index >= 0 && index < this[_data].elements.length - 1) {
3311
- var temp = this[_data].elements[index];
3312
- this[_data].elements[index] = this[_data].elements[index + 1];
3313
- this[_data].elements[index + 1] = temp;
3314
- }
3315
- this[_emitChangeData]();
3316
- this[_draw]();
3691
+ return moveUpElement(this, uuid);
3317
3692
  };
3318
3693
  Core.prototype.moveDownElement = function (uuid) {
3319
- var index = this[_helper].getElementIndexByUUID(uuid);
3320
- if (typeof index === 'number' && index > 0 && index < this[_data].elements.length) {
3321
- var temp = this[_data].elements[index];
3322
- this[_data].elements[index] = this[_data].elements[index - 1];
3323
- this[_data].elements[index - 1] = temp;
3324
- }
3325
- this[_emitChangeData]();
3694
+ return moveDownElement(this, uuid);
3695
+ };
3696
+ Core.prototype.updateElement = function (elem) {
3697
+ return updateElement(this, elem);
3698
+ };
3699
+ Core.prototype.addElement = function (elem) {
3700
+ return addElement(this, elem);
3701
+ };
3702
+ Core.prototype.deleteElement = function (uuid) {
3703
+ return deleteElement(this, uuid);
3704
+ };
3705
+ Core.prototype.insertElementBefore = function (elem, beforeUUID) {
3706
+ return insertElementBefore(this, elem, beforeUUID);
3707
+ };
3708
+ Core.prototype.insertElementBeforeIndex = function (elem, index) {
3709
+ return insertElementBeforeIndex(this, elem, index);
3710
+ };
3711
+ Core.prototype.getSelectedElements = function () {
3712
+ return getSelectedElements(this);
3713
+ };
3714
+ Core.prototype.insertElementAfter = function (elem, beforeUUID) {
3715
+ return insertElementAfter(this, elem, beforeUUID);
3716
+ };
3717
+ Core.prototype.insertElementAfterIndex = function (elem, index) {
3718
+ return insertElementAfterIndex(this, elem, index);
3719
+ };
3720
+ Core.prototype.resetSize = function (opts) {
3721
+ this[_opts] = __assign$1(__assign$1({}, this[_opts]), opts);
3722
+ this[_board].resetSize(opts);
3326
3723
  this[_draw]();
3327
3724
  };
3328
3725
  Core.prototype.scale = function (ratio) {
@@ -3362,58 +3759,6 @@ var Core = (function () {
3362
3759
  }
3363
3760
  this[_draw]({ resourceChangeUUIDs: resourceChangeUUIDs });
3364
3761
  };
3365
- Core.prototype.updateElement = function (elem) {
3366
- return updateElement(this, elem);
3367
- };
3368
- Core.prototype.addElement = function (elem) {
3369
- var _elem = deepClone(elem);
3370
- _elem.uuid = createUUID();
3371
- this[_data].elements.push(_elem);
3372
- this[_emitChangeData]();
3373
- this[_draw]();
3374
- return _elem.uuid;
3375
- };
3376
- Core.prototype.deleteElement = function (uuid) {
3377
- var index = this[_element].getElementIndex(this[_data], uuid);
3378
- if (index >= 0) {
3379
- this[_data].elements.splice(index, 1);
3380
- this[_emitChangeData]();
3381
- this[_draw]();
3382
- }
3383
- };
3384
- Core.prototype.insertElementBefore = function (elem, beforeUUID) {
3385
- var index = this[_helper].getElementIndexByUUID(beforeUUID);
3386
- if (index !== null) {
3387
- this.insertElementBeforeIndex(elem, index);
3388
- }
3389
- };
3390
- Core.prototype.insertElementBeforeIndex = function (elem, index) {
3391
- var _elem = deepClone(elem);
3392
- _elem.uuid = createUUID();
3393
- if (index >= 0) {
3394
- this[_data].elements.splice(index, 0, _elem);
3395
- this[_emitChangeData]();
3396
- this[_draw]();
3397
- }
3398
- };
3399
- Core.prototype.getSelectedElements = function () {
3400
- return getSelectedElements(this);
3401
- };
3402
- Core.prototype.insertElementAfter = function (elem, beforeUUID) {
3403
- var index = this[_helper].getElementIndexByUUID(beforeUUID);
3404
- if (index !== null) {
3405
- this.insertElementAfterIndex(elem, index);
3406
- }
3407
- };
3408
- Core.prototype.insertElementAfterIndex = function (elem, index) {
3409
- var _elem = deepClone(elem);
3410
- _elem.uuid = createUUID();
3411
- if (index >= 0) {
3412
- this[_data].elements.splice(index + 1, 0, _elem);
3413
- this[_emitChangeData]();
3414
- this[_draw]();
3415
- }
3416
- };
3417
3762
  Core.prototype.clearOperation = function () {
3418
3763
  this[_tempData].clear();
3419
3764
  this[_draw]();
@@ -3439,233 +3784,6 @@ var Core = (function () {
3439
3784
  Core.prototype.__getOriginContext = function () {
3440
3785
  return this[_board].getOriginContext();
3441
3786
  };
3442
- Core.prototype[_initEvent] = function () {
3443
- if (this[_hasInited] === true) {
3444
- return;
3445
- }
3446
- this[_board].on('hover', time.throttle(this[_handleHover].bind(this), 32));
3447
- this[_board].on('leave', time.throttle(this[_handleLeave].bind(this), 32));
3448
- this[_board].on('point', time.throttle(this[_handleClick].bind(this), 16));
3449
- this[_board].on('doubleClick', this[_handleDoubleClick].bind(this));
3450
- if (this[_onlyRender] === true) {
3451
- return;
3452
- }
3453
- this[_board].on('point', this[_handlePoint].bind(this));
3454
- this[_board].on('moveStart', this[_handleMoveStart].bind(this));
3455
- this[_board].on('move', time.throttle(this[_handleMove].bind(this), 16));
3456
- this[_board].on('moveEnd', this[_handleMoveEnd].bind(this));
3457
- };
3458
- Core.prototype[_handleDoubleClick] = function (point) {
3459
- var _h;
3460
- var _j = this[_element].isPointInElement(point, this[_data]), index = _j[0], uuid = _j[1];
3461
- if (index >= 0 && uuid) {
3462
- this[_coreEvent].trigger('screenDoubleClickElement', { index: index, uuid: uuid, element: deepClone((_h = this[_data].elements) === null || _h === void 0 ? void 0 : _h[index]) });
3463
- }
3464
- this[_draw]();
3465
- };
3466
- Core.prototype[_handleClick] = function (point) {
3467
- var _h;
3468
- var _j = this[_element].isPointInElement(point, this[_data]), index = _j[0], uuid = _j[1];
3469
- if (index >= 0 && uuid) {
3470
- this[_coreEvent].trigger('screenClickElement', { index: index, uuid: uuid, element: deepClone((_h = this[_data].elements) === null || _h === void 0 ? void 0 : _h[index]) });
3471
- }
3472
- this[_draw]();
3473
- };
3474
- Core.prototype[_handlePoint] = function (point) {
3475
- var _h, _j, _k;
3476
- if (!this[_mapper].isEffectivePoint(point)) {
3477
- return;
3478
- }
3479
- if (this[_helper].isPointInElementList(point, this[_data])) {
3480
- this[_mode] = Mode.SELECT_ELEMENT_LIST;
3481
- }
3482
- else {
3483
- var _l = this[_helper].isPointInElementWrapperDot(point), uuid = _l[0], direction = _l[1];
3484
- if (uuid && direction) {
3485
- this[_mode] = Mode.SELECT_ELEMENT_WRAPPER_DOT;
3486
- this[_selectedDotDirection] = direction;
3487
- this[_tempData].set('selectedUUID', uuid);
3488
- }
3489
- else {
3490
- var _m = this[_element].isPointInElement(point, this[_data]), index = _m[0], uuid_1 = _m[1];
3491
- if (index >= 0 && ((_j = (_h = this[_data].elements[index]) === null || _h === void 0 ? void 0 : _h.operation) === null || _j === void 0 ? void 0 : _j.invisible) !== true) {
3492
- this.selectElementByIndex(index, { useMode: true });
3493
- if (typeof uuid_1 === 'string' && this[_coreEvent].has('screenSelectElement')) {
3494
- this[_coreEvent].trigger('screenSelectElement', { index: index, uuid: uuid_1, element: deepClone((_k = this[_data].elements) === null || _k === void 0 ? void 0 : _k[index]) });
3495
- this[_emitChangeScreen]();
3496
- }
3497
- this[_mode] = Mode.SELECT_ELEMENT;
3498
- }
3499
- else {
3500
- this[_tempData].set('selectedUUIDList', []);
3501
- this[_mode] = Mode.SELECT_AREA;
3502
- }
3503
- }
3504
- }
3505
- this[_draw]();
3506
- };
3507
- Core.prototype[_handleMoveStart] = function (point) {
3508
- this[_prevPoint] = point;
3509
- var uuid = this[_tempData].get('selectedUUID');
3510
- if (this[_mode] === Mode.SELECT_ELEMENT_LIST) ;
3511
- else if (this[_mode] === Mode.SELECT_ELEMENT) {
3512
- if (typeof uuid === 'string' && this[_coreEvent].has('screenMoveElementStart')) {
3513
- this[_coreEvent].trigger('screenMoveElementStart', {
3514
- index: this[_element].getElementIndex(this[_data], uuid),
3515
- uuid: uuid,
3516
- x: point.x,
3517
- y: point.y
3518
- });
3519
- }
3520
- }
3521
- else if (this[_mode] === Mode.SELECT_AREA) {
3522
- this[_helper].startSelectArea(point);
3523
- }
3524
- };
3525
- Core.prototype[_handleMove] = function (point) {
3526
- if (this[_mode] === Mode.SELECT_ELEMENT_LIST) {
3527
- this[_dragElements](this[_tempData].get('selectedUUIDList'), point, this[_prevPoint]);
3528
- this[_draw]();
3529
- this[_cursorStatus] = CursorStatus.DRAGGING;
3530
- }
3531
- else if (typeof this[_tempData].get('selectedUUID') === 'string') {
3532
- if (this[_mode] === Mode.SELECT_ELEMENT) {
3533
- this[_dragElements]([this[_tempData].get('selectedUUID')], point, this[_prevPoint]);
3534
- this[_draw]();
3535
- this[_cursorStatus] = CursorStatus.DRAGGING;
3536
- }
3537
- else if (this[_mode] === Mode.SELECT_ELEMENT_WRAPPER_DOT && this[_selectedDotDirection]) {
3538
- this[_transfromElement](this[_tempData].get('selectedUUID'), point, this[_prevPoint], this[_selectedDotDirection]);
3539
- this[_cursorStatus] = CursorStatus.DRAGGING;
3540
- }
3541
- }
3542
- else if (this[_mode] === Mode.SELECT_AREA) {
3543
- this[_helper].changeSelectArea(point);
3544
- this[_draw]();
3545
- }
3546
- this[_prevPoint] = point;
3547
- };
3548
- Core.prototype[_handleMoveEnd] = function (point) {
3549
- var uuid = this[_tempData].get('selectedUUID');
3550
- if (typeof uuid === 'string') {
3551
- var index = this[_element].getElementIndex(this[_data], uuid);
3552
- var elem = this[_data].elements[index];
3553
- if (elem) {
3554
- if (this[_coreEvent].has('screenMoveElementEnd')) {
3555
- this[_coreEvent].trigger('screenMoveElementEnd', {
3556
- index: index,
3557
- uuid: uuid,
3558
- x: point.x,
3559
- y: point.y
3560
- });
3561
- }
3562
- if (this[_coreEvent].has('screenChangeElement')) {
3563
- this[_coreEvent].trigger('screenChangeElement', {
3564
- index: index,
3565
- uuid: uuid,
3566
- width: elem.w,
3567
- height: elem.h,
3568
- angle: elem.angle || 0
3569
- });
3570
- }
3571
- this[_emitChangeData]();
3572
- }
3573
- }
3574
- else if (this[_mode] === Mode.SELECT_AREA) {
3575
- var uuids = this[_helper].calcSelectedElements(this[_data]);
3576
- if (uuids.length > 0) {
3577
- this[_tempData].set('selectedUUIDList', uuids);
3578
- this[_tempData].set('selectedUUID', null);
3579
- }
3580
- else {
3581
- this[_mode] = Mode.NULL;
3582
- }
3583
- this[_helper].clearSelectedArea();
3584
- this[_draw]();
3585
- }
3586
- if (this[_mode] !== Mode.SELECT_ELEMENT) {
3587
- this[_tempData].set('selectedUUID', null);
3588
- }
3589
- this[_prevPoint] = null;
3590
- this[_cursorStatus] = CursorStatus.NULL;
3591
- this[_mode] = Mode.NULL;
3592
- };
3593
- Core.prototype[_handleHover] = function (point) {
3594
- var _h, _j;
3595
- var isMouseOverElement = false;
3596
- if (this[_mode] === Mode.SELECT_AREA) {
3597
- if (this[_onlyRender] !== true)
3598
- this[_board].resetCursor();
3599
- }
3600
- else if (this[_cursorStatus] === CursorStatus.NULL) {
3601
- var _k = this[_mapper].judgePointCursor(point, this[_data]), cursor = _k.cursor, elementUUID = _k.elementUUID;
3602
- if (this[_onlyRender] !== true)
3603
- this[_board].setCursor(cursor);
3604
- if (elementUUID) {
3605
- var index = this[_helper].getElementIndexByUUID(elementUUID);
3606
- if (index !== null && index >= 0) {
3607
- var elem = this[_data].elements[index];
3608
- if (((_h = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _h === void 0 ? void 0 : _h.lock) === true || ((_j = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _j === void 0 ? void 0 : _j.invisible) === true) {
3609
- this[_board].resetCursor();
3610
- return;
3611
- }
3612
- if (this[_tempData].get('hoverUUID') !== elem.uuid) {
3613
- var preIndex = this[_helper].getElementIndexByUUID(this[_tempData].get('hoverUUID') || '');
3614
- if (preIndex !== null && this[_data].elements[preIndex]) {
3615
- this[_coreEvent].trigger('mouseLeaveElement', {
3616
- uuid: this[_tempData].get('hoverUUID'),
3617
- index: preIndex,
3618
- element: this[_data].elements[preIndex]
3619
- });
3620
- }
3621
- }
3622
- if (elem) {
3623
- this[_coreEvent].trigger('mouseOverElement', { uuid: elem.uuid, index: index, element: elem, });
3624
- this[_tempData].set('hoverUUID', elem.uuid);
3625
- isMouseOverElement = true;
3626
- }
3627
- }
3628
- }
3629
- }
3630
- if (isMouseOverElement !== true && this[_tempData].get('hoverUUID') !== null) {
3631
- var uuid = this[_tempData].get('hoverUUID');
3632
- var index = this[_helper].getElementIndexByUUID(uuid || '');
3633
- if (index !== null)
3634
- this[_coreEvent].trigger('mouseLeaveElement', { uuid: uuid, index: index, element: this[_data].elements[index] });
3635
- this[_tempData].set('hoverUUID', null);
3636
- }
3637
- if (this[_coreEvent].has('mouseOverScreen'))
3638
- this[_coreEvent].trigger('mouseOverScreen', point);
3639
- };
3640
- Core.prototype[_handleLeave] = function () {
3641
- if (this[_coreEvent].has('mouseLeaveScreen'))
3642
- this[_coreEvent].trigger('mouseLeaveScreen', undefined);
3643
- };
3644
- Core.prototype[_dragElements] = function (uuids, point, prevPoint) {
3645
- var _this = this;
3646
- if (!prevPoint) {
3647
- return;
3648
- }
3649
- uuids.forEach(function (uuid) {
3650
- var _h, _j;
3651
- var idx = _this[_helper].getElementIndexByUUID(uuid);
3652
- if (idx === null)
3653
- return;
3654
- var elem = _this[_data].elements[idx];
3655
- if (((_h = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _h === void 0 ? void 0 : _h.lock) !== true && ((_j = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _j === void 0 ? void 0 : _j.invisible) !== true) {
3656
- _this[_element].dragElement(_this[_data], uuid, point, prevPoint, _this[_board].getContext().getTransform().scale);
3657
- }
3658
- });
3659
- this[_draw]();
3660
- };
3661
- Core.prototype[_transfromElement] = function (uuid, point, prevPoint, direction) {
3662
- if (!prevPoint) {
3663
- return null;
3664
- }
3665
- var result = this[_element].transformElement(this[_data], uuid, point, prevPoint, this[_board].getContext().getTransform().scale, direction);
3666
- this[_draw]();
3667
- return result;
3668
- };
3669
3787
  Core.prototype[_emitChangeScreen] = function () {
3670
3788
  if (this[_coreEvent].has('changeScreen')) {
3671
3789
  this[_coreEvent].trigger('changeScreen', __assign$1({}, this.getScreenTransform()));
@@ -3676,7 +3794,10 @@ var Core = (function () {
3676
3794
  this[_coreEvent].trigger('changeData', deepClone(this[_data]));
3677
3795
  }
3678
3796
  };
3679
- var _a, _b, _c, _d, _e, _f, _g;
3797
+ Core.prototype[_todo] = function () {
3798
+ console.log(this[_mapper]);
3799
+ };
3800
+ var _a, _b;
3680
3801
  Core.is = is;
3681
3802
  Core.check = check;
3682
3803
  return Core;