@labelbee/lb-annotation 1.9.0 → 1.10.0-alpha.0

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),tool=require("../../constant/tool.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),MathUtils=require("../../utils/MathUtils.js"),basicToolOperation=require("./basicToolOperation.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(d){return d&&typeof d=="object"&&"default"in d?d:{default:d}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,e,t)=>e in d?__defProp(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t,__spreadValues=(d,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(d,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(d,t,e[t]);return d},__spreadProps=(d,e)=>__defProps(d,__getOwnPropDescs(e)),EStatus;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends basicToolOperation.BasicToolOperation{constructor(e){super(e);this.drawActivatedLine=(t,i,n)=>{const s=___default.default.cloneDeep(this.activeLine);if(!s||s.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});s.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l))),this.updateActiveArea(),this.drawLine(s,t,a,!0,!0),this.drawLineNumber(s[0],o,a,"",this.defaultAttribute,r),t&&this.isCreate&&this.arc(t,POINT_RADIUS,a),this.cursor&&!this.selectedPoint&&!n&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,a)},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.isLineSelected){const i=this.getPointList(this.activeLine),n=this.activeLine.find(r=>LineToolUtils.default.calcDistance(this.coordUtils.getRenderCoord(r),t)<=POINT_ACTIVE_RADIUS);let s;!n&&this.activeLine&&(s=this.findNearestPoint(i,t)),this.hoverPointID=n?n.id:void 0,this.cursor=n||s==null?void 0:s.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,i,n,s=!0,r=!1,o)=>{const h=polygonTool.createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=n.color,s&&(t.lineWidth=n.lineWidth),r&&LineToolUtils.default.setReferenceCtx(t),i.forEach(({specialEdge:a},l)=>{const u=h.splice(0,SEGMENT_NUMBER+1);t.save(),t.beginPath(),o===l&&(t.lineWidth=4),u.forEach(({x:c,y:f},g)=>{const L=g>0?"lineTo":"moveTo";a&&LineToolUtils.default.setSpecialEdgeStyle(t),t[L](c,f)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,i,n,s=!1,r=!1)=>{const o=i?t.concat(i):t,h={color:n,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.default.drawCurveLine(this.ctx,o,h,!s,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),s&&t.forEach(a=>{var l,u;const c=a.id,f=c&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(c)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(a,f,n),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(c)||this.arc(a,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(t,i,n=!1)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=i.color,s.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.default.setReferenceCtx(s),t.forEach((r,o)=>{if(s.beginPath(),o>0){const h=t[o-1];s.save(),(h==null?void 0:h.specialEdge)&&LineToolUtils.default.setSpecialEdgeStyle(s),n&&this.hoverLineSegmentIndex+1===o&&(s.lineWidth=4),s.moveTo(h.x,h.y),s.lineTo(r.x,r.y),s.stroke(),s.restore()}}),s.restore())},this.drawLines=()=>{try{const t=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(h=>Object.assign(h,this.coordUtils.getRenderCoord(h)));const{order:n,label:s}=i,r=n,o=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,o,!1),this.drawLineNumber(i.pointList[0],r,o,s,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],o,i==null?void 0:i.textAttribute)}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,i)=>{var n;if(!Array.isArray(this.activeLine))return!1;((n=this.activeLine)==null?void 0:n.every(r=>this.isInBasicPolygon({x:r.x+t,y:r.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(t,i))},this.moveLineInRectRange=(t,i,n,s)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(v=>___default.default.isNumber(v)?v+t:0),u=[r,a].map(v=>___default.default.isNumber(v)?v+i:0),c=o>=0&&h&&MathUtils.default.isInRange(l,n),f=r>=0&&a&&MathUtils.default.isInRange(u,s),g=c?t:0,L=f?i:0;this.lineDragging=!0,this.moveActiveArea(g,L)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(t),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const t=this.lineList.find(n=>n.id===this.selectedID),i=t==null?void 0:t.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=t=>{const i=this.getCoordinate(t),{lineDragging:n}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const r=this.findHoverLine(i);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const s=this.getNextPoint(t,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(s);return}if(this.isActive){if(n)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(s);return}if(t.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&t.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,t.keyCode===keyCode.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(t.keyCode===keyCode.Delete){this.deleteLine();return}if(t.keyCode===keyCode.F){this.setInvalidLine(this.selectedID);return}if(t.keyCode===keyCode.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)},this.onRightDblClick=t=>{super.onRightDblClick(t);const i=this.getCoordinate(t);if(this.isActive){const n=this.findHoveredPoint(i);if(n){this.deleteSelectedLinePoint(n.id);return}this.deleteSelectedLine(i)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const i=t.length!==this.lineListLen;this.lineList=t,i&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(e.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.dependToolConfig={lineType:tool.ELineTypes.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===tool.ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===tool.ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===tool.EToolName.Polygon}get isDependRect(){return this.dependToolName===tool.EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(e=>this.attributeLockList.includes((e==null?void 0:e.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 e=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var i;return(i=t==null?void 0:t.pointList)==null?void 0:i.some(n=>CanvasUtils.inViewPort(n,e))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var e,t;return(t=(e=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(e,t=!1){if(e!==this.status){if(t){let i="";this.textCheckType===tool.ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.default.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=e,this.lineStatusChanged()}}isInBasicPolygon(e){var t,i;return polygonTool.isInPolygon(e,((t=this.basicResult)==null?void 0:t.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:e}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===tool.ELineTypes.Curve?polygonTool.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20):e}getNextCoordByRenderCoord(e){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(e))}getNextCoordByAbsCoord(e){var t;const i=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(e,i):e}pointInLine(e,t,i){return e.filter(n=>n).length<2?!1:e.some((n,s)=>{if(s===0)return!1;const r=this.coordUtils.getRenderCoord(e[s-1]),o=this.coordUtils.getRenderCoord(n);return LineToolUtils.default.isInLine(t,r,o,i)})}arc(e,t=POINT_RADIUS,i){var n,s,r,o,h,a;if(this.ctx){const{x:l,y:u}=e;(n=this.ctx)==null||n.save(),(s=this.ctx)==null||s.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,u,t,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:e,left:t,right:i,bottom:n}=this.activeArea,{x:s,y:r}=this.coordUtils.getRenderCoord({x:t,y:e});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(s,r,(i-t)*this.zoom,(n-e)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(e){var t,i,n,s;this.arc(e),(t=this.activeLine)==null||t.push(__spreadProps(__spreadValues({},e),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(n=this.actionsHistory)==null||n.initRecord(this.activeLine):(s=this.actionsHistory)==null||s.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(e,t=!1){this.updateStatus(0,t),this.addLinePoint(e)}isActiveLineValid(){var e;return this.selectedID?(e=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:e.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(e,t=!1){return StyleUtils.getStrokeAndFill(this.getColor(e.attribute),e.valid,{isSelected:t}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?MathUtils.default.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom):void 0}drawLineNumber(e,t=1,i,n="",s,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?t.toString():`${n}`;if(this.attributeConfigurable){const u=s?(a=(h=(o=this.attributeList)==null?void 0:o.find(c=>c.value===s))==null?void 0:h.key)!=null?a:s:"";l=[l,`${!r&&u?"\u65E0\u6548":""}${u}`].filter(c=>c).join("_")}this.drawText(e,l,i)}}drawLineTextAttribute(e,t,i){if(e&&i)return this.drawText(e,i,t,200)}drawText(e,t,i,n){var s,r;this.ctx&&((s=this.ctx)==null||s.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,n?DrawUtils.wrapText(this.canvas,t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y,n):this.ctx.fillText(t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y),(r=this.ctx)==null||r.restore())}moveActiveArea(e,t){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+t,bottom:this.activeArea.bottom+t,right:this.activeArea.right+e,left:this.activeArea.left+e})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+e,y:i.y+t})),this.updateLines())}findHoveredPoint(e){if(!!this.activeLine)return this.activeLine.find(t=>{const i=this.coordUtils.getRenderCoord(t);return LineToolUtils.default.calcDistance(i,e)<=POINT_ACTIVE_RADIUS})}findHoverLine(e){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const n=i?this.getPointList(i):[],s=this.getLineWidthScope();return n.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(n[o-1]);return LineToolUtils.default.isInLine(e,h,a,s)})})}getAdsorptionPoint(e){let t,i,n;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:s,id:r})=>{if(r===this.selectedID||!s||(s==null?void 0:s.length)<2)return;const o=this.findNearestPoint(s,e);if(o){if(o.minDistance===0){t=o.point;return}(i===void 0||o.minDistance<i)&&(t=o.point,i=o.minDistance)}}),n||t}findNearestPoint(e,t,i=7){let n;const s=i;for(let r=1;r<=e.length-1;r++){const o=this.coordUtils.getRenderCoord(e[r]),h=this.coordUtils.getRenderCoord(e[r-1]),{length:a,footPoint:l}=MathUtils.default.getFootOfPerpendicular(t,o,h),u=LineToolUtils.default.calcTwoPointDistance(o,t),c=LineToolUtils.default.calcTwoPointDistance(h,t);if(u<=i*2){n=o,i=0;break}if(c<=i*2){n=h,i=0;break}a<i&&(n=l,i=a)}return n?{point:n,minDistance:s}:void 0}getPointList(e){return this.isCurve?polygonTool.createSmoothCurvePointsFromPointList(e,SEGMENT_NUMBER):e}moveSelectedLine(e){const t=(e.x-this.prevAxis.x)/this.zoom,i=(e.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,i);return}if(this.isDependPolygon){this.moveLineInPolygon(t,i);return}let n=[0,this.imageSize.width],s=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;n=[r,r+h],s=[o,o+a]}this.moveLineInRectRange(t,i,n,s)}moveSelectPoint(e){if(!this.selectedPoint)return;const t=e.x-this.prevAxis.x,i=e.y-this.prevAxis.y,n=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,s=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,r={x:n,y:s};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(e,t){var i;const n=!!e.shiftKey,s=e.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&n){const r=this.activeLine.slice(-1)[0];return LineToolUtils.default.getVHPoint(r,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!s?this.getAdsorptionPoint(t):t}getNextPoint(e,t){const i=this.getCoordByConfig(e,t)||t;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(e){const t=this.getCoordinate(e),i=e.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(e,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!e.altKey)){const n=this.getAdsorptionPoint(t);n&&this.arc(n)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(e){if(super.onMouseMove(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);this.mouseMoveHandler(e),this.prevAxis=t}setActiveArea(e,t=!1){const i=this.findHoverLine(e);if(i){const n=this.lineList.findIndex(o=>o.id===(i==null?void 0:i.id)),s=MathUtils.default.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom),r=this.lineList[n];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=s,this.updateLineAttributes(r)}else t&&this.setNoneStatus();this.render()}setActiveLineByID(e){const t=this.lineList.find(i=>i.id===e);if(t){const i=MathUtils.default.calcViewportBoundaries((t==null?void 0:t.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom);this.updateStatus(1),this.setActiveLine(t.pointList),this.setSelectedLineID(t.id),this.activeArea=i,this.updateLineAttributes(t)}this.render()}setActiveLine(e){this.activeLine=e?___default.default.cloneDeep(e):void 0}historyChanged(e){const t=`${e}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const i=this.actionsHistory&&this.actionsHistory[e]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[t]){const i=this.history[e](),n=i==null?void 0:i.find(s=>s.id===this.selectedID);this.lineList=i,this.selectedID&&n?this.setActiveLine(n==null?void 0:n.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(e){if(this.isDependPolygon)return this.isInBasicPolygon(e);if(this.isDependRect){const{x:t,y:i,width:n,height:s}=this.basicResult,r=[t,t+n],o=[i,i+s];return MathUtils.default.isInRange(e.x,r)&&MathUtils.default.isInRange(e.y,o)}return MathUtils.default.isInRange(e.x,[0,this.imageSize.width])&&MathUtils.default.isInRange(e.y,[0,this.imageSize.height])}getPointInsertIndex(e,t){if(e&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((n,s)=>{if(s>0){const r=this.activeLine?this.activeLine[s-1]:void 0,o=this.isCurve?i.slice((s-1)*(SEGMENT_NUMBER+1),s*(SEGMENT_NUMBER+1)):[r,n];return this.pointInLine(o,e,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var e;return this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(e){const t=this.getPointInsertIndex(e,2)-1;if(t>-1){const i=this.activeLine[t];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var e;const t=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&i&&(this.activeLine.splice(t,0,__spreadProps(__spreadValues({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(e){if(super.onMouseDown(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);if(this.isMousedown=!0,this.prevAxis=t,e.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.isActive&&this.activeArea?LineToolUtils.default.inArea(this.activeArea,this.coordUtils.getAbsCoord(t)):!1,this.lineDragging=!1}lineHasChanged(){const e=this.lineList.find(t=>t.id===this.selectedID);return e?JSON.stringify(e.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const e=this.lineList.find(t=>t.id===this.selectedID);e&&(e.pointList=___default.default.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(e){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(e)||this.forbidMouseOperation||!this.imgInfo){t();return}e.which===1&&this.onLeftClick(e),e.which===3&&this.onRightClick(e),t()}isTextValid(e){return AttributeUtils.default.textAttributeValidate(this.textCheckType,this.customFormat,e)}createLineData(){const e=uuid(),t={pointList:___default.default.cloneDeep(this.activeLine),id:e,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(e=!0){var t,i,n,s;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(e){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),(n=this.history)==null||n.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(s=this.actionsHistory)==null||s.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(e){const t=e?this.lineList.find(i=>i.id===e):void 0;if(t){const i=t==null?void 0:t.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(e)}else this.setNoneStatus()}setNoneStatus(e=!0){e&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(e,t){this.isShift=t!=null?t:e.keyCode===keyCode.Shift}continueToEdit(){var e;this.updateStatus(0),this.cursor=void 0,(e=this.actionsHistory)==null||e.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(e){if(this.selectedID&&e.keyCode!==keyCode.Ctrl||!this.isCreate)return;const t=!e.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(e){if(super.onKeyDown(e),this.setKeyDownStatus(e),e.keyCode===keyCode.Z&&!e.ctrlKey&&this.toggleIsHide(),e.keyCode===keyCode.Shift&&this.render(),e.keyCode===keyCode.Tab){e.preventDefault(),this.selectToNextLine(e);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(e),this.config.attributeConfigurable){const t=AttributeUtils.default.getAttributeByKeycode(e.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(e){const t=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var n,s,r,o;return __spreadProps(__spreadValues({},i),{x:(s=(n=i.pointList[0])==null?void 0:n.x)!=null?s:0,y:(o=(r=i.pointList[0])==null?void 0:r.y)!=null?o:0})}),e,this.selectedID);t&&this.setActiveLineByID(t.id)}keyboardEventWhileLineCreating(e){!this.isCreate||(e.keyCode===keyCode.Ctrl&&this.setInvalidLineOnCreating(e),[keyCode.Shift,keyCode.Alt].includes(e.keyCode)&&this.renderNextPoint(e,this.prevAxis))}renderNextPoint(e,t){const i=this.coordUtils.getRenderCoord(this.getNextPoint(e,t));this.render(i)}deleteSelectedLine(e){const t=MathUtils.default.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.default.inArea(t,this.coordUtils.getAbsCoord(e))&&this.deleteLine()}deleteSelectedLinePoint(e){var t;this.pointsWithinRange(this.activeLine.length-1)&&e&&(this.setActiveLine(this.activeLine.filter(n=>n.id!==e)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var e;this.lineList=this.lineList.filter(t=>t.id!==this.selectedID),(e=this.history)==null||e.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(e,t,i=!0){var n;const s=this.lineList.find(r=>r.id===e);s&&(s.valid=t!==void 0?t:!s.valid,(n=this.history)==null||n.pushHistory(this.lineList),i&&this.render())}empty(){var e,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(e=this.actionsHistory)==null||e.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(e){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(e){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",e),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",e))}setLineAttribute(e,t,i){const n=i||this.selectedID;if(n){const s=this.lineList.find(r=>r.id===n);s&&(s[e]=t)}this.render()}updateAttribute(e){this.emit("updateAttribute",e)}updateLineAttributes(e){var t;if(this.attributeConfigurable&&e){const i=(e==null?void 0:e.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&e){const i=(e==null?void 0:e.textAttribute)||"";this.updateTextAttribute(i)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(e){if(this.selectedID){const t=this.lineList.find(i=>i.id===this.selectedID);t&&(t.textAttribute=e)}this.emit("updateText",e)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(e){this.textEditingID=e,this.render()}setSelectedLineID(e){var t,i;if(this.selectedID===e)return;const n=this.selectedID;e!==n&&n&&((t=this._textAttributeInstance)==null||t.changeSelected()),e||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=e,this.emit("selectedChange")}attributeLockListChange(e){this.attributeLockList=e,this.render()}setResult(e){this.setNoneStatus(),this.setLineList(e),this.render()}setConfig(e){super.setConfig(e)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(e=""){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var e,t;const i=this.isActiveLineValid(),n=this.defaultAttribute,s=this.getColor(n),r=i?s==null?void 0:s.valid.stroke:s==null?void 0:s.invalid.stroke,o=(t=(e=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:"";return{color:r,textAttribute:o}}renderTextAttribute(){var e,t,i,n;if(!this.ctx||!this.activeLine||((e=this.activeLine)==null?void 0:e.length)<2||this.isCreate)return;const s=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),u=s?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,c=(i=(t=this.lineList.find(f=>f.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({container:this.container,icon:this.getTextIconSvg(r),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((n=this._textAttributeInstance)==null?void 0:n.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${c}`,{left:a.x,top:a.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(e=""){return AttributeUtils.default.getTextIconSvg(e,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(e){if(this._textAttributeInstance&&e&&this.selectedID){let t=e;!AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}exports.INNER_POINT_RADIUS=INNER_POINT_RADIUS,exports.LINE_ORDER_OFFSET=LINE_ORDER_OFFSET,exports.POINT_ACTIVE_RADIUS=POINT_ACTIVE_RADIUS,exports.POINT_RADIUS=POINT_RADIUS,exports.SEGMENT_NUMBER=SEGMENT_NUMBER,exports.default=LineToolOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),tool=require("../../constant/tool.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),MathUtils=require("../../utils/MathUtils.js"),basicToolOperation=require("./basicToolOperation.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(d){return d&&typeof d=="object"&&"default"in d?d:{default:d}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,e,t)=>e in d?__defProp(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t,__spreadValues=(d,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(d,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(d,t,e[t]);return d},__spreadProps=(d,e)=>__defProps(d,__getOwnPropDescs(e)),EStatus;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends basicToolOperation.BasicToolOperation{constructor(e){super(e);this.drawActivatedLine=(t,i,n)=>{const s=___default.default.cloneDeep(this.activeLine);if(!s||s.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});s.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l))),this.isActive&&this.drawLineLength(s,a),this.updateActiveArea(),this.drawLine(s,t,a,!0,!0),this.drawLineNumber(s[0],o,a,"",this.defaultAttribute,r),t&&this.isCreate&&this.arc(t,POINT_RADIUS,a),this.cursor&&!this.selectedPoint&&!n&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,a)},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.isLineSelected){const i=this.getPointList(this.activeLine),n=this.activeLine.find(r=>LineToolUtils.default.calcDistance(this.coordUtils.getRenderCoord(r),t)<=POINT_ACTIVE_RADIUS);let s;!n&&this.activeLine&&(s=this.findNearestPoint(i,t)),this.hoverPointID=n?n.id:void 0,this.cursor=n||s==null?void 0:s.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,i,n,s=!0,r=!1,o)=>{const h=polygonTool.createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=n.color,s&&(t.lineWidth=n.lineWidth),r&&LineToolUtils.default.setReferenceCtx(t),i.forEach(({specialEdge:a},l)=>{const u=h.splice(0,SEGMENT_NUMBER+1);t.save(),t.beginPath(),o===l&&(t.lineWidth=4),u.forEach(({x:c,y:f},g)=>{const L=g>0?"lineTo":"moveTo";a&&LineToolUtils.default.setSpecialEdgeStyle(t),t[L](c,f)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,i,n,s=!1,r=!1)=>{const o=i?t.concat(i):t,h={color:n,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.default.drawCurveLine(this.ctx,o,h,!s,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),s&&t.forEach(a=>{var l,u;const c=a.id,f=c&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(c)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(a,f,n),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(c)||this.arc(a,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(t,i,n=!1)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=i.color,s.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.default.setReferenceCtx(s),t.forEach((r,o)=>{if(s.beginPath(),o>0){const h=t[o-1];s.save(),(h==null?void 0:h.specialEdge)&&LineToolUtils.default.setSpecialEdgeStyle(s),n&&this.hoverLineSegmentIndex+1===o&&(s.lineWidth=4),s.moveTo(h.x,h.y),s.lineTo(r.x,r.y),s.stroke(),s.restore()}}),s.restore())},this.drawLines=()=>{try{const t=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:n,label:s}=i,r=n,o=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,o,!1),this.drawLineNumber(i.pointList[0],r,o,s,i.attribute,i.valid),i.id!==this.textEditingID&&(this.drawLineTextAttribute(i.pointList[1],o,i==null?void 0:i.textAttribute),this.drawLineLength(i.pointList,o))}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,i)=>{var n;if(!Array.isArray(this.activeLine))return!1;((n=this.activeLine)==null?void 0:n.every(r=>this.isInBasicPolygon({x:r.x+t,y:r.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(t,i))},this.moveLineInRectRange=(t,i,n,s)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(v=>___default.default.isNumber(v)?v+t:0),u=[r,a].map(v=>___default.default.isNumber(v)?v+i:0),c=o>=0&&h&&MathUtils.default.isInRange(l,n),f=r>=0&&a&&MathUtils.default.isInRange(u,s),g=c?t:0,L=f?i:0;this.lineDragging=!0,this.moveActiveArea(g,L)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(t),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const t=this.lineList.find(n=>n.id===this.selectedID),i=t==null?void 0:t.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=t=>{const i=this.getCoordinate(t),{lineDragging:n}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const r=this.findHoverLine(i);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const s=this.getNextPoint(t,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(s);return}if(this.isActive){if(n)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(s);return}if(t.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&t.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,t.keyCode===keyCode.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(t.keyCode===keyCode.Delete){this.deleteLine();return}if(t.keyCode===keyCode.F){this.setInvalidLine(this.selectedID);return}if(t.keyCode===keyCode.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)},this.onRightDblClick=t=>{super.onRightDblClick(t);const i=this.getCoordinate(t);if(this.isActive){const n=this.findHoveredPoint(i);if(n){this.deleteSelectedLinePoint(n.id);return}this.deleteSelectedLine(i)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const i=t.length!==this.lineListLen;this.lineList=t,i&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(e.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.dependToolConfig={lineType:tool.ELineTypes.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===tool.ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===tool.ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===tool.EToolName.Polygon}get isDependRect(){return this.dependToolName===tool.EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(e=>this.attributeLockList.includes((e==null?void 0:e.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget}get showOrder(){var e;return(e=this.config.showOrder)!=null?e:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const e=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var i;return(i=t==null?void 0:t.pointList)==null?void 0:i.some(n=>CanvasUtils.inViewPort(n,e))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var e,t;return(t=(e=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(e,t=!1){if(e!==this.status){if(t){let i="";this.textCheckType===tool.ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.default.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=e,this.lineStatusChanged()}}isInBasicPolygon(e){var t,i;return polygonTool.isInPolygon(e,((t=this.basicResult)==null?void 0:t.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:e}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===tool.ELineTypes.Curve?polygonTool.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20):e}getNextCoordByRenderCoord(e){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(e))}getNextCoordByAbsCoord(e){var t;const i=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(e,i):e}pointInLine(e,t,i){return e.filter(n=>n).length<2?!1:e.some((n,s)=>{if(s===0)return!1;const r=this.coordUtils.getRenderCoord(e[s-1]),o=this.coordUtils.getRenderCoord(n);return LineToolUtils.default.isInLine(t,r,o,i)})}arc(e,t=POINT_RADIUS,i){var n,s,r,o,h,a;if(this.ctx){const{x:l,y:u}=e;(n=this.ctx)==null||n.save(),(s=this.ctx)==null||s.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,u,t,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:e,left:t,right:i,bottom:n}=this.activeArea,{x:s,y:r}=this.coordUtils.getRenderCoord({x:t,y:e});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(s,r,(i-t)*this.zoom,(n-e)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(e){var t,i,n,s;this.arc(e),(t=this.activeLine)==null||t.push(__spreadProps(__spreadValues({},e),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(n=this.actionsHistory)==null||n.initRecord(this.activeLine):(s=this.actionsHistory)==null||s.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(e,t=!1){this.updateStatus(0,t),this.addLinePoint(e)}isActiveLineValid(){var e;return this.selectedID?(e=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:e.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(e,t=!1){return StyleUtils.getStrokeAndFill(this.getColor(e.attribute),e.valid,{isSelected:t}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?MathUtils.default.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom):void 0}drawLineNumber(e,t=1,i,n="",s,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?t.toString():`${n}`;if(this.attributeConfigurable){const u=s?(a=(h=(o=this.attributeList)==null?void 0:o.find(c=>c.value===s))==null?void 0:h.key)!=null?a:s:"";l=[l,`${!r&&u?"\u65E0\u6548":""}${u}`].filter(c=>c).join("_")}this.drawText(e,l,i)}}drawLineTextAttribute(e,t,i){if(e&&i)return this.drawText(e,i,t,200)}drawLineLength(e,t){var i;if(((i=this.config)==null?void 0:i.showLineLength)&&e){const n=e.reduce((r,o,h)=>h<=0||!e[h-1].actual||!o.actual?r:r+LineToolUtils.default.calcDistance(e[h-1].actual,o.actual),0),s=e[e.length-1];this.drawText(s,`l = ${n.toFixed(2)}`,t)}}drawText(e,t,i,n){var s,r;this.ctx&&((s=this.ctx)==null||s.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,n?DrawUtils.wrapText(this.canvas,t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y,n):this.ctx.fillText(t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y),(r=this.ctx)==null||r.restore())}moveActiveArea(e,t){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+t,bottom:this.activeArea.bottom+t,right:this.activeArea.right+e,left:this.activeArea.left+e})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+e,y:i.y+t})),this.updateLines())}findHoveredPoint(e){if(!!this.activeLine)return this.activeLine.find(t=>{const i=this.coordUtils.getRenderCoord(t);return LineToolUtils.default.calcDistance(i,e)<=POINT_ACTIVE_RADIUS})}findHoverLine(e){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const n=i?this.getPointList(i):[],s=this.getLineWidthScope();return n.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(n[o-1]);return LineToolUtils.default.isInLine(e,h,a,s)})})}getAdsorptionPoint(e){let t,i,n;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:s,id:r})=>{if(r===this.selectedID||!s||(s==null?void 0:s.length)<2)return;const o=this.findNearestPoint(s,e);if(o){if(o.minDistance===0){t=o.point;return}(i===void 0||o.minDistance<i)&&(t=o.point,i=o.minDistance)}}),n||t}findNearestPoint(e,t,i=7){let n;const s=i;for(let r=1;r<=e.length-1;r++){const o=this.coordUtils.getRenderCoord(e[r]),h=this.coordUtils.getRenderCoord(e[r-1]),{length:a,footPoint:l}=MathUtils.default.getFootOfPerpendicular(t,o,h),u=LineToolUtils.default.calcTwoPointDistance(o,t),c=LineToolUtils.default.calcTwoPointDistance(h,t);if(u<=i*2){n=o,i=0;break}if(c<=i*2){n=h,i=0;break}a<i&&(n=l,i=a)}return n?{point:n,minDistance:s}:void 0}getPointList(e){return this.isCurve?polygonTool.createSmoothCurvePointsFromPointList(e,SEGMENT_NUMBER):e}moveSelectedLine(e){const t=(e.x-this.prevAxis.x)/this.zoom,i=(e.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,i);return}if(this.isDependPolygon){this.moveLineInPolygon(t,i);return}let n=[0,this.imageSize.width],s=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;n=[r,r+h],s=[o,o+a]}this.moveLineInRectRange(t,i,n,s)}moveSelectPoint(e){if(!this.selectedPoint)return;const t=e.x-this.prevAxis.x,i=e.y-this.prevAxis.y,n=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,s=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,r={x:n,y:s};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(e,t){var i;const n=!!e.shiftKey,s=e.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&n){const r=this.activeLine.slice(-1)[0];return LineToolUtils.default.getVHPoint(r,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!s?this.getAdsorptionPoint(t):t}getNextPoint(e,t){const i=this.getCoordByConfig(e,t)||t;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(e){const t=this.getCoordinate(e),i=e.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(e,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!e.altKey)){const n=this.getAdsorptionPoint(t);n&&this.arc(n)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(e){if(super.onMouseMove(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);this.mouseMoveHandler(e),this.prevAxis=t}setActiveArea(e,t=!1){const i=this.findHoverLine(e);if(i){const n=this.lineList.findIndex(o=>o.id===(i==null?void 0:i.id)),s=MathUtils.default.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom),r=this.lineList[n];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=s,this.updateLineAttributes(r)}else t&&this.setNoneStatus();this.render()}setActiveLineByID(e){const t=this.lineList.find(i=>i.id===e);if(t){const i=MathUtils.default.calcViewportBoundaries((t==null?void 0:t.pointList)||[],this.isCurve,SEGMENT_NUMBER,this.zoom);this.updateStatus(1),this.setActiveLine(t.pointList),this.setSelectedLineID(t.id),this.activeArea=i,this.updateLineAttributes(t)}this.render()}setActiveLine(e){this.activeLine=e?___default.default.cloneDeep(e):void 0}historyChanged(e){const t=`${e}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const i=this.actionsHistory&&this.actionsHistory[e]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[t]){const i=this.history[e](),n=i==null?void 0:i.find(s=>s.id===this.selectedID);this.lineList=i,this.selectedID&&n?this.setActiveLine(n==null?void 0:n.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(e){if(this.isDependPolygon)return this.isInBasicPolygon(e);if(this.isDependRect){const{x:t,y:i,width:n,height:s}=this.basicResult,r=[t,t+n],o=[i,i+s];return MathUtils.default.isInRange(e.x,r)&&MathUtils.default.isInRange(e.y,o)}return MathUtils.default.isInRange(e.x,[0,this.imageSize.width])&&MathUtils.default.isInRange(e.y,[0,this.imageSize.height])}getPointInsertIndex(e,t){if(e&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((n,s)=>{if(s>0){const r=this.activeLine?this.activeLine[s-1]:void 0,o=this.isCurve?i.slice((s-1)*(SEGMENT_NUMBER+1),s*(SEGMENT_NUMBER+1)):[r,n];return this.pointInLine(o,e,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var e;return this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(e){const t=this.getPointInsertIndex(e,2)-1;if(t>-1){const i=this.activeLine[t];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var e;const t=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&i&&(this.activeLine.splice(t,0,__spreadProps(__spreadValues({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(e){if(super.onMouseDown(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);if(this.isMousedown=!0,this.prevAxis=t,e.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.isActive&&this.activeArea?LineToolUtils.default.inArea(this.activeArea,this.coordUtils.getAbsCoord(t)):!1,this.lineDragging=!1}lineHasChanged(){const e=this.lineList.find(t=>t.id===this.selectedID);return e?JSON.stringify(e.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const e=this.lineList.find(t=>t.id===this.selectedID);e&&(e.pointList=___default.default.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(e){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(e)||this.forbidMouseOperation||!this.imgInfo){t();return}e.which===1&&this.onLeftClick(e),e.which===3&&this.onRightClick(e),t()}isTextValid(e){return AttributeUtils.default.textAttributeValidate(this.textCheckType,this.customFormat,e)}createLineData(){const e=uuid(),t={pointList:___default.default.cloneDeep(this.activeLine),id:e,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(e=!0){var t,i,n,s;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(e){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),(n=this.history)==null||n.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(s=this.actionsHistory)==null||s.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(e){const t=e?this.lineList.find(i=>i.id===e):void 0;if(t){const i=t==null?void 0:t.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(e)}else this.setNoneStatus()}setNoneStatus(e=!0){e&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(e,t){this.isShift=t!=null?t:e.keyCode===keyCode.Shift}continueToEdit(){var e;this.updateStatus(0),this.cursor=void 0,(e=this.actionsHistory)==null||e.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(e){if(this.selectedID&&e.keyCode!==keyCode.Ctrl||!this.isCreate)return;const t=!e.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(e){if(super.onKeyDown(e),this.setKeyDownStatus(e),e.keyCode===keyCode.Z&&!e.ctrlKey&&this.toggleIsHide(),e.keyCode===keyCode.Shift&&this.render(),e.keyCode===keyCode.Tab){e.preventDefault(),this.selectToNextLine(e);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(e),this.config.attributeConfigurable){const t=AttributeUtils.default.getAttributeByKeycode(e.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(e){const t=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var n,s,r,o;return __spreadProps(__spreadValues({},i),{x:(s=(n=i.pointList[0])==null?void 0:n.x)!=null?s:0,y:(o=(r=i.pointList[0])==null?void 0:r.y)!=null?o:0})}),e,this.selectedID);t&&this.setActiveLineByID(t.id)}keyboardEventWhileLineCreating(e){!this.isCreate||(e.keyCode===keyCode.Ctrl&&this.setInvalidLineOnCreating(e),[keyCode.Shift,keyCode.Alt].includes(e.keyCode)&&this.renderNextPoint(e,this.prevAxis))}renderNextPoint(e,t){const i=this.coordUtils.getRenderCoord(this.getNextPoint(e,t));this.render(i)}deleteSelectedLine(e){const t=MathUtils.default.calcViewportBoundaries(this.activeLine,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.default.inArea(t,this.coordUtils.getAbsCoord(e))&&this.deleteLine()}deleteSelectedLinePoint(e){var t;this.pointsWithinRange(this.activeLine.length-1)&&e&&(this.setActiveLine(this.activeLine.filter(n=>n.id!==e)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var e;this.lineList=this.lineList.filter(t=>t.id!==this.selectedID),(e=this.history)==null||e.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(e,t,i=!0){var n;const s=this.lineList.find(r=>r.id===e);s&&(s.valid=t!==void 0?t:!s.valid,(n=this.history)==null||n.pushHistory(this.lineList),i&&this.render())}empty(){var e,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(e=this.actionsHistory)==null||e.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(e){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(e){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",e),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",e))}setLineAttribute(e,t,i){const n=i||this.selectedID;if(n){const s=this.lineList.find(r=>r.id===n);s&&(s[e]=t)}this.render()}updateAttribute(e){this.emit("updateAttribute",e)}updateLineAttributes(e){var t;if(this.attributeConfigurable&&e){const i=(e==null?void 0:e.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&e){const i=(e==null?void 0:e.textAttribute)||"";this.updateTextAttribute(i)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(e){if(this.selectedID){const t=this.lineList.find(i=>i.id===this.selectedID);t&&(t.textAttribute=e)}this.emit("updateText",e)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(e){this.textEditingID=e,this.render()}setSelectedLineID(e){var t,i;if(this.selectedID===e)return;const n=this.selectedID;e!==n&&n&&((t=this._textAttributeInstance)==null||t.changeSelected()),e||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=e,this.emit("selectedChange")}attributeLockListChange(e){this.attributeLockList=e,this.render()}setResult(e){this.setNoneStatus(),this.setLineList(e),this.render()}setConfig(e){super.setConfig(e)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(e=""){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var e,t;const i=this.isActiveLineValid(),n=this.defaultAttribute,s=this.getColor(n),r=i?s==null?void 0:s.valid.stroke:s==null?void 0:s.invalid.stroke,o=(t=(e=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:"";return{color:r,textAttribute:o}}renderTextAttribute(){var e,t,i,n;if(!this.ctx||!this.activeLine||((e=this.activeLine)==null?void 0:e.length)<2||this.isCreate)return;const s=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),u=s?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,c=(i=(t=this.lineList.find(f=>f.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({container:this.container,icon:this.getTextIconSvg(r),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((n=this._textAttributeInstance)==null?void 0:n.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${c}`,{left:a.x,top:a.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(e=""){return AttributeUtils.default.getTextIconSvg(e,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(e){if(this._textAttributeInstance&&e&&this.selectedID){let t=e;!AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}exports.INNER_POINT_RADIUS=INNER_POINT_RADIUS,exports.LINE_ORDER_OFFSET=LINE_ORDER_OFFSET,exports.POINT_ACTIVE_RADIUS=POINT_ACTIVE_RADIUS,exports.POINT_RADIUS=POINT_RADIUS,exports.SEGMENT_NUMBER=SEGMENT_NUMBER,exports.default=LineToolOperation;
@@ -1 +1 @@
1
- "use strict";var annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),polygonOperation=require("./polygonOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,e)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues=(r,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(r,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(r,e,t[e]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var o;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=StyleUtils.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,o;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=StyleUtils.getStrokeAndFill(a,e.valid),d=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(d)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),o=this.currentPolygonListByPattern.map(n=>__spreadProps(__spreadValues({},n),{pointList:AxisUtils.default.changePointListByZoom(n.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(s,o,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var o,n,a,l;return __spreadProps(__spreadValues({},i),{x:(n=(o=i.pointList[0])==null?void 0:o.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}module.exports=PointCloud2dOperation;
1
+ "use strict";var annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),polygonOperation=require("./polygonOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,e)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues=(r,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(r,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(r,e,t[e]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var o;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=StyleUtils.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,o;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=StyleUtils.getStrokeAndFill(a,e.valid),d=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(d)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),o=this.currentPolygonListByPattern.map(n=>__spreadProps(__spreadValues({},n),{pointList:AxisUtils.default.changePointListByZoom(n.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(s,o,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var o,n,a,l;return __spreadProps(__spreadValues({},i),{x:(n=(o=i.pointList[0])==null?void 0:o.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.selectedIDs=t?[t]:[],this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}module.exports=PointCloud2dOperation;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),annotation$1=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),index$1=require("./core/pointCloud/index.js"),annotation=require("./core/pointCloud/annotation.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js");function _interopNamespaceDefaultOnly(o){return Object.freeze({__proto__:null,default:o})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.cAnnotation=annotation$1,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.cTool=tool,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils,exports.MathUtils=MathUtils.default,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.PointCloud=index$1.PointCloud,exports.PointCloudAnnotation=annotation.PointCloudAnnotation,exports.UnitUtils=UnitUtils,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),annotation$1=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),index$1=require("./core/pointCloud/index.js"),annotation=require("./core/pointCloud/annotation.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js");function _interopNamespaceDefaultOnly(o){return Object.freeze({__proto__:null,default:o})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.cAnnotation=annotation$1,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.cTool=tool,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils,exports.MathUtils=MathUtils.default,exports.ActionsHistory=ActionsHistory,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.PointCloud=index$1.PointCloud,exports.PointCloudAnnotation=annotation.PointCloudAnnotation,exports.UnitUtils=UnitUtils,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
@@ -269,6 +269,20 @@ export declare class PointCloud {
269
269
  y: number;
270
270
  z: number;
271
271
  }[];
272
+ /**
273
+ * Box to 2d Coordinate.
274
+ *
275
+ * Flow:
276
+ * 1. Model Translation
277
+ * 2. View Translation
278
+ * 3. Projection Translation
279
+ * 4. Viewport Translation
280
+ *
281
+ *
282
+ * @param boxParams
283
+ * @param perspectiveView
284
+ * @returns
285
+ */
272
286
  getBoxPolygon2DCoordinate(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView): {
273
287
  polygon2d: THREE.Vector3[];
274
288
  zoom: number;
@@ -284,7 +298,8 @@ export declare class PointCloud {
284
298
  x: number;
285
299
  y: number;
286
300
  z: number;
287
- }, offsetWidth: number, offsetDepth: number, selectedPointCloudBox: IPointCloudBox): {
301
+ }, // Just use x now.
302
+ offsetWidth: number, offsetDepth: number, selectedPointCloudBox: IPointCloudBox): {
288
303
  newBoxParams: IPointCloudBox;
289
304
  };
290
305
  getNewBoxByBackUpdate(offsetCenterPoint: {
@@ -84,6 +84,12 @@ declare class LineToolOperation extends BasicToolOperation {
84
84
  get isCurrentAttributeLocked(): boolean;
85
85
  get attributeFilteredLines(): ILine[];
86
86
  get enableOutOfTarget(): any;
87
+ /**
88
+ * Judgement of showing Order.
89
+ *
90
+ * Origin Config of LineTool: showOrder.
91
+ * Configurable of other tools: isShowOrder.
92
+ */
87
93
  get showOrder(): any;
88
94
  get edgeAdsorption(): any;
89
95
  get attributeList(): any;
@@ -195,6 +201,12 @@ declare class LineToolOperation extends BasicToolOperation {
195
201
  * @param color
196
202
  */
197
203
  drawLineTextAttribute(coord: ICoordinate, color: string, text?: string): void;
204
+ /**
205
+ * Draw the text of lineLength
206
+ *
207
+ * It will be controlled by showLineLength.
208
+ */
209
+ drawLineLength(pointList: ILinePoint[], color: string): void;
198
210
  drawText(coord: ICoordinate, text: string, color: string, lineWidth?: number): void;
199
211
  /**
200
212
  * 更新热区
@@ -23,6 +23,7 @@ import AxisUtils from './utils/tool/AxisUtils';
23
23
  import DrawUtils from './utils/tool/DrawUtils';
24
24
  import ImgUtils from './utils/ImgUtils';
25
25
  import MathUtils from './utils/MathUtils';
26
+ import ActionsHistory from './utils/ActionsHistory';
26
27
  import DblClickEventListener from './utils/tool/DblClickEventListener';
27
28
  import AnnotationEngine from './core';
28
29
  import { PointCloud } from './core/pointCloud';
@@ -30,5 +31,5 @@ import { PointCloudAnnotation } from './core/pointCloud/annotation';
30
31
  import UnitUtils from './utils/tool/UnitUtils';
31
32
  declare const CommonToolUtils: typeof EnhanceCommonToolUtils;
32
33
  declare const toolUtils: typeof EnhanceCommonToolUtils;
33
- export { RectOperation, TagOperation, PointOperation, LineToolOperation, PolygonOperation, TextToolOperation, BasicToolOperation, MeasureOperation, ViewOperation, PointCloud2dOperation, PointCloudAnnotation, cAnnotation, cAnnotationTask, cKeyCode, cStyle, cTool, toolUtils, uuid, DblClickEventListener, CommonToolUtils, MarkerUtils, RectUtils, AxisUtils, TagUtils, DrawUtils, ImgUtils, MathUtils, AnnotationEngine, ScribbleTool, PointCloud, UnitUtils, };
34
+ export { RectOperation, TagOperation, PointOperation, LineToolOperation, PolygonOperation, TextToolOperation, BasicToolOperation, MeasureOperation, ViewOperation, PointCloud2dOperation, PointCloudAnnotation, cAnnotation, cAnnotationTask, cKeyCode, cStyle, cTool, toolUtils, uuid, DblClickEventListener, CommonToolUtils, MarkerUtils, RectUtils, AxisUtils, TagUtils, DrawUtils, ImgUtils, MathUtils, AnnotationEngine, ScribbleTool, PointCloud, UnitUtils, ActionsHistory, };
34
35
  export * from './newCore';
@@ -1 +1 @@
1
- import g from"lodash";import{ELineTypes as D,ELineColor as U,EToolName as w,ETextType as B}from"../../constant/tool.js";import M from"../../utils/ActionsHistory.js";import S from"../../utils/uuid.js";import f from"../../constant/keyCode.js";import L from"../../utils/MathUtils.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import v from"../../utils/tool/LineToolUtils.js";import{createSmoothCurvePointsFromPointList as R,isInPolygon as j,createSmoothCurvePoints as W}from"../../utils/tool/polygonTool.js";import z from"../../utils/tool/CommonToolUtils.js";import N from"../../utils/tool/CanvasUtils.js";import K from"../../utils/tool/DrawUtils.js";import F from"../../utils/tool/StyleUtils.js";import b from"../../utils/tool/AttributeUtils.js";import $ from"./textAttributeClass.js";var J=Object.defineProperty,q=Object.defineProperties,G=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,k=(d,i,t)=>i in d?J(d,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[i]=t,T=(d,i)=>{for(var t in i||(i={}))Y.call(i,t)&&k(d,t,i[t]);if(O)for(var t of O(i))Z.call(i,t)&&k(d,t,i[t]);return d},_=(d,i)=>q(d,G(i)),E;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(E||(E={}));const p=16,y={x:0,y:20},m=3,x=5,H=2;class Q extends V{constructor(i){super(i);this.drawActivatedLine=(t,e,n)=>{const s=g.cloneDeep(this.activeLine);if(!s||s.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});s.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l))),this.updateActiveArea(),this.drawLine(s,t,a,!0,!0),this.drawLineNumber(s[0],o,a,"",this.defaultAttribute,r),t&&this.isCreate&&this.arc(t,m,a),this.cursor&&!this.selectedPoint&&!n&&!this.isShift&&this.arc(this.cursor,x,a)},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.isLineSelected){const e=this.getPointList(this.activeLine),n=this.activeLine.find(r=>v.calcDistance(this.coordUtils.getRenderCoord(r),t)<=x);let s;!n&&this.activeLine&&(s=this.findNearestPoint(e,t)),this.hoverPointID=n?n.id:void 0,this.cursor=n||s==null?void 0:s.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,e,n,s=!0,r=!1,o)=>{const h=R(e,p);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=n.color,s&&(t.lineWidth=n.lineWidth),r&&v.setReferenceCtx(t),e.forEach(({specialEdge:a},l)=>{const c=h.splice(0,p+1);t.save(),t.beginPath(),o===l&&(t.lineWidth=4),c.forEach(({x:u,y:A},I)=>{const P=I>0?"lineTo":"moveTo";a&&v.setSpecialEdgeStyle(t),t[P](u,A)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,e,n,s=!1,r=!1)=>{const o=e?t.concat(e):t,h={color:n,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?v.drawCurveLine(this.ctx,o,h,!s,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),s&&t.forEach(a=>{var l,c;const u=a.id,A=u&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(u)?x:m;this.arc(a,A,n),[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)||this.arc(a,H,"white")})},this.drawStraightLine=(t,e,n=!1)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=e.color,s.lineWidth=e.lineWidth,this.isReference&&v.setReferenceCtx(s),t.forEach((r,o)=>{if(s.beginPath(),o>0){const h=t[o-1];s.save(),(h==null?void 0:h.specialEdge)&&v.setSpecialEdgeStyle(s),n&&this.hoverLineSegmentIndex+1===o&&(s.lineWidth=4),s.moveTo(h.x,h.y),s.lineTo(r.x,r.y),s.stroke(),s.restore()}}),s.restore())},this.drawLines=()=>{try{const t=g.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(e=>{if(e.id!==this.selectedID&&e.pointList){e.pointList.map(h=>Object.assign(h,this.coordUtils.getRenderCoord(h)));const{order:n,label:s}=e,r=n,o=e&&this.getLineColorByAttribute(e);this.drawLine(e.pointList,void 0,o,!1),this.drawLineNumber(e.pointList[0],r,o,s,e.attribute,e.valid),e.id!==this.textEditingID&&this.drawLineTextAttribute(e.pointList[1],o,e==null?void 0:e.textAttribute)}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,e)=>{var n;if(!Array.isArray(this.activeLine))return!1;((n=this.activeLine)==null?void 0:n.every(r=>this.isInBasicPolygon({x:r.x+t,y:r.y+e})))&&(this.lineDragging=!0,this.moveActiveArea(t,e))},this.moveLineInRectRange=(t,e,n,s)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(C=>g.isNumber(C)?C+t:0),c=[r,a].map(C=>g.isNumber(C)?C+e:0),u=o>=0&&h&&L.isInRange(l,n),A=r>=0&&a&&L.isInRange(c,s),I=u?t:0,P=A?e:0;this.lineDragging=!0,this.moveActiveArea(I,P)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(t),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const t=this.lineList.find(n=>n.id===this.selectedID),e=t==null?void 0:t.attribute;typeof e=="string"&&(this.defaultAttribute=e,this.updateAttribute(e),this.render())}},this.onLeftClick=t=>{const e=this.getCoordinate(t),{lineDragging:n}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const r=this.findHoverLine(e);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const s=this.getNextPoint(t,e);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(s);return}if(this.isActive){if(n)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(s);return}if(t.shiftKey){this.updateLineSegmentSpecial(e);return}if(this.coordsInsideActiveArea&&t.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,t.keyCode===f.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(t.keyCode===f.Delete){this.deleteLine();return}if(t.keyCode===f.F){this.setInvalidLine(this.selectedID);return}if(t.keyCode===f.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)},this.onRightDblClick=t=>{super.onRightDblClick(t);const e=this.getCoordinate(t);if(this.isActive){const n=this.findHoveredPoint(e);if(n){this.deleteSelectedLinePoint(n.id);return}this.deleteSelectedLine(e)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const e=t.length!==this.lineListLen;this.lineList=t,e&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(i.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new M,this.dependToolConfig={lineType:D.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===D.Curve}get isMultipleColor(){return this.config.lineColor===U.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===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(i=>this.attributeLockList.includes((i==null?void 0:i.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 i=N.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var e;return(e=t==null?void 0:t.pointList)==null?void 0:e.some(n=>N.inViewPort(n,i))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var i,t;return(t=(i=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:i.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(i,t=!1){if(i!==this.status){if(t){let e="";this.textCheckType===B.Order&&this.isTextConfigurable&&(e=b.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",e)}this.status=i,this.lineStatusChanged()}}isInBasicPolygon(i){var t,e;return j(i,((t=this.basicResult)==null?void 0:t.pointList)||[],(e=this.dependToolConfig)==null?void 0:e.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:i}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===D.Curve?W(i.reduce((e,n)=>[...e,n.x,n.y],[]),.5,!0,20):i}getNextCoordByRenderCoord(i){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(i))}getNextCoordByAbsCoord(i){var t;const e=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return e?this.coordUtils.getNextCoordByDependTool(i,e):i}pointInLine(i,t,e){return i.filter(n=>n).length<2?!1:i.some((n,s)=>{if(s===0)return!1;const r=this.coordUtils.getRenderCoord(i[s-1]),o=this.coordUtils.getRenderCoord(n);return v.isInLine(t,r,o,e)})}arc(i,t=m,e){var n,s,r,o,h,a;if(this.ctx){const{x:l,y:c}=i;(n=this.ctx)==null||n.save(),(s=this.ctx)==null||s.beginPath(),this.ctx.fillStyle=e||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,c,t,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:i,left:t,right:e,bottom:n}=this.activeArea,{x:s,y:r}=this.coordUtils.getRenderCoord({x:t,y:i});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(s,r,(e-t)*this.zoom,(n-i)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(i){var t,e,n,s;this.arc(i),(t=this.activeLine)==null||t.push(_(T({},i),{id:S()})),((e=this.activeLine)==null?void 0:e.length)===1?(n=this.actionsHistory)==null||n.initRecord(this.activeLine):(s=this.actionsHistory)==null||s.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(i,t=!1){this.updateStatus(0,t),this.addLinePoint(i)}isActiveLineValid(){var i;return this.selectedID?(i=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:i.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(i,t=!1){return F.getStrokeAndFill(this.getColor(i.attribute),i.valid,{isSelected:t}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom):void 0}drawLineNumber(i,t=1,e,n="",s,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?t.toString():`${n}`;if(this.attributeConfigurable){const c=s?(a=(h=(o=this.attributeList)==null?void 0:o.find(u=>u.value===s))==null?void 0:h.key)!=null?a:s:"";l=[l,`${!r&&c?"\u65E0\u6548":""}${c}`].filter(u=>u).join("_")}this.drawText(i,l,e)}}drawLineTextAttribute(i,t,e){if(i&&e)return this.drawText(i,e,t,200)}drawText(i,t,e,n){var s,r;this.ctx&&((s=this.ctx)==null||s.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=e,this.ctx.strokeStyle=e,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,n?K.wrapText(this.canvas,t,i.x-y.x,i.y-y.y,n):this.ctx.fillText(t,i.x-y.x,i.y-y.y),(r=this.ctx)==null||r.restore())}moveActiveArea(i,t){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+t,bottom:this.activeArea.bottom+t,right:this.activeArea.right+i,left:this.activeArea.left+i})),this.activeLine&&(this.activeLine.map(e=>Object.assign(e,{x:e.x+i,y:e.y+t})),this.updateLines())}findHoveredPoint(i){if(!!this.activeLine)return this.activeLine.find(t=>{const e=this.coordUtils.getRenderCoord(t);return v.calcDistance(e,i)<=x})}findHoverLine(i){return g.cloneDeep(this.lineList).reverse().find(({pointList:e})=>{const n=e?this.getPointList(e):[],s=this.getLineWidthScope();return n.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(n[o-1]);return v.isInLine(i,h,a,s)})})}getAdsorptionPoint(i){let t,e,n;return g.cloneDeep(this.lineList).reverse().forEach(({pointList:s,id:r})=>{if(r===this.selectedID||!s||(s==null?void 0:s.length)<2)return;const o=this.findNearestPoint(s,i);if(o){if(o.minDistance===0){t=o.point;return}(e===void 0||o.minDistance<e)&&(t=o.point,e=o.minDistance)}}),n||t}findNearestPoint(i,t,e=7){let n;const s=e;for(let r=1;r<=i.length-1;r++){const o=this.coordUtils.getRenderCoord(i[r]),h=this.coordUtils.getRenderCoord(i[r-1]),{length:a,footPoint:l}=L.getFootOfPerpendicular(t,o,h),c=v.calcTwoPointDistance(o,t),u=v.calcTwoPointDistance(h,t);if(c<=e*2){n=o,e=0;break}if(u<=e*2){n=h,e=0;break}a<e&&(n=l,e=a)}return n?{point:n,minDistance:s}:void 0}getPointList(i){return this.isCurve?R(i,p):i}moveSelectedLine(i){const t=(i.x-this.prevAxis.x)/this.zoom,e=(i.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,e);return}if(this.isDependPolygon){this.moveLineInPolygon(t,e);return}let n=[0,this.imageSize.width],s=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;n=[r,r+h],s=[o,o+a]}this.moveLineInRectRange(t,e,n,s)}moveSelectPoint(i){if(!this.selectedPoint)return;const t=i.x-this.prevAxis.x,e=i.y-this.prevAxis.y,n=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,s=(this.selectedPoint?this.selectedPoint.y:0)+e/this.zoom,r={x:n,y:s};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(i,t){var e;const n=!!i.shiftKey,s=i.altKey;if(((e=this.activeLine)==null?void 0:e.length)>0&&n){const r=this.activeLine.slice(-1)[0];return v.getVHPoint(r,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!s?this.getAdsorptionPoint(t):t}getNextPoint(i,t){const e=this.getCoordByConfig(i,t)||t;return this.enableOutOfTarget?e:this.getNextCoordByRenderCoord(e)}lineHover(){this.render()}mouseMoveHandler(i){const t=this.getCoordinate(i),e=i.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(i,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!i.altKey)){const n=this.getAdsorptionPoint(t);n&&this.arc(n)}if(this.isActive){if(this.isMousedown&&e){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(i){if(super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(i);this.mouseMoveHandler(i),this.prevAxis=t}setActiveArea(i,t=!1){const e=this.findHoverLine(i);if(e){const n=this.lineList.findIndex(o=>o.id===(e==null?void 0:e.id)),s=L.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,p,this.zoom),r=this.lineList[n];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=s,this.updateLineAttributes(r)}else t&&this.setNoneStatus();this.render()}setActiveLineByID(i){const t=this.lineList.find(e=>e.id===i);if(t){const e=L.calcViewportBoundaries((t==null?void 0:t.pointList)||[],this.isCurve,p,this.zoom);this.updateStatus(1),this.setActiveLine(t.pointList),this.setSelectedLineID(t.id),this.activeArea=e,this.updateLineAttributes(t)}this.render()}setActiveLine(i){this.activeLine=i?g.cloneDeep(i):void 0}historyChanged(i){const t=`${i}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const e=this.actionsHistory&&this.actionsHistory[i]();this.setActiveLine(e),this.render()}return}if(this.history&&this.history[t]){const e=this.history[i](),n=e==null?void 0:e.find(s=>s.id===this.selectedID);this.lineList=e,this.selectedID&&n?this.setActiveLine(n==null?void 0:n.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(i){if(this.isDependPolygon)return this.isInBasicPolygon(i);if(this.isDependRect){const{x:t,y:e,width:n,height:s}=this.basicResult,r=[t,t+n],o=[e,e+s];return L.isInRange(i.x,r)&&L.isInRange(i.y,o)}return L.isInRange(i.x,[0,this.imageSize.width])&&L.isInRange(i.y,[0,this.imageSize.height])}getPointInsertIndex(i,t){if(i&&this.activeLine){const e=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((n,s)=>{if(s>0){const r=this.activeLine?this.activeLine[s-1]:void 0,o=this.isCurve?e.slice((s-1)*(p+1),s*(p+1)):[r,n];return this.pointInLine(o,i,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var i;return this.activeLine&&((i=this.activeLine)==null?void 0:i.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(i){const t=this.getPointInsertIndex(i,2)-1;if(t>-1){const e=this.activeLine[t];e.specialEdge=!e.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var i;const t=this.getPointInsertIndex(this.cursor),e=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&e&&(this.activeLine.splice(t,0,_(T({},this.coordUtils.getAbsCoord(this.cursor)),{id:S()})),this.updateLines(),(i=this.history)==null||i.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(i){if(super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(i);if(this.isMousedown=!0,this.prevAxis=t,i.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.isActive&&this.activeArea?v.inArea(this.activeArea,this.coordUtils.getAbsCoord(t)):!1,this.lineDragging=!1}lineHasChanged(){const i=this.lineList.find(t=>t.id===this.selectedID);return i?JSON.stringify(i.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const i=this.lineList.find(t=>t.id===this.selectedID);i&&(i.pointList=g.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(i){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo){t();return}i.which===1&&this.onLeftClick(i),i.which===3&&this.onRightClick(i),t()}isTextValid(i){return b.textAttributeValidate(this.textCheckType,this.customFormat,i)}createLineData(){const i=S(),t={pointList:g.cloneDeep(this.activeLine),id:i,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(i=!0){var t,e,n,s;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(i){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=g.cloneWith(this.activeLine),g.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(e=this.history)==null||e.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),(n=this.history)==null||n.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(s=this.actionsHistory)==null||s.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(i){const t=i?this.lineList.find(e=>e.id===i):void 0;if(t){const e=t==null?void 0:t.pointList;this.updateStatus(1),this.setActiveLine(e),this.setSelectedLineID(i)}else this.setNoneStatus()}setNoneStatus(i=!0){i&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(i,t){this.isShift=t!=null?t:i.keyCode===f.Shift}continueToEdit(){var i;this.updateStatus(0),this.cursor=void 0,(i=this.actionsHistory)==null||i.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(i){if(this.selectedID&&i.keyCode!==f.Ctrl||!this.isCreate)return;const t=!i.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(i){if(super.onKeyDown(i),this.setKeyDownStatus(i),i.keyCode===f.Z&&!i.ctrlKey&&this.toggleIsHide(),i.keyCode===f.Shift&&this.render(),i.keyCode===f.Tab){i.preventDefault(),this.selectToNextLine(i);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(i),this.config.attributeConfigurable){const t=b.getAttributeByKeycode(i.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(i){const t=z.getNextSelectedRectIDByEvent(this.viewPortLines.map(e=>{var n,s,r,o;return _(T({},e),{x:(s=(n=e.pointList[0])==null?void 0:n.x)!=null?s:0,y:(o=(r=e.pointList[0])==null?void 0:r.y)!=null?o:0})}),i,this.selectedID);t&&this.setActiveLineByID(t.id)}keyboardEventWhileLineCreating(i){!this.isCreate||(i.keyCode===f.Ctrl&&this.setInvalidLineOnCreating(i),[f.Shift,f.Alt].includes(i.keyCode)&&this.renderNextPoint(i,this.prevAxis))}renderNextPoint(i,t){const e=this.coordUtils.getRenderCoord(this.getNextPoint(i,t));this.render(e)}deleteSelectedLine(i){const t=L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom);v.inArea(t,this.coordUtils.getAbsCoord(i))&&this.deleteLine()}deleteSelectedLinePoint(i){var t;this.pointsWithinRange(this.activeLine.length-1)&&i&&(this.setActiveLine(this.activeLine.filter(n=>n.id!==i)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var i;this.lineList=this.lineList.filter(t=>t.id!==this.selectedID),(i=this.history)==null||i.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(i,t,e=!0){var n;const s=this.lineList.find(r=>r.id===i);s&&(s.valid=t!==void 0?t:!s.valid,(n=this.history)==null||n.pushHistory(this.lineList),e&&this.render())}empty(){var i,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(i=this.actionsHistory)==null||i.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(i){var t;this.attributeConfigurable&&(this.defaultAttribute=i,this.setLineAttribute("attribute",i),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(i){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",i),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",i))}setLineAttribute(i,t,e){const n=e||this.selectedID;if(n){const s=this.lineList.find(r=>r.id===n);s&&(s[i]=t)}this.render()}updateAttribute(i){this.emit("updateAttribute",i)}updateLineAttributes(i){var t;if(this.attributeConfigurable&&i){const e=(i==null?void 0:i.attribute)||"";this.defaultAttribute=e,this.updateAttribute(e)}if(this.isTextConfigurable&&i){const e=(i==null?void 0:i.textAttribute)||"";this.updateTextAttribute(e)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(i){if(this.selectedID){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.textAttribute=i)}this.emit("updateText",i)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(i){this.textEditingID=i,this.render()}setSelectedLineID(i){var t,e;if(this.selectedID===i)return;const n=this.selectedID;i!==n&&n&&((t=this._textAttributeInstance)==null||t.changeSelected()),i||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=i,this.emit("selectedChange")}attributeLockListChange(i){this.attributeLockList=i,this.render()}setResult(i){this.setNoneStatus(),this.setLineList(i),this.render()}setConfig(i){super.setConfig(i)}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(i=""){var t;this.attributeConfigurable&&(this.defaultAttribute=i,this.setLineAttribute("attribute",i),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var i,t;const e=this.isActiveLineValid(),n=this.defaultAttribute,s=this.getColor(n),r=e?s==null?void 0:s.valid.stroke:s==null?void 0:s.invalid.stroke,o=(t=(i=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:i.textAttribute)!=null?t:"";return{color:r,textAttribute:o}}renderTextAttribute(){var i,t,e,n;if(!this.ctx||!this.activeLine||((i=this.activeLine)==null?void 0:i.length)<2||this.isCreate)return;const s=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),c=s?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,u=(e=(t=this.lineList.find(A=>A.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";this._textAttributeInstance||(this._textAttributeInstance=new $({container:this.container,icon:this.getTextIconSvg(r),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((n=this._textAttributeInstance)==null?void 0:n.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:a.x,top:a.y,color:c}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(i=""){return b.getTextIconSvg(i,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(i){if(this._textAttributeInstance&&i&&this.selectedID){let t=i;!b.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}export{H as INNER_POINT_RADIUS,y as LINE_ORDER_OFFSET,x as POINT_ACTIVE_RADIUS,m as POINT_RADIUS,p as SEGMENT_NUMBER,Q as default};
1
+ import g from"lodash";import{ELineTypes as D,ELineColor as U,EToolName as w,ETextType as B}from"../../constant/tool.js";import M from"../../utils/ActionsHistory.js";import S from"../../utils/uuid.js";import f from"../../constant/keyCode.js";import L from"../../utils/MathUtils.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import v from"../../utils/tool/LineToolUtils.js";import{createSmoothCurvePointsFromPointList as R,isInPolygon as j,createSmoothCurvePoints as W}from"../../utils/tool/polygonTool.js";import z from"../../utils/tool/CommonToolUtils.js";import N from"../../utils/tool/CanvasUtils.js";import F from"../../utils/tool/DrawUtils.js";import K from"../../utils/tool/StyleUtils.js";import b from"../../utils/tool/AttributeUtils.js";import $ from"./textAttributeClass.js";var J=Object.defineProperty,q=Object.defineProperties,G=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,k=(d,i,t)=>i in d?J(d,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[i]=t,_=(d,i)=>{for(var t in i||(i={}))Y.call(i,t)&&k(d,t,i[t]);if(O)for(var t of O(i))Z.call(i,t)&&k(d,t,i[t]);return d},T=(d,i)=>q(d,G(i)),E;(function(d){d[d.Create=0]="Create",d[d.Active=1]="Active",d[d.None=2]="None"})(E||(E={}));const p=16,C={x:0,y:20},m=3,x=5,H=2;class Q extends V{constructor(i){super(i);this.drawActivatedLine=(t,e,n)=>{const s=g.cloneDeep(this.activeLine);if(!s||s.length===0)return;const r=this.isActiveLineValid();let o;const h=this.selectedID?this.lineList.find(l=>l.id===this.selectedID):void 0;h?o=h.order:o=this.nextOrder();const a=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!r});s.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l))),this.isActive&&this.drawLineLength(s,a),this.updateActiveArea(),this.drawLine(s,t,a,!0,!0),this.drawLineNumber(s[0],o,a,"",this.defaultAttribute,r),t&&this.isCreate&&this.arc(t,m,a),this.cursor&&!this.selectedPoint&&!n&&!this.isShift&&this.arc(this.cursor,x,a)},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.isLineSelected){const e=this.getPointList(this.activeLine),n=this.activeLine.find(r=>v.calcDistance(this.coordUtils.getRenderCoord(r),t)<=x);let s;!n&&this.activeLine&&(s=this.findNearestPoint(e,t)),this.hoverPointID=n?n.id:void 0,this.cursor=n||s==null?void 0:s.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,e,n,s=!0,r=!1,o)=>{const h=R(e,p);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=n.color,s&&(t.lineWidth=n.lineWidth),r&&v.setReferenceCtx(t),e.forEach(({specialEdge:a},l)=>{const c=h.splice(0,p+1);t.save(),t.beginPath(),o===l&&(t.lineWidth=4),c.forEach(({x:u,y:A},I)=>{const P=I>0?"lineTo":"moveTo";a&&v.setSpecialEdgeStyle(t),t[P](u,A)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,e,n,s=!1,r=!1)=>{const o=e?t.concat(e):t,h={color:n,lineWidth:r?1:this.lineStyle.lineWidth};this.isCurve?v.drawCurveLine(this.ctx,o,h,!s,this.isReference,r?this.hoverLineSegmentIndex:-1):this.drawStraightLine(o,h,r),s&&t.forEach(a=>{var l,c;const u=a.id,A=u&&[this.hoverPointID,(l=this.selectedPoint)==null?void 0:l.id].includes(u)?x:m;this.arc(a,A,n),[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(u)||this.arc(a,H,"white")})},this.drawStraightLine=(t,e,n=!1)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=e.color,s.lineWidth=e.lineWidth,this.isReference&&v.setReferenceCtx(s),t.forEach((r,o)=>{if(s.beginPath(),o>0){const h=t[o-1];s.save(),(h==null?void 0:h.specialEdge)&&v.setSpecialEdgeStyle(s),n&&this.hoverLineSegmentIndex+1===o&&(s.lineWidth=4),s.moveTo(h.x,h.y),s.lineTo(r.x,r.y),s.stroke(),s.restore()}}),s.restore())},this.drawLines=()=>{try{const t=g.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(e=>{if(e.id!==this.selectedID&&e.pointList){e.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:n,label:s}=e,r=n,o=e&&this.getLineColorByAttribute(e);this.drawLine(e.pointList,void 0,o,!1),this.drawLineNumber(e.pointList[0],r,o,s,e.attribute,e.valid),e.id!==this.textEditingID&&(this.drawLineTextAttribute(e.pointList[1],o,e==null?void 0:e.textAttribute),this.drawLineLength(e.pointList,o))}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,e)=>{var n;if(!Array.isArray(this.activeLine))return!1;((n=this.activeLine)==null?void 0:n.every(r=>this.isInBasicPolygon({x:r.x+t,y:r.y+e})))&&(this.lineDragging=!0,this.moveActiveArea(t,e))},this.moveLineInRectRange=(t,e,n,s)=>{if(this.activeArea===void 0)return;const{top:r,left:o,right:h,bottom:a}=this.activeArea,l=[o,h].map(y=>g.isNumber(y)?y+t:0),c=[r,a].map(y=>g.isNumber(y)?y+e:0),u=o>=0&&h&&L.isInRange(l,n),A=r>=0&&a&&L.isInRange(c,s),I=u?t:0,P=A?e:0;this.lineDragging=!0,this.moveActiveArea(I,P)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(t),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const t=this.lineList.find(n=>n.id===this.selectedID),e=t==null?void 0:t.attribute;typeof e=="string"&&(this.defaultAttribute=e,this.updateAttribute(e),this.render())}},this.onLeftClick=t=>{const e=this.getCoordinate(t),{lineDragging:n}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const r=this.findHoverLine(e);r&&this.setInvalidLine(r.id);return}if(this.isLinePointsExceed())return;const s=this.getNextPoint(t,e);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(s);return}if(this.isActive){if(n)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(s);return}if(t.shiftKey){this.updateLineSegmentSpecial(e);return}if(this.coordsInsideActiveArea&&t.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,t.keyCode===f.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(t.keyCode===f.Delete){this.deleteLine();return}if(t.keyCode===f.F){this.setInvalidLine(this.selectedID);return}if(t.keyCode===f.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)},this.onRightDblClick=t=>{super.onRightDblClick(t);const e=this.getCoordinate(t);if(this.isActive){const n=this.findHoveredPoint(e);if(n){this.deleteSelectedLinePoint(n.id);return}this.deleteSelectedLine(e)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const e=t.length!==this.lineListLen;this.lineList=t,e&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(i.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new M,this.dependToolConfig={lineType:D.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===D.Curve}get isMultipleColor(){return this.config.lineColor===U.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===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(i=>this.attributeLockList.includes((i==null?void 0:i.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget}get showOrder(){var i;return(i=this.config.showOrder)!=null?i:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const i=N.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var e;return(e=t==null?void 0:t.pointList)==null?void 0:e.some(n=>N.inViewPort(n,i))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var i,t;return(t=(i=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:i.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(i,t=!1){if(i!==this.status){if(t){let e="";this.textCheckType===B.Order&&this.isTextConfigurable&&(e=b.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",e)}this.status=i,this.lineStatusChanged()}}isInBasicPolygon(i){var t,e;return j(i,((t=this.basicResult)==null?void 0:t.pointList)||[],(e=this.dependToolConfig)==null?void 0:e.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:i}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===D.Curve?W(i.reduce((e,n)=>[...e,n.x,n.y],[]),.5,!0,20):i}getNextCoordByRenderCoord(i){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(i))}getNextCoordByAbsCoord(i){var t;const e=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return e?this.coordUtils.getNextCoordByDependTool(i,e):i}pointInLine(i,t,e){return i.filter(n=>n).length<2?!1:i.some((n,s)=>{if(s===0)return!1;const r=this.coordUtils.getRenderCoord(i[s-1]),o=this.coordUtils.getRenderCoord(n);return v.isInLine(t,r,o,e)})}arc(i,t=m,e){var n,s,r,o,h,a;if(this.ctx){const{x:l,y:c}=i;(n=this.ctx)==null||n.save(),(s=this.ctx)==null||s.beginPath(),this.ctx.fillStyle=e||this.lineStyle.color,(r=this.ctx)==null||r.arc(l,c,t,0,360),(o=this.ctx)==null||o.closePath(),(h=this.ctx)==null||h.fill(),(a=this.ctx)==null||a.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:i,left:t,right:e,bottom:n}=this.activeArea,{x:s,y:r}=this.coordUtils.getRenderCoord({x:t,y:i});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(s,r,(e-t)*this.zoom,(n-i)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(i){var t,e,n,s;this.arc(i),(t=this.activeLine)==null||t.push(T(_({},i),{id:S()})),((e=this.activeLine)==null?void 0:e.length)===1?(n=this.actionsHistory)==null||n.initRecord(this.activeLine):(s=this.actionsHistory)==null||s.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(i,t=!1){this.updateStatus(0,t),this.addLinePoint(i)}isActiveLineValid(){var i;return this.selectedID?(i=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:i.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(i,t=!1){return K.getStrokeAndFill(this.getColor(i.attribute),i.valid,{isSelected:t}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom):void 0}drawLineNumber(i,t=1,e,n="",s,r=!0){var o,h,a;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let l=this.showOrder?t.toString():`${n}`;if(this.attributeConfigurable){const c=s?(a=(h=(o=this.attributeList)==null?void 0:o.find(u=>u.value===s))==null?void 0:h.key)!=null?a:s:"";l=[l,`${!r&&c?"\u65E0\u6548":""}${c}`].filter(u=>u).join("_")}this.drawText(i,l,e)}}drawLineTextAttribute(i,t,e){if(i&&e)return this.drawText(i,e,t,200)}drawLineLength(i,t){var e;if(((e=this.config)==null?void 0:e.showLineLength)&&i){const n=i.reduce((r,o,h)=>h<=0||!i[h-1].actual||!o.actual?r:r+v.calcDistance(i[h-1].actual,o.actual),0),s=i[i.length-1];this.drawText(s,`l = ${n.toFixed(2)}`,t)}}drawText(i,t,e,n){var s,r;this.ctx&&((s=this.ctx)==null||s.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=e,this.ctx.strokeStyle=e,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,n?F.wrapText(this.canvas,t,i.x-C.x,i.y-C.y,n):this.ctx.fillText(t,i.x-C.x,i.y-C.y),(r=this.ctx)==null||r.restore())}moveActiveArea(i,t){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+t,bottom:this.activeArea.bottom+t,right:this.activeArea.right+i,left:this.activeArea.left+i})),this.activeLine&&(this.activeLine.map(e=>Object.assign(e,{x:e.x+i,y:e.y+t})),this.updateLines())}findHoveredPoint(i){if(!!this.activeLine)return this.activeLine.find(t=>{const e=this.coordUtils.getRenderCoord(t);return v.calcDistance(e,i)<=x})}findHoverLine(i){return g.cloneDeep(this.lineList).reverse().find(({pointList:e})=>{const n=e?this.getPointList(e):[],s=this.getLineWidthScope();return n.some((r,o)=>{if(o===0)return!1;const h=this.coordUtils.getRenderCoord(r),a=this.coordUtils.getRenderCoord(n[o-1]);return v.isInLine(i,h,a,s)})})}getAdsorptionPoint(i){let t,e,n;return g.cloneDeep(this.lineList).reverse().forEach(({pointList:s,id:r})=>{if(r===this.selectedID||!s||(s==null?void 0:s.length)<2)return;const o=this.findNearestPoint(s,i);if(o){if(o.minDistance===0){t=o.point;return}(e===void 0||o.minDistance<e)&&(t=o.point,e=o.minDistance)}}),n||t}findNearestPoint(i,t,e=7){let n;const s=e;for(let r=1;r<=i.length-1;r++){const o=this.coordUtils.getRenderCoord(i[r]),h=this.coordUtils.getRenderCoord(i[r-1]),{length:a,footPoint:l}=L.getFootOfPerpendicular(t,o,h),c=v.calcTwoPointDistance(o,t),u=v.calcTwoPointDistance(h,t);if(c<=e*2){n=o,e=0;break}if(u<=e*2){n=h,e=0;break}a<e&&(n=l,e=a)}return n?{point:n,minDistance:s}:void 0}getPointList(i){return this.isCurve?R(i,p):i}moveSelectedLine(i){const t=(i.x-this.prevAxis.x)/this.zoom,e=(i.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,e);return}if(this.isDependPolygon){this.moveLineInPolygon(t,e);return}let n=[0,this.imageSize.width],s=[0,this.imageSize.height];if(this.isDependRect){const{x:r,y:o,width:h,height:a}=this.basicResult;n=[r,r+h],s=[o,o+a]}this.moveLineInRectRange(t,e,n,s)}moveSelectPoint(i){if(!this.selectedPoint)return;const t=i.x-this.prevAxis.x,e=i.y-this.prevAxis.y,n=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,s=(this.selectedPoint?this.selectedPoint.y:0)+e/this.zoom,r={x:n,y:s};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(r)),this.updateLines(),this.render()}getCoordByConfig(i,t){var e;const n=!!i.shiftKey,s=i.altKey;if(((e=this.activeLine)==null?void 0:e.length)>0&&n){const r=this.activeLine.slice(-1)[0];return v.getVHPoint(r,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(r))}return this.edgeAdsorptionEnabled&&!s?this.getAdsorptionPoint(t):t}getNextPoint(i,t){const e=this.getCoordByConfig(i,t)||t;return this.enableOutOfTarget?e:this.getNextCoordByRenderCoord(e)}lineHover(){this.render()}mouseMoveHandler(i){const t=this.getCoordinate(i),e=i.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(i,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!i.altKey)){const n=this.getAdsorptionPoint(t);n&&this.arc(n)}if(this.isActive){if(this.isMousedown&&e){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(i){if(super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(i);this.mouseMoveHandler(i),this.prevAxis=t}setActiveArea(i,t=!1){const e=this.findHoverLine(i);if(e){const n=this.lineList.findIndex(o=>o.id===(e==null?void 0:e.id)),s=L.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,p,this.zoom),r=this.lineList[n];this.updateStatus(1),this.setActiveLine(r.pointList),this.setSelectedLineID(r.id),this.activeArea=s,this.updateLineAttributes(r)}else t&&this.setNoneStatus();this.render()}setActiveLineByID(i){const t=this.lineList.find(e=>e.id===i);if(t){const e=L.calcViewportBoundaries((t==null?void 0:t.pointList)||[],this.isCurve,p,this.zoom);this.updateStatus(1),this.setActiveLine(t.pointList),this.setSelectedLineID(t.id),this.activeArea=e,this.updateLineAttributes(t)}this.render()}setActiveLine(i){this.activeLine=i?g.cloneDeep(i):void 0}historyChanged(i){const t=`${i}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const e=this.actionsHistory&&this.actionsHistory[i]();this.setActiveLine(e),this.render()}return}if(this.history&&this.history[t]){const e=this.history[i](),n=e==null?void 0:e.find(s=>s.id===this.selectedID);this.lineList=e,this.selectedID&&n?this.setActiveLine(n==null?void 0:n.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(i){if(this.isDependPolygon)return this.isInBasicPolygon(i);if(this.isDependRect){const{x:t,y:e,width:n,height:s}=this.basicResult,r=[t,t+n],o=[e,e+s];return L.isInRange(i.x,r)&&L.isInRange(i.y,o)}return L.isInRange(i.x,[0,this.imageSize.width])&&L.isInRange(i.y,[0,this.imageSize.height])}getPointInsertIndex(i,t){if(i&&this.activeLine){const e=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((n,s)=>{if(s>0){const r=this.activeLine?this.activeLine[s-1]:void 0,o=this.isCurve?e.slice((s-1)*(p+1),s*(p+1)):[r,n];return this.pointInLine(o,i,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var i;return this.activeLine&&((i=this.activeLine)==null?void 0:i.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(i){const t=this.getPointInsertIndex(i,2)-1;if(t>-1){const e=this.activeLine[t];e.specialEdge=!e.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var i;const t=this.getPointInsertIndex(this.cursor),e=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&e&&(this.activeLine.splice(t,0,T(_({},this.coordUtils.getAbsCoord(this.cursor)),{id:S()})),this.updateLines(),(i=this.history)==null||i.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(i){if(super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(i);if(this.isMousedown=!0,this.prevAxis=t,i.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.isActive&&this.activeArea?v.inArea(this.activeArea,this.coordUtils.getAbsCoord(t)):!1,this.lineDragging=!1}lineHasChanged(){const i=this.lineList.find(t=>t.id===this.selectedID);return i?JSON.stringify(i.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const i=this.lineList.find(t=>t.id===this.selectedID);i&&(i.pointList=g.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(i){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo){t();return}i.which===1&&this.onLeftClick(i),i.which===3&&this.onRightClick(i),t()}isTextValid(i){return b.textAttributeValidate(this.textCheckType,this.customFormat,i)}createLineData(){const i=S(),t={pointList:g.cloneDeep(this.activeLine),id:i,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(i=!0){var t,e,n,s;const r=this.selectedID?!0:!!this.isTextConfigurable;let o;if(i){if(this.selectedID){const h=this.lineList.find(a=>a.id===this.selectedID);o=this.selectedID,h&&(h.pointList=g.cloneWith(this.activeLine),g.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(e=this.history)==null||e.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();o=h.id,this.setLineList([...this.lineList,h]),(n=this.history)==null||n.pushHistory(this.lineList)}}r?this.setActiveStatus(o):this.setNoneStatus(),(s=this.actionsHistory)==null||s.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(i){const t=i?this.lineList.find(e=>e.id===i):void 0;if(t){const e=t==null?void 0:t.pointList;this.updateStatus(1),this.setActiveLine(e),this.setSelectedLineID(i)}else this.setNoneStatus()}setNoneStatus(i=!0){i&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(i,t){this.isShift=t!=null?t:i.keyCode===f.Shift}continueToEdit(){var i;this.updateStatus(0),this.cursor=void 0,(i=this.actionsHistory)==null||i.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(i){if(this.selectedID&&i.keyCode!==f.Ctrl||!this.isCreate)return;const t=!i.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(i){if(super.onKeyDown(i),this.setKeyDownStatus(i),i.keyCode===f.Z&&!i.ctrlKey&&this.toggleIsHide(),i.keyCode===f.Shift&&this.render(),i.keyCode===f.Tab){i.preventDefault(),this.selectToNextLine(i);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(i),this.config.attributeConfigurable){const t=b.getAttributeByKeycode(i.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(i){const t=z.getNextSelectedRectIDByEvent(this.viewPortLines.map(e=>{var n,s,r,o;return T(_({},e),{x:(s=(n=e.pointList[0])==null?void 0:n.x)!=null?s:0,y:(o=(r=e.pointList[0])==null?void 0:r.y)!=null?o:0})}),i,this.selectedID);t&&this.setActiveLineByID(t.id)}keyboardEventWhileLineCreating(i){!this.isCreate||(i.keyCode===f.Ctrl&&this.setInvalidLineOnCreating(i),[f.Shift,f.Alt].includes(i.keyCode)&&this.renderNextPoint(i,this.prevAxis))}renderNextPoint(i,t){const e=this.coordUtils.getRenderCoord(this.getNextPoint(i,t));this.render(e)}deleteSelectedLine(i){const t=L.calcViewportBoundaries(this.activeLine,this.isCurve,p,this.zoom);v.inArea(t,this.coordUtils.getAbsCoord(i))&&this.deleteLine()}deleteSelectedLinePoint(i){var t;this.pointsWithinRange(this.activeLine.length-1)&&i&&(this.setActiveLine(this.activeLine.filter(n=>n.id!==i)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var i;this.lineList=this.lineList.filter(t=>t.id!==this.selectedID),(i=this.history)==null||i.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(i,t,e=!0){var n;const s=this.lineList.find(r=>r.id===i);s&&(s.valid=t!==void 0?t:!s.valid,(n=this.history)==null||n.pushHistory(this.lineList),e&&this.render())}empty(){var i,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(i=this.actionsHistory)==null||i.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(i){var t;this.attributeConfigurable&&(this.defaultAttribute=i,this.setLineAttribute("attribute",i),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(i){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",i),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",i))}setLineAttribute(i,t,e){const n=e||this.selectedID;if(n){const s=this.lineList.find(r=>r.id===n);s&&(s[i]=t)}this.render()}updateAttribute(i){this.emit("updateAttribute",i)}updateLineAttributes(i){var t;if(this.attributeConfigurable&&i){const e=(i==null?void 0:i.attribute)||"";this.defaultAttribute=e,this.updateAttribute(e)}if(this.isTextConfigurable&&i){const e=(i==null?void 0:i.textAttribute)||"";this.updateTextAttribute(e)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(i){if(this.selectedID){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.textAttribute=i)}this.emit("updateText",i)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(i){this.textEditingID=i,this.render()}setSelectedLineID(i){var t,e;if(this.selectedID===i)return;const n=this.selectedID;i!==n&&n&&((t=this._textAttributeInstance)==null||t.changeSelected()),i||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=i,this.emit("selectedChange")}attributeLockListChange(i){this.attributeLockList=i,this.render()}setResult(i){this.setNoneStatus(),this.setLineList(i),this.render()}setConfig(i){super.setConfig(i)}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(i=""){var t;this.attributeConfigurable&&(this.defaultAttribute=i,this.setLineAttribute("attribute",i),this.selectedID&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var i,t;const e=this.isActiveLineValid(),n=this.defaultAttribute,s=this.getColor(n),r=e?s==null?void 0:s.valid.stroke:s==null?void 0:s.invalid.stroke,o=(t=(i=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:i.textAttribute)!=null?t:"";return{color:r,textAttribute:o}}renderTextAttribute(){var i,t,e,n;if(!this.ctx||!this.activeLine||((i=this.activeLine)==null?void 0:i.length)<2||this.isCreate)return;const s=this.isActiveLineValid(),r=this.defaultAttribute,{x:o,y:h}=this.activeLine[1],a=this.coordUtils.getRenderCoord({x:o,y:h}),l=this.getColor(r),c=s?l==null?void 0:l.valid.stroke:l==null?void 0:l.invalid.stroke,u=(e=(t=this.lineList.find(A=>A.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";this._textAttributeInstance||(this._textAttributeInstance=new $({container:this.container,icon:this.getTextIconSvg(r),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((n=this._textAttributeInstance)==null?void 0:n.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${u}`,{left:a.x,top:a.y,color:c}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(r))}getTextIconSvg(i=""){return b.getTextIconSvg(i,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(i){if(this._textAttributeInstance&&i&&this.selectedID){let t=i;!b.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}export{H as INNER_POINT_RADIUS,C as LINE_ORDER_OFFSET,x as POINT_ACTIVE_RADIUS,m as POINT_RADIUS,p as SEGMENT_NUMBER,Q as default};
@@ -1 +1 @@
1
- import{ESortDirection as v}from"../../constant/annotation.js";import{EPolygonPattern as u}from"../../constant/tool.js";import d from"../../utils/tool/AxisUtils.js";import m from"../../utils/tool/CommonToolUtils.js";import c from"../../utils/tool/DrawUtils.js";import g from"../../utils/tool/PolygonUtils.js";import p from"../../utils/tool/StyleUtils.js";import I from"./polygonOperation.js";var _=Object.defineProperty,S=Object.defineProperties,L=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,P=(o,t,e)=>t in o?_(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,y=(o,t)=>{for(var e in t||(t={}))w.call(t,e)&&P(o,e,t[e]);if(f)for(var e of f(t))C.call(t,e)&&P(o,e,t[e]);return o},D=(o,t)=>S(o,L(t));class b extends I{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var r;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=p.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=d.changePointListByZoom(i.pointList,this.zoom,this.currentPos);c.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return g.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=p.getStrokeAndFill(a,e.valid),h=d.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);c.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||c.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===u.Rect?t.isRect===!0:this.pattern===u.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>D(y({},n),{pointList:d.changePointListByZoom(n.pointList,this.zoom)}));return g.getHoverPolygonID(s,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=v.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var r,n,a,l;return D(y({},i),{x:(n=(r=i.pointList[0])==null?void 0:r.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=m.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}export{b as default};
1
+ import{ESortDirection as v}from"../../constant/annotation.js";import{EPolygonPattern as u}from"../../constant/tool.js";import d from"../../utils/tool/AxisUtils.js";import m from"../../utils/tool/CommonToolUtils.js";import c from"../../utils/tool/DrawUtils.js";import g from"../../utils/tool/PolygonUtils.js";import p from"../../utils/tool/StyleUtils.js";import I from"./polygonOperation.js";var _=Object.defineProperty,S=Object.defineProperties,L=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable,P=(o,t,e)=>t in o?_(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,y=(o,t)=>{for(var e in t||(t={}))w.call(t,e)&&P(o,e,t[e]);if(f)for(var e of f(t))C.call(t,e)&&P(o,e,t[e]);return o},D=(o,t)=>S(o,L(t));class b extends I{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=i=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}i.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=i=>{var r;if(this.selectedPolygons){const n=this.getColor(i.attribute),a=p.getStrokeAndFill(n,i.valid,{isSelected:!0}),l=d.changePointListByZoom(i.pointList,this.zoom,this.currentPos);c.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),i.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,s;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(s=t.forbidAddNew)!=null?s:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return g.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var s,i,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:n}=e,a=this.getColor(n),l=p.getStrokeAndFill(a,e.valid),h=d.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);c.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(i=(s=this.style)==null?void 0:s.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||c.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===u.Rect?t.isRect===!0:this.pattern===u.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const s=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>D(y({},n),{pointList:d.changePointListByZoom(n.pointList,this.zoom)}));return g.getHoverPolygonID(s,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=v.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var r,n,a,l;return D(y({},i),{x:(n=(r=i.pointList[0])==null?void 0:r.x)!=null?n:0,y:(l=(a=i.pointList[0])==null?void 0:a.y)!=null?l:0})}),s=m.getNextSelectedRectID(e,t,this.selectedID);if(s)return this.setSelectedIDs([s.id]),this.render(),[s.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,s;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(s=this._textAttributInstance)==null||s.clearTextAttribute(),this.selectedID=t,this.selectedIDs=t?[t]:[],this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,s;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(s=this.basicCtx)==null||s.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}export{b as default};
package/es/index.js CHANGED
@@ -1 +1 @@
1
- export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as s from"./constant/tool.js";export{s as cTool};export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{PointCloud}from"./core/pointCloud/index.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";const i=o,l=o;export{i as CommonToolUtils,l as toolUtils};
1
+ export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as s from"./constant/tool.js";export{s as cTool};export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{PointCloud}from"./core/pointCloud/index.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";const i=o,l=o;export{i as CommonToolUtils,l as toolUtils};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.9.0",
3
+ "version": "1.10.0-alpha.0",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -92,11 +92,11 @@
92
92
  "typescript": "^4.2.3"
93
93
  },
94
94
  "dependencies": {
95
- "@labelbee/lb-utils": "^1.3.0",
95
+ "@labelbee/lb-utils": "^1.4.0-alpha.0",
96
96
  "@turf/turf": "5.1.6",
97
97
  "color-rgba": "^2.3.0",
98
98
  "lodash": "^4.17.20",
99
99
  "three": ">=0.141.0"
100
100
  },
101
- "gitHead": "f4aa456021fb60c76d994f350b38a7b6cc40ac75"
101
+ "gitHead": "0dec26dd6c5b1a59c20d670bc24b2fb0aa98c386"
102
102
  }