@plait/core 0.33.0 → 0.35.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/board/board.component.d.ts +1 -0
- package/constants/zoom.d.ts +3 -0
- package/esm2022/board/board.component.mjs +49 -31
- package/esm2022/constants/zoom.mjs +4 -0
- package/esm2022/utils/viewport.mjs +34 -5
- package/fesm2022/plait-core.mjs +207 -158
- package/fesm2022/plait-core.mjs.map +1 -1
- package/package.json +1 -1
- package/utils/viewport.d.ts +1 -0
package/fesm2022/plait-core.mjs
CHANGED
|
@@ -1142,6 +1142,136 @@ function drawBezierPath(points, options) {
|
|
|
1142
1142
|
return g;
|
|
1143
1143
|
}
|
|
1144
1144
|
|
|
1145
|
+
const ZOOM_STEP = 0.1;
|
|
1146
|
+
const MIN_ZOOM = 0.1;
|
|
1147
|
+
const MAX_ZOOM = 4;
|
|
1148
|
+
|
|
1149
|
+
function setViewport(board, viewport) {
|
|
1150
|
+
const operation = { type: 'set_viewport', properties: board.viewport, newProperties: viewport };
|
|
1151
|
+
board.apply(operation);
|
|
1152
|
+
}
|
|
1153
|
+
const ViewportTransforms$1 = {
|
|
1154
|
+
setViewport
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1157
|
+
function setTheme(board, themeColorMode) {
|
|
1158
|
+
const operation = { type: 'set_theme', properties: board.theme, newProperties: themeColorMode };
|
|
1159
|
+
board.apply(operation);
|
|
1160
|
+
}
|
|
1161
|
+
const ViewportTransforms = {
|
|
1162
|
+
setTheme
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
function updateViewport(board, origination, zoom) {
|
|
1166
|
+
zoom = zoom ?? board.viewport.zoom;
|
|
1167
|
+
setViewport(board, {
|
|
1168
|
+
...board.viewport,
|
|
1169
|
+
zoom,
|
|
1170
|
+
origination
|
|
1171
|
+
});
|
|
1172
|
+
clearViewportOrigination(board);
|
|
1173
|
+
}
|
|
1174
|
+
const updatePointerType = (board, pointer) => {
|
|
1175
|
+
board.pointer = pointer;
|
|
1176
|
+
const boardComponent = BOARD_TO_COMPONENT.get(board);
|
|
1177
|
+
boardComponent?.markForCheck();
|
|
1178
|
+
};
|
|
1179
|
+
function updateZoom(board, newZoom, isCenter = true) {
|
|
1180
|
+
newZoom = clampZoomLevel(newZoom);
|
|
1181
|
+
const mousePoint = PlaitBoard.getMovingPointInBoard(board);
|
|
1182
|
+
const nativeElement = PlaitBoard.getBoardContainer(board);
|
|
1183
|
+
const nativeElementRect = nativeElement.getBoundingClientRect();
|
|
1184
|
+
const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1185
|
+
let focusPoint = [boardContainerRect.width / 2, boardContainerRect.height / 2];
|
|
1186
|
+
if (!isCenter && mousePoint && distanceBetweenPointAndRectangle(mousePoint[0], mousePoint[1], nativeElementRect) === 0) {
|
|
1187
|
+
focusPoint = toPoint(mousePoint[0], mousePoint[1], nativeElement);
|
|
1188
|
+
}
|
|
1189
|
+
const zoom = board.viewport.zoom;
|
|
1190
|
+
const origination = getViewportOrigination(board);
|
|
1191
|
+
const centerX = origination[0] + focusPoint[0] / zoom;
|
|
1192
|
+
const centerY = origination[1] + focusPoint[1] / zoom;
|
|
1193
|
+
const newOrigination = [centerX - focusPoint[0] / newZoom, centerY - focusPoint[1] / newZoom];
|
|
1194
|
+
updateViewport(board, newOrigination, newZoom);
|
|
1195
|
+
}
|
|
1196
|
+
function fitViewport(board) {
|
|
1197
|
+
let scrollBarWidth = getRealScrollBarWidth(board);
|
|
1198
|
+
const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
1199
|
+
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1200
|
+
const zoom = board.viewport.zoom;
|
|
1201
|
+
const autoFitPadding = 16;
|
|
1202
|
+
const viewportWidth = boardContainerRect.width - 2 * autoFitPadding;
|
|
1203
|
+
const viewportHeight = boardContainerRect.height - 2 * autoFitPadding;
|
|
1204
|
+
let newZoom = zoom;
|
|
1205
|
+
if (viewportWidth < elementHostBox.width || viewportHeight < elementHostBox.height) {
|
|
1206
|
+
newZoom = Math.min(viewportWidth / elementHostBox.width, viewportHeight / elementHostBox.height);
|
|
1207
|
+
}
|
|
1208
|
+
else {
|
|
1209
|
+
newZoom = 1;
|
|
1210
|
+
}
|
|
1211
|
+
const centerPoint = getViewBoxCenterPoint(board);
|
|
1212
|
+
const newOrigination = [
|
|
1213
|
+
centerPoint[0] - boardContainerRect.width / 2 / newZoom + scrollBarWidth / 2 / zoom,
|
|
1214
|
+
centerPoint[1] - boardContainerRect.height / 2 / newZoom + scrollBarWidth / 2 / zoom
|
|
1215
|
+
];
|
|
1216
|
+
updateViewport(board, newOrigination, newZoom);
|
|
1217
|
+
}
|
|
1218
|
+
function fitViewportWidth(board, options) {
|
|
1219
|
+
let scrollBarWidth = getRealScrollBarWidth(board);
|
|
1220
|
+
const boardContainer = PlaitBoard.getBoardContainer(board);
|
|
1221
|
+
const boardContainerRectangle = boardContainer.getBoundingClientRect();
|
|
1222
|
+
let finalWidth = 0;
|
|
1223
|
+
if (options.maxWidth) {
|
|
1224
|
+
finalWidth = options.maxWidth;
|
|
1225
|
+
}
|
|
1226
|
+
else {
|
|
1227
|
+
finalWidth = boardContainerRectangle.width;
|
|
1228
|
+
}
|
|
1229
|
+
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
1230
|
+
const contentWidth = finalWidth - 2 * options.autoFitPadding;
|
|
1231
|
+
let newZoom = 0;
|
|
1232
|
+
if (contentWidth < elementHostBox.width) {
|
|
1233
|
+
newZoom = Math.min(contentWidth / elementHostBox.width);
|
|
1234
|
+
}
|
|
1235
|
+
else {
|
|
1236
|
+
newZoom = 1;
|
|
1237
|
+
}
|
|
1238
|
+
let finalHeight = elementHostBox.height * newZoom + 2 * options.autoFitPadding;
|
|
1239
|
+
if (finalHeight > options.limitHeight) {
|
|
1240
|
+
const containerEl = boardContainer.closest(`.${options.containerClass}`);
|
|
1241
|
+
containerEl.style.height = `${finalHeight}px`;
|
|
1242
|
+
initializeViewportContainer(board);
|
|
1243
|
+
}
|
|
1244
|
+
else {
|
|
1245
|
+
finalHeight = options.limitHeight;
|
|
1246
|
+
}
|
|
1247
|
+
const centerX = elementHostBox.x + elementHostBox.width / 2;
|
|
1248
|
+
const centerY = elementHostBox.y + elementHostBox.height / 2;
|
|
1249
|
+
const newOrigination = [
|
|
1250
|
+
centerX - finalWidth / 2 / newZoom + scrollBarWidth / 2 / newZoom,
|
|
1251
|
+
centerY - finalHeight / 2 / newZoom + scrollBarWidth / 2 / newZoom
|
|
1252
|
+
];
|
|
1253
|
+
updateViewport(board, newOrigination, newZoom);
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* apply theme to every element (remove element custom properties)
|
|
1257
|
+
* invoke applyThemeColor
|
|
1258
|
+
*/
|
|
1259
|
+
function updateThemeColor(board, mode) {
|
|
1260
|
+
mode = mode ?? board.theme.themeColorMode;
|
|
1261
|
+
setTheme(board, { themeColorMode: mode });
|
|
1262
|
+
depthFirstRecursion(board, element => {
|
|
1263
|
+
board.applyTheme(element);
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
const BoardTransforms = {
|
|
1267
|
+
updatePointerType,
|
|
1268
|
+
updateViewport,
|
|
1269
|
+
fitViewport,
|
|
1270
|
+
updateZoom,
|
|
1271
|
+
updateThemeColor,
|
|
1272
|
+
fitViewportWidth
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1145
1275
|
const IS_FROM_SCROLLING = new WeakMap();
|
|
1146
1276
|
const IS_FROM_VIEWPORT_CHANGE = new WeakMap();
|
|
1147
1277
|
function getViewportContainerRect(board) {
|
|
@@ -1196,7 +1326,7 @@ function getElementHostBBox(board, zoom) {
|
|
|
1196
1326
|
* @param maxZoom 最大缩放比
|
|
1197
1327
|
* @returns 正确的缩放比
|
|
1198
1328
|
*/
|
|
1199
|
-
function clampZoomLevel(zoom, minZoom =
|
|
1329
|
+
function clampZoomLevel(zoom, minZoom = MIN_ZOOM, maxZoom = MAX_ZOOM) {
|
|
1200
1330
|
return zoom < minZoom ? minZoom : zoom > maxZoom ? maxZoom : zoom;
|
|
1201
1331
|
}
|
|
1202
1332
|
function getViewBox(board, zoom) {
|
|
@@ -1228,8 +1358,9 @@ function setSVGViewBox(board, viewBox) {
|
|
|
1228
1358
|
}
|
|
1229
1359
|
function updateViewportOffset(board) {
|
|
1230
1360
|
const origination = getViewportOrigination(board);
|
|
1231
|
-
if (!origination)
|
|
1361
|
+
if (!origination) {
|
|
1232
1362
|
return;
|
|
1363
|
+
}
|
|
1233
1364
|
const { zoom } = board.viewport;
|
|
1234
1365
|
const viewBox = getViewBox(board, zoom);
|
|
1235
1366
|
const scrollLeft = (origination[0] - viewBox[0]) * zoom;
|
|
@@ -1238,12 +1369,38 @@ function updateViewportOffset(board) {
|
|
|
1238
1369
|
}
|
|
1239
1370
|
function updateViewportContainerScroll(board, left, top, isFromViewportChange = true) {
|
|
1240
1371
|
const viewportContainer = PlaitBoard.getViewportContainer(board);
|
|
1372
|
+
const previousScrollLeft = viewportContainer.scrollLeft;
|
|
1373
|
+
const previousScrollTop = viewportContainer.scrollTop;
|
|
1241
1374
|
if (viewportContainer.scrollLeft !== left || viewportContainer.scrollTop !== top) {
|
|
1242
1375
|
viewportContainer.scrollLeft = left;
|
|
1243
1376
|
viewportContainer.scrollTop = top;
|
|
1244
|
-
|
|
1377
|
+
const offsetWidth = viewportContainer.offsetWidth;
|
|
1378
|
+
const offsetHeight = viewportContainer.offsetHeight;
|
|
1379
|
+
if (previousScrollLeft === viewportContainer.scrollLeft && previousScrollTop === viewportContainer.scrollTop) {
|
|
1380
|
+
// The scroll event cannot be triggered, so the origination is modified directly based on the scroll distance.
|
|
1381
|
+
updateViewportByScrolling(board, previousScrollLeft, previousScrollTop);
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
const isValidLeftOrTop = left > 0 &&
|
|
1385
|
+
top > 0 &&
|
|
1386
|
+
left < viewportContainer.scrollWidth - offsetWidth &&
|
|
1387
|
+
top < viewportContainer.scrollHeight - offsetHeight;
|
|
1388
|
+
if (isFromViewportChange && isValidLeftOrTop) {
|
|
1389
|
+
setIsFromViewportChange(board, true);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1245
1392
|
}
|
|
1246
1393
|
}
|
|
1394
|
+
function updateViewportByScrolling(board, scrollLeft, scrollTop) {
|
|
1395
|
+
const zoom = board.viewport.zoom;
|
|
1396
|
+
const viewBox = getViewBox(board, zoom);
|
|
1397
|
+
const origination = [scrollLeft / zoom + viewBox[0], scrollTop / zoom + viewBox[1]];
|
|
1398
|
+
if (Point.isEquals(origination, board.viewport.origination)) {
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
BoardTransforms.updateViewport(board, origination);
|
|
1402
|
+
setIsFromScrolling(board, true);
|
|
1403
|
+
}
|
|
1247
1404
|
function initializeViewportContainer(board) {
|
|
1248
1405
|
const { width, height } = getViewportContainerRect(board);
|
|
1249
1406
|
const viewportContainer = PlaitBoard.getViewportContainer(board);
|
|
@@ -2555,132 +2712,6 @@ function addSelectionWithTemporaryElements(board, elements) {
|
|
|
2555
2712
|
}
|
|
2556
2713
|
}
|
|
2557
2714
|
|
|
2558
|
-
function setViewport(board, viewport) {
|
|
2559
|
-
const operation = { type: 'set_viewport', properties: board.viewport, newProperties: viewport };
|
|
2560
|
-
board.apply(operation);
|
|
2561
|
-
}
|
|
2562
|
-
const ViewportTransforms$1 = {
|
|
2563
|
-
setViewport
|
|
2564
|
-
};
|
|
2565
|
-
|
|
2566
|
-
function setTheme(board, themeColorMode) {
|
|
2567
|
-
const operation = { type: 'set_theme', properties: board.theme, newProperties: themeColorMode };
|
|
2568
|
-
board.apply(operation);
|
|
2569
|
-
}
|
|
2570
|
-
const ViewportTransforms = {
|
|
2571
|
-
setTheme
|
|
2572
|
-
};
|
|
2573
|
-
|
|
2574
|
-
function updateViewport(board, origination, zoom) {
|
|
2575
|
-
zoom = zoom ?? board.viewport.zoom;
|
|
2576
|
-
setViewport(board, {
|
|
2577
|
-
...board.viewport,
|
|
2578
|
-
zoom,
|
|
2579
|
-
origination
|
|
2580
|
-
});
|
|
2581
|
-
clearViewportOrigination(board);
|
|
2582
|
-
}
|
|
2583
|
-
const updatePointerType = (board, pointer) => {
|
|
2584
|
-
board.pointer = pointer;
|
|
2585
|
-
const boardComponent = BOARD_TO_COMPONENT.get(board);
|
|
2586
|
-
boardComponent?.markForCheck();
|
|
2587
|
-
};
|
|
2588
|
-
function updateZoom(board, newZoom, isCenter = true) {
|
|
2589
|
-
newZoom = clampZoomLevel(newZoom);
|
|
2590
|
-
const mousePoint = PlaitBoard.getMovingPointInBoard(board);
|
|
2591
|
-
const nativeElement = PlaitBoard.getBoardContainer(board);
|
|
2592
|
-
const nativeElementRect = nativeElement.getBoundingClientRect();
|
|
2593
|
-
const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
2594
|
-
let focusPoint = [boardContainerRect.width / 2, boardContainerRect.height / 2];
|
|
2595
|
-
if (!isCenter && mousePoint && distanceBetweenPointAndRectangle(mousePoint[0], mousePoint[1], nativeElementRect) === 0) {
|
|
2596
|
-
focusPoint = toPoint(mousePoint[0], mousePoint[1], nativeElement);
|
|
2597
|
-
}
|
|
2598
|
-
const zoom = board.viewport.zoom;
|
|
2599
|
-
const origination = getViewportOrigination(board);
|
|
2600
|
-
const centerX = origination[0] + focusPoint[0] / zoom;
|
|
2601
|
-
const centerY = origination[1] + focusPoint[1] / zoom;
|
|
2602
|
-
const newOrigination = [centerX - focusPoint[0] / newZoom, centerY - focusPoint[1] / newZoom];
|
|
2603
|
-
updateViewport(board, newOrigination, newZoom);
|
|
2604
|
-
}
|
|
2605
|
-
function fitViewport(board) {
|
|
2606
|
-
let scrollBarWidth = getRealScrollBarWidth(board);
|
|
2607
|
-
const boardContainerRect = PlaitBoard.getBoardContainer(board).getBoundingClientRect();
|
|
2608
|
-
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
2609
|
-
const zoom = board.viewport.zoom;
|
|
2610
|
-
const autoFitPadding = 16;
|
|
2611
|
-
const viewportWidth = boardContainerRect.width - 2 * autoFitPadding;
|
|
2612
|
-
const viewportHeight = boardContainerRect.height - 2 * autoFitPadding;
|
|
2613
|
-
let newZoom = zoom;
|
|
2614
|
-
if (viewportWidth < elementHostBox.width || viewportHeight < elementHostBox.height) {
|
|
2615
|
-
newZoom = Math.min(viewportWidth / elementHostBox.width, viewportHeight / elementHostBox.height);
|
|
2616
|
-
}
|
|
2617
|
-
else {
|
|
2618
|
-
newZoom = 1;
|
|
2619
|
-
}
|
|
2620
|
-
const centerPoint = getViewBoxCenterPoint(board);
|
|
2621
|
-
const newOrigination = [
|
|
2622
|
-
centerPoint[0] - boardContainerRect.width / 2 / newZoom + scrollBarWidth / 2 / zoom,
|
|
2623
|
-
centerPoint[1] - boardContainerRect.height / 2 / newZoom + scrollBarWidth / 2 / zoom
|
|
2624
|
-
];
|
|
2625
|
-
updateViewport(board, newOrigination, newZoom);
|
|
2626
|
-
}
|
|
2627
|
-
function fitViewportWidth(board, options) {
|
|
2628
|
-
let scrollBarWidth = getRealScrollBarWidth(board);
|
|
2629
|
-
const boardContainer = PlaitBoard.getBoardContainer(board);
|
|
2630
|
-
const boardContainerRectangle = boardContainer.getBoundingClientRect();
|
|
2631
|
-
let finalWidth = 0;
|
|
2632
|
-
if (options.maxWidth) {
|
|
2633
|
-
finalWidth = options.maxWidth;
|
|
2634
|
-
}
|
|
2635
|
-
else {
|
|
2636
|
-
finalWidth = boardContainerRectangle.width;
|
|
2637
|
-
}
|
|
2638
|
-
const elementHostBox = getRectangleByElements(board, board.children, true);
|
|
2639
|
-
const contentWidth = finalWidth - 2 * options.autoFitPadding;
|
|
2640
|
-
let newZoom = 0;
|
|
2641
|
-
if (contentWidth < elementHostBox.width) {
|
|
2642
|
-
newZoom = Math.min(contentWidth / elementHostBox.width);
|
|
2643
|
-
}
|
|
2644
|
-
else {
|
|
2645
|
-
newZoom = 1;
|
|
2646
|
-
}
|
|
2647
|
-
let finalHeight = elementHostBox.height * newZoom + 2 * options.autoFitPadding;
|
|
2648
|
-
if (finalHeight > options.limitHeight) {
|
|
2649
|
-
const containerEl = boardContainer.closest(`.${options.containerClass}`);
|
|
2650
|
-
containerEl.style.height = `${finalHeight}px`;
|
|
2651
|
-
initializeViewportContainer(board);
|
|
2652
|
-
}
|
|
2653
|
-
else {
|
|
2654
|
-
finalHeight = options.limitHeight;
|
|
2655
|
-
}
|
|
2656
|
-
const centerX = elementHostBox.x + elementHostBox.width / 2;
|
|
2657
|
-
const centerY = elementHostBox.y + elementHostBox.height / 2;
|
|
2658
|
-
const newOrigination = [
|
|
2659
|
-
centerX - finalWidth / 2 / newZoom + scrollBarWidth / 2 / newZoom,
|
|
2660
|
-
centerY - finalHeight / 2 / newZoom + scrollBarWidth / 2 / newZoom
|
|
2661
|
-
];
|
|
2662
|
-
updateViewport(board, newOrigination, newZoom);
|
|
2663
|
-
}
|
|
2664
|
-
/**
|
|
2665
|
-
* apply theme to every element (remove element custom properties)
|
|
2666
|
-
* invoke applyThemeColor
|
|
2667
|
-
*/
|
|
2668
|
-
function updateThemeColor(board, mode) {
|
|
2669
|
-
mode = mode ?? board.theme.themeColorMode;
|
|
2670
|
-
setTheme(board, { themeColorMode: mode });
|
|
2671
|
-
depthFirstRecursion(board, element => {
|
|
2672
|
-
board.applyTheme(element);
|
|
2673
|
-
});
|
|
2674
|
-
}
|
|
2675
|
-
const BoardTransforms = {
|
|
2676
|
-
updatePointerType,
|
|
2677
|
-
updateViewport,
|
|
2678
|
-
fitViewport,
|
|
2679
|
-
updateZoom,
|
|
2680
|
-
updateThemeColor,
|
|
2681
|
-
fitViewportWidth
|
|
2682
|
-
};
|
|
2683
|
-
|
|
2684
2715
|
const removeElements = (board, elements) => {
|
|
2685
2716
|
elements
|
|
2686
2717
|
.map(element => {
|
|
@@ -3859,6 +3890,7 @@ class PlaitBoardComponent {
|
|
|
3859
3890
|
this.ngZone.runOutsideAngular(() => {
|
|
3860
3891
|
this.initializeHookListener();
|
|
3861
3892
|
this.viewportScrollListener();
|
|
3893
|
+
this.wheelZoomListener();
|
|
3862
3894
|
this.elementResizeListener();
|
|
3863
3895
|
fromEvent(document, 'mouseleave')
|
|
3864
3896
|
.pipe(takeUntil(this.destroy$))
|
|
@@ -4039,35 +4071,24 @@ class PlaitBoardComponent {
|
|
|
4039
4071
|
});
|
|
4040
4072
|
}
|
|
4041
4073
|
viewportScrollListener() {
|
|
4042
|
-
this.
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
const zoom = this.board.viewport.zoom;
|
|
4054
|
-
const viewBox = getViewBox(this.board, zoom);
|
|
4055
|
-
const origination = [scrollLeft / zoom + viewBox[0], scrollTop / zoom + viewBox[1]];
|
|
4056
|
-
if (Point.isEquals(origination, this.board.viewport.origination)) {
|
|
4057
|
-
return;
|
|
4058
|
-
}
|
|
4059
|
-
BoardTransforms.updateViewport(this.board, origination);
|
|
4060
|
-
setIsFromScrolling(this.board, true);
|
|
4061
|
-
});
|
|
4074
|
+
fromEvent(this.viewportContainer.nativeElement, 'scroll')
|
|
4075
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
4076
|
+
if (isFromViewportChange(this.board)) {
|
|
4077
|
+
setIsFromViewportChange(this.board, false);
|
|
4078
|
+
return false;
|
|
4079
|
+
}
|
|
4080
|
+
return true;
|
|
4081
|
+
}))
|
|
4082
|
+
.subscribe((event) => {
|
|
4083
|
+
const { scrollLeft, scrollTop } = event.target;
|
|
4084
|
+
updateViewportByScrolling(this.board, scrollLeft, scrollTop);
|
|
4062
4085
|
});
|
|
4063
|
-
this.
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
}
|
|
4070
|
-
});
|
|
4086
|
+
fromEvent(this.viewportContainer.nativeElement, 'touchmove', { passive: false })
|
|
4087
|
+
.pipe(takeUntil(this.destroy$))
|
|
4088
|
+
.subscribe((event) => {
|
|
4089
|
+
if (isPreventTouchMove(this.board)) {
|
|
4090
|
+
event.preventDefault();
|
|
4091
|
+
}
|
|
4071
4092
|
});
|
|
4072
4093
|
}
|
|
4073
4094
|
elementResizeListener() {
|
|
@@ -4091,6 +4112,34 @@ class PlaitBoardComponent {
|
|
|
4091
4112
|
island.markForCheck();
|
|
4092
4113
|
});
|
|
4093
4114
|
}
|
|
4115
|
+
wheelZoomListener() {
|
|
4116
|
+
fromEvent(this.host, 'wheel', { passive: false })
|
|
4117
|
+
.pipe(takeUntil(this.destroy$))
|
|
4118
|
+
.subscribe((event) => {
|
|
4119
|
+
// Credits to excalidraw
|
|
4120
|
+
// https://github.com/excalidraw/excalidraw/blob/b7d7ccc929696cc17b4cc34452e4afd846d59f4f/src/components/App.tsx#L9060
|
|
4121
|
+
if (event.metaKey || event.ctrlKey) {
|
|
4122
|
+
event.preventDefault();
|
|
4123
|
+
const { deltaX, deltaY } = event;
|
|
4124
|
+
const zoom = this.board.viewport.zoom;
|
|
4125
|
+
const sign = Math.sign(deltaY);
|
|
4126
|
+
const MAX_STEP = ZOOM_STEP * 100;
|
|
4127
|
+
const absDelta = Math.abs(deltaY);
|
|
4128
|
+
let delta = deltaY;
|
|
4129
|
+
if (absDelta > MAX_STEP) {
|
|
4130
|
+
delta = MAX_STEP * sign;
|
|
4131
|
+
}
|
|
4132
|
+
let newZoom = zoom - delta / 100;
|
|
4133
|
+
// increase zoom steps the more zoomed-in we are (applies to >100% only)
|
|
4134
|
+
newZoom +=
|
|
4135
|
+
Math.log10(Math.max(1, zoom)) *
|
|
4136
|
+
-sign *
|
|
4137
|
+
// reduced amplification for small deltas (small movements on a trackpad)
|
|
4138
|
+
Math.min(1, absDelta / 20);
|
|
4139
|
+
BoardTransforms.updateZoom(this.board, newZoom, false);
|
|
4140
|
+
}
|
|
4141
|
+
});
|
|
4142
|
+
}
|
|
4094
4143
|
ngOnDestroy() {
|
|
4095
4144
|
this.destroy$.next();
|
|
4096
4145
|
this.destroy$.complete();
|
|
@@ -4346,5 +4395,5 @@ function createModModifierKeys() {
|
|
|
4346
4395
|
* Generated bundle index. Do not edit.
|
|
4347
4396
|
*/
|
|
4348
4397
|
|
|
4349
|
-
export { A, ACTIVE_STROKE_WIDTH, ALT, APOSTROPHE, ATTACHED_ELEMENT_CLASS_NAME, AT_SIGN, B, BACKSLASH, BACKSPACE, 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_MOVING_POINT_IN_BOARD, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_TOUCH_REF, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, C, CAPS_LOCK, CLIP_BOARD_FORMAT_KEY, CLOSE_SQUARE_BRACKET, COMMA, CONTEXT_MENU, CONTROL, ColorfulThemeColor, CoreTransforms, D, DASH, DELETE, DOWN_ARROW, DarkThemeColor, DefaultThemeColor, Direction, E, EIGHT, ELEMENT_TO_COMPONENT, END, ENTER, EQUALS, ESCAPE, F, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FF_EQUALS, FF_MINUS, FF_MUTE, FF_SEMICOLON, FF_VOLUME_DOWN, FF_VOLUME_UP, FIRST_MEDIA, FIVE, FLUSHING, FOUR, G, H, HOME, HOST_CLASS_NAME, I, INSERT, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_MAC, IS_SAFARI, IS_TEXT_EDITABLE, J, K, L, LAST_MEDIA, LEFT_ARROW, M, MAC_ENTER, MAC_META, MAC_WK_CMD_LEFT, MAC_WK_CMD_RIGHT, MAX_RADIUS, MERGING, META, MUTE, N, NINE, NODE_TO_INDEX, NODE_TO_PARENT, NS, NUMPAD_DIVIDE, NUMPAD_EIGHT, NUMPAD_FIVE, NUMPAD_FOUR, NUMPAD_MINUS, NUMPAD_MULTIPLY, NUMPAD_NINE, NUMPAD_ONE, NUMPAD_PERIOD, NUMPAD_PLUS, NUMPAD_SEVEN, NUMPAD_SIX, NUMPAD_THREE, NUMPAD_TWO, NUMPAD_ZERO, NUM_CENTER, NUM_LOCK, O, ONE, OPEN_SQUARE_BRACKET, P, PAGE_DOWN, PAGE_UP, PATH_REFS, PAUSE, PERIOD, PLUS_SIGN, POINTER_BUTTON, PRESS_AND_MOVE_BUFFER, PRINT_SCREEN, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElementComponent, PlaitContextService, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitIslandPopoverBaseComponent, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, Q, QUESTION_MARK, R, RIGHT_ARROW, RectangleClient, ResizeCursorClass, RetroThemeColor, S, SAVING, SCROLL_BAR_WIDTH, SCROLL_LOCK, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, SELECTION_RECTANGLE_CLASS_NAME, SEMICOLON, SEVEN, SHIFT, SINGLE_QUOTE, SIX, SLASH, SPACE, Selection, SoftThemeColor, StarryThemeColor, T, TAB, THREE, TILDE, TWO, ThemeColorMode, ThemeColors, Transforms, U, UP_ARROW, V, VOLUME_DOWN, VOLUME_UP, Viewport, W, X, Y, Z, ZERO, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, catmullRomFitting, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createFakeEvent, createForeignObject, createG, createKeyboardEvent, createMask, createModModifierKeys, createMouseEvent, createPath, createPointerEvent, createRect, createSVG, createSelectionRectangleG, createTestingBoard, createText, createTouchEvent, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, distanceBetweenPointAndSegments, downScale, downloadImage, drawArrow, drawBezierPath, drawCircle, drawLine, drawLinearPath, drawRectangle, drawRoundRectangle, fakeNodeWeakMap, findElements, getBoardRectangle, getClipboardByKey, getClipboardDataByMedia, getDataFromClipboard, getElementById, getElementHostBBox, getHitElementByPoint, getHitElementsBySelection, getIsRecursionFunc, getMovingElements, getNearestPointBetweenPointAndSegment, getNearestPointBetweenPointAndSegments, getRealScrollBarWidth, getRectangleByElements, getSelectedElements, getTemporaryElements, getTemporaryRef, getTextFromClipboard, getViewBox, getViewBoxCenterPoint, getViewportContainerRect, getViewportOrigination, handleTouchTarget, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange, isInPlaitBoard, isLineHitLine, isMainPointer, isNullOrUndefined, isPointInEllipse, isPointInPolygon, isPointInRoundRectangle, isPolylineHitRectangle, isPreventTouchMove, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, preventTouchMove, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setClipboardData, setClipboardDataByMedia, setClipboardDataByText, setIsFromScrolling, setIsFromViewportChange, setPathStrokeLinecap, setSVGViewBox, setSelectionMoving, setStrokeLinecap, shouldClear, shouldMerge, shouldSave, temporaryDisableSelection, throttleRAF, toImage, toPoint, transformPoint, transformPoints, updateForeignObject, updateForeignObjectWidth, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
|
|
4398
|
+
export { A, ACTIVE_STROKE_WIDTH, ALT, APOSTROPHE, ATTACHED_ELEMENT_CLASS_NAME, AT_SIGN, B, BACKSLASH, BACKSPACE, 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_MOVING_POINT_IN_BOARD, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_TOUCH_REF, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, C, CAPS_LOCK, CLIP_BOARD_FORMAT_KEY, CLOSE_SQUARE_BRACKET, COMMA, CONTEXT_MENU, CONTROL, ColorfulThemeColor, CoreTransforms, D, DASH, DELETE, DOWN_ARROW, DarkThemeColor, DefaultThemeColor, Direction, E, EIGHT, ELEMENT_TO_COMPONENT, END, ENTER, EQUALS, ESCAPE, F, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, FF_EQUALS, FF_MINUS, FF_MUTE, FF_SEMICOLON, FF_VOLUME_DOWN, FF_VOLUME_UP, FIRST_MEDIA, FIVE, FLUSHING, FOUR, G, H, HOME, HOST_CLASS_NAME, I, INSERT, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_MAC, IS_SAFARI, IS_TEXT_EDITABLE, J, K, L, LAST_MEDIA, LEFT_ARROW, M, MAC_ENTER, MAC_META, MAC_WK_CMD_LEFT, MAC_WK_CMD_RIGHT, MAX_RADIUS, MERGING, META, MUTE, N, NINE, NODE_TO_INDEX, NODE_TO_PARENT, NS, NUMPAD_DIVIDE, NUMPAD_EIGHT, NUMPAD_FIVE, NUMPAD_FOUR, NUMPAD_MINUS, NUMPAD_MULTIPLY, NUMPAD_NINE, NUMPAD_ONE, NUMPAD_PERIOD, NUMPAD_PLUS, NUMPAD_SEVEN, NUMPAD_SIX, NUMPAD_THREE, NUMPAD_TWO, NUMPAD_ZERO, NUM_CENTER, NUM_LOCK, O, ONE, OPEN_SQUARE_BRACKET, P, PAGE_DOWN, PAGE_UP, PATH_REFS, PAUSE, PERIOD, PLUS_SIGN, POINTER_BUTTON, PRESS_AND_MOVE_BUFFER, PRINT_SCREEN, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElementComponent, PlaitContextService, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitIslandPopoverBaseComponent, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, Q, QUESTION_MARK, R, RIGHT_ARROW, RectangleClient, ResizeCursorClass, RetroThemeColor, S, SAVING, SCROLL_BAR_WIDTH, SCROLL_LOCK, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, SELECTION_RECTANGLE_CLASS_NAME, SEMICOLON, SEVEN, SHIFT, SINGLE_QUOTE, SIX, SLASH, SPACE, Selection, SoftThemeColor, StarryThemeColor, T, TAB, THREE, TILDE, TWO, ThemeColorMode, ThemeColors, Transforms, U, UP_ARROW, V, VOLUME_DOWN, VOLUME_UP, Viewport, W, X, Y, Z, ZERO, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, catmullRomFitting, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createFakeEvent, createForeignObject, createG, createKeyboardEvent, createMask, createModModifierKeys, createMouseEvent, createPath, createPointerEvent, createRect, createSVG, createSelectionRectangleG, createTestingBoard, createText, createTouchEvent, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, distanceBetweenPointAndSegments, downScale, downloadImage, drawArrow, drawBezierPath, drawCircle, drawLine, drawLinearPath, drawRectangle, drawRoundRectangle, fakeNodeWeakMap, findElements, getBoardRectangle, getClipboardByKey, getClipboardDataByMedia, getDataFromClipboard, getElementById, getElementHostBBox, getHitElementByPoint, getHitElementsBySelection, getIsRecursionFunc, getMovingElements, getNearestPointBetweenPointAndSegment, getNearestPointBetweenPointAndSegments, getRealScrollBarWidth, getRectangleByElements, getSelectedElements, getTemporaryElements, getTemporaryRef, getTextFromClipboard, getViewBox, getViewBoxCenterPoint, getViewportContainerRect, getViewportOrigination, handleTouchTarget, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange, isInPlaitBoard, isLineHitLine, isMainPointer, isNullOrUndefined, isPointInEllipse, isPointInPolygon, isPointInRoundRectangle, isPolylineHitRectangle, isPreventTouchMove, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, preventTouchMove, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setClipboardData, setClipboardDataByMedia, setClipboardDataByText, setIsFromScrolling, setIsFromViewportChange, setPathStrokeLinecap, setSVGViewBox, setSelectionMoving, setStrokeLinecap, shouldClear, shouldMerge, shouldSave, temporaryDisableSelection, throttleRAF, toImage, toPoint, transformPoint, transformPoints, updateForeignObject, updateForeignObjectWidth, updateViewportByScrolling, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
|
|
4350
4399
|
//# sourceMappingURL=plait-core.mjs.map
|