@labelbee/lb-annotation 1.14.0-alpha.9 → 1.15.0-alpha.1

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 (41) hide show
  1. package/dist/core/pointCloud/annotation.js +1 -1
  2. package/dist/core/pointCloud/index.js +2 -2
  3. package/dist/core/scheduler.js +1 -1
  4. package/dist/core/toolOperation/LineToolOperation.js +1 -1
  5. package/dist/core/toolOperation/Selection.js +1 -0
  6. package/dist/core/toolOperation/cuboidOperation.js +1 -1
  7. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
  8. package/dist/core/toolOperation/pointOperation.js +1 -1
  9. package/dist/core/toolOperation/polygonOperation.js +1 -1
  10. package/dist/core/toolOperation/rectOperation.js +1 -1
  11. package/dist/core/toolOperation/textAttributeClass.js +9 -9
  12. package/dist/types/core/index.d.ts +2 -2
  13. package/dist/types/core/pointCloud/annotation.d.ts +2 -1
  14. package/dist/types/core/pointCloud/index.d.ts +8 -3
  15. package/dist/types/core/scheduler.d.ts +16 -3
  16. package/dist/types/core/toolOperation/LineToolOperation.d.ts +26 -36
  17. package/dist/types/core/toolOperation/Selection.d.ts +70 -0
  18. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +2 -10
  19. package/dist/types/core/toolOperation/pointOperation.d.ts +10 -4
  20. package/dist/types/core/toolOperation/polygonOperation.d.ts +23 -14
  21. package/dist/types/core/toolOperation/rectOperation.d.ts +41 -10
  22. package/dist/types/core/toolOperation/textAttributeClass.d.ts +6 -0
  23. package/dist/types/utils/tool/CommonToolUtils.d.ts +2 -2
  24. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +2 -2
  25. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -1
  26. package/dist/utils/tool/CommonToolUtils.js +1 -1
  27. package/dist/utils/tool/PolygonUtils.js +1 -1
  28. package/es/core/pointCloud/annotation.js +1 -1
  29. package/es/core/pointCloud/index.js +2 -2
  30. package/es/core/scheduler.js +1 -1
  31. package/es/core/toolOperation/LineToolOperation.js +1 -1
  32. package/es/core/toolOperation/Selection.js +1 -0
  33. package/es/core/toolOperation/cuboidOperation.js +1 -1
  34. package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
  35. package/es/core/toolOperation/pointOperation.js +1 -1
  36. package/es/core/toolOperation/polygonOperation.js +1 -1
  37. package/es/core/toolOperation/rectOperation.js +1 -1
  38. package/es/core/toolOperation/textAttributeClass.js +9 -9
  39. package/es/utils/tool/CommonToolUtils.js +1 -1
  40. package/es/utils/tool/PolygonUtils.js +1 -1
  41. package/package.json +2 -2
@@ -1 +1 @@
1
- import{getConfig as L,styleDefaultConfig as v}from"../constant/defaultConfig.js";import{getCurrentOperation as w}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as _}from"./toolOperation/basicToolOperation.js";var D=Object.defineProperty,I=Object.defineProperties,S=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,f=(e,t,o)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,b=(e,t)=>{for(var o in t||(t={}))T.call(t,o)&&f(e,o,t[o]);if(g)for(var o of g(t))N.call(t,o)&&f(e,o,t[o]);return e},x=(e,t)=>I(e,S(t));const C=e=>{const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,e.width,e.height),t.toDataURL()):""},d=(e,t,o)=>{const i=e[t];return e[t]=e[o],e[o]=i,e},y=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let u=y;u.getTopToolName=e=>y.isHybridTool(e)?e[e.length-1]:e;class z{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,i;this.init(),this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(u.getTopToolName(t.toolName))),this.style=(i=t.style)!=null?i:v}setImgNode(t,o){this.toolOperationList.forEach(i=>{i.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const i=x(b({},o.config),{attributeList:t});o.setConfig(JSON.stringify(i))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,i,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(i),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,i=window.document.createElement("div");i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.width=`${t}px`,i.style.height=`${o}px`;const s=this.toolOperationList.length+1;return i.style.zIndex=`${s}`,i}getEmptyImage(t,o){const i=C({width:t,height:o}),s=new Image;return s.src=i,s}createOperation(t,o,i){var s;const{width:a,height:l}=this.defaultSize,r=this.createDom(),p=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||p,hiddenImg:!!t};i&&Object.assign(h,i);let n;if(!t)n=new _(h),r.style.zIndex="0",n.init();else{const c=w(t);if(!c)return;n=new c(h)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.on("dragMove",({currentPos:c,zoom:O,imgInfo:m})=>{this.syncPosition(c,O,m,n)}),n.on("renderZoom",(c,O,m)=>{c&&O&&this.syncPosition(O,c,m,n)}),t?(this.container.appendChild(r),this.toolOperationList.push(n),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),n):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(n),this.toolOperationDom.unshift(r),n)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,i=t-2,s=this.toolOperationDom[o],a=this.toolOperationDom[i];if(!(!a||!s))return s.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,i),this.toolOperationDom=d(this.toolOperationDom,o,i),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,i,s,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,p=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!p||!h)return;const n=h.style.zIndex;return h.style.zIndex=`${p.style.zIndex}`,p.style.zIndex=`${n}`,(i=(o=this.toolOperationList[r]).clearActiveStatus)==null||i.call(o),(a=(s=this.toolOperationList[r]).clearCursorLine)==null||a.call(s),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,l),this.toolOperationDom=d(this.toolOperationDom,r,l),this.toolOperationNameList=d(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const i=this.toolOperationNameList.indexOf(t);i>=0&&this.toolOperationList[i].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}export{u as HybridToolUtils,z as ToolScheduler};
1
+ import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as D}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";var I=Object.defineProperty,M=Object.defineProperties,_=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?I(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,E=(i,t)=>{for(var o in t||(t={}))x.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))b.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>M(i,_(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(E({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let s;if(!t)s=new w(h),r.style.zIndex="0",s.init();else{const p=D(t);if(!p)return;s=new p(h)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,s)}),s.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const s=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,l),this.toolOperationDom=d(this.toolOperationDom,r,l),this.toolOperationNameList=d(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
@@ -1 +1 @@
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 j}from"./basicToolOperation.js";import u from"../../utils/tool/LineToolUtils.js";import{createSmoothCurvePointsFromPointList as R,isInPolygon as V,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";import J from"../../locales/index.js";import{EMessage as q}from"../../locales/constants.js";var G=Object.defineProperty,Y=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,E=(d,t,i)=>t in d?G(d,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[t]=i,_=(d,t)=>{for(var i in t||(t={}))Q.call(t,i)&&E(d,i,t[i]);if(O)for(var i of O(t))X.call(t,i)&&E(d,i,t[i]);return d},T=(d,t)=>Y(d,Z(t)),k;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(k||(k={}));const p=16,C={x:0,y:20},m=3,x=5,H=2;class tt extends j{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,m,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=>u.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&&u.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:v,y:A},I)=>{const D=I>0?"lineTo":"moveTo";a&&u.setSpecialEdgeStyle(i),i[D](v,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?u.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 v=a.id,A=v&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(v)?x:m;this.arc(a,A,s),[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(v)||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&&u.setReferenceCtx(n),i.forEach((r,o)=>{if(n.beginPath(),o>0){const h=i[o-1];n.save(),(h==null?void 0:h.specialEdge)&&u.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),v=o>=0&&h&&L.isInRange(l,s),A=r>=0&&a&&L.isInRange(c,n),I=v?i:0,D=A?e:0;this.lineDragging=!0,this.moveActiveArea(I,D)},this.onRightClick=i=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;if(u.lineLengthSum(this.activeLine||[])<this.minLength)return this.emit("messageInfo",`${J.getMessagesByLocale(q.MinLengthLimitErrorNotice,this.lang)}${this.minLength}`),!0;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 minLength(){var t;return((t=this.config)==null?void 0:t.minLength)||1}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 V(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 u.isInLine(i,r,o,e)})}arc(t,i=m,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(v=>v.value===n))==null?void 0:h.key)!=null?a:n:"";l=[l,`${!r&&c?"\u65E0\u6548":""}${c}`].filter(v=>v).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+u.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 u.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 u.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=u.calcTwoPointDistance(o,i),v=u.calcTwoPointDistance(h,i);if(c<=e*2){s=o,e=0;break}if(v<=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 u.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?u.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);u.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,v=(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(`${v}`,{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,m as POINT_RADIUS,p as SEGMENT_NUMBER,tt as default};
1
+ import g from"lodash";import{ELineTypes as D,ELineColor as U,EToolName as _,ETextType as M}from"../../constant/tool.js";import B from"../../utils/ActionsHistory.js";import S from"../../utils/uuid.js";import L from"../../constant/keyCode.js";import v from"../../utils/MathUtils.js";import{BasicToolOperation as j}from"./basicToolOperation.js";import u from"../../utils/tool/LineToolUtils.js";import{createSmoothCurvePointsFromPointList as R,isInPolygon as V,createSmoothCurvePoints as W}from"../../utils/tool/polygonTool.js";import K from"../../utils/tool/CommonToolUtils.js";import N from"../../utils/tool/CanvasUtils.js";import F from"../../utils/tool/DrawUtils.js";import z from"../../utils/tool/StyleUtils.js";import y from"../../utils/tool/AttributeUtils.js";import $ from"./textAttributeClass.js";import J from"./Selection.js";import Y from"../../locales/index.js";import{EMessage as X}from"../../locales/constants.js";var q=Object.defineProperty,G=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,E=(d,e,t)=>e in d?q(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t,T=(d,e)=>{for(var t in e||(e={}))Q.call(e,t)&&E(d,t,e[t]);if(O)for(var t of O(e))tt.call(e,t)&&E(d,t,e[t]);return d},w=(d,e)=>G(d,Z(e)),k;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(k||(k={}));const p=16,C={x:0,y:20},x=3,m=5,H=2;class et extends j{constructor(e){super(e);this.drawActivatedLine=(t,i,s)=>{const n=this.isCreate?g.cloneDeep([{pointList:this.activeLine,order:this.nextOrder(),attribute:this.defaultAttribute,valid:this.isLineValid}]):g.cloneDeep(this.selectedLines),o=this.isActiveLineValid();n.forEach(r=>{if((r==null?void 0:r.pointList)&&(r.pointList=r.pointList.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l)))),!r.pointList)return;const h=this.getLineColorByAttribute({attribute:r.attribute,valid:r.valid});return this.selectedLines.length>0&&(this.drawLineLength(r.pointList,h),this.renderActiveArea(v.calcViewportBoundaries(r.pointList,this.isCurve,p))),this.drawLine(r.pointList,t,h,!0,!0),this.drawLineNumber(r.pointList[0],r.order,h,"",this.defaultAttribute,o),t&&this.isCreate&&this.arc(t,x,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,m,h),r})},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.selectedID){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>u.calcDistance(this.coordUtils.getRenderCoord(o),t)<=m);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,t)),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.drawCurveLine=(t,i,s,n=!0,o=!1,r)=>{const h=R(i,p);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=s.color,n&&(t.lineWidth=s.lineWidth),o&&u.setReferenceCtx(t),i.forEach(({specialEdge:l},a)=>{const c=h.splice(0,p+1);t.save(),t.beginPath(),r===a&&(t.lineWidth=4),c.forEach(({x:f,y:b},I)=>{const P=I>0?"lineTo":"moveTo";l&&u.setSpecialEdgeStyle(t),t[P](f,b)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,i,s,n=!1,o=!1)=>{const r=i?t.concat(i):t,h={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?u.drawCurveLine(this.ctx,r,h,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(r,h,o),n&&t.forEach(l=>{var a,c;const f=l.id,b=f&&[this.hoverPointID,(a=this.selectedPoint)==null?void 0:a.id].includes(f)?m:x;this.arc(l,b,s),[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(f)||this.arc(l,H,"white")})},this.drawStraightLine=(t,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&&u.setReferenceCtx(n),t.forEach((o,r)=>{if(n.beginPath(),r>0){const h=t[r-1];n.save(),(h==null?void 0:h.specialEdge)&&u.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===r&&(n.lineWidth=4),n.moveTo(h.x,h.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const t=g.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(i=>{if(!this.selection.isIdSelected(i.id)&&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,o=s,r=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,r,!1),this.drawLineNumber(i.pointList[0],o,r,n,i.attribute,i.valid),i.id!==this.textEditingID&&(this.drawLineTextAttribute(i.pointList[1],r,i==null?void 0:i.textAttribute),this.drawLineLength(i.pointList,r))}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!1),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+t,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(t,i))},this.getSelectedLinesArea=()=>v.calcViewportBoundaries(this.selectedLines.reduce((t,i)=>(i==null?void 0:i.pointList)?t.concat(...i==null?void 0:i.pointList):t,[])),this.moveLineInRectRange=(t,i,s,n)=>{if(this.selectedLines.length===0)return;const{top:o,left:r,right:h,bottom:l}=this.getSelectedLinesArea(),a=[r,h].map(A=>g.isNumber(A)?A+t:0),c=[o,l].map(A=>g.isNumber(A)?A+i:0),f=r>=0&&h&&v.isInRange(a,s),b=o>=0&&l&&v.isInRange(c,n),I=f?t:0,P=b?i:0;this.lineDragging=!0,this.moveActiveArea(I,P)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;if(u.lineLengthSum(this.activeLine||[])<this.minLength)return this.emit("messageInfo",`${Y.getMessagesByLocale(X.MinLengthLimitErrorNotice,this.lang)}${this.minLength}`),!0;this.stopLineCreating(!0);return}const i=this.findHoverLine(this.getCoordinate(t));this.setSelectedLineID(i==null?void 0:i.id,t.ctrlKey),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedIDs.length>0){const t=this.lineList.find(s=>s.id===this.selectedIDs[0]),i=t==null?void 0:t.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=t=>{const i=this.getCoordinate(t),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(t,i);if(this.isCreate||this.isNone){this.setCreateStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreateStatusAndAddPoint(n);return}if(t.shiftKey){this.updateLineSegmentSpecial(i);return}this.coordsInsideActiveArea&&t.ctrlKey&&this.setInvalidLine(this.selectedID),this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,!this.selection.triggerKeyboardEvent(t,this.setLineList)){if(t.keyCode===L.Esc){this.stopLineCreating(!1);return}if(this.selectedLine){if(t.key==="Delete"){this.deleteLine();return}if(t.key==="f"){this.setInvalidLine(this.selectedID);return}if(t.key===" "){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)}},this.onRightDblClick=t=>{super.onRightDblClick(t);const i=this.getCoordinate(t);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const i=t.length!==this.lineListLen;this.lineList=t,i&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(e.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new B,this.selection=new J(this),this.dependToolConfig={lineType:D.Line}}get selectedLines(){return this.lineList.filter(e=>this.selection.isIdSelected(e.id))}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLine(){return this.lineList.find(e=>e.id===this.selectedID)}get isCreate(){return this.status===0}get isActive(){return this.selectedLines.length>0}get isNone(){return!this.isCreate&&this.selectedIDs.length===0}get isCurve(){return this.config.lineType===D.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===_.Polygon}get isDependRect(){return this.dependToolName===_.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(e=>this.attributeLockList.includes((e==null?void 0:e.attribute)||"")):this.lineList}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get enableOutOfTarget(){return this.config.enableOutOfTarget||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var e;return(e=this.config.showOrder)!=null?e:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get minLength(){var e;return((e=this.config)==null?void 0:e.minLength)||0}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 e=N.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var i;return(i=t==null?void 0:t.pointList)==null?void 0:i.some(s=>N.inViewPort(s,e))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var e,t;return(t=(e=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(e,t=!1){if(e!==this.status){if(t){let i="";this.textCheckType===M.Order&&this.isTextConfigurable&&(i=y.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=e,this.lineStatusChanged()}}isInBasicPolygon(e){var t,i;return V(e,((t=this.basicResult)==null?void 0:t.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:e}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===D.Curve?W(e.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):e}getNextCoordByRenderCoord(e){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(e))}getNextCoordByAbsCoord(e){var t;const i=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(e,i):e}pointInLine(e,t,i){return e.filter(s=>s).length<2?!1:e.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(e[n-1]),r=this.coordUtils.getRenderCoord(s);return u.isInLine(t,o,r,i)})}arc(e,t=x,i){var s,n,o,r,h,l;if(this.ctx){const{x:a,y:c}=e;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(o=this.ctx)==null||o.arc(a,c,t,0,360),(r=this.ctx)==null||r.closePath(),(h=this.ctx)==null||h.fill(),(l=this.ctx)==null||l.restore()}}renderActiveArea({top:e,left:t,right:i,bottom:s}){this.ctx&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(t,e,i-t,s-e),this.ctx.stroke(),this.ctx.restore())}addLinePoint(e){var t,i,s,n;this.arc(e),(t=this.activeLine)==null||t.push(w(T({},e),{id:S()})),((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()}setCreateStatusAndAddPoint(e,t=!1){this.updateStatus(0,t),this.addLinePoint(e)}isActiveLineValid(){var e;return this.selectedID?(e=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:e.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(e,t=!1){return z.getStrokeAndFill(this.getColor(e.attribute),e.valid,{isSelected:t}).stroke}drawLineNumber(e,t=1,i,s="",n,o=!0){var r,h,l;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let a=this.showOrder?t.toString():`${s}`;if(this.attributeConfigurable){const c=n?(l=(h=(r=this.attributeList)==null?void 0:r.find(f=>f.value===n))==null?void 0:h.key)!=null?l:n:"";a=[a,`${!o&&c?"\u65E0\u6548":""}${c}`].filter(f=>f).join("_")}this.drawText(e,a,i)}}drawLineTextAttribute(e,t,i){if(e&&i)return this.drawText(e,i,t,200)}drawLineLength(e,t){var i;if(((i=this.config)==null?void 0:i.showLineLength)&&e){const s=e.reduce((o,r,h)=>h<=0||!e[h-1].actual||!r.actual?o:o+u.calcDistance(e[h-1].actual,r.actual),0),n=e[e.length-1];this.drawText(n,`l = ${s.toFixed(2)}`,t)}}drawText(e,t,i,s){var n,o;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?F.wrapText(this.canvas,t,e.x-C.x,e.y-C.y,s):this.ctx.fillText(t,e.x-C.x,e.y-C.y),(o=this.ctx)==null||o.restore())}moveActiveArea(e,t){this.selectedLines.length>0&&(this.selectedLines.forEach(i=>{var s;(s=i.pointList)==null||s.forEach(n=>Object.assign(n,{x:n.x+e,y:n.y+t}))}),this.render()),this.emit("dataUpdated",this.lineList,this.selectedIDs)}findHoveredPoint(e){if(!!this.activeLine)return this.activeLine.find(t=>{const i=this.coordUtils.getRenderCoord(t);return u.calcDistance(i,e)<=m})}findHoverLine(e){return g.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,r)=>{if(r===0)return!1;const h=this.coordUtils.getRenderCoord(o),l=this.coordUtils.getRenderCoord(s[r-1]);return u.isInLine(e,h,l,n)})})}getAdsorptionPoint(e){let t,i,s;return g.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const r=this.findNearestPoint(n,e);if(r){if(r.minDistance===0){t=r.point;return}(i===void 0||r.minDistance<i)&&(t=r.point,i=r.minDistance)}}),s||t}findNearestPoint(e,t,i=7){let s;const n=i;for(let o=1;o<=e.length-1;o++){const r=this.coordUtils.getRenderCoord(e[o]),h=this.coordUtils.getRenderCoord(e[o-1]),{length:l,footPoint:a}=v.getFootOfPerpendicular(t,r,h),c=u.calcTwoPointDistance(r,t),f=u.calcTwoPointDistance(h,t);if(c<=i*2){s=r,i=0;break}if(f<=i*2){s=h,i=0;break}l<i&&(s=a,i=l)}return s?{point:s,minDistance:n}:void 0}getPointList(e){return this.isCurve?R(e,p):e}moveSelectedLine(e){const t=(e.x-this.prevAxis.x)/this.zoom,i=(e.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,i);return}if(this.isDependPolygon){this.moveLineInPolygon(t,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:r,width:h,height:l}=this.basicResult;s=[o,o+h],n=[r,r+l]}this.moveLineInRectRange(t,i,s,n)}moveSelectPoint(e){if(!this.selectedPoint)return;const t=e.x-this.prevAxis.x,i=e.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(e,t){var i;const s=!!e.shiftKey,n=e.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return u.getVHPoint(o,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(t):t}getNextPoint(e,t){const i=this.getCoordByConfig(e,t)||t;return this.enableOutOfTarget?this.coordUtils.getAbsCoord(i):this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(e){const t=this.getCoordinate(e),i=e.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(e,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!e.altKey)){const s=this.getAdsorptionPoint(t);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(e){if(super.onMouseMove(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);this.mouseMoveHandler(e),this.prevAxis=t}setActiveLine(e){this.activeLine=e?g.cloneDeep(e):void 0}historyChanged(e){const t=`${e}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const i=this.actionsHistory&&this.actionsHistory[e]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[t]){const i=this.history[e](),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(e){if(this.isDependPolygon)return this.isInBasicPolygon(e);if(this.isDependRect){const{x:t,y:i,width:s,height:n}=this.basicResult,o=[t,t+s],r=[i,i+n];return v.isInRange(e.x,o)&&v.isInRange(e.y,r)}return v.isInRange(e.x,[0,this.imageSize.width])&&v.isInRange(e.y,[0,this.imageSize.height])}getPointInsertIndex(e,t){if(e&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,r=this.isCurve?i.slice((n-1)*(p+1),n*(p+1)):[o,s];return this.pointInLine(r,e,t||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 e;return this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(e){const t=this.getPointInsertIndex(e,2)-1;if(t>-1){const i=this.activeLine[t];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var e;const t=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&i&&(this.activeLine.splice(t,0,w(T({},this.coordUtils.getAbsCoord(this.cursor)),{id:S()})),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList),this.render(),this.cursor=void 0)}isCoordOnSelectedArea(e){return this.selectedLines.some(t=>u.inArea(v.calcViewportBoundaries(t.pointList),this.coordUtils.getAbsCoord(e)))}onMouseDown(e){if(super.onMouseDown(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);if(this.isMousedown=!0,this.prevAxis=t,e.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.selectedLines.length>0?this.isCoordOnSelectedArea(t):!1,this.lineDragging=!1}lineHasChanged(){const e=this.lineList.find(t=>t.id===this.selectedID);return e?JSON.stringify(e.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const e=this.lineList.find(t=>t.id===this.selectedID);e&&(e.pointList=g.cloneDeep(this.activeLine),this.updatedLine=e,this.emit("dataUpdated",this.lineList))}onMouseUp(e){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(e)||this.forbidMouseOperation||!this.imgInfo){t();return}e.which===1&&this.onLeftClick(e),e.which===3&&this.onRightClick(e),t()}isTextValid(e){return y.textAttributeValidate(this.textCheckType,this.customFormat,e)}createLineData(){const e=S(),t={pointList:g.cloneDeep(this.activeLine),id:e,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(e=!0){var t,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let r;if(e){if(this.selectedID){const h=this.lineList.find(l=>l.id===this.selectedID);r=this.selectedID,h&&(h.pointList=g.cloneWith(this.activeLine),g.isEqual(h.pointList,(t=this.history)==null?void 0:t.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();r=h.id,this.setLineList([...this.lineList,h]),(s=this.history)==null||s.pushHistory(this.lineList)}}this.setNoneStatus(),o&&(this.activeLine=[],this.setSelectedLineID(r,!1,!1)),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList,this.selectedIDs),this.render()}setNoneStatus(e=!0){e&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(e,t){this.isShift=t!=null?t:e.keyCode===L.Shift}continueToEdit(){var e,t;((e=this.selectedLine)==null?void 0:e.pointList)&&(this.updateStatus(0),this.cursor=void 0,this.setActiveLine(this.selectedLine.pointList),(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render())}setInvalidLineOnCreating(e){if(this.selectedID&&e.keyCode!==L.Ctrl||!this.isCreate)return;const t=!e.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(e){if(super.onKeyDown(e),this.setKeyDownStatus(e),e.keyCode===L.Z&&!e.ctrlKey&&this.toggleIsHide(),e.keyCode===L.Shift&&this.render(),e.keyCode===L.Tab){e.preventDefault(),this.selectToNextLine(e);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(e),this.config.attributeConfigurable){const t=y.getAttributeByKeycode(e.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(e){const t=K.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,r;return w(T({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(r=(o=i.pointList[0])==null?void 0:o.y)!=null?r:0})}),e,this.selectedID);t&&this.selection.setSelectedIDs(t.id)}keyboardEventWhileLineCreating(e){!this.isCreate||(e.keyCode===L.Ctrl&&this.setInvalidLineOnCreating(e),[L.Shift,L.Alt].includes(e.keyCode)&&this.renderNextPoint(e,this.prevAxis))}renderNextPoint(e,t){const i=this.coordUtils.getRenderCoord(this.getNextPoint(e,t));this.render(i)}deleteSelectedLine(e){var t;if(this.selectedLine){const i=v.calcViewportBoundaries((t=this.selectedLine)==null?void 0:t.pointList,this.isCurve,p,this.zoom);u.inArea(i,this.coordUtils.getAbsCoord(e))&&this.deleteLine()}}deleteSelectedLinePoint(e){var t;this.pointsWithinRange(this.activeLine.length-1)&&e&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==e)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var e;this.lineList=this.lineList.filter(t=>!this.selection.isIdSelected(t.id)),(e=this.history)==null||e.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(e,t,i=!0){var s;const n=this.lineList.find(o=>o.id===e);n&&(n.valid=t!==void 0?t:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),this.emit("dataUpdated",this.lineList),i&&this.render())}empty(){var e,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(e=this.actionsHistory)==null||e.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(e){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedIDs.length>0&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(e){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",e),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",e))}setLineAttribute(e,t){this.selectedIDs.length>0&&(this.lineList.forEach(i=>{this.selection.isIdSelected(i.id)&&(i[e]=t)}),this.render())}updateAttribute(e){this.emit("updateAttribute",e)}updateLineAttributes(e){var t;if(this.attributeConfigurable&&e){const i=(e==null?void 0:e.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&e){const i=(e==null?void 0:e.textAttribute)||"";this.updateTextAttribute(i)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(e){if(this.selectedID){const t=this.lineList.find(i=>i.id===this.selectedID);t&&(t.textAttribute=e)}this.emit("updateText",e)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(e){this.textEditingID=e,this.render()}updateAttrWhileIDChanged(e){if(e){const t=this.lineList.find(i=>i.id===e);t&&this.setDefaultAttribute(t.attribute)}}setSelectedLineID(e,t=!1,i=!0){this.selection.setSelectedIDs(e,t),i&&e&&this.updateAttrWhileIDChanged(this.selectedID),this.selectedLine&&this.setActiveLine(this.selectedLine.pointList),this.selectedIDs.length===0&&this.setActiveLine([]),this.emit("selectedChange")}attributeLockListChange(e){this.attributeLockList=e,this.render()}setResult(e){this.setNoneStatus(),this.setLineList(e),this.render()}setConfig(e){super.setConfig(e)}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(e=""){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.changeStyle(this.defaultAttribute),this.setLineAttribute("attribute",e),this.selectedIDs.length>0&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var e,t;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,r=(t=(e=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:"";return{color:o,textAttribute:r}}renderTextAttribute(){var e,t,i,s;if(!this.ctx||!this.selectedLine||this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<2)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:r,y:h}=this.selectedLine.pointList[1],l=this.coordUtils.getRenderCoord({x:r,y:h}),a=this.getColor(o),c=n?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,f=(i=(t=this.lineList.find(b=>b.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new $({container:this.container,icon:this.getTextIconSvg(o),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${f}`,{left:l.x,top:l.y,color:c}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(e=""){return y.getTextIconSvg(e,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(e){if(this._textAttributeInstance&&e&&this.selectedID){let t=e;!y.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",y.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}export{H as INNER_POINT_RADIUS,C as LINE_ORDER_OFFSET,m as POINT_ACTIVE_RADIUS,x as POINT_RADIUS,p as SEGMENT_NUMBER,et as default};
@@ -0,0 +1 @@
1
+ import i from"lodash";import a from"../../utils/tool/CommonToolUtils.js";class r{constructor(t){t||console.error("MultipleSelect is require a tool instance"),this._selectedIDs=[],this.toolInstance=t}get selectedIDs(){return this._selectedIDs}get selectedID(){return this._selectedIDs.length===1?this._selectedIDs[0]:void 0}get visibleDataList(){const{dataList:t,attributeLockList:e,basicResult:s}=this.toolInstance,[l]=a.getRenderResultList(t,a.getSourceID(s),e);return l}get dataList(){return this.toolInstance.dataList}set selectedIDs(t){var e;(e=this.toolInstance._textAttributeInstance)==null||e.selectedIDsChanged(this.selectedIDs,t),this._selectedIDs=t,this.toolInstance.render()}updateSelectedIDs(t){if(!t){this._selectedIDs=[];return}this.selectedIDs.includes(t)?this.selectedIDs=this.selectedIDs.filter(e=>e!==t):this.selectedIDs=[...this.selectedIDs,t]}setSelectedIDs(t,e=!1){if(e){this.updateSelectedIDs(t);return}this.selectedIDs=t?[t]:[]}hardSetSelectedIDs(t){this.selectedIDs=t}selectAll(){this.selectedIDs=this.visibleDataList.map(t=>t.id),this.toolInstance.render()}toStashDataList(){this.selectedIDs.length>0&&(this.stashDataList=i.cloneDeep(this.dataList.filter(t=>this.selectedIDs.includes(t.id))))}toUnStashDataList(){if(this.stashDataList){const t=this.stashDataList;return this.stashDataList=void 0,t}}mergeStashData(t){const e=this.toUnStashDataList();if(!e)return;const s=i(this.dataList).keyBy("id").merge(i.keyBy(e,"id")).values().value();t(s),this.toolInstance.render()}isIdSelected(t){return this.selectedIDs.includes(t)}triggerKeyboardEvent(t,e){if(t.ctrlKey){if(t.key==="v")return this.mergeStashData(e),!0;if(t.key==="a")return this.selectAll(),!0;if(t.key==="c")return this.toStashDataList(),!0}return!1}}export{r as default};
@@ -1 +1 @@
1
- import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AxisUtils.js";import y from"../../utils/uuid.js";import{getCuboidHoverRange as S,getPlainPointsByDiagonalPoints as L,getPointsByBottomRightPoint as x,getCuboidDragMove as A,isCuboidWithInLimits as P,getHighlightPoints as _,getHighlightLines as T,getToggleDirectionButtonOffset as k,getCuboidTextAttributeOffset as M}from"../../utils/tool/CuboidUtils.js";import O from"../../utils/tool/PolygonUtils.js";import{EDragStatus as p,EDragTarget as v,ECuboidDirection as H}from"../../constant/annotation.js";import g from"../../utils/tool/AttributeUtils.js";import{DEFAULT_TEXT_MAX_WIDTH as B}from"../../constant/tool.js";import f from"../../constant/keyCode.js";import{BasicToolOperation as R}from"./basicToolOperation.js";import b from"../../utils/tool/DrawUtils.js";import U from"./cuboidToggleButtonClass.js";import F from"./textAttributeClass.js";import j from"../../locales/index.js";import{EMessage as z}from"../../locales/constants.js";var E=Object.defineProperty,W=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,D=(h,t,i)=>t in h?E(h,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):h[t]=i,u=(h,t)=>{for(var i in t||(t={}))N.call(t,i)&&D(h,i,t[i]);if(m)for(var i of m(t))K.call(t,i)&&D(h,i,t[i]);return h},a=(h,t)=>W(h,Z(t)),w;(function(h){h[h.Ready=1]="Ready",h[h.FirstPoint=2]="FirstPoint",h[h.Cuboid=3]="Cuboid"})(w||(w={}));const V=164;class X extends R{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:s}=this;if((s==null?void 0:s.length)>0){const o=s.map(n=>({id:n.id,pointList:l.changePointListByZoom(S(n),this.zoom)})),r=O.getHoverPolygonID(e,o);if(r)return{hoverID:r,hoverCuboid:s.find(n=>n.id===r)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=c.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}get selectedText(){var t,i;return(i=(t=this.selectedCuboid)==null?void 0:t.textAttribute)!=null?i:""}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=c.getRenderResultList(this.cuboidList,c.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=i,this.isHidden&&(t=[]),e&&t.push(e),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&l.isCloseCuboid(i,l.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getStylesToRender(t,i){var e,s;const o=this.getColor(t),r=i?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,n=i?o==null?void 0:o.valid.fill:o==null?void 0:o.invalid.fill,d=(s=(e=this.style)==null?void 0:e.width)!=null?s:2;return{strokeColor:r,toolColor:o,fillColor:n,lineWidth:d}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getStylesToRender(t.attribute,t.valid);return{width:V,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;g.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",g.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearActiveStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.deleteSelectedID(),this.render()}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;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")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?a(u({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case f.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!1}),this.render());break;case f.Delete:this.selectedID&&this.deleteCuboid(this.selectedID);break;case f.Z:this.setIsHidden(!this.isHidden),this.render();break;case f.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=g.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case f.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=p.Start;const e=this.getCoordinateUnderZoom(t),s={initCuboid:i,dragStartCoord:e},o=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom)),r=o==null?void 0:o[0];switch(r==null?void 0:r.type){case"point":this.dragInfo=a(u({},s),{dragTarget:v.Point,positions:r.positions});break;case"line":this.dragInfo=a(u({},s),{dragTarget:v.Line,positions:r.positions});break;default:this.dragInfo=a(u({},s),{dragTarget:v.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=c.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=a(u({},this.drawingCuboid),{frontPoints:L(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=a(u({},this.drawingCuboid),{backPoints:x({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:s,positions:o}=this.dragInfo,r=this.getCoordinateUnderZoom(t),n={x:(r.x-s.x)/this.zoom,y:(r.y-s.y)/this.zoom};this.dragStatus=p.Move;const d=A({offset:n,cuboid:e,dragTarget:i,positions:o});(d==null?void 0:d.backPoints)&&(d==null?void 0:d.backPoints.br.y)>(d==null?void 0:d.frontPoints.br.y)||(d&&this.updateSelectedCuboid(d),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),s=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=s,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);if(this.drawingCuboid={attribute:this.defaultAttribute,direction:H.Front,valid:!t.ctrlKey,id:y(8,62),sourceID:i,textAttribute:"",order:c.getMaxOrder(this.cuboidList.filter(s=>c.isSameSourceID(s.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=u({},e),this.drawingStatus=2,this.config.textConfigurable){let s="";s=g.getTextAttribute(this.cuboidList.filter(o=>c.isSameSourceID(o.sourceID,i)),this.config.textCheckType),this.drawingCuboid=a(u({},this.drawingCuboid),{textAttribute:s})}}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&P({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",j.getMessagesByLocale(z.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}deleteSelectedID(){this.setSelectedID("")}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}clearActiveStatus(){this.clearDrawingStatus(),this.deleteSelectedID()}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderHighlightCuboidCom(t){const i=l.changeCuboidByZoom(t,this.zoom,this.currentPos),e=i.id===this.hoverID,s=i.id===this.selectedID,{strokeColor:o,lineWidth:r}=this.getStylesToRender(i.attribute,i.valid),n={color:o,thickness:r};if(e||s){const d=_(i);d.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,5,u({},n))}),s&&(T(i).forEach(C=>{b.drawLine(this.canvas,C.p1,C.p2,{color:o,thickness:r+2})}),d.forEach(C=>{b.drawCircleWithFill(this.canvas,C.point,3,{color:"white"})}))}}renderSingleCuboid(t){var i,e;const s=l.changeCuboidByZoom(t,this.zoom,this.currentPos),{strokeColor:o,fillColor:r}=this.getStylesToRender(s.attribute,s.valid),n=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:d=!1}=this.style;b.drawCuboidWithText(this.canvas,s,{strokeColor:o,fillColor:r,thickness:n},{config:this.config,hiddenText:d,selectedID:this.selectedID}),this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(this._textAttributeInstance&&(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)?this._textAttributeInstance.clearTextAttribute():this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))),e){this.setCuboidList(this.cuboidList.map(s=>s.id===this.selectedID?a(u({},s),{attribute:this.defaultAttribute}):s)),this.history.pushHistory(this.cuboidList),this.render();return}this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{attribute:this.defaultAttribute}),this.render())}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||!t)return;const{attribute:i,valid:e}=t,{strokeColor:s}=this.getStylesToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new U({container:this.container,cuboidButtonMove:r=>this.updateMouseOperation(r),toggleDirection:r=>this.toggleDirection(r)}));const o=k({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:o.left,top:o.top,color:s})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getStylesToRender(i.attribute,i.valid),{attribute:s,textAttribute:o,frontPoints:r}=i,n=M({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),d=(r.br.x-r.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new F({width:B,container:this.container,icon:this.getTextIconSvg(s),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${o}`,{left:n.left,top:n.top,color:e,width:d})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.isHidden||this.currentShowList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderHighlightCuboidCom(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?a(u({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,s;const{strokeColor:o}=this.getStylesToRender(i.originCuboid.attribute,i.originCuboid.valid),r=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(n=>{b.drawCircleWithFill(this.canvas,l.changePointByZoom(n,this.zoom,this.currentPos),r,{color:o})});break;case"line":{const n=(s=i.points)==null?void 0:s.map(d=>l.changePointByZoom(d,this.zoom,this.currentPos));n&&b.drawLineWithPointList(this.canvas,n,{color:o,thickness:r});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}export{X as default};
1
+ import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AxisUtils.js";import y from"../../utils/uuid.js";import{getCuboidHoverRange as S,getPlainPointsByDiagonalPoints as L,getPointsByBottomRightPoint as x,getCuboidDragMove as A,isCuboidWithInLimits as P,getHighlightPoints as _,getHighlightLines as T,getToggleDirectionButtonOffset as k,getCuboidTextAttributeOffset as M}from"../../utils/tool/CuboidUtils.js";import O from"../../utils/tool/PolygonUtils.js";import{EDragStatus as p,EDragTarget as v,ECuboidDirection as H}from"../../constant/annotation.js";import g from"../../utils/tool/AttributeUtils.js";import{DEFAULT_TEXT_MAX_WIDTH as B}from"../../constant/tool.js";import f from"../../constant/keyCode.js";import{BasicToolOperation as R}from"./basicToolOperation.js";import b from"../../utils/tool/DrawUtils.js";import U from"./cuboidToggleButtonClass.js";import F from"./textAttributeClass.js";import j from"../../locales/index.js";import{EMessage as z}from"../../locales/constants.js";var E=Object.defineProperty,W=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,D=(h,t,i)=>t in h?E(h,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):h[t]=i,u=(h,t)=>{for(var i in t||(t={}))N.call(t,i)&&D(h,i,t[i]);if(m)for(var i of m(t))K.call(t,i)&&D(h,i,t[i]);return h},a=(h,t)=>W(h,Z(t)),w;(function(h){h[h.Ready=1]="Ready",h[h.FirstPoint=2]="FirstPoint",h[h.Cuboid=3]="Cuboid"})(w||(w={}));const V=164;class X extends R{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:s}=this;if((s==null?void 0:s.length)>0){const o=s.map(n=>({id:n.id,pointList:l.changePointListByZoom(S(n),this.zoom)})),r=O.getHoverPolygonID(e,o);if(r)return{hoverID:r,hoverCuboid:s.find(n=>n.id===r)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=c.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}get selectedText(){var t,i;return(i=(t=this.selectedCuboid)==null?void 0:t.textAttribute)!=null?i:""}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=c.getRenderResultList(this.cuboidList,c.getSourceID(this.basicResult),this.attributeLockList,this.selectedID?[this.selectedID]:void 0);return t=i,this.isHidden&&(t=[]),e.length===1&&t.push(e[0]),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&l.isCloseCuboid(i,l.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getStylesToRender(t,i){var e,s;const o=this.getColor(t),r=i?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,n=i?o==null?void 0:o.valid.fill:o==null?void 0:o.invalid.fill,d=(s=(e=this.style)==null?void 0:e.width)!=null?s:2;return{strokeColor:r,toolColor:o,fillColor:n,lineWidth:d}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getStylesToRender(t.attribute,t.valid);return{width:V,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;g.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",g.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearActiveStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.deleteSelectedID(),this.render()}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;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")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?a(u({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case f.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!1}),this.render());break;case f.Delete:this.selectedID&&this.deleteCuboid(this.selectedID);break;case f.Z:this.setIsHidden(!this.isHidden),this.render();break;case f.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=g.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case f.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=p.Start;const e=this.getCoordinateUnderZoom(t),s={initCuboid:i,dragStartCoord:e},o=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom)),r=o==null?void 0:o[0];switch(r==null?void 0:r.type){case"point":this.dragInfo=a(u({},s),{dragTarget:v.Point,positions:r.positions});break;case"line":this.dragInfo=a(u({},s),{dragTarget:v.Line,positions:r.positions});break;default:this.dragInfo=a(u({},s),{dragTarget:v.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=c.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=a(u({},this.drawingCuboid),{frontPoints:L(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=a(u({},this.drawingCuboid),{backPoints:x({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:s,positions:o}=this.dragInfo,r=this.getCoordinateUnderZoom(t),n={x:(r.x-s.x)/this.zoom,y:(r.y-s.y)/this.zoom};this.dragStatus=p.Move;const d=A({offset:n,cuboid:e,dragTarget:i,positions:o});(d==null?void 0:d.backPoints)&&(d==null?void 0:d.backPoints.br.y)>(d==null?void 0:d.frontPoints.br.y)||(d&&this.updateSelectedCuboid(d),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),s=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=s,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);if(this.drawingCuboid={attribute:this.defaultAttribute,direction:H.Front,valid:!t.ctrlKey,id:y(8,62),sourceID:i,textAttribute:"",order:c.getMaxOrder(this.cuboidList.filter(s=>c.isSameSourceID(s.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=u({},e),this.drawingStatus=2,this.config.textConfigurable){let s="";s=g.getTextAttribute(this.cuboidList.filter(o=>c.isSameSourceID(o.sourceID,i)),this.config.textCheckType),this.drawingCuboid=a(u({},this.drawingCuboid),{textAttribute:s})}}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&P({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",j.getMessagesByLocale(z.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}deleteSelectedID(){this.setSelectedID("")}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}clearActiveStatus(){this.clearDrawingStatus(),this.deleteSelectedID()}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderHighlightCuboidCom(t){const i=l.changeCuboidByZoom(t,this.zoom,this.currentPos),e=i.id===this.hoverID,s=i.id===this.selectedID,{strokeColor:o,lineWidth:r}=this.getStylesToRender(i.attribute,i.valid),n={color:o,thickness:r};if(e||s){const d=_(i);d.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,5,u({},n))}),s&&(T(i).forEach(C=>{b.drawLine(this.canvas,C.p1,C.p2,{color:o,thickness:r+2})}),d.forEach(C=>{b.drawCircleWithFill(this.canvas,C.point,3,{color:"white"})}))}}renderSingleCuboid(t){var i,e;const s=l.changeCuboidByZoom(t,this.zoom,this.currentPos),{strokeColor:o,fillColor:r}=this.getStylesToRender(s.attribute,s.valid),n=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:d=!1}=this.style;b.drawCuboidWithText(this.canvas,s,{strokeColor:o,fillColor:r,thickness:n},{config:this.config,hiddenText:d,selectedID:this.selectedID}),this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(this._textAttributeInstance&&(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)?this._textAttributeInstance.clearTextAttribute():this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))),e){this.setCuboidList(this.cuboidList.map(s=>s.id===this.selectedID?a(u({},s),{attribute:this.defaultAttribute}):s)),this.history.pushHistory(this.cuboidList),this.render();return}this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{attribute:this.defaultAttribute}),this.render())}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||!t)return;const{attribute:i,valid:e}=t,{strokeColor:s}=this.getStylesToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new U({container:this.container,cuboidButtonMove:r=>this.updateMouseOperation(r),toggleDirection:r=>this.toggleDirection(r)}));const o=k({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:o.left,top:o.top,color:s})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getStylesToRender(i.attribute,i.valid),{attribute:s,textAttribute:o,frontPoints:r}=i,n=M({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),d=(r.br.x-r.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new F({width:B,container:this.container,icon:this.getTextIconSvg(s),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${o}`,{left:n.left,top:n.top,color:e,width:d})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.isHidden||this.currentShowList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderHighlightCuboidCom(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?a(u({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,s;const{strokeColor:o}=this.getStylesToRender(i.originCuboid.attribute,i.originCuboid.valid),r=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(n=>{b.drawCircleWithFill(this.canvas,l.changePointByZoom(n,this.zoom,this.currentPos),r,{color:o})});break;case"line":{const n=(s=i.points)==null?void 0:s.map(d=>l.changePointByZoom(d,this.zoom,this.currentPos));n&&b.drawLineWithPointList(this.canvas,n,{color:o,thickness:r});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}export{X as default};
@@ -1 +1 @@
1
- import{INVALID_COLOR as I,toolStyleConverter as b}from"@labelbee/lb-utils";import{ESortDirection as C,EDragTarget as _}from"../../constant/annotation.js";import{EPolygonPattern as P}from"../../constant/tool.js";import y from"../../utils/tool/AxisUtils.js";import p from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import m from"../../utils/tool/PolygonUtils.js";import{polygonConfig as w}from"../../constant/defaultConfig.js";import S from"lodash";import A from"./polygonOperation.js";import{BasicToolOperation as x}from"./basicToolOperation.js";var O=Object.defineProperty,R=Object.defineProperties,j=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,v=(a,t,e)=>t in a?O(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,u=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&v(a,e,t[e]);if(L)for(var e of L(t))U.call(t,e)&&v(a,e,t[e]);return a},g=(a,t)=>R(a,j(t));class B extends A{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=r=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}if(r.ctrlKey){this.emit("addSelectedIDs",this.hoverID);return}this.emit("setSelectedIDs",this.hoverID);const l=(d=this.polygonList.find(c=>c.id===this.hoverID))==null?void 0:d.attribute;l&&l!==this.defaultAttribute&&this.emit("syncAttribute",l)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=r=>{var d;if(r){const l=this.getPointCloudLineColor(r),c=y.changePointListByZoom(r.pointList,this.zoom,this.currentPos);D.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:l,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),r.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(c)}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:r}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(l=>{if(this.selectedIDs.includes(l.id)){const c=r.find(f=>f.id===l.id);c&&d.push({newPolygon:l,originPolygon:c})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,o,s,n,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=p.jsonParser(t.config))!=null?o:{},this.hideAttributes=[],this.checkMode=(s=t.checkMode)!=null?s:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},w),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=p.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygon(t)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selectedIDs=t,this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return m.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const o=S.cloneDeep(this.selectedPolygons),s=[];(i=this.selectedPolygons)==null||i.forEach((n,h)=>{n.pointList=n.pointList.map(r=>{var d,l;const{x:c,y:f}=r;return g(u({},r),{x:c+((d=t.x)!=null?d:0),y:f+((l=t.y)!=null?l:0)})}),s.push({originPolygon:o[h],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",s),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?I:b.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,o,s;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),h=y.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);D.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:n,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(s=this.config)==null?void 0:s.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||D.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===P.Rect?t.isRect===!0:this.pattern===P.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:y.changePointListByZoom(n.pointList,this.zoom)}));return m.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=C.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(o=>{var s,n,h,r;return g(u({},o),{x:(n=(s=o.pointList[0])==null?void 0:s.x)!=null?n:0,y:(r=(h=o.pointList[0])==null?void 0:h.y)!=null?r:0})}),i=p.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const o=this.selectedID;t!==o&&o&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const o=this.dragPolygon(t,i);if(!o)return i;const s=g(u({},i),{pointList:o});return i.isRect===!0&&this.pattern===P.Normal&&Object.assign(s,{isRect:!1}),s}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}onMouseDown(t){if(x.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:_.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}}export{B as default};
1
+ import I from"lodash";import{INVALID_COLOR as b,toolStyleConverter as _}from"@labelbee/lb-utils";import{ESortDirection as C,EDragTarget as w,DEFAULT_TEXT_OFFSET as S}from"../../constant/annotation.js";import{EPolygonPattern as D}from"../../constant/tool.js";import f from"../../utils/tool/AxisUtils.js";import p from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import m from"../../utils/tool/PolygonUtils.js";import{polygonConfig as A}from"../../constant/defaultConfig.js";import x from"./polygonOperation.js";import{BasicToolOperation as T}from"./basicToolOperation.js";var O=Object.defineProperty,B=Object.defineProperties,R=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,L=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,u=(d,t)=>{for(var e in t||(t={}))U.call(t,e)&&L(d,e,t[e]);if(v)for(var e of v(t))j.call(t,e)&&L(d,e,t[e]);return d},g=(d,t)=>B(d,R(t));class k extends x{constructor(t){super(t);this.rightMouseUp=s=>{var a;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,s.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const l=(a=this.polygonList.find(c=>c.id===this.hoverID))==null?void 0:a.attribute;l&&l!==this.defaultAttribute&&this.emit("syncAttribute",l)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=s=>{var a;if(s){const l=this.getPointCloudLineColor(s),c=f.changePointListByZoom(s.pointList,this.zoom,this.currentPos);P.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:l,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(a=this.config)==null?void 0:a.lineType}),s.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(c),this.renderdrawTrackID(s))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:s}=this.dragInfo;if(this.selectedIDs.length>0){const a=[];this.polygonList.forEach(l=>{if(this.selectedIDs.includes(l.id)){const c=s.find(y=>y.id===l.id);c&&a.push({newPolygon:l,originPolygon:c})}}),this.emit("updatePolygonByDrag",a)}}};var e,i,o,r,n,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=p.jsonParser(t.config))!=null?o:{},this.hideAttributes=[],this.checkMode=(r=t.checkMode)!=null?r:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},A),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=p.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return m.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const o=I.cloneDeep(this.selectedPolygons),r=[];(i=this.selectedPolygons)==null||i.forEach((n,h)=>{n.pointList=n.pointList.map(s=>{var a,l;const{x:c,y}=s;return g(u({},s),{x:c+((a=t.x)!=null?a:0),y:y+((l=t.y)!=null?l:0)})}),r.push({originPolygon:o[h],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",r),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?b:_.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,o,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),h=f.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:n,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){const e=f.changePointListByZoom(t.pointList,this.zoom,this.currentPos),i=e[e.length-1],o=t==null?void 0:t.trackID;P.drawText(this.canvas,i,`${o}`,u({textAlign:"center",color:"white"},S))}renderRectPolygonDirection(t){t.length<2||P.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===D.Rect?t.isRect===!0:this.pattern===D.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:f.changePointListByZoom(n.pointList,this.zoom)}));return m.getHoverPolygonID(i,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=C.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(o=>{var r,n,h,s;return g(u({},o),{x:(n=(r=o.pointList[0])==null?void 0:r.x)!=null?n:0,y:(s=(h=o.pointList[0])==null?void 0:h.y)!=null?s:0})}),i=p.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const o=this.selectedID;t!==o&&o&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}onMouseDown(t){if(T.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:w.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}}export{k as default};
@@ -1 +1 @@
1
- import{EToolName as p,ELineTypes as _,edgeAdsorptionScope as k,EOperationMode as E}from"../../constant/tool.js";import j from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import P from"../../utils/tool/MarkerUtils.js";import z from"../../utils/MathUtils.js";import N from"lodash";import{EDragStatus as f,ESortDirection as w,DEFAULT_TEXT_OFFSET as B}from"../../constant/annotation.js";import S from"../../constant/keyCode.js";import C from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import h from"../../utils/tool/CommonToolUtils.js";import x from"../../utils/tool/DrawUtils.js";import Z from"../../utils/tool/StyleUtils.js";import H from"../../utils/uuid.js";import{BasicToolOperation as W}from"./basicToolOperation.js";import F from"./textAttributeClass.js";var K=Object.defineProperty,$=Object.defineProperties,V=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,X=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,R=Math.pow,O=(m,t,e)=>t in m?K(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,D=(m,t)=>{for(var e in t||(t={}))X.call(t,e)&&O(m,e,t[e]);if(T)for(var e of T(t))q.call(t,e)&&O(m,e,t[e]);return m},y=(m,t)=>$(m,V(t));const U=200;class G extends W{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(r=>r.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(v.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=c.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const r=c.changePointByZoom(n,this.zoom);return z.getLineLength(r,o)<.2})};var e,i;this.config=h.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=h.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=h.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}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")}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=f.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>y(D({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=f.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:N.cloneDeep(this.pointList)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===f.Start||this.dragStatus===f.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===f.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=f.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=f.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const r={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(r);return}const o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):c.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===p.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(r=>{r.id===this.selectedID&&(r.x=n.x,r.y=n.y)}),this.render())}onKeyDown(t){if(!h.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case S.Delete:this.deletePoint();break;case S.Tab:{this.onTabKeyDown(t);break}case S.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${C.getMessagesByLocale(A.LowerLimitPoint,this.lang)}`);return}const r=h.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[p.Polygon,p.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const b=((i=this.referenceData)==null?void 0:i.toolName)===p.Polygon,{dropFoot:I,hasClosed:M}=L.getClosestPoint(d,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:_.Line,k/this.zoom,{isClose:b});I&&(d=I),M&&this.emit("messageSuccess",`${C.getMessagesByLocale(A.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let l=!1;switch(this.dependToolName){case p.Rect:{l=!j.isInRect(d,this.basicResult);break}case p.Polygon:{l=!L.isInPolygon(d,this.basicResult.pointList);break}}if(l)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let a=y(D({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:H(8,62),sourceID:r,textAttribute:"",order:h.getMaxOrder(this.pointList.filter(l=>h.isSameSourceID(l.sourceID,r)))+1});if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.pointList.filter(b=>h.isSameSourceID(b.sourceID,r)),this.config.textCheckType),a=y(D({},a),{textAttribute:l})}if(this.hasMarkerConfig){const l=h.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(l)a=y(D({},a),{label:l.label}),this.markerIndex=l.index,this.emit("markIndexChange");else{this.emit("messageInfo",C.getMessagesByLocale(A.MarkerFinish,this.lang));return}}this.hoverID=a.id;const g=[...this.pointList,a];this.setPointList(g),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(g),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(R(t.x-e.x,2)+R(t.y-e.y,2))}getHoverId(){var t;const e=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.emit("pointSelected",this.hoverID),t&&this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=h.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===f.Move||this.dragStatus===f.Start)return;let e=w.ascend;t.shiftKey&&(e=w.descend);const[i,s]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let o=[...i];s&&(o=[...o,s]);const n=h.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=h.getRenderResultList(t,h.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===f.Move||this.dragStatus===f.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=f.Wait,{width:U*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(v.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(b=>b.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:r}=i,u=U*this.zoom*.6,d=c.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),a=this.getColor(n),g=r?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,l=4;this._textAttributInstance||(this._textAttributInstance=new F({width:u,container:this.container,icon:this.getTextIconSvg(n),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+l,color:g,width:u})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:r}=t,u=e||t.id===this.selectedID,d=this.getColor(r),a=c.changePointByZoom(t,this.zoom,this.currentPos),{width:g=2,hiddenText:l=!1}=this.style,b=Z.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});x.drawCircle(this.canvas,a,g,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:b.stroke,fill:b.fill});let I="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(I=`${t.order}`),t.label&&this.hasMarkerConfig&&(I=`${h.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${P.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(I=`${I} ${v.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),l||x.drawText(this.canvas,{x:a.x+g/2,y:a.y-g-4},I,{textAlign:"center",color:b.stroke}),u?this.renderTextAttribute():l||x.drawText(this.canvas,{x:a.x+g,y:a.y+g+24},n,D({color:b.stroke},B))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case E.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=h.getRenderResultList(this.pointList,h.getSourceID(this.basicResult),this.attributeLockList,this.selectedID),s=e;if(i&&s.push(i),s.length<2)return;const o=P.getAuxiliaryLineByMarkerList(this.config.markerList,"value");P.getAuxiliaryLineCoord(o,s).forEach(r=>{const{start:u,end:d}=r,a=c.changePointListByZoom([u,d],this.zoom,this.currentPos);x.drawLine(this.canvas,a[0],a[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===p.Polygon,{dropFoot:r}=L.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:_.Line,k/this.zoom,{isClose:n});r&&o!==r&&o!==r&&(o=r,x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{G as default};
1
+ import{EToolName as v,ELineTypes as w,edgeAdsorptionScope as _}from"../../constant/tool.js";import E from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import S from"../../utils/tool/MarkerUtils.js";import j from"../../utils/MathUtils.js";import z from"lodash";import{EDragStatus as f,ESortDirection as M,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import y from"../../constant/keyCode.js";import C from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/StyleUtils.js";import Z from"../../utils/uuid.js";import{BasicToolOperation as H}from"./basicToolOperation.js";import K from"./textAttributeClass.js";import W from"./Selection.js";var F=Object.defineProperty,$=Object.defineProperties,V=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,X=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,R=Math.pow,O=(m,t,e)=>t in m?F(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,x=(m,t)=>{for(var e in t||(t={}))X.call(t,e)&&O(m,e,t[e]);if(T)for(var e of T(t))q.call(t,e)&&O(m,e,t[e]);return m},P=(m,t)=>$(m,V(t));const U=200;class G extends H{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const o=this.config.markerList[s].value,n=this.currentPageResult.find(r=>r.label===o);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(p.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const o=c.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const r=c.changePointByZoom(n,this.zoom);return j.getLineLength(r,o)<.2})};var e,i;this.config=a.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.selection=new W(this),this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}get selectedID(){return this.selection.selectedID}get selectedIDs(){return this.selection.selectedIDs}get selectedPoints(){return this.pointList.filter(t=>this.selection.isIdSelected(t.id))}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=a.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=a.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPoints.length>0&&(this.selectedPoints.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.pointList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return p.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=f.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>P(x({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if(this.hoverID&&this.selection.isIdSelected(this.hoverID)&&t.button===0){this.dragStatus=f.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:z.cloneDeep(this.selectedPoints)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===f.Start||this.dragStatus===f.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(t),this.dragStatus===f.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=f.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=f.Move;const s=this.getCoordinateUnderZoom(t);if(this.selectedIDs.length>1&&this.dragInfo){const r={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(r);return}const o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):c.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===v.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(r=>{r.id===this.selectedID&&(r.x=n.x,r.y=n.y)}),this.render())}onKeyUp(t){super.onKeyUp(t),this.selection.triggerKeyboardEvent(t,this.setPointList.bind(this))}onKeyDown(t){if(!a.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case y.Delete:this.deletePoint();break;case y.Tab:{this.onTabKeyDown(t);break}case y.Z:this.setIsHidden(!this.isHidden),this.render();break;case y.A:this.selection.selectAll();break;default:{if(this.config.attributeConfigurable){const i=p.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${C.getMessagesByLocale(A.LowerLimitPoint,this.lang)}`);return}const r=a.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[v.Polygon,v.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const b=((i=this.referenceData)==null?void 0:i.toolName)===v.Polygon,{dropFoot:I,hasClosed:k}=L.getClosestPoint(d,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:w.Line,_/this.zoom,{isClose:b});I&&(d=I),k&&this.emit("messageSuccess",`${C.getMessagesByLocale(A.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let l=!1;switch(this.dependToolName){case v.Rect:{l=!E.isInRect(d,this.basicResult);break}case v.Polygon:{l=!L.isInPolygon(d,this.basicResult.pointList);break}}if(l)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let h=P(x({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:Z(8,62),sourceID:r,textAttribute:"",order:a.getMaxOrder(this.pointList.filter(l=>a.isSameSourceID(l.sourceID,r)))+1});if(this.config.textConfigurable){let l="";l=p.getTextAttribute(this.pointList.filter(b=>a.isSameSourceID(b.sourceID,r)),this.config.textCheckType),h=P(x({},h),{textAttribute:l})}if(this.hasMarkerConfig){const l=a.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(l)h=P(x({},h),{label:l.label}),this.markerIndex=l.index,this.emit("markIndexChange");else{this.emit("messageInfo",C.getMessagesByLocale(A.MarkerFinish,this.lang));return}}this.hoverID=h.id;const g=[...this.pointList,h];this.setPointList(g),this.emit("pointCreated",h,this.zoom),this.history.pushHistory(g),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(R(t.x-e.x,2)+R(t.y-e.y,2))}getHoverId(){var t;const e=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(t){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const i=this.pointList.filter(s=>s.id!==this.selectedID);this.setPointList(i),this.history.pushHistory(i),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const e=this.pointList.find(i=>i.id===this.hoverID);if(this.setSelectedID(this.hoverID,t.ctrlKey),this.emit("pointSelected",this.hoverID),e&&this.setDefaultAttribute(e==null?void 0:e.attribute),(e==null?void 0:e.label)&&this.hasMarkerConfig){const i=a.getCurrentMarkerIndex(e.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===f.Move||this.dragStatus===f.Start)return;let e=M.ascend;t.shiftKey&&(e=M.descend);const[i,s]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let o=[...i];s&&(o=[...o,...s]);const n=a.getNextSelectedRectID(o,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=a.getRenderResultList(t,a.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedIDs.length>0&&(this.setPointList(this.pointList.filter(e=>this.selection.isIdSelected(e.id))),this.history.pushHistory(this.pointList),(t=this._textAttributeInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===f.Move||this.dragStatus===f.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=f.Wait,{width:U*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;p.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",p.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(p.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(b=>b.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:n,valid:r}=i,u=U*this.zoom*.6,d=c.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),h=this.getColor(n),g=r?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,l=4;this._textAttributeInstance||(this._textAttributeInstance=new K({width:u,container:this.container,icon:this.getTextIconSvg(n),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((e=this._textAttributeInstance)==null?void 0:e.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+l,color:g,width:u})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:n="",attribute:r}=t,u=e||t.id===this.selectedID,d=this.getColor(r),h=c.changePointByZoom(t,this.zoom,this.currentPos),{width:g=2,hiddenText:l=!1}=this.style,b=B.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});D.drawCircle(this.canvas,h,g,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:b.stroke,fill:b.fill});let I="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(I=`${t.order}`),t.label&&this.hasMarkerConfig&&(I=`${a.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${S.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(I=`${I} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),l||D.drawText(this.canvas,{x:h.x+g/2,y:h.y-g-4},I,{textAlign:"center",color:b.stroke}),u?this.renderTextAttribute():l||D.drawText(this.canvas,{x:h.x+g,y:h.y+g+24},n,x({color:b.stroke},N))}renderMultiSelectedPoint(){this.selectedPoints.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){const[t,e]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&e.forEach(i=>{this.renderPoint(i,!0)})}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=a.getRenderResultList(this.pointList,a.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs),s=e;if(i&&s.push(...i),s.length<2)return;const o=S.getAuxiliaryLineByMarkerList(this.config.markerList,"value");S.getAuxiliaryLineCoord(o,s).forEach(r=>{const{start:u,end:d}=r,h=c.changePointListByZoom([u,d],this.zoom,this.currentPos);D.drawLine(this.canvas,h[0],h[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===v.Polygon,{dropFoot:r}=L.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:w.Line,_/this.zoom,{isClose:n});r&&o!==r&&o!==r&&(o=r,D.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),D.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}export{G as default};
@@ -1 +1 @@
1
- import{i18n as _}from"@labelbee/lb-utils";import j from"lodash";import D from"../../utils/MathUtils.js";import N from"../../utils/tool/RectUtils.js";import{ERotateDirection as W,EDragStatus as x,ESortDirection as U,EDragTarget as v,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import L from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as O,EToolName as H}from"../../constant/tool.js";import C from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import $ from"../../utils/ActionsHistory.js";import b from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import f from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import V from"./textAttributeClass.js";var X=Object.defineProperty,Y=Object.defineProperties,q=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,F=(I,t,e)=>t in I?X(I,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):I[t]=e,y=(I,t)=>{for(var e in t||(t={}))G.call(t,e)&&F(I,e,t[e]);if(Z)for(var e of Z(t))J.call(t,e)&&F(I,e,t[e]);return I},m=(I,t)=>Y(I,q(t));const z=164;class Q extends K{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(b.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new $,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return f.getPolygonByID(this.visiblePolygonList,this.selectedID)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>m(y({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=u.getRenderResultList(this.visiblePolygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?y(y({},i),t):i)}rotatePolygon(t=1,e=W.Clockwise,i=this.selectedID){if(!i)return;const s=f.getPolygonByID(this.polygonList,i);if(!s)return;const o=f.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(o,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=f.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),r=c.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(y({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3,minArea:i=1}=this.config;e<3&&(e=3),i<1&&(i=1);let s;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(f.calcPolygonSize(this.drawingPointList||[])<i){this.emit("messageInfo",`${C.getMessagesByLocale(S.MinAreaLimitErrorNotice,this.lang)}${i}`);return}const o=u.getSourceID(this.basicResult),l=[...this.polygonList];if(this.editPolygonID){const n=l.find(r=>r.id===this.editPolygonID);if(!n)return;n.pointList=this.drawingPointList,this.editPolygonID=""}else{const n=M(8,62);let r={id:n,sourceID:o,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(l.filter(h=>u.isSameSourceID(h.sourceID,o)))+1};if(this.config.textConfigurable){let h="";h=b.getTextAttribute(this.polygonList.filter(d=>u.isSameSourceID(d.sourceID,o)),this.config.textCheckType),r=m(y({},r),{textAttribute:h})}this.pattern===w.Rect&&t===!0&&(r=m(y({},r),{isRect:!0})),l.push(r),s=r,this.setSelectedIdAfterAddingDrawing(n)}this.setPolygonList(l),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(l),s&&this.emit("polygonCreated",s,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>m(y({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return f.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=c.changePointListByZoom(i.pointList,this.zoom);return f.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${C.getMessagesByLocale(S.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=U.ascend;t.shiftKey&&(e=U.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,d,g,a;return m(y({},r),{x:(d=(h=r.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=r.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(r=>B.inViewPort({x:r.x,y:r.y},o)),n=u.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case L.Space:this.spaceKeydown();break;case L.Esc:this.drawingPointList=[],this.editPolygonID="";break;case L.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case L.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case L.Delete:this.deletePolygon(this.selectedID),this.render();break;case L.Ctrl:this.isCtrl=!0;break;case L.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case L.Tab:{this.onTabKeyDown(t);break}case L.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=b.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case L.Ctrl:this.isCtrl=!1;break;case L.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=f.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let l=[0],n=v.Plane;this.dragStatus=x.Start;const r=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);r>-1?(n=v.Point,l=[r]):h>-1&&this.hoverEdgeIndex>-1&&(n=v.Line,l=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:l,originPolygon:this.selectedPolygon,dragPrevCoord:o,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==O.Line)return;const e=f.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=f.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=f.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const d=u.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var p,T;return a.id===this.selectedID?(r=a.attribute,h=(p=a==null?void 0:a.valid)!=null?p:!0,g=(T=a==null?void 0:a.textAttribute)!=null?T:"",m(y({},a),{pointList:n})):a}),l.length>0&&l.forEach((a,p)=>{o.push({sourceID:d,id:M(8,62),pointList:a,valid:h,order:u.getMaxOrder(this.currentShowList)+1+p,attribute:r,textAttribute:g})})}else o[s].pointList=f.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",_.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==O.Line){this.emit("messageInfo",_.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=f.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case H.Rect:{n=t.filter(r=>!N.isInRect(r,this.basicResult)).length>0;break}case H.Polygon:{n=f.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=D.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[v.Line].includes(o)){const d=D.getArrayIndex(n[0]-2,4),g=D.getArrayIndex(n[0]-1,4),a=[r[d],r[g]],p=D.getRectPerpendicularOffset(h,s,a);return{x:p.x/this.zoom,y:p.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===v.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=j.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=x.Move,o){case v.Plane:i=i.map(r=>m(y({},r),{x:r.x+n.x,y:r.y+n.y}));break;case v.Point:case v.Line:i=i.map((r,h)=>l&&l.includes(h)?m(y({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&o===v.Point&&l&&(i=D.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onDragMove(t){const e=this.polygonList.map(i=>{if(i.id===this.selectedID){const s=this.dragPolygon(t,i);if(!s)return i;const o=m(y({},i),{pointList:s});return i.isRect===!0&&this.pattern===w.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.enableDrag){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return b.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:z,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;b.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(b.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=z,d=c.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new V({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${l}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,d=this.getColor(h),g=A.getStrokeAndFill(d,e.valid),a=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let p=`${(l=b.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(p=`${e.order} ${p}`),P.drawText(this.canvas,a[0],p,y({color:g.stroke},k));const T=a[a.length-1];P.drawText(this.canvas,{x:T.x+E.x,y:T.y+E.y},r,y({color:g.stroke},k))}))}renderSelectedPolygon(){var t,e,i;const{selectedPolygon:s}=this;if(s){const o=this.getColor(s.attribute),l=A.getStrokeAndFill(o,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=b.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),P.drawText(this.canvas,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,y({color:l.stroke},k)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),l=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=f.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(r=h)}n.push(r)}P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:d,y:g}=c.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{Q as default};
1
+ import j from"lodash";import{i18n as _}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import N from"../../utils/tool/RectUtils.js";import{ERotateDirection as W,EDragStatus as x,ESortDirection as U,EDragTarget as v,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import L from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as O,EToolName as H}from"../../constant/tool.js";import C from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import K from"../../utils/ActionsHistory.js";import b from"../../utils/tool/AttributeUtils.js";import a from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import f from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import u from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as $}from"./basicToolOperation.js";import V from"./textAttributeClass.js";import X from"./Selection.js";var Y=Object.defineProperty,q=Object.defineProperties,G=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,F=(I,t,e)=>t in I?Y(I,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):I[t]=e,y=(I,t)=>{for(var e in t||(t={}))J.call(t,e)&&F(I,e,t[e]);if(Z)for(var e of Z(t))Q.call(t,e)&&F(I,e,t[e]);return I},m=(I,t)=>q(I,G(t));const z=164;class tt extends ${constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(b.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=f.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new K,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new X(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return u.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return u.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>m(y({},t),{pointList:a.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=f.getRenderResultList(this.polygonList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=f.getRenderResultList(this.polygonList,f.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?y(y({},i),t):i)}rotatePolygon(t=1,e=W.Clockwise,i=this.selectedID){if(!i)return;const s=u.getPolygonByID(this.polygonList,i);if(!s)return;const o=u.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=a.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(a.returnClosePointIndex(o,a.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=u.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),r=a.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(y({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(u.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${C.getMessagesByLocale(S.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=f.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=M(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:f.getMaxOrder(o.filter(r=>f.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=b.getTextAttribute(this.polygonList.filter(h=>f.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(y({},n),{textAttribute:r})}this.pattern===w.Rect&&t===!0&&(n=m(y({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>m(y({},o),{pointList:a.changePointListByZoom(o.pointList,this.zoom)}));return u.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=a.changePointListByZoom(i.pointList,this.zoom);return u.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=a.changePointListByZoom(e.pointList,this.zoom);return a.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${C.getMessagesByLocale(S.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=U.ascend;t.shiftKey&&(e=U.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=f.getRenderResultList(this.polygonList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,c,g,d;return m(y({},r),{x:(c=(h=r.pointList[0])==null?void 0:h.x)!=null?c:0,y:(d=(g=r.pointList[0])==null?void 0:g.y)!=null?d:0})}).filter(r=>B.inViewPort({x:r.x,y:r.y},o)),n=f.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!f.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case L.Space:this.spaceKeydown();break;case L.Esc:this.drawingPointList=[],this.editPolygonID="";break;case L.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case L.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case L.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case L.Ctrl:this.isCtrl=!0;break;case L.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case L.Tab:{this.onTabKeyDown(t);break}case L.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=b.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){if(super.onKeyUp(t),!this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))switch(t.keyCode){case L.Ctrl:this.isCtrl=!1;break;case L.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=u.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,a.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=v.Plane;const o=this.selectedPolygons[0].pointList,l=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=x.Start;const n=this.getHoverPointIndex(t),r=this.getHoverEdgeIndex(t);n>-1?(s=v.Point,i=[n]):r>-1&&this.hoverEdgeIndex>-1&&(s=v.Line,i=[r,(r+1)%o.length])}this.dragInfo={dragStartCoord:l,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:l,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==O.Line)return;const e=u.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=u.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=u.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const c=f.getSourceID(this.basicResult);let g="";o=this.polygonList.map(d=>{var p,T;return d.id===this.selectedID?(r=d.attribute,h=(p=d==null?void 0:d.valid)!=null?p:!0,g=(T=d==null?void 0:d.textAttribute)!=null?T:"",m(y({},d),{pointList:n})):d}),l.length>0&&l.forEach((d,p)=>{o.push({sourceID:c,id:M(8,62),pointList:d,valid:h,order:f.getMaxOrder(this.currentShowList)+1+p,attribute:r,textAttribute:g})})}else o[s].pointList=u.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",_.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==O.Line){this.emit("messageInfo",_.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=u.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(c=>!r.includes(c.id)).map(c=>c.id===this.selectedID?n:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case H.Rect:{n=t.filter(r=>!N.isInRect(r,this.basicResult)).length>0;break}case H.Polygon:{n=u.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=D.calcViewportBoundaries(a.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=m(y({},i),{pointList:s});return i.isRect===!0&&this.pattern===w.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[v.Line].includes(o)){const c=D.getArrayIndex(n[0]-2,4),g=D.getArrayIndex(n[0]-1,4),d=[r[c],r[g]],p=D.getRectPerpendicularOffset(h,s,d);return{x:p.x/this.zoom,y:p.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===v.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=j.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=x.Move,o){case v.Plane:i=i.map(r=>m(y({},r),{x:r.x+n.x,y:r.y+n.y}));break;case v.Point:case v.Line:i=i.map((r,h)=>l&&l.includes(h)?m(y({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&o===v.Point&&l&&(i=D.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render()),this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t)}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return b.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:z,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;b.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(b.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=z,c=a.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),d=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new V({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${l}`,{left:c.x,top:c.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,c=this.getColor(h),g=A.getStrokeAndFill(c,e.valid),d=a.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let p=`${(l=b.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(p=`${e.order} ${p}`),P.drawText(this.canvas,d[0],p,y({color:g.stroke},k));const T=d[d.length-1];P.drawText(this.canvas,{x:T.x+E.x,y:T.y+E.y},r,y({color:g.stroke},k))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),l=A.getStrokeAndFill(o,t.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,a.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let n=`${(i=b.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(n=`${t.order} ${n}`),P.drawText(this.canvas,a.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),n,y({color:l.stroke},k)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,a.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const o=this.getColor(this.defaultAttribute),l=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=a.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=u.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(r=h)}n.push(r)}P.drawSelectedPolygonWithFillAndLine(this.canvas,a.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:c,y:g}=a.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:c,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,a.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{tt as default};