@labelbee/lb-annotation 1.10.0-alpha.3 → 1.10.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/toolOperation/LineToolOperation.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/core/toolOperation/basicToolOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/core/toolOperation/rectOperation.js +1 -1
- package/dist/types/core/pointCloud/annotation.d.ts +1 -1
- package/dist/types/core/toolOperation/basicToolOperation.d.ts +5 -1
- package/dist/types/core/toolOperation/pointOperation.d.ts +11 -1
- package/dist/types/core/toolOperation/rectOperation.d.ts +0 -4
- package/es/core/toolOperation/LineToolOperation.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/basicToolOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/core/toolOperation/rectOperation.js +1 -1
- package/package.json +3 -3
|
@@ -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,{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
|
+
"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||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var e;return(e=this.config.showOrder)!=null?e:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get 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?this.coordUtils.getAbsCoord(i):this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(e){const t=this.getCoordinate(e),i=e.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(e,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!e.altKey)){const 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 _=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t));const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var s,l;const d=this.getCoordinateUnderZoom(o),i=AxisUtils.default.changePointByZoom(d,1/this.zoom);if(((s=this.annotations)==null?void 0:s.length)<=0||!((l=this.annotations)==null?void 0:l.length))return;let h="",n=Number.MAX_SAFE_INTEGER;for(let r=0;r<this.annotations.length;r++){const a=this.annotations[r];switch(a.type){case"rect":{const c=a.annotation;if(RectUtils.isInRect(d,c,newScope,this.zoom)){const u=c.width*c.height;u<n&&(h=c.id,n=u)}break}case"polygon":{const c=a.annotation;if(PolygonUtils.isInPolygon(i,c.pointList)){const u=PolygonUtils.getPolygonArea(c.pointList);u<n&&(h=c.id,n=u)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}checkConnectionPoints(t=this.annotations){const{connectionPoints:e}=MathUtils.default.getCollectionPointByAnnotationData(t);this.connectionPoints=e}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let s=[];o&&(s=[o]),this.emit("onChange","hover",s),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),o=__spreadValues(__spreadValues({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,s;const l=(o=t==null?void 0:t.fontSize)!=null?o:14,d=(s=t==null?void 0:t.fontFamily)!=null?s:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${l}px ${d}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let o="",s="";return!t||e===!0?{headerText:o,bottomText:s}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(s=t==null?void 0:t.textAttribute),{headerText:o,bottomText:s})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},s=ImgPosUtils.getBasicRecPos(this.imgNode,o,this.size,.5);if(s){this.setCurrentPos(s.currentPos),this.setCurrentPosStorage(s.currentPos);const{imgInfo:l}=this,{innerZoom:d}=this.innerPosAndZoom;l&&this.setImgInfo(__spreadProps(__spreadValues({},l),{width:l.width/d*s.innerZoom,height:l.height/d*s.innerZoom})),this.setZoom(s.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,s;if(t.type!=="line")return;const{style:l,fontStyle:d}=this.getRenderStyle(t),i=t.annotation;if(!(((e=i==null?void 0:i.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=tool.ELineTypes.Line}=i,n=AxisUtils.default.changePointListByZoom((o=i==null?void 0:i.pointList)!=null?o:[],this.zoom,this.currentPos),r=DrawUtils.drawPolygon(this.canvas,n,__spreadProps(__spreadValues(__spreadValues({},l),this.getReferenceOptions(i==null?void 0:i.isReference)),{lineType:h}));if((i==null?void 0:i.showDirection)===!0&&((s=i==null?void 0:i.pointList)==null?void 0:s.length)>2){let g=n[0],p=MathUtils.default.getLineCenterPoint([n[0],n[1]]);if(h===tool.ELineTypes.Curve){const y=Math.floor(tool.SEGMENT_NUMBER/2);g=r[y],p=r[y+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,p,{color:l.stroke,thickness:l.thickness}),DrawUtils.drawCircle(this.canvas,n[0],l.thickness+6,{color:l.stroke,thickness:l.thickness})}const{headerText:c,bottomText:u}=this.getRenderText(i,i==null?void 0:i.hiddenText);if(c&&DrawUtils.drawText(this.canvas,this.appendOffset(n[0]),c,d),u){const g=n[n.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),u,d)}}renderPolygon(t){var e,o,s,l,d;if(t.type!=="polygon")return;const{style:i,fontStyle:h}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:r=tool.ELineTypes.Line}=n,a=AxisUtils.default.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||i.fill){const f=rgba__default.default((l=(s=i==null?void 0:i.fill)!=null?s:i==null?void 0:i.stroke)!=null?l:DEFAULT_STROKE_COLOR),T=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,a,{color:T,lineType:r})}const c=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},i),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:r,strokeColor:i.stroke});let u=[];if(n.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,a,c):u=DrawUtils.drawPolygon(this.canvas,a,c),(n==null?void 0:n.showDirection)===!0&&((d=n==null?void 0:n.pointList)==null?void 0:d.length)>2){let f=a[0],T=MathUtils.default.getLineCenterPoint([a[0],a[1]]);if(r===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=u[x],T=u[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,T,{color:i.stroke,thickness:i.thickness}),DrawUtils.drawCircle(this.canvas,a[0],i.thickness+6,{color:i.stroke,thickness:i.thickness})}const{headerText:p,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(p&&DrawUtils.drawText(this.canvas,this.appendOffset(a[0]),p,h),y){const f=a[a.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,h)}}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=matrix.pointCloudLidar2image(e,e.calib),s={fill:"transparent"},l=___default.default.pick(e,["stroke","thickness"]);o.forEach((d,i)=>{const h=__spreadValues(__spreadProps(__spreadValues({},l),{id:`${t.annotation.id}-${i}`,pointList:d.pointList}),s);switch(d.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});break}})}render(){try{if(super.render(),this.loading===!0)return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,s,l,d,i;const h=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const r=e.annotation,{hiddenText:a=!1,isReference:c,hiddenRectSize:u=!1}=r,{zoom:g}=this,p=AxisUtils.default.changeRectByZoom(r,this.zoom,this.currentPos),{x:y,y:f,width:T,height:x}=p;if(r.id===this.mouseHoverID||h.fill){const m=rgba__default.default((s=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?s:DEFAULT_STROKE_COLOR),b=`rgba(${m[0]}, ${m[1]}, ${m[2]},${m[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,p,{color:b})}DrawUtils.drawRect(this.canvas,p,__spreadValues(__spreadProps(__spreadValues({},h),{hiddenText:!0}),this.getReferenceOptions(c)));const{headerText:w,bottomText:D}=this.getRenderText(r,r==null?void 0:r.hiddenText);w&&DrawUtils.drawText(this.canvas,{x:y,y:f-6},w,__spreadValues({textMaxWidth:300},n));const P=`${Math.round(T/g)} * ${Math.round(x/g)}`,S=P.length*7;if(!a&&!u&&DrawUtils.drawText(this.canvas,{x:y+T-S,y:f+x+15},P,n),D){const m=20,b=Math.max(20,T-S);DrawUtils.drawText(this.canvas,{x:y,y:f+x+m},r.textAttribute,__spreadValues({textMaxWidth:b},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const r=e.annotation,a=AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),c=(l=h.radius)!=null?l:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,a,c,h);const{headerText:u,bottomText:g}=this.getRenderText(r,r==null?void 0:r.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:a.x+c/2,y:a.y-c-4},u,__spreadValues({textAlign:"center"},n)),g&&DrawUtils.drawText(this.canvas,this.appendOffset({x:a.x+c,y:a.y+c+24}),g,n);break}case"text":{const r=e.annotation,{text:a,x:c,y:u,textMaxWidth:g,color:p="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:T=tool.DEFAULT_FONT,position:x}=r,w=10,D=10,P=AxisUtils.default.changePointByZoom({x:c,y:u},this.zoom,this.currentPos),{width:S,height:m,fontHeight:b=0}=MathUtils.default.getTextArea(this.canvas,r.text,g,T,f);if(x==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:P.x,y:P.y,width:S+D*2,height:m+w*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:P.x+D,y:P.y+b+w},a,{color:p,lineHeight:f,font:T,textMaxWidth:g});break}case"box3d":{this.renderBox3d(e);break}default:break}(i=(d=e.annotation)==null?void 0:d.renderEnhance)==null||i.call(d,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this})}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
|
|
1
|
+
"use strict";var _=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t));const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var s,l;const d=this.getCoordinateUnderZoom(o),i=AxisUtils.default.changePointByZoom(d,1/this.zoom);if(((s=this.annotations)==null?void 0:s.length)<=0||!((l=this.annotations)==null?void 0:l.length))return;let c="",n=Number.MAX_SAFE_INTEGER;for(let a=0;a<this.annotations.length;a++){const r=this.annotations[a];switch(r.type){case"rect":{const h=r.annotation;if(RectUtils.isInRect(d,h,newScope,this.zoom)){const u=h.width*h.height;u<n&&(c=h.id,n=u)}break}case"polygon":{const h=r.annotation;if(PolygonUtils.isInPolygon(i,h.pointList)){const u=PolygonUtils.getPolygonArea(h.pointList);u<n&&(c=h.id,n=u)}break}}}return c};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}checkConnectionPoints(t=this.annotations){const{connectionPoints:e}=MathUtils.default.getCollectionPointByAnnotationData(t);this.connectionPoints=e}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let s=[];o&&(s=[o]),this.emit("onChange","hover",s),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),o=__spreadValues(__spreadValues({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,s;const l=(o=t==null?void 0:t.fontSize)!=null?o:14,d=(s=t==null?void 0:t.fontFamily)!=null?s:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${l}px ${d}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let o="",s="";return!t||e===!0?{headerText:o,bottomText:s}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(s=t==null?void 0:t.textAttribute),{headerText:o,bottomText:s})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},s=ImgPosUtils.getBasicRecPos(this.imgNode,o,this.size,.5);if(s){this.setCurrentPos(s.currentPos),this.setCurrentPosStorage(s.currentPos);const{imgInfo:l}=this,{innerZoom:d}=this.innerPosAndZoom;l&&this.setImgInfo(__spreadProps(__spreadValues({},l),{width:l.width/d*s.innerZoom,height:l.height/d*s.innerZoom})),this.setZoom(s.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,s;if(t.type!=="line")return;const{style:l,fontStyle:d}=this.getRenderStyle(t),i=t.annotation;if(!(((e=i==null?void 0:i.pointList)==null?void 0:e.length)>=2))return;const{lineType:c=tool.ELineTypes.Line}=i,n=AxisUtils.default.changePointListByZoom((o=i==null?void 0:i.pointList)!=null?o:[],this.zoom,this.currentPos),a=__spreadProps(__spreadValues(__spreadValues({},l),this.getReferenceOptions(i==null?void 0:i.isReference)),{lineType:c,strokeColor:l.stroke});let r=[];if(i.showKeyPoint?r=DrawUtils.drawPolygonWithKeyPoint(this.canvas,n,a):r=DrawUtils.drawPolygon(this.canvas,n,a),(i==null?void 0:i.showDirection)===!0&&((s=i==null?void 0:i.pointList)==null?void 0:s.length)>2){let g=n[0],y=MathUtils.default.getLineCenterPoint([n[0],n[1]]);if(c===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);g=r[f],y=r[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,y,{color:l.stroke,thickness:l.thickness}),DrawUtils.drawCircle(this.canvas,n[0],l.thickness+6,{color:l.stroke,thickness:l.thickness})}const{headerText:u,bottomText:p}=this.getRenderText(i,i==null?void 0:i.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(n[0]),u,d),p){const g=n[n.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,d)}}renderPolygon(t){var e,o,s,l,d;if(t.type!=="polygon")return;const{style:i,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:a=tool.ELineTypes.Line}=n,r=AxisUtils.default.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||i.fill){const f=rgba__default.default((l=(s=i==null?void 0:i.fill)!=null?s:i==null?void 0:i.stroke)!=null?l:DEFAULT_STROKE_COLOR),T=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,r,{color:T,lineType:a})}const h=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},i),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:a,strokeColor:i.stroke});let u=[];if(n.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,r,h):u=DrawUtils.drawPolygon(this.canvas,r,h),(n==null?void 0:n.showDirection)===!0&&((d=n==null?void 0:n.pointList)==null?void 0:d.length)>2){let f=r[0],T=MathUtils.default.getLineCenterPoint([r[0],r[1]]);if(a===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=u[x],T=u[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,T,{color:i.stroke,thickness:i.thickness}),DrawUtils.drawCircle(this.canvas,r[0],i.thickness+6,{color:i.stroke,thickness:i.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(g&&DrawUtils.drawText(this.canvas,this.appendOffset(r[0]),g,c),y){const f=r[r.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,c)}}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=matrix.pointCloudLidar2image(e,e.calib),s={fill:"transparent"},l=___default.default.pick(e,["stroke","thickness"]);o.forEach((d,i)=>{const c=__spreadValues(__spreadProps(__spreadValues({},l),{id:`${t.annotation.id}-${i}`,pointList:d.pointList}),s);switch(d.type){case"line":this.renderLine({type:"line",annotation:c});break;case"polygon":this.renderPolygon({type:"polygon",annotation:c});break}})}render(){try{if(super.render(),this.loading===!0)return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,s,l,d,i;const c=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,c);switch(e.type){case"rect":{const a=e.annotation,{hiddenText:r=!1,isReference:h,hiddenRectSize:u=!1}=a,{zoom:p}=this,g=AxisUtils.default.changeRectByZoom(a,this.zoom,this.currentPos),{x:y,y:f,width:T,height:x}=g;if(a.id===this.mouseHoverID||c.fill){const P=rgba__default.default((s=(o=c==null?void 0:c.fill)!=null?o:c==null?void 0:c.stroke)!=null?s:DEFAULT_STROKE_COLOR),b=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,g,{color:b})}DrawUtils.drawRect(this.canvas,g,__spreadValues(__spreadProps(__spreadValues({},c),{hiddenText:!0}),this.getReferenceOptions(h)));const{headerText:w,bottomText:D}=this.getRenderText(a,a==null?void 0:a.hiddenText);w&&DrawUtils.drawText(this.canvas,{x:y,y:f-6},w,__spreadValues({textMaxWidth:300},n));const m=`${Math.round(T/p)} * ${Math.round(x/p)}`,S=m.length*7;if(!r&&!u&&DrawUtils.drawText(this.canvas,{x:y+T-S,y:f+x+15},m,n),D){const P=20,b=Math.max(20,T-S);DrawUtils.drawText(this.canvas,{x:y,y:f+x+P},a.textAttribute,__spreadValues({textMaxWidth:b},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const a=e.annotation,r=AxisUtils.default.changePointByZoom(a,this.zoom,this.currentPos),h=(l=c.radius)!=null?l:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,r,h,c);const{headerText:u,bottomText:p}=this.getRenderText(a,a==null?void 0:a.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:r.x+h/2,y:r.y-h-4},u,__spreadValues({textAlign:"center"},n)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:r.x+h,y:r.y+h+24}),p,n);break}case"text":{const a=e.annotation,{text:r,x:h,y:u,textMaxWidth:p,color:g="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:T=tool.DEFAULT_FONT,position:x}=a,w=10,D=10,m=AxisUtils.default.changePointByZoom({x:h,y:u},this.zoom,this.currentPos),{width:S,height:P,fontHeight:b=0}=MathUtils.default.getTextArea(this.canvas,a.text,p,T,f);if(x==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:m.x,y:m.y,width:S+D*2,height:P+w*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:m.x+D,y:m.y+b+w},r,{color:g,lineHeight:f,font:T,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}default:break}(i=(d=e.annotation)==null?void 0:d.renderEnhance)==null||i.call(d,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this})}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),defaultConfig=require("../../constant/defaultConfig.js"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t)),__async=(l,t,e)=>new Promise((i,s)=>{var o=a=>{try{n(e.next(a))}catch(h){s(h)}},r=a=>{try{n(e.throw(a))}catch(h){s(h)}},n=a=>a.done?i(a.value):Promise.resolve(a.value).then(o,r);n((e=e.apply(l,t)).next())});const zoomInfo={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>__async(this,null,function*(){var c,d;if(!this.imgNode)return;const u=(c=this._imgAttribute)==null?void 0:c.zoomRatio,g=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:m,imgInfo:v,zoom:f}=ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(v),this.setZoom(f),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",f,m,v)}),this.getCurrentPos=c=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let g;return d&&u?g={y:u.y+c.y-d.y,x:u.x+c.x-d.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(c,d,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const v=ZoomUtils.wheelChangePos(m,c,d,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:zoomInfo.max,rotate:this.rotate});if(!v)return;const{currentPos:f,ratio:I,zoom:b,imgInfo:y}=v;this.setZoom(b),this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(y),zoomInfo.ratio=I,this.emit("renderZoom",b,f,y)},this.zoomChanged=(c,d=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,c,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=c=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,c),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var e,i,s,o,r,n,a,h,C;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(i=(e=t.imgNode)==null?void 0:e.width)!=null?i:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:style.COLORS_ARRAY[4],fillColor:style.COLORS_ARRAY[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new ActionsHistory,this.style=(a=t.style)!=null?a:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(h=t.imgAttribute)!=null?h:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=annotation.ELang.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,0),this.basicCanvas=r;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(r,this.container.childNodes[0])):(this.container.appendChild(r),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:r}=this;if(t&&i&&r){let n=t;switch(r){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const h=MathUtils.default.calcViewportBoundaries(t.pointList);n={x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top}}break}}const a=ImgPosUtils.getBasicRecPos(i,n,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);a&&(this.setCurrentPos(a.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*a.innerZoom,height:o.height/this.innerZoom*a.innerZoom})),this.setZoom(a.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0;break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>zoomInfo.min&&(o=-1),s<0&&this.zoom<zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){var i;if((e==null?void 0:e.attributeConfigurable)===!0&&this.style.attributeColor){const r=AttributeUtils.default.getAttributeIndex(t,(i=e.attributeList)!=null?i:[])+1;return this.style.attributeColor[r]}const{color:s,toolColor:o}=this.style;return o?o[s]:defaultConfig.styleDefaultConfig.toolColor["1"]}getLineColor(t=""){var e,i,s;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const n=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return this.style.attributeLineColor?this.style.attributeLineColor[n]:""}const{color:o,lineColor:r}=this.style;return o&&r?r[o]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),defaultConfig=require("../../constant/defaultConfig.js"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t)),__async=(l,t,e)=>new Promise((i,s)=>{var o=a=>{try{n(e.next(a))}catch(h){s(h)}},r=a=>{try{n(e.throw(a))}catch(h){s(h)}},n=a=>a.done?i(a.value):Promise.resolve(a.value).then(o,r);n((e=e.apply(l,t)).next())});const zoomInfo={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>__async(this,null,function*(){var c,d;if(!this.imgNode)return;const u=(c=this._imgAttribute)==null?void 0:c.zoomRatio,g=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:m,imgInfo:v,zoom:f}=ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(v),this.setZoom(f),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",f,m,v)}),this.getCurrentPos=c=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let g;return d&&u?g={y:u.y+c.y-d.y,x:u.x+c.x-d.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(c,d,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const v=ZoomUtils.wheelChangePos(m,c,d,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:zoomInfo.max,rotate:this.rotate});if(!v)return;const{currentPos:f,ratio:I,zoom:b,imgInfo:y}=v;this.setZoom(b),this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(y),zoomInfo.ratio=I,this.emit("renderZoom",b,f,y)},this.zoomChanged=(c,d=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,c,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=c=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,c),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var e,i,s,o,r,n,a,h,C;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(i=(e=t.imgNode)==null?void 0:e.width)!=null?i:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:style.COLORS_ARRAY[4],fillColor:style.COLORS_ARRAY[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new ActionsHistory,this.style=(a=t.style)!=null?a:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(h=t.imgAttribute)!=null?h:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=annotation.ELang.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,0),this.basicCanvas=r;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(r,this.container.childNodes[0])):(this.container.appendChild(r),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:r}=this;if(t&&i&&r){let n=t;switch(r){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const h=MathUtils.default.calcViewportBoundaries(t.pointList);n={x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top}}break}}const a=ImgPosUtils.getBasicRecPos(i,n,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);a&&(this.setCurrentPos(a.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*a.innerZoom,height:o.height/this.innerZoom*a.innerZoom})),this.setZoom(a.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0;break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>zoomInfo.min&&(o=-1),s<0&&this.zoom<zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){var i;if((e==null?void 0:e.attributeConfigurable)===!0&&this.style.attributeColor){const r=AttributeUtils.default.getAttributeIndex(t,(i=e.attributeList)!=null?i:[])+1;return this.style.attributeColor[r]}const{color:s,toolColor:o}=this.style;return o?o[s]:defaultConfig.styleDefaultConfig.toolColor["1"]}getLineColor(t=""){var e,i,s;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const n=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return this.style.attributeLineColor?this.style.attributeLineColor[n]:""}const{color:o,lineColor:r}=this.style;return o&&r?r[o]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(d,t,e)=>t in d?__defProp(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,__spreadValues=(d,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(d,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(d,e,t[e]);return d},__spreadProps=(d,t)=>__defProps(d,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(r=>r.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=AxisUtils.default.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return MathUtils.default.getLineLength(r,i)<.2})},this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=annotation.EDragStatus.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===annotation.EDragStatus.Move&&this.history.pushHistory(this.pointList),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t),r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),h=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(h,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=h.x,a.y=h.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo)return;const{upperLimit:h}=this.config;if(h&&this.currentPageResult.length>=h){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const a=CommonToolUtils.getSourceID(this.basicResult),c=this.getCoordinateUnderZoom(t);let l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const u=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:f,hasClosed:b}=PolygonUtils.getClosestPoint(l,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:u});f&&(l=f),b&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let o=!1;switch(this.dependToolName){case tool.EToolName.Rect:{o=!RectUtils.isInRect(l,this.basicResult);break}case tool.EToolName.Polygon:{o=!PolygonUtils.isInPolygon(l,this.basicResult.pointList);break}}if(o)return}if(c.x<0||c.y<0||c.x>this.imgInfo.width||c.y>this.imgInfo.height)return}if(this.isMinDistance(l))return;let n=__spreadProps(__spreadValues({},l),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:a,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,a)))+1});if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.pointList.filter(u=>CommonToolUtils.isSameSourceID(u.sourceID,a)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:o})}if(this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)n=__spreadProps(__spreadValues({},n),{label:o.label}),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=n.id;const g=[...this.pointList,n];this.setPointList(g),this.history.pushHistory(g),this.setSelectedID(n.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let r=[...i];s&&(r=[...r,s]);const h=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);h&&this.setSelectedID(h.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(u=>u.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:h,valid:a}=i,c=TEXTAREA_WIDTH*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),n=this.getColor(h),g=a?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,o=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:c,container:this.container,icon:this.getTextIconSvg(h),color:g,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:l.x,top:l.y+o,color:g,width:c})}renderPoint(t){var e,i,s;const{textAttribute:r="",attribute:h}=t,a=t.id===this.selectedID,c=this.getColor(h),l=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:n=2,hiddenText:g=!1}=this.style,o=StyleUtils.getStrokeAndFill(c,t.valid,{isSelected:a||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,l,n,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:o.stroke,fill:o.fill});let u="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(u=`${t.order}`),t.label&&this.hasMarkerConfig&&(u=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(u=`${u} ${AttributeUtils.default.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),g||DrawUtils.drawText(this.canvas,{x:l.x+n/2,y:l.y-n-4},u,{textAlign:"center",color:o.stroke}),a?this.renderTextAttribute():g||DrawUtils.drawText(this.canvas,{x:l.x+n,y:l.y+n+24},r,__spreadValues({color:o.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderPointList(){const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const h=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:a}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:h});a&&r!==a&&r!==a&&(r=a,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
|
|
1
|
+
"use strict";var tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(u,t,e)=>t in u?__defProp(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,__spreadValues=(u,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(u,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(u,e,t[e]);return u},__spreadProps=(u,t)=>__defProps(u,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(r=>r.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=AxisUtils.default.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return MathUtils.default.getLineLength(r,i)<.2})},this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>__spreadProps(__spreadValues({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=annotation.EDragStatus.Start,this.isMultiMoveMode&&(this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:this.pointList});return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===annotation.EDragStatus.Move&&(this.history.pushHistory(this.pointList),this.dragInfo=void 0),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const o={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(o);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),h=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(h,this.basicResult.pointList)||(this.pointList.forEach(o=>{o.id===this.selectedID&&(o.x=h.x,o.y=h.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo)return;const{upperLimit:h}=this.config;if(h&&this.currentPageResult.length>=h){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),c=this.getCoordinateUnderZoom(t);let l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const g=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:f,hasClosed:v}=PolygonUtils.getClosestPoint(l,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:g});f&&(l=f),v&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let a=!1;switch(this.dependToolName){case tool.EToolName.Rect:{a=!RectUtils.isInRect(l,this.basicResult);break}case tool.EToolName.Polygon:{a=!PolygonUtils.isInPolygon(l,this.basicResult.pointList);break}}if(a)return}if(c.x<0||c.y<0||c.x>this.imgInfo.width||c.y>this.imgInfo.height)return}if(this.isMinDistance(l))return;let n=__spreadProps(__spreadValues({},l),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:o,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(a=>CommonToolUtils.isSameSourceID(a.sourceID,o)))+1});if(this.config.textConfigurable){let a="";a=AttributeUtils.default.getTextAttribute(this.pointList.filter(g=>CommonToolUtils.isSameSourceID(g.sourceID,o)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:a})}if(this.hasMarkerConfig){const a=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(a)n=__spreadProps(__spreadValues({},n),{label:a.label}),this.markerIndex=a.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=n.id;const d=[...this.pointList,n];this.setPointList(d),this.history.pushHistory(d),this.setSelectedID(n.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let r=[...i];s&&(r=[...r,s]);const h=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);h&&this.setSelectedID(h.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(g=>g.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:h,valid:o}=i,c=TEXTAREA_WIDTH*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),n=this.getColor(h),d=o?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:c,container:this.container,icon:this.getTextIconSvg(h),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:l.x,top:l.y+a,color:d,width:c})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:h="",attribute:o}=t,c=e||t.id===this.selectedID,l=this.getColor(o),n=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:d=2,hiddenText:a=!1}=this.style,g=StyleUtils.getStrokeAndFill(l,t.valid,{isSelected:c||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,n,d,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:g.stroke,fill:g.fill});let f="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),a||DrawUtils.drawText(this.canvas,{x:n.x+d/2,y:n.y-d-4},f,{textAlign:"center",color:g.stroke}),c?this.renderTextAttribute():a||DrawUtils.drawText(this.canvas,{x:n.x+d,y:n.y+d+24},h,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case tool.EOperationMode.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const h=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:o}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:h});o&&r!==o&&r!==o&&(r=o,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.operationMode=tool.EOperationMode.General,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:g}=this;if(g&&RectUtils.isInRect(i,g,r,this.zoom))return g.id}const a=o.filter(g=>RectUtils.isInRect(i,g,r,this.zoom));if(a.length===0)return"";if(a.length===1)return a[0].id;if(a.length>1)return a.map(s=>({size:s.width*s.height,id:s.id})).sort((s,f)=>s.size-f.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setOperationMode(t){this.operationMode=t}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const r=this.selectedRectID;t!==r&&r&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let a=0;a<r.length;a++){const g=r[a],{length:s}=MathUtils.default.getFootOfPerpendicular(o,g.begin,g.end);s<scope+10&&(e=a)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}multiMoveMouseDown(t){const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);return this.isMultiMoveMode&&i&&t.button===0?(this.dragInfo={dragStartCoord:e,dragTarget:tool.EDragTarget.Plane,startTime:+new Date,originRectList:this.rectList},this.dragStatus=annotation.EDragStatus.Start,!0):!1}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0||this.multiMoveMouseDown(t))return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!(!r||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const o=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const o=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:o,firstRect:r,startTime:+new Date},this.dragStatus=annotation.EDragStatus.Start}}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o,a,g;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.isMultiMoveMode){this.onDragMoveAll(s);return}if(!this.dragInfo.firstRect)return;const f=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:l,y:c,width:u,height:d}=f;let n=this.rectList.filter(h=>h.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n=__spreadProps(__spreadValues({},n),{x:l+s.x,y:c+s.y,width:u,height:d});break;case tool.EDragTarget.Point:{let h=l,R=c,x=u,b=d;switch(this.hoverRectPointIndex){case 0:{h=u-s.x<0?l+u:l+s.x,R=d-s.y<0?c+d:c+s.y,x=Math.abs(s.x-u),b=Math.abs(s.y-d);break}case 1:{h=u+s.x>0?l:l+u+s.x,R=d-s.y<0?c+d:c+s.y,x=Math.abs(u+s.x),b=Math.abs(d-s.y);break}case 2:{h=u+s.x>0?l:l+u+s.x,R=d+s.y>0?c:c+d+s.y,x=Math.abs(u+s.x),b=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{h=u-s.x<0?l+u:l+s.x,R=d+s.y>0?c:c+d+s.y,x=Math.abs(s.x-u),b=d+s.y>0?d+s.y:Math.abs(d+s.y);break}default:return}n=__spreadProps(__spreadValues({},n),{x:h,y:R,width:x,height:b})}break;case tool.EDragTarget.Line:{let h=l,R=c,x=u,b=d;switch(this.hoverRectEdgeIndex){case 0:{R=d-s.y<0?c+d:c+s.y,b=Math.abs(s.y-d);break}case 1:{h=u+s.x>0?l:l+u+s.x,x=Math.abs(u+s.x);break}case 2:{R=d+s.y>0?c:c+d+s.y,b=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{h=u-s.x<0?l+u:l+s.x,x=Math.abs(s.x-u);break}default:return}n=__spreadProps(__spreadValues({},n),{x:h,y:R,width:x,height:b});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(n,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const h=this.basicResult.x*this.zoom,R=this.basicResult.y*this.zoom,x=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==tool.EDragTarget.Plane&&(n.x<h-.01||n.y<R-.01||n.width>h+x-n.x+.01||n.height>R+b-n.y+.01))return;if(n.x<h&&(n.x=h),n.y<R&&(n.y=R),n.width>h+x-n.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n.x=h+x-u;break;case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(n.width=h+x-n.x);break;default:return}if(n.height>R+b-n.y)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n.y=R+b-d;break}}else if(n.x<0&&(n.x=0),n.y<0&&(n.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n.x+n.width>((r=this.imgInfo)==null?void 0:r.width)&&(n.x=this.imgInfo.width-u),n.y+n.height>((o=this.imgInfo)==null?void 0:o.height)&&(n.y=this.imgInfo.height-d);break;default:if(n.x+n.width>((a=this.imgInfo)==null?void 0:a.width)+.01||n.y+n.height>((g=this.imgInfo)==null?void 0:g.height)+.01)return}}this.setRectList(this.rectList.map(h=>h.id===n.id?RectUtils.getRectUnderZoom(n,1/this.zoom):h)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if((this.selectedRectID||this.isMultiMoveMode)&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const s=this.getHoverRectPointIndex(t);if(s!==this.hoverRectPointIndex){this.hoverRectPointIndex=s,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const f=this.getHoverRectEdgeIndex(t);if(f!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=f,this.render();return}}}const a=this.getHoverRectID(t),g=this.hoverRectID;if(this.hoverRectID=a,a!==g&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:s,y:f}=this.firstClickCoord,{width:l,height:c}=this.drawingRect;if(l=Math.abs(s-o.x),c=Math.abs(f-o.y),o.x<s&&(s=o.x),o.y<f&&(f=o.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:s,y:f,width:l,height:c}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;o.x<0&&(l=Math.abs(this.firstClickCoord.x),s=0),o.y<0&&(c=Math.abs(this.firstClickCoord.y),f=0),this.imgInfo&&(s+l>this.imgInfo.width&&(l=Math.abs(this.imgInfo.width-s)),f+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-f)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:s,y:f,width:l,height:c}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),r=AxisUtils.default.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=__spreadProps(__spreadValues({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.rectList.filter(a=>CommonToolUtils.isSameSourceID(a.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},r),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(o=>o.id===e),{selectedRectID:r}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(r!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const o=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(this.isMultiMoveMode&&this.setOperationMode(tool.EOperationMode.General),t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteRect(this.selectedRectID);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,o]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let a=[...r];o&&(a=[...a,o]);const g=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);a=a.filter(f=>CanvasUtils.inViewPort({x:f.x,y:f.y},g));const s=CommonToolUtils.getNextSelectedRectID(a,i,this.selectedRectID);s&&(this.setSelectedRectID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:a,attribute:g,valid:s}=e,f=o*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:i,y:r+a},this.currentPos,this.zoom),c=this.getColor(g),u=s?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:f,container:this.container,icon:this.getTextIconSvg(g),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+d,color:u,width:f})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),o=r.length,a=this.getColor(t.attribute);r.forEach((g,s)=>{var f,l;if(e.save(),e.moveTo(g.x,g.y),e.beginPath(),this.hoverRectPointIndex===s?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=a==null?void 0:a.invalid.stroke,e.fillStyle=a==null?void 0:a.invalid.stroke):(e.strokeStyle=a==null?void 0:a.valid.stroke,e.fillStyle=a==null?void 0:a.valid.stroke),e.arc(g.x*this.zoom+this.currentPos.x,g.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===s){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),u=t.valid===!1?(f=c==null?void 0:c.invalid)==null?void 0:f.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=u,e.moveTo(r[s].x*this.zoom+this.currentPos.x,r[s].y*this.zoom+this.currentPos.y),e.lineTo(r[(s+1)%o].x*this.zoom+this.currentPos.x,r[(s+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,o,a,g;if(this.ctx&&t){const{ctx:s,style:f}=this,{hiddenText:l=!1}=f;s.save();const{strokeColor:c,fillColor:u,textColor:d}=this.getRenderStyle(t);s.font="lighter 14px Arial";let n="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(n=`${t.order}`),t.label&&this.hasMarkerConfig&&(n=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(n=`${n} ${AttributeUtils.default.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const h=AxisUtils.default.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||DrawUtils.drawText(this.canvas,{x:h.x,y:h.y-6},n,__spreadProps(__spreadValues({color:c,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300}));const R=(g=(a=this.style)==null?void 0:a.width)!=null?g:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,h,{color:u}),DrawUtils.drawRect(this.canvas,h,{color:c,thickness:R,hiddenText:!0}),s.restore();let x=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(x=`${Math.round(t.width/this.zoom)} * ${Math.round(h.height/this.zoom)}`);const b=x.length*7;if(l||DrawUtils.drawText(this.canvas,{x:h.x+h.width-b,y:h.y+h.height+15},x,__spreadValues({color:d,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const I=0,w=Math.max(20,h.width-b);DrawUtils.drawText(this.canvas,{x:h.x,y:h.y+h.height+20+I},t.textAttribute,__spreadValues({color:d,font:"italic normal 900 14px Arial",textMaxWidth:w},annotation.DEFAULT_TEXT_SHADOW))}}}renderMultiSelectedRect(){this.operationMode===tool.EOperationMode.MultiMove&&this.rectList.forEach(t=>{this.renderDrawingRect(t),this.renderSelectedRect(t)})}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&(this.renderDrawingRect(r),this.renderSelectedRect(r),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(r,this.zoom,this.currentPos),this.getRenderStyle(r)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){switch(this.operationMode){case tool.EOperationMode.MultiMove:this.renderMultiSelectedRect();break;default:this.renderStaticRect(),this.renderCreatingRect()}}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(r=>r.id===this.selectedID?__spreadProps(__spreadValues({},r),{attribute:this.defaultAttribute}):r),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}exports.RectOperation=RectOperation,exports.default=RectOperation;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:g}=this;if(g&&RectUtils.isInRect(i,g,r,this.zoom))return g.id}const a=o.filter(g=>RectUtils.isInRect(i,g,r,this.zoom));if(a.length===0)return"";if(a.length===1)return a[0].id;if(a.length>1)return a.map(s=>({size:s.width*s.height,id:s.id})).sort((s,f)=>s.size-f.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const r=this.selectedRectID;t!==r&&r&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let a=0;a<r.length;a++){const g=r[a],{length:s}=MathUtils.default.getFootOfPerpendicular(o,g.begin,g.end);s<scope+10&&(e=a)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}multiMoveMouseDown(t){const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);return this.isMultiMoveMode&&i&&t.button===0?(this.dragInfo={dragStartCoord:e,dragTarget:tool.EDragTarget.Plane,startTime:+new Date,originRectList:this.rectList},this.dragStatus=annotation.EDragStatus.Start,!0):!1}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0||this.multiMoveMouseDown(t))return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!(!r||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const o=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const o=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:o,firstRect:r,startTime:+new Date},this.dragStatus=annotation.EDragStatus.Start}}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o,a,g;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.isMultiMoveMode){this.onDragMoveAll(s);return}if(!this.dragInfo.firstRect)return;const f=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:l,y:c,width:u,height:d}=f;let n=this.rectList.filter(h=>h.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n=__spreadProps(__spreadValues({},n),{x:l+s.x,y:c+s.y,width:u,height:d});break;case tool.EDragTarget.Point:{let h=l,R=c,x=u,b=d;switch(this.hoverRectPointIndex){case 0:{h=u-s.x<0?l+u:l+s.x,R=d-s.y<0?c+d:c+s.y,x=Math.abs(s.x-u),b=Math.abs(s.y-d);break}case 1:{h=u+s.x>0?l:l+u+s.x,R=d-s.y<0?c+d:c+s.y,x=Math.abs(u+s.x),b=Math.abs(d-s.y);break}case 2:{h=u+s.x>0?l:l+u+s.x,R=d+s.y>0?c:c+d+s.y,x=Math.abs(u+s.x),b=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{h=u-s.x<0?l+u:l+s.x,R=d+s.y>0?c:c+d+s.y,x=Math.abs(s.x-u),b=d+s.y>0?d+s.y:Math.abs(d+s.y);break}default:return}n=__spreadProps(__spreadValues({},n),{x:h,y:R,width:x,height:b})}break;case tool.EDragTarget.Line:{let h=l,R=c,x=u,b=d;switch(this.hoverRectEdgeIndex){case 0:{R=d-s.y<0?c+d:c+s.y,b=Math.abs(s.y-d);break}case 1:{h=u+s.x>0?l:l+u+s.x,x=Math.abs(u+s.x);break}case 2:{R=d+s.y>0?c:c+d+s.y,b=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{h=u-s.x<0?l+u:l+s.x,x=Math.abs(s.x-u);break}default:return}n=__spreadProps(__spreadValues({},n),{x:h,y:R,width:x,height:b});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(n,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const h=this.basicResult.x*this.zoom,R=this.basicResult.y*this.zoom,x=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==tool.EDragTarget.Plane&&(n.x<h-.01||n.y<R-.01||n.width>h+x-n.x+.01||n.height>R+b-n.y+.01))return;if(n.x<h&&(n.x=h),n.y<R&&(n.y=R),n.width>h+x-n.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n.x=h+x-u;break;case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(n.width=h+x-n.x);break;default:return}if(n.height>R+b-n.y)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n.y=R+b-d;break}}else if(n.x<0&&(n.x=0),n.y<0&&(n.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Plane:n.x+n.width>((r=this.imgInfo)==null?void 0:r.width)&&(n.x=this.imgInfo.width-u),n.y+n.height>((o=this.imgInfo)==null?void 0:o.height)&&(n.y=this.imgInfo.height-d);break;default:if(n.x+n.width>((a=this.imgInfo)==null?void 0:a.width)+.01||n.y+n.height>((g=this.imgInfo)==null?void 0:g.height)+.01)return}}this.setRectList(this.rectList.map(h=>h.id===n.id?RectUtils.getRectUnderZoom(n,1/this.zoom):h)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if((this.selectedRectID||this.isMultiMoveMode)&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const s=this.getHoverRectPointIndex(t);if(s!==this.hoverRectPointIndex){this.hoverRectPointIndex=s,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const f=this.getHoverRectEdgeIndex(t);if(f!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=f,this.render();return}}}const a=this.getHoverRectID(t),g=this.hoverRectID;if(this.hoverRectID=a,a!==g&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:s,y:f}=this.firstClickCoord,{width:l,height:c}=this.drawingRect;if(l=Math.abs(s-o.x),c=Math.abs(f-o.y),o.x<s&&(s=o.x),o.y<f&&(f=o.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:s,y:f,width:l,height:c}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;o.x<0&&(l=Math.abs(this.firstClickCoord.x),s=0),o.y<0&&(c=Math.abs(this.firstClickCoord.y),f=0),this.imgInfo&&(s+l>this.imgInfo.width&&(l=Math.abs(this.imgInfo.width-s)),f+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-f)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:s,y:f,width:l,height:c}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),r=AxisUtils.default.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=__spreadProps(__spreadValues({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.rectList.filter(a=>CommonToolUtils.isSameSourceID(a.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},r),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(o=>o.id===e),{selectedRectID:r}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(r!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const o=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(this.isMultiMoveMode&&this.setOperationMode(tool.EOperationMode.General),t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteRect(this.selectedRectID);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,o]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let a=[...r];o&&(a=[...a,o]);const g=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);a=a.filter(f=>CanvasUtils.inViewPort({x:f.x,y:f.y},g));const s=CommonToolUtils.getNextSelectedRectID(a,i,this.selectedRectID);s&&(this.setSelectedRectID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:a,attribute:g,valid:s}=e,f=o*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:i,y:r+a},this.currentPos,this.zoom),c=this.getColor(g),u=s?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:f,container:this.container,icon:this.getTextIconSvg(g),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+d,color:u,width:f})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),o=r.length,a=this.getColor(t.attribute);r.forEach((g,s)=>{var f,l;if(e.save(),e.moveTo(g.x,g.y),e.beginPath(),this.hoverRectPointIndex===s?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=a==null?void 0:a.invalid.stroke,e.fillStyle=a==null?void 0:a.invalid.stroke):(e.strokeStyle=a==null?void 0:a.valid.stroke,e.fillStyle=a==null?void 0:a.valid.stroke),e.arc(g.x*this.zoom+this.currentPos.x,g.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===s){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),u=t.valid===!1?(f=c==null?void 0:c.invalid)==null?void 0:f.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=u,e.moveTo(r[s].x*this.zoom+this.currentPos.x,r[s].y*this.zoom+this.currentPos.y),e.lineTo(r[(s+1)%o].x*this.zoom+this.currentPos.x,r[(s+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,o,a,g;if(this.ctx&&t){const{ctx:s,style:f}=this,{hiddenText:l=!1}=f;s.save();const{strokeColor:c,fillColor:u,textColor:d}=this.getRenderStyle(t);s.font="lighter 14px Arial";let n="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(n=`${t.order}`),t.label&&this.hasMarkerConfig&&(n=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(n=`${n} ${AttributeUtils.default.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const h=AxisUtils.default.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||DrawUtils.drawText(this.canvas,{x:h.x,y:h.y-6},n,__spreadProps(__spreadValues({color:c,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300}));const R=(g=(a=this.style)==null?void 0:a.width)!=null?g:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,h,{color:u}),DrawUtils.drawRect(this.canvas,h,{color:c,thickness:R,hiddenText:!0}),s.restore();let x=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(x=`${Math.round(t.width/this.zoom)} * ${Math.round(h.height/this.zoom)}`);const b=x.length*7;if(l||DrawUtils.drawText(this.canvas,{x:h.x+h.width-b,y:h.y+h.height+15},x,__spreadValues({color:d,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const I=0,w=Math.max(20,h.width-b);DrawUtils.drawText(this.canvas,{x:h.x,y:h.y+h.height+20+I},t.textAttribute,__spreadValues({color:d,font:"italic normal 900 14px Arial",textMaxWidth:w},annotation.DEFAULT_TEXT_SHADOW))}}}renderMultiSelectedRect(){!this.isMultiMoveMode||this.rectList.forEach(t=>{this.renderDrawingRect(t),this.renderSelectedRect(t)})}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&(this.renderDrawingRect(r),this.renderSelectedRect(r),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(r,this.zoom,this.currentPos),this.getRenderStyle(r)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){switch(this.operationMode){case tool.EOperationMode.MultiMove:this.renderMultiSelectedRect();break;default:this.renderStaticRect(),this.renderCreatingRect()}}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(r=>r.id===this.selectedID?__spreadProps(__spreadValues({},r),{attribute:this.defaultAttribute}):r),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}exports.RectOperation=RectOperation,exports.default=RectOperation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
2
|
+
* @file Unify management of pointCloud & pointCloud2dOperation (Three views => Top & Side & Back)
|
|
3
3
|
* @createDate 2022-07-18
|
|
4
4
|
* @author Ron <ron.f.luo@gmail.com>
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBasicText } from '@labelbee/lb-utils';
|
|
2
|
-
import { EToolName } from '@/constant/tool';
|
|
2
|
+
import { EOperationMode, EToolName } from '@/constant/tool';
|
|
3
3
|
import { IPolygonConfig, IPolygonData } from '@/types/tool/polygon';
|
|
4
4
|
import { CoordinateUtils } from '@/utils/tool/AxisUtils';
|
|
5
5
|
import { EDragStatus, EGrowthMode, ELang } from '../../constant/annotation';
|
|
@@ -63,6 +63,7 @@ declare class BasicToolOperation extends EventListener {
|
|
|
63
63
|
dataInjectionAtCreation?: TDataInjectionAtCreateion;
|
|
64
64
|
renderEnhance?: IRenderEnhance;
|
|
65
65
|
customRenderStyle?: (data: IRect | IPolygonData | IPoint | ILine | ITagResult | IBasicText) => IAnnotationStyle;
|
|
66
|
+
operationMode: EOperationMode;
|
|
66
67
|
private _firstClickCoordinate?;
|
|
67
68
|
private innerZoom;
|
|
68
69
|
private currentPosStorage?;
|
|
@@ -91,6 +92,7 @@ declare class BasicToolOperation extends EventListener {
|
|
|
91
92
|
currentPosStorage: ICoordinate | undefined;
|
|
92
93
|
};
|
|
93
94
|
get isShowDefaultCursor(): boolean;
|
|
95
|
+
get isMultiMoveMode(): boolean;
|
|
94
96
|
/**
|
|
95
97
|
* 是否含有列表标注
|
|
96
98
|
*/
|
|
@@ -100,6 +102,8 @@ declare class BasicToolOperation extends EventListener {
|
|
|
100
102
|
setReferenceData(referenceData: IReferenceData): void;
|
|
101
103
|
setImgInfo(size: ISize): void;
|
|
102
104
|
setCurrentPosStorage(currentPosStorage: ICoordinate): void;
|
|
105
|
+
setOperationMode(operationMode: EOperationMode): void;
|
|
106
|
+
recoverOperationMode(): void;
|
|
103
107
|
/**
|
|
104
108
|
* 外界直接更改当前渲染位置
|
|
105
109
|
* @param zoom
|
|
@@ -8,6 +8,10 @@ declare class PointOperation extends BasicToolOperation {
|
|
|
8
8
|
hoverID?: string;
|
|
9
9
|
selectedID?: string;
|
|
10
10
|
markerIndex: number;
|
|
11
|
+
dragInfo?: {
|
|
12
|
+
dragStartCoord: ICoordinate;
|
|
13
|
+
originPointList: IPointUnit[];
|
|
14
|
+
};
|
|
11
15
|
private _textAttributInstance?;
|
|
12
16
|
constructor(props: IPointOperationProps);
|
|
13
17
|
get dataList(): IPointUnit[];
|
|
@@ -57,6 +61,11 @@ declare class PointOperation extends BasicToolOperation {
|
|
|
57
61
|
*/
|
|
58
62
|
clearActiveStatus(): void;
|
|
59
63
|
setBasicResult(basicResult: any): void;
|
|
64
|
+
/**
|
|
65
|
+
* Offset is under zooming.
|
|
66
|
+
* @param offset
|
|
67
|
+
*/
|
|
68
|
+
onDragMoveAll(offset: ICoordinate): void;
|
|
60
69
|
onMouseDown(e: MouseEvent): true | undefined;
|
|
61
70
|
onMouseMove(e: MouseEvent): undefined;
|
|
62
71
|
onMouseUp(e: MouseEvent): true | undefined;
|
|
@@ -104,7 +113,8 @@ declare class PointOperation extends BasicToolOperation {
|
|
|
104
113
|
/**
|
|
105
114
|
* 绘制标点
|
|
106
115
|
*/
|
|
107
|
-
renderPoint(point: IPointUnit): void;
|
|
116
|
+
renderPoint(point: IPointUnit, isSelected?: boolean): void;
|
|
117
|
+
renderMultiSelectedPoint(): void;
|
|
108
118
|
renderPointList(): void;
|
|
109
119
|
/**
|
|
110
120
|
* 顶层渲染图标
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EOperationMode } from '../../constant/tool';
|
|
2
1
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
3
2
|
interface IRectOperationProps extends IBasicToolOperationProps {
|
|
4
3
|
drawOutSideTarget: boolean;
|
|
@@ -17,7 +16,6 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
17
16
|
isFlow: boolean;
|
|
18
17
|
config: IRectConfig;
|
|
19
18
|
markerIndex: number;
|
|
20
|
-
operationMode: EOperationMode;
|
|
21
19
|
private _textAttributInstance?;
|
|
22
20
|
private dragInfo?;
|
|
23
21
|
constructor(props: IRectOperationProps);
|
|
@@ -33,7 +31,6 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
33
31
|
get selectedRect(): IRect | undefined;
|
|
34
32
|
get selectedID(): string | undefined;
|
|
35
33
|
get selectedText(): string | undefined;
|
|
36
|
-
get isMultiMoveMode(): boolean;
|
|
37
34
|
get dataList(): IRect[];
|
|
38
35
|
/**
|
|
39
36
|
* 当前页面展示的框体
|
|
@@ -53,7 +50,6 @@ declare class RectOperation extends BasicToolOperation {
|
|
|
53
50
|
* @memberof RectOperation
|
|
54
51
|
*/
|
|
55
52
|
getCurrentPageResult(rectList: IRect[]): IRect[];
|
|
56
|
-
setOperationMode(operationMode: EOperationMode): void;
|
|
57
53
|
setSelectedID(newID?: string): void;
|
|
58
54
|
setSelectedRectID(newID?: string): void;
|
|
59
55
|
setStyle(toolStyle: any): void;
|
|
@@ -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 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
|
+
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,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,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||this.config.outOfTarget||this.config.drawOutsideTarget}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?this.coordUtils.getAbsCoord(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 E from"lodash";import M from"color-rgba";import
|
|
1
|
+
import E from"lodash";import M from"color-rgba";import c from"../../utils/tool/DrawUtils.js";import D from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import F from"../../utils/tool/PolygonUtils.js";import R from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as C,DEFAULT_FONT as j,SEGMENT_NUMBER as B}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as U,TEXT_ATTRIBUTE_OFFSET as I,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import N from"../../utils/tool/ImgPosUtils.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import{pointCloudLidar2image as V}from"../pointCloud/matrix.js";var X=Object.defineProperty,G=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,z=(P,t,e)=>t in P?X(P,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):P[t]=e,g=(P,t)=>{for(var e in t||(t={}))q.call(t,e)&&z(P,e,t[e]);if($)for(var e of $(t))J.call(t,e)&&z(P,e,t[e]);return P},b=(P,t)=>G(P,Y(t));const Q=3,tt=3,A="#6371FF";class et extends K{constructor(t){super(b(g({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var s,l;const f=this.getCoordinateUnderZoom(o),i=D.changePointByZoom(f,1/this.zoom);if(((s=this.annotations)==null?void 0:s.length)<=0||!((l=this.annotations)==null?void 0:l.length))return;let h="",n=Number.MAX_SAFE_INTEGER;for(let a=0;a<this.annotations.length;a++){const r=this.annotations[a];switch(r.type){case"rect":{const d=r.annotation;if(Z.isInRect(f,d,Q,this.zoom)){const u=d.width*d.height;u<n&&(h=d.id,n=u)}break}case"polygon":{const d=r.annotation;if(F.isInPolygon(i,d.pointList)){const u=F.getPolygonArea(d.pointList);u<n&&(h=d.id,n=u)}break}}}return h};var e;this.style=(e=t.style)!=null?e:{stroke:A,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({container:this.container,height:this.canvas.height})}checkConnectionPoints(t=this.annotations){const{connectionPoints:e}=R.getCollectionPointByAnnotationData(t);this.connectionPoints=e}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let s=[];o&&(s=[o]),this.emit("onChange","hover",s),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=g(g({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,s;const l=(o=t==null?void 0:t.fontSize)!=null?o:14,f=(s=t==null?void 0:t.fontFamily)!=null?s:"Arial";return b(g({},H),{color:e.stroke,font:`normal normal 600 ${l}px ${f}`})}appendOffset({x:t,y:e}){return{x:t+U.offsetX,y:e+U.offsetY}}getRenderText(t,e=!1){let o="",s="";return!t||e===!0?{headerText:o,bottomText:s}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(s=t==null?void 0:t.textAttribute),{headerText:o,bottomText:s})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=R.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},s=N.getBasicRecPos(this.imgNode,o,this.size,.5);if(s){this.setCurrentPos(s.currentPos),this.setCurrentPosStorage(s.currentPos);const{imgInfo:l}=this,{innerZoom:f}=this.innerPosAndZoom;l&&this.setImgInfo(b(g({},l),{width:l.width/f*s.innerZoom,height:l.height/f*s.innerZoom})),this.setZoom(s.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=D.changePointByZoom(t,this.zoom,this.currentPos);c.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),c.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,s;if(t.type!=="line")return;const{style:l,fontStyle:f}=this.getRenderStyle(t),i=t.annotation;if(!(((e=i==null?void 0:i.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=C.Line}=i,n=D.changePointListByZoom((o=i==null?void 0:i.pointList)!=null?o:[],this.zoom,this.currentPos),a=b(g(g({},l),this.getReferenceOptions(i==null?void 0:i.isReference)),{lineType:h,strokeColor:l.stroke});let r=[];if(i.showKeyPoint?r=c.drawPolygonWithKeyPoint(this.canvas,n,a):r=c.drawPolygon(this.canvas,n,a),(i==null?void 0:i.showDirection)===!0&&((s=i==null?void 0:i.pointList)==null?void 0:s.length)>2){let y=n[0],m=R.getLineCenterPoint([n[0],n[1]]);if(h===C.Curve){const p=Math.floor(B/2);y=r[p],m=r[p+1]}c.drawArrowByCanvas(this.canvas,y,m,{color:l.stroke,thickness:l.thickness}),c.drawCircle(this.canvas,n[0],l.thickness+6,{color:l.stroke,thickness:l.thickness})}const{headerText:u,bottomText:v}=this.getRenderText(i,i==null?void 0:i.hiddenText);if(u&&c.drawText(this.canvas,this.appendOffset(n[0]),u,f),v){const y=n[n.length-1];c.drawText(this.canvas,this.appendOffset({x:y.x+I.x,y:y.y+I.y}),v,f)}}renderPolygon(t){var e,o,s,l,f;if(t.type!=="polygon")return;const{style:i,fontStyle:h}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:a=C.Line}=n,r=D.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||i.fill){const p=M((l=(s=i==null?void 0:i.fill)!=null?s:i==null?void 0:i.stroke)!=null?l:A),x=`rgba(${p[0]}, ${p[1]}, ${p[2]},${p[3]*.8})`;c.drawPolygonWithFill(this.canvas,r,{color:x,lineType:a})}const d=b(g(b(g({},i),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:a,strokeColor:i.stroke});let u=[];if(n.showKeyPoint?u=c.drawPolygonWithKeyPoint(this.canvas,r,d):u=c.drawPolygon(this.canvas,r,d),(n==null?void 0:n.showDirection)===!0&&((f=n==null?void 0:n.pointList)==null?void 0:f.length)>2){let p=r[0],x=R.getLineCenterPoint([r[0],r[1]]);if(a===C.Curve){const w=Math.floor(B/2);p=u[w],x=u[w+1]}c.drawArrowByCanvas(this.canvas,p,x,{color:i.stroke,thickness:i.thickness}),c.drawCircle(this.canvas,r[0],i.thickness+6,{color:i.stroke,thickness:i.thickness})}const{headerText:y,bottomText:m}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(y&&c.drawText(this.canvas,this.appendOffset(r[0]),y,h),m){const p=r[r.length-1];c.drawText(this.canvas,this.appendOffset({x:p.x+I.x,y:p.y+I.y}),m,h)}}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=V(e,e.calib),s={fill:"transparent"},l=E.pick(e,["stroke","thickness"]);o.forEach((f,i)=>{const h=g(b(g({},l),{id:`${t.annotation.id}-${i}`,pointList:f.pointList}),s);switch(f.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});break}})}render(){try{if(super.render(),this.loading===!0)return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,s,l,f,i;const h=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const a=e.annotation,{hiddenText:r=!1,isReference:d,hiddenRectSize:u=!1}=a,{zoom:v}=this,y=D.changeRectByZoom(a,this.zoom,this.currentPos),{x:m,y:p,width:x,height:w}=y;if(a.id===this.mouseHoverID||h.fill){const T=M((s=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?s:A),S=`rgba(${T[0]}, ${T[1]}, ${T[2]},${T[3]*.8})`;c.drawRectWithFill(this.canvas,y,{color:S})}c.drawRect(this.canvas,y,g(b(g({},h),{hiddenText:!0}),this.getReferenceOptions(d)));const{headerText:k,bottomText:O}=this.getRenderText(a,a==null?void 0:a.hiddenText);k&&c.drawText(this.canvas,{x:m,y:p-6},k,g({textMaxWidth:300},n));const _=`${Math.round(x/v)} * ${Math.round(w/v)}`,L=_.length*7;if(!r&&!u&&c.drawText(this.canvas,{x:m+x-L,y:p+w+15},_,n),O){const T=20,S=Math.max(20,x-L);c.drawText(this.canvas,{x:m,y:p+w+T},a.textAttribute,g({textMaxWidth:S},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const a=e.annotation,r=D.changePointByZoom(a,this.zoom,this.currentPos),d=(l=h.radius)!=null?l:tt;c.drawCircle(this.canvas,r,d,h);const{headerText:u,bottomText:v}=this.getRenderText(a,a==null?void 0:a.hiddenText);u&&c.drawText(this.canvas,{x:r.x+d/2,y:r.y-d-4},u,g({textAlign:"center"},n)),v&&c.drawText(this.canvas,this.appendOffset({x:r.x+d,y:r.y+d+24}),v,n);break}case"text":{const a=e.annotation,{text:r,x:d,y:u,textMaxWidth:v,color:y="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:p=25,font:x=j,position:w}=a,k=10,O=10,_=D.changePointByZoom({x:d,y:u},this.zoom,this.currentPos),{width:L,height:T,fontHeight:S=0}=R.getTextArea(this.canvas,a.text,v,x,p);if(w==="rt")break;c.drawRectWithFill(this.canvas,{x:_.x,y:_.y,width:L+O*2,height:T+k*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),c.drawText(this.canvas,{x:_.x+O,y:_.y+S+k},r,{color:y,lineHeight:p,font:x,textMaxWidth:v});break}case"box3d":{this.renderBox3d(e);break}default:break}(i=(f=e.annotation)==null?void 0:f.renderEnhance)==null||i.call(f,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this})}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{et as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNumber as _}from"lodash";import{styleDefaultConfig as A}from"../../constant/defaultConfig.js";import{EToolName as b}from"../../constant/tool.js";import x from"../../utils/MathUtils.js";import p,{CoordinateUtils as N}from"../../utils/tool/AxisUtils.js";import j from"../../utils/tool/CanvasUtils.js";import w from"../../utils/tool/CommonToolUtils.js";import T from"../../utils/tool/LineToolUtils.js";import{EGrowthMode as K,EDragStatus as W,ELang as H}from"../../constant/annotation.js";import y from"../../constant/keyCode.js";import{COLORS_ARRAY as S,styleString as F,BASE_ICON as G}from"../../constant/style.js";import R from"../../locales/index.js";import{EMessage as k}from"../../locales/constants.js";import V from"../../utils/ActionsHistory.js";import z from"../../utils/tool/AttributeUtils.js";import Y from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import E from"../../utils/tool/ImgPosUtils.js";import $ from"../../utils/tool/RenderDomUtils.js";import U from"../../utils/tool/ZoomUtils.js";import X from"./eventListener.js";var q=Object.defineProperty,J=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,M=(l,t,i)=>t in l?q(l,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):l[t]=i,Z=(l,t)=>{for(var i in t||(t={}))tt.call(t,i)&&M(l,i,t[i]);if(B)for(var i of B(t))it.call(t,i)&&M(l,i,t[i]);return l},et=(l,t)=>J(l,Q(t)),st=(l,t,i)=>new Promise((e,s)=>{var o=a=>{try{n(i.next(a))}catch(h){s(h)}},r=a=>{try{n(i.throw(a))}catch(h){s(h)}},n=a=>a.done?e(a.value):Promise.resolve(a.value).then(o,r);n((i=i.apply(l,t)).next())});const I={min:.2,max:1e3,ratio:.4};class ot extends X{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>st(this,null,function*(){var c,d;if(!this.imgNode)return;const u=(c=this._imgAttribute)==null?void 0:c.zoomRatio,m=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:f,imgInfo:C,zoom:v}=E.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(C),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,C)}),this.getCurrentPos=c=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let m;return d&&u?m={y:u.y+c.y-d.y,x:u.x+c.x-d.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(c,d,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const C=U.wheelChangePos(f,c,d,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:I.max,rotate:this.rotate});if(!C)return;const{currentPos:v,ratio:O,zoom:L,imgInfo:D}=C;this.setZoom(L),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(D),I.ratio=O,this.emit("renderZoom",L,v,D)},this.zoomChanged=(c,d=K.Linear)=>{const u=U.zoomChanged(this.zoom,c,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=c=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,c),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var i,e,s,o,r,n,a,h,P;this.container=t.container,this.config=w.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(e=(i=t.imgNode)==null?void 0:i.width)!=null?e:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:S[4],fillColor:S[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new V,this.style=(a=t.style)!=null?a:w.jsonParser(F),this._imgAttribute=(h=t.imgAttribute)!=null?h:{},this.isHidden=!1,this.dragStatus=W.Wait,this.defaultAttribute=(P=t==null?void 0:t.defaultAttribute)!=null?P:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=H.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new Y(this.container,200),this.coordUtils=new N(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return G[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return j.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s;const o=this.pixelRatio,r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,0),this.basicCanvas=r;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(r,this.container.childNodes[0])):(this.container.appendChild(r),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(Z({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:o,dependToolName:r}=this;if(t&&e&&r){let n=t;switch(r){case b.Polygon:case b.Line:{if(t.pointList){const h=x.calcViewportBoundaries(t.pointList);n={x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top}}break}}const a=E.getBasicRecPos(e,n,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);a&&(this.setCurrentPos(a.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(et(Z({},o),{width:o.width/this.innerZoom*a.innerZoom,height:o.height/this.innerZoom*a.innerZoom})),this.setZoom(a.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!_(i==null?void 0:i.x)||!_(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||T.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===y.Alt&&t.preventDefault(),t.keyCode){case y.Space:this.isSpaceKey=!0;break;case y.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case y.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>I.min&&(o=-1),s<0&&this.zoom<I.max&&(o=1),this.wheelChangePos(e,o),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=w.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",R.getMessagesByLocale(k.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",R.getMessagesByLocale(k.NoRotateNotice,this.lang)),!1;const t=x.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){var e;if((i==null?void 0:i.attributeConfigurable)===!0&&this.style.attributeColor){const r=z.getAttributeIndex(t,(e=i.attributeList)!=null?e:[])+1;return this.style.attributeColor[r]}const{color:s,toolColor:o}=this.style;return o?o[s]:A.toolColor["1"]}getLineColor(t=""){var i,e,s;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const n=z.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return this.style.attributeLineColor?this.style.attributeLineColor[n]:""}const{color:o,lineColor:r}=this.style;return o&&r?r[o]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=$.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case b.Rect:{g.drawRect(this.basicCanvas,p.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case b.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,p.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case b.Line:{g.drawLineWithPointList(this.basicCanvas,p.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{ot as BasicToolOperation};
|
|
1
|
+
import{isNumber as x}from"lodash";import{styleDefaultConfig as N}from"../../constant/defaultConfig.js";import{EOperationMode as y,EToolName as b}from"../../constant/tool.js";import S from"../../utils/MathUtils.js";import w,{CoordinateUtils as j}from"../../utils/tool/AxisUtils.js";import T from"../../utils/tool/CanvasUtils.js";import P from"../../utils/tool/CommonToolUtils.js";import K from"../../utils/tool/LineToolUtils.js";import{EGrowthMode as W,EDragStatus as G,ELang as H}from"../../constant/annotation.js";import I from"../../constant/keyCode.js";import{COLORS_ARRAY as M,styleString as F,BASE_ICON as V}from"../../constant/style.js";import R from"../../locales/index.js";import{EMessage as k}from"../../locales/constants.js";import Y from"../../utils/ActionsHistory.js";import z from"../../utils/tool/AttributeUtils.js";import $ from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import E from"../../utils/tool/ImgPosUtils.js";import X from"../../utils/tool/RenderDomUtils.js";import U from"../../utils/tool/ZoomUtils.js";import q from"./eventListener.js";var J=Object.defineProperty,Q=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,O=(l,t,i)=>t in l?J(l,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):l[t]=i,Z=(l,t)=>{for(var i in t||(t={}))it.call(t,i)&&O(l,i,t[i]);if(B)for(var i of B(t))et.call(t,i)&&O(l,i,t[i]);return l},st=(l,t)=>Q(l,tt(t)),ot=(l,t,i)=>new Promise((e,s)=>{var o=a=>{try{n(i.next(a))}catch(h){s(h)}},r=a=>{try{n(i.throw(a))}catch(h){s(h)}},n=a=>a.done?e(a.value):Promise.resolve(a.value).then(o,r);n((i=i.apply(l,t)).next())});const p={min:.2,max:1e3,ratio:.4};class rt extends q{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.operationMode=y.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>ot(this,null,function*(){var c,d;if(!this.imgNode)return;const u=(c=this._imgAttribute)==null?void 0:c.zoomRatio,m=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:f,imgInfo:C,zoom:v}=E.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(C),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,C)}),this.getCurrentPos=c=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let m;return d&&u?m={y:u.y+c.y-d.y,x:u.x+c.x-d.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(c,d,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const C=U.wheelChangePos(f,c,d,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:p.max,rotate:this.rotate});if(!C)return;const{currentPos:v,ratio:A,zoom:D,imgInfo:_}=C;this.setZoom(D),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(_),p.ratio=A,this.emit("renderZoom",D,v,_)},this.zoomChanged=(c,d=W.Linear)=>{const u=U.zoomChanged(this.zoom,c,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=c=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,c),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var i,e,s,o,r,n,a,h,L;this.container=t.container,this.config=P.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(e=(i=t.imgNode)==null?void 0:i.width)!=null?e:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:M[4],fillColor:M[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new Y,this.style=(a=t.style)!=null?a:P.jsonParser(F),this._imgAttribute=(h=t.imgAttribute)!=null?h:{},this.isHidden=!1,this.dragStatus=G.Wait,this.defaultAttribute=(L=t==null?void 0:t.defaultAttribute)!=null?L:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=H.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new $(this.container,200),this.coordUtils=new j(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return V[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===y.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===y.MultiMove&&this.setOperationMode(y.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return T.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s;const o=this.pixelRatio,r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,0),this.basicCanvas=r;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(r,this.container.childNodes[0])):(this.container.appendChild(r),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(Z({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:o,dependToolName:r}=this;if(t&&e&&r){let n=t;switch(r){case b.Polygon:case b.Line:{if(t.pointList){const h=S.calcViewportBoundaries(t.pointList);n={x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top}}break}}const a=E.getBasicRecPos(e,n,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);a&&(this.setCurrentPos(a.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(st(Z({},o),{width:o.width/this.innerZoom*a.innerZoom,height:o.height/this.innerZoom*a.innerZoom})),this.setZoom(a.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!x(i==null?void 0:i.x)||!x(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||K.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===I.Alt&&t.preventDefault(),t.keyCode){case I.Space:this.isSpaceKey=!0;break;case I.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case I.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>p.min&&(o=-1),s<0&&this.zoom<p.max&&(o=1),this.wheelChangePos(e,o),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=P.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",R.getMessagesByLocale(k.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",R.getMessagesByLocale(k.NoRotateNotice,this.lang)),!1;const t=S.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){var e;if((i==null?void 0:i.attributeConfigurable)===!0&&this.style.attributeColor){const r=z.getAttributeIndex(t,(e=i.attributeList)!=null?e:[])+1;return this.style.attributeColor[r]}const{color:s,toolColor:o}=this.style;return o?o[s]:N.toolColor["1"]}getLineColor(t=""){var i,e,s;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const n=z.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return this.style.attributeLineColor?this.style.attributeLineColor[n]:""}const{color:o,lineColor:r}=this.style;return o&&r?r[o]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=X.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case b.Rect:{g.drawRect(this.basicCanvas,w.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case b.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,w.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case b.Line:{g.drawLineWithPointList(this.basicCanvas,w.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{rt as BasicToolOperation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EToolName as p,ELineTypes as _,edgeAdsorptionScope as k}from"../../constant/tool.js";import U from"../../utils/tool/RectUtils.js";import x from"../../utils/tool/PolygonUtils.js";import j from"../../utils/tool/MarkerUtils.js";import E from"../../utils/MathUtils.js";import{EDragStatus as d,ESortDirection as T,DEFAULT_TEXT_OFFSET as z}from"../../constant/annotation.js";import S from"../../constant/keyCode.js";import P from"../../locales/index.js";import{EMessage as y}from"../../locales/constants.js";import I from"../../utils/tool/AttributeUtils.js";import u from"../../utils/tool/AxisUtils.js";import n from"../../utils/tool/CommonToolUtils.js";import v from"../../utils/tool/DrawUtils.js";import N from"../../utils/tool/StyleUtils.js";import B from"../../utils/uuid.js";import{BasicToolOperation as H}from"./basicToolOperation.js";import Z from"./textAttributeClass.js";var W=Object.defineProperty,F=Object.defineProperties,K=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable,M=Math.pow,R=(g,t,e)=>t in g?W(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,D=(g,t)=>{for(var e in t||(t={}))$.call(t,e)&&R(g,e,t[e]);if(w)for(var e of w(t))V.call(t,e)&&R(g,e,t[e]);return g},C=(g,t)=>F(g,K(t));const O=200;class X extends H{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(o=>o.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(I.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=u.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const o=u.changePointByZoom(s,this.zoom);return E.getLineLength(o,i)<.2})},this.config=n.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=n.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=n.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return I.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=d.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=d.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===d.Start||this.dragStatus===d.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===d.Move&&this.history.pushHistory(this.pointList),this.dragStatus=d.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=d.Move;const s=this.getCoordinateUnderZoom(t),o=u.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),l=this.drawOutsideTarget?u.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):u.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===p.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!x.isInPolygon(l,this.basicResult.pointList)||(this.pointList.forEach(h=>{h.id===this.selectedID&&(h.x=l.x,h.y=l.y)}),this.render())}onKeyDown(t){if(!n.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case S.Delete:this.deletePoint();break;case S.Tab:{this.onTabKeyDown(t);break}case S.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=I.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo)return;const{upperLimit:l}=this.config;if(l&&this.currentPageResult.length>=l){this.emit("messageInfo",`${P.getMessagesByLocale(y.LowerLimitPoint,this.lang)}`);return}const h=n.getSourceID(this.basicResult),m=this.getCoordinateUnderZoom(t);let c=u.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[p.Polygon,p.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const f=((i=this.referenceData)==null?void 0:i.toolName)===p.Polygon,{dropFoot:L,hasClosed:A}=x.getClosestPoint(c,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:_.Line,k/this.zoom,{isClose:f});L&&(c=L),A&&this.emit("messageSuccess",`${P.getMessagesByLocale(y.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let r=!1;switch(this.dependToolName){case p.Rect:{r=!U.isInRect(c,this.basicResult);break}case p.Polygon:{r=!x.isInPolygon(c,this.basicResult.pointList);break}}if(r)return}if(m.x<0||m.y<0||m.x>this.imgInfo.width||m.y>this.imgInfo.height)return}if(this.isMinDistance(c))return;let a=C(D({},c),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:B(8,62),sourceID:h,textAttribute:"",order:n.getMaxOrder(this.pointList.filter(r=>n.isSameSourceID(r.sourceID,h)))+1});if(this.config.textConfigurable){let r="";r=I.getTextAttribute(this.pointList.filter(f=>n.isSameSourceID(f.sourceID,h)),this.config.textCheckType),a=C(D({},a),{textAttribute:r})}if(this.hasMarkerConfig){const r=n.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(r)a=C(D({},a),{label:r.label}),this.markerIndex=r.index,this.emit("markIndexChange");else{this.emit("messageInfo",P.getMessagesByLocale(y.MarkerFinish,this.lang));return}}this.hoverID=a.id;const b=[...this.pointList,a];this.setPointList(b),this.history.pushHistory(b),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(M(t.x-e.x,2)+M(t.y-e.y,2))}getHoverId(){var t;const e=u.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=n.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===d.Move||this.dragStatus===d.Start)return;let e=T.ascend;t.shiftKey&&(e=T.descend);const[i,s]=n.getRenderResultList(this.pointList,n.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let o=[...i];s&&(o=[...o,s]);const l=n.getNextSelectedRectID(o,e,this.selectedID);l&&this.setSelectedID(l.id)}get currentPageResult(){const[t]=n.getRenderResultList(this.pointList,n.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=n.getRenderResultList(t,n.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===d.Move||this.dragStatus===d.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=d.Wait,{width:O*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;I.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",I.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(I.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(f=>f.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:l,valid:h}=i,m=O*this.zoom*.6,c=u.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),a=this.getColor(l),b=h?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,r=4;this._textAttributInstance||(this._textAttributInstance=new Z({width:m,container:this.container,icon:this.getTextIconSvg(l),color:b,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:c.x,top:c.y+r,color:b,width:m})}renderPoint(t){var e,i,s;const{textAttribute:o="",attribute:l}=t,h=t.id===this.selectedID,m=this.getColor(l),c=u.changePointByZoom(t,this.zoom,this.currentPos),{width:a=2,hiddenText:b=!1}=this.style,r=N.getStrokeAndFill(m,t.valid,{isSelected:h||t.id===this.hoverID});v.drawCircle(this.canvas,c,a,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:r.stroke,fill:r.fill});let f="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${n.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${j.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${I.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),b||v.drawText(this.canvas,{x:c.x+a/2,y:c.y-a-4},f,{textAlign:"center",color:r.stroke}),h?this.renderTextAttribute():b||v.drawText(this.canvas,{x:c.x+a,y:c.y+a+24},o,D({color:r.stroke},z))}renderPointList(){const[t,e]=n.getRenderResultList(this.pointList,n.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=u.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const l=((t=this.referenceData)==null?void 0:t.toolName)===p.Polygon,{dropFoot:h}=x.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:_.Line,k/this.zoom,{isClose:l});h&&o!==h&&o!==h&&(o=h,v.drawCircle(this.canvas,u.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),v.drawCircle(this.canvas,u.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}export{X as default};
|
|
1
|
+
import{EToolName as p,ELineTypes as A,edgeAdsorptionScope as _,EOperationMode as U}from"../../constant/tool.js";import E from"../../utils/tool/RectUtils.js";import L from"../../utils/tool/PolygonUtils.js";import j from"../../utils/tool/MarkerUtils.js";import z from"../../utils/MathUtils.js";import{EDragStatus as d,ESortDirection as k,DEFAULT_TEXT_OFFSET as N}from"../../constant/annotation.js";import S from"../../constant/keyCode.js";import y from"../../locales/index.js";import{EMessage as C}from"../../locales/constants.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import r from"../../utils/tool/CommonToolUtils.js";import x from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/StyleUtils.js";import H from"../../utils/uuid.js";import{BasicToolOperation as Z}from"./basicToolOperation.js";import W from"./textAttributeClass.js";var F=Object.defineProperty,K=Object.defineProperties,$=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,T=Math.pow,O=(g,t,e)=>t in g?F(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,D=(g,t)=>{for(var e in t||(t={}))V.call(t,e)&&O(g,e,t[e]);if(w)for(var e of w(t))X.call(t,e)&&O(g,e,t[e]);return g},P=(g,t)=>K(g,$(t));const R=200;class q extends Z{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(o=>o.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(v.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=c.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const o=c.changePointByZoom(s,this.zoom);return z.getLineLength(o,i)<.2})},this.config=r.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=r.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=r.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=d.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>P(D({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=d.Start,this.isMultiMoveMode&&(this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:this.pointList});return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===d.Start||this.dragStatus===d.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===d.Move&&(this.history.pushHistory(this.pointList),this.dragInfo=void 0),this.dragStatus=d.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=d.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const n={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(n);return}const o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),l=this.drawOutsideTarget?c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):c.changePointByZoom(o,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===p.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!L.isInPolygon(l,this.basicResult.pointList)||(this.pointList.forEach(n=>{n.id===this.selectedID&&(n.x=l.x,n.y=l.y)}),this.render())}onKeyDown(t){if(!r.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case S.Delete:this.deletePoint();break;case S.Tab:{this.onTabKeyDown(t);break}case S.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,o;if(!this.imgInfo)return;const{upperLimit:l}=this.config;if(l&&this.currentPageResult.length>=l){this.emit("messageInfo",`${y.getMessagesByLocale(C.LowerLimitPoint,this.lang)}`);return}const n=r.getSourceID(this.basicResult),m=this.getCoordinateUnderZoom(t);let u=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[p.Polygon,p.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const b=((i=this.referenceData)==null?void 0:i.toolName)===p.Polygon,{dropFoot:I,hasClosed:M}=L.getClosestPoint(u,this.referenceData.result,(o=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?o:A.Line,_/this.zoom,{isClose:b});I&&(u=I),M&&this.emit("messageSuccess",`${y.getMessagesByLocale(C.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let h=!1;switch(this.dependToolName){case p.Rect:{h=!E.isInRect(u,this.basicResult);break}case p.Polygon:{h=!L.isInPolygon(u,this.basicResult.pointList);break}}if(h)return}if(m.x<0||m.y<0||m.x>this.imgInfo.width||m.y>this.imgInfo.height)return}if(this.isMinDistance(u))return;let a=P(D({},u),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:H(8,62),sourceID:n,textAttribute:"",order:r.getMaxOrder(this.pointList.filter(h=>r.isSameSourceID(h.sourceID,n)))+1});if(this.config.textConfigurable){let h="";h=v.getTextAttribute(this.pointList.filter(b=>r.isSameSourceID(b.sourceID,n)),this.config.textCheckType),a=P(D({},a),{textAttribute:h})}if(this.hasMarkerConfig){const h=r.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)a=P(D({},a),{label:h.label}),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",y.getMessagesByLocale(C.MarkerFinish,this.lang));return}}this.hoverID=a.id;const f=[...this.pointList,a];this.setPointList(f),this.history.pushHistory(f),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(T(t.x-e.x,2)+T(t.y-e.y,2))}getHoverId(){var t;const e=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=r.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===d.Move||this.dragStatus===d.Start)return;let e=k.ascend;t.shiftKey&&(e=k.descend);const[i,s]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let o=[...i];s&&(o=[...o,s]);const l=r.getNextSelectedRectID(o,e,this.selectedID);l&&this.setSelectedID(l.id)}get currentPageResult(){const[t]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=r.getRenderResultList(t,r.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===d.Move||this.dragStatus===d.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(o=>o.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(o=>o.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=d.Wait,{width:R*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(v.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(b=>b.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:o,attribute:l,valid:n}=i,m=R*this.zoom*.6,u=c.getOffsetCoordinate({x:s,y:o},this.currentPos,this.zoom),a=this.getColor(l),f=n?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,h=4;this._textAttributInstance||(this._textAttributInstance=new W({width:m,container:this.container,icon:this.getTextIconSvg(l),color:f,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:u.x,top:u.y+h,color:f,width:m})}renderPoint(t,e=!1){var i,s,o;const{textAttribute:l="",attribute:n}=t,m=e||t.id===this.selectedID,u=this.getColor(n),a=c.changePointByZoom(t,this.zoom,this.currentPos),{width:f=2,hiddenText:h=!1}=this.style,b=B.getStrokeAndFill(u,t.valid,{isSelected:m||t.id===this.hoverID});x.drawCircle(this.canvas,a,f,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:b.stroke,fill:b.fill});let I="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(I=`${t.order}`),t.label&&this.hasMarkerConfig&&(I=`${r.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${j.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(I=`${I} ${v.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`),h||x.drawText(this.canvas,{x:a.x+f/2,y:a.y-f-4},I,{textAlign:"center",color:b.stroke}),m?this.renderTextAttribute():h||x.drawText(this.canvas,{x:a.x+f,y:a.y+f+24},l,D({color:b.stroke},N))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case U.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=r.getRenderResultList(this.pointList,r.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let o=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const l=((t=this.referenceData)==null?void 0:t.toolName)===p.Polygon,{dropFoot:n}=L.getClosestPoint(o,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:A.Line,_/this.zoom,{isClose:l});n&&o!==n&&o!==n&&(o=n,x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),x.drawCircle(this.canvas,c.changePointByZoom(o,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}export{q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import N from"../../utils/MathUtils.js";import S from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/RectUtils.js";import{EDragStatus as p,ESortDirection as O,DEFAULT_TEXT_SHADOW as _}from"../../constant/annotation.js";import{EOperationMode as C,EDragTarget as w}from"../../constant/tool.js";import M from"../../constant/keyCode.js";import P from"../../locales/index.js";import{EMessage as T}from"../../locales/constants.js";import L from"../../utils/tool/AttributeUtils.js";import U from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import k from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as E}from"../../utils/tool/polygonTool.js";import K from"../../utils/uuid.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var F=Object.defineProperty,X=Object.defineProperties,G=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,j=(D,t,e)=>t in D?F(D,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):D[t]=e,x=(D,t)=>{for(var e in t||(t={}))Y.call(t,e)&&j(D,e,t[e]);if(H)for(var e of H(t))J.call(t,e)&&j(D,e,t[e]);return D},m=(D,t)=>X(D,G(t));const A=6;class W extends V{constructor(t){super(t);this.operationMode=C.General,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=A,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:g}=this;if(g&&y.isInRect(i,g,r,this.zoom))return g.id}const h=o.filter(g=>y.isInRect(i,g,r,this.zoom));if(h.length===0)return"";if(h.length===1)return h[0].id;if(h.length>1)return h.map(s=>({size:s.width*s.height,id:s.id})).sort((s,f)=>s.size-f.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(L.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get isMultiMoveMode(){return this.operationMode===C.MultiMove}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setOperationMode(t){this.operationMode=t}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const r=this.selectedRectID;t!==r&&r&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;L.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",L.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?m(x({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?S.returnClosePointIndex(this.getCoordinateUnderZoom(t),y.getRectPointList(this.selectedRect,this.zoom),A+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=y.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let h=0;h<r.length;h++){const g=r[h],{length:s}=N.getFootOfPerpendicular(o,g.begin,g.end);s<A+10&&(e=h)}return e}getTextIconSvg(t=""){return L.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}multiMoveMouseDown(t){const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);return this.isMultiMoveMode&&i&&t.button===0?(this.dragInfo={dragStartCoord:e,dragTarget:w.Plane,startTime:+new Date,originRectList:this.rectList},this.dragStatus=p.Start,!0):!1}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0||this.multiMoveMouseDown(t))return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!(!r||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const o=w.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=w.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const o=w.Plane;this.dragInfo={dragStartCoord:e,dragTarget:o,firstRect:r,startTime:+new Date},this.dragStatus=p.Start}}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>m(x({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o,h,g;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=p.Move,this.isMultiMoveMode){this.onDragMoveAll(s);return}if(!this.dragInfo.firstRect)return;const f=y.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:l,y:c,width:u,height:d}=f;let n=this.rectList.filter(a=>a.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case w.Plane:n=m(x({},n),{x:l+s.x,y:c+s.y,width:u,height:d});break;case w.Point:{let a=l,b=c,I=u,v=d;switch(this.hoverRectPointIndex){case 0:{a=u-s.x<0?l+u:l+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(s.x-u),v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(u+s.x),v=Math.abs(d-s.y);break}case 2:{a=u+s.x>0?l:l+u+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(u+s.x),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(s.x-u),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v})}break;case w.Line:{let a=l,b=c,I=u,v=d;switch(this.hoverRectEdgeIndex){case 0:{b=d-s.y<0?c+d:c+s.y,v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,I=Math.abs(u+s.x);break}case 2:{b=d+s.y>0?c:c+d+s.y,v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,I=Math.abs(s.x-u);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(n,E(this.basicResult.pointList,this.zoom)))return;const a=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,I=this.basicResult.width*this.zoom,v=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==w.Plane&&(n.x<a-.01||n.y<b-.01||n.width>a+I-n.x+.01||n.height>b+v-n.y+.01))return;if(n.x<a&&(n.x=a),n.y<b&&(n.y=b),n.width>a+I-n.x)switch(this.dragInfo.dragTarget){case w.Plane:n.x=a+I-u;break;case w.Point:case w.Line:s.x>0&&s.y>0&&(n.width=a+I-n.x);break;default:return}if(n.height>b+v-n.y)switch(this.dragInfo.dragTarget){case w.Plane:n.y=b+v-d;break}}else if(n.x<0&&(n.x=0),n.y<0&&(n.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case w.Plane:n.x+n.width>((r=this.imgInfo)==null?void 0:r.width)&&(n.x=this.imgInfo.width-u),n.y+n.height>((o=this.imgInfo)==null?void 0:o.height)&&(n.y=this.imgInfo.height-d);break;default:if(n.x+n.width>((h=this.imgInfo)==null?void 0:h.width)+.01||n.y+n.height>((g=this.imgInfo)==null?void 0:g.height)+.01)return}}this.setRectList(this.rectList.map(a=>a.id===n.id?y.getRectUnderZoom(n,1/this.zoom):a)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=S.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if((this.selectedRectID||this.isMultiMoveMode)&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const s=this.getHoverRectPointIndex(t);if(s!==this.hoverRectPointIndex){this.hoverRectPointIndex=s,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const f=this.getHoverRectEdgeIndex(t);if(f!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=f,this.render();return}}}const h=this.getHoverRectID(t),g=this.hoverRectID;if(this.hoverRectID=h,h!==g&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:s,y:f}=this.firstClickCoord,{width:l,height:c}=this.drawingRect;if(l=Math.abs(s-o.x),c=Math.abs(f-o.y),o.x<s&&(s=o.x),o.y<f&&(f=o.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),E(this.basicResult.pointList,this.zoom)))return;o.x<0&&(l=Math.abs(this.firstClickCoord.x),s=0),o.y<0&&(c=Math.abs(this.firstClickCoord.y),f=0),this.imgInfo&&(s+l>this.imgInfo.width&&(l=Math.abs(this.imgInfo.width-s)),f+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-f)))}this.drawingRect=m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?m(x({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),r=S.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=m(x({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:K(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",P.getMessagesByLocale(T.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=L.getTextAttribute(this.rectList.filter(h=>R.isSameSourceID(h.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=x({},r),this.firstCurrentPos=x({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",P.getMessagesByLocale(T.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=p.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=p.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,m(x({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(o=>o.id===e),{selectedRectID:r}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(r!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(i.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(this.isMultiMoveMode&&this.setOperationMode(C.General),t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case M.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case M.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case M.Z:this.setIsHidden(!this.isHidden),this.render();break;case M.Delete:this.deleteRect(this.selectedRectID);break;case M.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=O.ascend;t.shiftKey&&(i=O.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let h=[...r];o&&(h=[...h,o]);const g=U.getViewPort(this.canvas,this.currentPos,this.zoom);h=h.filter(f=>U.inViewPort({x:f.x,y:f.y},g));const s=R.getNextSelectedRectID(h,i,this.selectedRectID);s&&(this.setSelectedRectID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute));break}default:{if(this.config.attributeConfigurable){const i=L.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case M.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=y.getRectUnderZoom(this.drawingRect,1/e),r=S.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=y.getRectUnderZoom(i,this.zoom),this.firstClickCoord=S.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:h,attribute:g,valid:s}=e,f=o*this.zoom*.6,l=S.getOffsetCoordinate({x:i,y:r+h},this.currentPos,this.zoom),c=this.getColor(g),u=s?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new $({width:f,container:this.container,icon:this.getTextIconSvg(g),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+d,color:u,width:f})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=y.getRectPointList(t),o=r.length,h=this.getColor(t.attribute);r.forEach((g,s)=>{var f,l;if(e.save(),e.moveTo(g.x,g.y),e.beginPath(),this.hoverRectPointIndex===s?i=A+6:i=A,t.valid===!1?(e.strokeStyle=h==null?void 0:h.invalid.stroke,e.fillStyle=h==null?void 0:h.invalid.stroke):(e.strokeStyle=h==null?void 0:h.valid.stroke,e.fillStyle=h==null?void 0:h.valid.stroke),e.arc(g.x*this.zoom+this.currentPos.x,g.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===s){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),u=t.valid===!1?(f=c==null?void 0:c.invalid)==null?void 0:f.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=u,e.moveTo(r[s].x*this.zoom+this.currentPos.x,r[s].y*this.zoom+this.currentPos.y),e.lineTo(r[(s+1)%o].x*this.zoom+this.currentPos.x,r[(s+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,o,h,g;if(this.ctx&&t){const{ctx:s,style:f}=this,{hiddenText:l=!1}=f;s.save();const{strokeColor:c,fillColor:u,textColor:d}=this.getRenderStyle(t);s.font="lighter 14px Arial";let n="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(n=`${t.order}`),t.label&&this.hasMarkerConfig&&(n=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${B.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(n=`${n} ${L.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const a=S.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||k.drawText(this.canvas,{x:a.x,y:a.y-6},n,m(x({color:c,font:"normal normal 900 14px SourceHanSansCN-Regular"},_),{textMaxWidth:300}));const b=(g=(h=this.style)==null?void 0:h.width)!=null?g:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&k.drawRectWithFill(this.canvas,a,{color:u}),k.drawRect(this.canvas,a,{color:c,thickness:b,hiddenText:!0}),s.restore();let I=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(I=`${Math.round(t.width/this.zoom)} * ${Math.round(a.height/this.zoom)}`);const v=I.length*7;if(l||k.drawText(this.canvas,{x:a.x+a.width-v,y:a.y+a.height+15},I,x({color:d,font:"normal normal 600 14px Arial"},_)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,a.width-v);k.drawText(this.canvas,{x:a.x,y:a.y+a.height+20+z},t.textAttribute,x({color:d,font:"italic normal 900 14px Arial",textMaxWidth:Z},_))}}}renderMultiSelectedRect(){this.operationMode===C.MultiMove&&this.rectList.forEach(t=>{this.renderDrawingRect(t),this.renderSelectedRect(t)})}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,S.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&(this.renderDrawingRect(r),this.renderSelectedRect(r),e.selectedRender&&e.selectedRender(this.canvas,S.changeRectByZoom(r,this.zoom,this.currentPos),this.getRenderStyle(r)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,S.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){switch(this.operationMode){case C.MultiMove:this.renderMultiSelectedRect();break;default:this.renderStaticRect(),this.renderCreatingRect()}}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(r=>r.id===this.selectedID?m(x({},r),{attribute:this.defaultAttribute}):r),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=p.Wait,this.setSelectedRectID(void 0),this.setOperationMode(C.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",P.getMessagesByLocale(T.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",P.getMessagesByLocale(T.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
|
|
1
|
+
import N from"../../utils/MathUtils.js";import S from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/RectUtils.js";import{EDragStatus as L,ESortDirection as O,DEFAULT_TEXT_SHADOW as T}from"../../constant/annotation.js";import{EDragTarget as w,EOperationMode as _}from"../../constant/tool.js";import p from"../../constant/keyCode.js";import A from"../../locales/index.js";import{EMessage as P}from"../../locales/constants.js";import C from"../../utils/tool/AttributeUtils.js";import U from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import k from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as E}from"../../utils/tool/polygonTool.js";import K from"../../utils/uuid.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var F=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,j=(D,t,e)=>t in D?F(D,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):D[t]=e,x=(D,t)=>{for(var e in t||(t={}))G.call(t,e)&&j(D,e,t[e]);if(H)for(var e of H(t))J.call(t,e)&&j(D,e,t[e]);return D},m=(D,t)=>X(D,Y(t));const M=6;class W extends V{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=M,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:g}=this;if(g&&y.isInRect(i,g,r,this.zoom))return g.id}const h=o.filter(g=>y.isInRect(i,g,r,this.zoom));if(h.length===0)return"";if(h.length===1)return h[0].id;if(h.length>1)return h.map(s=>({size:s.width*s.height,id:s.id})).sort((s,f)=>s.size-f.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(C.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const r=this.selectedRectID;t!==r&&r&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;C.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",C.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?m(x({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?S.returnClosePointIndex(this.getCoordinateUnderZoom(t),y.getRectPointList(this.selectedRect,this.zoom),M+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=y.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let h=0;h<r.length;h++){const g=r[h],{length:s}=N.getFootOfPerpendicular(o,g.begin,g.end);s<M+10&&(e=h)}return e}getTextIconSvg(t=""){return C.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}multiMoveMouseDown(t){const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);return this.isMultiMoveMode&&i&&t.button===0?(this.dragInfo={dragStartCoord:e,dragTarget:w.Plane,startTime:+new Date,originRectList:this.rectList},this.dragStatus=L.Start,!0):!1}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0||this.multiMoveMouseDown(t))return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!(!r||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const o=w.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=L.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=w.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=L.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const o=w.Plane;this.dragInfo={dragStartCoord:e,dragTarget:o,firstRect:r,startTime:+new Date},this.dragStatus=L.Start}}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>m(x({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o,h,g;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=L.Move,this.isMultiMoveMode){this.onDragMoveAll(s);return}if(!this.dragInfo.firstRect)return;const f=y.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:l,y:c,width:u,height:d}=f;let n=this.rectList.filter(a=>a.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case w.Plane:n=m(x({},n),{x:l+s.x,y:c+s.y,width:u,height:d});break;case w.Point:{let a=l,b=c,I=u,v=d;switch(this.hoverRectPointIndex){case 0:{a=u-s.x<0?l+u:l+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(s.x-u),v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(u+s.x),v=Math.abs(d-s.y);break}case 2:{a=u+s.x>0?l:l+u+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(u+s.x),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(s.x-u),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v})}break;case w.Line:{let a=l,b=c,I=u,v=d;switch(this.hoverRectEdgeIndex){case 0:{b=d-s.y<0?c+d:c+s.y,v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,I=Math.abs(u+s.x);break}case 2:{b=d+s.y>0?c:c+d+s.y,v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,I=Math.abs(s.x-u);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(n,E(this.basicResult.pointList,this.zoom)))return;const a=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,I=this.basicResult.width*this.zoom,v=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==w.Plane&&(n.x<a-.01||n.y<b-.01||n.width>a+I-n.x+.01||n.height>b+v-n.y+.01))return;if(n.x<a&&(n.x=a),n.y<b&&(n.y=b),n.width>a+I-n.x)switch(this.dragInfo.dragTarget){case w.Plane:n.x=a+I-u;break;case w.Point:case w.Line:s.x>0&&s.y>0&&(n.width=a+I-n.x);break;default:return}if(n.height>b+v-n.y)switch(this.dragInfo.dragTarget){case w.Plane:n.y=b+v-d;break}}else if(n.x<0&&(n.x=0),n.y<0&&(n.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case w.Plane:n.x+n.width>((r=this.imgInfo)==null?void 0:r.width)&&(n.x=this.imgInfo.width-u),n.y+n.height>((o=this.imgInfo)==null?void 0:o.height)&&(n.y=this.imgInfo.height-d);break;default:if(n.x+n.width>((h=this.imgInfo)==null?void 0:h.width)+.01||n.y+n.height>((g=this.imgInfo)==null?void 0:g.height)+.01)return}}this.setRectList(this.rectList.map(a=>a.id===n.id?y.getRectUnderZoom(n,1/this.zoom):a)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=S.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if((this.selectedRectID||this.isMultiMoveMode)&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const s=this.getHoverRectPointIndex(t);if(s!==this.hoverRectPointIndex){this.hoverRectPointIndex=s,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const f=this.getHoverRectEdgeIndex(t);if(f!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=f,this.render();return}}}const h=this.getHoverRectID(t),g=this.hoverRectID;if(this.hoverRectID=h,h!==g&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:s,y:f}=this.firstClickCoord,{width:l,height:c}=this.drawingRect;if(l=Math.abs(s-o.x),c=Math.abs(f-o.y),o.x<s&&(s=o.x),o.y<f&&(f=o.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),E(this.basicResult.pointList,this.zoom)))return;o.x<0&&(l=Math.abs(this.firstClickCoord.x),s=0),o.y<0&&(c=Math.abs(this.firstClickCoord.y),f=0),this.imgInfo&&(s+l>this.imgInfo.width&&(l=Math.abs(this.imgInfo.width-s)),f+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-f)))}this.drawingRect=m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?m(x({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),r=S.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=m(x({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:K(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",A.getMessagesByLocale(P.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=C.getTextAttribute(this.rectList.filter(h=>R.isSameSourceID(h.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=x({},r),this.firstCurrentPos=x({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",A.getMessagesByLocale(P.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,m(x({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(o=>o.id===e),{selectedRectID:r}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(r!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(i.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===L.Move){this.dragInfo=void 0,this.dragStatus=L.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(this.isMultiMoveMode&&this.setOperationMode(_.General),t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case p.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case p.Z:this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deleteRect(this.selectedRectID);break;case p.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=O.ascend;t.shiftKey&&(i=O.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let h=[...r];o&&(h=[...h,o]);const g=U.getViewPort(this.canvas,this.currentPos,this.zoom);h=h.filter(f=>U.inViewPort({x:f.x,y:f.y},g));const s=R.getNextSelectedRectID(h,i,this.selectedRectID);s&&(this.setSelectedRectID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute));break}default:{if(this.config.attributeConfigurable){const i=C.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=y.getRectUnderZoom(this.drawingRect,1/e),r=S.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=y.getRectUnderZoom(i,this.zoom),this.firstClickCoord=S.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:h,attribute:g,valid:s}=e,f=o*this.zoom*.6,l=S.getOffsetCoordinate({x:i,y:r+h},this.currentPos,this.zoom),c=this.getColor(g),u=s?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new $({width:f,container:this.container,icon:this.getTextIconSvg(g),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+d,color:u,width:f})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=y.getRectPointList(t),o=r.length,h=this.getColor(t.attribute);r.forEach((g,s)=>{var f,l;if(e.save(),e.moveTo(g.x,g.y),e.beginPath(),this.hoverRectPointIndex===s?i=M+6:i=M,t.valid===!1?(e.strokeStyle=h==null?void 0:h.invalid.stroke,e.fillStyle=h==null?void 0:h.invalid.stroke):(e.strokeStyle=h==null?void 0:h.valid.stroke,e.fillStyle=h==null?void 0:h.valid.stroke),e.arc(g.x*this.zoom+this.currentPos.x,g.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===s){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),u=t.valid===!1?(f=c==null?void 0:c.invalid)==null?void 0:f.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=u,e.moveTo(r[s].x*this.zoom+this.currentPos.x,r[s].y*this.zoom+this.currentPos.y),e.lineTo(r[(s+1)%o].x*this.zoom+this.currentPos.x,r[(s+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,o,h,g;if(this.ctx&&t){const{ctx:s,style:f}=this,{hiddenText:l=!1}=f;s.save();const{strokeColor:c,fillColor:u,textColor:d}=this.getRenderStyle(t);s.font="lighter 14px Arial";let n="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(n=`${t.order}`),t.label&&this.hasMarkerConfig&&(n=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${B.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(n=`${n} ${C.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const a=S.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||k.drawText(this.canvas,{x:a.x,y:a.y-6},n,m(x({color:c,font:"normal normal 900 14px SourceHanSansCN-Regular"},T),{textMaxWidth:300}));const b=(g=(h=this.style)==null?void 0:h.width)!=null?g:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&k.drawRectWithFill(this.canvas,a,{color:u}),k.drawRect(this.canvas,a,{color:c,thickness:b,hiddenText:!0}),s.restore();let I=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(I=`${Math.round(t.width/this.zoom)} * ${Math.round(a.height/this.zoom)}`);const v=I.length*7;if(l||k.drawText(this.canvas,{x:a.x+a.width-v,y:a.y+a.height+15},I,x({color:d,font:"normal normal 600 14px Arial"},T)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,a.width-v);k.drawText(this.canvas,{x:a.x,y:a.y+a.height+20+z},t.textAttribute,x({color:d,font:"italic normal 900 14px Arial",textMaxWidth:Z},T))}}}renderMultiSelectedRect(){!this.isMultiMoveMode||this.rectList.forEach(t=>{this.renderDrawingRect(t),this.renderSelectedRect(t)})}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,S.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&(this.renderDrawingRect(r),this.renderSelectedRect(r),e.selectedRender&&e.selectedRender(this.canvas,S.changeRectByZoom(r,this.zoom,this.currentPos),this.getRenderStyle(r)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,S.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){switch(this.operationMode){case _.MultiMove:this.renderMultiSelectedRect();break;default:this.renderStaticRect(),this.renderCreatingRect()}}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(r=>r.id===this.selectedID?m(x({},r),{attribute:this.defaultAttribute}):r),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait,this.setSelectedRectID(void 0),this.setOperationMode(_.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",A.getMessagesByLocale(P.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",A.getMessagesByLocale(P.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.10.0-alpha.
|
|
3
|
+
"version": "1.10.0-alpha.5",
|
|
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.4.0-alpha.
|
|
95
|
+
"@labelbee/lb-utils": "^1.4.0-alpha.5",
|
|
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": "
|
|
101
|
+
"gitHead": "0021238d19a2f4439005c54016ff975c1017280b"
|
|
102
102
|
}
|