@plait/core 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/interfaces/board.mjs +2 -2
- package/esm2020/interfaces/viewport.mjs +1 -1
- package/esm2020/plugins/with-hand.mjs +3 -3
- package/esm2020/plugins/with-moving.mjs +9 -11
- package/esm2020/plugins/with-selection.mjs +9 -10
- package/esm2020/transforms/board.mjs +49 -18
- package/esm2020/utils/board.mjs +11 -2
- package/esm2020/utils/index.mjs +2 -1
- package/esm2020/utils/selected-element.mjs +14 -3
- package/esm2020/utils/to-image.mjs +106 -0
- package/esm2020/utils/tree.mjs +8 -3
- package/esm2020/utils/viewport.mjs +9 -5
- package/fesm2015/plait-core.mjs +221 -59
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +218 -58
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/board.d.ts +1 -1
- package/interfaces/viewport.d.ts +6 -0
- package/package.json +1 -1
- package/transforms/board.d.ts +3 -0
- package/utils/board.d.ts +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/selected-element.d.ts +2 -1
- package/utils/to-image.d.ts +10 -0
- package/utils/tree.d.ts +1 -1
- package/utils/viewport.d.ts +1 -0
package/fesm2015/plait-core.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { timer, Subject, fromEvent } from 'rxjs';
|
|
|
5
5
|
import { takeUntil, filter, tap } from 'rxjs/operators';
|
|
6
6
|
import produce, { createDraft, finishDraft, isDraft } from 'immer';
|
|
7
7
|
import { isKeyHotkey, isHotkey } from 'is-hotkey';
|
|
8
|
+
import { __awaiter } from 'tslib';
|
|
8
9
|
import * as i1 from '@angular/common';
|
|
9
10
|
import { CommonModule } from '@angular/common';
|
|
10
11
|
|
|
@@ -28,10 +29,14 @@ const BOARD_TO_TEMPORARY_ELEMENTS = new WeakMap();
|
|
|
28
29
|
const BOARD_TO_MOVING_ELEMENT = new WeakMap();
|
|
29
30
|
const PATH_REFS = new WeakMap();
|
|
30
31
|
|
|
31
|
-
function depthFirstRecursion(node, callback, recursion) {
|
|
32
|
-
var _a;
|
|
32
|
+
function depthFirstRecursion(node, callback, recursion, isReverse) {
|
|
33
33
|
if (!recursion || recursion(node)) {
|
|
34
|
-
|
|
34
|
+
let children = [];
|
|
35
|
+
if (node.children) {
|
|
36
|
+
children = [...node.children];
|
|
37
|
+
}
|
|
38
|
+
children = isReverse ? children.reverse() : children;
|
|
39
|
+
children.forEach(child => {
|
|
35
40
|
depthFirstRecursion(child, callback, recursion);
|
|
36
41
|
});
|
|
37
42
|
}
|
|
@@ -173,7 +178,7 @@ const PlaitBoard = {
|
|
|
173
178
|
getComponent(board) {
|
|
174
179
|
return BOARD_TO_COMPONENT.get(board);
|
|
175
180
|
},
|
|
176
|
-
|
|
181
|
+
getBoardContainer(board) {
|
|
177
182
|
return PlaitBoard.getComponent(board).nativeElement;
|
|
178
183
|
},
|
|
179
184
|
getRectangle(board) {
|
|
@@ -765,10 +770,27 @@ function distanceBetweenPointAndRectangle(x, y, rect) {
|
|
|
765
770
|
return Math.sqrt(dx * dx + dy * dy);
|
|
766
771
|
}
|
|
767
772
|
|
|
773
|
+
const SELECTION_BORDER_COLOR = '#6698FF';
|
|
774
|
+
const SELECTION_FILL_COLOR = '#6698FF19'; // 主色 0.1 透明度
|
|
775
|
+
const Selection = {
|
|
776
|
+
isCollapsed(selection) {
|
|
777
|
+
if (selection.anchor[0] == selection.focus[0] && selection.anchor[1] === selection.focus[1]) {
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
|
|
768
786
|
const getHitElements = (board, selection) => {
|
|
769
787
|
const realSelection = selection || board.selection;
|
|
770
788
|
const selectedElements = [];
|
|
789
|
+
const isCollapsed = realSelection && realSelection.ranges.length === 1 && Selection.isCollapsed(realSelection.ranges[0]);
|
|
771
790
|
depthFirstRecursion(board, node => {
|
|
791
|
+
if (selectedElements.length > 0 && isCollapsed) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
772
794
|
if (!PlaitBoard.isBoard(node) &&
|
|
773
795
|
realSelection &&
|
|
774
796
|
realSelection.ranges.some(range => {
|
|
@@ -783,10 +805,16 @@ const getHitElements = (board, selection) => {
|
|
|
783
805
|
else {
|
|
784
806
|
return false;
|
|
785
807
|
}
|
|
786
|
-
});
|
|
808
|
+
}, true);
|
|
787
809
|
return selectedElements;
|
|
788
810
|
};
|
|
789
|
-
const
|
|
811
|
+
const getHitElementOfRoot = (board, rootElements, range) => {
|
|
812
|
+
const newRootElements = [...rootElements].reverse();
|
|
813
|
+
return newRootElements.find(item => {
|
|
814
|
+
return board.isHitSelection(item, range);
|
|
815
|
+
});
|
|
816
|
+
};
|
|
817
|
+
const isHitElements = (board, elements, ranges) => {
|
|
790
818
|
let isIntersectionElements = false;
|
|
791
819
|
if (elements.length) {
|
|
792
820
|
elements.map(item => {
|
|
@@ -919,11 +947,20 @@ function transformPoint(board, point) {
|
|
|
919
947
|
return newPoint;
|
|
920
948
|
}
|
|
921
949
|
function isInPlaitBoard(board, x, y) {
|
|
922
|
-
const plaitBoardElement = PlaitBoard.
|
|
950
|
+
const plaitBoardElement = PlaitBoard.getBoardContainer(board);
|
|
923
951
|
const plaitBoardRect = plaitBoardElement.getBoundingClientRect();
|
|
924
952
|
const distances = distanceBetweenPointAndRectangle(x, y, plaitBoardRect);
|
|
925
953
|
return distances === 0;
|
|
926
954
|
}
|
|
955
|
+
function getRealScrollBarWidth(board) {
|
|
956
|
+
const { hideScrollbar } = board.options;
|
|
957
|
+
let scrollBarWidth = 0;
|
|
958
|
+
if (!hideScrollbar) {
|
|
959
|
+
const viewportContainer = PlaitBoard.getViewportContainer(board);
|
|
960
|
+
scrollBarWidth = viewportContainer.offsetWidth - viewportContainer.clientWidth;
|
|
961
|
+
}
|
|
962
|
+
return scrollBarWidth;
|
|
963
|
+
}
|
|
927
964
|
|
|
928
965
|
function createForeignObject(x, y, width, height) {
|
|
929
966
|
var newForeignObject = document.createElementNS(NS, 'foreignObject');
|
|
@@ -1284,6 +1321,112 @@ const cacheMovingElements = (board, elements) => {
|
|
|
1284
1321
|
BOARD_TO_MOVING_ELEMENT.set(board, elements);
|
|
1285
1322
|
};
|
|
1286
1323
|
|
|
1324
|
+
function cloneCSSStyle(nativeNode, clonedNode) {
|
|
1325
|
+
const targetStyle = clonedNode.style;
|
|
1326
|
+
if (!targetStyle) {
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
const sourceStyle = window.getComputedStyle(nativeNode);
|
|
1330
|
+
if (sourceStyle.cssText) {
|
|
1331
|
+
targetStyle.cssText = sourceStyle.cssText;
|
|
1332
|
+
targetStyle.transformOrigin = sourceStyle.transformOrigin;
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
Array.from(sourceStyle).forEach(name => {
|
|
1336
|
+
let value = sourceStyle.getPropertyValue(name);
|
|
1337
|
+
targetStyle.setProperty(name, value, sourceStyle.getPropertyPriority(name));
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function createCanvas(width, height, fillStyle) {
|
|
1342
|
+
const canvas = document.createElement('canvas');
|
|
1343
|
+
const ctx = canvas.getContext('2d');
|
|
1344
|
+
canvas.width = width;
|
|
1345
|
+
canvas.height = height;
|
|
1346
|
+
canvas.style.width = `${width}px`;
|
|
1347
|
+
canvas.style.height = `${height}px`;
|
|
1348
|
+
ctx.strokeStyle = '#ffffff';
|
|
1349
|
+
ctx.fillStyle = fillStyle;
|
|
1350
|
+
ctx.fillRect(0, 0, width, height);
|
|
1351
|
+
return {
|
|
1352
|
+
canvas,
|
|
1353
|
+
ctx
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
function isElementNode(node) {
|
|
1357
|
+
return node.nodeType === Node.ELEMENT_NODE;
|
|
1358
|
+
}
|
|
1359
|
+
function cloneSvg(board, options) {
|
|
1360
|
+
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1361
|
+
const { width, height, x, y } = elementHostBox;
|
|
1362
|
+
const { padding = 4, inlineStyleClassNames } = options;
|
|
1363
|
+
const sourceSvg = PlaitBoard.getHost(board);
|
|
1364
|
+
const cloneSvgElement = sourceSvg.cloneNode(true);
|
|
1365
|
+
cloneSvgElement.style.width = `${width}px`;
|
|
1366
|
+
cloneSvgElement.style.height = `${height}px`;
|
|
1367
|
+
cloneSvgElement.style.backgroundColor = '';
|
|
1368
|
+
cloneSvgElement.setAttribute('width', `${width}`);
|
|
1369
|
+
cloneSvgElement.setAttribute('height', `${height}`);
|
|
1370
|
+
cloneSvgElement.setAttribute('viewBox', [x - padding, y - padding, width + 2 * padding, height + 2 * padding].join(','));
|
|
1371
|
+
if (inlineStyleClassNames) {
|
|
1372
|
+
const sourceNodes = Array.from(sourceSvg.querySelectorAll(inlineStyleClassNames));
|
|
1373
|
+
const cloneNodes = Array.from(cloneSvgElement.querySelectorAll(inlineStyleClassNames));
|
|
1374
|
+
sourceNodes.forEach((node, index) => {
|
|
1375
|
+
const cloneNode = cloneNodes[index];
|
|
1376
|
+
const childElements = Array.from(node.querySelectorAll('*')).filter(isElementNode);
|
|
1377
|
+
const cloneChildElements = Array.from(cloneNode.querySelectorAll('*')).filter(isElementNode);
|
|
1378
|
+
sourceNodes.push(...childElements);
|
|
1379
|
+
cloneNodes.push(...cloneChildElements);
|
|
1380
|
+
});
|
|
1381
|
+
sourceNodes.forEach((node, index) => {
|
|
1382
|
+
const cloneNode = cloneNodes[index];
|
|
1383
|
+
cloneCSSStyle(node, cloneNode);
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
return cloneSvgElement;
|
|
1387
|
+
}
|
|
1388
|
+
function loadImage(src) {
|
|
1389
|
+
return new Promise((resolve, reject) => {
|
|
1390
|
+
const img = new Image();
|
|
1391
|
+
img.onload = () => resolve(img);
|
|
1392
|
+
img.onerror = () => reject(new Error('Failed to load image'));
|
|
1393
|
+
img.src = src;
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
function toImage(board, options) {
|
|
1397
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1398
|
+
if (!board) {
|
|
1399
|
+
return undefined;
|
|
1400
|
+
}
|
|
1401
|
+
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1402
|
+
const { ratio = 2, fillStyle = 'transparent' } = options;
|
|
1403
|
+
const { width, height } = elementHostBox;
|
|
1404
|
+
const ratioWidth = width * ratio;
|
|
1405
|
+
const ratioHeight = height * ratio;
|
|
1406
|
+
const cloneSvgElement = cloneSvg(board, options);
|
|
1407
|
+
const { canvas, ctx } = createCanvas(ratioWidth, ratioHeight, fillStyle);
|
|
1408
|
+
const svgStr = new XMLSerializer().serializeToString(cloneSvgElement);
|
|
1409
|
+
const imgSrc = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgStr)}`;
|
|
1410
|
+
try {
|
|
1411
|
+
const img = yield loadImage(imgSrc);
|
|
1412
|
+
ctx.drawImage(img, 0, 0, ratioWidth, ratioHeight);
|
|
1413
|
+
const url = canvas.toDataURL('image/png');
|
|
1414
|
+
return url;
|
|
1415
|
+
}
|
|
1416
|
+
catch (error) {
|
|
1417
|
+
console.error('Error converting SVG to image:', error);
|
|
1418
|
+
return undefined;
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
function downloadImage(url, name) {
|
|
1423
|
+
const a = document.createElement('a');
|
|
1424
|
+
a.href = url;
|
|
1425
|
+
a.download = name;
|
|
1426
|
+
a.click();
|
|
1427
|
+
a.remove();
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1287
1430
|
const PlaitElement = {
|
|
1288
1431
|
isRootElement(value) {
|
|
1289
1432
|
const parent = NODE_TO_PARENT.get(value);
|
|
@@ -1416,19 +1559,6 @@ const Point = {
|
|
|
1416
1559
|
}
|
|
1417
1560
|
};
|
|
1418
1561
|
|
|
1419
|
-
const SELECTION_BORDER_COLOR = '#6698FF';
|
|
1420
|
-
const SELECTION_FILL_COLOR = '#6698FF19'; // 主色 0.1 透明度
|
|
1421
|
-
const Selection = {
|
|
1422
|
-
isCollapsed(selection) {
|
|
1423
|
-
if (selection.anchor[0] == selection.focus[0] && selection.anchor[1] === selection.focus[1]) {
|
|
1424
|
-
return true;
|
|
1425
|
-
}
|
|
1426
|
-
else {
|
|
1427
|
-
return false;
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
};
|
|
1431
|
-
|
|
1432
1562
|
const SAVING = new WeakMap();
|
|
1433
1563
|
const MERGING = new WeakMap();
|
|
1434
1564
|
|
|
@@ -1442,7 +1572,7 @@ const IS_FROM_VIEWPORT_CHANGE = new WeakMap();
|
|
|
1442
1572
|
function getViewportContainerRect(board) {
|
|
1443
1573
|
const { hideScrollbar } = board.options;
|
|
1444
1574
|
const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
1445
|
-
const viewportRect = PlaitBoard.
|
|
1575
|
+
const viewportRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1446
1576
|
return {
|
|
1447
1577
|
width: viewportRect.width + scrollBarWidth,
|
|
1448
1578
|
height: viewportRect.height + scrollBarWidth
|
|
@@ -1450,7 +1580,7 @@ function getViewportContainerRect(board) {
|
|
|
1450
1580
|
}
|
|
1451
1581
|
function getElementHostBBox(board, zoom) {
|
|
1452
1582
|
const childrenRect = getRectangleByElements(board, board.children, true);
|
|
1453
|
-
const viewportContainerRect = PlaitBoard.
|
|
1583
|
+
const viewportContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1454
1584
|
const containerWidth = viewportContainerRect.width / zoom;
|
|
1455
1585
|
const containerHeight = viewportContainerRect.height / zoom;
|
|
1456
1586
|
let left;
|
|
@@ -1495,7 +1625,7 @@ function clampZoomLevel(zoom, minZoom = 0.2, maxZoom = 4) {
|
|
|
1495
1625
|
return zoom < minZoom ? minZoom : zoom > maxZoom ? maxZoom : zoom;
|
|
1496
1626
|
}
|
|
1497
1627
|
function getViewBox(board, zoom) {
|
|
1498
|
-
const boardContainerRectangle = PlaitBoard.
|
|
1628
|
+
const boardContainerRectangle = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1499
1629
|
const elementHostBBox = getElementHostBBox(board, zoom);
|
|
1500
1630
|
const horizontalPadding = boardContainerRectangle.width / 2;
|
|
1501
1631
|
const verticalPadding = boardContainerRectangle.height / 2;
|
|
@@ -1507,6 +1637,10 @@ function getViewBox(board, zoom) {
|
|
|
1507
1637
|
];
|
|
1508
1638
|
return viewBox;
|
|
1509
1639
|
}
|
|
1640
|
+
function getViewBoxCenterPoint(board) {
|
|
1641
|
+
const childrenRectangle = getRectangleByElements(board, board.children, true);
|
|
1642
|
+
return [childrenRectangle.x + childrenRectangle.width / 2, childrenRectangle.y + childrenRectangle.height / 2];
|
|
1643
|
+
}
|
|
1510
1644
|
function setSVGViewBox(board, viewBox) {
|
|
1511
1645
|
const zoom = board.viewport.zoom;
|
|
1512
1646
|
const hostElement = PlaitBoard.getHost(board);
|
|
@@ -1550,7 +1684,7 @@ function initializeViewportOffset(board) {
|
|
|
1550
1684
|
var _a;
|
|
1551
1685
|
if (!((_a = board.viewport) === null || _a === void 0 ? void 0 : _a.origination)) {
|
|
1552
1686
|
const zoom = board.viewport.zoom;
|
|
1553
|
-
const viewportContainerRect = PlaitBoard.
|
|
1687
|
+
const viewportContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1554
1688
|
const viewBox = getViewBox(board, zoom);
|
|
1555
1689
|
const centerX = viewBox[0] + viewBox[2] / 2;
|
|
1556
1690
|
const centerY = viewBox[1] + viewBox[3] / 2;
|
|
@@ -1612,9 +1746,9 @@ const updatePointerType = (board, pointer) => {
|
|
|
1612
1746
|
function updateZoom(board, newZoom, isCenter = true) {
|
|
1613
1747
|
newZoom = clampZoomLevel(newZoom);
|
|
1614
1748
|
const mousePoint = PlaitBoard.getMovingPoint(board);
|
|
1615
|
-
const nativeElement = PlaitBoard.
|
|
1749
|
+
const nativeElement = PlaitBoard.getBoardContainer(board);
|
|
1616
1750
|
const nativeElementRect = nativeElement.getBoundingClientRect();
|
|
1617
|
-
const boardContainerRect = PlaitBoard.
|
|
1751
|
+
const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1618
1752
|
let focusPoint = [boardContainerRect.width / 2, boardContainerRect.height / 2];
|
|
1619
1753
|
if (!isCenter && mousePoint && distanceBetweenPointAndRectangle(mousePoint[0], mousePoint[1], nativeElementRect) === 0) {
|
|
1620
1754
|
focusPoint = toPoint(mousePoint[0], mousePoint[1], nativeElement);
|
|
@@ -1627,13 +1761,8 @@ function updateZoom(board, newZoom, isCenter = true) {
|
|
|
1627
1761
|
updateViewport(board, newOrigination, newZoom);
|
|
1628
1762
|
}
|
|
1629
1763
|
function fitViewport(board) {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
if (!hideScrollbar) {
|
|
1633
|
-
const viewportContainer = PlaitBoard.getViewportContainer(board);
|
|
1634
|
-
scrollBarWidth = viewportContainer.offsetWidth - viewportContainer.clientWidth;
|
|
1635
|
-
}
|
|
1636
|
-
const boardContainerRect = PlaitBoard.getBoardNativeElement(board).getBoundingClientRect();
|
|
1764
|
+
let scrollBarWidth = getRealScrollBarWidth(board);
|
|
1765
|
+
const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1637
1766
|
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1638
1767
|
const zoom = board.viewport.zoom;
|
|
1639
1768
|
const autoFitPadding = 16;
|
|
@@ -1646,12 +1775,47 @@ function fitViewport(board) {
|
|
|
1646
1775
|
else {
|
|
1647
1776
|
newZoom = 1;
|
|
1648
1777
|
}
|
|
1649
|
-
const
|
|
1650
|
-
const centerX = viewBox[0] + viewBox[2] / 2;
|
|
1651
|
-
const centerY = viewBox[1] + viewBox[3] / 2;
|
|
1778
|
+
const centerPoint = getViewBoxCenterPoint(board);
|
|
1652
1779
|
const newOrigination = [
|
|
1653
|
-
|
|
1654
|
-
|
|
1780
|
+
centerPoint[0] - boardContainerRect.width / 2 / newZoom + scrollBarWidth / 2 / zoom,
|
|
1781
|
+
centerPoint[1] - boardContainerRect.height / 2 / newZoom + scrollBarWidth / 2 / zoom
|
|
1782
|
+
];
|
|
1783
|
+
updateViewport(board, newOrigination, newZoom);
|
|
1784
|
+
}
|
|
1785
|
+
function fitViewportWidth(board, options) {
|
|
1786
|
+
let scrollBarWidth = getRealScrollBarWidth(board);
|
|
1787
|
+
const boardContainer = PlaitBoard.getBoardContainer(board);
|
|
1788
|
+
const boardContainerRectangle = boardContainer.getBoundingClientRect();
|
|
1789
|
+
let finalWidth = 0;
|
|
1790
|
+
if (options.maxWidth) {
|
|
1791
|
+
finalWidth = options.maxWidth;
|
|
1792
|
+
}
|
|
1793
|
+
else {
|
|
1794
|
+
finalWidth = boardContainerRectangle.width;
|
|
1795
|
+
}
|
|
1796
|
+
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1797
|
+
const contentWidth = finalWidth - 2 * options.autoFitPadding;
|
|
1798
|
+
let newZoom = 0;
|
|
1799
|
+
if (contentWidth < elementHostBox.width) {
|
|
1800
|
+
newZoom = Math.min(contentWidth / elementHostBox.width);
|
|
1801
|
+
}
|
|
1802
|
+
else {
|
|
1803
|
+
newZoom = 1;
|
|
1804
|
+
}
|
|
1805
|
+
let finalHeight = elementHostBox.height * newZoom + 2 * options.autoFitPadding;
|
|
1806
|
+
if (finalHeight > options.limitHeight) {
|
|
1807
|
+
const containerEl = boardContainer.closest(`.${options.containerClass}`);
|
|
1808
|
+
containerEl.style.height = `${finalHeight}px`;
|
|
1809
|
+
initializeViewportContainer(board);
|
|
1810
|
+
}
|
|
1811
|
+
else {
|
|
1812
|
+
finalHeight = options.limitHeight;
|
|
1813
|
+
}
|
|
1814
|
+
const centerX = elementHostBox.x + elementHostBox.width / 2;
|
|
1815
|
+
const centerY = elementHostBox.y + elementHostBox.height / 2;
|
|
1816
|
+
const newOrigination = [
|
|
1817
|
+
centerX - finalWidth / 2 / newZoom + scrollBarWidth / 2 / newZoom,
|
|
1818
|
+
centerY - finalHeight / 2 / newZoom + scrollBarWidth / 2 / newZoom
|
|
1655
1819
|
];
|
|
1656
1820
|
updateViewport(board, newOrigination, newZoom);
|
|
1657
1821
|
}
|
|
@@ -1671,7 +1835,8 @@ const BoardTransforms = {
|
|
|
1671
1835
|
updateViewport,
|
|
1672
1836
|
fitViewport,
|
|
1673
1837
|
updateZoom,
|
|
1674
|
-
updateThemeColor
|
|
1838
|
+
updateThemeColor,
|
|
1839
|
+
fitViewportWidth
|
|
1675
1840
|
};
|
|
1676
1841
|
|
|
1677
1842
|
const Transforms = Object.assign(Object.assign(Object.assign(Object.assign({}, GeneralTransforms), ViewportTransforms$1), SelectionTransforms), NodeTransforms);
|
|
@@ -1883,7 +2048,7 @@ function withHandPointer(board) {
|
|
|
1883
2048
|
board.mousedown = (event) => {
|
|
1884
2049
|
if (PlaitBoard.isPointer(board, PlaitPointerType.hand) && isMainPointer(event)) {
|
|
1885
2050
|
isMoving = true;
|
|
1886
|
-
PlaitBoard.
|
|
2051
|
+
PlaitBoard.getBoardContainer(board).classList.add('viewport-moving');
|
|
1887
2052
|
plaitBoardMove.x = event.x;
|
|
1888
2053
|
plaitBoardMove.y = event.y;
|
|
1889
2054
|
}
|
|
@@ -1903,7 +2068,7 @@ function withHandPointer(board) {
|
|
|
1903
2068
|
board.globalMouseup = (event) => {
|
|
1904
2069
|
if (board.selection) {
|
|
1905
2070
|
isMoving = false;
|
|
1906
|
-
PlaitBoard.
|
|
2071
|
+
PlaitBoard.getBoardContainer(board).classList.remove('viewport-moving');
|
|
1907
2072
|
plaitBoardMove.x = 0;
|
|
1908
2073
|
plaitBoardMove.y = 0;
|
|
1909
2074
|
}
|
|
@@ -1943,14 +2108,13 @@ function withSelection(board) {
|
|
|
1943
2108
|
}
|
|
1944
2109
|
const options = board.getPluginOptions(PlaitPluginKey.withSelection);
|
|
1945
2110
|
const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
1946
|
-
const
|
|
2111
|
+
const range = { anchor: point, focus: point };
|
|
2112
|
+
const hitElements = getHitElements(board, { ranges: [range] });
|
|
1947
2113
|
const selectedElements = getSelectedElements(board);
|
|
1948
|
-
if (
|
|
2114
|
+
if (hitElements.length === 1 && selectedElements.includes(hitElements[0])) {
|
|
1949
2115
|
mousedown(event);
|
|
1950
2116
|
return;
|
|
1951
2117
|
}
|
|
1952
|
-
const range = { anchor: point, focus: point };
|
|
1953
|
-
const hitElements = getHitElements(board, { ranges: [range] });
|
|
1954
2118
|
if (PlaitBoard.isPointer(board, PlaitPointerType.selection) &&
|
|
1955
2119
|
hitElements.length === 0 &&
|
|
1956
2120
|
options.isMultiple &&
|
|
@@ -1961,7 +2125,7 @@ function withSelection(board) {
|
|
|
1961
2125
|
// prevent text from being selected
|
|
1962
2126
|
event.preventDefault();
|
|
1963
2127
|
}
|
|
1964
|
-
Transforms.setSelection(board, { ranges:
|
|
2128
|
+
Transforms.setSelection(board, { ranges: [range] });
|
|
1965
2129
|
mousedown(event);
|
|
1966
2130
|
};
|
|
1967
2131
|
board.globalMousemove = (event) => {
|
|
@@ -1996,7 +2160,7 @@ function withSelection(board) {
|
|
|
1996
2160
|
Transforms.setSelection(board, { ranges: [{ anchor: start, focus: end }] });
|
|
1997
2161
|
}
|
|
1998
2162
|
if (PlaitBoard.isFocus(board)) {
|
|
1999
|
-
const isInBoard = event.target instanceof Node && PlaitBoard.
|
|
2163
|
+
const isInBoard = event.target instanceof Node && PlaitBoard.getBoardContainer(board).contains(event.target);
|
|
2000
2164
|
const isInDocument = event.target instanceof Node && document.contains(event.target);
|
|
2001
2165
|
const isAttachedElement = event.target instanceof Element && event.target.closest(`.${ATTACHED_ELEMENT_CLASS_NAME}`);
|
|
2002
2166
|
// Clear selection when mouse board outside area
|
|
@@ -2072,11 +2236,11 @@ function isSelectionMoving(board) {
|
|
|
2072
2236
|
return !!BOARD_TO_IS_SELECTION_MOVING.get(board);
|
|
2073
2237
|
}
|
|
2074
2238
|
function setSelectionMoving(board) {
|
|
2075
|
-
PlaitBoard.
|
|
2239
|
+
PlaitBoard.getBoardContainer(board).classList.add('selection-moving');
|
|
2076
2240
|
BOARD_TO_IS_SELECTION_MOVING.set(board, true);
|
|
2077
2241
|
}
|
|
2078
2242
|
function clearSelectionMoving(board) {
|
|
2079
|
-
PlaitBoard.
|
|
2243
|
+
PlaitBoard.getBoardContainer(board).classList.remove('selection-moving');
|
|
2080
2244
|
BOARD_TO_IS_SELECTION_MOVING.delete(board);
|
|
2081
2245
|
}
|
|
2082
2246
|
function createSelectionOuterG(board, selectElements) {
|
|
@@ -2127,19 +2291,17 @@ function withMoving(board) {
|
|
|
2127
2291
|
board.mousedown = event => {
|
|
2128
2292
|
const host = BOARD_TO_HOST.get(board);
|
|
2129
2293
|
const point = transformPoint(board, toPoint(event.x, event.y, host));
|
|
2130
|
-
const
|
|
2294
|
+
const range = { anchor: point, focus: point };
|
|
2131
2295
|
let movableElements = board.children.filter(item => board.isMovable(item));
|
|
2132
2296
|
if (movableElements.length) {
|
|
2133
2297
|
startPoint = point;
|
|
2134
2298
|
const selectedRootElements = getSelectedElements(board).filter(item => movableElements.includes(item));
|
|
2135
|
-
const
|
|
2136
|
-
if (
|
|
2299
|
+
const hitElement = getHitElementOfRoot(board, movableElements, range);
|
|
2300
|
+
if (hitElement && selectedRootElements.includes(hitElement)) {
|
|
2137
2301
|
activeElements = selectedRootElements;
|
|
2138
2302
|
}
|
|
2139
|
-
else {
|
|
2140
|
-
activeElements =
|
|
2141
|
-
return board.isHitSelection(item, range);
|
|
2142
|
-
}));
|
|
2303
|
+
else if (hitElement) {
|
|
2304
|
+
activeElements = [hitElement];
|
|
2143
2305
|
}
|
|
2144
2306
|
}
|
|
2145
2307
|
mousedown(event);
|
|
@@ -2165,7 +2327,7 @@ function withMoving(board) {
|
|
|
2165
2327
|
MERGING.set(board, true);
|
|
2166
2328
|
return PlaitNode.get(board, [index]);
|
|
2167
2329
|
});
|
|
2168
|
-
PlaitBoard.
|
|
2330
|
+
PlaitBoard.getBoardContainer(board).classList.add('element-moving');
|
|
2169
2331
|
addMovingElements(board, currentElements);
|
|
2170
2332
|
});
|
|
2171
2333
|
}
|
|
@@ -2199,7 +2361,7 @@ function withMoving(board) {
|
|
|
2199
2361
|
activeElements = [];
|
|
2200
2362
|
removeMovingElements(board);
|
|
2201
2363
|
MERGING.set(board, false);
|
|
2202
|
-
PlaitBoard.
|
|
2364
|
+
PlaitBoard.getBoardContainer(board).classList.remove('element-moving');
|
|
2203
2365
|
}
|
|
2204
2366
|
return board;
|
|
2205
2367
|
}
|
|
@@ -2774,5 +2936,5 @@ const clearNodeWeakMap = (object) => {
|
|
|
2774
2936
|
* Generated bundle index. Do not edit.
|
|
2775
2937
|
*/
|
|
2776
2938
|
|
|
2777
|
-
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ColorfulThemeColor, DarkThemeColor, DefaultThemeColor, ELEMENT_TO_COMPONENT, FLUSHING, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NODE_TO_INDEX, NODE_TO_PARENT, NS, PATH_REFS, POINTER_BUTTON, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, RectangleClient, RetroThemeColor, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, SoftThemeColor, StarryThemeColor, ThemeColorMode, ThemeColors, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createForeignObject, createG, createPath, createSVG, createSelectionOuterG, createTestingBoard, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawLinearPath, drawRoundRectangle, fakeNodeWeakMap, getBoardRectangle, getElementHostBBox, getHitElements, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange,
|
|
2939
|
+
export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ColorfulThemeColor, DarkThemeColor, DefaultThemeColor, ELEMENT_TO_COMPONENT, FLUSHING, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NODE_TO_INDEX, NODE_TO_PARENT, NS, PATH_REFS, POINTER_BUTTON, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, RectangleClient, RetroThemeColor, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, SoftThemeColor, StarryThemeColor, ThemeColorMode, ThemeColors, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createForeignObject, createG, createPath, createSVG, createSelectionOuterG, createTestingBoard, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, downloadImage, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawLinearPath, drawRoundRectangle, fakeNodeWeakMap, getBoardRectangle, getElementHostBBox, getHitElementOfRoot, getHitElements, getMovingElements, getRealScrollBarWidth, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewBoxCenterPoint, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange, isHitElements, isInPlaitBoard, isMainPointer, isNullOrUndefined, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, shouldClear, shouldMerge, shouldSave, throttleRAF, toImage, toPoint, transformPoint, transformPoints, updateForeignObject, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
|
|
2778
2940
|
//# sourceMappingURL=plait-core.mjs.map
|