@8btc/whiteboard 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -358,10 +358,6 @@
358
358
  pointer-events: auto;
359
359
  }
360
360
 
361
- .pointer-events-none {
362
- pointer-events: none;
363
- }
364
-
365
361
  .visible {
366
362
  visibility: visible;
367
363
  }
@@ -561,10 +557,6 @@
561
557
  touch-action: none;
562
558
  }
563
559
 
564
- .resize {
565
- resize: both;
566
- }
567
-
568
560
  .grid-cols-2 {
569
561
  grid-template-columns: repeat(2, minmax(0, 1fr));
570
562
  }
package/dist/index.d.ts CHANGED
@@ -60,8 +60,9 @@ export declare class CanvasApi extends CanvasCore {
60
60
  * 删除指定的节点
61
61
  * 如果删除的是 image 节点,会同步删除所有关联的 image-marker
62
62
  * @param nodeIds - 要删除的节点 ID 数组
63
+ * @returns 被删除的节点数据数组
63
64
  */
64
- deleteNodes(nodeIds: string[]): void;
65
+ deleteNodes(nodeIds: string[]): INode[];
65
66
  /**
66
67
  * 滚动到内容区域
67
68
  * - 如果提供了 nodeIds,将指定的节点居中显示
@@ -93,7 +94,7 @@ declare class CanvasCore extends CanvasState_2 {
93
94
  /**
94
95
  * 发射事件(供内部类使用)
95
96
  */
96
- emitEvent<K extends keyof StateEvents>(event: K, data: StateEvents[K]): void;
97
+ emitEvent<StageEvent extends keyof StateEvents>(event: StageEvent, data: StateEvents[StageEvent]): void;
97
98
  /**
98
99
  * 获取 Konva.Stage 实例
99
100
  */
@@ -385,6 +386,8 @@ declare type StateEvents = {
385
386
  "viewport:change": ICoreState["viewport"];
386
387
  "transformer:positionChange": TransformerPosition | null;
387
388
  "toolType:change": ICoreState["toolType"];
389
+ "nodes:created": ICoreState["nodes"];
390
+ "nodes:deleted": INode[];
388
391
  };
389
392
 
390
393
  export declare type ToolType = "select" | "hand" | "rectangle" | "image-marker";
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
- var _core, _stage, _viewport, _handleWheel, _handlePointerDown, _handlePointerMove, _handlePointerUp, _handleDragStart, _handleDragMove, _handleDragEnd, _CanvasStage_instances, setupEventListeners_fn, _core2, _transformer, _handleTransformStart, _handleTransform, _handleTransformEnd, _handleDragStart2, _handleDragMove2, _handleDragEnd2, _CanvasTransformer_instances, setupEventListeners_fn2, _animation, _RectNode_instances, initAnimation_fn, destroyAnimation_fn, _toolTypeChangeHandler, setupEventHandlers_fn, _ImageNode_instances, loadImage_fn, _toolTypeChangeHandler2, setupEventHandlers_fn2, syncImageMarkers_fn, syncImageMarkersToState_fn, _rect, _markerGroup, _circle, _text, _ImageMarkerNode_instances, setupEventHandlers_fn3, _canvasStage, _mainLayer, _canvasTransformer, _draftNode;
12
+ var _core, _stage, _viewport, _handleWheel, _handlePointerDown, _handlePointerMove, _handlePointerUp, _handleDragStart, _handleDragMove, _handleDragEnd, _CanvasStage_instances, setupEventListeners_fn, _core2, _transformer, _handleTransformStart, _handleTransform, _handleTransformEnd, _handleDragStart2, _handleDragMove2, _handleDragEnd2, _CanvasTransformer_instances, setupEventListeners_fn2, _toolTypeChangeHandler, _RectNode_instances, setupEventHandlers_fn, _ImageNode_instances, loadImage_fn, _toolTypeChangeHandler2, setupEventHandlers_fn2, syncImageMarkers_fn, syncImageMarkersToState_fn, _rect, _markerGroup, _circle, _text, _ImageMarkerNode_instances, setupEventHandlers_fn3, _canvasStage, _mainLayer, _canvasTransformer, _draftNode;
13
13
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
14
14
  import { useState, useEffect, useRef } from "react";
15
15
  import Konva from "konva";
@@ -510,66 +510,13 @@ class CanvasState {
510
510
  }
511
511
  }
512
512
  const NODE_NAME_FOR_SELECT = "shapeNameForSelect";
513
- const RECT$1 = {
513
+ const RECT = {
514
514
  CORNER_RADIUS: 6,
515
515
  MIN_SIZE: 10
516
516
  };
517
517
  const IMAGE = {
518
518
  MIN_SIZE: 10
519
519
  };
520
- const RECT = {
521
- MIN_SIZE: 10
522
- };
523
- function clamp(value, range) {
524
- return Math.min(Math.max(value, range[0]), range[1]);
525
- }
526
- function calculatePerimeter(width, height, cornerRadius) {
527
- return 2 * (height + width - cornerRadius * (4 - Math.PI));
528
- }
529
- function getDashValue(shapeLength, strokeWidth, lineStyle) {
530
- let ratio = 1;
531
- let dashLength = 0;
532
- let dashGap = 0;
533
- switch (lineStyle) {
534
- case "dashed":
535
- dashLength = Math.min(strokeWidth * 2, shapeLength / 4);
536
- break;
537
- case "dotted":
538
- ratio = 8;
539
- dashLength = strokeWidth / ratio;
540
- break;
541
- default:
542
- return [];
543
- }
544
- let dashCount = Math.floor(shapeLength / dashLength / (2 * ratio));
545
- dashCount = Math.max(dashCount, 3);
546
- dashLength = shapeLength / dashCount / (2 * ratio);
547
- dashGap = (shapeLength - dashCount * dashLength) / dashCount;
548
- return [dashLength, dashGap];
549
- }
550
- function getSizeValue(key) {
551
- switch (key) {
552
- case "small":
553
- return 2;
554
- case "medium":
555
- return 3;
556
- case "large":
557
- return 5;
558
- case "extra-large":
559
- return 8;
560
- default:
561
- return 3;
562
- }
563
- }
564
- function getTotalDashLength(dash) {
565
- return Array.isArray(dash) && dash.length > 1 ? dash[0] + dash[1] : 0;
566
- }
567
- function getRectSize(rect) {
568
- return {
569
- width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
570
- height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
571
- };
572
- }
573
520
  class BaseCanvasNode {
574
521
  constructor(core, node) {
575
522
  __publicField(this, "core");
@@ -592,43 +539,30 @@ class BaseCanvasNode {
592
539
  return this.node;
593
540
  }
594
541
  }
595
- function createRectAnimation(rect, totalDashLength) {
596
- if (!totalDashLength || totalDashLength === 0) {
597
- return null;
598
- }
599
- const anim = new Konva.Animation((frame) => {
600
- if (!frame) return;
601
- const dashOffset = -frame.time / 10 % totalDashLength;
602
- rect.dashOffset(dashOffset);
603
- }, rect.getLayer());
542
+ function getRectSize(rect) {
604
543
  return {
605
- start: () => anim.start(),
606
- stop: () => anim.stop(),
607
- isRunning: () => anim.isRunning()
544
+ width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
545
+ height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
608
546
  };
609
547
  }
610
548
  class RectNode extends BaseCanvasNode {
611
549
  constructor(core, node) {
612
550
  super(core, node);
613
551
  __privateAdd(this, _RectNode_instances);
614
- __privateAdd(this, _animation, null);
615
552
  __privateAdd(this, _toolTypeChangeHandler, (toolType) => {
616
553
  const isSelect = toolType === "select";
617
554
  this.element.listening(isSelect);
618
555
  });
619
- if (node.style.animated) {
620
- __privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
621
- }
622
556
  __privateMethod(this, _RectNode_instances, setupEventHandlers_fn).call(this, this.getElement());
623
557
  }
624
558
  createElement() {
625
559
  const width = Math.max(
626
- this.node.props.width ?? RECT$1.MIN_SIZE,
627
- RECT$1.MIN_SIZE
560
+ this.node.props.width ?? RECT.MIN_SIZE,
561
+ RECT.MIN_SIZE
628
562
  );
629
563
  const height = Math.max(
630
- this.node.props.height ?? RECT$1.MIN_SIZE,
631
- RECT$1.MIN_SIZE
564
+ this.node.props.height ?? RECT.MIN_SIZE,
565
+ RECT.MIN_SIZE
632
566
  );
633
567
  const config = {
634
568
  id: this.node.id,
@@ -636,7 +570,7 @@ class RectNode extends BaseCanvasNode {
636
570
  ...this.node.style,
637
571
  width,
638
572
  height,
639
- cornerRadius: RECT$1.CORNER_RADIUS,
573
+ cornerRadius: RECT.CORNER_RADIUS,
640
574
  name: NODE_NAME_FOR_SELECT,
641
575
  draggable: true,
642
576
  stroke: "black",
@@ -675,79 +609,38 @@ class RectNode extends BaseCanvasNode {
675
609
  rect.x(this.node.props.x);
676
610
  rect.y(this.node.props.y);
677
611
  const width = Math.max(
678
- this.node.props.width ?? RECT$1.MIN_SIZE,
679
- RECT$1.MIN_SIZE
612
+ this.node.props.width ?? RECT.MIN_SIZE,
613
+ RECT.MIN_SIZE
680
614
  );
681
615
  const height = Math.max(
682
- this.node.props.height ?? RECT$1.MIN_SIZE,
683
- RECT$1.MIN_SIZE
616
+ this.node.props.height ?? RECT.MIN_SIZE,
617
+ RECT.MIN_SIZE
684
618
  );
685
619
  rect.width(width);
686
620
  rect.height(height);
687
- if (this.node.style.animated && !__privateGet(this, _animation)) {
688
- __privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
689
- } else if (!this.node.style.animated && __privateGet(this, _animation)) {
690
- __privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
691
- }
692
621
  }
693
622
  /**
694
623
  * 销毁
695
624
  */
696
625
  destroy() {
697
626
  this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
698
- __privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
699
627
  this.element.destroy();
700
628
  }
701
629
  }
702
- _animation = new WeakMap();
703
- _RectNode_instances = new WeakSet();
704
- /**
705
- * 初始化动画
706
- */
707
- initAnimation_fn = function() {
708
- const rect = this.getElement();
709
- const dash = rect.dash();
710
- if (!dash || dash.length === 0) return;
711
- const totalDashLength = getTotalDashLength(dash);
712
- __privateSet(this, _animation, createRectAnimation(rect, totalDashLength));
713
- if (__privateGet(this, _animation)) {
714
- __privateGet(this, _animation).start();
715
- }
716
- };
717
- /**
718
- * 销毁动画
719
- */
720
- destroyAnimation_fn = function() {
721
- if (__privateGet(this, _animation)) {
722
- __privateGet(this, _animation).stop();
723
- __privateSet(this, _animation, null);
724
- }
725
- };
726
630
  _toolTypeChangeHandler = new WeakMap();
631
+ _RectNode_instances = new WeakSet();
727
632
  /**
728
633
  * 设置事件处理器
729
634
  */
730
635
  setupEventHandlers_fn = function(rect) {
731
636
  const element = rect;
732
637
  this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
733
- element.on("transformstart", () => {
734
- if (this.node.style.animated && __privateGet(this, _animation)) {
735
- __privateGet(this, _animation).stop();
736
- }
737
- });
738
638
  element.on("transform", (event) => {
739
639
  const rect2 = event.target;
740
640
  const { width, height } = getRectSize(rect2);
741
- const totalLength = calculatePerimeter(width, height, RECT$1.CORNER_RADIUS);
742
- const dash = getDashValue(
743
- totalLength,
744
- getSizeValue(this.node.style.size),
745
- this.node.style.line
746
- );
747
641
  rect2.scale({ x: 1, y: 1 });
748
642
  rect2.width(width);
749
643
  rect2.height(height);
750
- rect2.dash(dash.map((d) => d * this.core.getStageScale()));
751
644
  });
752
645
  element.on("transformend", (event) => {
753
646
  const rect2 = event.target;
@@ -764,9 +657,6 @@ setupEventHandlers_fn = function(rect) {
764
657
  this.core._syncNodeFromElement(this.node.id, {
765
658
  props: newProps
766
659
  });
767
- if (this.node.style.animated && __privateGet(this, _animation)?.isRunning() === false) {
768
- __privateGet(this, _animation).start();
769
- }
770
660
  });
771
661
  element.on("dragend", (event) => {
772
662
  const rect2 = event.target;
@@ -1006,12 +896,12 @@ class ImageMarkerNode extends BaseCanvasNode {
1006
896
  }
1007
897
  createElement() {
1008
898
  const width = Math.max(
1009
- this.node.props.width ?? RECT$1.MIN_SIZE,
1010
- RECT$1.MIN_SIZE
899
+ this.node.props.width ?? RECT.MIN_SIZE,
900
+ RECT.MIN_SIZE
1011
901
  );
1012
902
  const height = Math.max(
1013
- this.node.props.height ?? RECT$1.MIN_SIZE,
1014
- RECT$1.MIN_SIZE
903
+ this.node.props.height ?? RECT.MIN_SIZE,
904
+ RECT.MIN_SIZE
1015
905
  );
1016
906
  const group = new Konva.Group({
1017
907
  id: this.node.id,
@@ -1032,7 +922,7 @@ class ImageMarkerNode extends BaseCanvasNode {
1032
922
  strokeWidth: 2,
1033
923
  dash: [5, 5],
1034
924
  fill: "transparent",
1035
- cornerRadius: RECT$1.CORNER_RADIUS
925
+ cornerRadius: RECT.CORNER_RADIUS
1036
926
  });
1037
927
  const markerGroup = new Konva.Group({
1038
928
  name: "marker-group",
@@ -1094,12 +984,12 @@ class ImageMarkerNode extends BaseCanvasNode {
1094
984
  group.x(this.node.props.x);
1095
985
  group.y(this.node.props.y);
1096
986
  const width = Math.max(
1097
- this.node.props.width ?? RECT$1.MIN_SIZE,
1098
- RECT$1.MIN_SIZE
987
+ this.node.props.width ?? RECT.MIN_SIZE,
988
+ RECT.MIN_SIZE
1099
989
  );
1100
990
  const height = Math.max(
1101
- this.node.props.height ?? RECT$1.MIN_SIZE,
1102
- RECT$1.MIN_SIZE
991
+ this.node.props.height ?? RECT.MIN_SIZE,
992
+ RECT.MIN_SIZE
1103
993
  );
1104
994
  group.width(width);
1105
995
  group.height(height);
@@ -1167,6 +1057,9 @@ function createCanvasNodeByType(core, type, config) {
1167
1057
  return null;
1168
1058
  }
1169
1059
  }
1060
+ function clamp(value, range) {
1061
+ return Math.min(Math.max(value, range[0]), range[1]);
1062
+ }
1170
1063
  const createNodeByType = (type, position, style, meta) => {
1171
1064
  const baseNode = {
1172
1065
  type,
@@ -1223,8 +1116,8 @@ function updateNodeByType(node, position) {
1223
1116
  ...node.props,
1224
1117
  x: p1.x,
1225
1118
  y: p1.y,
1226
- width: Math.max(p2.x - p1.x, RECT$1.MIN_SIZE),
1227
- height: Math.max(p2.y - p1.y, RECT$1.MIN_SIZE)
1119
+ width: Math.max(p2.x - p1.x, RECT.MIN_SIZE),
1120
+ height: Math.max(p2.y - p1.y, RECT.MIN_SIZE)
1228
1121
  },
1229
1122
  meta: {
1230
1123
  ...node.meta,
@@ -1401,6 +1294,7 @@ class CanvasCore extends CanvasState {
1401
1294
  },
1402
1295
  true
1403
1296
  );
1297
+ this.emit("nodes:created", nodes);
1404
1298
  }
1405
1299
  /**
1406
1300
  * 创建图片标注节点(内部使用)
@@ -1789,9 +1683,10 @@ class CanvasApi extends CanvasCore {
1789
1683
  * 删除指定的节点
1790
1684
  * 如果删除的是 image 节点,会同步删除所有关联的 image-marker
1791
1685
  * @param nodeIds - 要删除的节点 ID 数组
1686
+ * @returns 被删除的节点数据数组
1792
1687
  */
1793
1688
  deleteNodes(nodeIds) {
1794
- if (nodeIds.length === 0) return;
1689
+ if (nodeIds.length === 0) return [];
1795
1690
  const nodes = this.getState().nodes || [];
1796
1691
  const idsToDelete = new Set(nodeIds);
1797
1692
  nodeIds.forEach((id) => {
@@ -1804,6 +1699,7 @@ class CanvasApi extends CanvasCore {
1804
1699
  });
1805
1700
  }
1806
1701
  });
1702
+ const deletedNodes = nodes.filter((n) => idsToDelete.has(n.id));
1807
1703
  idsToDelete.forEach((id) => {
1808
1704
  const shape = this.getStage().findOne(`#${id}`);
1809
1705
  if (shape) {
@@ -1819,6 +1715,8 @@ class CanvasApi extends CanvasCore {
1819
1715
  },
1820
1716
  true
1821
1717
  );
1718
+ this.emit("nodes:deleted", deletedNodes);
1719
+ return deletedNodes;
1822
1720
  }
1823
1721
  /**
1824
1722
  * 滚动到内容区域
package/dist/index.umd.js CHANGED
@@ -13,7 +13,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
13
13
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
14
14
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
15
15
 
16
- var _core, _stage, _viewport, _handleWheel, _handlePointerDown, _handlePointerMove, _handlePointerUp, _handleDragStart, _handleDragMove, _handleDragEnd, _CanvasStage_instances, setupEventListeners_fn, _core2, _transformer, _handleTransformStart, _handleTransform, _handleTransformEnd, _handleDragStart2, _handleDragMove2, _handleDragEnd2, _CanvasTransformer_instances, setupEventListeners_fn2, _animation, _RectNode_instances, initAnimation_fn, destroyAnimation_fn, _toolTypeChangeHandler, setupEventHandlers_fn, _ImageNode_instances, loadImage_fn, _toolTypeChangeHandler2, setupEventHandlers_fn2, syncImageMarkers_fn, syncImageMarkersToState_fn, _rect, _markerGroup, _circle, _text, _ImageMarkerNode_instances, setupEventHandlers_fn3, _canvasStage, _mainLayer, _canvasTransformer, _draftNode;
16
+ var _core, _stage, _viewport, _handleWheel, _handlePointerDown, _handlePointerMove, _handlePointerUp, _handleDragStart, _handleDragMove, _handleDragEnd, _CanvasStage_instances, setupEventListeners_fn, _core2, _transformer, _handleTransformStart, _handleTransform, _handleTransformEnd, _handleDragStart2, _handleDragMove2, _handleDragEnd2, _CanvasTransformer_instances, setupEventListeners_fn2, _toolTypeChangeHandler, _RectNode_instances, setupEventHandlers_fn, _ImageNode_instances, loadImage_fn, _toolTypeChangeHandler2, setupEventHandlers_fn2, syncImageMarkers_fn, syncImageMarkersToState_fn, _rect, _markerGroup, _circle, _text, _ImageMarkerNode_instances, setupEventHandlers_fn3, _canvasStage, _mainLayer, _canvasTransformer, _draftNode;
17
17
  var __vite_style__ = document.createElement("style");
18
18
  __vite_style__.textContent = `/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */
19
19
  @layer properties {
@@ -375,10 +375,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
375
375
  pointer-events: auto;
376
376
  }
377
377
 
378
- .pointer-events-none {
379
- pointer-events: none;
380
- }
381
-
382
378
  .visible {
383
379
  visibility: visible;
384
380
  }
@@ -578,10 +574,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
578
574
  touch-action: none;
579
575
  }
580
576
 
581
- .resize {
582
- resize: both;
583
- }
584
-
585
577
  .grid-cols-2 {
586
578
  grid-template-columns: repeat(2, minmax(0, 1fr));
587
579
  }
@@ -1829,66 +1821,13 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1829
1821
  }
1830
1822
  }
1831
1823
  const NODE_NAME_FOR_SELECT = "shapeNameForSelect";
1832
- const RECT$1 = {
1824
+ const RECT = {
1833
1825
  CORNER_RADIUS: 6,
1834
1826
  MIN_SIZE: 10
1835
1827
  };
1836
1828
  const IMAGE = {
1837
1829
  MIN_SIZE: 10
1838
1830
  };
1839
- const RECT = {
1840
- MIN_SIZE: 10
1841
- };
1842
- function clamp(value, range) {
1843
- return Math.min(Math.max(value, range[0]), range[1]);
1844
- }
1845
- function calculatePerimeter(width, height, cornerRadius) {
1846
- return 2 * (height + width - cornerRadius * (4 - Math.PI));
1847
- }
1848
- function getDashValue(shapeLength, strokeWidth, lineStyle) {
1849
- let ratio = 1;
1850
- let dashLength = 0;
1851
- let dashGap = 0;
1852
- switch (lineStyle) {
1853
- case "dashed":
1854
- dashLength = Math.min(strokeWidth * 2, shapeLength / 4);
1855
- break;
1856
- case "dotted":
1857
- ratio = 8;
1858
- dashLength = strokeWidth / ratio;
1859
- break;
1860
- default:
1861
- return [];
1862
- }
1863
- let dashCount = Math.floor(shapeLength / dashLength / (2 * ratio));
1864
- dashCount = Math.max(dashCount, 3);
1865
- dashLength = shapeLength / dashCount / (2 * ratio);
1866
- dashGap = (shapeLength - dashCount * dashLength) / dashCount;
1867
- return [dashLength, dashGap];
1868
- }
1869
- function getSizeValue(key) {
1870
- switch (key) {
1871
- case "small":
1872
- return 2;
1873
- case "medium":
1874
- return 3;
1875
- case "large":
1876
- return 5;
1877
- case "extra-large":
1878
- return 8;
1879
- default:
1880
- return 3;
1881
- }
1882
- }
1883
- function getTotalDashLength(dash) {
1884
- return Array.isArray(dash) && dash.length > 1 ? dash[0] + dash[1] : 0;
1885
- }
1886
- function getRectSize(rect) {
1887
- return {
1888
- width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
1889
- height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
1890
- };
1891
- }
1892
1831
  class BaseCanvasNode {
1893
1832
  constructor(core, node) {
1894
1833
  __publicField(this, "core");
@@ -1911,43 +1850,30 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1911
1850
  return this.node;
1912
1851
  }
1913
1852
  }
1914
- function createRectAnimation(rect, totalDashLength) {
1915
- if (!totalDashLength || totalDashLength === 0) {
1916
- return null;
1917
- }
1918
- const anim = new Konva.Animation((frame) => {
1919
- if (!frame) return;
1920
- const dashOffset = -frame.time / 10 % totalDashLength;
1921
- rect.dashOffset(dashOffset);
1922
- }, rect.getLayer());
1853
+ function getRectSize(rect) {
1923
1854
  return {
1924
- start: () => anim.start(),
1925
- stop: () => anim.stop(),
1926
- isRunning: () => anim.isRunning()
1855
+ width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
1856
+ height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
1927
1857
  };
1928
1858
  }
1929
1859
  class RectNode extends BaseCanvasNode {
1930
1860
  constructor(core, node) {
1931
1861
  super(core, node);
1932
1862
  __privateAdd(this, _RectNode_instances);
1933
- __privateAdd(this, _animation, null);
1934
1863
  __privateAdd(this, _toolTypeChangeHandler, (toolType) => {
1935
1864
  const isSelect = toolType === "select";
1936
1865
  this.element.listening(isSelect);
1937
1866
  });
1938
- if (node.style.animated) {
1939
- __privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
1940
- }
1941
1867
  __privateMethod(this, _RectNode_instances, setupEventHandlers_fn).call(this, this.getElement());
1942
1868
  }
1943
1869
  createElement() {
1944
1870
  const width = Math.max(
1945
- this.node.props.width ?? RECT$1.MIN_SIZE,
1946
- RECT$1.MIN_SIZE
1871
+ this.node.props.width ?? RECT.MIN_SIZE,
1872
+ RECT.MIN_SIZE
1947
1873
  );
1948
1874
  const height = Math.max(
1949
- this.node.props.height ?? RECT$1.MIN_SIZE,
1950
- RECT$1.MIN_SIZE
1875
+ this.node.props.height ?? RECT.MIN_SIZE,
1876
+ RECT.MIN_SIZE
1951
1877
  );
1952
1878
  const config = {
1953
1879
  id: this.node.id,
@@ -1955,7 +1881,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1955
1881
  ...this.node.style,
1956
1882
  width,
1957
1883
  height,
1958
- cornerRadius: RECT$1.CORNER_RADIUS,
1884
+ cornerRadius: RECT.CORNER_RADIUS,
1959
1885
  name: NODE_NAME_FOR_SELECT,
1960
1886
  draggable: true,
1961
1887
  stroke: "black",
@@ -1994,79 +1920,38 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1994
1920
  rect.x(this.node.props.x);
1995
1921
  rect.y(this.node.props.y);
1996
1922
  const width = Math.max(
1997
- this.node.props.width ?? RECT$1.MIN_SIZE,
1998
- RECT$1.MIN_SIZE
1923
+ this.node.props.width ?? RECT.MIN_SIZE,
1924
+ RECT.MIN_SIZE
1999
1925
  );
2000
1926
  const height = Math.max(
2001
- this.node.props.height ?? RECT$1.MIN_SIZE,
2002
- RECT$1.MIN_SIZE
1927
+ this.node.props.height ?? RECT.MIN_SIZE,
1928
+ RECT.MIN_SIZE
2003
1929
  );
2004
1930
  rect.width(width);
2005
1931
  rect.height(height);
2006
- if (this.node.style.animated && !__privateGet(this, _animation)) {
2007
- __privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
2008
- } else if (!this.node.style.animated && __privateGet(this, _animation)) {
2009
- __privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
2010
- }
2011
1932
  }
2012
1933
  /**
2013
1934
  * 销毁
2014
1935
  */
2015
1936
  destroy() {
2016
1937
  this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
2017
- __privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
2018
1938
  this.element.destroy();
2019
1939
  }
2020
1940
  }
2021
- _animation = new WeakMap();
2022
- _RectNode_instances = new WeakSet();
2023
- /**
2024
- * 初始化动画
2025
- */
2026
- initAnimation_fn = function() {
2027
- const rect = this.getElement();
2028
- const dash = rect.dash();
2029
- if (!dash || dash.length === 0) return;
2030
- const totalDashLength = getTotalDashLength(dash);
2031
- __privateSet(this, _animation, createRectAnimation(rect, totalDashLength));
2032
- if (__privateGet(this, _animation)) {
2033
- __privateGet(this, _animation).start();
2034
- }
2035
- };
2036
- /**
2037
- * 销毁动画
2038
- */
2039
- destroyAnimation_fn = function() {
2040
- if (__privateGet(this, _animation)) {
2041
- __privateGet(this, _animation).stop();
2042
- __privateSet(this, _animation, null);
2043
- }
2044
- };
2045
1941
  _toolTypeChangeHandler = new WeakMap();
1942
+ _RectNode_instances = new WeakSet();
2046
1943
  /**
2047
1944
  * 设置事件处理器
2048
1945
  */
2049
1946
  setupEventHandlers_fn = function(rect) {
2050
1947
  const element = rect;
2051
1948
  this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
2052
- element.on("transformstart", () => {
2053
- if (this.node.style.animated && __privateGet(this, _animation)) {
2054
- __privateGet(this, _animation).stop();
2055
- }
2056
- });
2057
1949
  element.on("transform", (event) => {
2058
1950
  const rect2 = event.target;
2059
1951
  const { width, height } = getRectSize(rect2);
2060
- const totalLength = calculatePerimeter(width, height, RECT$1.CORNER_RADIUS);
2061
- const dash = getDashValue(
2062
- totalLength,
2063
- getSizeValue(this.node.style.size),
2064
- this.node.style.line
2065
- );
2066
1952
  rect2.scale({ x: 1, y: 1 });
2067
1953
  rect2.width(width);
2068
1954
  rect2.height(height);
2069
- rect2.dash(dash.map((d) => d * this.core.getStageScale()));
2070
1955
  });
2071
1956
  element.on("transformend", (event) => {
2072
1957
  const rect2 = event.target;
@@ -2083,9 +1968,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2083
1968
  this.core._syncNodeFromElement(this.node.id, {
2084
1969
  props: newProps
2085
1970
  });
2086
- if (this.node.style.animated && __privateGet(this, _animation)?.isRunning() === false) {
2087
- __privateGet(this, _animation).start();
2088
- }
2089
1971
  });
2090
1972
  element.on("dragend", (event) => {
2091
1973
  const rect2 = event.target;
@@ -2325,12 +2207,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2325
2207
  }
2326
2208
  createElement() {
2327
2209
  const width = Math.max(
2328
- this.node.props.width ?? RECT$1.MIN_SIZE,
2329
- RECT$1.MIN_SIZE
2210
+ this.node.props.width ?? RECT.MIN_SIZE,
2211
+ RECT.MIN_SIZE
2330
2212
  );
2331
2213
  const height = Math.max(
2332
- this.node.props.height ?? RECT$1.MIN_SIZE,
2333
- RECT$1.MIN_SIZE
2214
+ this.node.props.height ?? RECT.MIN_SIZE,
2215
+ RECT.MIN_SIZE
2334
2216
  );
2335
2217
  const group = new Konva.Group({
2336
2218
  id: this.node.id,
@@ -2351,7 +2233,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2351
2233
  strokeWidth: 2,
2352
2234
  dash: [5, 5],
2353
2235
  fill: "transparent",
2354
- cornerRadius: RECT$1.CORNER_RADIUS
2236
+ cornerRadius: RECT.CORNER_RADIUS
2355
2237
  });
2356
2238
  const markerGroup = new Konva.Group({
2357
2239
  name: "marker-group",
@@ -2413,12 +2295,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2413
2295
  group.x(this.node.props.x);
2414
2296
  group.y(this.node.props.y);
2415
2297
  const width = Math.max(
2416
- this.node.props.width ?? RECT$1.MIN_SIZE,
2417
- RECT$1.MIN_SIZE
2298
+ this.node.props.width ?? RECT.MIN_SIZE,
2299
+ RECT.MIN_SIZE
2418
2300
  );
2419
2301
  const height = Math.max(
2420
- this.node.props.height ?? RECT$1.MIN_SIZE,
2421
- RECT$1.MIN_SIZE
2302
+ this.node.props.height ?? RECT.MIN_SIZE,
2303
+ RECT.MIN_SIZE
2422
2304
  );
2423
2305
  group.width(width);
2424
2306
  group.height(height);
@@ -2486,6 +2368,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2486
2368
  return null;
2487
2369
  }
2488
2370
  }
2371
+ function clamp(value, range) {
2372
+ return Math.min(Math.max(value, range[0]), range[1]);
2373
+ }
2489
2374
  const createNodeByType = (type, position, style, meta) => {
2490
2375
  const baseNode = {
2491
2376
  type,
@@ -2542,8 +2427,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2542
2427
  ...node.props,
2543
2428
  x: p1.x,
2544
2429
  y: p1.y,
2545
- width: Math.max(p2.x - p1.x, RECT$1.MIN_SIZE),
2546
- height: Math.max(p2.y - p1.y, RECT$1.MIN_SIZE)
2430
+ width: Math.max(p2.x - p1.x, RECT.MIN_SIZE),
2431
+ height: Math.max(p2.y - p1.y, RECT.MIN_SIZE)
2547
2432
  },
2548
2433
  meta: {
2549
2434
  ...node.meta,
@@ -2720,6 +2605,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2720
2605
  },
2721
2606
  true
2722
2607
  );
2608
+ this.emit("nodes:created", nodes);
2723
2609
  }
2724
2610
  /**
2725
2611
  * 创建图片标注节点(内部使用)
@@ -3108,9 +2994,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3108
2994
  * 删除指定的节点
3109
2995
  * 如果删除的是 image 节点,会同步删除所有关联的 image-marker
3110
2996
  * @param nodeIds - 要删除的节点 ID 数组
2997
+ * @returns 被删除的节点数据数组
3111
2998
  */
3112
2999
  deleteNodes(nodeIds) {
3113
- if (nodeIds.length === 0) return;
3000
+ if (nodeIds.length === 0) return [];
3114
3001
  const nodes = this.getState().nodes || [];
3115
3002
  const idsToDelete = new Set(nodeIds);
3116
3003
  nodeIds.forEach((id) => {
@@ -3123,6 +3010,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3123
3010
  });
3124
3011
  }
3125
3012
  });
3013
+ const deletedNodes = nodes.filter((n) => idsToDelete.has(n.id));
3126
3014
  idsToDelete.forEach((id) => {
3127
3015
  const shape = this.getStage().findOne(`#${id}`);
3128
3016
  if (shape) {
@@ -3138,6 +3026,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3138
3026
  },
3139
3027
  true
3140
3028
  );
3029
+ this.emit("nodes:deleted", deletedNodes);
3030
+ return deletedNodes;
3141
3031
  }
3142
3032
  /**
3143
3033
  * 滚动到内容区域
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8btc/whiteboard",
3
3
  "private": false,
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
7
7
  "module": "./dist/index.js",