@8btc/whiteboard 0.0.7 → 0.0.9
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 +0 -8
- package/dist/index.d.ts +3 -1
- package/dist/index.js +74 -170
- package/dist/index.umd.js +74 -178
- package/package.json +1 -1
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
|
@@ -93,7 +93,7 @@ declare class CanvasCore extends CanvasState_2 {
|
|
|
93
93
|
/**
|
|
94
94
|
* 发射事件(供内部类使用)
|
|
95
95
|
*/
|
|
96
|
-
emitEvent<
|
|
96
|
+
emitEvent<StageEvent extends keyof StateEvents>(event: StageEvent, data: StateEvents[StageEvent]): void;
|
|
97
97
|
/**
|
|
98
98
|
* 获取 Konva.Stage 实例
|
|
99
99
|
*/
|
|
@@ -385,6 +385,8 @@ declare type StateEvents = {
|
|
|
385
385
|
"viewport:change": ICoreState["viewport"];
|
|
386
386
|
"transformer:positionChange": TransformerPosition | null;
|
|
387
387
|
"toolType:change": ICoreState["toolType"];
|
|
388
|
+
"nodes:created": ICoreState["nodes"];
|
|
389
|
+
"nodes:deleted": string[];
|
|
388
390
|
};
|
|
389
391
|
|
|
390
392
|
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,
|
|
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";
|
|
@@ -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
|
/**
|
|
@@ -511,78 +510,21 @@ class CanvasState {
|
|
|
511
510
|
}
|
|
512
511
|
}
|
|
513
512
|
const NODE_NAME_FOR_SELECT = "shapeNameForSelect";
|
|
514
|
-
const RECT
|
|
513
|
+
const RECT = {
|
|
515
514
|
CORNER_RADIUS: 6,
|
|
516
515
|
MIN_SIZE: 10
|
|
517
516
|
};
|
|
518
517
|
const IMAGE = {
|
|
519
518
|
MIN_SIZE: 10
|
|
520
519
|
};
|
|
521
|
-
const RECT = {
|
|
522
|
-
MIN_SIZE: 10
|
|
523
|
-
};
|
|
524
|
-
function calculatePerimeter(width, height, cornerRadius) {
|
|
525
|
-
return 2 * (height + width - cornerRadius * (4 - Math.PI));
|
|
526
|
-
}
|
|
527
|
-
function getDashValue(shapeLength, strokeWidth, lineStyle) {
|
|
528
|
-
let ratio = 1;
|
|
529
|
-
let dashLength = 0;
|
|
530
|
-
let dashGap = 0;
|
|
531
|
-
switch (lineStyle) {
|
|
532
|
-
case "dashed":
|
|
533
|
-
dashLength = Math.min(strokeWidth * 2, shapeLength / 4);
|
|
534
|
-
break;
|
|
535
|
-
case "dotted":
|
|
536
|
-
ratio = 8;
|
|
537
|
-
dashLength = strokeWidth / ratio;
|
|
538
|
-
break;
|
|
539
|
-
default:
|
|
540
|
-
return [];
|
|
541
|
-
}
|
|
542
|
-
let dashCount = Math.floor(shapeLength / dashLength / (2 * ratio));
|
|
543
|
-
dashCount = Math.max(dashCount, 3);
|
|
544
|
-
dashLength = shapeLength / dashCount / (2 * ratio);
|
|
545
|
-
dashGap = (shapeLength - dashCount * dashLength) / dashCount;
|
|
546
|
-
return [dashLength, dashGap];
|
|
547
|
-
}
|
|
548
|
-
function getSizeValue(key) {
|
|
549
|
-
switch (key) {
|
|
550
|
-
case "small":
|
|
551
|
-
return 2;
|
|
552
|
-
case "medium":
|
|
553
|
-
return 3;
|
|
554
|
-
case "large":
|
|
555
|
-
return 5;
|
|
556
|
-
case "extra-large":
|
|
557
|
-
return 8;
|
|
558
|
-
default:
|
|
559
|
-
return 3;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
function getTotalDashLength(dash) {
|
|
563
|
-
return Array.isArray(dash) && dash.length > 1 ? dash[0] + dash[1] : 0;
|
|
564
|
-
}
|
|
565
|
-
function getRectSize(rect) {
|
|
566
|
-
return {
|
|
567
|
-
width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
|
|
568
|
-
height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
520
|
class BaseCanvasNode {
|
|
572
521
|
constructor(core, node) {
|
|
573
522
|
__publicField(this, "core");
|
|
574
523
|
__publicField(this, "node");
|
|
575
524
|
__publicField(this, "element");
|
|
576
|
-
__publicField(this, "toolTypeChangeHandler");
|
|
577
525
|
this.core = core;
|
|
578
526
|
this.node = node;
|
|
579
527
|
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
528
|
}
|
|
587
529
|
/**
|
|
588
530
|
* 获取 Konva 元素
|
|
@@ -596,47 +538,31 @@ class BaseCanvasNode {
|
|
|
596
538
|
getNode() {
|
|
597
539
|
return this.node;
|
|
598
540
|
}
|
|
599
|
-
/**
|
|
600
|
-
* 销毁节点
|
|
601
|
-
*/
|
|
602
|
-
destroy() {
|
|
603
|
-
this.core.off("toolType:change", this.toolTypeChangeHandler);
|
|
604
|
-
this.element.destroy();
|
|
605
|
-
}
|
|
606
541
|
}
|
|
607
|
-
function
|
|
608
|
-
if (!totalDashLength || totalDashLength === 0) {
|
|
609
|
-
return null;
|
|
610
|
-
}
|
|
611
|
-
const anim = new Konva.Animation((frame) => {
|
|
612
|
-
if (!frame) return;
|
|
613
|
-
const dashOffset = -frame.time / 10 % totalDashLength;
|
|
614
|
-
rect.dashOffset(dashOffset);
|
|
615
|
-
}, rect.getLayer());
|
|
542
|
+
function getRectSize(rect) {
|
|
616
543
|
return {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
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())
|
|
620
546
|
};
|
|
621
547
|
}
|
|
622
548
|
class RectNode extends BaseCanvasNode {
|
|
623
549
|
constructor(core, node) {
|
|
624
550
|
super(core, node);
|
|
625
551
|
__privateAdd(this, _RectNode_instances);
|
|
626
|
-
__privateAdd(this,
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
552
|
+
__privateAdd(this, _toolTypeChangeHandler, (toolType) => {
|
|
553
|
+
const isSelect = toolType === "select";
|
|
554
|
+
this.element.listening(isSelect);
|
|
555
|
+
});
|
|
630
556
|
__privateMethod(this, _RectNode_instances, setupEventHandlers_fn).call(this, this.getElement());
|
|
631
557
|
}
|
|
632
558
|
createElement() {
|
|
633
559
|
const width = Math.max(
|
|
634
|
-
this.node.props.width ?? RECT
|
|
635
|
-
RECT
|
|
560
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
561
|
+
RECT.MIN_SIZE
|
|
636
562
|
);
|
|
637
563
|
const height = Math.max(
|
|
638
|
-
this.node.props.height ?? RECT
|
|
639
|
-
RECT
|
|
564
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
565
|
+
RECT.MIN_SIZE
|
|
640
566
|
);
|
|
641
567
|
const config = {
|
|
642
568
|
id: this.node.id,
|
|
@@ -644,7 +570,7 @@ class RectNode extends BaseCanvasNode {
|
|
|
644
570
|
...this.node.style,
|
|
645
571
|
width,
|
|
646
572
|
height,
|
|
647
|
-
cornerRadius: RECT
|
|
573
|
+
cornerRadius: RECT.CORNER_RADIUS,
|
|
648
574
|
name: NODE_NAME_FOR_SELECT,
|
|
649
575
|
draggable: true,
|
|
650
576
|
stroke: "black",
|
|
@@ -683,76 +609,38 @@ class RectNode extends BaseCanvasNode {
|
|
|
683
609
|
rect.x(this.node.props.x);
|
|
684
610
|
rect.y(this.node.props.y);
|
|
685
611
|
const width = Math.max(
|
|
686
|
-
this.node.props.width ?? RECT
|
|
687
|
-
RECT
|
|
612
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
613
|
+
RECT.MIN_SIZE
|
|
688
614
|
);
|
|
689
615
|
const height = Math.max(
|
|
690
|
-
this.node.props.height ?? RECT
|
|
691
|
-
RECT
|
|
616
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
617
|
+
RECT.MIN_SIZE
|
|
692
618
|
);
|
|
693
619
|
rect.width(width);
|
|
694
620
|
rect.height(height);
|
|
695
|
-
if (this.node.style.animated && !__privateGet(this, _animation)) {
|
|
696
|
-
__privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
|
|
697
|
-
} else if (!this.node.style.animated && __privateGet(this, _animation)) {
|
|
698
|
-
__privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
|
|
699
|
-
}
|
|
700
621
|
}
|
|
701
622
|
/**
|
|
702
623
|
* 销毁
|
|
703
624
|
*/
|
|
704
625
|
destroy() {
|
|
705
|
-
|
|
706
|
-
|
|
626
|
+
this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
627
|
+
this.element.destroy();
|
|
707
628
|
}
|
|
708
629
|
}
|
|
709
|
-
|
|
630
|
+
_toolTypeChangeHandler = new WeakMap();
|
|
710
631
|
_RectNode_instances = new WeakSet();
|
|
711
|
-
/**
|
|
712
|
-
* 初始化动画
|
|
713
|
-
*/
|
|
714
|
-
initAnimation_fn = function() {
|
|
715
|
-
const rect = this.getElement();
|
|
716
|
-
const dash = rect.dash();
|
|
717
|
-
if (!dash || dash.length === 0) return;
|
|
718
|
-
const totalDashLength = getTotalDashLength(dash);
|
|
719
|
-
__privateSet(this, _animation, createRectAnimation(rect, totalDashLength));
|
|
720
|
-
if (__privateGet(this, _animation)) {
|
|
721
|
-
__privateGet(this, _animation).start();
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
/**
|
|
725
|
-
* 销毁动画
|
|
726
|
-
*/
|
|
727
|
-
destroyAnimation_fn = function() {
|
|
728
|
-
if (__privateGet(this, _animation)) {
|
|
729
|
-
__privateGet(this, _animation).stop();
|
|
730
|
-
__privateSet(this, _animation, null);
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
632
|
/**
|
|
734
633
|
* 设置事件处理器
|
|
735
634
|
*/
|
|
736
|
-
setupEventHandlers_fn = function(rect
|
|
737
|
-
const element = rect
|
|
738
|
-
|
|
739
|
-
if (this.node.style.animated && __privateGet(this, _animation)) {
|
|
740
|
-
__privateGet(this, _animation).stop();
|
|
741
|
-
}
|
|
742
|
-
});
|
|
635
|
+
setupEventHandlers_fn = function(rect) {
|
|
636
|
+
const element = rect;
|
|
637
|
+
this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
743
638
|
element.on("transform", (event) => {
|
|
744
639
|
const rect2 = event.target;
|
|
745
640
|
const { width, height } = getRectSize(rect2);
|
|
746
|
-
const totalLength = calculatePerimeter(width, height, RECT$1.CORNER_RADIUS);
|
|
747
|
-
const dash = getDashValue(
|
|
748
|
-
totalLength,
|
|
749
|
-
getSizeValue(this.node.style.size),
|
|
750
|
-
this.node.style.line
|
|
751
|
-
);
|
|
752
641
|
rect2.scale({ x: 1, y: 1 });
|
|
753
642
|
rect2.width(width);
|
|
754
643
|
rect2.height(height);
|
|
755
|
-
rect2.dash(dash.map((d) => d * this.core.getStageScale()));
|
|
756
644
|
});
|
|
757
645
|
element.on("transformend", (event) => {
|
|
758
646
|
const rect2 = event.target;
|
|
@@ -769,9 +657,6 @@ setupEventHandlers_fn = function(rect = void 0) {
|
|
|
769
657
|
this.core._syncNodeFromElement(this.node.id, {
|
|
770
658
|
props: newProps
|
|
771
659
|
});
|
|
772
|
-
if (this.node.style.animated && __privateGet(this, _animation)?.isRunning() === false) {
|
|
773
|
-
__privateGet(this, _animation).start();
|
|
774
|
-
}
|
|
775
660
|
});
|
|
776
661
|
element.on("dragend", (event) => {
|
|
777
662
|
const rect2 = event.target;
|
|
@@ -790,6 +675,10 @@ class ImageNode extends BaseCanvasNode {
|
|
|
790
675
|
constructor(core, node) {
|
|
791
676
|
super(core, node);
|
|
792
677
|
__privateAdd(this, _ImageNode_instances);
|
|
678
|
+
__privateAdd(this, _toolTypeChangeHandler2, (toolType) => {
|
|
679
|
+
const isSelect = toolType === "select";
|
|
680
|
+
this.element.listening(isSelect);
|
|
681
|
+
});
|
|
793
682
|
__privateMethod(this, _ImageNode_instances, loadImage_fn).call(this);
|
|
794
683
|
__privateMethod(this, _ImageNode_instances, setupEventHandlers_fn2).call(this, this.getElement());
|
|
795
684
|
}
|
|
@@ -853,7 +742,8 @@ class ImageNode extends BaseCanvasNode {
|
|
|
853
742
|
* 销毁
|
|
854
743
|
*/
|
|
855
744
|
destroy() {
|
|
856
|
-
|
|
745
|
+
this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
|
|
746
|
+
this.element.destroy();
|
|
857
747
|
}
|
|
858
748
|
}
|
|
859
749
|
_ImageNode_instances = new WeakSet();
|
|
@@ -880,10 +770,12 @@ loadImage_fn = function() {
|
|
|
880
770
|
console.error("Failed to load image:", imageUrl);
|
|
881
771
|
};
|
|
882
772
|
};
|
|
773
|
+
_toolTypeChangeHandler2 = new WeakMap();
|
|
883
774
|
/**
|
|
884
775
|
* 设置事件处理器
|
|
885
776
|
*/
|
|
886
777
|
setupEventHandlers_fn2 = function(img) {
|
|
778
|
+
this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
|
|
887
779
|
img.on("transform", (event) => {
|
|
888
780
|
const img2 = event.target;
|
|
889
781
|
const width = Math.max(IMAGE.MIN_SIZE, img2.width() * img2.scaleX());
|
|
@@ -1004,12 +896,12 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1004
896
|
}
|
|
1005
897
|
createElement() {
|
|
1006
898
|
const width = Math.max(
|
|
1007
|
-
this.node.props.width ?? RECT
|
|
1008
|
-
RECT
|
|
899
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
900
|
+
RECT.MIN_SIZE
|
|
1009
901
|
);
|
|
1010
902
|
const height = Math.max(
|
|
1011
|
-
this.node.props.height ?? RECT
|
|
1012
|
-
RECT
|
|
903
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
904
|
+
RECT.MIN_SIZE
|
|
1013
905
|
);
|
|
1014
906
|
const group = new Konva.Group({
|
|
1015
907
|
id: this.node.id,
|
|
@@ -1017,7 +909,8 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1017
909
|
x: this.node.props.x,
|
|
1018
910
|
y: this.node.props.y,
|
|
1019
911
|
width,
|
|
1020
|
-
height
|
|
912
|
+
height,
|
|
913
|
+
listening: false
|
|
1021
914
|
});
|
|
1022
915
|
const rect = new Konva.Rect({
|
|
1023
916
|
name: "rect",
|
|
@@ -1029,7 +922,7 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1029
922
|
strokeWidth: 2,
|
|
1030
923
|
dash: [5, 5],
|
|
1031
924
|
fill: "transparent",
|
|
1032
|
-
cornerRadius: RECT
|
|
925
|
+
cornerRadius: RECT.CORNER_RADIUS
|
|
1033
926
|
});
|
|
1034
927
|
const markerGroup = new Konva.Group({
|
|
1035
928
|
name: "marker-group",
|
|
@@ -1091,12 +984,12 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1091
984
|
group.x(this.node.props.x);
|
|
1092
985
|
group.y(this.node.props.y);
|
|
1093
986
|
const width = Math.max(
|
|
1094
|
-
this.node.props.width ?? RECT
|
|
1095
|
-
RECT
|
|
987
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
988
|
+
RECT.MIN_SIZE
|
|
1096
989
|
);
|
|
1097
990
|
const height = Math.max(
|
|
1098
|
-
this.node.props.height ?? RECT
|
|
1099
|
-
RECT
|
|
991
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
992
|
+
RECT.MIN_SIZE
|
|
1100
993
|
);
|
|
1101
994
|
group.width(width);
|
|
1102
995
|
group.height(height);
|
|
@@ -1115,7 +1008,7 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1115
1008
|
* 销毁
|
|
1116
1009
|
*/
|
|
1117
1010
|
destroy() {
|
|
1118
|
-
|
|
1011
|
+
this.element.destroy();
|
|
1119
1012
|
}
|
|
1120
1013
|
/**
|
|
1121
1014
|
* 更新焦点状态(hover 或 selected)
|
|
@@ -1164,6 +1057,9 @@ function createCanvasNodeByType(core, type, config) {
|
|
|
1164
1057
|
return null;
|
|
1165
1058
|
}
|
|
1166
1059
|
}
|
|
1060
|
+
function clamp(value, range) {
|
|
1061
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1062
|
+
}
|
|
1167
1063
|
const createNodeByType = (type, position, style, meta) => {
|
|
1168
1064
|
const baseNode = {
|
|
1169
1065
|
type,
|
|
@@ -1182,7 +1078,10 @@ const createNodeByType = (type, position, style, meta) => {
|
|
|
1182
1078
|
rotation: 0,
|
|
1183
1079
|
visible: true
|
|
1184
1080
|
},
|
|
1185
|
-
meta:
|
|
1081
|
+
meta: {
|
|
1082
|
+
...meta,
|
|
1083
|
+
startPoint: position
|
|
1084
|
+
}
|
|
1186
1085
|
};
|
|
1187
1086
|
if (type === "image-marker") {
|
|
1188
1087
|
return {
|
|
@@ -1196,27 +1095,34 @@ const createNodeByType = (type, position, style, meta) => {
|
|
|
1196
1095
|
}
|
|
1197
1096
|
return baseNode;
|
|
1198
1097
|
};
|
|
1199
|
-
function updateNodeByType(node, position
|
|
1098
|
+
function updateNodeByType(node, position) {
|
|
1200
1099
|
let finalPosition = position;
|
|
1201
|
-
if (node.type === "image-marker" && bounds) {
|
|
1100
|
+
if (node.type === "image-marker" && node.meta.bounds) {
|
|
1101
|
+
const bounds = node.meta.bounds;
|
|
1202
1102
|
finalPosition = {
|
|
1203
|
-
x:
|
|
1204
|
-
y:
|
|
1103
|
+
x: clamp(position.x, [bounds.x, bounds.x + bounds.width]),
|
|
1104
|
+
y: clamp(position.y, [bounds.y, bounds.y + bounds.height])
|
|
1205
1105
|
};
|
|
1206
1106
|
}
|
|
1207
|
-
const [p1, p2] = normalizePoints(
|
|
1208
|
-
{ x: node.props.x, y: node.props.y },
|
|
1209
|
-
finalPosition
|
|
1210
|
-
);
|
|
1211
1107
|
if (node.type === "rectangle" || node.type === "image-marker") {
|
|
1108
|
+
const startPoint = node.meta.startPoint ?? {
|
|
1109
|
+
x: node.props.x,
|
|
1110
|
+
y: node.props.y
|
|
1111
|
+
};
|
|
1112
|
+
const [p1, p2] = normalizePoints(startPoint, finalPosition);
|
|
1212
1113
|
return {
|
|
1213
1114
|
...node,
|
|
1214
1115
|
props: {
|
|
1215
1116
|
...node.props,
|
|
1216
1117
|
x: p1.x,
|
|
1217
1118
|
y: p1.y,
|
|
1218
|
-
width: Math.max(p2.x - p1.x, RECT
|
|
1219
|
-
height: Math.max(p2.y - p1.y, RECT
|
|
1119
|
+
width: Math.max(p2.x - p1.x, RECT.MIN_SIZE),
|
|
1120
|
+
height: Math.max(p2.y - p1.y, RECT.MIN_SIZE)
|
|
1121
|
+
},
|
|
1122
|
+
meta: {
|
|
1123
|
+
...node.meta,
|
|
1124
|
+
// 保存初始起点,以便后续更新使用
|
|
1125
|
+
startPoint
|
|
1220
1126
|
}
|
|
1221
1127
|
};
|
|
1222
1128
|
}
|
|
@@ -1388,6 +1294,7 @@ class CanvasCore extends CanvasState {
|
|
|
1388
1294
|
},
|
|
1389
1295
|
true
|
|
1390
1296
|
);
|
|
1297
|
+
this.emit("nodes:created", nodes);
|
|
1391
1298
|
}
|
|
1392
1299
|
/**
|
|
1393
1300
|
* 创建图片标注节点(内部使用)
|
|
@@ -1477,17 +1384,16 @@ class CanvasCore extends CanvasState {
|
|
|
1477
1384
|
}
|
|
1478
1385
|
const node = createNodeByType(type, position, void 0, meta);
|
|
1479
1386
|
__privateSet(this, _draftNode, createCanvasNodeByType(this, type, node));
|
|
1480
|
-
console.log(__privateGet(this, _draftNode));
|
|
1481
1387
|
if (!__privateGet(this, _draftNode)) return;
|
|
1482
1388
|
__privateGet(this, _mainLayer).add(__privateGet(this, _draftNode).getElement());
|
|
1483
1389
|
}
|
|
1484
1390
|
/**
|
|
1485
1391
|
* @internal 仅供内部使用
|
|
1486
1392
|
*/
|
|
1487
|
-
updateDraftNode(position
|
|
1393
|
+
updateDraftNode(position) {
|
|
1488
1394
|
if (!__privateGet(this, _draftNode)) return;
|
|
1489
1395
|
const node = __privateGet(this, _draftNode).getNode();
|
|
1490
|
-
const updatedNode = updateNodeByType(node, position
|
|
1396
|
+
const updatedNode = updateNodeByType(node, position);
|
|
1491
1397
|
__privateGet(this, _draftNode).updateNode(updatedNode);
|
|
1492
1398
|
}
|
|
1493
1399
|
/**
|
|
@@ -1807,6 +1713,7 @@ class CanvasApi extends CanvasCore {
|
|
|
1807
1713
|
},
|
|
1808
1714
|
true
|
|
1809
1715
|
);
|
|
1716
|
+
this.emit("nodes:deleted", Array.from(idsToDelete));
|
|
1810
1717
|
}
|
|
1811
1718
|
/**
|
|
1812
1719
|
* 滚动到内容区域
|
|
@@ -1884,11 +1791,11 @@ class CanvasApi extends CanvasCore {
|
|
|
1884
1791
|
this.updateViewport({ x, y, scale: newScale }, true);
|
|
1885
1792
|
}
|
|
1886
1793
|
}
|
|
1887
|
-
function modulate(value, rangeA, rangeB,
|
|
1794
|
+
function modulate(value, rangeA, rangeB, clamp2 = false) {
|
|
1888
1795
|
const [fromLow, fromHigh] = rangeA;
|
|
1889
1796
|
const [v0, v1] = rangeB;
|
|
1890
1797
|
const result = v0 + (value - fromLow) / (fromHigh - fromLow) * (v1 - v0);
|
|
1891
|
-
return
|
|
1798
|
+
return clamp2 ? v0 < v1 ? Math.max(Math.min(result, v1), v0) : Math.max(Math.min(result, v0), v1) : result;
|
|
1892
1799
|
}
|
|
1893
1800
|
const gridSteps = [
|
|
1894
1801
|
{
|
|
@@ -2130,9 +2037,6 @@ function PureCanvas({ setApi }) {
|
|
|
2130
2037
|
core.on("viewport:change", (newViewport) => {
|
|
2131
2038
|
setViewport(newViewport);
|
|
2132
2039
|
});
|
|
2133
|
-
core.on("transformer:positionChange", (position) => {
|
|
2134
|
-
console.log("Transformer position changed:", position);
|
|
2135
|
-
});
|
|
2136
2040
|
return () => {
|
|
2137
2041
|
core.dispose();
|
|
2138
2042
|
};
|
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,
|
|
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
|
}
|
|
@@ -1588,7 +1580,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1588
1580
|
* 处理 transform 事件
|
|
1589
1581
|
*/
|
|
1590
1582
|
__privateAdd(this, _handleTransform, () => {
|
|
1591
|
-
console.log("transforming...");
|
|
1592
1583
|
this.emitPositionChange();
|
|
1593
1584
|
});
|
|
1594
1585
|
/**
|
|
@@ -1830,78 +1821,21 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1830
1821
|
}
|
|
1831
1822
|
}
|
|
1832
1823
|
const NODE_NAME_FOR_SELECT = "shapeNameForSelect";
|
|
1833
|
-
const RECT
|
|
1824
|
+
const RECT = {
|
|
1834
1825
|
CORNER_RADIUS: 6,
|
|
1835
1826
|
MIN_SIZE: 10
|
|
1836
1827
|
};
|
|
1837
1828
|
const IMAGE = {
|
|
1838
1829
|
MIN_SIZE: 10
|
|
1839
1830
|
};
|
|
1840
|
-
const RECT = {
|
|
1841
|
-
MIN_SIZE: 10
|
|
1842
|
-
};
|
|
1843
|
-
function calculatePerimeter(width, height, cornerRadius) {
|
|
1844
|
-
return 2 * (height + width - cornerRadius * (4 - Math.PI));
|
|
1845
|
-
}
|
|
1846
|
-
function getDashValue(shapeLength, strokeWidth, lineStyle) {
|
|
1847
|
-
let ratio = 1;
|
|
1848
|
-
let dashLength = 0;
|
|
1849
|
-
let dashGap = 0;
|
|
1850
|
-
switch (lineStyle) {
|
|
1851
|
-
case "dashed":
|
|
1852
|
-
dashLength = Math.min(strokeWidth * 2, shapeLength / 4);
|
|
1853
|
-
break;
|
|
1854
|
-
case "dotted":
|
|
1855
|
-
ratio = 8;
|
|
1856
|
-
dashLength = strokeWidth / ratio;
|
|
1857
|
-
break;
|
|
1858
|
-
default:
|
|
1859
|
-
return [];
|
|
1860
|
-
}
|
|
1861
|
-
let dashCount = Math.floor(shapeLength / dashLength / (2 * ratio));
|
|
1862
|
-
dashCount = Math.max(dashCount, 3);
|
|
1863
|
-
dashLength = shapeLength / dashCount / (2 * ratio);
|
|
1864
|
-
dashGap = (shapeLength - dashCount * dashLength) / dashCount;
|
|
1865
|
-
return [dashLength, dashGap];
|
|
1866
|
-
}
|
|
1867
|
-
function getSizeValue(key) {
|
|
1868
|
-
switch (key) {
|
|
1869
|
-
case "small":
|
|
1870
|
-
return 2;
|
|
1871
|
-
case "medium":
|
|
1872
|
-
return 3;
|
|
1873
|
-
case "large":
|
|
1874
|
-
return 5;
|
|
1875
|
-
case "extra-large":
|
|
1876
|
-
return 8;
|
|
1877
|
-
default:
|
|
1878
|
-
return 3;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
function getTotalDashLength(dash) {
|
|
1882
|
-
return Array.isArray(dash) && dash.length > 1 ? dash[0] + dash[1] : 0;
|
|
1883
|
-
}
|
|
1884
|
-
function getRectSize(rect) {
|
|
1885
|
-
return {
|
|
1886
|
-
width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
|
|
1887
|
-
height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
|
|
1888
|
-
};
|
|
1889
|
-
}
|
|
1890
1831
|
class BaseCanvasNode {
|
|
1891
1832
|
constructor(core, node) {
|
|
1892
1833
|
__publicField(this, "core");
|
|
1893
1834
|
__publicField(this, "node");
|
|
1894
1835
|
__publicField(this, "element");
|
|
1895
|
-
__publicField(this, "toolTypeChangeHandler");
|
|
1896
1836
|
this.core = core;
|
|
1897
1837
|
this.node = node;
|
|
1898
1838
|
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
1839
|
}
|
|
1906
1840
|
/**
|
|
1907
1841
|
* 获取 Konva 元素
|
|
@@ -1915,47 +1849,31 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1915
1849
|
getNode() {
|
|
1916
1850
|
return this.node;
|
|
1917
1851
|
}
|
|
1918
|
-
/**
|
|
1919
|
-
* 销毁节点
|
|
1920
|
-
*/
|
|
1921
|
-
destroy() {
|
|
1922
|
-
this.core.off("toolType:change", this.toolTypeChangeHandler);
|
|
1923
|
-
this.element.destroy();
|
|
1924
|
-
}
|
|
1925
1852
|
}
|
|
1926
|
-
function
|
|
1927
|
-
if (!totalDashLength || totalDashLength === 0) {
|
|
1928
|
-
return null;
|
|
1929
|
-
}
|
|
1930
|
-
const anim = new Konva.Animation((frame) => {
|
|
1931
|
-
if (!frame) return;
|
|
1932
|
-
const dashOffset = -frame.time / 10 % totalDashLength;
|
|
1933
|
-
rect.dashOffset(dashOffset);
|
|
1934
|
-
}, rect.getLayer());
|
|
1853
|
+
function getRectSize(rect) {
|
|
1935
1854
|
return {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
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())
|
|
1939
1857
|
};
|
|
1940
1858
|
}
|
|
1941
1859
|
class RectNode extends BaseCanvasNode {
|
|
1942
1860
|
constructor(core, node) {
|
|
1943
1861
|
super(core, node);
|
|
1944
1862
|
__privateAdd(this, _RectNode_instances);
|
|
1945
|
-
__privateAdd(this,
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
}
|
|
1863
|
+
__privateAdd(this, _toolTypeChangeHandler, (toolType) => {
|
|
1864
|
+
const isSelect = toolType === "select";
|
|
1865
|
+
this.element.listening(isSelect);
|
|
1866
|
+
});
|
|
1949
1867
|
__privateMethod(this, _RectNode_instances, setupEventHandlers_fn).call(this, this.getElement());
|
|
1950
1868
|
}
|
|
1951
1869
|
createElement() {
|
|
1952
1870
|
const width = Math.max(
|
|
1953
|
-
this.node.props.width ?? RECT
|
|
1954
|
-
RECT
|
|
1871
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
1872
|
+
RECT.MIN_SIZE
|
|
1955
1873
|
);
|
|
1956
1874
|
const height = Math.max(
|
|
1957
|
-
this.node.props.height ?? RECT
|
|
1958
|
-
RECT
|
|
1875
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
1876
|
+
RECT.MIN_SIZE
|
|
1959
1877
|
);
|
|
1960
1878
|
const config = {
|
|
1961
1879
|
id: this.node.id,
|
|
@@ -1963,7 +1881,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1963
1881
|
...this.node.style,
|
|
1964
1882
|
width,
|
|
1965
1883
|
height,
|
|
1966
|
-
cornerRadius: RECT
|
|
1884
|
+
cornerRadius: RECT.CORNER_RADIUS,
|
|
1967
1885
|
name: NODE_NAME_FOR_SELECT,
|
|
1968
1886
|
draggable: true,
|
|
1969
1887
|
stroke: "black",
|
|
@@ -2002,76 +1920,38 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2002
1920
|
rect.x(this.node.props.x);
|
|
2003
1921
|
rect.y(this.node.props.y);
|
|
2004
1922
|
const width = Math.max(
|
|
2005
|
-
this.node.props.width ?? RECT
|
|
2006
|
-
RECT
|
|
1923
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
1924
|
+
RECT.MIN_SIZE
|
|
2007
1925
|
);
|
|
2008
1926
|
const height = Math.max(
|
|
2009
|
-
this.node.props.height ?? RECT
|
|
2010
|
-
RECT
|
|
1927
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
1928
|
+
RECT.MIN_SIZE
|
|
2011
1929
|
);
|
|
2012
1930
|
rect.width(width);
|
|
2013
1931
|
rect.height(height);
|
|
2014
|
-
if (this.node.style.animated && !__privateGet(this, _animation)) {
|
|
2015
|
-
__privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
|
|
2016
|
-
} else if (!this.node.style.animated && __privateGet(this, _animation)) {
|
|
2017
|
-
__privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
|
|
2018
|
-
}
|
|
2019
1932
|
}
|
|
2020
1933
|
/**
|
|
2021
1934
|
* 销毁
|
|
2022
1935
|
*/
|
|
2023
1936
|
destroy() {
|
|
2024
|
-
|
|
2025
|
-
|
|
1937
|
+
this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
1938
|
+
this.element.destroy();
|
|
2026
1939
|
}
|
|
2027
1940
|
}
|
|
2028
|
-
|
|
1941
|
+
_toolTypeChangeHandler = new WeakMap();
|
|
2029
1942
|
_RectNode_instances = new WeakSet();
|
|
2030
|
-
/**
|
|
2031
|
-
* 初始化动画
|
|
2032
|
-
*/
|
|
2033
|
-
initAnimation_fn = function() {
|
|
2034
|
-
const rect = this.getElement();
|
|
2035
|
-
const dash = rect.dash();
|
|
2036
|
-
if (!dash || dash.length === 0) return;
|
|
2037
|
-
const totalDashLength = getTotalDashLength(dash);
|
|
2038
|
-
__privateSet(this, _animation, createRectAnimation(rect, totalDashLength));
|
|
2039
|
-
if (__privateGet(this, _animation)) {
|
|
2040
|
-
__privateGet(this, _animation).start();
|
|
2041
|
-
}
|
|
2042
|
-
};
|
|
2043
|
-
/**
|
|
2044
|
-
* 销毁动画
|
|
2045
|
-
*/
|
|
2046
|
-
destroyAnimation_fn = function() {
|
|
2047
|
-
if (__privateGet(this, _animation)) {
|
|
2048
|
-
__privateGet(this, _animation).stop();
|
|
2049
|
-
__privateSet(this, _animation, null);
|
|
2050
|
-
}
|
|
2051
|
-
};
|
|
2052
1943
|
/**
|
|
2053
1944
|
* 设置事件处理器
|
|
2054
1945
|
*/
|
|
2055
|
-
setupEventHandlers_fn = function(rect
|
|
2056
|
-
const element = rect
|
|
2057
|
-
|
|
2058
|
-
if (this.node.style.animated && __privateGet(this, _animation)) {
|
|
2059
|
-
__privateGet(this, _animation).stop();
|
|
2060
|
-
}
|
|
2061
|
-
});
|
|
1946
|
+
setupEventHandlers_fn = function(rect) {
|
|
1947
|
+
const element = rect;
|
|
1948
|
+
this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
2062
1949
|
element.on("transform", (event) => {
|
|
2063
1950
|
const rect2 = event.target;
|
|
2064
1951
|
const { width, height } = getRectSize(rect2);
|
|
2065
|
-
const totalLength = calculatePerimeter(width, height, RECT$1.CORNER_RADIUS);
|
|
2066
|
-
const dash = getDashValue(
|
|
2067
|
-
totalLength,
|
|
2068
|
-
getSizeValue(this.node.style.size),
|
|
2069
|
-
this.node.style.line
|
|
2070
|
-
);
|
|
2071
1952
|
rect2.scale({ x: 1, y: 1 });
|
|
2072
1953
|
rect2.width(width);
|
|
2073
1954
|
rect2.height(height);
|
|
2074
|
-
rect2.dash(dash.map((d) => d * this.core.getStageScale()));
|
|
2075
1955
|
});
|
|
2076
1956
|
element.on("transformend", (event) => {
|
|
2077
1957
|
const rect2 = event.target;
|
|
@@ -2088,9 +1968,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2088
1968
|
this.core._syncNodeFromElement(this.node.id, {
|
|
2089
1969
|
props: newProps
|
|
2090
1970
|
});
|
|
2091
|
-
if (this.node.style.animated && __privateGet(this, _animation)?.isRunning() === false) {
|
|
2092
|
-
__privateGet(this, _animation).start();
|
|
2093
|
-
}
|
|
2094
1971
|
});
|
|
2095
1972
|
element.on("dragend", (event) => {
|
|
2096
1973
|
const rect2 = event.target;
|
|
@@ -2109,6 +1986,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2109
1986
|
constructor(core, node) {
|
|
2110
1987
|
super(core, node);
|
|
2111
1988
|
__privateAdd(this, _ImageNode_instances);
|
|
1989
|
+
__privateAdd(this, _toolTypeChangeHandler2, (toolType) => {
|
|
1990
|
+
const isSelect = toolType === "select";
|
|
1991
|
+
this.element.listening(isSelect);
|
|
1992
|
+
});
|
|
2112
1993
|
__privateMethod(this, _ImageNode_instances, loadImage_fn).call(this);
|
|
2113
1994
|
__privateMethod(this, _ImageNode_instances, setupEventHandlers_fn2).call(this, this.getElement());
|
|
2114
1995
|
}
|
|
@@ -2172,7 +2053,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2172
2053
|
* 销毁
|
|
2173
2054
|
*/
|
|
2174
2055
|
destroy() {
|
|
2175
|
-
|
|
2056
|
+
this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
|
|
2057
|
+
this.element.destroy();
|
|
2176
2058
|
}
|
|
2177
2059
|
}
|
|
2178
2060
|
_ImageNode_instances = new WeakSet();
|
|
@@ -2199,10 +2081,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2199
2081
|
console.error("Failed to load image:", imageUrl);
|
|
2200
2082
|
};
|
|
2201
2083
|
};
|
|
2084
|
+
_toolTypeChangeHandler2 = new WeakMap();
|
|
2202
2085
|
/**
|
|
2203
2086
|
* 设置事件处理器
|
|
2204
2087
|
*/
|
|
2205
2088
|
setupEventHandlers_fn2 = function(img) {
|
|
2089
|
+
this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler2));
|
|
2206
2090
|
img.on("transform", (event) => {
|
|
2207
2091
|
const img2 = event.target;
|
|
2208
2092
|
const width = Math.max(IMAGE.MIN_SIZE, img2.width() * img2.scaleX());
|
|
@@ -2323,12 +2207,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2323
2207
|
}
|
|
2324
2208
|
createElement() {
|
|
2325
2209
|
const width = Math.max(
|
|
2326
|
-
this.node.props.width ?? RECT
|
|
2327
|
-
RECT
|
|
2210
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
2211
|
+
RECT.MIN_SIZE
|
|
2328
2212
|
);
|
|
2329
2213
|
const height = Math.max(
|
|
2330
|
-
this.node.props.height ?? RECT
|
|
2331
|
-
RECT
|
|
2214
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
2215
|
+
RECT.MIN_SIZE
|
|
2332
2216
|
);
|
|
2333
2217
|
const group = new Konva.Group({
|
|
2334
2218
|
id: this.node.id,
|
|
@@ -2336,7 +2220,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2336
2220
|
x: this.node.props.x,
|
|
2337
2221
|
y: this.node.props.y,
|
|
2338
2222
|
width,
|
|
2339
|
-
height
|
|
2223
|
+
height,
|
|
2224
|
+
listening: false
|
|
2340
2225
|
});
|
|
2341
2226
|
const rect = new Konva.Rect({
|
|
2342
2227
|
name: "rect",
|
|
@@ -2348,7 +2233,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2348
2233
|
strokeWidth: 2,
|
|
2349
2234
|
dash: [5, 5],
|
|
2350
2235
|
fill: "transparent",
|
|
2351
|
-
cornerRadius: RECT
|
|
2236
|
+
cornerRadius: RECT.CORNER_RADIUS
|
|
2352
2237
|
});
|
|
2353
2238
|
const markerGroup = new Konva.Group({
|
|
2354
2239
|
name: "marker-group",
|
|
@@ -2410,12 +2295,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2410
2295
|
group.x(this.node.props.x);
|
|
2411
2296
|
group.y(this.node.props.y);
|
|
2412
2297
|
const width = Math.max(
|
|
2413
|
-
this.node.props.width ?? RECT
|
|
2414
|
-
RECT
|
|
2298
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
2299
|
+
RECT.MIN_SIZE
|
|
2415
2300
|
);
|
|
2416
2301
|
const height = Math.max(
|
|
2417
|
-
this.node.props.height ?? RECT
|
|
2418
|
-
RECT
|
|
2302
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
2303
|
+
RECT.MIN_SIZE
|
|
2419
2304
|
);
|
|
2420
2305
|
group.width(width);
|
|
2421
2306
|
group.height(height);
|
|
@@ -2434,7 +2319,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2434
2319
|
* 销毁
|
|
2435
2320
|
*/
|
|
2436
2321
|
destroy() {
|
|
2437
|
-
|
|
2322
|
+
this.element.destroy();
|
|
2438
2323
|
}
|
|
2439
2324
|
/**
|
|
2440
2325
|
* 更新焦点状态(hover 或 selected)
|
|
@@ -2483,6 +2368,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2483
2368
|
return null;
|
|
2484
2369
|
}
|
|
2485
2370
|
}
|
|
2371
|
+
function clamp(value, range) {
|
|
2372
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
2373
|
+
}
|
|
2486
2374
|
const createNodeByType = (type, position, style, meta) => {
|
|
2487
2375
|
const baseNode = {
|
|
2488
2376
|
type,
|
|
@@ -2501,7 +2389,10 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2501
2389
|
rotation: 0,
|
|
2502
2390
|
visible: true
|
|
2503
2391
|
},
|
|
2504
|
-
meta:
|
|
2392
|
+
meta: {
|
|
2393
|
+
...meta,
|
|
2394
|
+
startPoint: position
|
|
2395
|
+
}
|
|
2505
2396
|
};
|
|
2506
2397
|
if (type === "image-marker") {
|
|
2507
2398
|
return {
|
|
@@ -2515,27 +2406,34 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2515
2406
|
}
|
|
2516
2407
|
return baseNode;
|
|
2517
2408
|
};
|
|
2518
|
-
function updateNodeByType(node, position
|
|
2409
|
+
function updateNodeByType(node, position) {
|
|
2519
2410
|
let finalPosition = position;
|
|
2520
|
-
if (node.type === "image-marker" && bounds) {
|
|
2411
|
+
if (node.type === "image-marker" && node.meta.bounds) {
|
|
2412
|
+
const bounds = node.meta.bounds;
|
|
2521
2413
|
finalPosition = {
|
|
2522
|
-
x:
|
|
2523
|
-
y:
|
|
2414
|
+
x: clamp(position.x, [bounds.x, bounds.x + bounds.width]),
|
|
2415
|
+
y: clamp(position.y, [bounds.y, bounds.y + bounds.height])
|
|
2524
2416
|
};
|
|
2525
2417
|
}
|
|
2526
|
-
const [p1, p2] = normalizePoints(
|
|
2527
|
-
{ x: node.props.x, y: node.props.y },
|
|
2528
|
-
finalPosition
|
|
2529
|
-
);
|
|
2530
2418
|
if (node.type === "rectangle" || node.type === "image-marker") {
|
|
2419
|
+
const startPoint = node.meta.startPoint ?? {
|
|
2420
|
+
x: node.props.x,
|
|
2421
|
+
y: node.props.y
|
|
2422
|
+
};
|
|
2423
|
+
const [p1, p2] = normalizePoints(startPoint, finalPosition);
|
|
2531
2424
|
return {
|
|
2532
2425
|
...node,
|
|
2533
2426
|
props: {
|
|
2534
2427
|
...node.props,
|
|
2535
2428
|
x: p1.x,
|
|
2536
2429
|
y: p1.y,
|
|
2537
|
-
width: Math.max(p2.x - p1.x, RECT
|
|
2538
|
-
height: Math.max(p2.y - p1.y, RECT
|
|
2430
|
+
width: Math.max(p2.x - p1.x, RECT.MIN_SIZE),
|
|
2431
|
+
height: Math.max(p2.y - p1.y, RECT.MIN_SIZE)
|
|
2432
|
+
},
|
|
2433
|
+
meta: {
|
|
2434
|
+
...node.meta,
|
|
2435
|
+
// 保存初始起点,以便后续更新使用
|
|
2436
|
+
startPoint
|
|
2539
2437
|
}
|
|
2540
2438
|
};
|
|
2541
2439
|
}
|
|
@@ -2707,6 +2605,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2707
2605
|
},
|
|
2708
2606
|
true
|
|
2709
2607
|
);
|
|
2608
|
+
this.emit("nodes:created", nodes);
|
|
2710
2609
|
}
|
|
2711
2610
|
/**
|
|
2712
2611
|
* 创建图片标注节点(内部使用)
|
|
@@ -2796,17 +2695,16 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2796
2695
|
}
|
|
2797
2696
|
const node = createNodeByType(type, position, void 0, meta);
|
|
2798
2697
|
__privateSet(this, _draftNode, createCanvasNodeByType(this, type, node));
|
|
2799
|
-
console.log(__privateGet(this, _draftNode));
|
|
2800
2698
|
if (!__privateGet(this, _draftNode)) return;
|
|
2801
2699
|
__privateGet(this, _mainLayer).add(__privateGet(this, _draftNode).getElement());
|
|
2802
2700
|
}
|
|
2803
2701
|
/**
|
|
2804
2702
|
* @internal 仅供内部使用
|
|
2805
2703
|
*/
|
|
2806
|
-
updateDraftNode(position
|
|
2704
|
+
updateDraftNode(position) {
|
|
2807
2705
|
if (!__privateGet(this, _draftNode)) return;
|
|
2808
2706
|
const node = __privateGet(this, _draftNode).getNode();
|
|
2809
|
-
const updatedNode = updateNodeByType(node, position
|
|
2707
|
+
const updatedNode = updateNodeByType(node, position);
|
|
2810
2708
|
__privateGet(this, _draftNode).updateNode(updatedNode);
|
|
2811
2709
|
}
|
|
2812
2710
|
/**
|
|
@@ -3126,6 +3024,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3126
3024
|
},
|
|
3127
3025
|
true
|
|
3128
3026
|
);
|
|
3027
|
+
this.emit("nodes:deleted", Array.from(idsToDelete));
|
|
3129
3028
|
}
|
|
3130
3029
|
/**
|
|
3131
3030
|
* 滚动到内容区域
|
|
@@ -3203,11 +3102,11 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3203
3102
|
this.updateViewport({ x, y, scale: newScale }, true);
|
|
3204
3103
|
}
|
|
3205
3104
|
}
|
|
3206
|
-
function modulate(value, rangeA, rangeB,
|
|
3105
|
+
function modulate(value, rangeA, rangeB, clamp2 = false) {
|
|
3207
3106
|
const [fromLow, fromHigh] = rangeA;
|
|
3208
3107
|
const [v0, v1] = rangeB;
|
|
3209
3108
|
const result = v0 + (value - fromLow) / (fromHigh - fromLow) * (v1 - v0);
|
|
3210
|
-
return
|
|
3109
|
+
return clamp2 ? v0 < v1 ? Math.max(Math.min(result, v1), v0) : Math.max(Math.min(result, v0), v1) : result;
|
|
3211
3110
|
}
|
|
3212
3111
|
const gridSteps = [
|
|
3213
3112
|
{
|
|
@@ -3449,9 +3348,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3449
3348
|
core.on("viewport:change", (newViewport) => {
|
|
3450
3349
|
setViewport(newViewport);
|
|
3451
3350
|
});
|
|
3452
|
-
core.on("transformer:positionChange", (position) => {
|
|
3453
|
-
console.log("Transformer position changed:", position);
|
|
3454
|
-
});
|
|
3455
3351
|
return () => {
|
|
3456
3352
|
core.dispose();
|
|
3457
3353
|
};
|