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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/core/pointCloud/annotation.js +1 -1
  2. package/dist/core/pointCloud/index.js +2 -2
  3. package/dist/core/scheduler.js +1 -1
  4. package/dist/core/toolOperation/LineToolOperation.js +1 -1
  5. package/dist/core/toolOperation/Selection.js +1 -0
  6. package/dist/core/toolOperation/cuboidOperation.js +1 -1
  7. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
  8. package/dist/core/toolOperation/pointOperation.js +1 -1
  9. package/dist/core/toolOperation/polygonOperation.js +1 -1
  10. package/dist/core/toolOperation/rectOperation.js +1 -1
  11. package/dist/core/toolOperation/textAttributeClass.js +9 -9
  12. package/dist/types/core/index.d.ts +2 -2
  13. package/dist/types/core/pointCloud/annotation.d.ts +2 -1
  14. package/dist/types/core/pointCloud/index.d.ts +8 -3
  15. package/dist/types/core/scheduler.d.ts +16 -3
  16. package/dist/types/core/toolOperation/LineToolOperation.d.ts +26 -36
  17. package/dist/types/core/toolOperation/Selection.d.ts +70 -0
  18. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +2 -10
  19. package/dist/types/core/toolOperation/pointOperation.d.ts +10 -4
  20. package/dist/types/core/toolOperation/polygonOperation.d.ts +23 -14
  21. package/dist/types/core/toolOperation/rectOperation.d.ts +41 -10
  22. package/dist/types/core/toolOperation/textAttributeClass.d.ts +6 -0
  23. package/dist/types/utils/tool/CommonToolUtils.d.ts +2 -2
  24. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +2 -2
  25. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -1
  26. package/dist/utils/tool/CommonToolUtils.js +1 -1
  27. package/dist/utils/tool/PolygonUtils.js +1 -1
  28. package/es/core/pointCloud/annotation.js +1 -1
  29. package/es/core/pointCloud/index.js +2 -2
  30. package/es/core/scheduler.js +1 -1
  31. package/es/core/toolOperation/LineToolOperation.js +1 -1
  32. package/es/core/toolOperation/Selection.js +1 -0
  33. package/es/core/toolOperation/cuboidOperation.js +1 -1
  34. package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
  35. package/es/core/toolOperation/pointOperation.js +1 -1
  36. package/es/core/toolOperation/polygonOperation.js +1 -1
  37. package/es/core/toolOperation/rectOperation.js +1 -1
  38. package/es/core/toolOperation/textAttributeClass.js +9 -9
  39. package/es/utils/tool/CommonToolUtils.js +1 -1
  40. package/es/utils/tool/PolygonUtils.js +1 -1
  41. package/package.json +2 -2
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.visiblePolygonList,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.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),r=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const a=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=a,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3,minArea:i=1}=this.config;e<3&&(e=3),i<1&&(i=1);let s;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(PolygonUtils.calcPolygonSize(this.drawingPointList||[])<i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinAreaLimitErrorNotice,this.lang)}${i}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),l=[...this.polygonList];if(this.editPolygonID){const n=l.find(r=>r.id===this.editPolygonID);if(!n)return;n.pointList=this.drawingPointList,this.editPolygonID=""}else{const n=uuid(8,62);let r={id:n,sourceID:o,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(l.filter(a=>CommonToolUtils.isSameSourceID(a.sourceID,o)))+1};if(this.config.textConfigurable){let a="";a=AttributeUtils.default.getTextAttribute(this.polygonList.filter(d=>CommonToolUtils.isSameSourceID(d.sourceID,o)),this.config.textCheckType),r=__spreadProps(__spreadValues({},r),{textAttribute:a})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(r=__spreadProps(__spreadValues({},r),{isRect:!0})),l.push(r),s=r,this.setSelectedIdAfterAddingDrawing(n)}this.setPolygonList(l),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(l),s&&this.emit("polygonCreated",s,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var a,d,g,h;return __spreadProps(__spreadValues({},r),{x:(d=(a=r.pointList[0])==null?void 0:a.x)!=null?d:0,y:(h=(g=r.pointList[0])==null?void 0:g.y)!=null?h:0})}).filter(r=>CanvasUtils.inViewPort({x:r.x,y:r.y},o)),n=CommonToolUtils.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygon(this.selectedID),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let l=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const r=this.getHoverPointIndex(t),a=this.getHoverEdgeIndex(t);r>-1?(n=annotation.EDragTarget.Point,l=[r]):a>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,l=[a,(a+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:l,originPolygon:this.selectedPolygon,dragPrevCoord:o,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=PolygonUtils.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",a=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(h=>{var u,f;return h.id===this.selectedID?(r=h.attribute,a=(u=h==null?void 0:h.valid)!=null?u:!0,g=(f=h==null?void 0:h.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},h),{pointList:n})):h}),l.length>0&&l.forEach((h,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:h,valid:a,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:r,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(a=>a.id===this.selectedID),o=this.currentShowList.find(a=>a.id===i);if(!o||!s)return;const l=PolygonUtils.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const a=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(a),this.history.pushHistory(a),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(r=>!RectUtils.isInRect(r,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:a}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),g=MathUtils.default.getArrayIndex(n[0]-1,4),h=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(a,s,h);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-a.x)/this.zoom,y:(s.y-a.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+n.x,y:r.y+n.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((r,a)=>l&&l.includes(a)?__spreadProps(__spreadValues({},r),{x:s[a].x+n.x,y:s[a].y+n.y}):r);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&l&&(i=MathUtils.default.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onDragMove(t){const e=this.polygonList.map(i=>{if(i.id===this.selectedID){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.enableDrag){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}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.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],a=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),h=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:a,container:this.container,icon:this.getTextIconSvg(s),color:h,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${l}`,{left:d.x,top:d.y,color:h,width:a})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:a}=e,d=this.getColor(a),g=StyleUtils.getStrokeAndFill(d,e.valid),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(l=AttributeUtils.default.getAttributeShowText(a,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,h[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=h[h.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},r,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;const{selectedPolygon:s}=this;if(s){const o=this.getColor(s.attribute),l=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:l.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:a}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);a&&(r=a)}n.push(r)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),a=n==null?void 0:n.pointList[this.hoverPointIndex];if(a){const{x:d,y:g}=AxisUtils.default.changePointByZoom(a,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
1
+ "use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(c){return c&&typeof c=="object"&&"default"in c?c:{default:c}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new Selection(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),r=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(PolygonUtils.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=uuid(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(r=>CommonToolUtils.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:r})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,d,g,a;return __spreadProps(__spreadValues({},r),{x:(d=(h=r.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=r.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(r=>CanvasUtils.inViewPort({x:r.x,y:r.y},o)),n=CommonToolUtils.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){if(super.onKeyUp(t),!this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))switch(t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=annotation.EDragTarget.Plane;const o=this.selectedPolygons[0].pointList,l=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=annotation.EDragStatus.Start;const n=this.getHoverPointIndex(t),r=this.getHoverEdgeIndex(t);n>-1?(s=annotation.EDragTarget.Point,i=[n]):r>-1&&this.hoverEdgeIndex>-1&&(s=annotation.EDragTarget.Line,i=[r,(r+1)%o.length])}this.dragInfo={dragStartCoord:l,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:l,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=PolygonUtils.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const d=CommonToolUtils.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(r=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,g=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),l.length>0&&l.forEach((a,u)=>{o.push({sourceID:d,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:r,textAttribute:g})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=PolygonUtils.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(d=>!r.includes(d.id)).map(d=>d.id===this.selectedID?n:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(r=>!RectUtils.isInRect(r,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=__spreadProps(__spreadValues({},i),{pointList:s});return i.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(o)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),g=MathUtils.default.getArrayIndex(n[0]-1,4),a=[r[d],r[g]],u=MathUtils.default.getRectPerpendicularOffset(h,s,a);return{x:u.x/this.zoom,y:u.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===annotation.EDragTarget.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=___default.default.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=annotation.EDragStatus.Move,o){case annotation.EDragTarget.Plane:i=i.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+n.x,y:r.y+n.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((r,h)=>l&&l.includes(h)?__spreadProps(__spreadValues({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&o===annotation.EDragTarget.Point&&l&&(i=MathUtils.default.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render()),this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t)}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList);return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&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.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=TEXT_MAX_WIDTH,d=AxisUtils.default.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${l}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,d=this.getColor(h),g=StyleUtils.getStrokeAndFill(d,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:g.fill,strokeColor:g.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(l=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},r,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),l=StyleUtils.getStrokeAndFill(o,t.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let n=`${(i=AttributeUtils.default.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(n=`${t.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:l.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const o=this.getColor(this.defaultAttribute),l=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(r=h)}n.push(r)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:d,y:g}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:d,y:g},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
@@ -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.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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),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"),Selection=require("./Selection.js");function _interopDefaultLegacy(R){return R&&typeof R=="object"&&"default"in R?R:{default:R}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(R,t,e)=>t in R?__defProp(R,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):R[t]=e,__spreadValues=(R,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(R,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(R,e,t[e]);return R},__spreadProps=(R,t)=>__defProps(R,__getOwnPropDescs(t));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 s=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===s);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const s=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:l}=this;if(l&&RectUtils.isInRect(s,l,r,this.zoom))return l.id}const i=o.filter(l=>RectUtils.isInRect(s,l,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(n=>({size:n.width*n.height,id:n.id})).sort((n,h)=>n.size-h.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),this.selection=new Selection(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._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const s=this.rectList.length;this.rectList=t,s!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,s]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),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,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){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(s=>s.id===this.selectedRectID?__spreadProps(__spreadValues({},s),{textAttribute:e}):s),!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:s}=this,r=RectUtils.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const l=r[i],{length:n}=MathUtils.default.getFootOfPerpendicular(o,l.begin,l.end);n<scope+10&&(e=i)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),s=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;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(this.selection.isIdSelected(s)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const s=t.reduce((r,o)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(o,e))),[]);return MathUtils.default.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,o,i;if(this.config.drawOutsideTarget!==!1)return!1;const l=this.getRectsBoundaries(t,e),n={y:l.top,x:l.left,height:l.bottom-l.top,width:l.right-l.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(n,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const h=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(i=this.imgNode)==null?void 0:i.width};if(h)return[{x:l.left,y:l.top},{x:l.right,y:l.bottom}].some(c=>!RectUtils.isInRect(c,h))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=s.find(i=>i.id===r.id);return o||r}))}}onDragMoveAll(t){var e,s;!((s=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:s.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,s,r,o;if(!this.dragInfo)return;const i={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const l=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:h,width:c,height:a}=l;let d=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let g=n,f=h,u=c,x=a;switch(this.hoverRectPointIndex){case 0:{g=c-i.x<0?n+c:n+i.x,f=a-i.y<0?h+a:h+i.y,u=Math.abs(i.x-c),x=Math.abs(i.y-a);break}case 1:{g=c+i.x>0?n:n+c+i.x,f=a-i.y<0?h+a:h+i.y,u=Math.abs(c+i.x),x=Math.abs(a-i.y);break}case 2:{g=c+i.x>0?n:n+c+i.x,f=a+i.y>0?h:h+a+i.y,u=Math.abs(c+i.x),x=a+i.y>0?a+i.y:Math.abs(a+i.y);break}case 3:{g=c-i.x<0?n+c:n+i.x,f=a+i.y>0?h:h+a+i.y,u=Math.abs(i.x-c),x=a+i.y>0?a+i.y:Math.abs(a+i.y);break}default:return}d=__spreadProps(__spreadValues({},d),{x:g,y:f,width:u,height:x})}break;case tool.EDragTarget.Line:{let g=n,f=h,u=c,x=a;switch(this.hoverRectEdgeIndex){case 0:{f=a-i.y<0?h+a:h+i.y,x=Math.abs(i.y-a);break}case 1:{g=c+i.x>0?n:n+c+i.x,u=Math.abs(c+i.x);break}case 2:{f=a+i.y>0?h:h+a+i.y,x=a+i.y>0?a+i.y:Math.abs(a+i.y);break}case 3:{g=c-i.x<0?n+c:n+i.x,u=Math.abs(i.x-c);break}default:return}d=__spreadProps(__spreadValues({},d),{x:g,y:f,width:u,height:x});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(d,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,f=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(d.x<g-.01||d.y<f-.01||d.width>g+u-d.x+.01||d.height>f+x-d.y+.01)return;if(d.x<g&&(d.x=g),d.y<f&&(d.y=f),d.width>g+u-d.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:i.x>0&&i.y>0&&(d.width=g+u-d.x);break;default:return}if(d.height>f+x-d.y)switch(this.dragInfo.dragTarget){}}else if(d.x<0&&(d.x=0),d.y<0&&(d.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(d.x+d.width>((r=this.imgInfo)==null?void 0:r.width)+.01||d.y+d.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===d.id?RectUtils.getRectUnderZoom(d,1/this.zoom):g)),this.render()}onMouseMove(t){var e,s;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.selectedIDs.length>0&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const i=this.getHoverRectID(t),l=this.hoverRectID;if(this.hoverRectID=i,i!==l&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:h}=this.firstClickCoord,{width:c,height:a}=this.drawingRect;if(c=Math.abs(n-o.x),a=Math.abs(h-o.y),o.x<n&&(n=o.x),o.y<h&&(h=o.y),this.config.drawOutsideTarget===!1){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:h,width:c,height:a}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;o.x<0&&(c=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(a=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(n+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-n)),h+a>this.imgInfo.height&&(a=Math.abs(this.imgInfo.height-h)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:h,width:c,height:a}),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 s=this.getCoordinateUnderZoom(t),r=AxisUtils.default.changeDrawOutsideTarget(s,{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(i=>CommonToolUtils.isSameSourceID(i.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 s=this.getDrawingRectWithRectList();this.setRectList(s,!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:s,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,s/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:s,height:r})]}rightMouseUp(t){var e,s;const r=this.getHoverRectID(t),o=this.rectList.find(i=>i.id===r);if(o&&this.setDefaultAttribute(o.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((s=this.dragInfo)==null?void 0:s.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(r,t.ctrlKey),this.hoverRectID="",(o==null?void 0:o.label)&&this.hasMarkerConfig){const i=CommonToolUtils.getCurrentMarkerIndex(o.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),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(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.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}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.deleteSelectedRect();break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=annotation.ESortDirection.ascend;t.shiftKey&&(s=annotation.ESortDirection.descend);const[r,o]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const l=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(h=>CanvasUtils.inViewPort({x:h.x,y:h.y},l));const n=CommonToolUtils.getNextSelectedRectID(i,s,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const s=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){if(super.onKeyUp(t),!this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))switch(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 s,r;this.drawingRect&&this.firstClickCoord&&(s=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(s,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),s=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:s}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const s=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,o=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,o=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:s}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:s,y:r,width:o,height:i,attribute:l,valid:n}=e,h=o*this.zoom*.6,c=AxisUtils.default.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),a=this.getColor(l),d=n?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(l),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+g,color:d,width:h})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=RectUtils.getRectPointList(t),o=r.length,i=this.getColor(t.attribute);r.forEach((l,n)=>{var h,c;if(e.save(),e.moveTo(l.x,l.y),e.beginPath(),this.hoverRectPointIndex===n?s=scope+6:s=scope,t.valid===!1?(e.strokeStyle=i==null?void 0:i.invalid.stroke,e.fillStyle=i==null?void 0:i.invalid.stroke):(e.strokeStyle=i==null?void 0:i.valid.stroke,e.fillStyle=i==null?void 0:i.valid.stroke),e.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const a=this.getColor(t.attribute),d=t.valid===!1?(h=a==null?void 0:a.invalid)==null?void 0:h.stroke:(c=a==null?void 0:a.valid)==null?void 0:c.stroke;e.strokeStyle=d,e.moveTo(r[n].x*this.zoom+this.currentPos.x,r[n].y*this.zoom+this.currentPos.y),e.lineTo(r[(n+1)%o].x*this.zoom+this.currentPos.x,r[(n+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,o,i,l;if(this.ctx&&t){const{ctx:n,style:h}=this,{hiddenText:c=!1}=h;n.save();const{strokeColor:a,fillColor:d,textColor:g}=this.getRenderStyle(t);n.font="lighter 14px Arial";let f="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=AxisUtils.default.changeRectByZoom(t,s?e:this.zoom,this.currentPos);c||DrawUtils.drawText(this.canvas,{x:u.x,y:u.y-6},f,__spreadProps(__spreadValues({color:a,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300}));const x=(l=(i=this.style)==null?void 0:i.width)!=null?l:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,u,{color:d}),DrawUtils.drawRect(this.canvas,u,{color:a,thickness:x,hiddenText:!0}),n.restore();let b=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(b=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const v=b.length*7;if(c||DrawUtils.drawText(this.canvas,{x:u.x+u.width-v,y:u.y+u.height+15},b,__spreadValues({color:g,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const I=0,w=Math.max(20,u.width-v);DrawUtils.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+I},t.textAttribute,__spreadValues({color:g,font:"italic normal 900 14px Arial",textMaxWidth:w},annotation.DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||s==null||s.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))})}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(){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"),this.selectedRects&&(this.setRectList(this.rectList.map(s=>this.selection.isIdSelected(s.id)?__spreadProps(__spreadValues({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.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(s=>s.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 s=this.rectList.find(r=>r.id===t);if((s==null?void 0:s.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._textAttributeInstance)==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,23 +1,23 @@
1
- "use strict";var keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js");const defaultWidth=30,DEFAULT_TEXT_WIDTH=164;class TextAttributeClass{constructor(t){this.textKeyDown=a=>{switch(a.stopPropagation(),a.keyCode){case keyCode.Enter:this.submitTextarea(),this.appendToContainer();break}};const{container:i,icon:e,color:r,getCurrentSelectedData:o,updateSelectedTextAttribute:n}=t,s=t.width||DEFAULT_TEXT_WIDTH;this.container=i,this.getCurrentSelectedData=o,this.updateSelectedTextAttribute=n,this._textAttributeDOM=this.initTextAttributeDOM(),this._iconDOM=this.initIconDOM(e),this._textDOM=this.initTextDOM(s,tool.TEXT_ATTRIBUTE_LINE_HEIGHT),this._textareaDOM=this.initTextareaDOM(s,r),this.appendToContainer()}get isExit(){return this._textAttributeDOM?this.container.contains(this._textAttributeDOM):!1}get isExitTextareaDOM(){return this._textareaDOM?this.container.contains(this._textareaDOM):!1}updateIcon(t){this._iconDOM&&(this._iconDOM.innerHTML=t)}appendToContainer(){!this._textAttributeDOM||!this._textDOM||!this._iconDOM||(this.container.appendChild(this._textAttributeDOM),this._textAttributeDOM.appendChild(this._textDOM),this._textAttributeDOM.appendChild(this._iconDOM))}initTextAttributeDOM(){const t=document.createElement("div");return t.setAttribute("id","textArea"),t}initTextDOM(t,i){const e=document.createElement("span");return e.setAttribute("style",`
1
+ "use strict";var _=require("lodash"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js");const defaultWidth=30,DEFAULT_TEXT_WIDTH=164;class TextAttributeClass{constructor(t){this.textKeyDown=a=>{switch(a.stopPropagation(),a.keyCode){case keyCode.Enter:this.submitTextarea(),this.appendToContainer();break}};const{container:e,icon:i,color:r,getCurrentSelectedData:o,updateSelectedTextAttribute:n}=t,s=t.width||DEFAULT_TEXT_WIDTH;this.container=e,this.getCurrentSelectedData=o,this.updateSelectedTextAttribute=n,this._textAttributeDOM=this.initTextAttributeDOM(),this._iconDOM=this.initIconDOM(i),this._textDOM=this.initTextDOM(s,tool.TEXT_ATTRIBUTE_LINE_HEIGHT),this._textareaDOM=this.initTextareaDOM(s,r),this.appendToContainer()}get isExit(){return this._textAttributeDOM?this.container.contains(this._textAttributeDOM):!1}get isExitTextareaDOM(){return this._textareaDOM?this.container.contains(this._textareaDOM):!1}updateIcon(t){this._iconDOM&&(this._iconDOM.innerHTML=t)}appendToContainer(){!this._textAttributeDOM||!this._textDOM||!this._iconDOM||(this.container.appendChild(this._textAttributeDOM),this._textAttributeDOM.appendChild(this._textDOM),this._textAttributeDOM.appendChild(this._iconDOM))}initTextAttributeDOM(){const t=document.createElement("div");return t.setAttribute("id","textArea"),t}initTextDOM(t,e){const i=document.createElement("span");return i.setAttribute("style",`
2
2
  width: ${Math.max(t,defaultWidth)}px;
3
- line-height: ${i}px;
3
+ line-height: ${e}px;
4
4
  word-break: break-all;
5
5
  white-space: pre-line;
6
6
  font-style: italic;
7
- `),e}initIconDOM(t){const i=document.createElement("div");return i.setAttribute("id","annotation_text"),i.innerHTML=t,i.addEventListener("mouseup",e=>{e.stopPropagation(),this.renderTextarea()}),i.addEventListener("mousedown",e=>{e.stopPropagation()}),i.addEventListener("contextmenu",e=>{e.stopPropagation()}),i.setAttribute("style",`
7
+ `),i}initIconDOM(t){const e=document.createElement("div");return e.setAttribute("id","annotation_text"),e.innerHTML=t,e.addEventListener("mouseup",i=>{i.stopPropagation(),this.renderTextarea()}),e.addEventListener("mousedown",i=>{i.stopPropagation()}),e.addEventListener("contextmenu",i=>{i.stopPropagation()}),e.setAttribute("style",`
8
8
  position: absolute;
9
9
  left: -20px;
10
10
  top: 4px;
11
11
  cursor: pointer;
12
12
  z-index: 10
13
- `),i}initTextareaDOM(t,i){const e=document.createElement("textarea");return e.addEventListener("click",r=>{r.stopPropagation()}),e.addEventListener("mouseup",r=>{r.stopPropagation()}),e.setAttribute("style",`
13
+ `),e}initTextareaDOM(t,e){const i=document.createElement("textarea");return i.addEventListener("click",r=>{r.stopPropagation()}),i.addEventListener("mouseup",r=>{r.stopPropagation()}),i.setAttribute("style",`
14
14
  background-color: transparent;
15
15
  border-radius: 5px;
16
- border-color: ${i};
16
+ border-color: ${e};
17
17
  outline: none;
18
18
  resize: none;
19
19
  width: ${Math.max(t,30)}px;
20
- `),e.setAttribute("maxLength",`${tool.TEXT_ATTRIBUTE_MAX_LENGTH}`),e}removeTextDOM(){!this._textAttributeDOM||this._textDOM&&this._textAttributeDOM.removeChild(this._textDOM)}removeIconDOM(){!this._textAttributeDOM||this._iconDOM&&this._textAttributeDOM.removeChild(this._iconDOM)}removeTextareaDOM(){var t,i;this._textareaDOM&&this._textAttributeDOM&&((t=this._textAttributeDOM)==null?void 0:t.contains(this._textareaDOM))&&((i=this._textAttributeDOM)==null||i.removeChild(this._textareaDOM))}submitTextarea(){var t;this._textareaDOM&&(this.updateSelectedTextAttribute((t=this._textareaDOM)==null?void 0:t.value),this.removeTextareaDOM(),this.clearTextAttribute())}clearTextAttribute(){this._textAttributeDOM&&this.container.contains(this._textAttributeDOM)&&this.container.removeChild(this._textAttributeDOM)}renderTextarea(){if(!this._textAttributeDOM||!this._textareaDOM)return;const t=this.getCurrentSelectedData();if(!t)return;const{width:i=DEFAULT_TEXT_WIDTH,textAttribute:e,color:r}=t;this._textareaDOM.value=`${e}`,this._textareaDOM.setAttribute("style",`
20
+ `),i.setAttribute("maxLength",`${tool.TEXT_ATTRIBUTE_MAX_LENGTH}`),i}removeTextDOM(){!this._textAttributeDOM||this._textDOM&&this._textAttributeDOM.removeChild(this._textDOM)}removeIconDOM(){!this._textAttributeDOM||this._iconDOM&&this._textAttributeDOM.removeChild(this._iconDOM)}removeTextareaDOM(){var t,e;this._textareaDOM&&this._textAttributeDOM&&((t=this._textAttributeDOM)==null?void 0:t.contains(this._textareaDOM))&&((e=this._textAttributeDOM)==null||e.removeChild(this._textareaDOM))}submitTextarea(){var t;this._textareaDOM&&(this.updateSelectedTextAttribute((t=this._textareaDOM)==null?void 0:t.value),this.removeTextareaDOM(),this.clearTextAttribute())}clearTextAttribute(){this._textAttributeDOM&&this.container.contains(this._textAttributeDOM)&&this.container.removeChild(this._textAttributeDOM)}renderTextarea(){if(!this._textAttributeDOM||!this._textareaDOM)return;const t=this.getCurrentSelectedData();if(!t)return;const{width:e=DEFAULT_TEXT_WIDTH,textAttribute:i,color:r}=t;this._textareaDOM.value=`${i}`,this._textareaDOM.setAttribute("style",`
21
21
  background-color: rgba(0,0,0,0.4);
22
22
  border-radius: 5px;
23
23
  border-color: ${r};
@@ -26,12 +26,12 @@
26
26
  font-style: italic;
27
27
  font-weight: 900;
28
28
  text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.6);
29
- width: ${Math.max(i,defaultWidth)}px;
30
- `),this._textareaDOM.setAttribute("maxLength",`${tool.TEXT_ATTRIBUTE_MAX_LENGTH}`),this._textAttributeDOM.appendChild(this._textareaDOM),this.removeIconDOM(),this.removeTextDOM(),this._textareaDOM.focus(),this._textareaDOM.addEventListener("keydown",this.textKeyDown)}update(t,i){var e;const{left:r,top:o,color:n,width:s=DEFAULT_TEXT_WIDTH}=i,a=Math.max(s,defaultWidth);(e=this._textAttributeDOM)==null||e.setAttribute("style",`
29
+ width: ${Math.max(e,defaultWidth)}px;
30
+ `),this._textareaDOM.setAttribute("maxLength",`${tool.TEXT_ATTRIBUTE_MAX_LENGTH}`),this._textAttributeDOM.appendChild(this._textareaDOM),this.removeIconDOM(),this.removeTextDOM(),this._textareaDOM.focus(),this._textareaDOM.addEventListener("keydown",this.textKeyDown)}update(t,e){var i;const{left:r,top:o,color:n,width:s=DEFAULT_TEXT_WIDTH}=e,a=Math.max(s,defaultWidth);(i=this._textAttributeDOM)==null||i.setAttribute("style",`
31
31
  position: absolute;
32
32
  width: ${a}px;
33
33
  font-size: 14px;
34
34
  left:${r}px;
35
35
  top: ${o}px;
36
36
  color: ${n};
37
- `),this._textDOM&&(this._textDOM.innerHTML=`${t}`),this._textareaDOM&&(this._textareaDOM.style.width=`${a}px`,this._textareaDOM.style.borderColor=`${n}`)}changeSelected(){this.isExitTextareaDOM&&this.submitTextarea()}}module.exports=TextAttributeClass;
37
+ `),this._textDOM&&(this._textDOM.innerHTML=`${t}`),this._textareaDOM&&(this._textareaDOM.style.width=`${a}px`,this._textareaDOM.style.borderColor=`${n}`)}selectedIDsChanged(t,e){if(t.length===1&&e.length===1){if(_.isEqual(t,e))return;this==null||this.changeSelected()}(e==null?void 0:e.length)!==1&&(this.removeTextareaDOM(),this==null||this.clearTextAttribute())}changeSelected(){this.isExitTextareaDOM&&this.submitTextarea()}}module.exports=TextAttributeClass;
@@ -89,13 +89,13 @@ export default class AnnotationEngine {
89
89
  *
90
90
  * It will be deleted later.
91
91
  */
92
- switchLastTwoCanvas(): import("./toolOperation/rectOperation").RectOperation | import("./toolOperation/polygonOperation").default | undefined;
92
+ switchLastTwoCanvas(): import("./toolOperation/polygonOperation").default | import("./toolOperation/rectOperation").RectOperation | undefined;
93
93
  /**
94
94
  * Notice & TODO. Temporary additions
95
95
  * Just to get ToolInstance to update something.
96
96
  * @returns
97
97
  */
98
- get firstToolInstance(): import("./toolOperation/rectOperation").RectOperation | import("./toolOperation/polygonOperation").default | import("./toolOperation/segmentByRect").default;
98
+ get firstToolInstance(): import("./toolOperation/polygonOperation").default | import("./toolOperation/rectOperation").RectOperation | import("./toolOperation/segmentByRect").default;
99
99
  /**
100
100
  * 自定义样式渲染
101
101
  * @param customRenderStyle
@@ -22,6 +22,7 @@ interface IPointCloudAnnotationProps {
22
22
  config: IPointCloudConfig;
23
23
  checkMode?: boolean;
24
24
  toolName: THybridToolName;
25
+ proxyMode?: boolean;
25
26
  }
26
27
  export declare class PointCloudAnnotation implements IPointCloudAnnotationOperation {
27
28
  pointCloudInstance: PointCloud;
@@ -30,7 +31,7 @@ export declare class PointCloudAnnotation implements IPointCloudAnnotationOperat
30
31
  toolScheduler: ToolScheduler;
31
32
  toolInstance: any;
32
33
  config: IPointCloudConfig;
33
- constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName }: IPointCloudAnnotationProps);
34
+ constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName, proxyMode, }: IPointCloudAnnotationProps);
34
35
  updateConfig(config: IPointCloudConfig): void;
35
36
  updateAttributeList(attributeList: IInputList[]): void;
36
37
  /**
@@ -48,6 +48,7 @@ export declare class PointCloud {
48
48
  private cacheInstance;
49
49
  private showDirection;
50
50
  private currentPCDSrc?;
51
+ private pointsMaterialSize;
51
52
  /**
52
53
  * Record the src of Highlight PCD.
53
54
  *
@@ -94,7 +95,7 @@ export declare class PointCloud {
94
95
  addSphereToSense: (sphereParams: IPointCloudSphere, color?: string) => void;
95
96
  generateSphere: (sphereParams: IPointCloudSphere) => void;
96
97
  generateSpheres: (spheres: IPointCloudSphere[]) => void;
97
- AddBoxToSense: (boxParams: IPointCloudBox, color?: THREE.ColorRepresentation) => void;
98
+ addBoxToSense: (boxParams: IPointCloudBox, color?: THREE.ColorRepresentation) => void;
98
99
  generateBoxes(boxes: IPointCloudBox[]): void;
99
100
  /**
100
101
  * Get OrthographicCamera Params to Change
@@ -365,9 +366,13 @@ export declare class PointCloud {
365
366
  applyZAxisPoints: (zAxisLimit: number) => void;
366
367
  /**
367
368
  * Update point size
368
- * @param zoomIn
369
+ * @param param0
370
+ * @returns
369
371
  */
370
- updatePointSize: (zoomIn: boolean) => void;
372
+ updatePointSize: ({ zoomIn, customSize }: {
373
+ zoomIn?: boolean | undefined;
374
+ customSize?: number | undefined;
375
+ }) => void;
371
376
  render(): void;
372
377
  }
373
378
  export * from './matrix';
@@ -16,6 +16,7 @@ interface IToolSchedulerProps {
16
16
  imgNode?: HTMLImageElement;
17
17
  config?: string;
18
18
  style?: any;
19
+ proxyMode?: boolean;
19
20
  }
20
21
  export declare class HybridToolUtils {
21
22
  static isSingleTool(toolName: THybridToolName): boolean;
@@ -31,6 +32,7 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
31
32
  private config;
32
33
  private style;
33
34
  private imgNode?;
35
+ private proxyMode?;
34
36
  constructor(props: IToolSchedulerProps);
35
37
  setImgNode(imgNode: HTMLImageElement, basicImgInfo?: Partial<{
36
38
  valid: boolean;
@@ -60,18 +62,18 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
60
62
  *
61
63
  * It will be deleted later.
62
64
  */
63
- switchLastTwoCanvas(): RectOperation | PolygonOperation | undefined;
65
+ switchLastTwoCanvas(): PolygonOperation | RectOperation | undefined;
64
66
  /**
65
67
  * Notice & TODO. Temporary additions
66
68
  * Just to set data to toolInstance.
67
69
  * @returns
68
70
  */
69
- getFirstToolOperation(): RectOperation | PolygonOperation | SegmentByRect;
71
+ getFirstToolOperation(): PolygonOperation | RectOperation | SegmentByRect;
70
72
  /**
71
73
  * Switch to canvas by given toolName
72
74
  * TODO: change operationList to operationMap
73
75
  */
74
- switchToCanvas(toolName: EToolName): RectOperation | PolygonOperation | undefined;
76
+ switchToCanvas(toolName: EToolName): PolygonOperation | RectOperation | undefined;
75
77
  /**
76
78
  *
77
79
  * @param toolName
@@ -85,5 +87,16 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
85
87
  clearStatusAndResult(): void;
86
88
  destroyAllLayer(): void;
87
89
  init(): void;
90
+ destroy(): void;
91
+ eventBinding(): void;
92
+ eventUnBinding(): void;
93
+ onWheel(e: MouseEvent): void;
94
+ onMouseDown(e: MouseEvent): void;
95
+ onMouseMove(e: MouseEvent): void;
96
+ onMouseUp(e: MouseEvent): void;
97
+ /**
98
+ * Get current tool name of toolInstance
99
+ */
100
+ getCurrentToolName(): EToolName;
88
101
  }
89
102
  export {};
@@ -34,16 +34,17 @@ declare class LineToolOperation extends BasicToolOperation {
34
34
  */
35
35
  drawActivatedLine: (coord?: ICoordinate, e?: MouseEvent, hideTempAxis?: boolean) => void;
36
36
  _textAttributInstance?: TextAttributeClass;
37
+ /** 选中所有线条 */
38
+ get selectedLines(): ILine[];
37
39
  /** 线条是否被选中 */
38
40
  get isLineSelected(): "" | ILinePoint[] | undefined;
39
- /** 选中点线条的点 */
40
- get selectedLinePoints(): any[];
41
+ /** 选中单个线条 */
42
+ get selectedLine(): ILine | undefined;
41
43
  /**
42
44
  * 绘制hover的点
43
45
  * @param coord
44
46
  */
45
47
  drawHoverPoint: (coord: ICoordinate) => void;
46
- selectedID?: string;
47
48
  updatedLine: ILine;
48
49
  toolName: string;
49
50
  private lineList;
@@ -62,11 +63,11 @@ declare class LineToolOperation extends BasicToolOperation {
62
63
  private hoverPointID?;
63
64
  private dependToolConfig?;
64
65
  private isReference;
65
- private _textAttributeInstance?;
66
+ _textAttributeInstance?: TextAttributeClass;
66
67
  private textEditingID?;
67
68
  private isLineValid;
68
69
  private lineDragging;
69
- private selectedIDs;
70
+ private selection;
70
71
  constructor(props: ILineOperationProps);
71
72
  /** 创建状态 */
72
73
  get isCreate(): boolean;
@@ -88,6 +89,14 @@ declare class LineToolOperation extends BasicToolOperation {
88
89
  get isDependRect(): boolean;
89
90
  get isCurrentAttributeLocked(): boolean;
90
91
  get attributeFilteredLines(): ILine[];
92
+ get selectedIDs(): string[];
93
+ get selectedID(): string | undefined;
94
+ /**
95
+ * Judgement of showing Order.
96
+ *
97
+ * Origin Config of LineTool: enableOutOfTarget & outOfTarget.
98
+ * Configurable of other tools: drawOutsideTarget.
99
+ */
91
100
  get enableOutOfTarget(): any;
92
101
  /**
93
102
  * Judgement of showing Order.
@@ -151,19 +160,13 @@ declare class LineToolOperation extends BasicToolOperation {
151
160
  /**
152
161
  * 对存在绘制对象,绘制热区
153
162
  */
154
- renderActiveArea(): void;
155
- /**
156
- * Update selectedIDs and rerender
157
- * @param selectedIDs
158
- */
159
- setSelectedIDs(selectedIDs: string[]): void;
160
- setSelectedID(newID?: string): void;
163
+ renderActiveArea({ top, left, right, bottom }: IRectArea): void;
161
164
  /**
162
165
  * 添加点
163
166
  * @param coord 坐标
164
167
  */
165
168
  addLinePoint(coord: ICoordinate): void;
166
- setCreatStatusAndAddPoint(coord: ICoordinate, isRestText?: boolean): void;
169
+ setCreateStatusAndAddPoint(coord: ICoordinate, isRestText?: boolean): void;
167
170
  /**
168
171
  * 当前激活的线条是否为有效线, 优先获取存在的数据
169
172
  */
@@ -188,14 +191,6 @@ declare class LineToolOperation extends BasicToolOperation {
188
191
  * 渲染已经绘制的线段
189
192
  */
190
193
  render: (nextPoint?: IPoint) => void;
191
- /** 重新计算并渲染热区 */
192
- updateActiveArea(): void;
193
- getActiveArea(): {
194
- top: number;
195
- bottom: number;
196
- left: number;
197
- right: number;
198
- } | undefined;
199
194
  /**
200
195
  * 绘制线条序号(包含属性或者标签)
201
196
  * @param coord
@@ -256,6 +251,12 @@ declare class LineToolOperation extends BasicToolOperation {
256
251
  * @param offsetY
257
252
  */
258
253
  moveLineInPolygon: (offsetX: number, offsetY: number) => false | undefined;
254
+ getSelectedLinesArea: () => {
255
+ top: number;
256
+ bottom: number;
257
+ left: number;
258
+ right: number;
259
+ };
259
260
  /**
260
261
  * 在矩形内移动线条
261
262
  * @param offsetX x轴的偏移量
@@ -296,18 +297,6 @@ declare class LineToolOperation extends BasicToolOperation {
296
297
  /** 鼠标移动事件 */
297
298
  mouseMoveHandler(e: MouseEvent): void;
298
299
  onMouseMove(e: MouseEvent): void;
299
- /**
300
- * 设置激活区域
301
- * @param coord
302
- * @param outsideCancel
303
- * @todo 拖拽区域取消选中
304
- */
305
- setActiveArea(coord: ICoordinate, outsideCancel?: boolean): void;
306
- /**
307
- * 根据id选中线条
308
- * @param id
309
- */
310
- setActiveLineByID(id: string): void;
311
300
  setActiveLine(pointList?: ILinePoint[]): void;
312
301
  onRightClick: (e: MouseEvent) => true | undefined;
313
302
  historyChanged(funcName: 'undo' | 'redo'): void;
@@ -329,6 +318,7 @@ declare class LineToolOperation extends BasicToolOperation {
329
318
  updateLineSegmentSpecial(coord: ICoordinate): void;
330
319
  onLeftClick: (e: MouseEvent) => void;
331
320
  addLinePointToActiveLine(): void;
321
+ isCoordOnSelectedArea(coord: ICoordinate): boolean;
332
322
  onMouseDown(e: MouseEvent): void;
333
323
  lineHasChanged(): boolean;
334
324
  updateLines(): void;
@@ -341,7 +331,6 @@ declare class LineToolOperation extends BasicToolOperation {
341
331
  * @param isAppend
342
332
  */
343
333
  stopLineCreating(isAppend?: boolean): void;
344
- setActiveStatus(id?: string): void;
345
334
  /**
346
335
  * 设置为无状态
347
336
  * @param updateStatus
@@ -398,7 +387,7 @@ declare class LineToolOperation extends BasicToolOperation {
398
387
  /** 设置线条文本标注属性 */
399
388
  setTextAttribute(text: string): void;
400
389
  /** 更新线条的属性 */
401
- setLineAttribute(key: 'attribute' | 'textAttribute', value: string, id?: string): void;
390
+ setLineAttribute(key: 'attribute' | 'textAttribute', value: string): void;
402
391
  /** 更新外部属性列表的选中值 */
403
392
  updateAttribute(attribute: string): void;
404
393
  /** 更新线条的属性 */
@@ -408,7 +397,8 @@ declare class LineToolOperation extends BasicToolOperation {
408
397
  /** 保存当前绘制的数据, 避免创建中的数据不会被保存到 */
409
398
  saveData(): void;
410
399
  setTextEditingID(id: string): void;
411
- setSelectedLineID(id?: string): void;
400
+ updateAttrWhileIDChanged(id?: string): void;
401
+ setSelectedLineID(id?: string, isAppend?: boolean, triggerAttrUpdate?: boolean): void;
412
402
  attributeLockListChange(attributeLockList: string[]): void;
413
403
  setReference: (isReference: boolean) => void;
414
404
  /**