@8btc/whiteboard 0.0.13 → 0.0.15

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.d.ts CHANGED
@@ -73,6 +73,14 @@ export declare class CanvasApi extends CanvasCore {
73
73
  * @returns 被删除的节点数据数组
74
74
  */
75
75
  deleteNodes(nodeIds: string[]): INode[];
76
+ /**
77
+ * 将节点移动到最上层
78
+ */
79
+ moveNodesToTop(nodeIds: string[]): void;
80
+ /**
81
+ * 将节点移动到最下层
82
+ */
83
+ moveNodesToBottom(nodeIds: string[]): void;
76
84
  /**
77
85
  * 滚动到内容区域
78
86
  * - 如果提供了 nodeIds,将指定的节点居中显示
package/dist/index.js CHANGED
@@ -691,13 +691,18 @@ class ImageNode extends BaseCanvasNode {
691
691
  __privateMethod(this, _ImageNode_instances, setupEventHandlers_fn2).call(this, this.getElement());
692
692
  }
693
693
  createElement() {
694
+ const width = this.node.props.width || IMAGE.MIN_SIZE;
695
+ const height = this.node.props.height || IMAGE.MIN_SIZE;
694
696
  const placeholder = document.createElement("canvas");
695
- placeholder.width = 1;
696
- placeholder.height = 1;
697
+ placeholder.width = width;
698
+ placeholder.height = height;
697
699
  const img = new Konva.Image({
698
700
  id: this.node.id,
699
701
  x: this.node.props.x,
700
702
  y: this.node.props.y,
703
+ width,
704
+ height,
705
+ rotation: this.node.props.rotation || 0,
701
706
  name: `${NODE_NAMES.nodeRoot} ${NODE_NAMES.selectable} ${NODE_NAMES.image}`,
702
707
  draggable: true,
703
708
  image: placeholder
@@ -924,7 +929,7 @@ class ImageMarkerNode extends BaseCanvasNode {
924
929
  );
925
930
  const group = new Konva.Group({
926
931
  id: this.node.id,
927
- name: `${NODE_NAMES.nodeRoot} ${NODE_NAMES.imageMarker} ${this.node.meta.parent} ${NODE_NAMES.selectable}`,
932
+ name: `${NODE_NAMES.nodeRoot} ${NODE_NAMES.imageMarker} ${this.node.meta.parent}`,
928
933
  x: this.node.props.x,
929
934
  y: this.node.props.y,
930
935
  width,
@@ -1041,7 +1046,8 @@ class ImageMarkerNode extends BaseCanvasNode {
1041
1046
  * 更新焦点状态(hover 或 selected)
1042
1047
  */
1043
1048
  setFocusState(isFocus) {
1044
- const strokeWidth = isFocus ? 4 : 3;
1049
+ const stageScale = this.core.getStageScale();
1050
+ const strokeWidth = isFocus ? 4 / stageScale : 3 / stageScale;
1045
1051
  const scale = isFocus ? 1.2 : 1;
1046
1052
  __privateGet(this, _rect).strokeWidth(strokeWidth);
1047
1053
  __privateGet(this, _circle).strokeWidth(strokeWidth);
@@ -1833,7 +1839,8 @@ class CanvasApi extends CanvasCore {
1833
1839
  * 如果删除的是 image 节点,会同步删除所有关联的 image-marker
1834
1840
  */
1835
1841
  deleteSelectedNodes() {
1836
- super.deleteSelectedNodes();
1842
+ const selectedNodeIds = this.getState().selectedNodeIds || [];
1843
+ this.deleteNodes(selectedNodeIds);
1837
1844
  }
1838
1845
  /**
1839
1846
  * 删除指定的节点
@@ -1844,6 +1851,30 @@ class CanvasApi extends CanvasCore {
1844
1851
  deleteNodes(nodeIds) {
1845
1852
  return super.deleteNodes(nodeIds);
1846
1853
  }
1854
+ /**
1855
+ * 将节点移动到最上层
1856
+ */
1857
+ moveNodesToTop(nodeIds) {
1858
+ if (nodeIds.length === 0) return;
1859
+ nodeIds.forEach((id) => {
1860
+ const shape = this.getStage().findOne(`#${id}`);
1861
+ if (shape) {
1862
+ shape.moveToTop();
1863
+ }
1864
+ });
1865
+ }
1866
+ /**
1867
+ * 将节点移动到最下层
1868
+ */
1869
+ moveNodesToBottom(nodeIds) {
1870
+ if (nodeIds.length === 0) return;
1871
+ nodeIds.forEach((id) => {
1872
+ const shape = this.getStage().findOne(`#${id}`);
1873
+ if (shape) {
1874
+ shape.moveToBottom();
1875
+ }
1876
+ });
1877
+ }
1847
1878
  /**
1848
1879
  * 滚动到内容区域
1849
1880
  * - 如果提供了 nodeIds,将指定的节点居中显示
package/dist/index.umd.js CHANGED
@@ -2008,13 +2008,18 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2008
2008
  __privateMethod(this, _ImageNode_instances, setupEventHandlers_fn2).call(this, this.getElement());
2009
2009
  }
2010
2010
  createElement() {
2011
+ const width = this.node.props.width || IMAGE.MIN_SIZE;
2012
+ const height = this.node.props.height || IMAGE.MIN_SIZE;
2011
2013
  const placeholder = document.createElement("canvas");
2012
- placeholder.width = 1;
2013
- placeholder.height = 1;
2014
+ placeholder.width = width;
2015
+ placeholder.height = height;
2014
2016
  const img = new Konva.Image({
2015
2017
  id: this.node.id,
2016
2018
  x: this.node.props.x,
2017
2019
  y: this.node.props.y,
2020
+ width,
2021
+ height,
2022
+ rotation: this.node.props.rotation || 0,
2018
2023
  name: `${NODE_NAMES.nodeRoot} ${NODE_NAMES.selectable} ${NODE_NAMES.image}`,
2019
2024
  draggable: true,
2020
2025
  image: placeholder
@@ -2241,7 +2246,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2241
2246
  );
2242
2247
  const group = new Konva.Group({
2243
2248
  id: this.node.id,
2244
- name: `${NODE_NAMES.nodeRoot} ${NODE_NAMES.imageMarker} ${this.node.meta.parent} ${NODE_NAMES.selectable}`,
2249
+ name: `${NODE_NAMES.nodeRoot} ${NODE_NAMES.imageMarker} ${this.node.meta.parent}`,
2245
2250
  x: this.node.props.x,
2246
2251
  y: this.node.props.y,
2247
2252
  width,
@@ -2358,7 +2363,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2358
2363
  * 更新焦点状态(hover 或 selected)
2359
2364
  */
2360
2365
  setFocusState(isFocus) {
2361
- const strokeWidth = isFocus ? 4 : 3;
2366
+ const stageScale = this.core.getStageScale();
2367
+ const strokeWidth = isFocus ? 4 / stageScale : 3 / stageScale;
2362
2368
  const scale = isFocus ? 1.2 : 1;
2363
2369
  __privateGet(this, _rect).strokeWidth(strokeWidth);
2364
2370
  __privateGet(this, _circle).strokeWidth(strokeWidth);
@@ -3150,7 +3156,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3150
3156
  * 如果删除的是 image 节点,会同步删除所有关联的 image-marker
3151
3157
  */
3152
3158
  deleteSelectedNodes() {
3153
- super.deleteSelectedNodes();
3159
+ const selectedNodeIds = this.getState().selectedNodeIds || [];
3160
+ this.deleteNodes(selectedNodeIds);
3154
3161
  }
3155
3162
  /**
3156
3163
  * 删除指定的节点
@@ -3161,6 +3168,30 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3161
3168
  deleteNodes(nodeIds) {
3162
3169
  return super.deleteNodes(nodeIds);
3163
3170
  }
3171
+ /**
3172
+ * 将节点移动到最上层
3173
+ */
3174
+ moveNodesToTop(nodeIds) {
3175
+ if (nodeIds.length === 0) return;
3176
+ nodeIds.forEach((id) => {
3177
+ const shape = this.getStage().findOne(`#${id}`);
3178
+ if (shape) {
3179
+ shape.moveToTop();
3180
+ }
3181
+ });
3182
+ }
3183
+ /**
3184
+ * 将节点移动到最下层
3185
+ */
3186
+ moveNodesToBottom(nodeIds) {
3187
+ if (nodeIds.length === 0) return;
3188
+ nodeIds.forEach((id) => {
3189
+ const shape = this.getStage().findOne(`#${id}`);
3190
+ if (shape) {
3191
+ shape.moveToBottom();
3192
+ }
3193
+ });
3194
+ }
3164
3195
  /**
3165
3196
  * 滚动到内容区域
3166
3197
  * - 如果提供了 nodeIds,将指定的节点居中显示
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8btc/whiteboard",
3
3
  "private": false,
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
7
7
  "module": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "**/*.css"
21
21
  ],
22
22
  "scripts": {
23
- "dev": "vite --port 6999",
23
+ "dev": "vite --port 6999 --host",
24
24
  "build": "tsc -b && vite build",
25
25
  "lint": "eslint .",
26
26
  "preview": "vite preview",