@labelbee/lb-annotation 1.14.0-alpha.11 → 1.14.0-alpha.13

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 (35) hide show
  1. package/dist/core/pointCloud/annotation.js +1 -1
  2. package/dist/core/toolOperation/LineToolOperation.js +1 -1
  3. package/dist/core/toolOperation/Selection.js +1 -0
  4. package/dist/core/toolOperation/cuboidOperation.js +1 -1
  5. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
  6. package/dist/core/toolOperation/pointOperation.js +1 -1
  7. package/dist/core/toolOperation/polygonOperation.js +1 -1
  8. package/dist/core/toolOperation/rectOperation.js +1 -1
  9. package/dist/core/toolOperation/textAttributeClass.js +9 -9
  10. package/dist/types/core/index.d.ts +2 -2
  11. package/dist/types/core/scheduler.d.ts +3 -3
  12. package/dist/types/core/toolOperation/LineToolOperation.d.ts +26 -36
  13. package/dist/types/core/toolOperation/Selection.d.ts +70 -0
  14. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +1 -10
  15. package/dist/types/core/toolOperation/pointOperation.d.ts +10 -4
  16. package/dist/types/core/toolOperation/polygonOperation.d.ts +21 -14
  17. package/dist/types/core/toolOperation/rectOperation.d.ts +41 -10
  18. package/dist/types/core/toolOperation/textAttributeClass.d.ts +6 -0
  19. package/dist/types/utils/tool/CommonToolUtils.d.ts +2 -2
  20. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +2 -2
  21. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -1
  22. package/dist/utils/tool/CommonToolUtils.js +1 -1
  23. package/dist/utils/tool/PolygonUtils.js +1 -1
  24. package/es/core/pointCloud/annotation.js +1 -1
  25. package/es/core/toolOperation/LineToolOperation.js +1 -1
  26. package/es/core/toolOperation/Selection.js +1 -0
  27. package/es/core/toolOperation/cuboidOperation.js +1 -1
  28. package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
  29. package/es/core/toolOperation/pointOperation.js +1 -1
  30. package/es/core/toolOperation/polygonOperation.js +1 -1
  31. package/es/core/toolOperation/rectOperation.js +1 -1
  32. package/es/core/toolOperation/textAttributeClass.js +9 -9
  33. package/es/utils/tool/CommonToolUtils.js +1 -1
  34. package/es/utils/tool/PolygonUtils.js +1 -1
  35. package/package.json +1 -1
@@ -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
@@ -60,18 +60,18 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
60
60
  *
61
61
  * It will be deleted later.
62
62
  */
63
- switchLastTwoCanvas(): RectOperation | PolygonOperation | undefined;
63
+ switchLastTwoCanvas(): PolygonOperation | RectOperation | undefined;
64
64
  /**
65
65
  * Notice & TODO. Temporary additions
66
66
  * Just to set data to toolInstance.
67
67
  * @returns
68
68
  */
69
- getFirstToolOperation(): RectOperation | PolygonOperation | SegmentByRect;
69
+ getFirstToolOperation(): PolygonOperation | RectOperation | SegmentByRect;
70
70
  /**
71
71
  * Switch to canvas by given toolName
72
72
  * TODO: change operationList to operationMap
73
73
  */
74
- switchToCanvas(toolName: EToolName): RectOperation | PolygonOperation | undefined;
74
+ switchToCanvas(toolName: EToolName): PolygonOperation | RectOperation | undefined;
75
75
  /**
76
76
  *
77
77
  * @param toolName
@@ -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): void;
412
402
  attributeLockListChange(attributeLockList: string[]): void;
413
403
  setReference: (isReference: boolean) => void;
414
404
  /**
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @file Manage selectedIds for ToolInstance
3
+ * @author Glenfiddish <edwinlee0927@hotmail.com>
4
+ * @createdate 2023-03-01
5
+ */
6
+ import { IPolygonData } from '@/types/tool/polygon';
7
+ import LineToolOperation from './LineToolOperation';
8
+ import PointOperation from './pointOperation';
9
+ import PolygonOperation from './polygonOperation';
10
+ import { RectOperation } from './rectOperation';
11
+ type ToolInstance = PointOperation | PolygonOperation | LineToolOperation | RectOperation;
12
+ type SelectedID = string;
13
+ type SelectedIDs = SelectedID[];
14
+ type DataUnit = IPointUnit | IPolygonData | ILine | IRect;
15
+ type DataList = Array<DataUnit>;
16
+ export type SetDataList = (dataList: DataList) => void;
17
+ declare class Selection {
18
+ private _selectedIDs;
19
+ private toolInstance;
20
+ private stashDataList?;
21
+ constructor(toolInstance: ToolInstance);
22
+ get selectedIDs(): SelectedIDs;
23
+ get selectedID(): string | undefined;
24
+ get visibleDataList(): any[];
25
+ get dataList(): DataList;
26
+ /**
27
+ * Trigger tools and _textAttributeInstance to re-render when _selectedIDs changed
28
+ */
29
+ private set selectedIDs(value);
30
+ /**
31
+ * Update selectedIDs:
32
+ * Remove selectedID when selectedIDs includes
33
+ * Append selectedID when selectedIDs not includes
34
+ * SelectedID is
35
+ * @param selectedID
36
+ */
37
+ private updateSelectedIDs;
38
+ /**
39
+ * Set selectedIDs
40
+ * isAppend is true: push or remove from selectedIDs
41
+ * isAppend is false: overwrite selectedIDs
42
+ * @param id
43
+ * @param isAppend
44
+ */
45
+ setSelectedIDs(id?: string, isAppend?: boolean): void;
46
+ /**
47
+ * Force set selectedIDs not calc
48
+ * @param ids
49
+ */
50
+ hardSetSelectedIDs(ids: string[]): void;
51
+ selectAll(): void;
52
+ /**
53
+ * Stash data list and pop while paste
54
+ */
55
+ toStashDataList(): void;
56
+ toUnStashDataList(): DataList | undefined;
57
+ mergeStashData(setDataList: (dataList: DataList) => void): void;
58
+ isIdSelected(id: string): boolean;
59
+ /**
60
+ * Trigger selection events(hijacking tools' key down event)
61
+ * - Copy selected data
62
+ * - Paste stash data
63
+ * - Select visible data
64
+ * @param e
65
+ * @param setDataList
66
+ * @returns if
67
+ */
68
+ triggerKeyboardEvent(e: KeyboardEvent, setDataList: SetDataList): boolean;
69
+ }
70
+ export default Selection;
@@ -1,10 +1,3 @@
1
- /**
2
- * It can expand various types of operations
3
- *
4
- * @file PointCloud 2D Operation
5
- * @createdate 2022-07-11
6
- * @author Ron <ron.f.luo@gmail.com>
7
- */
8
1
  import { IPointCloudConfig } from '@labelbee/lb-utils';
9
2
  import { ESortDirection } from '@/constant/annotation';
10
3
  import { IPolygonData, IPolygonPoint } from '@/types/tool/polygon';
@@ -20,7 +13,6 @@ declare class PointCloud2dOperation extends PolygonOperation {
20
13
  forbidAddNew: boolean;
21
14
  pointCloudConfig: IPointCloudConfig;
22
15
  private checkMode;
23
- private selectedIDs;
24
16
  constructor(props: IPolygonOperationProps & IPointCloud2dOperationProps);
25
17
  get getSelectedIDs(): string[];
26
18
  get enableDrag(): boolean;
@@ -41,7 +33,7 @@ declare class PointCloud2dOperation extends PolygonOperation {
41
33
  * @override
42
34
  */
43
35
  rightMouseUp: (e: MouseEvent) => void;
44
- get selectedPolygons(): IPolygonData[] | undefined;
36
+ get selectedPolygons(): IPolygonData[];
45
37
  updateSelectedPolygonsPoints(offset: Partial<ICoordinate>): void;
46
38
  /**
47
39
  * keydown event
@@ -106,7 +98,6 @@ declare class PointCloud2dOperation extends PolygonOperation {
106
98
  * @returns
107
99
  */
108
100
  setPolygonValidAndRender(id: string, isUpdate?: boolean): void;
109
- onDragMove(e: MouseEvent): void;
110
101
  onMouseDown(e: MouseEvent): true | undefined;
111
102
  /**
112
103
  * Just Update Data. Not Clear Status
@@ -1,4 +1,6 @@
1
1
  import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
2
+ import TextAttributeClass from './textAttributeClass';
3
+ import Selection from './Selection';
2
4
  export interface IPointOperationProps extends IBasicToolOperationProps {
3
5
  style: any;
4
6
  forbidAddNew?: boolean;
@@ -8,18 +10,21 @@ declare class PointOperation extends BasicToolOperation {
8
10
  config: IPointToolConfig;
9
11
  pointList: IPointUnit[];
10
12
  hoverID?: string;
11
- selectedID?: string;
12
13
  markerIndex: number;
13
14
  dragInfo?: {
14
15
  dragStartCoord: ICoordinate;
15
16
  originPointList: IPointUnit[];
16
17
  };
18
+ selection: Selection;
19
+ _textAttributeInstance?: TextAttributeClass;
17
20
  forbidAddNew?: boolean;
18
21
  forbidDelete?: boolean;
19
- private _textAttributInstance?;
20
22
  constructor(props: IPointOperationProps);
21
23
  get dataList(): IPointUnit[];
22
24
  get drawOutsideTarget(): boolean;
25
+ get selectedID(): string | undefined;
26
+ get selectedIDs(): string[];
27
+ get selectedPoints(): IPointUnit[];
23
28
  /**
24
29
  * 向外部提供标记的更改
25
30
  * @param markerIndex
@@ -54,7 +59,7 @@ declare class PointOperation extends BasicToolOperation {
54
59
  textChange: (v: string) => void;
55
60
  get selectedText(): string | undefined;
56
61
  setStyle(toolStyle: any): void;
57
- setSelectedID(newID?: string): void;
62
+ setSelectedID(newID?: string, isAppend?: boolean): void;
58
63
  /**
59
64
  * 获取当前配置下的 icon svg
60
65
  * @param attribute
@@ -74,13 +79,14 @@ declare class PointOperation extends BasicToolOperation {
74
79
  onMouseMove(e: MouseEvent): undefined;
75
80
  onMouseUp(e: MouseEvent): true | undefined;
76
81
  onDragMove(e: MouseEvent): void;
82
+ onKeyUp(e: KeyboardEvent): boolean | void;
77
83
  onKeyDown(e: KeyboardEvent): void;
78
84
  isMinDistance: (coord: ICoordinate) => boolean;
79
85
  createPoint(e: MouseEvent): void;
80
86
  isInPoint(pos: ICoordinate, point: ICoordinate, zoom?: number): boolean;
81
87
  getHoverId(): string | undefined;
82
88
  get selectedPoint(): IPointUnit | undefined;
83
- rightMouseUp(): void;
89
+ rightMouseUp(e: MouseEvent): void;
84
90
  onTabKeyDown(e: KeyboardEvent): void;
85
91
  /**
86
92
  * 当前依赖状态下本页的所有的点
@@ -3,6 +3,7 @@ import { EPolygonPattern } from '../../constant/tool';
3
3
  import { IPolygonConfig, IPolygonData, IPolygonPoint } from '../../types/tool/polygon';
4
4
  import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
5
5
  import TextAttributeClass from './textAttributeClass';
6
+ import Selection from './Selection';
6
7
  export interface IPolygonOperationProps extends IBasicToolOperationProps {
7
8
  }
8
9
  declare class PolygonOperation extends BasicToolOperation {
@@ -12,7 +13,6 @@ declare class PolygonOperation extends BasicToolOperation {
12
13
  hoverID?: string;
13
14
  hoverPointIndex: number;
14
15
  hoverEdgeIndex: number;
15
- selectedID?: string;
16
16
  editPolygonID?: string;
17
17
  pattern: EPolygonPattern;
18
18
  isCombined: boolean;
@@ -22,19 +22,24 @@ declare class PolygonOperation extends BasicToolOperation {
22
22
  changePointIndex?: number[];
23
23
  dragTarget: EDragTarget;
24
24
  originPolygon?: IPolygonData;
25
+ selectedPolygons?: IPolygonData[];
25
26
  dragPrevCoord: ICoordinate;
26
27
  originPolygonList: IPolygonData[];
27
28
  };
28
29
  private drawingHistory;
29
30
  isCtrl: boolean;
30
31
  isAlt: boolean;
31
- _textAttributInstance?: TextAttributeClass;
32
+ _textAttributeInstance?: TextAttributeClass;
32
33
  forbidAddNewPolygonFuc?: (e: MouseEvent) => boolean;
34
+ selection: Selection;
33
35
  constructor(props: IPolygonOperationProps);
36
+ get selectedIDs(): string[];
37
+ get selectedID(): string | undefined;
34
38
  eventBinding(): void;
35
39
  eventUnbinding(): void;
36
40
  destroy(): void;
37
41
  get selectedPolygon(): IPolygonData | undefined;
42
+ get selectedPolygons(): IPolygonData[];
38
43
  get hoverPolygon(): IPolygonData | undefined;
39
44
  get enableDrag(): boolean;
40
45
  get visiblePolygonList(): IPolygonData[];
@@ -71,6 +76,11 @@ declare class PolygonOperation extends BasicToolOperation {
71
76
  * @memberof RectOperation
72
77
  */
73
78
  get currentPageResult(): IPolygonData[];
79
+ /**
80
+ * Just Update Data. Not Clear Status
81
+ * @param polygonList
82
+ */
83
+ setResultAndSelectedID(polygonList: IPolygonData[], selectedID: string): void;
74
84
  setResult(polygonList: IPolygonData[]): void;
75
85
  /**
76
86
  * 外层 sidabr 调用
@@ -98,7 +108,7 @@ declare class PolygonOperation extends BasicToolOperation {
98
108
  clearActiveStatus(): void;
99
109
  clearDrawingStatus(): void;
100
110
  setPolygonList(polygonList: IPolygonData[]): void;
101
- setSelectedID(newID?: string): void;
111
+ setSelectedID(newID?: string, isAppend?: boolean): void;
102
112
  setDefaultAttribute(defaultAttribute?: string): void;
103
113
  setStyle(toolStyle: any): void;
104
114
  setPolygonValidAndRender(id: string): void;
@@ -116,7 +126,7 @@ declare class PolygonOperation extends BasicToolOperation {
116
126
  getHoverID(e: MouseEvent): string;
117
127
  getHoverEdgeIndex(e: MouseEvent): number;
118
128
  getHoverPointIndex(e: MouseEvent): number;
119
- deletePolygon(id?: string): void;
129
+ deletePolygons(id?: string[]): void;
120
130
  deletePolygonPoint(index: number): void;
121
131
  spaceKeydown(): void;
122
132
  onTabKeyDown(e: KeyboardEvent): void;
@@ -142,6 +152,11 @@ declare class PolygonOperation extends BasicToolOperation {
142
152
  * @returns
143
153
  */
144
154
  isPolygonOutSide(selectedPointList: IPolygonPoint[]): boolean;
155
+ /**
156
+ * Update polygon position while enableDrag is true
157
+ * @param e {MouseEvent}
158
+ */
159
+ onDragMove(e: MouseEvent): void;
145
160
  /**
146
161
  * According to the mode of dragTarget, get the offset when dragging
147
162
  * @param e {MouseEvent}
@@ -153,11 +168,6 @@ declare class PolygonOperation extends BasicToolOperation {
153
168
  y: number;
154
169
  };
155
170
  dragPolygon(e: MouseEvent, selectedPolygon: IPolygonData): IPolygonPoint[] | undefined;
156
- /**
157
- * Update polygon position while enableDrag is true
158
- * @param e {MouseEvent}
159
- */
160
- onDragMove(e: MouseEvent): void;
161
171
  onMouseMove(e: MouseEvent): void;
162
172
  /**
163
173
  * Emit updateList for views update
@@ -183,11 +193,8 @@ declare class PolygonOperation extends BasicToolOperation {
183
193
  updateSelectedTextAttribute(newTextAttribute?: string): void;
184
194
  renderTextAttribute(): void;
185
195
  renderStaticPolygon(): void;
186
- /**
187
- * Render selected polygon
188
- * @param selectedPolygon
189
- */
190
- renderSelectedPolygon(): void;
196
+ renderSelectedPolygons(): void;
197
+ renderSelectedPolygon(polygon: IPolygonData): void;
191
198
  renderHoverPolygon(): void;
192
199
  renderPolygon(): void;
193
200
  render(): void;