@labelbee/lb-annotation 1.13.0 → 1.14.0-alpha.0

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.
Files changed (66) hide show
  1. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -0
  2. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -0
  3. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -0
  4. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -0
  5. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -0
  6. package/dist/constant/annotation.js +1 -1
  7. package/dist/constant/tool.js +1 -1
  8. package/dist/core/pointCloud/annotation.js +1 -1
  9. package/dist/core/pointCloud/index.js +2 -2
  10. package/dist/core/scheduler.js +1 -1
  11. package/dist/core/toolOperation/ViewOperation.js +1 -1
  12. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  13. package/dist/core/toolOperation/cuboidOperation.js +1 -0
  14. package/dist/core/toolOperation/cuboidToggleButtonClass.js +31 -0
  15. package/dist/types/constant/annotation.d.ts +45 -1
  16. package/dist/types/constant/tool.d.ts +6 -1
  17. package/dist/types/core/index.d.ts +1 -2
  18. package/dist/types/core/pointCloud/annotation.d.ts +11 -1
  19. package/dist/types/core/pointCloud/index.d.ts +11 -1
  20. package/dist/types/core/pointCloud/matrix.d.ts +1 -0
  21. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  22. package/dist/types/core/scheduler.d.ts +7 -2
  23. package/dist/types/core/toolOperation/ViewOperation.d.ts +3 -2
  24. package/dist/types/core/toolOperation/basicToolOperation.d.ts +11 -1
  25. package/dist/types/core/toolOperation/cuboidOperation.d.ts +155 -0
  26. package/dist/types/core/toolOperation/cuboidToggleButtonClass.d.ts +38 -0
  27. package/dist/types/utils/MathUtils.d.ts +1 -1
  28. package/dist/types/utils/tool/AttributeUtils.d.ts +7 -0
  29. package/dist/types/utils/tool/AxisUtils.d.ts +50 -1
  30. package/dist/types/utils/tool/CuboidUtils.d.ts +267 -0
  31. package/dist/types/utils/tool/DrawUtils.d.ts +12 -0
  32. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +4 -2
  33. package/dist/types/utils/tool/PolygonUtils.d.ts +5 -2
  34. package/dist/utils/MathUtils.js +2 -2
  35. package/dist/utils/tool/AttributeUtils.js +1 -1
  36. package/dist/utils/tool/AxisUtils.js +1 -1
  37. package/dist/utils/tool/CuboidUtils.js +1 -0
  38. package/dist/utils/tool/DrawUtils.js +3 -3
  39. package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -1
  40. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  41. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  42. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  43. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  44. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -0
  45. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -0
  46. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -0
  47. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -0
  48. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -0
  49. package/es/constant/annotation.js +1 -1
  50. package/es/constant/tool.js +1 -1
  51. package/es/core/pointCloud/annotation.js +1 -1
  52. package/es/core/pointCloud/index.js +2 -2
  53. package/es/core/pointCloud/segmentation.js +50 -0
  54. package/es/core/scheduler.js +1 -1
  55. package/es/core/toolOperation/ViewOperation.js +1 -1
  56. package/es/core/toolOperation/basicToolOperation.js +1 -1
  57. package/es/core/toolOperation/cuboidOperation.js +1 -0
  58. package/es/core/toolOperation/cuboidToggleButtonClass.js +31 -0
  59. package/es/core/toolOperation/scribbleTool2.js +249 -0
  60. package/es/utils/MathUtils.js +2 -2
  61. package/es/utils/tool/AttributeUtils.js +1 -1
  62. package/es/utils/tool/AxisUtils.js +1 -1
  63. package/es/utils/tool/CuboidUtils.js +1 -0
  64. package/es/utils/tool/DrawUtils.js +3 -3
  65. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -1
  66. package/package.json +3 -3
@@ -0,0 +1,249 @@
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.getCoordinateUnderZoom(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
+ };
56
+ this.penSize = DEFAULT_PEN_SIZE;
57
+ }
58
+ get color() {
59
+ var _a, _b;
60
+ return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
61
+ }
62
+ get penSizeWithZoom() {
63
+ return this.penSize / this.zoom;
64
+ }
65
+ setPenSize(size) {
66
+ this.penSize = size;
67
+ }
68
+ initCacheCanvas(imgNode) {
69
+ if (this.cacheCanvas || !imgNode) {
70
+ return;
71
+ }
72
+ const {canvas, ctx} = ImgConversionUtils.createCanvas(imgNode);
73
+ this.cacheCanvas = canvas;
74
+ this.cacheContext = ctx;
75
+ }
76
+ updateCacheCanvasSize(imgNode) {
77
+ if (this.cacheCanvas) {
78
+ this.cacheCanvas.width = imgNode.width;
79
+ this.cacheCanvas.height = imgNode.height;
80
+ }
81
+ }
82
+ updateUrl2CacheContext(url) {
83
+ ImgConversionUtils.createImgDom(url).then((img) => {
84
+ if (!this.cacheContext) {
85
+ this.initCacheCanvas(img);
86
+ }
87
+ if (this.cacheContext) {
88
+ this.cacheContext.save();
89
+ this.clearResult();
90
+ this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
91
+ this.cacheContext.restore();
92
+ this.render();
93
+ }
94
+ });
95
+ }
96
+ setImgNode(imgNode, basicImgInfo) {
97
+ super.setImgNode(imgNode, basicImgInfo);
98
+ if (this.cacheCanvas) {
99
+ this.updateCacheCanvasSize(imgNode);
100
+ } else {
101
+ this.initCacheCanvas(imgNode);
102
+ }
103
+ }
104
+ setResult(data) {
105
+ var _a;
106
+ const {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
107
+ this.history.initRecord([url], !!url);
108
+ this.clearResult();
109
+ if (!url) {
110
+ this.render();
111
+ return;
112
+ }
113
+ this.updateUrl2CacheContext(url);
114
+ }
115
+ onKeyDown(e) {
116
+ if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
117
+ return;
118
+ }
119
+ const {keyCode} = e;
120
+ const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
121
+ if (keyCode2Attribute !== void 0) {
122
+ this.setDefaultAttribute(keyCode2Attribute);
123
+ }
124
+ }
125
+ eventBinding() {
126
+ super.eventBinding();
127
+ }
128
+ setDefaultAttribute(attributeValue) {
129
+ const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
130
+ if (attributeInfo) {
131
+ this.defaultAttribute = attributeInfo.value;
132
+ this.defaultAttributeInfo = attributeInfo;
133
+ this.emit("changeAttributeSidebar");
134
+ this.render();
135
+ }
136
+ }
137
+ clearStatusAfterLeave() {
138
+ this.onScribbleEnd();
139
+ this.startPoint = void 0;
140
+ }
141
+ onMouseLeave() {
142
+ super.onMouseLeave();
143
+ this.clearStatusAfterLeave();
144
+ }
145
+ onScribbleStart(e) {
146
+ if (!this.cacheContext) {
147
+ return;
148
+ }
149
+ this.cacheContext.save();
150
+ this.cacheContext.beginPath();
151
+ this.cacheContext.strokeStyle = this.color;
152
+ this.cacheContext.lineWidth = this.penSizeWithZoom;
153
+ this.cacheContext.lineCap = "round";
154
+ this.cacheContext.lineJoin = "round";
155
+ const originCoordinate = AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
156
+ this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
157
+ this.startPoint = originCoordinate;
158
+ }
159
+ onScribbleMove(e) {
160
+ if (e.buttons === 1 && this.cacheContext && this.startPoint) {
161
+ const originCoordinate = this.getOriginCoordinate(e);
162
+ this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
163
+ this.cacheContext.stroke();
164
+ }
165
+ }
166
+ onScribbleEnd() {
167
+ var _a, _b, _c;
168
+ if (this.startPoint) {
169
+ (_a = this.cacheContext) == null ? void 0 : _a.closePath();
170
+ (_b = this.cacheContext) == null ? void 0 : _b.restore();
171
+ this.startPoint = void 0;
172
+ this.history.pushHistory((_c = this.cacheCanvas) == null ? void 0 : _c.toDataURL("image/png", 0));
173
+ }
174
+ }
175
+ eraseArc(e) {
176
+ var _a;
177
+ if (this.cacheContext) {
178
+ const originCoordinate = this.getOriginCoordinate(e);
179
+ this.cacheContext.save();
180
+ this.cacheContext.beginPath();
181
+ this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
182
+ this.cacheContext.clip();
183
+ this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
184
+ (_a = this.cacheContext) == null ? void 0 : _a.restore();
185
+ }
186
+ }
187
+ onEraseStart(e) {
188
+ if (!this.cacheContext || e.buttons !== 1) {
189
+ return;
190
+ }
191
+ this.eraseArc(e);
192
+ }
193
+ onEraseMove(e) {
194
+ if (!this.cacheContext || e.buttons !== 1) {
195
+ return;
196
+ }
197
+ this.eraseArc(e);
198
+ }
199
+ onEraseEnd() {
200
+ }
201
+ exportData() {
202
+ var _a;
203
+ const imgBase64 = (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
204
+ return [[], this.basicImgInfo, {imgBase64}];
205
+ }
206
+ clearCacheCanvas() {
207
+ var _a;
208
+ (_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
209
+ this.render();
210
+ }
211
+ clearResult() {
212
+ this.clearCacheCanvas();
213
+ }
214
+ renderPoint(radius) {
215
+ DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
216
+ }
217
+ render() {
218
+ super.render();
219
+ if (!this.ctx || !this.cacheCanvas) {
220
+ return;
221
+ }
222
+ this.ctx.save();
223
+ this.ctx.globalAlpha = 0.5;
224
+ DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
225
+ zoom: this.zoom,
226
+ currentPos: this.currentPos,
227
+ rotate: this.rotate
228
+ });
229
+ this.ctx.restore();
230
+ if (this.forbidOperation || this.forbidCursorLine) {
231
+ return;
232
+ }
233
+ this.renderPoint(this.penSize / 2);
234
+ }
235
+ undo() {
236
+ const url = this.history.undo();
237
+ if (url && this.cacheCanvas) {
238
+ this.updateUrl2CacheContext(url);
239
+ }
240
+ }
241
+ redo() {
242
+ const url = this.history.redo();
243
+ if (url && this.cacheCanvas) {
244
+ this.updateUrl2CacheContext(url);
245
+ }
246
+ }
247
+ }
248
+
249
+ export { ScribbleTool as default };
@@ -1,2 +1,2 @@
1
- import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,a=t.split(`
2
- `);let l=0;for(let f=0;f<a.length;f++){const u=a[f].split("");let g="";for(let y=0;y<u.length;y++){const p=g+u[y],P=i.measureText(p).width;P>o&&y>0?(g=u[y],n+=r,l=o):(g=p,P>l&&(l=P))}f!==a.length-1&&(n+=r)}return{width:l,height:n+c,lineHeight:r,fontHeight:c}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,c={x:i.x-n.x,y:i.y-n.y},a=h.add(t,c);return h.getVector(e,a)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const c=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,a=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=c,n[r]=a,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const c=h.getVector(o,n),a=h.len(c),l=c.y/a,f=c.x/a;return{x:a*M.cosAPlusB(l,f,r,i)+o.x,y:a*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,c=Math.acos(n);return r>0?Math.PI*2-c:c}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,c)=>{const{dropFoot:a}=w.getClosestPoint(n,c,T.Line,1,{isClose:!1});if(a!==n){const l=`${a.x} + ${a.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let c="";c=n.id,r.forEach((a,l)=>{if(a.id===c)return;const f=[...r];f.splice(l,1),a.pointList.forEach(u=>{i(u,f)})})}),{connectionPoints:t}}};let d=m;d.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},d.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},d.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let c=e;t&&(c=B(e,o)),c.forEach(({x:p,y:x})=>{i.push(p),n.push(x)});let a=Math.min(...i),l=Math.max(...i),f=Math.min(...n),u=Math.max(...n);const g=l-a,y=u-f;if(g<r){const p=(r-g)/2;a-=p,l+=p}if(y<r){const p=(r-y)/2;f-=p,u+=p}return{top:f,bottom:u,left:a,right:l}},d.getFootOfPerpendicular=(e,t,o,s=!1)=>{let r={x:0,y:0};const i=t.x-o.x,n=t.y-o.y;if(Math.abs(i)<1e-8&&Math.abs(n)<1e-8)return r=t,r;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=i*i+n*n,r.x=t.x+c*i,r.y=t.y+c*n;const a=m.getLineLength(e,r),l=2,f=Math.min(t.x,o.x),u=Math.max(t.x,o.x),g=Math.min(t.y,o.y),y=Math.max(t.y,o.y),p=!(m.isInRange(e.x,[f,u])||m.isInRange(e.y,[g,y])),x=e.x>u+l||e.x<f-l||e.y>y+l||e.y<g-l;return(s?p:x)?{footPoint:r,length:Infinity}:{footPoint:r,length:a}};var D=d;export{M as Trigonometric,D as default};
1
+ import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=t.split(`
2
+ `);let l=0;for(let f=0;f<c.length;f++){const p=c[f].split("");let g="";for(let y=0;y<p.length;y++){const u=g+p[y],d=i.measureText(u).width;d>o&&y>0?(g=p[y],n+=r,l=o):(g=u,d>l&&(l=d))}f!==c.length-1&&(n+=r)}return{width:l,height:n+a,lineHeight:r,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,a={x:i.x-n.x,y:i.y-n.y},c=h.add(t,a);return h.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const a=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,c=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=a,n[r]=c,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const a=h.getVector(o,n),c=h.len(a),l=a.y/c,f=a.x/c;return{x:c*M.cosAPlusB(l,f,r,i)+o.x,y:c*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,a=Math.acos(n);return r>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,a)=>{const{dropFoot:c}=w.getClosestPoint(n,a,T.Line,1,{isClose:!1});if(c!==n){const l=`${c.x} + ${c.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let a="";a=n.id,r.forEach((c,l)=>{if(c.id===a)return;const f=[...r];f.splice(l,1),c.pointList.forEach(p=>{i(p,f)})})}),{connectionPoints:t}}};let x=m;x.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},x.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},x.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let a=e;t&&(a=B(e,o)),a.forEach(({x:u,y:P})=>{i.push(u),n.push(P)});let c=Math.min(...i),l=Math.max(...i),f=Math.min(...n),p=Math.max(...n);const g=l-c,y=p-f;if(g<r){const u=(r-g)/2;c-=u,l+=u}if(y<r){const u=(r-y)/2;f-=u,p+=u}return{top:f,bottom:p,left:c,right:l}},x.getFootOfPerpendicular=(e,t,o,s=!1,r=!1)=>{let i={x:0,y:0};const n=t.x-o.x,a=t.y-o.y;if(Math.abs(n)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=n*n+a*a,i.x=t.x+c*n,i.y=t.y+c*a;const l=m.getLineLength(e,i),f=2,p=Math.min(t.x,o.x),g=Math.max(t.x,o.x),y=Math.min(t.y,o.y),u=Math.max(t.y,o.y),P=!(m.isInRange(e.x,[p,g])||m.isInRange(e.y,[y,u])),d=e.x>g+f||e.x<p-f||e.y>u+f||e.y<y-f;return!r&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:l}};var D=x;export{M as Trigonometric,D as default};
@@ -1 +1 @@
1
- import{isNumber as I}from"lodash";import{ICON_ARRAY as c,NULL_ICON as O,NULL_COLOR as g,COLORS_ARRAY as o}from"../../constant/style.js";import{ETextType as u}from"../../constant/tool.js";import l from"../../locales/index.js";import{EMessage as d}from"../../locales/constants.js";import p from"../MathUtils.js";import E from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var y=Object.defineProperty,N=Object.defineProperties,R=Object.getOwnPropertyDescriptors,x=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,v=(s,t,r)=>t in s?y(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r,b=(s,t)=>{for(var r in t||(t={}))P.call(t,r)&&v(s,r,t[r]);if(x)for(var r of x(t))w.call(t,r)&&v(s,r,t[r]);return s},h=(s,t)=>N(s,R(t));const _="^[0-9]+$",m="^[A-Za-z]+$";class T{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(A=>A.value===t);let i=(n=c[a%c.length])!=null?n:O;e||(i=E),i="";const f=new Image;return f.src=i,f}static checkString(t,r){let e="";switch(t){case u.Order:case u.NumberOnly:e=_;break;case u.EnglishOnly:e=m;break;case u.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?g:o[e%o.length]}catch(e){return g}}static getTextAttribute(t,r){try{if(r===u.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?h(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case u.Order:case u.NumberOnly:return l.getMessagesByLocale(d.TextCheckNumberErrorNotice,r);case u.EnglishOnly:return l.getMessagesByLocale(d.TextCheckEnglishErrorNotice,r);case u.CustomFormat:return l.getMessagesByLocale(d.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return h(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){if(e===!0){const a=(r==null?void 0:r.findIndex(i=>(i==null?void 0:i.value)===t))%o.length+1;return c[a]}return n}static getAttributeByKeycode(t,r){var e;let n;return p.isInRange(t,[48,57])&&(n=t-48),p.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{m as REGEXP_ENGLISH,_ as REGEXP_NUMBER,T as default};
1
+ import{isNumber as I}from"lodash";import{ToolStyleUtils as O}from"@labelbee/lb-utils";import{NULL_COLOR as f,COLORS_ARRAY as c,ICON_ARRAY as d,NULL_ICON as E}from"../../constant/style.js";import{ETextType as s}from"../../constant/tool.js";import g from"../../locales/index.js";import{EMessage as p}from"../../locales/constants.js";import h from"../MathUtils.js";import y from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var w=Object.defineProperty,N=Object.defineProperties,P=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,x=(l,t,r)=>t in l?w(l,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[t]=r,b=(l,t)=>{for(var r in t||(t={}))R.call(t,r)&&x(l,r,t[r]);if(v)for(var r of v(t))T.call(t,r)&&x(l,r,t[r]);return l},m=(l,t)=>N(l,P(t));const _="^[0-9]+$",A="^[A-Za-z]+$";class M{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(o=>o.value===t);let i=(n=d[a%d.length])!=null?n:E;e||(i=y),i="";const u=new Image;return u.src=i,u}static checkString(t,r){let e="";switch(t){case s.Order:case s.NumberOnly:e=_;break;case s.EnglishOnly:e=A;break;case s.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?f:c[e%c.length]}catch(e){return f}}static getTextAttribute(t,r){try{if(r===s.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?m(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case s.Order:case s.NumberOnly:return g.getMessagesByLocale(p.TextCheckNumberErrorNotice,r);case s.EnglishOnly:return g.getMessagesByLocale(p.TextCheckEnglishErrorNotice,r);case s.CustomFormat:return g.getMessagesByLocale(p.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return m(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){var a;if(e===!0){const i=(r==null?void 0:r.findIndex(o=>(o==null?void 0:o.value)===t))%c.length+1,u=(a=r==null?void 0:r.find(o=>o.value===t))==null?void 0:a.color;if(u){const o=O.rgbaStringToHex(u);return this.generateIconAttribute({fill:o})}return d[i]}return n}static generateIconAttribute({fill:t,width:r=16,height:e=16,xmlns:n="http://www.w3.org/2000/svg",xlink:a="http://www.w3.org/1999/xlink"}){return`<span style={color:${t}}><svg xmlns=${n} xmlns:xlink=${a} width=${r} height=${e} viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill='currentColor'/></g></g></svg></span>`}static getAttributeByKeycode(t,r){var e;let n;return h.isInRange(t,[48,57])&&(n=t-48),h.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{A as REGEXP_ENGLISH,_ as REGEXP_NUMBER,M as default};
@@ -1 +1 @@
1
- import{EToolName as f,ELineTypes as m}from"../../constant/tool.js";import y from"../MathUtils.js";import g from"./PolygonUtils.js";import u,{POINT_RADIUS as P}from"./LineToolUtils.js";var w=Object.defineProperty,_=Object.defineProperties,O=Object.getOwnPropertyDescriptors,p=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,I=(h,t,e)=>t in h?w(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,l=(h,t)=>{for(var e in t||(t={}))v.call(t,e)&&I(h,e,t[e]);if(p)for(var e of p(t))R.call(t,e)&&I(h,e,t[e]);return h},x=(h,t)=>_(h,O(t));class T{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,o,n,s){return typeof o=="boolean"&&!o&&(n&&s?(t.x-e.x>(n.x+n.width)*s&&(t.x=(n.x+n.width)*s+e.x),t.x-e.x<n.x*s&&(t.x=n.x*s+e.x),t.y-e.y>(n.y+n.height)*s&&(t.y=(n.y+n.height)*s+e.y),t.y-e.y<n.y*s&&(t.y=n.y*s+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:o,height:n}=i,{x:s,y:r}=t;switch(e%360){case 90:return{x:n-r,y:s};case 180:return{x:o-s,y:n-r};case 270:return{x:r,y:o-s};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return x(l({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return x(l({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(o=>this.changePointByZoom(o,e,i))}static axisArea(t,e=3){const{x:i,y:o}=t,n=[];for(let s=i-e;s<i+e;s+=e/3)for(let r=o-e;r<o+e;r+=e/3)n.push({x:s,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let o=-1;for(let n=0;n<e.length;n++){const s=e[n];this.getIsInScope(t,s,i)&&(o=n)}return o}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class D{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===f.Polygon}get isDependRect(){return this.dependToolName===f.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:o,width:n,height:s}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[o,o+s])}}getPolygonPointList(t,e){return t===m.Curve?g.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const o=this.getRenderCoord(e),n=this.getRenderCoord(t),s={pointA:o,pointB:n};return u.calcOptimalIntersection(i,s,o,P,this.zoom)}coordInsidePolygon(t,e,i,o){const{pointList:n}=i,s=o==null?void 0:o.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(s,n);if(g.isInPolygon(t,r))return t;const c=r.concat(r[0]).map(d=>this.getRenderCoord(d)),a=this.getIntersection(t,e,c);return a?this.getAbsCoord(a==null?void 0:a.point):t}coordInsideImage(t){return this.coordInsideRect(t,x(l({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:o,height:n}=this.basicResult,s=[e,e+o],r=[i,i+n];return y.isInRange(t.x,s)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return g.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{D as CoordinateUtils,T as default};
1
+ import{EToolName as u,ELineTypes as C}from"../../constant/tool.js";import y from"../MathUtils.js";import x from"./PolygonUtils.js";import _,{POINT_RADIUS as v}from"./LineToolUtils.js";import{getHighlightPoints as P,getHighlightLines as m,getCuboidHoverRange as L}from"./CuboidUtils.js";var B=Object.defineProperty,R=Object.defineProperties,D=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,w=(a,t,e)=>t in a?B(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&w(a,e,t[e]);if(O)for(var e of O(t))Z.call(t,e)&&w(a,e,t[e]);return a},c=(a,t)=>R(a,D(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:r}=t;switch(e%360){case 90:return{x:n-r,y:o};case 180:return{x:s-o,y:n-r};case 270:return{x:r,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static changePlanePointByZoom(t,e,i={x:0,y:0}){return Object.entries(t).reduce((s,[n,o])=>{const r=I.changePointByZoom(o,e,i);return c(f({},s),{[n]:r})},{})}static changeCuboidByZoom(t,e,i={x:0,y:0}){return c(f({},t),{frontPoints:this.changePlanePointByZoom(t.frontPoints,e,i),backPoints:t.backPoints?this.changePlanePointByZoom(t.backPoints,e,i):t.backPoints})}static transformPlain2PointList({tl:t,tr:e,br:i,bl:s}){return[t,e,i,s]}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let r=s-e;r<s+e;r+=e/3)n.push({x:o,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static isCloseCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5}=i;for(let r=0;r<s.length;r++){const l=s[r];if(this.getIsInScope(t,l.point,n))return!0}const o=m(e);for(let r=0;r<o.length;r++){const l=o[r],{length:p}=y.getFootOfPerpendicular(t,l.p1,l.p2,!0);if(p<n)return!0}return!!x.isInPolygon(t,L(e))}static isCloseCuboidList(t,e,i={scope:5,zoom:1}){return e.some(s=>this.isCloseCuboid(t,s,i))}static returnClosePointOrLineInCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5,zoom:o=1}=i;for(let h=0;h<s.length;h++){const g=s[h];if(this.getIsInScope(t,g.point,n))return[{type:"point",points:[this.changePointByZoom(s[h].point,o)],originCuboid:e,positions:g.positions}]}let r=n;const l=m(e);let p;for(let h=0;h<l.length;h++){const g=l[h],{length:d}=y.getFootOfPerpendicular(t,g.p1,g.p2,!0);d<r&&(r=d,p=[{type:"line",points:this.changePointListByZoom([g.p1,g.p2],o),originCuboid:e,positions:g.positions}])}if(p)return p}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class b{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===u.Polygon}get isDependRect(){return this.dependToolName===u.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===C.Curve?x.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return _.calcOptimalIntersection(i,o,s,v,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(o,n);if(x.isInPolygon(t,r))return t;const p=r.concat(r[0]).map(g=>this.getRenderCoord(g)),h=this.getIntersection(t,e,p);return h?this.getAbsCoord(h==null?void 0:h.point):t}coordInsideImage(t){return this.coordInsideRect(t,c(f({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],r=[i,i+n];return y.isInRange(t.x,o)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return x.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{b as CoordinateUtils,I as default};
@@ -0,0 +1 @@
1
+ import{cloneDeep as E}from"lodash";import{ECuboidPlain as a,ECuboidPosition as f,ECuboidDirection as w,EDragTarget as C,DIAGONAL_POINT as U,ECuboidLineDirection as O,CUBOID_ROW as X,CUBOID_COLUMN as Y}from"../../constant/annotation.js";import v from"./AxisUtils.js";import G from"../VectorUtils.js";import F from"./LineToolUtils.js";var V=Object.defineProperty,z=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,I=(n,t,i)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[t]=i,x=(n,t)=>{for(var i in t||(t={}))q.call(t,i)&&I(n,i,t[i]);if(D)for(var i of D(t))J.call(t,i)&&I(n,i,t[i]);return n},d=(n,t)=>z(n,Q(t));function m({tr:n,tl:t,br:i}){return{width:Math.abs(n.x-t.x),height:Math.abs(i.y-n.y),centerPoints:{x:(t.x+i.x)/2,y:(t.y+i.y)/2}}}function g({frontPoints:n,backPoints:t}){const{width:i,height:e,centerPoints:s}=m(n),{width:o,height:r,centerPoints:l}=m(t);return{frontCenter:s,backCenter:l,frontWidth:i,frontHeight:e,backWidth:o,backHeight:r,isLeftSide:l.x<s.x}}function S(n,t){return{tl:{x:Math.min(n.x,t.x),y:Math.min(n.y,t.y)},tr:{x:Math.max(n.x,t.x),y:Math.min(n.y,t.y)},bl:{x:Math.min(n.x,t.x),y:Math.max(n.y,t.y)},br:{x:Math.max(n.x,t.x),y:Math.max(n.y,t.y)}}}function _(n){const t=Object.values(n).reduce((o,r)=>r.x<o?r.x:o,Number.MAX_SAFE_INTEGER),i=Object.values(n).reduce((o,r)=>r.x>o?r.x:o,0),e=Object.values(n).reduce((o,r)=>r.y<o?r.y:o,Number.MAX_SAFE_INTEGER),s=Object.values(n).reduce((o,r)=>r.y>o?r.y:o,0);return{tl:{x:t,y:e},tr:{x:i,y:e},bl:{x:t,y:s},br:{x:i,y:s}}}function N(n){const[t,i]=n;if(X[t.position]===i.position)return O.Row;if(Y[t.position]===i.position)return O.Column}function M({coord:n,points:t}){const{width:i,height:e}=m(t);return{br:n,tr:{x:n.x,y:n.y-e},tl:{x:n.x-i,y:n.y-e},bl:{x:n.x-i,y:n.y}}}function j({coord:n,points:t}){const{width:i,height:e}=m(t);return{bl:n,tr:{x:n.x+i,y:n.y-e},tl:{x:n.x,y:n.y-e},br:{x:n.x+i,y:n.y}}}function H({frontPoints:n,backPoints:t}){const{isLeftSide:i}=g({frontPoints:n,backPoints:t});return i?{top:{p1:n.tl,p2:t.tl},bottom:{p1:n.bl,p2:t.bl}}:{top:{p1:n.tr,p2:t.tr},bottom:{p1:n.br,p2:t.br}}}function k({frontPoints:n,backPoints:t}){const{isLeftSide:i}=g({frontPoints:n,backPoints:t});let e=x({},t);const s=H({frontPoints:n,backPoints:t}),o=F.lineIntersection({pointA:s.bottom.p1,pointB:s.bottom.p2},{pointA:s.top.p1,pointB:s.top.p2});if(i){const r=F.lineIntersection({pointA:t.bl,pointB:t.br},{pointA:n.br,pointB:o});r&&(e=d(x({},t),{br:r,tr:{x:r.x,y:t.tl.y}}))}else{const r=F.lineIntersection({pointA:t.bl,pointB:t.br},{pointA:n.bl,pointB:o});r&&(e=d(x({},t),{bl:r,tl:{x:r.x,y:t.tr.y}}))}return{backPoints:e}}function R({frontPoints:n,backPoints:t}){const{isLeftSide:i,frontHeight:e,backHeight:s}=g({frontPoints:n,backPoints:t});let o=x({},t);return i?o=j({coord:t.bl,points:n}):o=M({coord:t.br,points:n}),e>s&&(o=k({frontPoints:n,backPoints:t}).backPoints),{frontPoints:n,backPoints:o}}function T({frontPoints:n,backPoints:t}){const{isLeftSide:i,frontHeight:e,backHeight:s,frontWidth:o,backWidth:r}=g({frontPoints:n,backPoints:t});let l=x({},n),p=t;return i||r>o?l=j({coord:n.bl,points:t}):l=M({coord:n.br,points:t}),e>s&&(l.tl.y=n.tl.y,l.tr.y=n.tr.y,p=k({backPoints:t,frontPoints:n}).backPoints),o>=r&&Object.keys(l).forEach(c=>{l[c].x=n[c].x}),{frontPoints:l,backPoints:p}}function K({frontPoints:n,backPoints:t}){return[{p1:n.bl,p2:t.bl},{p1:n.tl,p2:t.tl},{p1:n.tr,p2:t.tr},{p1:n.br,p2:t.br}]}function Z(n){const{frontPoints:t,backPoints:i}=n,{isLeftSide:e}=g(n),s=[{p1:t.tl,p2:t.tr,positions:[{plain:a.Front,position:f.TL},{plain:a.Front,position:f.TR}]},{p1:t.tr,p2:t.br,plain:a.Front,positions:[{plain:a.Front,position:f.TR},{plain:a.Front,position:f.BR}]},{p1:t.br,p2:t.bl,plain:a.Front,positions:[{plain:a.Front,position:f.BR},{plain:a.Front,position:f.BL}]},{p1:t.bl,p2:t.tl,plain:a.Front,positions:[{plain:a.Front,position:f.BL},{plain:a.Front,position:f.TL}]}];return e?[...s,{p1:i.tl,p2:i.bl,positions:[{plain:a.Back,position:f.TL},{plain:a.Back,position:f.BL}]}]:[...s,{p1:i.tr,p2:i.br,positions:[{plain:a.Back,position:f.TR},{plain:a.Back,position:f.BR}]}]}function $(n){const{backPoints:t}=n,{isLeftSide:i}=g(n),e=Object.entries(n.frontPoints).map(([s,o])=>({positions:[{plain:a.Front,position:s}],point:o}));return i?[{point:t.tl,positions:[{position:f.TL,plain:a.Back}]},{point:t.bl,positions:[{position:f.BL,plain:a.Back}]},...e]:[{point:t.tr,positions:[{position:f.TR,plain:a.Back}]},{point:t.br,positions:[{position:f.BR,plain:a.Back}]},...e]}function tt(n){const{frontPoints:t,backPoints:i}=n,{backCenter:e,frontCenter:s,frontHeight:o,frontWidth:r,backHeight:l,backWidth:p,isLeftSide:c}=g(n),u=Math.abs(r-p),y=Math.abs(o-l),P=Math.abs(s.x-e.x),B=Math.abs(s.y-e.y),h=P>u,b=B>y;return h||b?b&&!h?[t.tl,i.tl,i.tr,t.tr,t.br,t.bl]:h&&!b?c?[t.tl,t.tr,t.br,t.bl,i.bl,i.tl]:[t.tl,t.tr,i.tr,i.br,t.br,t.bl]:h&&b?c?[i.tl,i.tr,t.tr,t.br,t.bl,i.bl]:[t.tl,i.tl,i.tr,i.br,t.br,t.bl]:[]:[t.tl,t.tr,t.br,t.bl]}function W({offset:n,frontPoints:t,backPoints:i,positions:e}){let s=E(t),o=E(i);if((e==null?void 0:e.length)===2){const r=e.every(b=>b.plain===a.Front),l=!r,p=N([e[0],e[1]]),c=p===O.Row,u=p===O.Column;let y=n;c&&(y={x:0,y:n.y}),u&&(y={y:0,x:n.x}),r&&(e==null||e.forEach(({position:b})=>{const L=s,A=L[b];L[b]={x:A.x+y.x,y:A.y+y.y}}),s=_(s),o=_(o)),l&&Object.keys(o).forEach(b=>{o[b]={x:o[b].x+y.x,y:o[b].y+y.y}});const P=r?R:T,{frontPoints:B,backPoints:h}=P({frontPoints:s,backPoints:o});s=B,o=h}return{frontPoints:s,backPoints:o}}function nt({offset:n,cuboid:t,dragTarget:i,positions:e}){const{frontPoints:s,backPoints:o}=t;switch(i){case C.Cuboid:{const r=Object.entries(s).reduce((p,[c,u])=>d(x({},p),{[c]:{x:u.x+n.x,y:u.y+n.y}}),{}),l=Object.entries(o).reduce((p,[c,u])=>d(x({},p),{[c]:{x:u.x+n.x,y:u.y+n.y}}),{});return d(x({},t),{frontPoints:r,backPoints:l})}case C.Line:{const{frontPoints:r,backPoints:l}=W({offset:n,frontPoints:s,backPoints:o,positions:e});return d(x({},t),{frontPoints:r,backPoints:l})}case C.Point:{if(!(e==null?void 0:e[0]))return;const r=e[0],l=r.plain===a.Front,p=l?s:o;let c=p[r.position];const u=p[U[r.position]];if(!c||!u)return;c=G.add(c,n);const y=S(c,u),P=l?R:T;let B={frontPoints:s,backPoints:y};l&&(B={frontPoints:y,backPoints:o});const{frontPoints:h,backPoints:b}=P(B);return d(x({},t),{frontPoints:h,backPoints:b})}default:{console.error("No DragTarget");break}}}function it({direction:n,frontPoints:t,backPoints:i}){if(n&&t&&i){let e=t;switch(n){case w.Back:e=i;break;case w.Left:e={bl:i.bl,br:t.bl,tl:i.tl,tr:t.tl};break;case w.Right:e={bl:i.br,br:t.br,tl:i.tr,tr:t.tr};break;case w.Top:e={bl:i.tl,br:t.tl,tl:i.tr,tr:t.tr};break;default:e=t;break}return v.transformPlain2PointList(e)}}function et({cuboid:n,currentPos:t,zoom:i}){const{frontPoints:e}=n,s={width:40,height:74},o={x:(e.bl.x+e.tl.x)/2,y:(e.bl.y+e.tl.y)/2},r=s.width+10,l=s.height/2,p={x:o.x,y:o.y},c=v.getOffsetCoordinate(p,t,i);return{left:c.x-r,top:c.y-l}}function ot({cuboid:n,currentPos:t,zoom:i,leftOffset:e=16,topOffset:s=2}){const{frontPoints:o}=n,r={x:o.bl.x,y:o.bl.y},l=v.getOffsetCoordinate(r,t,i);return{left:l.x+e,top:l.y+s}}function rt({cuboid:n,config:t}){const{minHeight:i,minWidth:e}=t,{width:s,height:o}=m(n.frontPoints);return s>=e&&o>=i}export{R as getBackPointsByFrontPoints,K as getCuboidAllSideLine,g as getCuboidBasicInfo,nt as getCuboidDragMove,tt as getCuboidHoverRange,H as getCuboidShowingSideLine,ot as getCuboidTextAttributeOffset,T as getFrontPointsByBackPoints,Z as getHighlightLines,$ as getHighlightPoints,_ as getMaxExternalQuadrilateral,W as getNewPointsAfterOffset,S as getPlainPointsByDiagonalPoints,m as getPlanePointsBasicInfo,it as getPointListsByDirection,j as getPointsByBottomLeftPoint,M as getPointsByBottomRightPoint,k as getPointsByIntersection,et as getToggleDirectionButtonOffset,rt as isCuboidWithInLimits,N as judgeCuboidLineIsRowOrColumn};
@@ -1,3 +1,3 @@
1
- import{ELineTypes as x,SEGMENT_NUMBER as P,DEFAULT_FONT as S}from"../../constant/tool.js";import m from"./PolygonUtils.js";import T from"./UnitUtils.js";var _=Object.defineProperty,E=Object.defineProperties,k=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,A=(y,r,t)=>r in y?_(y,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[r]=t,F=(y,r)=>{for(var t in r||(r={}))O.call(r,t)&&A(y,t,r[t]);if(v)for(var t of v(r))D.call(r,t)&&A(y,t,r[t]);return y},W=(y,r)=>E(y,k(r));const M=1,I={x:0,y:0},R=0,w="";class b{static drawLine(r,t,l,o={}){const e=r.getContext("2d"),{color:s=w,thickness:n=1,lineCap:c="round",lineDash:a}=o;e.save(),e.strokeStyle=s,e.lineWidth=n,e.lineCap=c,a&&e.setLineDash(a),e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(l.x+1,l.y+1),e.stroke(),e.restore()}static drawRect(r,t,l={}){const o=r.getContext("2d"),{color:e=w,thickness:s=1,lineCap:n="round",hiddenText:c=!1,lineDash:a}=l;if(o.save(),o.strokeStyle=e,o.lineWidth=s,o.lineCap=n,Array.isArray(a)&&o.setLineDash(a),o.fillStyle=e,o.strokeRect(t.x,t.y,t.width,t.height),c===!1){let i="";if(t.attribute&&(i=`${i} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},i),t.textAttribute){const d=`${~~t.width} * ${~~t.height}`.length*7,g=0,u=Math.max(20,t.width-d);this.drawText(r,{x:t.x,y:t.y+t.height+20+g},t.textAttribute,{textMaxWidth:u})}}o.restore()}static drawRectWithFill(r,t,l={}){const o=r.getContext("2d"),{color:e=w}=l;o.save(),o.fillStyle=e,o.fillRect(t.x,t.y,t.width,t.height),o.restore()}static drawTagByDom(r,t,l){const o=r;if(!((t==null?void 0:t.length)>0))return;const e=document.createElement("div");return e.innerHTML=t,e.setAttribute("id",l),o==null||o.appendChild(e),e}static drawTag(r,t){var l;const o=r==null?void 0:r.parentNode,e=window.self.document.getElementById("tagToolTag");if(e&&o&&o.contains(e)&&(o==null||o.removeChild(e)),!((t==null?void 0:t.length)>0))return;const s=document.createElement("div");return s.innerHTML=(l=t.reduce((n,c)=>`${n}${c.keyName}: ${c.value.join(" \u3001 ")}
2
- `,""))!=null?l:"",s.setAttribute("id","tagToolTag"),o==null||o.appendChild(s),s}static drawLineWithPointList(r,t,l={}){if(t.length<2)return;const o=r.getContext("2d"),{color:e=w,thickness:s=1,lineCap:n="round",lineType:c=x.Line,lineDash:a,hoverEdgeIndex:i}=l;o.save(),(()=>{o.strokeStyle=e,o.lineWidth=s,o.lineCap=n,Array.isArray(a)?o.setLineDash(a):o.setLineDash([])})(),c===x.Curve?(i!==void 0&&i>-1&&t.push(t[0]),t=m.createSmoothCurvePointsFromPointList([...t],P),i!==void 0&&i>-1&&(t=t.slice((P+1)*i,(P+1)*(i+1)))):i!==void 0&&i>-1&&(t=[...t,t[0]],t=t.slice(i,i+2));const d=[];o.beginPath(),o.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&d.push({i1:h,i2:h+1}),o.lineTo(t[h+1].x,t[h+1].y);o.stroke(),o.save(),o.lineWidth=s*.8,o.lineCap="butt",o.strokeStyle="white",o.setLineDash([3,3]),d.forEach(h=>{const C=t[h.i1],p=t[h.i2];o.beginPath(),o.moveTo(C.x,C.y),o.lineTo(p.x,p.y),o.stroke()}),o.restore();const g=4,u=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,g+u,e),this.drawSpecialPoint(r,h,g,"white"))}),o.restore(),t}static drawCircle(r,t,l,o={}){const e=r.getContext("2d"),{startAngleDeg:s=0,endAngleDeg:n=360,thickness:c=1,color:a=w,fill:i=w}=o,f=T.deg2rad(s),d=T.deg2rad(n);e.save(),e.beginPath(),e.strokeStyle=a,e.fillStyle=i,e.lineWidth=c,e.arc(t.x,t.y,l,f,d,!1),e.stroke(),i&&e.fill(),e.closePath(),e.restore()}static drawCircleWithFill(r,t,l=3,o={}){const e=r.getContext("2d"),{color:s=w}=o;e.save();const n=T.deg2rad(0),c=T.deg2rad(360);e.fillStyle=s,e.beginPath(),e.arc(t.x,t.y,l,n,c,!1),e.fill(),e.restore()}static drawSpecialPoint(r,t,l=6,o){const e=r.getContext("2d"),{x:s,y:n}=t;e.save(),e.beginPath(),e.fillStyle=o;const c=l*1.5,a=c*Math.sqrt(3)/2,i=c/2;e.moveTo(s,n-c),e.lineTo(s-a,n+i),e.lineTo(s+a,n+i),e.closePath(),e.fill(),e.restore()}static drawPolygon(r,t,l={}){const{isClose:o=!1,lineType:e=x.Line}=l;return o===!0&&(t=[...t,t[0]]),e===x.Curve&&(t=m.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,W(F({},l),{lineType:x.Line})),t}static drawPolygonWithFill(r,t,l={}){if(t.length<2)return;const o=r.getContext("2d"),{color:e=w,lineType:s=x.Line}=l;o.save(),o.fillStyle=e,o.beginPath(),s===x.Curve&&(t=m.createSmoothCurvePointsFromPointList([...t,t[0]]));const[n,...c]=t;return o.moveTo(n.x,n.y),c.forEach(a=>{o.lineTo(a.x,a.y)}),o.fill(),o.restore(),t}static drawPolygonWithFillAndLine(r,t,l={}){const{strokeColor:o,fillColor:e,thickness:s,lineCap:n,isClose:c,lineType:a}=l,i=this.drawPolygon(r,t,{color:o,thickness:s,lineCap:n,isClose:c,lineType:a});return this.drawPolygonWithFill(r,t,{color:e,lineType:a}),i}static drawPolygonWithKeyPoint(r,t,l={}){const{pointColor:o="white",strokeColor:e}=l,s=this.drawPolygon(r,t,l);return s.forEach(n=>{this.drawCircleWithFill(r,n,4,{color:e}),this.drawCircleWithFill(r,n,3,{color:o})}),s}static drawSelectedPolygonWithFillAndLine(r,t,l={}){const{pointColor:o="white",strokeColor:e}=l,s=this.drawPolygonWithFillAndLine(r,t,l);return s.forEach(n=>{this.drawCircleWithFill(r,n,4,{color:e}),this.drawCircleWithFill(r,n,3,{color:o})}),s}static drawText(r,t,l,o={}){if(!l)return;const e=r.getContext("2d"),{color:s=w,font:n=S,shadowColor:c="",shadowBlur:a=0,shadowOffsetX:i=0,shadowOffsetY:f=0,textMaxWidth:d=164,offsetX:g=0,offsetY:u=0,textAlign:h="start",lineHeight:C}=o;e.save(),e.textAlign=h,e.fillStyle=s!=null?s:"white",e.font=n,e.shadowColor=c,e.shadowOffsetX=i,e.shadowOffsetY=f,e.shadowBlur=a,this.wrapText(r,`${l}`,t.x+g,t.y+u,d,C),e.restore()}static wrapText(r,t,l,o,e,s){if(typeof t!="string"||typeof l!="number"||typeof o!="number")return;const n=r.getContext("2d");typeof e=="undefined"&&(e=r&&r.width||300),typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
3
- `);for(let a=0;a<c.length;a++){const i=c[a].split("");let f="";for(let d=0;d<i.length;d++){const g=f+i[d],h=n.measureText(g).width;e||(e=300),h>e&&d>0?(n.fillText(f,l,o),f=i[d],o+=s):f=g}n.fillText(f,l,o),o+=s}}static drawArrow(r,t,l,o={}){const{color:e=w,thickness:s=1,lineCap:n="round",theta:c=30,headLen:a=10}=o,i=Math.atan2(t.y-l.y,t.x-l.x)*180/Math.PI,f=(i+c)*Math.PI/180,d=(i-c)*Math.PI/180,g=a*Math.cos(f),u=a*Math.sin(f),h=a*Math.cos(d),C=a*Math.sin(d);r.save(),r.strokeStyle=e,r.lineWidth=s,r.lineCap=n,r.beginPath(),r.moveTo(l.x+g,l.y+u),r.lineTo(l.x,l.y),r.lineTo(l.x+h,l.y+C),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,l,o={}){const e=r.getContext("2d");this.drawArrow(e,t,l,o)}}b.drawImg=(y,r,t={})=>{const l=y.getContext("2d"),{zoom:o=M,currentPos:e=I,rotate:s=R,imgAttribute:n}=t;switch(l.save(),s){case 0:l.translate(e.x,e.y);break;case 90:l.translate(e.x+r.height*o,e.y),l.rotate(90*Math.PI/180);break;case 180:l.translate(e.x+r.width*o,e.y+r.height*o),l.rotate(Math.PI);break;case 270:l.translate(e.x,e.y+r.width*o),l.rotate(270*Math.PI/180);break;default:l.translate(e.x,e.y);break}if(n){const{contrast:c,saturation:a,brightness:i}=n;l.filter=`saturate(${a+100}%) contrast(${c+100}%) brightness(${i+100}%)`}l.drawImage(r,0,0,r.width*o,r.height*o),l.restore()};export{b as default};
1
+ import{ELineTypes as u,SEGMENT_NUMBER as m,DEFAULT_FONT as E}from"../../constant/tool.js";import p from"./PolygonUtils.js";import C from"./UnitUtils.js";import S from"./AxisUtils.js";import{getCuboidAllSideLine as D,getPointListsByDirection as O}from"./CuboidUtils.js";var F=Object.defineProperty,W=Object.defineProperties,U=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,_=(r,t,i)=>t in r?F(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,T=(r,t)=>{for(var i in t||(t={}))M.call(t,i)&&_(r,i,t[i]);if(v)for(var i of v(t))I.call(t,i)&&_(r,i,t[i]);return r},b=(r,t)=>W(r,U(t));const R=1,L={x:0,y:0},$=0,g="",P=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=g,thickness:s=1,lineCap:c="round",lineDash:a}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=c,a&&o.setLineDash(a),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=g,thickness:l=1,lineCap:s="round",hiddenText:c=!1,lineDash:a}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(a)&&e.setLineDash(a),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),c===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const d=`${~~t.width} * ${~~t.height}`.length*7,y=0,w=Math.max(20,t.width-d);this.drawText(r,{x:t.x,y:t.y+t.height+20+y},t.textAttribute,{textMaxWidth:w})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=g}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,c)=>`${s}${c.keyName}: ${c.value.join(" \u3001 ")}
2
+ `,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=g,thickness:l=1,lineCap:s="round",lineType:c=u.Line,lineDash:a,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(a)?e.setLineDash(a):e.setLineDash([])})(),c===u.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=p.createSmoothCurvePointsFromPointList([...t],m),n!==void 0&&n>-1&&(t=t.slice((m+1)*n,(m+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const d=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&d.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),d.forEach(h=>{const x=t[h.i1],A=t[h.i2];e.beginPath(),e.moveTo(x.x,x.y),e.lineTo(A.x,A.y),e.stroke()}),e.restore();const y=4,w=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,y+w,o),this.drawSpecialPoint(r,h,y,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:c=1,color:a=g,fill:n=g}=e,f=C.deg2rad(l),d=C.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=a,o.fillStyle=n,o.lineWidth=c,o.arc(t.x,t.y,i,f,d,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=g}=e;o.save();const s=C.deg2rad(0),c=C.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,c,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const c=i*1.5,a=c*Math.sqrt(3)/2,n=c/2;o.moveTo(l,s-c),o.lineTo(l-a,s+n),o.lineTo(l+a,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=u.Line}=i;return e===!0&&(t=[...t,t[0]]),o===u.Curve&&(t=p.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,b(T({},i),{lineType:u.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=g,lineType:l=u.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===u.Curve&&(t=p.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...c]=t;return e.moveTo(s.x,s.y),c.forEach(a=>{e.lineTo(a.x,a.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:c,lineType:a}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:c,lineType:a});return this.drawPolygonWithFill(r,t,{color:o,lineType:a}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=g,font:s=E,shadowColor:c="",shadowBlur:a=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:d=164,offsetX:y=0,offsetY:w=0,textAlign:h="start",lineHeight:x}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=c,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=a,this.wrapText(r,`${i}`,t.x+y,t.y+w,d,x),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
3
+ `);for(let a=0;a<c.length;a++){const n=c[a].split("");let f="";for(let d=0;d<n.length;d++){const y=f+n[d],h=s.measureText(y).width;o||(o=300),h>o&&d>0?(s.fillText(f,i,e),f=n[d],e+=l):f=y}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=g,thickness:l=1,lineCap:s="round",theta:c=30,headLen:a=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+c)*Math.PI/180,d=(n-c)*Math.PI/180,y=a*Math.cos(f),w=a*Math.sin(f),h=a*Math.cos(d),x=a*Math.sin(d);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+y,i.y+w),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+x),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:c,fillColor:a}=i,n={color:s,thickness:c};if(e){const d=S.transformPlain2PointList(e);P.drawPolygon(r,d,b(T({},n),{isClose:!0}));const y=D(t);y==null||y.forEach(w=>{P.drawLine(r,w.p1,w.p2,T({},n))})}const f=S.transformPlain2PointList(l);if(o&&e&&l){const d=O({direction:o,frontPoints:l,backPoints:e});d&&P.drawPolygonWithFill(r,d,{color:a})}P.drawPolygon(r,f,b(T({},n),{isClose:!0}))}};let k=P;k.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=R,currentPos:l=L,rotate:s=$,imgAttribute:c}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(c){const{contrast:a,saturation:n,brightness:f}=c;e.filter=`saturate(${n+100}%) contrast(${a+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{k as default};
@@ -1 +1 @@
1
- import{EToolName as o,ECheckModel as n}from"../../constant/tool.js";import i from"../../core/toolOperation/ScribbleTool.js";import a from"../../core/toolOperation/checkOperation.js";import c from"../../core/toolOperation/polygonOperation.js";import{RectOperation as p}from"../../core/toolOperation/rectOperation.js";import l from"../../core/toolOperation/tagOperation.js";import m from"../../core/toolOperation/LineToolOperation.js";import s from"../../core/toolOperation/pointOperation.js";import O from"../../core/toolOperation/TextToolOperation.js";import T from"../../core/toolOperation/segmentByRect.js";import f from"./CommonToolUtils.js";const t=e=>{switch(e){case o.Rect:case o.RectTrack:return p;case o.SegmentByRect:return T;case o.Tag:return l;case o.Polygon:return c;case n.Check:return a;case o.Line:return m;case o.Point:return s;case o.Text:return O;case o.ScribbleTool:return i;default:throw new Error("not match tool")}};class r extends f{}r.getCurrentOperation=t;export{r as default,t as getCurrentOperation};
1
+ import{EToolName as o,ECheckModel as n}from"../../constant/tool.js";import i from"../../core/toolOperation/ScribbleTool.js";import a from"../../core/toolOperation/cuboidOperation.js";import p from"../../core/toolOperation/pointCloud2dOperation.js";import c from"../../core/toolOperation/checkOperation.js";import l from"../../core/toolOperation/polygonOperation.js";import{RectOperation as m}from"../../core/toolOperation/rectOperation.js";import s from"../../core/toolOperation/tagOperation.js";import O from"../../core/toolOperation/LineToolOperation.js";import u from"../../core/toolOperation/pointOperation.js";import T from"../../core/toolOperation/TextToolOperation.js";import f from"../../core/toolOperation/segmentByRect.js";import j from"./CommonToolUtils.js";const e=t=>{switch(t){case o.Rect:case o.RectTrack:return m;case o.SegmentByRect:return f;case o.Tag:return s;case o.Polygon:return l;case n.Check:return c;case o.Line:return O;case o.Point:return u;case o.Text:return T;case o.ScribbleTool:return i;case o.Cuboid:return a;case o.PointCloudPolygon:return p;default:throw new Error("not match tool")}};class r extends j{}r.getCurrentOperation=e;export{r as default,e as getCurrentOperation};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.13.0",
3
+ "version": "1.14.0-alpha.0",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -92,11 +92,11 @@
92
92
  "typescript": "^4.2.3"
93
93
  },
94
94
  "dependencies": {
95
- "@labelbee/lb-utils": "^1.6.0",
95
+ "@labelbee/lb-utils": "^1.7.0-alpha.0",
96
96
  "@turf/turf": "5.1.6",
97
97
  "color-rgba": "^2.3.0",
98
98
  "lodash": "^4.17.20",
99
99
  "three": ">=0.141.0"
100
100
  },
101
- "gitHead": "9be3cbf1aa9560340678721703ab9c137b9d91f5"
101
+ "gitHead": "86c10122b654945d5bcb0d6208551d4996a276f1"
102
102
  }