@8btc/whiteboard 0.0.6 → 0.0.8

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.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, setupEventHandlers_fn, _ImageNode_instances, loadImage_fn, 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, _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;
13
13
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
14
14
  import { useState, useEffect, useRef } from "react";
15
15
  import Konva from "konva";
@@ -81,7 +81,6 @@ class CanvasStage {
81
81
  }
82
82
  if (toolType === "image-marker" && pointerPos) {
83
83
  const imageShape = __privateGet(this, _core).findImageAtPosition(pointerPos);
84
- console.log(imageShape, "imageShape");
85
84
  if (imageShape) {
86
85
  const width = imageShape.width();
87
86
  const height = imageShape.height();
@@ -270,7 +269,6 @@ class CanvasTransformer {
270
269
  * 处理 transform 事件
271
270
  */
272
271
  __privateAdd(this, _handleTransform, () => {
273
- console.log("transforming...");
274
272
  this.emitPositionChange();
275
273
  });
276
274
  /**
@@ -522,6 +520,9 @@ const IMAGE = {
522
520
  const RECT = {
523
521
  MIN_SIZE: 10
524
522
  };
523
+ function clamp(value, range) {
524
+ return Math.min(Math.max(value, range[0]), range[1]);
525
+ }
525
526
  function calculatePerimeter(width, height, cornerRadius) {
526
527
  return 2 * (height + width - cornerRadius * (4 - Math.PI));
527
528
  }
@@ -574,16 +575,9 @@ class BaseCanvasNode {
574
575
  __publicField(this, "core");
575
576
  __publicField(this, "node");
576
577
  __publicField(this, "element");
577
- __publicField(this, "toolTypeChangeHandler");
578
578
  this.core = core;
579
579
  this.node = node;
580
580
  this.element = this.createElement();
581
- this.toolTypeChangeHandler = (toolType) => {
582
- const isSelect = toolType === "select";
583
- this.element.listening(isSelect);
584
- };
585
- this.toolTypeChangeHandler(this.core.getToolType());
586
- this.core.on("toolType:change", this.toolTypeChangeHandler);
587
581
  }
588
582
  /**
589
583
  * 获取 Konva 元素
@@ -597,13 +591,6 @@ class BaseCanvasNode {
597
591
  getNode() {
598
592
  return this.node;
599
593
  }
600
- /**
601
- * 销毁节点
602
- */
603
- destroy() {
604
- this.core.off("toolType:change", this.toolTypeChangeHandler);
605
- this.element.destroy();
606
- }
607
594
  }
608
595
  function createRectAnimation(rect, totalDashLength) {
609
596
  if (!totalDashLength || totalDashLength === 0) {
@@ -625,6 +612,10 @@ class RectNode extends BaseCanvasNode {
625
612
  super(core, node);
626
613
  __privateAdd(this, _RectNode_instances);
627
614
  __privateAdd(this, _animation, null);
615
+ __privateAdd(this, _toolTypeChangeHandler, (toolType) => {
616
+ const isSelect = toolType === "select";
617
+ this.element.listening(isSelect);
618
+ });
628
619
  if (node.style.animated) {
629
620
  __privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
630
621
  }
@@ -703,8 +694,9 @@ class RectNode extends BaseCanvasNode {
703
694
  * 销毁
704
695
  */
705
696
  destroy() {
697
+ this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
706
698
  __privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
707
- super.destroy();
699
+ this.element.destroy();
708
700
  }
709
701
  }
710
702
  _animation = new WeakMap();
@@ -731,11 +723,13 @@ destroyAnimation_fn = function() {
731
723
  __privateSet(this, _animation, null);
732
724
  }
733
725
  };
726
+ _toolTypeChangeHandler = new WeakMap();
734
727
  /**
735
728
  * 设置事件处理器
736
729
  */
737
- setupEventHandlers_fn = function(rect = void 0) {
738
- const element = rect ?? this.getElement();
730
+ setupEventHandlers_fn = function(rect) {
731
+ const element = rect;
732
+ this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
739
733
  element.on("transformstart", () => {
740
734
  if (this.node.style.animated && __privateGet(this, _animation)) {
741
735
  __privateGet(this, _animation).stop();
@@ -791,6 +785,10 @@ class ImageNode extends BaseCanvasNode {
791
785
  constructor(core, node) {
792
786
  super(core, node);
793
787
  __privateAdd(this, _ImageNode_instances);
788
+ __privateAdd(this, _toolTypeChangeHandler2, (toolType) => {
789
+ const isSelect = toolType === "select";
790
+ this.element.listening(isSelect);
791
+ });
794
792
  __privateMethod(this, _ImageNode_instances, loadImage_fn).call(this);
795
793
  __privateMethod(this, _ImageNode_instances, setupEventHandlers_fn2).call(this, this.getElement());
796
794
  }
@@ -854,7 +852,8 @@ class ImageNode extends BaseCanvasNode {
854
852
  * 销毁
855
853
  */
856
854
  destroy() {
857
- super.destroy();
855
+ this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
856
+ this.element.destroy();
858
857
  }
859
858
  }
860
859
  _ImageNode_instances = new WeakSet();
@@ -881,10 +880,12 @@ loadImage_fn = function() {
881
880
  console.error("Failed to load image:", imageUrl);
882
881
  };
883
882
  };
883
+ _toolTypeChangeHandler2 = new WeakMap();
884
884
  /**
885
885
  * 设置事件处理器
886
886
  */
887
887
  setupEventHandlers_fn2 = function(img) {
888
+ this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
888
889
  img.on("transform", (event) => {
889
890
  const img2 = event.target;
890
891
  const width = Math.max(IMAGE.MIN_SIZE, img2.width() * img2.scaleX());
@@ -1018,7 +1019,8 @@ class ImageMarkerNode extends BaseCanvasNode {
1018
1019
  x: this.node.props.x,
1019
1020
  y: this.node.props.y,
1020
1021
  width,
1021
- height
1022
+ height,
1023
+ listening: false
1022
1024
  });
1023
1025
  const rect = new Konva.Rect({
1024
1026
  name: "rect",
@@ -1116,7 +1118,7 @@ class ImageMarkerNode extends BaseCanvasNode {
1116
1118
  * 销毁
1117
1119
  */
1118
1120
  destroy() {
1119
- super.destroy();
1121
+ this.element.destroy();
1120
1122
  }
1121
1123
  /**
1122
1124
  * 更新焦点状态(hover 或 selected)
@@ -1183,7 +1185,10 @@ const createNodeByType = (type, position, style, meta) => {
1183
1185
  rotation: 0,
1184
1186
  visible: true
1185
1187
  },
1186
- meta: meta ?? {}
1188
+ meta: {
1189
+ ...meta,
1190
+ startPoint: position
1191
+ }
1187
1192
  };
1188
1193
  if (type === "image-marker") {
1189
1194
  return {
@@ -1197,19 +1202,21 @@ const createNodeByType = (type, position, style, meta) => {
1197
1202
  }
1198
1203
  return baseNode;
1199
1204
  };
1200
- function updateNodeByType(node, position, bounds) {
1205
+ function updateNodeByType(node, position) {
1201
1206
  let finalPosition = position;
1202
- if (node.type === "image-marker" && bounds) {
1207
+ if (node.type === "image-marker" && node.meta.bounds) {
1208
+ const bounds = node.meta.bounds;
1203
1209
  finalPosition = {
1204
- x: Math.max(bounds.x, Math.min(bounds.x + bounds.width, position.x)),
1205
- y: Math.max(bounds.y, Math.min(bounds.y + bounds.height, position.y))
1210
+ x: clamp(position.x, [bounds.x, bounds.x + bounds.width]),
1211
+ y: clamp(position.y, [bounds.y, bounds.y + bounds.height])
1206
1212
  };
1207
1213
  }
1208
- const [p1, p2] = normalizePoints(
1209
- { x: node.props.x, y: node.props.y },
1210
- finalPosition
1211
- );
1212
1214
  if (node.type === "rectangle" || node.type === "image-marker") {
1215
+ const startPoint = node.meta.startPoint ?? {
1216
+ x: node.props.x,
1217
+ y: node.props.y
1218
+ };
1219
+ const [p1, p2] = normalizePoints(startPoint, finalPosition);
1213
1220
  return {
1214
1221
  ...node,
1215
1222
  props: {
@@ -1218,6 +1225,11 @@ function updateNodeByType(node, position, bounds) {
1218
1225
  y: p1.y,
1219
1226
  width: Math.max(p2.x - p1.x, RECT$1.MIN_SIZE),
1220
1227
  height: Math.max(p2.y - p1.y, RECT$1.MIN_SIZE)
1228
+ },
1229
+ meta: {
1230
+ ...node.meta,
1231
+ // 保存初始起点,以便后续更新使用
1232
+ startPoint
1221
1233
  }
1222
1234
  };
1223
1235
  }
@@ -1448,21 +1460,21 @@ class CanvasCore extends CanvasState {
1448
1460
  * @internal 仅供内部使用
1449
1461
  */
1450
1462
  findImageAtPosition(position) {
1451
- const stage = __privateGet(this, _canvasStage).getStage();
1452
- const imageShapes = stage.find(
1463
+ const layer = __privateGet(this, _mainLayer).getLayer();
1464
+ const imageShapes = layer.find(
1453
1465
  (node) => node.getClassName() === "Image"
1454
1466
  );
1455
1467
  const originalListeningStates = imageShapes.map(
1456
1468
  (shape) => shape.listening()
1457
1469
  );
1458
1470
  imageShapes.forEach((shape) => shape.listening(true));
1471
+ layer.draw();
1459
1472
  try {
1460
- const shapes = stage.getAllIntersections(position);
1461
- const imageShapesAtPos = shapes.filter(
1462
- (shape) => shape.getClassName() === "Image"
1463
- );
1464
- if (imageShapesAtPos.length === 0) return null;
1465
- return imageShapesAtPos[imageShapesAtPos.length - 1];
1473
+ const shape = layer.getIntersection(position);
1474
+ if (shape?.getClassName() === "Image") {
1475
+ return shape;
1476
+ }
1477
+ return null;
1466
1478
  } finally {
1467
1479
  imageShapes.forEach((shape, index) => {
1468
1480
  shape.listening(originalListeningStates[index]);
@@ -1478,17 +1490,16 @@ class CanvasCore extends CanvasState {
1478
1490
  }
1479
1491
  const node = createNodeByType(type, position, void 0, meta);
1480
1492
  __privateSet(this, _draftNode, createCanvasNodeByType(this, type, node));
1481
- console.log(__privateGet(this, _draftNode));
1482
1493
  if (!__privateGet(this, _draftNode)) return;
1483
1494
  __privateGet(this, _mainLayer).add(__privateGet(this, _draftNode).getElement());
1484
1495
  }
1485
1496
  /**
1486
1497
  * @internal 仅供内部使用
1487
1498
  */
1488
- updateDraftNode(position, bounds) {
1499
+ updateDraftNode(position) {
1489
1500
  if (!__privateGet(this, _draftNode)) return;
1490
1501
  const node = __privateGet(this, _draftNode).getNode();
1491
- const updatedNode = updateNodeByType(node, position, bounds);
1502
+ const updatedNode = updateNodeByType(node, position);
1492
1503
  __privateGet(this, _draftNode).updateNode(updatedNode);
1493
1504
  }
1494
1505
  /**
@@ -1885,11 +1896,11 @@ class CanvasApi extends CanvasCore {
1885
1896
  this.updateViewport({ x, y, scale: newScale }, true);
1886
1897
  }
1887
1898
  }
1888
- function modulate(value, rangeA, rangeB, clamp = false) {
1899
+ function modulate(value, rangeA, rangeB, clamp2 = false) {
1889
1900
  const [fromLow, fromHigh] = rangeA;
1890
1901
  const [v0, v1] = rangeB;
1891
1902
  const result = v0 + (value - fromLow) / (fromHigh - fromLow) * (v1 - v0);
1892
- return clamp ? v0 < v1 ? Math.max(Math.min(result, v1), v0) : Math.max(Math.min(result, v0), v1) : result;
1903
+ return clamp2 ? v0 < v1 ? Math.max(Math.min(result, v1), v0) : Math.max(Math.min(result, v0), v1) : result;
1893
1904
  }
1894
1905
  const gridSteps = [
1895
1906
  {
@@ -2131,9 +2142,6 @@ function PureCanvas({ setApi }) {
2131
2142
  core.on("viewport:change", (newViewport) => {
2132
2143
  setViewport(newViewport);
2133
2144
  });
2134
- core.on("transformer:positionChange", (position) => {
2135
- console.log("Transformer position changed:", position);
2136
- });
2137
2145
  return () => {
2138
2146
  core.dispose();
2139
2147
  };
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, setupEventHandlers_fn, _ImageNode_instances, loadImage_fn, 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, _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;
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 {
@@ -1400,7 +1400,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1400
1400
  }
1401
1401
  if (toolType === "image-marker" && pointerPos) {
1402
1402
  const imageShape = __privateGet(this, _core).findImageAtPosition(pointerPos);
1403
- console.log(imageShape, "imageShape");
1404
1403
  if (imageShape) {
1405
1404
  const width = imageShape.width();
1406
1405
  const height = imageShape.height();
@@ -1589,7 +1588,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1589
1588
  * 处理 transform 事件
1590
1589
  */
1591
1590
  __privateAdd(this, _handleTransform, () => {
1592
- console.log("transforming...");
1593
1591
  this.emitPositionChange();
1594
1592
  });
1595
1593
  /**
@@ -1841,6 +1839,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1841
1839
  const RECT = {
1842
1840
  MIN_SIZE: 10
1843
1841
  };
1842
+ function clamp(value, range) {
1843
+ return Math.min(Math.max(value, range[0]), range[1]);
1844
+ }
1844
1845
  function calculatePerimeter(width, height, cornerRadius) {
1845
1846
  return 2 * (height + width - cornerRadius * (4 - Math.PI));
1846
1847
  }
@@ -1893,16 +1894,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1893
1894
  __publicField(this, "core");
1894
1895
  __publicField(this, "node");
1895
1896
  __publicField(this, "element");
1896
- __publicField(this, "toolTypeChangeHandler");
1897
1897
  this.core = core;
1898
1898
  this.node = node;
1899
1899
  this.element = this.createElement();
1900
- this.toolTypeChangeHandler = (toolType) => {
1901
- const isSelect = toolType === "select";
1902
- this.element.listening(isSelect);
1903
- };
1904
- this.toolTypeChangeHandler(this.core.getToolType());
1905
- this.core.on("toolType:change", this.toolTypeChangeHandler);
1906
1900
  }
1907
1901
  /**
1908
1902
  * 获取 Konva 元素
@@ -1916,13 +1910,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1916
1910
  getNode() {
1917
1911
  return this.node;
1918
1912
  }
1919
- /**
1920
- * 销毁节点
1921
- */
1922
- destroy() {
1923
- this.core.off("toolType:change", this.toolTypeChangeHandler);
1924
- this.element.destroy();
1925
- }
1926
1913
  }
1927
1914
  function createRectAnimation(rect, totalDashLength) {
1928
1915
  if (!totalDashLength || totalDashLength === 0) {
@@ -1944,6 +1931,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1944
1931
  super(core, node);
1945
1932
  __privateAdd(this, _RectNode_instances);
1946
1933
  __privateAdd(this, _animation, null);
1934
+ __privateAdd(this, _toolTypeChangeHandler, (toolType) => {
1935
+ const isSelect = toolType === "select";
1936
+ this.element.listening(isSelect);
1937
+ });
1947
1938
  if (node.style.animated) {
1948
1939
  __privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
1949
1940
  }
@@ -2022,8 +2013,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2022
2013
  * 销毁
2023
2014
  */
2024
2015
  destroy() {
2016
+ this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
2025
2017
  __privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
2026
- super.destroy();
2018
+ this.element.destroy();
2027
2019
  }
2028
2020
  }
2029
2021
  _animation = new WeakMap();
@@ -2050,11 +2042,13 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2050
2042
  __privateSet(this, _animation, null);
2051
2043
  }
2052
2044
  };
2045
+ _toolTypeChangeHandler = new WeakMap();
2053
2046
  /**
2054
2047
  * 设置事件处理器
2055
2048
  */
2056
- setupEventHandlers_fn = function(rect = void 0) {
2057
- const element = rect ?? this.getElement();
2049
+ setupEventHandlers_fn = function(rect) {
2050
+ const element = rect;
2051
+ this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
2058
2052
  element.on("transformstart", () => {
2059
2053
  if (this.node.style.animated && __privateGet(this, _animation)) {
2060
2054
  __privateGet(this, _animation).stop();
@@ -2110,6 +2104,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2110
2104
  constructor(core, node) {
2111
2105
  super(core, node);
2112
2106
  __privateAdd(this, _ImageNode_instances);
2107
+ __privateAdd(this, _toolTypeChangeHandler2, (toolType) => {
2108
+ const isSelect = toolType === "select";
2109
+ this.element.listening(isSelect);
2110
+ });
2113
2111
  __privateMethod(this, _ImageNode_instances, loadImage_fn).call(this);
2114
2112
  __privateMethod(this, _ImageNode_instances, setupEventHandlers_fn2).call(this, this.getElement());
2115
2113
  }
@@ -2173,7 +2171,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2173
2171
  * 销毁
2174
2172
  */
2175
2173
  destroy() {
2176
- super.destroy();
2174
+ this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
2175
+ this.element.destroy();
2177
2176
  }
2178
2177
  }
2179
2178
  _ImageNode_instances = new WeakSet();
@@ -2200,10 +2199,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2200
2199
  console.error("Failed to load image:", imageUrl);
2201
2200
  };
2202
2201
  };
2202
+ _toolTypeChangeHandler2 = new WeakMap();
2203
2203
  /**
2204
2204
  * 设置事件处理器
2205
2205
  */
2206
2206
  setupEventHandlers_fn2 = function(img) {
2207
+ this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
2207
2208
  img.on("transform", (event) => {
2208
2209
  const img2 = event.target;
2209
2210
  const width = Math.max(IMAGE.MIN_SIZE, img2.width() * img2.scaleX());
@@ -2337,7 +2338,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2337
2338
  x: this.node.props.x,
2338
2339
  y: this.node.props.y,
2339
2340
  width,
2340
- height
2341
+ height,
2342
+ listening: false
2341
2343
  });
2342
2344
  const rect = new Konva.Rect({
2343
2345
  name: "rect",
@@ -2435,7 +2437,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2435
2437
  * 销毁
2436
2438
  */
2437
2439
  destroy() {
2438
- super.destroy();
2440
+ this.element.destroy();
2439
2441
  }
2440
2442
  /**
2441
2443
  * 更新焦点状态(hover 或 selected)
@@ -2502,7 +2504,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2502
2504
  rotation: 0,
2503
2505
  visible: true
2504
2506
  },
2505
- meta: meta ?? {}
2507
+ meta: {
2508
+ ...meta,
2509
+ startPoint: position
2510
+ }
2506
2511
  };
2507
2512
  if (type === "image-marker") {
2508
2513
  return {
@@ -2516,19 +2521,21 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2516
2521
  }
2517
2522
  return baseNode;
2518
2523
  };
2519
- function updateNodeByType(node, position, bounds) {
2524
+ function updateNodeByType(node, position) {
2520
2525
  let finalPosition = position;
2521
- if (node.type === "image-marker" && bounds) {
2526
+ if (node.type === "image-marker" && node.meta.bounds) {
2527
+ const bounds = node.meta.bounds;
2522
2528
  finalPosition = {
2523
- x: Math.max(bounds.x, Math.min(bounds.x + bounds.width, position.x)),
2524
- y: Math.max(bounds.y, Math.min(bounds.y + bounds.height, position.y))
2529
+ x: clamp(position.x, [bounds.x, bounds.x + bounds.width]),
2530
+ y: clamp(position.y, [bounds.y, bounds.y + bounds.height])
2525
2531
  };
2526
2532
  }
2527
- const [p1, p2] = normalizePoints(
2528
- { x: node.props.x, y: node.props.y },
2529
- finalPosition
2530
- );
2531
2533
  if (node.type === "rectangle" || node.type === "image-marker") {
2534
+ const startPoint = node.meta.startPoint ?? {
2535
+ x: node.props.x,
2536
+ y: node.props.y
2537
+ };
2538
+ const [p1, p2] = normalizePoints(startPoint, finalPosition);
2532
2539
  return {
2533
2540
  ...node,
2534
2541
  props: {
@@ -2537,6 +2544,11 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2537
2544
  y: p1.y,
2538
2545
  width: Math.max(p2.x - p1.x, RECT$1.MIN_SIZE),
2539
2546
  height: Math.max(p2.y - p1.y, RECT$1.MIN_SIZE)
2547
+ },
2548
+ meta: {
2549
+ ...node.meta,
2550
+ // 保存初始起点,以便后续更新使用
2551
+ startPoint
2540
2552
  }
2541
2553
  };
2542
2554
  }
@@ -2767,21 +2779,21 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2767
2779
  * @internal 仅供内部使用
2768
2780
  */
2769
2781
  findImageAtPosition(position) {
2770
- const stage = __privateGet(this, _canvasStage).getStage();
2771
- const imageShapes = stage.find(
2782
+ const layer = __privateGet(this, _mainLayer).getLayer();
2783
+ const imageShapes = layer.find(
2772
2784
  (node) => node.getClassName() === "Image"
2773
2785
  );
2774
2786
  const originalListeningStates = imageShapes.map(
2775
2787
  (shape) => shape.listening()
2776
2788
  );
2777
2789
  imageShapes.forEach((shape) => shape.listening(true));
2790
+ layer.draw();
2778
2791
  try {
2779
- const shapes = stage.getAllIntersections(position);
2780
- const imageShapesAtPos = shapes.filter(
2781
- (shape) => shape.getClassName() === "Image"
2782
- );
2783
- if (imageShapesAtPos.length === 0) return null;
2784
- return imageShapesAtPos[imageShapesAtPos.length - 1];
2792
+ const shape = layer.getIntersection(position);
2793
+ if (shape?.getClassName() === "Image") {
2794
+ return shape;
2795
+ }
2796
+ return null;
2785
2797
  } finally {
2786
2798
  imageShapes.forEach((shape, index) => {
2787
2799
  shape.listening(originalListeningStates[index]);
@@ -2797,17 +2809,16 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2797
2809
  }
2798
2810
  const node = createNodeByType(type, position, void 0, meta);
2799
2811
  __privateSet(this, _draftNode, createCanvasNodeByType(this, type, node));
2800
- console.log(__privateGet(this, _draftNode));
2801
2812
  if (!__privateGet(this, _draftNode)) return;
2802
2813
  __privateGet(this, _mainLayer).add(__privateGet(this, _draftNode).getElement());
2803
2814
  }
2804
2815
  /**
2805
2816
  * @internal 仅供内部使用
2806
2817
  */
2807
- updateDraftNode(position, bounds) {
2818
+ updateDraftNode(position) {
2808
2819
  if (!__privateGet(this, _draftNode)) return;
2809
2820
  const node = __privateGet(this, _draftNode).getNode();
2810
- const updatedNode = updateNodeByType(node, position, bounds);
2821
+ const updatedNode = updateNodeByType(node, position);
2811
2822
  __privateGet(this, _draftNode).updateNode(updatedNode);
2812
2823
  }
2813
2824
  /**
@@ -3204,11 +3215,11 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3204
3215
  this.updateViewport({ x, y, scale: newScale }, true);
3205
3216
  }
3206
3217
  }
3207
- function modulate(value, rangeA, rangeB, clamp = false) {
3218
+ function modulate(value, rangeA, rangeB, clamp2 = false) {
3208
3219
  const [fromLow, fromHigh] = rangeA;
3209
3220
  const [v0, v1] = rangeB;
3210
3221
  const result = v0 + (value - fromLow) / (fromHigh - fromLow) * (v1 - v0);
3211
- return clamp ? v0 < v1 ? Math.max(Math.min(result, v1), v0) : Math.max(Math.min(result, v0), v1) : result;
3222
+ return clamp2 ? v0 < v1 ? Math.max(Math.min(result, v1), v0) : Math.max(Math.min(result, v0), v1) : result;
3212
3223
  }
3213
3224
  const gridSteps = [
3214
3225
  {
@@ -3450,9 +3461,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3450
3461
  core.on("viewport:change", (newViewport) => {
3451
3462
  setViewport(newViewport);
3452
3463
  });
3453
- core.on("transformer:positionChange", (position) => {
3454
- console.log("Transformer position changed:", position);
3455
- });
3456
3464
  return () => {
3457
3465
  core.dispose();
3458
3466
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8btc/whiteboard",
3
3
  "private": false,
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
7
7
  "module": "./dist/index.js",