@labelbee/lb-annotation 1.14.0-alpha.3 → 1.14.0-alpha.6
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/types/core/pointCloud/index.d.ts +2 -2
- 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,877 +1 @@
|
|
|
1
|
-
import { toolStyleConverter } from '@labelbee/lb-utils';
|
|
2
|
-
import { isNumber } from 'lodash';
|
|
3
|
-
import { EOperationMode, EToolName } from '../../constant/tool.js';
|
|
4
|
-
import MathUtils from '../../utils/MathUtils.js';
|
|
5
|
-
import AxisUtils, { CoordinateUtils } from '../../utils/tool/AxisUtils.js';
|
|
6
|
-
import CanvasUtils from '../../utils/tool/CanvasUtils.js';
|
|
7
|
-
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
8
|
-
import LineToolUtils from '../../utils/tool/LineToolUtils.js';
|
|
9
|
-
import { EGrowthMode, EDragStatus, ELang } from '../../constant/annotation.js';
|
|
10
|
-
import EKeyCode from '../../constant/keyCode.js';
|
|
11
|
-
import { COLORS_ARRAY, styleString, BASE_ICON } from '../../constant/style.js';
|
|
12
|
-
import Locale from '../../locales/index.js';
|
|
13
|
-
import { EMessage } from '../../locales/constants.js';
|
|
14
|
-
import ActionsHistory from '../../utils/ActionsHistory.js';
|
|
15
|
-
import AttributeUtils from '../../utils/tool/AttributeUtils.js';
|
|
16
|
-
import DblClickEventListener from '../../utils/tool/DblClickEventListener.js';
|
|
17
|
-
import DrawUtils from '../../utils/tool/DrawUtils.js';
|
|
18
|
-
import ImgPosUtils from '../../utils/tool/ImgPosUtils.js';
|
|
19
|
-
import RenderDomUtils from '../../utils/tool/RenderDomUtils.js';
|
|
20
|
-
import ZoomUtils from '../../utils/tool/ZoomUtils.js';
|
|
21
|
-
import EventListener from './eventListener.js';
|
|
22
|
-
|
|
23
|
-
var __defProp = Object.defineProperty;
|
|
24
|
-
var __defProps = Object.defineProperties;
|
|
25
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
26
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
27
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
28
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
29
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
30
|
-
var __spreadValues = (a, b) => {
|
|
31
|
-
for (var prop in b || (b = {}))
|
|
32
|
-
if (__hasOwnProp.call(b, prop))
|
|
33
|
-
__defNormalProp(a, prop, b[prop]);
|
|
34
|
-
if (__getOwnPropSymbols)
|
|
35
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
36
|
-
if (__propIsEnum.call(b, prop))
|
|
37
|
-
__defNormalProp(a, prop, b[prop]);
|
|
38
|
-
}
|
|
39
|
-
return a;
|
|
40
|
-
};
|
|
41
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
42
|
-
var __async = (__this, __arguments, generator) => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
var fulfilled = (value) => {
|
|
45
|
-
try {
|
|
46
|
-
step(generator.next(value));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var rejected = (value) => {
|
|
52
|
-
try {
|
|
53
|
-
step(generator.throw(value));
|
|
54
|
-
} catch (e) {
|
|
55
|
-
reject(e);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
const zoomInfo = {
|
|
63
|
-
min: 0.2,
|
|
64
|
-
max: 1e3,
|
|
65
|
-
ratio: 0.4
|
|
66
|
-
};
|
|
67
|
-
class BasicToolOperation extends EventListener {
|
|
68
|
-
constructor(props) {
|
|
69
|
-
super();
|
|
70
|
-
this.isDrag = false;
|
|
71
|
-
this.isSpaceKey = false;
|
|
72
|
-
this.operationMode = EOperationMode.General;
|
|
73
|
-
this.innerZoom = 1;
|
|
74
|
-
this.basicZoom = 0.01;
|
|
75
|
-
this.isSpaceClick = false;
|
|
76
|
-
this.isDragStart = false;
|
|
77
|
-
this.startTime = 0;
|
|
78
|
-
this.initImgPos = () => __async(this, null, function* () {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
if (!this.imgNode) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const zoomRatio = (_a = this._imgAttribute) == null ? void 0 : _a.zoomRatio;
|
|
84
|
-
const isOriginalSize = (_b = this._imgAttribute) == null ? void 0 : _b.isOriginalSize;
|
|
85
|
-
const {currentPos, imgInfo, zoom} = ImgPosUtils.getInitImgPos(this.size, {width: this.imgNode.width, height: this.imgNode.height}, this.rotate, zoomRatio, isOriginalSize);
|
|
86
|
-
this.setCurrentPos(currentPos);
|
|
87
|
-
this.currentPosStorage = currentPos;
|
|
88
|
-
this.setImgInfo(imgInfo);
|
|
89
|
-
this.setZoom(zoom);
|
|
90
|
-
this.render();
|
|
91
|
-
this.renderBasicCanvas();
|
|
92
|
-
this.emit("dependRender");
|
|
93
|
-
this.emit("renderZoom", zoom, currentPos, imgInfo);
|
|
94
|
-
});
|
|
95
|
-
this.getCurrentPos = (coord) => {
|
|
96
|
-
const {_firstClickCoordinate, currentPosStorage} = this;
|
|
97
|
-
try {
|
|
98
|
-
let currentPos;
|
|
99
|
-
if (_firstClickCoordinate && currentPosStorage) {
|
|
100
|
-
currentPos = {
|
|
101
|
-
y: currentPosStorage.y + coord.y - _firstClickCoordinate.y,
|
|
102
|
-
x: currentPosStorage.x + coord.x - _firstClickCoordinate.x
|
|
103
|
-
};
|
|
104
|
-
} else {
|
|
105
|
-
currentPos = {
|
|
106
|
-
x: 0,
|
|
107
|
-
y: 0
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
return currentPos;
|
|
111
|
-
} catch (e) {
|
|
112
|
-
console.error(e);
|
|
113
|
-
return {
|
|
114
|
-
x: 0,
|
|
115
|
-
y: 0
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
this.wheelChangePos = (coord, operator, newZoom) => {
|
|
120
|
-
const {currentPos, imgNode} = this;
|
|
121
|
-
if (!imgNode) {
|
|
122
|
-
console.error("unable to load image");
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (this.zoom === this.basicZoom && operator === -1) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const pos = ZoomUtils.wheelChangePos(imgNode, coord, operator, currentPos, {
|
|
129
|
-
zoom: newZoom || this.zoom,
|
|
130
|
-
innerZoom: this.innerZoom,
|
|
131
|
-
basicZoom: this.basicZoom,
|
|
132
|
-
zoomMax: zoomInfo.max,
|
|
133
|
-
rotate: this.rotate
|
|
134
|
-
});
|
|
135
|
-
if (!pos) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const {currentPos: newCurrentPos, ratio, zoom, imgInfo} = pos;
|
|
139
|
-
this.setZoom(zoom);
|
|
140
|
-
this.setCurrentPos(newCurrentPos);
|
|
141
|
-
this.currentPosStorage = newCurrentPos;
|
|
142
|
-
this.setImgInfo(imgInfo);
|
|
143
|
-
zoomInfo.ratio = ratio;
|
|
144
|
-
this.emit("renderZoom", zoom, newCurrentPos, imgInfo);
|
|
145
|
-
};
|
|
146
|
-
this.zoomChanged = (isZoomIn, growthMode = EGrowthMode.Linear) => {
|
|
147
|
-
const newZoom = ZoomUtils.zoomChanged(this.zoom, isZoomIn, growthMode);
|
|
148
|
-
this.wheelChangePos(this.getGetCenterCoordinate(), newZoom > this.zoom ? 1 : -1, newZoom);
|
|
149
|
-
this.render();
|
|
150
|
-
this.renderBasicCanvas();
|
|
151
|
-
};
|
|
152
|
-
this.zoomChangeOnCenter = (newZoom) => {
|
|
153
|
-
this.wheelChangePos(this.getGetCenterCoordinate(), 0, newZoom);
|
|
154
|
-
this.render();
|
|
155
|
-
this.renderBasicCanvas();
|
|
156
|
-
};
|
|
157
|
-
this.drawImg = () => {
|
|
158
|
-
if (!this.imgNode || this.hiddenImg === true)
|
|
159
|
-
return;
|
|
160
|
-
DrawUtils.drawImg(this.basicCanvas, this.imgNode, {
|
|
161
|
-
zoom: this.zoom,
|
|
162
|
-
currentPos: this.currentPos,
|
|
163
|
-
rotate: this.rotate,
|
|
164
|
-
imgAttribute: this._imgAttribute
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
168
|
-
this.container = props.container;
|
|
169
|
-
this.config = CommonToolUtils.jsonParser(props.config);
|
|
170
|
-
this.showDefaultCursor = props.showDefaultCursor || false;
|
|
171
|
-
this.destroyCanvas();
|
|
172
|
-
this.createCanvas(props.size, props.isAppend);
|
|
173
|
-
this.imgNode = props.imgNode;
|
|
174
|
-
this.isImgError = !props.imgNode;
|
|
175
|
-
this.basicImgInfo = {
|
|
176
|
-
width: (_b = (_a = props.imgNode) == null ? void 0 : _a.width) != null ? _b : 0,
|
|
177
|
-
height: (_d = (_c = props.imgNode) == null ? void 0 : _c.height) != null ? _d : 0,
|
|
178
|
-
valid: true,
|
|
179
|
-
rotate: 0
|
|
180
|
-
};
|
|
181
|
-
this.forbidOperation = (_e = props.forbidOperation) != null ? _e : false;
|
|
182
|
-
this.forbidBasicResultRender = (_f = props.forbidBasicResultRender) != null ? _f : false;
|
|
183
|
-
this.size = props.size;
|
|
184
|
-
this.currentPos = {
|
|
185
|
-
x: 0,
|
|
186
|
-
y: 0
|
|
187
|
-
};
|
|
188
|
-
this.zoom = 1;
|
|
189
|
-
this.coord = {
|
|
190
|
-
x: -1,
|
|
191
|
-
y: -1
|
|
192
|
-
};
|
|
193
|
-
this.currentPosStorage = {
|
|
194
|
-
x: 0,
|
|
195
|
-
y: 0
|
|
196
|
-
};
|
|
197
|
-
this.isShowCursor = false;
|
|
198
|
-
this.style = {
|
|
199
|
-
strokeColor: COLORS_ARRAY[4],
|
|
200
|
-
fillColor: COLORS_ARRAY[4],
|
|
201
|
-
strokeWidth: 2,
|
|
202
|
-
opacity: 1
|
|
203
|
-
};
|
|
204
|
-
this.attributeLockList = [];
|
|
205
|
-
this.history = new ActionsHistory();
|
|
206
|
-
this.style = (_g = props.style) != null ? _g : CommonToolUtils.jsonParser(styleString);
|
|
207
|
-
this._imgAttribute = (_h = props.imgAttribute) != null ? _h : {};
|
|
208
|
-
this.isHidden = false;
|
|
209
|
-
this.dragStatus = EDragStatus.Wait;
|
|
210
|
-
this.defaultAttribute = (_i = props == null ? void 0 : props.defaultAttribute) != null ? _i : "";
|
|
211
|
-
this.forbidCursorLine = !!props.forbidCursorLine;
|
|
212
|
-
this.lang = ELang.Zh;
|
|
213
|
-
this.onMouseDown = this.onMouseDown.bind(this);
|
|
214
|
-
this.onMouseMove = this.onMouseMove.bind(this);
|
|
215
|
-
this.onMouseLeave = this.onMouseLeave.bind(this);
|
|
216
|
-
this.onMouseUp = this.onMouseUp.bind(this);
|
|
217
|
-
this.onKeyDown = this.onKeyDown.bind(this);
|
|
218
|
-
this.onKeyUp = this.onKeyUp.bind(this);
|
|
219
|
-
this.onWheel = this.onWheel.bind(this);
|
|
220
|
-
this.onLeftDblClick = this.onLeftDblClick.bind(this);
|
|
221
|
-
this.onRightDblClick = this.onRightDblClick.bind(this);
|
|
222
|
-
this.onClick = this.onClick.bind(this);
|
|
223
|
-
this.clearImgDrag = this.clearImgDrag.bind(this);
|
|
224
|
-
this.dblClickListener = new DblClickEventListener(this.container, 200);
|
|
225
|
-
this.coordUtils = new CoordinateUtils(this);
|
|
226
|
-
this.coordUtils.setBasicImgInfo(this.basicImgInfo);
|
|
227
|
-
this.hiddenImg = props.hiddenImg || false;
|
|
228
|
-
}
|
|
229
|
-
onContextmenu(e) {
|
|
230
|
-
e.preventDefault();
|
|
231
|
-
}
|
|
232
|
-
get ctx() {
|
|
233
|
-
var _a;
|
|
234
|
-
return this._ctx || ((_a = this.canvas) == null ? void 0 : _a.getContext("2d"));
|
|
235
|
-
}
|
|
236
|
-
get basicCtx() {
|
|
237
|
-
var _a;
|
|
238
|
-
return (_a = this.basicCanvas) == null ? void 0 : _a.getContext("2d");
|
|
239
|
-
}
|
|
240
|
-
get rotate() {
|
|
241
|
-
var _a, _b;
|
|
242
|
-
return (_b = (_a = this.basicImgInfo) == null ? void 0 : _a.rotate) != null ? _b : 0;
|
|
243
|
-
}
|
|
244
|
-
get valid() {
|
|
245
|
-
var _a, _b;
|
|
246
|
-
return (_b = (_a = this.basicImgInfo) == null ? void 0 : _a.valid) != null ? _b : true;
|
|
247
|
-
}
|
|
248
|
-
get baseIcon() {
|
|
249
|
-
return BASE_ICON[this.style.color];
|
|
250
|
-
}
|
|
251
|
-
get defaultCursor() {
|
|
252
|
-
return this.showDefaultCursor ? "default" : "none";
|
|
253
|
-
}
|
|
254
|
-
get dataList() {
|
|
255
|
-
return [];
|
|
256
|
-
}
|
|
257
|
-
get innerPosAndZoom() {
|
|
258
|
-
return {
|
|
259
|
-
innerZoom: this.innerZoom,
|
|
260
|
-
currentPosStorage: this.currentPosStorage
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
get isShowDefaultCursor() {
|
|
264
|
-
return this.showDefaultCursor;
|
|
265
|
-
}
|
|
266
|
-
get isMultiMoveMode() {
|
|
267
|
-
return this.operationMode === EOperationMode.MultiMove;
|
|
268
|
-
}
|
|
269
|
-
get hasMarkerConfig() {
|
|
270
|
-
return this.config.markerConfigurable === true && this.config.markerList && this.config.markerList.length > 0;
|
|
271
|
-
}
|
|
272
|
-
setZoom(zoom) {
|
|
273
|
-
this.zoom = zoom;
|
|
274
|
-
this.innerZoom = zoom;
|
|
275
|
-
this.coordUtils.setZoomAndCurrentPos(this.zoom, this.currentPos);
|
|
276
|
-
}
|
|
277
|
-
setCurrentPos(currentPos) {
|
|
278
|
-
this.currentPos = currentPos;
|
|
279
|
-
this.coordUtils.setZoomAndCurrentPos(this.zoom, this.currentPos);
|
|
280
|
-
}
|
|
281
|
-
setReferenceData(referenceData) {
|
|
282
|
-
this.referenceData = referenceData;
|
|
283
|
-
}
|
|
284
|
-
setImgInfo(size) {
|
|
285
|
-
this.imgInfo = size;
|
|
286
|
-
}
|
|
287
|
-
setCurrentPosStorage(currentPosStorage) {
|
|
288
|
-
this.currentPosStorage = currentPosStorage;
|
|
289
|
-
}
|
|
290
|
-
setOperationMode(operationMode) {
|
|
291
|
-
this.operationMode = operationMode;
|
|
292
|
-
}
|
|
293
|
-
recoverOperationMode() {
|
|
294
|
-
if (this.operationMode === EOperationMode.MultiMove) {
|
|
295
|
-
this.setOperationMode(EOperationMode.General);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
updatePosition(params) {
|
|
299
|
-
const {zoom, currentPos} = params;
|
|
300
|
-
this.setZoom(zoom);
|
|
301
|
-
this.setCurrentPos(currentPos);
|
|
302
|
-
this.currentPosStorage = currentPos;
|
|
303
|
-
this.renderBasicCanvas();
|
|
304
|
-
this.render();
|
|
305
|
-
}
|
|
306
|
-
setLang(lang) {
|
|
307
|
-
this.lang = lang;
|
|
308
|
-
}
|
|
309
|
-
setShowDefaultCursor(showDefaultCursor) {
|
|
310
|
-
this.showDefaultCursor = showDefaultCursor;
|
|
311
|
-
this.container.style.cursor = this.defaultCursor;
|
|
312
|
-
}
|
|
313
|
-
setCustomCursor(cursor) {
|
|
314
|
-
this.container.style.cursor = cursor;
|
|
315
|
-
}
|
|
316
|
-
get forbidMouseOperation() {
|
|
317
|
-
return this.forbidOperation || this.valid === false;
|
|
318
|
-
}
|
|
319
|
-
get pixelRatio() {
|
|
320
|
-
var _a;
|
|
321
|
-
return CanvasUtils.getPixelRatio((_a = this.canvas) == null ? void 0 : _a.getContext("2d"));
|
|
322
|
-
}
|
|
323
|
-
init() {
|
|
324
|
-
this.eventUnbinding();
|
|
325
|
-
this.initPosition();
|
|
326
|
-
this.eventBinding();
|
|
327
|
-
this.render();
|
|
328
|
-
this.renderBasicCanvas();
|
|
329
|
-
}
|
|
330
|
-
destroy() {
|
|
331
|
-
this.destroyCanvas();
|
|
332
|
-
this.eventUnbinding();
|
|
333
|
-
}
|
|
334
|
-
updateCanvasBasicStyle(canvas, size, zIndex) {
|
|
335
|
-
const pixel = this.pixelRatio;
|
|
336
|
-
canvas.style.position = "absolute";
|
|
337
|
-
canvas.width = size.width * pixel;
|
|
338
|
-
canvas.height = size.height * pixel;
|
|
339
|
-
canvas.style.width = `${size.width}px`;
|
|
340
|
-
canvas.style.height = `${size.height}px`;
|
|
341
|
-
canvas.style.left = "0";
|
|
342
|
-
canvas.style.top = "0";
|
|
343
|
-
canvas.style.zIndex = `${zIndex} `;
|
|
344
|
-
}
|
|
345
|
-
createCanvas(size, isAppend = true) {
|
|
346
|
-
var _a, _b;
|
|
347
|
-
const pixel = this.pixelRatio;
|
|
348
|
-
const basicCanvas = document.createElement("canvas");
|
|
349
|
-
this.updateCanvasBasicStyle(basicCanvas, size, 0);
|
|
350
|
-
this.basicCanvas = basicCanvas;
|
|
351
|
-
const canvas = document.createElement("canvas");
|
|
352
|
-
this.updateCanvasBasicStyle(canvas, size, 10);
|
|
353
|
-
if (isAppend) {
|
|
354
|
-
if (this.container.hasChildNodes()) {
|
|
355
|
-
this.container.insertBefore(canvas, this.container.childNodes[0]);
|
|
356
|
-
this.container.insertBefore(basicCanvas, this.container.childNodes[0]);
|
|
357
|
-
} else {
|
|
358
|
-
this.container.appendChild(basicCanvas);
|
|
359
|
-
this.container.appendChild(canvas);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
this.canvas = canvas;
|
|
363
|
-
this.container.style.cursor = this.defaultCursor;
|
|
364
|
-
(_a = this.ctx) == null ? void 0 : _a.scale(pixel, pixel);
|
|
365
|
-
(_b = this.basicCtx) == null ? void 0 : _b.scale(pixel, pixel);
|
|
366
|
-
}
|
|
367
|
-
destroyCanvas() {
|
|
368
|
-
if (this.canvas && this.container.contains(this.canvas)) {
|
|
369
|
-
this.container.removeChild(this.canvas);
|
|
370
|
-
}
|
|
371
|
-
if (this.basicCanvas && this.container.contains(this.basicCanvas)) {
|
|
372
|
-
this.container.removeChild(this.basicCanvas);
|
|
373
|
-
}
|
|
374
|
-
this.clearInvalidPage();
|
|
375
|
-
this.clearImgDrag();
|
|
376
|
-
}
|
|
377
|
-
setStyle(toolStyle) {
|
|
378
|
-
this.style = toolStyle;
|
|
379
|
-
this.render();
|
|
380
|
-
}
|
|
381
|
-
setImgNode(imgNode, basicImgInfo = {}) {
|
|
382
|
-
this.imgNode = imgNode;
|
|
383
|
-
this.setBasicImgInfo(__spreadValues({
|
|
384
|
-
width: imgNode.width,
|
|
385
|
-
height: imgNode.height,
|
|
386
|
-
valid: true,
|
|
387
|
-
rotate: 0
|
|
388
|
-
}, basicImgInfo));
|
|
389
|
-
if (this.isImgError === true) {
|
|
390
|
-
this.isImgError = false;
|
|
391
|
-
this.emit("changeAnnotationShow");
|
|
392
|
-
}
|
|
393
|
-
if (typeof basicImgInfo.valid === "boolean") {
|
|
394
|
-
this.setValid(basicImgInfo.valid);
|
|
395
|
-
}
|
|
396
|
-
this.initImgPos();
|
|
397
|
-
this.render();
|
|
398
|
-
this.renderBasicCanvas();
|
|
399
|
-
}
|
|
400
|
-
setErrorImg() {
|
|
401
|
-
const originIsImgError = this.isImgError;
|
|
402
|
-
this.isImgError = true;
|
|
403
|
-
this.imgNode = void 0;
|
|
404
|
-
this.setBasicImgInfo({
|
|
405
|
-
width: 0,
|
|
406
|
-
height: 0,
|
|
407
|
-
valid: true,
|
|
408
|
-
rotate: 0
|
|
409
|
-
});
|
|
410
|
-
if (originIsImgError === false) {
|
|
411
|
-
this.emit("changeAnnotationShow");
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
setBasicImgInfo(basicImgInfo) {
|
|
415
|
-
this.basicImgInfo = basicImgInfo;
|
|
416
|
-
this.coordUtils.setBasicImgInfo(basicImgInfo);
|
|
417
|
-
}
|
|
418
|
-
setForbidOperation(forbidOperation) {
|
|
419
|
-
this.forbidOperation = forbidOperation;
|
|
420
|
-
this.setShowDefaultCursor(forbidOperation);
|
|
421
|
-
this.render();
|
|
422
|
-
}
|
|
423
|
-
setForbidCursorLine(forbidCursorLine) {
|
|
424
|
-
this.forbidCursorLine = forbidCursorLine;
|
|
425
|
-
this.render();
|
|
426
|
-
}
|
|
427
|
-
setIsHidden(isHidden) {
|
|
428
|
-
this.isHidden = isHidden;
|
|
429
|
-
this.emit("hiddenChange");
|
|
430
|
-
}
|
|
431
|
-
setDefaultAttribute(attribute) {
|
|
432
|
-
this.defaultAttribute = attribute;
|
|
433
|
-
}
|
|
434
|
-
getCoordinateInOrigin(e) {
|
|
435
|
-
const bounding = this.canvas.getBoundingClientRect();
|
|
436
|
-
return {
|
|
437
|
-
x: (e.clientX - bounding.left - this.currentPos.x) / this.zoom,
|
|
438
|
-
y: (e.clientY - bounding.top - this.currentPos.y) / this.zoom
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
getTextIconSvg(attribute = "") {
|
|
442
|
-
var _a;
|
|
443
|
-
return AttributeUtils.getTextIconSvg(attribute, (_a = this.config) == null ? void 0 : _a.attributeList, this.config.attributeConfigurable, this.baseIcon);
|
|
444
|
-
}
|
|
445
|
-
setIsShowOrder(isShowOrder) {
|
|
446
|
-
this.config.isShowOrder = isShowOrder;
|
|
447
|
-
this.render();
|
|
448
|
-
}
|
|
449
|
-
getCoordinate(e) {
|
|
450
|
-
const bounding = this.canvas.getBoundingClientRect();
|
|
451
|
-
return {
|
|
452
|
-
x: e.clientX - bounding.left,
|
|
453
|
-
y: e.clientY - bounding.top
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
getCoordinateUnderZoom(e) {
|
|
457
|
-
const bounding = this.canvas.getBoundingClientRect();
|
|
458
|
-
return {
|
|
459
|
-
x: e.clientX - bounding.left - this.currentPos.x,
|
|
460
|
-
y: e.clientY - bounding.top - this.currentPos.y
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
getCoordinateUnderZoomByRotate(e) {
|
|
464
|
-
const {x, y} = this.getCoordinateUnderZoom(e);
|
|
465
|
-
if (this.basicImgInfo.rotate === 90) {
|
|
466
|
-
return {
|
|
467
|
-
x: y,
|
|
468
|
-
y: this.basicImgInfo.height * this.zoom - x
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
if (this.basicImgInfo.rotate === 180) {
|
|
472
|
-
return {
|
|
473
|
-
x: this.basicImgInfo.width * this.zoom - x,
|
|
474
|
-
y: this.basicImgInfo.height * this.zoom - y
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
if (this.basicImgInfo.rotate === 270) {
|
|
478
|
-
return {
|
|
479
|
-
x: this.basicImgInfo.width * this.zoom - y,
|
|
480
|
-
y: x
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
return {
|
|
484
|
-
x,
|
|
485
|
-
y
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
getGetCenterCoordinate() {
|
|
489
|
-
return {
|
|
490
|
-
x: this.size.width / 2,
|
|
491
|
-
y: this.size.height / 2
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
initPosition() {
|
|
495
|
-
if (this.basicResult && this.imgInfo) {
|
|
496
|
-
const {basicResult, size, imgNode, _imgAttribute, imgInfo, dependToolName} = this;
|
|
497
|
-
if (basicResult && imgNode && dependToolName) {
|
|
498
|
-
let newBoundry = basicResult;
|
|
499
|
-
switch (dependToolName) {
|
|
500
|
-
case EToolName.Polygon:
|
|
501
|
-
case EToolName.Line: {
|
|
502
|
-
if (basicResult.pointList) {
|
|
503
|
-
const basicZone = MathUtils.calcViewportBoundaries(basicResult.pointList);
|
|
504
|
-
newBoundry = {
|
|
505
|
-
x: basicZone.left,
|
|
506
|
-
y: basicZone.top,
|
|
507
|
-
width: basicZone.right - basicZone.left,
|
|
508
|
-
height: basicZone.bottom - basicZone.top
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
const pos = ImgPosUtils.getBasicRecPos(imgNode, newBoundry, size, void 0, _imgAttribute == null ? void 0 : _imgAttribute.zoomRatio, _imgAttribute == null ? void 0 : _imgAttribute.isOriginalSize);
|
|
515
|
-
if (pos) {
|
|
516
|
-
this.setCurrentPos(pos.currentPos);
|
|
517
|
-
this.currentPosStorage = this.currentPos;
|
|
518
|
-
this.setImgInfo(__spreadProps(__spreadValues({}, imgInfo), {
|
|
519
|
-
width: imgInfo.width / this.innerZoom * pos.innerZoom,
|
|
520
|
-
height: imgInfo.height / this.innerZoom * pos.innerZoom
|
|
521
|
-
}));
|
|
522
|
-
this.setZoom(pos.innerZoom);
|
|
523
|
-
this.render();
|
|
524
|
-
this.renderBasicCanvas();
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
} else {
|
|
528
|
-
this.initImgPos();
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
undo() {
|
|
532
|
-
this.history.undo();
|
|
533
|
-
}
|
|
534
|
-
redo() {
|
|
535
|
-
this.history.redo();
|
|
536
|
-
}
|
|
537
|
-
clearCanvas() {
|
|
538
|
-
var _a;
|
|
539
|
-
(_a = this.ctx) == null ? void 0 : _a.clearRect(0, 0, this.size.width, this.size.height);
|
|
540
|
-
}
|
|
541
|
-
clearBasicCanvas() {
|
|
542
|
-
var _a;
|
|
543
|
-
(_a = this.basicCtx) == null ? void 0 : _a.clearRect(0, 0, this.size.width, this.size.height);
|
|
544
|
-
}
|
|
545
|
-
eventBinding() {
|
|
546
|
-
this.dblClickListener.addEvent(() => {
|
|
547
|
-
}, this.onLeftDblClick, this.onRightDblClick);
|
|
548
|
-
this.container.addEventListener("mousedown", this.onMouseDown);
|
|
549
|
-
this.container.addEventListener("mousemove", this.onMouseMove);
|
|
550
|
-
this.container.addEventListener("mouseup", this.onMouseUp);
|
|
551
|
-
this.container.addEventListener("mouseleave", this.onMouseLeave);
|
|
552
|
-
this.container.addEventListener("click", this.onClick);
|
|
553
|
-
this.container.addEventListener("wheel", this.onWheel);
|
|
554
|
-
document.addEventListener("keydown", this.onKeyDown);
|
|
555
|
-
document.addEventListener("keyup", this.onKeyUp);
|
|
556
|
-
window.parent.document.addEventListener("contextmenu", this.onContextmenu, false);
|
|
557
|
-
}
|
|
558
|
-
eventUnbinding() {
|
|
559
|
-
this.container.removeEventListener("mousedown", this.onMouseDown);
|
|
560
|
-
this.container.removeEventListener("mousemove", this.onMouseMove);
|
|
561
|
-
this.container.removeEventListener("mouseup", this.onMouseUp);
|
|
562
|
-
this.container.removeEventListener("mouseleave", this.onMouseLeave);
|
|
563
|
-
this.container.removeEventListener("wheel", this.onWheel);
|
|
564
|
-
this.container.removeEventListener("click", this.onClick);
|
|
565
|
-
document.removeEventListener("keydown", this.onKeyDown);
|
|
566
|
-
document.removeEventListener("keyup", this.onKeyUp);
|
|
567
|
-
window.parent.document.removeEventListener("contextmenu", this.onContextmenu, false);
|
|
568
|
-
this.dblClickListener.removeEvent();
|
|
569
|
-
}
|
|
570
|
-
clearImgDrag() {
|
|
571
|
-
this.isDrag = false;
|
|
572
|
-
this.isDragStart = false;
|
|
573
|
-
this.isSpaceClick = false;
|
|
574
|
-
this.startTime = 0;
|
|
575
|
-
this.container.style.cursor = this.defaultCursor;
|
|
576
|
-
this.forbidCursorLine = false;
|
|
577
|
-
}
|
|
578
|
-
clearCursorLine() {
|
|
579
|
-
this.coord = {
|
|
580
|
-
x: -1,
|
|
581
|
-
y: -1
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
onMouseDown(e) {
|
|
585
|
-
if (!this.canvas || this.isImgError) {
|
|
586
|
-
return true;
|
|
587
|
-
}
|
|
588
|
-
const coord = this.getCoordinate(e);
|
|
589
|
-
if (this.isSpaceKey && e.button === 0 || e.button === 2) {
|
|
590
|
-
e.stopPropagation();
|
|
591
|
-
this._firstClickCoordinate = coord;
|
|
592
|
-
this.currentPosStorage = this.currentPos;
|
|
593
|
-
this.isSpaceClick = true;
|
|
594
|
-
this.isDragStart = true;
|
|
595
|
-
this.startTime = new Date().getTime();
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
onMouseMove(e) {
|
|
599
|
-
if (!this.canvas || this.isImgError) {
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
const coord = this.getCoordinate(e);
|
|
603
|
-
if (this.isShowCursor) {
|
|
604
|
-
this.coord = coord;
|
|
605
|
-
}
|
|
606
|
-
try {
|
|
607
|
-
if (!coord || !isNumber(coord == null ? void 0 : coord.x) || !isNumber(coord == null ? void 0 : coord.y)) {
|
|
608
|
-
throw new Error("coord error");
|
|
609
|
-
}
|
|
610
|
-
this.coord = coord;
|
|
611
|
-
if ((this.isSpaceClick || this.isDragStart) && this._firstClickCoordinate) {
|
|
612
|
-
const currentPos = this.getCurrentPos(coord);
|
|
613
|
-
this.setCurrentPos(currentPos);
|
|
614
|
-
this.isDrag = true;
|
|
615
|
-
this.container.style.cursor = "grabbing";
|
|
616
|
-
this.forbidCursorLine = true;
|
|
617
|
-
this.renderBasicCanvas();
|
|
618
|
-
this.emit("dependRender");
|
|
619
|
-
this.emit("dragMove", {currentPos, zoom: this.zoom, imgInfo: this.imgInfo});
|
|
620
|
-
}
|
|
621
|
-
this.render();
|
|
622
|
-
} catch (error) {
|
|
623
|
-
console.error(error);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
onMouseUp(e) {
|
|
627
|
-
if (!this.canvas || this.isImgError) {
|
|
628
|
-
return true;
|
|
629
|
-
}
|
|
630
|
-
this.container.style.cursor = this.defaultCursor;
|
|
631
|
-
this.forbidCursorLine = false;
|
|
632
|
-
this.isDrag = false;
|
|
633
|
-
this.isDragStart = false;
|
|
634
|
-
this.isSpaceClick = false;
|
|
635
|
-
if (this.startTime !== 0 && this._firstClickCoordinate) {
|
|
636
|
-
const time = new Date().getTime();
|
|
637
|
-
const currentCoord = this.getCoordinate(e);
|
|
638
|
-
if (time - this.startTime > 1e3 || this.isSpaceKey === true || LineToolUtils.calcTwoPointDistance(currentCoord, this._firstClickCoordinate) > 10) {
|
|
639
|
-
e.stopPropagation();
|
|
640
|
-
this.startTime = 0;
|
|
641
|
-
this.render();
|
|
642
|
-
return true;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
this.startTime = 0;
|
|
646
|
-
this.render();
|
|
647
|
-
}
|
|
648
|
-
onMouseLeave() {
|
|
649
|
-
this.clearImgDrag();
|
|
650
|
-
}
|
|
651
|
-
onClick(e) {
|
|
652
|
-
}
|
|
653
|
-
onLeftDblClick(e) {
|
|
654
|
-
}
|
|
655
|
-
onRightDblClick(e) {
|
|
656
|
-
this.clearImgDrag();
|
|
657
|
-
}
|
|
658
|
-
onKeyDown(e) {
|
|
659
|
-
if (e.keyCode === EKeyCode.Alt) {
|
|
660
|
-
e.preventDefault();
|
|
661
|
-
}
|
|
662
|
-
switch (e.keyCode) {
|
|
663
|
-
case EKeyCode.Space:
|
|
664
|
-
this.isSpaceKey = true;
|
|
665
|
-
break;
|
|
666
|
-
case EKeyCode.Z:
|
|
667
|
-
if (e.ctrlKey) {
|
|
668
|
-
if (e.shiftKey) {
|
|
669
|
-
this.redo();
|
|
670
|
-
} else {
|
|
671
|
-
this.undo();
|
|
672
|
-
}
|
|
673
|
-
return false;
|
|
674
|
-
}
|
|
675
|
-
break;
|
|
676
|
-
}
|
|
677
|
-
return true;
|
|
678
|
-
}
|
|
679
|
-
onKeyUp(e) {
|
|
680
|
-
switch (e.keyCode) {
|
|
681
|
-
case EKeyCode.Space:
|
|
682
|
-
this.isSpaceKey = false;
|
|
683
|
-
break;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
exportCustomData() {
|
|
687
|
-
return {};
|
|
688
|
-
}
|
|
689
|
-
onWheel(e, isRender = true) {
|
|
690
|
-
if (!this.imgNode || !this.coord) {
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
e.preventDefault();
|
|
694
|
-
e.stopPropagation();
|
|
695
|
-
const coord = this.getCoordinate(e);
|
|
696
|
-
const delta = e.deltaY || e.wheelDelta;
|
|
697
|
-
let operator = 0;
|
|
698
|
-
if (delta > 0 && this.zoom > zoomInfo.min) {
|
|
699
|
-
operator = -1;
|
|
700
|
-
}
|
|
701
|
-
if (delta < 0 && this.zoom < zoomInfo.max) {
|
|
702
|
-
operator = 1;
|
|
703
|
-
}
|
|
704
|
-
this.wheelChangePos(coord, operator);
|
|
705
|
-
this.emit("dependRender");
|
|
706
|
-
if (isRender) {
|
|
707
|
-
this.render();
|
|
708
|
-
}
|
|
709
|
-
this.renderBasicCanvas();
|
|
710
|
-
}
|
|
711
|
-
renderCursorLine(lineColor = ((_a) => (_a = this.style.lineColor[0]) != null ? _a : "")()) {
|
|
712
|
-
if (!this.ctx || this.forbidCursorLine || this.forbidOperation) {
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
const {x, y} = this.coord;
|
|
716
|
-
DrawUtils.drawLine(this.canvas, {x: 0, y}, {x: 1e4, y}, {color: lineColor});
|
|
717
|
-
DrawUtils.drawLine(this.canvas, {x, y: 0}, {x, y: 1e4}, {color: lineColor});
|
|
718
|
-
DrawUtils.drawCircleWithFill(this.canvas, {x, y}, 1, {color: "white"});
|
|
719
|
-
}
|
|
720
|
-
setSize(size) {
|
|
721
|
-
var _a;
|
|
722
|
-
this.size = size;
|
|
723
|
-
if (this.container.contains(this.canvas)) {
|
|
724
|
-
this.destroyCanvas();
|
|
725
|
-
this.createCanvas(size);
|
|
726
|
-
this.eventUnbinding();
|
|
727
|
-
this.init();
|
|
728
|
-
if (((_a = this.basicImgInfo) == null ? void 0 : _a.valid) === false) {
|
|
729
|
-
this.renderInvalidPage();
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
setImgAttribute(imgAttribute) {
|
|
734
|
-
const oldImgAttribute = this._imgAttribute;
|
|
735
|
-
this._imgAttribute = imgAttribute;
|
|
736
|
-
if ((oldImgAttribute == null ? void 0 : oldImgAttribute.zoomRatio) !== imgAttribute.zoomRatio || oldImgAttribute.isOriginalSize !== imgAttribute.isOriginalSize) {
|
|
737
|
-
this.initImgPos();
|
|
738
|
-
return;
|
|
739
|
-
}
|
|
740
|
-
this.renderBasicCanvas();
|
|
741
|
-
this.render();
|
|
742
|
-
}
|
|
743
|
-
clearResult(sendMessage) {
|
|
744
|
-
}
|
|
745
|
-
setValid(valid) {
|
|
746
|
-
this.basicImgInfo.valid = valid;
|
|
747
|
-
if (valid === false) {
|
|
748
|
-
this.renderInvalidPage();
|
|
749
|
-
this.clearResult(false);
|
|
750
|
-
} else {
|
|
751
|
-
this.clearInvalidPage();
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
setRotate(rotate) {
|
|
755
|
-
this.basicImgInfo.rotate = rotate;
|
|
756
|
-
}
|
|
757
|
-
setBasicResult(basicResult) {
|
|
758
|
-
this.basicResult = basicResult;
|
|
759
|
-
this.coordUtils.setBasicResult(basicResult);
|
|
760
|
-
this.initPosition();
|
|
761
|
-
this.emit("dependRender");
|
|
762
|
-
}
|
|
763
|
-
setDependName(dependToolName, dependToolConfig) {
|
|
764
|
-
this.dependToolName = dependToolName;
|
|
765
|
-
this.coordUtils.setDependInfo(dependToolName, dependToolConfig);
|
|
766
|
-
}
|
|
767
|
-
setAttributeLockList(attributeLockList) {
|
|
768
|
-
this.attributeLockList = attributeLockList;
|
|
769
|
-
this.render();
|
|
770
|
-
}
|
|
771
|
-
setConfig(config) {
|
|
772
|
-
this.config = CommonToolUtils.jsonParser(config);
|
|
773
|
-
}
|
|
774
|
-
setDataInjectionAtCreation(dataInjectionAtCreation) {
|
|
775
|
-
this.dataInjectionAtCreation = dataInjectionAtCreation;
|
|
776
|
-
}
|
|
777
|
-
setRenderEnhance(renderEnhance) {
|
|
778
|
-
this.renderEnhance = renderEnhance;
|
|
779
|
-
}
|
|
780
|
-
setCustomRenderStyle(customRenderStyle) {
|
|
781
|
-
this.customRenderStyle = customRenderStyle;
|
|
782
|
-
}
|
|
783
|
-
updateRotate() {
|
|
784
|
-
if (this.dependToolName) {
|
|
785
|
-
this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.NoRotateInDependence, this.lang));
|
|
786
|
-
return false;
|
|
787
|
-
}
|
|
788
|
-
if (this.dataList.length > 0) {
|
|
789
|
-
this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.NoRotateNotice, this.lang));
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
const rotate = MathUtils.getRotate(this.basicImgInfo.rotate);
|
|
793
|
-
this.basicImgInfo.rotate = rotate;
|
|
794
|
-
this.initImgPos();
|
|
795
|
-
this.emit("updateResult");
|
|
796
|
-
}
|
|
797
|
-
getColor(attribute = "", config = this.config) {
|
|
798
|
-
return toolStyleConverter.getColorByConfig({attribute, config, style: this.style});
|
|
799
|
-
}
|
|
800
|
-
getLineColor(attribute = "") {
|
|
801
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
802
|
-
if (((_a = this.config) == null ? void 0 : _a.attributeConfigurable) === true) {
|
|
803
|
-
const attributeIndex = AttributeUtils.getAttributeIndex(attribute, (_c = (_b = this.config) == null ? void 0 : _b.attributeList) != null ? _c : []) + 1;
|
|
804
|
-
const color2 = (_f = (_e = (_d = this.config) == null ? void 0 : _d.attributeList) == null ? void 0 : _e.find((i) => i.value === attribute)) == null ? void 0 : _f.color;
|
|
805
|
-
if (color2) {
|
|
806
|
-
return (_h = (_g = toolStyleConverter.getColorByConfig({attribute, config: this.config})) == null ? void 0 : _g.valid) == null ? void 0 : _h.stroke;
|
|
807
|
-
}
|
|
808
|
-
return this.style.attributeLineColor ? this.style.attributeLineColor[attributeIndex] : "";
|
|
809
|
-
}
|
|
810
|
-
const {color, lineColor} = this.style;
|
|
811
|
-
if (color && lineColor) {
|
|
812
|
-
return lineColor[color];
|
|
813
|
-
}
|
|
814
|
-
return "";
|
|
815
|
-
}
|
|
816
|
-
clearInvalidPage() {
|
|
817
|
-
if (this._invalidDOM && this.container && this.container.contains(this._invalidDOM)) {
|
|
818
|
-
this.container.removeChild(this._invalidDOM);
|
|
819
|
-
this._invalidDOM = void 0;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
renderInvalidPage() {
|
|
823
|
-
if (!this.container || this._invalidDOM) {
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
this._invalidDOM = RenderDomUtils.renderInvalidPage(this.container, this.size, this.lang);
|
|
827
|
-
}
|
|
828
|
-
renderBasicCanvas() {
|
|
829
|
-
if (!this.basicCanvas) {
|
|
830
|
-
return;
|
|
831
|
-
}
|
|
832
|
-
this.clearBasicCanvas();
|
|
833
|
-
this.drawImg();
|
|
834
|
-
const thickness = 3;
|
|
835
|
-
if (this.forbidBasicResultRender) {
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
if (this.basicResult && this.dependToolName) {
|
|
839
|
-
switch (this.dependToolName) {
|
|
840
|
-
case EToolName.Rect: {
|
|
841
|
-
DrawUtils.drawRect(this.basicCanvas, AxisUtils.changeRectByZoom(this.basicResult, this.zoom, this.currentPos), {
|
|
842
|
-
color: "rgba(204,204,204,1.00)",
|
|
843
|
-
thickness
|
|
844
|
-
});
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
case EToolName.Polygon: {
|
|
848
|
-
DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas, AxisUtils.changePointListByZoom(this.basicResult.pointList, this.zoom, this.currentPos), {
|
|
849
|
-
fillColor: "transparent",
|
|
850
|
-
strokeColor: "rgba(204,204,204,1.00)",
|
|
851
|
-
isClose: true,
|
|
852
|
-
thickness
|
|
853
|
-
});
|
|
854
|
-
break;
|
|
855
|
-
}
|
|
856
|
-
case EToolName.Line: {
|
|
857
|
-
DrawUtils.drawLineWithPointList(this.basicCanvas, AxisUtils.changePointListByZoom(this.basicResult.pointList, this.zoom, this.currentPos), {
|
|
858
|
-
color: "rgba(204,204,204,1.00)",
|
|
859
|
-
thickness
|
|
860
|
-
});
|
|
861
|
-
break;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
render() {
|
|
867
|
-
if (!this.canvas || !this.ctx || !this.imgNode) {
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
this.clearCanvas();
|
|
871
|
-
}
|
|
872
|
-
changeStyle(newAttribute = this.defaultAttribute) {
|
|
873
|
-
this.emit("changeStyle", {attribute: newAttribute});
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
export { BasicToolOperation };
|
|
1
|
+
import{toolStyleConverter as x}from"@labelbee/lb-utils";import{isNumber as S}from"lodash";import{EOperationMode as I,EToolName as y}from"../../constant/tool.js";import R from"../../utils/MathUtils.js";import w,{CoordinateUtils as j}from"../../utils/tool/AxisUtils.js";import T from"../../utils/tool/CanvasUtils.js";import L from"../../utils/tool/CommonToolUtils.js";import K from"../../utils/tool/LineToolUtils.js";import{EGrowthMode as W,EDragStatus as G,ELang as H}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{COLORS_ARRAY as M,styleString as Y,BASE_ICON as F}from"../../constant/style.js";import k from"../../locales/index.js";import{EMessage as z}from"../../locales/constants.js";import V from"../../utils/ActionsHistory.js";import E from"../../utils/tool/AttributeUtils.js";import X from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/ImgPosUtils.js";import $ from"../../utils/tool/RenderDomUtils.js";import U from"../../utils/tool/ZoomUtils.js";import q from"./eventListener.js";var J=Object.defineProperty,Q=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,Z=(d,t,i)=>t in d?J(d,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[t]=i,A=(d,t)=>{for(var i in t||(t={}))it.call(t,i)&&Z(d,i,t[i]);if(O)for(var i of O(t))et.call(t,i)&&Z(d,i,t[i]);return d},st=(d,t)=>Q(d,tt(t)),ot=(d,t,i)=>new Promise((e,s)=>{var o=r=>{try{n(i.next(r))}catch(a){s(a)}},h=r=>{try{n(i.throw(r))}catch(a){s(a)}},n=r=>r.done?e(r.value):Promise.resolve(r.value).then(o,h);n((i=i.apply(d,t)).next())});const P={min:.2,max:1e3,ratio:.4};class rt extends q{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.operationMode=I.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>ot(this,null,function*(){var l,c;if(!this.imgNode)return;const u=(l=this._imgAttribute)==null?void 0:l.zoomRatio,m=(c=this._imgAttribute)==null?void 0:c.isOriginalSize,{currentPos:f,imgInfo:b,zoom:v}=B.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(b),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,b)}),this.getCurrentPos=l=>{const{_firstClickCoordinate:c,currentPosStorage:u}=this;try{let m;return c&&u?m={y:u.y+l.y-c.y,x:u.x+l.x-c.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(l,c,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&c===-1)return;const b=U.wheelChangePos(f,l,c,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:P.max,rotate:this.rotate});if(!b)return;const{currentPos:v,ratio:N,zoom:_,imgInfo:D}=b;this.setZoom(_),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(D),P.ratio=N,this.emit("renderZoom",_,v,D)},this.zoomChanged=(l,c=W.Linear)=>{const u=U.zoomChanged(this.zoom,l,c);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=l=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,l),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var i,e,s,o,h,n,r,a,C;this.container=t.container,this.config=L.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(e=(i=t.imgNode)==null?void 0:i.width)!=null?e:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(h=t.forbidOperation)!=null?h:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:M[4],fillColor:M[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new V,this.style=(r=t.style)!=null?r:L.jsonParser(Y),this._imgAttribute=(a=t.imgAttribute)!=null?a:{},this.isHidden=!1,this.dragStatus=G.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=H.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new X(this.container,200),this.coordUtils=new j(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return F[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===I.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===I.MultiMove&&this.setOperationMode(I.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return T.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(A({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return E.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&e&&h){let n=t;switch(h){case y.Polygon:case y.Line:{if(t.pointList){const a=R.calcViewportBoundaries(t.pointList);n={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const r=B.getBasicRecPos(e,n,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);r&&(this.setCurrentPos(r.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(st(A({},o),{width:o.width/this.innerZoom*r.innerZoom,height:o.height/this.innerZoom*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!S(i==null?void 0:i.x)||!S(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||K.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===p.Alt&&t.preventDefault(),t.keyCode){case p.Space:this.isSpaceKey=!0;break;case p.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case p.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>P.min&&(o=-1),s<0&&this.zoom<P.max&&(o=1),this.wheelChangePos(e,o),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=L.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",k.getMessagesByLocale(z.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",k.getMessagesByLocale(z.NoRotateNotice,this.lang)),!1;const t=R.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return x.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,o,h,n,r,a;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const c=E.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((n=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(m=>m.value===t))==null?void 0:n.color)?(a=(r=x.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[c]:""}const{color:C,lineColor:l}=this.style;return C&&l?l[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=$.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{g.drawRect(this.basicCanvas,w.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,w.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{g.drawLineWithPointList(this.basicCanvas,w.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{rt as BasicToolOperation};
|