@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +8 -1
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
  3. package/dist/_virtual/filterBoxWorker.js +8 -1
  4. package/dist/_virtual/highlightWorker.js +8 -1
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
  17. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
  18. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
  19. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
  25. package/dist/constant/annotation.js +127 -1
  26. package/dist/constant/annotationTask.js +30 -1
  27. package/dist/constant/defaultConfig.js +266 -1
  28. package/dist/constant/keyCode.js +38 -1
  29. package/dist/constant/style.js +98 -1
  30. package/dist/constant/tool.js +236 -1
  31. package/dist/core/index.js +150 -1
  32. package/dist/core/pointCloud/OrbitControls.js +665 -1
  33. package/dist/core/pointCloud/PCDLoader.js +260 -2
  34. package/dist/core/pointCloud/annotation.js +215 -1
  35. package/dist/core/pointCloud/cache.js +53 -1
  36. package/dist/core/pointCloud/index.js +991 -5
  37. package/dist/core/pointCloud/matrix.js +138 -1
  38. package/dist/core/pointCloud/segmentation.js +144 -0
  39. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
  40. package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
  41. package/dist/core/scheduler.js +233 -1
  42. package/dist/core/toolOperation/LineToolOperation.js +1434 -1
  43. package/dist/core/toolOperation/ScribbleTool.js +292 -1
  44. package/dist/core/toolOperation/TextToolOperation.js +131 -1
  45. package/dist/core/toolOperation/ViewOperation.js +556 -1
  46. package/dist/core/toolOperation/basicToolOperation.js +881 -1
  47. package/dist/core/toolOperation/checkOperation.js +208 -1
  48. package/dist/core/toolOperation/cuboidOperation.js +754 -1
  49. package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
  50. package/dist/core/toolOperation/eventListener.js +37 -1
  51. package/dist/core/toolOperation/measureOperation.js +41 -1
  52. package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
  53. package/dist/core/toolOperation/pointOperation.js +696 -1
  54. package/dist/core/toolOperation/polygonOperation.js +1251 -1
  55. package/dist/core/toolOperation/rectOperation.js +1233 -1
  56. package/dist/core/toolOperation/segmentByRect.js +174 -1
  57. package/dist/core/toolOperation/tagOperation.js +201 -3
  58. package/dist/core/toolOperation/textAttributeClass.js +182 -16
  59. package/dist/index.js +185 -1
  60. package/dist/locales/constants.js +24 -1
  61. package/dist/locales/en_US/message.js +25 -1
  62. package/dist/locales/index.js +19 -1
  63. package/dist/locales/zh_CN/message.js +25 -1
  64. package/dist/newCore/CanvasScheduler.js +35 -1
  65. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  66. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  67. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  68. package/dist/utils/ActionsHistory.js +84 -1
  69. package/dist/utils/ImgUtils.js +23 -1
  70. package/dist/utils/MathUtils.js +385 -2
  71. package/dist/utils/VectorUtils.js +25 -1
  72. package/dist/utils/tool/AttributeUtils.js +218 -1
  73. package/dist/utils/tool/AxisUtils.js +340 -1
  74. package/dist/utils/tool/CanvasUtils.js +62 -1
  75. package/dist/utils/tool/CommonToolUtils.js +174 -1
  76. package/dist/utils/tool/CuboidUtils.js +704 -1
  77. package/dist/utils/tool/DblClickEventListener.js +102 -1
  78. package/dist/utils/tool/DrawUtils.js +492 -3
  79. package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
  80. package/dist/utils/tool/ImgPosUtils.js +58 -1
  81. package/dist/utils/tool/LineToolUtils.js +261 -1
  82. package/dist/utils/tool/MarkerUtils.js +56 -1
  83. package/dist/utils/tool/PolygonUtils.js +460 -1
  84. package/dist/utils/tool/RectUtils.js +155 -1
  85. package/dist/utils/tool/RenderDomClass.js +57 -7
  86. package/dist/utils/tool/RenderDomUtils.js +21 -4
  87. package/dist/utils/tool/StyleUtils.js +31 -1
  88. package/dist/utils/tool/TagUtils.js +129 -1
  89. package/dist/utils/tool/UnitUtils.js +12 -1
  90. package/dist/utils/tool/ZoomUtils.js +72 -1
  91. package/dist/utils/tool/polygonTool.js +133 -1
  92. package/dist/utils/uuid.js +26 -1
  93. package/es/_virtual/MathUtilsWorker.js +6 -1
  94. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  95. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  96. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
  97. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  98. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  99. package/es/_virtual/filterBoxWorker.js +6 -1
  100. package/es/_virtual/highlightWorker.js +6 -1
  101. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
  102. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
  103. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
  104. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
  105. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
  106. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
  107. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
  108. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
  109. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
  110. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
  111. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
  112. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
  113. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
  114. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
  115. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
  116. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
  117. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
  118. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
  119. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
  120. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
  121. package/es/constant/annotation.js +113 -1
  122. package/es/constant/annotationTask.js +25 -1
  123. package/es/constant/defaultConfig.js +260 -1
  124. package/es/constant/keyCode.js +36 -1
  125. package/es/constant/style.js +74 -1
  126. package/es/constant/tool.js +220 -1
  127. package/es/core/index.js +148 -1
  128. package/es/core/pointCloud/OrbitControls.js +661 -1
  129. package/es/core/pointCloud/PCDLoader.js +256 -2
  130. package/es/core/pointCloud/annotation.js +211 -1
  131. package/es/core/pointCloud/cache.js +49 -1
  132. package/es/core/pointCloud/index.js +962 -5
  133. package/es/core/pointCloud/matrix.js +109 -1
  134. package/es/core/pointCloud/segmentation.js +120 -0
  135. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
  136. package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
  137. package/es/core/scheduler.js +228 -1
  138. package/es/core/toolOperation/LineToolOperation.js +1421 -1
  139. package/es/core/toolOperation/ScribbleTool.js +290 -1
  140. package/es/core/toolOperation/TextToolOperation.js +129 -1
  141. package/es/core/toolOperation/ViewOperation.js +549 -1
  142. package/es/core/toolOperation/basicToolOperation.js +877 -1
  143. package/es/core/toolOperation/checkOperation.js +206 -1
  144. package/es/core/toolOperation/cuboidOperation.js +752 -1
  145. package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
  146. package/es/core/toolOperation/eventListener.js +35 -1
  147. package/es/core/toolOperation/measureOperation.js +39 -1
  148. package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
  149. package/es/core/toolOperation/pointOperation.js +690 -1
  150. package/es/core/toolOperation/polygonOperation.js +1245 -1
  151. package/es/core/toolOperation/rectOperation.js +1228 -1
  152. package/es/core/toolOperation/scribbleTool2.js +249 -0
  153. package/es/core/toolOperation/segmentByRect.js +172 -1
  154. package/es/core/toolOperation/tagOperation.js +199 -3
  155. package/es/core/toolOperation/textAttributeClass.js +180 -16
  156. package/es/index.js +46 -1
  157. package/es/locales/constants.js +22 -1
  158. package/es/locales/en_US/message.js +23 -1
  159. package/es/locales/index.js +17 -1
  160. package/es/locales/zh_CN/message.js +23 -1
  161. package/es/newCore/CanvasScheduler.js +31 -1
  162. package/es/utils/ActionsHistory.js +78 -1
  163. package/es/utils/ImgUtils.js +21 -1
  164. package/es/utils/MathUtils.js +380 -2
  165. package/es/utils/VectorUtils.js +23 -1
  166. package/es/utils/tool/AttributeUtils.js +212 -1
  167. package/es/utils/tool/AxisUtils.js +335 -1
  168. package/es/utils/tool/CanvasUtils.js +60 -1
  169. package/es/utils/tool/CommonToolUtils.js +172 -1
  170. package/es/utils/tool/CuboidUtils.js +680 -1
  171. package/es/utils/tool/DblClickEventListener.js +100 -1
  172. package/es/utils/tool/DrawUtils.js +490 -3
  173. package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
  174. package/es/utils/tool/ImgPosUtils.js +56 -1
  175. package/es/utils/tool/LineToolUtils.js +255 -1
  176. package/es/utils/tool/MarkerUtils.js +54 -1
  177. package/es/utils/tool/PolygonUtils.js +458 -1
  178. package/es/utils/tool/RectUtils.js +153 -1
  179. package/es/utils/tool/RenderDomClass.js +55 -7
  180. package/es/utils/tool/RenderDomUtils.js +19 -4
  181. package/es/utils/tool/StyleUtils.js +29 -1
  182. package/es/utils/tool/TagUtils.js +127 -1
  183. package/es/utils/tool/UnitUtils.js +10 -1
  184. package/es/utils/tool/ZoomUtils.js +70 -1
  185. package/es/utils/tool/polygonTool.js +126 -1
  186. package/es/utils/uuid.js +24 -1
  187. package/package.json +7 -5
@@ -1 +1,100 @@
1
- import n from"./AxisUtils.js";class m{constructor(e,s){this.rcTime=0,this.mouseDownTime=0,this.onMouseDown=()=>{this.mouseDownTime=new Date().getTime()},this.dom=e,this.isDoubleClick=!1,this.delay=s}getRcTime(){return this.rcTime}getCoord(e){return{x:e.clientX,y:e.clientY}}removeEvent(){!this.dom||(this.dom.removeEventListener("mouseup",this.mouseUp),this.dom.removeEventListener("mousemove",this.mouseMove),this.dom.removeEventListener("dblclick",this.dblclick),this.dom.removeEventListener("mousedown",this.onMouseDown))}addEvent(e,s,c,o){!this.dom||(this.removeEvent(),this.mouseUp=i=>{const t=new Date().getTime(),h=o?o(i):!0;if(t-this.mouseDownTime>this.delay||h!==!0){e(i);return}if(i.button===2)if(this.rcTime===0)setTimeout(()=>{this.rcTime=0},this.delay),this.rcTime=t;else{t-this.rcTime<this.delay&&(c(i),clearTimeout(this.setTimeFun),this.cacheFunction=void 0),this.rcTime=0;return}this.setTimeFun&&clearTimeout(this.setTimeFun),this.clickCoord=this.getCoord(i),this.cacheFunction=()=>e(i),this.setTimeFun=setTimeout(()=>{if(this.isDoubleClick){this.isDoubleClick=!1;return}this.cacheFunction(),this.clickCoord=void 0},this.delay)},this.mouseMove=i=>{const t=this.getCoord(i);this.clickCoord&&!n.getIsInScope(t,this.clickCoord,10)&&(this.cacheFunction&&this.cacheFunction(),this.clickCoord=void 0,this.cacheFunction=null,clearTimeout(this.setTimeFun))},this.dblclick=i=>{this.isDoubleClick=!0,this.clickCoord=void 0,s(i)},this.dom.addEventListener("mouseup",this.mouseUp),this.dom.addEventListener("mousemove",this.mouseMove),this.dom.addEventListener("dblclick",this.dblclick),this.dom.addEventListener("mousedown",this.onMouseDown))}clearRightDblClick(){this.rcTime=0}}export{m as default};
1
+ import AxisUtils from './AxisUtils.js';
2
+
3
+ class DblClickEventListener {
4
+ constructor(dom, delay) {
5
+ this.rcTime = 0;
6
+ this.mouseDownTime = 0;
7
+ this.onMouseDown = () => {
8
+ this.mouseDownTime = new Date().getTime();
9
+ };
10
+ this.dom = dom;
11
+ this.isDoubleClick = false;
12
+ this.delay = delay;
13
+ }
14
+ getRcTime() {
15
+ return this.rcTime;
16
+ }
17
+ getCoord(e) {
18
+ return {
19
+ x: e.clientX,
20
+ y: e.clientY
21
+ };
22
+ }
23
+ removeEvent() {
24
+ if (!this.dom) {
25
+ return;
26
+ }
27
+ this.dom.removeEventListener("mouseup", this.mouseUp);
28
+ this.dom.removeEventListener("mousemove", this.mouseMove);
29
+ this.dom.removeEventListener("dblclick", this.dblclick);
30
+ this.dom.removeEventListener("mousedown", this.onMouseDown);
31
+ }
32
+ addEvent(singleClickFun, leftDblClick, rightDblClick, isAllowDouble) {
33
+ if (!this.dom) {
34
+ return;
35
+ }
36
+ this.removeEvent();
37
+ this.mouseUp = (e) => {
38
+ const cTime = new Date().getTime();
39
+ const isDoubleClick = isAllowDouble ? isAllowDouble(e) : true;
40
+ if (cTime - this.mouseDownTime > this.delay || isDoubleClick !== true) {
41
+ singleClickFun(e);
42
+ return;
43
+ }
44
+ if (e.button === 2) {
45
+ if (this.rcTime === 0) {
46
+ setTimeout(() => {
47
+ this.rcTime = 0;
48
+ }, this.delay);
49
+ this.rcTime = cTime;
50
+ } else {
51
+ if (cTime - this.rcTime < this.delay) {
52
+ rightDblClick(e);
53
+ clearTimeout(this.setTimeFun);
54
+ this.cacheFunction = void 0;
55
+ }
56
+ this.rcTime = 0;
57
+ return;
58
+ }
59
+ }
60
+ if (this.setTimeFun) {
61
+ clearTimeout(this.setTimeFun);
62
+ }
63
+ this.clickCoord = this.getCoord(e);
64
+ this.cacheFunction = () => singleClickFun(e);
65
+ this.setTimeFun = setTimeout(() => {
66
+ if (this.isDoubleClick) {
67
+ this.isDoubleClick = false;
68
+ return;
69
+ }
70
+ this.cacheFunction();
71
+ this.clickCoord = void 0;
72
+ }, this.delay);
73
+ };
74
+ this.mouseMove = (e) => {
75
+ const currentCoord = this.getCoord(e);
76
+ if (this.clickCoord && !AxisUtils.getIsInScope(currentCoord, this.clickCoord, 10)) {
77
+ if (this.cacheFunction) {
78
+ this.cacheFunction();
79
+ }
80
+ this.clickCoord = void 0;
81
+ this.cacheFunction = null;
82
+ clearTimeout(this.setTimeFun);
83
+ }
84
+ };
85
+ this.dblclick = (e) => {
86
+ this.isDoubleClick = true;
87
+ this.clickCoord = void 0;
88
+ leftDblClick(e);
89
+ };
90
+ this.dom.addEventListener("mouseup", this.mouseUp);
91
+ this.dom.addEventListener("mousemove", this.mouseMove);
92
+ this.dom.addEventListener("dblclick", this.dblclick);
93
+ this.dom.addEventListener("mousedown", this.onMouseDown);
94
+ }
95
+ clearRightDblClick() {
96
+ this.rcTime = 0;
97
+ }
98
+ }
99
+
100
+ export { DblClickEventListener as default };
@@ -1,3 +1,490 @@
1
- import{ELineTypes as P,SEGMENT_NUMBER as p,DEFAULT_FONT as O}from"../../constant/tool.js";import b from"./PolygonUtils.js";import T from"./UnitUtils.js";import S from"./AxisUtils.js";import{getCuboidAllSideLine as D,getPointListsByDirection as W,getCuboidTextAttributeOffset as F}from"./CuboidUtils.js";import M from"./AttributeUtils.js";var U=Object.defineProperty,I=Object.defineProperties,R=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,k=(r,t,i)=>t in r?U(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))$.call(t,i)&&k(r,i,t[i]);if(v)for(var i of v(t))L.call(t,i)&&k(r,i,t[i]);return r},A=(r,t)=>I(r,R(t));const j=1,B={x:0,y:0},X=0,u="",x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=u,thickness:s=1,lineCap:a="round",lineDash:d}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=a,d&&o.setLineDash(d),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=u,thickness:l=1,lineCap:s="round",hiddenText:a=!1,lineDash:d}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)&&e.setLineDash(d),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),a===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,w=0,y=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+w},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=u}=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,a)=>`${s}${a.keyName}: ${a.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=u,thickness:l=1,lineCap:s="round",lineType:a=P.Line,lineDash:d,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)?e.setLineDash(d):e.setLineDash([])})(),a===P.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=b.createSmoothCurvePointsFromPointList([...t],p),n!==void 0&&n>-1&&(t=t.slice((p+1)*n,(p+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.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]),c.forEach(h=>{const g=t[h.i1],C=t[h.i2];e.beginPath(),e.moveTo(g.x,g.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const w=4,y=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,w+y,o),this.drawSpecialPoint(r,h,w,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:a=1,color:d=u,fill:n=u}=e,f=T.deg2rad(l),c=T.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=d,o.fillStyle=n,o.lineWidth=a,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=u}=e;o.save();const s=T.deg2rad(0),a=T.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,a,!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 a=i*1.5,d=a*Math.sqrt(3)/2,n=a/2;o.moveTo(l,s-a),o.lineTo(l-d,s+n),o.lineTo(l+d,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=P.Line}=i;return e===!0&&(t=[...t,t[0]]),o===P.Curve&&(t=b.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,A(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=u,lineType:l=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===P.Curve&&(t=b.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...a]=t;return e.moveTo(s.x,s.y),a.forEach(d=>{e.lineTo(d.x,d.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:a,lineType:d}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:a,lineType:d});return this.drawPolygonWithFill(r,t,{color:o,lineType:d}),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=u,font:s=O,shadowColor:a="",shadowBlur:d=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:w=0,offsetY:y=0,textAlign:h="start",lineHeight:g}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=a,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=d,this.wrapText(r,`${i}`,t.x+w,t.y+y,c,g),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 a=t.split(`
3
- `);for(let d=0;d<a.length;d++){const n=a[d].split("");let f="";for(let c=0;c<n.length;c++){const w=f+n[c],h=s.measureText(w).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=n[c],e+=l):f=w}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=u,thickness:l=1,lineCap:s="round",theta:a=30,headLen:d=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+a)*Math.PI/180,c=(n-a)*Math.PI/180,w=d*Math.cos(f),y=d*Math.sin(f),h=d*Math.cos(c),g=d*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+w,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+g),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:a,fillColor:d}=i,n={color:s,thickness:a};if(e){const c=S.transformPlain2PointList(e);x.drawPolygon(r,c,A(m({},n),{isClose:!0}));const w=D(t);w==null||w.forEach(y=>{x.drawLine(r,y.p1,y.p2,m({},n))})}const f=S.transformPlain2PointList(l);if(o&&e&&l){const c=W({direction:o,frontPoints:l,backPoints:e});c&&x.drawPolygonWithFill(r,c,{color:d})}x.drawPolygon(r,f,A(m({},n),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:a,selectedID:d,headerText:n,bottomText:f}=e,{backPoints:c,frontPoints:w,textAttribute:y}=t,h=w.br.x-w.bl.x;x.drawCuboid(r,t,i);let g="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.attribute&&(g=`${g} ${M.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!a&&c&&g&&x.drawText(r,{x:c.tl.x,y:c.tl.y-5},n!=null?n:g,{color:o,textMaxWidth:300});const C=F({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!a&&y&&t.id!==d){const E=Math.max(20,h*.8);x.drawText(r,{x:C.left,y:C.top},f!=null?f:y,{color:l,textMaxWidth:E})}}};let _=x;_.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=j,currentPos:l=B,rotate:s=X,imgAttribute:a}=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(a){const{contrast:d,saturation:n,brightness:f}=a;e.filter=`saturate(${n+100}%) contrast(${d+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{_ as default};
1
+ import { ELineTypes, SEGMENT_NUMBER, DEFAULT_FONT } from '../../constant/tool.js';
2
+ import PolygonUtils from './PolygonUtils.js';
3
+ import UnitUtils from './UnitUtils.js';
4
+ import AxisUtils from './AxisUtils.js';
5
+ import { getCuboidAllSideLine, getPointListsByDirection, getCuboidTextAttributeOffset } from './CuboidUtils.js';
6
+ import AttributeUtils from './AttributeUtils.js';
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __defProps = Object.defineProperties;
10
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
11
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ const DEFAULT_ZOOM = 1;
28
+ const DEFAULT_CURRENT_POS = {
29
+ x: 0,
30
+ y: 0
31
+ };
32
+ const DEFAULT_ROTATE = 0;
33
+ const DEFAULT_COLOR = "";
34
+ const _DrawUtils = class {
35
+ static drawLine(canvas, startPoint, endPoint, options = {}) {
36
+ const ctx = canvas.getContext("2d");
37
+ const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", lineDash} = options;
38
+ ctx.save();
39
+ ctx.strokeStyle = color;
40
+ ctx.lineWidth = thickness;
41
+ ctx.lineCap = lineCap;
42
+ if (lineDash) {
43
+ ctx.setLineDash(lineDash);
44
+ }
45
+ ctx.beginPath();
46
+ ctx.moveTo(startPoint.x, startPoint.y);
47
+ ctx.lineTo(endPoint.x + 1, endPoint.y + 1);
48
+ ctx.stroke();
49
+ ctx.restore();
50
+ }
51
+ static drawRect(canvas, rect, options = {}) {
52
+ const ctx = canvas.getContext("2d");
53
+ const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", hiddenText = false, lineDash} = options;
54
+ ctx.save();
55
+ ctx.strokeStyle = color;
56
+ ctx.lineWidth = thickness;
57
+ ctx.lineCap = lineCap;
58
+ if (Array.isArray(lineDash)) {
59
+ ctx.setLineDash(lineDash);
60
+ }
61
+ ctx.fillStyle = color;
62
+ ctx.strokeRect(rect.x, rect.y, rect.width, rect.height);
63
+ if (hiddenText === false) {
64
+ let showText = "";
65
+ if (rect.attribute) {
66
+ showText = `${showText} ${rect.attribute}`;
67
+ }
68
+ this.drawText(canvas, {x: rect.x, y: rect.y - 5}, showText);
69
+ if (rect.textAttribute) {
70
+ const text = `${~~rect.width} * ${~~rect.height}`;
71
+ const textSizeWidth = text.length * 7;
72
+ const marginTop = 0;
73
+ const textWidth = Math.max(20, rect.width - textSizeWidth);
74
+ this.drawText(canvas, {x: rect.x, y: rect.y + rect.height + 20 + marginTop}, rect.textAttribute, {
75
+ textMaxWidth: textWidth
76
+ });
77
+ }
78
+ }
79
+ ctx.restore();
80
+ }
81
+ static drawRectWithFill(canvas, rect, options = {}) {
82
+ const ctx = canvas.getContext("2d");
83
+ const {color = DEFAULT_COLOR} = options;
84
+ ctx.save();
85
+ ctx.fillStyle = color;
86
+ ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
87
+ ctx.restore();
88
+ }
89
+ static drawTagByDom(parent, text, id) {
90
+ const parentNode = parent;
91
+ if (!((text == null ? void 0 : text.length) > 0)) {
92
+ return;
93
+ }
94
+ const dom = document.createElement("div");
95
+ dom.innerHTML = text;
96
+ dom.setAttribute("id", id);
97
+ parentNode == null ? void 0 : parentNode.appendChild(dom);
98
+ return dom;
99
+ }
100
+ static drawTag(canvas, tagList) {
101
+ var _a;
102
+ const parentNode = canvas == null ? void 0 : canvas.parentNode;
103
+ const oldDom = window.self.document.getElementById("tagToolTag");
104
+ if (oldDom && parentNode && parentNode.contains(oldDom)) {
105
+ parentNode == null ? void 0 : parentNode.removeChild(oldDom);
106
+ }
107
+ if (!((tagList == null ? void 0 : tagList.length) > 0)) {
108
+ return;
109
+ }
110
+ const dom = document.createElement("div");
111
+ dom.innerHTML = (_a = tagList.reduce((acc, cur) => {
112
+ return `${acc}${cur.keyName}: ${cur.value.join(` \u3001 `)}
113
+ `;
114
+ }, "")) != null ? _a : "";
115
+ dom.setAttribute("id", "tagToolTag");
116
+ parentNode == null ? void 0 : parentNode.appendChild(dom);
117
+ return dom;
118
+ }
119
+ static drawLineWithPointList(canvas, pointList, options = {}) {
120
+ if (pointList.length < 2) {
121
+ return;
122
+ }
123
+ const ctx = canvas.getContext("2d");
124
+ const {
125
+ color = DEFAULT_COLOR,
126
+ thickness = 1,
127
+ lineCap = "round",
128
+ lineType = ELineTypes.Line,
129
+ lineDash,
130
+ hoverEdgeIndex
131
+ } = options;
132
+ ctx.save();
133
+ const setStyle = () => {
134
+ ctx.strokeStyle = color;
135
+ ctx.lineWidth = thickness;
136
+ ctx.lineCap = lineCap;
137
+ if (Array.isArray(lineDash)) {
138
+ ctx.setLineDash(lineDash);
139
+ } else {
140
+ ctx.setLineDash([]);
141
+ }
142
+ };
143
+ setStyle();
144
+ if (lineType === ELineTypes.Curve) {
145
+ if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
146
+ pointList.push(pointList[0]);
147
+ }
148
+ pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList], SEGMENT_NUMBER);
149
+ if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
150
+ pointList = pointList.slice((SEGMENT_NUMBER + 1) * hoverEdgeIndex, (SEGMENT_NUMBER + 1) * (hoverEdgeIndex + 1));
151
+ }
152
+ } else if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
153
+ pointList = [...pointList, pointList[0]];
154
+ pointList = pointList.slice(hoverEdgeIndex, hoverEdgeIndex + 2);
155
+ }
156
+ const specialEdgeList = [];
157
+ ctx.beginPath();
158
+ ctx.moveTo(pointList[0].x, pointList[0].y);
159
+ for (let i = 0; i < pointList.length - 1; i++) {
160
+ if (pointList[i].specialEdge) {
161
+ specialEdgeList.push({
162
+ i1: i,
163
+ i2: i + 1
164
+ });
165
+ }
166
+ ctx.lineTo(pointList[i + 1].x, pointList[i + 1].y);
167
+ }
168
+ ctx.stroke();
169
+ ctx.save();
170
+ ctx.lineWidth = thickness * 0.8;
171
+ ctx.lineCap = "butt";
172
+ ctx.strokeStyle = "white";
173
+ ctx.setLineDash([3, 3]);
174
+ specialEdgeList.forEach((v) => {
175
+ const point1 = pointList[v.i1];
176
+ const point2 = pointList[v.i2];
177
+ ctx.beginPath();
178
+ ctx.moveTo(point1.x, point1.y);
179
+ ctx.lineTo(point2.x, point2.y);
180
+ ctx.stroke();
181
+ });
182
+ ctx.restore();
183
+ const DEFAULT_SPECIAL_POINT_RADIUS = 4;
184
+ const DEFAULT_BORDER = 2;
185
+ pointList.forEach((p) => {
186
+ if (p.specialPoint) {
187
+ this.drawSpecialPoint(canvas, p, DEFAULT_SPECIAL_POINT_RADIUS + DEFAULT_BORDER, color);
188
+ this.drawSpecialPoint(canvas, p, DEFAULT_SPECIAL_POINT_RADIUS, "white");
189
+ }
190
+ });
191
+ ctx.restore();
192
+ return pointList;
193
+ }
194
+ static drawCircle(canvas, anchorPoint, radius, options = {}) {
195
+ const ctx = canvas.getContext("2d");
196
+ const {
197
+ startAngleDeg = 0,
198
+ endAngleDeg = 360,
199
+ thickness = 1,
200
+ color = DEFAULT_COLOR,
201
+ fill = DEFAULT_COLOR
202
+ } = options;
203
+ const startAngleRad = UnitUtils.deg2rad(startAngleDeg);
204
+ const endAngleRad = UnitUtils.deg2rad(endAngleDeg);
205
+ ctx.save();
206
+ ctx.beginPath();
207
+ ctx.strokeStyle = color;
208
+ ctx.fillStyle = fill;
209
+ ctx.lineWidth = thickness;
210
+ ctx.arc(anchorPoint.x, anchorPoint.y, radius, startAngleRad, endAngleRad, false);
211
+ ctx.stroke();
212
+ if (fill) {
213
+ ctx.fill();
214
+ }
215
+ ctx.closePath();
216
+ ctx.restore();
217
+ }
218
+ static drawCircleWithFill(canvas, anchorPoint, radius = 3, options = {}) {
219
+ const ctx = canvas.getContext("2d");
220
+ const {color = DEFAULT_COLOR} = options;
221
+ ctx.save();
222
+ const startAngleRad = UnitUtils.deg2rad(0);
223
+ const endAngleRad = UnitUtils.deg2rad(360);
224
+ ctx.fillStyle = color;
225
+ ctx.beginPath();
226
+ ctx.arc(anchorPoint.x, anchorPoint.y, radius, startAngleRad, endAngleRad, false);
227
+ ctx.fill();
228
+ ctx.restore();
229
+ }
230
+ static drawSpecialPoint(canvas, point, pointRadius = 6, fillStyle) {
231
+ const ctx = canvas.getContext("2d");
232
+ const {x, y} = point;
233
+ ctx.save();
234
+ ctx.beginPath();
235
+ ctx.fillStyle = fillStyle;
236
+ const newPointRadius = pointRadius * 1.5;
237
+ const xl = newPointRadius * Math.sqrt(3) / 2;
238
+ const yl = newPointRadius / 2;
239
+ ctx.moveTo(x, y - newPointRadius);
240
+ ctx.lineTo(x - xl, y + yl);
241
+ ctx.lineTo(x + xl, y + yl);
242
+ ctx.closePath();
243
+ ctx.fill();
244
+ ctx.restore();
245
+ }
246
+ static drawPolygon(canvas, pointList, options = {}) {
247
+ const {isClose = false, lineType = ELineTypes.Line} = options;
248
+ if (isClose === true) {
249
+ pointList = [...pointList, pointList[0]];
250
+ }
251
+ if (lineType === ELineTypes.Curve) {
252
+ pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList]);
253
+ }
254
+ this.drawLineWithPointList(canvas, pointList, __spreadProps(__spreadValues({}, options), {
255
+ lineType: ELineTypes.Line
256
+ }));
257
+ return pointList;
258
+ }
259
+ static drawPolygonWithFill(canvas, pointList, options = {}) {
260
+ if (pointList.length < 2) {
261
+ return;
262
+ }
263
+ const ctx = canvas.getContext("2d");
264
+ const {color = DEFAULT_COLOR, lineType = ELineTypes.Line} = options;
265
+ ctx.save();
266
+ ctx.fillStyle = color;
267
+ ctx.beginPath();
268
+ if (lineType === ELineTypes.Curve) {
269
+ pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList, pointList[0]]);
270
+ }
271
+ const [startPoint, ...otherPointList] = pointList;
272
+ ctx.moveTo(startPoint.x, startPoint.y);
273
+ otherPointList.forEach((point) => {
274
+ ctx.lineTo(point.x, point.y);
275
+ });
276
+ ctx.fill();
277
+ ctx.restore();
278
+ return pointList;
279
+ }
280
+ static drawPolygonWithFillAndLine(canvas, pointList, options = {}) {
281
+ const {strokeColor, fillColor, thickness, lineCap, isClose, lineType} = options;
282
+ const newPointList = this.drawPolygon(canvas, pointList, {
283
+ color: strokeColor,
284
+ thickness,
285
+ lineCap,
286
+ isClose,
287
+ lineType
288
+ });
289
+ this.drawPolygonWithFill(canvas, pointList, {color: fillColor, lineType});
290
+ return newPointList;
291
+ }
292
+ static drawPolygonWithKeyPoint(canvas, pointList, options = {}) {
293
+ const {pointColor = "white", strokeColor} = options;
294
+ const newPointList = this.drawPolygon(canvas, pointList, options);
295
+ newPointList.forEach((point) => {
296
+ this.drawCircleWithFill(canvas, point, 4, {color: strokeColor});
297
+ this.drawCircleWithFill(canvas, point, 3, {color: pointColor});
298
+ });
299
+ return newPointList;
300
+ }
301
+ static drawSelectedPolygonWithFillAndLine(canvas, pointList, options = {}) {
302
+ const {pointColor = "white", strokeColor} = options;
303
+ const newPointList = this.drawPolygonWithFillAndLine(canvas, pointList, options);
304
+ newPointList.forEach((point) => {
305
+ this.drawCircleWithFill(canvas, point, 4, {color: strokeColor});
306
+ this.drawCircleWithFill(canvas, point, 3, {color: pointColor});
307
+ });
308
+ return newPointList;
309
+ }
310
+ static drawText(canvas, startPoint, text, options = {}) {
311
+ if (!text) {
312
+ return;
313
+ }
314
+ const ctx = canvas.getContext("2d");
315
+ const {
316
+ color = DEFAULT_COLOR,
317
+ font = DEFAULT_FONT,
318
+ shadowColor = "",
319
+ shadowBlur = 0,
320
+ shadowOffsetX = 0,
321
+ shadowOffsetY = 0,
322
+ textMaxWidth = 164,
323
+ offsetX = 0,
324
+ offsetY = 0,
325
+ textAlign = "start",
326
+ lineHeight
327
+ } = options;
328
+ ctx.save();
329
+ ctx.textAlign = textAlign;
330
+ ctx.fillStyle = color != null ? color : "white";
331
+ ctx.font = font;
332
+ ctx.shadowColor = shadowColor;
333
+ ctx.shadowOffsetX = shadowOffsetX;
334
+ ctx.shadowOffsetY = shadowOffsetY;
335
+ ctx.shadowBlur = shadowBlur;
336
+ this.wrapText(canvas, `${text}`, startPoint.x + offsetX, startPoint.y + offsetY, textMaxWidth, lineHeight);
337
+ ctx.restore();
338
+ }
339
+ static wrapText(canvas, text, x, y, maxWidth, lineHeight) {
340
+ if (typeof text !== "string" || typeof x !== "number" || typeof y !== "number") {
341
+ return;
342
+ }
343
+ const context = canvas.getContext("2d");
344
+ if (typeof maxWidth === "undefined") {
345
+ maxWidth = canvas && canvas.width || 300;
346
+ }
347
+ if (typeof lineHeight === "undefined") {
348
+ lineHeight = canvas && parseInt(window.getComputedStyle(canvas).lineHeight, 10) || parseInt(window.getComputedStyle(document.body).lineHeight, 10);
349
+ }
350
+ const arrParagraph = text.split("\n");
351
+ for (let i = 0; i < arrParagraph.length; i++) {
352
+ const arrText = arrParagraph[i].split("");
353
+ let line = "";
354
+ for (let n = 0; n < arrText.length; n++) {
355
+ const testLine = line + arrText[n];
356
+ const metrics = context.measureText(testLine);
357
+ const testWidth = metrics.width;
358
+ if (!maxWidth) {
359
+ maxWidth = 300;
360
+ }
361
+ if (testWidth > maxWidth && n > 0) {
362
+ context.fillText(line, x, y);
363
+ line = arrText[n];
364
+ y += lineHeight;
365
+ } else {
366
+ line = testLine;
367
+ }
368
+ }
369
+ context.fillText(line, x, y);
370
+ y += lineHeight;
371
+ }
372
+ }
373
+ static drawArrow(ctx, startPoint, endPoint, options = {}) {
374
+ const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", theta = 30, headLen = 10} = options;
375
+ const angle = Math.atan2(startPoint.y - endPoint.y, startPoint.x - endPoint.x) * 180 / Math.PI;
376
+ const angle1 = (angle + theta) * Math.PI / 180;
377
+ const angle2 = (angle - theta) * Math.PI / 180;
378
+ const topX = headLen * Math.cos(angle1);
379
+ const topY = headLen * Math.sin(angle1);
380
+ const botX = headLen * Math.cos(angle2);
381
+ const botY = headLen * Math.sin(angle2);
382
+ ctx.save();
383
+ ctx.strokeStyle = color;
384
+ ctx.lineWidth = thickness;
385
+ ctx.lineCap = lineCap;
386
+ ctx.beginPath();
387
+ ctx.moveTo(endPoint.x + topX, endPoint.y + topY);
388
+ ctx.lineTo(endPoint.x, endPoint.y);
389
+ ctx.lineTo(endPoint.x + botX, endPoint.y + botY);
390
+ ctx.stroke();
391
+ ctx.restore();
392
+ }
393
+ static drawArrowByCanvas(canvas, startPoint, endPoint, options = {}) {
394
+ const ctx = canvas.getContext("2d");
395
+ this.drawArrow(ctx, startPoint, endPoint, options);
396
+ }
397
+ static drawCuboid(canvas, cuboid, options = {}) {
398
+ const {backPoints, direction, frontPoints} = cuboid;
399
+ const {strokeColor, thickness, fillColor} = options;
400
+ const defaultStyle = {
401
+ color: strokeColor,
402
+ thickness
403
+ };
404
+ if (backPoints) {
405
+ const backPointList = AxisUtils.transformPlain2PointList(backPoints);
406
+ _DrawUtils.drawPolygon(canvas, backPointList, __spreadProps(__spreadValues({}, defaultStyle), {isClose: true}));
407
+ const sideLine = getCuboidAllSideLine(cuboid);
408
+ sideLine == null ? void 0 : sideLine.forEach((line) => {
409
+ _DrawUtils.drawLine(canvas, line.p1, line.p2, __spreadValues({}, defaultStyle));
410
+ });
411
+ }
412
+ const pointList = AxisUtils.transformPlain2PointList(frontPoints);
413
+ if (direction && backPoints && frontPoints) {
414
+ const points = getPointListsByDirection({direction, frontPoints, backPoints});
415
+ if (points) {
416
+ _DrawUtils.drawPolygonWithFill(canvas, points, {color: fillColor});
417
+ }
418
+ }
419
+ _DrawUtils.drawPolygon(canvas, pointList, __spreadProps(__spreadValues({}, defaultStyle), {isClose: true}));
420
+ }
421
+ static drawCuboidWithText(canvas, cuboid, options, dataConfig) {
422
+ const {strokeColor} = options;
423
+ const textColor = strokeColor;
424
+ const {config, hiddenText, selectedID, headerText, bottomText} = dataConfig;
425
+ const {backPoints, frontPoints, textAttribute} = cuboid;
426
+ const frontPointsSizeWidth = frontPoints.br.x - frontPoints.bl.x;
427
+ _DrawUtils.drawCuboid(canvas, cuboid, options);
428
+ let showText = "";
429
+ if ((config == null ? void 0 : config.isShowOrder) && cuboid.order && (cuboid == null ? void 0 : cuboid.order) > 0) {
430
+ showText = `${cuboid.order}`;
431
+ }
432
+ if (cuboid.attribute) {
433
+ showText = `${showText} ${AttributeUtils.getAttributeShowText(cuboid.attribute, config == null ? void 0 : config.attributeList)}`;
434
+ }
435
+ if (!hiddenText && backPoints && showText) {
436
+ _DrawUtils.drawText(canvas, {x: backPoints.tl.x, y: backPoints.tl.y - 5}, headerText != null ? headerText : showText, {
437
+ color: strokeColor,
438
+ textMaxWidth: 300
439
+ });
440
+ }
441
+ const textPosition = getCuboidTextAttributeOffset({
442
+ cuboid,
443
+ currentPos: {x: 0, y: 0},
444
+ zoom: 1,
445
+ topOffset: 16,
446
+ leftOffset: 0
447
+ });
448
+ if (!hiddenText && textAttribute && cuboid.id !== selectedID) {
449
+ const textWidth = Math.max(20, frontPointsSizeWidth * 0.8);
450
+ _DrawUtils.drawText(canvas, {x: textPosition.left, y: textPosition.top}, bottomText != null ? bottomText : textAttribute, {
451
+ color: textColor,
452
+ textMaxWidth: textWidth
453
+ });
454
+ }
455
+ }
456
+ };
457
+ let DrawUtils = _DrawUtils;
458
+ DrawUtils.drawImg = (canvas, imgNode, options = {}) => {
459
+ const ctx = canvas.getContext("2d");
460
+ const {zoom = DEFAULT_ZOOM, currentPos = DEFAULT_CURRENT_POS, rotate = DEFAULT_ROTATE, imgAttribute} = options;
461
+ ctx.save();
462
+ switch (rotate) {
463
+ case 0:
464
+ ctx.translate(currentPos.x, currentPos.y);
465
+ break;
466
+ case 90:
467
+ ctx.translate(currentPos.x + imgNode.height * zoom, currentPos.y);
468
+ ctx.rotate(90 * Math.PI / 180);
469
+ break;
470
+ case 180:
471
+ ctx.translate(currentPos.x + imgNode.width * zoom, currentPos.y + imgNode.height * zoom);
472
+ ctx.rotate(Math.PI);
473
+ break;
474
+ case 270:
475
+ ctx.translate(currentPos.x, currentPos.y + imgNode.width * zoom);
476
+ ctx.rotate(270 * Math.PI / 180);
477
+ break;
478
+ default:
479
+ ctx.translate(currentPos.x, currentPos.y);
480
+ break;
481
+ }
482
+ if (imgAttribute) {
483
+ const {contrast, saturation, brightness} = imgAttribute;
484
+ ctx.filter = `saturate(${saturation + 100}%) contrast(${contrast + 100}%) brightness(${brightness + 100}%)`;
485
+ }
486
+ ctx.drawImage(imgNode, 0, 0, imgNode.width * zoom, imgNode.height * zoom);
487
+ ctx.restore();
488
+ };
489
+
490
+ export { DrawUtils as default };
@@ -1 +1,48 @@
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};
1
+ import { EToolName, ECheckModel } from '../../constant/tool.js';
2
+ import ScribbleTool from '../../core/toolOperation/ScribbleTool.js';
3
+ import CuboidOperation from '../../core/toolOperation/cuboidOperation.js';
4
+ import PointCloud2dOperation from '../../core/toolOperation/pointCloud2dOperation.js';
5
+ import CheckOperation from '../../core/toolOperation/checkOperation.js';
6
+ import PolygonOperation from '../../core/toolOperation/polygonOperation.js';
7
+ import { RectOperation } from '../../core/toolOperation/rectOperation.js';
8
+ import TagOperation from '../../core/toolOperation/tagOperation.js';
9
+ import LineToolOperation from '../../core/toolOperation/LineToolOperation.js';
10
+ import PointOperation from '../../core/toolOperation/pointOperation.js';
11
+ import TextToolOperation from '../../core/toolOperation/TextToolOperation.js';
12
+ import SegmentByRect from '../../core/toolOperation/segmentByRect.js';
13
+ import CommonToolUtils from './CommonToolUtils.js';
14
+
15
+ const getCurrentOperation = (toolName) => {
16
+ switch (toolName) {
17
+ case EToolName.Rect:
18
+ case EToolName.RectTrack:
19
+ return RectOperation;
20
+ case EToolName.SegmentByRect:
21
+ return SegmentByRect;
22
+ case EToolName.Tag:
23
+ return TagOperation;
24
+ case EToolName.Polygon:
25
+ return PolygonOperation;
26
+ case ECheckModel.Check:
27
+ return CheckOperation;
28
+ case EToolName.Line:
29
+ return LineToolOperation;
30
+ case EToolName.Point:
31
+ return PointOperation;
32
+ case EToolName.Text:
33
+ return TextToolOperation;
34
+ case EToolName.ScribbleTool:
35
+ return ScribbleTool;
36
+ case EToolName.Cuboid:
37
+ return CuboidOperation;
38
+ case EToolName.PointCloudPolygon:
39
+ return PointCloud2dOperation;
40
+ default:
41
+ throw new Error("not match tool");
42
+ }
43
+ };
44
+ class EnhanceCommonToolUtils extends CommonToolUtils {
45
+ }
46
+ EnhanceCommonToolUtils.getCurrentOperation = getCurrentOperation;
47
+
48
+ export { EnhanceCommonToolUtils as default, getCurrentOperation };