@plait/core 0.0.52 → 0.0.55
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 +31 -8
- package/esm2020/board/board.component.mjs +196 -117
- package/esm2020/interfaces/viewport.mjs +2 -5
- package/esm2020/plugins/create-board.mjs +3 -4
- package/esm2020/utils/matrix.mjs +62 -51
- package/fesm2015/plait-core.mjs +256 -171
- package/fesm2015/plait-core.mjs.map +1 -1
- package/fesm2020/plait-core.mjs +259 -173
- package/fesm2020/plait-core.mjs.map +1 -1
- package/interfaces/viewport.d.ts +1 -2
- package/package.json +1 -1
- package/styles/styles.scss +8 -1
- package/utils/matrix.d.ts +23 -7
package/fesm2015/plait-core.mjs
CHANGED
|
@@ -239,10 +239,7 @@ function isNullOrUndefined(value) {
|
|
|
239
239
|
|
|
240
240
|
const Viewport = {
|
|
241
241
|
isViewport: (value) => {
|
|
242
|
-
return (!isNullOrUndefined(value.
|
|
243
|
-
!isNullOrUndefined(value.offsetYRatio) &&
|
|
244
|
-
!isNullOrUndefined(value.zoom) &&
|
|
245
|
-
!isNullOrUndefined(value.viewBackgroundColor));
|
|
242
|
+
return !isNullOrUndefined(value.zoom) && !isNullOrUndefined(value.viewBackgroundColor) && !isNullOrUndefined(value.canvasPoint);
|
|
246
243
|
}
|
|
247
244
|
};
|
|
248
245
|
|
|
@@ -450,10 +447,9 @@ function createBoard(host, children, options) {
|
|
|
450
447
|
const board = {
|
|
451
448
|
host,
|
|
452
449
|
viewport: {
|
|
453
|
-
offsetXRatio: 0.5,
|
|
454
|
-
offsetYRatio: 0.5,
|
|
455
450
|
zoom: 1,
|
|
456
|
-
viewBackgroundColor: '#000'
|
|
451
|
+
viewBackgroundColor: '#000',
|
|
452
|
+
canvasPoint: []
|
|
457
453
|
},
|
|
458
454
|
children,
|
|
459
455
|
operations: [],
|
|
@@ -811,36 +807,81 @@ function invert(oldMatrix, newMatrix) {
|
|
|
811
807
|
: null;
|
|
812
808
|
}
|
|
813
809
|
function transformMat3(e, t, n) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
810
|
+
e = [t[0] * n[0] + t[1] * n[3] + t[2] * n[6], t[0] * n[1] + t[1] * n[4] + t[2] * n[7], t[0] * n[2] + t[1] * n[5] + t[2] * n[8]];
|
|
811
|
+
return e;
|
|
812
|
+
}
|
|
813
|
+
function convertPoint(arr) {
|
|
814
|
+
return Array.isArray(arr)
|
|
815
|
+
? {
|
|
816
|
+
x: arr[0],
|
|
817
|
+
y: arr[1]
|
|
818
|
+
}
|
|
819
|
+
: arr;
|
|
820
|
+
}
|
|
821
|
+
function invertClient(board, point, matrix) {
|
|
822
|
+
const convert = convertPoint(point);
|
|
823
|
+
const clientBox = getViewportClientBox(board);
|
|
824
|
+
const newPoint = [convert.x - clientBox.x, convert.y - clientBox.y, 1];
|
|
825
|
+
const invertMatrix = invert([], matrix);
|
|
826
|
+
const newMatrix = transformMat3([], [newPoint[0], newPoint[1], 1], invertMatrix);
|
|
827
|
+
return [newMatrix[0], newMatrix[1]];
|
|
828
|
+
}
|
|
829
|
+
function invertViewport(point, matrix) {
|
|
830
|
+
const newPoint = convertPoint(point);
|
|
831
|
+
const invertMatrix = invert([], matrix);
|
|
832
|
+
return transformMat3([], [newPoint.x, newPoint.y, 1], invertMatrix);
|
|
833
|
+
}
|
|
834
|
+
function convertViewport(point, matrix) {
|
|
835
|
+
const newPoint = convertPoint(point);
|
|
836
|
+
return transformMat3([], [newPoint.x, newPoint.y, 1], matrix);
|
|
837
|
+
}
|
|
838
|
+
function getViewportCanvasBox(board, matrix) {
|
|
839
|
+
const clientBox = getViewportClientBox(board);
|
|
840
|
+
const client = invertClient(board, [clientBox.minX, clientBox.minY], matrix);
|
|
841
|
+
const newClient = invertClient(board, [clientBox.maxX, clientBox.maxY], matrix);
|
|
842
|
+
return {
|
|
843
|
+
minX: client[0],
|
|
844
|
+
minY: client[1],
|
|
845
|
+
maxX: newClient[0],
|
|
846
|
+
maxY: newClient[1],
|
|
847
|
+
x: client[0],
|
|
848
|
+
y: client[1],
|
|
849
|
+
width: newClient[0] - client[0],
|
|
850
|
+
height: newClient[1] - client[1]
|
|
851
|
+
};
|
|
818
852
|
}
|
|
819
853
|
function getViewportClientBox(board) {
|
|
820
854
|
var _a;
|
|
821
|
-
const hideScrollbar = board.options.hideScrollbar;
|
|
822
|
-
const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
823
855
|
const container = (_a = board.host) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
824
856
|
const containerRect = container === null || container === void 0 ? void 0 : container.getBoundingClientRect();
|
|
825
|
-
const width = containerRect.width - scrollBarWidth;
|
|
826
|
-
const height = containerRect.height - scrollBarWidth;
|
|
827
857
|
const x = containerRect.x || containerRect.left;
|
|
828
858
|
const y = containerRect.y || containerRect.top;
|
|
859
|
+
const width = containerRect.width - SCROLL_BAR_WIDTH;
|
|
860
|
+
const height = containerRect.height - SCROLL_BAR_WIDTH;
|
|
829
861
|
return {
|
|
830
|
-
|
|
831
|
-
|
|
862
|
+
minX: x,
|
|
863
|
+
minY: y,
|
|
864
|
+
maxX: x + width,
|
|
865
|
+
maxY: y + height,
|
|
832
866
|
x,
|
|
833
|
-
y
|
|
867
|
+
y,
|
|
868
|
+
width,
|
|
869
|
+
height
|
|
834
870
|
};
|
|
835
871
|
}
|
|
836
|
-
function
|
|
837
|
-
const
|
|
872
|
+
function getGraphicsBBox(board) {
|
|
873
|
+
const rootGroup = board.host.firstChild;
|
|
874
|
+
const rootGroupBox = rootGroup.getBBox();
|
|
875
|
+
return rootGroupBox;
|
|
876
|
+
}
|
|
877
|
+
function calculateBBox(board, zoom) {
|
|
878
|
+
const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
|
|
879
|
+
// const clientBox = getViewportClientBox(board);
|
|
838
880
|
const rootGroup = board.host.firstChild;
|
|
839
|
-
const zoom = board.viewport.zoom;
|
|
840
881
|
const rootGroupBox = rootGroup.getBBox();
|
|
841
882
|
let box = {};
|
|
842
|
-
const containerWidth =
|
|
843
|
-
const containerHeight =
|
|
883
|
+
const containerWidth = boardComponent.width / zoom;
|
|
884
|
+
const containerHeight = boardComponent.height / zoom;
|
|
844
885
|
if (rootGroupBox.width < containerWidth) {
|
|
845
886
|
const offsetX = rootGroupBox.x + rootGroupBox.width / 2;
|
|
846
887
|
const containerX = containerWidth / 2;
|
|
@@ -864,40 +905,6 @@ function calculateBBox(board) {
|
|
|
864
905
|
// 在新的缩放比容器宽高下的内容盒子位置
|
|
865
906
|
return box;
|
|
866
907
|
}
|
|
867
|
-
function getViewBox(board) {
|
|
868
|
-
const viewportBox = getViewportClientBox(board);
|
|
869
|
-
const rootGroupBBox = calculateBBox(board);
|
|
870
|
-
const padding = [viewportBox.height / 2, viewportBox.width / 2];
|
|
871
|
-
const zoom = board.viewport.zoom;
|
|
872
|
-
const minX = rootGroupBBox.left - padding[1] / zoom;
|
|
873
|
-
const minY = rootGroupBBox.top - padding[0] / zoom;
|
|
874
|
-
const viewportWidth = (rootGroupBBox.right - rootGroupBBox.left) * zoom + 2 * padding[1];
|
|
875
|
-
const viewportHeight = (rootGroupBBox.bottom - rootGroupBBox.top) * zoom + 2 * padding[0];
|
|
876
|
-
const width = viewportWidth / zoom;
|
|
877
|
-
const height = viewportHeight / zoom;
|
|
878
|
-
return { minX, minY, width, height, viewportWidth, viewportHeight };
|
|
879
|
-
}
|
|
880
|
-
function isOutExtent(board, node, gap) {
|
|
881
|
-
const result = { x: 0, y: 0 };
|
|
882
|
-
if (!node)
|
|
883
|
-
return result;
|
|
884
|
-
const boardComponent = PLAIT_BOARD_TO_COMPONENT.get(board);
|
|
885
|
-
const scrollBarWidth = board.options.hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
886
|
-
const canvasRect = boardComponent.contentContainer.nativeElement.getBoundingClientRect();
|
|
887
|
-
if (node.left < canvasRect.left + gap) {
|
|
888
|
-
result.x = canvasRect.left - node.left - gap;
|
|
889
|
-
}
|
|
890
|
-
else if (node.right > canvasRect.right - scrollBarWidth - gap) {
|
|
891
|
-
result.x = canvasRect.right - scrollBarWidth - gap - node.right - node.width;
|
|
892
|
-
}
|
|
893
|
-
if (node.top < canvasRect.top + gap) {
|
|
894
|
-
result.y = canvasRect.top - node.top - gap;
|
|
895
|
-
}
|
|
896
|
-
else if (node.bottom > canvasRect.bottom - scrollBarWidth - gap) {
|
|
897
|
-
result.y = canvasRect.bottom - scrollBarWidth - gap - node.bottom - node.height;
|
|
898
|
-
}
|
|
899
|
-
return result;
|
|
900
|
-
}
|
|
901
908
|
|
|
902
909
|
function withHistory(board) {
|
|
903
910
|
const { apply, keydown } = board;
|
|
@@ -1217,8 +1224,11 @@ class PlaitBoardComponent {
|
|
|
1217
1224
|
this.destroy$ = new Subject();
|
|
1218
1225
|
this.autoFitPadding = 8;
|
|
1219
1226
|
this.isMoving = false;
|
|
1220
|
-
this.
|
|
1221
|
-
this.
|
|
1227
|
+
this.zoom = 1;
|
|
1228
|
+
this.viewportCanvasBox = {};
|
|
1229
|
+
this.focusPoint = [0, 0];
|
|
1230
|
+
this.width = 0;
|
|
1231
|
+
this.height = 0;
|
|
1222
1232
|
this.plaitValue = [];
|
|
1223
1233
|
this.plaitPlugins = [];
|
|
1224
1234
|
this.plaitChange = new EventEmitter();
|
|
@@ -1263,27 +1273,20 @@ class PlaitBoardComponent {
|
|
|
1263
1273
|
viewport: this.board.viewport,
|
|
1264
1274
|
selection: this.board.selection
|
|
1265
1275
|
};
|
|
1266
|
-
if (this.board.operations.
|
|
1276
|
+
if (this.board.operations.length > 0) {
|
|
1267
1277
|
this.updateViewport();
|
|
1268
1278
|
}
|
|
1269
|
-
if (this.board.operations.some(op => ['set_node', 'remove_node'].includes(op.type))) {
|
|
1270
|
-
this.calculateViewport();
|
|
1271
|
-
}
|
|
1272
1279
|
this.plaitChange.emit(changeEvent);
|
|
1273
1280
|
});
|
|
1274
1281
|
this.hasInitialized = true;
|
|
1275
1282
|
}
|
|
1276
|
-
setMatrix() {
|
|
1277
|
-
const viewBox = getViewBox(this.board);
|
|
1278
|
-
const zoom = this.board.viewport.zoom;
|
|
1279
|
-
this.matrix = [zoom, 0, 0, 0, zoom, 0, -this.scrollLeft - zoom * viewBox.minX, -this.scrollTop - zoom * viewBox.minY, 1];
|
|
1280
|
-
}
|
|
1281
1283
|
ngOnChanges(changes) {
|
|
1282
1284
|
if (this.hasInitialized) {
|
|
1283
1285
|
const valueChange = changes['plaitValue'];
|
|
1284
1286
|
const options = changes['plaitOptions'];
|
|
1285
|
-
if (valueChange)
|
|
1287
|
+
if (valueChange) {
|
|
1286
1288
|
this.board.children = valueChange.currentValue;
|
|
1289
|
+
}
|
|
1287
1290
|
if (options)
|
|
1288
1291
|
this.board.options = options.currentValue;
|
|
1289
1292
|
this.cdr.markForCheck();
|
|
@@ -1292,7 +1295,8 @@ class PlaitBoardComponent {
|
|
|
1292
1295
|
ngAfterViewInit() {
|
|
1293
1296
|
this.plaitBoardInitialized.emit(this.board);
|
|
1294
1297
|
this.initContainerSize();
|
|
1295
|
-
this.
|
|
1298
|
+
this.setViewport(1);
|
|
1299
|
+
this.plaitViewport ? this.initCanvas(this.plaitViewport) : this.focusGraphicCenter();
|
|
1296
1300
|
}
|
|
1297
1301
|
initializePlugins() {
|
|
1298
1302
|
let board = withMove(withHistory(withSelection(withBoard(createBoard(this.host, this.plaitValue, this.plaitOptions)))));
|
|
@@ -1368,34 +1372,49 @@ class PlaitBoardComponent {
|
|
|
1368
1372
|
(_a = this.board) === null || _a === void 0 ? void 0 : _a.setFragment(event.clipboardData);
|
|
1369
1373
|
(_b = this.board) === null || _b === void 0 ? void 0 : _b.deleteFragment(event.clipboardData);
|
|
1370
1374
|
});
|
|
1371
|
-
fromEvent(this.contentContainer.nativeElement, '
|
|
1372
|
-
.pipe(takeUntil(this.destroy$), filter((
|
|
1373
|
-
if (!this.isFocused) {
|
|
1374
|
-
e.preventDefault();
|
|
1375
|
-
e.stopPropagation();
|
|
1376
|
-
}
|
|
1375
|
+
fromEvent(this.contentContainer.nativeElement, 'mousemove')
|
|
1376
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
1377
1377
|
return !!this.isFocused;
|
|
1378
1378
|
}))
|
|
1379
|
-
.subscribe()
|
|
1379
|
+
.subscribe((e) => {
|
|
1380
|
+
this.focusPoint = [e.clientX, e.clientY];
|
|
1381
|
+
});
|
|
1382
|
+
fromEvent(this.contentContainer.nativeElement, 'mouseleave')
|
|
1383
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
1384
|
+
return !!this.isFocused;
|
|
1385
|
+
}))
|
|
1386
|
+
.subscribe((e) => {
|
|
1387
|
+
this.resetFocusPoint();
|
|
1388
|
+
});
|
|
1380
1389
|
fromEvent(this.contentContainer.nativeElement, 'scroll')
|
|
1381
|
-
.pipe(takeUntil(this.destroy$), filter((
|
|
1382
|
-
if (!this.isFocused) {
|
|
1383
|
-
e.preventDefault();
|
|
1384
|
-
e.stopPropagation();
|
|
1385
|
-
}
|
|
1390
|
+
.pipe(takeUntil(this.destroy$), filter(() => {
|
|
1386
1391
|
return !!this.isFocused;
|
|
1387
1392
|
}))
|
|
1388
1393
|
.subscribe((event) => {
|
|
1389
1394
|
const scrollLeft = event.target.scrollLeft;
|
|
1390
1395
|
const scrollTop = event.target.scrollTop;
|
|
1391
|
-
this.
|
|
1396
|
+
(Math.abs(this.scrollLeft - scrollLeft) <= 1 && Math.abs(this.scrollTop - scrollTop) <= 1) ||
|
|
1397
|
+
this.setScroll(scrollLeft, scrollTop);
|
|
1392
1398
|
});
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1399
|
+
this.resizeElement();
|
|
1400
|
+
}
|
|
1401
|
+
resizeElement() {
|
|
1402
|
+
this.resizeObserver = new ResizeObserver(entries => {
|
|
1403
|
+
for (let entry of entries) {
|
|
1404
|
+
const { width, height } = entry.contentRect;
|
|
1405
|
+
const hideScrollbar = this.board.options.hideScrollbar;
|
|
1406
|
+
const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
1407
|
+
this.width = width + scrollBarWidth;
|
|
1408
|
+
this.height = height + scrollBarWidth;
|
|
1409
|
+
this.changeSize();
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
this.resizeObserver.observe(this.elementRef.nativeElement);
|
|
1396
1413
|
}
|
|
1397
1414
|
initContainerSize() {
|
|
1398
|
-
|
|
1415
|
+
const clientBox = getViewportClientBox(this.board);
|
|
1416
|
+
this.width = clientBox.width;
|
|
1417
|
+
this.height = clientBox.height;
|
|
1399
1418
|
this.resizeViewport();
|
|
1400
1419
|
}
|
|
1401
1420
|
resizeViewport() {
|
|
@@ -1411,73 +1430,151 @@ class PlaitBoardComponent {
|
|
|
1411
1430
|
this.renderer2.setStyle(this.contentContainer.nativeElement, 'maxWidth', width);
|
|
1412
1431
|
this.renderer2.setStyle(this.contentContainer.nativeElement, 'maxHeight', height);
|
|
1413
1432
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
const viewBox = getViewBox(this.board);
|
|
1419
|
-
const scrollLeftRatio = left / (viewBox.viewportWidth - viewportBox.width);
|
|
1420
|
-
const scrollTopRatio = top / (viewBox.viewportHeight - viewportBox.height);
|
|
1421
|
-
this.setViewport({
|
|
1422
|
-
offsetXRatio: scrollLeftRatio,
|
|
1423
|
-
offsetYRatio: scrollTopRatio
|
|
1424
|
-
});
|
|
1425
|
-
}
|
|
1426
|
-
updateScroll() {
|
|
1427
|
-
const container = this.contentContainer.nativeElement;
|
|
1428
|
-
container.scrollTo({
|
|
1429
|
-
top: this.scrollTop,
|
|
1430
|
-
left: this.scrollLeft
|
|
1431
|
-
});
|
|
1433
|
+
setMatrix() {
|
|
1434
|
+
const viewBox = this.viewBox;
|
|
1435
|
+
const zoom = this.zoom;
|
|
1436
|
+
this.matrix = [zoom, 0, 0, 0, zoom, 0, -this.scrollLeft - zoom * viewBox[0], -this.scrollTop - zoom * viewBox[1], 1];
|
|
1432
1437
|
}
|
|
1433
|
-
|
|
1434
|
-
const
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1438
|
+
updateViewport() {
|
|
1439
|
+
const clientBox = getViewportClientBox(this.board);
|
|
1440
|
+
this.setViewport(this.board.viewport.zoom, [clientBox.x, clientBox.y]);
|
|
1441
|
+
}
|
|
1442
|
+
setViewport(zoom, focusPoint) {
|
|
1443
|
+
zoom = zoom !== null && zoom !== void 0 ? zoom : this.zoom;
|
|
1444
|
+
zoom = calculateZoom(zoom);
|
|
1445
|
+
if (zoom !== this.zoom) {
|
|
1446
|
+
this.zoom = zoom;
|
|
1447
|
+
}
|
|
1448
|
+
focusPoint = focusPoint !== null && focusPoint !== void 0 ? focusPoint : this.focusPoint;
|
|
1449
|
+
let scrollLeft;
|
|
1450
|
+
let scrollTop;
|
|
1451
|
+
const clientBox = getViewportClientBox(this.board);
|
|
1441
1452
|
const matrix = this.matrix;
|
|
1442
|
-
const
|
|
1453
|
+
const box = calculateBBox(this.board, zoom);
|
|
1454
|
+
const padding = [this.height / 2, this.width / 2];
|
|
1455
|
+
const rootGroupWidth = box.right - box.left;
|
|
1456
|
+
const rootGroupHeight = box.bottom - box.top;
|
|
1457
|
+
const canvasWidth = rootGroupWidth * zoom + 2 * padding[1];
|
|
1458
|
+
const canvasHeight = rootGroupHeight * zoom + 2 * padding[0];
|
|
1459
|
+
const viewBox = [box.left - padding[1] / zoom, box.top - padding[0] / zoom, canvasWidth / zoom, canvasHeight / zoom];
|
|
1443
1460
|
if (matrix) {
|
|
1444
|
-
const
|
|
1445
|
-
const
|
|
1446
|
-
const
|
|
1447
|
-
const
|
|
1448
|
-
const
|
|
1449
|
-
scrollLeft =
|
|
1450
|
-
scrollTop =
|
|
1461
|
+
const canvasPoint = [focusPoint[0] - clientBox.x, focusPoint[1] - clientBox.y, 1];
|
|
1462
|
+
const invertMatrix = invert([], matrix);
|
|
1463
|
+
const matrix1 = transformMat3([], [canvasPoint[0], canvasPoint[1], 1], invertMatrix);
|
|
1464
|
+
const matrix2 = [zoom, 0, 0, 0, zoom, 0, -zoom * viewBox[0], -zoom * viewBox[1], 1];
|
|
1465
|
+
const newMatrix = transformMat3([], matrix1, matrix2);
|
|
1466
|
+
scrollLeft = newMatrix[0] - canvasPoint[0];
|
|
1467
|
+
scrollTop = newMatrix[1] - canvasPoint[1];
|
|
1451
1468
|
}
|
|
1452
1469
|
else {
|
|
1453
|
-
scrollLeft = (
|
|
1454
|
-
scrollTop =
|
|
1470
|
+
scrollLeft = (canvasWidth - clientBox.width) / 2;
|
|
1471
|
+
scrollTop = padding[0] / 2 - box.top;
|
|
1472
|
+
}
|
|
1473
|
+
this.canvasWidth = canvasWidth;
|
|
1474
|
+
this.canvasHeight = canvasHeight;
|
|
1475
|
+
this.zoom = zoom;
|
|
1476
|
+
this.viewBox = viewBox;
|
|
1477
|
+
this.setScrollLeft(scrollLeft);
|
|
1478
|
+
this.setScrollTop(scrollTop);
|
|
1479
|
+
this.change();
|
|
1480
|
+
}
|
|
1481
|
+
setScrollLeft(left) {
|
|
1482
|
+
const hideScrollbar = this.board.options.hideScrollbar;
|
|
1483
|
+
const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
1484
|
+
const width = this.canvasWidth - this.width + scrollBarWidth;
|
|
1485
|
+
this.scrollLeft = left < 0 ? 0 : left > width ? width : left;
|
|
1486
|
+
}
|
|
1487
|
+
setScrollTop(top) {
|
|
1488
|
+
const hideScrollbar = this.board.options.hideScrollbar;
|
|
1489
|
+
const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
|
|
1490
|
+
const height = this.canvasHeight - this.height + scrollBarWidth;
|
|
1491
|
+
this.scrollTop = top < 0 ? 0 : top > height ? height : top;
|
|
1492
|
+
}
|
|
1493
|
+
setScroll(left, top) {
|
|
1494
|
+
this.setScrollLeft(left);
|
|
1495
|
+
this.setScrollTop(top);
|
|
1496
|
+
this.change();
|
|
1497
|
+
}
|
|
1498
|
+
moveTo(point, zoom) {
|
|
1499
|
+
zoom = zoom !== null && zoom !== void 0 ? zoom : this.zoom;
|
|
1500
|
+
const r = invertViewport([0, 0], this.matrix);
|
|
1501
|
+
this.setScroll(this.scrollLeft + (point[0] - r[0]) * zoom, this.scrollTop + (point[1] - r[1]) * zoom);
|
|
1502
|
+
}
|
|
1503
|
+
scrollIntoView(node) {
|
|
1504
|
+
const canvasRect = this.host.getBoundingClientRect();
|
|
1505
|
+
if (!(canvasRect.width <= this.width && canvasRect.height <= this.height)) {
|
|
1506
|
+
const point = convertViewport([node.x, node.y], this.matrix);
|
|
1507
|
+
const fullPoint = convertViewport([node.x + node.width, node.y + node.height], this.matrix);
|
|
1508
|
+
const width = this.width;
|
|
1509
|
+
const height = this.height;
|
|
1510
|
+
let left = this.scrollLeft;
|
|
1511
|
+
let top = this.scrollTop;
|
|
1512
|
+
if (fullPoint[0] > width - SCROLL_BAR_WIDTH) {
|
|
1513
|
+
left += fullPoint[0] - width + SCROLL_BAR_WIDTH;
|
|
1514
|
+
}
|
|
1515
|
+
if (fullPoint[1] > height - SCROLL_BAR_WIDTH) {
|
|
1516
|
+
top += fullPoint[1] - height + SCROLL_BAR_WIDTH;
|
|
1517
|
+
}
|
|
1518
|
+
(left === this.scrollLeft && top === this.scrollTop) || this.setScroll(left, top);
|
|
1455
1519
|
}
|
|
1456
|
-
this.setScroll(scrollLeft, scrollTop);
|
|
1457
|
-
this.updateViewport();
|
|
1458
1520
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
const offsetXRatio = this.board.viewport.offsetXRatio;
|
|
1462
|
-
const offsetYRatio = this.board.viewport.offsetYRatio;
|
|
1463
|
-
const viewportBox = getViewportClientBox(this.board);
|
|
1464
|
-
const { minX, minY, width, height, viewportWidth, viewportHeight } = viewBox;
|
|
1465
|
-
const box = [minX, minY, width, height];
|
|
1466
|
-
this.scrollLeft = (viewportWidth - viewportBox.width) * offsetXRatio;
|
|
1467
|
-
this.scrollTop = (viewportHeight - viewportBox.height) * offsetYRatio;
|
|
1521
|
+
change() {
|
|
1522
|
+
this.resizeViewport();
|
|
1468
1523
|
this.renderer2.setStyle(this.host, 'display', 'block');
|
|
1469
|
-
this.renderer2.setStyle(this.host, 'width', `${
|
|
1470
|
-
this.renderer2.setStyle(this.host, 'height', `${
|
|
1471
|
-
if (
|
|
1472
|
-
this.renderer2.setAttribute(this.host, 'viewBox',
|
|
1524
|
+
this.renderer2.setStyle(this.host, 'width', `${this.canvasWidth}px`);
|
|
1525
|
+
this.renderer2.setStyle(this.host, 'height', `${this.canvasHeight}px`);
|
|
1526
|
+
if (this.viewBox && this.viewBox[2] > 0 && this.viewBox[3] > 0) {
|
|
1527
|
+
this.renderer2.setAttribute(this.host, 'viewBox', this.viewBox.join(','));
|
|
1473
1528
|
}
|
|
1474
|
-
this.
|
|
1529
|
+
this.contentContainer.nativeElement.scrollLeft = this.scrollLeft;
|
|
1530
|
+
this.contentContainer.nativeElement.scrollTop = this.scrollTop;
|
|
1475
1531
|
this.setMatrix();
|
|
1532
|
+
this.setViewportSetting();
|
|
1533
|
+
this.viewportCanvasBox = getViewportCanvasBox(this.board, this.matrix);
|
|
1534
|
+
}
|
|
1535
|
+
restoreCanvasPoint(point, zoom) {
|
|
1536
|
+
zoom = zoom !== null && zoom !== void 0 ? zoom : this.zoom;
|
|
1537
|
+
this.setViewport(zoom);
|
|
1538
|
+
this.moveTo(point, zoom);
|
|
1539
|
+
}
|
|
1540
|
+
initCanvas(viewport) {
|
|
1541
|
+
const canvasPoint = viewport === null || viewport === void 0 ? void 0 : viewport.canvasPoint;
|
|
1542
|
+
if (canvasPoint) {
|
|
1543
|
+
this.restoreCanvasPoint(canvasPoint, viewport.zoom);
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
this.setViewport(viewport.zoom);
|
|
1547
|
+
this.setScroll(this.scrollLeft, this.scrollTop);
|
|
1548
|
+
}
|
|
1476
1549
|
}
|
|
1477
|
-
|
|
1478
|
-
this.
|
|
1479
|
-
|
|
1480
|
-
this.
|
|
1550
|
+
focusGraphicCenter() {
|
|
1551
|
+
const rootGroup = this.board.host.firstChild;
|
|
1552
|
+
const rootGroupBox = rootGroup.getBBox();
|
|
1553
|
+
this.focus([rootGroupBox.x + rootGroupBox.width / 2, rootGroupBox.y + rootGroupBox.height / 2]);
|
|
1554
|
+
this.change();
|
|
1555
|
+
this.setViewport(1);
|
|
1556
|
+
}
|
|
1557
|
+
focus(point) {
|
|
1558
|
+
const clientBox = getViewportClientBox(this.board);
|
|
1559
|
+
const matrix = transformMat3([], [point[0], point[1], 1], this.matrix);
|
|
1560
|
+
const newPoint = [clientBox.width / 2, clientBox.height / 2];
|
|
1561
|
+
const scrollLeft = newPoint[0] - matrix[0];
|
|
1562
|
+
const scrollTop = newPoint[1] - matrix[1];
|
|
1563
|
+
this.setScrollLeft(this.scrollLeft - scrollLeft);
|
|
1564
|
+
this.setScrollTop(this.scrollTop - scrollTop);
|
|
1565
|
+
this.setMatrix();
|
|
1566
|
+
}
|
|
1567
|
+
resetFocusPoint() {
|
|
1568
|
+
const clientBox = getViewportClientBox(this.board);
|
|
1569
|
+
this.focusPoint = [clientBox.x + clientBox.width / 2, clientBox.y + clientBox.height / 2];
|
|
1570
|
+
}
|
|
1571
|
+
setViewportSetting() {
|
|
1572
|
+
var _a;
|
|
1573
|
+
const viewport = (_a = this.board) === null || _a === void 0 ? void 0 : _a.viewport;
|
|
1574
|
+
Transforms.setViewport(this.board, Object.assign(Object.assign({}, viewport), { zoom: this.zoom, canvasPoint: invertViewport([0, 0], this.matrix) }));
|
|
1575
|
+
}
|
|
1576
|
+
changeSize() {
|
|
1577
|
+
this.updateViewport();
|
|
1481
1578
|
}
|
|
1482
1579
|
// 拖拽模式
|
|
1483
1580
|
changeMoveMode(cursorStatus) {
|
|
@@ -1486,52 +1583,40 @@ class PlaitBoardComponent {
|
|
|
1486
1583
|
}
|
|
1487
1584
|
// 适应画布
|
|
1488
1585
|
adaptHandle() {
|
|
1489
|
-
const
|
|
1586
|
+
const clientBox = getViewportClientBox(this.board);
|
|
1490
1587
|
const rootGroup = this.host.firstChild;
|
|
1491
1588
|
const rootGroupBox = rootGroup.getBBox();
|
|
1492
|
-
const viewportWidth =
|
|
1493
|
-
const viewportHeight =
|
|
1494
|
-
let zoom = this.
|
|
1589
|
+
const viewportWidth = clientBox.width - 2 * this.autoFitPadding;
|
|
1590
|
+
const viewportHeight = clientBox.height - 2 * this.autoFitPadding;
|
|
1591
|
+
let zoom = this.zoom;
|
|
1495
1592
|
if (viewportWidth < rootGroupBox.width || viewportHeight < rootGroupBox.height) {
|
|
1496
1593
|
zoom = Math.min(viewportWidth / rootGroupBox.width, viewportHeight / rootGroupBox.height);
|
|
1497
1594
|
}
|
|
1498
1595
|
else {
|
|
1499
1596
|
zoom = 1;
|
|
1500
1597
|
}
|
|
1501
|
-
this.
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
offsetYRatio: 0.5
|
|
1505
|
-
});
|
|
1598
|
+
this.focus([rootGroupBox.x + rootGroupBox.width / 2, rootGroupBox.y + rootGroupBox.height / 2]);
|
|
1599
|
+
this.resetFocusPoint();
|
|
1600
|
+
this.setViewport(zoom);
|
|
1506
1601
|
}
|
|
1507
1602
|
// 放大
|
|
1508
1603
|
zoomInHandle() {
|
|
1509
|
-
|
|
1510
|
-
this.setViewport({
|
|
1511
|
-
zoom: calculateZoom(zoom + 0.1)
|
|
1512
|
-
});
|
|
1604
|
+
this.setViewport(this.zoom + 0.1);
|
|
1513
1605
|
}
|
|
1514
1606
|
// 缩小
|
|
1515
1607
|
zoomOutHandle() {
|
|
1516
|
-
|
|
1517
|
-
this.setViewport({
|
|
1518
|
-
zoom: calculateZoom(zoom - 0.1)
|
|
1519
|
-
});
|
|
1608
|
+
this.setViewport(this.zoom - 0.1);
|
|
1520
1609
|
}
|
|
1521
1610
|
resetZoomHandel() {
|
|
1522
|
-
this.setViewport(
|
|
1523
|
-
zoom: 1
|
|
1524
|
-
});
|
|
1525
|
-
}
|
|
1526
|
-
setViewport(options) {
|
|
1527
|
-
var _a;
|
|
1528
|
-
const viewport = (_a = this.board) === null || _a === void 0 ? void 0 : _a.viewport;
|
|
1529
|
-
Transforms.setViewport(this.board, Object.assign(Object.assign({}, viewport), options));
|
|
1611
|
+
this.setViewport(1);
|
|
1530
1612
|
}
|
|
1531
1613
|
ngOnDestroy() {
|
|
1532
1614
|
this.destroy$.next();
|
|
1533
1615
|
this.destroy$.complete();
|
|
1534
1616
|
HOST_TO_ROUGH_SVG.delete(this.host);
|
|
1617
|
+
if (this.resizeObserver) {
|
|
1618
|
+
this.resizeObserver.disconnect();
|
|
1619
|
+
}
|
|
1535
1620
|
}
|
|
1536
1621
|
movingChange(isMoving) {
|
|
1537
1622
|
this.isMoving = isMoving;
|
|
@@ -1539,7 +1624,7 @@ class PlaitBoardComponent {
|
|
|
1539
1624
|
}
|
|
1540
1625
|
PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
1541
1626
|
PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: PlaitBoardComponent, selector: "plait-board", inputs: { plaitValue: "plaitValue", plaitViewport: "plaitViewport", plaitPlugins: "plaitPlugins", plaitOptions: "plaitOptions" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.moving": "this.moving", "class.focused": "this.focused" } }, queries: [{ propertyName: "toolbarTemplateRef", first: true, predicate: ["plaitToolbar"], descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }, { propertyName: "contentContainer", first: true, predicate: ["container"], descendants: true, read: ElementRef, static: true }], usesOnChanges: true, ngImport: i0, template: `
|
|
1542
|
-
<div class="container" #container>
|
|
1627
|
+
<div class="viewport-container" #container>
|
|
1543
1628
|
<svg #svg width="100%" height="100%" style="position: relative;"></svg>
|
|
1544
1629
|
<plait-element
|
|
1545
1630
|
*ngFor="let item of board.children; let index = index; trackBy: trackBy"
|
|
@@ -1568,7 +1653,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1568
1653
|
args: [{
|
|
1569
1654
|
selector: 'plait-board',
|
|
1570
1655
|
template: `
|
|
1571
|
-
<div class="container" #container>
|
|
1656
|
+
<div class="viewport-container" #container>
|
|
1572
1657
|
<svg #svg width="100%" height="100%" style="position: relative;"></svg>
|
|
1573
1658
|
<plait-element
|
|
1574
1659
|
*ngFor="let item of board.children; let index = index; trackBy: trackBy"
|
|
@@ -1652,5 +1737,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1652
1737
|
* Generated bundle index. Do not edit.
|
|
1653
1738
|
*/
|
|
1654
1739
|
|
|
1655
|
-
export { BOARD_TO_ON_CHANGE, BaseCursorStatus, CLIP_BOARD_FORMAT_KEY, FLUSHING, HOST_TO_ROUGH_SVG, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MERGING, NS, PLAIT_BOARD_TO_COMPONENT, Path, PlaitBoardComponent, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitToolbarComponent, SAVING, SCROLL_BAR_WIDTH, Transforms, Viewport, calculateBBox, calculateZoom, createG, createSVG, createText, distanceBetweenPointAndPoint, distanceBetweenPointAndSegment,
|
|
1740
|
+
export { BOARD_TO_ON_CHANGE, BaseCursorStatus, CLIP_BOARD_FORMAT_KEY, FLUSHING, HOST_TO_ROUGH_SVG, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MERGING, NS, PLAIT_BOARD_TO_COMPONENT, Path, PlaitBoardComponent, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitToolbarComponent, SAVING, SCROLL_BAR_WIDTH, Transforms, Viewport, calculateBBox, calculateZoom, convertPoint, convertViewport, createG, createSVG, createText, distanceBetweenPointAndPoint, distanceBetweenPointAndSegment, getGraphicsBBox, getViewportCanvasBox, getViewportClientBox, hotkeys, idCreator, inverse, invert, invertClient, invertViewport, isNoSelectionElement, isNullOrUndefined, isSetViewportOperation, rotate, shouldClear, shouldMerge, shouldSave, toPoint, toRectangleClient, transformMat3, transformPoint, transformPoints, updateCursorStatus };
|
|
1656
1741
|
//# sourceMappingURL=plait-core.mjs.map
|