@labelbee/lb-annotation 1.27.0-alpha.5 → 1.27.0-alpha.50

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 (39) hide show
  1. package/dist/_virtual/highlightWorker.js +1 -1
  2. package/dist/constant/keyCode.js +1 -1
  3. package/dist/core/pointCloud/index.js +2 -2
  4. package/dist/core/pointCloud/matrix.js +1 -1
  5. package/dist/core/pointCloud/omniCamera.js +1 -1
  6. package/dist/core/toolOperation/ViewOperation.js +2 -1
  7. package/dist/core/toolOperation/pointCloud2DRectOperation.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/utils/reCalcRect.js +1 -0
  12. package/dist/index.js +1 -1
  13. package/dist/types/constant/keyCode.d.ts +1 -0
  14. package/dist/types/core/pointCloud/index.d.ts +5 -1
  15. package/dist/types/core/toolOperation/ViewOperation.d.ts +3 -0
  16. package/dist/types/core/toolOperation/pointCloud2DRectOperation.d.ts +8 -3
  17. package/dist/types/core/toolOperation/pointOperation.d.ts +4 -0
  18. package/dist/types/core/toolOperation/polygonOperation.d.ts +2 -0
  19. package/dist/types/core/toolOperation/rectOperation.d.ts +14 -3
  20. package/dist/types/core/toolOperation/utils/reCalcRect.d.ts +9 -0
  21. package/dist/types/index.d.ts +3 -1
  22. package/dist/types/utils/tool/AxisUtils.d.ts +1 -0
  23. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
  24. package/dist/types/utils/tool/RectUtils.d.ts +1 -0
  25. package/dist/utils/tool/PolygonUtils.js +1 -1
  26. package/es/_virtual/highlightWorker.js +1 -1
  27. package/es/constant/keyCode.js +1 -1
  28. package/es/core/pointCloud/index.js +2 -2
  29. package/es/core/pointCloud/matrix.js +1 -1
  30. package/es/core/pointCloud/omniCamera.js +1 -1
  31. package/es/core/toolOperation/ViewOperation.js +2 -1
  32. package/es/core/toolOperation/pointCloud2DRectOperation.js +1 -1
  33. package/es/core/toolOperation/pointOperation.js +1 -1
  34. package/es/core/toolOperation/polygonOperation.js +1 -1
  35. package/es/core/toolOperation/rectOperation.js +1 -1
  36. package/es/core/toolOperation/utils/reCalcRect.js +1 -0
  37. package/es/index.js +1 -1
  38. package/es/utils/tool/PolygonUtils.js +1 -1
  39. package/package.json +2 -2
@@ -1 +1 @@
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.highlightVisible=!1,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:a}=this;if(a&&RectUtils.isInRect(s,a,r,this.zoom))return a.id}const i=o.filter(a=>RectUtils.isInRect(s,a,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,c)=>n.size-c.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.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 drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}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 a=r[i],{length:n}=MathUtils.default.getFootOfPerpendicular(o,a.begin,a.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.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),n={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.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 c=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(c)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,c))}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 a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:c,width:d,height:h}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let g=n,f=c,u=d,b=h;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?n+d:n+i.x,f=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-d),b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,f=h-i.y<0?c+h:c+i.y,u=Math.abs(d+i.x),b=Math.abs(h-i.y);break}case 2:{g=d+i.x>0?n:n+d+i.x,f=h+i.y>0?c:c+h+i.y,u=Math.abs(d+i.x),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,f=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-d),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:b})}break;case tool.EDragTarget.Line:{let g=n,f=c,u=d,b=h;switch(this.hoverRectEdgeIndex){case 0:{f=h-i.y<0?c+h:c+i.y,b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,u=Math.abs(d+i.x);break}case 2:{f=h+i.y>0?c:c+h+i.y,b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,u=Math.abs(i.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(l,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,b=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<f-.01||l.width>g+u-l.x+.01||l.height>f+b-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<f&&(l.y=f),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>f+b-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?RectUtils.getRectUnderZoom(l,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.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 c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=i,i!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:c}=this.firstClickCoord,{width:d,height:h}=this.drawingRect;if(d=Math.abs(n-o.x),h=Math.abs(c-o.y),o.x<n&&(n=o.x),o.y<c&&(c=o.y),this.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:c,width:d,height:h}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;o.x<0&&(d=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(h=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(n+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-n)),c+h>this.imgInfo.height&&(h=Math.abs(this.imgInfo.height-c)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:c,width:d,height:h}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),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.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,r;const o=this.getHoverRectID(t),i=this.rectList.find(a=>a.id===o);if(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(o,t.ctrlKey),i&&((r=this.selectedIDs)==null?void 0:r.length)===1&&this.setDefaultAttribute(i.attribute),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const a=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);a>=0&&(this.setMarkerIndex(a),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}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"),this.updateDragResult();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||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))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 a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>CanvasUtils.inViewPort({x:c.x,y:c.y},a));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){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 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:a,valid:n}=e,c=o*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),h=this.getColor(a),l=n?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:c,container:this.container,icon:this.getTextIconSvg(a),color:l,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:d.x,top:d.y+g,color:l,width:c})}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((a,n)=>{var c,d;if(e.save(),e.moveTo(a.x,a.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(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const h=this.getColor(t.attribute),l=t.valid===!1?(c=h==null?void 0:h.invalid)==null?void 0:c.stroke:(d=h==null?void 0:h.valid)==null?void 0:d.stroke;e.strokeStyle=l,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,a;if(this.ctx&&t){const{ctx:n,style:c}=this,{hiddenText:d=!1}=c;n.save();const{strokeColor:h,fillColor:l,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);d||DrawUtils.drawText(this.canvas,{x:u.x,y:u.y-6},f,__spreadProps(__spreadValues({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:h,position:{x:u.x-5,y:u.y-16}});const b=(a=(i=this.style)==null?void 0:i.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,u,{color:l}),DrawUtils.drawRect(this.canvas,u,{color:h,thickness:b,hiddenText:!0}),n.restore();let x=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(x=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const v=x.length*7;if(d||DrawUtils.drawText(this.canvas,{x:u.x+u.width-v,y:u.y+u.height+15},x,__spreadValues({color:g,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!d&&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.highlightVisible);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
+ "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.highlightVisible=!1,this.enableAddRect=!0,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(n=>n.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:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(s,a,r,this.zoom))return a.id}const i=n.filter(a=>RectUtils.isInRect(s,a,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(o=>({size:o.width*o.height,id:o.id})).sort((o,c)=>o.size-c.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const s=this.rectList.find(r=>r.id===e);return(s==null?void 0:s.textAttribute)||""}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.selectedRectTextAttribute="",this.markerIndex=0,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 drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}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),n=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const a=r[i],{length:o}=MathUtils.default.getFootOfPerpendicular(n,a.begin,a.end);o<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(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,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,n)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(n,e))),[]);return MathUtils.default.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,n,i;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),o={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(o,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const c=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(i=this.imgNode)==null?void 0:i.width};if(c)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,c))}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 n=s.find(i=>i.id===r.id);return n||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,n;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 a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:o,y:c,width:d,height:h}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let g=o,f=c,u=d,b=h;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?o+d:o+i.x,f=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-d),b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?o:o+d+i.x,f=h-i.y<0?c+h:c+i.y,u=Math.abs(d+i.x),b=Math.abs(h-i.y);break}case 2:{g=d+i.x>0?o:o+d+i.x,f=h+i.y>0?c:c+h+i.y,u=Math.abs(d+i.x),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?o+d:o+i.x,f=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-d),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:b})}break;case tool.EDragTarget.Line:{let g=o,f=c,u=d,b=h;switch(this.hoverRectEdgeIndex){case 0:{f=h-i.y<0?c+h:c+i.y,b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?o:o+d+i.x,u=Math.abs(d+i.x);break}case 2:{f=h+i.y>0?c:c+h+i.y,b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?o+d:o+i.x,u=Math.abs(i.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(l,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,b=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<f-.01||l.width>g+u-l.x+.01||l.height>f+b-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<f&&(l.y=f),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>f+b-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?RectUtils.getRectUnderZoom(l,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),n=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=i,i!==a&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:c}=this.firstClickCoord,{width:d,height:h}=this.drawingRect;if(d=Math.abs(o-n.x),h=Math.abs(c-n.y),n.x<o&&(o=n.x),n.y<c&&(c=n.y),this.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:o,y:c,width:d,height:h}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;n.x<0&&(d=Math.abs(this.firstClickCoord.x),o=0),n.y<0&&(h=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(o+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-o)),c+h>this.imgInfo.height&&(h=Math.abs(this.imgInfo.height-c)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:c,width:d,height:h}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),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.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 n=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:n.label})),this.markerIndex=n.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 n="";n=AttributeUtils.default.getTextAttribute(this.rectList.filter(i=>CommonToolUtils.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(n=>CommonToolUtils.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},r),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.clearDrawingStatus(),this.render();return}const s=this.getDrawingRectWithRectList();this.setRectList(s,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}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,r;const n=this.getHoverRectID(t),i=this.rectList.find(a=>a.id===n);if(this.selectedRectTextAttribute="",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(n,t.ctrlKey),i&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(n),this.setDefaultAttribute(i.attribute)),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const a=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);a>=0&&(this.setMarkerIndex(a),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}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"),this.updateDragResult();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.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))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(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=annotation.ESortDirection.ascend;t.shiftKey&&(s=annotation.ESortDirection.descend);const[r,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];n&&(i=[...i,...n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>CanvasUtils.inViewPort({x:c.x,y:c.y},a));const o=CommonToolUtils.getNextSelectedRectID(i,s,this.selectedRectID);o&&(this.setSelectedRectID(o.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(o.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){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 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,n;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,n=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,n=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:n,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:n,height:i,attribute:a,valid:o}=e,c=n*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),h=this.getColor(a),l=o?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:c,container:this.container,icon:this.getTextIconSvg(a),color:l,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:d.x,top:d.y+g,color:l,width:c})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=RectUtils.getRectPointList(t),n=r.length,i=this.getColor(t.attribute);r.forEach((a,o)=>{var c,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===o?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(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===o){e.beginPath(),e.lineWidth=10;const h=this.getColor(t.attribute),l=t.valid===!1?(c=h==null?void 0:h.invalid)==null?void 0:c.stroke:(d=h==null?void 0:h.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[o].x*this.zoom+this.currentPos.x,r[o].y*this.zoom+this.currentPos.y),e.lineTo(r[(o+1)%n].x*this.zoom+this.currentPos.x,r[(o+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,n,i,a;if(this.ctx&&t){const{ctx:o,style:c}=this,{hiddenText:d=!1}=c;o.save();const{strokeColor:h,fillColor:l,textColor:g}=this.getRenderStyle(t);o.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,(n=this.config)==null?void 0:n.attributeList)}`);const u=AxisUtils.default.changeRectByZoom(t,s?e:this.zoom,this.currentPos);d||DrawUtils.drawText(this.canvas,{x:u.x,y:u.y-6},f,__spreadProps(__spreadValues({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:h,position:{x:u.x-5,y:u.y-16}});const b=(a=(i=this.style)==null?void 0:i.width)!=null?a:2,w=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||w||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,u,{color:l}),DrawUtils.drawRect(this.canvas,u,{color:h,thickness:b,hiddenText:!0,lineDash:t.lineDash}),o.restore();let x=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(x=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const v=x.length*7;if(d||DrawUtils.drawText(this.canvas,{x:u.x+u.width-v,y:u.y+u.height+15},x,__spreadValues({color:g,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!d&&t.textAttribute&&t.id!==this.selectedRectID){const I=0,m=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:m},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.highlightVisible);this.isHidden||s==null||s.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),r&&r.forEach(n=>{this.renderDrawingRect(n),this.renderSelectedRect(n),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))})}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")}clearDrawingStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}clearActiveStatus(){this.clearDrawingStatus(),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;
@@ -0,0 +1 @@
1
+ "use strict";var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,n,s)=>n in o?__defProp(o,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[n]=s,__spreadValues=(o,n)=>{for(var s in n||(n={}))__hasOwnProp.call(n,s)&&__defNormalProp(o,s,n[s]);if(__getOwnPropSymbols)for(var s of __getOwnPropSymbols(n))__propIsEnum.call(n,s)&&__defNormalProp(o,s,n[s]);return o},__spreadProps=(o,n)=>__defProps(o,__getOwnPropDescs(n));const findNearestPoints=(o,n)=>{const s={x:(n.x+n.width)/2,y:(n.y+n.height)/2};let r=Infinity,i=[];for(const y of o){const x=Math.sqrt(Math.pow(s.x-y.x,2)+Math.pow(s.y-y.y,2));x<r?(r=x,i=[y]):x===r&&i.push(y)}return i},findInTargetRectPoints=(o,n)=>[{x:o.x,y:o.y,position:0},{x:o.x+o.width,y:o.y,position:1},{x:o.x,y:o.y+o.height,position:2},{x:o.x+o.width,y:o.y+o.height,position:3}].filter(i=>i.x>=n.x&&i.x<=n.width+n.x&&i.y>=n.y&&i.y<=n.height+n.y),findInTargetRectEdges=(o,n)=>{const s=o.x+o.width,r=o.y+o.height,i=n.x+n.width,y=n.y+n.height,x=o.x<=i&&s>=n.x&&o.y<=y&&r>=n.y,e=o.x<=n.x&&s>=i&&o.y<=n.y&&r>=y;return x||e},reCalcRect=(o,n,s,r)=>{const i=findInTargetRectPoints(o,n);if(i.length>0){const x=i.length>=3?i:findNearestPoints(i,n),e=x[0].position||0,h={0:t=>({x:t.x,y:t.y}),1:t=>({x:t.x-s,y:t.y}),2:t=>({x:t.x,y:t.y-r}),3:t=>({x:t.x-s,y:t.y-r})},{x:p,y:f}=h[e](x[0],s,r);return{width:s,height:r,x:p,y:f}}return findInTargetRectEdges(o,n)?{width:s,height:r,x:(n.x+n.width-s)/2,y:(n.y+n.height-r)/2}:__spreadProps(__spreadValues({},o),{noChange:!0})};module.exports=reCalcRect;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),pointCloud2DRectOperation=require("./core/toolOperation/pointCloud2DRectOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),segmentByRect=require("./core/toolOperation/segmentByRect.js"),segmentBySAM=require("./core/toolOperation/segmentBySAM.js"),annotation=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),AttributeUtils=require("./utils/tool/AttributeUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),EventBus=require("./utils/EventBus.js"),CanvasUtils=require("./utils/tool/CanvasUtils.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),StyleUtils=require("./utils/tool/StyleUtils.js"),cursorTextClass=require("./core/toolOperation/cursorTextClass.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js"),index$1=require("./core/pointCloud/index.js"),matrix=require("./core/pointCloud/matrix.js"),annotation$1=require("./core/pointCloud/annotation.js");function _interopNamespaceDefaultOnly(e){return Object.freeze({__proto__:null,default:e})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.PointCloud2DRectOperation=pointCloud2DRectOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.SegmentByRect=segmentByRect,exports.SegmentBySAM=segmentBySAM,exports.cAnnotation=annotation,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.CLIENT_TOOL_HEAD_TYPE=tool.CLIENT_TOOL_HEAD_TYPE,exports.CLIENT_TOOL_NAME=tool.CLIENT_TOOL_NAME,exports.DEFAULT_FONT=tool.DEFAULT_FONT,exports.DEFAULT_TEXT_MAX_WIDTH=tool.DEFAULT_TEXT_MAX_WIDTH,Object.defineProperty(exports,"EAnnotationMode",{enumerable:!0,get:function(){return tool.EAnnotationMode}}),Object.defineProperty(exports,"EAudioToolName",{enumerable:!0,get:function(){return tool.EAudioToolName}}),Object.defineProperty(exports,"EAuditStatus",{enumerable:!0,get:function(){return tool.EAuditStatus}}),Object.defineProperty(exports,"ECheckModel",{enumerable:!0,get:function(){return tool.ECheckModel}}),Object.defineProperty(exports,"EDependPattern",{enumerable:!0,get:function(){return tool.EDependPattern}}),Object.defineProperty(exports,"EDragTarget",{enumerable:!0,get:function(){return tool.EDragTarget}}),Object.defineProperty(exports,"EDrawPointPattern",{enumerable:!0,get:function(){return tool.EDrawPointPattern}}),Object.defineProperty(exports,"EFilterToolOperation",{enumerable:!0,get:function(){return tool.EFilterToolOperation}}),Object.defineProperty(exports,"ELineColor",{enumerable:!0,get:function(){return tool.ELineColor}}),Object.defineProperty(exports,"ELineTypes",{enumerable:!0,get:function(){return tool.ELineTypes}}),Object.defineProperty(exports,"EOperationMode",{enumerable:!0,get:function(){return tool.EOperationMode}}),Object.defineProperty(exports,"EPageOperator",{enumerable:!0,get:function(){return tool.EPageOperator}}),Object.defineProperty(exports,"EPointCloudName",{enumerable:!0,get:function(){return tool.EPointCloudName}}),Object.defineProperty(exports,"EPolygonPattern",{enumerable:!0,get:function(){return tool.EPolygonPattern}}),Object.defineProperty(exports,"ERectPattern",{enumerable:!0,get:function(){return tool.ERectPattern}}),Object.defineProperty(exports,"EScribblePattern",{enumerable:!0,get:function(){return tool.EScribblePattern}}),Object.defineProperty(exports,"ESelectedType",{enumerable:!0,get:function(){return tool.ESelectedType}}),Object.defineProperty(exports,"ETextType",{enumerable:!0,get:function(){return tool.ETextType}}),Object.defineProperty(exports,"EThumbnailOption",{enumerable:!0,get:function(){return tool.EThumbnailOption}}),Object.defineProperty(exports,"EToolName",{enumerable:!0,get:function(){return tool.EToolName}}),Object.defineProperty(exports,"EToolType",{enumerable:!0,get:function(){return tool.EToolType}}),Object.defineProperty(exports,"EVideoToolName",{enumerable:!0,get:function(){return tool.EVideoToolName}}),exports.OPERATION_LIST=tool.OPERATION_LIST,exports.SEGMENT_NUMBER=tool.SEGMENT_NUMBER,exports.TEXT_ATTRIBUTE_LINE_HEIGHT=tool.TEXT_ATTRIBUTE_LINE_HEIGHT,exports.TEXT_ATTRIBUTE_MAX_LENGTH=tool.TEXT_ATTRIBUTE_MAX_LENGTH,exports.TEXT_TYPE=tool.TEXT_TYPE,exports.TOOL_NAME=tool.TOOL_NAME,exports.TOOL_NAME_EN=tool.TOOL_NAME_EN,exports.cTool=tool,exports.edgeAdsorptionScope=tool.edgeAdsorptionScope,exports.editStepWidth=tool.editStepWidth,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils.default,exports.MathUtils=MathUtils.default,exports.AttributeUtils=AttributeUtils.default,exports.ActionsHistory=ActionsHistory,exports.EventBus=EventBus,exports.CanvasUtils=CanvasUtils,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.StyleUtils=StyleUtils,exports.CursorTextClass=cursorTextClass,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.PointCloud=index$1.PointCloud,exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloudAnnotation=annotation$1.PointCloudAnnotation,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),pointCloud2DRectOperation=require("./core/toolOperation/pointCloud2DRectOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),segmentByRect=require("./core/toolOperation/segmentByRect.js"),segmentBySAM=require("./core/toolOperation/segmentBySAM.js"),annotation=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),AttributeUtils=require("./utils/tool/AttributeUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),EventBus=require("./utils/EventBus.js"),CanvasUtils=require("./utils/tool/CanvasUtils.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),StyleUtils=require("./utils/tool/StyleUtils.js"),cursorTextClass=require("./core/toolOperation/cursorTextClass.js"),constants=require("./locales/constants.js"),message=require("./locales/zh_CN/message.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js"),index$1=require("./core/pointCloud/index.js"),matrix=require("./core/pointCloud/matrix.js"),annotation$1=require("./core/pointCloud/annotation.js");function _interopNamespaceDefaultOnly(e){return Object.freeze({__proto__:null,default:e})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.PointCloud2DRectOperation=pointCloud2DRectOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.SegmentByRect=segmentByRect,exports.SegmentBySAM=segmentBySAM,exports.cAnnotation=annotation,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.CLIENT_TOOL_HEAD_TYPE=tool.CLIENT_TOOL_HEAD_TYPE,exports.CLIENT_TOOL_NAME=tool.CLIENT_TOOL_NAME,exports.DEFAULT_FONT=tool.DEFAULT_FONT,exports.DEFAULT_TEXT_MAX_WIDTH=tool.DEFAULT_TEXT_MAX_WIDTH,Object.defineProperty(exports,"EAnnotationMode",{enumerable:!0,get:function(){return tool.EAnnotationMode}}),Object.defineProperty(exports,"EAudioToolName",{enumerable:!0,get:function(){return tool.EAudioToolName}}),Object.defineProperty(exports,"EAuditStatus",{enumerable:!0,get:function(){return tool.EAuditStatus}}),Object.defineProperty(exports,"ECheckModel",{enumerable:!0,get:function(){return tool.ECheckModel}}),Object.defineProperty(exports,"EDependPattern",{enumerable:!0,get:function(){return tool.EDependPattern}}),Object.defineProperty(exports,"EDragTarget",{enumerable:!0,get:function(){return tool.EDragTarget}}),Object.defineProperty(exports,"EDrawPointPattern",{enumerable:!0,get:function(){return tool.EDrawPointPattern}}),Object.defineProperty(exports,"EFilterToolOperation",{enumerable:!0,get:function(){return tool.EFilterToolOperation}}),Object.defineProperty(exports,"ELineColor",{enumerable:!0,get:function(){return tool.ELineColor}}),Object.defineProperty(exports,"ELineTypes",{enumerable:!0,get:function(){return tool.ELineTypes}}),Object.defineProperty(exports,"EOperationMode",{enumerable:!0,get:function(){return tool.EOperationMode}}),Object.defineProperty(exports,"EPageOperator",{enumerable:!0,get:function(){return tool.EPageOperator}}),Object.defineProperty(exports,"EPointCloudName",{enumerable:!0,get:function(){return tool.EPointCloudName}}),Object.defineProperty(exports,"EPolygonPattern",{enumerable:!0,get:function(){return tool.EPolygonPattern}}),Object.defineProperty(exports,"ERectPattern",{enumerable:!0,get:function(){return tool.ERectPattern}}),Object.defineProperty(exports,"EScribblePattern",{enumerable:!0,get:function(){return tool.EScribblePattern}}),Object.defineProperty(exports,"ESelectedType",{enumerable:!0,get:function(){return tool.ESelectedType}}),Object.defineProperty(exports,"ETextType",{enumerable:!0,get:function(){return tool.ETextType}}),Object.defineProperty(exports,"EThumbnailOption",{enumerable:!0,get:function(){return tool.EThumbnailOption}}),Object.defineProperty(exports,"EToolName",{enumerable:!0,get:function(){return tool.EToolName}}),Object.defineProperty(exports,"EToolType",{enumerable:!0,get:function(){return tool.EToolType}}),Object.defineProperty(exports,"EVideoToolName",{enumerable:!0,get:function(){return tool.EVideoToolName}}),exports.OPERATION_LIST=tool.OPERATION_LIST,exports.SEGMENT_NUMBER=tool.SEGMENT_NUMBER,exports.TEXT_ATTRIBUTE_LINE_HEIGHT=tool.TEXT_ATTRIBUTE_LINE_HEIGHT,exports.TEXT_ATTRIBUTE_MAX_LENGTH=tool.TEXT_ATTRIBUTE_MAX_LENGTH,exports.TEXT_TYPE=tool.TEXT_TYPE,exports.TOOL_NAME=tool.TOOL_NAME,exports.TOOL_NAME_EN=tool.TOOL_NAME_EN,exports.cTool=tool,exports.edgeAdsorptionScope=tool.edgeAdsorptionScope,exports.editStepWidth=tool.editStepWidth,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils.default,exports.MathUtils=MathUtils.default,exports.AttributeUtils=AttributeUtils.default,exports.ActionsHistory=ActionsHistory,exports.EventBus=EventBus,exports.CanvasUtils=CanvasUtils,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.StyleUtils=StyleUtils,exports.CursorTextClass=cursorTextClass,Object.defineProperty(exports,"EMessage",{enumerable:!0,get:function(){return constants.EMessage}}),exports.MESSAGE_CN=message,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.PointCloud=index$1.PointCloud,exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.omniCamera11VTransfer=matrix.omniCamera11VTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloudAnnotation=annotation$1.PointCloudAnnotation,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
@@ -17,6 +17,7 @@ declare enum EKeyCode {
17
17
  Y = 89,
18
18
  S = 83,
19
19
  Q = 81,
20
+ P = 80,
20
21
  One = 49,
21
22
  Two = 50,
22
23
  Three = 51,
@@ -244,6 +244,7 @@ export declare class PointCloud extends EventListener {
244
244
  getHighlightIndexByMappingImgList: ({ mappingImgList, points, }: {
245
245
  mappingImgList: Array<{
246
246
  url: string;
247
+ fallbackUrl: string;
247
248
  calib?: ICalib;
248
249
  }>;
249
250
  points: ArrayLike<number>;
@@ -255,7 +256,10 @@ export declare class PointCloud extends EventListener {
255
256
  * @param boxParams
256
257
  * @returns
257
258
  */
258
- highlightOriginPointCloud(pointCloudBoxList?: IPointCloudBox[], highlightIndex?: number[]): Promise<THREE.BufferAttribute[] | undefined>;
259
+ highlightOriginPointCloud(pointCloudBoxList?: IPointCloudBox[], highlightIndex?: number[], config?: {
260
+ modifiedBoxIds: string[];
261
+ resetAreas: ICoordinate[][];
262
+ }): Promise<THREE.BufferAttribute[] | undefined>;
259
263
  /**
260
264
  * Clean all highlightBox
261
265
  */
@@ -50,6 +50,9 @@ export default class ViewOperation extends BasicToolOperation {
50
50
  onMouseMove(e: MouseEvent): void;
51
51
  getHoverRectID: (e: MouseEvent) => string | undefined;
52
52
  updateData(annotations: TAnnotationViewData[]): Promise<void>;
53
+ setConfig(config: {
54
+ [a: string]: any;
55
+ } | string): void;
53
56
  /**
54
57
  * 获取当前结果的标注类型
55
58
  * @param obj
@@ -3,12 +3,17 @@
3
3
  * @author lihuaqi <lihuaqi@sensetime.com>
4
4
  * @date 2023年7月27日
5
5
  */
6
+ import { IPointCloud2DRectOperationViewRect } from '@labelbee/lb-utils';
6
7
  import { RectOperation } from './rectOperation';
7
8
  declare class PointCloud2DRectOperation extends RectOperation {
8
9
  checkMode?: Boolean;
9
10
  constructor(props: any);
10
- createNewDrawingRect(): void;
11
- deleteSelectedRect(): void;
12
- onMouseMove(e: MouseEvent): undefined;
11
+ createNewDrawingRect(e: MouseEvent, basicSourceID: string): void;
12
+ deleteSelectedRect(e: UIEvent): void;
13
+ setSelectedIdAfterAddingDrawingRect(): void;
14
+ setSelectedRectID(newID?: string): void;
15
+ onKeyDown(e: KeyboardEvent): true | undefined;
16
+ renderDrawingRect(rect: IPointCloud2DRectOperationViewRect & IRect, zoom?: number, isZoom?: boolean): void;
17
+ resizeRect(resizeWidth?: number, resizeHeight?: number): void;
13
18
  }
14
19
  export default PointCloud2DRectOperation;
@@ -81,6 +81,10 @@ declare class PointOperation extends BasicToolOperation {
81
81
  onDragMove(e: MouseEvent): void;
82
82
  onKeyDown(e: KeyboardEvent): void;
83
83
  isMinDistance: (coord: ICoordinate) => boolean;
84
+ getNearPoint(coordinate: ICoordinate): {
85
+ newPoint: ICoordinate;
86
+ hasClosed: boolean;
87
+ };
84
88
  createPoint(e: MouseEvent): void;
85
89
  isInPoint(pos: ICoordinate, point: ICoordinate, zoom?: number): boolean;
86
90
  getHoverId(): string | undefined;
@@ -98,6 +98,7 @@ declare class PolygonOperation extends BasicToolOperation {
98
98
  */
99
99
  setPolygonDataByID(newPolygonData: Partial<IPolygonData>, id?: string): IPolygonData[];
100
100
  rotatePolygon(angle?: number, direction?: ERotateDirection, selectedID?: string | undefined): void;
101
+ rotatePolygonEdge(pointList: IPolygonPoint[], selectedID?: string | undefined): void;
101
102
  addPointInDrawing(e: MouseEvent): void;
102
103
  clearResult(): void;
103
104
  /**
@@ -184,6 +185,7 @@ declare class PolygonOperation extends BasicToolOperation {
184
185
  */
185
186
  emitUpdatePolygonByDrag: () => void;
186
187
  leftMouseUpdateValid(e: MouseEvent): boolean;
188
+ stopDrag(): void;
187
189
  leftMouseUp(e: MouseEvent): void;
188
190
  onMouseUp(e: MouseEvent): undefined;
189
191
  dragMouseUp(): void;
@@ -10,6 +10,7 @@ declare class RectOperation extends BasicToolOperation {
10
10
  firstCurrentPos?: ICoordinate;
11
11
  rectList: IRect[];
12
12
  hoverRectID?: string;
13
+ selectedRectTextAttribute: string;
13
14
  hoverRectPointIndex: number;
14
15
  hoverRectEdgeIndex: number;
15
16
  isFlow: boolean;
@@ -20,6 +21,8 @@ declare class RectOperation extends BasicToolOperation {
20
21
  private selection;
21
22
  private dragInfo?;
22
23
  private highlightVisible;
24
+ /** Whether or not add rect */
25
+ private enableAddRect;
23
26
  constructor(props: IRectOperationProps);
24
27
  setResult(rectList: IRect[]): void;
25
28
  destroy(): void;
@@ -73,6 +76,10 @@ declare class RectOperation extends BasicToolOperation {
73
76
  /** 更新文本输入,并且进行关闭 */
74
77
  updateSelectedRectTextAttribute(newTextAttribute?: string): void;
75
78
  getHoverRectID: (e: MouseEvent) => string;
79
+ /**
80
+ * 获取当前选中rect的文本
81
+ */
82
+ getSelectedRectTextAttribute: (hoverRectID: string) => string;
76
83
  /**
77
84
  * 获取当前的选中部分的hoverIndex
78
85
  * ../../../param e
@@ -99,6 +106,7 @@ declare class RectOperation extends BasicToolOperation {
99
106
  disableDelete?: boolean | undefined;
100
107
  isHighlight?: boolean | undefined;
101
108
  label?: string | undefined;
109
+ lineDash?: number[] | undefined;
102
110
  };
103
111
  getRectsBoundaries(rects: IRect[], offset: ICoordinate): {
104
112
  top: number;
@@ -144,9 +152,11 @@ declare class RectOperation extends BasicToolOperation {
144
152
  rightMouseUp(e: MouseEvent): void;
145
153
  shiftRightMouseUp(e: MouseEvent): void;
146
154
  updateDragResult(): void;
155
+ /** Allow/Disallow to add rect to rectList */
156
+ setEnableAddRect(isEnableAddRect: boolean): void;
147
157
  onMouseUp(e: MouseEvent): true | undefined;
148
158
  onRightDblClick(e: MouseEvent): void;
149
- deleteSelectedRect(): void;
159
+ deleteSelectedRect(e: UIEvent): void;
150
160
  onKeyDown(e: KeyboardEvent): true | undefined;
151
161
  onKeyUp(e: KeyboardEvent): void;
152
162
  onWheel(e: MouseEvent): void;
@@ -172,8 +182,8 @@ declare class RectOperation extends BasicToolOperation {
172
182
  /**
173
183
  * 绘制当前框的
174
184
  * @param rect 当前矩形框
175
- * @param zoom 是否进行缩放
176
- * @param isZoom 矩形框是否为缩放后的比例
185
+ * @param zoom 缩放比例
186
+ * @param isZoom 是否进行缩放
177
187
  */
178
188
  renderDrawingRect(rect: IRect, zoom?: number, isZoom?: boolean): void;
179
189
  /**
@@ -192,6 +202,7 @@ declare class RectOperation extends BasicToolOperation {
192
202
  render(): void;
193
203
  setDefaultAttribute(defaultAttribute?: string): void;
194
204
  setValid(valid: boolean): void;
205
+ private clearDrawingStatus;
195
206
  /**
196
207
  * 清楚所有的中间状态
197
208
  */
@@ -0,0 +1,9 @@
1
+ interface RectInfo {
2
+ width: number;
3
+ height: number;
4
+ x: number;
5
+ y: number;
6
+ noChange?: boolean;
7
+ }
8
+ declare const reCalcRect: (curRect: RectInfo, targetRect: RectInfo, scaleWidth: number, scaleHeight: number) => RectInfo;
9
+ export default reCalcRect;
@@ -35,9 +35,11 @@ import AnnotationEngine from './core';
35
35
  import UnitUtils from './utils/tool/UnitUtils';
36
36
  import StyleUtils from './utils/tool/StyleUtils';
37
37
  import CursorTextClass from './core/toolOperation/cursorTextClass';
38
+ import { EMessage } from './locales/constants';
39
+ import MESSAGE_CN from './locales/zh_CN/message';
38
40
  declare const CommonToolUtils: typeof EnhanceCommonToolUtils;
39
41
  declare const toolUtils: typeof EnhanceCommonToolUtils;
40
- export { RectOperation, TagOperation, PointOperation, LineToolOperation, PolygonOperation, TextToolOperation, BasicToolOperation, PointCloud2DRectOperation, MeasureOperation, ViewOperation, PointCloud2dOperation, SegmentByRect, SegmentBySAM, CursorTextClass, cAnnotation, cAnnotationTask, cKeyCode, cStyle, cTool, toolUtils, DblClickEventListener, CommonToolUtils, uuid, MarkerUtils, RectUtils, AxisUtils, TagUtils, DrawUtils, ImgUtils, MathUtils, AttributeUtils, CanvasUtils, AnnotationEngine, ScribbleTool, UnitUtils, StyleUtils, ActionsHistory, EventBus, };
42
+ export { RectOperation, TagOperation, PointOperation, LineToolOperation, PolygonOperation, TextToolOperation, BasicToolOperation, PointCloud2DRectOperation, MeasureOperation, ViewOperation, PointCloud2dOperation, SegmentByRect, SegmentBySAM, CursorTextClass, cAnnotation, cAnnotationTask, cKeyCode, cStyle, cTool, toolUtils, DblClickEventListener, CommonToolUtils, uuid, MarkerUtils, RectUtils, AxisUtils, TagUtils, DrawUtils, ImgUtils, MathUtils, AttributeUtils, CanvasUtils, AnnotationEngine, ScribbleTool, UnitUtils, StyleUtils, ActionsHistory, EventBus, EMessage, MESSAGE_CN, };
41
43
  export * from './newCore';
42
44
  export * from './constant/tool';
43
45
  export * from './core/pointCloud';
@@ -35,6 +35,7 @@ export default class AxisUtils {
35
35
  disableDelete?: boolean | undefined;
36
36
  isHighlight?: boolean | undefined;
37
37
  label?: string | undefined;
38
+ lineDash?: number[] | undefined;
38
39
  };
39
40
  /**
40
41
  * 计算点在 zoom 和 currentPos 的转换
@@ -13,6 +13,7 @@ export default class PolygonUtils {
13
13
  */
14
14
  static calcPolygonSize(pointList?: IPolygonPoint[]): number;
15
15
  static isInPolygon(checkPoint: IPolygonPoint, polygonPoints: (IPolygonPoint | ICoordinate)[], lineType?: ELineTypes): boolean;
16
+ static isPointInOrOnPolygon(point: IPolygonPoint, polygonData: (IPolygonPoint | ICoordinate)[], errorMargin?: number): boolean;
16
17
  /**
17
18
  * 通过数据转换为平滑曲线的点提交 [{x: number, y: number}...] => [x, ...smoothCurvePoints ,y]
18
19
  * @param pointList
@@ -59,6 +59,7 @@ export default class RectUtils {
59
59
  disableDelete?: boolean | undefined;
60
60
  isHighlight?: boolean | undefined;
61
61
  label?: string | undefined;
62
+ lineDash?: number[] | undefined;
62
63
  };
63
64
  /**
64
65
  * 判断当前矩形是否不在多边形内
@@ -1 +1 @@
1
- "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,n=3,i=tool.ELineTypes.Line){let r="",o=Infinity;const l=AxisUtils.default.axisArea(e,n);return t.forEach(s=>{s.pointList&&l.forEach(u=>{const a=this.calcPolygonSize(s.pointList);this.isInPolygon(u,s.pointList,i)&&a<o&&(r=s.id,o=a)})}),r}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,n=e.reduce((i,r,o,l)=>{const s=l[(o+1)%t];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(e,t,n=tool.ELineTypes.Line){let i=0,r,o,l,s;t=[...t],n===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((a,h)=>[...a,h.x,h.y],[]),.5,!0,20)),[l]=t;const u=t.length;for(r=1;r<=u;r++)s=t[r%u],e.x>Math.min(l.x,s.x)&&e.x<=Math.max(l.x,s.x)&&e.y<=Math.max(l.y,s.y)&&l.x!==s.x&&(o=(e.x-l.x)*(s.y-l.y)/(s.x-l.x)+l.y,(l.y===s.y||e.y<=o)&&i++),l=s;return i%2!=0}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,t).map((i,r)=>{var o;const l=r/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),u=(o=e[s])!=null?o:{};return __spreadValues(s===l?__spreadValues({},u):{specialEdge:u.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,n=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const r=[],o=e.slice(0);let l,s,u,a,h,g,P,E,x,m,c,d,f;for(n?(o.unshift(e[e.length-1]),o.unshift(e[e.length-2]),o.unshift(e[e.length-1]),o.unshift(e[e.length-2]),o.push(e[0]),o.push(e[1])):(o.unshift(e[1]),o.unshift(e[0]),o.push(e[e.length-2]),o.push(e[e.length-1])),f=2;f<o.length-4;f+=2)for(u=(o[f+2]-o[f-2])*t,a=(o[f+4]-o[f-0])*t,h=(o[f+3]-o[f-1])*t,g=(o[f+5]-o[f+1])*t,d=0;d<=i;d++)c=d/i,P=2*Math.pow(c,3)-3*Math.pow(c,2)+1,E=-(2*Math.pow(c,3))+3*Math.pow(c,2),x=Math.pow(c,3)-2*Math.pow(c,2)+c,m=Math.pow(c,3)-Math.pow(c,2),l=P*o[f]+E*o[f+2]+x*u+m*a,s=P*o[f+1]+E*o[f+3]+x*h+m*g,r.push(l),r.push(s);const v=[];for(let y=0;y<r.length-1;y+=2)v.push({x:r[y],y:r[y+1]});if(n)for(let y=0;y<i+1;y++){const M=v.shift();v.push(M)}return v}static getPolygonByID(e,t){return e.find(n=>n.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(n=>t.includes(n.id)):[]}static getHoverEdgeIndex(e,t,n=tool.ELineTypes.Line,i=3){let r=[...t];n===tool.ELineTypes.Curve?r=this.createSmoothCurvePoints(t.reduce((s,u)=>[...s,u.x,u.y],[]),.5,!0,tool.SEGMENT_NUMBER):n===tool.ELineTypes.Line&&r.push(r[0]);let o=-1,l=i;for(let s=0;s<r.length-1;s++){const{length:u}=MathUtils.default.getFootOfPerpendicular(e,r[s],r[s+1]);u<l&&(o=s,l=u)}return o===-1?-1:n===tool.ELineTypes.Curve?Math.floor(o/tool.SEGMENT_NUMBER):o}static getClosestPoint(e,t,n=tool.ELineTypes.Line,i=3,r){var o;let l=!1;const s=(o=r==null?void 0:r.isClose)!=null?o:!0;let u="",a=-1,h=Infinity,g=e;const P=20;let E=!1;return t.forEach(x=>{if(!E&&!!x.pointList)switch(n){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(x.pointList,s).forEach((c,d)=>{if(E)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,c.point1,c.point2);const y=MathUtils.default.getLineLength(c.point1,e),M=MathUtils.default.getLineLength(c.point2,e);y<i*2&&(v=c.point1,f=y,E=!0),M<i*2&&(v=c.point2,f=M,E=!0),f<h&&f<i&&(u=x.id,a=d,h=f,g=v,l=!0)});break;case tool.ELineTypes.Curve:{const m=this.createSmoothCurvePoints(x.pointList.reduce((c,d)=>[...c,d.x,d.y],[]),.5,s,P);for(let c=0;c<m.length-1;c++){const{length:d,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,m[c],m[c+1]);d<h&&d<i&&(u=x.id,a=Math.floor(c/(P+1)),h=d,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:a,closestPolygonID:u,hasClosed:l}}static isPointListInPolygon(e,t,n=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,n))}static isPointListOutSidePolygon(e,t,n=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,n))}static getPolygonArea(e){let t=0;for(let n=0,i=e.length;n<i;n++){const r=e[n].x,o=e[n===e.length-1?0:n+1].y,l=e[n===e.length-1?0:n+1].x,s=e[n].y;t+=r*o*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,n){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,n)}static deletePolygonLastPoint(e,t,n,i){return n===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var n,i;try{let r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(a=>[a.x,a.y]))]]),u=turf.difference(r,s);u&&(r=u)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const u=s.length,a=s.filter((h,g)=>{const P=(g+1)%u;return!AxisUtils.default.getIsInScope(h,s[P],1)});return a.length<3?l:[...l,a]},[])}catch(r){console.error(r)}}static getPolygonPointList(e,t){const n=t.find(i=>i.id===e);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(n=>PolygonUtils.isPointListInPolygon(e,n.pointList))}static clipPolygonFromWrapPolygon(e,t){const n=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),r=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),o=t[r];let l=[...t.slice(0,r),o,...e,e[0],...t.slice(r,t.length)];return n===i&&(l=[...t.slice(0,r),o,e[0],...e.reverse(),...t.slice(r,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let n,i,r,o=0,l;if(t<3)return 0;for(n=0;n<t;n++)i=(n+1)%t,r=(n+2)%t,l=(e[i].x-e[n].x)*(e[r].y-e[i].y),l-=(e[i].y-e[n].y)*(e[r].x-e[i].x),l<0?o--:l>0&&o++;return o>0?1:o<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let n=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((r,o)=>{const l=LineToolUtils.default.calcDistance(e,r);l<n&&(n=l,i=o)}),i}static combinePolygonWithPolygon(e,t){var n,i;try{const r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(a=>[a.x,a.y]))]]),o=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(a=>[a.x,a.y]))]]),l=turf.union(r,o),s=[],u=e;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(t.id);const a=l==null?void 0:l.geometry.coordinates.map(h=>{var g;return((g=l==null?void 0:l.geometry)==null?void 0:g.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];u.pointList=a}return{newPolygon:u,unionList:s}}catch(r){console.error(r)}}static composePointList(e,t){let n=0,i=0,r=Number.MAX_VALUE;return e.forEach((o,l)=>{t.forEach((s,u)=>{const a=LineToolUtils.default.calcDistance(o,s);a<r&&(n=l+1,i=u+1,r=a)})}),[...e.slice(0,n),...t.slice(i,t.length),...t.slice(0,i),...e.slice(n,e.length)]}static composeSegmentPolygonList(e){var t,n;const i=[];for(let r=0;r<e.length;r++)for(let o=0;o<e.length;o++){const l=(t=e[r])==null?void 0:t.pointList,s=(n=e[o])==null?void 0:n.pointList;r!==o&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[r].pointList=PolygonUtils.composePointList(l,s),i.unshift(o))}return i.forEach(r=>{e.splice(r,1)}),e}}module.exports=PolygonUtils;
1
+ "use strict";var turf=require("@turf/turf"),annotation=require("../../constant/annotation.js"),CommonToolUtils=require("./CommonToolUtils.js"),tool=require("../../constant/tool.js"),AxisUtils=require("./AxisUtils.js"),MathUtils=require("../MathUtils.js"),LineToolUtils=require("./LineToolUtils.js"),__defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(L,e,t)=>e in L?__defProp(L,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):L[e]=t,__spreadValues=(L,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(L,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(L,t,e[t]);return L};class PolygonUtils{static getHoverPolygonID(e,t,o=3,i=tool.ELineTypes.Line){let n="",r=Infinity;const l=AxisUtils.default.axisArea(e,o);return t.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(n=s.id,r=u)})}),n}static calcPolygonSize(e=[]){if((e==null?void 0:e.length)<=2)return 0;const t=e.length,o=e.reduce((i,n,r,l)=>{const s=l[(r+1)%t];return i+n.x*s.y-s.x*n.y},0);return Math.abs(o)/2}static isInPolygon(e,t,o=tool.ELineTypes.Line){return t=[...t],o===tool.ELineTypes.Curve&&(t=this.createSmoothCurvePoints(t.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(e,t)}static isPointInOrOnPolygon(e,t,o=1e-9){const{x:i,y:n}=e;let r=!1;for(let l=0,s=t.length-1;l<t.length;s=l++){const{x:c,y:u}=t[l],{x:h,y:d}=t[s],y=i<=Math.max(c,h)&&i>=Math.min(c,h)&&n<=Math.max(u,d)&&n>=Math.min(u,d),P=(n-u)*(h-c)-(i-c)*(d-u);if(y&&Math.abs(P)<o)return!0;u>n!=d>n&&i<(h-c)*(n-u)/(d-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(e,t=tool.SEGMENT_NUMBER){return this.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!1,t).map((i,n)=>{var r;const l=n/(tool.SEGMENT_NUMBER+1),s=Math.floor(l),c=(r=e[s])!=null?r:{};return __spreadValues(s===l?__spreadValues({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(e,t=.5,o=!1,i=tool.SEGMENT_NUMBER){if(e.length<4)return e;const n=[],r=e.slice(0);let l,s,c,u,h,d,y,P,m,x,a,g,f;for(o?(r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.unshift(e[e.length-1]),r.unshift(e[e.length-2]),r.push(e[0]),r.push(e[1])):(r.unshift(e[1]),r.unshift(e[0]),r.push(e[e.length-2]),r.push(e[e.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*t,u=(r[f+4]-r[f-0])*t,h=(r[f+3]-r[f-1])*t,d=(r[f+5]-r[f+1])*t,g=0;g<=i;g++)a=g/i,y=2*Math.pow(a,3)-3*Math.pow(a,2)+1,P=-(2*Math.pow(a,3))+3*Math.pow(a,2),m=Math.pow(a,3)-2*Math.pow(a,2)+a,x=Math.pow(a,3)-Math.pow(a,2),l=y*r[f]+P*r[f+2]+m*c+x*u,s=y*r[f+1]+P*r[f+3]+m*h+x*d,n.push(l),n.push(s);const v=[];for(let E=0;E<n.length-1;E+=2)v.push({x:n[E],y:n[E+1]});if(o)for(let E=0;E<i+1;E++){const M=v.shift();v.push(M)}return v}static getPolygonByID(e,t){return e.find(o=>o.id===t)}static getPolygonByIDs(e,t){return t&&(t==null?void 0:t.length)>0?e.filter(o=>t.includes(o.id)):[]}static getHoverEdgeIndex(e,t,o=tool.ELineTypes.Line,i=5){let n=[...t];o===tool.ELineTypes.Curve?n=this.createSmoothCurvePoints(t.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,tool.SEGMENT_NUMBER):o===tool.ELineTypes.Line&&n.push(n[0]);let r=-1,l=i;for(let s=0;s<n.length-1;s++){const{length:c}=MathUtils.default.getFootOfPerpendicular(e,n[s],n[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:o===tool.ELineTypes.Curve?Math.floor(r/tool.SEGMENT_NUMBER):r}static getClosestPoint(e,t,o=tool.ELineTypes.Line,i=3,n){var r;let l=!1;const s=(r=n==null?void 0:n.isClose)!=null?r:!0;let c="",u=-1,h=Infinity,d=e;const y=20;let P=!1;return t.forEach(m=>{if(!P&&!!m.pointList)switch(o){case tool.ELineTypes.Line:CommonToolUtils.findAllLine(m.pointList,s).forEach((a,g)=>{if(P)return;let{length:f,footPoint:v}=MathUtils.default.getFootOfPerpendicular(e,a.point1,a.point2);const E=MathUtils.default.getLineLength(a.point1,e),M=MathUtils.default.getLineLength(a.point2,e);E<i*2&&(v=a.point1,f=E,P=!0),M<i*2&&(v=a.point2,f=M,P=!0),f<h&&f<i&&(c=m.id,u=g,h=f,d=v,l=!0)});break;case tool.ELineTypes.Curve:{const x=this.createSmoothCurvePoints(m.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,y);for(let a=0;a<x.length-1;a++){const{length:g,footPoint:f}=MathUtils.default.getFootOfPerpendicular(e,x[a],x[a+1]);g<h&&g<i&&(c=m.id,u=Math.floor(a/(y+1)),h=g,d=f,l=!0)}}break}}),{dropFoot:d,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(e,t,o=tool.ELineTypes.Line){return e.every(i=>this.isInPolygon(i,t,o))}static isPointListOutSidePolygon(e,t,o=tool.ELineTypes.Line){return e.some(i=>!this.isInPolygon(i,t,o))}static getPolygonArea(e){let t=0;for(let o=0,i=e.length;o<i;o++){const n=e[o].x,r=e[o===e.length-1?0:o+1].y,l=e[o===e.length-1?0:o+1].x,s=e[o].y;t+=n*r*.5,t-=l*s*.5}return Math.abs(t)}static updatePolygonByRotate(e,t=1,o){let i=1;return e===annotation.ERotateDirection.Anticlockwise&&(i=-1),i*=t,MathUtils.default.rotateRectPointList(i,o)}static deletePolygonLastPoint(e,t,o,i){return o===i.length-1?e:[...e,{x:t[0],y:t[1]}]}static concatBeginAndEnd(e){return e.length<1?e:[...e,e[0]]}static segmentPolygonByPolygon(e,t){var o,i;try{let n=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.map(l=>[l.x,l.y]))]]);return t.forEach(l=>{const s=turf.polygon([[...PolygonUtils.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=turf.difference(n,s);c&&(n=c)}),((i=(o=n==null?void 0:n.geometry)==null?void 0:o.coordinates.map(l=>{var s;return((s=n==null?void 0:n.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):l.reduce(PolygonUtils.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((h,d)=>{const y=(d+1)%c;return!AxisUtils.default.getIsInScope(h,s[y],1)});return u.length<3?l:[...l,u]},[])}catch(n){console.error(n)}}static getPolygonPointList(e,t){const o=t.find(i=>i.id===e);return o&&o.pointList&&o.pointList.length>0?o.pointList:[]}static getWrapPolygonIndex(e,t){return t.findIndex(o=>PolygonUtils.isPointListInPolygon(e,o.pointList))}static clipPolygonFromWrapPolygon(e,t){const o=PolygonUtils.isPolygonClosewise(t),i=PolygonUtils.isPolygonClosewise(e),n=PolygonUtils.getClosePointDistanceFromPolygon(e[0],t),r=t[n];let l=[...t.slice(0,n),r,...e,e[0],...t.slice(n,t.length)];return o===i&&(l=[...t.slice(0,n),r,e[0],...e.reverse(),...t.slice(n,t.length)]),l}static isPolygonClosewise(e){const t=e.length;let o,i,n,r=0,l;if(t<3)return 0;for(o=0;o<t;o++)i=(o+1)%t,n=(o+2)%t,l=(e[i].x-e[o].x)*(e[n].y-e[i].y),l-=(e[i].y-e[o].y)*(e[n].x-e[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(e,t){let o=Number.MAX_SAFE_INTEGER,i=-1;return t.forEach((n,r)=>{const l=LineToolUtils.default.calcDistance(e,n);l<o&&(o=l,i=r)}),i}static combinePolygonWithPolygon(e,t){var o,i;try{const n=turf.polygon([[...PolygonUtils.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),r=turf.polygon([[...PolygonUtils.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=turf.union(n,r),s=[],c=e;if(((i=(o=l==null?void 0:l.geometry)==null?void 0:o.coordinates)==null?void 0:i.length)===1){s.push(t.id);const u=l==null?void 0:l.geometry.coordinates.map(h=>{var d;return((d=l==null?void 0:l.geometry)==null?void 0:d.type)==="MultiPolygon"?h[0].reduce(PolygonUtils.deletePolygonLastPoint,[]):h.reduce(PolygonUtils.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(n){console.error(n)}}static composePointList(e,t){let o=0,i=0,n=Number.MAX_VALUE;return e.forEach((r,l)=>{t.forEach((s,c)=>{const u=LineToolUtils.default.calcDistance(r,s);u<n&&(o=l+1,i=c+1,n=u)})}),[...e.slice(0,o),...t.slice(i,t.length),...t.slice(0,i),...e.slice(o,e.length)]}static composeSegmentPolygonList(e){var t,o;const i=[];for(let n=0;n<e.length;n++)for(let r=0;r<e.length;r++){const l=(t=e[n])==null?void 0:t.pointList,s=(o=e[r])==null?void 0:o.pointList;n!==r&&l&&s&&PolygonUtils.isPointListInPolygon(s,l)&&(e[n].pointList=PolygonUtils.composePointList(l,s),i.unshift(r))}return i.forEach(n=>{e.splice(n,1)}),e}}module.exports=PolygonUtils;
@@ -1 +1 @@
1
- import{createBase64WorkerFactory as b}from"./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js";var d=b("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwp2YXIgd29ya2VyX2NvZGU9ZnVuY3Rpb24oeCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHAodCl7Y29uc3QgZT0tNyxpPTMsbz1pLWU7cmV0dXJuIHQ8ZSYmKHQ9ZSksdD5pJiYodD1pKSxNYXRoLmZsb29yKCh0LWUpL28qMjU1KX1mdW5jdGlvbiBoKCl7bGV0IHQ7Y29uc3QgZT1uZXcgQXJyYXkoMjU2KS5maWxsKCIiKS5tYXAoKCk9Pm5ldyBBcnJheSgzKS5maWxsKCIiKSk7Zm9yKGxldCBpPTA7aTwyMDtpKyspe2Zvcih0PTA7dDwzMjt0KyspZVt0XVswXT0xMjgrNCp0LGVbdF1bMV09MCxlW3RdWzJdPTA7Zm9yKGVbMzJdWzBdPTI1NSxlWzMyXVsxXT0wLGVbMzJdWzJdPTAsdD0wO3Q8NjM7dCsrKWVbMzMrdF1bMF09MjU1LGVbMzMrdF1bMV09NCs0KnQsZVszMyt0XVsyXT0wO2ZvcihlWzk2XVswXT0yNTQsZVs5Nl1bMV09MjU1LGVbOTZdWzJdPTIsdD0wO3Q8NjI7dCsrKWVbOTcrdF1bMF09MjUwLTQqdCxlWzk3K3RdWzFdPTI1NSxlWzk3K3RdWzJdPTYrNCp0O2ZvcihlWzE1OV1bMF09MSxlWzE1OV1bMV09MjU1LGVbMTU5XVsyXT0yNTQsdD0wO3Q8NjQ7dCsrKWVbMTYwK3RdWzBdPTAsZVsxNjArdF1bMV09MjUyLXQqNCxlWzE2MCt0XVsyXT0yNTU7Zm9yKHQ9MDt0PDMyO3QrKyllWzIyNCt0XVswXT0wLGVbMjI0K3RdWzFdPTAsZVsyMjQrdF1bMl09MjUyLTQqdH1yZXR1cm4gZX1jb25zdCBDPWgoKTtmdW5jdGlvbiBkKHQsZSxpPTApe2xldCBvPTAscyxhLHIsZjtlPVsuLi5lXSxpPT09MSYmKGU9Y3JlYXRlU21vb3RoQ3VydmVQb2ludHMoZS5yZWR1Y2UoKGMsdSk9PlsuLi5jLHUueCx1LnldLFtdKSwuNSwhMCxTRUdNRU5UX05VTUJFUikpLFtyXT1lO2NvbnN0IG49ZS5sZW5ndGg7Zm9yKHM9MTtzPD1uO3MrKylmPWVbcyVuXSx0Lng+TWF0aC5taW4oci54LGYueCkmJnQueDw9TWF0aC5tYXgoci54LGYueCkmJnQueTw9TWF0aC5tYXgoci55LGYueSkmJnIueCE9PWYueCYmKGE9KHQueC1yLngpKihmLnktci55KS8oZi54LXIueCkrci55LChyLnk9PT1mLnl8fHQueTw9YSkmJm8rKykscj1mO3JldHVybiBvJTIhPTB9ZnVuY3Rpb24gYih7ek1pbjp0LHpNYXg6ZSxwb2x5Z29uUG9pbnRMaXN0OmksYXR0cmlidXRlOm8seDpzLHk6YSx6OnIsY29sb3JMaXN0OmYsdmFsaWQ6bn0pe2lmKGQoe3g6cyx5OmF9LGkpJiZyPj10JiZyPD1lKXJldHVybiBuPT09ITE/WzEsMTAzLzI1NSwxMDIvMjU1XTpmW29dP2Zbb10ucmdiYS5zbGljZSgwLDMpLm1hcCh1PT51LzI1NSk6WzEsMCwwXX1yZXR1cm4gb25tZXNzYWdlPWZ1bmN0aW9uKGUpe2NvbnN0e3Bvc2l0aW9uOmksY29sb3I6byxjdWJvaWRMaXN0OnMsY29sb3JMaXN0OmEsaGlnaGxpZ2h0SW5kZXg6cn09ZS5kYXRhO2xldCBmPTA7Zm9yKGxldCBuPTA7bjxpLmxlbmd0aDtuKz0zKXtjb25zdCBjPWlbbl0sdT1pW24rMV0sZz1pW24rMl0sbT1zLm1hcChsPT5iKHtwb2x5Z29uUG9pbnRMaXN0OmwucG9seWdvblBvaW50TGlzdCx6TWluOmwuek1pbix6TWF4Omwuek1heCx4OmMseTp1LHo6ZyxhdHRyaWJ1dGU6bC5hdHRyaWJ1dGUsY29sb3JMaXN0OmEsdmFsaWQ6bC52YWxpZH0pKS5maWx0ZXIobD0+bCkucG9wKCk7aWYobSl7ZisrO2NvbnN0W2wseSxNXT1tO29bbl09bCxvW24rMV09eSxvW24rMl09TX1lbHNle2NvbnN0IGw9TWF0aC5mbG9vcihuLzMpO2lmKHImJnJbbF09PT0xKW9bbl09MCxvW24rMV09MCxvW24rMl09MDtlbHNle2NvbnN0IHk9cChnKSxNPUNbeV0sW3csSSxfXT1NO29bbl09dy8yNTUsb1tuKzFdPUkvMjU1LG9bbisyXT1fLzI1NX19fXBvc3RNZXNzYWdlKHtwb2ludHM6aSxjb2xvcjpvLG51bTpmfSl9LHguaXNJblBvbHlnb249ZCxPYmplY3QuZGVmaW5lUHJvcGVydHkoeCwiX19lc01vZHVsZSIse3ZhbHVlOiEwfSkseH0oe30pOwoK",null,!1);export{d as default};
1
+ import{createBase64WorkerFactory as b}from"./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js";var l=b("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwp2YXIgd29ya2VyX2NvZGU9ZnVuY3Rpb24ocCl7InVzZSBzdHJpY3QiO2NvbnN0IHY9Wy0xLC0xLC0xXTtsZXQgST0hMTtmdW5jdGlvbiBCKGUpe2NvbnN0IHQ9LTcsbz0zLG49by10O3JldHVybiBlPHQmJihlPXQpLGU+byYmKGU9byksTWF0aC5mbG9vcigoZS10KS9uKjI1NSl9ZnVuY3Rpb24gRSgpe2xldCBlO2NvbnN0IHQ9bmV3IEFycmF5KDI1NikuZmlsbCgiIikubWFwKCgpPT5uZXcgQXJyYXkoMykuZmlsbCgiIikpO2ZvcihsZXQgbz0wO288MjA7bysrKXtmb3IoZT0wO2U8MzI7ZSsrKXRbZV1bMF09MTI4KzQqZSx0W2VdWzFdPTAsdFtlXVsyXT0wO2Zvcih0WzMyXVswXT0yNTUsdFszMl1bMV09MCx0WzMyXVsyXT0wLGU9MDtlPDYzO2UrKyl0WzMzK2VdWzBdPTI1NSx0WzMzK2VdWzFdPTQrNCplLHRbMzMrZV1bMl09MDtmb3IodFs5Nl1bMF09MjU0LHRbOTZdWzFdPTI1NSx0Wzk2XVsyXT0yLGU9MDtlPDYyO2UrKyl0Wzk3K2VdWzBdPTI1MC00KmUsdFs5NytlXVsxXT0yNTUsdFs5NytlXVsyXT02KzQqZTtmb3IodFsxNTldWzBdPTEsdFsxNTldWzFdPTI1NSx0WzE1OV1bMl09MjU0LGU9MDtlPDY0O2UrKyl0WzE2MCtlXVswXT0wLHRbMTYwK2VdWzFdPTI1Mi1lKjQsdFsxNjArZV1bMl09MjU1O2ZvcihlPTA7ZTwzMjtlKyspdFsyMjQrZV1bMF09MCx0WzIyNCtlXVsxXT0wLHRbMjI0K2VdWzJdPTI1Mi00KmV9cmV0dXJuIHR9Y29uc3QgUj1FKCk7ZnVuY3Rpb24gaChlLHQsbz0wKXtsZXQgbj0wLGEseCxpLGw7dD1bLi4udF0sbz09PTEmJih0PWNyZWF0ZVNtb290aEN1cnZlUG9pbnRzKHQucmVkdWNlKCh5LGMpPT5bLi4ueSxjLngsYy55XSxbXSksLjUsITAsU0VHTUVOVF9OVU1CRVIpKSxbaV09dDtjb25zdCB1PXQubGVuZ3RoO2ZvcihhPTE7YTw9dTthKyspbD10W2EldV0sZS54Pk1hdGgubWluKGkueCxsLngpJiZlLng8PU1hdGgubWF4KGkueCxsLngpJiZlLnk8PU1hdGgubWF4KGkueSxsLnkpJiZpLnghPT1sLngmJih4PShlLngtaS54KSoobC55LWkueSkvKGwueC1pLngpK2kueSwoaS55PT09bC55fHxlLnk8PXgpJiZuKyspLGk9bDtyZXR1cm4gbiUyIT0wfWZ1bmN0aW9uIE8oe3pNaW46ZSx6TWF4OnQscG9seWdvblBvaW50TGlzdDpvLGF0dHJpYnV0ZTpuLHg6YSx5OngsejppLGNvbG9yTGlzdDpsLHZhbGlkOnV9KXtpZihoKHt4OmEseTp4fSxvKSYmaT49ZSYmaTw9dClyZXR1cm4gdT09PSExP1sxLDEwMy8yNTUsMTAyLzI1NV06bFtuXT9sW25dLnJnYmEuc2xpY2UoMCwzKS5tYXAoYz0+Yy8yNTUpOlsxLDAsMF19ZnVuY3Rpb24gbShlKXtjb25zdCB0PUIoZSksbz1SW3RdLFtuLGEseF09bztyZXR1cm5bbi8yNTUsYS8yNTUseC8yNTVdfXJldHVybiBvbm1lc3NhZ2U9ZnVuY3Rpb24odCl7Y29uc3R7cG9zaXRpb246byxjb2xvcjpuLGN1Ym9pZExpc3Q6YSxjb2xvckxpc3Q6eCxoaWdobGlnaHRJbmRleDppfT10LmRhdGE7bGV0e21vZGlmaWVkQm94SWRzOmw9W10scmVzZXRBcmVhczp1PVtdfT10LmRhdGEseT0wO2Z1bmN0aW9uIGMoKXt5Kz0xfWlmKCFvKXJldHVybjtjb25zdCBfPSEhKGk9PW51bGw/dm9pZCAwOmkubGVuZ3RoKTsoX3x8SSkmJihsPVtdLHU9W10pO2NvbnN0IHc9bC5sZW5ndGg/YS5maWx0ZXIocj0+bC5pbmNsdWRlcyhyLmlkKSk6YTtmb3IobGV0IHI9MDtyPG8ubGVuZ3RoO3IrPTMpe2NvbnN0IEM9b1tyXSxMPW9bcisxXSxkPW9bcisyXTtsZXQgZztpZih1Lmxlbmd0aD09PTEmJiFsLmxlbmd0aCloKHt4OkMseTpMfSx1WzBdKT9nPW0oZCk6Zz12O2Vsc2UgaWYodS5sZW5ndGh8fGwubGVuZ3RoKXtsZXQgcz0hMTt3LnNvbWUoZj0+e2NvbnN0IE09Tyh7cG9seWdvblBvaW50TGlzdDpmLnBvbHlnb25Qb2ludExpc3Qsek1pbjpmLnpNaW4sek1heDpmLnpNYXgseDpDLHk6TCx6OmQsYXR0cmlidXRlOmYuYXR0cmlidXRlLGNvbG9yTGlzdDp4LHZhbGlkOmYudmFsaWR9KTtyZXR1cm4gTT8oYygpLGc9TSxzPSEwLCEwKTohMX0pLCFzJiZ1Lmxlbmd0aCYmKHM9dS5zb21lKGY9Pmgoe3g6Qyx5Okx9LGYpPyhnPW0oZCksITApOiExKSksIXMmJiFfJiYoST9nPW0oZCk6Zz12KX1lbHNlIHcuc29tZShzPT57Y29uc3QgZj1PKHtwb2x5Z29uUG9pbnRMaXN0OnMucG9seWdvblBvaW50TGlzdCx6TWluOnMuek1pbix6TWF4OnMuek1heCx4OkMseTpMLHo6ZCxhdHRyaWJ1dGU6cy5hdHRyaWJ1dGUsY29sb3JMaXN0OngsdmFsaWQ6cy52YWxpZH0pO3JldHVybiBmPyhjKCksZz1mLCEwKTohMX0pO2NvbnN0IEE9cz0+e2NvbnN0IGY9TWF0aC5mbG9vcihzLzMpO3JldHVybiBpJiZpW2ZdPT09MX07aWYoZylpZihnWzBdPT09dlswXSYmQShyKSluW3JdPTAsbltyKzFdPTAsbltyKzJdPTA7ZWxzZXtjb25zdFtzLGYsTV09ZztuW3JdPXMsbltyKzFdPWYsbltyKzJdPU19ZWxzZSBpZihBKHIpKW5bcl09MCxuW3IrMV09MCxuW3IrMl09MDtlbHNle2NvbnN0W3MsZixNXT1tKGQpO25bcl09cyxuW3IrMV09ZixuW3IrMl09TX19ST1fLHBvc3RNZXNzYWdlKHtwb2ludHM6byxjb2xvcjpuLG51bTp5fSl9LHAuaXNJblBvbHlnb249aCxPYmplY3QuZGVmaW5lUHJvcGVydHkocCwiX19lc01vZHVsZSIse3ZhbHVlOiEwfSkscH0oe30pOwoK",null,!1);export{l as default};
@@ -1 +1 @@
1
- var a;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(a||(a={}));var n=a;export{n as default};
1
+ var a;(function(t){t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.O=79]="O",t[t.L=76]="L",t[t.R=82]="R",t[t.Z=90]="Z",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.S=83]="S",t[t.Q=81]="Q",t[t.P=80]="P",t[t.One=49]="One",t[t.Two=50]="Two",t[t.Three=51]="Three",t[t.Delete=46]="Delete",t[t.F11=122]="F11",t[t.Space=32]="Space",t[t.Esc=27]="Esc",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Enter=13]="Enter",t[t.Ctrl=17]="Ctrl",t[t.Alt=18]="Alt",t[t.Shift=16]="Shift",t[t.Tab=9]="Tab",t[t.BackSpace=8]="BackSpace",t[t.Minus=189]="Minus",t[t.Equal=187]="Equal"})(a||(a={}));var n=a;export{n as default};