@idraw/core 0.4.0-beta.18 → 0.4.0-beta.19

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.
@@ -1418,9 +1418,9 @@ var __privateMethod = (obj, member, method) => {
1418
1418
  ];
1419
1419
  }
1420
1420
  function isViewPointInElement(p, opts) {
1421
- const { context2d: ctx, element: elem, viewScaleInfo, viewSizeInfo } = opts;
1421
+ const { context2d: ctx, element: elem, viewScaleInfo } = opts;
1422
1422
  const { angle: angle2 = 0 } = elem;
1423
- const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo });
1423
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo });
1424
1424
  const vertexes = rotateElementVertexes({ x: x2, y: y2, w: w2, h: h2, angle: angle2 });
1425
1425
  if (vertexes.length >= 2) {
1426
1426
  ctx.beginPath();
@@ -1435,6 +1435,21 @@ var __privateMethod = (obj, member, method) => {
1435
1435
  }
1436
1436
  return false;
1437
1437
  }
1438
+ function isViewPointInVertexes(p, vertexes, opts) {
1439
+ const xList = [vertexes[0].x, vertexes[1].x, vertexes[2].x, vertexes[3].x];
1440
+ const yList = [vertexes[0].y, vertexes[1].y, vertexes[2].y, vertexes[3].y];
1441
+ const mixX = Math.min(...xList);
1442
+ const maxX = Math.max(...xList);
1443
+ const mixY = Math.min(...yList);
1444
+ const maxY = Math.max(...yList);
1445
+ if (p.x > mixX && p.x < maxX && p.y > mixY && p.y < maxY) {
1446
+ return true;
1447
+ }
1448
+ if ((opts === null || opts === void 0 ? void 0 : opts.includeBorder) === true && (p.x === mixX || p.x === maxX || p.y === mixY || p.y === maxY)) {
1449
+ return true;
1450
+ }
1451
+ return false;
1452
+ }
1438
1453
  function getViewPointAtElement(p, opts) {
1439
1454
  var _a, _b, _c;
1440
1455
  const { context2d: ctx, data, viewScaleInfo, viewSizeInfo, groupQueue } = opts;
@@ -1791,6 +1806,103 @@ var __privateMethod = (obj, member, method) => {
1791
1806
  };
1792
1807
  return sizeController;
1793
1808
  }
1809
+ function calcLayoutSizeController(layoutSize, opts) {
1810
+ const { controllerSize: controllerSize2, viewScaleInfo } = opts;
1811
+ const ctrlSize = controllerSize2 && controllerSize2 > 0 ? controllerSize2 : 8;
1812
+ const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(layoutSize, { viewScaleInfo });
1813
+ const center = calcElementCenter({ x: x2, y: y2, w: w2, h: h2 });
1814
+ const topCenter = { x: center.x, y: y2 };
1815
+ const rightCenter = { x: x2 + w2, y: center.y };
1816
+ const bottomCenter = { x: center.x, y: y2 + h2 };
1817
+ const leftCenter = { x: x2, y: center.y };
1818
+ const topLeftCenter = { x: x2, y: y2 };
1819
+ const topRightCenter = { x: x2 + w2, y: y2 };
1820
+ const bottomRightCenter = { x: x2 + w2, y: y2 + h2 };
1821
+ const bottomLeftCenter = { x: x2, y: y2 + h2 };
1822
+ const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: 0 });
1823
+ const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: 0 });
1824
+ const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: 0 });
1825
+ const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: 0 });
1826
+ const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: 0 });
1827
+ const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: 0 });
1828
+ const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: 0 });
1829
+ const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: 0 });
1830
+ const topLeftVertexes = calcElementVertexes(topLeftSize);
1831
+ const topRightVertexes = calcElementVertexes(topRightSize);
1832
+ const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
1833
+ const bottomRightVertexes = calcElementVertexes(bottomRightSize);
1834
+ const topVertexes = [topLeftVertexes[1], topRightVertexes[0], topRightVertexes[3], topLeftVertexes[2]];
1835
+ const rightVertexes = [topRightVertexes[3], topRightVertexes[2], bottomRightVertexes[1], bottomRightVertexes[0]];
1836
+ const bottomVertexes = [bottomLeftVertexes[1], bottomRightVertexes[0], bottomRightVertexes[3], bottomLeftVertexes[2]];
1837
+ const leftVertexes = [topLeftVertexes[3], topLeftVertexes[2], bottomLeftVertexes[1], bottomLeftVertexes[0]];
1838
+ const topMiddleVertexes = calcElementVertexes(topMiddleSize);
1839
+ const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
1840
+ const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
1841
+ const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
1842
+ const sizeController = {
1843
+ left: {
1844
+ type: "left",
1845
+ vertexes: leftVertexes,
1846
+ center: leftCenter
1847
+ },
1848
+ right: {
1849
+ type: "right",
1850
+ vertexes: rightVertexes,
1851
+ center: rightCenter
1852
+ },
1853
+ top: {
1854
+ type: "top",
1855
+ vertexes: topVertexes,
1856
+ center: topCenter
1857
+ },
1858
+ bottom: {
1859
+ type: "bottom",
1860
+ vertexes: bottomVertexes,
1861
+ center: bottomCenter
1862
+ },
1863
+ topLeft: {
1864
+ type: "top-left",
1865
+ vertexes: topLeftVertexes,
1866
+ center: topLeftCenter
1867
+ },
1868
+ topRight: {
1869
+ type: "top-right",
1870
+ vertexes: topRightVertexes,
1871
+ center: topRightCenter
1872
+ },
1873
+ bottomLeft: {
1874
+ type: "bottom-left",
1875
+ vertexes: bottomLeftVertexes,
1876
+ center: bottomLeftCenter
1877
+ },
1878
+ bottomRight: {
1879
+ type: "bottom-right",
1880
+ vertexes: bottomRightVertexes,
1881
+ center: bottomRightCenter
1882
+ },
1883
+ leftMiddle: {
1884
+ type: "left-middle",
1885
+ vertexes: leftMiddleVertexes,
1886
+ center: leftCenter
1887
+ },
1888
+ rightMiddle: {
1889
+ type: "right-middle",
1890
+ vertexes: rightMiddleVertexes,
1891
+ center: rightCenter
1892
+ },
1893
+ topMiddle: {
1894
+ type: "top-middle",
1895
+ vertexes: topMiddleVertexes,
1896
+ center: topCenter
1897
+ },
1898
+ bottomMiddle: {
1899
+ type: "bottom-middle",
1900
+ vertexes: bottomMiddleVertexes,
1901
+ center: bottomCenter
1902
+ }
1903
+ };
1904
+ return sizeController;
1905
+ }
1794
1906
  function generateSVGPath(commands) {
1795
1907
  let path = "";
1796
1908
  commands.forEach((item) => {
@@ -1821,7 +1933,6 @@ var __privateMethod = (obj, member, method) => {
1821
1933
  textAlign: "left",
1822
1934
  verticalAlign: "top",
1823
1935
  fontSize: 16,
1824
- lineHeight: 20,
1825
1936
  fontFamily: "sans-serif",
1826
1937
  fontWeight: 400,
1827
1938
  overflow: "hidden"
@@ -2449,7 +2560,7 @@ var __privateMethod = (obj, member, method) => {
2449
2560
  const detailConfig = getDefaultElementDetailConfig();
2450
2561
  function drawText(ctx, elem, opts) {
2451
2562
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2452
- const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
2563
+ const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = calcViewElementSize(elem, { viewScaleInfo }) || elem;
2453
2564
  const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2454
2565
  rotateElement$1(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
2455
2566
  drawBox(ctx, viewElem, {
@@ -2460,8 +2571,10 @@ var __privateMethod = (obj, member, method) => {
2460
2571
  parentOpacity,
2461
2572
  renderContent: () => {
2462
2573
  const detail = Object.assign(Object.assign({}, detailConfig), elem.detail);
2463
- const fontSize2 = (detail.fontSize || detailConfig.fontSize) * viewScaleInfo.scale;
2464
- const lineHeight2 = detail.lineHeight ? detail.lineHeight * viewScaleInfo.scale : fontSize2;
2574
+ const originFontSize = detail.fontSize || detailConfig.fontSize;
2575
+ const fontSize2 = originFontSize * viewScaleInfo.scale;
2576
+ const originLineHeight = detail.lineHeight || originFontSize;
2577
+ const lineHeight2 = originLineHeight * viewScaleInfo.scale;
2465
2578
  ctx.fillStyle = elem.detail.color || detailConfig.color;
2466
2579
  ctx.textBaseline = "top";
2467
2580
  ctx.$setFont({
@@ -2478,7 +2591,7 @@ var __privateMethod = (obj, member, method) => {
2478
2591
  let lineText = "";
2479
2592
  if (tempText.length > 0) {
2480
2593
  for (let i = 0; i < tempText.length; i++) {
2481
- if (ctx.measureText(lineText + (tempText[i] || "")).width < ctx.$doPixelRatio(w2)) {
2594
+ if (ctx.measureText(lineText + (tempText[i] || "")).width <= ctx.$doPixelRatio(w2)) {
2482
2595
  lineText += tempText[i] || "";
2483
2596
  } else {
2484
2597
  lines.push({
@@ -2492,7 +2605,7 @@ var __privateMethod = (obj, member, method) => {
2492
2605
  break;
2493
2606
  }
2494
2607
  if (tempText.length - 1 === i) {
2495
- if ((lineNum + 1) * fontHeight < h2) {
2608
+ if ((lineNum + 1) * fontHeight <= h2) {
2496
2609
  lines.push({
2497
2610
  text: lineText,
2498
2611
  width: ctx.$undoPixelRatio(ctx.measureText(lineText).width)
@@ -2748,7 +2861,7 @@ var __privateMethod = (obj, member, method) => {
2748
2861
  }
2749
2862
  function drawLayout(ctx, layout, opts, renderContent) {
2750
2863
  const { viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2751
- const elem = Object.assign({ uuid: "layout", type: "group", x: 0, y: 0 }, layout);
2864
+ const elem = Object.assign({ uuid: "layout", type: "group" }, layout);
2752
2865
  const { x: x2, y: y2, w: w2, h: h2 } = calcViewElementSize(elem, { viewScaleInfo, viewSizeInfo }) || elem;
2753
2866
  const angle2 = 0;
2754
2867
  const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
@@ -2762,7 +2875,7 @@ var __privateMethod = (obj, member, method) => {
2762
2875
  });
2763
2876
  if (layout.detail.overflow === "hidden") {
2764
2877
  const { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 } = opts;
2765
- const elem2 = Object.assign({ uuid: "layout", type: "group", x: 0, y: 0 }, layout);
2878
+ const elem2 = Object.assign({ uuid: "layout", type: "group" }, layout);
2766
2879
  const viewElemSize = calcViewElementSize(elem2, { viewScaleInfo: viewScaleInfo2, viewSizeInfo: viewSizeInfo2 }) || elem2;
2767
2880
  const viewElem2 = Object.assign(Object.assign({}, elem2), viewElemSize);
2768
2881
  const { x: x3, y: y3, w: w3, h: h3, radiusList } = calcViewBoxSize(viewElem2, {
@@ -4220,22 +4333,23 @@ var __privateMethod = (obj, member, method) => {
4220
4333
  }
4221
4334
  return key2;
4222
4335
  };
4223
- const key$2 = "SELECT";
4224
- const keyActionType = Symbol(`${key$2}_actionType`);
4225
- const keyResizeType = Symbol(`${key$2}_resizeType`);
4226
- const keyAreaStart = Symbol(`${key$2}_areaStart`);
4227
- const keyAreaEnd = Symbol(`${key$2}_areaEnd`);
4228
- const keyHoverElement = Symbol(`${key$2}_hoverElement`);
4229
- const keyHoverElementVertexes = Symbol(`${key$2}_hoverElementVertexes`);
4230
- const keySelectedElementList = Symbol(`${key$2}_selectedElementList`);
4231
- const keySelectedElementListVertexes = Symbol(`${key$2}_selectedElementListVertexes`);
4232
- const keySelectedElementController = Symbol(`${key$2}_selectedElementController`);
4233
- const keySelectedElementPosition = Symbol(`${key$2}_selectedElementPosition`);
4234
- const keySelectedReferenceXLines = Symbol(`${key$2}_selectedReferenceXLines`);
4235
- const keySelectedReferenceYLines = Symbol(`${key$2}_selectedReferenceYLines`);
4236
- const keyGroupQueue = Symbol(`${key$2}_groupQueue`);
4237
- const keyGroupQueueVertexesList = Symbol(`${key$2}_groupQueueVertexesList`);
4238
- const keyIsMoving = Symbol(`${key$2}_isMoving`);
4336
+ const eventChange = "change";
4337
+ const key$3 = "SELECT";
4338
+ const keyActionType = Symbol(`${key$3}_actionType`);
4339
+ const keyResizeType = Symbol(`${key$3}_resizeType`);
4340
+ const keyAreaStart = Symbol(`${key$3}_areaStart`);
4341
+ const keyAreaEnd = Symbol(`${key$3}_areaEnd`);
4342
+ const keyHoverElement = Symbol(`${key$3}_hoverElement`);
4343
+ const keyHoverElementVertexes = Symbol(`${key$3}_hoverElementVertexes`);
4344
+ const keySelectedElementList = Symbol(`${key$3}_selectedElementList`);
4345
+ const keySelectedElementListVertexes = Symbol(`${key$3}_selectedElementListVertexes`);
4346
+ const keySelectedElementController = Symbol(`${key$3}_selectedElementController`);
4347
+ const keySelectedElementPosition = Symbol(`${key$3}_selectedElementPosition`);
4348
+ const keySelectedReferenceXLines = Symbol(`${key$3}_selectedReferenceXLines`);
4349
+ const keySelectedReferenceYLines = Symbol(`${key$3}_selectedReferenceYLines`);
4350
+ const keyGroupQueue = Symbol(`${key$3}_groupQueue`);
4351
+ const keyGroupQueueVertexesList = Symbol(`${key$3}_groupQueueVertexesList`);
4352
+ const keyIsMoving = Symbol(`${key$3}_isMoving`);
4239
4353
  const selectWrapperBorderWidth = 2;
4240
4354
  const resizeControllerBorderWidth = 4;
4241
4355
  const areaBorderWidth = 1;
@@ -5882,6 +5996,11 @@ var __privateMethod = (obj, member, method) => {
5882
5996
  });
5883
5997
  triggerCursor(target);
5884
5998
  if (target.type === null) {
5999
+ if (sharer.getSharedStorage(keyHoverElement) || sharer.getSharedStorage(keyHoverElementVertexes)) {
6000
+ sharer.setSharedStorage(keyHoverElement, null);
6001
+ sharer.setSharedStorage(keyHoverElementVertexes, null);
6002
+ viewer.drawFrame();
6003
+ }
5885
6004
  return;
5886
6005
  }
5887
6006
  if (target.type === "over-element" && sharer.getSharedStorage(keyActionType) === "select" && target.elements.length === 1 && target.elements[0].uuid === ((_c = (_b = getActiveElements()) == null ? void 0 : _b[0]) == null ? void 0 : _c.uuid)) {
@@ -6188,7 +6307,7 @@ var __privateMethod = (obj, member, method) => {
6188
6307
  }
6189
6308
  if (data && ["drag", "drag-list", "drag-list-end", "resize"].includes(actionType)) {
6190
6309
  let type = "dragElement";
6191
- eventHub.trigger("change", { data, type });
6310
+ eventHub.trigger(eventChange, { data, type });
6192
6311
  }
6193
6312
  viewer.drawFrame();
6194
6313
  };
@@ -6326,12 +6445,12 @@ var __privateMethod = (obj, member, method) => {
6326
6445
  }
6327
6446
  };
6328
6447
  };
6329
- const key$1 = "SCROLL";
6330
- const keyXThumbRect = Symbol(`${key$1}_xThumbRect`);
6331
- const keyYThumbRect = Symbol(`${key$1}_yThumbRect`);
6332
- const keyPrevPoint$1 = Symbol(`${key$1}_prevPoint`);
6333
- const keyActivePoint = Symbol(`${key$1}_activePoint`);
6334
- const keyActiveThumbType = Symbol(`${key$1}_activeThumbType`);
6448
+ const key$2 = "SCROLL";
6449
+ const keyXThumbRect = Symbol(`${key$2}_xThumbRect`);
6450
+ const keyYThumbRect = Symbol(`${key$2}_yThumbRect`);
6451
+ const keyPrevPoint$1 = Symbol(`${key$2}_prevPoint`);
6452
+ const keyActivePoint = Symbol(`${key$2}_activePoint`);
6453
+ const keyActiveThumbType = Symbol(`${key$2}_activeThumbType`);
6335
6454
  const minScrollerWidth = 12;
6336
6455
  const scrollerLineWidth = 16;
6337
6456
  const scrollerThumbAlpha = 0.3;
@@ -6923,8 +7042,8 @@ var __privateMethod = (obj, member, method) => {
6923
7042
  }
6924
7043
  };
6925
7044
  };
6926
- const key = "DRAG";
6927
- const keyPrevPoint = Symbol(`${key}_prevPoint`);
7045
+ const key$1 = "DRAG";
7046
+ const keyPrevPoint = Symbol(`${key$1}_prevPoint`);
6928
7047
  const MiddlewareDragger = (opts) => {
6929
7048
  const { eventHub, sharer, viewer } = opts;
6930
7049
  let isDragging = false;
@@ -7182,6 +7301,337 @@ var __privateMethod = (obj, member, method) => {
7182
7301
  }
7183
7302
  };
7184
7303
  };
7304
+ const key = "LAYOUT_SELECT";
7305
+ const keyLayoutActionType = Symbol(`${key}_layoutActionType`);
7306
+ const keyLayoutControlType = Symbol(`${key}_layoutControlType`);
7307
+ const keyLayoutController = Symbol(`${key}_layoutController`);
7308
+ const selectColor = "#1973ba";
7309
+ const disableColor = "#5b5959b5";
7310
+ function drawControllerBox(ctx, boxVertexes) {
7311
+ ctx.setLineDash([]);
7312
+ ctx.fillStyle = "#FFFFFF";
7313
+ ctx.beginPath();
7314
+ ctx.moveTo(boxVertexes[0].x, boxVertexes[0].y);
7315
+ ctx.lineTo(boxVertexes[1].x, boxVertexes[1].y);
7316
+ ctx.lineTo(boxVertexes[2].x, boxVertexes[2].y);
7317
+ ctx.lineTo(boxVertexes[3].x, boxVertexes[3].y);
7318
+ ctx.closePath();
7319
+ ctx.fill();
7320
+ ctx.strokeStyle = selectColor;
7321
+ ctx.lineWidth = 2;
7322
+ ctx.beginPath();
7323
+ ctx.moveTo(boxVertexes[0].x, boxVertexes[0].y);
7324
+ ctx.lineTo(boxVertexes[1].x, boxVertexes[1].y);
7325
+ ctx.lineTo(boxVertexes[2].x, boxVertexes[2].y);
7326
+ ctx.lineTo(boxVertexes[3].x, boxVertexes[3].y);
7327
+ ctx.closePath();
7328
+ ctx.stroke();
7329
+ }
7330
+ function drawControllerCross(ctx, opts) {
7331
+ const { vertexes, strokeStyle, lineWidth } = opts;
7332
+ ctx.setLineDash([]);
7333
+ ctx.strokeStyle = strokeStyle;
7334
+ ctx.lineWidth = lineWidth;
7335
+ ctx.beginPath();
7336
+ ctx.moveTo(vertexes[0].x, vertexes[0].y);
7337
+ ctx.lineTo(vertexes[2].x, vertexes[2].y);
7338
+ ctx.closePath();
7339
+ ctx.stroke();
7340
+ ctx.beginPath();
7341
+ ctx.moveTo(vertexes[1].x, vertexes[1].y);
7342
+ ctx.lineTo(vertexes[3].x, vertexes[3].y);
7343
+ ctx.closePath();
7344
+ ctx.stroke();
7345
+ }
7346
+ function drawControllerLine(ctx, opts) {
7347
+ const { start, end, centerVertexes, disabled } = opts;
7348
+ const lineWidth = disabled === true ? 1 : 2;
7349
+ const strokeStyle = disabled === true ? disableColor : selectColor;
7350
+ ctx.setLineDash([]);
7351
+ ctx.strokeStyle = strokeStyle;
7352
+ ctx.lineWidth = lineWidth;
7353
+ ctx.beginPath();
7354
+ ctx.moveTo(start.x, start.y);
7355
+ ctx.lineTo(end.x, end.y);
7356
+ ctx.closePath();
7357
+ ctx.stroke();
7358
+ if (disabled === true) {
7359
+ drawControllerCross(ctx, {
7360
+ vertexes: centerVertexes,
7361
+ lineWidth,
7362
+ strokeStyle
7363
+ });
7364
+ }
7365
+ }
7366
+ function drawLayoutController(ctx, opts) {
7367
+ const { controller, operations } = opts;
7368
+ const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, rightMiddle, bottomMiddle, leftMiddle } = controller;
7369
+ drawControllerLine(ctx, { start: topLeft.center, end: topRight.center, centerVertexes: topMiddle.vertexes, disabled: !!(operations == null ? void 0 : operations.disableTop) });
7370
+ drawControllerLine(ctx, { start: topRight.center, end: bottomRight.center, centerVertexes: rightMiddle.vertexes, disabled: !!(operations == null ? void 0 : operations.disableRight) });
7371
+ drawControllerLine(ctx, { start: bottomRight.center, end: bottomLeft.center, centerVertexes: bottomMiddle.vertexes, disabled: !!(operations == null ? void 0 : operations.disableBottom) });
7372
+ drawControllerLine(ctx, { start: bottomLeft.center, end: topLeft.center, centerVertexes: leftMiddle.vertexes, disabled: !!(operations == null ? void 0 : operations.disableLeft) });
7373
+ const disabledOpts = {
7374
+ lineWidth: 1,
7375
+ strokeStyle: disableColor
7376
+ };
7377
+ if ((operations == null ? void 0 : operations.disableTopLeft) === true) {
7378
+ drawControllerCross(ctx, { vertexes: topLeft.vertexes, ...disabledOpts });
7379
+ } else {
7380
+ drawControllerBox(ctx, topLeft.vertexes);
7381
+ }
7382
+ if ((operations == null ? void 0 : operations.disableTopRight) === true) {
7383
+ drawControllerCross(ctx, { vertexes: topRight.vertexes, ...disabledOpts });
7384
+ } else {
7385
+ drawControllerBox(ctx, topRight.vertexes);
7386
+ }
7387
+ if ((operations == null ? void 0 : operations.disableBottomRight) === true) {
7388
+ drawControllerCross(ctx, { vertexes: bottomRight.vertexes, ...disabledOpts });
7389
+ } else {
7390
+ drawControllerBox(ctx, bottomRight.vertexes);
7391
+ }
7392
+ if ((operations == null ? void 0 : operations.disableBottomLeft) === true) {
7393
+ drawControllerCross(ctx, { vertexes: bottomLeft.vertexes, ...disabledOpts });
7394
+ } else {
7395
+ drawControllerBox(ctx, bottomLeft.vertexes);
7396
+ }
7397
+ }
7398
+ const MiddlewareLayoutSelector = (opts) => {
7399
+ const { sharer, boardContent, calculator, viewer, eventHub } = opts;
7400
+ const { helperContext } = boardContent;
7401
+ let prevPoint = null;
7402
+ const clear = () => {
7403
+ prevPoint = null;
7404
+ sharer.setSharedStorage(keyLayoutActionType, null);
7405
+ sharer.setSharedStorage(keyLayoutControlType, null);
7406
+ sharer.setSharedStorage(keyLayoutController, null);
7407
+ };
7408
+ const isInElementAction = () => {
7409
+ const elementType = sharer.getSharedStorage(keyActionType);
7410
+ if (elementType) {
7411
+ return true;
7412
+ }
7413
+ return false;
7414
+ };
7415
+ const isDisbaledControl = (controlType) => {
7416
+ var _a;
7417
+ const data = sharer.getActiveStorage("data");
7418
+ if ((_a = data == null ? void 0 : data.layout) == null ? void 0 : _a.operations) {
7419
+ const operations = data.layout.operations;
7420
+ if (controlType === "left" && operations.disableLeft === true) {
7421
+ return true;
7422
+ }
7423
+ if (controlType === "top" && operations.disableTop === true) {
7424
+ return true;
7425
+ }
7426
+ if (controlType === "right" && operations.disableRight === true) {
7427
+ return true;
7428
+ }
7429
+ if (controlType === "bottom" && operations.disableBottom === true) {
7430
+ return true;
7431
+ }
7432
+ if (controlType === "top-left" && operations.disableTopLeft === true) {
7433
+ return true;
7434
+ }
7435
+ if (controlType === "top-right" && operations.disableTopRight === true) {
7436
+ return true;
7437
+ }
7438
+ if (controlType === "bottom-left" && operations.disableBottomLeft === true) {
7439
+ return true;
7440
+ }
7441
+ if (controlType === "bottom-right" && operations.disableBottomRight === true) {
7442
+ return true;
7443
+ }
7444
+ }
7445
+ return false;
7446
+ };
7447
+ const getLayoutSize = () => {
7448
+ const data = sharer.getActiveStorage("data");
7449
+ if (data == null ? void 0 : data.layout) {
7450
+ const { x: x2, y: y2, w: w2, h: h2 } = data.layout;
7451
+ return { x: x2, y: y2, w: w2, h: h2 };
7452
+ }
7453
+ return null;
7454
+ };
7455
+ const resetController = () => {
7456
+ const viewScaleInfo = sharer.getActiveViewScaleInfo();
7457
+ const size = getLayoutSize();
7458
+ if (size) {
7459
+ const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
7460
+ sharer.setSharedStorage(keyLayoutController, controller);
7461
+ } else {
7462
+ sharer.setSharedStorage(keyLayoutController, null);
7463
+ }
7464
+ };
7465
+ const resetControlType = (e) => {
7466
+ const data = sharer.getActiveStorage("data");
7467
+ const controller = sharer.getSharedStorage(keyLayoutController);
7468
+ if (controller && (data == null ? void 0 : data.layout) && (e == null ? void 0 : e.point)) {
7469
+ let layoutControlType = null;
7470
+ if (controller) {
7471
+ const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = controller;
7472
+ const list = [topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left];
7473
+ for (let i = 0; i < list.length; i++) {
7474
+ const item = list[i];
7475
+ if (isViewPointInVertexes(e.point, item.vertexes)) {
7476
+ layoutControlType = `${item.type}`;
7477
+ break;
7478
+ }
7479
+ }
7480
+ if (layoutControlType) {
7481
+ sharer.setSharedStorage(keyLayoutControlType, layoutControlType);
7482
+ eventHub.trigger(middlewareEventSelectClear, {});
7483
+ return layoutControlType;
7484
+ }
7485
+ }
7486
+ }
7487
+ return null;
7488
+ };
7489
+ return {
7490
+ name: "@middleware/layout-selector",
7491
+ use: () => {
7492
+ clear();
7493
+ resetController();
7494
+ },
7495
+ hover: (e) => {
7496
+ if (isInElementAction()) {
7497
+ return;
7498
+ }
7499
+ const prevLayoutActionType = sharer.getSharedStorage(keyLayoutActionType);
7500
+ const data = sharer.getActiveStorage("data");
7501
+ if ((data == null ? void 0 : data.layout) && prevLayoutActionType !== "resize") {
7502
+ resetController();
7503
+ const layoutControlType = resetControlType(e);
7504
+ if (layoutControlType) {
7505
+ sharer.setSharedStorage(keyLayoutActionType, "hover");
7506
+ if (!isDisbaledControl(layoutControlType)) {
7507
+ eventHub.trigger("cursor", {
7508
+ type: `resize-${layoutControlType}`,
7509
+ groupQueue: [],
7510
+ element: getLayoutSize()
7511
+ });
7512
+ }
7513
+ viewer.drawFrame();
7514
+ } else {
7515
+ sharer.setSharedStorage(keyLayoutActionType, null);
7516
+ }
7517
+ }
7518
+ if (["hover", "resize"].includes(sharer.getSharedStorage(keyLayoutActionType))) {
7519
+ return false;
7520
+ }
7521
+ if (prevLayoutActionType === "hover" && !sharer.getSharedStorage(keyLayoutActionType)) {
7522
+ viewer.drawFrame();
7523
+ }
7524
+ },
7525
+ pointStart: (e) => {
7526
+ if (isInElementAction()) {
7527
+ return;
7528
+ }
7529
+ resetController();
7530
+ const layoutControlType = resetControlType(e);
7531
+ prevPoint = e.point;
7532
+ if (layoutControlType) {
7533
+ if (isDisbaledControl(layoutControlType)) {
7534
+ return;
7535
+ }
7536
+ sharer.setSharedStorage(keyLayoutActionType, "resize");
7537
+ return false;
7538
+ }
7539
+ const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
7540
+ if (["hover", "resize"].includes(layoutActionType)) {
7541
+ return false;
7542
+ }
7543
+ },
7544
+ pointMove: (e) => {
7545
+ if (isInElementAction()) {
7546
+ return;
7547
+ }
7548
+ const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
7549
+ const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
7550
+ const data = sharer.getActiveStorage("data");
7551
+ if (layoutControlType && isDisbaledControl(layoutControlType)) {
7552
+ return;
7553
+ }
7554
+ if (layoutActionType === "resize" && layoutControlType && (data == null ? void 0 : data.layout)) {
7555
+ if (prevPoint) {
7556
+ const scale = sharer.getActiveStorage("scale");
7557
+ const moveX = (e.point.x - prevPoint.x) / scale;
7558
+ const moveY = (e.point.y - prevPoint.y) / scale;
7559
+ const { x: x2, y: y2, w: w2, h: h2 } = data.layout;
7560
+ if (layoutControlType === "top") {
7561
+ data.layout.y = calculator.toGridNum(y2 + moveY);
7562
+ data.layout.h = calculator.toGridNum(h2 - moveY);
7563
+ } else if (layoutControlType === "right") {
7564
+ data.layout.w = calculator.toGridNum(w2 + moveX);
7565
+ } else if (layoutControlType === "bottom") {
7566
+ data.layout.h = calculator.toGridNum(h2 + moveY);
7567
+ } else if (layoutControlType === "left") {
7568
+ data.layout.x = calculator.toGridNum(x2 + moveX);
7569
+ data.layout.w = calculator.toGridNum(w2 - moveX);
7570
+ } else if (layoutControlType === "top-left") {
7571
+ data.layout.x = calculator.toGridNum(x2 + moveX);
7572
+ data.layout.y = calculator.toGridNum(y2 + moveY);
7573
+ data.layout.w = calculator.toGridNum(w2 - moveX);
7574
+ data.layout.h = calculator.toGridNum(h2 - moveY);
7575
+ } else if (layoutControlType === "top-right") {
7576
+ data.layout.y = calculator.toGridNum(y2 + moveY);
7577
+ data.layout.w = calculator.toGridNum(w2 + moveX);
7578
+ data.layout.h = calculator.toGridNum(h2 - moveY);
7579
+ } else if (layoutControlType === "bottom-right") {
7580
+ data.layout.w = calculator.toGridNum(w2 + moveX);
7581
+ data.layout.h = calculator.toGridNum(h2 + moveY);
7582
+ } else if (layoutControlType === "bottom-left") {
7583
+ data.layout.x = calculator.toGridNum(x2 + moveX);
7584
+ data.layout.w = calculator.toGridNum(w2 - moveX);
7585
+ data.layout.h = calculator.toGridNum(h2 + moveY);
7586
+ }
7587
+ }
7588
+ prevPoint = e.point;
7589
+ resetController();
7590
+ viewer.drawFrame();
7591
+ return false;
7592
+ }
7593
+ if (["hover", "resize"].includes(layoutActionType)) {
7594
+ return false;
7595
+ }
7596
+ },
7597
+ pointEnd: () => {
7598
+ const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
7599
+ const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
7600
+ const data = sharer.getActiveStorage("data");
7601
+ if (data && layoutActionType === "resize" && layoutControlType && !isDisbaledControl(layoutControlType)) {
7602
+ eventHub.trigger(eventChange, {
7603
+ type: "changeLayout",
7604
+ data
7605
+ });
7606
+ }
7607
+ clear();
7608
+ },
7609
+ beforeDrawFrame: ({ snapshot }) => {
7610
+ var _a;
7611
+ const { sharedStore, activeStore } = snapshot;
7612
+ const layoutActionType = sharedStore[keyLayoutActionType];
7613
+ const layoutControlType = sharedStore[keyLayoutControlType];
7614
+ if (((_a = activeStore.data) == null ? void 0 : _a.layout) && layoutActionType && layoutControlType) {
7615
+ if (["hover", "resize"].includes(layoutActionType)) {
7616
+ const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
7617
+ const { x: x2, y: y2, w: w2, h: h2 } = activeStore.data.layout;
7618
+ const size = { x: x2, y: y2, w: w2, h: h2 };
7619
+ const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
7620
+ drawLayoutController(helperContext, { controller, operations: activeStore.data.layout.operations || {} });
7621
+ }
7622
+ }
7623
+ },
7624
+ scrollX: () => {
7625
+ clear();
7626
+ },
7627
+ scrollY: () => {
7628
+ clear();
7629
+ },
7630
+ wheelScale: () => {
7631
+ clear();
7632
+ }
7633
+ };
7634
+ };
7185
7635
  class Core {
7186
7636
  constructor(container, opts) {
7187
7637
  __privateAdd(this, _initContainer);
@@ -7298,11 +7748,13 @@ var __privateMethod = (obj, member, method) => {
7298
7748
  exports.Core = Core;
7299
7749
  exports.MiddlewareDragger = MiddlewareDragger;
7300
7750
  exports.MiddlewareInfo = MiddlewareInfo;
7751
+ exports.MiddlewareLayoutSelector = MiddlewareLayoutSelector;
7301
7752
  exports.MiddlewareRuler = MiddlewareRuler;
7302
7753
  exports.MiddlewareScaler = MiddlewareScaler;
7303
7754
  exports.MiddlewareScroller = MiddlewareScroller;
7304
7755
  exports.MiddlewareSelector = MiddlewareSelector;
7305
7756
  exports.MiddlewareTextEditor = MiddlewareTextEditor;
7757
+ exports.eventChange = eventChange;
7306
7758
  exports.middlewareEventRuler = middlewareEventRuler;
7307
7759
  exports.middlewareEventScale = middlewareEventScale;
7308
7760
  exports.middlewareEventSelect = middlewareEventSelect;