@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,1228 @@
1
- import N from"../../utils/MathUtils.js";import S from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/RectUtils.js";import{EDragStatus as L,ESortDirection as O,DEFAULT_TEXT_SHADOW as T}from"../../constant/annotation.js";import{EDragTarget as w,EOperationMode as _}from"../../constant/tool.js";import p from"../../constant/keyCode.js";import A from"../../locales/index.js";import{EMessage as P}from"../../locales/constants.js";import C from"../../utils/tool/AttributeUtils.js";import U from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import k from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as E}from"../../utils/tool/polygonTool.js";import K from"../../utils/uuid.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var F=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,j=(D,t,e)=>t in D?F(D,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):D[t]=e,x=(D,t)=>{for(var e in t||(t={}))G.call(t,e)&&j(D,e,t[e]);if(H)for(var e of H(t))J.call(t,e)&&j(D,e,t[e]);return D},m=(D,t)=>X(D,Y(t));const M=6;class W extends V{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=M,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:g}=this;if(g&&y.isInRect(i,g,r,this.zoom))return g.id}const h=o.filter(g=>y.isInRect(i,g,r,this.zoom));if(h.length===0)return"";if(h.length===1)return h[0].id;if(h.length>1)return h.map(s=>({size:s.width*s.height,id:s.id})).sort((s,f)=>s.size-f.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(C.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const r=this.selectedRectID;t!==r&&r&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;C.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",C.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?m(x({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?S.returnClosePointIndex(this.getCoordinateUnderZoom(t),y.getRectPointList(this.selectedRect,this.zoom),M+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=y.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let h=0;h<r.length;h++){const g=r[h],{length:s}=N.getFootOfPerpendicular(o,g.begin,g.end);s<M+10&&(e=h)}return e}getTextIconSvg(t=""){return C.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}multiMoveMouseDown(t){const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);return this.isMultiMoveMode&&i&&t.button===0?(this.dragInfo={dragStartCoord:e,dragTarget:w.Plane,startTime:+new Date,originRectList:this.rectList},this.dragStatus=L.Start,!0):!1}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0||this.multiMoveMouseDown(t))return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!(!r||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const o=w.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=L.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=w.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=L.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const o=w.Plane;this.dragInfo={dragStartCoord:e,dragTarget:o,firstRect:r,startTime:+new Date},this.dragStatus=L.Start}}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>m(x({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o,h,g;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=L.Move,this.isMultiMoveMode){this.onDragMoveAll(s);return}if(!this.dragInfo.firstRect)return;const f=y.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:l,y:c,width:u,height:d}=f;let n=this.rectList.filter(a=>a.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case w.Plane:n=m(x({},n),{x:l+s.x,y:c+s.y,width:u,height:d});break;case w.Point:{let a=l,b=c,I=u,v=d;switch(this.hoverRectPointIndex){case 0:{a=u-s.x<0?l+u:l+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(s.x-u),v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(u+s.x),v=Math.abs(d-s.y);break}case 2:{a=u+s.x>0?l:l+u+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(u+s.x),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(s.x-u),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v})}break;case w.Line:{let a=l,b=c,I=u,v=d;switch(this.hoverRectEdgeIndex){case 0:{b=d-s.y<0?c+d:c+s.y,v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,I=Math.abs(u+s.x);break}case 2:{b=d+s.y>0?c:c+d+s.y,v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,I=Math.abs(s.x-u);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(n,E(this.basicResult.pointList,this.zoom)))return;const a=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,I=this.basicResult.width*this.zoom,v=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==w.Plane&&(n.x<a-.01||n.y<b-.01||n.width>a+I-n.x+.01||n.height>b+v-n.y+.01))return;if(n.x<a&&(n.x=a),n.y<b&&(n.y=b),n.width>a+I-n.x)switch(this.dragInfo.dragTarget){case w.Plane:n.x=a+I-u;break;case w.Point:case w.Line:s.x>0&&s.y>0&&(n.width=a+I-n.x);break;default:return}if(n.height>b+v-n.y)switch(this.dragInfo.dragTarget){case w.Plane:n.y=b+v-d;break}}else if(n.x<0&&(n.x=0),n.y<0&&(n.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case w.Plane:n.x+n.width>((r=this.imgInfo)==null?void 0:r.width)&&(n.x=this.imgInfo.width-u),n.y+n.height>((o=this.imgInfo)==null?void 0:o.height)&&(n.y=this.imgInfo.height-d);break;default:if(n.x+n.width>((h=this.imgInfo)==null?void 0:h.width)+.01||n.y+n.height>((g=this.imgInfo)==null?void 0:g.height)+.01)return}}this.setRectList(this.rectList.map(a=>a.id===n.id?y.getRectUnderZoom(n,1/this.zoom):a)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=S.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if((this.selectedRectID||this.isMultiMoveMode)&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const s=this.getHoverRectPointIndex(t);if(s!==this.hoverRectPointIndex){this.hoverRectPointIndex=s,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const f=this.getHoverRectEdgeIndex(t);if(f!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=f,this.render();return}}}const h=this.getHoverRectID(t),g=this.hoverRectID;if(this.hoverRectID=h,h!==g&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:s,y:f}=this.firstClickCoord,{width:l,height:c}=this.drawingRect;if(l=Math.abs(s-o.x),c=Math.abs(f-o.y),o.x<s&&(s=o.x),o.y<f&&(f=o.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),E(this.basicResult.pointList,this.zoom)))return;o.x<0&&(l=Math.abs(this.firstClickCoord.x),s=0),o.y<0&&(c=Math.abs(this.firstClickCoord.y),f=0),this.imgInfo&&(s+l>this.imgInfo.width&&(l=Math.abs(this.imgInfo.width-s)),f+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-f)))}this.drawingRect=m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?m(x({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),r=S.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=m(x({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:K(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",A.getMessagesByLocale(P.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=C.getTextAttribute(this.rectList.filter(h=>R.isSameSourceID(h.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=x({},r),this.firstCurrentPos=x({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",A.getMessagesByLocale(P.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,m(x({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(o=>o.id===e),{selectedRectID:r}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(r!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(i.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===L.Move){this.dragInfo=void 0,this.dragStatus=L.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(this.isMultiMoveMode&&this.setOperationMode(_.General),t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case p.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case p.Z:this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deleteRect(this.selectedRectID);break;case p.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=O.ascend;t.shiftKey&&(i=O.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let h=[...r];o&&(h=[...h,o]);const g=U.getViewPort(this.canvas,this.currentPos,this.zoom);h=h.filter(f=>U.inViewPort({x:f.x,y:f.y},g));const s=R.getNextSelectedRectID(h,i,this.selectedRectID);s&&(this.setSelectedRectID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute));break}default:{if(this.config.attributeConfigurable){const i=C.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=y.getRectUnderZoom(this.drawingRect,1/e),r=S.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=y.getRectUnderZoom(i,this.zoom),this.firstClickCoord=S.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:h,attribute:g,valid:s}=e,f=o*this.zoom*.6,l=S.getOffsetCoordinate({x:i,y:r+h},this.currentPos,this.zoom),c=this.getColor(g),u=s?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new $({width:f,container:this.container,icon:this.getTextIconSvg(g),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+d,color:u,width:f})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=y.getRectPointList(t),o=r.length,h=this.getColor(t.attribute);r.forEach((g,s)=>{var f,l;if(e.save(),e.moveTo(g.x,g.y),e.beginPath(),this.hoverRectPointIndex===s?i=M+6:i=M,t.valid===!1?(e.strokeStyle=h==null?void 0:h.invalid.stroke,e.fillStyle=h==null?void 0:h.invalid.stroke):(e.strokeStyle=h==null?void 0:h.valid.stroke,e.fillStyle=h==null?void 0:h.valid.stroke),e.arc(g.x*this.zoom+this.currentPos.x,g.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===s){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),u=t.valid===!1?(f=c==null?void 0:c.invalid)==null?void 0:f.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=u,e.moveTo(r[s].x*this.zoom+this.currentPos.x,r[s].y*this.zoom+this.currentPos.y),e.lineTo(r[(s+1)%o].x*this.zoom+this.currentPos.x,r[(s+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,o,h,g;if(this.ctx&&t){const{ctx:s,style:f}=this,{hiddenText:l=!1}=f;s.save();const{strokeColor:c,fillColor:u,textColor:d}=this.getRenderStyle(t);s.font="lighter 14px Arial";let n="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(n=`${t.order}`),t.label&&this.hasMarkerConfig&&(n=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${B.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(n=`${n} ${C.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const a=S.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||k.drawText(this.canvas,{x:a.x,y:a.y-6},n,m(x({color:c,font:"normal normal 900 14px SourceHanSansCN-Regular"},T),{textMaxWidth:300}));const b=(g=(h=this.style)==null?void 0:h.width)!=null?g:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&k.drawRectWithFill(this.canvas,a,{color:u}),k.drawRect(this.canvas,a,{color:c,thickness:b,hiddenText:!0}),s.restore();let I=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(I=`${Math.round(t.width/this.zoom)} * ${Math.round(a.height/this.zoom)}`);const v=I.length*7;if(l||k.drawText(this.canvas,{x:a.x+a.width-v,y:a.y+a.height+15},I,x({color:d,font:"normal normal 600 14px Arial"},T)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,a.width-v);k.drawText(this.canvas,{x:a.x,y:a.y+a.height+20+z},t.textAttribute,x({color:d,font:"italic normal 900 14px Arial",textMaxWidth:Z},T))}}}renderMultiSelectedRect(){!this.isMultiMoveMode||this.rectList.forEach(t=>{this.renderDrawingRect(t),this.renderSelectedRect(t)})}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,S.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&(this.renderDrawingRect(r),this.renderSelectedRect(r),e.selectedRender&&e.selectedRender(this.canvas,S.changeRectByZoom(r,this.zoom,this.currentPos),this.getRenderStyle(r)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,S.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){switch(this.operationMode){case _.MultiMove:this.renderMultiSelectedRect();break;default:this.renderStaticRect(),this.renderCreatingRect()}}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(r=>r.id===this.selectedID?m(x({},r),{attribute:this.defaultAttribute}):r),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait,this.setSelectedRectID(void 0),this.setOperationMode(_.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",A.getMessagesByLocale(P.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",A.getMessagesByLocale(P.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
1
+ import MathUtils from '../../utils/MathUtils.js';
2
+ import AxisUtils from '../../utils/tool/AxisUtils.js';
3
+ import RectUtils from '../../utils/tool/RectUtils.js';
4
+ import { EDragStatus, ESortDirection, DEFAULT_TEXT_SHADOW } from '../../constant/annotation.js';
5
+ import { EDragTarget, EOperationMode } from '../../constant/tool.js';
6
+ import EKeyCode from '../../constant/keyCode.js';
7
+ import Locale from '../../locales/index.js';
8
+ import { EMessage } from '../../locales/constants.js';
9
+ import AttributeUtils from '../../utils/tool/AttributeUtils.js';
10
+ import CanvasUtils from '../../utils/tool/CanvasUtils.js';
11
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
12
+ import DrawUtils from '../../utils/tool/DrawUtils.js';
13
+ import MarkerUtils from '../../utils/tool/MarkerUtils.js';
14
+ import { getPolygonPointUnderZoom } from '../../utils/tool/polygonTool.js';
15
+ import uuid from '../../utils/uuid.js';
16
+ import { BasicToolOperation } from './basicToolOperation.js';
17
+ import TextAttributeClass from './textAttributeClass.js';
18
+
19
+ var __defProp = Object.defineProperty;
20
+ var __defProps = Object.defineProperties;
21
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
22
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
23
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
24
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
25
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
26
+ var __spreadValues = (a, b) => {
27
+ for (var prop in b || (b = {}))
28
+ if (__hasOwnProp.call(b, prop))
29
+ __defNormalProp(a, prop, b[prop]);
30
+ if (__getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(b)) {
32
+ if (__propIsEnum.call(b, prop))
33
+ __defNormalProp(a, prop, b[prop]);
34
+ }
35
+ return a;
36
+ };
37
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
38
+ const scope = 6;
39
+ class RectOperation extends BasicToolOperation {
40
+ constructor(props) {
41
+ super(props);
42
+ this.setMarkerIndex = (markerIndex) => {
43
+ this.markerIndex = markerIndex;
44
+ };
45
+ this.setMarkerIndexAndSelect = (markerIndex) => {
46
+ if (!this.config.markerList) {
47
+ return;
48
+ }
49
+ this.markerIndex = markerIndex;
50
+ const markerValue = this.config.markerList[markerIndex].value;
51
+ const currentRect = this.currentPageResult.find((rect) => rect.label === markerValue);
52
+ if (currentRect) {
53
+ this.setSelectedID(currentRect.id);
54
+ if (this.config.attributeConfigurable === true) {
55
+ this.setDefaultAttribute(currentRect.attribute);
56
+ }
57
+ }
58
+ this.emit("markIndexChange");
59
+ };
60
+ this.getHoverRectID = (e) => {
61
+ const coordinate = this.getCoordinateUnderZoom(e);
62
+ const newScope = scope;
63
+ const {currentShowList} = this;
64
+ if (currentShowList.length > 0) {
65
+ if (this.selectedRectID) {
66
+ const {selectedRect} = this;
67
+ if (selectedRect) {
68
+ if (RectUtils.isInRect(coordinate, selectedRect, newScope, this.zoom)) {
69
+ return selectedRect.id;
70
+ }
71
+ }
72
+ }
73
+ const hoverList = currentShowList.filter((rect) => RectUtils.isInRect(coordinate, rect, newScope, this.zoom));
74
+ if (hoverList.length === 0) {
75
+ return "";
76
+ }
77
+ if (hoverList.length === 1) {
78
+ return hoverList[0].id;
79
+ }
80
+ if (hoverList.length > 1) {
81
+ const rectSizeList = hoverList.map((rect) => ({size: rect.width * rect.height, id: rect.id})).sort((a, b) => a.size - b.size);
82
+ return rectSizeList[0].id;
83
+ }
84
+ }
85
+ return "";
86
+ };
87
+ this.textChange = (v) => {
88
+ if (this.config.textConfigurable !== true || !this.selectedRectID) {
89
+ return;
90
+ }
91
+ this.setRectList(AttributeUtils.textChange(v, this.selectedRectID, this.rectList), true);
92
+ this.emit("selectedChange");
93
+ this.render();
94
+ };
95
+ this.drawOutSideTarget = props.drawOutSideTarget || false;
96
+ this.rectList = [];
97
+ this.isFlow = true;
98
+ this.config = CommonToolUtils.jsonParser(props.config);
99
+ this.hoverRectEdgeIndex = -1;
100
+ this.hoverRectPointIndex = -1;
101
+ this.markerIndex = 0;
102
+ this.setStyle(props.style);
103
+ this.createNewDrawingRect = this.createNewDrawingRect.bind(this);
104
+ this.getDrawingRectWithRectList = this.getDrawingRectWithRectList.bind(this);
105
+ this.setSelectedIdAfterAddingDrawingRect = this.setSelectedIdAfterAddingDrawingRect.bind(this);
106
+ this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
107
+ this.updateSelectedRectTextAttribute = this.updateSelectedRectTextAttribute.bind(this);
108
+ this.setSelectedID = this.setSelectedID.bind(this);
109
+ }
110
+ setResult(rectList) {
111
+ this.clearActiveStatus();
112
+ this.setRectList(rectList);
113
+ if (this.hasMarkerConfig) {
114
+ const nextMarkerInfo = CommonToolUtils.getNextMarker(this.getCurrentPageResult(rectList), this.config.markerList);
115
+ if (nextMarkerInfo) {
116
+ this.setMarkerIndex(nextMarkerInfo.index);
117
+ }
118
+ }
119
+ this.render();
120
+ }
121
+ destroy() {
122
+ super.destroy();
123
+ if (this._textAttributInstance) {
124
+ this._textAttributInstance.clearTextAttribute();
125
+ }
126
+ }
127
+ setConfig(config, isClear = false) {
128
+ this.config = CommonToolUtils.jsonParser(config);
129
+ if (isClear === true) {
130
+ this.clearResult(false);
131
+ }
132
+ }
133
+ setRectList(rectList, isUpload = false) {
134
+ const oldLen = this.rectList.length;
135
+ this.rectList = rectList;
136
+ if (oldLen !== rectList.length) {
137
+ this.emit("updatePageNumber");
138
+ }
139
+ if (isUpload) {
140
+ this.emit("updateResult");
141
+ }
142
+ }
143
+ get selectedRect() {
144
+ return this.rectList.find((v) => v.id === this.selectedRectID);
145
+ }
146
+ get selectedID() {
147
+ return this.selectedRectID;
148
+ }
149
+ get selectedText() {
150
+ var _a;
151
+ return (_a = this.selectedRect) == null ? void 0 : _a.textAttribute;
152
+ }
153
+ get dataList() {
154
+ return this.rectList;
155
+ }
156
+ get currentShowList() {
157
+ let rect = [];
158
+ const [showingRect, selectedRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
159
+ rect = showingRect;
160
+ if (this.isHidden) {
161
+ rect = [];
162
+ }
163
+ if (selectedRect) {
164
+ rect.push(selectedRect);
165
+ }
166
+ return rect;
167
+ }
168
+ get currentPageResult() {
169
+ const [showingRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), []);
170
+ return showingRect;
171
+ }
172
+ getCurrentPageResult(rectList) {
173
+ const [showingRect] = CommonToolUtils.getRenderResultList(rectList, CommonToolUtils.getSourceID(this.basicResult), []);
174
+ return showingRect;
175
+ }
176
+ setSelectedID(newID) {
177
+ this.setSelectedRectID(newID);
178
+ }
179
+ setSelectedRectID(newID) {
180
+ var _a, _b;
181
+ const oldID = this.selectedRectID;
182
+ if (newID !== oldID && oldID) {
183
+ (_a = this._textAttributInstance) == null ? void 0 : _a.changeSelected();
184
+ }
185
+ if (!newID) {
186
+ (_b = this._textAttributInstance) == null ? void 0 : _b.clearTextAttribute();
187
+ }
188
+ this.selectedRectID = newID;
189
+ this.render();
190
+ this.emit("selectedChange");
191
+ }
192
+ setStyle(toolStyle) {
193
+ var _a;
194
+ super.setStyle(toolStyle);
195
+ if (this._textAttributInstance && this.config.attributeConfigurable === false) {
196
+ (_a = this._textAttributInstance) == null ? void 0 : _a.updateIcon(this.getTextIconSvg());
197
+ }
198
+ }
199
+ updateSelectedRectTextAttribute(newTextAttribute) {
200
+ if (this._textAttributInstance && newTextAttribute) {
201
+ let textAttribute = newTextAttribute;
202
+ if (AttributeUtils.textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
203
+ this.emit("messageError", AttributeUtils.getErrorNotice(this.config.textCheckType, this.lang));
204
+ textAttribute = "";
205
+ }
206
+ this.setRectList(this.rectList.map((v) => {
207
+ if (v.id === this.selectedRectID) {
208
+ return __spreadProps(__spreadValues({}, v), {
209
+ textAttribute
210
+ });
211
+ }
212
+ return v;
213
+ }), true);
214
+ this.emit("updateTextAttribute");
215
+ this.render();
216
+ }
217
+ }
218
+ getHoverRectPointIndex(e) {
219
+ if (!this.selectedRect) {
220
+ return -1;
221
+ }
222
+ return AxisUtils.returnClosePointIndex(this.getCoordinateUnderZoom(e), RectUtils.getRectPointList(this.selectedRect, this.zoom), scope + 2);
223
+ }
224
+ getHoverRectEdgeIndex(e) {
225
+ if (!this.selectedRect) {
226
+ return -1;
227
+ }
228
+ let edgeIndex = -1;
229
+ const {selectedRect} = this;
230
+ const edgeList = RectUtils.getRectEdgeList(selectedRect, this.zoom);
231
+ const coordinate = this.getCoordinateUnderZoom(e);
232
+ for (let i = 0; i < edgeList.length; i++) {
233
+ const edge = edgeList[i];
234
+ const {length} = MathUtils.getFootOfPerpendicular(coordinate, edge.begin, edge.end);
235
+ if (length < scope + 10) {
236
+ edgeIndex = i;
237
+ }
238
+ }
239
+ return edgeIndex;
240
+ }
241
+ getTextIconSvg(attribute = "") {
242
+ return AttributeUtils.getTextIconSvg(attribute, this.config.attributeList, this.config.attributeConfigurable, this.baseIcon);
243
+ }
244
+ multiMoveMouseDown(e) {
245
+ const dragStartCoord = this.getCoordinateUnderZoom(e);
246
+ const hoverRectID = this.getHoverRectID(e);
247
+ if (this.isMultiMoveMode && hoverRectID && e.button === 0) {
248
+ this.dragInfo = {
249
+ dragStartCoord,
250
+ dragTarget: EDragTarget.Plane,
251
+ startTime: +new Date(),
252
+ originRectList: this.rectList
253
+ };
254
+ this.dragStatus = EDragStatus.Start;
255
+ return true;
256
+ }
257
+ return false;
258
+ }
259
+ onMouseDown(e) {
260
+ if (super.onMouseDown(e) || this.forbidMouseOperation || e.ctrlKey === true) {
261
+ return;
262
+ }
263
+ if (this.multiMoveMouseDown(e)) {
264
+ return;
265
+ }
266
+ const dragStartCoord = this.getCoordinateUnderZoom(e);
267
+ const hoverRectID = this.getHoverRectID(e);
268
+ const firstRect = this.currentShowList.find((v) => v.id === this.selectedRectID);
269
+ if (!firstRect || e.button === 2 || e.button === 0 && this.isSpaceKey === true) {
270
+ return;
271
+ }
272
+ if (this.selectedRectID) {
273
+ if (this.getHoverRectPointIndex(e) > -1) {
274
+ const dragTarget = EDragTarget.Point;
275
+ this.dragInfo = {
276
+ dragStartCoord,
277
+ dragTarget,
278
+ startTime: +new Date(),
279
+ firstRect
280
+ };
281
+ this.dragStatus = EDragStatus.Start;
282
+ return;
283
+ }
284
+ if (this.getHoverRectEdgeIndex(e) > -1) {
285
+ const dragTarget = EDragTarget.Line;
286
+ this.dragInfo = {
287
+ dragStartCoord,
288
+ dragTarget,
289
+ startTime: +new Date(),
290
+ firstRect
291
+ };
292
+ this.dragStatus = EDragStatus.Start;
293
+ return;
294
+ }
295
+ }
296
+ if (hoverRectID === this.selectedRectID && !this.drawingRect) {
297
+ const dragTarget = EDragTarget.Plane;
298
+ this.dragInfo = {
299
+ dragStartCoord,
300
+ dragTarget,
301
+ firstRect,
302
+ startTime: +new Date()
303
+ };
304
+ this.dragStatus = EDragStatus.Start;
305
+ }
306
+ return void 0;
307
+ }
308
+ onDragMoveAll(offset) {
309
+ var _a, _b;
310
+ if (!((_b = (_a = this.dragInfo) == null ? void 0 : _a.originRectList) == null ? void 0 : _b.length)) {
311
+ return;
312
+ }
313
+ this.setRectList(this.dragInfo.originRectList.map((rect) => {
314
+ const newRect = __spreadProps(__spreadValues({}, rect), {
315
+ x: rect.x + offset.x / this.zoom,
316
+ y: rect.y + offset.y / this.zoom
317
+ });
318
+ return newRect;
319
+ }));
320
+ this.render();
321
+ }
322
+ onDragMove(coordinate) {
323
+ var _a, _b, _c, _d, _e, _f;
324
+ if (!this.dragInfo) {
325
+ return;
326
+ }
327
+ const offset = {
328
+ x: coordinate.x - this.dragInfo.dragStartCoord.x,
329
+ y: coordinate.y - this.dragInfo.dragStartCoord.y
330
+ };
331
+ this.dragStatus = EDragStatus.Move;
332
+ if (this.isMultiMoveMode) {
333
+ this.onDragMoveAll(offset);
334
+ return;
335
+ }
336
+ if (!this.dragInfo.firstRect) {
337
+ return;
338
+ }
339
+ const dragRect = RectUtils.getRectUnderZoom(this.dragInfo.firstRect, this.zoom);
340
+ const {x, y, width, height} = dragRect;
341
+ let selectedRect = this.rectList.filter((v) => v.id === this.selectedRectID)[0];
342
+ switch (this.dragInfo.dragTarget) {
343
+ case EDragTarget.Plane:
344
+ selectedRect = __spreadProps(__spreadValues({}, selectedRect), {
345
+ x: x + offset.x,
346
+ y: y + offset.y,
347
+ width,
348
+ height
349
+ });
350
+ break;
351
+ case EDragTarget.Point:
352
+ {
353
+ let newX = x;
354
+ let newY = y;
355
+ let newWidth = width;
356
+ let newHeight = height;
357
+ switch (this.hoverRectPointIndex) {
358
+ case 0: {
359
+ newX = width - offset.x < 0 ? x + width : x + offset.x;
360
+ newY = height - offset.y < 0 ? y + height : y + offset.y;
361
+ newWidth = Math.abs(offset.x - width);
362
+ newHeight = Math.abs(offset.y - height);
363
+ break;
364
+ }
365
+ case 1: {
366
+ newX = width + offset.x > 0 ? x : x + width + offset.x;
367
+ newY = height - offset.y < 0 ? y + height : y + offset.y;
368
+ newWidth = Math.abs(width + offset.x);
369
+ newHeight = Math.abs(height - offset.y);
370
+ break;
371
+ }
372
+ case 2: {
373
+ newX = width + offset.x > 0 ? x : x + width + offset.x;
374
+ newY = height + offset.y > 0 ? y : y + height + offset.y;
375
+ newWidth = Math.abs(width + offset.x);
376
+ newHeight = height + offset.y > 0 ? height + offset.y : Math.abs(height + offset.y);
377
+ break;
378
+ }
379
+ case 3: {
380
+ newX = width - offset.x < 0 ? x + width : x + offset.x;
381
+ newY = height + offset.y > 0 ? y : y + height + offset.y;
382
+ newWidth = Math.abs(offset.x - width);
383
+ newHeight = height + offset.y > 0 ? height + offset.y : Math.abs(height + offset.y);
384
+ break;
385
+ }
386
+ default: {
387
+ return;
388
+ }
389
+ }
390
+ selectedRect = __spreadProps(__spreadValues({}, selectedRect), {
391
+ x: newX,
392
+ y: newY,
393
+ width: newWidth,
394
+ height: newHeight
395
+ });
396
+ }
397
+ break;
398
+ case EDragTarget.Line: {
399
+ let newX = x;
400
+ let newY = y;
401
+ let newWidth = width;
402
+ let newHeight = height;
403
+ switch (this.hoverRectEdgeIndex) {
404
+ case 0: {
405
+ newY = height - offset.y < 0 ? y + height : y + offset.y;
406
+ newHeight = Math.abs(offset.y - height);
407
+ break;
408
+ }
409
+ case 1: {
410
+ newX = width + offset.x > 0 ? x : x + width + offset.x;
411
+ newWidth = Math.abs(width + offset.x);
412
+ break;
413
+ }
414
+ case 2: {
415
+ newY = height + offset.y > 0 ? y : y + height + offset.y;
416
+ newHeight = height + offset.y > 0 ? height + offset.y : Math.abs(height + offset.y);
417
+ break;
418
+ }
419
+ case 3: {
420
+ newX = width - offset.x < 0 ? x + width : x + offset.x;
421
+ newWidth = Math.abs(offset.x - width);
422
+ break;
423
+ }
424
+ default: {
425
+ return;
426
+ }
427
+ }
428
+ selectedRect = __spreadProps(__spreadValues({}, selectedRect), {
429
+ x: newX,
430
+ y: newY,
431
+ width: newWidth,
432
+ height: newHeight
433
+ });
434
+ break;
435
+ }
436
+ default: {
437
+ return;
438
+ }
439
+ }
440
+ if (this.config.drawOutsideTarget === false) {
441
+ if (this.basicResult) {
442
+ if (((_b = (_a = this.basicResult) == null ? void 0 : _a.pointList) == null ? void 0 : _b.length) > 0) {
443
+ if (RectUtils.isRectNotInPolygon(selectedRect, getPolygonPointUnderZoom(this.basicResult.pointList, this.zoom))) {
444
+ return;
445
+ }
446
+ }
447
+ const basicX = this.basicResult.x * this.zoom;
448
+ const basicY = this.basicResult.y * this.zoom;
449
+ const basicWidth = this.basicResult.width * this.zoom;
450
+ const basicHeight = this.basicResult.height * this.zoom;
451
+ if (this.dragInfo.dragTarget !== EDragTarget.Plane && (selectedRect.x < basicX - 0.01 || selectedRect.y < basicY - 0.01 || selectedRect.width > basicX + basicWidth - selectedRect.x + 0.01 || selectedRect.height > basicY + basicHeight - selectedRect.y + 0.01)) {
452
+ return;
453
+ }
454
+ if (selectedRect.x < basicX) {
455
+ selectedRect.x = basicX;
456
+ }
457
+ if (selectedRect.y < basicY) {
458
+ selectedRect.y = basicY;
459
+ }
460
+ if (selectedRect.width > basicX + basicWidth - selectedRect.x) {
461
+ switch (this.dragInfo.dragTarget) {
462
+ case EDragTarget.Plane:
463
+ selectedRect.x = basicX + basicWidth - width;
464
+ break;
465
+ case EDragTarget.Point:
466
+ case EDragTarget.Line:
467
+ if (offset.x > 0 && offset.y > 0) {
468
+ selectedRect.width = basicX + basicWidth - selectedRect.x;
469
+ }
470
+ break;
471
+ default: {
472
+ return;
473
+ }
474
+ }
475
+ }
476
+ if (selectedRect.height > basicY + basicHeight - selectedRect.y) {
477
+ switch (this.dragInfo.dragTarget) {
478
+ case EDragTarget.Plane:
479
+ selectedRect.y = basicY + basicHeight - height;
480
+ break;
481
+ }
482
+ }
483
+ } else {
484
+ if (selectedRect.x < 0) {
485
+ selectedRect.x = 0;
486
+ }
487
+ if (selectedRect.y < 0) {
488
+ selectedRect.y = 0;
489
+ }
490
+ if (this.imgInfo) {
491
+ switch (this.dragInfo.dragTarget) {
492
+ case EDragTarget.Plane:
493
+ if (selectedRect.x + selectedRect.width > ((_c = this.imgInfo) == null ? void 0 : _c.width)) {
494
+ selectedRect.x = this.imgInfo.width - width;
495
+ }
496
+ if (selectedRect.y + selectedRect.height > ((_d = this.imgInfo) == null ? void 0 : _d.height)) {
497
+ selectedRect.y = this.imgInfo.height - height;
498
+ }
499
+ break;
500
+ default: {
501
+ if (selectedRect.x + selectedRect.width > ((_e = this.imgInfo) == null ? void 0 : _e.width) + 0.01 || selectedRect.y + selectedRect.height > ((_f = this.imgInfo) == null ? void 0 : _f.height) + 0.01) {
502
+ return;
503
+ }
504
+ }
505
+ }
506
+ }
507
+ }
508
+ }
509
+ this.setRectList(this.rectList.map((v) => {
510
+ if (v.id === selectedRect.id) {
511
+ return RectUtils.getRectUnderZoom(selectedRect, 1 / this.zoom);
512
+ }
513
+ return v;
514
+ }));
515
+ this.render();
516
+ }
517
+ onMouseMove(e) {
518
+ var _a, _b;
519
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
520
+ return;
521
+ }
522
+ const coordinateZoom = this.getCoordinateUnderZoom(e);
523
+ const coordinate = AxisUtils.changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.config.drawOutsideTarget, this.basicResult, this.zoom);
524
+ if ((this.selectedRectID || this.isMultiMoveMode) && this.dragInfo) {
525
+ this.onDragMove(coordinate);
526
+ return;
527
+ }
528
+ if (this.selectedRectID) {
529
+ const hoverRectPointIndex = this.getHoverRectPointIndex(e);
530
+ if (hoverRectPointIndex !== this.hoverRectPointIndex) {
531
+ this.hoverRectPointIndex = hoverRectPointIndex;
532
+ this.hoverRectEdgeIndex = -1;
533
+ this.render();
534
+ return;
535
+ }
536
+ if (this.hoverRectPointIndex === -1) {
537
+ const hoverRectEdgeIndex = this.getHoverRectEdgeIndex(e);
538
+ if (hoverRectEdgeIndex !== this.hoverRectEdgeIndex) {
539
+ this.hoverRectEdgeIndex = hoverRectEdgeIndex;
540
+ this.render();
541
+ return;
542
+ }
543
+ }
544
+ }
545
+ const hoverRectID = this.getHoverRectID(e);
546
+ const oldHoverRectID = this.hoverRectID;
547
+ this.hoverRectID = hoverRectID;
548
+ if (hoverRectID !== oldHoverRectID) {
549
+ this.render();
550
+ }
551
+ if (this.drawingRect && this.firstClickCoord) {
552
+ let {x, y} = this.firstClickCoord;
553
+ let {width, height} = this.drawingRect;
554
+ width = Math.abs(x - coordinate.x);
555
+ height = Math.abs(y - coordinate.y);
556
+ if (coordinate.x < x) {
557
+ x = coordinate.x;
558
+ }
559
+ if (coordinate.y < y) {
560
+ y = coordinate.y;
561
+ }
562
+ if (this.config.drawOutsideTarget === false) {
563
+ if (((_b = (_a = this.basicResult) == null ? void 0 : _a.pointList) == null ? void 0 : _b.length) > 0) {
564
+ if (RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({}, this.drawingRect), {
565
+ x,
566
+ y,
567
+ width,
568
+ height
569
+ }), getPolygonPointUnderZoom(this.basicResult.pointList, this.zoom))) {
570
+ return;
571
+ }
572
+ }
573
+ if (coordinate.x < 0) {
574
+ width = Math.abs(this.firstClickCoord.x);
575
+ x = 0;
576
+ }
577
+ if (coordinate.y < 0) {
578
+ height = Math.abs(this.firstClickCoord.y);
579
+ y = 0;
580
+ }
581
+ if (this.imgInfo) {
582
+ if (x + width > this.imgInfo.width) {
583
+ width = Math.abs(this.imgInfo.width - x);
584
+ }
585
+ if (y + height > this.imgInfo.height) {
586
+ height = Math.abs(this.imgInfo.height - y);
587
+ }
588
+ }
589
+ }
590
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
591
+ x,
592
+ y,
593
+ width,
594
+ height
595
+ });
596
+ this.render();
597
+ }
598
+ return void 0;
599
+ }
600
+ setAttributeLockList(attributeLockList) {
601
+ this.setSelectedRectID(void 0);
602
+ super.setAttributeLockList(attributeLockList);
603
+ }
604
+ setBasicResult(basicResult) {
605
+ super.setBasicResult(basicResult);
606
+ this.clearActiveStatus();
607
+ }
608
+ setRectValidAndRender(id) {
609
+ if (!id) {
610
+ return;
611
+ }
612
+ this.setRectList(this.rectList.map((rect) => {
613
+ if (rect.id === id) {
614
+ return __spreadProps(__spreadValues({}, rect), {
615
+ valid: !rect.valid
616
+ });
617
+ }
618
+ return rect;
619
+ }), true);
620
+ this.render();
621
+ this.emit("updateResult");
622
+ }
623
+ createNewDrawingRect(e, basicSourceID) {
624
+ if (!this.imgInfo) {
625
+ return;
626
+ }
627
+ const coordinateZoom = this.getCoordinateUnderZoom(e);
628
+ const coordinate = AxisUtils.changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.config.drawOutsideTarget, this.basicResult, this.zoom);
629
+ this.setSelectedRectID("");
630
+ this.hoverRectID = "";
631
+ if (this.drawOutSideTarget) {
632
+ if (coordinate.x < 0) {
633
+ coordinate.x = 0;
634
+ }
635
+ if (coordinate.y < 0) {
636
+ coordinate.y = 0;
637
+ }
638
+ }
639
+ this.drawingRect = __spreadProps(__spreadValues({}, coordinate), {
640
+ width: 0,
641
+ height: 0,
642
+ attribute: this.defaultAttribute,
643
+ valid: !e.ctrlKey,
644
+ id: uuid(8, 62),
645
+ sourceID: basicSourceID,
646
+ textAttribute: ""
647
+ });
648
+ if (this.hasMarkerConfig) {
649
+ const nextMarkInfo = CommonToolUtils.getNextMarker(this.currentPageResult, this.config.markerList, this.markerIndex);
650
+ if (nextMarkInfo) {
651
+ if (this.drawingRect) {
652
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
653
+ label: nextMarkInfo.label
654
+ });
655
+ }
656
+ this.markerIndex = nextMarkInfo.index;
657
+ this.emit("markIndexChange");
658
+ } else {
659
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.MarkerFinish, this.lang));
660
+ this.drawingRect = void 0;
661
+ return;
662
+ }
663
+ }
664
+ if (this.config.textConfigurable) {
665
+ let textAttribute = "";
666
+ textAttribute = AttributeUtils.getTextAttribute(this.rectList.filter((rect) => CommonToolUtils.isSameSourceID(rect.sourceID, basicSourceID)), this.config.textCheckType);
667
+ if (this.drawingRect) {
668
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
669
+ textAttribute
670
+ });
671
+ }
672
+ }
673
+ Object.assign(this.drawingRect, {
674
+ order: CommonToolUtils.getMaxOrder(this.rectList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1
675
+ });
676
+ this.firstClickCoord = __spreadValues({}, coordinate);
677
+ this.firstCurrentPos = __spreadValues({}, this.currentPos);
678
+ if (this.dataInjectionAtCreation) {
679
+ const data = this.dataInjectionAtCreation(this.drawingRect);
680
+ if (data) {
681
+ Object.assign(this.drawingRect, data);
682
+ }
683
+ }
684
+ }
685
+ addDrawingRectToRectList() {
686
+ if (!this.drawingRect) {
687
+ return;
688
+ }
689
+ let {width, height} = this.drawingRect;
690
+ width /= this.zoom;
691
+ height /= this.zoom;
692
+ if (Math.round(width) < this.config.minWidth || Math.round(height) < this.config.minHeight) {
693
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.RectErrorSizeNotice, this.lang));
694
+ this.drawingRect = void 0;
695
+ this.firstClickCoord = void 0;
696
+ this.dragInfo = void 0;
697
+ this.dragStatus = EDragStatus.Wait;
698
+ this.render();
699
+ return;
700
+ }
701
+ const newRectList = this.getDrawingRectWithRectList();
702
+ this.setRectList(newRectList, true);
703
+ this.history.pushHistory(this.rectList);
704
+ this.setSelectedIdAfterAddingDrawingRect();
705
+ this.firstClickCoord = void 0;
706
+ this.drawingRect = void 0;
707
+ this.dragInfo = void 0;
708
+ this.dragStatus = EDragStatus.Wait;
709
+ }
710
+ setSelectedIdAfterAddingDrawingRect() {
711
+ if (!this.drawingRect) {
712
+ return;
713
+ }
714
+ if (this.config.textConfigurable) {
715
+ this.setSelectedRectID(this.drawingRect.id);
716
+ } else {
717
+ this.setSelectedRectID();
718
+ }
719
+ }
720
+ getDrawingRectWithRectList() {
721
+ if (!this.drawingRect) {
722
+ return this.rectList;
723
+ }
724
+ let {x, y, width, height} = this.drawingRect;
725
+ x /= this.zoom;
726
+ y /= this.zoom;
727
+ width /= this.zoom;
728
+ height /= this.zoom;
729
+ return [
730
+ ...this.rectList,
731
+ __spreadProps(__spreadValues({}, this.drawingRect), {
732
+ x,
733
+ y,
734
+ width,
735
+ height
736
+ })
737
+ ];
738
+ }
739
+ rightMouseUp(e) {
740
+ const hoverRectID = this.getHoverRectID(e);
741
+ const hoverRect = this.rectList.find((v) => v.id === hoverRectID);
742
+ const {selectedRectID} = this;
743
+ this.setSelectedRectID(void 0);
744
+ if (hoverRect) {
745
+ this.setDefaultAttribute(hoverRect.attribute);
746
+ }
747
+ if (this.drawingRect) {
748
+ this.drawingRect = void 0;
749
+ this.firstClickCoord = void 0;
750
+ } else {
751
+ if (selectedRectID !== hoverRectID) {
752
+ this.dblClickListener.clearRightDblClick();
753
+ }
754
+ this.setSelectedRectID(hoverRectID);
755
+ this.hoverRectID = "";
756
+ if ((hoverRect == null ? void 0 : hoverRect.label) && this.hasMarkerConfig) {
757
+ const markerIndex = CommonToolUtils.getCurrentMarkerIndex(hoverRect.label, this.config.markerList);
758
+ if (markerIndex >= 0) {
759
+ this.setMarkerIndex(markerIndex);
760
+ this.emit("markIndexChange");
761
+ }
762
+ }
763
+ }
764
+ this.render();
765
+ }
766
+ shiftRightMouseUp(e) {
767
+ const hoverRectID = this.getHoverRectID(e);
768
+ this.emit("shiftRightMouseUp", hoverRectID);
769
+ }
770
+ onMouseUp(e) {
771
+ if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
772
+ return true;
773
+ }
774
+ if (this.dragInfo && this.dragStatus === EDragStatus.Move) {
775
+ this.dragInfo = void 0;
776
+ this.dragStatus = EDragStatus.Wait;
777
+ this.history.pushHistory(this.rectList);
778
+ this.emit("updateResult");
779
+ return;
780
+ }
781
+ if (this.isMultiMoveMode) {
782
+ this.setOperationMode(EOperationMode.General);
783
+ }
784
+ if (e.button === 2 && e.shiftKey === true) {
785
+ this.shiftRightMouseUp(e);
786
+ return;
787
+ }
788
+ if (e.button === 2) {
789
+ this.rightMouseUp(e);
790
+ return;
791
+ }
792
+ const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
793
+ if (this.drawingRect) {
794
+ this.addDrawingRectToRectList();
795
+ return;
796
+ }
797
+ if (e.ctrlKey === true && e.button === 0 && this.hoverRectID) {
798
+ this.setRectValidAndRender(this.hoverRectID);
799
+ return;
800
+ }
801
+ this.createNewDrawingRect(e, basicSourceID);
802
+ this.render();
803
+ return void 0;
804
+ }
805
+ onRightDblClick(e) {
806
+ super.onRightDblClick(e);
807
+ const hoverRectID = this.getHoverRectID(e);
808
+ if (this.selectedRectID && this.selectedRectID === hoverRectID) {
809
+ this.deleteRect(hoverRectID);
810
+ }
811
+ }
812
+ onKeyDown(e) {
813
+ if (!CommonToolUtils.hotkeyFilter(e)) {
814
+ return;
815
+ }
816
+ if (super.onKeyDown(e) === false) {
817
+ return;
818
+ }
819
+ const {keyCode} = e;
820
+ switch (keyCode) {
821
+ case EKeyCode.Ctrl:
822
+ if (this.drawingRect) {
823
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
824
+ valid: !e.ctrlKey
825
+ });
826
+ this.render();
827
+ }
828
+ break;
829
+ case EKeyCode.F:
830
+ if (this.selectedRectID) {
831
+ this.setRectValidAndRender(this.selectedRectID);
832
+ }
833
+ break;
834
+ case EKeyCode.Z:
835
+ this.setIsHidden(!this.isHidden);
836
+ this.render();
837
+ break;
838
+ case EKeyCode.Delete:
839
+ this.deleteRect(this.selectedRectID);
840
+ break;
841
+ case EKeyCode.Tab: {
842
+ e.preventDefault();
843
+ if (this.drawingRect) {
844
+ return;
845
+ }
846
+ let sort = ESortDirection.ascend;
847
+ if (e.shiftKey) {
848
+ sort = ESortDirection.descend;
849
+ }
850
+ const [showingRect, selectedRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedRectID);
851
+ let rectList = [...showingRect];
852
+ if (selectedRect) {
853
+ rectList = [...rectList, selectedRect];
854
+ }
855
+ const viewPort = CanvasUtils.getViewPort(this.canvas, this.currentPos, this.zoom);
856
+ rectList = rectList.filter((rect) => CanvasUtils.inViewPort({x: rect.x, y: rect.y}, viewPort));
857
+ const nextSelectedRect = CommonToolUtils.getNextSelectedRectID(rectList, sort, this.selectedRectID);
858
+ if (nextSelectedRect) {
859
+ this.setSelectedRectID(nextSelectedRect.id);
860
+ if (this.config.attributeConfigurable === true) {
861
+ this.setDefaultAttribute(nextSelectedRect.attribute);
862
+ }
863
+ }
864
+ break;
865
+ }
866
+ default: {
867
+ if (this.config.attributeConfigurable) {
868
+ const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
869
+ if (keyCode2Attribute !== void 0) {
870
+ this.setDefaultAttribute(keyCode2Attribute);
871
+ }
872
+ }
873
+ break;
874
+ }
875
+ }
876
+ return true;
877
+ }
878
+ onKeyUp(e) {
879
+ super.onKeyUp(e);
880
+ switch (e.keyCode) {
881
+ case EKeyCode.Ctrl:
882
+ if (this.drawingRect) {
883
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
884
+ valid: true
885
+ });
886
+ this.render();
887
+ }
888
+ break;
889
+ }
890
+ }
891
+ onWheel(e) {
892
+ const oldZoom = this.zoom;
893
+ let newDrawingRect;
894
+ let newFirsClickCoord;
895
+ if (this.drawingRect && this.firstClickCoord) {
896
+ newDrawingRect = RectUtils.getRectUnderZoom(this.drawingRect, 1 / oldZoom);
897
+ newFirsClickCoord = AxisUtils.changePointByZoom(this.firstClickCoord, 1 / oldZoom);
898
+ }
899
+ super.onWheel(e, false);
900
+ if (newDrawingRect && newFirsClickCoord) {
901
+ this.drawingRect = RectUtils.getRectUnderZoom(newDrawingRect, this.zoom);
902
+ this.firstClickCoord = AxisUtils.changePointByZoom(newFirsClickCoord, this.zoom);
903
+ }
904
+ this.render();
905
+ }
906
+ getCurrentSelectedData() {
907
+ const {selectedRect} = this;
908
+ if (!selectedRect) {
909
+ return;
910
+ }
911
+ const toolColor = this.getColor(selectedRect.attribute);
912
+ const color = selectedRect.valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
913
+ return {
914
+ width: selectedRect.width * this.zoom * 0.6,
915
+ textAttribute: selectedRect.textAttribute,
916
+ color
917
+ };
918
+ }
919
+ getRenderStyle(rect) {
920
+ const customStyle = this.customRenderStyle && this.customRenderStyle(rect);
921
+ if (customStyle) {
922
+ return customStyle;
923
+ }
924
+ const toolColor = this.getColor(rect.attribute);
925
+ let strokeColor;
926
+ let fillColor;
927
+ if (rect.valid === false) {
928
+ strokeColor = toolColor == null ? void 0 : toolColor.invalid.stroke;
929
+ fillColor = toolColor == null ? void 0 : toolColor.invalid.fill;
930
+ } else {
931
+ strokeColor = toolColor == null ? void 0 : toolColor.valid.stroke;
932
+ fillColor = toolColor == null ? void 0 : toolColor.valid.fill;
933
+ }
934
+ return {
935
+ strokeColor,
936
+ fillColor,
937
+ textColor: strokeColor,
938
+ toolColor
939
+ };
940
+ }
941
+ renderTextAttribute() {
942
+ var _a;
943
+ const {selectedRect} = this;
944
+ if (!this.ctx || this.config.textConfigurable !== true || !selectedRect) {
945
+ return;
946
+ }
947
+ const {x, y, width, height, attribute, valid} = selectedRect;
948
+ const newWidth = width * this.zoom * 0.6;
949
+ const coordinate = AxisUtils.getOffsetCoordinate({x, y: y + height}, this.currentPos, this.zoom);
950
+ const toolColor = this.getColor(attribute);
951
+ const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
952
+ const distance = 4;
953
+ if (!this._textAttributInstance) {
954
+ this._textAttributInstance = new TextAttributeClass({
955
+ width: newWidth,
956
+ container: this.container,
957
+ icon: this.getTextIconSvg(attribute),
958
+ color,
959
+ getCurrentSelectedData: this.getCurrentSelectedData,
960
+ updateSelectedTextAttribute: this.updateSelectedRectTextAttribute
961
+ });
962
+ }
963
+ if (this._textAttributInstance && !((_a = this._textAttributInstance) == null ? void 0 : _a.isExit)) {
964
+ this._textAttributInstance.appendToContainer();
965
+ }
966
+ this._textAttributInstance.update(`${selectedRect.textAttribute}`, {
967
+ left: coordinate.x,
968
+ top: coordinate.y + distance,
969
+ color,
970
+ width: newWidth
971
+ });
972
+ }
973
+ renderSelectedRect(rect) {
974
+ if (!this.ctx || !rect) {
975
+ return;
976
+ }
977
+ const {ctx} = this;
978
+ let radius = 10;
979
+ const pointList = RectUtils.getRectPointList(rect);
980
+ const len = pointList.length;
981
+ const toolColor = this.getColor(rect.attribute);
982
+ pointList.forEach((v, i) => {
983
+ var _a, _b;
984
+ ctx.save();
985
+ ctx.moveTo(v.x, v.y);
986
+ ctx.beginPath();
987
+ if (this.hoverRectPointIndex === i) {
988
+ radius = scope + 6;
989
+ } else {
990
+ radius = scope;
991
+ }
992
+ if (rect.valid === false) {
993
+ ctx.strokeStyle = toolColor == null ? void 0 : toolColor.invalid.stroke;
994
+ ctx.fillStyle = toolColor == null ? void 0 : toolColor.invalid.stroke;
995
+ } else {
996
+ ctx.strokeStyle = toolColor == null ? void 0 : toolColor.valid.stroke;
997
+ ctx.fillStyle = toolColor == null ? void 0 : toolColor.valid.stroke;
998
+ }
999
+ ctx.arc(v.x * this.zoom + this.currentPos.x, v.y * this.zoom + this.currentPos.y, radius, 0, 2 * Math.PI);
1000
+ ctx.fill();
1001
+ if (this.hoverRectEdgeIndex === i) {
1002
+ ctx.beginPath();
1003
+ ctx.lineWidth = 10;
1004
+ const lineColor = this.getColor(rect.attribute);
1005
+ const strokeStyle = rect.valid === false ? (_a = lineColor == null ? void 0 : lineColor.invalid) == null ? void 0 : _a.stroke : (_b = lineColor == null ? void 0 : lineColor.valid) == null ? void 0 : _b.stroke;
1006
+ ctx.strokeStyle = strokeStyle;
1007
+ ctx.moveTo(pointList[i].x * this.zoom + this.currentPos.x, pointList[i].y * this.zoom + this.currentPos.y);
1008
+ ctx.lineTo(pointList[(i + 1) % len].x * this.zoom + this.currentPos.x, pointList[(i + 1) % len].y * this.zoom + this.currentPos.y);
1009
+ ctx.stroke();
1010
+ }
1011
+ ctx.restore();
1012
+ });
1013
+ this.renderTextAttribute();
1014
+ }
1015
+ renderDrawingRect(rect, zoom = this.zoom, isZoom = false) {
1016
+ var _a, _b, _c, _d;
1017
+ if (this.ctx && rect) {
1018
+ const {ctx, style} = this;
1019
+ const {hiddenText = false} = style;
1020
+ ctx.save();
1021
+ const {strokeColor, fillColor, textColor} = this.getRenderStyle(rect);
1022
+ ctx.font = "lighter 14px Arial";
1023
+ let showText = "";
1024
+ if (((_a = this.config) == null ? void 0 : _a.isShowOrder) && rect.order && (rect == null ? void 0 : rect.order) > 0) {
1025
+ showText = `${rect.order}`;
1026
+ }
1027
+ if (rect.label && this.hasMarkerConfig) {
1028
+ const order = CommonToolUtils.getCurrentMarkerIndex(rect.label, this.config.markerList) + 1;
1029
+ showText = `${order}_${MarkerUtils.getMarkerShowText(rect.label, this.config.markerList)}`;
1030
+ }
1031
+ if (rect.attribute) {
1032
+ showText = `${showText} ${AttributeUtils.getAttributeShowText(rect.attribute, (_b = this.config) == null ? void 0 : _b.attributeList)}`;
1033
+ }
1034
+ const transformRect = AxisUtils.changeRectByZoom(rect, isZoom ? zoom : this.zoom, this.currentPos);
1035
+ if (!hiddenText) {
1036
+ DrawUtils.drawText(this.canvas, {x: transformRect.x, y: transformRect.y - 6}, showText, __spreadProps(__spreadValues({
1037
+ color: strokeColor,
1038
+ font: "normal normal 900 14px SourceHanSansCN-Regular"
1039
+ }, DEFAULT_TEXT_SHADOW), {
1040
+ textMaxWidth: 300
1041
+ }));
1042
+ }
1043
+ const lineWidth = (_d = (_c = this.style) == null ? void 0 : _c.width) != null ? _d : 2;
1044
+ if (rect.id === this.hoverRectID || rect.id === this.selectedRectID || this.isMultiMoveMode) {
1045
+ DrawUtils.drawRectWithFill(this.canvas, transformRect, {color: fillColor});
1046
+ }
1047
+ DrawUtils.drawRect(this.canvas, transformRect, {color: strokeColor, thickness: lineWidth, hiddenText: true});
1048
+ ctx.restore();
1049
+ let rectSize = `${Math.round(rect.width)} * ${Math.round(rect.height)}`;
1050
+ if (isZoom === true) {
1051
+ rectSize = `${Math.round(rect.width / this.zoom)} * ${Math.round(transformRect.height / this.zoom)}`;
1052
+ }
1053
+ const textSizeWidth = rectSize.length * 7;
1054
+ if (!hiddenText) {
1055
+ DrawUtils.drawText(this.canvas, {x: transformRect.x + transformRect.width - textSizeWidth, y: transformRect.y + transformRect.height + 15}, rectSize, __spreadValues({
1056
+ color: textColor,
1057
+ font: "normal normal 600 14px Arial"
1058
+ }, DEFAULT_TEXT_SHADOW));
1059
+ }
1060
+ if (!hiddenText && rect.textAttribute && rect.id !== this.selectedRectID) {
1061
+ const marginTop = 0;
1062
+ const textWidth = Math.max(20, transformRect.width - textSizeWidth);
1063
+ DrawUtils.drawText(this.canvas, {x: transformRect.x, y: transformRect.y + transformRect.height + 20 + marginTop}, rect.textAttribute, __spreadValues({
1064
+ color: textColor,
1065
+ font: "italic normal 900 14px Arial",
1066
+ textMaxWidth: textWidth
1067
+ }, DEFAULT_TEXT_SHADOW));
1068
+ }
1069
+ }
1070
+ }
1071
+ renderMultiSelectedRect() {
1072
+ if (!this.isMultiMoveMode) {
1073
+ return;
1074
+ }
1075
+ this.rectList.forEach((rect) => {
1076
+ this.renderDrawingRect(rect);
1077
+ this.renderSelectedRect(rect);
1078
+ });
1079
+ }
1080
+ renderStaticRect() {
1081
+ var _a;
1082
+ if (!(((_a = this.rectList) == null ? void 0 : _a.length) > 0 && JSON.stringify(this.rectList))) {
1083
+ return;
1084
+ }
1085
+ const {renderEnhance = {}} = this;
1086
+ const [showingRect, selectedRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedRectID);
1087
+ if (!this.isHidden) {
1088
+ showingRect == null ? void 0 : showingRect.forEach((rect) => {
1089
+ this.renderDrawingRect(rect);
1090
+ if (renderEnhance.staticRender) {
1091
+ renderEnhance.staticRender(this.canvas, AxisUtils.changeRectByZoom(rect, this.zoom, this.currentPos), this.getRenderStyle(rect));
1092
+ }
1093
+ });
1094
+ }
1095
+ if (selectedRect) {
1096
+ this.renderDrawingRect(selectedRect);
1097
+ this.renderSelectedRect(selectedRect);
1098
+ if (renderEnhance.selectedRender) {
1099
+ renderEnhance.selectedRender(this.canvas, AxisUtils.changeRectByZoom(selectedRect, this.zoom, this.currentPos), this.getRenderStyle(selectedRect));
1100
+ }
1101
+ }
1102
+ }
1103
+ renderCreatingRect() {
1104
+ if (!this.drawingRect) {
1105
+ return;
1106
+ }
1107
+ const {renderEnhance = {}} = this;
1108
+ this.renderDrawingRect(this.drawingRect, 1, true);
1109
+ if (renderEnhance.creatingRender) {
1110
+ renderEnhance.creatingRender(this.canvas, AxisUtils.changeRectByZoom(this.drawingRect, 1, this.currentPos), this.getRenderStyle(this.drawingRect));
1111
+ }
1112
+ }
1113
+ renderRect() {
1114
+ switch (this.operationMode) {
1115
+ case EOperationMode.MultiMove:
1116
+ this.renderMultiSelectedRect();
1117
+ break;
1118
+ default: {
1119
+ this.renderStaticRect();
1120
+ this.renderCreatingRect();
1121
+ }
1122
+ }
1123
+ }
1124
+ render() {
1125
+ if (!this.ctx) {
1126
+ return;
1127
+ }
1128
+ super.render();
1129
+ this.renderRect();
1130
+ this.renderCursorLine(this.getLineColor(this.defaultAttribute));
1131
+ }
1132
+ setDefaultAttribute(defaultAttribute) {
1133
+ const oldDefault = this.defaultAttribute;
1134
+ this.defaultAttribute = defaultAttribute != null ? defaultAttribute : "";
1135
+ if (oldDefault !== defaultAttribute) {
1136
+ this.changeStyle(defaultAttribute);
1137
+ this.emit("changeAttributeSidebar");
1138
+ const {selectedRect} = this;
1139
+ if (selectedRect) {
1140
+ this.setRectList(this.rectList.map((v) => {
1141
+ if (v.id === this.selectedID) {
1142
+ return __spreadProps(__spreadValues({}, v), {
1143
+ attribute: this.defaultAttribute
1144
+ });
1145
+ }
1146
+ return v;
1147
+ }), true);
1148
+ this.history.pushHistory(this.rectList);
1149
+ this.render();
1150
+ }
1151
+ if (this.drawingRect) {
1152
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
1153
+ attribute: this.defaultAttribute
1154
+ });
1155
+ this.render();
1156
+ }
1157
+ if (this._textAttributInstance) {
1158
+ if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(this.defaultAttribute)) {
1159
+ this._textAttributInstance.clearTextAttribute();
1160
+ return;
1161
+ }
1162
+ this._textAttributInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
1163
+ }
1164
+ }
1165
+ }
1166
+ setValid(valid) {
1167
+ super.setValid(valid);
1168
+ this.emit("updateResult");
1169
+ }
1170
+ clearActiveStatus() {
1171
+ this.drawingRect = void 0;
1172
+ this.firstClickCoord = void 0;
1173
+ this.dragInfo = void 0;
1174
+ this.dragStatus = EDragStatus.Wait;
1175
+ this.setSelectedRectID(void 0);
1176
+ this.setOperationMode(EOperationMode.General);
1177
+ }
1178
+ clearResult(sendMessage = true) {
1179
+ const newRectList = this.rectList.filter((rect) => rect.disableDelete === true);
1180
+ if (newRectList.length > 0 && sendMessage) {
1181
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.ClearPartialData, this.lang));
1182
+ }
1183
+ this.setRectList(newRectList, true);
1184
+ this.setSelectedRectID(void 0);
1185
+ }
1186
+ deleteRect(rectID) {
1187
+ var _a;
1188
+ if (!rectID) {
1189
+ return;
1190
+ }
1191
+ const selectedRect = this.rectList.find((v) => v.id === rectID);
1192
+ if ((selectedRect == null ? void 0 : selectedRect.disableDelete) === true) {
1193
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.DisableDelete, this.lang));
1194
+ return;
1195
+ }
1196
+ this.setRectList(this.rectList.filter((v) => v.id !== rectID), true);
1197
+ this.history.pushHistory(this.rectList);
1198
+ this.setSelectedRectID(void 0);
1199
+ (_a = this._textAttributInstance) == null ? void 0 : _a.clearTextAttribute();
1200
+ this.render();
1201
+ }
1202
+ exportData() {
1203
+ const {rectList} = this;
1204
+ return [rectList, this.basicImgInfo];
1205
+ }
1206
+ undo() {
1207
+ const rectList = this.history.undo();
1208
+ if (rectList) {
1209
+ if (rectList.length !== this.rectList.length) {
1210
+ this.setSelectedRectID("");
1211
+ }
1212
+ this.setRectList(rectList, true);
1213
+ this.render();
1214
+ }
1215
+ }
1216
+ redo() {
1217
+ const rectList = this.history.redo();
1218
+ if (rectList) {
1219
+ if (rectList.length !== this.rectList.length) {
1220
+ this.setSelectedRectID("");
1221
+ }
1222
+ this.setRectList(rectList, true);
1223
+ this.render();
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ export { RectOperation, RectOperation as default };