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