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