@plait/core 0.2.0-next.8 → 0.2.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.
@@ -213,6 +213,13 @@ const Path = {
213
213
  const last = path[path.length - 1];
214
214
  return path.slice(0, -1).concat(last + 1);
215
215
  },
216
+ previous(path) {
217
+ if (path.length === 0) {
218
+ throw new Error(`Cannot get the next path of a root path [${path}], because it has no previous index.`);
219
+ }
220
+ const last = path[path.length - 1];
221
+ return path.slice(0, -1).concat(last - 1);
222
+ },
216
223
  /**
217
224
  * Check if a path is an ancestor of another.
218
225
  */
@@ -660,6 +667,24 @@ function createText(x, y, fill, textContent) {
660
667
  return text;
661
668
  }
662
669
 
670
+ function createForeignObject(x, y, width, height) {
671
+ var newForeignObject = document.createElementNS(NS, 'foreignObject');
672
+ newForeignObject.setAttribute('x', `${x}`);
673
+ newForeignObject.setAttribute('y', `${y}`);
674
+ newForeignObject.setAttribute('width', `${width}`);
675
+ newForeignObject.setAttribute('height', `${height}`);
676
+ return newForeignObject;
677
+ }
678
+ function updateForeignObject(g, width, height, x, y) {
679
+ const foreignObject = g.querySelector('foreignObject');
680
+ if (foreignObject) {
681
+ foreignObject.setAttribute('width', `${width}`);
682
+ foreignObject.setAttribute('height', `${height}`);
683
+ foreignObject.setAttribute('x', `${x}`);
684
+ foreignObject.setAttribute('y', `${y}`);
685
+ }
686
+ }
687
+
663
688
  const IS_IOS = typeof navigator !== 'undefined' &&
664
689
  typeof window !== 'undefined' &&
665
690
  /iPad|iPhone|iPod/.test(navigator.userAgent) &&
@@ -860,6 +885,12 @@ const RectangleClient = {
860
885
  width: rectangle.width + Math.abs(offset) * 2,
861
886
  height: rectangle.height + Math.abs(offset) * 2
862
887
  };
888
+ },
889
+ isEqual: (rectangle, otherRectangle) => {
890
+ return (rectangle.x === otherRectangle.x &&
891
+ rectangle.y === otherRectangle.y &&
892
+ rectangle.width === otherRectangle.width &&
893
+ rectangle.height === otherRectangle.height);
863
894
  }
864
895
  };
865
896
 
@@ -1750,7 +1781,11 @@ function withSelection(board) {
1750
1781
  selectionMovingG?.remove();
1751
1782
  if (Math.hypot(width, height) > 5) {
1752
1783
  end = movedTarget;
1753
- Transforms.setSelection(board, { ranges: [{ anchor: start, focus: end }] });
1784
+ throttleRAF(() => {
1785
+ if (start && end) {
1786
+ Transforms.setSelection(board, { ranges: [{ anchor: start, focus: end }] });
1787
+ }
1788
+ });
1754
1789
  setSelectionMoving(board);
1755
1790
  const rough = PlaitBoard.getRoughSVG(board);
1756
1791
  selectionMovingG = rough.rectangle(x, y, width, height, {
@@ -2005,8 +2040,8 @@ class PlaitElementComponent {
2005
2040
  if (this.index > 0) {
2006
2041
  const brotherElement = this.parent.children[this.index - 1];
2007
2042
  const lastElement = PlaitNode.last(this.board, PlaitBoard.findPath(this.board, brotherElement));
2008
- const siblingElement = lastElement || brotherElement;
2009
- siblingG = PlaitElement.getComponent(siblingElement).g;
2043
+ let component = PlaitElement.getComponent(lastElement) || PlaitElement.getComponent(brotherElement);
2044
+ siblingG = component.g;
2010
2045
  }
2011
2046
  this.parentG.insertBefore(g, siblingG);
2012
2047
  }
@@ -2493,5 +2528,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2493
2528
  * Generated bundle index. Do not edit.
2494
2529
  */
2495
2530
 
2496
- 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, 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, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, 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, updateViewportContainerScroll, updateViewportOffset, updateViewportOrigination, withMoving, withSelection };
2531
+ 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, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, 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 };
2497
2532
  //# sourceMappingURL=plait-core.mjs.map