@plait/core 0.5.0 → 0.8.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.
@@ -61,6 +61,14 @@ function getRectangleByElements(board, elements, recursion) {
61
61
  calcRectangleClient(element);
62
62
  }
63
63
  });
64
+ if (boundaryBox.left === Number.MAX_VALUE) {
65
+ return {
66
+ x: 0,
67
+ y: 0,
68
+ width: 0,
69
+ height: 0
70
+ };
71
+ }
64
72
  return {
65
73
  x: boundaryBox.left,
66
74
  y: boundaryBox.top,
@@ -72,6 +80,54 @@ function getBoardRectangle(board) {
72
80
  return getRectangleByElements(board, board.children, true);
73
81
  }
74
82
 
83
+ var ThemeColorMode;
84
+ (function (ThemeColorMode) {
85
+ ThemeColorMode["default"] = "default";
86
+ ThemeColorMode["colorful"] = "colorful";
87
+ ThemeColorMode["soft"] = "soft";
88
+ ThemeColorMode["retro"] = "retro";
89
+ ThemeColorMode["dark"] = "dark";
90
+ ThemeColorMode["starry"] = "starry";
91
+ })(ThemeColorMode || (ThemeColorMode = {}));
92
+ const DefaultThemeColor = {
93
+ mode: ThemeColorMode.default,
94
+ boardBackground: '#ffffff',
95
+ textColor: '#333333'
96
+ };
97
+ const ColorfulThemeColor = {
98
+ mode: ThemeColorMode.colorful,
99
+ boardBackground: '#ffffff',
100
+ textColor: '#333333'
101
+ };
102
+ const SoftThemeColor = {
103
+ mode: ThemeColorMode.soft,
104
+ boardBackground: '#f5f5f5',
105
+ textColor: '#333333'
106
+ };
107
+ const RetroThemeColor = {
108
+ mode: ThemeColorMode.retro,
109
+ boardBackground: '#f9f8ed',
110
+ textColor: '#333333'
111
+ };
112
+ const DarkThemeColor = {
113
+ mode: ThemeColorMode.dark,
114
+ boardBackground: '#141414',
115
+ textColor: '#FFFFFF'
116
+ };
117
+ const StarryThemeColor = {
118
+ mode: ThemeColorMode.starry,
119
+ boardBackground: '#0d2537',
120
+ textColor: '#FFFFFF'
121
+ };
122
+ const ThemeColors = [
123
+ DefaultThemeColor,
124
+ ColorfulThemeColor,
125
+ SoftThemeColor,
126
+ RetroThemeColor,
127
+ DarkThemeColor,
128
+ StarryThemeColor
129
+ ];
130
+
75
131
  const PlaitBoard = {
76
132
  isBoard(value) {
77
133
  const cachedIsBoard = IS_BOARD_CACHE.get(value);
@@ -142,6 +198,9 @@ const PlaitBoard = {
142
198
  },
143
199
  getMovingPoint(board) {
144
200
  return BOARD_TO_MOVING_POINT.get(board);
201
+ },
202
+ getThemeColors(board) {
203
+ return (board.options.themeColors || ThemeColors);
145
204
  }
146
205
  };
147
206
 
@@ -393,7 +452,7 @@ const PlaitNode = {
393
452
  }
394
453
  };
395
454
 
396
- const applyToDraft = (board, selection, viewport, op) => {
455
+ const applyToDraft = (board, selection, viewport, theme, op) => {
397
456
  switch (op.type) {
398
457
  case 'insert_node': {
399
458
  const { path, node } = op;
@@ -498,8 +557,13 @@ const applyToDraft = (board, selection, viewport, op) => {
498
557
  }
499
558
  break;
500
559
  }
560
+ case 'set_theme': {
561
+ const { newProperties } = op;
562
+ theme = newProperties;
563
+ break;
564
+ }
501
565
  }
502
- return { selection, viewport };
566
+ return { selection, viewport, theme };
503
567
  };
504
568
  const GeneralTransforms = {
505
569
  /**
@@ -509,10 +573,12 @@ const GeneralTransforms = {
509
573
  board.children = createDraft(board.children);
510
574
  let viewport = board.viewport && createDraft(board.viewport);
511
575
  let selection = board.selection && createDraft(board.selection);
576
+ let theme = board.theme && createDraft(board.theme);
512
577
  try {
513
- const state = applyToDraft(board, selection, viewport, op);
578
+ const state = applyToDraft(board, selection, viewport, theme, op);
514
579
  viewport = state.viewport;
515
580
  selection = state.selection;
581
+ theme = state.theme;
516
582
  }
517
583
  finally {
518
584
  board.children = finishDraft(board.children);
@@ -523,6 +589,7 @@ const GeneralTransforms = {
523
589
  board.selection = null;
524
590
  }
525
591
  board.viewport = isDraft(viewport) ? finishDraft(viewport) : viewport;
592
+ board.theme = isDraft(theme) ? finishDraft(theme) : theme;
526
593
  }
527
594
  }
528
595
  };
@@ -582,7 +649,7 @@ function setViewport(board, viewport) {
582
649
  const operation = { type: 'set_viewport', properties: board.viewport, newProperties: viewport };
583
650
  board.apply(operation);
584
651
  }
585
- const ViewportTransforms = {
652
+ const ViewportTransforms$1 = {
586
653
  setViewport
587
654
  };
588
655
 
@@ -1350,6 +1417,10 @@ const inverse = (op) => {
1350
1417
  return { ...op, properties: newProperties, newProperties: properties };
1351
1418
  }
1352
1419
  }
1420
+ case 'set_theme': {
1421
+ const { properties, newProperties } = op;
1422
+ return { ...op, properties: newProperties, newProperties: properties };
1423
+ }
1353
1424
  }
1354
1425
  };
1355
1426
  const PlaitOperation = {
@@ -1443,18 +1514,16 @@ function clampZoomLevel(zoom, minZoom = 0.2, maxZoom = 4) {
1443
1514
  }
1444
1515
  function getViewBox(board, zoom) {
1445
1516
  const { hideScrollbar } = board.options;
1446
- const scrollBarWidth = hideScrollbar ? SCROLL_BAR_WIDTH : 0;
1517
+ const scrollBarWidth = hideScrollbar ? 0 : SCROLL_BAR_WIDTH;
1447
1518
  const viewportContainerRect = PlaitBoard.getBoardNativeElement(board).getBoundingClientRect();
1448
1519
  const elementHostBBox = getElementHostBBox(board, zoom);
1449
1520
  const horizontalPadding = viewportContainerRect.width / 2;
1450
1521
  const verticalPadding = viewportContainerRect.height / 2;
1451
- const viewportWidth = (elementHostBBox.right - elementHostBBox.left) * zoom + 2 * horizontalPadding + scrollBarWidth;
1452
- const viewportHeight = (elementHostBBox.bottom - elementHostBBox.top) * zoom + 2 * verticalPadding + scrollBarWidth;
1453
1522
  const viewBox = [
1454
1523
  elementHostBBox.left - horizontalPadding / zoom,
1455
1524
  elementHostBBox.top - verticalPadding / zoom,
1456
- viewportWidth / zoom,
1457
- viewportHeight / zoom
1525
+ elementHostBBox.right - elementHostBBox.left + (horizontalPadding * 2 - scrollBarWidth) / zoom,
1526
+ elementHostBBox.bottom - elementHostBBox.top + (verticalPadding * 2 - scrollBarWidth) / zoom
1458
1527
  ];
1459
1528
  return viewBox;
1460
1529
  }
@@ -1540,6 +1609,14 @@ const setIsFromViewportChange = (board, state) => {
1540
1609
  };
1541
1610
  function scrollToRectangle(board, client) { }
1542
1611
 
1612
+ function setTheme(board, themeColorMode) {
1613
+ const operation = { type: 'set_theme', properties: board.theme, newProperties: themeColorMode };
1614
+ board.apply(operation);
1615
+ }
1616
+ const ViewportTransforms = {
1617
+ setTheme
1618
+ };
1619
+
1543
1620
  function updateViewport(board, origination, zoom) {
1544
1621
  zoom = zoom ?? board.viewport.zoom;
1545
1622
  setViewport(board, {
@@ -1595,16 +1672,28 @@ function fitViewport(board) {
1595
1672
  ];
1596
1673
  updateViewport(board, newOrigination, newZoom);
1597
1674
  }
1675
+ /**
1676
+ * apply theme to every element (remove element custom properties)
1677
+ * invoke applyThemeColor
1678
+ */
1679
+ function updateThemeColor(board, mode) {
1680
+ mode = mode ?? board.theme.themeColorMode;
1681
+ setTheme(board, { themeColorMode: mode });
1682
+ depthFirstRecursion(board, element => {
1683
+ board.applyTheme(element);
1684
+ });
1685
+ }
1598
1686
  const BoardTransforms = {
1599
1687
  updatePointerType,
1600
1688
  updateViewport,
1601
1689
  fitViewport,
1602
- updateZoom
1690
+ updateZoom,
1691
+ updateThemeColor
1603
1692
  };
1604
1693
 
1605
1694
  const Transforms = {
1606
1695
  ...GeneralTransforms,
1607
- ...ViewportTransforms,
1696
+ ...ViewportTransforms$1,
1608
1697
  ...SelectionTransforms,
1609
1698
  ...NodeTransforms
1610
1699
  };
@@ -1626,10 +1715,10 @@ const PathRef = {
1626
1715
  function createBoard(children, options) {
1627
1716
  const board = {
1628
1717
  viewport: {
1629
- zoom: 1,
1630
- viewBackgroundColor: '#000'
1718
+ zoom: 1
1631
1719
  },
1632
1720
  children,
1721
+ theme: { themeColorMode: ThemeColorMode.default },
1633
1722
  operations: [],
1634
1723
  history: {
1635
1724
  redos: [],
@@ -1703,7 +1792,8 @@ function createBoard(children, options) {
1703
1792
  isHitSelection: element => false,
1704
1793
  isRecursion: element => true,
1705
1794
  isMovable: element => false,
1706
- getRectangle: element => null
1795
+ getRectangle: element => null,
1796
+ applyTheme: (element) => { }
1707
1797
  };
1708
1798
  return board;
1709
1799
  }
@@ -1881,12 +1971,18 @@ function withSelection(board) {
1881
1971
  return;
1882
1972
  }
1883
1973
  const range = { anchor: point, focus: point };
1974
+ const hitElements = getHitElements(board, { ranges: [range] });
1884
1975
  if (PlaitBoard.isPointer(board, PlaitPointerType.selection) &&
1885
1976
  getHitElements(board, { ranges: [range] }).length === 0 &&
1977
+ hitElements.length === 0 &&
1886
1978
  options.isMultiple &&
1887
1979
  !options.isDisabledSelect) {
1888
1980
  start = point;
1889
1981
  }
1982
+ if (PlaitBoard.isPointer(board, PlaitPointerType.selection) && hitElements.length === 0 && !PlaitBoard.hasBeenTextEditing(board)) {
1983
+ // prevent text from being selected
1984
+ event.preventDefault();
1985
+ }
1890
1986
  Transforms.setSelection(board, { ranges: ranges });
1891
1987
  mousedown(event);
1892
1988
  };
@@ -2327,7 +2423,7 @@ class PlaitBoardComponent {
2327
2423
  return this.svg.nativeElement;
2328
2424
  }
2329
2425
  get hostClass() {
2330
- return `plait-board-container pointer-${this.board.pointer}`;
2426
+ return `plait-board-container pointer-${this.board.pointer} theme-${this.board.theme.themeColorMode}`;
2331
2427
  }
2332
2428
  get readonly() {
2333
2429
  return this.board.options.readonly;
@@ -2381,7 +2477,8 @@ class PlaitBoardComponent {
2381
2477
  children: this.board.children,
2382
2478
  operations: this.board.operations,
2383
2479
  viewport: this.board.viewport,
2384
- selection: this.board.selection
2480
+ selection: this.board.selection,
2481
+ theme: this.board.theme
2385
2482
  };
2386
2483
  this.updateIslands();
2387
2484
  this.plaitChange.emit(changeEvent);
@@ -2422,6 +2519,9 @@ class PlaitBoardComponent {
2422
2519
  if (this.plaitViewport) {
2423
2520
  this.board.viewport = this.plaitViewport;
2424
2521
  }
2522
+ if (this.plaitTheme) {
2523
+ this.board.theme = this.plaitTheme;
2524
+ }
2425
2525
  }
2426
2526
  initializeHookListener() {
2427
2527
  fromEvent(this.host, 'mousedown')
@@ -2466,6 +2566,16 @@ class PlaitBoardComponent {
2466
2566
  event.preventDefault();
2467
2567
  BoardTransforms.updateZoom(this.board, this.board.viewport.zoom - 0.1);
2468
2568
  }
2569
+ if (isHotkey('mod+0', { byKey: true })(event)) {
2570
+ event.preventDefault();
2571
+ BoardTransforms.updateZoom(this.board, 1);
2572
+ return;
2573
+ }
2574
+ if (isHotkey('mod+shift+=', { byKey: true })(event)) {
2575
+ event.preventDefault();
2576
+ BoardTransforms.fitViewport(this.board);
2577
+ return;
2578
+ }
2469
2579
  }
2470
2580
  }), filter(event => this.isFocused && !PlaitBoard.hasBeenTextEditing(this.board) && !hasInputOrTextareaTarget(event.target)))
2471
2581
  .subscribe((event) => {
@@ -2569,9 +2679,9 @@ class PlaitBoardComponent {
2569
2679
  }
2570
2680
  }
2571
2681
  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 });
2572
- 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", "class.disabled-scroll": "this.disabledScrollOnNonFocus" } }, 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: `
2682
+ 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", plaitTheme: "plaitTheme" }, outputs: { plaitChange: "plaitChange", plaitBoardInitialized: "plaitBoardInitialized" }, host: { properties: { "class": "this.hostClass", "class.readonly": "this.readonly", "class.focused": "this.isFocused", "class.disabled-scroll": "this.disabledScrollOnNonFocus" } }, 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: `
2573
2683
  <div class="viewport-container" #viewportContainer>
2574
- <svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
2684
+ <svg #svg width="100%" height="100%" style="position: relative;" class="board-host-svg"><g class="element-host"></g></svg>
2575
2685
  <plait-children [board]="board" [effect]="effect"></plait-children>
2576
2686
  </div>
2577
2687
  <ng-content></ng-content>
@@ -2582,7 +2692,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2582
2692
  selector: 'plait-board',
2583
2693
  template: `
2584
2694
  <div class="viewport-container" #viewportContainer>
2585
- <svg #svg width="100%" height="100%" style="position: relative;"><g class="element-host"></g></svg>
2695
+ <svg #svg width="100%" height="100%" style="position: relative;" class="board-host-svg"><g class="element-host"></g></svg>
2586
2696
  <plait-children [board]="board" [effect]="effect"></plait-children>
2587
2697
  </div>
2588
2698
  <ng-content></ng-content>
@@ -2597,6 +2707,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.5", ngImpor
2597
2707
  type: Input
2598
2708
  }], plaitOptions: [{
2599
2709
  type: Input
2710
+ }], plaitTheme: [{
2711
+ type: Input
2600
2712
  }], plaitChange: [{
2601
2713
  type: Output
2602
2714
  }], plaitBoardInitialized: [{
@@ -2676,5 +2788,5 @@ const clearNodeWeakMap = (object) => {
2676
2788
  * Generated bundle index. Do not edit.
2677
2789
  */
2678
2790
 
2679
- 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 };
2791
+ export { BOARD_TO_COMPONENT, BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_IS_SELECTION_MOVING, BOARD_TO_MOVING_ELEMENT, BOARD_TO_MOVING_POINT, BOARD_TO_ON_CHANGE, BOARD_TO_ROUGH_SVG, BOARD_TO_SELECTED_ELEMENT, BOARD_TO_TEMPORARY_ELEMENTS, BOARD_TO_VIEWPORT_ORIGINATION, BoardTransforms, CLIP_BOARD_FORMAT_KEY, ColorfulThemeColor, DarkThemeColor, DefaultThemeColor, ELEMENT_TO_COMPONENT, FLUSHING, IS_APPLE, IS_BOARD_CACHE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_IOS, IS_SAFARI, IS_TEXT_EDITABLE, MAX_RADIUS, MERGING, NODE_TO_INDEX, NODE_TO_PARENT, NS, PATH_REFS, POINTER_BUTTON, Path, PlaitBoard, PlaitBoardComponent, PlaitChildrenElement, PlaitElement, PlaitElementComponent, PlaitHistoryBoard, PlaitIslandBaseComponent, PlaitModule, PlaitNode, PlaitOperation, PlaitPluginElementComponent, PlaitPluginKey, PlaitPointerType, Point, RectangleClient, RetroThemeColor, SAVING, SCROLL_BAR_WIDTH, SELECTION_BORDER_COLOR, SELECTION_FILL_COLOR, Selection, SoftThemeColor, StarryThemeColor, ThemeColorMode, ThemeColors, Transforms, Viewport, addMovingElements, addSelectedElement, arrowPoints, cacheMovingElements, cacheSelectedElements, clampZoomLevel, clearNodeWeakMap, clearSelectedElement, clearSelectionMoving, clearViewportOrigination, createForeignObject, createG, createPath, createSVG, createSelectionOuterG, createTestingBoard, createText, debounce, deleteTemporaryElements, depthFirstRecursion, distanceBetweenPointAndPoint, distanceBetweenPointAndRectangle, distanceBetweenPointAndSegment, drawAbstractRoundRectangle, drawArrow, drawCircle, drawLine, drawLinearPath, drawRoundRectangle, fakeNodeWeakMap, getBoardRectangle, getElementHostBBox, getHitElements, getMovingElements, getRectangleByElements, getSelectedElements, getTemporaryElements, getViewBox, getViewportContainerRect, getViewportOrigination, hasBeforeContextChange, hasInputOrTextareaTarget, hasOnBoardChange, hasOnContextChanged, hotkeys, idCreator, initializeViewBox, initializeViewportContainer, initializeViewportOffset, inverse, isDOMElement, isDOMNode, isFromScrolling, isFromViewportChange, 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 };
2680
2792
  //# sourceMappingURL=plait-core.mjs.map