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