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

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 +2 -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 +19 -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 +4 -0
  23. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
  24. package/dist/types/utils/tool/RectUtils.d.ts +4 -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 +2 -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,2 @@
1
- import B from"lodash";import{distance as N}from"@turf/turf";import O from"../../utils/MathUtils.js";import w from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import{EDragStatus as y,ESortDirection as U,DEFAULT_TEXT_SHADOW as T}from"../../constant/annotation.js";import{EDragTarget as D,EOperationMode as V}from"../../constant/tool.js";import S from"../../constant/keyCode.js";import k from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import E from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import L from"../../utils/tool/DrawUtils.js";import K from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as P}from"../../utils/tool/polygonTool.js";import $ from"../../utils/uuid.js";import{BasicToolOperation as F}from"./basicToolOperation.js";import X from"./textAttributeClass.js";import Y from"./Selection.js";var G=Object.defineProperty,J=Object.defineProperties,q=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,j=(v,t,e)=>t in v?G(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,f=(v,t)=>{for(var e in t||(t={}))Q.call(t,e)&&j(v,e,t[e]);if(H)for(var e of H(t))tt.call(t,e)&&j(v,e,t[e]);return v},x=(v,t)=>J(v,q(t));const C=6;class W extends F{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=C,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&I.isInRect(s,a,r,this.zoom))return a.id}const i=o.filter(a=>I.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(p.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.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 Y(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.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]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,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;p.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",p.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(s=>s.id===this.selectedRectID?x(f({},s),{textAttribute:e}):s),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?w.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),C+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:s}=this,r=I.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const a=r[i],{length:n}=O.getFootOfPerpendicular(o,a.begin,a.end);n<C+10&&(e=i)}return e}getTextIconSvg(t=""){return p.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=D.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=D.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}}if(this.selection.isIdSelected(s)&&!this.drawingRect){const r=D.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=y.Start}}}appendOffsetRect(t,e){return x(f({},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(...I.getRectPointList(this.appendOffsetRect(o,e))),[]);return O.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 I.isRectNotInPolygon(n,P(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=>!I.isInRect(d,c))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=B.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>x(f({},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=>x(f({},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=y.Move,this.dragInfo.dragTarget===D.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const a=I.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 D.Point:{let g=n,b=c,u=d,m=h;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?n+d:n+i.x,b=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-d),m=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,b=h-i.y<0?c+h:c+i.y,u=Math.abs(d+i.x),m=Math.abs(h-i.y);break}case 2:{g=d+i.x>0?n:n+d+i.x,b=h+i.y>0?c:c+h+i.y,u=Math.abs(d+i.x),m=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,b=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-d),m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}l=x(f({},l),{x:g,y:b,width:u,height:m})}break;case D.Line:{let g=n,b=c,u=d,m=h;switch(this.hoverRectEdgeIndex){case 0:{b=h-i.y<0?c+h:c+i.y,m=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:{b=h+i.y>0?c:c+h+i.y,m=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=x(f({},l),{x:g,y:b,width:u,height:m});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&&I.isRectNotInPolygon(l,P(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,m=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<b-.01||l.width>g+u-l.x+.01||l.height>b+m-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<b&&(l.y=b),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case D.Point:case D.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>b+m-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?I.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=w.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&&I.isRectNotInPolygon(x(f({},this.drawingRect),{x:n,y:c,width:d,height:h}),P(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=x(f({},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?x(f({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),r=w.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=x(f({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:$(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",k.getMessagesByLocale(A.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=p.getTextAttribute(this.rectList.filter(i=>R.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=f({},r),this.firstCurrentPos=f({},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",k.getMessagesByLocale(A.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.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=y.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,x(f({},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)&&N((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=R.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",f({},this.selectedRect))}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===y.Move){this.dragInfo=void 0,this.dragStatus=y.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=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case S.Ctrl:this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case S.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case S.Z:this.setIsHidden(!this.isHidden),this.render();break;case S.Delete:this.deleteSelectedRect();break;case S.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=U.ascend;t.shiftKey&&(s=U.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const a=E.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>E.inViewPort({x:c.x,y:c.y},a));const n=R.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=p.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case S.Ctrl:this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let s,r;this.drawingRect&&this.firstClickCoord&&(s=I.getRectUnderZoom(this.drawingRect,1/e),r=w.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=I.getRectUnderZoom(s,this.zoom),this.firstClickCoord=w.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=w.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 X({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=I.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=C+6:s=C,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 b="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(b=`${t.order}`),t.label&&this.hasMarkerConfig&&(b=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${K.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(b=`${b} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=w.changeRectByZoom(t,s?e:this.zoom,this.currentPos);d||L.drawText(this.canvas,{x:u.x,y:u.y-6},b,x(f({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},T),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&L.drawHighlightFlag({canvas:this.canvas,color:h,position:{x:u.x-5,y:u.y-16}});const m=(a=(i=this.style)==null?void 0:i.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&L.drawRectWithFill(this.canvas,u,{color:l}),L.drawRect(this.canvas,u,{color:h,thickness:m,hiddenText:!0}),n.restore();let M=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(M=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const _=M.length*7;if(d||L.drawText(this.canvas,{x:u.x+u.width-_,y:u.y+u.height+15},M,f({color:g,font:"normal normal 600 14px Arial"},T)),!d&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,u.width-_);L.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+z},t.textAttribute,f({color:g,font:"italic normal 900 14px Arial",textMaxWidth:Z},T))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=R.getRenderResultList(this.rectList,R.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,w.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,w.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,w.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)?x(f({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=x(f({},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=y.Wait,this.setSelectedRectID(void 0),this.setOperationMode(V.General)}clearResult(t=!0){const e=this.rectList.filter(s=>s.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",k.getMessagesByLocale(A.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",k.getMessagesByLocale(A.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())}}export{W as RectOperation,W as default};
1
+ import $ from"lodash";import{distance as F}from"@turf/turf";import H from"../../utils/MathUtils.js";import y from"../../utils/tool/AxisUtils.js";import v from"../../utils/tool/RectUtils.js";import z from"../../utils/tool/TagUtils.js";import{EDragStatus as S,ESortDirection as j,DEFAULT_TEXT_SHADOW as O}from"../../constant/annotation.js";import{EDragTarget as D,EOperationMode as X}from"../../constant/tool.js";import L from"../../constant/keyCode.js";import T from"../../locales/index.js";import{EMessage as M}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import W from"../../utils/tool/CanvasUtils.js";import f from"../../utils/tool/CommonToolUtils.js";import A from"../../utils/tool/DrawUtils.js";import Y from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as U}from"../../utils/tool/polygonTool.js";import G from"../../utils/uuid.js";import{BasicToolOperation as J}from"./basicToolOperation.js";import q from"./textAttributeClass.js";import Q from"./Selection.js";var tt=Object.defineProperty,et=Object.defineProperties,it=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,B=(w,t,e)=>t in w?tt(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,g=(w,t)=>{for(var e in t||(t={}))st.call(t,e)&&B(w,e,t[e]);if(Z)for(var e of Z(t))rt.call(t,e)&&B(w,e,t[e]);return w},R=(w,t)=>et(w,it(t));const C=6;class N extends J{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 i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=C,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:c}=this;if(c&&v.isInRect(i,c,r,this.zoom))return c.id}const s=o.filter(c=>v.isInRect(i,c,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(n=>({size:n.width*n.height,id:n.id})).sort((n,h)=>n.size-h.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.setDefaultSubAttribute=()=>{var e,i,r,o;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=z.getDefaultResultByConfig((o=(r=this.config)==null?void 0:r.subAttributeList)!=null?o:[]);this.setRectList(this.rectList.map(c=>{var n;if(c.id===this.selectedRectID){const h=(n=c==null?void 0:c.subAttribute)!=null?n:s;return R(g({},c),{subAttribute:h})}return c}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(p.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=f.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.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Q(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=f.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=f.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get 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,i]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=f.getRenderResultList(t,f.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;p.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",p.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?R(g({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const o=(r=i==null?void 0:i.subAttribute)!=null?r:{};return R(g({},i),{subAttribute:R(g({},o),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?y.returnClosePointIndex(this.getCoordinateUnderZoom(t),v.getRectPointList(this.selectedRect,this.zoom),C+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=v.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const c=r[s],{length:n}=H.getFootOfPerpendicular(o,c.begin,c.end);n<C+10&&(e=s)}return e}getTextIconSvg(t=""){return p.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),i=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=D.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=S.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=D.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=S.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=D.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=S.Start}}}appendOffsetRect(t,e){return R(g({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,o)=>r.concat(...v.getRectPointList(this.appendOffsetRect(o,e))),[]);return H.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,o,s;if(this.drawOutSideTarget!==!1)return!1;const c=this.getRectsBoundaries(t,e),n={y:c.top,x:c.left,height:c.bottom-c.top,width:c.right-c.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return v.isRectNotInPolygon(n,U(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const h=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(s=this.imgNode)==null?void 0:s.width};if(h)return[{x:c.left,y:c.top},{x:c.right,y:c.bottom}].some(d=>!v.isInRect(d,h))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=$.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>R(g({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=i.find(s=>s.id===r.id);return o||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>R(g({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=S.Move,this.dragInfo.dragTarget===D.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const c=v.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:h,width:d,height:a}=c;let l=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case D.Point:{let u=n,x=h,m=d,b=a;switch(this.hoverRectPointIndex){case 0:{u=d-s.x<0?n+d:n+s.x,x=a-s.y<0?h+a:h+s.y,m=Math.abs(s.x-d),b=Math.abs(s.y-a);break}case 1:{u=d+s.x>0?n:n+d+s.x,x=a-s.y<0?h+a:h+s.y,m=Math.abs(d+s.x),b=Math.abs(a-s.y);break}case 2:{u=d+s.x>0?n:n+d+s.x,x=a+s.y>0?h:h+a+s.y,m=Math.abs(d+s.x),b=a+s.y>0?a+s.y:Math.abs(a+s.y);break}case 3:{u=d-s.x<0?n+d:n+s.x,x=a+s.y>0?h:h+a+s.y,m=Math.abs(s.x-d),b=a+s.y>0?a+s.y:Math.abs(a+s.y);break}default:return}l=R(g({},l),{x:u,y:x,width:m,height:b})}break;case D.Line:{let u=n,x=h,m=d,b=a;switch(this.hoverRectEdgeIndex){case 0:{x=a-s.y<0?h+a:h+s.y,b=Math.abs(s.y-a);break}case 1:{u=d+s.x>0?n:n+d+s.x,m=Math.abs(d+s.x);break}case 2:{x=a+s.y>0?h:h+a+s.y,b=a+s.y>0?a+s.y:Math.abs(a+s.y);break}case 3:{u=d-s.x<0?n+d:n+s.x,m=Math.abs(s.x-d);break}default:return}l=R(g({},l),{x:u,y:x,width:m,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&v.isRectNotInPolygon(l,U(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,x=this.basicResult.y*this.zoom,m=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(l.x<u-.01||l.y<x-.01||l.width>u+m-l.x+.01||l.height>x+b-l.y+.01)return;if(l.x<u&&(l.x=u),l.y<x&&(l.y=x),l.width>u+m-l.x)switch(this.dragInfo.dragTarget){case D.Point:case D.Line:s.x>0&&s.y>0&&(l.width=u+m-l.x);break;default:return}if(l.height>x+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(u=>u.id===l.id?v.getRectUnderZoom(l,1/this.zoom):u)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=y.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 h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const s=this.getHoverRectID(t),c=this.hoverRectID;if(this.hoverRectID=s,s!==c&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:n,y:h}=this.firstClickCoord,{width:d,height:a}=this.drawingRect;if(d=Math.abs(n-o.x),a=Math.abs(h-o.y),o.x<n&&(n=o.x),o.y<h&&(h=o.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&v.isRectNotInPolygon(R(g({},this.drawingRect),{x:n,y:h,width:d,height:a}),U(this.basicResult.pointList,this.zoom)))return;o.x<0&&(d=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(a=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(n+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-n)),h+a>this.imgInfo.height&&(a=Math.abs(this.imgInfo.height-h)))}this.drawingRect=R(g({},this.drawingRect),{x:n,y:h,width:d,height:a}),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?R(g({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){var i,r,o,s;if(!this.imgInfo)return;const c=this.getCoordinateUnderZoom(t),n=y.changeDrawOutsideTarget(c,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(n.x<0&&(n.x=0),n.y<0&&(n.y=0)),this.drawingRect=R(g({},n),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:G(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const h=f.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)this.drawingRect&&(this.drawingRect=R(g({},this.drawingRect),{label:h.label})),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",T.getMessagesByLocale(M.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let h="";h=p.getTextAttribute(this.rectList.filter(d=>f.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=R(g({},this.drawingRect),{textAttribute:h}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const h=z.getDefaultResultByConfig((s=(o=this.config)==null?void 0:o.subAttributeList)!=null?s:[]);this.drawingRect=R(g({},this.drawingRect),{subAttribute:h})}if(Object.assign(this.drawingRect,{order:f.getMaxOrder(this.rectList.filter(h=>f.isSameSourceID(h.sourceID,e)))+1}),this.firstClickCoord=g({},n),this.firstCurrentPos=g({},this.currentPos),this.dataInjectionAtCreation){const h=this.dataInjectionAtCreation(this.drawingRect);h&&Object.assign(this.drawingRect,h)}}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",T.getMessagesByLocale(M.RectErrorSizeNotice,this.lang)),this.clearDrawingStatus(),this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!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:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,R(g({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,o,s;const c=this.getHoverRectID(t),n=this.rectList.find(h=>h.id===c);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&F((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(c,t.ctrlKey),n&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(c),this.setDefaultAttribute(n.attribute)),this.hoverRectID="",(n==null?void 0:n.label)&&this.hasMarkerConfig){const h=f.getCurrentMarkerIndex(n.label,this.config.markerList);h>=0&&(this.setMarkerIndex(h),this.emit("markIndexChange"))}((o=this.config)==null?void 0:o.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",g({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===S.Move){this.dragInfo=void 0,this.dragStatus=S.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=f.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(!f.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case L.Ctrl:this.drawingRect&&(this.drawingRect=R(g({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case L.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case L.Z:this.setIsHidden(!this.isHidden),this.render();break;case L.Delete:this.deleteSelectedRect(t);break;case L.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=j.ascend;t.shiftKey&&(i=j.descend);const[r,o]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];o&&(s=[...s,...o]);const c=W.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(h=>W.inViewPort({x:h.x,y:h.y},c));const n=f.getNextSelectedRectID(s,i,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const i=p.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case L.Ctrl:this.drawingRect&&(this.drawingRect=R(g({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=v.getRectUnderZoom(this.drawingRect,1/e),r=y.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=v.getRectUnderZoom(i,this.zoom),this.firstClickCoord=y.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,o=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,o=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:o,height:s,attribute:c,valid:n}=e,h=o*this.zoom*.6,d=y.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),a=this.getColor(c),l=n?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new q({width:h,container:this.container,icon:this.getTextIconSvg(c),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+u,color:l,width:h})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=v.getRectPointList(t),o=r.length,s=this.getColor(t.attribute);r.forEach((c,n)=>{var h,d;if(e.save(),e.moveTo(c.x,c.y),e.beginPath(),this.hoverRectPointIndex===n?i=C+6:i=C,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(c.x*this.zoom+this.currentPos.x,c.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const a=this.getColor(t.attribute),l=t.valid===!1?(h=a==null?void 0:a.invalid)==null?void 0:h.stroke:(d=a==null?void 0:a.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,i=!1){var r,o,s,c,n,h;if(this.ctx&&t){const{ctx:d,style:a}=this,{hiddenText:l=!1}=a;d.save();const{strokeColor:u,fillColor:x,textColor:m}=this.getRenderStyle(t);d.font="lighter 14px Arial";let b="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(b=`${t.order}`),t.label&&this.hasMarkerConfig&&(b=`${f.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${Y.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(b=`${b} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`,(t==null?void 0:t.subAttribute)&&((s=this.config)==null?void 0:s.secondaryAttributeConfigurable)&&((c=this.config)==null?void 0:c.subAttributeList)&&z.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(k=>{b+=`
2
+ ${k.keyName}: ${k.value.join("\u3001")}`}));const I=y.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||A.drawText(this.canvas,{x:I.x,y:I.y-6},b,R(g({color:u,font:"normal normal 900 14px SourceHanSansCN-Regular"},O),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&A.drawHighlightFlag({canvas:this.canvas,color:u,position:{x:I.x-5,y:I.y-16}});const V=(h=(n=this.style)==null?void 0:n.width)!=null?h:2,K=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||K||t.id===this.selectedRectID||this.isMultiMoveMode)&&A.drawRectWithFill(this.canvas,I,{color:x}),A.drawRect(this.canvas,I,{color:u,thickness:V,hiddenText:!0,lineDash:t.lineDash}),d.restore();let _=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(_=`${Math.round(t.width/this.zoom)} * ${Math.round(I.height/this.zoom)}`);const E=_.length*7;if(l||A.drawText(this.canvas,{x:I.x+I.width-E,y:I.y+I.height+15},_,g({color:m,font:"normal normal 600 14px Arial"},O)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const P=0,k=Math.max(20,I.width-E);A.drawText(this.canvas,{x:I.x,y:I.y+I.height+20+P},t.textAttribute,g({color:m,font:"italic normal 900 14px Arial",textMaxWidth:k},O))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,y.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,y.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,y.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(i=>this.selection.isIdSelected(i.id)?R(g({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=R(g({},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=S.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(X.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",T.getMessagesByLocale(M.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",T.getMessagesByLocale(M.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())}}export{N as RectOperation,N as default};
@@ -0,0 +1 @@
1
+ var _=Object.defineProperty,d=Object.defineProperties,O=Object.getOwnPropertyDescriptors,p=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,e=(o,n,s)=>n in o?_(o,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[n]=s,l=(o,n)=>{for(var s in n||(n={}))a.call(n,s)&&e(o,s,n[s]);if(p)for(var s of p(n))v.call(n,s)&&e(o,s,n[s]);return o},I=(o,n)=>d(o,O(n));const m=(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},T=(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),b=(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,h=o.x<=n.x&&s>=i&&o.y<=n.y&&r>=y;return x||h},g=(o,n,s,r)=>{const i=T(o,n);if(i.length>0){const x=i.length>=3?i:m(i,n),h=x[0].position||0,f={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:w}=f[h](x[0],s,r);return{width:s,height:r,x:P,y:w}}return b(o,n)?{width:s,height:r,x:(n.x+n.width-s)/2,y:(n.y+n.height-r)/2}:I(l({},o),{noChange:!0})};export{g as default};
package/es/index.js CHANGED
@@ -1 +1 @@
1
- export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";export{default as SegmentByRect}from"./core/toolOperation/segmentByRect.js";export{default as SegmentBySAM}from"./core/toolOperation/segmentBySAM.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as CanvasUtils}from"./utils/tool/CanvasUtils.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{default as CursorTextClass}from"./core/toolOperation/cursorTextClass.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
1
+ export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";export{default as SegmentByRect}from"./core/toolOperation/segmentByRect.js";export{default as SegmentBySAM}from"./core/toolOperation/segmentBySAM.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as CanvasUtils}from"./utils/tool/CanvasUtils.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{default as CursorTextClass}from"./core/toolOperation/cursorTextClass.js";export{EMessage}from"./locales/constants.js";export{default as MESSAGE_CN}from"./locales/zh_CN/message.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,omniCamera11VTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
@@ -1 +1 @@
1
- import{polygon as A,difference as B,union as O}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import N from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as p}from"../../constant/tool.js";import D from"./AxisUtils.js";import L from"../MathUtils.js";import b from"./LineToolUtils.js";var z=Object.defineProperty,_=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,j=(M,t,e)=>t in M?z(M,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):M[t]=e,S=(M,t)=>{for(var e in t||(t={}))R.call(t,e)&&j(M,e,t[e]);if(_)for(var e of _(t))T.call(t,e)&&j(M,e,t[e]);return M};class h{static getHoverPolygonID(t,e,n=3,i=y.Line){let o="",r=Infinity;const l=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&l.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<r&&(o=s.id,r=u)})}),o}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,o,r,l)=>{const s=l[(r+1)%e];return i+o.x*s.y-s.x*o.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,o,r,l,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,d)=>[...u,d.x,d.y],[]),.5,!0,20)),[l]=e;const c=e.length;for(o=1;o<=c;o++)s=e[o%c],t.x>Math.min(l.x,s.x)&&t.x<=Math.max(l.x,s.x)&&t.y<=Math.max(l.y,s.y)&&l.x!==s.x&&(r=(t.x-l.x)*(s.y-l.y)/(s.x-l.x)+l.y,(l.y===s.y||t.y<=r)&&i++),l=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=p){return this.createSmoothCurvePoints(t.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!1,e).map((i,o)=>{var r;const l=o/(p+1),s=Math.floor(l),c=(r=t[s])!=null?r:{};return S(s===l?S({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=p){if(t.length<4)return t;const o=[],r=t.slice(0);let l,s,c,u,d,m,v,E,P,I,a,g,f;for(n?(r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.push(t[0]),r.push(t[1])):(r.unshift(t[1]),r.unshift(t[0]),r.push(t[t.length-2]),r.push(t[t.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*e,u=(r[f+4]-r[f-0])*e,d=(r[f+3]-r[f-1])*e,m=(r[f+5]-r[f+1])*e,g=0;g<=i;g++)a=g/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,E=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,I=Math.pow(a,3)-Math.pow(a,2),l=v*r[f]+E*r[f+2]+P*c+I*u,s=v*r[f+1]+E*r[f+3]+P*d+I*m,o.push(l),o.push(s);const C=[];for(let x=0;x<o.length-1;x+=2)C.push({x:o[x],y:o[x+1]});if(n)for(let x=0;x<i+1;x++){const w=C.shift();C.push(w)}return C}static getPolygonByID(t,e){return t.find(n=>n.id===e)}static getPolygonByIDs(t,e){return e&&(e==null?void 0:e.length)>0?t.filter(n=>e.includes(n.id)):[]}static getHoverEdgeIndex(t,e,n=y.Line,i=3){let o=[...e];n===y.Curve?o=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,p):n===y.Line&&o.push(o[0]);let r=-1,l=i;for(let s=0;s<o.length-1;s++){const{length:c}=L.getFootOfPerpendicular(t,o[s],o[s+1]);c<l&&(r=s,l=c)}return r===-1?-1:n===y.Curve?Math.floor(r/p):r}static getClosestPoint(t,e,n=y.Line,i=3,o){var r;let l=!1;const s=(r=o==null?void 0:o.isClose)!=null?r:!0;let c="",u=-1,d=Infinity,m=t;const v=20;let E=!1;return e.forEach(P=>{if(!E&&!!P.pointList)switch(n){case y.Line:N.findAllLine(P.pointList,s).forEach((a,g)=>{if(E)return;let{length:f,footPoint:C}=L.getFootOfPerpendicular(t,a.point1,a.point2);const x=L.getLineLength(a.point1,t),w=L.getLineLength(a.point2,t);x<i*2&&(C=a.point1,f=x,E=!0),w<i*2&&(C=a.point2,f=w,E=!0),f<d&&f<i&&(c=P.id,u=g,d=f,m=C,l=!0)});break;case y.Curve:{const I=this.createSmoothCurvePoints(P.pointList.reduce((a,g)=>[...a,g.x,g.y],[]),.5,s,v);for(let a=0;a<I.length-1;a++){const{length:g,footPoint:f}=L.getFootOfPerpendicular(t,I[a],I[a+1]);g<d&&g<i&&(c=P.id,u=Math.floor(a/(v+1)),d=g,m=f,l=!0)}}break}}),{dropFoot:m,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,n=y.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=y.Line){return t.some(i=>!this.isInPolygon(i,e,n))}static getPolygonArea(t){let e=0;for(let n=0,i=t.length;n<i;n++){const o=t[n].x,r=t[n===t.length-1?0:n+1].y,l=t[n===t.length-1?0:n+1].x,s=t[n].y;e+=o*r*.5,e-=l*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,n){let i=1;return t===F.Anticlockwise&&(i=-1),i*=e,L.rotateRectPointList(i,n)}static deletePolygonLastPoint(t,e,n,i){return n===i.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var n,i;try{let o=A([[...h.concatBeginAndEnd(t.map(l=>[l.x,l.y]))]]);return e.forEach(l=>{const s=A([[...h.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=B(o,s);c&&(o=c)}),((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates.map(l=>{var s;return((s=o==null?void 0:o.geometry)==null?void 0:s.type)==="MultiPolygon"?l[0].reduce(h.deletePolygonLastPoint,[]):l.reduce(h.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((d,m)=>{const v=(m+1)%c;return!D.getIsInScope(d,s[v],1)});return u.length<3?l:[...l,u]},[])}catch(o){console.error(o)}}static getPolygonPointList(t,e){const n=e.find(i=>i.id===t);return n&&n.pointList&&n.pointList.length>0?n.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(n=>h.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=h.isPolygonClosewise(e),i=h.isPolygonClosewise(t),o=h.getClosePointDistanceFromPolygon(t[0],e),r=e[o];let l=[...e.slice(0,o),r,...t,t[0],...e.slice(o,e.length)];return n===i&&(l=[...e.slice(0,o),r,t[0],...t.reverse(),...e.slice(o,e.length)]),l}static isPolygonClosewise(t){const e=t.length;let n,i,o,r=0,l;if(e<3)return 0;for(n=0;n<e;n++)i=(n+1)%e,o=(n+2)%e,l=(t[i].x-t[n].x)*(t[o].y-t[i].y),l-=(t[i].y-t[n].y)*(t[o].x-t[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let n=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((o,r)=>{const l=b.calcDistance(t,o);l<n&&(n=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const o=A([[...h.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),r=A([[...h.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),l=O(o,r),s=[],c=t;if(((i=(n=l==null?void 0:l.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=l==null?void 0:l.geometry.coordinates.map(d=>{var m;return((m=l==null?void 0:l.geometry)==null?void 0:m.type)==="MultiPolygon"?d[0].reduce(h.deletePolygonLastPoint,[]):d.reduce(h.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(o){console.error(o)}}static composePointList(t,e){let n=0,i=0,o=Number.MAX_VALUE;return t.forEach((r,l)=>{e.forEach((s,c)=>{const u=b.calcDistance(r,s);u<o&&(n=l+1,i=c+1,o=u)})}),[...t.slice(0,n),...e.slice(i,e.length),...e.slice(0,i),...t.slice(n,t.length)]}static composeSegmentPolygonList(t){var e,n;const i=[];for(let o=0;o<t.length;o++)for(let r=0;r<t.length;r++){const l=(e=t[o])==null?void 0:e.pointList,s=(n=t[r])==null?void 0:n.pointList;o!==r&&l&&s&&h.isPointListInPolygon(s,l)&&(t[o].pointList=h.composePointList(l,s),i.unshift(r))}return i.forEach(o=>{t.splice(o,1)}),t}}export{h as default};
1
+ import{polygon as S,difference as _,union as B}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import N from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as p}from"../../constant/tool.js";import b from"./AxisUtils.js";import L from"../MathUtils.js";import O from"./LineToolUtils.js";var z=Object.defineProperty,j=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,D=(C,t,e)=>t in C?z(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,A=(C,t)=>{for(var e in t||(t={}))R.call(t,e)&&D(C,e,t[e]);if(j)for(var e of j(t))k.call(t,e)&&D(C,e,t[e]);return C};class d{static getHoverPolygonID(t,e,o=3,i=y.Line){let n="",r=Infinity;const l=b.axisArea(t,o);return e.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(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,o=t.reduce((i,n,r,l)=>{const s=l[(r+1)%e];return i+n.x*s.y-s.x*n.y},0);return Math.abs(o)/2}static isInPolygon(t,e,o=y.Line){return e=[...e],o===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(t,e)}static isPointInOrOnPolygon(t,e,o=1e-9){const{x:i,y:n}=t;let r=!1;for(let l=0,s=e.length-1;l<e.length;s=l++){const{x:c,y:u}=e[l],{x:h,y:g}=e[s],P=i<=Math.max(c,h)&&i>=Math.min(c,h)&&n<=Math.max(u,g)&&n>=Math.min(u,g),x=(n-u)*(h-c)-(i-c)*(g-u);if(P&&Math.abs(x)<o)return!0;u>n!=g>n&&i<(h-c)*(n-u)/(g-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(t,e=p){return this.createSmoothCurvePoints(t.reduce((i,n)=>[...i,n.x,n.y],[]),.5,!1,e).map((i,n)=>{var r;const l=n/(p+1),s=Math.floor(l),c=(r=t[s])!=null?r:{};return A(s===l?A({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,o=!1,i=p){if(t.length<4)return t;const n=[],r=t.slice(0);let l,s,c,u,h,g,P,x,v,I,a,m,f;for(o?(r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.unshift(t[t.length-1]),r.unshift(t[t.length-2]),r.push(t[0]),r.push(t[1])):(r.unshift(t[1]),r.unshift(t[0]),r.push(t[t.length-2]),r.push(t[t.length-1])),f=2;f<r.length-4;f+=2)for(c=(r[f+2]-r[f-2])*e,u=(r[f+4]-r[f-0])*e,h=(r[f+3]-r[f-1])*e,g=(r[f+5]-r[f+1])*e,m=0;m<=i;m++)a=m/i,P=2*Math.pow(a,3)-3*Math.pow(a,2)+1,x=-(2*Math.pow(a,3))+3*Math.pow(a,2),v=Math.pow(a,3)-2*Math.pow(a,2)+a,I=Math.pow(a,3)-Math.pow(a,2),l=P*r[f]+x*r[f+2]+v*c+I*u,s=P*r[f+1]+x*r[f+3]+v*h+I*g,n.push(l),n.push(s);const M=[];for(let E=0;E<n.length-1;E+=2)M.push({x:n[E],y:n[E+1]});if(o)for(let E=0;E<i+1;E++){const w=M.shift();M.push(w)}return M}static getPolygonByID(t,e){return t.find(o=>o.id===e)}static getPolygonByIDs(t,e){return e&&(e==null?void 0:e.length)>0?t.filter(o=>e.includes(o.id)):[]}static getHoverEdgeIndex(t,e,o=y.Line,i=5){let n=[...e];o===y.Curve?n=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,p):o===y.Line&&n.push(n[0]);let r=-1,l=i;for(let s=0;s<n.length-1;s++){const{length:c}=L.getFootOfPerpendicular(t,n[s],n[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:o===y.Curve?Math.floor(r/p):r}static getClosestPoint(t,e,o=y.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,g=t;const P=20;let x=!1;return e.forEach(v=>{if(!x&&!!v.pointList)switch(o){case y.Line:N.findAllLine(v.pointList,s).forEach((a,m)=>{if(x)return;let{length:f,footPoint:M}=L.getFootOfPerpendicular(t,a.point1,a.point2);const E=L.getLineLength(a.point1,t),w=L.getLineLength(a.point2,t);E<i*2&&(M=a.point1,f=E,x=!0),w<i*2&&(M=a.point2,f=w,x=!0),f<h&&f<i&&(c=v.id,u=m,h=f,g=M,l=!0)});break;case y.Curve:{const I=this.createSmoothCurvePoints(v.pointList.reduce((a,m)=>[...a,m.x,m.y],[]),.5,s,P);for(let a=0;a<I.length-1;a++){const{length:m,footPoint:f}=L.getFootOfPerpendicular(t,I[a],I[a+1]);m<h&&m<i&&(c=v.id,u=Math.floor(a/(P+1)),h=m,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,o=y.Line){return t.every(i=>this.isInPolygon(i,e,o))}static isPointListOutSidePolygon(t,e,o=y.Line){return t.some(i=>!this.isInPolygon(i,e,o))}static getPolygonArea(t){let e=0;for(let o=0,i=t.length;o<i;o++){const n=t[o].x,r=t[o===t.length-1?0:o+1].y,l=t[o===t.length-1?0:o+1].x,s=t[o].y;e+=n*r*.5,e-=l*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,o){let i=1;return t===F.Anticlockwise&&(i=-1),i*=e,L.rotateRectPointList(i,o)}static deletePolygonLastPoint(t,e,o,i){return o===i.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var o,i;try{let n=S([[...d.concatBeginAndEnd(t.map(l=>[l.x,l.y]))]]);return e.forEach(l=>{const s=S([[...d.concatBeginAndEnd(l.pointList.map(u=>[u.x,u.y]))]]),c=_(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(d.deletePolygonLastPoint,[]):l.reduce(d.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((l,s)=>{const c=s.length,u=s.filter((h,g)=>{const P=(g+1)%c;return!b.getIsInScope(h,s[P],1)});return u.length<3?l:[...l,u]},[])}catch(n){console.error(n)}}static getPolygonPointList(t,e){const o=e.find(i=>i.id===t);return o&&o.pointList&&o.pointList.length>0?o.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(o=>d.isPointListInPolygon(t,o.pointList))}static clipPolygonFromWrapPolygon(t,e){const o=d.isPolygonClosewise(e),i=d.isPolygonClosewise(t),n=d.getClosePointDistanceFromPolygon(t[0],e),r=e[n];let l=[...e.slice(0,n),r,...t,t[0],...e.slice(n,e.length)];return o===i&&(l=[...e.slice(0,n),r,t[0],...t.reverse(),...e.slice(n,e.length)]),l}static isPolygonClosewise(t){const e=t.length;let o,i,n,r=0,l;if(e<3)return 0;for(o=0;o<e;o++)i=(o+1)%e,n=(o+2)%e,l=(t[i].x-t[o].x)*(t[n].y-t[i].y),l-=(t[i].y-t[o].y)*(t[n].x-t[i].x),l<0?r--:l>0&&r++;return r>0?1:r<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let o=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((n,r)=>{const l=O.calcDistance(t,n);l<o&&(o=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var o,i;try{const n=S([[...d.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),r=S([[...d.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),l=B(n,r),s=[],c=t;if(((i=(o=l==null?void 0:l.geometry)==null?void 0:o.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=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(d.deletePolygonLastPoint,[]):h.reduce(d.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(n){console.error(n)}}static composePointList(t,e){let o=0,i=0,n=Number.MAX_VALUE;return t.forEach((r,l)=>{e.forEach((s,c)=>{const u=O.calcDistance(r,s);u<n&&(o=l+1,i=c+1,n=u)})}),[...t.slice(0,o),...e.slice(i,e.length),...e.slice(0,i),...t.slice(o,t.length)]}static composeSegmentPolygonList(t){var e,o;const i=[];for(let n=0;n<t.length;n++)for(let r=0;r<t.length;r++){const l=(e=t[n])==null?void 0:e.pointList,s=(o=t[r])==null?void 0:o.pointList;n!==r&&l&&s&&d.isPointListInPolygon(s,l)&&(t[n].pointList=d.composePointList(l,s),i.unshift(r))}return i.forEach(n=>{t.splice(n,1)}),t}}export{d as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.27.0-alpha.5",
3
+ "version": "1.27.0-alpha.51",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.19.0-alpha.2",
97
+ "@labelbee/lb-utils": "1.19.0-alpha.21",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",