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