@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,1434 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),tool=require("../../constant/tool.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),MathUtils=require("../../utils/MathUtils.js"),basicToolOperation=require("./basicToolOperation.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(d){return d&&typeof d=="object"&&"default"in d?d:{default:d}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,t,e)=>t in d?__defProp(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,__spreadValues=(d,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(d,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(d,e,t[e]);return d},__spreadProps=(d,t)=>__defProps(d,__getOwnPropDescs(t)),EStatus;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=___default.default.cloneDeep(this.activeLine);if(!n||n.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});n.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l))),this.isActive&&this.drawLineLength(n,a),this.updateActiveArea(),this.drawLine(n,e,a,!0,!0),this.drawLineNumber(n[0],o,a,"",this.defaultAttribute,r),e&&this.isCreate&&this.arc(e,POINT_RADIUS,a),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,a)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(r=>LineToolUtils.default.calcDistance(this.coordUtils.getRenderCoord(r),e)<=POINT_ACTIVE_RADIUS);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.updatedLine={id:"",valid:!1,order:0},this.toolName="lineTool",this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.selectedIDs=[],this.drawCurveLine=(e,i,s,n=!0,r=!1,o)=>{const h=polygonTool.createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),r&&LineToolUtils.default.setReferenceCtx(e),i.forEach(({specialEdge:a},l)=>{const u=h.splice(0,SEGMENT_NUMBER+1);e.save(),e.beginPath(),o===l&&(e.lineWidth=4),u.forEach(({x:c,y:f},g)=>{const L=g>0?"lineTo":"moveTo";a&&LineToolUtils.default.setSpecialEdgeStyle(e),e[L](c,f)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,r=!1)=>{const o=i?e.concat(i):e,h={color:s,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.default.drawCurveLine(this.ctx,o,h,!n,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),n&&e.forEach(a=>{var l,u;const c=a.id,f=c&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(c)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(a,f,s),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(c)||this.arc(a,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.default.setReferenceCtx(n),e.forEach((r,o)=>{if(n.beginPath(),o>0){const h=e[o-1];n.save(),(h==null?void 0:h.specialEdge)&&LineToolUtils.default.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===o&&(n.lineWidth=4),n.moveTo(h.x,h.y),n.lineTo(r.x,r.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:s,label:n}=i,r=s,o=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,o,!1),this.drawLineNumber(i.pointList[0],r,o,n,i.attribute,i.valid),i.id!==this.textEditingID&&(this.drawLineTextAttribute(i.pointList[1],o,i==null?void 0:i.textAttribute),this.drawLineLength(i.pointList,o))}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(r=>this.isInBasicPolygon({x:r.x+e,y:r.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(v=>___default.default.isNumber(v)?v+e:0),u=[r,a].map(v=>___default.default.isNumber(v)?v+i:0),c=o>=0&&h&&MathUtils.default.isInRange(l,s),f=r>=0&&a&&MathUtils.default.isInRange(u,n),g=c?e:0,L=f?i:0;this.lineDragging=!0,this.moveActiveArea(g,L)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const r=this.findHoverLine(i);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===keyCode.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===keyCode.Delete){this.deleteLine();return}if(e.keyCode===keyCode.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===keyCode.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.dependToolConfig={lineType:tool.ELineTypes.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===tool.ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===tool.ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===tool.EToolName.Polygon}get isDependRect(){return this.dependToolName===tool.EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(t=>this.attributeLockList.includes((t==null?void 0:t.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var t;return(t=this.config.showOrder)!=null?t:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>CanvasUtils.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===tool.ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.default.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return polygonTool.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===tool.ELineTypes.Curve?polygonTool.createSmoothCurvePoints(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const r=this.coordUtils.getRenderCoord(t[n-1]),o=this.coordUtils.getRenderCoord(s);return LineToolUtils.default.isInLine(e,r,o,i)})}arc(t,e=POINT_RADIUS,i){var s,n,r,o,h,a;if(this.ctx){const{x:l,y:u}=t;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,u,e,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:r}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,r,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}setSelectedIDs(t){this.selectedIDs=t,this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}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")}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(__spreadProps(__spreadValues({},t),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return StyleUtils.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?MathUtils.default.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const u=n?(a=(h=(o=this.attributeList)==null?void 0:o.find(c=>c.value===n))==null?void 0:h.key)!=null?a:n:"";l=[l,`${!r&&u?"\u65E0\u6548":""}${u}`].filter(c=>c).join("_")}this.drawText(t,l,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawLineLength(t,e){var i;if(((i=this.config)==null?void 0:i.showLineLength)&&t){const s=t.reduce((r,o,h)=>h<=0||!t[h-1].actual||!o.actual?r:r+LineToolUtils.default.calcDistance(t[h-1].actual,o.actual),0),n=t[t.length-1];this.drawText(n,`l = ${s.toFixed(2)}`,e)}}drawText(t,e,i,s){var n,r;this.ctx&&((n=this.ctx)==null||n.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=i,this.ctx.strokeStyle=i,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,s?DrawUtils.wrapText(this.canvas,e,t.x-LINE_ORDER_OFFSET.x,t.y-LINE_ORDER_OFFSET.y,s):this.ctx.fillText(e,t.x-LINE_ORDER_OFFSET.x,t.y-LINE_ORDER_OFFSET.y),(r=this.ctx)==null||r.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines()),this.emit("updateLineByDrag",this.updatedLine)}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return LineToolUtils.default.calcDistance(i,t)<=POINT_ACTIVE_RADIUS})}findHoverLine(t){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(s[o-1]);return LineToolUtils.default.isInLine(t,h,a,n)})})}getAdsorptionPoint(t){let e,i,s;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:r})=>{if(r===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const o=this.findNearestPoint(n,t);if(o){if(o.minDistance===0){e=o.point;return}(i===void 0||o.minDistance<i)&&(e=o.point,i=o.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let r=1;r<=t.length-1;r++){const o=this.coordUtils.getRenderCoord(t[r]),h=this.coordUtils.getRenderCoord(t[r-1]),{length:a,footPoint:l}=MathUtils.default.getFootOfPerpendicular(e,o,h),u=LineToolUtils.default.calcTwoPointDistance(o,e),c=LineToolUtils.default.calcTwoPointDistance(h,e);if(u<=i*2){s=o,i=0;break}if(c<=i*2){s=h,i=0;break}a<i&&(s=l,i=a)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?polygonTool.createSmoothCurvePointsFromPointList(t,SEGMENT_NUMBER):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;s=[r,r+h],n=[o,o+a]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){if(!this.selectedPoint)return;const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,r={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const r=this.activeLine.slice(-1)[0];return LineToolUtils.default.getVHPoint(r,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?this.coordUtils.getAbsCoord(i):this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(o=>o.id===(i==null?void 0:i.id)),n=MathUtils.default.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom),r=this.lineList[s];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=n,this.updateLineAttributes(r)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=MathUtils.default.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?___default.default.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,r=[e,e+s],o=[i,i+n];return MathUtils.default.isInRange(t.x,r)&&MathUtils.default.isInRange(t.y,o)}return MathUtils.default.isInRange(t.x,[0,this.imageSize.width])&&MathUtils.default.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const r=this.activeLine?this.activeLine[n-1]:void 0,o=this.isCurve?i.slice((n-1)*(SEGMENT_NUMBER+1),n*(SEGMENT_NUMBER+1)):[r,s];return this.pointInLine(o,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,__spreadProps(__spreadValues({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?LineToolUtils.default.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=___default.default.cloneDeep(this.activeLine),this.updatedLine=t,this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return AttributeUtils.default.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=uuid(),e={pointList:___default.default.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(t){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(h.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),this.emit("lineCreated",h,this.zoom,this.currentPos),(s=this.history)==null||s.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===keyCode.Shift}continueToEdit(){var t;this.updateStatus(0),this.cursor=void 0,(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(t){if(this.selectedID&&t.keyCode!==keyCode.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===keyCode.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===keyCode.Shift&&this.render(),t.keyCode===keyCode.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=AttributeUtils.default.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,r,o;return __spreadProps(__spreadValues({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(o=(r=i.pointList[0])==null?void 0:r.y)!=null?o:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===keyCode.Ctrl&&this.setInvalidLineOnCreating(t),[keyCode.Shift,keyCode.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=MathUtils.default.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.default.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.emit("lineDeleted",this.selectedID),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(r=>r.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(r=>r.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.changeStyle(this.defaultAttribute),this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),r=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,o=(e=(t=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:r,textAttribute:o}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),u=n?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,c=(i=(e=this.lineList.find(f=>f.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({container:this.container,icon:this.getTextIconSvg(r),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${c}`,{left:a.x,top:a.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}exports.INNER_POINT_RADIUS=INNER_POINT_RADIUS,exports.LINE_ORDER_OFFSET=LINE_ORDER_OFFSET,exports.POINT_ACTIVE_RADIUS=POINT_ACTIVE_RADIUS,exports.POINT_RADIUS=POINT_RADIUS,exports.SEGMENT_NUMBER=SEGMENT_NUMBER,exports.default=LineToolOperation;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _ = require('lodash');
6
+ var tool = require('../../constant/tool.js');
7
+ var ActionsHistory = require('../../utils/ActionsHistory.js');
8
+ var uuid = require('../../utils/uuid.js');
9
+ var keyCode = require('../../constant/keyCode.js');
10
+ var MathUtils = require('../../utils/MathUtils.js');
11
+ var basicToolOperation = require('./basicToolOperation.js');
12
+ var LineToolUtils = require('../../utils/tool/LineToolUtils.js');
13
+ var polygonTool = require('../../utils/tool/polygonTool.js');
14
+ var CommonToolUtils = require('../../utils/tool/CommonToolUtils.js');
15
+ var CanvasUtils = require('../../utils/tool/CanvasUtils.js');
16
+ var DrawUtils = require('../../utils/tool/DrawUtils.js');
17
+ var StyleUtils = require('../../utils/tool/StyleUtils.js');
18
+ var AttributeUtils = require('../../utils/tool/AttributeUtils.js');
19
+ var textAttributeClass = require('./textAttributeClass.js');
20
+
21
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
22
+
23
+ var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
24
+
25
+ var __defProp = Object.defineProperty;
26
+ var __defProps = Object.defineProperties;
27
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
28
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
29
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
30
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
31
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
32
+ var __spreadValues = (a, b) => {
33
+ for (var prop in b || (b = {}))
34
+ if (__hasOwnProp.call(b, prop))
35
+ __defNormalProp(a, prop, b[prop]);
36
+ if (__getOwnPropSymbols)
37
+ for (var prop of __getOwnPropSymbols(b)) {
38
+ if (__propIsEnum.call(b, prop))
39
+ __defNormalProp(a, prop, b[prop]);
40
+ }
41
+ return a;
42
+ };
43
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
44
+ var EStatus;
45
+ (function(EStatus2) {
46
+ EStatus2[EStatus2["Create"] = 0] = "Create";
47
+ EStatus2[EStatus2["Active"] = 1] = "Active";
48
+ EStatus2[EStatus2["None"] = 2] = "None";
49
+ })(EStatus || (EStatus = {}));
50
+ const SEGMENT_NUMBER = 16;
51
+ const LINE_ORDER_OFFSET = {
52
+ x: 0,
53
+ y: 20
54
+ };
55
+ const POINT_RADIUS = 3;
56
+ const POINT_ACTIVE_RADIUS = 5;
57
+ const INNER_POINT_RADIUS = 2;
58
+ class LineToolOperation extends basicToolOperation.BasicToolOperation {
59
+ constructor(props) {
60
+ super(props);
61
+ this.drawActivatedLine = (coord, e, hideTempAxis) => {
62
+ const activeLine = ___default["default"].cloneDeep(this.activeLine);
63
+ if (!activeLine || activeLine.length === 0) {
64
+ return;
65
+ }
66
+ const isActiveLineValid = this.isActiveLineValid();
67
+ let order;
68
+ const existLine = this.selectedID ? this.lineList.find((i) => i.id === this.selectedID) : void 0;
69
+ if (existLine) {
70
+ order = existLine.order;
71
+ } else {
72
+ order = this.nextOrder();
73
+ }
74
+ const color = this.getLineColorByAttribute({attribute: this.defaultAttribute, valid: !!isActiveLineValid});
75
+ activeLine.map((point) => Object.assign(point, {
76
+ actual: {x: point.x, y: point.y}
77
+ }, this.coordUtils.getRenderCoord(point)));
78
+ if (this.isActive) {
79
+ this.drawLineLength(activeLine, color);
80
+ }
81
+ this.updateActiveArea();
82
+ this.drawLine(activeLine, coord, color, true, true);
83
+ this.drawLineNumber(activeLine[0], order, color, "", this.defaultAttribute, isActiveLineValid);
84
+ if (coord && this.isCreate) {
85
+ this.arc(coord, POINT_RADIUS, color);
86
+ }
87
+ if (this.cursor && !this.selectedPoint && !hideTempAxis && !this.isShift) {
88
+ this.arc(this.cursor, POINT_ACTIVE_RADIUS, color);
89
+ }
90
+ };
91
+ this.drawHoverPoint = (coord) => {
92
+ if (this.isMousedown) {
93
+ return;
94
+ }
95
+ if (coord && this.isLineSelected) {
96
+ const pointList = this.getPointList(this.activeLine);
97
+ const hoverPoint = this.activeLine.find((i) => LineToolUtils["default"].calcDistance(this.coordUtils.getRenderCoord(i), coord) <= POINT_ACTIVE_RADIUS);
98
+ let nearestPoint;
99
+ if (!hoverPoint && this.activeLine) {
100
+ nearestPoint = this.findNearestPoint(pointList, coord);
101
+ }
102
+ this.hoverPointID = hoverPoint ? hoverPoint.id : void 0;
103
+ this.cursor = hoverPoint ? void 0 : nearestPoint == null ? void 0 : nearestPoint.point;
104
+ }
105
+ };
106
+ this.updatedLine = {
107
+ id: "",
108
+ valid: false,
109
+ order: 0
110
+ };
111
+ this.toolName = "lineTool";
112
+ this.lineList = [];
113
+ this.activeLine = [];
114
+ this.coordsInsideActiveArea = false;
115
+ this.hoverLineSegmentIndex = -1;
116
+ this.isShift = false;
117
+ this.isReference = false;
118
+ this.selectedIDs = [];
119
+ this.drawCurveLine = (ctx, points, config, applyLineWidth = true, isReference = false, hoverLineSegmentIndex) => {
120
+ const pointList = polygonTool.createSmoothCurvePointsFromPointList(points, SEGMENT_NUMBER);
121
+ ctx.save();
122
+ ctx.lineCap = "round";
123
+ ctx.lineJoin = "round";
124
+ ctx.strokeStyle = config.color;
125
+ if (applyLineWidth) {
126
+ ctx.lineWidth = config.lineWidth;
127
+ }
128
+ if (isReference) {
129
+ LineToolUtils["default"].setReferenceCtx(ctx);
130
+ }
131
+ points.forEach(({specialEdge}, index) => {
132
+ const curveLinePoints = pointList.splice(0, SEGMENT_NUMBER + 1);
133
+ ctx.save();
134
+ ctx.beginPath();
135
+ if (hoverLineSegmentIndex === index) {
136
+ ctx.lineWidth = 4;
137
+ }
138
+ curveLinePoints.forEach(({x, y}, pointIndex) => {
139
+ const fn = pointIndex > 0 ? "lineTo" : "moveTo";
140
+ if (specialEdge) {
141
+ LineToolUtils["default"].setSpecialEdgeStyle(ctx);
142
+ }
143
+ ctx[fn](x, y);
144
+ });
145
+ ctx.stroke();
146
+ ctx.restore();
147
+ });
148
+ ctx.restore();
149
+ };
150
+ this.drawLine = (points, cursor, color, showPoint = false, isActive = false) => {
151
+ const pointsToDraw = cursor ? points.concat(cursor) : points;
152
+ const lineConfig = {color, lineWidth: isActive ? 1 : this.lineStyle.lineWidth};
153
+ if (this.isCurve) {
154
+ LineToolUtils["default"].drawCurveLine(this.ctx, pointsToDraw, lineConfig, !showPoint, this.isReference, isActive ? this.hoverLineSegmentIndex : -1);
155
+ } else {
156
+ this.drawStraightLine(pointsToDraw, lineConfig, isActive);
157
+ }
158
+ if (showPoint) {
159
+ points.forEach((point) => {
160
+ var _a, _b;
161
+ const pointID = point.id;
162
+ const pointRadius = pointID && [this.hoverPointID, (_a = this.selectedPoint) == null ? void 0 : _a.id].includes(pointID) ? POINT_ACTIVE_RADIUS : POINT_RADIUS;
163
+ this.arc(point, pointRadius, color);
164
+ if (![this.hoverPointID, (_b = this.selectedPoint) == null ? void 0 : _b.id].includes(pointID)) {
165
+ this.arc(point, INNER_POINT_RADIUS, "white");
166
+ }
167
+ });
168
+ }
169
+ };
170
+ this.drawStraightLine = (points, config, isActive = false) => {
171
+ const {ctx} = this;
172
+ if (ctx) {
173
+ ctx.save();
174
+ ctx.lineCap = "round";
175
+ ctx.lineJoin = "round";
176
+ ctx.strokeStyle = config.color;
177
+ ctx.lineWidth = config.lineWidth;
178
+ if (this.isReference) {
179
+ LineToolUtils["default"].setReferenceCtx(ctx);
180
+ }
181
+ points.forEach((point, index) => {
182
+ ctx.beginPath();
183
+ if (index > 0) {
184
+ const prePoint = points[index - 1];
185
+ ctx.save();
186
+ if (prePoint == null ? void 0 : prePoint.specialEdge) {
187
+ LineToolUtils["default"].setSpecialEdgeStyle(ctx);
188
+ }
189
+ if (isActive && this.hoverLineSegmentIndex + 1 === index) {
190
+ ctx.lineWidth = 4;
191
+ }
192
+ ctx.moveTo(prePoint.x, prePoint.y);
193
+ ctx.lineTo(point.x, point.y);
194
+ ctx.stroke();
195
+ ctx.restore();
196
+ }
197
+ });
198
+ ctx.restore();
199
+ }
200
+ };
201
+ this.drawLines = () => {
202
+ try {
203
+ const lineList = ___default["default"].cloneDeep(this.attributeFilteredLines);
204
+ if (this.isHidden) {
205
+ return;
206
+ }
207
+ lineList.forEach((line) => {
208
+ if (line.id === this.selectedID) {
209
+ return;
210
+ }
211
+ if (line.pointList) {
212
+ line.pointList.map((i) => Object.assign(i, {actual: {x: i.x, y: i.y}}, this.coordUtils.getRenderCoord(i)));
213
+ const {order, label} = line;
214
+ const displayOrder = order;
215
+ const color = line && this.getLineColorByAttribute(line);
216
+ this.drawLine(line.pointList, void 0, color, false);
217
+ this.drawLineNumber(line.pointList[0], displayOrder, color, label, line.attribute, line.valid);
218
+ if (line.id !== this.textEditingID) {
219
+ this.drawLineTextAttribute(line.pointList[1], color, line == null ? void 0 : line.textAttribute);
220
+ this.drawLineLength(line.pointList, color);
221
+ }
222
+ }
223
+ });
224
+ } catch (e) {
225
+ console.error(e, "\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF");
226
+ this.lineList = [];
227
+ this.clearCanvas();
228
+ }
229
+ };
230
+ this.render = (nextPoint) => {
231
+ super.render();
232
+ this.drawLines();
233
+ this.drawActivatedLine(nextPoint, void 0, true);
234
+ this.renderTextAttribute();
235
+ this.renderCursorLine(this.getLineColor(this.defaultAttribute));
236
+ };
237
+ this.moveLineInPolygon = (offsetX, offsetY) => {
238
+ var _a;
239
+ if (!Array.isArray(this.activeLine)) {
240
+ return false;
241
+ }
242
+ const allPointsInRange = (_a = this.activeLine) == null ? void 0 : _a.every((i) => {
243
+ return this.isInBasicPolygon({x: i.x + offsetX, y: i.y + offsetY});
244
+ });
245
+ if (allPointsInRange) {
246
+ this.lineDragging = true;
247
+ this.moveActiveArea(offsetX, offsetY);
248
+ }
249
+ };
250
+ this.moveLineInRectRange = (offsetX, offsetY, rectHorizontalRange, rectVerticalRange) => {
251
+ if (this.activeArea === void 0) {
252
+ return;
253
+ }
254
+ const {top, left, right, bottom} = this.activeArea;
255
+ const hBoundaries = [left, right].map((i) => ___default["default"].isNumber(i) ? i + offsetX : 0);
256
+ const vBoundaries = [top, bottom].map((i) => ___default["default"].isNumber(i) ? i + offsetY : 0);
257
+ const horizontalInRange = left >= 0 && right && MathUtils["default"].isInRange(hBoundaries, rectHorizontalRange);
258
+ const verticalInRange = top >= 0 && bottom && MathUtils["default"].isInRange(vBoundaries, rectVerticalRange);
259
+ const calcOffsetX = horizontalInRange ? offsetX : 0;
260
+ const calcOffsetY = verticalInRange ? offsetY : 0;
261
+ this.lineDragging = true;
262
+ this.moveActiveArea(calcOffsetX, calcOffsetY);
263
+ };
264
+ this.onRightClick = (e) => {
265
+ this.cursor = void 0;
266
+ if (this.isCreate) {
267
+ if (this.isLinePointsNotEnough()) {
268
+ return;
269
+ }
270
+ this.stopLineCreating(true);
271
+ return;
272
+ }
273
+ this.setActiveArea(this.getCoordinate(e), true);
274
+ this.emit("contextmenu");
275
+ };
276
+ this.updateSelectedAttributeAfterHistoryChanged = () => {
277
+ if (this.selectedID) {
278
+ const line = this.lineList.find((i) => i.id === this.selectedID);
279
+ const attribute = line == null ? void 0 : line.attribute;
280
+ if (typeof attribute === "string") {
281
+ this.defaultAttribute = attribute;
282
+ this.updateAttribute(attribute);
283
+ this.render();
284
+ }
285
+ }
286
+ };
287
+ this.onLeftClick = (e) => {
288
+ const coord = this.getCoordinate(e);
289
+ const {lineDragging} = this;
290
+ this.lineDragging = false;
291
+ if (this.isSpaceKey) {
292
+ return;
293
+ }
294
+ if (this.isNone && e.ctrlKey) {
295
+ const hoveredLine = this.findHoverLine(coord);
296
+ if (hoveredLine) {
297
+ this.setInvalidLine(hoveredLine.id);
298
+ }
299
+ return;
300
+ }
301
+ if (this.isLinePointsExceed()) {
302
+ return;
303
+ }
304
+ const nextAxis = this.getNextPoint(e, coord);
305
+ if (this.isCreate || this.isNone) {
306
+ this.setCreatStatusAndAddPoint(nextAxis);
307
+ return;
308
+ }
309
+ if (this.isActive) {
310
+ if (lineDragging) {
311
+ return;
312
+ }
313
+ const isMouseCoordOutsideActiveArea = this.isMouseCoordOutsideActiveArea();
314
+ if (isMouseCoordOutsideActiveArea) {
315
+ this.setNoneStatus(false);
316
+ this.setCreatStatusAndAddPoint(nextAxis);
317
+ return;
318
+ }
319
+ const isSetSpecialLine = e.shiftKey;
320
+ if (isSetSpecialLine) {
321
+ this.updateLineSegmentSpecial(coord);
322
+ return;
323
+ }
324
+ if (this.coordsInsideActiveArea && e.ctrlKey) {
325
+ this.setInvalidLine(this.selectedID);
326
+ return;
327
+ }
328
+ this.addLinePointToActiveLine();
329
+ }
330
+ };
331
+ this.onDblclick = () => {
332
+ };
333
+ this.onKeyUp = (e) => {
334
+ super.onKeyUp(e);
335
+ this.isShift = false;
336
+ this.hoverLineSegmentIndex = -1;
337
+ if (e.keyCode === keyCode.Esc) {
338
+ this.stopLineCreating(false);
339
+ return;
340
+ }
341
+ if (this.isActive) {
342
+ if (e.keyCode === keyCode.Delete) {
343
+ this.deleteLine();
344
+ return;
345
+ }
346
+ if (e.keyCode === keyCode.F) {
347
+ this.setInvalidLine(this.selectedID);
348
+ return;
349
+ }
350
+ if (e.keyCode === keyCode.Space) {
351
+ this.continueToEdit();
352
+ return;
353
+ }
354
+ }
355
+ this.keyboardEventWhileLineCreating(e);
356
+ };
357
+ this.onRightDblClick = (e) => {
358
+ super.onRightDblClick(e);
359
+ const coord = this.getCoordinate(e);
360
+ if (this.isActive) {
361
+ const hoverPoint = this.findHoveredPoint(coord);
362
+ if (hoverPoint) {
363
+ this.deleteSelectedLinePoint(hoverPoint.id);
364
+ return;
365
+ }
366
+ this.deleteSelectedLine(coord);
367
+ }
368
+ };
369
+ this.setReference = (isReference) => {
370
+ this.isReference = isReference;
371
+ };
372
+ this.pointsWithinRange = (count) => {
373
+ if (this.lowerLimitPointNum && count < this.lowerLimitPointNum) {
374
+ return false;
375
+ }
376
+ if (this.upperLimitPointNum && count > this.upperLimitPointNum) {
377
+ return false;
378
+ }
379
+ return true;
380
+ };
381
+ this.setLineList = (lineList) => {
382
+ const lengthChanged = lineList.length !== this.lineListLen;
383
+ this.lineList = lineList;
384
+ if (lengthChanged) {
385
+ this.emit("updatePageNumber");
386
+ }
387
+ };
388
+ this.textChange = (v) => {
389
+ if (this.config.textConfigurable === false || !this.selectedID) {
390
+ return;
391
+ }
392
+ this.updateSelectedTextAttribute(v);
393
+ this.emit("selectedChange");
394
+ };
395
+ this.status = 2;
396
+ this.isMousedown = false;
397
+ this.lineDragging = false;
398
+ this.isLineValid = true;
399
+ this.setConfig(props.config);
400
+ this.prevAxis = {
401
+ x: 0,
402
+ y: 0
403
+ };
404
+ this.textEditingID = "";
405
+ this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
406
+ this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
407
+ this.actionsHistory = new ActionsHistory();
408
+ this.dependToolConfig = {
409
+ lineType: tool.ELineTypes.Line
410
+ };
411
+ }
412
+ get isLineSelected() {
413
+ return this.selectedID && this.activeLine;
414
+ }
415
+ get selectedLinePoints() {
416
+ return this.activeLine ? this.getPointList(this.activeLine) : [];
417
+ }
418
+ get isCreate() {
419
+ return this.status === 0;
420
+ }
421
+ get isActive() {
422
+ return this.status === 1;
423
+ }
424
+ get isNone() {
425
+ return this.status === 2;
426
+ }
427
+ get isCurve() {
428
+ return this.config.lineType === tool.ELineTypes.Curve;
429
+ }
430
+ get isMultipleColor() {
431
+ return this.config.lineColor === tool.ELineColor.MultiColor;
432
+ }
433
+ get imageSize() {
434
+ if (this.rotate % 180 === 0) {
435
+ return this.basicImgInfo;
436
+ }
437
+ return {
438
+ width: this.basicImgInfo.height,
439
+ height: this.basicImgInfo.width
440
+ };
441
+ }
442
+ get lineListLen() {
443
+ return this.lineList.length;
444
+ }
445
+ get edgeAdsorptionEnabled() {
446
+ return this.edgeAdsorption && !this.isCurve && this.lineListLen > 0;
447
+ }
448
+ get attributeConfigurable() {
449
+ return this.config.attributeConfigurable;
450
+ }
451
+ get isTextConfigurable() {
452
+ return this.config.textConfigurable;
453
+ }
454
+ get isDependPolygon() {
455
+ return this.dependToolName === tool.EToolName.Polygon;
456
+ }
457
+ get isDependRect() {
458
+ return this.dependToolName === tool.EToolName.Rect;
459
+ }
460
+ get isCurrentAttributeLocked() {
461
+ return this.attributeLockList.includes(this.defaultAttribute);
462
+ }
463
+ get attributeFilteredLines() {
464
+ if (this.attributeLockList.length > 0) {
465
+ return this.lineList.filter((v) => this.attributeLockList.includes((v == null ? void 0 : v.attribute) || ""));
466
+ }
467
+ return this.lineList;
468
+ }
469
+ get enableOutOfTarget() {
470
+ return this.config.enableOutOfTarget || this.config.outOfTarget || this.config.drawOutsideTarget;
471
+ }
472
+ get showOrder() {
473
+ var _a;
474
+ return (_a = this.config.showOrder) != null ? _a : this.config.isShowOrder;
475
+ }
476
+ get edgeAdsorption() {
477
+ return this.config.edgeAdsorption;
478
+ }
479
+ get attributeList() {
480
+ return this.config.attributeList;
481
+ }
482
+ get lowerLimitPointNum() {
483
+ return this.config.lowerLimitPointNum;
484
+ }
485
+ get upperLimitPointNum() {
486
+ return this.config.upperLimitPointNum;
487
+ }
488
+ get textCheckType() {
489
+ return this.config.textCheckType;
490
+ }
491
+ get customFormat() {
492
+ return this.config.customFormat;
493
+ }
494
+ get dataList() {
495
+ return this.lineList;
496
+ }
497
+ get hasActiveLine() {
498
+ return this.activeLine && this.activeLine.length > 0;
499
+ }
500
+ get viewPortLines() {
501
+ const viewPort = CanvasUtils.getViewPort(this.canvas, this.currentPos, this.zoom);
502
+ if (this.isHidden) {
503
+ return [];
504
+ }
505
+ return this.attributeFilteredLines.filter((i) => {
506
+ var _a;
507
+ return (_a = i == null ? void 0 : i.pointList) == null ? void 0 : _a.some((p) => CanvasUtils.inViewPort(p, viewPort));
508
+ });
509
+ }
510
+ get lineStyle() {
511
+ return {
512
+ lineWidth: this.style.width,
513
+ color: this.getLineColor(this.defaultAttribute),
514
+ opacity: this.style.opacity
515
+ };
516
+ }
517
+ get selectedText() {
518
+ var _a, _b;
519
+ return (_b = (_a = this.lineList.find((i) => i.id === this.selectedID)) == null ? void 0 : _a.textAttribute) != null ? _b : "";
520
+ }
521
+ get currentPageResult() {
522
+ return this.lineList;
523
+ }
524
+ updateStatus(status, resetText = false) {
525
+ if (status === this.status) {
526
+ return;
527
+ }
528
+ if (resetText) {
529
+ let defaultText = "";
530
+ if (this.textCheckType === tool.ETextType.Order && this.isTextConfigurable) {
531
+ defaultText = AttributeUtils["default"].getTextAttribute(this.lineList, this.textCheckType);
532
+ }
533
+ this.emit("updateText", defaultText);
534
+ }
535
+ this.status = status;
536
+ this.lineStatusChanged();
537
+ }
538
+ isInBasicPolygon(coord) {
539
+ var _a, _b;
540
+ return polygonTool.isInPolygon(coord, ((_a = this.basicResult) == null ? void 0 : _a.pointList) || [], (_b = this.dependToolConfig) == null ? void 0 : _b.lineType);
541
+ }
542
+ getPolygonPointList() {
543
+ if (!this.basicResult) {
544
+ return [];
545
+ }
546
+ const {pointList} = this.basicResult;
547
+ const {lineType} = this.dependToolConfig;
548
+ return lineType === tool.ELineTypes.Curve ? polygonTool.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
549
+ return [...acc, cur.x, cur.y];
550
+ }, []), 0.5, true, 20) : pointList;
551
+ }
552
+ getNextCoordByRenderCoord(renderCoord) {
553
+ return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(renderCoord));
554
+ }
555
+ getNextCoordByAbsCoord(absCoord) {
556
+ var _a;
557
+ const preAxis = (_a = this.activeLine) == null ? void 0 : _a.slice(-1)[0];
558
+ if (preAxis) {
559
+ return this.coordUtils.getNextCoordByDependTool(absCoord, preAxis);
560
+ }
561
+ return absCoord;
562
+ }
563
+ pointInLine(pointList, checkPoint, scope) {
564
+ if (pointList.filter((i) => i).length < 2) {
565
+ return false;
566
+ }
567
+ return pointList.some((point, index) => {
568
+ if (index === 0) {
569
+ return false;
570
+ }
571
+ const point1 = this.coordUtils.getRenderCoord(pointList[index - 1]);
572
+ const point2 = this.coordUtils.getRenderCoord(point);
573
+ return LineToolUtils["default"].isInLine(checkPoint, point1, point2, scope);
574
+ });
575
+ }
576
+ arc(coord, size = POINT_RADIUS, color) {
577
+ var _a, _b, _c, _d, _e, _f;
578
+ if (this.ctx) {
579
+ const {x, y} = coord;
580
+ (_a = this.ctx) == null ? void 0 : _a.save();
581
+ (_b = this.ctx) == null ? void 0 : _b.beginPath();
582
+ this.ctx.fillStyle = color || this.lineStyle.color;
583
+ (_c = this.ctx) == null ? void 0 : _c.arc(x, y, size, 0, 360);
584
+ (_d = this.ctx) == null ? void 0 : _d.closePath();
585
+ (_e = this.ctx) == null ? void 0 : _e.fill();
586
+ (_f = this.ctx) == null ? void 0 : _f.restore();
587
+ }
588
+ }
589
+ renderActiveArea() {
590
+ if (this.isActive && this.activeArea && this.ctx) {
591
+ const {top, left, right, bottom} = this.activeArea;
592
+ const {x, y} = this.coordUtils.getRenderCoord({x: left, y: top});
593
+ this.ctx.save();
594
+ this.ctx.beginPath();
595
+ this.ctx.strokeStyle = "#B3B8FF";
596
+ this.ctx.rect(x, y, (right - left) * this.zoom, (bottom - top) * this.zoom);
597
+ this.ctx.stroke();
598
+ this.ctx.restore();
599
+ }
600
+ }
601
+ setSelectedIDs(selectedIDs) {
602
+ this.selectedIDs = selectedIDs;
603
+ if (this.selectedIDs.length < 2) {
604
+ this.setSelectedID(this.selectedIDs.length === 1 ? this.selectedIDs[0] : "");
605
+ }
606
+ this.render();
607
+ }
608
+ setSelectedID(newID) {
609
+ var _a, _b;
610
+ const oldID = this.selectedID;
611
+ if (newID !== oldID && oldID) {
612
+ (_a = this._textAttributInstance) == null ? void 0 : _a.changeSelected();
613
+ }
614
+ if (!newID) {
615
+ (_b = this._textAttributInstance) == null ? void 0 : _b.clearTextAttribute();
616
+ }
617
+ this.selectedID = newID;
618
+ this.render();
619
+ this.emit("selectedChange");
620
+ }
621
+ addLinePoint(coord) {
622
+ var _a, _b, _c, _d;
623
+ this.arc(coord);
624
+ (_a = this.activeLine) == null ? void 0 : _a.push(__spreadProps(__spreadValues({}, coord), {id: uuid()}));
625
+ if (((_b = this.activeLine) == null ? void 0 : _b.length) === 1) {
626
+ (_c = this.actionsHistory) == null ? void 0 : _c.initRecord(this.activeLine);
627
+ } else {
628
+ (_d = this.actionsHistory) == null ? void 0 : _d.pushHistory(this.activeLine);
629
+ }
630
+ this.render();
631
+ }
632
+ setCreatStatusAndAddPoint(coord, isRestText = false) {
633
+ this.updateStatus(0, isRestText);
634
+ this.addLinePoint(coord);
635
+ }
636
+ isActiveLineValid() {
637
+ var _a;
638
+ return this.selectedID ? (_a = this.lineList.find((i) => i.id === this.selectedID)) == null ? void 0 : _a.valid : this.isLineValid;
639
+ }
640
+ nextOrder() {
641
+ return this.lineListLen === 0 ? 1 : this.lineList.slice(-1)[0].order + 1;
642
+ }
643
+ getLineColorByAttribute(line, isSelected = false) {
644
+ return StyleUtils.getStrokeAndFill(this.getColor(line.attribute), line.valid, {isSelected}).stroke;
645
+ }
646
+ updateActiveArea() {
647
+ this.activeArea = this.getActiveArea();
648
+ this.renderActiveArea();
649
+ }
650
+ getActiveArea() {
651
+ return this.hasActiveLine ? MathUtils["default"].calcViewportBoundaries(this.activeLine, this.isCurve, SEGMENT_NUMBER, this.zoom) : void 0;
652
+ }
653
+ drawLineNumber(coord, order = 1, color, label = "", attribute, valid = true) {
654
+ var _a, _b, _c;
655
+ if ((this.showOrder || this.attributeConfigurable) && this.ctx) {
656
+ let text = this.showOrder ? order.toString() : `${label}`;
657
+ if (this.attributeConfigurable) {
658
+ const keyForAttribute = attribute ? (_c = (_b = (_a = this.attributeList) == null ? void 0 : _a.find((i) => i.value === attribute)) == null ? void 0 : _b.key) != null ? _c : attribute : "";
659
+ text = [text, `${!valid && keyForAttribute ? "\u65E0\u6548" : ""}${keyForAttribute}`].filter((i) => i).join("_");
660
+ }
661
+ this.drawText(coord, text, color);
662
+ }
663
+ }
664
+ drawLineTextAttribute(coord, color, text) {
665
+ if (coord && text) {
666
+ return this.drawText(coord, text, color, 200);
667
+ }
668
+ }
669
+ drawLineLength(pointList, color) {
670
+ var _a;
671
+ if (((_a = this.config) == null ? void 0 : _a.showLineLength) && pointList) {
672
+ const length = pointList.reduce((pre, next, index) => {
673
+ if (index <= 0 || !pointList[index - 1].actual || !next.actual) {
674
+ return pre;
675
+ }
676
+ return pre + LineToolUtils["default"].calcDistance(pointList[index - 1].actual, next.actual);
677
+ }, 0);
678
+ const renderPos = pointList[pointList.length - 1];
679
+ this.drawText(renderPos, `l = ${length.toFixed(2)}`, color);
680
+ }
681
+ }
682
+ drawText(coord, text, color, lineWidth) {
683
+ var _a, _b;
684
+ if (this.ctx) {
685
+ (_a = this.ctx) == null ? void 0 : _a.save();
686
+ this.ctx.font = "italic bold 14px SourceHanSansCN-Regular";
687
+ this.ctx.fillStyle = color;
688
+ this.ctx.strokeStyle = color;
689
+ this.ctx.shadowColor = "rgba(0, 0, 0, 0.6)";
690
+ this.ctx.shadowOffsetY = 2;
691
+ this.ctx.shadowBlur = 4;
692
+ if (lineWidth) {
693
+ DrawUtils.wrapText(this.canvas, text, coord.x - LINE_ORDER_OFFSET.x, coord.y - LINE_ORDER_OFFSET.y, lineWidth);
694
+ } else {
695
+ this.ctx.fillText(text, coord.x - LINE_ORDER_OFFSET.x, coord.y - LINE_ORDER_OFFSET.y);
696
+ }
697
+ (_b = this.ctx) == null ? void 0 : _b.restore();
698
+ }
699
+ }
700
+ moveActiveArea(offsetX, offsetY) {
701
+ if (this.activeArea) {
702
+ this.activeArea = Object.assign(this.activeArea, {
703
+ top: this.activeArea.top + offsetY,
704
+ bottom: this.activeArea.bottom + offsetY,
705
+ right: this.activeArea.right + offsetX,
706
+ left: this.activeArea.left + offsetX
707
+ });
708
+ }
709
+ if (this.activeLine) {
710
+ this.activeLine.map((i) => Object.assign(i, {x: i.x + offsetX, y: i.y + offsetY}));
711
+ this.updateLines();
712
+ }
713
+ this.emit("updateLineByDrag", this.updatedLine);
714
+ }
715
+ findHoveredPoint(coord) {
716
+ if (!this.activeLine) {
717
+ return;
718
+ }
719
+ return this.activeLine.find((i) => {
720
+ const iAxis = this.coordUtils.getRenderCoord(i);
721
+ return LineToolUtils["default"].calcDistance(iAxis, coord) <= POINT_ACTIVE_RADIUS;
722
+ });
723
+ }
724
+ findHoverLine(coord) {
725
+ const line = ___default["default"].cloneDeep(this.lineList).reverse().find(({pointList}) => {
726
+ const list = pointList ? this.getPointList(pointList) : [];
727
+ const scope = this.getLineWidthScope();
728
+ return list.some((point, index) => {
729
+ if (index === 0) {
730
+ return false;
731
+ }
732
+ const point1 = this.coordUtils.getRenderCoord(point);
733
+ const point2 = this.coordUtils.getRenderCoord(list[index - 1]);
734
+ return LineToolUtils["default"].isInLine(coord, point1, point2, scope);
735
+ });
736
+ });
737
+ return line;
738
+ }
739
+ getAdsorptionPoint(coord) {
740
+ let point;
741
+ let minDistance;
742
+ let snappedPoint;
743
+ ___default["default"].cloneDeep(this.lineList).reverse().forEach(({pointList, id}) => {
744
+ if (id === this.selectedID || !pointList || (pointList == null ? void 0 : pointList.length) < 2) {
745
+ return;
746
+ }
747
+ const nearestPoint = this.findNearestPoint(pointList, coord);
748
+ if (nearestPoint) {
749
+ if (nearestPoint.minDistance === 0) {
750
+ point = nearestPoint.point;
751
+ return;
752
+ }
753
+ if (minDistance === void 0 || nearestPoint.minDistance < minDistance) {
754
+ point = nearestPoint.point;
755
+ minDistance = nearestPoint.minDistance;
756
+ }
757
+ }
758
+ });
759
+ return snappedPoint || point;
760
+ }
761
+ findNearestPoint(pointList, coord, minLength = 7) {
762
+ let point;
763
+ const minDistance = minLength;
764
+ for (let i = 1; i <= pointList.length - 1; i++) {
765
+ const point1 = this.coordUtils.getRenderCoord(pointList[i]);
766
+ const point2 = this.coordUtils.getRenderCoord(pointList[i - 1]);
767
+ const {length, footPoint} = MathUtils["default"].getFootOfPerpendicular(coord, point1, point2);
768
+ const twoPointDistance1 = LineToolUtils["default"].calcTwoPointDistance(point1, coord);
769
+ const twoPointDistance2 = LineToolUtils["default"].calcTwoPointDistance(point2, coord);
770
+ if (twoPointDistance1 <= minLength * 2) {
771
+ point = point1;
772
+ minLength = 0;
773
+ break;
774
+ }
775
+ if (twoPointDistance2 <= minLength * 2) {
776
+ point = point2;
777
+ minLength = 0;
778
+ break;
779
+ }
780
+ if (length < minLength) {
781
+ point = footPoint;
782
+ minLength = length;
783
+ }
784
+ }
785
+ return point ? {point, minDistance} : void 0;
786
+ }
787
+ getPointList(pointList) {
788
+ return this.isCurve ? polygonTool.createSmoothCurvePointsFromPointList(pointList, SEGMENT_NUMBER) : pointList;
789
+ }
790
+ moveSelectedLine(coord) {
791
+ const offsetX = (coord.x - this.prevAxis.x) / this.zoom;
792
+ const offsetY = (coord.y - this.prevAxis.y) / this.zoom;
793
+ if (this.enableOutOfTarget) {
794
+ this.lineDragging = true;
795
+ this.moveActiveArea(offsetX, offsetY);
796
+ return;
797
+ }
798
+ if (this.isDependPolygon) {
799
+ this.moveLineInPolygon(offsetX, offsetY);
800
+ return;
801
+ }
802
+ let rectHorizontalRange = [0, this.imageSize.width];
803
+ let rectVerticalRange = [0, this.imageSize.height];
804
+ if (this.isDependRect) {
805
+ const {x, y, width, height} = this.basicResult;
806
+ rectHorizontalRange = [x, x + width];
807
+ rectVerticalRange = [y, y + height];
808
+ }
809
+ this.moveLineInRectRange(offsetX, offsetY, rectHorizontalRange, rectVerticalRange);
810
+ }
811
+ moveSelectPoint(coord) {
812
+ if (!this.selectedPoint) {
813
+ return;
814
+ }
815
+ const offsetX = coord.x - this.prevAxis.x;
816
+ const offsetY = coord.y - this.prevAxis.y;
817
+ const newX = (this.selectedPoint ? this.selectedPoint.x : 0) + offsetX / this.zoom;
818
+ const newY = (this.selectedPoint ? this.selectedPoint.y : 0) + offsetY / this.zoom;
819
+ const pointPosition = {
820
+ x: newX,
821
+ y: newY
822
+ };
823
+ Object.assign(this.selectedPoint, this.getNextCoordByAbsCoord(pointPosition));
824
+ this.updateLines();
825
+ this.render();
826
+ }
827
+ getCoordByConfig(e, coord) {
828
+ var _a;
829
+ const isVH = !!e.shiftKey;
830
+ const disabledAdsorb = e.altKey;
831
+ if (((_a = this.activeLine) == null ? void 0 : _a.length) > 0 && isVH) {
832
+ const lastPoint = this.activeLine.slice(-1)[0];
833
+ return LineToolUtils["default"].getVHPoint(lastPoint, coord, this.coordUtils.getAbsCoord(coord), this.coordUtils.getRenderCoord(lastPoint));
834
+ }
835
+ if (this.edgeAdsorptionEnabled && !disabledAdsorb) {
836
+ return this.getAdsorptionPoint(coord);
837
+ }
838
+ return coord;
839
+ }
840
+ getNextPoint(e, nextPoint) {
841
+ const newPoint = this.getCoordByConfig(e, nextPoint) || nextPoint;
842
+ return this.enableOutOfTarget ? this.coordUtils.getAbsCoord(newPoint) : this.getNextCoordByRenderCoord(newPoint);
843
+ }
844
+ lineHover() {
845
+ this.render();
846
+ }
847
+ mouseMoveHandler(e) {
848
+ const coord = this.getCoordinate(e);
849
+ const isLeftClick = e.which === 1;
850
+ if (this.isCreate) {
851
+ if (this.hasActiveLine) {
852
+ this.renderNextPoint(e, coord);
853
+ }
854
+ return;
855
+ }
856
+ if (this.isNone) {
857
+ this.lineHover();
858
+ if (this.edgeAdsorptionEnabled && !e.altKey) {
859
+ const edgeAdsorptionPoint = this.getAdsorptionPoint(coord);
860
+ if (edgeAdsorptionPoint) {
861
+ this.arc(edgeAdsorptionPoint);
862
+ }
863
+ }
864
+ }
865
+ if (this.isActive) {
866
+ if (this.isMousedown && isLeftClick) {
867
+ if (this.selectedPoint) {
868
+ this.moveSelectPoint(coord);
869
+ return;
870
+ }
871
+ if (this.coordsInsideActiveArea) {
872
+ this.moveSelectedLine(coord);
873
+ this.drawActivatedLine(void 0, void 0, true);
874
+ return;
875
+ }
876
+ }
877
+ this.drawHoverPoint(coord);
878
+ this.render();
879
+ }
880
+ }
881
+ onMouseMove(e) {
882
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
883
+ return;
884
+ }
885
+ const coord = this.getCoordinate(e);
886
+ this.mouseMoveHandler(e);
887
+ this.prevAxis = coord;
888
+ }
889
+ setActiveArea(coord, outsideCancel = false) {
890
+ const activeLine = this.findHoverLine(coord);
891
+ if (activeLine) {
892
+ const index = this.lineList.findIndex((i) => i.id === (activeLine == null ? void 0 : activeLine.id));
893
+ const area = MathUtils["default"].calcViewportBoundaries((activeLine == null ? void 0 : activeLine.pointList) || [], this.isCurve, SEGMENT_NUMBER, this.zoom);
894
+ const line = this.lineList[index];
895
+ this.updateStatus(1);
896
+ this.setActiveLine(line.pointList);
897
+ this.setSelectedLineID(line.id);
898
+ this.activeArea = area;
899
+ this.updateLineAttributes(line);
900
+ } else if (outsideCancel) {
901
+ this.setNoneStatus();
902
+ }
903
+ this.render();
904
+ }
905
+ setActiveLineByID(id) {
906
+ const line = this.lineList.find((i) => i.id === id);
907
+ if (line) {
908
+ const area = MathUtils["default"].calcViewportBoundaries((line == null ? void 0 : line.pointList) || [], this.isCurve, SEGMENT_NUMBER, this.zoom);
909
+ this.updateStatus(1);
910
+ this.setActiveLine(line.pointList);
911
+ this.setSelectedLineID(line.id);
912
+ this.activeArea = area;
913
+ this.updateLineAttributes(line);
914
+ }
915
+ this.render();
916
+ }
917
+ setActiveLine(pointList) {
918
+ this.activeLine = pointList ? ___default["default"].cloneDeep(pointList) : void 0;
919
+ }
920
+ historyChanged(funcName) {
921
+ const enableKeyName = `${funcName}Enabled`;
922
+ if (this.isCreate) {
923
+ if (this.actionsHistory && this.actionsHistory[enableKeyName]) {
924
+ const record = this.actionsHistory && this.actionsHistory[funcName]();
925
+ this.setActiveLine(record);
926
+ this.render();
927
+ }
928
+ return;
929
+ }
930
+ if (this.history && this.history[enableKeyName]) {
931
+ const currentHistory = this.history[funcName]();
932
+ const activeLine = currentHistory == null ? void 0 : currentHistory.find((i) => i.id === this.selectedID);
933
+ this.lineList = currentHistory;
934
+ if (this.selectedID && activeLine) {
935
+ this.setActiveLine(activeLine == null ? void 0 : activeLine.pointList);
936
+ } else {
937
+ this.setNoneStatus();
938
+ }
939
+ this.render();
940
+ }
941
+ this.emit("dataUpdated", this.lineList);
942
+ }
943
+ undo() {
944
+ this.historyChanged("undo");
945
+ this.updateSelectedAttributeAfterHistoryChanged();
946
+ }
947
+ redo() {
948
+ this.historyChanged("redo");
949
+ this.updateSelectedAttributeAfterHistoryChanged();
950
+ }
951
+ isCoordInsideTarget(coord) {
952
+ if (this.isDependPolygon) {
953
+ return this.isInBasicPolygon(coord);
954
+ }
955
+ if (this.isDependRect) {
956
+ const {x, y, width, height} = this.basicResult;
957
+ const rectHorizontalRange = [x, x + width];
958
+ const rectVerticalRange = [y, y + height];
959
+ return MathUtils["default"].isInRange(coord.x, rectHorizontalRange) && MathUtils["default"].isInRange(coord.y, rectVerticalRange);
960
+ }
961
+ return MathUtils["default"].isInRange(coord.x, [0, this.imageSize.width]) && MathUtils["default"].isInRange(coord.y, [0, this.imageSize.height]);
962
+ }
963
+ getPointInsertIndex(coord, scope) {
964
+ if (coord && this.activeLine) {
965
+ const pointList = this.getPointList(this.activeLine);
966
+ if (this.activeLine.length === 2) {
967
+ return 1;
968
+ }
969
+ return this.activeLine.findIndex((i, index) => {
970
+ if (index > 0) {
971
+ const straightLinePoints = this.activeLine ? this.activeLine[index - 1] : void 0;
972
+ const points = this.isCurve ? pointList.slice((index - 1) * (SEGMENT_NUMBER + 1), index * (SEGMENT_NUMBER + 1)) : [straightLinePoints, i];
973
+ return this.pointInLine(points, coord, scope || this.getLineWidthScope());
974
+ }
975
+ return false;
976
+ });
977
+ }
978
+ return -1;
979
+ }
980
+ getLineWidthScope() {
981
+ return this.lineStyle.lineWidth;
982
+ }
983
+ isMouseCoordOutsideActiveArea() {
984
+ return !this.coordsInsideActiveArea && !this.selectedPoint;
985
+ }
986
+ isLinePointsExceed() {
987
+ return this.isCreate && this.activeLine && this.upperLimitPointNum && ~~this.upperLimitPointNum <= this.activeLine.length;
988
+ }
989
+ isLinePointsNotEnough() {
990
+ var _a;
991
+ return this.activeLine && ((_a = this.activeLine) == null ? void 0 : _a.length) < this.lowerLimitPointNum;
992
+ }
993
+ updateLineSegmentSpecial(coord) {
994
+ const specialEdgeIndex = this.getPointInsertIndex(coord, 2) - 1;
995
+ if (specialEdgeIndex > -1) {
996
+ const pointData = this.activeLine[specialEdgeIndex];
997
+ pointData.specialEdge = !pointData.specialEdge;
998
+ this.hoverLineSegmentIndex = -1;
999
+ this.render();
1000
+ }
1001
+ }
1002
+ addLinePointToActiveLine() {
1003
+ var _a;
1004
+ const insertIndex = this.getPointInsertIndex(this.cursor);
1005
+ const pointsWithInRange = this.pointsWithinRange(this.activeLine.length + 1);
1006
+ if (this.cursor && insertIndex > -1 && pointsWithInRange) {
1007
+ this.activeLine.splice(insertIndex, 0, __spreadProps(__spreadValues({}, this.coordUtils.getAbsCoord(this.cursor)), {id: uuid()}));
1008
+ this.updateLines();
1009
+ (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList);
1010
+ this.render();
1011
+ this.cursor = void 0;
1012
+ }
1013
+ }
1014
+ onMouseDown(e) {
1015
+ if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
1016
+ return;
1017
+ }
1018
+ const coord = this.getCoordinate(e);
1019
+ this.isMousedown = true;
1020
+ this.prevAxis = coord;
1021
+ if (e.which === 3) {
1022
+ this.cursor = void 0;
1023
+ return;
1024
+ }
1025
+ this.selectedPoint = this.findHoveredPoint(coord);
1026
+ this.coordsInsideActiveArea = this.isActive && this.activeArea ? LineToolUtils["default"].inArea(this.activeArea, this.coordUtils.getAbsCoord(coord)) : false;
1027
+ this.lineDragging = false;
1028
+ }
1029
+ lineHasChanged() {
1030
+ const line = this.lineList.find((i) => i.id === this.selectedID);
1031
+ return line ? JSON.stringify(line.pointList) !== JSON.stringify(this.activeLine) : false;
1032
+ }
1033
+ updateLines() {
1034
+ const line = this.lineList.find((i) => i.id === this.selectedID);
1035
+ if (line) {
1036
+ line.pointList = ___default["default"].cloneDeep(this.activeLine);
1037
+ this.updatedLine = line;
1038
+ this.emit("dataUpdated", this.lineList);
1039
+ }
1040
+ }
1041
+ onMouseUp(e) {
1042
+ const reset = () => {
1043
+ this.isMousedown = false;
1044
+ this.hoverPointID = void 0;
1045
+ this.cursor = void 0;
1046
+ this.selectedPoint = void 0;
1047
+ };
1048
+ this.hoverPointID = void 0;
1049
+ if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
1050
+ reset();
1051
+ return;
1052
+ }
1053
+ if (e.which === 1) {
1054
+ this.onLeftClick(e);
1055
+ }
1056
+ if (e.which === 3) {
1057
+ this.onRightClick(e);
1058
+ }
1059
+ reset();
1060
+ }
1061
+ isTextValid(text) {
1062
+ return AttributeUtils["default"].textAttributeValidate(this.textCheckType, this.customFormat, text);
1063
+ }
1064
+ createLineData() {
1065
+ const id = uuid();
1066
+ const newLine = {
1067
+ pointList: ___default["default"].cloneDeep(this.activeLine),
1068
+ id,
1069
+ valid: this.isLineValid,
1070
+ order: this.nextOrder()
1071
+ };
1072
+ newLine.attribute = this.defaultAttribute;
1073
+ return newLine;
1074
+ }
1075
+ stopLineCreating(isAppend = true) {
1076
+ var _a, _b, _c, _d;
1077
+ const setActiveAfterCreating = this.selectedID ? true : !!this.isTextConfigurable;
1078
+ let selectedID;
1079
+ if (isAppend) {
1080
+ if (this.selectedID) {
1081
+ const line = this.lineList.find((i) => i.id === this.selectedID);
1082
+ selectedID = this.selectedID;
1083
+ if (line) {
1084
+ line.pointList = ___default["default"].cloneWith(this.activeLine);
1085
+ if (!___default["default"].isEqual(line.pointList, (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList))) {
1086
+ (_b = this.history) == null ? void 0 : _b.pushHistory(this.lineList);
1087
+ }
1088
+ }
1089
+ } else if (this.isCreate && this.activeLine && this.activeLine.length > 1) {
1090
+ const newLine = this.createLineData();
1091
+ selectedID = newLine.id;
1092
+ this.setLineList([...this.lineList, newLine]);
1093
+ this.emit("lineCreated", newLine, this.zoom, this.currentPos);
1094
+ (_c = this.history) == null ? void 0 : _c.pushHistory(this.lineList);
1095
+ }
1096
+ }
1097
+ if (setActiveAfterCreating) {
1098
+ this.setActiveStatus(selectedID);
1099
+ } else {
1100
+ this.setNoneStatus();
1101
+ }
1102
+ (_d = this.actionsHistory) == null ? void 0 : _d.empty();
1103
+ this.emit("dataUpdated", this.lineList);
1104
+ this.render();
1105
+ }
1106
+ setActiveStatus(id) {
1107
+ const line = id ? this.lineList.find((i) => i.id === id) : void 0;
1108
+ if (line) {
1109
+ const pointList = line == null ? void 0 : line.pointList;
1110
+ this.updateStatus(1);
1111
+ this.setActiveLine(pointList);
1112
+ this.setSelectedLineID(id);
1113
+ } else {
1114
+ this.setNoneStatus();
1115
+ }
1116
+ }
1117
+ setNoneStatus(updateStatus = true) {
1118
+ if (updateStatus) {
1119
+ this.updateStatus(2);
1120
+ }
1121
+ this.activeLine = [];
1122
+ this.setSelectedLineID(void 0);
1123
+ this.activeArea = void 0;
1124
+ this.isLineValid = true;
1125
+ this.cursor = void 0;
1126
+ }
1127
+ setKeyDownStatus(e, value) {
1128
+ this.isShift = value != null ? value : e.keyCode === keyCode.Shift;
1129
+ }
1130
+ continueToEdit() {
1131
+ var _a;
1132
+ this.updateStatus(0);
1133
+ this.cursor = void 0;
1134
+ (_a = this.actionsHistory) == null ? void 0 : _a.pushHistory(this.activeLine);
1135
+ this.render();
1136
+ }
1137
+ setInvalidLineOnCreating(e) {
1138
+ if (this.selectedID && e.keyCode !== keyCode.Ctrl || !this.isCreate) {
1139
+ return;
1140
+ }
1141
+ const valid = !e.ctrlKey;
1142
+ if (this.selectedID) {
1143
+ this.setInvalidLine(this.selectedID, valid, false);
1144
+ } else {
1145
+ this.isLineValid = valid;
1146
+ }
1147
+ }
1148
+ onKeyDown(e) {
1149
+ super.onKeyDown(e);
1150
+ this.setKeyDownStatus(e);
1151
+ if (e.keyCode === keyCode.Z && !e.ctrlKey) {
1152
+ this.toggleIsHide();
1153
+ }
1154
+ if (e.keyCode === keyCode.Shift) {
1155
+ this.render();
1156
+ }
1157
+ if (e.keyCode === keyCode.Tab) {
1158
+ e.preventDefault();
1159
+ this.selectToNextLine(e);
1160
+ return;
1161
+ }
1162
+ if (this.isCreate) {
1163
+ this.keyboardEventWhileLineCreating(e);
1164
+ }
1165
+ if (this.config.attributeConfigurable) {
1166
+ const keyCode2Attribute = AttributeUtils["default"].getAttributeByKeycode(e.keyCode, this.config.attributeList);
1167
+ if (keyCode2Attribute !== void 0) {
1168
+ this.setDefaultAttribute(keyCode2Attribute);
1169
+ }
1170
+ }
1171
+ }
1172
+ selectToNextLine(e) {
1173
+ const nextSelectedLine = CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map((i) => {
1174
+ var _a, _b, _c, _d;
1175
+ return __spreadProps(__spreadValues({}, i), {
1176
+ x: (_b = (_a = i.pointList[0]) == null ? void 0 : _a.x) != null ? _b : 0,
1177
+ y: (_d = (_c = i.pointList[0]) == null ? void 0 : _c.y) != null ? _d : 0
1178
+ });
1179
+ }), e, this.selectedID);
1180
+ if (nextSelectedLine) {
1181
+ this.setActiveLineByID(nextSelectedLine.id);
1182
+ }
1183
+ }
1184
+ keyboardEventWhileLineCreating(e) {
1185
+ if (!this.isCreate) {
1186
+ return;
1187
+ }
1188
+ if (e.keyCode === keyCode.Ctrl) {
1189
+ this.setInvalidLineOnCreating(e);
1190
+ }
1191
+ if ([keyCode.Shift, keyCode.Alt].includes(e.keyCode)) {
1192
+ this.renderNextPoint(e, this.prevAxis);
1193
+ }
1194
+ }
1195
+ renderNextPoint(e, coord) {
1196
+ const nextPoint = this.coordUtils.getRenderCoord(this.getNextPoint(e, coord));
1197
+ this.render(nextPoint);
1198
+ }
1199
+ deleteSelectedLine(coord) {
1200
+ const boundary = MathUtils["default"].calcViewportBoundaries(this.activeLine, this.isCurve, SEGMENT_NUMBER, this.zoom);
1201
+ const axisOnArea = LineToolUtils["default"].inArea(boundary, this.coordUtils.getAbsCoord(coord));
1202
+ if (axisOnArea) {
1203
+ this.deleteLine();
1204
+ }
1205
+ }
1206
+ deleteSelectedLinePoint(selectedID) {
1207
+ var _a;
1208
+ const pointsWithinRange = this.pointsWithinRange(this.activeLine.length - 1);
1209
+ if (pointsWithinRange && selectedID) {
1210
+ this.setActiveLine(this.activeLine.filter((i) => i.id !== selectedID));
1211
+ this.updateLines();
1212
+ (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList);
1213
+ }
1214
+ this.cursor = void 0;
1215
+ this.render();
1216
+ }
1217
+ deleteLine() {
1218
+ var _a;
1219
+ this.lineList = this.lineList.filter((i) => i.id !== this.selectedID);
1220
+ (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList);
1221
+ this.setNoneStatus();
1222
+ this.emit("dataUpdated", this.lineList);
1223
+ this.emit("lineDeleted", this.selectedID);
1224
+ this.render();
1225
+ }
1226
+ setInvalidLine(id, valid, isRender = true) {
1227
+ var _a;
1228
+ const line = this.lineList.find((i) => i.id === id);
1229
+ if (line) {
1230
+ line.valid = valid !== void 0 ? valid : !line.valid;
1231
+ (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList);
1232
+ if (isRender) {
1233
+ this.render();
1234
+ }
1235
+ }
1236
+ }
1237
+ empty() {
1238
+ var _a, _b;
1239
+ this.lineList = [];
1240
+ this.setNoneStatus();
1241
+ this.selectedPoint = void 0;
1242
+ (_a = this.actionsHistory) == null ? void 0 : _a.empty();
1243
+ (_b = this.history) == null ? void 0 : _b.init();
1244
+ this.emit("dataUpdated", this.lineList);
1245
+ this.render();
1246
+ }
1247
+ setAttribute(attribute) {
1248
+ var _a;
1249
+ if (this.attributeConfigurable) {
1250
+ this.defaultAttribute = attribute;
1251
+ this.setLineAttribute("attribute", attribute);
1252
+ if (this.selectedID) {
1253
+ (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList);
1254
+ }
1255
+ }
1256
+ }
1257
+ setTextAttribute(text) {
1258
+ var _a;
1259
+ if (this.isTextConfigurable) {
1260
+ this.setLineAttribute("textAttribute", text);
1261
+ (_a = this.history) == null ? void 0 : _a.applyAttribute(this.selectedID, "textAttribute", text);
1262
+ }
1263
+ }
1264
+ setLineAttribute(key, value, id) {
1265
+ const targetID = id || this.selectedID;
1266
+ if (targetID) {
1267
+ const line = this.lineList.find((i) => i.id === targetID);
1268
+ if (line) {
1269
+ line[key] = value;
1270
+ }
1271
+ }
1272
+ this.render();
1273
+ }
1274
+ updateAttribute(attribute) {
1275
+ this.emit("updateAttribute", attribute);
1276
+ }
1277
+ updateLineAttributes(line) {
1278
+ var _a;
1279
+ if (this.attributeConfigurable && line) {
1280
+ const attribute = (line == null ? void 0 : line.attribute) || "";
1281
+ this.defaultAttribute = attribute;
1282
+ this.updateAttribute(attribute);
1283
+ }
1284
+ if (this.isTextConfigurable && line) {
1285
+ const text = (line == null ? void 0 : line.textAttribute) || "";
1286
+ this.updateTextAttribute(text);
1287
+ }
1288
+ (_a = this.history) == null ? void 0 : _a.updateHistory(this.lineList);
1289
+ }
1290
+ lineStatusChanged() {
1291
+ this.emit("lineStatusChanged", {
1292
+ status: this.status,
1293
+ selectedLineID: this.selectedID
1294
+ });
1295
+ }
1296
+ updateTextAttribute(text) {
1297
+ if (this.selectedID) {
1298
+ const line = this.lineList.find((i) => i.id === this.selectedID);
1299
+ if (line) {
1300
+ line.textAttribute = text;
1301
+ }
1302
+ }
1303
+ this.emit("updateText", text);
1304
+ }
1305
+ saveData() {
1306
+ this.stopLineCreating();
1307
+ this.setNoneStatus();
1308
+ this.render();
1309
+ }
1310
+ setTextEditingID(id) {
1311
+ this.textEditingID = id;
1312
+ this.render();
1313
+ }
1314
+ setSelectedLineID(id) {
1315
+ var _a, _b;
1316
+ if (this.selectedID === id) {
1317
+ return;
1318
+ }
1319
+ const oldID = this.selectedID;
1320
+ if (id !== oldID && oldID) {
1321
+ (_a = this._textAttributeInstance) == null ? void 0 : _a.changeSelected();
1322
+ }
1323
+ if (!id) {
1324
+ (_b = this._textAttributeInstance) == null ? void 0 : _b.clearTextAttribute();
1325
+ }
1326
+ this.selectedID = id;
1327
+ this.emit("selectedChange");
1328
+ }
1329
+ attributeLockListChange(attributeLockList) {
1330
+ this.attributeLockList = attributeLockList;
1331
+ this.render();
1332
+ }
1333
+ setResult(lineList) {
1334
+ this.setNoneStatus();
1335
+ this.setLineList(lineList);
1336
+ this.render();
1337
+ }
1338
+ setConfig(config) {
1339
+ super.setConfig(config);
1340
+ }
1341
+ toggleIsHide() {
1342
+ this.setIsHidden(!this.isHidden);
1343
+ this.render();
1344
+ }
1345
+ clearCanvas() {
1346
+ super.clearCanvas();
1347
+ }
1348
+ clearResult() {
1349
+ this.setResult([]);
1350
+ this.setSelectedLineID(void 0);
1351
+ this.render();
1352
+ }
1353
+ exportData() {
1354
+ return [this.lineList, this.basicImgInfo];
1355
+ }
1356
+ setDefaultAttribute(attribute = "") {
1357
+ var _a;
1358
+ if (this.attributeConfigurable) {
1359
+ this.defaultAttribute = attribute;
1360
+ this.changeStyle(this.defaultAttribute);
1361
+ this.setLineAttribute("attribute", attribute);
1362
+ if (this.selectedID) {
1363
+ (_a = this.history) == null ? void 0 : _a.pushHistory(this.lineList);
1364
+ }
1365
+ this.emit("changeAttributeSidebar");
1366
+ }
1367
+ }
1368
+ getCurrentSelectedData() {
1369
+ var _a, _b;
1370
+ const valid = this.isActiveLineValid();
1371
+ const attribute = this.defaultAttribute;
1372
+ const toolColor = this.getColor(attribute);
1373
+ const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
1374
+ const textAttribute = (_b = (_a = this.lineList.find((i) => i.id === this.selectedID)) == null ? void 0 : _a.textAttribute) != null ? _b : "";
1375
+ return {
1376
+ color,
1377
+ textAttribute
1378
+ };
1379
+ }
1380
+ renderTextAttribute() {
1381
+ var _a, _b, _c, _d;
1382
+ if (!this.ctx || !this.activeLine || ((_a = this.activeLine) == null ? void 0 : _a.length) < 2 || this.isCreate) {
1383
+ return;
1384
+ }
1385
+ const valid = this.isActiveLineValid();
1386
+ const attribute = this.defaultAttribute;
1387
+ const {x, y} = this.activeLine[1];
1388
+ const coordinate = this.coordUtils.getRenderCoord({x, y});
1389
+ const toolColor = this.getColor(attribute);
1390
+ const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
1391
+ const textAttribute = (_c = (_b = this.lineList.find((i) => i.id === this.selectedID)) == null ? void 0 : _b.textAttribute) != null ? _c : "";
1392
+ if (!this._textAttributeInstance) {
1393
+ this._textAttributeInstance = new textAttributeClass({
1394
+ container: this.container,
1395
+ icon: this.getTextIconSvg(attribute),
1396
+ color,
1397
+ getCurrentSelectedData: this.getCurrentSelectedData,
1398
+ updateSelectedTextAttribute: this.updateSelectedTextAttribute
1399
+ });
1400
+ }
1401
+ if (this._textAttributeInstance && !((_d = this._textAttributeInstance) == null ? void 0 : _d.isExit)) {
1402
+ this._textAttributeInstance.appendToContainer();
1403
+ }
1404
+ this._textAttributeInstance.update(`${textAttribute}`, {
1405
+ left: coordinate.x,
1406
+ top: coordinate.y,
1407
+ color
1408
+ });
1409
+ this._textAttributeInstance.updateIcon(this.getTextIconSvg(attribute));
1410
+ }
1411
+ getTextIconSvg(attribute = "") {
1412
+ return AttributeUtils["default"].getTextIconSvg(attribute, this.config.attributeList, this.config.attributeConfigurable, this.baseIcon);
1413
+ }
1414
+ updateSelectedTextAttribute(newTextAttribute) {
1415
+ if (this._textAttributeInstance && newTextAttribute && this.selectedID) {
1416
+ let textAttribute = newTextAttribute;
1417
+ const textAttributeInvalid = !AttributeUtils["default"].textAttributeValidate(this.config.textCheckType, "", textAttribute);
1418
+ if (textAttributeInvalid) {
1419
+ this.emit("messageError", AttributeUtils["default"].getErrorNotice(this.config.textCheckType, this.lang));
1420
+ textAttribute = "";
1421
+ }
1422
+ this.setTextAttribute(textAttribute);
1423
+ this.emit("updateTextAttribute");
1424
+ this.render();
1425
+ }
1426
+ }
1427
+ }
1428
+
1429
+ exports.INNER_POINT_RADIUS = INNER_POINT_RADIUS;
1430
+ exports.LINE_ORDER_OFFSET = LINE_ORDER_OFFSET;
1431
+ exports.POINT_ACTIVE_RADIUS = POINT_ACTIVE_RADIUS;
1432
+ exports.POINT_RADIUS = POINT_RADIUS;
1433
+ exports.SEGMENT_NUMBER = SEGMENT_NUMBER;
1434
+ exports["default"] = LineToolOperation;