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