@labelbee/lb-annotation 1.14.0-alpha.3 → 1.14.0-alpha.5
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/_virtual/MathUtilsWorker.js +1 -8
- package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -35
- package/dist/_virtual/filterBoxWorker.js +1 -8
- package/dist/_virtual/highlightWorker.js +1 -8
- package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -5
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -5
- package/dist/assets/attributeIcon/icon_editFEN.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editHUANG.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editLAN.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editLV.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editQING.svg.js +1 -5
- package/dist/constant/annotation.js +1 -127
- package/dist/constant/annotationTask.js +1 -30
- package/dist/constant/defaultConfig.js +1 -266
- package/dist/constant/keyCode.js +1 -38
- package/dist/constant/style.js +1 -98
- package/dist/constant/tool.js +1 -236
- package/dist/core/index.js +1 -150
- package/dist/core/pointCloud/OrbitControls.js +1 -665
- package/dist/core/pointCloud/PCDLoader.js +2 -260
- package/dist/core/pointCloud/annotation.js +1 -215
- package/dist/core/pointCloud/cache.js +1 -53
- package/dist/core/pointCloud/index.js +5 -991
- package/dist/core/pointCloud/matrix.js +1 -138
- package/dist/core/scheduler.js +1 -233
- package/dist/core/toolOperation/LineToolOperation.js +1 -1434
- package/dist/core/toolOperation/ScribbleTool.js +1 -292
- package/dist/core/toolOperation/TextToolOperation.js +1 -131
- package/dist/core/toolOperation/ViewOperation.js +1 -556
- package/dist/core/toolOperation/basicToolOperation.js +1 -881
- package/dist/core/toolOperation/checkOperation.js +1 -208
- package/dist/core/toolOperation/cuboidOperation.js +1 -754
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +7 -152
- package/dist/core/toolOperation/eventListener.js +1 -37
- package/dist/core/toolOperation/measureOperation.js +1 -41
- package/dist/core/toolOperation/pointCloud2dOperation.js +1 -365
- package/dist/core/toolOperation/pointOperation.js +1 -696
- package/dist/core/toolOperation/polygonOperation.js +1 -1251
- package/dist/core/toolOperation/rectOperation.js +1 -1233
- package/dist/core/toolOperation/segmentByRect.js +1 -174
- package/dist/core/toolOperation/tagOperation.js +3 -201
- package/dist/core/toolOperation/textAttributeClass.js +16 -182
- package/dist/index.js +1 -185
- package/dist/locales/constants.js +1 -24
- package/dist/locales/en_US/message.js +1 -25
- package/dist/locales/index.js +1 -19
- package/dist/locales/zh_CN/message.js +1 -25
- package/dist/newCore/CanvasScheduler.js +1 -35
- package/dist/utils/ActionsHistory.js +1 -84
- package/dist/utils/ImgUtils.js +1 -23
- package/dist/utils/MathUtils.js +2 -385
- package/dist/utils/VectorUtils.js +1 -25
- package/dist/utils/tool/AttributeUtils.js +1 -218
- package/dist/utils/tool/AxisUtils.js +1 -340
- package/dist/utils/tool/CanvasUtils.js +1 -62
- package/dist/utils/tool/CommonToolUtils.js +1 -174
- package/dist/utils/tool/CuboidUtils.js +1 -704
- package/dist/utils/tool/DblClickEventListener.js +1 -102
- package/dist/utils/tool/DrawUtils.js +3 -492
- package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -53
- package/dist/utils/tool/ImgPosUtils.js +1 -58
- package/dist/utils/tool/LineToolUtils.js +1 -261
- package/dist/utils/tool/MarkerUtils.js +1 -56
- package/dist/utils/tool/PolygonUtils.js +1 -460
- package/dist/utils/tool/RectUtils.js +1 -155
- package/dist/utils/tool/RenderDomClass.js +7 -57
- package/dist/utils/tool/RenderDomUtils.js +4 -21
- package/dist/utils/tool/StyleUtils.js +1 -31
- package/dist/utils/tool/TagUtils.js +1 -129
- package/dist/utils/tool/UnitUtils.js +1 -12
- package/dist/utils/tool/ZoomUtils.js +1 -72
- package/dist/utils/tool/polygonTool.js +1 -133
- package/dist/utils/uuid.js +1 -26
- package/es/_virtual/MathUtilsWorker.js +1 -6
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -31
- package/es/_virtual/filterBoxWorker.js +1 -6
- package/es/_virtual/highlightWorker.js +1 -6
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -3
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
- package/es/assets/attributeIcon/icon_editFEN.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editLAN.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editLV.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editQING.svg.js +1 -3
- package/es/constant/annotation.js +1 -113
- package/es/constant/annotationTask.js +1 -25
- package/es/constant/defaultConfig.js +1 -260
- package/es/constant/keyCode.js +1 -36
- package/es/constant/style.js +1 -74
- package/es/constant/tool.js +1 -220
- package/es/core/index.js +1 -148
- package/es/core/pointCloud/OrbitControls.js +1 -661
- package/es/core/pointCloud/PCDLoader.js +2 -256
- package/es/core/pointCloud/annotation.js +1 -211
- package/es/core/pointCloud/cache.js +1 -49
- package/es/core/pointCloud/index.js +5 -962
- package/es/core/pointCloud/matrix.js +1 -109
- package/es/core/scheduler.js +1 -228
- package/es/core/toolOperation/LineToolOperation.js +1 -1421
- package/es/core/toolOperation/ScribbleTool.js +1 -290
- package/es/core/toolOperation/TextToolOperation.js +1 -129
- package/es/core/toolOperation/ViewOperation.js +1 -549
- package/es/core/toolOperation/basicToolOperation.js +1 -877
- package/es/core/toolOperation/checkOperation.js +1 -206
- package/es/core/toolOperation/cuboidOperation.js +1 -752
- package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
- package/es/core/toolOperation/eventListener.js +1 -35
- package/es/core/toolOperation/measureOperation.js +1 -39
- package/es/core/toolOperation/pointCloud2dOperation.js +1 -359
- package/es/core/toolOperation/pointOperation.js +1 -690
- package/es/core/toolOperation/polygonOperation.js +1 -1245
- package/es/core/toolOperation/rectOperation.js +1 -1228
- package/es/core/toolOperation/segmentByRect.js +1 -172
- package/es/core/toolOperation/tagOperation.js +3 -199
- package/es/core/toolOperation/textAttributeClass.js +16 -180
- package/es/index.js +1 -46
- package/es/locales/constants.js +1 -22
- package/es/locales/en_US/message.js +1 -23
- package/es/locales/index.js +1 -17
- package/es/locales/zh_CN/message.js +1 -23
- package/es/newCore/CanvasScheduler.js +1 -31
- package/es/utils/ActionsHistory.js +1 -78
- package/es/utils/ImgUtils.js +1 -21
- package/es/utils/MathUtils.js +2 -380
- package/es/utils/VectorUtils.js +1 -23
- package/es/utils/tool/AttributeUtils.js +1 -212
- package/es/utils/tool/AxisUtils.js +1 -335
- package/es/utils/tool/CanvasUtils.js +1 -60
- package/es/utils/tool/CommonToolUtils.js +1 -172
- package/es/utils/tool/CuboidUtils.js +1 -680
- package/es/utils/tool/DblClickEventListener.js +1 -100
- package/es/utils/tool/DrawUtils.js +3 -490
- package/es/utils/tool/EnhanceCommonToolUtils.js +1 -48
- package/es/utils/tool/ImgPosUtils.js +1 -56
- package/es/utils/tool/LineToolUtils.js +1 -255
- package/es/utils/tool/MarkerUtils.js +1 -54
- package/es/utils/tool/PolygonUtils.js +1 -458
- package/es/utils/tool/RectUtils.js +1 -153
- package/es/utils/tool/RenderDomClass.js +7 -55
- package/es/utils/tool/RenderDomUtils.js +4 -19
- package/es/utils/tool/StyleUtils.js +1 -29
- package/es/utils/tool/TagUtils.js +1 -127
- package/es/utils/tool/UnitUtils.js +1 -10
- package/es/utils/tool/ZoomUtils.js +1 -70
- package/es/utils/tool/polygonTool.js +1 -126
- package/es/utils/uuid.js +1 -24
- package/package.json +3 -4
- package/LICENSE +0 -203
- package/dist/core/pointCloud/segmentation.js +0 -144
- package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +0 -26
- package/dist/core/pointCloud/selector/Sse3dSelector.js +0 -16
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
- package/es/core/pointCloud/segmentation.js +0 -120
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +0 -24
- package/es/core/pointCloud/selector/Sse3dSelector.js +0 -14
- package/es/core/toolOperation/scribbleTool2.js +0 -249
|
@@ -1,292 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var lbUtils = require('@labelbee/lb-utils');
|
|
4
|
-
var AxisUtils = require('../../utils/tool/AxisUtils.js');
|
|
5
|
-
var DrawUtils = require('../../utils/tool/DrawUtils.js');
|
|
6
|
-
var tool = require('../../constant/tool.js');
|
|
7
|
-
var CommonToolUtils = require('../../utils/tool/CommonToolUtils.js');
|
|
8
|
-
var AttributeUtils = require('../../utils/tool/AttributeUtils.js');
|
|
9
|
-
var basicToolOperation = require('./basicToolOperation.js');
|
|
10
|
-
|
|
11
|
-
const DEFAULT_PEN_SIZE = 20;
|
|
12
|
-
const DEFAULT_COLOR = "white";
|
|
13
|
-
class ScribbleTool extends basicToolOperation.BasicToolOperation {
|
|
14
|
-
constructor(props) {
|
|
15
|
-
super(props);
|
|
16
|
-
this.toolName = tool.EToolName.ScribbleTool;
|
|
17
|
-
this.action = tool.EScribblePattern.Scribble;
|
|
18
|
-
this.getOriginCoordinate = (e) => {
|
|
19
|
-
return AxisUtils["default"].changePointByZoom(this.getCoordinateUnderZoomByRotate(e), 1 / this.zoom);
|
|
20
|
-
};
|
|
21
|
-
this.onMouseDown = (e) => {
|
|
22
|
-
if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
this.initCacheCanvas(this.imgNode);
|
|
26
|
-
this.mouseEvents("onMouseDown").call(this, e);
|
|
27
|
-
};
|
|
28
|
-
this.onMouseMove = (e) => {
|
|
29
|
-
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
this.mouseEvents("onMouseMove").call(this, e);
|
|
33
|
-
};
|
|
34
|
-
this.onMouseUp = (e) => {
|
|
35
|
-
if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
this.mouseEvents("onMouseUp").call(this, e);
|
|
39
|
-
};
|
|
40
|
-
this.mouseEvents = (eventType) => {
|
|
41
|
-
const events = {
|
|
42
|
-
[tool.EScribblePattern.Scribble]: {
|
|
43
|
-
onMouseMove: this.onScribbleMove,
|
|
44
|
-
onMouseUp: this.onScribbleEnd,
|
|
45
|
-
onMouseDown: this.onScribbleStart
|
|
46
|
-
},
|
|
47
|
-
[tool.EScribblePattern.Erase]: {
|
|
48
|
-
onMouseMove: this.onEraseMove,
|
|
49
|
-
onMouseUp: this.onEraseEnd,
|
|
50
|
-
onMouseDown: this.onEraseStart
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
return events[this.action][eventType];
|
|
54
|
-
};
|
|
55
|
-
this.setPattern = (pattern) => {
|
|
56
|
-
this.action = pattern;
|
|
57
|
-
switch (pattern) {
|
|
58
|
-
case tool.EScribblePattern.Erase: {
|
|
59
|
-
this.setCustomCursor(this.cursorErase);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
default: {
|
|
63
|
-
this.setCustomCursor("none");
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var _a;
|
|
69
|
-
this.penSize = DEFAULT_PEN_SIZE;
|
|
70
|
-
if (((_a = this.config.attributeList) == null ? void 0 : _a.length) > 0) {
|
|
71
|
-
const firstAttributeInfo = this.config.attributeList[0];
|
|
72
|
-
this.setDefaultAttribute(firstAttributeInfo.value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
get cursorErase() {
|
|
76
|
-
const svgIcon = `<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>`;
|
|
77
|
-
const iconUrl = `data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(svgIcon)))}`;
|
|
78
|
-
return `url(${iconUrl}) 0 0, auto`;
|
|
79
|
-
}
|
|
80
|
-
get defaultCursor() {
|
|
81
|
-
if (this.action === tool.EScribblePattern.Erase) {
|
|
82
|
-
return this.cursorErase;
|
|
83
|
-
}
|
|
84
|
-
return this.isShowDefaultCursor ? "default" : "none";
|
|
85
|
-
}
|
|
86
|
-
get color() {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
|
|
89
|
-
}
|
|
90
|
-
get penSizeWithZoom() {
|
|
91
|
-
return this.penSize / this.zoom;
|
|
92
|
-
}
|
|
93
|
-
get cacheCanvasToDataUrl() {
|
|
94
|
-
var _a;
|
|
95
|
-
return (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
|
|
96
|
-
}
|
|
97
|
-
setPenSize(size) {
|
|
98
|
-
this.penSize = size;
|
|
99
|
-
}
|
|
100
|
-
initCacheCanvas(imgNode) {
|
|
101
|
-
if (this.cacheCanvas || !imgNode) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const {canvas, ctx} = lbUtils.ImgConversionUtils.createCanvas(imgNode);
|
|
105
|
-
this.cacheCanvas = canvas;
|
|
106
|
-
this.cacheContext = ctx;
|
|
107
|
-
}
|
|
108
|
-
updateCacheCanvasSize(imgNode) {
|
|
109
|
-
if (this.cacheCanvas) {
|
|
110
|
-
this.cacheCanvas.width = imgNode.width;
|
|
111
|
-
this.cacheCanvas.height = imgNode.height;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
updateUrl2CacheContext(url) {
|
|
115
|
-
lbUtils.ImgConversionUtils.createImgDom(url).then((img) => {
|
|
116
|
-
if (!this.cacheContext) {
|
|
117
|
-
this.initCacheCanvas(img);
|
|
118
|
-
}
|
|
119
|
-
if (this.cacheContext) {
|
|
120
|
-
this.cacheContext.save();
|
|
121
|
-
this.clearCacheCanvas();
|
|
122
|
-
this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
|
|
123
|
-
this.cacheContext.restore();
|
|
124
|
-
this.render();
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
setImgNode(imgNode, basicImgInfo) {
|
|
129
|
-
super.setImgNode(imgNode, basicImgInfo);
|
|
130
|
-
if (this.cacheCanvas) {
|
|
131
|
-
this.updateCacheCanvasSize(imgNode);
|
|
132
|
-
} else {
|
|
133
|
-
this.initCacheCanvas(imgNode);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
setResult(data) {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
let {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
|
|
139
|
-
this.clearCacheCanvas();
|
|
140
|
-
if (!url) {
|
|
141
|
-
url = (_b = this.cacheCanvasToDataUrl) != null ? _b : "";
|
|
142
|
-
}
|
|
143
|
-
this.history.initRecord([url], true);
|
|
144
|
-
if (!url) {
|
|
145
|
-
this.render();
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
this.updateUrl2CacheContext(url);
|
|
149
|
-
}
|
|
150
|
-
onKeyDown(e) {
|
|
151
|
-
if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const {keyCode} = e;
|
|
155
|
-
const keyCode2Attribute = AttributeUtils["default"].getAttributeByKeycode(keyCode, this.config.attributeList);
|
|
156
|
-
if (keyCode2Attribute !== void 0) {
|
|
157
|
-
this.setDefaultAttribute(keyCode2Attribute);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
eventBinding() {
|
|
161
|
-
super.eventBinding();
|
|
162
|
-
}
|
|
163
|
-
setDefaultAttribute(attributeValue) {
|
|
164
|
-
const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
|
|
165
|
-
if (attributeInfo) {
|
|
166
|
-
this.defaultAttribute = attributeInfo.value;
|
|
167
|
-
this.defaultAttributeInfo = attributeInfo;
|
|
168
|
-
this.emit("changeAttributeSidebar");
|
|
169
|
-
this.render();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
clearStatusAfterLeave() {
|
|
173
|
-
this.onScribbleEnd();
|
|
174
|
-
this.startPoint = void 0;
|
|
175
|
-
}
|
|
176
|
-
onMouseLeave() {
|
|
177
|
-
super.onMouseLeave();
|
|
178
|
-
this.clearStatusAfterLeave();
|
|
179
|
-
}
|
|
180
|
-
onScribbleStart(e) {
|
|
181
|
-
if (!this.cacheContext) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
this.cacheContext.save();
|
|
185
|
-
this.cacheContext.beginPath();
|
|
186
|
-
this.cacheContext.strokeStyle = this.color;
|
|
187
|
-
this.cacheContext.lineWidth = this.penSizeWithZoom;
|
|
188
|
-
this.cacheContext.lineCap = "round";
|
|
189
|
-
this.cacheContext.lineJoin = "round";
|
|
190
|
-
const originCoordinate = this.getOriginCoordinate(e);
|
|
191
|
-
this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
|
|
192
|
-
this.startPoint = originCoordinate;
|
|
193
|
-
}
|
|
194
|
-
onScribbleMove(e) {
|
|
195
|
-
if (e.buttons === 1 && this.cacheContext && this.startPoint) {
|
|
196
|
-
const originCoordinate = this.getOriginCoordinate(e);
|
|
197
|
-
this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
|
|
198
|
-
this.cacheContext.stroke();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
onScribbleEnd() {
|
|
202
|
-
var _a, _b;
|
|
203
|
-
if (this.startPoint) {
|
|
204
|
-
(_a = this.cacheContext) == null ? void 0 : _a.closePath();
|
|
205
|
-
(_b = this.cacheContext) == null ? void 0 : _b.restore();
|
|
206
|
-
this.startPoint = void 0;
|
|
207
|
-
this.history.pushHistory(this.cacheCanvasToDataUrl);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
eraseArc(e) {
|
|
211
|
-
var _a;
|
|
212
|
-
if (this.cacheContext) {
|
|
213
|
-
const originCoordinate = this.getOriginCoordinate(e);
|
|
214
|
-
this.cacheContext.save();
|
|
215
|
-
this.cacheContext.beginPath();
|
|
216
|
-
this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
|
|
217
|
-
this.cacheContext.clip();
|
|
218
|
-
this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
|
|
219
|
-
(_a = this.cacheContext) == null ? void 0 : _a.restore();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
onEraseStart(e) {
|
|
223
|
-
if (!this.cacheContext || e.buttons !== 1) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
this.eraseArc(e);
|
|
227
|
-
}
|
|
228
|
-
onEraseMove(e) {
|
|
229
|
-
if (!this.cacheContext || e.buttons !== 1) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
this.eraseArc(e);
|
|
233
|
-
}
|
|
234
|
-
onEraseEnd() {
|
|
235
|
-
}
|
|
236
|
-
exportData() {
|
|
237
|
-
const imgBase64 = this.cacheCanvasToDataUrl;
|
|
238
|
-
return [[], this.basicImgInfo, {imgBase64}];
|
|
239
|
-
}
|
|
240
|
-
clearCacheCanvas() {
|
|
241
|
-
var _a;
|
|
242
|
-
(_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
|
|
243
|
-
this.render();
|
|
244
|
-
}
|
|
245
|
-
clearResult() {
|
|
246
|
-
this.clearCacheCanvas();
|
|
247
|
-
this.history.pushHistory(this.cacheCanvasToDataUrl);
|
|
248
|
-
}
|
|
249
|
-
renderPoint(radius) {
|
|
250
|
-
DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
|
|
251
|
-
}
|
|
252
|
-
renderBorderPoint(radius) {
|
|
253
|
-
DrawUtils.drawCircle(this.canvas, this.coord, radius, {color: "black"});
|
|
254
|
-
}
|
|
255
|
-
render() {
|
|
256
|
-
super.render();
|
|
257
|
-
if (!this.ctx || !this.cacheCanvas) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
this.ctx.save();
|
|
261
|
-
this.ctx.globalAlpha = 0.5;
|
|
262
|
-
DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
|
|
263
|
-
zoom: this.zoom,
|
|
264
|
-
currentPos: this.currentPos,
|
|
265
|
-
rotate: this.rotate
|
|
266
|
-
});
|
|
267
|
-
this.ctx.restore();
|
|
268
|
-
if (this.forbidOperation || this.forbidCursorLine) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
const radius = this.penSize / 2;
|
|
272
|
-
if (this.action === tool.EScribblePattern.Erase) {
|
|
273
|
-
this.renderBorderPoint(radius);
|
|
274
|
-
} else {
|
|
275
|
-
this.renderPoint(radius);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
undo() {
|
|
279
|
-
const url = this.history.undo();
|
|
280
|
-
if (url && this.cacheCanvas) {
|
|
281
|
-
this.updateUrl2CacheContext(url);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
redo() {
|
|
285
|
-
const url = this.history.redo();
|
|
286
|
-
if (url && this.cacheCanvas) {
|
|
287
|
-
this.updateUrl2CacheContext(url);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
module.exports = ScribbleTool;
|
|
1
|
+
"use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),tool=require("../../constant/tool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),basicToolOperation=require("./basicToolOperation.js");const DEFAULT_PEN_SIZE=20,DEFAULT_COLOR="white";class ScribbleTool extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.toolName=tool.EToolName.ScribbleTool,this.action=tool.EScribblePattern.Scribble,this.getOriginCoordinate=i=>AxisUtils.default.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[tool.EScribblePattern.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[tool.EScribblePattern.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case tool.EScribblePattern.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=DEFAULT_PEN_SIZE,((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===tool.EScribblePattern.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:DEFAULT_COLOR}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=lbUtils.ImgConversionUtils.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){lbUtils.ImgConversionUtils.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e}onScribbleMove(t){if(t.buttons===1&&this.cacheContext&&this.startPoint){const e=this.getOriginCoordinate(t);this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke()}}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){DrawUtils.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){DrawUtils.drawCircle(this.canvas,this.coord,t,{color:"black"})}render(){if(super.render(),!this.ctx||!this.cacheCanvas||(this.ctx.save(),this.ctx.globalAlpha=.5,DrawUtils.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===tool.EScribblePattern.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}module.exports=ScribbleTool;
|
|
@@ -1,131 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var uuid = require('../../utils/uuid.js');
|
|
4
|
-
var keyCode = require('../../constant/keyCode.js');
|
|
5
|
-
var CommonToolUtils = require('../../utils/tool/CommonToolUtils.js');
|
|
6
|
-
var basicToolOperation = require('./basicToolOperation.js');
|
|
7
|
-
|
|
8
|
-
class TextToolOperation extends basicToolOperation.BasicToolOperation {
|
|
9
|
-
constructor(props) {
|
|
10
|
-
super(props);
|
|
11
|
-
this.getSingleResult = (sourceID) => {
|
|
12
|
-
const initValue = {};
|
|
13
|
-
if (this.config.configList.length > 0) {
|
|
14
|
-
this.config.configList.forEach((i) => {
|
|
15
|
-
var _a;
|
|
16
|
-
initValue[i.key] = (_a = i.default) != null ? _a : "";
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return {value: initValue, id: uuid(), sourceID: sourceID != null ? sourceID : CommonToolUtils.getSourceID()};
|
|
20
|
-
};
|
|
21
|
-
this.getInitResultList = (dataSourceStep, basicResultList) => {
|
|
22
|
-
if (dataSourceStep > 0) {
|
|
23
|
-
return basicResultList.map((i) => this.getSingleResult(i.id));
|
|
24
|
-
}
|
|
25
|
-
return [this.getSingleResult()];
|
|
26
|
-
};
|
|
27
|
-
this.textList = [];
|
|
28
|
-
this.setShowDefaultCursor(true);
|
|
29
|
-
this.setConfig(props.config);
|
|
30
|
-
this.initTextDisplayContainer();
|
|
31
|
-
}
|
|
32
|
-
get dataList() {
|
|
33
|
-
return this.textList;
|
|
34
|
-
}
|
|
35
|
-
get textValueContainerID() {
|
|
36
|
-
return "textValueContainer";
|
|
37
|
-
}
|
|
38
|
-
get textValueContainer() {
|
|
39
|
-
return document.getElementById(this.textValueContainerID);
|
|
40
|
-
}
|
|
41
|
-
get currentPageResult() {
|
|
42
|
-
return this.textList;
|
|
43
|
-
}
|
|
44
|
-
setResult(textResultList) {
|
|
45
|
-
var _a;
|
|
46
|
-
this.textList = textResultList;
|
|
47
|
-
this.toggleTextContainerVisible(true);
|
|
48
|
-
const values = (_a = this.textList[0]) == null ? void 0 : _a.value;
|
|
49
|
-
if (values) {
|
|
50
|
-
Object.keys(values).forEach((k) => {
|
|
51
|
-
this.renderText(k, values[k]);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
this.emit("valueUpdated");
|
|
55
|
-
this.toggleTextContainerVisible(!!values);
|
|
56
|
-
}
|
|
57
|
-
updateTextValue(k, v) {
|
|
58
|
-
this.textList[0].value[k] = v;
|
|
59
|
-
this.renderText(k, v);
|
|
60
|
-
this.emit("valueUpdated");
|
|
61
|
-
}
|
|
62
|
-
renderText(key, value) {
|
|
63
|
-
const textDom = document.getElementById(`textKey${key}`);
|
|
64
|
-
if (textDom) {
|
|
65
|
-
textDom.innerText = value;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
getTextDomID(key) {
|
|
69
|
-
return `textKey${key}`;
|
|
70
|
-
}
|
|
71
|
-
initTextDisplayContainer() {
|
|
72
|
-
const dom = document.createElement("div");
|
|
73
|
-
const domStyle = {
|
|
74
|
-
position: "absolute",
|
|
75
|
-
right: "0",
|
|
76
|
-
top: "0",
|
|
77
|
-
"z-index": "20",
|
|
78
|
-
"max-width": "20%",
|
|
79
|
-
"font-family": "SourceHanSansCN-Regular",
|
|
80
|
-
background: "rgb(102, 230, 255)",
|
|
81
|
-
color: "white",
|
|
82
|
-
"word-break": "break-all",
|
|
83
|
-
"line-height": "24px",
|
|
84
|
-
"white-space": "pre-wrap",
|
|
85
|
-
"max-height": "80%",
|
|
86
|
-
"overflow-y": "auto",
|
|
87
|
-
opacity: "0.6"
|
|
88
|
-
};
|
|
89
|
-
dom.setAttribute("style", Object.keys(domStyle).reduce((pre, key) => {
|
|
90
|
-
pre += `${key}: ${domStyle[key]};`;
|
|
91
|
-
return pre;
|
|
92
|
-
}, ""));
|
|
93
|
-
dom.setAttribute("id", this.textValueContainerID);
|
|
94
|
-
this.config.configList.forEach((i) => {
|
|
95
|
-
const div = document.createElement("div");
|
|
96
|
-
const label = document.createElement("div");
|
|
97
|
-
const value = document.createElement("div");
|
|
98
|
-
div.setAttribute("style", "padding: 8px 16px");
|
|
99
|
-
label.innerText = `${i.key}:`;
|
|
100
|
-
value.innerText = "";
|
|
101
|
-
value.setAttribute("id", this.getTextDomID(i.key));
|
|
102
|
-
div.appendChild(label);
|
|
103
|
-
div.appendChild(value);
|
|
104
|
-
dom.appendChild(div);
|
|
105
|
-
});
|
|
106
|
-
this.container.appendChild(dom);
|
|
107
|
-
}
|
|
108
|
-
exportData() {
|
|
109
|
-
return [this.textList, this.basicImgInfo];
|
|
110
|
-
}
|
|
111
|
-
destroyCanvas() {
|
|
112
|
-
super.destroyCanvas();
|
|
113
|
-
if (this.textValueContainer) {
|
|
114
|
-
this.container.removeChild(this.textValueContainer);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
onKeyDown(e) {
|
|
118
|
-
super.onKeyDown(e);
|
|
119
|
-
if (e.keyCode === keyCode.Z) {
|
|
120
|
-
this.toggleTextContainerVisible();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
toggleTextContainerVisible(isVisible) {
|
|
124
|
-
if (this.textValueContainer) {
|
|
125
|
-
const display = (isVisible !== void 0 ? !isVisible : this.textValueContainer.style.display === "block") ? "none" : "block";
|
|
126
|
-
this.textValueContainer.style.display = display;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
module.exports = TextToolOperation;
|
|
1
|
+
"use strict";var uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),basicToolOperation=require("./basicToolOperation.js");class TextToolOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var s;e[n.key]=(s=n.default)!=null?s:""}),{value:e,id:uuid(),sourceID:i!=null?i:CommonToolUtils.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),i={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),s=document.createElement("div"),o=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),s.innerText=`${e.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(s),n.appendChild(o),t.appendChild(n)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===keyCode.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}module.exports=TextToolOperation;
|