@plait/core 0.2.4 → 0.4.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.
Files changed (58) hide show
  1. package/board/board.component.d.ts +11 -10
  2. package/board/board.component.interface.d.ts +2 -1
  3. package/constants/index.d.ts +6 -0
  4. package/core/island/island-base.component.d.ts +16 -0
  5. package/esm2020/board/board.component.interface.mjs +1 -1
  6. package/esm2020/board/board.component.mjs +52 -55
  7. package/esm2020/constants/index.mjs +7 -1
  8. package/esm2020/core/element/plugin-element.mjs +2 -2
  9. package/esm2020/core/island/island-base.component.mjs +33 -0
  10. package/esm2020/interfaces/board.mjs +11 -2
  11. package/esm2020/interfaces/index.mjs +2 -1
  12. package/esm2020/interfaces/node.mjs +1 -1
  13. package/esm2020/interfaces/path-ref.mjs +15 -0
  14. package/esm2020/interfaces/plugin-key.mjs +5 -0
  15. package/esm2020/plait.module.mjs +3 -4
  16. package/esm2020/plugins/create-board.mjs +32 -3
  17. package/esm2020/plugins/with-hand.mjs +10 -15
  18. package/esm2020/plugins/with-options.mjs +13 -0
  19. package/esm2020/plugins/with-selection.mjs +27 -17
  20. package/esm2020/public-api.mjs +4 -2
  21. package/esm2020/testing/core/create-board.mjs +13 -0
  22. package/esm2020/testing/core/fake-weak-map.mjs +18 -0
  23. package/esm2020/testing/core/index.mjs +3 -0
  24. package/esm2020/testing/index.mjs +2 -0
  25. package/esm2020/transforms/board.mjs +63 -4
  26. package/esm2020/utils/dom/common.mjs +12 -1
  27. package/esm2020/utils/draw/line.mjs +21 -1
  28. package/esm2020/utils/selected-element.mjs +5 -3
  29. package/esm2020/utils/viewport.mjs +2 -55
  30. package/esm2020/utils/weak-maps.mjs +2 -1
  31. package/fesm2015/plait-core.mjs +621 -507
  32. package/fesm2015/plait-core.mjs.map +1 -1
  33. package/fesm2020/plait-core.mjs +635 -521
  34. package/fesm2020/plait-core.mjs.map +1 -1
  35. package/interfaces/board.d.ts +8 -2
  36. package/interfaces/index.d.ts +1 -0
  37. package/interfaces/node.d.ts +1 -1
  38. package/interfaces/path-ref.d.ts +13 -0
  39. package/interfaces/plugin-key.d.ts +3 -0
  40. package/package.json +3 -3
  41. package/plait.module.d.ts +2 -3
  42. package/plugins/create-board.d.ts +1 -1
  43. package/plugins/with-options.d.ts +9 -0
  44. package/plugins/with-selection.d.ts +4 -0
  45. package/public-api.d.ts +3 -1
  46. package/styles/styles.scss +0 -73
  47. package/testing/core/create-board.d.ts +6 -0
  48. package/testing/core/fake-weak-map.d.ts +4 -0
  49. package/testing/core/index.d.ts +2 -0
  50. package/testing/index.d.ts +1 -0
  51. package/transforms/board.d.ts +9 -2
  52. package/utils/dom/common.d.ts +3 -0
  53. package/utils/draw/line.d.ts +1 -0
  54. package/utils/selected-element.d.ts +2 -2
  55. package/utils/viewport.d.ts +0 -3
  56. package/utils/weak-maps.d.ts +2 -0
  57. package/core/toolbar/toolbar.component.d.ts +0 -21
  58. package/esm2020/core/toolbar/toolbar.component.mjs +0 -60
@@ -1,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Input, Component, ChangeDetectionStrategy, EventEmitter, HostBinding, Output, ElementRef, ViewChild, ContentChild, NgModule } from '@angular/core';
2
+ import { Directive, Input, Component, ChangeDetectionStrategy, EventEmitter, ElementRef, Output, HostBinding, ViewChild, ContentChildren, NgModule } from '@angular/core';
3
3
  import rough from 'roughjs/bin/rough';
4
4
  import { timer, Subject, fromEvent } from 'rxjs';
5
- import { takeUntil, filter } from 'rxjs/operators';
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
8
  import * as i1 from '@angular/common';
@@ -26,6 +26,7 @@ const BOARD_TO_IS_SELECTION_MOVING = new WeakMap();
26
26
  // save no standard selected elements
27
27
  const BOARD_TO_TEMPORARY_ELEMENTS = new WeakMap();
28
28
  const BOARD_TO_MOVING_ELEMENT = new WeakMap();
29
+ const PATH_REFS = new WeakMap();
29
30
 
30
31
  function depthFirstRecursion(node, callback, recursion) {
31
32
  if (!recursion || recursion(node)) {
@@ -132,6 +133,15 @@ const PlaitBoard = {
132
133
  },
133
134
  hasBeenTextEditing(board) {
134
135
  return !!IS_TEXT_EDITABLE.get(board);
136
+ },
137
+ getPointer(board) {
138
+ return board.pointer;
139
+ },
140
+ isPointer(board, pointer) {
141
+ return board.pointer === pointer;
142
+ },
143
+ getMovingPoint(board) {
144
+ return BOARD_TO_MOVING_POINT.get(board);
135
145
  }
136
146
  };
137
147
 
@@ -568,12 +578,74 @@ function setSelectionWithTemporaryElements(board, elements) {
568
578
  });
569
579
  }
570
580
 
571
- function setViewport$1(board, viewport) {
581
+ function setViewport(board, viewport) {
572
582
  const operation = { type: 'set_viewport', properties: board.viewport, newProperties: viewport };
573
583
  board.apply(operation);
574
584
  }
575
585
  const ViewportTransforms = {
576
- setViewport: setViewport$1
586
+ setViewport
587
+ };
588
+
589
+ const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
590
+ const SCROLL_BAR_WIDTH = 20;
591
+ const MAX_RADIUS = 16;
592
+ const POINTER_BUTTON = {
593
+ MAIN: 0,
594
+ WHEEL: 1,
595
+ SECONDARY: 2,
596
+ TOUCH: -1,
597
+ };
598
+
599
+ const NS = 'http://www.w3.org/2000/svg';
600
+ function toPoint(x, y, container) {
601
+ const rect = container.getBoundingClientRect();
602
+ return [x - rect.x, y - rect.y];
603
+ }
604
+ function createG() {
605
+ const newG = document.createElementNS(NS, 'g');
606
+ return newG;
607
+ }
608
+ function createPath() {
609
+ const newG = document.createElementNS(NS, 'path');
610
+ return newG;
611
+ }
612
+ function createSVG() {
613
+ const svg = document.createElementNS(NS, 'svg');
614
+ return svg;
615
+ }
616
+ function createText(x, y, fill, textContent) {
617
+ var text = document.createElementNS(NS, 'text');
618
+ text.setAttribute('x', `${x}`);
619
+ text.setAttribute('y', `${y}`);
620
+ text.setAttribute('fill', fill);
621
+ text.textContent = textContent;
622
+ return text;
623
+ }
624
+ /**
625
+ * Check if a DOM node is an element node.
626
+ */
627
+ const isDOMElement = (value) => {
628
+ return isDOMNode(value) && value.nodeType === 1;
629
+ };
630
+ /**
631
+ * Check if a value is a DOM node.
632
+ */
633
+ const isDOMNode = (value) => {
634
+ return value instanceof window.Node;
635
+ };
636
+ const hasInputOrTextareaTarget = (target) => {
637
+ if (isDOMElement(target)) {
638
+ if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
639
+ return true;
640
+ }
641
+ }
642
+ return false;
643
+ };
644
+ const isSecondaryPointer = (event) => {
645
+ return event.button === POINTER_BUTTON.SECONDARY;
646
+ };
647
+ const isMainPointer = (event) => {
648
+ return event.button === POINTER_BUTTON.MAIN;
577
649
  };
578
650
 
579
651
  // https://stackoverflow.com/a/6853926/232122
@@ -624,109 +696,17 @@ function distanceBetweenPointAndRectangle(x, y, rect) {
624
696
  return Math.sqrt(dx * dx + dy * dy);
625
697
  }
626
698
 
627
- function transformPoints(board, points) {
628
- const newPoints = points.map(point => {
629
- return transformPoint(board, point);
630
- });
631
- return newPoints;
632
- }
633
- function transformPoint(board, point) {
634
- const { width, height } = PlaitBoard.getHost(board).getBoundingClientRect();
635
- const viewBox = PlaitBoard.getHost(board).viewBox.baseVal;
636
- const x = (point[0] / width) * viewBox.width + viewBox.x;
637
- const y = (point[1] / height) * viewBox.height + viewBox.y;
638
- const newPoint = [x, y];
639
- return newPoint;
640
- }
641
- function isInPlaitBoard(board, x, y) {
642
- const plaitBoardElement = PlaitBoard.getBoardNativeElement(board);
643
- const plaitBoardRect = plaitBoardElement.getBoundingClientRect();
644
- const distances = distanceBetweenPointAndRectangle(x, y, plaitBoardRect);
645
- return distances === 0;
646
- }
647
-
648
- const NS = 'http://www.w3.org/2000/svg';
649
- function toPoint(x, y, container) {
650
- const rect = container.getBoundingClientRect();
651
- return [x - rect.x, y - rect.y];
652
- }
653
- function createG() {
654
- const newG = document.createElementNS(NS, 'g');
655
- return newG;
656
- }
657
- function createSVG() {
658
- const svg = document.createElementNS(NS, 'svg');
659
- return svg;
660
- }
661
- function createText(x, y, fill, textContent) {
662
- var text = document.createElementNS(NS, 'text');
663
- text.setAttribute('x', `${x}`);
664
- text.setAttribute('y', `${y}`);
665
- text.setAttribute('fill', fill);
666
- text.textContent = textContent;
667
- return text;
668
- }
669
- /**
670
- * Check if a DOM node is an element node.
671
- */
672
- const isDOMElement = (value) => {
673
- return isDOMNode(value) && value.nodeType === 1;
674
- };
675
- /**
676
- * Check if a value is a DOM node.
677
- */
678
- const isDOMNode = (value) => {
679
- return value instanceof window.Node;
680
- };
681
- const hasInputOrTextareaTarget = (target) => {
682
- if (isDOMElement(target)) {
683
- if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
684
- return true;
685
- }
686
- }
687
- return false;
688
- };
689
-
690
- function createForeignObject(x, y, width, height) {
691
- var newForeignObject = document.createElementNS(NS, 'foreignObject');
692
- newForeignObject.setAttribute('x', `${x}`);
693
- newForeignObject.setAttribute('y', `${y}`);
694
- newForeignObject.setAttribute('width', `${width}`);
695
- newForeignObject.setAttribute('height', `${height}`);
696
- return newForeignObject;
697
- }
698
- function updateForeignObject(g, width, height, x, y) {
699
- const foreignObject = g.querySelector('foreignObject');
700
- if (foreignObject) {
701
- foreignObject.setAttribute('width', `${width}`);
702
- foreignObject.setAttribute('height', `${height}`);
703
- foreignObject.setAttribute('x', `${x}`);
704
- foreignObject.setAttribute('y', `${y}`);
705
- }
706
- }
707
-
708
- const IS_IOS = typeof navigator !== 'undefined' &&
709
- typeof window !== 'undefined' &&
710
- /iPad|iPhone|iPod/.test(navigator.userAgent) &&
711
- !window.MSStream;
712
- const IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
713
- const IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
714
- const IS_SAFARI = typeof navigator !== 'undefined' && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
715
- // "modern" Edge was released at 79.x
716
- const IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent);
717
- const IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent);
718
- // Native beforeInput events don't work well with react on Chrome 75 and older, Chrome 76+ can use beforeInput
719
- const IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent);
720
-
721
699
  /**
722
700
  * Extendable Custom Types Interface
723
701
  */
724
702
 
725
- const getHitElements = (board) => {
703
+ const getHitElements = (board, selection) => {
704
+ const realSelection = selection || board.selection;
726
705
  const selectedElements = [];
727
706
  depthFirstRecursion(board, node => {
728
707
  if (!PlaitBoard.isBoard(node) &&
729
- board.selection?.ranges.some(range => {
708
+ realSelection &&
709
+ realSelection.ranges.some(range => {
730
710
  return board.isHitSelection(node, range);
731
711
  })) {
732
712
  selectedElements.push(node);
@@ -807,7 +787,7 @@ class PlaitPluginElementComponent {
807
787
  }
808
788
  }
809
789
  else {
810
- if (PlaitElement.isRootElement(this.element) && this.element.children && this.element.children.length > 0) {
790
+ if (PlaitElement.isRootElement(this.element) && this.element.children) {
811
791
  this.g = createG();
812
792
  this.rootG = createG();
813
793
  this.rootG.append(this.g);
@@ -859,174 +839,66 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
859
839
  }] } });
860
840
  const ELEMENT_TO_COMPONENT = new WeakMap();
861
841
 
862
- const PlaitElement = {
863
- isRootElement(value) {
864
- const parent = NODE_TO_PARENT.get(value);
865
- if (parent && PlaitBoard.isBoard(parent)) {
866
- return true;
867
- }
868
- else {
869
- return false;
870
- }
871
- },
872
- getComponent(value) {
873
- return ELEMENT_TO_COMPONENT.get(value);
842
+ function transformPoints(board, points) {
843
+ const newPoints = points.map(point => {
844
+ return transformPoint(board, point);
845
+ });
846
+ return newPoints;
847
+ }
848
+ function transformPoint(board, point) {
849
+ const { width, height } = PlaitBoard.getHost(board).getBoundingClientRect();
850
+ const viewBox = PlaitBoard.getHost(board).viewBox.baseVal;
851
+ const x = (point[0] / width) * viewBox.width + viewBox.x;
852
+ const y = (point[1] / height) * viewBox.height + viewBox.y;
853
+ const newPoint = [x, y];
854
+ return newPoint;
855
+ }
856
+ function isInPlaitBoard(board, x, y) {
857
+ const plaitBoardElement = PlaitBoard.getBoardNativeElement(board);
858
+ const plaitBoardRect = plaitBoardElement.getBoundingClientRect();
859
+ const distances = distanceBetweenPointAndRectangle(x, y, plaitBoardRect);
860
+ return distances === 0;
861
+ }
862
+
863
+ function createForeignObject(x, y, width, height) {
864
+ var newForeignObject = document.createElementNS(NS, 'foreignObject');
865
+ newForeignObject.setAttribute('x', `${x}`);
866
+ newForeignObject.setAttribute('y', `${y}`);
867
+ newForeignObject.setAttribute('width', `${width}`);
868
+ newForeignObject.setAttribute('height', `${height}`);
869
+ return newForeignObject;
870
+ }
871
+ function updateForeignObject(g, width, height, x, y) {
872
+ const foreignObject = g.querySelector('foreignObject');
873
+ if (foreignObject) {
874
+ foreignObject.setAttribute('width', `${width}`);
875
+ foreignObject.setAttribute('height', `${height}`);
876
+ foreignObject.setAttribute('x', `${x}`);
877
+ foreignObject.setAttribute('y', `${y}`);
874
878
  }
875
- };
879
+ }
876
880
 
877
- const RectangleClient = {
878
- isHit: (origin, target) => {
879
- const minX = origin.x < target.x ? origin.x : target.x;
880
- const maxX = origin.x + origin.width > target.x + target.width ? origin.x + origin.width : target.x + target.width;
881
- const minY = origin.y < target.y ? origin.y : target.y;
882
- const maxY = origin.y + origin.height > target.y + target.height ? origin.y + origin.height : target.y + target.height;
883
- // float calculate error( eg: 1.4210854715202004e-14 > 0)
884
- if (Math.floor(maxX - minX - origin.width - target.width) <= 0 && Math.floor(maxY - minY - origin.height - target.height) <= 0) {
885
- return true;
886
- }
887
- else {
888
- return false;
889
- }
890
- },
891
- toRectangleClient: (points) => {
892
- const xArray = points.map(ele => ele[0]);
893
- const yArray = points.map(ele => ele[1]);
894
- const xMin = Math.min(...xArray);
895
- const xMax = Math.max(...xArray);
896
- const yMin = Math.min(...yArray);
897
- const yMax = Math.max(...yArray);
898
- const rect = { x: xMin, y: yMin, width: xMax - xMin, height: yMax - yMin };
899
- return rect;
900
- },
901
- getOutlineRectangle: (rectangle, offset) => {
902
- return {
903
- x: rectangle.x + offset,
904
- y: rectangle.y + offset,
905
- width: rectangle.width + Math.abs(offset) * 2,
906
- height: rectangle.height + Math.abs(offset) * 2
907
- };
908
- },
909
- isEqual: (rectangle, otherRectangle) => {
910
- return (rectangle.x === otherRectangle.x &&
911
- rectangle.y === otherRectangle.y &&
912
- rectangle.width === otherRectangle.width &&
913
- rectangle.height === otherRectangle.height);
881
+ const IS_IOS = typeof navigator !== 'undefined' &&
882
+ typeof window !== 'undefined' &&
883
+ /iPad|iPhone|iPod/.test(navigator.userAgent) &&
884
+ !window.MSStream;
885
+ const IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
886
+ const IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
887
+ const IS_SAFARI = typeof navigator !== 'undefined' && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
888
+ // "modern" Edge was released at 79.x
889
+ const IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent);
890
+ const IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent);
891
+ // Native beforeInput events don't work well with react on Chrome 75 and older, Chrome 76+ can use beforeInput
892
+ const IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent);
893
+
894
+ /**
895
+ * Check whether to merge an operation into the previous operation.
896
+ */
897
+ const shouldMerge = (op, prev) => {
898
+ if (op.type === 'set_viewport' && op.type === prev?.type) {
899
+ return true;
914
900
  }
915
- };
916
-
917
- const isSetViewportOperation = (value) => {
918
- return value.type === 'set_viewport';
919
- };
920
- const inverse = (op) => {
921
- switch (op.type) {
922
- case 'insert_node': {
923
- return { ...op, type: 'remove_node' };
924
- }
925
- case 'remove_node': {
926
- return { ...op, type: 'insert_node' };
927
- }
928
- case 'move_node': {
929
- const { newPath, path } = op;
930
- // PERF: in this case the move operation is a no-op anyways.
931
- if (Path.equals(newPath, path)) {
932
- return op;
933
- }
934
- // when operation path is [0,0] -> [0,2], should exec Path.transform to get [0,1] -> [0,0]
935
- // shoud not return [0,2] -> [0,0] #WIK-8981
936
- // if (Path.isSibling(path, newPath)) {
937
- // return { ...op, path: newPath, newPath: path };
938
- // }
939
- // If the move does not happen within a single parent it is possible
940
- // for the move to impact the true path to the location where the node
941
- // was removed from and where it was inserted. We have to adjust for this
942
- // and find the original path. We can accomplish this (only in non-sibling)
943
- // moves by looking at the impact of the move operation on the node
944
- // after the original move path.
945
- const inversePath = Path.transform(path, op);
946
- const inverseNewPath = Path.transform(Path.next(path), op);
947
- return { ...op, path: inversePath, newPath: inverseNewPath };
948
- }
949
- case 'set_node': {
950
- const { properties, newProperties } = op;
951
- return { ...op, properties: newProperties, newProperties: properties };
952
- }
953
- case 'set_selection': {
954
- const { properties, newProperties } = op;
955
- if (properties == null) {
956
- return {
957
- ...op,
958
- properties: newProperties,
959
- newProperties: null
960
- };
961
- }
962
- else if (newProperties == null) {
963
- return {
964
- ...op,
965
- properties: null,
966
- newProperties: properties
967
- };
968
- }
969
- else {
970
- return { ...op, properties: newProperties, newProperties: properties };
971
- }
972
- }
973
- case 'set_viewport': {
974
- const { properties, newProperties } = op;
975
- if (properties == null) {
976
- return {
977
- ...op,
978
- properties: newProperties,
979
- newProperties: newProperties
980
- };
981
- }
982
- else if (newProperties == null) {
983
- return {
984
- ...op,
985
- properties: properties,
986
- newProperties: properties
987
- };
988
- }
989
- else {
990
- return { ...op, properties: newProperties, newProperties: properties };
991
- }
992
- }
993
- }
994
- };
995
- const PlaitOperation = {
996
- isSetViewportOperation,
997
- inverse
998
- };
999
-
1000
- const Point = {
1001
- isEquals(point, otherPoint) {
1002
- return point && otherPoint && point[0] === otherPoint[0] && point[1] === otherPoint[1];
1003
- }
1004
- };
1005
-
1006
- const SELECTION_BORDER_COLOR = '#6698FF';
1007
- const SELECTION_FILL_COLOR = '#6698FF19'; // 主色 0.1 透明度
1008
- const Selection = {
1009
- isCollapsed(selection) {
1010
- if (selection.anchor[0] == selection.focus[0] && selection.anchor[1] === selection.focus[1]) {
1011
- return true;
1012
- }
1013
- else {
1014
- return false;
1015
- }
1016
- }
1017
- };
1018
-
1019
- const SAVING = new WeakMap();
1020
- const MERGING = new WeakMap();
1021
-
1022
- /**
1023
- * Check whether to merge an operation into the previous operation.
1024
- */
1025
- const shouldMerge = (op, prev) => {
1026
- if (op.type === 'set_viewport' && op.type === prev?.type) {
1027
- return true;
1028
- }
1029
- return false;
901
+ return false;
1030
902
  };
1031
903
  /**
1032
904
  * Check whether an operation needs to be saved to the history.
@@ -1187,10 +1059,6 @@ function idCreator(length = 5) {
1187
1059
  return key;
1188
1060
  }
1189
1061
 
1190
- const CLIP_BOARD_FORMAT_KEY = 'x-plait-fragment';
1191
- const SCROLL_BAR_WIDTH = 20;
1192
- const MAX_RADIUS = 16;
1193
-
1194
1062
  /**
1195
1063
  * drawRoundRectangle
1196
1064
  */
@@ -1253,37 +1121,268 @@ function drawAbstractRoundRectangle(rs, x1, y1, x2, y2, isHorizontal, options) {
1253
1121
  l0,-${handleSideLine}
1254
1122
  a${radius},${radius},0,0,1,${radius},-${radius}`, options);
1255
1123
  }
1256
- }
1124
+ }
1125
+
1126
+ function arrowPoints(start, end, maxHypotenuseLength = 10, degree = 40) {
1127
+ const width = Math.abs(start[0] - end[0]);
1128
+ const height = Math.abs(start[1] - end[1]);
1129
+ let hypotenuse = Math.hypot(width, height); // 斜边
1130
+ const realRotateLine = hypotenuse > maxHypotenuseLength * 2 ? maxHypotenuseLength : hypotenuse / 2;
1131
+ const rotateWidth = (realRotateLine / hypotenuse) * width;
1132
+ const rotateHeight = (realRotateLine / hypotenuse) * height;
1133
+ const rotatePoint = [
1134
+ end[0] > start[0] ? end[0] - rotateWidth : end[0] + rotateWidth,
1135
+ end[1] > start[1] ? end[1] - rotateHeight : end[1] + rotateHeight
1136
+ ];
1137
+ const pointRight = rotate(rotatePoint[0], rotatePoint[1], end[0], end[1], (degree * Math.PI) / 180);
1138
+ const pointLeft = rotate(rotatePoint[0], rotatePoint[1], end[0], end[1], (-degree * Math.PI) / 180);
1139
+ return { pointLeft, pointRight };
1140
+ }
1141
+ function drawArrow(rs, start, end, options, maxHypotenuseLength = 10, degree = 40) {
1142
+ const { pointLeft, pointRight } = arrowPoints(start, end, maxHypotenuseLength, degree);
1143
+ const arrowLineLeft = rs.linearPath([pointLeft, end], options);
1144
+ const arrowLineRight = rs.linearPath([pointRight, end], options);
1145
+ return [arrowLineLeft, arrowLineRight];
1146
+ }
1147
+
1148
+ function drawCircle(roughSVG, point, diameter, options) {
1149
+ return roughSVG.circle(point[0], point[1], diameter, options);
1150
+ }
1151
+
1152
+ function drawLine(rs, start, end, options) {
1153
+ return rs.linearPath([start, end], options);
1154
+ }
1155
+ function drawLinearPath(points, options) {
1156
+ const g = createG();
1157
+ const path = createPath();
1158
+ let polylinePath = '';
1159
+ points.forEach((point, index) => {
1160
+ if (index === 0) {
1161
+ polylinePath += `M ${point[0]} ${point[1]} `;
1162
+ }
1163
+ else {
1164
+ polylinePath += `L ${point[0]} ${point[1]} `;
1165
+ }
1166
+ });
1167
+ path.setAttribute('d', polylinePath);
1168
+ path.setAttribute('stroke', `${options?.stroke}`);
1169
+ path.setAttribute('stroke-width', `${options?.strokeWidth}`);
1170
+ path.setAttribute('fill', `none`);
1171
+ g.appendChild(path);
1172
+ return g;
1173
+ }
1174
+
1175
+ let timerId = null;
1176
+ const throttleRAF = (fn) => {
1177
+ const scheduleFunc = () => {
1178
+ timerId = requestAnimationFrame(() => {
1179
+ timerId = null;
1180
+ fn();
1181
+ });
1182
+ };
1183
+ if (timerId !== null) {
1184
+ cancelAnimationFrame(timerId);
1185
+ timerId = null;
1186
+ }
1187
+ scheduleFunc();
1188
+ };
1189
+ const debounce = (func, wait, options) => {
1190
+ let timerSubscription = null;
1191
+ return () => {
1192
+ if (timerSubscription && !timerSubscription.closed) {
1193
+ timerSubscription.unsubscribe();
1194
+ timerSubscription = timer(wait).subscribe(() => {
1195
+ func();
1196
+ });
1197
+ }
1198
+ else {
1199
+ if (options?.leading) {
1200
+ func();
1201
+ }
1202
+ timerSubscription = timer(wait).subscribe();
1203
+ }
1204
+ };
1205
+ };
1206
+
1207
+ const getMovingElements = (board) => {
1208
+ return BOARD_TO_MOVING_ELEMENT.get(board) || [];
1209
+ };
1210
+ const addMovingElements = (board, elements) => {
1211
+ const movingElements = getMovingElements(board);
1212
+ const newElements = elements.filter(item => !movingElements.find(movingElement => movingElement.key === item.key));
1213
+ cacheMovingElements(board, [...movingElements, ...newElements]);
1214
+ };
1215
+ const removeMovingElements = (board) => {
1216
+ BOARD_TO_MOVING_ELEMENT.delete(board);
1217
+ };
1218
+ const cacheMovingElements = (board, elements) => {
1219
+ BOARD_TO_MOVING_ELEMENT.set(board, elements);
1220
+ };
1221
+
1222
+ const PlaitElement = {
1223
+ isRootElement(value) {
1224
+ const parent = NODE_TO_PARENT.get(value);
1225
+ if (parent && PlaitBoard.isBoard(parent)) {
1226
+ return true;
1227
+ }
1228
+ else {
1229
+ return false;
1230
+ }
1231
+ },
1232
+ getComponent(value) {
1233
+ return ELEMENT_TO_COMPONENT.get(value);
1234
+ }
1235
+ };
1236
+
1237
+ const RectangleClient = {
1238
+ isHit: (origin, target) => {
1239
+ const minX = origin.x < target.x ? origin.x : target.x;
1240
+ const maxX = origin.x + origin.width > target.x + target.width ? origin.x + origin.width : target.x + target.width;
1241
+ const minY = origin.y < target.y ? origin.y : target.y;
1242
+ const maxY = origin.y + origin.height > target.y + target.height ? origin.y + origin.height : target.y + target.height;
1243
+ // float calculate error( eg: 1.4210854715202004e-14 > 0)
1244
+ if (Math.floor(maxX - minX - origin.width - target.width) <= 0 && Math.floor(maxY - minY - origin.height - target.height) <= 0) {
1245
+ return true;
1246
+ }
1247
+ else {
1248
+ return false;
1249
+ }
1250
+ },
1251
+ toRectangleClient: (points) => {
1252
+ const xArray = points.map(ele => ele[0]);
1253
+ const yArray = points.map(ele => ele[1]);
1254
+ const xMin = Math.min(...xArray);
1255
+ const xMax = Math.max(...xArray);
1256
+ const yMin = Math.min(...yArray);
1257
+ const yMax = Math.max(...yArray);
1258
+ const rect = { x: xMin, y: yMin, width: xMax - xMin, height: yMax - yMin };
1259
+ return rect;
1260
+ },
1261
+ getOutlineRectangle: (rectangle, offset) => {
1262
+ return {
1263
+ x: rectangle.x + offset,
1264
+ y: rectangle.y + offset,
1265
+ width: rectangle.width + Math.abs(offset) * 2,
1266
+ height: rectangle.height + Math.abs(offset) * 2
1267
+ };
1268
+ },
1269
+ isEqual: (rectangle, otherRectangle) => {
1270
+ return (rectangle.x === otherRectangle.x &&
1271
+ rectangle.y === otherRectangle.y &&
1272
+ rectangle.width === otherRectangle.width &&
1273
+ rectangle.height === otherRectangle.height);
1274
+ }
1275
+ };
1276
+
1277
+ const isSetViewportOperation = (value) => {
1278
+ return value.type === 'set_viewport';
1279
+ };
1280
+ const inverse = (op) => {
1281
+ switch (op.type) {
1282
+ case 'insert_node': {
1283
+ return { ...op, type: 'remove_node' };
1284
+ }
1285
+ case 'remove_node': {
1286
+ return { ...op, type: 'insert_node' };
1287
+ }
1288
+ case 'move_node': {
1289
+ const { newPath, path } = op;
1290
+ // PERF: in this case the move operation is a no-op anyways.
1291
+ if (Path.equals(newPath, path)) {
1292
+ return op;
1293
+ }
1294
+ // when operation path is [0,0] -> [0,2], should exec Path.transform to get [0,1] -> [0,0]
1295
+ // shoud not return [0,2] -> [0,0] #WIK-8981
1296
+ // if (Path.isSibling(path, newPath)) {
1297
+ // return { ...op, path: newPath, newPath: path };
1298
+ // }
1299
+ // If the move does not happen within a single parent it is possible
1300
+ // for the move to impact the true path to the location where the node
1301
+ // was removed from and where it was inserted. We have to adjust for this
1302
+ // and find the original path. We can accomplish this (only in non-sibling)
1303
+ // moves by looking at the impact of the move operation on the node
1304
+ // after the original move path.
1305
+ const inversePath = Path.transform(path, op);
1306
+ const inverseNewPath = Path.transform(Path.next(path), op);
1307
+ return { ...op, path: inversePath, newPath: inverseNewPath };
1308
+ }
1309
+ case 'set_node': {
1310
+ const { properties, newProperties } = op;
1311
+ return { ...op, properties: newProperties, newProperties: properties };
1312
+ }
1313
+ case 'set_selection': {
1314
+ const { properties, newProperties } = op;
1315
+ if (properties == null) {
1316
+ return {
1317
+ ...op,
1318
+ properties: newProperties,
1319
+ newProperties: null
1320
+ };
1321
+ }
1322
+ else if (newProperties == null) {
1323
+ return {
1324
+ ...op,
1325
+ properties: null,
1326
+ newProperties: properties
1327
+ };
1328
+ }
1329
+ else {
1330
+ return { ...op, properties: newProperties, newProperties: properties };
1331
+ }
1332
+ }
1333
+ case 'set_viewport': {
1334
+ const { properties, newProperties } = op;
1335
+ if (properties == null) {
1336
+ return {
1337
+ ...op,
1338
+ properties: newProperties,
1339
+ newProperties: newProperties
1340
+ };
1341
+ }
1342
+ else if (newProperties == null) {
1343
+ return {
1344
+ ...op,
1345
+ properties: properties,
1346
+ newProperties: properties
1347
+ };
1348
+ }
1349
+ else {
1350
+ return { ...op, properties: newProperties, newProperties: properties };
1351
+ }
1352
+ }
1353
+ }
1354
+ };
1355
+ const PlaitOperation = {
1356
+ isSetViewportOperation,
1357
+ inverse
1358
+ };
1359
+
1360
+ const Point = {
1361
+ isEquals(point, otherPoint) {
1362
+ return point && otherPoint && point[0] === otherPoint[0] && point[1] === otherPoint[1];
1363
+ }
1364
+ };
1257
1365
 
1258
- function arrowPoints(start, end, maxHypotenuseLength = 10, degree = 40) {
1259
- const width = Math.abs(start[0] - end[0]);
1260
- const height = Math.abs(start[1] - end[1]);
1261
- let hypotenuse = Math.hypot(width, height); // 斜边
1262
- const realRotateLine = hypotenuse > maxHypotenuseLength * 2 ? maxHypotenuseLength : hypotenuse / 2;
1263
- const rotateWidth = (realRotateLine / hypotenuse) * width;
1264
- const rotateHeight = (realRotateLine / hypotenuse) * height;
1265
- const rotatePoint = [
1266
- end[0] > start[0] ? end[0] - rotateWidth : end[0] + rotateWidth,
1267
- end[1] > start[1] ? end[1] - rotateHeight : end[1] + rotateHeight
1268
- ];
1269
- const pointRight = rotate(rotatePoint[0], rotatePoint[1], end[0], end[1], (degree * Math.PI) / 180);
1270
- const pointLeft = rotate(rotatePoint[0], rotatePoint[1], end[0], end[1], (-degree * Math.PI) / 180);
1271
- return { pointLeft, pointRight };
1272
- }
1273
- function drawArrow(rs, start, end, options, maxHypotenuseLength = 10, degree = 40) {
1274
- const { pointLeft, pointRight } = arrowPoints(start, end, maxHypotenuseLength, degree);
1275
- const arrowLineLeft = rs.linearPath([pointLeft, end], options);
1276
- const arrowLineRight = rs.linearPath([pointRight, end], options);
1277
- return [arrowLineLeft, arrowLineRight];
1278
- }
1366
+ const SELECTION_BORDER_COLOR = '#6698FF';
1367
+ const SELECTION_FILL_COLOR = '#6698FF19'; // 主色 0.1 透明度
1368
+ const Selection = {
1369
+ isCollapsed(selection) {
1370
+ if (selection.anchor[0] == selection.focus[0] && selection.anchor[1] === selection.focus[1]) {
1371
+ return true;
1372
+ }
1373
+ else {
1374
+ return false;
1375
+ }
1376
+ }
1377
+ };
1279
1378
 
1280
- function drawCircle(roughSVG, point, diameter, options) {
1281
- return roughSVG.circle(point[0], point[1], diameter, options);
1282
- }
1379
+ const SAVING = new WeakMap();
1380
+ const MERGING = new WeakMap();
1283
1381
 
1284
- function drawLine(rs, start, end, options) {
1285
- return rs.linearPath([start, end], options);
1286
- }
1382
+ var PlaitPluginKey;
1383
+ (function (PlaitPluginKey) {
1384
+ PlaitPluginKey["withSelection"] = "withSelection";
1385
+ })(PlaitPluginKey || (PlaitPluginKey = {}));
1287
1386
 
1288
1387
  const IS_FROM_SCROLLING = new WeakMap();
1289
1388
  const IS_FROM_VIEWPORT_CHANGE = new WeakMap();
@@ -1412,18 +1511,52 @@ function initializeViewportOffset(board) {
1412
1511
  }
1413
1512
  updateViewportOffset(board);
1414
1513
  }
1415
- function setViewport(board, origination, zoom) {
1514
+ const updateViewportOrigination = (board, origination) => {
1515
+ BOARD_TO_VIEWPORT_ORIGINATION.set(board, origination);
1516
+ };
1517
+ const clearViewportOrigination = (board) => {
1518
+ BOARD_TO_VIEWPORT_ORIGINATION.delete(board);
1519
+ };
1520
+ const getViewportOrigination = (board) => {
1521
+ const origination = BOARD_TO_VIEWPORT_ORIGINATION.get(board);
1522
+ if (origination) {
1523
+ return origination;
1524
+ }
1525
+ else {
1526
+ return board.viewport.origination;
1527
+ }
1528
+ };
1529
+ const isFromScrolling = (board) => {
1530
+ return !!IS_FROM_SCROLLING.get(board);
1531
+ };
1532
+ const setIsFromScrolling = (board, state) => {
1533
+ IS_FROM_SCROLLING.set(board, state);
1534
+ };
1535
+ const isFromViewportChange = (board) => {
1536
+ return !!IS_FROM_VIEWPORT_CHANGE.get(board);
1537
+ };
1538
+ const setIsFromViewportChange = (board, state) => {
1539
+ IS_FROM_VIEWPORT_CHANGE.set(board, state);
1540
+ };
1541
+ function scrollToRectangle(board, client) { }
1542
+
1543
+ function updateViewport(board, origination, zoom) {
1416
1544
  zoom = zoom ?? board.viewport.zoom;
1417
- Transforms.setViewport(board, {
1545
+ setViewport(board, {
1418
1546
  ...board.viewport,
1419
1547
  zoom,
1420
1548
  origination
1421
1549
  });
1422
1550
  clearViewportOrigination(board);
1423
1551
  }
1424
- function changeZoom(board, newZoom, isCenter = true) {
1552
+ const updatePointerType = (board, pointer) => {
1553
+ board.pointer = pointer;
1554
+ const boardComponent = BOARD_TO_COMPONENT.get(board);
1555
+ boardComponent?.markForCheck();
1556
+ };
1557
+ function updateZoom(board, newZoom, isCenter = true) {
1425
1558
  newZoom = clampZoomLevel(newZoom);
1426
- const mousePoint = BOARD_TO_MOVING_POINT.get(board);
1559
+ const mousePoint = PlaitBoard.getMovingPoint(board);
1427
1560
  const nativeElement = PlaitBoard.getBoardNativeElement(board);
1428
1561
  const nativeElementRect = nativeElement.getBoundingClientRect();
1429
1562
  const viewportContainerRect = getViewportContainerRect(board);
@@ -1436,7 +1569,7 @@ function changeZoom(board, newZoom, isCenter = true) {
1436
1569
  const centerX = origination[0] + focusPoint[0] / zoom;
1437
1570
  const centerY = origination[1] + focusPoint[1] / zoom;
1438
1571
  const newOrigination = [centerX - focusPoint[0] / newZoom, centerY - focusPoint[1] / newZoom];
1439
- setViewport(board, newOrigination, newZoom);
1572
+ updateViewport(board, newOrigination, newZoom);
1440
1573
  }
1441
1574
  function fitViewport(board) {
1442
1575
  const nativeElementRect = PlaitBoard.getBoardNativeElement(board).getBoundingClientRect();
@@ -1460,91 +1593,13 @@ function fitViewport(board) {
1460
1593
  centerX - viewportContainerRect.width / 2 / newZoom,
1461
1594
  centerY - viewportContainerRect.height / 2 / newZoom
1462
1595
  ];
1463
- setViewport(board, newOrigination, newZoom);
1596
+ updateViewport(board, newOrigination, newZoom);
1464
1597
  }
1465
- const updateViewportOrigination = (board, origination) => {
1466
- BOARD_TO_VIEWPORT_ORIGINATION.set(board, origination);
1467
- };
1468
- const clearViewportOrigination = (board) => {
1469
- BOARD_TO_VIEWPORT_ORIGINATION.delete(board);
1470
- };
1471
- const getViewportOrigination = (board) => {
1472
- const origination = BOARD_TO_VIEWPORT_ORIGINATION.get(board);
1473
- if (origination) {
1474
- return origination;
1475
- }
1476
- else {
1477
- return board.viewport.origination;
1478
- }
1479
- };
1480
- const isFromScrolling = (board) => {
1481
- return !!IS_FROM_SCROLLING.get(board);
1482
- };
1483
- const setIsFromScrolling = (board, state) => {
1484
- IS_FROM_SCROLLING.set(board, state);
1485
- };
1486
- const isFromViewportChange = (board) => {
1487
- return !!IS_FROM_VIEWPORT_CHANGE.get(board);
1488
- };
1489
- const setIsFromViewportChange = (board, state) => {
1490
- IS_FROM_VIEWPORT_CHANGE.set(board, state);
1491
- };
1492
- function scrollToRectangle(board, client) { }
1493
-
1494
- let timerId = null;
1495
- const throttleRAF = (fn) => {
1496
- const scheduleFunc = () => {
1497
- timerId = requestAnimationFrame(() => {
1498
- timerId = null;
1499
- fn();
1500
- });
1501
- };
1502
- if (timerId !== null) {
1503
- cancelAnimationFrame(timerId);
1504
- timerId = null;
1505
- }
1506
- scheduleFunc();
1507
- };
1508
- const debounce = (func, wait, options) => {
1509
- let timerSubscription = null;
1510
- return () => {
1511
- if (timerSubscription && !timerSubscription.closed) {
1512
- timerSubscription.unsubscribe();
1513
- timerSubscription = timer(wait).subscribe(() => {
1514
- func();
1515
- });
1516
- }
1517
- else {
1518
- if (options?.leading) {
1519
- func();
1520
- }
1521
- timerSubscription = timer(wait).subscribe();
1522
- }
1523
- };
1524
- };
1525
-
1526
- const getMovingElements = (board) => {
1527
- return BOARD_TO_MOVING_ELEMENT.get(board) || [];
1528
- };
1529
- const addMovingElements = (board, elements) => {
1530
- const movingElements = getMovingElements(board);
1531
- const newElements = elements.filter(item => !movingElements.find(movingElement => movingElement.key === item.key));
1532
- cacheMovingElements(board, [...movingElements, ...newElements]);
1533
- };
1534
- const removeMovingElements = (board) => {
1535
- BOARD_TO_MOVING_ELEMENT.delete(board);
1536
- };
1537
- const cacheMovingElements = (board, elements) => {
1538
- BOARD_TO_MOVING_ELEMENT.set(board, elements);
1539
- };
1540
-
1541
- const updatePointerType = (board, pointer) => {
1542
- board.pointer = pointer;
1543
- const boardComponent = BOARD_TO_COMPONENT.get(board);
1544
- boardComponent?.markForCheck();
1545
- };
1546
1598
  const BoardTransforms = {
1547
- updatePointerType
1599
+ updatePointerType,
1600
+ updateViewport,
1601
+ fitViewport,
1602
+ updateZoom
1548
1603
  };
1549
1604
 
1550
1605
  const Transforms = {
@@ -1554,6 +1609,20 @@ const Transforms = {
1554
1609
  ...NodeTransforms
1555
1610
  };
1556
1611
 
1612
+ const PathRef = {
1613
+ transform(ref, op) {
1614
+ const { current } = ref;
1615
+ if (current == null) {
1616
+ return;
1617
+ }
1618
+ const path = Path.transform(current, op);
1619
+ ref.current = path;
1620
+ if (path == null) {
1621
+ ref.unref();
1622
+ }
1623
+ }
1624
+ };
1625
+
1557
1626
  function createBoard(children, options) {
1558
1627
  const board = {
1559
1628
  viewport: {
@@ -1567,14 +1636,17 @@ function createBoard(children, options) {
1567
1636
  undos: []
1568
1637
  },
1569
1638
  selection: null,
1570
- pointer: PlaitPointerType.selection,
1571
1639
  options: options || {
1572
1640
  readonly: false,
1573
1641
  hideScrollbar: false
1574
1642
  },
1643
+ pointer: options?.readonly ? PlaitPointerType.hand : PlaitPointerType.selection,
1575
1644
  undo: () => { },
1576
1645
  redo: () => { },
1577
1646
  apply: (operation) => {
1647
+ for (const ref of board.pathRefs()) {
1648
+ PathRef.transform(ref, operation);
1649
+ }
1578
1650
  board.operations.push(operation);
1579
1651
  Transforms.transform(board, operation);
1580
1652
  if (!FLUSHING.get(board)) {
@@ -1586,6 +1658,31 @@ function createBoard(children, options) {
1586
1658
  });
1587
1659
  }
1588
1660
  },
1661
+ pathRef: (path, options) => {
1662
+ const affinity = options?.affinity || 'forward';
1663
+ const ref = {
1664
+ current: path,
1665
+ affinity,
1666
+ unref() {
1667
+ const { current } = ref;
1668
+ const pathRefs = board.pathRefs();
1669
+ pathRefs.delete(ref);
1670
+ ref.current = null;
1671
+ return current;
1672
+ }
1673
+ };
1674
+ const refs = board.pathRefs();
1675
+ refs.add(ref);
1676
+ return ref;
1677
+ },
1678
+ pathRefs: () => {
1679
+ let refs = PATH_REFS.get(board);
1680
+ if (!refs) {
1681
+ refs = new Set();
1682
+ PATH_REFS.set(board, refs);
1683
+ }
1684
+ return refs;
1685
+ },
1589
1686
  onChange: () => { },
1590
1687
  mousedown: (event) => { },
1591
1688
  mousemove: (event) => { },
@@ -1714,13 +1811,7 @@ function withHandPointer(board) {
1714
1811
  y: 0
1715
1812
  };
1716
1813
  board.mousedown = (event) => {
1717
- if (board.options.readonly) {
1718
- updatePointerType(board, PlaitPointerType.hand);
1719
- }
1720
- else if (!board.selection) {
1721
- updatePointerType(board, PlaitPointerType.selection);
1722
- }
1723
- if (board.pointer === PlaitPointerType.hand && board.selection) {
1814
+ if (PlaitBoard.isPointer(board, PlaitPointerType.hand) && isMainPointer(event)) {
1724
1815
  isMoving = true;
1725
1816
  PlaitBoard.getBoardNativeElement(board).classList.add('viewport-moving');
1726
1817
  plaitBoardMove.x = event.x;
@@ -1729,7 +1820,7 @@ function withHandPointer(board) {
1729
1820
  mousedown(event);
1730
1821
  };
1731
1822
  board.mousemove = (event) => {
1732
- if (board.pointer === PlaitPointerType.hand && board.selection && isMoving) {
1823
+ if (PlaitBoard.isPointer(board, PlaitPointerType.hand) && board.selection && isMoving) {
1733
1824
  const viewportContainer = PlaitBoard.getViewportContainer(board);
1734
1825
  const left = viewportContainer.scrollLeft - (event.x - plaitBoardMove.x);
1735
1826
  const top = viewportContainer.scrollTop - (event.y - plaitBoardMove.y);
@@ -1749,17 +1840,17 @@ function withHandPointer(board) {
1749
1840
  globalMouseup(event);
1750
1841
  };
1751
1842
  board.keydown = (event) => {
1752
- if (board.selection && event.code === 'Space') {
1753
- if (board.pointer !== PlaitPointerType.hand) {
1754
- updatePointerType(board, PlaitPointerType.hand);
1843
+ if (event.code === 'Space') {
1844
+ if (!PlaitBoard.isPointer(board, PlaitPointerType.hand)) {
1845
+ BoardTransforms.updatePointerType(board, PlaitPointerType.hand);
1755
1846
  }
1756
1847
  event.preventDefault();
1757
1848
  }
1758
1849
  keydown(event);
1759
1850
  };
1760
1851
  board.keyup = (event) => {
1761
- if (board.selection && !board.options.readonly && event.code === 'Space') {
1762
- updatePointerType(board, PlaitPointerType.selection);
1852
+ if (!board.options.readonly && event.code === 'Space') {
1853
+ BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
1763
1854
  }
1764
1855
  keyup(event);
1765
1856
  };
@@ -1776,22 +1867,26 @@ function withSelection(board) {
1776
1867
  let selectionOuterG;
1777
1868
  let previousSelectedElements;
1778
1869
  board.mousedown = (event) => {
1779
- if (event.button === 0) {
1780
- start = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
1870
+ if (!isMainPointer(event)) {
1871
+ mousedown(event);
1872
+ return;
1781
1873
  }
1782
- if (start) {
1783
- const ranges = [{ anchor: start, focus: start }];
1784
- const selectedElements = getSelectedElements(board);
1785
- if (isIntersectionElements(board, selectedElements, ranges)) {
1786
- start = null;
1787
- mousedown(event);
1788
- return;
1789
- }
1790
- Transforms.setSelection(board, { ranges: ranges });
1791
- if (board.pointer === PlaitPointerType.hand || getHitElements(board).length) {
1792
- start = null;
1793
- }
1874
+ const options = board.getPluginOptions(PlaitPluginKey.withSelection);
1875
+ const point = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
1876
+ const ranges = [{ anchor: point, focus: point }];
1877
+ const selectedElements = getSelectedElements(board);
1878
+ if (isIntersectionElements(board, selectedElements, ranges)) {
1879
+ mousedown(event);
1880
+ return;
1794
1881
  }
1882
+ const range = { anchor: point, focus: point };
1883
+ if (PlaitBoard.isPointer(board, PlaitPointerType.selection) &&
1884
+ PlaitBoard.isFocus(board) &&
1885
+ getHitElements(board, { ranges: [range] }).length === 0 &&
1886
+ options.isMultiple) {
1887
+ start = point;
1888
+ }
1889
+ Transforms.setSelection(board, { ranges: ranges });
1795
1890
  mousedown(event);
1796
1891
  };
1797
1892
  board.globalMousemove = (event) => {
@@ -1846,7 +1941,11 @@ function withSelection(board) {
1846
1941
  if (board.operations.find(value => value.type === 'set_selection')) {
1847
1942
  selectionOuterG?.remove();
1848
1943
  const temporaryElements = getTemporaryElements(board);
1849
- const elements = temporaryElements ? temporaryElements : getHitElements(board);
1944
+ let elements = temporaryElements ? temporaryElements : getHitElements(board);
1945
+ const options = board.getPluginOptions(PlaitPluginKey.withSelection);
1946
+ if (!options.isMultiple && elements.length > 1) {
1947
+ elements = [elements[0]];
1948
+ }
1850
1949
  cacheSelectedElements(board, elements);
1851
1950
  previousSelectedElements = elements;
1852
1951
  const { width, height } = getRectangleByElements(board, elements, false);
@@ -1882,6 +1981,7 @@ function withSelection(board) {
1882
1981
  }
1883
1982
  onChange();
1884
1983
  };
1984
+ board.setPluginOptions(PlaitPluginKey.withSelection, { isMultiple: true });
1885
1985
  return board;
1886
1986
  }
1887
1987
  function getTemporaryElements(board) {
@@ -2023,6 +2123,50 @@ function withMoving(board) {
2023
2123
  return board;
2024
2124
  }
2025
2125
 
2126
+ const withOptions = (board) => {
2127
+ const pluginOptions = new Map();
2128
+ const newBoard = board;
2129
+ newBoard.getPluginOptions = key => {
2130
+ return pluginOptions.get(key);
2131
+ };
2132
+ newBoard.setPluginOptions = (key, options) => {
2133
+ const oldOptions = newBoard.getPluginOptions(key) || {};
2134
+ pluginOptions.set(key, { ...oldOptions, ...options });
2135
+ };
2136
+ return newBoard;
2137
+ };
2138
+
2139
+ class PlaitIslandBaseComponent {
2140
+ constructor(cdr) {
2141
+ this.cdr = cdr;
2142
+ }
2143
+ initialize(board) {
2144
+ this.board = board;
2145
+ this.markForCheck();
2146
+ }
2147
+ markForCheck() {
2148
+ this.cdr.markForCheck();
2149
+ }
2150
+ }
2151
+ PlaitIslandBaseComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitIslandBaseComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
2152
+ PlaitIslandBaseComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.5", type: PlaitIslandBaseComponent, host: { classAttribute: "plait-island-container" }, ngImport: i0 });
2153
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitIslandBaseComponent, decorators: [{
2154
+ type: Directive,
2155
+ args: [{
2156
+ host: {
2157
+ class: 'plait-island-container'
2158
+ }
2159
+ }]
2160
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; } });
2161
+ const hasOnBoardChange = (value) => {
2162
+ if (value.onBoardChange) {
2163
+ return true;
2164
+ }
2165
+ else {
2166
+ return false;
2167
+ }
2168
+ };
2169
+
2026
2170
  class PlaitElementComponent {
2027
2171
  constructor(renderer2, viewContainerRef) {
2028
2172
  this.renderer2 = renderer2;
@@ -2173,68 +2317,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2173
2317
  type: Input
2174
2318
  }] } });
2175
2319
 
2176
- class PlaitToolbarComponent {
2177
- constructor() {
2178
- this.PlaitPointerType = PlaitPointerType;
2179
- this.hostClass = `plait-board-toolbar`;
2180
- this.adaptHandle = new EventEmitter();
2181
- this.zoomInHandle = new EventEmitter();
2182
- this.zoomOutHandle = new EventEmitter();
2183
- this.resetZoomHandel = new EventEmitter();
2184
- }
2185
- get zoom() {
2186
- const zoom = this.board?.viewport.zoom || 1;
2187
- return Number((zoom * 100).toFixed(0));
2188
- }
2189
- get isHand() {
2190
- return this.board.pointer === PlaitPointerType.hand;
2191
- }
2192
- activeHand() {
2193
- updatePointerType(this.board, this.isHand ? PlaitPointerType.selection : PlaitPointerType.hand);
2194
- }
2195
- // 适应画布
2196
- adapt() {
2197
- this.adaptHandle.emit();
2198
- }
2199
- // 放大
2200
- zoomIn() {
2201
- this.zoomInHandle.emit();
2202
- }
2203
- // 缩小
2204
- zoomOut() {
2205
- this.zoomOutHandle.emit();
2206
- }
2207
- resetZoom() {
2208
- this.resetZoomHandel.emit();
2209
- }
2210
- }
2211
- PlaitToolbarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitToolbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2212
- PlaitToolbarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", type: PlaitToolbarComponent, selector: "plait-toolbar", inputs: { board: "board" }, outputs: { adaptHandle: "adaptHandle", zoomInHandle: "zoomInHandle", zoomOutHandle: "zoomOutHandle", resetZoomHandel: "resetZoomHandel" }, host: { properties: { "class": "this.hostClass" } }, ngImport: i0, template: "<div class=\"zoom-toolbar island plait-board-attached\">\n <a class=\"toolbar-item plait-action-icon\" [ngClass]=\"{ 'icon-active': isHand }\" (click)=\"activeHand()\">\n <ng-template [ngTemplateOutlet]=\"dragMoveTemplate\"></ng-template>\n </a>\n <div class=\"divider\"></div>\n <a class=\"toolbar-item plait-action-icon\" (mousedown)=\"adapt()\">\n <ng-template [ngTemplateOutlet]=\"adaptTemplate\"></ng-template>\n </a>\n <div class=\"divider\"></div>\n <a class=\"toolbar-item plait-action-icon\" (mousedown)=\"zoomOut()\">\n <ng-template [ngTemplateOutlet]=\"zoomOutTemplate\"></ng-template>\n </a>\n <div class=\"toolbar-item zoom-value\" (mousedown)=\"resetZoom()\">{{ zoom }}%</div>\n <a class=\"toolbar-item plait-action-icon\" (mousedown)=\"zoomIn()\">\n <ng-template [ngTemplateOutlet]=\"zoomInTemplate\"></ng-template>\n </a>\n</div>\n\n<ng-template #dragMoveTemplate>\n <svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/hand</title>\n <g id=\"1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/hand\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M8.44583468,0.500225887 C9.07406934,0.510185679 9.54739531,0.839591366 9.86192311,1.34305279 C9.89696656,1.39914649 9.92878401,1.45492964 9.9576026,1.50991157 L9.9576026,1.50991157 L10.0210033,1.64201027 L10.061978,1.62350755 C10.1972891,1.56834247 10.3444107,1.53218464 10.5027907,1.51755353 L10.5027907,1.51755353 L10.6649031,1.51019133 C11.4883708,1.51019133 12.0208782,1.99343346 12.3023042,2.66393278 C12.3903714,2.87392911 12.4344191,3.10047818 12.4339446,3.3257952 L12.4339446,3.3257952 L12.4360033,3.80501027 L12.5160535,3.78341501 C12.6124478,3.76124046 12.7138812,3.74739854 12.820201,3.74250274 L12.820201,3.74250274 L12.9833264,3.74194533 C13.6121166,3.7657478 14.0645887,4.0801724 14.3087062,4.56112689 C14.4521117,4.8436609 14.4987984,5.11349437 14.4999262,5.33449618 L14.4999262,5.33449618 L14.3922653,12.049414 C14.3784752,12.909177 14.0717787,13.7360948 13.5212406,14.3825228 C13.4055676,14.5183496 13.2843697,14.643961 13.1582361,14.7596335 C12.4634771,15.3967716 11.755103,15.6538706 11.1897396,15.7000055 L11.1897396,15.7000055 L7.4723083,15.6798158 C7.14276373,15.634268 6.81580098,15.5154267 6.49455235,15.3472501 C6.25643701,15.2225944 6.06881706,15.0975452 5.88705731,14.9494308 L5.88705731,14.9494308 L2.55198782,11.500873 C2.39559475,11.3769079 2.17626793,11.1748532 1.9548636,10.9139403 C1.57867502,10.4706225 1.33501976,10.0139923 1.30330257,9.52833025 C1.28093191,9.18578476 1.37200912,8.85641102 1.5826788,8.56872564 C1.82538833,8.23725279 2.12881965,8.02107162 2.47470569,7.92957033 C2.95807982,7.80169771 3.42705723,7.92468989 3.86509644,8.18731167 C4.04431391,8.29475961 4.1816109,8.40304483 4.26225571,8.47866867 L4.26225571,8.47866867 L4.61400328,8.79701027 L4.57247249,3.59275349 L4.57628524,3.46204923 C4.5897691,3.23444442 4.64087578,2.95701848 4.75937106,2.66961597 C5.01017272,2.06131302 5.49670227,1.64692543 6.21363856,1.60818786 C6.44223508,1.59583681 6.65042099,1.62176802 6.83696985,1.68057551 L6.83696985,1.68057551 L6.86400328,1.69001027 C6.88501862,1.63593052 6.90764242,1.58175442 6.9331867,1.52672633 L6.9331867,1.52672633 L7.01883595,1.35955614 C7.31549194,0.832047939 7.79476072,0.48993549 8.44583468,0.500225887 Z M8.42684173,1.70001476 C8.26825412,1.69756905 8.16339456,1.77242008 8.06478367,1.94776814 C8.03967773,1.99241107 8.01831703,2.03811495 8.00083464,2.07855067 L8.00083464,2.07855067 L7.94879157,2.2035905 L7.94354455,2.20731401 L7.943,3.161 L7.97170661,3.16123746 L7.97170661,7.60991883 L6.77170661,7.60991883 L6.771,3.338 L6.74362358,3.33880359 C6.74284189,3.29064626 6.73014163,3.20282206 6.7002616,3.11094408 L6.66446012,3.01903385 C6.58982025,2.85766739 6.49843292,2.79455071 6.27838133,2.80644008 C6.07001018,2.81769881 5.95642108,2.91444507 5.86877664,3.12702089 C5.79792279,3.29887224 5.77228127,3.48655908 5.77246879,3.58977183 L5.77246879,3.58977183 L5.83613619,11.5252021 L3.41863956,9.33477657 L3.31637296,9.25979571 L3.24805011,9.21651224 C3.06096922,9.10434987 2.89279975,9.06024641 2.78159879,9.0896637 C2.71007735,9.10858411 2.63607367,9.1613084 2.55086305,9.27768211 C2.51020424,9.33320478 2.49638061,9.38319687 2.50075171,9.4501283 C2.51206889,9.62341997 2.64503022,9.87260054 2.86983366,10.1375191 C3.03268834,10.3294345 3.19762053,10.4813781 3.35554956,10.6131022 L3.35554956,10.6131022 L6.68454317,14.0569073 C6.71106575,14.0773808 6.74806086,14.1037158 6.79369091,14.1335929 L6.79369091,14.1335929 L6.95464838,14.2315311 L7.05111031,14.2841211 C7.25978123,14.3933622 7.46253523,14.4670573 7.55685495,14.4854708 L7.55685495,14.4854708 L11.1407985,14.5022108 C11.1503576,14.5013899 11.1627905,14.4997539 11.1779002,14.4971772 L11.1779002,14.4971772 L11.2991076,14.4694224 C11.3491682,14.4557375 11.4083624,14.437284 11.4751158,14.4130563 C11.769383,14.3062543 12.066676,14.1324596 12.3471758,13.8752234 C12.4371203,13.7927386 12.5240597,13.7026333 12.607654,13.6044743 C12.9760464,13.1719172 13.183059,12.6137678 13.1924195,12.030173 L13.1924195,12.030173 L13.3000132,5.32832551 C13.2997939,5.29016685 13.2826117,5.19085946 13.2386527,5.10425262 C13.1843838,4.99733326 13.1129774,4.94771265 12.9379578,4.94108739 C12.6814739,4.93138871 12.534132,5.11189595 12.4756792,5.39480062 L12.4768718,7.52734922 L11.2768718,7.52734922 L11.276,5.688 L11.2462883,5.6883208 L11.2339541,3.32771285 C11.2341,3.2560396 11.2209054,3.18817621 11.1957482,3.12818892 C11.0820579,2.85732094 10.9199288,2.71019133 10.6649031,2.71019133 C10.456829,2.71019133 10.3197487,2.87378067 10.2524297,3.11264939 L10.2530225,7.512783 L9.05302254,7.512783 L9.053,3.288 L9.01554331,3.28724203 L8.98800328,2.29901027 L8.9629175,2.22263368 C8.94515567,2.17417174 8.92167756,2.11937748 8.8924232,2.06330056 L8.8924232,2.06330056 L8.84420197,1.9788544 C8.72758855,1.79219249 8.59915015,1.70280728 8.42684173,1.70001476 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n\n<ng-template #adaptTemplate>\n <svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/Fit canvas</title>\n <g id=\"1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/Fit-canvas\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M14.9971494,10.4 L14.9971494,13.4020516 C14.9971494,14.2366152 14.3581879,14.9219414 13.542782,14.9955129 L13.3971494,15.0020516 L10.4,15.0020516 L10.4,13.8020516 L13.3971494,13.8020516 C13.590449,13.8020516 13.7517243,13.6649388 13.7890228,13.4826656 L13.7971494,13.4020516 L13.7971494,10.4 L14.9971494,10.4 Z M2.2,10.4 L2.2,13.3971494 C2.2,13.590449 2.3371128,13.7517243 2.51938605,13.7890228 L2.6,13.7971494 L5.60205161,13.7971494 L5.60205161,14.9971494 L2.6,14.9971494 C1.76543638,14.9971494 1.08011021,14.3581879 1.00653868,13.542782 L1,13.3971494 L1,10.4 L2.2,10.4 Z M10.5024511,4.9 C11.3861067,4.9 12.1024511,5.6163444 12.1024511,6.5 L12.1024511,6.5 L12.1024511,9.5 C12.1024511,10.3836556 11.3861067,11.1 10.5024511,11.1 L10.5024511,11.1 L5.50245112,11.1 C4.61879552,11.1 3.90245112,10.3836556 3.90245112,9.5 L3.90245112,9.5 L3.90245112,6.5 C3.90245112,5.6163444 4.61879552,4.9 5.50245112,4.9 L5.50245112,4.9 Z M10.5024511,6.1 L5.50245112,6.1 C5.28153722,6.1 5.10245112,6.2790861 5.10245112,6.5 L5.10245112,6.5 L5.10245112,9.5 C5.10245112,9.7209139 5.28153722,9.9 5.50245112,9.9 L5.50245112,9.9 L10.5024511,9.9 C10.723365,9.9 10.9024511,9.7209139 10.9024511,9.5 L10.9024511,9.5 L10.9024511,6.5 C10.9024511,6.2790861 10.723365,6.1 10.5024511,6.1 L10.5024511,6.1 Z M5.59714938,1 L5.59714938,2.2 L2.6,2.2 C2.40670034,2.2 2.24542508,2.3371128 2.20812658,2.51938605 L2.2,2.6 L2.2,5.60205161 L1,5.60205161 L1,2.6 C1,1.76543638 1.63896152,1.08011021 2.45436739,1.00653868 L2.6,1 L5.59714938,1 Z M13.3971494,1 L13.542782,1.00653868 C14.3581879,1.08011021 14.9971494,1.76543638 14.9971494,2.6 L14.9971494,2.6 L14.9971494,5.60205161 L13.7971494,5.60205161 L13.7971494,2.6 L13.7890228,2.51938605 C13.7517243,2.3371128 13.590449,2.2 13.3971494,2.2 L13.3971494,2.2 L10.4,2.2 L10.4,1 L13.3971494,1 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n<ng-template #zoomOutTemplate>\n <svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>action/zoom-out</title>\n <desc>Created with Sketch.</desc>\n <g id=\"action/zoom-out\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M6.85,2.73225886e-13 C10.6331505,2.73225886e-13 13.7,3.06684946 13.7,6.85 C13.7,8.54194045 13.0865836,10.0906098 12.0700142,11.2857448 L15.4201976,14.5717081 C15.6567367,14.8037768 15.6603607,15.1836585 15.4282919,15.4201976 C15.1962232,15.6567367 14.8163415,15.6603607 14.5798024,15.4282919 L14.5798024,15.4282919 L11.2163456,12.128262 C10.0309427,13.1099691 8.50937591,13.7 6.85,13.7 C3.06684946,13.7 4.58522109e-14,10.6331505 4.58522109e-14,6.85 C4.58522109e-14,3.06684946 3.06684946,2.73225886e-13 6.85,2.73225886e-13 Z M6.85,1.2 C3.72959116,1.2 1.2,3.72959116 1.2,6.85 C1.2,9.97040884 3.72959116,12.5 6.85,12.5 C8.31753357,12.5 9.65438791,11.9404957 10.6588859,11.0231643 C10.6855412,10.9625408 10.7245275,10.9050898 10.7743982,10.8542584 C10.8288931,10.7987137 10.8915387,10.7560124 10.9585649,10.7261903 C11.9144009,9.71595758 12.5,8.35136579 12.5,6.85 C12.5,3.72959116 9.97040884,1.2 6.85,1.2 Z M4.6,6.2 L9.12944565,6.2 C9.4608165,6.2 9.72944565,6.46862915 9.72944565,6.8 C9.72944565,7.09823376 9.51185604,7.34564675 9.22676876,7.39214701 L9.12944565,7.4 L4.6,7.4 C4.26862915,7.4 4,7.13137085 4,6.8 C4,6.50176624 4.21758961,6.25435325 4.50267688,6.20785299 L4.6,6.2 L9.12944565,6.2 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n\n<ng-template #zoomInTemplate\n ><svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>action/zoom-in</title>\n <desc>Created with Sketch.</desc>\n <g id=\"action/zoom-in\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M6.85,-1.81188398e-13 C10.6331505,-1.81188398e-13 13.7,3.06684946 13.7,6.85 C13.7,8.54194045 13.0865836,10.0906098 12.0700142,11.2857448 L15.4201976,14.5717081 C15.6567367,14.8037768 15.6603607,15.1836585 15.4282919,15.4201976 C15.1962232,15.6567367 14.8163415,15.6603607 14.5798024,15.4282919 L14.5798024,15.4282919 L11.2163456,12.128262 C10.0309427,13.1099691 8.50937591,13.7 6.85,13.7 C3.06684946,13.7 4.61852778e-14,10.6331505 4.61852778e-14,6.85 C4.61852778e-14,3.06684946 3.06684946,-1.81188398e-13 6.85,-1.81188398e-13 Z M6.85,1.2 C3.72959116,1.2 1.2,3.72959116 1.2,6.85 C1.2,9.97040884 3.72959116,12.5 6.85,12.5 C8.31753357,12.5 9.65438791,11.9404957 10.6588859,11.0231643 C10.6855412,10.9625408 10.7245275,10.9050898 10.7743982,10.8542584 C10.8288931,10.7987137 10.8915387,10.7560124 10.9585649,10.7261903 C11.9144009,9.71595758 12.5,8.35136579 12.5,6.85 C12.5,3.72959116 9.97040884,1.2 6.85,1.2 Z M6.86472282,3.93527718 C7.16295659,3.93527718 7.41036958,4.15286679 7.45686984,4.43795406 L7.46472282,4.53527718 L7.464,6.19927718 L9.12944565,6.2 C9.42767941,6.2 9.6750924,6.41758961 9.72159266,6.70267688 L9.72944565,6.8 C9.72944565,7.09823376 9.51185604,7.34564675 9.22676876,7.39214701 L9.12944565,7.4 L7.464,7.39927718 L7.46472282,9.06472282 C7.46472282,9.36295659 7.24713321,9.61036958 6.96204594,9.65686984 L6.86472282,9.66472282 C6.56648906,9.66472282 6.31907607,9.44713321 6.27257581,9.16204594 L6.26472282,9.06472282 L6.264,7.39927718 L4.6,7.4 C4.30176624,7.4 4.05435325,7.18241039 4.00785299,6.89732312 L4,6.8 C4,6.50176624 4.21758961,6.25435325 4.50267688,6.20785299 L4.6,6.2 L6.264,6.19927718 L6.26472282,4.53527718 C6.26472282,4.2701805 6.43664548,4.0452385 6.67507642,3.96586557 L6.76739971,3.94313016 L6.86472282,3.93527718 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n", dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2213
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitToolbarComponent, decorators: [{
2214
- type: Component,
2215
- args: [{ selector: 'plait-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"zoom-toolbar island plait-board-attached\">\n <a class=\"toolbar-item plait-action-icon\" [ngClass]=\"{ 'icon-active': isHand }\" (click)=\"activeHand()\">\n <ng-template [ngTemplateOutlet]=\"dragMoveTemplate\"></ng-template>\n </a>\n <div class=\"divider\"></div>\n <a class=\"toolbar-item plait-action-icon\" (mousedown)=\"adapt()\">\n <ng-template [ngTemplateOutlet]=\"adaptTemplate\"></ng-template>\n </a>\n <div class=\"divider\"></div>\n <a class=\"toolbar-item plait-action-icon\" (mousedown)=\"zoomOut()\">\n <ng-template [ngTemplateOutlet]=\"zoomOutTemplate\"></ng-template>\n </a>\n <div class=\"toolbar-item zoom-value\" (mousedown)=\"resetZoom()\">{{ zoom }}%</div>\n <a class=\"toolbar-item plait-action-icon\" (mousedown)=\"zoomIn()\">\n <ng-template [ngTemplateOutlet]=\"zoomInTemplate\"></ng-template>\n </a>\n</div>\n\n<ng-template #dragMoveTemplate>\n <svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/hand</title>\n <g id=\"1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/hand\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M8.44583468,0.500225887 C9.07406934,0.510185679 9.54739531,0.839591366 9.86192311,1.34305279 C9.89696656,1.39914649 9.92878401,1.45492964 9.9576026,1.50991157 L9.9576026,1.50991157 L10.0210033,1.64201027 L10.061978,1.62350755 C10.1972891,1.56834247 10.3444107,1.53218464 10.5027907,1.51755353 L10.5027907,1.51755353 L10.6649031,1.51019133 C11.4883708,1.51019133 12.0208782,1.99343346 12.3023042,2.66393278 C12.3903714,2.87392911 12.4344191,3.10047818 12.4339446,3.3257952 L12.4339446,3.3257952 L12.4360033,3.80501027 L12.5160535,3.78341501 C12.6124478,3.76124046 12.7138812,3.74739854 12.820201,3.74250274 L12.820201,3.74250274 L12.9833264,3.74194533 C13.6121166,3.7657478 14.0645887,4.0801724 14.3087062,4.56112689 C14.4521117,4.8436609 14.4987984,5.11349437 14.4999262,5.33449618 L14.4999262,5.33449618 L14.3922653,12.049414 C14.3784752,12.909177 14.0717787,13.7360948 13.5212406,14.3825228 C13.4055676,14.5183496 13.2843697,14.643961 13.1582361,14.7596335 C12.4634771,15.3967716 11.755103,15.6538706 11.1897396,15.7000055 L11.1897396,15.7000055 L7.4723083,15.6798158 C7.14276373,15.634268 6.81580098,15.5154267 6.49455235,15.3472501 C6.25643701,15.2225944 6.06881706,15.0975452 5.88705731,14.9494308 L5.88705731,14.9494308 L2.55198782,11.500873 C2.39559475,11.3769079 2.17626793,11.1748532 1.9548636,10.9139403 C1.57867502,10.4706225 1.33501976,10.0139923 1.30330257,9.52833025 C1.28093191,9.18578476 1.37200912,8.85641102 1.5826788,8.56872564 C1.82538833,8.23725279 2.12881965,8.02107162 2.47470569,7.92957033 C2.95807982,7.80169771 3.42705723,7.92468989 3.86509644,8.18731167 C4.04431391,8.29475961 4.1816109,8.40304483 4.26225571,8.47866867 L4.26225571,8.47866867 L4.61400328,8.79701027 L4.57247249,3.59275349 L4.57628524,3.46204923 C4.5897691,3.23444442 4.64087578,2.95701848 4.75937106,2.66961597 C5.01017272,2.06131302 5.49670227,1.64692543 6.21363856,1.60818786 C6.44223508,1.59583681 6.65042099,1.62176802 6.83696985,1.68057551 L6.83696985,1.68057551 L6.86400328,1.69001027 C6.88501862,1.63593052 6.90764242,1.58175442 6.9331867,1.52672633 L6.9331867,1.52672633 L7.01883595,1.35955614 C7.31549194,0.832047939 7.79476072,0.48993549 8.44583468,0.500225887 Z M8.42684173,1.70001476 C8.26825412,1.69756905 8.16339456,1.77242008 8.06478367,1.94776814 C8.03967773,1.99241107 8.01831703,2.03811495 8.00083464,2.07855067 L8.00083464,2.07855067 L7.94879157,2.2035905 L7.94354455,2.20731401 L7.943,3.161 L7.97170661,3.16123746 L7.97170661,7.60991883 L6.77170661,7.60991883 L6.771,3.338 L6.74362358,3.33880359 C6.74284189,3.29064626 6.73014163,3.20282206 6.7002616,3.11094408 L6.66446012,3.01903385 C6.58982025,2.85766739 6.49843292,2.79455071 6.27838133,2.80644008 C6.07001018,2.81769881 5.95642108,2.91444507 5.86877664,3.12702089 C5.79792279,3.29887224 5.77228127,3.48655908 5.77246879,3.58977183 L5.77246879,3.58977183 L5.83613619,11.5252021 L3.41863956,9.33477657 L3.31637296,9.25979571 L3.24805011,9.21651224 C3.06096922,9.10434987 2.89279975,9.06024641 2.78159879,9.0896637 C2.71007735,9.10858411 2.63607367,9.1613084 2.55086305,9.27768211 C2.51020424,9.33320478 2.49638061,9.38319687 2.50075171,9.4501283 C2.51206889,9.62341997 2.64503022,9.87260054 2.86983366,10.1375191 C3.03268834,10.3294345 3.19762053,10.4813781 3.35554956,10.6131022 L3.35554956,10.6131022 L6.68454317,14.0569073 C6.71106575,14.0773808 6.74806086,14.1037158 6.79369091,14.1335929 L6.79369091,14.1335929 L6.95464838,14.2315311 L7.05111031,14.2841211 C7.25978123,14.3933622 7.46253523,14.4670573 7.55685495,14.4854708 L7.55685495,14.4854708 L11.1407985,14.5022108 C11.1503576,14.5013899 11.1627905,14.4997539 11.1779002,14.4971772 L11.1779002,14.4971772 L11.2991076,14.4694224 C11.3491682,14.4557375 11.4083624,14.437284 11.4751158,14.4130563 C11.769383,14.3062543 12.066676,14.1324596 12.3471758,13.8752234 C12.4371203,13.7927386 12.5240597,13.7026333 12.607654,13.6044743 C12.9760464,13.1719172 13.183059,12.6137678 13.1924195,12.030173 L13.1924195,12.030173 L13.3000132,5.32832551 C13.2997939,5.29016685 13.2826117,5.19085946 13.2386527,5.10425262 C13.1843838,4.99733326 13.1129774,4.94771265 12.9379578,4.94108739 C12.6814739,4.93138871 12.534132,5.11189595 12.4756792,5.39480062 L12.4768718,7.52734922 L11.2768718,7.52734922 L11.276,5.688 L11.2462883,5.6883208 L11.2339541,3.32771285 C11.2341,3.2560396 11.2209054,3.18817621 11.1957482,3.12818892 C11.0820579,2.85732094 10.9199288,2.71019133 10.6649031,2.71019133 C10.456829,2.71019133 10.3197487,2.87378067 10.2524297,3.11264939 L10.2530225,7.512783 L9.05302254,7.512783 L9.053,3.288 L9.01554331,3.28724203 L8.98800328,2.29901027 L8.9629175,2.22263368 C8.94515567,2.17417174 8.92167756,2.11937748 8.8924232,2.06330056 L8.8924232,2.06330056 L8.84420197,1.9788544 C8.72758855,1.79219249 8.59915015,1.70280728 8.42684173,1.70001476 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n\n<ng-template #adaptTemplate>\n <svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/Fit canvas</title>\n <g id=\"1.Base\u57FA\u7840/1.icon\u56FE\u6807/2.normal/Fit-canvas\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M14.9971494,10.4 L14.9971494,13.4020516 C14.9971494,14.2366152 14.3581879,14.9219414 13.542782,14.9955129 L13.3971494,15.0020516 L10.4,15.0020516 L10.4,13.8020516 L13.3971494,13.8020516 C13.590449,13.8020516 13.7517243,13.6649388 13.7890228,13.4826656 L13.7971494,13.4020516 L13.7971494,10.4 L14.9971494,10.4 Z M2.2,10.4 L2.2,13.3971494 C2.2,13.590449 2.3371128,13.7517243 2.51938605,13.7890228 L2.6,13.7971494 L5.60205161,13.7971494 L5.60205161,14.9971494 L2.6,14.9971494 C1.76543638,14.9971494 1.08011021,14.3581879 1.00653868,13.542782 L1,13.3971494 L1,10.4 L2.2,10.4 Z M10.5024511,4.9 C11.3861067,4.9 12.1024511,5.6163444 12.1024511,6.5 L12.1024511,6.5 L12.1024511,9.5 C12.1024511,10.3836556 11.3861067,11.1 10.5024511,11.1 L10.5024511,11.1 L5.50245112,11.1 C4.61879552,11.1 3.90245112,10.3836556 3.90245112,9.5 L3.90245112,9.5 L3.90245112,6.5 C3.90245112,5.6163444 4.61879552,4.9 5.50245112,4.9 L5.50245112,4.9 Z M10.5024511,6.1 L5.50245112,6.1 C5.28153722,6.1 5.10245112,6.2790861 5.10245112,6.5 L5.10245112,6.5 L5.10245112,9.5 C5.10245112,9.7209139 5.28153722,9.9 5.50245112,9.9 L5.50245112,9.9 L10.5024511,9.9 C10.723365,9.9 10.9024511,9.7209139 10.9024511,9.5 L10.9024511,9.5 L10.9024511,6.5 C10.9024511,6.2790861 10.723365,6.1 10.5024511,6.1 L10.5024511,6.1 Z M5.59714938,1 L5.59714938,2.2 L2.6,2.2 C2.40670034,2.2 2.24542508,2.3371128 2.20812658,2.51938605 L2.2,2.6 L2.2,5.60205161 L1,5.60205161 L1,2.6 C1,1.76543638 1.63896152,1.08011021 2.45436739,1.00653868 L2.6,1 L5.59714938,1 Z M13.3971494,1 L13.542782,1.00653868 C14.3581879,1.08011021 14.9971494,1.76543638 14.9971494,2.6 L14.9971494,2.6 L14.9971494,5.60205161 L13.7971494,5.60205161 L13.7971494,2.6 L13.7890228,2.51938605 C13.7517243,2.3371128 13.590449,2.2 13.3971494,2.2 L13.3971494,2.2 L10.4,2.2 L10.4,1 L13.3971494,1 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n<ng-template #zoomOutTemplate>\n <svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>action/zoom-out</title>\n <desc>Created with Sketch.</desc>\n <g id=\"action/zoom-out\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M6.85,2.73225886e-13 C10.6331505,2.73225886e-13 13.7,3.06684946 13.7,6.85 C13.7,8.54194045 13.0865836,10.0906098 12.0700142,11.2857448 L15.4201976,14.5717081 C15.6567367,14.8037768 15.6603607,15.1836585 15.4282919,15.4201976 C15.1962232,15.6567367 14.8163415,15.6603607 14.5798024,15.4282919 L14.5798024,15.4282919 L11.2163456,12.128262 C10.0309427,13.1099691 8.50937591,13.7 6.85,13.7 C3.06684946,13.7 4.58522109e-14,10.6331505 4.58522109e-14,6.85 C4.58522109e-14,3.06684946 3.06684946,2.73225886e-13 6.85,2.73225886e-13 Z M6.85,1.2 C3.72959116,1.2 1.2,3.72959116 1.2,6.85 C1.2,9.97040884 3.72959116,12.5 6.85,12.5 C8.31753357,12.5 9.65438791,11.9404957 10.6588859,11.0231643 C10.6855412,10.9625408 10.7245275,10.9050898 10.7743982,10.8542584 C10.8288931,10.7987137 10.8915387,10.7560124 10.9585649,10.7261903 C11.9144009,9.71595758 12.5,8.35136579 12.5,6.85 C12.5,3.72959116 9.97040884,1.2 6.85,1.2 Z M4.6,6.2 L9.12944565,6.2 C9.4608165,6.2 9.72944565,6.46862915 9.72944565,6.8 C9.72944565,7.09823376 9.51185604,7.34564675 9.22676876,7.39214701 L9.12944565,7.4 L4.6,7.4 C4.26862915,7.4 4,7.13137085 4,6.8 C4,6.50176624 4.21758961,6.25435325 4.50267688,6.20785299 L4.6,6.2 L9.12944565,6.2 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n\n<ng-template #zoomInTemplate\n ><svg\n width=\"16px\"\n height=\"16px\"\n viewBox=\"0 0 16 16\"\n version=\"1.1\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n >\n <title>action/zoom-in</title>\n <desc>Created with Sketch.</desc>\n <g id=\"action/zoom-in\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\n <path\n d=\"M6.85,-1.81188398e-13 C10.6331505,-1.81188398e-13 13.7,3.06684946 13.7,6.85 C13.7,8.54194045 13.0865836,10.0906098 12.0700142,11.2857448 L15.4201976,14.5717081 C15.6567367,14.8037768 15.6603607,15.1836585 15.4282919,15.4201976 C15.1962232,15.6567367 14.8163415,15.6603607 14.5798024,15.4282919 L14.5798024,15.4282919 L11.2163456,12.128262 C10.0309427,13.1099691 8.50937591,13.7 6.85,13.7 C3.06684946,13.7 4.61852778e-14,10.6331505 4.61852778e-14,6.85 C4.61852778e-14,3.06684946 3.06684946,-1.81188398e-13 6.85,-1.81188398e-13 Z M6.85,1.2 C3.72959116,1.2 1.2,3.72959116 1.2,6.85 C1.2,9.97040884 3.72959116,12.5 6.85,12.5 C8.31753357,12.5 9.65438791,11.9404957 10.6588859,11.0231643 C10.6855412,10.9625408 10.7245275,10.9050898 10.7743982,10.8542584 C10.8288931,10.7987137 10.8915387,10.7560124 10.9585649,10.7261903 C11.9144009,9.71595758 12.5,8.35136579 12.5,6.85 C12.5,3.72959116 9.97040884,1.2 6.85,1.2 Z M6.86472282,3.93527718 C7.16295659,3.93527718 7.41036958,4.15286679 7.45686984,4.43795406 L7.46472282,4.53527718 L7.464,6.19927718 L9.12944565,6.2 C9.42767941,6.2 9.6750924,6.41758961 9.72159266,6.70267688 L9.72944565,6.8 C9.72944565,7.09823376 9.51185604,7.34564675 9.22676876,7.39214701 L9.12944565,7.4 L7.464,7.39927718 L7.46472282,9.06472282 C7.46472282,9.36295659 7.24713321,9.61036958 6.96204594,9.65686984 L6.86472282,9.66472282 C6.56648906,9.66472282 6.31907607,9.44713321 6.27257581,9.16204594 L6.26472282,9.06472282 L6.264,7.39927718 L4.6,7.4 C4.30176624,7.4 4.05435325,7.18241039 4.00785299,6.89732312 L4,6.8 C4,6.50176624 4.21758961,6.25435325 4.50267688,6.20785299 L4.6,6.2 L6.264,6.19927718 L6.26472282,4.53527718 C6.26472282,4.2701805 6.43664548,4.0452385 6.67507642,3.96586557 L6.76739971,3.94313016 L6.86472282,3.93527718 Z\"\n id=\"\u5F62\u72B6\u7ED3\u5408\"\n fill-rule=\"nonzero\"\n ></path>\n </g>\n </svg>\n</ng-template>\n" }]
2216
- }], propDecorators: { hostClass: [{
2217
- type: HostBinding,
2218
- args: ['class']
2219
- }], board: [{
2220
- type: Input
2221
- }], adaptHandle: [{
2222
- type: Output
2223
- }], zoomInHandle: [{
2224
- type: Output
2225
- }], zoomOutHandle: [{
2226
- type: Output
2227
- }], resetZoomHandel: [{
2228
- type: Output
2229
- }] } });
2230
-
2231
2320
  const ElementHostClass = 'element-host';
2232
2321
  class PlaitBoardComponent {
2233
2322
  get host() {
2234
2323
  return this.svg.nativeElement;
2235
2324
  }
2236
2325
  get hostClass() {
2237
- return `plait-board-container ${this.board.pointer}`;
2326
+ return `plait-board-container pointer-${this.board.pointer}`;
2238
2327
  }
2239
2328
  get readonly() {
2240
2329
  return this.board.options.readonly;
@@ -2245,8 +2334,9 @@ class PlaitBoardComponent {
2245
2334
  get nativeElement() {
2246
2335
  return this.elementRef.nativeElement;
2247
2336
  }
2248
- constructor(cdr, elementRef, ngZone) {
2337
+ constructor(cdr, viewContainerRef, elementRef, ngZone) {
2249
2338
  this.cdr = cdr;
2339
+ this.viewContainerRef = viewContainerRef;
2250
2340
  this.elementRef = elementRef;
2251
2341
  this.ngZone = ngZone;
2252
2342
  this.hasInitialized = false;
@@ -2286,11 +2376,15 @@ class PlaitBoardComponent {
2286
2376
  viewport: this.board.viewport,
2287
2377
  selection: this.board.selection
2288
2378
  };
2379
+ this.updateIslands();
2289
2380
  this.plaitChange.emit(changeEvent);
2290
2381
  });
2291
2382
  });
2292
2383
  this.hasInitialized = true;
2293
2384
  }
2385
+ ngAfterContentInit() {
2386
+ this.initializeIslands();
2387
+ }
2294
2388
  detect() {
2295
2389
  this.effect = {};
2296
2390
  this.cdr.detectChanges();
@@ -2313,7 +2407,7 @@ class PlaitBoardComponent {
2313
2407
  initializeViewportOffset(this.board);
2314
2408
  }
2315
2409
  initializePlugins() {
2316
- let board = withHandPointer(withHistory(withSelection(withMoving(withBoard(withViewport(createBoard(this.plaitValue, this.plaitOptions)))))));
2410
+ let board = withHandPointer(withHistory(withSelection(withMoving(withBoard(withViewport(withOptions(createBoard(this.plaitValue, this.plaitOptions))))))));
2317
2411
  this.plaitPlugins.forEach(plugin => {
2318
2412
  board = plugin(board);
2319
2413
  });
@@ -2350,21 +2444,24 @@ class PlaitBoardComponent {
2350
2444
  this.board.globalMouseup(event);
2351
2445
  });
2352
2446
  fromEvent(this.host, 'dblclick')
2353
- .pipe(takeUntil(this.destroy$))
2447
+ .pipe(takeUntil(this.destroy$), filter(() => this.isFocused && !PlaitBoard.hasBeenTextEditing(this.board)))
2354
2448
  .subscribe((event) => {
2355
2449
  this.board.dblclick(event);
2356
2450
  });
2357
2451
  fromEvent(document, 'keydown')
2358
- .pipe(takeUntil(this.destroy$), filter(event => this.isFocused && !PlaitBoard.hasBeenTextEditing(this.board) && !hasInputOrTextareaTarget(event.target)))
2359
- .subscribe((event) => {
2360
- if (isHotkey(['mod+=', 'mod++'], { byKey: true })(event)) {
2361
- event.preventDefault();
2362
- this.zoomInHandle(false);
2363
- }
2364
- if (isHotkey('mod+-', { byKey: true })(event)) {
2365
- this.zoomOutHandle();
2366
- event.preventDefault();
2452
+ .pipe(takeUntil(this.destroy$), tap((event) => {
2453
+ if (PlaitBoard.getMovingPoint(this.board)) {
2454
+ if (isHotkey(['mod+=', 'mod++'], { byKey: true })(event)) {
2455
+ event.preventDefault();
2456
+ BoardTransforms.updateZoom(this.board, this.board.viewport.zoom + 0.1, false);
2457
+ }
2458
+ if (isHotkey('mod+-', { byKey: true })(event)) {
2459
+ event.preventDefault();
2460
+ BoardTransforms.updateZoom(this.board, this.board.viewport.zoom - 0.1);
2461
+ }
2367
2462
  }
2463
+ }), filter(event => this.isFocused && !PlaitBoard.hasBeenTextEditing(this.board) && !hasInputOrTextareaTarget(event.target)))
2464
+ .subscribe((event) => {
2368
2465
  this.board?.keydown(event);
2369
2466
  });
2370
2467
  fromEvent(document, 'keyup')
@@ -2381,7 +2478,7 @@ class PlaitBoardComponent {
2381
2478
  fromEvent(document, 'paste')
2382
2479
  .pipe(takeUntil(this.destroy$), filter(() => this.isFocused && !PlaitBoard.isReadonly(this.board) && !PlaitBoard.hasBeenTextEditing(this.board)))
2383
2480
  .subscribe((clipboardEvent) => {
2384
- const mousePoint = BOARD_TO_MOVING_POINT.get(this.board);
2481
+ const mousePoint = PlaitBoard.getMovingPoint(this.board);
2385
2482
  const rect = this.nativeElement.getBoundingClientRect();
2386
2483
  if (mousePoint && distanceBetweenPointAndRectangle(mousePoint[0], mousePoint[1], rect) === 0) {
2387
2484
  const targetPoint = transformPoint(this.board, toPoint(mousePoint[0], mousePoint[1], this.host));
@@ -2414,7 +2511,7 @@ class PlaitBoardComponent {
2414
2511
  if (Point.isEquals(origination, this.board.viewport.origination)) {
2415
2512
  return;
2416
2513
  }
2417
- setViewport(this.board, origination);
2514
+ BoardTransforms.updateViewport(this.board, origination);
2418
2515
  setIsFromScrolling(this.board, true);
2419
2516
  });
2420
2517
  });
@@ -2434,17 +2531,18 @@ class PlaitBoardComponent {
2434
2531
  BOARD_TO_MOVING_POINT.delete(this.board);
2435
2532
  });
2436
2533
  }
2437
- adaptHandle() {
2438
- fitViewport(this.board);
2439
- }
2440
- zoomInHandle(isCenter = true) {
2441
- changeZoom(this.board, this.board.viewport.zoom + 0.1, isCenter);
2442
- }
2443
- zoomOutHandle() {
2444
- changeZoom(this.board, this.board.viewport.zoom - 0.1);
2534
+ initializeIslands() {
2535
+ this.islands?.forEach(island => {
2536
+ island.initialize(this.board);
2537
+ });
2445
2538
  }
2446
- resetZoomHandel() {
2447
- changeZoom(this.board, 1);
2539
+ updateIslands() {
2540
+ this.islands?.forEach(island => {
2541
+ if (hasOnBoardChange(island)) {
2542
+ island.onBoardChange();
2543
+ }
2544
+ island.markForCheck();
2545
+ });
2448
2546
  }
2449
2547
  ngOnDestroy() {
2450
2548
  this.destroy$.next();
@@ -2459,24 +2557,19 @@ class PlaitBoardComponent {
2459
2557
  }
2460
2558
  markForCheck() {
2461
2559
  this.cdr.markForCheck();
2560
+ this.ngZone.run(() => {
2561
+ this.updateIslands();
2562
+ });
2462
2563
  }
2463
2564
  }
2464
- PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
2465
- PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", 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.focused": "this.isFocused" } }, queries: [{ propertyName: "toolbarTemplateRef", first: true, predicate: ["plaitToolbar"], descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }, { propertyName: "viewportContainer", first: true, predicate: ["viewportContainer"], descendants: true, read: ElementRef, static: true }], usesOnChanges: true, ngImport: i0, template: `
2565
+ PlaitBoardComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ViewContainerRef }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
2566
+ PlaitBoardComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.5", 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.focused": "this.isFocused" } }, queries: [{ propertyName: "islands", predicate: PlaitIslandBaseComponent, descendants: true }], viewQueries: [{ propertyName: "svg", first: true, predicate: ["svg"], descendants: true, static: true }, { propertyName: "viewportContainer", first: true, predicate: ["viewportContainer"], descendants: true, read: ElementRef, static: true }], usesOnChanges: true, ngImport: i0, template: `
2466
2567
  <div class="viewport-container" #viewportContainer>
2467
2568
  <svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
2468
2569
  <plait-children [board]="board" [effect]="effect"></plait-children>
2469
2570
  </div>
2470
- <plait-toolbar
2471
- *ngIf="isFocused && !toolbarTemplateRef"
2472
- [board]="board"
2473
- (adaptHandle)="adaptHandle()"
2474
- (zoomInHandle)="zoomInHandle()"
2475
- (zoomOutHandle)="zoomOutHandle()"
2476
- (resetZoomHandel)="resetZoomHandel()"
2477
- ></plait-toolbar>
2478
2571
  <ng-content></ng-content>
2479
- `, isInline: true, dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: PlaitChildrenElement, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }, { kind: "component", type: PlaitToolbarComponent, selector: "plait-toolbar", inputs: ["board"], outputs: ["adaptHandle", "zoomInHandle", "zoomOutHandle", "resetZoomHandel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2572
+ `, isInline: true, dependencies: [{ kind: "component", type: PlaitChildrenElement, selector: "plait-children", inputs: ["board", "parent", "effect", "parentG"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2480
2573
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitBoardComponent, decorators: [{
2481
2574
  type: Component,
2482
2575
  args: [{
@@ -2486,19 +2579,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2486
2579
  <svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
2487
2580
  <plait-children [board]="board" [effect]="effect"></plait-children>
2488
2581
  </div>
2489
- <plait-toolbar
2490
- *ngIf="isFocused && !toolbarTemplateRef"
2491
- [board]="board"
2492
- (adaptHandle)="adaptHandle()"
2493
- (zoomInHandle)="zoomInHandle()"
2494
- (zoomOutHandle)="zoomOutHandle()"
2495
- (resetZoomHandel)="resetZoomHandel()"
2496
- ></plait-toolbar>
2497
2582
  <ng-content></ng-content>
2498
2583
  `,
2499
2584
  changeDetection: ChangeDetectionStrategy.OnPush
2500
2585
  }]
2501
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: { plaitValue: [{
2586
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ViewContainerRef }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: { plaitValue: [{
2502
2587
  type: Input
2503
2588
  }], plaitViewport: [{
2504
2589
  type: Input
@@ -2522,19 +2607,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2522
2607
  }], svg: [{
2523
2608
  type: ViewChild,
2524
2609
  args: ['svg', { static: true }]
2525
- }], toolbarTemplateRef: [{
2526
- type: ContentChild,
2527
- args: ['plaitToolbar']
2528
2610
  }], viewportContainer: [{
2529
2611
  type: ViewChild,
2530
2612
  args: ['viewportContainer', { read: ElementRef, static: true }]
2613
+ }], islands: [{
2614
+ type: ContentChildren,
2615
+ args: [PlaitIslandBaseComponent, { descendants: true }]
2531
2616
  }] } });
2532
2617
 
2533
- const COMPONENTS = [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent, PlaitToolbarComponent];
2618
+ const COMPONENTS = [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent];
2534
2619
  class PlaitModule {
2535
2620
  }
2536
2621
  PlaitModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2537
- PlaitModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, declarations: [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent, PlaitToolbarComponent], imports: [CommonModule], exports: [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent, PlaitToolbarComponent] });
2622
+ PlaitModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, declarations: [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent], imports: [CommonModule], exports: [PlaitBoardComponent, PlaitChildrenElement, PlaitElementComponent] });
2538
2623
  PlaitModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, imports: [CommonModule] });
2539
2624
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImport: i0, type: PlaitModule, decorators: [{
2540
2625
  type: NgModule,
@@ -2545,6 +2630,35 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2545
2630
  }]
2546
2631
  }] });
2547
2632
 
2633
+ /**
2634
+ * 1.create board instance
2635
+ * 2.build fake node weak map
2636
+ */
2637
+ const createTestingBoard = (plugins, children, options = { readonly: false, hideScrollbar: true }) => {
2638
+ let board = createBoard(children, options);
2639
+ plugins.forEach(plugin => {
2640
+ board = plugin(board);
2641
+ });
2642
+ return board;
2643
+ };
2644
+
2645
+ const fakeNodeWeakMap = (object) => {
2646
+ const children = object.children || [];
2647
+ children.forEach((value, index) => {
2648
+ NODE_TO_PARENT.set(value, object);
2649
+ NODE_TO_INDEX.set(value, index);
2650
+ fakeNodeWeakMap(value);
2651
+ });
2652
+ };
2653
+ const clearNodeWeakMap = (object) => {
2654
+ const children = object.children || [];
2655
+ children.forEach(value => {
2656
+ NODE_TO_PARENT.delete(value);
2657
+ NODE_TO_INDEX.delete(value);
2658
+ clearNodeWeakMap(value);
2659
+ });
2660
+ };
2661
+
2548
2662
  /*
2549
2663
  * Public API Surface of plait
2550
2664
  */
@@ -2553,5 +2667,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2553
2667
  * Generated bundle index. Do not edit.
2554
2668
  */
2555
2669
 
2556
- 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, 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, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPointerType, PlaitToolbarComponent, Point, RectangleClient, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, changeZoom, clampZoomLevel, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createForeignObject, createG, createSVG, createSelectionOuterG, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawRoundRectangle, fitViewport, getBoardRectangle, getElementHostBBox, getHitElements, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange, isInPlaitBoard, isIntersectionElements, isNullOrUndefined, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, setViewport, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateForeignObject, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
2670
+ 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, 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, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, 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, isInPlaitBoard, isIntersectionElements, isMainPointer, isNullOrUndefined, isSecondaryPointer, isSelectedElement, isSelectionMoving, isSetViewportOperation, normalizePoint, removeMovingElements, removeSelectedElement, rotate, scrollToRectangle, setIsFromScrolling, setIsFromViewportChange, setSVGViewBox, setSelectionMoving, shouldClear, shouldMerge, shouldSave, throttleRAF, toPoint, transformPoint, transformPoints, updateForeignObject, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withOptions, withSelection };
2557
2671
  //# sourceMappingURL=plait-core.mjs.map