@8btc/whiteboard 0.0.8 → 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 +31 -136
- package/dist/index.umd.js +31 -144
- 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";
|
|
@@ -510,66 +510,13 @@ class CanvasState {
|
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
const NODE_NAME_FOR_SELECT = "shapeNameForSelect";
|
|
513
|
-
const RECT
|
|
513
|
+
const RECT = {
|
|
514
514
|
CORNER_RADIUS: 6,
|
|
515
515
|
MIN_SIZE: 10
|
|
516
516
|
};
|
|
517
517
|
const IMAGE = {
|
|
518
518
|
MIN_SIZE: 10
|
|
519
519
|
};
|
|
520
|
-
const RECT = {
|
|
521
|
-
MIN_SIZE: 10
|
|
522
|
-
};
|
|
523
|
-
function clamp(value, range) {
|
|
524
|
-
return Math.min(Math.max(value, range[0]), range[1]);
|
|
525
|
-
}
|
|
526
|
-
function calculatePerimeter(width, height, cornerRadius) {
|
|
527
|
-
return 2 * (height + width - cornerRadius * (4 - Math.PI));
|
|
528
|
-
}
|
|
529
|
-
function getDashValue(shapeLength, strokeWidth, lineStyle) {
|
|
530
|
-
let ratio = 1;
|
|
531
|
-
let dashLength = 0;
|
|
532
|
-
let dashGap = 0;
|
|
533
|
-
switch (lineStyle) {
|
|
534
|
-
case "dashed":
|
|
535
|
-
dashLength = Math.min(strokeWidth * 2, shapeLength / 4);
|
|
536
|
-
break;
|
|
537
|
-
case "dotted":
|
|
538
|
-
ratio = 8;
|
|
539
|
-
dashLength = strokeWidth / ratio;
|
|
540
|
-
break;
|
|
541
|
-
default:
|
|
542
|
-
return [];
|
|
543
|
-
}
|
|
544
|
-
let dashCount = Math.floor(shapeLength / dashLength / (2 * ratio));
|
|
545
|
-
dashCount = Math.max(dashCount, 3);
|
|
546
|
-
dashLength = shapeLength / dashCount / (2 * ratio);
|
|
547
|
-
dashGap = (shapeLength - dashCount * dashLength) / dashCount;
|
|
548
|
-
return [dashLength, dashGap];
|
|
549
|
-
}
|
|
550
|
-
function getSizeValue(key) {
|
|
551
|
-
switch (key) {
|
|
552
|
-
case "small":
|
|
553
|
-
return 2;
|
|
554
|
-
case "medium":
|
|
555
|
-
return 3;
|
|
556
|
-
case "large":
|
|
557
|
-
return 5;
|
|
558
|
-
case "extra-large":
|
|
559
|
-
return 8;
|
|
560
|
-
default:
|
|
561
|
-
return 3;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
function getTotalDashLength(dash) {
|
|
565
|
-
return Array.isArray(dash) && dash.length > 1 ? dash[0] + dash[1] : 0;
|
|
566
|
-
}
|
|
567
|
-
function getRectSize(rect) {
|
|
568
|
-
return {
|
|
569
|
-
width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
|
|
570
|
-
height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
520
|
class BaseCanvasNode {
|
|
574
521
|
constructor(core, node) {
|
|
575
522
|
__publicField(this, "core");
|
|
@@ -592,43 +539,30 @@ class BaseCanvasNode {
|
|
|
592
539
|
return this.node;
|
|
593
540
|
}
|
|
594
541
|
}
|
|
595
|
-
function
|
|
596
|
-
if (!totalDashLength || totalDashLength === 0) {
|
|
597
|
-
return null;
|
|
598
|
-
}
|
|
599
|
-
const anim = new Konva.Animation((frame) => {
|
|
600
|
-
if (!frame) return;
|
|
601
|
-
const dashOffset = -frame.time / 10 % totalDashLength;
|
|
602
|
-
rect.dashOffset(dashOffset);
|
|
603
|
-
}, rect.getLayer());
|
|
542
|
+
function getRectSize(rect) {
|
|
604
543
|
return {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
isRunning: () => anim.isRunning()
|
|
544
|
+
width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
|
|
545
|
+
height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
|
|
608
546
|
};
|
|
609
547
|
}
|
|
610
548
|
class RectNode extends BaseCanvasNode {
|
|
611
549
|
constructor(core, node) {
|
|
612
550
|
super(core, node);
|
|
613
551
|
__privateAdd(this, _RectNode_instances);
|
|
614
|
-
__privateAdd(this, _animation, null);
|
|
615
552
|
__privateAdd(this, _toolTypeChangeHandler, (toolType) => {
|
|
616
553
|
const isSelect = toolType === "select";
|
|
617
554
|
this.element.listening(isSelect);
|
|
618
555
|
});
|
|
619
|
-
if (node.style.animated) {
|
|
620
|
-
__privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
|
|
621
|
-
}
|
|
622
556
|
__privateMethod(this, _RectNode_instances, setupEventHandlers_fn).call(this, this.getElement());
|
|
623
557
|
}
|
|
624
558
|
createElement() {
|
|
625
559
|
const width = Math.max(
|
|
626
|
-
this.node.props.width ?? RECT
|
|
627
|
-
RECT
|
|
560
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
561
|
+
RECT.MIN_SIZE
|
|
628
562
|
);
|
|
629
563
|
const height = Math.max(
|
|
630
|
-
this.node.props.height ?? RECT
|
|
631
|
-
RECT
|
|
564
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
565
|
+
RECT.MIN_SIZE
|
|
632
566
|
);
|
|
633
567
|
const config = {
|
|
634
568
|
id: this.node.id,
|
|
@@ -636,7 +570,7 @@ class RectNode extends BaseCanvasNode {
|
|
|
636
570
|
...this.node.style,
|
|
637
571
|
width,
|
|
638
572
|
height,
|
|
639
|
-
cornerRadius: RECT
|
|
573
|
+
cornerRadius: RECT.CORNER_RADIUS,
|
|
640
574
|
name: NODE_NAME_FOR_SELECT,
|
|
641
575
|
draggable: true,
|
|
642
576
|
stroke: "black",
|
|
@@ -675,79 +609,38 @@ class RectNode extends BaseCanvasNode {
|
|
|
675
609
|
rect.x(this.node.props.x);
|
|
676
610
|
rect.y(this.node.props.y);
|
|
677
611
|
const width = Math.max(
|
|
678
|
-
this.node.props.width ?? RECT
|
|
679
|
-
RECT
|
|
612
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
613
|
+
RECT.MIN_SIZE
|
|
680
614
|
);
|
|
681
615
|
const height = Math.max(
|
|
682
|
-
this.node.props.height ?? RECT
|
|
683
|
-
RECT
|
|
616
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
617
|
+
RECT.MIN_SIZE
|
|
684
618
|
);
|
|
685
619
|
rect.width(width);
|
|
686
620
|
rect.height(height);
|
|
687
|
-
if (this.node.style.animated && !__privateGet(this, _animation)) {
|
|
688
|
-
__privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
|
|
689
|
-
} else if (!this.node.style.animated && __privateGet(this, _animation)) {
|
|
690
|
-
__privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
|
|
691
|
-
}
|
|
692
621
|
}
|
|
693
622
|
/**
|
|
694
623
|
* 销毁
|
|
695
624
|
*/
|
|
696
625
|
destroy() {
|
|
697
626
|
this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
698
|
-
__privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
|
|
699
627
|
this.element.destroy();
|
|
700
628
|
}
|
|
701
629
|
}
|
|
702
|
-
_animation = new WeakMap();
|
|
703
|
-
_RectNode_instances = new WeakSet();
|
|
704
|
-
/**
|
|
705
|
-
* 初始化动画
|
|
706
|
-
*/
|
|
707
|
-
initAnimation_fn = function() {
|
|
708
|
-
const rect = this.getElement();
|
|
709
|
-
const dash = rect.dash();
|
|
710
|
-
if (!dash || dash.length === 0) return;
|
|
711
|
-
const totalDashLength = getTotalDashLength(dash);
|
|
712
|
-
__privateSet(this, _animation, createRectAnimation(rect, totalDashLength));
|
|
713
|
-
if (__privateGet(this, _animation)) {
|
|
714
|
-
__privateGet(this, _animation).start();
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
/**
|
|
718
|
-
* 销毁动画
|
|
719
|
-
*/
|
|
720
|
-
destroyAnimation_fn = function() {
|
|
721
|
-
if (__privateGet(this, _animation)) {
|
|
722
|
-
__privateGet(this, _animation).stop();
|
|
723
|
-
__privateSet(this, _animation, null);
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
630
|
_toolTypeChangeHandler = new WeakMap();
|
|
631
|
+
_RectNode_instances = new WeakSet();
|
|
727
632
|
/**
|
|
728
633
|
* 设置事件处理器
|
|
729
634
|
*/
|
|
730
635
|
setupEventHandlers_fn = function(rect) {
|
|
731
636
|
const element = rect;
|
|
732
637
|
this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
733
|
-
element.on("transformstart", () => {
|
|
734
|
-
if (this.node.style.animated && __privateGet(this, _animation)) {
|
|
735
|
-
__privateGet(this, _animation).stop();
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
638
|
element.on("transform", (event) => {
|
|
739
639
|
const rect2 = event.target;
|
|
740
640
|
const { width, height } = getRectSize(rect2);
|
|
741
|
-
const totalLength = calculatePerimeter(width, height, RECT$1.CORNER_RADIUS);
|
|
742
|
-
const dash = getDashValue(
|
|
743
|
-
totalLength,
|
|
744
|
-
getSizeValue(this.node.style.size),
|
|
745
|
-
this.node.style.line
|
|
746
|
-
);
|
|
747
641
|
rect2.scale({ x: 1, y: 1 });
|
|
748
642
|
rect2.width(width);
|
|
749
643
|
rect2.height(height);
|
|
750
|
-
rect2.dash(dash.map((d) => d * this.core.getStageScale()));
|
|
751
644
|
});
|
|
752
645
|
element.on("transformend", (event) => {
|
|
753
646
|
const rect2 = event.target;
|
|
@@ -764,9 +657,6 @@ setupEventHandlers_fn = function(rect) {
|
|
|
764
657
|
this.core._syncNodeFromElement(this.node.id, {
|
|
765
658
|
props: newProps
|
|
766
659
|
});
|
|
767
|
-
if (this.node.style.animated && __privateGet(this, _animation)?.isRunning() === false) {
|
|
768
|
-
__privateGet(this, _animation).start();
|
|
769
|
-
}
|
|
770
660
|
});
|
|
771
661
|
element.on("dragend", (event) => {
|
|
772
662
|
const rect2 = event.target;
|
|
@@ -1006,12 +896,12 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1006
896
|
}
|
|
1007
897
|
createElement() {
|
|
1008
898
|
const width = Math.max(
|
|
1009
|
-
this.node.props.width ?? RECT
|
|
1010
|
-
RECT
|
|
899
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
900
|
+
RECT.MIN_SIZE
|
|
1011
901
|
);
|
|
1012
902
|
const height = Math.max(
|
|
1013
|
-
this.node.props.height ?? RECT
|
|
1014
|
-
RECT
|
|
903
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
904
|
+
RECT.MIN_SIZE
|
|
1015
905
|
);
|
|
1016
906
|
const group = new Konva.Group({
|
|
1017
907
|
id: this.node.id,
|
|
@@ -1032,7 +922,7 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1032
922
|
strokeWidth: 2,
|
|
1033
923
|
dash: [5, 5],
|
|
1034
924
|
fill: "transparent",
|
|
1035
|
-
cornerRadius: RECT
|
|
925
|
+
cornerRadius: RECT.CORNER_RADIUS
|
|
1036
926
|
});
|
|
1037
927
|
const markerGroup = new Konva.Group({
|
|
1038
928
|
name: "marker-group",
|
|
@@ -1094,12 +984,12 @@ class ImageMarkerNode extends BaseCanvasNode {
|
|
|
1094
984
|
group.x(this.node.props.x);
|
|
1095
985
|
group.y(this.node.props.y);
|
|
1096
986
|
const width = Math.max(
|
|
1097
|
-
this.node.props.width ?? RECT
|
|
1098
|
-
RECT
|
|
987
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
988
|
+
RECT.MIN_SIZE
|
|
1099
989
|
);
|
|
1100
990
|
const height = Math.max(
|
|
1101
|
-
this.node.props.height ?? RECT
|
|
1102
|
-
RECT
|
|
991
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
992
|
+
RECT.MIN_SIZE
|
|
1103
993
|
);
|
|
1104
994
|
group.width(width);
|
|
1105
995
|
group.height(height);
|
|
@@ -1167,6 +1057,9 @@ function createCanvasNodeByType(core, type, config) {
|
|
|
1167
1057
|
return null;
|
|
1168
1058
|
}
|
|
1169
1059
|
}
|
|
1060
|
+
function clamp(value, range) {
|
|
1061
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1062
|
+
}
|
|
1170
1063
|
const createNodeByType = (type, position, style, meta) => {
|
|
1171
1064
|
const baseNode = {
|
|
1172
1065
|
type,
|
|
@@ -1223,8 +1116,8 @@ function updateNodeByType(node, position) {
|
|
|
1223
1116
|
...node.props,
|
|
1224
1117
|
x: p1.x,
|
|
1225
1118
|
y: p1.y,
|
|
1226
|
-
width: Math.max(p2.x - p1.x, RECT
|
|
1227
|
-
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)
|
|
1228
1121
|
},
|
|
1229
1122
|
meta: {
|
|
1230
1123
|
...node.meta,
|
|
@@ -1401,6 +1294,7 @@ class CanvasCore extends CanvasState {
|
|
|
1401
1294
|
},
|
|
1402
1295
|
true
|
|
1403
1296
|
);
|
|
1297
|
+
this.emit("nodes:created", nodes);
|
|
1404
1298
|
}
|
|
1405
1299
|
/**
|
|
1406
1300
|
* 创建图片标注节点(内部使用)
|
|
@@ -1819,6 +1713,7 @@ class CanvasApi extends CanvasCore {
|
|
|
1819
1713
|
},
|
|
1820
1714
|
true
|
|
1821
1715
|
);
|
|
1716
|
+
this.emit("nodes:deleted", Array.from(idsToDelete));
|
|
1822
1717
|
}
|
|
1823
1718
|
/**
|
|
1824
1719
|
* 滚动到内容区域
|
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
|
}
|
|
@@ -1829,66 +1821,13 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1829
1821
|
}
|
|
1830
1822
|
}
|
|
1831
1823
|
const NODE_NAME_FOR_SELECT = "shapeNameForSelect";
|
|
1832
|
-
const RECT
|
|
1824
|
+
const RECT = {
|
|
1833
1825
|
CORNER_RADIUS: 6,
|
|
1834
1826
|
MIN_SIZE: 10
|
|
1835
1827
|
};
|
|
1836
1828
|
const IMAGE = {
|
|
1837
1829
|
MIN_SIZE: 10
|
|
1838
1830
|
};
|
|
1839
|
-
const RECT = {
|
|
1840
|
-
MIN_SIZE: 10
|
|
1841
|
-
};
|
|
1842
|
-
function clamp(value, range) {
|
|
1843
|
-
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1844
|
-
}
|
|
1845
|
-
function calculatePerimeter(width, height, cornerRadius) {
|
|
1846
|
-
return 2 * (height + width - cornerRadius * (4 - Math.PI));
|
|
1847
|
-
}
|
|
1848
|
-
function getDashValue(shapeLength, strokeWidth, lineStyle) {
|
|
1849
|
-
let ratio = 1;
|
|
1850
|
-
let dashLength = 0;
|
|
1851
|
-
let dashGap = 0;
|
|
1852
|
-
switch (lineStyle) {
|
|
1853
|
-
case "dashed":
|
|
1854
|
-
dashLength = Math.min(strokeWidth * 2, shapeLength / 4);
|
|
1855
|
-
break;
|
|
1856
|
-
case "dotted":
|
|
1857
|
-
ratio = 8;
|
|
1858
|
-
dashLength = strokeWidth / ratio;
|
|
1859
|
-
break;
|
|
1860
|
-
default:
|
|
1861
|
-
return [];
|
|
1862
|
-
}
|
|
1863
|
-
let dashCount = Math.floor(shapeLength / dashLength / (2 * ratio));
|
|
1864
|
-
dashCount = Math.max(dashCount, 3);
|
|
1865
|
-
dashLength = shapeLength / dashCount / (2 * ratio);
|
|
1866
|
-
dashGap = (shapeLength - dashCount * dashLength) / dashCount;
|
|
1867
|
-
return [dashLength, dashGap];
|
|
1868
|
-
}
|
|
1869
|
-
function getSizeValue(key) {
|
|
1870
|
-
switch (key) {
|
|
1871
|
-
case "small":
|
|
1872
|
-
return 2;
|
|
1873
|
-
case "medium":
|
|
1874
|
-
return 3;
|
|
1875
|
-
case "large":
|
|
1876
|
-
return 5;
|
|
1877
|
-
case "extra-large":
|
|
1878
|
-
return 8;
|
|
1879
|
-
default:
|
|
1880
|
-
return 3;
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
function getTotalDashLength(dash) {
|
|
1884
|
-
return Array.isArray(dash) && dash.length > 1 ? dash[0] + dash[1] : 0;
|
|
1885
|
-
}
|
|
1886
|
-
function getRectSize(rect) {
|
|
1887
|
-
return {
|
|
1888
|
-
width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
|
|
1889
|
-
height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
|
|
1890
|
-
};
|
|
1891
|
-
}
|
|
1892
1831
|
class BaseCanvasNode {
|
|
1893
1832
|
constructor(core, node) {
|
|
1894
1833
|
__publicField(this, "core");
|
|
@@ -1911,43 +1850,30 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1911
1850
|
return this.node;
|
|
1912
1851
|
}
|
|
1913
1852
|
}
|
|
1914
|
-
function
|
|
1915
|
-
if (!totalDashLength || totalDashLength === 0) {
|
|
1916
|
-
return null;
|
|
1917
|
-
}
|
|
1918
|
-
const anim = new Konva.Animation((frame) => {
|
|
1919
|
-
if (!frame) return;
|
|
1920
|
-
const dashOffset = -frame.time / 10 % totalDashLength;
|
|
1921
|
-
rect.dashOffset(dashOffset);
|
|
1922
|
-
}, rect.getLayer());
|
|
1853
|
+
function getRectSize(rect) {
|
|
1923
1854
|
return {
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
isRunning: () => anim.isRunning()
|
|
1855
|
+
width: Math.max(RECT.MIN_SIZE, rect.width() * rect.scaleX()),
|
|
1856
|
+
height: Math.max(RECT.MIN_SIZE, rect.height() * rect.scaleY())
|
|
1927
1857
|
};
|
|
1928
1858
|
}
|
|
1929
1859
|
class RectNode extends BaseCanvasNode {
|
|
1930
1860
|
constructor(core, node) {
|
|
1931
1861
|
super(core, node);
|
|
1932
1862
|
__privateAdd(this, _RectNode_instances);
|
|
1933
|
-
__privateAdd(this, _animation, null);
|
|
1934
1863
|
__privateAdd(this, _toolTypeChangeHandler, (toolType) => {
|
|
1935
1864
|
const isSelect = toolType === "select";
|
|
1936
1865
|
this.element.listening(isSelect);
|
|
1937
1866
|
});
|
|
1938
|
-
if (node.style.animated) {
|
|
1939
|
-
__privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
|
|
1940
|
-
}
|
|
1941
1867
|
__privateMethod(this, _RectNode_instances, setupEventHandlers_fn).call(this, this.getElement());
|
|
1942
1868
|
}
|
|
1943
1869
|
createElement() {
|
|
1944
1870
|
const width = Math.max(
|
|
1945
|
-
this.node.props.width ?? RECT
|
|
1946
|
-
RECT
|
|
1871
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
1872
|
+
RECT.MIN_SIZE
|
|
1947
1873
|
);
|
|
1948
1874
|
const height = Math.max(
|
|
1949
|
-
this.node.props.height ?? RECT
|
|
1950
|
-
RECT
|
|
1875
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
1876
|
+
RECT.MIN_SIZE
|
|
1951
1877
|
);
|
|
1952
1878
|
const config = {
|
|
1953
1879
|
id: this.node.id,
|
|
@@ -1955,7 +1881,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1955
1881
|
...this.node.style,
|
|
1956
1882
|
width,
|
|
1957
1883
|
height,
|
|
1958
|
-
cornerRadius: RECT
|
|
1884
|
+
cornerRadius: RECT.CORNER_RADIUS,
|
|
1959
1885
|
name: NODE_NAME_FOR_SELECT,
|
|
1960
1886
|
draggable: true,
|
|
1961
1887
|
stroke: "black",
|
|
@@ -1994,79 +1920,38 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1994
1920
|
rect.x(this.node.props.x);
|
|
1995
1921
|
rect.y(this.node.props.y);
|
|
1996
1922
|
const width = Math.max(
|
|
1997
|
-
this.node.props.width ?? RECT
|
|
1998
|
-
RECT
|
|
1923
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
1924
|
+
RECT.MIN_SIZE
|
|
1999
1925
|
);
|
|
2000
1926
|
const height = Math.max(
|
|
2001
|
-
this.node.props.height ?? RECT
|
|
2002
|
-
RECT
|
|
1927
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
1928
|
+
RECT.MIN_SIZE
|
|
2003
1929
|
);
|
|
2004
1930
|
rect.width(width);
|
|
2005
1931
|
rect.height(height);
|
|
2006
|
-
if (this.node.style.animated && !__privateGet(this, _animation)) {
|
|
2007
|
-
__privateMethod(this, _RectNode_instances, initAnimation_fn).call(this);
|
|
2008
|
-
} else if (!this.node.style.animated && __privateGet(this, _animation)) {
|
|
2009
|
-
__privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
|
|
2010
|
-
}
|
|
2011
1932
|
}
|
|
2012
1933
|
/**
|
|
2013
1934
|
* 销毁
|
|
2014
1935
|
*/
|
|
2015
1936
|
destroy() {
|
|
2016
1937
|
this.core.off("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
2017
|
-
__privateMethod(this, _RectNode_instances, destroyAnimation_fn).call(this);
|
|
2018
1938
|
this.element.destroy();
|
|
2019
1939
|
}
|
|
2020
1940
|
}
|
|
2021
|
-
_animation = new WeakMap();
|
|
2022
|
-
_RectNode_instances = new WeakSet();
|
|
2023
|
-
/**
|
|
2024
|
-
* 初始化动画
|
|
2025
|
-
*/
|
|
2026
|
-
initAnimation_fn = function() {
|
|
2027
|
-
const rect = this.getElement();
|
|
2028
|
-
const dash = rect.dash();
|
|
2029
|
-
if (!dash || dash.length === 0) return;
|
|
2030
|
-
const totalDashLength = getTotalDashLength(dash);
|
|
2031
|
-
__privateSet(this, _animation, createRectAnimation(rect, totalDashLength));
|
|
2032
|
-
if (__privateGet(this, _animation)) {
|
|
2033
|
-
__privateGet(this, _animation).start();
|
|
2034
|
-
}
|
|
2035
|
-
};
|
|
2036
|
-
/**
|
|
2037
|
-
* 销毁动画
|
|
2038
|
-
*/
|
|
2039
|
-
destroyAnimation_fn = function() {
|
|
2040
|
-
if (__privateGet(this, _animation)) {
|
|
2041
|
-
__privateGet(this, _animation).stop();
|
|
2042
|
-
__privateSet(this, _animation, null);
|
|
2043
|
-
}
|
|
2044
|
-
};
|
|
2045
1941
|
_toolTypeChangeHandler = new WeakMap();
|
|
1942
|
+
_RectNode_instances = new WeakSet();
|
|
2046
1943
|
/**
|
|
2047
1944
|
* 设置事件处理器
|
|
2048
1945
|
*/
|
|
2049
1946
|
setupEventHandlers_fn = function(rect) {
|
|
2050
1947
|
const element = rect;
|
|
2051
1948
|
this.core.on("toolType:change", __privateGet(this, _toolTypeChangeHandler));
|
|
2052
|
-
element.on("transformstart", () => {
|
|
2053
|
-
if (this.node.style.animated && __privateGet(this, _animation)) {
|
|
2054
|
-
__privateGet(this, _animation).stop();
|
|
2055
|
-
}
|
|
2056
|
-
});
|
|
2057
1949
|
element.on("transform", (event) => {
|
|
2058
1950
|
const rect2 = event.target;
|
|
2059
1951
|
const { width, height } = getRectSize(rect2);
|
|
2060
|
-
const totalLength = calculatePerimeter(width, height, RECT$1.CORNER_RADIUS);
|
|
2061
|
-
const dash = getDashValue(
|
|
2062
|
-
totalLength,
|
|
2063
|
-
getSizeValue(this.node.style.size),
|
|
2064
|
-
this.node.style.line
|
|
2065
|
-
);
|
|
2066
1952
|
rect2.scale({ x: 1, y: 1 });
|
|
2067
1953
|
rect2.width(width);
|
|
2068
1954
|
rect2.height(height);
|
|
2069
|
-
rect2.dash(dash.map((d) => d * this.core.getStageScale()));
|
|
2070
1955
|
});
|
|
2071
1956
|
element.on("transformend", (event) => {
|
|
2072
1957
|
const rect2 = event.target;
|
|
@@ -2083,9 +1968,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2083
1968
|
this.core._syncNodeFromElement(this.node.id, {
|
|
2084
1969
|
props: newProps
|
|
2085
1970
|
});
|
|
2086
|
-
if (this.node.style.animated && __privateGet(this, _animation)?.isRunning() === false) {
|
|
2087
|
-
__privateGet(this, _animation).start();
|
|
2088
|
-
}
|
|
2089
1971
|
});
|
|
2090
1972
|
element.on("dragend", (event) => {
|
|
2091
1973
|
const rect2 = event.target;
|
|
@@ -2325,12 +2207,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2325
2207
|
}
|
|
2326
2208
|
createElement() {
|
|
2327
2209
|
const width = Math.max(
|
|
2328
|
-
this.node.props.width ?? RECT
|
|
2329
|
-
RECT
|
|
2210
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
2211
|
+
RECT.MIN_SIZE
|
|
2330
2212
|
);
|
|
2331
2213
|
const height = Math.max(
|
|
2332
|
-
this.node.props.height ?? RECT
|
|
2333
|
-
RECT
|
|
2214
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
2215
|
+
RECT.MIN_SIZE
|
|
2334
2216
|
);
|
|
2335
2217
|
const group = new Konva.Group({
|
|
2336
2218
|
id: this.node.id,
|
|
@@ -2351,7 +2233,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2351
2233
|
strokeWidth: 2,
|
|
2352
2234
|
dash: [5, 5],
|
|
2353
2235
|
fill: "transparent",
|
|
2354
|
-
cornerRadius: RECT
|
|
2236
|
+
cornerRadius: RECT.CORNER_RADIUS
|
|
2355
2237
|
});
|
|
2356
2238
|
const markerGroup = new Konva.Group({
|
|
2357
2239
|
name: "marker-group",
|
|
@@ -2413,12 +2295,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2413
2295
|
group.x(this.node.props.x);
|
|
2414
2296
|
group.y(this.node.props.y);
|
|
2415
2297
|
const width = Math.max(
|
|
2416
|
-
this.node.props.width ?? RECT
|
|
2417
|
-
RECT
|
|
2298
|
+
this.node.props.width ?? RECT.MIN_SIZE,
|
|
2299
|
+
RECT.MIN_SIZE
|
|
2418
2300
|
);
|
|
2419
2301
|
const height = Math.max(
|
|
2420
|
-
this.node.props.height ?? RECT
|
|
2421
|
-
RECT
|
|
2302
|
+
this.node.props.height ?? RECT.MIN_SIZE,
|
|
2303
|
+
RECT.MIN_SIZE
|
|
2422
2304
|
);
|
|
2423
2305
|
group.width(width);
|
|
2424
2306
|
group.height(height);
|
|
@@ -2486,6 +2368,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2486
2368
|
return null;
|
|
2487
2369
|
}
|
|
2488
2370
|
}
|
|
2371
|
+
function clamp(value, range) {
|
|
2372
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
2373
|
+
}
|
|
2489
2374
|
const createNodeByType = (type, position, style, meta) => {
|
|
2490
2375
|
const baseNode = {
|
|
2491
2376
|
type,
|
|
@@ -2542,8 +2427,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2542
2427
|
...node.props,
|
|
2543
2428
|
x: p1.x,
|
|
2544
2429
|
y: p1.y,
|
|
2545
|
-
width: Math.max(p2.x - p1.x, RECT
|
|
2546
|
-
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)
|
|
2547
2432
|
},
|
|
2548
2433
|
meta: {
|
|
2549
2434
|
...node.meta,
|
|
@@ -2720,6 +2605,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
2720
2605
|
},
|
|
2721
2606
|
true
|
|
2722
2607
|
);
|
|
2608
|
+
this.emit("nodes:created", nodes);
|
|
2723
2609
|
}
|
|
2724
2610
|
/**
|
|
2725
2611
|
* 创建图片标注节点(内部使用)
|
|
@@ -3138,6 +3024,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
3138
3024
|
},
|
|
3139
3025
|
true
|
|
3140
3026
|
);
|
|
3027
|
+
this.emit("nodes:deleted", Array.from(idsToDelete));
|
|
3141
3028
|
}
|
|
3142
3029
|
/**
|
|
3143
3030
|
* 滚动到内容区域
|