@labelbee/lb-annotation 1.7.2-alpha.0 → 1.7.2-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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";/*!
2
- * sense-annotation v1.7.2-alpha.0
2
+ * sense-annotation v1.7.2-alpha.1
3
3
  * (c) 2020-2022
4
4
  * Released under the Apache-2.0 License.
5
5
  */Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),rgba=require("color-rgba");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba);const editStepWidth=320;var EPointCloudName;(function(r){r.PointCloud="pointCloudTool"})(EPointCloudName||(EPointCloudName={}));var EVideoToolName;(function(r){r.VideoTextTool="videoTextTool",r.VideoTagTool="videoTagTool",r.VideoClipTool="videoClipTool"})(EVideoToolName||(EVideoToolName={}));var EToolType;(function(r){r[r.Rect=0]="Rect",r[r.Tag=1]="Tag"})(EToolType||(EToolType={}));var EToolName;(function(r){r.Rect="rectTool",r.Tag="tagTool",r.Point="pointTool",r.PointMarker="pointMarkerTool",r.Segmentation="segmentationTool",r.Filter="filterTool",r.Text="textTool",r.Polygon="polygonTool",r.Line="lineTool",r.LineMarker="lineMarkerTool",r.Empty="emptyTool",r.FolderTag="folderTagTool",r.RectTrack="rectTrackTool",r.Face="faceTool",r.ClientAttribute="clientAttributeTool",r.OCRRelation="OCRRelationTool"})(EToolName||(EToolName={}));var ECheckModel;(function(r){r.Check="check"})(ECheckModel||(ECheckModel={}));var ERectPattern;(function(r){r[r.nothing=0]="nothing",r[r.RectBG=1]="RectBG",r[r.showOrder=2]="showOrder"})(ERectPattern||(ERectPattern={}));const TOOL_NAME={[EToolName.Rect]:"\u62C9\u6846",[EToolName.Tag]:"\u6807\u7B7E",[EToolName.Point]:"\u6807\u70B9",[EToolName.PointMarker]:"\u5217\u8868\u6807\u70B9",[EToolName.Segmentation]:"\u524D\u666F\u5206\u5272",[EToolName.Filter]:"\u7B5B\u9009",[EToolName.Text]:"\u6587\u672C",[EToolName.Polygon]:"\u591A\u8FB9\u5F62",[EToolName.Line]:"\u7EBF\u6761",[EToolName.LineMarker]:"\u5217\u8868\u7EBF\u6761",[EToolName.FolderTag]:"\u6587\u4EF6\u5939\u6807\u7B7E",[EToolName.RectTrack]:"\u62C9\u6846\u8DDF\u8E2A",[EToolName.Face]:"\u4EBA\u8138106\u5DE5\u5177",[EToolName.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[EToolName.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177",[EVideoToolName.VideoTextTool]:"\u89C6\u9891\u6587\u672C",[EVideoToolName.VideoTagTool]:"\u89C6\u9891\u6807\u7B7E",[EVideoToolName.VideoClipTool]:"\u89C6\u9891\u622A\u53D6",[EPointCloudName.PointCloud]:"\u70B9\u4E91"};var EDependPattern;(function(r){r[r.noDepend=1]="noDepend",r[r.dependOrigin=2]="dependOrigin",r[r.dependShape=3]="dependShape",r[r.dependLine=4]="dependLine",r[r.dependPolygon=5]="dependPolygon",r[r.dependPreShape=101]="dependPreShape",r[r.dependPreLine=102]="dependPreLine",r[r.dependPrePolygon=103]="dependPrePolygon"})(EDependPattern||(EDependPattern={}));var EFilterToolOperation;(function(r){r.lc="leftClick",r.rc="rightClick",r.clc="ctrlLeftClick",r.crc="ctrlRightClick"})(EFilterToolOperation||(EFilterToolOperation={}));const OPERATION_LIST={leftClick:"\u9F20\u6807\u5DE6\u952E",rightClick:"\u9F20\u6807\u53F3\u952E",ctrlLeftClick:"ctrl + \u9F20\u6807\u5DE6\u952E",ctrlRightClick:"ctrl + \u9F20\u6807\u53F3\u952E"};var EAnnotationMode;(function(r){r[r.Normal=1]="Normal",r[r.Modify=2]="Modify"})(EAnnotationMode||(EAnnotationMode={}));var ELineTypes;(function(r){r[r.Line=0]="Line",r[r.Curve=1]="Curve"})(ELineTypes||(ELineTypes={}));var ELineColor;(function(r){r[r.SingleColor=0]="SingleColor",r[r.MultiColor=1]="MultiColor"})(ELineColor||(ELineColor={}));var ESelectedType;(function(r){r[r.Form=1]="Form",r[r.Json=2]="Json"})(ESelectedType||(ESelectedType={}));var EDragTarget$1;(function(r){r[r.Point=0]="Point",r[r.Line=1]="Line",r[r.Plane=2]="Plane"})(EDragTarget$1||(EDragTarget$1={}));var EDrawPointPattern;(function(r){r[r.None=0]="None",r[r.Drawing=1]="Drawing",r[r.Edit=2]="Edit"})(EDrawPointPattern||(EDrawPointPattern={}));var EPageOperator$1;(function(r){r[r.Backward=0]="Backward",r[r.Forward=1]="Forward",r[r.JumpSkip=2]="JumpSkip",r[r.None=3]="None"})(EPageOperator$1||(EPageOperator$1={}));var EAuditStatus;(function(r){r[r.Wait=0]="Wait",r[r.Pass=1]="Pass",r[r.Fail=2]="Fail",r[r.Loading=3]="Loading"})(EAuditStatus||(EAuditStatus={}));var ETextType;(function(r){r[r.AnyString=0]="AnyString",r[r.Order=1]="Order",r[r.EnglishOnly=2]="EnglishOnly",r[r.NumberOnly=3]="NumberOnly",r[r.CustomFormat=4]="CustomFormat"})(ETextType||(ETextType={}));const TEXT_TYPE={0:"\u4EFB\u610F\u5B57\u7B26",1:"\u5E8F\u53F7",2:"\u4EC5\u82F1\u6587",3:"\u4EC5\u6570\u5B57"},TEXT_ATTRIBUTE_MAX_LENGTH=1e3,TEXT_ATTRIBUTE_LINE_HEIGHT=16,DEFAULT_TEXT_MAX_WIDTH=300,DEFAULT_FONT="normal normal 500 14px Arial";var EThumbnailOption;(function(r){r[r.ImgList=1e3]="ImgList",r[r.TrackPrediction=1001]="TrackPrediction",r[r.ImgSearch=1002]="ImgSearch"})(EThumbnailOption||(EThumbnailOption={}));const CLIENT_TOOL_HEAD_TYPE={[EPointCloudName.PointCloud]:"sensebeepc",[EToolName.ClientAttribute]:"sensebeepc-EnumAttributeTool",[EToolName.Face]:"sensebeepc-FacePointsLabellingTool",[EToolName.OCRRelation]:"sensebeepc-OCRRelationTool"},CLIENT_TOOL_NAME={[EPointCloudName.PointCloud]:"\u70B9\u4E91\u5BA2\u6237\u7AEF",[EToolName.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[EToolName.Face]:"\u4EBA\u8138106\u70B9\u5DE5\u5177",[EToolName.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177"},SEGMENT_NUMBER$2=16,edgeAdsorptionScope=10;var EPolygonPattern;(function(r){r[r.Normal=0]="Normal",r[r.Rect=1]="Rect"})(EPolygonPattern||(EPolygonPattern={}));var tool=Object.freeze({__proto__:null,editStepWidth,get EPointCloudName(){return EPointCloudName},get EVideoToolName(){return EVideoToolName},get EToolType(){return EToolType},get EToolName(){return EToolName},get ECheckModel(){return ECheckModel},get ERectPattern(){return ERectPattern},TOOL_NAME,get EDependPattern(){return EDependPattern},get EFilterToolOperation(){return EFilterToolOperation},OPERATION_LIST,get EAnnotationMode(){return EAnnotationMode},get ELineTypes(){return ELineTypes},get ELineColor(){return ELineColor},get ESelectedType(){return ESelectedType},get EDragTarget(){return EDragTarget$1},get EDrawPointPattern(){return EDrawPointPattern},get EPageOperator(){return EPageOperator$1},get EAuditStatus(){return EAuditStatus},get ETextType(){return ETextType},TEXT_TYPE,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_ATTRIBUTE_LINE_HEIGHT,DEFAULT_TEXT_MAX_WIDTH,DEFAULT_FONT,get EThumbnailOption(){return EThumbnailOption},CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,SEGMENT_NUMBER:SEGMENT_NUMBER$2,edgeAdsorptionScope,get EPolygonPattern(){return EPolygonPattern}}),__defProp$g=Object.defineProperty,__defProps$d=Object.defineProperties,__getOwnPropDescs$d=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$g=Object.getOwnPropertySymbols,__hasOwnProp$g=Object.prototype.hasOwnProperty,__propIsEnum$g=Object.prototype.propertyIsEnumerable,__defNormalProp$g=(r,t,e)=>t in r?__defProp$g(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$g=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$g.call(t,e)&&__defNormalProp$g(r,e,t[e]);if(__getOwnPropSymbols$g)for(var e of __getOwnPropSymbols$g(t))__propIsEnum$g.call(t,e)&&__defNormalProp$g(r,e,t[e]);return r},__spreadProps$d=(r,t)=>__defProps$d(r,__getOwnPropDescs$d(t));function createSmoothCurvePoints(r,t=.5,e=!1,i=16){if(r.length<4)return r;const s=[],n=r.slice(0);let o,a,l,h,c,g,u,d,f,v,p,b,x;for(e?(n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.push(r[0]),n.push(r[1])):(n.unshift(r[1]),n.unshift(r[0]),n.push(r[r.length-2]),n.push(r[r.length-1])),x=2;x<n.length-4;x+=2)for(l=(n[x+2]-n[x-2])*t,h=(n[x+4]-n[x-0])*t,c=(n[x+3]-n[x-1])*t,g=(n[x+5]-n[x+1])*t,b=0;b<=i;b++)p=b/i,u=2*Math.pow(p,3)-3*Math.pow(p,2)+1,d=-(2*Math.pow(p,3))+3*Math.pow(p,2),f=Math.pow(p,3)-2*Math.pow(p,2)+p,v=Math.pow(p,3)-Math.pow(p,2),o=u*n[x]+d*n[x+2]+f*l+v*h,a=u*n[x+1]+d*n[x+3]+f*c+v*g,s.push(o),s.push(a);const y=[];for(let I=0;I<s.length-1;I+=2)y.push({x:s[I],y:s[I+1]});if(e)for(let I=0;I<i+1;I++){const m=y.shift();y.push(m)}return y}const createSmoothCurvePointsFromPointList=(r,t=16)=>createSmoothCurvePoints(r.reduce((e,i)=>[...e,i.x,i.y],[]),.5,!1,t);function isInPolygon(r,t,e=ELineTypes.Line){let i=0,s,n,o,a;t=[...t],e===ELineTypes.Curve&&(t=createSmoothCurvePoints(t.reduce((h,c)=>[...h,c.x,c.y],[]),.5,!0,SEGMENT_NUMBER$2)),[o]=t;const l=t.length;for(s=1;s<=l;s++)a=t[s%l],r.x>Math.min(o.x,a.x)&&r.x<=Math.max(o.x,a.x)&&r.y<=Math.max(o.y,a.y)&&o.x!==a.x&&(n=(r.x-o.x)*(a.y-o.y)/(a.x-o.x)+o.y,(o.y===a.y||r.y<=n)&&i++),o=a;return i%2!=0}function getPolygonPointUnderZoom(r,t=1){return r.map(e=>__spreadProps$d(__spreadValues$g({},e),{x:e.x*t,y:e.y*t}))}var __pow$1=Math.pow;class Vector{static add(t,e){return{x:t.x+e.x,y:t.y+e.y}}static getVector(t,e){return{x:e.x-t.x,y:e.y-t.y}}static len(t){return Math.sqrt(__pow$1(t.x,2)+__pow$1(t.y,2))}static dotProduct(t,e){return t.x*e.x+t.y+e.y}}class Trigonometric{static tanAPlusB(t,e){return(t+e)/(1-t*e)}static sinAPlusB(t,e,i,s){return s*t+e*i}static cosAPlusB(t,e,i,s){return e*s-t*i}}const _MathUtils=class{static getRotate(r){return r+90>=360?r+90-360:r+90}static getLineLength(r,t){return Math.sqrt(Math.pow(t.y-r.y,2)+Math.pow(t.x-r.x,2))}static getTextArea(r,t,e=DEFAULT_TEXT_MAX_WIDTH,i=DEFAULT_FONT,s){if(typeof t!="string")return{width:0,height:0};const n=r.getContext("2d");n.font=i;let o=0;typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=r&&parseInt(window.getComputedStyle(r).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,l=t.split(`
@@ -74,7 +74,7 @@
74
74
  background: rgba(102, 111, 255, 1);
75
75
  opacity: 0.6;
76
76
  clear: both;
77
- `),(o=(n=this.canvas)==null?void 0:n.parentNode)==null||o.appendChild(a)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}var __defProp$7=Object.defineProperty,__defProps$6=Object.defineProperties,__getOwnPropDescs$6=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$7=Object.getOwnPropertySymbols,__hasOwnProp$7=Object.prototype.hasOwnProperty,__propIsEnum$7=Object.prototype.propertyIsEnumerable,__defNormalProp$7=(r,t,e)=>t in r?__defProp$7(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$7=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$7.call(t,e)&&__defNormalProp$7(r,e,t[e]);if(__getOwnPropSymbols$7)for(var e of __getOwnPropSymbols$7(t))__propIsEnum$7.call(t,e)&&__defNormalProp$7(r,e,t[e]);return r},__spreadProps$6=(r,t)=>__defProps$6(r,__getOwnPropDescs$6(t)),EStatus;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends BasicToolOperation{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=___default.default.cloneDeep(this.activeLine);if(!n||n.length===0)return;const o=this.isActiveLineValid();let a;const l=this.selectedID?this.lineList.find(c=>c.id===this.selectedID):void 0;l?a=l.order:a=this.nextOrder();const h=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!o});n.map(c=>Object.assign(c,this.coordUtils.getRenderCoord(c))),this.updateActiveArea(),this.drawLine(n,e,h,!0,!0),this.drawLineNumber(n[0],a,h,"",this.defaultAttribute,o),e&&this.isCreate&&this.arc(e,POINT_RADIUS,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,h)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>LineToolUtils.calcDistance(this.coordUtils.getRenderCoord(o),e)<=POINT_ACTIVE_RADIUS);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(e,i,s,n=!0,o=!1,a)=>{const l=createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),o&&LineToolUtils.setReferenceCtx(e),i.forEach(({specialEdge:h},c)=>{const g=l.splice(0,SEGMENT_NUMBER+1);e.save(),e.beginPath(),a===c&&(e.lineWidth=4),g.forEach(({x:u,y:d},f)=>{const v=f>0?"lineTo":"moveTo";h&&LineToolUtils.setSpecialEdgeStyle(e),e[v](u,d)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,o=!1)=>{const a=i?e.concat(i):e,l={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.drawCurveLine(this.ctx,a,l,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(a,l,o),n&&e.forEach(h=>{var c,g;const u=h.id,d=u&&[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(h,d,s),[this.hoverPointID,(g=this.selectedPoint)==null?void 0:g.id].includes(u)||this.arc(h,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.setReferenceCtx(n),e.forEach((o,a)=>{if(n.beginPath(),a>0){const l=e[a-1];n.save(),(l==null?void 0:l.specialEdge)&&LineToolUtils.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===a&&(n.lineWidth=4),n.moveTo(l.x,l.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l)));const{order:s,label:n}=i,o=s,a=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,a,!1),this.drawLineNumber(i.pointList[0],o,a,n,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],a,i==null?void 0:i.textAttribute)}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+e,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:o,left:a,right:l,bottom:h}=this.activeArea,c=[a,l].map(p=>___default.default.isNumber(p)?p+e:0),g=[o,h].map(p=>___default.default.isNumber(p)?p+i:0),u=a>=0&&l&&MathUtils.isInRange(c,s),d=o>=0&&h&&MathUtils.isInRange(g,n),f=u?e:0,v=d?i:0;this.lineDragging=!0,this.moveActiveArea(f,v)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===EKeyCode$1.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===EKeyCode$1.Delete){this.deleteLine();return}if(e.keyCode===EKeyCode$1.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===EKeyCode$1.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.dependToolConfig={lineType:ELineTypes.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===EToolName.Polygon}get isDependRect(){return this.dependToolName===EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(t=>this.attributeLockList.includes((t==null?void 0:t.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget}get showOrder(){return this.config.showOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>CanvasUtils.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===ELineTypes.Curve?createSmoothCurvePoints(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(t[n-1]),a=this.coordUtils.getRenderCoord(s);return LineToolUtils.isInLine(e,o,a,i)})}arc(t,e=POINT_RADIUS,i){var s,n,o,a,l,h;if(this.ctx){const{x:c,y:g}=t;(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(c,g,e,0,360),(a=this.ctx)==null||a.closePath(),(l=this.ctx)==null||l.fill(),(h=this.ctx)==null||h.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:o}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,o,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(__spreadProps$6(__spreadValues$7({},t),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return StyleUtils.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?MathUtils.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,o=!0){var a,l,h;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let c=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const g=n?(h=(l=(a=this.attributeList)==null?void 0:a.find(u=>u.value===n))==null?void 0:l.key)!=null?h:n:"";c=[c,`${!o&&g?"\u65E0\u6548":""}${g}`].filter(u=>u).join("_")}this.drawText(t,c,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawText(t,e,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?DrawUtils.wrapText(this.canvas,e,t.x-LINE_ORDER_OFFSET.x,t.y-LINE_ORDER_OFFSET.y,s):this.ctx.fillText(e,t.x-LINE_ORDER_OFFSET.x,t.y-LINE_ORDER_OFFSET.y),(o=this.ctx)==null||o.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines())}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return LineToolUtils.calcDistance(i,t)<=POINT_ACTIVE_RADIUS})}findHoverLine(t){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,a)=>{if(a===0)return!1;const l=this.coordUtils.getRenderCoord(o),h=this.coordUtils.getRenderCoord(s[a-1]);return LineToolUtils.isInLine(t,l,h,n)})})}getAdsorptionPoint(t){let e,i,s;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const a=this.findNearestPoint(n,t);if(a){if(a.minDistance===0){e=a.point;return}(i===void 0||a.minDistance<i)&&(e=a.point,i=a.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let o=1;o<=t.length-1;o++){const a=this.coordUtils.getRenderCoord(t[o]),l=this.coordUtils.getRenderCoord(t[o-1]),{length:h,footPoint:c}=MathUtils.getFootOfPerpendicular(e,a,l),g=LineToolUtils.calcTwoPointDistance(a,e),u=LineToolUtils.calcTwoPointDistance(l,e);if(g<=i*2){s=a,i=0;break}if(u<=i*2){s=l,i=0;break}h<i&&(s=c,i=h)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?createSmoothCurvePointsFromPointList(t,SEGMENT_NUMBER):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:a,width:l,height:h}=this.basicResult;s=[o,o+l],n=[a,a+h]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return LineToolUtils.getVHPoint(o,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(a=>a.id===(i==null?void 0:i.id)),n=MathUtils.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom),o=this.lineList[s];this.updateStatus(1),this.setActiveLine(o.pointList),this.setSelectedLineID(o.id),this.activeArea=n,this.updateLineAttributes(o)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=MathUtils.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?___default.default.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return MathUtils.isInRange(t.x,o)&&MathUtils.isInRange(t.y,a)}return MathUtils.isInRange(t.x,[0,this.imageSize.width])&&MathUtils.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,a=this.isCurve?i.slice((n-1)*(SEGMENT_NUMBER+1),n*(SEGMENT_NUMBER+1)):[o,s];return this.pointInLine(a,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,__spreadProps$6(__spreadValues$7({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?LineToolUtils.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=___default.default.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return AttributeUtils.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=uuid(),e={pointList:___default.default.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let a;if(t){if(this.selectedID){const l=this.lineList.find(h=>h.id===this.selectedID);a=this.selectedID,l&&(l.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(l.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const l=this.createLineData();a=l.id,this.setLineList([...this.lineList,l]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?this.setActiveStatus(a):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===EKeyCode$1.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!==EKeyCode$1.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===EKeyCode$1.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===EKeyCode$1.Shift&&this.render(),t.keyCode===EKeyCode$1.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=AttributeUtils.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,a;return __spreadProps$6(__spreadValues$7({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(a=(o=i.pointList[0])==null?void 0:o.y)!=null?a:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===EKeyCode$1.Ctrl&&this.setInvalidLineOnCreating(t),[EKeyCode$1.Shift,EKeyCode$1.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=MathUtils.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(o=>o.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(o=>o.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=(e=(t=this.lineList.find(l=>l.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:o,textAttribute:a}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:a,y:l}=this.activeLine[1],h=this.coordUtils.getRenderCoord({x:a,y:l}),c=this.getColor(o),g=n?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=(i=(e=this.lineList.find(d=>d.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new TextAttributeClass({container:this.container,icon:this.getTextIconSvg(o),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:h.x,top:h.y,color:g}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(t=""){return AttributeUtils.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!AttributeUtils.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",AttributeUtils.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}class MarkerUtils{static getMarkerShowText(t,e=[]){return AttributeUtils.getAttributeShowText(t,e)}}var __defProp$6=Object.defineProperty,__defProps$5=Object.defineProperties,__getOwnPropDescs$5=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$6=Object.getOwnPropertySymbols,__hasOwnProp$6=Object.prototype.hasOwnProperty,__propIsEnum$6=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp$6=(r,t,e)=>t in r?__defProp$6(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$6=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$6.call(t,e)&&__defNormalProp$6(r,e,t[e]);if(__getOwnPropSymbols$6)for(var e of __getOwnPropSymbols$6(t))__propIsEnum$6.call(t,e)&&__defNormalProp$6(r,e,t[e]);return r},__spreadProps$5=(r,t)=>__defProps$5(r,__getOwnPropDescs$5(t));const TEXTAREA_WIDTH=200;class PointOperation extends BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=AxisUtils.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const n=AxisUtils.changePointByZoom(s,this.zoom);return MathUtils.getLineLength(n,i)<.2})},this.config=CommonToolUtils.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)}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=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),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=CommonToolUtils.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 AttributeUtils.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=EDragStatus.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===EDragStatus.Start||this.dragStatus===EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===EDragStatus.Move&&this.history.pushHistory(this.pointList),this.dragStatus=EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=EDragStatus.Move;const s=this.getCoordinateUnderZoom(t),n=AxisUtils.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),o=this.drawOutsideTarget?AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.changePointByZoom(n,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(o,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=o.x,a.y=o.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case EKeyCode$1.Delete:this.deletePoint();break;case EKeyCode$1.Tab:{this.onTabKeyDown(t);break}case EKeyCode$1.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s;if(!this.imgInfo)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${Locale.getMessagesByLocale(EMessage.LowerLimitPoint,this.lang)}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),a=this.getCoordinateUnderZoom(t);let l=AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData){const g=((e=this.referenceData)==null?void 0:e.toolName)===EToolName.Polygon,{dropFoot:u}=PolygonUtils.getClosestPoint(l,this.referenceData.result,(s=(i=this.referenceData.config)==null?void 0:i.lineType)!=null?s:ELineTypes.Line,edgeAdsorptionScope/this.zoom,{isClose:g});u&&(l=u,this.emit("messageSuccess",`${Locale.getMessagesByLocale(EMessage.SuccessfulEdgeAdsorption,this.lang)}`))}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let g=!1;switch(this.dependToolName){case EToolName.Rect:{g=!RectUtils.isInRect(l,this.basicResult);break}case EToolName.Polygon:{g=!PolygonUtils.isInPolygon(l,this.basicResult.pointList);break}}if(g)return}if(a.x<0||a.y<0||a.x>this.imgInfo.width||a.y>this.imgInfo.height)return}if(this.isMinDistance(l))return;let h=__spreadProps$5(__spreadValues$6({},l),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:o,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(g=>CommonToolUtils.isSameSourceID(g.sourceID,o)))+1});if(this.config.textConfigurable){let g="";g=AttributeUtils.getTextAttribute(this.pointList.filter(u=>CommonToolUtils.isSameSourceID(u.sourceID,o)),this.config.textCheckType),h=__spreadProps$5(__spreadValues$6({},h),{textAttribute:g})}if(this.hasMarkerConfig){const g=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(g)h=__spreadProps$5(__spreadValues$6({},h),{label:g.label}),this.markerIndex=g.index,this.emit("markIndexChange");else{this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.MarkerFinish,this.lang));return}}this.hoverID=h.id;const c=[...this.pointList,h];this.setPointList(c),this.history.pushHistory(c),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.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}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===EDragStatus.Move||this.dragStatus===EDragStatus.Start)return;let e=ESortDirection.ascend;t.shiftKey&&(e=ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=CommonToolUtils.getNextSelectedRectID(n,e,this.selectedID);o&&this.setSelectedID(o.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.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.render())}undoAndRedo(t){var e,i;if(this.dragStatus===EDragStatus.Move||this.dragStatus===EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(n=>n.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(n=>n.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=EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.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(d=>d.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:n,attribute:o,valid:a}=i,l=TEXTAREA_WIDTH*this.zoom*.6,h=AxisUtils.getOffsetCoordinate({x:s,y:n},this.currentPos,this.zoom),c=this.getColor(o),g=a?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributInstance||(this._textAttributInstance=new TextAttributeClass({width:l,container:this.container,icon:this.getTextIconSvg(o),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:h.x,top:h.y+u,color:g,width:l})}renderPoint(t){var e,i,s;const{textAttribute:n="",attribute:o}=t,a=t.id===this.selectedID,l=this.getColor(o),h=AxisUtils.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:g=!1}=this.style,u=StyleUtils.getStrokeAndFill(l,t.valid,{isSelected:a||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,h,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:u.stroke,fill:u.fill});let d="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(d=`${t.order}`),t.label&&this.hasMarkerConfig&&(d=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(d=`${d} ${AttributeUtils.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),g||DrawUtils.drawText(this.canvas,{x:h.x+c/2,y:h.y-c-4},d,{textAlign:"center",color:u.stroke}),a?this.renderTextAttribute():g||DrawUtils.drawText(this.canvas,{x:h.x+c,y:h.y+c+24},n,__spreadValues$6({color:u.stroke},DEFAULT_TEXT_OFFSET))}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let n=AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const o=((t=this.referenceData)==null?void 0:t.toolName)===EToolName.Polygon,{dropFoot:a}=PolygonUtils.getClosestPoint(n,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:ELineTypes.Line,edgeAdsorptionScope/this.zoom,{isClose:o});a&&n!==a&&n!==a&&(n=a,DrawUtils.drawCircle(this.canvas,AxisUtils.changePointByZoom(n,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.changePointByZoom(n,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}class TextToolOperation extends BasicToolOperation{constructor(t){super(t);this.getSingleResult=e=>{const i={};return this.config.configList.length>0&&this.config.configList.forEach(s=>{var n;i[s.key]=(n=s.default)!=null?n:""}),{value:i,id:uuid(),sourceID:e!=null?e:CommonToolUtils.getSourceID()}},this.getInitResultList=(e,i)=>e>0?i.map(s=>this.getSingleResult(s.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var e;this.textList=t,this.toggleTextContainerVisible(!0);const i=(e=this.textList[0])==null?void 0:e.value;i&&Object.keys(i).forEach(s=>{this.renderText(s,i[s])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!i)}updateTextValue(t,e){this.textList[0].value[t]=e,this.renderText(t,e),this.emit("valueUpdated")}renderText(t,e){const i=document.getElementById(`textKey${t}`);i&&(i.innerText=e)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),e={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(e).reduce((i,s)=>(i+=`${s}: ${e[s]};`,i),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(i=>{const s=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");s.setAttribute("style","padding: 8px 16px"),n.innerText=`${i.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(i.key)),s.appendChild(n),s.appendChild(o),t.appendChild(s)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===EKeyCode$1.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const e=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=e}}}var __defProp$5=Object.defineProperty,__defProps$4=Object.defineProperties,__getOwnPropDescs$4=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$5=Object.getOwnPropertySymbols,__hasOwnProp$5=Object.prototype.hasOwnProperty,__propIsEnum$5=Object.prototype.propertyIsEnumerable,__defNormalProp$5=(r,t,e)=>t in r?__defProp$5(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$5=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$5.call(t,e)&&__defNormalProp$5(r,e,t[e]);if(__getOwnPropSymbols$5)for(var e of __getOwnPropSymbols$5(t))__propIsEnum$5.call(t,e)&&__defNormalProp$5(r,e,t[e]);return r},__spreadProps$4=(r,t)=>__defProps$4(r,__getOwnPropDescs$4(t));class CommonToolUtils{static getStepInfo(t,e){return e==null?void 0:e.filter(i=>i.step===t)[0]}static getCurrentStepInfo(t,e){const i=this.getStepInfo(t,e);return i&&(i.type===EStepType.QUALITY_INSPECTION||i.type===EStepType.MANUAL_CORRECTION)?this.getCurrentStepInfo(i.dataSourceStep,e):i}static getMaxOrder(t){let e=0;return t.forEach(i=>{i.order&&i.order>e&&(e=i.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:i,type:s}=e;if(!i||!s)return!0;let n=!0;return(e.isContentEditable||i==="TEXTAREA"||(i==="INPUT"&&s!=="radio"||i==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getCurrentOperation(t){switch(t){case EToolName.Rect:case EToolName.RectTrack:return RectOperation;case EToolName.Tag:return TagOperation;case EToolName.Polygon:return PolygonOperation;case ECheckModel.Check:return CheckOperation;case EToolName.Line:return LineToolOperation;case EToolName.Point:return PointOperation;case EToolName.Text:return TextToolOperation;default:throw new Error("not match tool")}}static getNextSelectedRectID(t,e=ESortDirection.ascend,i){let s=1;e===ESortDirection.descend&&(s=-1);const n=t.sort((l,h)=>l.x-h.x==0?l.y-h.y:s*(l.x-h.x)),o=n.findIndex(l=>l.id===i),a=n.length;return n[(o+1)%a]}static getNextSelectedRectIDByEvent(t,e,i){const s=e.shiftKey?ESortDirection.descend:ESortDirection.ascend;return this.getNextSelectedRectID(t,s,i)}static getRenderResultList(t,e,i=[],s){let n;return[t.filter(a=>s&&s===(a==null?void 0:a.id)?(n=a,!1):!(i.length>0&&!i.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),n]}static getSourceID(t){var e;const i="";return t&&(e=t==null?void 0:t.id)!=null?e:i}static findAllLine(t,e=!0){const i=[],s=[...t];s.length>=3&&e===!0&&s.push(__spreadValues$5({},s[0]));for(let n=0;n<s.length;n++)s[n+1]&&i.push({point1:s[n],point2:s[n+1],pointIndex:n});return i}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],i){if((e==null?void 0:e.length)===0)return;let s=e.map((n,o)=>__spreadProps$4(__spreadValues$5({},n),{index:o}));if(typeof i=="number"&&i>0){const n=e[i];if(n&&t.every(o=>o.label!==n.value))return{label:n.value,index:i};s=[...s.slice(i,e.length),...s.slice(0,i)]}for(let n=0;n<s.length;n++)if(!t.some(o=>o.label===s[n].value))return{label:s[n].value,index:s[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(i=>t===i.value)}}CommonToolUtils.jsonParser=(r,t={})=>{try{return typeof r=="string"?JSON.parse(r):_.isObject(r)?r:t}catch(e){return t}};var __defProp$4=Object.defineProperty,__getOwnPropSymbols$4=Object.getOwnPropertySymbols,__hasOwnProp$4=Object.prototype.hasOwnProperty,__propIsEnum$4=Object.prototype.propertyIsEnumerable,__defNormalProp$4=(r,t,e)=>t in r?__defProp$4(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$4=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$4.call(t,e)&&__defNormalProp$4(r,e,t[e]);if(__getOwnPropSymbols$4)for(var e of __getOwnPropSymbols$4(t))__propIsEnum$4.call(t,e)&&__defNormalProp$4(r,e,t[e]);return r};class PolygonUtils{static getHoverPolygonID(t,e,i=3,s=ELineTypes.Line){let n="",o=Infinity;const a=AxisUtils.axisArea(t,i);return e.forEach(l=>{l.pointList&&a.forEach(h=>{const c=this.calcPolygonSize(l.pointList);this.isInPolygon(h,l.pointList,s)&&c<o&&(n=l.id,o=c)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,i=t.reduce((s,n,o,a)=>{const l=a[(o+1)%e];return s+n.x*l.y-l.x*n.y},0);return Math.abs(i)/2}static isInPolygon(t,e,i=ELineTypes.Line){let s=0,n,o,a,l;e=[...e],i===ELineTypes.Curve&&(e=this.createSmoothCurvePoints(e.reduce((c,g)=>[...c,g.x,g.y],[]),.5,!0,20)),[a]=e;const h=e.length;for(n=1;n<=h;n++)l=e[n%h],t.x>Math.min(a.x,l.x)&&t.x<=Math.max(a.x,l.x)&&t.y<=Math.max(a.y,l.y)&&a.x!==l.x&&(o=(t.x-a.x)*(l.y-a.y)/(l.x-a.x)+a.y,(a.y===l.y||t.y<=o)&&s++),a=l;return s%2!=0}static createSmoothCurvePointsFromPointList(t,e=SEGMENT_NUMBER$2){return this.createSmoothCurvePoints(t.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!1,e).map((s,n)=>{var o;const a=n/(SEGMENT_NUMBER$2+1),l=Math.floor(a),h=(o=t[l])!=null?o:{};return __spreadValues$4(l===a?__spreadValues$4({},h):{specialEdge:h.specialEdge},s)})}static createSmoothCurvePoints(t,e=.5,i=!1,s=SEGMENT_NUMBER$2){if(t.length<4)return t;const n=[],o=t.slice(0);let a,l,h,c,g,u,d,f,v,p,b,x,y;for(i?(o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.push(t[0]),o.push(t[1])):(o.unshift(t[1]),o.unshift(t[0]),o.push(t[t.length-2]),o.push(t[t.length-1])),y=2;y<o.length-4;y+=2)for(h=(o[y+2]-o[y-2])*e,c=(o[y+4]-o[y-0])*e,g=(o[y+3]-o[y-1])*e,u=(o[y+5]-o[y+1])*e,x=0;x<=s;x++)b=x/s,d=2*Math.pow(b,3)-3*Math.pow(b,2)+1,f=-(2*Math.pow(b,3))+3*Math.pow(b,2),v=Math.pow(b,3)-2*Math.pow(b,2)+b,p=Math.pow(b,3)-Math.pow(b,2),a=d*o[y]+f*o[y+2]+v*h+p*c,l=d*o[y+1]+f*o[y+3]+v*g+p*u,n.push(a),n.push(l);const I=[];for(let m=0;m<n.length-1;m+=2)I.push({x:n[m],y:n[m+1]});if(i)for(let m=0;m<s+1;m++){const w=I.shift();I.push(w)}return I}static getPolygonByID(t,e){return t.find(i=>i.id===e)}static getHoverEdgeIndex(t,e,i=ELineTypes.Line,s=3){let n=[...e];i===ELineTypes.Curve?n=this.createSmoothCurvePoints(e.reduce((l,h)=>[...l,h.x,h.y],[]),.5,!0,SEGMENT_NUMBER$2):i===ELineTypes.Line&&n.push(n[0]);let o=-1,a=s;for(let l=0;l<n.length-1;l++){const{length:h}=MathUtils.getFootOfPerpendicular(t,n[l],n[l+1]);h<a&&(o=l,a=h)}return o===-1?-1:i===ELineTypes.Curve?Math.floor(o/SEGMENT_NUMBER$2):o}static getClosestPoint(t,e,i=ELineTypes.Line,s=3,n){var o;const a=(o=n==null?void 0:n.isClose)!=null?o:!0;let l="",h=-1,c=Infinity,g=t;const u=20;let d=!1;return e.forEach(f=>{if(!d&&!!f.pointList)switch(i){case ELineTypes.Line:CommonToolUtils.findAllLine(f.pointList,a).forEach((p,b)=>{if(d)return;let{length:x,footPoint:y}=MathUtils.getFootOfPerpendicular(t,p.point1,p.point2);const I=MathUtils.getLineLength(p.point1,t),m=MathUtils.getLineLength(p.point2,t);I<s*2&&(y=p.point1,x=I,d=!0),m<s*2&&(y=p.point2,x=m,d=!0),x<c&&x<s&&(l=f.id,h=b,c=x,g=y)});break;case ELineTypes.Curve:{const v=this.createSmoothCurvePoints(f.pointList.reduce((p,b)=>[...p,b.x,b.y],[]),.5,a,u);for(let p=0;p<v.length-1;p++){const{length:b,footPoint:x}=MathUtils.getFootOfPerpendicular(t,v[p],v[p+1]);b<c&&b<s&&(l=f.id,h=Math.floor(p/(u+1)),c=b,g=x)}}break}}),{dropFoot:g,closestEdgeIndex:h,closestPolygonID:l}}static isPointListInPolygon(t,e,i=ELineTypes.Line){return t.every(s=>this.isInPolygon(s,e,i))}static isPointListOutSidePolygon(t,e,i=ELineTypes.Line){return t.some(s=>!this.isInPolygon(s,e,i))}static getPolygonArea(t){let e=0;for(let i=0,s=t.length;i<s;i++){const n=t[i].x,o=t[i===t.length-1?0:i+1].y,a=t[i===t.length-1?0:i+1].x,l=t[i].y;e+=n*o*.5,e-=a*l*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,i){let s=1;return t===ERotateDirection.Anticlockwise&&(s=-1),s*=e,MathUtils.rotateRectPointList(s,i)}}var __defProp$3=Object.defineProperty,__defProps$3=Object.defineProperties,__getOwnPropDescs$3=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$3=Object.getOwnPropertySymbols,__hasOwnProp$3=Object.prototype.hasOwnProperty,__propIsEnum$3=Object.prototype.propertyIsEnumerable,__defNormalProp$3=(r,t,e)=>t in r?__defProp$3(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$3=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$3.call(t,e)&&__defNormalProp$3(r,e,t[e]);if(__getOwnPropSymbols$3)for(var e of __getOwnPropSymbols$3(t))__propIsEnum$3.call(t,e)&&__defNormalProp$3(r,e,t[e]);return r},__spreadProps$3=(r,t)=>__defProps$3(r,__getOwnPropDescs$3(t));class AxisUtils{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:a}=t;switch(e%360){case 90:return{x:n-a,y:o};case 180:return{x:s-o,y:n-a};case 270:return{x:a,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return __spreadProps$3(__spreadValues$3({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return __spreadProps$3(__spreadValues$3({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let a=s-e;a<s+e;a+=e/3)n.push({x:o,y:a});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class CoordinateUtils{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===EToolName.Polygon}get isDependRect(){return this.dependToolName===EToolName.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:MathUtils.withinRange(t.x,[i,i+n]),y:MathUtils.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===ELineTypes.Curve?PolygonUtils.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return LineToolUtils.calcOptimalIntersection(i,o,s,POINT_RADIUS$1,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const a=this.getPolygonPointList(o,n);if(PolygonUtils.isInPolygon(t,a))return t;const h=a.concat(a[0]).map(g=>this.getRenderCoord(g)),c=this.getIntersection(t,e,h);return c?this.getAbsCoord(c==null?void 0:c.point):t}coordInsideImage(t){return this.coordInsideRect(t,__spreadProps$3(__spreadValues$3({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return MathUtils.isInRange(t.x,o)&&MathUtils.isInRange(t.y,a)}return MathUtils.isInRange(t.x,[0,this.basicImgInfo.width])&&MathUtils.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return PolygonUtils.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}var __defProp$2=Object.defineProperty,__defProps$2=Object.defineProperties,__getOwnPropDescs$2=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$2=Object.getOwnPropertySymbols,__hasOwnProp$2=Object.prototype.hasOwnProperty,__propIsEnum$2=Object.prototype.propertyIsEnumerable,__defNormalProp$2=(r,t,e)=>t in r?__defProp$2(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$2=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$2.call(t,e)&&__defNormalProp$2(r,e,t[e]);if(__getOwnPropSymbols$2)for(var e of __getOwnPropSymbols$2(t))__propIsEnum$2.call(t,e)&&__defNormalProp$2(r,e,t[e]);return r},__spreadProps$2=(r,t)=>__defProps$2(r,__getOwnPropDescs$2(t));const scope=6;class RectOperation extends BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),s=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,s,this.zoom))return a.id}const o=n.filter(a=>RectUtils.isInRect(i,a,s,this.zoom));if(o.length===0)return"";if(o.length===1)return o[0].id;if(o.length>1)return o.map(l=>({size:l.width*l.height,id:l.id})).sort((l,h)=>l.size-h.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const s=this.selectedRectID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;AttributeUtils.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps$2(__spreadValues$2({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,s=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let o=0;o<s.length;o++){const a=s[o],{length:l}=MathUtils.getFootOfPerpendicular(n,a.begin,a.end);l<scope+10&&(e=o)}return e}getTextIconSvg(t=""){return AttributeUtils.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),s=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!(!s||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const n=EDragTarget$1.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=EDragTarget$1.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=EDragStatus.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const n=EDragTarget$1.Plane;this.dragInfo={dragStartCoord:e,dragTarget:n,firstRect:s,startTime:+new Date},this.dragStatus=EDragStatus.Start}}}onDragMove(t){var e,i,s,n,o,a;if(!this.dragInfo)return;this.dragStatus=EDragStatus.Move;const l=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:c,width:g,height:u}=l,d={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};let f=this.rectList.filter(v=>v.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f=__spreadProps$2(__spreadValues$2({},f),{x:h+d.x,y:c+d.y,width:g,height:u});break;case EDragTarget$1.Point:{let v=h,p=c,b=g,x=u;switch(this.hoverRectPointIndex){case 0:{v=g-d.x<0?h+g:h+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(d.x-g),x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(g+d.x),x=Math.abs(u-d.y);break}case 2:{v=g+d.x>0?h:h+g+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(g+d.x),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(d.x-g),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}default:return}f=__spreadProps$2(__spreadValues$2({},f),{x:v,y:p,width:b,height:x})}break;case EDragTarget$1.Line:{let v=h,p=c,b=g,x=u;switch(this.hoverRectEdgeIndex){case 0:{p=u-d.y<0?c+u:c+d.y,x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,b=Math.abs(g+d.x);break}case 2:{p=u+d.y>0?c:c+u+d.y,x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,b=Math.abs(d.x-g);break}default:return}f=__spreadProps$2(__spreadValues$2({},f),{x:v,y:p,width:b,height:x});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(f,getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const v=this.basicResult.x*this.zoom,p=this.basicResult.y*this.zoom,b=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==EDragTarget$1.Plane&&(f.x<v-.01||f.y<p-.01||f.width>v+b-f.x+.01||f.height>p+x-f.y+.01))return;if(f.x<v&&(f.x=v),f.y<p&&(f.y=p),f.width>v+b-f.x)switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f.x=v+b-g;break;case EDragTarget$1.Point:case EDragTarget$1.Line:d.x>0&&d.y>0&&(f.width=v+b-f.x);break;default:return}if(f.height>p+x-f.y)switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f.y=p+x-u;break}}else if(f.x<0&&(f.x=0),f.y<0&&(f.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f.x+f.width>((s=this.imgInfo)==null?void 0:s.width)&&(f.x=this.imgInfo.width-g),f.y+f.height>((n=this.imgInfo)==null?void 0:n.height)&&(f.y=this.imgInfo.height-u);break;default:if(f.x+f.width>((o=this.imgInfo)==null?void 0:o.width)+.01||f.y+f.height>((a=this.imgInfo)==null?void 0:a.height)+.01)return}}this.setRectList(this.rectList.map(v=>v.id===f.id?RectUtils.getRectUnderZoom(f,1/this.zoom):v)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),n=AxisUtils.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedRectID&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const l=this.getHoverRectPointIndex(t);if(l!==this.hoverRectPointIndex){this.hoverRectPointIndex=l,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const o=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=o,o!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:l,y:h}=this.firstClickCoord,{width:c,height:g}=this.drawingRect;if(c=Math.abs(l-n.x),g=Math.abs(h-n.y),n.x<l&&(l=n.x),n.y<h&&(h=n.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps$2(__spreadValues$2({},this.drawingRect),{x:l,y:h,width:c,height:g}),getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;n.x<0&&(c=Math.abs(this.firstClickCoord.x),l=0),n.y<0&&(g=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(l+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-l)),h+g>this.imgInfo.height&&(g=Math.abs(this.imgInfo.height-h)))}this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{x:l,y:h,width:c,height:g}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps$2(__spreadValues$2({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(s.x<0&&(s.x=0),s.y<0&&(s.y=0)),this.drawingRect=__spreadProps$2(__spreadValues$2({},s),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=AttributeUtils.getTextAttribute(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(n=>CommonToolUtils.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=__spreadValues$2({},s),this.firstCurrentPos=__spreadValues$2({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:s}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,s/=this.zoom,[...this.rectList,__spreadProps$2(__spreadValues$2({},this.drawingRect),{x:t,y:e,width:i,height:s})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(n=>n.id===e),{selectedRectID:s}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(s!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const n=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case EKeyCode$1.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case EKeyCode$1.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case EKeyCode$1.Z:this.setIsHidden(!this.isHidden),this.render();break;case EKeyCode$1.Delete:this.deleteRect(this.selectedRectID);break;case EKeyCode$1.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=ESortDirection.ascend;t.shiftKey&&(i=ESortDirection.descend);const[s,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let o=[...s];n&&(o=[...o,n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);o=o.filter(h=>CanvasUtils.inViewPort({x:h.x,y:h.y},a));const l=CommonToolUtils.getNextSelectedRectID(o,i,this.selectedRectID);l&&(this.setSelectedRectID(l.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(l.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case EKeyCode$1.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,s;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),s=AxisUtils.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&s&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.changePointByZoom(s,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.getColor(t.attribute);let i,s;return t.valid===!1?(i=e==null?void 0:e.invalid.stroke,s=e==null?void 0:e.invalid.fill):(i=e==null?void 0:e.valid.stroke,s=e==null?void 0:e.valid.fill),{strokeColor:i,fillColor:s,textColor:i,toolColor:e}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:s,width:n,height:o,attribute:a,valid:l}=e,h=n*this.zoom*.6,c=AxisUtils.getOffsetCoordinate({x:i,y:s+o},this.currentPos,this.zoom),g=this.getColor(a),u=l?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new TextAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(a),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+d,color:u,width:h})}renderSelectedRect(t){const{selectedRect:e}=this;if(!this.ctx||!t||!e)return;const{ctx:i}=this;let s=10;const n=RectUtils.getRectPointList(e),o=n.length,a=this.getColor(t.attribute);n.forEach((l,h)=>{var c,g;if(i.save(),i.moveTo(l.x,l.y),i.beginPath(),this.hoverRectPointIndex===h?s=scope+6:s=scope,t.valid===!1?(i.strokeStyle=a==null?void 0:a.invalid.stroke,i.fillStyle=a==null?void 0:a.invalid.stroke):(i.strokeStyle=a==null?void 0:a.valid.stroke,i.fillStyle=a==null?void 0:a.valid.stroke),i.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),i.fill(),this.hoverRectEdgeIndex===h){i.beginPath(),i.lineWidth=10;const u=this.getColor(t.attribute),d=t.valid===!1?(c=u==null?void 0:u.invalid)==null?void 0:c.stroke:(g=u==null?void 0:u.valid)==null?void 0:g.stroke;i.strokeStyle=d,i.moveTo(n[h].x*this.zoom+this.currentPos.x,n[h].y*this.zoom+this.currentPos.y),i.lineTo(n[(h+1)%o].x*this.zoom+this.currentPos.x,n[(h+1)%o].y*this.zoom+this.currentPos.y),i.stroke()}i.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var s,n,o,a;if(this.ctx&&t){const{ctx:l,style:h}=this,{hiddenText:c=!1}=h;l.save();const{strokeColor:g,fillColor:u,textColor:d}=this.getRenderStyle(t);l.font="lighter 14px Arial";let f="";((s=this.config)==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`);const v=AxisUtils.changeRectByZoom(t,i?e:this.zoom,this.currentPos);c||DrawUtils.drawText(this.canvas,{x:v.x,y:v.y-6},f,__spreadProps$2(__spreadValues$2({color:g,font:"normal normal 900 14px SourceHanSansCN-Regular"},DEFAULT_TEXT_SHADOW),{textMaxWidth:300}));const p=(a=(o=this.style)==null?void 0:o.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID)&&DrawUtils.drawRectWithFill(this.canvas,v,{color:u}),DrawUtils.drawRect(this.canvas,v,{color:g,thickness:p,hiddenText:!0}),l.restore();let b=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(b=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const x=b.length*7;if(c||DrawUtils.drawText(this.canvas,{x:v.x+v.width-x,y:v.y+v.height+15},b,__spreadValues$2({color:d,font:"normal normal 600 14px Arial"},DEFAULT_TEXT_SHADOW)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const y=0,I=Math.max(20,v.width-x);DrawUtils.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+y},t.textAttribute,__spreadValues$2({color:d,font:"italic normal 900 14px Arial",textMaxWidth:I},DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,s]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,AxisUtils.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),s&&(this.renderDrawingRect(s),this.renderSelectedRect(s),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.changeRectByZoom(s,this.zoom,this.currentPos),this.getRenderStyle(s)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(s=>s.id===this.selectedID?__spreadProps$2(__spreadValues$2({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait,this.setSelectedRectID(void 0)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(s=>s.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(s=>s.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}var __defProp$1=Object.defineProperty,__defProps$1=Object.defineProperties,__getOwnPropDescs$1=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$1=Object.getOwnPropertySymbols,__hasOwnProp$1=Object.prototype.hasOwnProperty,__propIsEnum$1=Object.prototype.propertyIsEnumerable,__defNormalProp$1=(r,t,e)=>t in r?__defProp$1(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$1=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$1.call(t,e)&&__defNormalProp$1(r,e,t[e]);if(__getOwnPropSymbols$1)for(var e of __getOwnPropSymbols$1(t))__propIsEnum$1.call(t,e)&&__defNormalProp$1(r,e,t[e]);return r},__spreadProps$1=(r,t)=>__defProps$1(r,__getOwnPropDescs$1(t));const config={textConfigurable:!1,attributeConfigurable:!0,attributeList:[]};class MeasureOperation extends RectOperation{constructor(t){super(__spreadProps$1(__spreadValues$1({},t),{config:JSON.stringify(config)}))}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||this.setSelectedRectID(this.drawingRect.id)}}class RenderDomClass{constructor(t){this._domMap=new Map,this._container=t.container,this._height=t.height}wheelChange(t){t.stopPropagation()}clearTag(t){const e=this._container,i=window.self.document.getElementById(t);i&&e&&e.contains(i)&&(i.removeEventListener("wheel",this.wheelChange),e==null||e.removeChild(i))}render(t){const e=Array.from(this._domMap.keys()),i=t.map(s=>s.id);t.forEach(s=>{const{text:n,textMaxWidth:o,color:a="white",background:l="rgba(0, 0, 0, 0.6)",style:h}=s;if(this._domMap.has(s.id)){const c=this._domMap.get(s.id);c&&(c.innerHTML=n)}else{const c=DrawUtils.drawTagByDom(this._container,n,s.id);c&&(c.setAttribute("style",`
77
+ `),(o=(n=this.canvas)==null?void 0:n.parentNode)==null||o.appendChild(a)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}var __defProp$7=Object.defineProperty,__defProps$6=Object.defineProperties,__getOwnPropDescs$6=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$7=Object.getOwnPropertySymbols,__hasOwnProp$7=Object.prototype.hasOwnProperty,__propIsEnum$7=Object.prototype.propertyIsEnumerable,__defNormalProp$7=(r,t,e)=>t in r?__defProp$7(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$7=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$7.call(t,e)&&__defNormalProp$7(r,e,t[e]);if(__getOwnPropSymbols$7)for(var e of __getOwnPropSymbols$7(t))__propIsEnum$7.call(t,e)&&__defNormalProp$7(r,e,t[e]);return r},__spreadProps$6=(r,t)=>__defProps$6(r,__getOwnPropDescs$6(t)),EStatus;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends BasicToolOperation{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=___default.default.cloneDeep(this.activeLine);if(!n||n.length===0)return;const o=this.isActiveLineValid();let a;const l=this.selectedID?this.lineList.find(c=>c.id===this.selectedID):void 0;l?a=l.order:a=this.nextOrder();const h=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!o});n.map(c=>Object.assign(c,this.coordUtils.getRenderCoord(c))),this.updateActiveArea(),this.drawLine(n,e,h,!0,!0),this.drawLineNumber(n[0],a,h,"",this.defaultAttribute,o),e&&this.isCreate&&this.arc(e,POINT_RADIUS,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,h)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>LineToolUtils.calcDistance(this.coordUtils.getRenderCoord(o),e)<=POINT_ACTIVE_RADIUS);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(e,i,s,n=!0,o=!1,a)=>{const l=createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),o&&LineToolUtils.setReferenceCtx(e),i.forEach(({specialEdge:h},c)=>{const g=l.splice(0,SEGMENT_NUMBER+1);e.save(),e.beginPath(),a===c&&(e.lineWidth=4),g.forEach(({x:u,y:d},f)=>{const v=f>0?"lineTo":"moveTo";h&&LineToolUtils.setSpecialEdgeStyle(e),e[v](u,d)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,o=!1)=>{const a=i?e.concat(i):e,l={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.drawCurveLine(this.ctx,a,l,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(a,l,o),n&&e.forEach(h=>{var c,g;const u=h.id,d=u&&[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(h,d,s),[this.hoverPointID,(g=this.selectedPoint)==null?void 0:g.id].includes(u)||this.arc(h,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.setReferenceCtx(n),e.forEach((o,a)=>{if(n.beginPath(),a>0){const l=e[a-1];n.save(),(l==null?void 0:l.specialEdge)&&LineToolUtils.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===a&&(n.lineWidth=4),n.moveTo(l.x,l.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l)));const{order:s,label:n}=i,o=s,a=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,a,!1),this.drawLineNumber(i.pointList[0],o,a,n,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],a,i==null?void 0:i.textAttribute)}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+e,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:o,left:a,right:l,bottom:h}=this.activeArea,c=[a,l].map(p=>___default.default.isNumber(p)?p+e:0),g=[o,h].map(p=>___default.default.isNumber(p)?p+i:0),u=a>=0&&l&&MathUtils.isInRange(c,s),d=o>=0&&h&&MathUtils.isInRange(g,n),f=u?e:0,v=d?i:0;this.lineDragging=!0,this.moveActiveArea(f,v)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===EKeyCode$1.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===EKeyCode$1.Delete){this.deleteLine();return}if(e.keyCode===EKeyCode$1.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===EKeyCode$1.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.dependToolConfig={lineType:ELineTypes.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===EToolName.Polygon}get isDependRect(){return this.dependToolName===EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(t=>this.attributeLockList.includes((t==null?void 0:t.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget}get showOrder(){return this.config.showOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>CanvasUtils.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===ELineTypes.Curve?createSmoothCurvePoints(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(t[n-1]),a=this.coordUtils.getRenderCoord(s);return LineToolUtils.isInLine(e,o,a,i)})}arc(t,e=POINT_RADIUS,i){var s,n,o,a,l,h;if(this.ctx){const{x:c,y:g}=t;(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(c,g,e,0,360),(a=this.ctx)==null||a.closePath(),(l=this.ctx)==null||l.fill(),(h=this.ctx)==null||h.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:o}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,o,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(__spreadProps$6(__spreadValues$7({},t),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return StyleUtils.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?MathUtils.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,o=!0){var a,l,h;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let c=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const g=n?(h=(l=(a=this.attributeList)==null?void 0:a.find(u=>u.value===n))==null?void 0:l.key)!=null?h:n:"";c=[c,`${!o&&g?"\u65E0\u6548":""}${g}`].filter(u=>u).join("_")}this.drawText(t,c,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawText(t,e,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?DrawUtils.wrapText(this.canvas,e,t.x-LINE_ORDER_OFFSET.x,t.y-LINE_ORDER_OFFSET.y,s):this.ctx.fillText(e,t.x-LINE_ORDER_OFFSET.x,t.y-LINE_ORDER_OFFSET.y),(o=this.ctx)==null||o.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines())}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return LineToolUtils.calcDistance(i,t)<=POINT_ACTIVE_RADIUS})}findHoverLine(t){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,a)=>{if(a===0)return!1;const l=this.coordUtils.getRenderCoord(o),h=this.coordUtils.getRenderCoord(s[a-1]);return LineToolUtils.isInLine(t,l,h,n)})})}getAdsorptionPoint(t){let e,i,s;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const a=this.findNearestPoint(n,t);if(a){if(a.minDistance===0){e=a.point;return}(i===void 0||a.minDistance<i)&&(e=a.point,i=a.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let o=1;o<=t.length-1;o++){const a=this.coordUtils.getRenderCoord(t[o]),l=this.coordUtils.getRenderCoord(t[o-1]),{length:h,footPoint:c}=MathUtils.getFootOfPerpendicular(e,a,l),g=LineToolUtils.calcTwoPointDistance(a,e),u=LineToolUtils.calcTwoPointDistance(l,e);if(g<=i*2){s=a,i=0;break}if(u<=i*2){s=l,i=0;break}h<i&&(s=c,i=h)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?createSmoothCurvePointsFromPointList(t,SEGMENT_NUMBER):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:a,width:l,height:h}=this.basicResult;s=[o,o+l],n=[a,a+h]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return LineToolUtils.getVHPoint(o,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(a=>a.id===(i==null?void 0:i.id)),n=MathUtils.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom),o=this.lineList[s];this.updateStatus(1),this.setActiveLine(o.pointList),this.setSelectedLineID(o.id),this.activeArea=n,this.updateLineAttributes(o)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=MathUtils.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?___default.default.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return MathUtils.isInRange(t.x,o)&&MathUtils.isInRange(t.y,a)}return MathUtils.isInRange(t.x,[0,this.imageSize.width])&&MathUtils.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,a=this.isCurve?i.slice((n-1)*(SEGMENT_NUMBER+1),n*(SEGMENT_NUMBER+1)):[o,s];return this.pointInLine(a,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,__spreadProps$6(__spreadValues$7({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?LineToolUtils.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=___default.default.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return AttributeUtils.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=uuid(),e={pointList:___default.default.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let a;if(t){if(this.selectedID){const l=this.lineList.find(h=>h.id===this.selectedID);a=this.selectedID,l&&(l.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(l.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const l=this.createLineData();a=l.id,this.setLineList([...this.lineList,l]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?this.setActiveStatus(a):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===EKeyCode$1.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!==EKeyCode$1.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===EKeyCode$1.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===EKeyCode$1.Shift&&this.render(),t.keyCode===EKeyCode$1.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=AttributeUtils.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,a;return __spreadProps$6(__spreadValues$7({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(a=(o=i.pointList[0])==null?void 0:o.y)!=null?a:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===EKeyCode$1.Ctrl&&this.setInvalidLineOnCreating(t),[EKeyCode$1.Shift,EKeyCode$1.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=MathUtils.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(o=>o.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(o=>o.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=(e=(t=this.lineList.find(l=>l.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:o,textAttribute:a}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:a,y:l}=this.activeLine[1],h=this.coordUtils.getRenderCoord({x:a,y:l}),c=this.getColor(o),g=n?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=(i=(e=this.lineList.find(d=>d.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new TextAttributeClass({container:this.container,icon:this.getTextIconSvg(o),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:h.x,top:h.y,color:g}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(t=""){return AttributeUtils.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!AttributeUtils.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",AttributeUtils.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}class MarkerUtils{static getMarkerShowText(t,e=[]){return AttributeUtils.getAttributeShowText(t,e)}}var __defProp$6=Object.defineProperty,__defProps$5=Object.defineProperties,__getOwnPropDescs$5=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$6=Object.getOwnPropertySymbols,__hasOwnProp$6=Object.prototype.hasOwnProperty,__propIsEnum$6=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp$6=(r,t,e)=>t in r?__defProp$6(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$6=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$6.call(t,e)&&__defNormalProp$6(r,e,t[e]);if(__getOwnPropSymbols$6)for(var e of __getOwnPropSymbols$6(t))__propIsEnum$6.call(t,e)&&__defNormalProp$6(r,e,t[e]);return r},__spreadProps$5=(r,t)=>__defProps$5(r,__getOwnPropDescs$5(t));const TEXTAREA_WIDTH=200;class PointOperation extends BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=AxisUtils.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const n=AxisUtils.changePointByZoom(s,this.zoom);return MathUtils.getLineLength(n,i)<.2})},this.config=CommonToolUtils.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)}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=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),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=CommonToolUtils.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 AttributeUtils.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=EDragStatus.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===EDragStatus.Start||this.dragStatus===EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===EDragStatus.Move&&this.history.pushHistory(this.pointList),this.dragStatus=EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=EDragStatus.Move;const s=this.getCoordinateUnderZoom(t),n=AxisUtils.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),o=this.drawOutsideTarget?AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.changePointByZoom(n,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(o,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=o.x,a.y=o.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case EKeyCode$1.Delete:this.deletePoint();break;case EKeyCode$1.Tab:{this.onTabKeyDown(t);break}case EKeyCode$1.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,n;if(!this.imgInfo)return;const{upperLimit:o}=this.config;if(o&&this.currentPageResult.length>=o){this.emit("messageInfo",`${Locale.getMessagesByLocale(EMessage.LowerLimitPoint,this.lang)}`);return}const a=CommonToolUtils.getSourceID(this.basicResult),l=this.getCoordinateUnderZoom(t);let h=AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[EToolName.Polygon,EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const d=((i=this.referenceData)==null?void 0:i.toolName)===EToolName.Polygon,{dropFoot:f}=PolygonUtils.getClosestPoint(h,this.referenceData.result,(n=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?n:ELineTypes.Line,edgeAdsorptionScope/this.zoom,{isClose:d});f&&(h=f,this.emit("messageSuccess",`${Locale.getMessagesByLocale(EMessage.SuccessfulEdgeAdsorption,this.lang)}`))}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let u=!1;switch(this.dependToolName){case EToolName.Rect:{u=!RectUtils.isInRect(h,this.basicResult);break}case EToolName.Polygon:{u=!PolygonUtils.isInPolygon(h,this.basicResult.pointList);break}}if(u)return}if(l.x<0||l.y<0||l.x>this.imgInfo.width||l.y>this.imgInfo.height)return}if(this.isMinDistance(h))return;let c=__spreadProps$5(__spreadValues$6({},h),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:a,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(u=>CommonToolUtils.isSameSourceID(u.sourceID,a)))+1});if(this.config.textConfigurable){let u="";u=AttributeUtils.getTextAttribute(this.pointList.filter(d=>CommonToolUtils.isSameSourceID(d.sourceID,a)),this.config.textCheckType),c=__spreadProps$5(__spreadValues$6({},c),{textAttribute:u})}if(this.hasMarkerConfig){const u=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(u)c=__spreadProps$5(__spreadValues$6({},c),{label:u.label}),this.markerIndex=u.index,this.emit("markIndexChange");else{this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.MarkerFinish,this.lang));return}}this.hoverID=c.id;const g=[...this.pointList,c];this.setPointList(g),this.history.pushHistory(g),this.setSelectedID(c.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.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}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===EDragStatus.Move||this.dragStatus===EDragStatus.Start)return;let e=ESortDirection.ascend;t.shiftKey&&(e=ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=CommonToolUtils.getNextSelectedRectID(n,e,this.selectedID);o&&this.setSelectedID(o.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.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.render())}undoAndRedo(t){var e,i;if(this.dragStatus===EDragStatus.Move||this.dragStatus===EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(n=>n.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(n=>n.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=EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.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(d=>d.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:n,attribute:o,valid:a}=i,l=TEXTAREA_WIDTH*this.zoom*.6,h=AxisUtils.getOffsetCoordinate({x:s,y:n},this.currentPos,this.zoom),c=this.getColor(o),g=a?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributInstance||(this._textAttributInstance=new TextAttributeClass({width:l,container:this.container,icon:this.getTextIconSvg(o),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:h.x,top:h.y+u,color:g,width:l})}renderPoint(t){var e,i,s;const{textAttribute:n="",attribute:o}=t,a=t.id===this.selectedID,l=this.getColor(o),h=AxisUtils.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:g=!1}=this.style,u=StyleUtils.getStrokeAndFill(l,t.valid,{isSelected:a||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,h,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:u.stroke,fill:u.fill});let d="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(d=`${t.order}`),t.label&&this.hasMarkerConfig&&(d=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(d=`${d} ${AttributeUtils.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),g||DrawUtils.drawText(this.canvas,{x:h.x+c/2,y:h.y-c-4},d,{textAlign:"center",color:u.stroke}),a?this.renderTextAttribute():g||DrawUtils.drawText(this.canvas,{x:h.x+c,y:h.y+c+24},n,__spreadValues$6({color:u.stroke},DEFAULT_TEXT_OFFSET))}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let n=AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const o=((t=this.referenceData)==null?void 0:t.toolName)===EToolName.Polygon,{dropFoot:a}=PolygonUtils.getClosestPoint(n,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:ELineTypes.Line,edgeAdsorptionScope/this.zoom,{isClose:o});a&&n!==a&&n!==a&&(n=a,DrawUtils.drawCircle(this.canvas,AxisUtils.changePointByZoom(n,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.changePointByZoom(n,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}class TextToolOperation extends BasicToolOperation{constructor(t){super(t);this.getSingleResult=e=>{const i={};return this.config.configList.length>0&&this.config.configList.forEach(s=>{var n;i[s.key]=(n=s.default)!=null?n:""}),{value:i,id:uuid(),sourceID:e!=null?e:CommonToolUtils.getSourceID()}},this.getInitResultList=(e,i)=>e>0?i.map(s=>this.getSingleResult(s.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var e;this.textList=t,this.toggleTextContainerVisible(!0);const i=(e=this.textList[0])==null?void 0:e.value;i&&Object.keys(i).forEach(s=>{this.renderText(s,i[s])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!i)}updateTextValue(t,e){this.textList[0].value[t]=e,this.renderText(t,e),this.emit("valueUpdated")}renderText(t,e){const i=document.getElementById(`textKey${t}`);i&&(i.innerText=e)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),e={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(e).reduce((i,s)=>(i+=`${s}: ${e[s]};`,i),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(i=>{const s=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");s.setAttribute("style","padding: 8px 16px"),n.innerText=`${i.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(i.key)),s.appendChild(n),s.appendChild(o),t.appendChild(s)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===EKeyCode$1.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const e=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=e}}}var __defProp$5=Object.defineProperty,__defProps$4=Object.defineProperties,__getOwnPropDescs$4=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$5=Object.getOwnPropertySymbols,__hasOwnProp$5=Object.prototype.hasOwnProperty,__propIsEnum$5=Object.prototype.propertyIsEnumerable,__defNormalProp$5=(r,t,e)=>t in r?__defProp$5(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$5=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$5.call(t,e)&&__defNormalProp$5(r,e,t[e]);if(__getOwnPropSymbols$5)for(var e of __getOwnPropSymbols$5(t))__propIsEnum$5.call(t,e)&&__defNormalProp$5(r,e,t[e]);return r},__spreadProps$4=(r,t)=>__defProps$4(r,__getOwnPropDescs$4(t));class CommonToolUtils{static getStepInfo(t,e){return e==null?void 0:e.filter(i=>i.step===t)[0]}static getCurrentStepInfo(t,e){const i=this.getStepInfo(t,e);return i&&(i.type===EStepType.QUALITY_INSPECTION||i.type===EStepType.MANUAL_CORRECTION)?this.getCurrentStepInfo(i.dataSourceStep,e):i}static getMaxOrder(t){let e=0;return t.forEach(i=>{i.order&&i.order>e&&(e=i.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:i,type:s}=e;if(!i||!s)return!0;let n=!0;return(e.isContentEditable||i==="TEXTAREA"||(i==="INPUT"&&s!=="radio"||i==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getCurrentOperation(t){switch(t){case EToolName.Rect:case EToolName.RectTrack:return RectOperation;case EToolName.Tag:return TagOperation;case EToolName.Polygon:return PolygonOperation;case ECheckModel.Check:return CheckOperation;case EToolName.Line:return LineToolOperation;case EToolName.Point:return PointOperation;case EToolName.Text:return TextToolOperation;default:throw new Error("not match tool")}}static getNextSelectedRectID(t,e=ESortDirection.ascend,i){let s=1;e===ESortDirection.descend&&(s=-1);const n=t.sort((l,h)=>l.x-h.x==0?l.y-h.y:s*(l.x-h.x)),o=n.findIndex(l=>l.id===i),a=n.length;return n[(o+1)%a]}static getNextSelectedRectIDByEvent(t,e,i){const s=e.shiftKey?ESortDirection.descend:ESortDirection.ascend;return this.getNextSelectedRectID(t,s,i)}static getRenderResultList(t,e,i=[],s){let n;return[t.filter(a=>s&&s===(a==null?void 0:a.id)?(n=a,!1):!(i.length>0&&!i.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),n]}static getSourceID(t){var e;const i="";return t&&(e=t==null?void 0:t.id)!=null?e:i}static findAllLine(t,e=!0){const i=[],s=[...t];s.length>=3&&e===!0&&s.push(__spreadValues$5({},s[0]));for(let n=0;n<s.length;n++)s[n+1]&&i.push({point1:s[n],point2:s[n+1],pointIndex:n});return i}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],i){if((e==null?void 0:e.length)===0)return;let s=e.map((n,o)=>__spreadProps$4(__spreadValues$5({},n),{index:o}));if(typeof i=="number"&&i>0){const n=e[i];if(n&&t.every(o=>o.label!==n.value))return{label:n.value,index:i};s=[...s.slice(i,e.length),...s.slice(0,i)]}for(let n=0;n<s.length;n++)if(!t.some(o=>o.label===s[n].value))return{label:s[n].value,index:s[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(i=>t===i.value)}}CommonToolUtils.jsonParser=(r,t={})=>{try{return typeof r=="string"?JSON.parse(r):_.isObject(r)?r:t}catch(e){return t}};var __defProp$4=Object.defineProperty,__getOwnPropSymbols$4=Object.getOwnPropertySymbols,__hasOwnProp$4=Object.prototype.hasOwnProperty,__propIsEnum$4=Object.prototype.propertyIsEnumerable,__defNormalProp$4=(r,t,e)=>t in r?__defProp$4(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$4=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$4.call(t,e)&&__defNormalProp$4(r,e,t[e]);if(__getOwnPropSymbols$4)for(var e of __getOwnPropSymbols$4(t))__propIsEnum$4.call(t,e)&&__defNormalProp$4(r,e,t[e]);return r};class PolygonUtils{static getHoverPolygonID(t,e,i=3,s=ELineTypes.Line){let n="",o=Infinity;const a=AxisUtils.axisArea(t,i);return e.forEach(l=>{l.pointList&&a.forEach(h=>{const c=this.calcPolygonSize(l.pointList);this.isInPolygon(h,l.pointList,s)&&c<o&&(n=l.id,o=c)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,i=t.reduce((s,n,o,a)=>{const l=a[(o+1)%e];return s+n.x*l.y-l.x*n.y},0);return Math.abs(i)/2}static isInPolygon(t,e,i=ELineTypes.Line){let s=0,n,o,a,l;e=[...e],i===ELineTypes.Curve&&(e=this.createSmoothCurvePoints(e.reduce((c,g)=>[...c,g.x,g.y],[]),.5,!0,20)),[a]=e;const h=e.length;for(n=1;n<=h;n++)l=e[n%h],t.x>Math.min(a.x,l.x)&&t.x<=Math.max(a.x,l.x)&&t.y<=Math.max(a.y,l.y)&&a.x!==l.x&&(o=(t.x-a.x)*(l.y-a.y)/(l.x-a.x)+a.y,(a.y===l.y||t.y<=o)&&s++),a=l;return s%2!=0}static createSmoothCurvePointsFromPointList(t,e=SEGMENT_NUMBER$2){return this.createSmoothCurvePoints(t.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!1,e).map((s,n)=>{var o;const a=n/(SEGMENT_NUMBER$2+1),l=Math.floor(a),h=(o=t[l])!=null?o:{};return __spreadValues$4(l===a?__spreadValues$4({},h):{specialEdge:h.specialEdge},s)})}static createSmoothCurvePoints(t,e=.5,i=!1,s=SEGMENT_NUMBER$2){if(t.length<4)return t;const n=[],o=t.slice(0);let a,l,h,c,g,u,d,f,v,p,b,x,y;for(i?(o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.push(t[0]),o.push(t[1])):(o.unshift(t[1]),o.unshift(t[0]),o.push(t[t.length-2]),o.push(t[t.length-1])),y=2;y<o.length-4;y+=2)for(h=(o[y+2]-o[y-2])*e,c=(o[y+4]-o[y-0])*e,g=(o[y+3]-o[y-1])*e,u=(o[y+5]-o[y+1])*e,x=0;x<=s;x++)b=x/s,d=2*Math.pow(b,3)-3*Math.pow(b,2)+1,f=-(2*Math.pow(b,3))+3*Math.pow(b,2),v=Math.pow(b,3)-2*Math.pow(b,2)+b,p=Math.pow(b,3)-Math.pow(b,2),a=d*o[y]+f*o[y+2]+v*h+p*c,l=d*o[y+1]+f*o[y+3]+v*g+p*u,n.push(a),n.push(l);const I=[];for(let m=0;m<n.length-1;m+=2)I.push({x:n[m],y:n[m+1]});if(i)for(let m=0;m<s+1;m++){const w=I.shift();I.push(w)}return I}static getPolygonByID(t,e){return t.find(i=>i.id===e)}static getHoverEdgeIndex(t,e,i=ELineTypes.Line,s=3){let n=[...e];i===ELineTypes.Curve?n=this.createSmoothCurvePoints(e.reduce((l,h)=>[...l,h.x,h.y],[]),.5,!0,SEGMENT_NUMBER$2):i===ELineTypes.Line&&n.push(n[0]);let o=-1,a=s;for(let l=0;l<n.length-1;l++){const{length:h}=MathUtils.getFootOfPerpendicular(t,n[l],n[l+1]);h<a&&(o=l,a=h)}return o===-1?-1:i===ELineTypes.Curve?Math.floor(o/SEGMENT_NUMBER$2):o}static getClosestPoint(t,e,i=ELineTypes.Line,s=3,n){var o;const a=(o=n==null?void 0:n.isClose)!=null?o:!0;let l="",h=-1,c=Infinity,g=t;const u=20;let d=!1;return e.forEach(f=>{if(!d&&!!f.pointList)switch(i){case ELineTypes.Line:CommonToolUtils.findAllLine(f.pointList,a).forEach((p,b)=>{if(d)return;let{length:x,footPoint:y}=MathUtils.getFootOfPerpendicular(t,p.point1,p.point2);const I=MathUtils.getLineLength(p.point1,t),m=MathUtils.getLineLength(p.point2,t);I<s*2&&(y=p.point1,x=I,d=!0),m<s*2&&(y=p.point2,x=m,d=!0),x<c&&x<s&&(l=f.id,h=b,c=x,g=y)});break;case ELineTypes.Curve:{const v=this.createSmoothCurvePoints(f.pointList.reduce((p,b)=>[...p,b.x,b.y],[]),.5,a,u);for(let p=0;p<v.length-1;p++){const{length:b,footPoint:x}=MathUtils.getFootOfPerpendicular(t,v[p],v[p+1]);b<c&&b<s&&(l=f.id,h=Math.floor(p/(u+1)),c=b,g=x)}}break}}),{dropFoot:g,closestEdgeIndex:h,closestPolygonID:l}}static isPointListInPolygon(t,e,i=ELineTypes.Line){return t.every(s=>this.isInPolygon(s,e,i))}static isPointListOutSidePolygon(t,e,i=ELineTypes.Line){return t.some(s=>!this.isInPolygon(s,e,i))}static getPolygonArea(t){let e=0;for(let i=0,s=t.length;i<s;i++){const n=t[i].x,o=t[i===t.length-1?0:i+1].y,a=t[i===t.length-1?0:i+1].x,l=t[i].y;e+=n*o*.5,e-=a*l*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,i){let s=1;return t===ERotateDirection.Anticlockwise&&(s=-1),s*=e,MathUtils.rotateRectPointList(s,i)}}var __defProp$3=Object.defineProperty,__defProps$3=Object.defineProperties,__getOwnPropDescs$3=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$3=Object.getOwnPropertySymbols,__hasOwnProp$3=Object.prototype.hasOwnProperty,__propIsEnum$3=Object.prototype.propertyIsEnumerable,__defNormalProp$3=(r,t,e)=>t in r?__defProp$3(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$3=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$3.call(t,e)&&__defNormalProp$3(r,e,t[e]);if(__getOwnPropSymbols$3)for(var e of __getOwnPropSymbols$3(t))__propIsEnum$3.call(t,e)&&__defNormalProp$3(r,e,t[e]);return r},__spreadProps$3=(r,t)=>__defProps$3(r,__getOwnPropDescs$3(t));class AxisUtils{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:a}=t;switch(e%360){case 90:return{x:n-a,y:o};case 180:return{x:s-o,y:n-a};case 270:return{x:a,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return __spreadProps$3(__spreadValues$3({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return __spreadProps$3(__spreadValues$3({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let a=s-e;a<s+e;a+=e/3)n.push({x:o,y:a});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class CoordinateUtils{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===EToolName.Polygon}get isDependRect(){return this.dependToolName===EToolName.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:MathUtils.withinRange(t.x,[i,i+n]),y:MathUtils.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===ELineTypes.Curve?PolygonUtils.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return LineToolUtils.calcOptimalIntersection(i,o,s,POINT_RADIUS$1,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const a=this.getPolygonPointList(o,n);if(PolygonUtils.isInPolygon(t,a))return t;const h=a.concat(a[0]).map(g=>this.getRenderCoord(g)),c=this.getIntersection(t,e,h);return c?this.getAbsCoord(c==null?void 0:c.point):t}coordInsideImage(t){return this.coordInsideRect(t,__spreadProps$3(__spreadValues$3({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return MathUtils.isInRange(t.x,o)&&MathUtils.isInRange(t.y,a)}return MathUtils.isInRange(t.x,[0,this.basicImgInfo.width])&&MathUtils.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return PolygonUtils.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}var __defProp$2=Object.defineProperty,__defProps$2=Object.defineProperties,__getOwnPropDescs$2=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$2=Object.getOwnPropertySymbols,__hasOwnProp$2=Object.prototype.hasOwnProperty,__propIsEnum$2=Object.prototype.propertyIsEnumerable,__defNormalProp$2=(r,t,e)=>t in r?__defProp$2(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$2=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$2.call(t,e)&&__defNormalProp$2(r,e,t[e]);if(__getOwnPropSymbols$2)for(var e of __getOwnPropSymbols$2(t))__propIsEnum$2.call(t,e)&&__defNormalProp$2(r,e,t[e]);return r},__spreadProps$2=(r,t)=>__defProps$2(r,__getOwnPropDescs$2(t));const scope=6;class RectOperation extends BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),s=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,s,this.zoom))return a.id}const o=n.filter(a=>RectUtils.isInRect(i,a,s,this.zoom));if(o.length===0)return"";if(o.length===1)return o[0].id;if(o.length>1)return o.map(l=>({size:l.width*l.height,id:l.id})).sort((l,h)=>l.size-h.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const s=this.selectedRectID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;AttributeUtils.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps$2(__spreadValues$2({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,s=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let o=0;o<s.length;o++){const a=s[o],{length:l}=MathUtils.getFootOfPerpendicular(n,a.begin,a.end);l<scope+10&&(e=o)}return e}getTextIconSvg(t=""){return AttributeUtils.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),s=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!(!s||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const n=EDragTarget$1.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=EDragTarget$1.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=EDragStatus.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const n=EDragTarget$1.Plane;this.dragInfo={dragStartCoord:e,dragTarget:n,firstRect:s,startTime:+new Date},this.dragStatus=EDragStatus.Start}}}onDragMove(t){var e,i,s,n,o,a;if(!this.dragInfo)return;this.dragStatus=EDragStatus.Move;const l=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:c,width:g,height:u}=l,d={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};let f=this.rectList.filter(v=>v.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f=__spreadProps$2(__spreadValues$2({},f),{x:h+d.x,y:c+d.y,width:g,height:u});break;case EDragTarget$1.Point:{let v=h,p=c,b=g,x=u;switch(this.hoverRectPointIndex){case 0:{v=g-d.x<0?h+g:h+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(d.x-g),x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(g+d.x),x=Math.abs(u-d.y);break}case 2:{v=g+d.x>0?h:h+g+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(g+d.x),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(d.x-g),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}default:return}f=__spreadProps$2(__spreadValues$2({},f),{x:v,y:p,width:b,height:x})}break;case EDragTarget$1.Line:{let v=h,p=c,b=g,x=u;switch(this.hoverRectEdgeIndex){case 0:{p=u-d.y<0?c+u:c+d.y,x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,b=Math.abs(g+d.x);break}case 2:{p=u+d.y>0?c:c+u+d.y,x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,b=Math.abs(d.x-g);break}default:return}f=__spreadProps$2(__spreadValues$2({},f),{x:v,y:p,width:b,height:x});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(f,getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const v=this.basicResult.x*this.zoom,p=this.basicResult.y*this.zoom,b=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==EDragTarget$1.Plane&&(f.x<v-.01||f.y<p-.01||f.width>v+b-f.x+.01||f.height>p+x-f.y+.01))return;if(f.x<v&&(f.x=v),f.y<p&&(f.y=p),f.width>v+b-f.x)switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f.x=v+b-g;break;case EDragTarget$1.Point:case EDragTarget$1.Line:d.x>0&&d.y>0&&(f.width=v+b-f.x);break;default:return}if(f.height>p+x-f.y)switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f.y=p+x-u;break}}else if(f.x<0&&(f.x=0),f.y<0&&(f.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case EDragTarget$1.Plane:f.x+f.width>((s=this.imgInfo)==null?void 0:s.width)&&(f.x=this.imgInfo.width-g),f.y+f.height>((n=this.imgInfo)==null?void 0:n.height)&&(f.y=this.imgInfo.height-u);break;default:if(f.x+f.width>((o=this.imgInfo)==null?void 0:o.width)+.01||f.y+f.height>((a=this.imgInfo)==null?void 0:a.height)+.01)return}}this.setRectList(this.rectList.map(v=>v.id===f.id?RectUtils.getRectUnderZoom(f,1/this.zoom):v)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),n=AxisUtils.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedRectID&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const l=this.getHoverRectPointIndex(t);if(l!==this.hoverRectPointIndex){this.hoverRectPointIndex=l,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const o=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=o,o!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:l,y:h}=this.firstClickCoord,{width:c,height:g}=this.drawingRect;if(c=Math.abs(l-n.x),g=Math.abs(h-n.y),n.x<l&&(l=n.x),n.y<h&&(h=n.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps$2(__spreadValues$2({},this.drawingRect),{x:l,y:h,width:c,height:g}),getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;n.x<0&&(c=Math.abs(this.firstClickCoord.x),l=0),n.y<0&&(g=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(l+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-l)),h+g>this.imgInfo.height&&(g=Math.abs(this.imgInfo.height-h)))}this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{x:l,y:h,width:c,height:g}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps$2(__spreadValues$2({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(s.x<0&&(s.x=0),s.y<0&&(s.y=0)),this.drawingRect=__spreadProps$2(__spreadValues$2({},s),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=AttributeUtils.getTextAttribute(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(n=>CommonToolUtils.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=__spreadValues$2({},s),this.firstCurrentPos=__spreadValues$2({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:s}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,s/=this.zoom,[...this.rectList,__spreadProps$2(__spreadValues$2({},this.drawingRect),{x:t,y:e,width:i,height:s})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(n=>n.id===e),{selectedRectID:s}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(s!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const n=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case EKeyCode$1.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case EKeyCode$1.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case EKeyCode$1.Z:this.setIsHidden(!this.isHidden),this.render();break;case EKeyCode$1.Delete:this.deleteRect(this.selectedRectID);break;case EKeyCode$1.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=ESortDirection.ascend;t.shiftKey&&(i=ESortDirection.descend);const[s,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let o=[...s];n&&(o=[...o,n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);o=o.filter(h=>CanvasUtils.inViewPort({x:h.x,y:h.y},a));const l=CommonToolUtils.getNextSelectedRectID(o,i,this.selectedRectID);l&&(this.setSelectedRectID(l.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(l.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case EKeyCode$1.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,s;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),s=AxisUtils.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&s&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.changePointByZoom(s,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.getColor(t.attribute);let i,s;return t.valid===!1?(i=e==null?void 0:e.invalid.stroke,s=e==null?void 0:e.invalid.fill):(i=e==null?void 0:e.valid.stroke,s=e==null?void 0:e.valid.fill),{strokeColor:i,fillColor:s,textColor:i,toolColor:e}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:s,width:n,height:o,attribute:a,valid:l}=e,h=n*this.zoom*.6,c=AxisUtils.getOffsetCoordinate({x:i,y:s+o},this.currentPos,this.zoom),g=this.getColor(a),u=l?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new TextAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(a),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+d,color:u,width:h})}renderSelectedRect(t){const{selectedRect:e}=this;if(!this.ctx||!t||!e)return;const{ctx:i}=this;let s=10;const n=RectUtils.getRectPointList(e),o=n.length,a=this.getColor(t.attribute);n.forEach((l,h)=>{var c,g;if(i.save(),i.moveTo(l.x,l.y),i.beginPath(),this.hoverRectPointIndex===h?s=scope+6:s=scope,t.valid===!1?(i.strokeStyle=a==null?void 0:a.invalid.stroke,i.fillStyle=a==null?void 0:a.invalid.stroke):(i.strokeStyle=a==null?void 0:a.valid.stroke,i.fillStyle=a==null?void 0:a.valid.stroke),i.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),i.fill(),this.hoverRectEdgeIndex===h){i.beginPath(),i.lineWidth=10;const u=this.getColor(t.attribute),d=t.valid===!1?(c=u==null?void 0:u.invalid)==null?void 0:c.stroke:(g=u==null?void 0:u.valid)==null?void 0:g.stroke;i.strokeStyle=d,i.moveTo(n[h].x*this.zoom+this.currentPos.x,n[h].y*this.zoom+this.currentPos.y),i.lineTo(n[(h+1)%o].x*this.zoom+this.currentPos.x,n[(h+1)%o].y*this.zoom+this.currentPos.y),i.stroke()}i.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var s,n,o,a;if(this.ctx&&t){const{ctx:l,style:h}=this,{hiddenText:c=!1}=h;l.save();const{strokeColor:g,fillColor:u,textColor:d}=this.getRenderStyle(t);l.font="lighter 14px Arial";let f="";((s=this.config)==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`);const v=AxisUtils.changeRectByZoom(t,i?e:this.zoom,this.currentPos);c||DrawUtils.drawText(this.canvas,{x:v.x,y:v.y-6},f,__spreadProps$2(__spreadValues$2({color:g,font:"normal normal 900 14px SourceHanSansCN-Regular"},DEFAULT_TEXT_SHADOW),{textMaxWidth:300}));const p=(a=(o=this.style)==null?void 0:o.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID)&&DrawUtils.drawRectWithFill(this.canvas,v,{color:u}),DrawUtils.drawRect(this.canvas,v,{color:g,thickness:p,hiddenText:!0}),l.restore();let b=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(b=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const x=b.length*7;if(c||DrawUtils.drawText(this.canvas,{x:v.x+v.width-x,y:v.y+v.height+15},b,__spreadValues$2({color:d,font:"normal normal 600 14px Arial"},DEFAULT_TEXT_SHADOW)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const y=0,I=Math.max(20,v.width-x);DrawUtils.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+y},t.textAttribute,__spreadValues$2({color:d,font:"italic normal 900 14px Arial",textMaxWidth:I},DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,s]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,AxisUtils.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),s&&(this.renderDrawingRect(s),this.renderSelectedRect(s),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.changeRectByZoom(s,this.zoom,this.currentPos),this.getRenderStyle(s)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(s=>s.id===this.selectedID?__spreadProps$2(__spreadValues$2({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps$2(__spreadValues$2({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=EDragStatus.Wait,this.setSelectedRectID(void 0)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(s=>s.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",Locale.getMessagesByLocale(EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(s=>s.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}var __defProp$1=Object.defineProperty,__defProps$1=Object.defineProperties,__getOwnPropDescs$1=Object.getOwnPropertyDescriptors,__getOwnPropSymbols$1=Object.getOwnPropertySymbols,__hasOwnProp$1=Object.prototype.hasOwnProperty,__propIsEnum$1=Object.prototype.propertyIsEnumerable,__defNormalProp$1=(r,t,e)=>t in r?__defProp$1(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues$1=(r,t)=>{for(var e in t||(t={}))__hasOwnProp$1.call(t,e)&&__defNormalProp$1(r,e,t[e]);if(__getOwnPropSymbols$1)for(var e of __getOwnPropSymbols$1(t))__propIsEnum$1.call(t,e)&&__defNormalProp$1(r,e,t[e]);return r},__spreadProps$1=(r,t)=>__defProps$1(r,__getOwnPropDescs$1(t));const config={textConfigurable:!1,attributeConfigurable:!0,attributeList:[]};class MeasureOperation extends RectOperation{constructor(t){super(__spreadProps$1(__spreadValues$1({},t),{config:JSON.stringify(config)}))}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||this.setSelectedRectID(this.drawingRect.id)}}class RenderDomClass{constructor(t){this._domMap=new Map,this._container=t.container,this._height=t.height}wheelChange(t){t.stopPropagation()}clearTag(t){const e=this._container,i=window.self.document.getElementById(t);i&&e&&e.contains(i)&&(i.removeEventListener("wheel",this.wheelChange),e==null||e.removeChild(i))}render(t){const e=Array.from(this._domMap.keys()),i=t.map(s=>s.id);t.forEach(s=>{const{text:n,textMaxWidth:o,color:a="white",background:l="rgba(0, 0, 0, 0.6)",style:h}=s;if(this._domMap.has(s.id)){const c=this._domMap.get(s.id);c&&(c.innerHTML=n)}else{const c=DrawUtils.drawTagByDom(this._container,n,s.id);c&&(c.setAttribute("style",`
78
78
  position: absolute;
79
79
  top: 0;
80
80
  right: 0;
package/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sense-annotation v1.7.2-alpha.0
2
+ * sense-annotation v1.7.2-alpha.1
3
3
  * (c) 2020-2022
4
4
  * Released under the Apache-2.0 License.
5
5
  */import B,{isNumber as $t,cloneDeep as ki,isObject as Oi}from"lodash";import ve from"color-rgba";const Mi=320;var ft;(function(r){r.PointCloud="pointCloudTool"})(ft||(ft={}));var vt;(function(r){r.VideoTextTool="videoTextTool",r.VideoTagTool="videoTagTool",r.VideoClipTool="videoClipTool"})(vt||(vt={}));var Zt;(function(r){r[r.Rect=0]="Rect",r[r.Tag=1]="Tag"})(Zt||(Zt={}));var w;(function(r){r.Rect="rectTool",r.Tag="tagTool",r.Point="pointTool",r.PointMarker="pointMarkerTool",r.Segmentation="segmentationTool",r.Filter="filterTool",r.Text="textTool",r.Polygon="polygonTool",r.Line="lineTool",r.LineMarker="lineMarkerTool",r.Empty="emptyTool",r.FolderTag="folderTagTool",r.RectTrack="rectTrackTool",r.Face="faceTool",r.ClientAttribute="clientAttributeTool",r.OCRRelation="OCRRelationTool"})(w||(w={}));var Rt;(function(r){r.Check="check"})(Rt||(Rt={}));var Ut;(function(r){r[r.nothing=0]="nothing",r[r.RectBG=1]="RectBG",r[r.showOrder=2]="showOrder"})(Ut||(Ut={}));const Ei={[w.Rect]:"\u62C9\u6846",[w.Tag]:"\u6807\u7B7E",[w.Point]:"\u6807\u70B9",[w.PointMarker]:"\u5217\u8868\u6807\u70B9",[w.Segmentation]:"\u524D\u666F\u5206\u5272",[w.Filter]:"\u7B5B\u9009",[w.Text]:"\u6587\u672C",[w.Polygon]:"\u591A\u8FB9\u5F62",[w.Line]:"\u7EBF\u6761",[w.LineMarker]:"\u5217\u8868\u7EBF\u6761",[w.FolderTag]:"\u6587\u4EF6\u5939\u6807\u7B7E",[w.RectTrack]:"\u62C9\u6846\u8DDF\u8E2A",[w.Face]:"\u4EBA\u8138106\u5DE5\u5177",[w.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[w.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177",[vt.VideoTextTool]:"\u89C6\u9891\u6587\u672C",[vt.VideoTagTool]:"\u89C6\u9891\u6807\u7B7E",[vt.VideoClipTool]:"\u89C6\u9891\u622A\u53D6",[ft.PointCloud]:"\u70B9\u4E91"};var zt;(function(r){r[r.noDepend=1]="noDepend",r[r.dependOrigin=2]="dependOrigin",r[r.dependShape=3]="dependShape",r[r.dependLine=4]="dependLine",r[r.dependPolygon=5]="dependPolygon",r[r.dependPreShape=101]="dependPreShape",r[r.dependPreLine=102]="dependPreLine",r[r.dependPrePolygon=103]="dependPrePolygon"})(zt||(zt={}));var dt;(function(r){r.lc="leftClick",r.rc="rightClick",r.clc="ctrlLeftClick",r.crc="ctrlRightClick"})(dt||(dt={}));const Hi={leftClick:"\u9F20\u6807\u5DE6\u952E",rightClick:"\u9F20\u6807\u53F3\u952E",ctrlLeftClick:"ctrl + \u9F20\u6807\u5DE6\u952E",ctrlRightClick:"ctrl + \u9F20\u6807\u53F3\u952E"};var Vt;(function(r){r[r.Normal=1]="Normal",r[r.Modify=2]="Modify"})(Vt||(Vt={}));var T;(function(r){r[r.Line=0]="Line",r[r.Curve=1]="Curve"})(T||(T={}));var At;(function(r){r[r.SingleColor=0]="SingleColor",r[r.MultiColor=1]="MultiColor"})(At||(At={}));var Wt;(function(r){r[r.Form=1]="Form",r[r.Json=2]="Json"})(Wt||(Wt={}));var z;(function(r){r[r.Point=0]="Point",r[r.Line=1]="Line",r[r.Plane=2]="Plane"})(z||(z={}));var jt;(function(r){r[r.None=0]="None",r[r.Drawing=1]="Drawing",r[r.Edit=2]="Edit"})(jt||(jt={}));var Xt;(function(r){r[r.Backward=0]="Backward",r[r.Forward=1]="Forward",r[r.JumpSkip=2]="JumpSkip",r[r.None=3]="None"})(Xt||(Xt={}));var Yt;(function(r){r[r.Wait=0]="Wait",r[r.Pass=1]="Pass",r[r.Fail=2]="Fail",r[r.Loading=3]="Loading"})(Yt||(Yt={}));var j;(function(r){r[r.AnyString=0]="AnyString",r[r.Order=1]="Order",r[r.EnglishOnly=2]="EnglishOnly",r[r.NumberOnly=3]="NumberOnly",r[r.CustomFormat=4]="CustomFormat"})(j||(j={}));const Ni={0:"\u4EFB\u610F\u5B57\u7B26",1:"\u5E8F\u53F7",2:"\u4EC5\u82F1\u6587",3:"\u4EC5\u6570\u5B57"},Gt=1e3,pe=16,be=300,Tt="normal normal 500 14px Arial";var Kt;(function(r){r[r.ImgList=1e3]="ImgList",r[r.TrackPrediction=1001]="TrackPrediction",r[r.ImgSearch=1002]="ImgSearch"})(Kt||(Kt={}));const Bi={[ft.PointCloud]:"sensebeepc",[w.ClientAttribute]:"sensebeepc-EnumAttributeTool",[w.Face]:"sensebeepc-FacePointsLabellingTool",[w.OCRRelation]:"sensebeepc-OCRRelationTool"},Fi={[ft.PointCloud]:"\u70B9\u4E91\u5BA2\u6237\u7AEF",[w.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[w.Face]:"\u4EBA\u8138106\u70B9\u5DE5\u5177",[w.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177"},X=16,pt=10;var q;(function(r){r[r.Normal=0]="Normal",r[r.Rect=1]="Rect"})(q||(q={}));var $i=Object.freeze({__proto__:null,editStepWidth:Mi,get EPointCloudName(){return ft},get EVideoToolName(){return vt},get EToolType(){return Zt},get EToolName(){return w},get ECheckModel(){return Rt},get ERectPattern(){return Ut},TOOL_NAME:Ei,get EDependPattern(){return zt},get EFilterToolOperation(){return dt},OPERATION_LIST:Hi,get EAnnotationMode(){return Vt},get ELineTypes(){return T},get ELineColor(){return At},get ESelectedType(){return Wt},get EDragTarget(){return z},get EDrawPointPattern(){return jt},get EPageOperator(){return Xt},get EAuditStatus(){return Yt},get ETextType(){return j},TEXT_TYPE:Ni,TEXT_ATTRIBUTE_MAX_LENGTH:Gt,TEXT_ATTRIBUTE_LINE_HEIGHT:pe,DEFAULT_TEXT_MAX_WIDTH:be,DEFAULT_FONT:Tt,get EThumbnailOption(){return Kt},CLIENT_TOOL_HEAD_TYPE:Bi,CLIENT_TOOL_NAME:Fi,SEGMENT_NUMBER:X,edgeAdsorptionScope:pt,get EPolygonPattern(){return q}}),Zi=Object.defineProperty,Ui=Object.defineProperties,zi=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertySymbols,Vi=Object.prototype.hasOwnProperty,Wi=Object.prototype.propertyIsEnumerable,ye=(r,t,e)=>t in r?Zi(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ji=(r,t)=>{for(var e in t||(t={}))Vi.call(t,e)&&ye(r,e,t[e]);if(xe)for(var e of xe(t))Wi.call(t,e)&&ye(r,e,t[e]);return r},Xi=(r,t)=>Ui(r,zi(t));function Jt(r,t=.5,e=!1,i=16){if(r.length<4)return r;const s=[],n=r.slice(0);let o,a,l,h,c,g,u,d,f,v,p,b,x;for(e?(n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.push(r[0]),n.push(r[1])):(n.unshift(r[1]),n.unshift(r[0]),n.push(r[r.length-2]),n.push(r[r.length-1])),x=2;x<n.length-4;x+=2)for(l=(n[x+2]-n[x-2])*t,h=(n[x+4]-n[x-0])*t,c=(n[x+3]-n[x-1])*t,g=(n[x+5]-n[x+1])*t,b=0;b<=i;b++)p=b/i,u=2*Math.pow(p,3)-3*Math.pow(p,2)+1,d=-(2*Math.pow(p,3))+3*Math.pow(p,2),f=Math.pow(p,3)-2*Math.pow(p,2)+p,v=Math.pow(p,3)-Math.pow(p,2),o=u*n[x]+d*n[x+2]+f*l+v*h,a=u*n[x+1]+d*n[x+3]+f*c+v*g,s.push(o),s.push(a);const C=[];for(let _=0;_<s.length-1;_+=2)C.push({x:s[_],y:s[_+1]});if(e)for(let _=0;_<i+1;_++){const D=C.shift();C.push(D)}return C}const St=(r,t=16)=>Jt(r.reduce((e,i)=>[...e,i.x,i.y],[]),.5,!1,t);function me(r,t,e=T.Line){let i=0,s,n,o,a;t=[...t],e===T.Curve&&(t=Jt(t.reduce((h,c)=>[...h,c.x,c.y],[]),.5,!0,X)),[o]=t;const l=t.length;for(s=1;s<=l;s++)a=t[s%l],r.x>Math.min(o.x,a.x)&&r.x<=Math.max(o.x,a.x)&&r.y<=Math.max(o.y,a.y)&&o.x!==a.x&&(n=(r.x-o.x)*(a.y-o.y)/(a.x-o.x)+o.y,(o.y===a.y||r.y<=n)&&i++),o=a;return i%2!=0}function Ie(r,t=1){return r.map(e=>Xi(ji({},e),{x:e.x*t,y:e.y*t}))}var we=Math.pow;class bt{static add(t,e){return{x:t.x+e.x,y:t.y+e.y}}static getVector(t,e){return{x:e.x-t.x,y:e.y-t.y}}static len(t){return Math.sqrt(we(t.x,2)+we(t.y,2))}static dotProduct(t,e){return t.x*e.x+t.y+e.y}}class Le{static tanAPlusB(t,e){return(t+e)/(1-t*e)}static sinAPlusB(t,e,i,s){return s*t+e*i}static cosAPlusB(t,e,i,s){return e*s-t*i}}const xt=class{static getRotate(r){return r+90>=360?r+90-360:r+90}static getLineLength(r,t){return Math.sqrt(Math.pow(t.y-r.y,2)+Math.pow(t.x-r.x,2))}static getTextArea(r,t,e=be,i=Tt,s){if(typeof t!="string")return{width:0,height:0};const n=r.getContext("2d");n.font=i;let o=0;typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=r&&parseInt(window.getComputedStyle(r).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,l=t.split(`
@@ -74,7 +74,7 @@
74
74
  background: rgba(102, 111, 255, 1);
75
75
  opacity: 0.6;
76
76
  clear: both;
77
- `),(o=(n=this.canvas)==null?void 0:n.parentNode)==null||o.appendChild(a)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}var Tr=Object.defineProperty,Sr=Object.defineProperties,kr=Object.getOwnPropertyDescriptors,hi=Object.getOwnPropertySymbols,Or=Object.prototype.hasOwnProperty,Mr=Object.prototype.propertyIsEnumerable,ci=(r,t,e)=>t in r?Tr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,re=(r,t)=>{for(var e in t||(t={}))Or.call(t,e)&&ci(r,e,t[e]);if(hi)for(var e of hi(t))Mr.call(t,e)&&ci(r,e,t[e]);return r},ne=(r,t)=>Sr(r,kr(t)),di;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.None=2]="None"})(di||(di={}));const nt=16,Nt={x:0,y:20},oe=3,Bt=5,Er=2;class ui extends st{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=B.cloneDeep(this.activeLine);if(!n||n.length===0)return;const o=this.isActiveLineValid();let a;const l=this.selectedID?this.lineList.find(c=>c.id===this.selectedID):void 0;l?a=l.order:a=this.nextOrder();const h=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!o});n.map(c=>Object.assign(c,this.coordUtils.getRenderCoord(c))),this.updateActiveArea(),this.drawLine(n,e,h,!0,!0),this.drawLineNumber(n[0],a,h,"",this.defaultAttribute,o),e&&this.isCreate&&this.arc(e,oe,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,Bt,h)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>O.calcDistance(this.coordUtils.getRenderCoord(o),e)<=Bt);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(e,i,s,n=!0,o=!1,a)=>{const l=St(i,nt);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),o&&O.setReferenceCtx(e),i.forEach(({specialEdge:h},c)=>{const g=l.splice(0,nt+1);e.save(),e.beginPath(),a===c&&(e.lineWidth=4),g.forEach(({x:u,y:d},f)=>{const v=f>0?"lineTo":"moveTo";h&&O.setSpecialEdgeStyle(e),e[v](u,d)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,o=!1)=>{const a=i?e.concat(i):e,l={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?O.drawCurveLine(this.ctx,a,l,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(a,l,o),n&&e.forEach(h=>{var c,g;const u=h.id,d=u&&[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)?Bt:oe;this.arc(h,d,s),[this.hoverPointID,(g=this.selectedPoint)==null?void 0:g.id].includes(u)||this.arc(h,Er,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&O.setReferenceCtx(n),e.forEach((o,a)=>{if(n.beginPath(),a>0){const l=e[a-1];n.save(),(l==null?void 0:l.specialEdge)&&O.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===a&&(n.lineWidth=4),n.moveTo(l.x,l.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=B.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l)));const{order:s,label:n}=i,o=s,a=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,a,!1),this.drawLineNumber(i.pointList[0],o,a,n,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],a,i==null?void 0:i.textAttribute)}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+e,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:o,left:a,right:l,bottom:h}=this.activeArea,c=[a,l].map(p=>B.isNumber(p)?p+e:0),g=[o,h].map(p=>B.isNumber(p)?p+i:0),u=a>=0&&l&&L.isInRange(c,s),d=o>=0&&h&&L.isInRange(g,n),f=u?e:0,v=d?i:0;this.lineDragging=!0,this.moveActiveArea(f,v)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===A.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===A.Delete){this.deleteLine();return}if(e.keyCode===A.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===A.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ee,this.dependToolConfig={lineType:T.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===T.Curve}get isMultipleColor(){return this.config.lineColor===At.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}get showOrder(){return this.config.showOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=it.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>it.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===j.Order&&this.isTextConfigurable&&(i=S.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return me(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===T.Curve?Jt(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(t[n-1]),a=this.coordUtils.getRenderCoord(s);return O.isInLine(e,o,a,i)})}arc(t,e=oe,i){var s,n,o,a,l,h;if(this.ctx){const{x:c,y:g}=t;(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(c,g,e,0,360),(a=this.ctx)==null||a.closePath(),(l=this.ctx)==null||l.fill(),(h=this.ctx)==null||h.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:o}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,o,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(ne(re({},t),{id:J()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return tt.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?L.calcViewportBoundaries(this.activeLine,this.isCurve,nt,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,o=!0){var a,l,h;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let c=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const g=n?(h=(l=(a=this.attributeList)==null?void 0:a.find(u=>u.value===n))==null?void 0:l.key)!=null?h:n:"";c=[c,`${!o&&g?"\u65E0\u6548":""}${g}`].filter(u=>u).join("_")}this.drawText(t,c,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawText(t,e,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?I.wrapText(this.canvas,e,t.x-Nt.x,t.y-Nt.y,s):this.ctx.fillText(e,t.x-Nt.x,t.y-Nt.y),(o=this.ctx)==null||o.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines())}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return O.calcDistance(i,t)<=Bt})}findHoverLine(t){return B.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,a)=>{if(a===0)return!1;const l=this.coordUtils.getRenderCoord(o),h=this.coordUtils.getRenderCoord(s[a-1]);return O.isInLine(t,l,h,n)})})}getAdsorptionPoint(t){let e,i,s;return B.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const a=this.findNearestPoint(n,t);if(a){if(a.minDistance===0){e=a.point;return}(i===void 0||a.minDistance<i)&&(e=a.point,i=a.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let o=1;o<=t.length-1;o++){const a=this.coordUtils.getRenderCoord(t[o]),l=this.coordUtils.getRenderCoord(t[o-1]),{length:h,footPoint:c}=L.getFootOfPerpendicular(e,a,l),g=O.calcTwoPointDistance(a,e),u=O.calcTwoPointDistance(l,e);if(g<=i*2){s=a,i=0;break}if(u<=i*2){s=l,i=0;break}h<i&&(s=c,i=h)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?St(t,nt):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:a,width:l,height:h}=this.basicResult;s=[o,o+l],n=[a,a+h]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return O.getVHPoint(o,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(a=>a.id===(i==null?void 0:i.id)),n=L.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,nt,this.zoom),o=this.lineList[s];this.updateStatus(1),this.setActiveLine(o.pointList),this.setSelectedLineID(o.id),this.activeArea=n,this.updateLineAttributes(o)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=L.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,nt,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?B.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return L.isInRange(t.x,o)&&L.isInRange(t.y,a)}return L.isInRange(t.x,[0,this.imageSize.width])&&L.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,a=this.isCurve?i.slice((n-1)*(nt+1),n*(nt+1)):[o,s];return this.pointInLine(a,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,ne(re({},this.coordUtils.getAbsCoord(this.cursor)),{id:J()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?O.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=B.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return S.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=J(),e={pointList:B.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let a;if(t){if(this.selectedID){const l=this.lineList.find(h=>h.id===this.selectedID);a=this.selectedID,l&&(l.pointList=B.cloneWith(this.activeLine),B.isEqual(l.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const l=this.createLineData();a=l.id,this.setLineList([...this.lineList,l]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?this.setActiveStatus(a):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===A.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!==A.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===A.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===A.Shift&&this.render(),t.keyCode===A.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=S.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=y.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,a;return ne(re({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(a=(o=i.pointList[0])==null?void 0:o.y)!=null?a:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===A.Ctrl&&this.setInvalidLineOnCreating(t),[A.Shift,A.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=L.calcViewportBoundaries(this.activeLine,this.isCurve,nt,this.zoom);O.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(o=>o.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(o=>o.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=(e=(t=this.lineList.find(l=>l.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:o,textAttribute:a}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:a,y:l}=this.activeLine[1],h=this.coordUtils.getRenderCoord({x:a,y:l}),c=this.getColor(o),g=n?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=(i=(e=this.lineList.find(d=>d.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new Ht({container:this.container,icon:this.getTextIconSvg(o),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:h.x,top:h.y,color:g}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!S.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}class ae{static getMarkerShowText(t,e=[]){return S.getAttributeShowText(t,e)}}var Hr=Object.defineProperty,Nr=Object.defineProperties,Br=Object.getOwnPropertyDescriptors,gi=Object.getOwnPropertySymbols,Fr=Object.prototype.hasOwnProperty,$r=Object.prototype.propertyIsEnumerable,fi=Math.pow,vi=(r,t,e)=>t in r?Hr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ft=(r,t)=>{for(var e in t||(t={}))Fr.call(t,e)&&vi(r,e,t[e]);if(gi)for(var e of gi(t))$r.call(t,e)&&vi(r,e,t[e]);return r},le=(r,t)=>Nr(r,Br(t));const pi=200;class bi extends st{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(S.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=m.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const n=m.changePointByZoom(s,this.zoom);return L.getLineLength(n,i)<.2})},this.config=y.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)}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=y.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),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=y.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 S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=k.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=k.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===k.Start||this.dragStatus===k.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===k.Move&&this.history.pushHistory(this.pointList),this.dragStatus=k.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=k.Move;const s=this.getCoordinateUnderZoom(t),n=m.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),o=this.drawOutsideTarget?m.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):m.changePointByZoom(n,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===w.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!M.isInPolygon(o,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=o.x,a.y=o.y)}),this.render())}onKeyDown(t){if(!y.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Delete:this.deletePoint();break;case A.Tab:{this.onTabKeyDown(t);break}case A.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s;if(!this.imgInfo)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${N.getMessagesByLocale(P.LowerLimitPoint,this.lang)}`);return}const o=y.getSourceID(this.basicResult),a=this.getCoordinateUnderZoom(t);let l=m.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData){const g=((e=this.referenceData)==null?void 0:e.toolName)===w.Polygon,{dropFoot:u}=M.getClosestPoint(l,this.referenceData.result,(s=(i=this.referenceData.config)==null?void 0:i.lineType)!=null?s:T.Line,pt/this.zoom,{isClose:g});u&&(l=u,this.emit("messageSuccess",`${N.getMessagesByLocale(P.SuccessfulEdgeAdsorption,this.lang)}`))}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let g=!1;switch(this.dependToolName){case w.Rect:{g=!$.isInRect(l,this.basicResult);break}case w.Polygon:{g=!M.isInPolygon(l,this.basicResult.pointList);break}}if(g)return}if(a.x<0||a.y<0||a.x>this.imgInfo.width||a.y>this.imgInfo.height)return}if(this.isMinDistance(l))return;let h=le(Ft({},l),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:o,textAttribute:"",order:y.getMaxOrder(this.pointList.filter(g=>y.isSameSourceID(g.sourceID,o)))+1});if(this.config.textConfigurable){let g="";g=S.getTextAttribute(this.pointList.filter(u=>y.isSameSourceID(u.sourceID,o)),this.config.textCheckType),h=le(Ft({},h),{textAttribute:g})}if(this.hasMarkerConfig){const g=y.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(g)h=le(Ft({},h),{label:g.label}),this.markerIndex=g.index,this.emit("markIndexChange");else{this.emit("messageInfo",N.getMessagesByLocale(P.MarkerFinish,this.lang));return}}this.hoverID=h.id;const c=[...this.pointList,h];this.setPointList(c),this.history.pushHistory(c),this.setSelectedID(h.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(fi(t.x-e.x,2)+fi(t.y-e.y,2))}getHoverId(){var t;const e=m.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}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=y.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===k.Move||this.dragStatus===k.Start)return;let e=Y.ascend;t.shiftKey&&(e=Y.descend);const[i,s]=y.getRenderResultList(this.pointList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=y.getNextSelectedRectID(n,e,this.selectedID);o&&this.setSelectedID(o.id)}get currentPageResult(){const[t]=y.getRenderResultList(this.pointList,y.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=y.getRenderResultList(t,y.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.render())}undoAndRedo(t){var e,i;if(this.dragStatus===k.Move||this.dragStatus===k.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(n=>n.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(n=>n.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=k.Wait,{width:pi*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(S.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(d=>d.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:n,attribute:o,valid:a}=i,l=pi*this.zoom*.6,h=m.getOffsetCoordinate({x:s,y:n},this.currentPos,this.zoom),c=this.getColor(o),g=a?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributInstance||(this._textAttributInstance=new Ht({width:l,container:this.container,icon:this.getTextIconSvg(o),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:h.x,top:h.y+u,color:g,width:l})}renderPoint(t){var e,i,s;const{textAttribute:n="",attribute:o}=t,a=t.id===this.selectedID,l=this.getColor(o),h=m.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:g=!1}=this.style,u=tt.getStrokeAndFill(l,t.valid,{isSelected:a||t.id===this.hoverID});I.drawCircle(this.canvas,h,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:u.stroke,fill:u.fill});let d="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(d=`${t.order}`),t.label&&this.hasMarkerConfig&&(d=`${y.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${ae.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(d=`${d} ${S.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),g||I.drawText(this.canvas,{x:h.x+c/2,y:h.y-c-4},d,{textAlign:"center",color:u.stroke}),a?this.renderTextAttribute():g||I.drawText(this.canvas,{x:h.x+c,y:h.y+c+24},n,Ft({color:u.stroke},G))}renderPointList(){const[t,e]=y.getRenderResultList(this.pointList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let n=m.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const o=((t=this.referenceData)==null?void 0:t.toolName)===w.Polygon,{dropFoot:a}=M.getClosestPoint(n,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:T.Line,pt/this.zoom,{isClose:o});a&&n!==a&&n!==a&&(n=a,I.drawCircle(this.canvas,m.changePointByZoom(n,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),I.drawCircle(this.canvas,m.changePointByZoom(n,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}class xi extends st{constructor(t){super(t);this.getSingleResult=e=>{const i={};return this.config.configList.length>0&&this.config.configList.forEach(s=>{var n;i[s.key]=(n=s.default)!=null?n:""}),{value:i,id:J(),sourceID:e!=null?e:y.getSourceID()}},this.getInitResultList=(e,i)=>e>0?i.map(s=>this.getSingleResult(s.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var e;this.textList=t,this.toggleTextContainerVisible(!0);const i=(e=this.textList[0])==null?void 0:e.value;i&&Object.keys(i).forEach(s=>{this.renderText(s,i[s])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!i)}updateTextValue(t,e){this.textList[0].value[t]=e,this.renderText(t,e),this.emit("valueUpdated")}renderText(t,e){const i=document.getElementById(`textKey${t}`);i&&(i.innerText=e)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),e={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(e).reduce((i,s)=>(i+=`${s}: ${e[s]};`,i),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(i=>{const s=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");s.setAttribute("style","padding: 8px 16px"),n.innerText=`${i.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(i.key)),s.appendChild(n),s.appendChild(o),t.appendChild(s)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===A.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const e=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=e}}}var Zr=Object.defineProperty,Ur=Object.defineProperties,zr=Object.getOwnPropertyDescriptors,yi=Object.getOwnPropertySymbols,Vr=Object.prototype.hasOwnProperty,Wr=Object.prototype.propertyIsEnumerable,mi=(r,t,e)=>t in r?Zr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ii=(r,t)=>{for(var e in t||(t={}))Vr.call(t,e)&&mi(r,e,t[e]);if(yi)for(var e of yi(t))Wr.call(t,e)&&mi(r,e,t[e]);return r},jr=(r,t)=>Ur(r,zr(t));class y{static getStepInfo(t,e){return e==null?void 0:e.filter(i=>i.step===t)[0]}static getCurrentStepInfo(t,e){const i=this.getStepInfo(t,e);return i&&(i.type===Lt.QUALITY_INSPECTION||i.type===Lt.MANUAL_CORRECTION)?this.getCurrentStepInfo(i.dataSourceStep,e):i}static getMaxOrder(t){let e=0;return t.forEach(i=>{i.order&&i.order>e&&(e=i.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:i,type:s}=e;if(!i||!s)return!0;let n=!0;return(e.isContentEditable||i==="TEXTAREA"||(i==="INPUT"&&s!=="radio"||i==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getCurrentOperation(t){switch(t){case w.Rect:case w.RectTrack:return ue;case w.Tag:return li;case w.Polygon:return ai;case Rt.Check:return Pr;case w.Line:return ui;case w.Point:return bi;case w.Text:return xi;default:throw new Error("not match tool")}}static getNextSelectedRectID(t,e=Y.ascend,i){let s=1;e===Y.descend&&(s=-1);const n=t.sort((l,h)=>l.x-h.x==0?l.y-h.y:s*(l.x-h.x)),o=n.findIndex(l=>l.id===i),a=n.length;return n[(o+1)%a]}static getNextSelectedRectIDByEvent(t,e,i){const s=e.shiftKey?Y.descend:Y.ascend;return this.getNextSelectedRectID(t,s,i)}static getRenderResultList(t,e,i=[],s){let n;return[t.filter(a=>s&&s===(a==null?void 0:a.id)?(n=a,!1):!(i.length>0&&!i.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),n]}static getSourceID(t){var e;const i="";return t&&(e=t==null?void 0:t.id)!=null?e:i}static findAllLine(t,e=!0){const i=[],s=[...t];s.length>=3&&e===!0&&s.push(Ii({},s[0]));for(let n=0;n<s.length;n++)s[n+1]&&i.push({point1:s[n],point2:s[n+1],pointIndex:n});return i}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],i){if((e==null?void 0:e.length)===0)return;let s=e.map((n,o)=>jr(Ii({},n),{index:o}));if(typeof i=="number"&&i>0){const n=e[i];if(n&&t.every(o=>o.label!==n.value))return{label:n.value,index:i};s=[...s.slice(i,e.length),...s.slice(0,i)]}for(let n=0;n<s.length;n++)if(!t.some(o=>o.label===s[n].value))return{label:s[n].value,index:s[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(i=>t===i.value)}}y.jsonParser=(r,t={})=>{try{return typeof r=="string"?JSON.parse(r):Oi(r)?r:t}catch(e){return t}};var Xr=Object.defineProperty,wi=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,Li=(r,t,e)=>t in r?Xr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,he=(r,t)=>{for(var e in t||(t={}))Yr.call(t,e)&&Li(r,e,t[e]);if(wi)for(var e of wi(t))Gr.call(t,e)&&Li(r,e,t[e]);return r};class M{static getHoverPolygonID(t,e,i=3,s=T.Line){let n="",o=Infinity;const a=m.axisArea(t,i);return e.forEach(l=>{l.pointList&&a.forEach(h=>{const c=this.calcPolygonSize(l.pointList);this.isInPolygon(h,l.pointList,s)&&c<o&&(n=l.id,o=c)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,i=t.reduce((s,n,o,a)=>{const l=a[(o+1)%e];return s+n.x*l.y-l.x*n.y},0);return Math.abs(i)/2}static isInPolygon(t,e,i=T.Line){let s=0,n,o,a,l;e=[...e],i===T.Curve&&(e=this.createSmoothCurvePoints(e.reduce((c,g)=>[...c,g.x,g.y],[]),.5,!0,20)),[a]=e;const h=e.length;for(n=1;n<=h;n++)l=e[n%h],t.x>Math.min(a.x,l.x)&&t.x<=Math.max(a.x,l.x)&&t.y<=Math.max(a.y,l.y)&&a.x!==l.x&&(o=(t.x-a.x)*(l.y-a.y)/(l.x-a.x)+a.y,(a.y===l.y||t.y<=o)&&s++),a=l;return s%2!=0}static createSmoothCurvePointsFromPointList(t,e=X){return this.createSmoothCurvePoints(t.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!1,e).map((s,n)=>{var o;const a=n/(X+1),l=Math.floor(a),h=(o=t[l])!=null?o:{};return he(l===a?he({},h):{specialEdge:h.specialEdge},s)})}static createSmoothCurvePoints(t,e=.5,i=!1,s=X){if(t.length<4)return t;const n=[],o=t.slice(0);let a,l,h,c,g,u,d,f,v,p,b,x,C;for(i?(o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.push(t[0]),o.push(t[1])):(o.unshift(t[1]),o.unshift(t[0]),o.push(t[t.length-2]),o.push(t[t.length-1])),C=2;C<o.length-4;C+=2)for(h=(o[C+2]-o[C-2])*e,c=(o[C+4]-o[C-0])*e,g=(o[C+3]-o[C-1])*e,u=(o[C+5]-o[C+1])*e,x=0;x<=s;x++)b=x/s,d=2*Math.pow(b,3)-3*Math.pow(b,2)+1,f=-(2*Math.pow(b,3))+3*Math.pow(b,2),v=Math.pow(b,3)-2*Math.pow(b,2)+b,p=Math.pow(b,3)-Math.pow(b,2),a=d*o[C]+f*o[C+2]+v*h+p*c,l=d*o[C+1]+f*o[C+3]+v*g+p*u,n.push(a),n.push(l);const _=[];for(let D=0;D<n.length-1;D+=2)_.push({x:n[D],y:n[D+1]});if(i)for(let D=0;D<s+1;D++){const R=_.shift();_.push(R)}return _}static getPolygonByID(t,e){return t.find(i=>i.id===e)}static getHoverEdgeIndex(t,e,i=T.Line,s=3){let n=[...e];i===T.Curve?n=this.createSmoothCurvePoints(e.reduce((l,h)=>[...l,h.x,h.y],[]),.5,!0,X):i===T.Line&&n.push(n[0]);let o=-1,a=s;for(let l=0;l<n.length-1;l++){const{length:h}=L.getFootOfPerpendicular(t,n[l],n[l+1]);h<a&&(o=l,a=h)}return o===-1?-1:i===T.Curve?Math.floor(o/X):o}static getClosestPoint(t,e,i=T.Line,s=3,n){var o;const a=(o=n==null?void 0:n.isClose)!=null?o:!0;let l="",h=-1,c=Infinity,g=t;const u=20;let d=!1;return e.forEach(f=>{if(!d&&!!f.pointList)switch(i){case T.Line:y.findAllLine(f.pointList,a).forEach((p,b)=>{if(d)return;let{length:x,footPoint:C}=L.getFootOfPerpendicular(t,p.point1,p.point2);const _=L.getLineLength(p.point1,t),D=L.getLineLength(p.point2,t);_<s*2&&(C=p.point1,x=_,d=!0),D<s*2&&(C=p.point2,x=D,d=!0),x<c&&x<s&&(l=f.id,h=b,c=x,g=C)});break;case T.Curve:{const v=this.createSmoothCurvePoints(f.pointList.reduce((p,b)=>[...p,b.x,b.y],[]),.5,a,u);for(let p=0;p<v.length-1;p++){const{length:b,footPoint:x}=L.getFootOfPerpendicular(t,v[p],v[p+1]);b<c&&b<s&&(l=f.id,h=Math.floor(p/(u+1)),c=b,g=x)}}break}}),{dropFoot:g,closestEdgeIndex:h,closestPolygonID:l}}static isPointListInPolygon(t,e,i=T.Line){return t.every(s=>this.isInPolygon(s,e,i))}static isPointListOutSidePolygon(t,e,i=T.Line){return t.some(s=>!this.isInPolygon(s,e,i))}static getPolygonArea(t){let e=0;for(let i=0,s=t.length;i<s;i++){const n=t[i].x,o=t[i===t.length-1?0:i+1].y,a=t[i===t.length-1?0:i+1].x,l=t[i].y;e+=n*o*.5,e-=a*l*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,i){let s=1;return t===Pt.Anticlockwise&&(s=-1),s*=e,L.rotateRectPointList(s,i)}}var Kr=Object.defineProperty,Jr=Object.defineProperties,qr=Object.getOwnPropertyDescriptors,Pi=Object.getOwnPropertySymbols,Qr=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,Ci=(r,t,e)=>t in r?Kr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ce=(r,t)=>{for(var e in t||(t={}))Qr.call(t,e)&&Ci(r,e,t[e]);if(Pi)for(var e of Pi(t))tn.call(t,e)&&Ci(r,e,t[e]);return r},de=(r,t)=>Jr(r,qr(t));class m{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:a}=t;switch(e%360){case 90:return{x:n-a,y:o};case 180:return{x:s-o,y:n-a};case 270:return{x:a,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return de(ce({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return de(ce({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let a=s-e;a<s+e;a+=e/3)n.push({x:o,y:a});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class en{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===w.Polygon}get isDependRect(){return this.dependToolName===w.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:L.withinRange(t.x,[i,i+n]),y:L.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===T.Curve?M.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return O.calcOptimalIntersection(i,o,s,hr,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const a=this.getPolygonPointList(o,n);if(M.isInPolygon(t,a))return t;const h=a.concat(a[0]).map(g=>this.getRenderCoord(g)),c=this.getIntersection(t,e,h);return c?this.getAbsCoord(c==null?void 0:c.point):t}coordInsideImage(t){return this.coordInsideRect(t,de(ce({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return L.isInRange(t.x,o)&&L.isInRange(t.y,a)}return L.isInRange(t.x,[0,this.basicImgInfo.width])&&L.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return M.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}var sn=Object.defineProperty,rn=Object.defineProperties,nn=Object.getOwnPropertyDescriptors,Di=Object.getOwnPropertySymbols,on=Object.prototype.hasOwnProperty,an=Object.prototype.propertyIsEnumerable,_i=(r,t,e)=>t in r?sn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))on.call(t,e)&&_i(r,e,t[e]);if(Di)for(var e of Di(t))an.call(t,e)&&_i(r,e,t[e]);return r},U=(r,t)=>rn(r,nn(t));const Dt=6;class ue extends st{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),s=Dt,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&$.isInRect(i,a,s,this.zoom))return a.id}const o=n.filter(a=>$.isInRect(i,a,s,this.zoom));if(o.length===0)return"";if(o.length===1)return o[0].id;if(o.length>1)return o.map(l=>({size:l.width*l.height,id:l.id})).sort((l,h)=>l.size-h.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(S.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=y.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=y.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=y.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=y.getRenderResultList(t,y.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const s=this.selectedRectID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?U(H({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?m.returnClosePointIndex(this.getCoordinateUnderZoom(t),$.getRectPointList(this.selectedRect,this.zoom),Dt+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,s=$.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let o=0;o<s.length;o++){const a=s[o],{length:l}=L.getFootOfPerpendicular(n,a.begin,a.end);l<Dt+10&&(e=o)}return e}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),s=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!(!s||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const n=z.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=k.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=z.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=k.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const n=z.Plane;this.dragInfo={dragStartCoord:e,dragTarget:n,firstRect:s,startTime:+new Date},this.dragStatus=k.Start}}}onDragMove(t){var e,i,s,n,o,a;if(!this.dragInfo)return;this.dragStatus=k.Move;const l=$.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:c,width:g,height:u}=l,d={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};let f=this.rectList.filter(v=>v.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case z.Plane:f=U(H({},f),{x:h+d.x,y:c+d.y,width:g,height:u});break;case z.Point:{let v=h,p=c,b=g,x=u;switch(this.hoverRectPointIndex){case 0:{v=g-d.x<0?h+g:h+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(d.x-g),x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(g+d.x),x=Math.abs(u-d.y);break}case 2:{v=g+d.x>0?h:h+g+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(g+d.x),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(d.x-g),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}default:return}f=U(H({},f),{x:v,y:p,width:b,height:x})}break;case z.Line:{let v=h,p=c,b=g,x=u;switch(this.hoverRectEdgeIndex){case 0:{p=u-d.y<0?c+u:c+d.y,x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,b=Math.abs(g+d.x);break}case 2:{p=u+d.y>0?c:c+u+d.y,x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,b=Math.abs(d.x-g);break}default:return}f=U(H({},f),{x:v,y:p,width:b,height:x});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&$.isRectNotInPolygon(f,Ie(this.basicResult.pointList,this.zoom)))return;const v=this.basicResult.x*this.zoom,p=this.basicResult.y*this.zoom,b=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==z.Plane&&(f.x<v-.01||f.y<p-.01||f.width>v+b-f.x+.01||f.height>p+x-f.y+.01))return;if(f.x<v&&(f.x=v),f.y<p&&(f.y=p),f.width>v+b-f.x)switch(this.dragInfo.dragTarget){case z.Plane:f.x=v+b-g;break;case z.Point:case z.Line:d.x>0&&d.y>0&&(f.width=v+b-f.x);break;default:return}if(f.height>p+x-f.y)switch(this.dragInfo.dragTarget){case z.Plane:f.y=p+x-u;break}}else if(f.x<0&&(f.x=0),f.y<0&&(f.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case z.Plane:f.x+f.width>((s=this.imgInfo)==null?void 0:s.width)&&(f.x=this.imgInfo.width-g),f.y+f.height>((n=this.imgInfo)==null?void 0:n.height)&&(f.y=this.imgInfo.height-u);break;default:if(f.x+f.width>((o=this.imgInfo)==null?void 0:o.width)+.01||f.y+f.height>((a=this.imgInfo)==null?void 0:a.height)+.01)return}}this.setRectList(this.rectList.map(v=>v.id===f.id?$.getRectUnderZoom(f,1/this.zoom):v)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),n=m.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedRectID&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const l=this.getHoverRectPointIndex(t);if(l!==this.hoverRectPointIndex){this.hoverRectPointIndex=l,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const o=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=o,o!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:l,y:h}=this.firstClickCoord,{width:c,height:g}=this.drawingRect;if(c=Math.abs(l-n.x),g=Math.abs(h-n.y),n.x<l&&(l=n.x),n.y<h&&(h=n.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&$.isRectNotInPolygon(U(H({},this.drawingRect),{x:l,y:h,width:c,height:g}),Ie(this.basicResult.pointList,this.zoom)))return;n.x<0&&(c=Math.abs(this.firstClickCoord.x),l=0),n.y<0&&(g=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(l+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-l)),h+g>this.imgInfo.height&&(g=Math.abs(this.imgInfo.height-h)))}this.drawingRect=U(H({},this.drawingRect),{x:l,y:h,width:c,height:g}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?U(H({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),s=m.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(s.x<0&&(s.x=0),s.y<0&&(s.y=0)),this.drawingRect=U(H({},s),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=y.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",N.getMessagesByLocale(P.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=S.getTextAttribute(this.rectList.filter(o=>y.isSameSourceID(o.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:y.getMaxOrder(this.rectList.filter(n=>y.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=H({},s),this.firstCurrentPos=H({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",N.getMessagesByLocale(P.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=k.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=k.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:s}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,s/=this.zoom,[...this.rectList,U(H({},this.drawingRect),{x:t,y:e,width:i,height:s})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(n=>n.id===e),{selectedRectID:s}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(s!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const n=y.getCurrentMarkerIndex(i.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===k.Move){this.dragInfo=void 0,this.dragStatus=k.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=y.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!y.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Ctrl:this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteRect(this.selectedRectID);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=Y.ascend;t.shiftKey&&(i=Y.descend);const[s,n]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let o=[...s];n&&(o=[...o,n]);const a=it.getViewPort(this.canvas,this.currentPos,this.zoom);o=o.filter(h=>it.inViewPort({x:h.x,y:h.y},a));const l=y.getNextSelectedRectID(o,i,this.selectedRectID);l&&(this.setSelectedRectID(l.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(l.attribute));break}default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,s;this.drawingRect&&this.firstClickCoord&&(i=$.getRectUnderZoom(this.drawingRect,1/e),s=m.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&s&&(this.drawingRect=$.getRectUnderZoom(i,this.zoom),this.firstClickCoord=m.changePointByZoom(s,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.getColor(t.attribute);let i,s;return t.valid===!1?(i=e==null?void 0:e.invalid.stroke,s=e==null?void 0:e.invalid.fill):(i=e==null?void 0:e.valid.stroke,s=e==null?void 0:e.valid.fill),{strokeColor:i,fillColor:s,textColor:i,toolColor:e}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:s,width:n,height:o,attribute:a,valid:l}=e,h=n*this.zoom*.6,c=m.getOffsetCoordinate({x:i,y:s+o},this.currentPos,this.zoom),g=this.getColor(a),u=l?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new Ht({width:h,container:this.container,icon:this.getTextIconSvg(a),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+d,color:u,width:h})}renderSelectedRect(t){const{selectedRect:e}=this;if(!this.ctx||!t||!e)return;const{ctx:i}=this;let s=10;const n=$.getRectPointList(e),o=n.length,a=this.getColor(t.attribute);n.forEach((l,h)=>{var c,g;if(i.save(),i.moveTo(l.x,l.y),i.beginPath(),this.hoverRectPointIndex===h?s=Dt+6:s=Dt,t.valid===!1?(i.strokeStyle=a==null?void 0:a.invalid.stroke,i.fillStyle=a==null?void 0:a.invalid.stroke):(i.strokeStyle=a==null?void 0:a.valid.stroke,i.fillStyle=a==null?void 0:a.valid.stroke),i.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),i.fill(),this.hoverRectEdgeIndex===h){i.beginPath(),i.lineWidth=10;const u=this.getColor(t.attribute),d=t.valid===!1?(c=u==null?void 0:u.invalid)==null?void 0:c.stroke:(g=u==null?void 0:u.valid)==null?void 0:g.stroke;i.strokeStyle=d,i.moveTo(n[h].x*this.zoom+this.currentPos.x,n[h].y*this.zoom+this.currentPos.y),i.lineTo(n[(h+1)%o].x*this.zoom+this.currentPos.x,n[(h+1)%o].y*this.zoom+this.currentPos.y),i.stroke()}i.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var s,n,o,a;if(this.ctx&&t){const{ctx:l,style:h}=this,{hiddenText:c=!1}=h;l.save();const{strokeColor:g,fillColor:u,textColor:d}=this.getRenderStyle(t);l.font="lighter 14px Arial";let f="";((s=this.config)==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${y.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${ae.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${S.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`);const v=m.changeRectByZoom(t,i?e:this.zoom,this.currentPos);c||I.drawText(this.canvas,{x:v.x,y:v.y-6},f,U(H({color:g,font:"normal normal 900 14px SourceHanSansCN-Regular"},ut),{textMaxWidth:300}));const p=(a=(o=this.style)==null?void 0:o.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID)&&I.drawRectWithFill(this.canvas,v,{color:u}),I.drawRect(this.canvas,v,{color:g,thickness:p,hiddenText:!0}),l.restore();let b=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(b=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const x=b.length*7;if(c||I.drawText(this.canvas,{x:v.x+v.width-x,y:v.y+v.height+15},b,H({color:d,font:"normal normal 600 14px Arial"},ut)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const C=0,_=Math.max(20,v.width-x);I.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+C},t.textAttribute,H({color:d,font:"italic normal 900 14px Arial",textMaxWidth:_},ut))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,s]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,m.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),s&&(this.renderDrawingRect(s),this.renderSelectedRect(s),e.selectedRender&&e.selectedRender(this.canvas,m.changeRectByZoom(s,this.zoom,this.currentPos),this.getRenderStyle(s)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,m.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(s=>s.id===this.selectedID?U(H({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=k.Wait,this.setSelectedRectID(void 0)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",N.getMessagesByLocale(P.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(s=>s.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",N.getMessagesByLocale(P.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(s=>s.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}var ln=Object.defineProperty,hn=Object.defineProperties,cn=Object.getOwnPropertyDescriptors,Ri=Object.getOwnPropertySymbols,dn=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable,Ai=(r,t,e)=>t in r?ln(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,gn=(r,t)=>{for(var e in t||(t={}))dn.call(t,e)&&Ai(r,e,t[e]);if(Ri)for(var e of Ri(t))un.call(t,e)&&Ai(r,e,t[e]);return r},fn=(r,t)=>hn(r,cn(t));const vn={textConfigurable:!1,attributeConfigurable:!0,attributeList:[]};class pn extends ue{constructor(t){super(fn(gn({},t),{config:JSON.stringify(vn)}))}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||this.setSelectedRectID(this.drawingRect.id)}}class bn{constructor(t){this._domMap=new Map,this._container=t.container,this._height=t.height}wheelChange(t){t.stopPropagation()}clearTag(t){const e=this._container,i=window.self.document.getElementById(t);i&&e&&e.contains(i)&&(i.removeEventListener("wheel",this.wheelChange),e==null||e.removeChild(i))}render(t){const e=Array.from(this._domMap.keys()),i=t.map(s=>s.id);t.forEach(s=>{const{text:n,textMaxWidth:o,color:a="white",background:l="rgba(0, 0, 0, 0.6)",style:h}=s;if(this._domMap.has(s.id)){const c=this._domMap.get(s.id);c&&(c.innerHTML=n)}else{const c=I.drawTagByDom(this._container,n,s.id);c&&(c.setAttribute("style",`
77
+ `),(o=(n=this.canvas)==null?void 0:n.parentNode)==null||o.appendChild(a)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}var Tr=Object.defineProperty,Sr=Object.defineProperties,kr=Object.getOwnPropertyDescriptors,hi=Object.getOwnPropertySymbols,Or=Object.prototype.hasOwnProperty,Mr=Object.prototype.propertyIsEnumerable,ci=(r,t,e)=>t in r?Tr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,re=(r,t)=>{for(var e in t||(t={}))Or.call(t,e)&&ci(r,e,t[e]);if(hi)for(var e of hi(t))Mr.call(t,e)&&ci(r,e,t[e]);return r},ne=(r,t)=>Sr(r,kr(t)),di;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.None=2]="None"})(di||(di={}));const nt=16,Nt={x:0,y:20},oe=3,Bt=5,Er=2;class ui extends st{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=B.cloneDeep(this.activeLine);if(!n||n.length===0)return;const o=this.isActiveLineValid();let a;const l=this.selectedID?this.lineList.find(c=>c.id===this.selectedID):void 0;l?a=l.order:a=this.nextOrder();const h=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!o});n.map(c=>Object.assign(c,this.coordUtils.getRenderCoord(c))),this.updateActiveArea(),this.drawLine(n,e,h,!0,!0),this.drawLineNumber(n[0],a,h,"",this.defaultAttribute,o),e&&this.isCreate&&this.arc(e,oe,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,Bt,h)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>O.calcDistance(this.coordUtils.getRenderCoord(o),e)<=Bt);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(e,i,s,n=!0,o=!1,a)=>{const l=St(i,nt);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),o&&O.setReferenceCtx(e),i.forEach(({specialEdge:h},c)=>{const g=l.splice(0,nt+1);e.save(),e.beginPath(),a===c&&(e.lineWidth=4),g.forEach(({x:u,y:d},f)=>{const v=f>0?"lineTo":"moveTo";h&&O.setSpecialEdgeStyle(e),e[v](u,d)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,o=!1)=>{const a=i?e.concat(i):e,l={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?O.drawCurveLine(this.ctx,a,l,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(a,l,o),n&&e.forEach(h=>{var c,g;const u=h.id,d=u&&[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)?Bt:oe;this.arc(h,d,s),[this.hoverPointID,(g=this.selectedPoint)==null?void 0:g.id].includes(u)||this.arc(h,Er,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&O.setReferenceCtx(n),e.forEach((o,a)=>{if(n.beginPath(),a>0){const l=e[a-1];n.save(),(l==null?void 0:l.specialEdge)&&O.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===a&&(n.lineWidth=4),n.moveTo(l.x,l.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=B.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l)));const{order:s,label:n}=i,o=s,a=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,a,!1),this.drawLineNumber(i.pointList[0],o,a,n,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],a,i==null?void 0:i.textAttribute)}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+e,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:o,left:a,right:l,bottom:h}=this.activeArea,c=[a,l].map(p=>B.isNumber(p)?p+e:0),g=[o,h].map(p=>B.isNumber(p)?p+i:0),u=a>=0&&l&&L.isInRange(c,s),d=o>=0&&h&&L.isInRange(g,n),f=u?e:0,v=d?i:0;this.lineDragging=!0,this.moveActiveArea(f,v)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===A.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===A.Delete){this.deleteLine();return}if(e.keyCode===A.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===A.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ee,this.dependToolConfig={lineType:T.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===T.Curve}get isMultipleColor(){return this.config.lineColor===At.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}get showOrder(){return this.config.showOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=it.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>it.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===j.Order&&this.isTextConfigurable&&(i=S.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return me(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===T.Curve?Jt(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(t[n-1]),a=this.coordUtils.getRenderCoord(s);return O.isInLine(e,o,a,i)})}arc(t,e=oe,i){var s,n,o,a,l,h;if(this.ctx){const{x:c,y:g}=t;(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(c,g,e,0,360),(a=this.ctx)==null||a.closePath(),(l=this.ctx)==null||l.fill(),(h=this.ctx)==null||h.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:o}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,o,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(ne(re({},t),{id:J()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return tt.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?L.calcViewportBoundaries(this.activeLine,this.isCurve,nt,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,o=!0){var a,l,h;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let c=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const g=n?(h=(l=(a=this.attributeList)==null?void 0:a.find(u=>u.value===n))==null?void 0:l.key)!=null?h:n:"";c=[c,`${!o&&g?"\u65E0\u6548":""}${g}`].filter(u=>u).join("_")}this.drawText(t,c,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawText(t,e,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?I.wrapText(this.canvas,e,t.x-Nt.x,t.y-Nt.y,s):this.ctx.fillText(e,t.x-Nt.x,t.y-Nt.y),(o=this.ctx)==null||o.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines())}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return O.calcDistance(i,t)<=Bt})}findHoverLine(t){return B.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,a)=>{if(a===0)return!1;const l=this.coordUtils.getRenderCoord(o),h=this.coordUtils.getRenderCoord(s[a-1]);return O.isInLine(t,l,h,n)})})}getAdsorptionPoint(t){let e,i,s;return B.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const a=this.findNearestPoint(n,t);if(a){if(a.minDistance===0){e=a.point;return}(i===void 0||a.minDistance<i)&&(e=a.point,i=a.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let o=1;o<=t.length-1;o++){const a=this.coordUtils.getRenderCoord(t[o]),l=this.coordUtils.getRenderCoord(t[o-1]),{length:h,footPoint:c}=L.getFootOfPerpendicular(e,a,l),g=O.calcTwoPointDistance(a,e),u=O.calcTwoPointDistance(l,e);if(g<=i*2){s=a,i=0;break}if(u<=i*2){s=l,i=0;break}h<i&&(s=c,i=h)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?St(t,nt):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:a,width:l,height:h}=this.basicResult;s=[o,o+l],n=[a,a+h]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return O.getVHPoint(o,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(a=>a.id===(i==null?void 0:i.id)),n=L.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,nt,this.zoom),o=this.lineList[s];this.updateStatus(1),this.setActiveLine(o.pointList),this.setSelectedLineID(o.id),this.activeArea=n,this.updateLineAttributes(o)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=L.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,nt,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?B.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return L.isInRange(t.x,o)&&L.isInRange(t.y,a)}return L.isInRange(t.x,[0,this.imageSize.width])&&L.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,a=this.isCurve?i.slice((n-1)*(nt+1),n*(nt+1)):[o,s];return this.pointInLine(a,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,ne(re({},this.coordUtils.getAbsCoord(this.cursor)),{id:J()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?O.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=B.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return S.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=J(),e={pointList:B.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let a;if(t){if(this.selectedID){const l=this.lineList.find(h=>h.id===this.selectedID);a=this.selectedID,l&&(l.pointList=B.cloneWith(this.activeLine),B.isEqual(l.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const l=this.createLineData();a=l.id,this.setLineList([...this.lineList,l]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?this.setActiveStatus(a):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===A.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!==A.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===A.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===A.Shift&&this.render(),t.keyCode===A.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=S.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=y.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,a;return ne(re({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(a=(o=i.pointList[0])==null?void 0:o.y)!=null?a:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===A.Ctrl&&this.setInvalidLineOnCreating(t),[A.Shift,A.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=L.calcViewportBoundaries(this.activeLine,this.isCurve,nt,this.zoom);O.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(o=>o.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(o=>o.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=(e=(t=this.lineList.find(l=>l.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:o,textAttribute:a}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:a,y:l}=this.activeLine[1],h=this.coordUtils.getRenderCoord({x:a,y:l}),c=this.getColor(o),g=n?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=(i=(e=this.lineList.find(d=>d.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new Ht({container:this.container,icon:this.getTextIconSvg(o),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:h.x,top:h.y,color:g}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!S.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}class ae{static getMarkerShowText(t,e=[]){return S.getAttributeShowText(t,e)}}var Hr=Object.defineProperty,Nr=Object.defineProperties,Br=Object.getOwnPropertyDescriptors,gi=Object.getOwnPropertySymbols,Fr=Object.prototype.hasOwnProperty,$r=Object.prototype.propertyIsEnumerable,fi=Math.pow,vi=(r,t,e)=>t in r?Hr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ft=(r,t)=>{for(var e in t||(t={}))Fr.call(t,e)&&vi(r,e,t[e]);if(gi)for(var e of gi(t))$r.call(t,e)&&vi(r,e,t[e]);return r},le=(r,t)=>Nr(r,Br(t));const pi=200;class bi extends st{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(S.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=m.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const n=m.changePointByZoom(s,this.zoom);return L.getLineLength(n,i)<.2})},this.config=y.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)}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=y.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),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=y.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 S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=k.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=k.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===k.Start||this.dragStatus===k.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===k.Move&&this.history.pushHistory(this.pointList),this.dragStatus=k.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=k.Move;const s=this.getCoordinateUnderZoom(t),n=m.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),o=this.drawOutsideTarget?m.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):m.changePointByZoom(n,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===w.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!M.isInPolygon(o,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=o.x,a.y=o.y)}),this.render())}onKeyDown(t){if(!y.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Delete:this.deletePoint();break;case A.Tab:{this.onTabKeyDown(t);break}case A.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,n;if(!this.imgInfo)return;const{upperLimit:o}=this.config;if(o&&this.currentPageResult.length>=o){this.emit("messageInfo",`${N.getMessagesByLocale(P.LowerLimitPoint,this.lang)}`);return}const a=y.getSourceID(this.basicResult),l=this.getCoordinateUnderZoom(t);let h=m.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[w.Polygon,w.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const d=((i=this.referenceData)==null?void 0:i.toolName)===w.Polygon,{dropFoot:f}=M.getClosestPoint(h,this.referenceData.result,(n=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?n:T.Line,pt/this.zoom,{isClose:d});f&&(h=f,this.emit("messageSuccess",`${N.getMessagesByLocale(P.SuccessfulEdgeAdsorption,this.lang)}`))}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let u=!1;switch(this.dependToolName){case w.Rect:{u=!$.isInRect(h,this.basicResult);break}case w.Polygon:{u=!M.isInPolygon(h,this.basicResult.pointList);break}}if(u)return}if(l.x<0||l.y<0||l.x>this.imgInfo.width||l.y>this.imgInfo.height)return}if(this.isMinDistance(h))return;let c=le(Ft({},h),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:a,textAttribute:"",order:y.getMaxOrder(this.pointList.filter(u=>y.isSameSourceID(u.sourceID,a)))+1});if(this.config.textConfigurable){let u="";u=S.getTextAttribute(this.pointList.filter(d=>y.isSameSourceID(d.sourceID,a)),this.config.textCheckType),c=le(Ft({},c),{textAttribute:u})}if(this.hasMarkerConfig){const u=y.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(u)c=le(Ft({},c),{label:u.label}),this.markerIndex=u.index,this.emit("markIndexChange");else{this.emit("messageInfo",N.getMessagesByLocale(P.MarkerFinish,this.lang));return}}this.hoverID=c.id;const g=[...this.pointList,c];this.setPointList(g),this.history.pushHistory(g),this.setSelectedID(c.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(fi(t.x-e.x,2)+fi(t.y-e.y,2))}getHoverId(){var t;const e=m.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}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=y.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===k.Move||this.dragStatus===k.Start)return;let e=Y.ascend;t.shiftKey&&(e=Y.descend);const[i,s]=y.getRenderResultList(this.pointList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=y.getNextSelectedRectID(n,e,this.selectedID);o&&this.setSelectedID(o.id)}get currentPageResult(){const[t]=y.getRenderResultList(this.pointList,y.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=y.getRenderResultList(t,y.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.render())}undoAndRedo(t){var e,i;if(this.dragStatus===k.Move||this.dragStatus===k.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(n=>n.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(n=>n.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=k.Wait,{width:pi*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(S.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(d=>d.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:n,attribute:o,valid:a}=i,l=pi*this.zoom*.6,h=m.getOffsetCoordinate({x:s,y:n},this.currentPos,this.zoom),c=this.getColor(o),g=a?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributInstance||(this._textAttributInstance=new Ht({width:l,container:this.container,icon:this.getTextIconSvg(o),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:h.x,top:h.y+u,color:g,width:l})}renderPoint(t){var e,i,s;const{textAttribute:n="",attribute:o}=t,a=t.id===this.selectedID,l=this.getColor(o),h=m.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:g=!1}=this.style,u=tt.getStrokeAndFill(l,t.valid,{isSelected:a||t.id===this.hoverID});I.drawCircle(this.canvas,h,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:u.stroke,fill:u.fill});let d="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(d=`${t.order}`),t.label&&this.hasMarkerConfig&&(d=`${y.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${ae.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(d=`${d} ${S.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),g||I.drawText(this.canvas,{x:h.x+c/2,y:h.y-c-4},d,{textAlign:"center",color:u.stroke}),a?this.renderTextAttribute():g||I.drawText(this.canvas,{x:h.x+c,y:h.y+c+24},n,Ft({color:u.stroke},G))}renderPointList(){const[t,e]=y.getRenderResultList(this.pointList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let n=m.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const o=((t=this.referenceData)==null?void 0:t.toolName)===w.Polygon,{dropFoot:a}=M.getClosestPoint(n,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:T.Line,pt/this.zoom,{isClose:o});a&&n!==a&&n!==a&&(n=a,I.drawCircle(this.canvas,m.changePointByZoom(n,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),I.drawCircle(this.canvas,m.changePointByZoom(n,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}class xi extends st{constructor(t){super(t);this.getSingleResult=e=>{const i={};return this.config.configList.length>0&&this.config.configList.forEach(s=>{var n;i[s.key]=(n=s.default)!=null?n:""}),{value:i,id:J(),sourceID:e!=null?e:y.getSourceID()}},this.getInitResultList=(e,i)=>e>0?i.map(s=>this.getSingleResult(s.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var e;this.textList=t,this.toggleTextContainerVisible(!0);const i=(e=this.textList[0])==null?void 0:e.value;i&&Object.keys(i).forEach(s=>{this.renderText(s,i[s])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!i)}updateTextValue(t,e){this.textList[0].value[t]=e,this.renderText(t,e),this.emit("valueUpdated")}renderText(t,e){const i=document.getElementById(`textKey${t}`);i&&(i.innerText=e)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),e={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(e).reduce((i,s)=>(i+=`${s}: ${e[s]};`,i),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(i=>{const s=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");s.setAttribute("style","padding: 8px 16px"),n.innerText=`${i.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(i.key)),s.appendChild(n),s.appendChild(o),t.appendChild(s)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===A.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const e=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=e}}}var Zr=Object.defineProperty,Ur=Object.defineProperties,zr=Object.getOwnPropertyDescriptors,yi=Object.getOwnPropertySymbols,Vr=Object.prototype.hasOwnProperty,Wr=Object.prototype.propertyIsEnumerable,mi=(r,t,e)=>t in r?Zr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ii=(r,t)=>{for(var e in t||(t={}))Vr.call(t,e)&&mi(r,e,t[e]);if(yi)for(var e of yi(t))Wr.call(t,e)&&mi(r,e,t[e]);return r},jr=(r,t)=>Ur(r,zr(t));class y{static getStepInfo(t,e){return e==null?void 0:e.filter(i=>i.step===t)[0]}static getCurrentStepInfo(t,e){const i=this.getStepInfo(t,e);return i&&(i.type===Lt.QUALITY_INSPECTION||i.type===Lt.MANUAL_CORRECTION)?this.getCurrentStepInfo(i.dataSourceStep,e):i}static getMaxOrder(t){let e=0;return t.forEach(i=>{i.order&&i.order>e&&(e=i.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:i,type:s}=e;if(!i||!s)return!0;let n=!0;return(e.isContentEditable||i==="TEXTAREA"||(i==="INPUT"&&s!=="radio"||i==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getCurrentOperation(t){switch(t){case w.Rect:case w.RectTrack:return ue;case w.Tag:return li;case w.Polygon:return ai;case Rt.Check:return Pr;case w.Line:return ui;case w.Point:return bi;case w.Text:return xi;default:throw new Error("not match tool")}}static getNextSelectedRectID(t,e=Y.ascend,i){let s=1;e===Y.descend&&(s=-1);const n=t.sort((l,h)=>l.x-h.x==0?l.y-h.y:s*(l.x-h.x)),o=n.findIndex(l=>l.id===i),a=n.length;return n[(o+1)%a]}static getNextSelectedRectIDByEvent(t,e,i){const s=e.shiftKey?Y.descend:Y.ascend;return this.getNextSelectedRectID(t,s,i)}static getRenderResultList(t,e,i=[],s){let n;return[t.filter(a=>s&&s===(a==null?void 0:a.id)?(n=a,!1):!(i.length>0&&!i.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),n]}static getSourceID(t){var e;const i="";return t&&(e=t==null?void 0:t.id)!=null?e:i}static findAllLine(t,e=!0){const i=[],s=[...t];s.length>=3&&e===!0&&s.push(Ii({},s[0]));for(let n=0;n<s.length;n++)s[n+1]&&i.push({point1:s[n],point2:s[n+1],pointIndex:n});return i}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],i){if((e==null?void 0:e.length)===0)return;let s=e.map((n,o)=>jr(Ii({},n),{index:o}));if(typeof i=="number"&&i>0){const n=e[i];if(n&&t.every(o=>o.label!==n.value))return{label:n.value,index:i};s=[...s.slice(i,e.length),...s.slice(0,i)]}for(let n=0;n<s.length;n++)if(!t.some(o=>o.label===s[n].value))return{label:s[n].value,index:s[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(i=>t===i.value)}}y.jsonParser=(r,t={})=>{try{return typeof r=="string"?JSON.parse(r):Oi(r)?r:t}catch(e){return t}};var Xr=Object.defineProperty,wi=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,Li=(r,t,e)=>t in r?Xr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,he=(r,t)=>{for(var e in t||(t={}))Yr.call(t,e)&&Li(r,e,t[e]);if(wi)for(var e of wi(t))Gr.call(t,e)&&Li(r,e,t[e]);return r};class M{static getHoverPolygonID(t,e,i=3,s=T.Line){let n="",o=Infinity;const a=m.axisArea(t,i);return e.forEach(l=>{l.pointList&&a.forEach(h=>{const c=this.calcPolygonSize(l.pointList);this.isInPolygon(h,l.pointList,s)&&c<o&&(n=l.id,o=c)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,i=t.reduce((s,n,o,a)=>{const l=a[(o+1)%e];return s+n.x*l.y-l.x*n.y},0);return Math.abs(i)/2}static isInPolygon(t,e,i=T.Line){let s=0,n,o,a,l;e=[...e],i===T.Curve&&(e=this.createSmoothCurvePoints(e.reduce((c,g)=>[...c,g.x,g.y],[]),.5,!0,20)),[a]=e;const h=e.length;for(n=1;n<=h;n++)l=e[n%h],t.x>Math.min(a.x,l.x)&&t.x<=Math.max(a.x,l.x)&&t.y<=Math.max(a.y,l.y)&&a.x!==l.x&&(o=(t.x-a.x)*(l.y-a.y)/(l.x-a.x)+a.y,(a.y===l.y||t.y<=o)&&s++),a=l;return s%2!=0}static createSmoothCurvePointsFromPointList(t,e=X){return this.createSmoothCurvePoints(t.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!1,e).map((s,n)=>{var o;const a=n/(X+1),l=Math.floor(a),h=(o=t[l])!=null?o:{};return he(l===a?he({},h):{specialEdge:h.specialEdge},s)})}static createSmoothCurvePoints(t,e=.5,i=!1,s=X){if(t.length<4)return t;const n=[],o=t.slice(0);let a,l,h,c,g,u,d,f,v,p,b,x,C;for(i?(o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.push(t[0]),o.push(t[1])):(o.unshift(t[1]),o.unshift(t[0]),o.push(t[t.length-2]),o.push(t[t.length-1])),C=2;C<o.length-4;C+=2)for(h=(o[C+2]-o[C-2])*e,c=(o[C+4]-o[C-0])*e,g=(o[C+3]-o[C-1])*e,u=(o[C+5]-o[C+1])*e,x=0;x<=s;x++)b=x/s,d=2*Math.pow(b,3)-3*Math.pow(b,2)+1,f=-(2*Math.pow(b,3))+3*Math.pow(b,2),v=Math.pow(b,3)-2*Math.pow(b,2)+b,p=Math.pow(b,3)-Math.pow(b,2),a=d*o[C]+f*o[C+2]+v*h+p*c,l=d*o[C+1]+f*o[C+3]+v*g+p*u,n.push(a),n.push(l);const _=[];for(let D=0;D<n.length-1;D+=2)_.push({x:n[D],y:n[D+1]});if(i)for(let D=0;D<s+1;D++){const R=_.shift();_.push(R)}return _}static getPolygonByID(t,e){return t.find(i=>i.id===e)}static getHoverEdgeIndex(t,e,i=T.Line,s=3){let n=[...e];i===T.Curve?n=this.createSmoothCurvePoints(e.reduce((l,h)=>[...l,h.x,h.y],[]),.5,!0,X):i===T.Line&&n.push(n[0]);let o=-1,a=s;for(let l=0;l<n.length-1;l++){const{length:h}=L.getFootOfPerpendicular(t,n[l],n[l+1]);h<a&&(o=l,a=h)}return o===-1?-1:i===T.Curve?Math.floor(o/X):o}static getClosestPoint(t,e,i=T.Line,s=3,n){var o;const a=(o=n==null?void 0:n.isClose)!=null?o:!0;let l="",h=-1,c=Infinity,g=t;const u=20;let d=!1;return e.forEach(f=>{if(!d&&!!f.pointList)switch(i){case T.Line:y.findAllLine(f.pointList,a).forEach((p,b)=>{if(d)return;let{length:x,footPoint:C}=L.getFootOfPerpendicular(t,p.point1,p.point2);const _=L.getLineLength(p.point1,t),D=L.getLineLength(p.point2,t);_<s*2&&(C=p.point1,x=_,d=!0),D<s*2&&(C=p.point2,x=D,d=!0),x<c&&x<s&&(l=f.id,h=b,c=x,g=C)});break;case T.Curve:{const v=this.createSmoothCurvePoints(f.pointList.reduce((p,b)=>[...p,b.x,b.y],[]),.5,a,u);for(let p=0;p<v.length-1;p++){const{length:b,footPoint:x}=L.getFootOfPerpendicular(t,v[p],v[p+1]);b<c&&b<s&&(l=f.id,h=Math.floor(p/(u+1)),c=b,g=x)}}break}}),{dropFoot:g,closestEdgeIndex:h,closestPolygonID:l}}static isPointListInPolygon(t,e,i=T.Line){return t.every(s=>this.isInPolygon(s,e,i))}static isPointListOutSidePolygon(t,e,i=T.Line){return t.some(s=>!this.isInPolygon(s,e,i))}static getPolygonArea(t){let e=0;for(let i=0,s=t.length;i<s;i++){const n=t[i].x,o=t[i===t.length-1?0:i+1].y,a=t[i===t.length-1?0:i+1].x,l=t[i].y;e+=n*o*.5,e-=a*l*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,i){let s=1;return t===Pt.Anticlockwise&&(s=-1),s*=e,L.rotateRectPointList(s,i)}}var Kr=Object.defineProperty,Jr=Object.defineProperties,qr=Object.getOwnPropertyDescriptors,Pi=Object.getOwnPropertySymbols,Qr=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,Ci=(r,t,e)=>t in r?Kr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ce=(r,t)=>{for(var e in t||(t={}))Qr.call(t,e)&&Ci(r,e,t[e]);if(Pi)for(var e of Pi(t))tn.call(t,e)&&Ci(r,e,t[e]);return r},de=(r,t)=>Jr(r,qr(t));class m{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:a}=t;switch(e%360){case 90:return{x:n-a,y:o};case 180:return{x:s-o,y:n-a};case 270:return{x:a,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return de(ce({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return de(ce({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let a=s-e;a<s+e;a+=e/3)n.push({x:o,y:a});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class en{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===w.Polygon}get isDependRect(){return this.dependToolName===w.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:L.withinRange(t.x,[i,i+n]),y:L.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===T.Curve?M.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return O.calcOptimalIntersection(i,o,s,hr,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const a=this.getPolygonPointList(o,n);if(M.isInPolygon(t,a))return t;const h=a.concat(a[0]).map(g=>this.getRenderCoord(g)),c=this.getIntersection(t,e,h);return c?this.getAbsCoord(c==null?void 0:c.point):t}coordInsideImage(t){return this.coordInsideRect(t,de(ce({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return L.isInRange(t.x,o)&&L.isInRange(t.y,a)}return L.isInRange(t.x,[0,this.basicImgInfo.width])&&L.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return M.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}var sn=Object.defineProperty,rn=Object.defineProperties,nn=Object.getOwnPropertyDescriptors,Di=Object.getOwnPropertySymbols,on=Object.prototype.hasOwnProperty,an=Object.prototype.propertyIsEnumerable,_i=(r,t,e)=>t in r?sn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,H=(r,t)=>{for(var e in t||(t={}))on.call(t,e)&&_i(r,e,t[e]);if(Di)for(var e of Di(t))an.call(t,e)&&_i(r,e,t[e]);return r},U=(r,t)=>rn(r,nn(t));const Dt=6;class ue extends st{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),s=Dt,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&$.isInRect(i,a,s,this.zoom))return a.id}const o=n.filter(a=>$.isInRect(i,a,s,this.zoom));if(o.length===0)return"";if(o.length===1)return o[0].id;if(o.length>1)return o.map(l=>({size:l.width*l.height,id:l.id})).sort((l,h)=>l.size-h.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(S.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=y.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=y.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=y.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=y.getRenderResultList(t,y.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const s=this.selectedRectID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?U(H({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?m.returnClosePointIndex(this.getCoordinateUnderZoom(t),$.getRectPointList(this.selectedRect,this.zoom),Dt+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,s=$.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let o=0;o<s.length;o++){const a=s[o],{length:l}=L.getFootOfPerpendicular(n,a.begin,a.end);l<Dt+10&&(e=o)}return e}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),s=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!(!s||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const n=z.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=k.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=z.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=k.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const n=z.Plane;this.dragInfo={dragStartCoord:e,dragTarget:n,firstRect:s,startTime:+new Date},this.dragStatus=k.Start}}}onDragMove(t){var e,i,s,n,o,a;if(!this.dragInfo)return;this.dragStatus=k.Move;const l=$.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:c,width:g,height:u}=l,d={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};let f=this.rectList.filter(v=>v.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case z.Plane:f=U(H({},f),{x:h+d.x,y:c+d.y,width:g,height:u});break;case z.Point:{let v=h,p=c,b=g,x=u;switch(this.hoverRectPointIndex){case 0:{v=g-d.x<0?h+g:h+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(d.x-g),x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,p=u-d.y<0?c+u:c+d.y,b=Math.abs(g+d.x),x=Math.abs(u-d.y);break}case 2:{v=g+d.x>0?h:h+g+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(g+d.x),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,p=u+d.y>0?c:c+u+d.y,b=Math.abs(d.x-g),x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}default:return}f=U(H({},f),{x:v,y:p,width:b,height:x})}break;case z.Line:{let v=h,p=c,b=g,x=u;switch(this.hoverRectEdgeIndex){case 0:{p=u-d.y<0?c+u:c+d.y,x=Math.abs(d.y-u);break}case 1:{v=g+d.x>0?h:h+g+d.x,b=Math.abs(g+d.x);break}case 2:{p=u+d.y>0?c:c+u+d.y,x=u+d.y>0?u+d.y:Math.abs(u+d.y);break}case 3:{v=g-d.x<0?h+g:h+d.x,b=Math.abs(d.x-g);break}default:return}f=U(H({},f),{x:v,y:p,width:b,height:x});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&$.isRectNotInPolygon(f,Ie(this.basicResult.pointList,this.zoom)))return;const v=this.basicResult.x*this.zoom,p=this.basicResult.y*this.zoom,b=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==z.Plane&&(f.x<v-.01||f.y<p-.01||f.width>v+b-f.x+.01||f.height>p+x-f.y+.01))return;if(f.x<v&&(f.x=v),f.y<p&&(f.y=p),f.width>v+b-f.x)switch(this.dragInfo.dragTarget){case z.Plane:f.x=v+b-g;break;case z.Point:case z.Line:d.x>0&&d.y>0&&(f.width=v+b-f.x);break;default:return}if(f.height>p+x-f.y)switch(this.dragInfo.dragTarget){case z.Plane:f.y=p+x-u;break}}else if(f.x<0&&(f.x=0),f.y<0&&(f.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case z.Plane:f.x+f.width>((s=this.imgInfo)==null?void 0:s.width)&&(f.x=this.imgInfo.width-g),f.y+f.height>((n=this.imgInfo)==null?void 0:n.height)&&(f.y=this.imgInfo.height-u);break;default:if(f.x+f.width>((o=this.imgInfo)==null?void 0:o.width)+.01||f.y+f.height>((a=this.imgInfo)==null?void 0:a.height)+.01)return}}this.setRectList(this.rectList.map(v=>v.id===f.id?$.getRectUnderZoom(f,1/this.zoom):v)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),n=m.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedRectID&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const l=this.getHoverRectPointIndex(t);if(l!==this.hoverRectPointIndex){this.hoverRectPointIndex=l,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const o=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=o,o!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:l,y:h}=this.firstClickCoord,{width:c,height:g}=this.drawingRect;if(c=Math.abs(l-n.x),g=Math.abs(h-n.y),n.x<l&&(l=n.x),n.y<h&&(h=n.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&$.isRectNotInPolygon(U(H({},this.drawingRect),{x:l,y:h,width:c,height:g}),Ie(this.basicResult.pointList,this.zoom)))return;n.x<0&&(c=Math.abs(this.firstClickCoord.x),l=0),n.y<0&&(g=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(l+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-l)),h+g>this.imgInfo.height&&(g=Math.abs(this.imgInfo.height-h)))}this.drawingRect=U(H({},this.drawingRect),{x:l,y:h,width:c,height:g}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?U(H({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),s=m.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(s.x<0&&(s.x=0),s.y<0&&(s.y=0)),this.drawingRect=U(H({},s),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=y.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",N.getMessagesByLocale(P.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=S.getTextAttribute(this.rectList.filter(o=>y.isSameSourceID(o.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:y.getMaxOrder(this.rectList.filter(n=>y.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=H({},s),this.firstCurrentPos=H({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",N.getMessagesByLocale(P.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=k.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=k.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:s}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,s/=this.zoom,[...this.rectList,U(H({},this.drawingRect),{x:t,y:e,width:i,height:s})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(n=>n.id===e),{selectedRectID:s}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(s!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const n=y.getCurrentMarkerIndex(i.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===k.Move){this.dragInfo=void 0,this.dragStatus=k.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=y.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!y.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Ctrl:this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteRect(this.selectedRectID);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=Y.ascend;t.shiftKey&&(i=Y.descend);const[s,n]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let o=[...s];n&&(o=[...o,n]);const a=it.getViewPort(this.canvas,this.currentPos,this.zoom);o=o.filter(h=>it.inViewPort({x:h.x,y:h.y},a));const l=y.getNextSelectedRectID(o,i,this.selectedRectID);l&&(this.setSelectedRectID(l.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(l.attribute));break}default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,s;this.drawingRect&&this.firstClickCoord&&(i=$.getRectUnderZoom(this.drawingRect,1/e),s=m.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&s&&(this.drawingRect=$.getRectUnderZoom(i,this.zoom),this.firstClickCoord=m.changePointByZoom(s,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.getColor(t.attribute);let i,s;return t.valid===!1?(i=e==null?void 0:e.invalid.stroke,s=e==null?void 0:e.invalid.fill):(i=e==null?void 0:e.valid.stroke,s=e==null?void 0:e.valid.fill),{strokeColor:i,fillColor:s,textColor:i,toolColor:e}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:s,width:n,height:o,attribute:a,valid:l}=e,h=n*this.zoom*.6,c=m.getOffsetCoordinate({x:i,y:s+o},this.currentPos,this.zoom),g=this.getColor(a),u=l?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new Ht({width:h,container:this.container,icon:this.getTextIconSvg(a),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+d,color:u,width:h})}renderSelectedRect(t){const{selectedRect:e}=this;if(!this.ctx||!t||!e)return;const{ctx:i}=this;let s=10;const n=$.getRectPointList(e),o=n.length,a=this.getColor(t.attribute);n.forEach((l,h)=>{var c,g;if(i.save(),i.moveTo(l.x,l.y),i.beginPath(),this.hoverRectPointIndex===h?s=Dt+6:s=Dt,t.valid===!1?(i.strokeStyle=a==null?void 0:a.invalid.stroke,i.fillStyle=a==null?void 0:a.invalid.stroke):(i.strokeStyle=a==null?void 0:a.valid.stroke,i.fillStyle=a==null?void 0:a.valid.stroke),i.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),i.fill(),this.hoverRectEdgeIndex===h){i.beginPath(),i.lineWidth=10;const u=this.getColor(t.attribute),d=t.valid===!1?(c=u==null?void 0:u.invalid)==null?void 0:c.stroke:(g=u==null?void 0:u.valid)==null?void 0:g.stroke;i.strokeStyle=d,i.moveTo(n[h].x*this.zoom+this.currentPos.x,n[h].y*this.zoom+this.currentPos.y),i.lineTo(n[(h+1)%o].x*this.zoom+this.currentPos.x,n[(h+1)%o].y*this.zoom+this.currentPos.y),i.stroke()}i.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var s,n,o,a;if(this.ctx&&t){const{ctx:l,style:h}=this,{hiddenText:c=!1}=h;l.save();const{strokeColor:g,fillColor:u,textColor:d}=this.getRenderStyle(t);l.font="lighter 14px Arial";let f="";((s=this.config)==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${y.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${ae.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${S.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`);const v=m.changeRectByZoom(t,i?e:this.zoom,this.currentPos);c||I.drawText(this.canvas,{x:v.x,y:v.y-6},f,U(H({color:g,font:"normal normal 900 14px SourceHanSansCN-Regular"},ut),{textMaxWidth:300}));const p=(a=(o=this.style)==null?void 0:o.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID)&&I.drawRectWithFill(this.canvas,v,{color:u}),I.drawRect(this.canvas,v,{color:g,thickness:p,hiddenText:!0}),l.restore();let b=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(b=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const x=b.length*7;if(c||I.drawText(this.canvas,{x:v.x+v.width-x,y:v.y+v.height+15},b,H({color:d,font:"normal normal 600 14px Arial"},ut)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const C=0,_=Math.max(20,v.width-x);I.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+C},t.textAttribute,H({color:d,font:"italic normal 900 14px Arial",textMaxWidth:_},ut))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,s]=y.getRenderResultList(this.rectList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,m.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),s&&(this.renderDrawingRect(s),this.renderSelectedRect(s),e.selectedRender&&e.selectedRender(this.canvas,m.changeRectByZoom(s,this.zoom,this.currentPos),this.getRenderStyle(s)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,m.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(s=>s.id===this.selectedID?U(H({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=U(H({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=k.Wait,this.setSelectedRectID(void 0)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",N.getMessagesByLocale(P.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(s=>s.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",N.getMessagesByLocale(P.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(s=>s.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}var ln=Object.defineProperty,hn=Object.defineProperties,cn=Object.getOwnPropertyDescriptors,Ri=Object.getOwnPropertySymbols,dn=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable,Ai=(r,t,e)=>t in r?ln(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,gn=(r,t)=>{for(var e in t||(t={}))dn.call(t,e)&&Ai(r,e,t[e]);if(Ri)for(var e of Ri(t))un.call(t,e)&&Ai(r,e,t[e]);return r},fn=(r,t)=>hn(r,cn(t));const vn={textConfigurable:!1,attributeConfigurable:!0,attributeList:[]};class pn extends ue{constructor(t){super(fn(gn({},t),{config:JSON.stringify(vn)}))}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||this.setSelectedRectID(this.drawingRect.id)}}class bn{constructor(t){this._domMap=new Map,this._container=t.container,this._height=t.height}wheelChange(t){t.stopPropagation()}clearTag(t){const e=this._container,i=window.self.document.getElementById(t);i&&e&&e.contains(i)&&(i.removeEventListener("wheel",this.wheelChange),e==null||e.removeChild(i))}render(t){const e=Array.from(this._domMap.keys()),i=t.map(s=>s.id);t.forEach(s=>{const{text:n,textMaxWidth:o,color:a="white",background:l="rgba(0, 0, 0, 0.6)",style:h}=s;if(this._domMap.has(s.id)){const c=this._domMap.get(s.id);c&&(c.innerHTML=n)}else{const c=I.drawTagByDom(this._container,n,s.id);c&&(c.setAttribute("style",`
78
78
  position: absolute;
79
79
  top: 0;
80
80
  right: 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.7.2-alpha.0",
3
+ "version": "1.7.2-alpha.1",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",