@labelbee/lb-annotation 1.28.0-alpha.3 → 1.28.0-alpha.31

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 (47) hide show
  1. package/dist/_virtual/highlightWorker.js +1 -1
  2. package/dist/constant/tool.js +1 -1
  3. package/dist/core/pointCloud/annotation.js +1 -1
  4. package/dist/core/pointCloud/index.js +4 -4
  5. package/dist/core/pointCloud/matrix.js +1 -1
  6. package/dist/core/scheduler.js +1 -1
  7. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  8. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
  9. package/dist/core/toolOperation/pointOperation.js +1 -1
  10. package/dist/core/toolOperation/polygonOperation.js +2 -1
  11. package/dist/core/toolOperation/rectOperation.js +2 -2
  12. package/dist/index.js +1 -1
  13. package/dist/types/constant/tool.d.ts +7 -0
  14. package/dist/types/core/pointCloud/QuadTree25D.d.ts +78 -0
  15. package/dist/types/core/pointCloud/annotation.d.ts +4 -3
  16. package/dist/types/core/pointCloud/index.d.ts +17 -8
  17. package/dist/types/core/scheduler.d.ts +1 -1
  18. package/dist/types/core/toolOperation/ScribbleTool.d.ts +1 -9
  19. package/dist/types/core/toolOperation/basicToolOperation.d.ts +8 -1
  20. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +19 -0
  21. package/dist/types/core/toolOperation/pointOperation.d.ts +1 -0
  22. package/dist/types/core/toolOperation/polygonOperation.d.ts +20 -13
  23. package/dist/types/core/toolOperation/rectOperation.d.ts +14 -4
  24. package/dist/types/utils/tool/AxisUtils.d.ts +3 -27
  25. package/dist/utils/tool/AxisUtils.js +1 -1
  26. package/dist/utils/tool/DrawUtils.js +1 -1
  27. package/dist/utils/tool/PolygonUtils.js +1 -1
  28. package/dist/utils/tool/TagUtils.js +1 -1
  29. package/dist/utils/tool/polygonTool.js +1 -1
  30. package/es/_virtual/highlightWorker.js +1 -1
  31. package/es/constant/tool.js +1 -1
  32. package/es/core/pointCloud/annotation.js +1 -1
  33. package/es/core/pointCloud/index.js +4 -4
  34. package/es/core/pointCloud/matrix.js +1 -1
  35. package/es/core/scheduler.js +1 -1
  36. package/es/core/toolOperation/basicToolOperation.js +1 -1
  37. package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
  38. package/es/core/toolOperation/pointOperation.js +1 -1
  39. package/es/core/toolOperation/polygonOperation.js +2 -1
  40. package/es/core/toolOperation/rectOperation.js +2 -2
  41. package/es/index.js +1 -1
  42. package/es/utils/tool/AxisUtils.js +1 -1
  43. package/es/utils/tool/DrawUtils.js +3 -3
  44. package/es/utils/tool/PolygonUtils.js +1 -1
  45. package/es/utils/tool/TagUtils.js +1 -1
  46. package/es/utils/tool/polygonTool.js +1 -1
  47. package/package.json +4 -4
@@ -1 +1,2 @@
1
- import j from"lodash";import{i18n as _}from"@labelbee/lb-utils";import b from"../../utils/MathUtils.js";import N from"../../utils/tool/RectUtils.js";import{ERotateDirection as K,ESortDirection as U,EDragTarget as v,EDragStatus as S,TEXT_ATTRIBUTE_OFFSET as E,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import L from"../../constant/keyCode.js";import{EPolygonPattern as x,edgeAdsorptionScope as R,ELineTypes as O,EToolName as H}from"../../constant/tool.js";import w from"../../locales/index.js";import{EMessage as C}from"../../locales/constants.js";import $ from"../../utils/ActionsHistory.js";import D from"../../utils/tool/AttributeUtils.js";import a from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import f from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import u from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as W}from"./basicToolOperation.js";import V from"./textAttributeClass.js";import X from"./Selection.js";var Y=Object.defineProperty,q=Object.defineProperties,G=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,F=(I,t,e)=>t in I?Y(I,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):I[t]=e,y=(I,t)=>{for(var e in t||(t={}))J.call(t,e)&&F(I,e,t[e]);if(Z)for(var e of Z(t))Q.call(t,e)&&F(I,e,t[e]);return I},m=(I,t)=>q(I,G(t));const z=164;class tt extends W{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(D.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=f.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new $,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=x.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new X(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return u.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return u.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>m(y({},t),{pointList:a.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=f.getRenderResultList(this.polygonList,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.polygonList,f.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?y(y({},i),t):i)}rotatePolygon(t=1,e=K.Clockwise,i=this.selectedID){if(!i)return;const s=u.getPolygonByID(this.polygonList,i);if(!s)return;const o=u.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}rotatePolygonEdge(t,e=this.selectedID){!e||!u.getPolygonByID(this.polygonList,e)||(this.setPolygonList(this.setPolygonDataByID({pointList:t},e)),this.render())}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${w.getMessagesByLocale(C.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=a.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(a.returnClosePointIndex(o,a.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=u.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),r=a.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===x.Rect&&this.drawingPointList.length===2){const h=b.getRectangleByRightAngle(r,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${w.getMessagesByLocale(C.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(r),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.stopDrag(),this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t,e){if(!t)return;const i=this.polygonList.map(s=>{var o;if(s.id===t){const l=(o=s==null?void 0:s.valid)!=null?o:!0;return m(y({},s),{valid:e!=null?e:!l})}return s});this.setPolygonList(i),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(u.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${w.getMessagesByLocale(C.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=f.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const l=o.find(n=>n.id===this.editPolygonID);if(!l)return;l.pointList=this.drawingPointList,this.editPolygonID=""}else{const l=M(8,62);let n={id:l,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:f.getMaxOrder(o.filter(r=>f.isSameSourceID(r.sourceID,s)))+1};if(this.config.textConfigurable){let r="";r=D.getTextAttribute(this.polygonList.filter(h=>f.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(y({},n),{textAttribute:r})}this.pattern===x.Rect&&t===!0&&(n=m(y({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(l)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>m(y({},o),{pointList:a.changePointListByZoom(o.pointList,this.zoom)}));return u.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=a.changePointListByZoom(i.pointList,this.zoom);return u.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=a.changePointListByZoom(e.pointList,this.zoom);return a.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${w.getMessagesByLocale(C.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${w.getMessagesByLocale(C.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=U.ascend;t.shiftKey&&(e=U.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=f.getRenderResultList(this.polygonList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),l=s.map(r=>{var h,g,c,d;return m(y({},r),{x:(g=(h=r.pointList[0])==null?void 0:h.x)!=null?g:0,y:(d=(c=r.pointList[0])==null?void 0:c.y)!=null?d:0})}).filter(r=>B.inViewPort({x:r.x,y:r.y},o)),n=f.getNextSelectedRectID(l,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:r}=this;r&&this.setDefaultAttribute(r.attribute)}this.render()}onKeyDown(t){if(!f.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))return;const{keyCode:e}=t;switch(e){case L.Space:this.spaceKeydown();break;case L.Esc:this.drawingPointList=[],this.editPolygonID="";break;case L.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case L.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case L.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case L.Ctrl:this.isCtrl=!0;break;case L.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case L.Tab:{this.onTabKeyDown(t);break}case L.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=D.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case L.Ctrl:this.isCtrl=!1;break;case L.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${w.getMessagesByLocale(C.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=u.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${w.getMessagesByLocale(C.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,a.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}onMouseLeave(){this.dragInfo&&(this.emitUpdatePolygonByDrag(),this.clearPolygonDrag(),this.history.pushHistory(this.polygonList))}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=v.Plane;const o=this.selectedPolygons[0].pointList,l=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=S.Start;const n=this.getHoverPointIndex(t),r=this.getHoverEdgeIndex(t);n>-1?(s=v.Point,i=[n]):r>-1&&this.hoverEdgeIndex>-1&&(s=v.Line,i=[r,(r+1)%o.length])}this.dragInfo={dragStartCoord:l,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:l,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==O.Line)return;const e=u.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(l=>l.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=u.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const l=u.segmentPolygonByPolygon(e,i);if(!l)return;const n=l.shift();if(!n)return;let r="",h=!0;const g=f.getSourceID(this.basicResult);let c="";o=this.polygonList.map(d=>{var p,T;return d.id===this.selectedID?(r=d.attribute,h=(p=d==null?void 0:d.valid)!=null?p:!0,c=(T=d==null?void 0:d.textAttribute)!=null?T:"",m(y({},d),{pointList:n})):d}),l.length>0&&l.forEach((d,p)=>{o.push({sourceID:g,id:M(8,62),pointList:d,valid:h,order:f.getMaxOrder(this.currentShowList)+1+p,attribute:r,textAttribute:c})})}else o[s].pointList=u.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(l=>l.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",_.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==O.Line){this.emit("messageInfo",_.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const l=u.combinePolygonWithPolygon(s,o);if(!l)return;const{newPolygon:n,unionList:r}=l;if(r.length===1&&n){const h=this.polygonList.filter(g=>!r.includes(g.id)).map(g=>g.id===this.selectedID?n:g);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case H.Rect:{n=t.filter(r=>!N.isInRect(r,this.basicResult)).length>0;break}case H.Polygon:{n=u.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=b.calcViewportBoundaries(a.changePointListByZoom(t,this.zoom)),l=1e-5;return e<0||i<0||s>this.imgInfo.width+l||o>this.imgInfo.height+l}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=m(y({},i),{pointList:s});return i.isRect===!0&&this.pattern===x.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e),this.render()}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:l,changePointIndex:n,initPointList:r,dragStartCoord:h}=this.dragInfo;if(this.pattern===x.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[v.Line].includes(o)){const g=b.getArrayIndex(n[0]-2,4),c=b.getArrayIndex(n[0]-1,4),d=[r[g],r[c]],p=b.getRectPerpendicularOffset(h,s,d);return{x:p.x/this.zoom,y:p.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===v.Plane?{x:(s.x-l.x)/this.zoom,y:(s.y-l.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=j.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:l}=this.dragInfo,n=this.getDragOffset(t,e);switch(this.dragStatus=S.Move,o){case v.Plane:i=i.map(r=>m(y({},r),{x:r.x+n.x,y:r.y+n.y}));break;case v.Point:case v.Line:i=i.map((r,h)=>l&&l.includes(h)?m(y({},r),{x:s[h].x+n.x,y:s[h].y+n.y}):r);break}if(this.pattern===x.Rect&&(e==null?void 0:e.isRect)===!0&&o===v.Point&&l&&(i=b.getPointListFromPointOffset(s,l[0],n)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render()),this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t)}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}stopDrag(){this.dragInfo=void 0,this.dragStatus=S.Wait}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===S.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.stopDrag(),this.history.pushHistory(this.polygonList);return}if(this.dragInfo&&this.dragStatus===S.Start){this.stopDrag();return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===S.Start&&this.stopDrag()}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return D.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:z,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;D.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",D.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(D.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:l}=e,{x:n,y:r}=i[i.length-1],h=z,g=a.getOffsetCoordinate({x:n,y:r},this.currentPos,this.zoom),c=this.getColor(s),d=o?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new V({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${l}`,{left:g.x,top:g.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,l,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:r,attribute:h}=e,g=this.getColor(h),c=A.getStrokeAndFill(g,e.valid),d=a.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:c.fill,strokeColor:c.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let p=`${(l=D.getAttributeShowText(h,this.config.attributeList))!=null?l:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(p=`${e.order} ${p}`),P.drawText(this.canvas,d[0],p,y({color:c.stroke},k));const T=d[d.length-1];P.drawText(this.canvas,{x:T.x+E.x,y:T.y+E.y},r,y({color:c.stroke},k))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),l=A.getStrokeAndFill(o,t.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,a.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let n=`${(i=D.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(n=`${t.order} ${n}`),P.drawText(this.canvas,a.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),n,y({color:l.stroke},k)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,a.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const o=this.getColor(this.defaultAttribute),l=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],r=a.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===x.Rect&&n.length===2)n=b.getRectangleByRightAngle(r,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=u.getClosestPoint(r,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(r=h)}n.push(r)}P.drawSelectedPolygonWithFillAndLine(this.canvas,a.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:g,y:c}=a.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:c},5,{color:r.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const r=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,a.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:r.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,l=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:l},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(l/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{tt as default};
1
+ import K from"lodash";import{i18n as A}from"@labelbee/lb-utils";import T from"../../utils/MathUtils.js";import W from"../../utils/tool/RectUtils.js";import{ERotateDirection as V,ESortDirection as M,EDragTarget as v,EDragStatus as x,TEXT_ATTRIBUTE_OFFSET as O,DEFAULT_TEXT_OFFSET as R}from"../../constant/annotation.js";import m from"../../constant/keyCode.js";import{EPolygonPattern as _,edgeAdsorptionScope as U,ELineTypes as B,EToolName as F}from"../../constant/tool.js";import w from"../../locales/index.js";import{EMessage as C}from"../../locales/constants.js";import X from"../../utils/ActionsHistory.js";import b from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/CanvasUtils.js";import y from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import u from"../../utils/tool/PolygonUtils.js";import S from"../../utils/tool/StyleUtils.js";import q from"../../utils/tool/TagUtils.js";import j from"../../utils/uuid.js";import{BasicToolOperation as Y}from"./basicToolOperation.js";import G from"./textAttributeClass.js";import J from"./Selection.js";var Q=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,z=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,N=(I,t,e)=>t in I?Q(I,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):I[t]=e,f=(I,t)=>{for(var e in t||(t={}))it.call(t,e)&&N(I,e,t[e]);if(z)for(var e of z(t))st.call(t,e)&&N(I,e,t[e]);return I},L=(I,t)=>tt(I,et(t));const $=164;class ot extends Y{constructor(t){super(L(f({},t),{isOffscreenCanvas:!0}));this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(b.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygon:e}=this.dragInfo;this.emit("updatePolygonByDrag",[{newPolygon:this.selectedPolygon,originPolygon:e}])}},this.config=y.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.attrChangeTrigger=0,this.drawingHistory=new X,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=_.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.selection=new J(this)}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get minArea(){return this.config.minArea||0}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get selectedPolygon(){return u.getPolygonByID(this.visiblePolygonList,this.selectedID)}get selectedPolygons(){return u.getPolygonByIDs(this.polygonList,this.selectedIDs)}get hoverPolygon(){return this.visiblePolygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get enableDrag(){return Boolean(this.selectedID&&this.dragInfo)}get visiblePolygonList(){return this.polygonList}get polygonListUnderZoom(){return this.visiblePolygonList.map(t=>L(f({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=y.getRenderResultList(this.polygonList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=y.getRenderResultList(this.polygonList,y.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&this.setSelectedID(e),this.render()}setResult(t,e=!0){this.clearActiveStatus(e),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=V.Clockwise,i=this.selectedID){if(!i)return;const s=u.getPolygonByID(this.polygonList,i);if(!s)return;const o=u.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}rotatePolygonEdge(t,e=this.selectedID){!e||!u.getPolygonByID(this.polygonList,e)||(this.setPolygonList(this.setPolygonDataByID({pointList:t},e)),this.render())}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${w.getMessagesByLocale(C.UpperLimitErrorNotice,this.lang)}${e}`);return}const s=this.getCoordinateUnderZoom(t),o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(o,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:l}=u.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,U),n=c.changePointByZoom(l&&t.altKey===!1&&i?l:o,1/this.zoom);!this.addPointInDrawingHook(n).continue||(this.drawingPointList.push(n),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList))}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.stopDrag(),this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(t=!0){this.clearPolygonDrag(),t&&this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setAttrChangeTrigger(t=0){this.attrChangeTrigger=t}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,(this.attrChangeTrigger||e!==t)&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedPolygons.length>0&&(this.selectedPolygons.forEach(i=>{i.attribute=t}),this.history.pushHistory(this.polygonList),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t,e){if(!t)return;const i=this.polygonList.map(s=>{var o;if(s.id===t){const r=(o=s==null?void 0:s.valid)!=null?o:!0;return L(f({},s),{valid:e!=null?e:!r})}return s});this.setPolygonList(i),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}if(u.calcPolygonSize(this.drawingPointList||[])<this.minArea){this.emit("messageInfo",`${w.getMessagesByLocale(C.MinAreaLimitErrorNotice,this.lang)}${this.minArea}`);return}const s=y.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(l=>l.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=j(8,62);let l={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:y.getMaxOrder(o.filter(n=>y.isSameSourceID(n.sourceID,s)))+1};if(this.config.textConfigurable){let n="";n=b.getTextAttribute(this.polygonList.filter(h=>y.isSameSourceID(h.sourceID,s)),this.config.textCheckType),l=L(f({},l),{textAttribute:n})}this.pattern===_.Rect&&t===!0&&(l=L(f({},l),{isRect:!0})),o.push(l),i=l,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>L(f({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return u.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=c.changePointListByZoom(i.pointList,this.zoom);return u.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygons(t){var e;if(!t||t.length===0)return;const i=this.polygonList.filter(s=>this.selection.isIdSelected(s.id));this.emit("deletedObject",{deletedObject:i[0],id:i[0].id}),this.setPolygonList(this.polygonList.filter(s=>!this.selection.isIdSelected(s.id))),this.history.pushHistory(this.polygonList),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${w.getMessagesByLocale(C.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${w.getMessagesByLocale(C.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=M.ascend;t.shiftKey&&(e=M.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=y.getRenderResultList(this.polygonList,y.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...e];i&&(s=[...s,...i]);const o=Z.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(n=>{var h,d,g,a;return L(f({},n),{x:(d=(h=n.pointList[0])==null?void 0:h.x)!=null?d:0,y:(a=(g=n.pointList[0])==null?void 0:g.y)!=null?a:0})}).filter(n=>Z.inViewPort({x:n.x,y:n.y},o)),l=y.getNextSelectedRectID(r,t,this.selectedID);if(l){this.setSelectedID(l.id);const{selectedPolygon:n}=this;n&&this.setDefaultAttribute(n.attribute)}this.render()}onKeyDown(t){if(!y.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setPolygonList.bind(this)))return;const{keyCode:e}=t;switch(e){case m.Space:this.spaceKeydown();break;case m.Esc:this.drawingPointList=[],this.editPolygonID="";break;case m.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case m.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case m.Delete:this.deletePolygons(this.selectedIDs),this.render();break;case m.Ctrl:this.isCtrl=!0;break;case m.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case m.Tab:{this.onTabKeyDown(t);break}case m.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=b.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case m.Ctrl:this.isCtrl=!1;break;case m.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID,t.ctrlKey);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${w.getMessagesByLocale(C.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=u.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,U);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${w.getMessagesByLocale(C.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygons([e]),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}onMouseLeave(){this.dragInfo&&(this.emitUpdatePolygonByDrag(),this.clearPolygonDrag(),this.history.pushHistory(this.polygonList))}dragMouseDown(t){if(t.button!==0)return;const e=this.getHoverID(t);if(!this.selection.isIdSelected(e))return;let i=[0],s=v.Plane;const o=this.selectedPolygons[0].pointList,r=this.getCoordinateUnderZoom(t);if(this.selectedPolygons.length===1){this.dragStatus=x.Start;const l=this.getHoverPointIndex(t),n=this.getHoverEdgeIndex(t);l>-1?(s=v.Point,i=[l]):n>-1&&this.hoverEdgeIndex>-1&&(s=v.Line,i=[n,(n+1)%o.length])}this.dragInfo={dragStartCoord:r,dragTarget:s,initPointList:o,changePointIndex:i,originPolygon:this.selectedPolygon,selectedPolygons:this.selectedPolygons,dragPrevCoord:r,originPolygonList:this.polygonList}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==B.Line)return;const e=u.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=u.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=u.segmentPolygonByPolygon(e,i);if(!r)return;const l=r.shift();if(!l)return;let n="",h=!0;const d=y.getSourceID(this.basicResult);let g="";o=this.polygonList.map(a=>{var p,D;return a.id===this.selectedID?(n=a.attribute,h=(p=a==null?void 0:a.valid)!=null?p:!0,g=(D=a==null?void 0:a.textAttribute)!=null?D:"",L(f({},a),{pointList:l})):a}),r.length>0&&r.forEach((a,p)=>{o.push({sourceID:d,id:j(8,62),pointList:a,valid:h,order:y.getMaxOrder(this.currentShowList)+1+p,attribute:n,textAttribute:g})})}else o[s].pointList=u.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",A.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==B.Line){this.emit("messageInfo",A.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=u.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:l,unionList:n}=r;if(n.length===1&&l){const h=this.polygonList.filter(d=>!n.includes(d.id)).map(d=>d.id===this.selectedID?l:d);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",A.t("CombineSuccess"))}else this.emit("messageInfo",A.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let l=!1;switch(this.dependToolName){case F.Rect:{l=t.filter(n=>!W.isInRect(n,this.basicResult)).length>0;break}case F.Polygon:{l=u.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return l}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=T.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){const e=this.polygonList.map(i=>{if(this.selectedIDs.includes(i.id)){const s=this.dragPolygon(t,i);if(!s)return i;const o=L(f({},i),{pointList:s});return i.isRect===!0&&this.pattern===_.Normal&&Object.assign(o,{isRect:!1}),o}return i});this.dragInfo.dragPrevCoord=this.getCoordinateUnderZoom(t),this.setPolygonList(e)}getDragOffset(t,e){var i;const s=this.getCoordinateUnderZoom(t),{dragTarget:o,dragPrevCoord:r,changePointIndex:l,initPointList:n,dragStartCoord:h}=this.dragInfo;if(this.pattern===_.Rect&&(e==null?void 0:e.isRect)===!0&&l&&[v.Line].includes(o)){const d=T.getArrayIndex(l[0]-2,4),g=T.getArrayIndex(l[0]-1,4),a=[n[d],n[g]],p=T.getRectPerpendicularOffset(h,s,a);return{x:p.x/this.zoom,y:p.y/this.zoom}}return((i=this.dragInfo)==null?void 0:i.dragTarget)===v.Plane?{x:(s.x-r.x)/this.zoom,y:(s.y-r.y)/this.zoom}:{x:(s.x-h.x)/this.zoom,y:(s.y-h.y)/this.zoom}}dragPolygon(t,e){let i=K.cloneDeep(e==null?void 0:e.pointList);if(!i||!this.dragInfo)return;const{initPointList:s,dragTarget:o,changePointIndex:r}=this.dragInfo,l=this.getDragOffset(t,e);switch(this.dragStatus=x.Move,o){case v.Plane:i=i.map(n=>L(f({},n),{x:n.x+l.x,y:n.y+l.y}));break;case v.Point:case v.Line:i=i.map((n,h)=>r&&r.includes(h)?L(f({},n),{x:s[h].x+l.x,y:s[h].y+l.y}):n);break}if(this.pattern===_.Rect&&(e==null?void 0:e.isRect)===!0&&o===v.Point&&r&&(i=T.getPointListFromPointOffset(s,r[0],l)),!(this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i)))return i}determineTrigger(t){if(this.isDrag)return"drag";if(this.dragInfo)return"dragSingle";let e="";const i=this.getHoverID(t);this.hoverID!==i?(this.hoverID=i,e=""):e="move";let s=-1,o=-1;const{selectedID:r}=this;return r&&(s=this.getHoverPointIndex(t),s>-1?this.hoverPointIndex!==s?e="":e="noRender":(o=this.getHoverEdgeIndex(t),this.hoverEdgeIndex!==o?e="":e="noRender"),this.hoverEdgeIndex=o,this.hoverPointIndex=s),e}onMouseMove(t){requestAnimationFrame(()=>{const e=Date.now();if(e-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=e,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;if(this.drawingPointList.length>0){this.render();return}const i=this.determineTrigger(t);this.selectedIDs.length>0&&this.dragInfo&&this.onDragMove(t),this.render(i)})}leftMouseUpdateValid(t){const e=this.getHoverID(t);return this.drawingPointList.length===0&&t.ctrlKey===!0&&e?(this.setPolygonValidAndRender(e),!0):!1}stopDrag(){this.dragInfo=void 0,this.dragStatus=x.Wait}leftMouseUp(t){this.leftMouseUpdateValid(t)||this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){this.emit("updateResult"),this.emitUpdatePolygonByDrag(),this.stopDrag(),this.history.pushHistory(this.polygonList);return}if(this.dragInfo&&this.dragStatus===x.Start){this.stopDrag();return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&this.stopDrag()}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return b.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:$,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;b.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",b.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(b.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:l,y:n}=i[i.length-1],h=$,d=c.getOffsetCoordinate({x:l,y:n},this.currentPos,this.zoom),g=this.getColor(s),a=o?g==null?void 0:g.valid.stroke:g==null?void 0:g.invalid.stroke;this._textAttributeInstance||(this._textAttributeInstance=new G({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${r}`,{left:d.x,top:d.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,o,r,l,n,h;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:d,attribute:g}=e,a=this.getColor(g),p=S.getStrokeAndFill(a,e.valid),D=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,D,{fillColor:p.fill,strokeColor:p.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let k=`${(r=b.getAttributeShowText(g,this.config.attributeList))!=null?r:""}`;((l=this.config)==null?void 0:l.isShowOrder)&&(e==null?void 0:e.order)>0&&(k=`${e.order} ${k}`),(e==null?void 0:e.subAttribute)&&((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&q.getTagNameList(e.subAttribute,this.config.subAttributeList).forEach(H=>{k+=`
2
+ ${H.keyName}: ${H.value.join("\u3001")}`}),P.drawText(this.canvas,D[0],k,f({color:p.stroke},R));const E=D[D.length-1];P.drawText(this.canvas,{x:E.x+O.x,y:E.y+O.y},d,f({color:p.stroke},R))}))}renderSelectedPolygons(){this.selectedPolygons.forEach(t=>{this.renderSelectedPolygon(t)})}renderSelectedPolygon(t){var e,i,s;if(t){const o=this.getColor(t.attribute),r=S.getStrokeAndFill(o,t.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(t.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(e=this.config)==null?void 0:e.lineType});let l=`${(i=b.getAttributeShowText(t.attribute,this.config.attributeList))!=null?i:""}`;((s=this.config)==null?void 0:s.isShowOrder)&&(t==null?void 0:t.order)>0&&(l=`${t.order} ${l}`),P.drawText(this.canvas,c.changePointByZoom(t.pointList[0],this.zoom,this.currentPos),l,f({color:r.stroke},R)),this.renderTextAttribute()}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=S.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(t){var e,i,s,o;t!=="move"&&this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygons();const r=this.getColor(this.defaultAttribute),l=S.getStrokeAndFill(r,!this.isCtrl);if(((e=this.drawingPointList)==null?void 0:e.length)>0){let n=[...this.drawingPointList],h=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const d=this.getPointListByRectDrawing(h,n).value;if(d)n=d;else{if(((i=this.config)==null?void 0:i.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:a}=u.getClosestPoint(h,this.polygonList,(s=this.config)==null?void 0:s.lineType,U/this.zoom);a&&(h=a)}n.push(h)}const g=c.changePointListByZoom(n,this.zoom,this.currentPos);P.drawSelectedPolygonWithFillAndLine(this.canvas,g,{fillColor:l.fill,strokeColor:l.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType}),this.renderPolygonHook(g)}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const h=S.getStrokeAndFill(r,n.valid,{isSelected:!0}),d=n==null?void 0:n.pointList[this.hoverPointIndex];if(d){const{x:g,y:a}=c.changePointByZoom(d,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:h.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const h=S.getStrokeAndFill(r,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:h.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(o=this.config)==null?void 0:o.lineType})}}render(t){!this.ctx||(t!=="move"&&super.render(),t!=="drag"&&t!=="dragSingle"&&this.renderPolygon(t),t==="dragSingle"&&this.renderSelectedPolygons(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){requestAnimationFrame(()=>{this.clearOffscreenCanvas();const{x:e,y:i}=this.coord;if(P.drawLine(this.offscreenCanvas,{x:0,y:i},{x:1e4,y:i},{color:t}),P.drawLine(this.offscreenCanvas,{x:e,y:0},{x:e,y:1e4},{color:t}),P.drawCircleWithFill(this.offscreenCanvas,{x:e,y:i},1,{color:"white"}),this.isCombined){const s=10,o=186,r=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},A.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}})}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}addPointInDrawingHook(...t){return{continue:!0}}renderPolygonHook(...t){return{continue:!0}}getPointListByRectDrawing(...t){return{continue:!0}}}export{ot as default};
@@ -1,2 +1,2 @@
1
- import F from"lodash";import{distance as X}from"@turf/turf";import j from"../../utils/MathUtils.js";import y from"../../utils/tool/AxisUtils.js";import v from"../../utils/tool/RectUtils.js";import O from"../../utils/tool/TagUtils.js";import{EDragStatus as S,ESortDirection as W,DEFAULT_TEXT_SHADOW as U}from"../../constant/annotation.js";import{EDragTarget as D,EOperationMode as Y}from"../../constant/tool.js";import A from"../../constant/keyCode.js";import _ from"../../locales/index.js";import{EMessage as M}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import Z from"../../utils/tool/CanvasUtils.js";import f from"../../utils/tool/CommonToolUtils.js";import C from"../../utils/tool/DrawUtils.js";import G from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as E}from"../../utils/tool/polygonTool.js";import J from"../../utils/uuid.js";import{BasicToolOperation as q}from"./basicToolOperation.js";import Q from"./textAttributeClass.js";import tt from"./Selection.js";var et=Object.defineProperty,it=Object.defineProperties,st=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,N=(w,t,e)=>t in w?et(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,g=(w,t)=>{for(var e in t||(t={}))rt.call(t,e)&&N(w,e,t[e]);if(B)for(var e of B(t))ot.call(t,e)&&N(w,e,t[e]);return w},R=(w,t)=>it(w,st(t));const k=6;class V extends q{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=k,{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=O.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 tt(this)}renderPointCloud2DHighlight(){}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),k+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}=j.getFootOfPerpendicular(o,c.begin,c.end);n<k+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 j.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,E(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=F.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,b=h,x=d,m=a;switch(this.hoverRectPointIndex){case 0:{u=d-s.x<0?n+d:n+s.x,b=a-s.y<0?h+a:h+s.y,x=Math.abs(s.x-d),m=Math.abs(s.y-a);break}case 1:{u=d+s.x>0?n:n+d+s.x,b=a-s.y<0?h+a:h+s.y,x=Math.abs(d+s.x),m=Math.abs(a-s.y);break}case 2:{u=d+s.x>0?n:n+d+s.x,b=a+s.y>0?h:h+a+s.y,x=Math.abs(d+s.x),m=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,b=a+s.y>0?h:h+a+s.y,x=Math.abs(s.x-d),m=a+s.y>0?a+s.y:Math.abs(a+s.y);break}default:return}l=R(g({},l),{x:u,y:b,width:x,height:m})}break;case D.Line:{let u=n,b=h,x=d,m=a;switch(this.hoverRectEdgeIndex){case 0:{b=a-s.y<0?h+a:h+s.y,m=Math.abs(s.y-a);break}case 1:{u=d+s.x>0?n:n+d+s.x,x=Math.abs(d+s.x);break}case 2:{b=a+s.y>0?h:h+a+s.y,m=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=Math.abs(s.x-d);break}default:return}l=R(g({},l),{x:u,y:b,width:x,height:m});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,E(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,x=this.basicResult.width*this.zoom,m=this.basicResult.height*this.zoom;if(l.x<u-.01||l.y<b-.01||l.width>u+x-l.x+.01||l.height>b+m-l.y+.01)return;if(l.x<u&&(l.x=u),l.y<b&&(l.y=b),l.width>u+x-l.x)switch(this.dragInfo.dragTarget){case D.Point:case D.Line:s.x>0&&s.y>0&&(l.width=u+x-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(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}),E(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:J(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",_.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=O.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",_.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(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?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)&&X((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()}return this.render(),n}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 A.Ctrl:this.drawingRect&&(this.drawingRect=R(g({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteSelectedRect(t);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=W.ascend;t.shiftKey&&(i=W.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=Z.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(h=>Z.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 A.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=k+6:i=k,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,r=!1){var o,s,c,n,h,d;if(this.ctx&&t){const{ctx:a,style:l}=this,{hiddenText:u=!1}=l;a.save();const{strokeColor:b,fillColor:x,textColor:m}=this.getRenderStyle(t);a.font="lighter 14px Arial";let L="";((o=this.config)==null?void 0:o.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(L=`${t.order}`),t.label&&this.hasMarkerConfig&&(L=`${f.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${G.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(L=`${L} ${p.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((c=this.config)==null?void 0:c.secondaryAttributeConfigurable)&&((n=this.config)==null?void 0:n.subAttributeList)&&O.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(T=>{L+=`
2
- ${T.keyName}: ${T.value.join("\u3001")}`}));const I=y.changeRectByZoom(t,i?e:this.zoom,this.currentPos);u||C.drawText(this.canvas,{x:I.x,y:I.y-6},L,R(g({color:b,font:"normal normal 900 14px SourceHanSansCN-Regular"},U),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&C.drawHighlightFlag({canvas:this.canvas,color:b,position:{x:I.x-5,y:I.y-16}});const K=(d=(h=this.style)==null?void 0:h.width)!=null?d:2,$=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||$||t.id===this.selectedRectID||this.isMultiMoveMode||r)&&C.drawRectWithFill(this.canvas,I,{color:x}),C.drawRect(this.canvas,I,{color:b,thickness:K,hiddenText:!0,lineDash:t.lineDash}),a.restore();let P=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(P=`${Math.round(t.width/this.zoom)} * ${Math.round(I.height/this.zoom)}`);const H=P.length*7;if(u||C.drawText(this.canvas,{x:I.x+I.width-H,y:I.y+I.height+15},P,g({color:m,font:"normal normal 600 14px Arial"},U)),!u&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,T=Math.max(20,I.width-H);C.drawText(this.canvas,{x:I.x,y:I.y+I.height+20+z},t.textAttribute,g({color:m,font:"italic normal 900 14px Arial",textMaxWidth:T},U))}}}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))}),this.renderPointCloud2DHighlight()}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(Y.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",_.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",_.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())}setHoverRectID(t){this.hoverRectID=t}}export{V as RectOperation,V as default};
1
+ import $ from"lodash";import{distance as X}from"@turf/turf";import j from"../../utils/MathUtils.js";import y from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import P from"../../utils/tool/TagUtils.js";import{i18n as Y}from"@labelbee/lb-utils";import{EDragStatus as p,ESortDirection as W,DEFAULT_TEXT_SHADOW as z}from"../../constant/annotation.js";import{EDragTarget as S,EOperationMode as q}from"../../constant/tool.js";import A from"../../constant/keyCode.js";import O from"../../locales/index.js";import{EMessage as U}from"../../locales/constants.js";import L from"../../utils/tool/AttributeUtils.js";import Z from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import D from"../../utils/tool/DrawUtils.js";import G from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as H}from"../../utils/tool/polygonTool.js";import J from"../../utils/uuid.js";import{BasicToolOperation as Q}from"./basicToolOperation.js";import tt from"./textAttributeClass.js";import et from"./Selection.js";var it=Object.defineProperty,st=Object.defineProperties,rt=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,N=(w,t,e)=>t in w?it(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,u=(w,t)=>{for(var e in t||(t={}))nt.call(t,e)&&N(w,e,t[e]);if(B)for(var e of B(t))ot.call(t,e)&&N(w,e,t[e]);return w},f=(w,t)=>st(w,rt(t));const k=6;class V extends Q{constructor(t){super(f(u({},t),{isOffscreenCanvas:!0}));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(n=>n.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=k,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&I.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>I.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(h=>({size:h.width*h.height,id:h.id})).sort((h,o)=>h.size-o.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.lastMouseMoveTime=0,this.mouseMoveThrottle=16,this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=P.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var h;if(a.id===this.selectedRectID){const o=(h=a==null?void 0:a.subAttribute)!=null?h:s;return f(u({},a),{subAttribute:o})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(L.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.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 et(this)}renderPointCloud2DHighlight(){}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 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]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,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;L.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",L.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?f(u({},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 n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return f(u({},i),{subAttribute:f(u({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?y.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),k+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=I.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:h}=j.getFootOfPerpendicular(n,a.begin,a.end);h<k+10&&(e=s)}return e}getTextIconSvg(t=""){return L.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(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=S.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=S.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=p.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=S.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=p.Start}}}appendOffsetRect(t,e){return f(u({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...I.getRectPointList(this.appendOffsetRect(n,e))),[]);return j.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),h={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return I.isRectNotInPolygon(h,H(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const o=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(o)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!I.isInRect(d,o))}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=>f(u({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||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=>f(u({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=p.Move,this.dragInfo.dragTarget===S.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=I.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:o,width:d,height:c}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case S.Point:{let g=h,b=o,m=d,x=c;switch(this.hoverRectPointIndex){case 0:{g=d-s.x<0?h+d:h+s.x,b=c-s.y<0?o+c:o+s.y,m=Math.abs(s.x-d),x=Math.abs(s.y-c);break}case 1:{g=d+s.x>0?h:h+d+s.x,b=c-s.y<0?o+c:o+s.y,m=Math.abs(d+s.x),x=Math.abs(c-s.y);break}case 2:{g=d+s.x>0?h:h+d+s.x,b=c+s.y>0?o:o+c+s.y,m=Math.abs(d+s.x),x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{g=d-s.x<0?h+d:h+s.x,b=c+s.y>0?o:o+c+s.y,m=Math.abs(s.x-d),x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=f(u({},l),{x:g,y:b,width:m,height:x})}break;case S.Line:{let g=h,b=o,m=d,x=c;switch(this.hoverRectEdgeIndex){case 0:{b=c-s.y<0?o+c:o+s.y,x=Math.abs(s.y-c);break}case 1:{g=d+s.x>0?h:h+d+s.x,m=Math.abs(d+s.x);break}case 2:{b=c+s.y>0?o:o+c+s.y,x=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{g=d-s.x<0?h+d:h+s.x,m=Math.abs(s.x-d);break}default:return}l=f(u({},l),{x:g,y:b,width:m,height:x});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&&I.isRectNotInPolygon(l,H(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,m=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<b-.01||l.width>g+m-l.x+.01||l.height>b+x-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<b&&(l.y=b),l.width>g+m-l.x)switch(this.dragInfo.dragTarget){case S.Point:case S.Line:s.x>0&&s.y>0&&(l.width=g+m-l.x);break;default:return}if(l.height>b+x-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?I.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){requestAnimationFrame(()=>{var e,i;const r=Date.now();if(r-this.lastMouseMoveTime<this.mouseMoveThrottle||(this.lastMouseMoveTime=r,super.onMouseMove(t,!1)||this.forbidMouseOperation||!this.imgInfo))return;const n=this.getCoordinateUnderZoom(t),s=y.changeDrawOutsideTarget(n,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(s),this.render();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 d=this.getHoverRectEdgeIndex(t);if(d!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=d,this.render();return}}}const a=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=a,a!==h&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:d}=this.firstClickCoord,{width:c,height:l}=this.drawingRect;if(c=Math.abs(o-s.x),l=Math.abs(d-s.y),s.x<o&&(o=s.x),s.y<d&&(d=s.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&I.isRectNotInPolygon(f(u({},this.drawingRect),{x:o,y:d,width:c,height:l}),H(this.basicResult.pointList,this.zoom)))return;s.x<0&&(c=Math.abs(this.firstClickCoord.x),o=0),s.y<0&&(l=Math.abs(this.firstClickCoord.y),d=0),this.imgInfo&&(o+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-o)),d+l>this.imgInfo.height&&(l=Math.abs(this.imgInfo.height-d)))}this.drawingRect=f(u({},this.drawingRect),{x:o,y:d,width:c,height:l}),this.render()}if(this.isDrag&&!this.dragInfo){this.render("drag");return}this.render("move")})}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){const e=this.rectList.some(i=>i==null?void 0:i.valid);this.setRectList(this.rectList.map(i=>i.id===t?f(u({},i),{valid:!i.valid}):(this.selection.isIdSelected(i.id)&&(i.valid=!e),i)),!0),this.render(),this.emit("updateResult")}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),h=y.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(h.x<0&&(h.x=0),h.y<0&&(h.y=0)),this.drawingRect=f(u({},h),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",O.getMessagesByLocale(U.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=L.getTextAttribute(this.rectList.filter(d=>R.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{textAttribute:o}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const o=P.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=f(u({},this.drawingRect),{subAttribute:o})}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=u({},h),this.firstCurrentPos=u({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}checkSize({width:t,height:e,minWidth:i,minHeight:r,isAttributeConfig:n=!1}){return Math.round(t)<i||Math.round(e)<r?(this.emit("messageInfo",Y.t(n?"TheSizeOfTheDrawingBoxIsSmallerThanTheMinimumDrawingSizeInTheMainPropertyConfiguration":"TheDrawFrameSizeIsSmallerThanTheMinimumDrawSizeInTheStepConfiguration")),this.clearDrawingStatus(),this.render(),!1):!0}addDrawingRectToRectList(){var t,e,i;if(!this.drawingRect)return;let{width:r,height:n}=this.drawingRect;r/=this.zoom,n/=this.zoom;const{attribute:s}=this.drawingRect;let a={minWidth:this.config.minWidth,minHeight:this.config.minHeight};if(s&&this.config.attributeConfigurable){const d=(i=((e=(t=this.config)==null?void 0:t.attributeList)!=null?e:[]).find(c=>c.value===s))==null?void 0:i.limit;d&&(a=f(u({},d),{isAttributeConfig:!0}))}if(!this.checkSize(u({width:r,height:n},a)))return;const h=this.getDrawingRectWithRectList();this.setRectList(h,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){var t;!this.drawingRect||(this.config.textConfigurable||((t=this.config)==null?void 0:t.secondaryAttributeConfigurable)?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,f(u({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),h=this.rectList.find(o=>o.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&X((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),h&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(h.attribute)),this.hoverRectID="",(h==null?void 0:h.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(h.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),h}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",u({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===p.Move){this.dragInfo=void 0,this.dragStatus=p.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),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.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(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case A.Ctrl:this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedIDs.length>0&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteSelectedRect(t);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=W.ascend;t.shiftKey&&(i=W.descend);const[r,n]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=Z.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(o=>Z.inViewPort({x:o.x,y:o.y},a));const h=R.getNextSelectedRectID(s,i,this.selectedRectID);h&&(this.setSelectedRectID(h.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(h.attribute));break}default:{if(this.config.attributeConfigurable){const i=L.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.drawingRect&&(this.drawingRect=f(u({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=I.getRectUnderZoom(this.drawingRect,1/e),r=y.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=I.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,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,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:n,height:s,attribute:a,valid:h}=e,o=n*this.zoom*.6,d=y.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=h?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new tt({width:o,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:o})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=I.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,h)=>{var o,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===h?i=k+6:i=k,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(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===h){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(o=c==null?void 0:c.invalid)==null?void 0:o.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[h].x*this.zoom+this.currentPos.x,r[h].y*this.zoom+this.currentPos.y),e.lineTo(r[(h+1)%n].x*this.zoom+this.currentPos.x,r[(h+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1,r=!1){var n,s,a,h,o,d;if(this.ctx&&t){const{ctx:c,style:l}=this,{hiddenText:g=!1}=l;c.save();const{strokeColor:b,fillColor:m,textColor:x}=this.getRenderStyle(t);c.font="lighter 14px Arial";let C="";((n=this.config)==null?void 0:n.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(C=`${t.order}`),t.label&&this.hasMarkerConfig&&(C=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${G.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(C=`${C} ${L.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`,(t==null?void 0:t.subAttribute)&&((a=this.config)==null?void 0:a.secondaryAttributeConfigurable)&&((h=this.config)==null?void 0:h.subAttributeList)&&P.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(T=>{C+=`
2
+ ${T.keyName}: ${T.value.join("\u3001")}`}));const v=y.changeRectByZoom(t,i?e:this.zoom,this.currentPos);g||D.drawText(this.canvas,{x:v.x,y:v.y-6},C,f(u({color:b,font:"normal normal 900 14px SourceHanSansCN-Regular"},z),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&D.drawHighlightFlag({canvas:this.canvas,color:b,position:{x:v.x-5,y:v.y-16}});const K=(d=(o=this.style)==null?void 0:o.width)!=null?d:2,F=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||F||t.id===this.selectedRectID||this.isMultiMoveMode||r)&&D.drawRectWithFill(this.canvas,v,{color:m}),D.drawRect(this.canvas,v,{color:b,thickness:K,hiddenText:!0,lineDash:t.lineDash}),c.restore();let M=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(M=`${Math.round(t.width/this.zoom)} * ${Math.round(v.height/this.zoom)}`);const E=M.length*7;if(g||D.drawText(this.canvas,{x:v.x+v.width-E,y:v.y+v.height+15},M,u({color:x,font:"normal normal 600 14px Arial"},z)),!g&&t.textAttribute&&t.id!==this.selectedRectID){const _=0,T=Math.max(20,v.width-E);D.drawText(this.canvas,{x:v.x,y:v.y+v.height+20+_},t.textAttribute,u({color:x,font:"italic normal 900 14px Arial",textMaxWidth:T},z))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,y.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,y.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),this.renderPointCloud2DHighlight()}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(t){t!=="move"&&this.renderStaticRect(),this.renderCreatingRect()}render(t){!this.ctx||(t!=="move"&&super.render(),t!=="drag"&&this.renderRect(t),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){this.clearOffscreenCanvas();const{x:e,y:i}=this.coord;D.drawLine(this.offscreenCanvas,{x:0,y:i},{x:1e4,y:i},{color:t}),D.drawLine(this.offscreenCanvas,{x:e,y:0},{x:e,y:1e4},{color:t}),D.drawCircleWithFill(this.offscreenCanvas,{x:e,y:i},1,{color:"white"})}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)?f(u({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=f(u({},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=p.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(q.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",O.getMessagesByLocale(U.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",O.getMessagesByLocale(U.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())}setHoverRectID(t){this.hoverRectID=t}}export{V as RectOperation,V 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{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
+ 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,ERectToolModeType,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,RECT_TOOL_MODE_NAME,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{EToolName as u,ELineTypes as C}from"../../constant/tool.js";import y from"../MathUtils.js";import x from"./PolygonUtils.js";import v,{POINT_RADIUS as _}from"./LineToolUtils.js";import{getHighlightPoints as P,getHighlightLines as m,getCuboidHoverRange as B}from"./CuboidUtils.js";var L=Object.defineProperty,R=Object.defineProperties,D=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,w=(a,t,e)=>t in a?L(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&w(a,e,t[e]);if(O)for(var e of O(t))Z.call(t,e)&&w(a,e,t[e]);return a},c=(a,t)=>R(a,D(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:r}=t;switch(e%360){case 90:return{x:n-r,y:o};case 180:return{x:s-o,y:n-r};case 270:return{x:r,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t==null?void 0:t.map(s=>this.changePointByZoom(s,e,i))}static changePlanePointByZoom(t,e,i={x:0,y:0}){return Object.entries(t).reduce((s,[n,o])=>{const r=I.changePointByZoom(o,e,i);return c(f({},s),{[n]:r})},{})}static changeCuboidByZoom(t,e,i={x:0,y:0}){return c(f({},t),{frontPoints:this.changePlanePointByZoom(t.frontPoints,e,i),backPoints:t.backPoints?this.changePlanePointByZoom(t.backPoints,e,i):t.backPoints})}static transformPlain2PointList({tl:t,tr:e,br:i,bl:s}){return[t,e,i,s]}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let r=s-e;r<s+e;r+=e/3)n.push({x:o,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static isCloseCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5}=i;for(let r=0;r<s.length;r++){const l=s[r];if(this.getIsInScope(t,l.point,n))return!0}const o=m(e);for(let r=0;r<o.length;r++){const l=o[r],{length:p}=y.getFootOfPerpendicular(t,l.p1,l.p2,!0);if(p<n)return!0}return!!x.isInPolygon(t,B(e))}static isCloseCuboidList(t,e,i={scope:5,zoom:1}){return e.some(s=>this.isCloseCuboid(t,s,i))}static returnClosePointOrLineInCuboid(t,e,i={scope:5,zoom:1}){const s=P(e),{scope:n=5,zoom:o=1}=i;for(let h=0;h<s.length;h++){const g=s[h];if(this.getIsInScope(t,g.point,n))return[{type:"point",points:[this.changePointByZoom(s[h].point,o)],originCuboid:e,positions:g.positions}]}let r=n;const l=m(e);let p;for(let h=0;h<l.length;h++){const g=l[h],{length:d}=y.getFootOfPerpendicular(t,g.p1,g.p2,!0);d<r&&(r=d,p=[{type:"line",points:this.changePointListByZoom([g.p1,g.p2],o),originCuboid:e,positions:g.positions}])}if(p)return p}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class b{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===u.Polygon}get isDependRect(){return this.dependToolName===u.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===C.Curve?x.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return v.calcOptimalIntersection(i,o,s,_,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(o,n);if(x.isInPolygon(t,r))return t;const p=r.concat(r[0]).map(g=>this.getRenderCoord(g)),h=this.getIntersection(t,e,p);return h?this.getAbsCoord(h==null?void 0:h.point):t}coordInsideImage(t){return this.coordInsideRect(t,c(f({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],r=[i,i+n];return y.isInRange(t.x,o)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return x.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{b as CoordinateUtils,I as default};
1
+ import{EToolName as u,ELineTypes as C}from"../../constant/tool.js";import y from"../MathUtils.js";import x from"./PolygonUtils.js";import v,{POINT_RADIUS as _}from"./LineToolUtils.js";import{getHighlightPoints as m,getHighlightLines as P,getCuboidHoverRange as B}from"./CuboidUtils.js";var L=Object.defineProperty,R=Object.defineProperties,D=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,T=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,w=(a,t,e)=>t in a?L(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,f=(a,t)=>{for(var e in t||(t={}))T.call(t,e)&&w(a,e,t[e]);if(O)for(var e of O(t))Z.call(t,e)&&w(a,e,t[e]);return a},c=(a,t)=>R(a,D(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:r}=t;switch(e%360){case 90:return{x:n-r,y:o};case 180:return{x:s-o,y:n-r};case 270:return{x:r,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return e===1&&i.x===0&&i.y===0?t:c(f({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t==null?void 0:t.map(s=>this.changePointByZoom(s,e,i))}static changePlanePointByZoom(t,e,i={x:0,y:0}){return Object.entries(t).reduce((s,[n,o])=>{const r=I.changePointByZoom(o,e,i);return c(f({},s),{[n]:r})},{})}static changeCuboidByZoom(t,e,i={x:0,y:0}){return c(f({},t),{frontPoints:this.changePlanePointByZoom(t.frontPoints,e,i),backPoints:t.backPoints?this.changePlanePointByZoom(t.backPoints,e,i):t.backPoints})}static transformPlain2PointList({tl:t,tr:e,br:i,bl:s}){return[t,e,i,s]}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let r=s-e;r<s+e;r+=e/3)n.push({x:o,y:r});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static isCloseCuboid(t,e,i={scope:5,zoom:1}){const s=m(e),{scope:n=5}=i;for(let r=0;r<s.length;r++){const l=s[r];if(this.getIsInScope(t,l.point,n))return!0}const o=P(e);for(let r=0;r<o.length;r++){const l=o[r],{length:p}=y.getFootOfPerpendicular(t,l.p1,l.p2,!0);if(p<n)return!0}return!!x.isInPolygon(t,B(e))}static isCloseCuboidList(t,e,i={scope:5,zoom:1}){return e.some(s=>this.isCloseCuboid(t,s,i))}static returnClosePointOrLineInCuboid(t,e,i={scope:5,zoom:1}){const s=m(e),{scope:n=5,zoom:o=1}=i;for(let h=0;h<s.length;h++){const g=s[h];if(this.getIsInScope(t,g.point,n))return[{type:"point",points:[this.changePointByZoom(s[h].point,o)],originCuboid:e,positions:g.positions}]}let r=n;const l=P(e);let p;for(let h=0;h<l.length;h++){const g=l[h],{length:d}=y.getFootOfPerpendicular(t,g.p1,g.p2,!0);d<r&&(r=d,p=[{type:"line",points:this.changePointListByZoom([g.p1,g.p2],o),originCuboid:e,positions:g.positions}])}if(p)return p}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class b{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===u.Polygon}get isDependRect(){return this.dependToolName===u.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:y.withinRange(t.x,[i,i+n]),y:y.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===C.Curve?x.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return v.calcOptimalIntersection(i,o,s,_,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const r=this.getPolygonPointList(o,n);if(x.isInPolygon(t,r))return t;const p=r.concat(r[0]).map(g=>this.getRenderCoord(g)),h=this.getIntersection(t,e,p);return h?this.getAbsCoord(h==null?void 0:h.point):t}coordInsideImage(t){return this.coordInsideRect(t,c(f({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],r=[i,i+n];return y.isInRange(t.x,o)&&y.isInRange(t.y,r)}return y.isInRange(t.x,[0,this.basicImgInfo.width])&&y.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return x.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}export{b as CoordinateUtils,I as default};
@@ -1,3 +1,3 @@
1
- import E from"color-rgba";import{NULL_COLOR as M,MathUtils as W}from"@labelbee/lb-utils";import{ELineTypes as P,SEGMENT_NUMBER as b,DEFAULT_FONT as U}from"../../constant/tool.js";import A from"./PolygonUtils.js";import T from"./UnitUtils.js";import k from"./AxisUtils.js";import{getCuboidAllSideLine as F,getPointListsByDirection as L,getCuboidTextAttributeOffset as I}from"./CuboidUtils.js";import R from"./AttributeUtils.js";var $=Object.defineProperty,j=Object.defineProperties,B=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,_=(r,t,i)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))H.call(t,i)&&_(r,i,t[i]);if(v)for(var i of v(t))N.call(t,i)&&_(r,i,t[i]);return r},S=(r,t)=>j(r,B(t));const z=1,X={x:0,y:0},Y=0,y="",Z=[{d:"M0.423514 10.1595C-0.362666 7.22543 1.37854 4.20957 4.3126 3.42339C7.24666 2.63721 10.2625 4.37842 11.0487 7.31248L49.8716 152.201C50.6577 155.135 48.9165 158.151 45.9825 158.937C43.0484 159.724 40.0325 157.982 39.2464 155.048L0.423514 10.1595Z"},{d:"M14.0774 9.47294C28.5 -16.5001 91.5 25.5001 113.138 0.529419L131.773 70.076C112 96.9999 50.5 54 32.7124 79.0196L14.0774 9.47294Z"}],x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:s=y,thickness:l=1,lineCap:c="round",lineDash:n}=e;o.save(),o.strokeStyle=s,o.lineWidth=l,o.lineCap=c,n&&o.setLineDash(n),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=y,thickness:s=1,lineCap:l="round",hiddenText:c=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),c===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const h=`${~~t.width} * ${~~t.height}`.length*7,g=0,u=Math.max(20,t.width-h);this.drawText(r,{x:t.x,y:t.y+t.height+20+g},t.textAttribute,{textMaxWidth:u})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=y}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const s=document.createElement("div");return s.innerHTML=(i=t.reduce((l,c)=>`${l}${c.keyName}: ${c.value.join(" \u3001 ")}
2
- `,""))!=null?i:"",s.setAttribute("id","tagToolTag"),e==null||e.appendChild(s),s}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=y,thickness:s=1,lineCap:l="round",lineType:c=P.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),c===P.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=A.createSmoothCurvePointsFromPointList([...t],b),a!==void 0&&a>-1&&(t=t.slice((b+1)*a,(b+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+2));const h=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let f=0;f<t.length-1;f++)t[f].specialEdge&&h.push({i1:f,i2:f+1}),e.lineTo(t[f+1].x,t[f+1].y);e.stroke(),e.save(),e.lineWidth=s*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),h.forEach(f=>{const w=t[f.i1],C=t[f.i2];e.beginPath(),e.moveTo(w.x,w.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const g=4,u=2;return t.forEach(f=>{f.specialPoint&&(this.drawSpecialPoint(r,f,g+u,o),this.drawSpecialPoint(r,f,g,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:s=0,endAngleDeg:l=360,thickness:c=1,color:n=y,fill:a=y}=e,d=T.deg2rad(s),h=T.deg2rad(l);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=c,o.arc(t.x,t.y,i,d,h,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:s=y}=e;o.save();const l=T.deg2rad(0),c=T.deg2rad(360);o.fillStyle=s,o.beginPath(),o.arc(t.x,t.y,i,l,c,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:s,y:l}=t;o.save(),o.beginPath(),o.fillStyle=e;const c=i*1.5,n=c*Math.sqrt(3)/2,a=c/2;o.moveTo(s,l-c),o.lineTo(s-n,l+a),o.lineTo(s+n,l+a),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=P.Line}=i;return e===!0&&(t=[...t,t[0]]),o===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,S(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=y,lineType:s=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),s===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t,t[0]]));const[l,...c]=t;return e.moveTo(l.x,l.y),c.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:s,lineCap:l,isClose:c,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:s,lineCap:l,isClose:c,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygon(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygonWithFillAndLine(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:s=y,font:l=U,shadowColor:c="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:d=0,textMaxWidth:h=164,offsetX:g=0,offsetY:u=0,textAlign:f="start",lineHeight:w}=e;o.save(),o.textAlign=f,o.fillStyle=s!=null?s:"white",o.font=l,o.shadowColor=c,o.shadowOffsetX=a,o.shadowOffsetY=d,o.shadowBlur=n,this.wrapText(r,`${i}`,t.x+g,t.y+u,h,w),o.restore()}static wrapText(r,t,i,e,o,s){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const l=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
3
- `);for(let n=0;n<c.length;n++){const a=c[n].split("");let d="";for(let h=0;h<a.length;h++){const g=d+a[h],f=l.measureText(g).width;o||(o=300),f>o&&h>0?(l.fillText(d,i,e),d=a[h],e+=s):d=g}l.fillText(d,i,e),e+=s}}static drawArrow(r,t,i,e={}){const{color:o=y,thickness:s=1,lineCap:l="round",theta:c=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,d=(a+c)*Math.PI/180,h=(a-c)*Math.PI/180,g=n*Math.cos(d),u=n*Math.sin(d),f=n*Math.cos(h),w=n*Math.sin(h);r.save(),r.strokeStyle=o,r.lineWidth=s,r.lineCap=l,r.beginPath(),r.moveTo(i.x+g,i.y+u),r.lineTo(i.x,i.y),r.lineTo(i.x+f,i.y+w),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:s}=t,{strokeColor:l,thickness:c,fillColor:n}=i,a={color:l,thickness:c};if(e){const h=k.transformPlain2PointList(e);x.drawPolygon(r,h,S(m({},a),{isClose:!0}));const g=F(t);g==null||g.forEach(u=>{x.drawLine(r,u.p1,u.p2,m({},a))})}const d=k.transformPlain2PointList(s);if(o&&e&&s){const h=L({direction:o,frontPoints:s,backPoints:e});h&&x.drawPolygonWithFill(r,h,{color:n})}x.drawPolygon(r,d,S(m({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,s=o,{config:l,hiddenText:c,selectedID:n,headerText:a,bottomText:d}=e,{backPoints:h,frontPoints:g,textAttribute:u}=t,f=g.br.x-g.bl.x;x.drawCuboid(r,t,i);let w="";(l==null?void 0:l.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(w=`${t.order}`),t.attribute&&(w=`${w} ${R.getAttributeShowText(t.attribute,l==null?void 0:l.attributeList)}`),!c&&h&&w&&x.drawText(r,{x:h.tl.x,y:h.tl.y-5},a!=null?a:w,{color:o,textMaxWidth:300});const C=I({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!c&&u&&t.id!==n){const p=Math.max(20,f*.8);x.drawText(r,{x:C.left,y:C.top},d!=null?d:u,{color:s,textMaxWidth:p})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const s=r.getContext("2d"),{width:l,height:c}=i,n=s.getImageData(0,0,l,c),[a,d,h,g]=E(e!=null?e:M),u=w=>{n.data[w]=a,n.data[w+1]=d,n.data[w+2]=h,n.data[w+3]=Math.floor(255*g)},f=W.generateCoordinates(o);return t.forEach(w=>{for(const[C,p]of f){const D=(w.y+p)*(n.width*4)+(w.x+C)*4;u(D)}}),s.putImageData(n,0,0),{canvas:r}}static drawHighlightFlag(r){const{canvas:t,position:i,color:e,scale:o=.1}=r,s=t.getContext("2d");if(!!s)for(const l of Z){s.beginPath();const c=l.d.split(/(?=[CLMZclmz])/);for(const n of c){const d=n.slice(1).split(" ").map(Number).map((h,g)=>g%2==0?h*o+i.x:h*o+i.y);switch(n[0]){case"M":s.moveTo(d[0],d[1]);break;case"C":s.bezierCurveTo(d[0],d[1],d[2],d[3],d[4],d[5]);break;case"L":s.lineTo(d[0],d[1]);break;case"Z":s.closePath();break}}s.fillStyle=e,s.fill()}}};let O=x;O.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=z,currentPos:s=X,rotate:l=Y,imgAttribute:c}=i;switch(e.save(),l){case 0:e.translate(s.x,s.y);break;case 90:e.translate(s.x+t.height*o,s.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(s.x+t.width*o,s.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(s.x,s.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(s.x,s.y);break}if(c){const{contrast:n,saturation:a,brightness:d}=c;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${d+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{O as default};
1
+ import E from"color-rgba";import{NULL_COLOR as M,MathUtils as W}from"@labelbee/lb-utils";import{ELineTypes as P,SEGMENT_NUMBER as b,DEFAULT_FONT as U}from"../../constant/tool.js";import A from"./PolygonUtils.js";import T from"./UnitUtils.js";import k from"./AxisUtils.js";import{getCuboidAllSideLine as F,getPointListsByDirection as L,getCuboidTextAttributeOffset as I}from"./CuboidUtils.js";import R from"./AttributeUtils.js";var $=Object.defineProperty,j=Object.defineProperties,H=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable,_=(r,t,i)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))N.call(t,i)&&_(r,i,t[i]);if(v)for(var i of v(t))z.call(t,i)&&_(r,i,t[i]);return r},S=(r,t)=>j(r,H(t));const B=1,Z={x:0,y:0},X=0,w="",Y=[{d:"M0.423514 10.1595C-0.362666 7.22543 1.37854 4.20957 4.3126 3.42339C7.24666 2.63721 10.2625 4.37842 11.0487 7.31248L49.8716 152.201C50.6577 155.135 48.9165 158.151 45.9825 158.937C43.0484 159.724 40.0325 157.982 39.2464 155.048L0.423514 10.1595Z"},{d:"M14.0774 9.47294C28.5 -16.5001 91.5 25.5001 113.138 0.529419L131.773 70.076C112 96.9999 50.5 54 32.7124 79.0196L14.0774 9.47294Z"}],x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:s=w,thickness:l=1,lineCap:c="round",lineDash:n}=e;o.save(),o.strokeStyle=s,o.lineWidth=l,o.lineCap=c,n&&o.setLineDash(n),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=w,thickness:s=1,lineCap:l="round",hiddenText:c=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),c===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const h=`${~~t.width} * ${~~t.height}`.length*7,g=0,y=Math.max(20,t.width-h);this.drawText(r,{x:t.x,y:t.y+t.height+20+g},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=w}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const s=document.createElement("div");return s.innerHTML=(i=t.reduce((l,c)=>`${l}${c.keyName}: ${c.value.join(" \u3001 ")}
2
+ `,""))!=null?i:"",s.setAttribute("id","tagToolTag"),e==null||e.appendChild(s),s}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=w,thickness:s=1,lineCap:l="round",lineType:c=P.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),c===P.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=A.createSmoothCurvePointsFromPointList([...t],b),a!==void 0&&a>-1&&(t=t.slice((b+1)*a,(b+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+2));const h=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let f=0;f<t.length-1;f++)t[f].specialEdge&&h.push({i1:f,i2:f+1}),e.lineTo(t[f+1].x,t[f+1].y);e.stroke(),e.save(),e.lineWidth=s*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),h.forEach(f=>{const u=t[f.i1],C=t[f.i2];e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const g=4,y=2;return t.forEach(f=>{f.specialPoint&&(this.drawSpecialPoint(r,f,g+y,o),this.drawSpecialPoint(r,f,g,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:s=0,endAngleDeg:l=360,thickness:c=1,color:n=w,fill:a=w}=e,d=T.deg2rad(s),h=T.deg2rad(l);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=c,o.arc(t.x,t.y,i,d,h,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:s=w}=e;o.save();const l=T.deg2rad(0),c=T.deg2rad(360);o.fillStyle=s,o.beginPath(),o.arc(t.x,t.y,i,l,c,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:s,y:l}=t;o.save(),o.beginPath(),o.fillStyle=e;const c=i*1.5,n=c*Math.sqrt(3)/2,a=c/2;o.moveTo(s,l-c),o.lineTo(s-n,l+a),o.lineTo(s+n,l+a),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=P.Line}=i;return e===!0&&(t=[...t,t[0]]),o===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,S(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=w,lineType:s=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),s===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t,t[0]]));const[l,...c]=t;return e.moveTo(l.x,l.y),c.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:s,lineCap:l,isClose:c,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:s,lineCap:l,isClose:c,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygon(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygonWithFillAndLine(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:s=w,font:l=U,shadowColor:c="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:d=0,textMaxWidth:h=164,offsetX:g=0,offsetY:y=0,textAlign:f="start",lineHeight:u}=e;!o||(o.save(),Object.assign(o,{textAlign:f,fillStyle:s!=null?s:"white",font:l,shadowColor:c,shadowOffsetX:a,shadowOffsetY:d,shadowBlur:n}),this.wrapText(r,i,t.x+g,t.y+y,h,u),o.restore())}static wrapText(r,t,i,e,o,s){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const l=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
3
+ `);for(let n=0;n<c.length;n++){const a=c[n].split("");let d="";for(let h=0;h<a.length;h++){const g=d+a[h],f=l.measureText(g).width;o||(o=300),f>o&&h>0?(l.fillText(d,i,e),d=a[h],e+=s):d=g}l.fillText(d,i,e),e+=s}}static drawArrow(r,t,i,e={}){const{color:o=w,thickness:s=1,lineCap:l="round",theta:c=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,d=(a+c)*Math.PI/180,h=(a-c)*Math.PI/180,g=n*Math.cos(d),y=n*Math.sin(d),f=n*Math.cos(h),u=n*Math.sin(h);r.save(),r.strokeStyle=o,r.lineWidth=s,r.lineCap=l,r.beginPath(),r.moveTo(i.x+g,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+f,i.y+u),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:s}=t,{strokeColor:l,thickness:c,fillColor:n}=i,a={color:l,thickness:c};if(e){const h=k.transformPlain2PointList(e);x.drawPolygon(r,h,S(m({},a),{isClose:!0}));const g=F(t);g==null||g.forEach(y=>{x.drawLine(r,y.p1,y.p2,m({},a))})}const d=k.transformPlain2PointList(s);if(o&&e&&s){const h=L({direction:o,frontPoints:s,backPoints:e});h&&x.drawPolygonWithFill(r,h,{color:n})}x.drawPolygon(r,d,S(m({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,s=o,{config:l,hiddenText:c,selectedID:n,headerText:a,bottomText:d}=e,{backPoints:h,frontPoints:g,textAttribute:y}=t,f=g.br.x-g.bl.x;x.drawCuboid(r,t,i);let u="";(l==null?void 0:l.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(u=`${t.order}`),t.attribute&&(u=`${u} ${R.getAttributeShowText(t.attribute,l==null?void 0:l.attributeList)}`),!c&&h&&u&&x.drawText(r,{x:h.tl.x,y:h.tl.y-5},a!=null?a:u,{color:o,textMaxWidth:300});const C=I({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!c&&y&&t.id!==n){const p=Math.max(20,f*.8);x.drawText(r,{x:C.left,y:C.top},d!=null?d:y,{color:s,textMaxWidth:p})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const s=r.getContext("2d"),{width:l,height:c}=i,n=s.getImageData(0,0,l,c),[a,d,h,g]=E(e!=null?e:M),y=u=>{n.data[u]=a,n.data[u+1]=d,n.data[u+2]=h,n.data[u+3]=Math.floor(255*g)},f=W.generateCoordinates(o);return t.forEach(u=>{for(const[C,p]of f){const D=(u.y+p)*(n.width*4)+(u.x+C)*4;y(D)}}),s.putImageData(n,0,0),{canvas:r}}static drawHighlightFlag(r){const{canvas:t,position:i,color:e,scale:o=.1}=r,s=t.getContext("2d");if(!!s)for(const l of Y){s.beginPath();const c=l.d.split(/(?=[CLMZclmz])/);for(const n of c){const d=n.slice(1).split(" ").map(Number).map((h,g)=>g%2==0?h*o+i.x:h*o+i.y);switch(n[0]){case"M":s.moveTo(d[0],d[1]);break;case"C":s.bezierCurveTo(d[0],d[1],d[2],d[3],d[4],d[5]);break;case"L":s.lineTo(d[0],d[1]);break;case"Z":s.closePath();break}}s.fillStyle=e,s.fill()}}};let O=x;O.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=B,currentPos:s=Z,rotate:l=X,imgAttribute:c}=i;switch(e.save(),l){case 0:e.translate(s.x,s.y);break;case 90:e.translate(s.x+t.height*o,s.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(s.x+t.width*o,s.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(s.x,s.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(s.x,s.y);break}if(c){const{contrast:n,saturation:a,brightness:d}=c;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${d+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{O as default};
@@ -1 +1 @@
1
- import{polygon as S,difference as _,union as B}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import H from"./CommonToolUtils.js";import{ELineTypes as m,SEGMENT_NUMBER as L}from"../../constant/tool.js";import O from"./AxisUtils.js";import M from"../MathUtils.js";import j from"./LineToolUtils.js";var N=Object.defineProperty,b=Object.getOwnPropertySymbols,z=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,D=(C,t,e)=>t in C?N(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,A=(C,t)=>{for(var e in t||(t={}))z.call(t,e)&&D(C,e,t[e]);if(b)for(var e of b(t))R.call(t,e)&&D(C,e,t[e]);return C};class d{static getHoverPolygonID(t,e,n=3,i=m.Line){let o="",r=Infinity;const l=O.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=m.Line){return e=[...e],n===m.Curve&&(e=this.createSmoothCurvePoints(e.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(t,e)}static isPointInOrOnPolygon(t,e,n=1e-9){const{x:i,y:o}=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)&&o<=Math.max(u,g)&&o>=Math.min(u,g),x=(o-u)*(h-c)-(i-c)*(g-u);if(P&&Math.abs(x)<n)return!0;u>o!=g>o&&i<(h-c)*(o-u)/(g-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(t,e=L){return this.createSmoothCurvePoints(t.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!1,e).map((i,o)=>{var r;const l=o/(L+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,n=!1,i=L){if(t.length<4)return t;const o=[],r=t.slice(0);let l,s,c,u,h,g,P,x,v,E,a,y,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,h=(r[f+3]-r[f-1])*e,g=(r[f+5]-r[f+1])*e,y=0;y<=i;y++)a=y/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,E=Math.pow(a,3)-Math.pow(a,2),l=P*r[f]+x*r[f+2]+v*c+E*u,s=P*r[f+1]+x*r[f+3]+v*h+E*g,o.push(l),o.push(s);const I=[];for(let p=0;p<o.length-1;p+=2)I.push({x:o[p],y:o[p+1]});if(n)for(let p=0;p<i+1;p++){const w=I.shift();I.push(w)}return I}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=m.Line,i=5){let o=[...e];n===m.Curve?o=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,L):n===m.Line&&o.push(o[0]);let r=-1,l=i;for(let s=0;s<o.length-1;s++){const{length:c}=M.getFootOfPerpendicular(t,o[s],o[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:n===m.Curve?Math.floor(r/L):r}static getClosestPoint(t,e,n=m.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,h=Infinity,g=t;const P=20;let x=!1;return e.forEach(v=>{if(!x&&!!v.pointList)switch(n){case m.Line:H.findAllLine(v.pointList,s).forEach((a,y)=>{if(x)return;let{length:f,footPoint:I}=M.getFootOfPerpendicular(t,a.point1,a.point2);const p=M.getLineLength(a.point1,t),w=M.getLineLength(a.point2,t);p<i*2&&(I=a.point1,f=p,x=!0),w<i*2&&(I=a.point2,f=w,x=!0),f<h&&f<i&&(c=v.id,u=y,h=f,g=I,l=!0)});break;case m.Curve:{const E=this.createSmoothCurvePoints(v.pointList.reduce((a,y)=>[...a,y.x,y.y],[]),.5,s,P);for(let a=0;a<E.length-1;a++){const{length:y,footPoint:f}=M.getFootOfPerpendicular(t,E[a],E[a+1]);y<h&&y<i&&(c=v.id,u=Math.floor(a/(P+1)),h=y,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,n=m.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=m.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,M.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=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=_(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(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!O.getIsInScope(h,s[P],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=>d.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=d.isPolygonClosewise(e),i=d.isPolygonClosewise(t),o=d.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=j.calcDistance(t,o);l<n&&(n=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const o=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(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(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(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=j.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&&d.isPointListInPolygon(s,l)&&(t[o].pointList=d.composePointList(l,s),i.unshift(r))}return i.forEach(o=>{t.splice(o,1)}),t}static computeConvexHull(t){t.sort((o,r)=>o.x!==r.x?o.x-r.x:o.y-r.y);const e=(o,r,l)=>(r.x-o.x)*(l.y-o.y)-(r.y-o.y)*(l.x-o.x),n=[];for(const o of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],o)<=0;)n.pop();n.push(o)}const i=[];for(let o=t.length-1;o>=0;o--){const r=t[o];for(;i.length>=2&&e(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return i.pop(),n.pop(),n.concat(i)}static createConvexHullGroup(t){const e={};return t.forEach(n=>{n.type==="line"&&(e[n.annotation.id]||(e[n.annotation.id]={points:[],convexHull:[]}),e[n.annotation.id].points.push(...n.annotation.pointList))}),Object.keys(e).forEach(n=>{e[n].convexHull=this.computeConvexHull(e[n].points)}),e}}export{d as default};
1
+ import{polygon as S,difference as _,union as B}from"@turf/turf";import{ERotateDirection as F}from"../../constant/annotation.js";import H from"./CommonToolUtils.js";import{ELineTypes as m,SEGMENT_NUMBER as L}from"../../constant/tool.js";import O from"./AxisUtils.js";import M from"../MathUtils.js";import j from"./LineToolUtils.js";var N=Object.defineProperty,b=Object.getOwnPropertySymbols,z=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,D=(C,t,e)=>t in C?N(C,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):C[t]=e,A=(C,t)=>{for(var e in t||(t={}))z.call(t,e)&&D(C,e,t[e]);if(b)for(var e of b(t))R.call(t,e)&&D(C,e,t[e]);return C};class d{static getHoverPolygonID(t,e,n=3,i=m.Line){let o="",r=Infinity;const l=O.axisArea(t,n);return e.forEach(s=>{s.pointList&&l.forEach(c=>{if(this.isInPolygon(c,s.pointList,i)){const u=this.calcPolygonSize(s.pointList);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=m.Line){return e=[...e],n===m.Curve&&(e=this.createSmoothCurvePoints(e.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!0,20)),this.isPointInOrOnPolygon(t,e)}static isPointInOrOnPolygon(t,e,n=1e-9){const{x:i,y:o}=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)&&o<=Math.max(u,g)&&o>=Math.min(u,g),x=(o-u)*(h-c)-(i-c)*(g-u);if(P&&Math.abs(x)<n)return!0;u>o!=g>o&&i<(h-c)*(o-u)/(g-u)+c&&(r=!r)}return r}static createSmoothCurvePointsFromPointList(t,e=L){return this.createSmoothCurvePoints(t.reduce((i,o)=>[...i,o.x,o.y],[]),.5,!1,e).map((i,o)=>{var r;const l=o/(L+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,n=!1,i=L){if(t.length<4)return t;const o=[],r=t.slice(0);let l,s,c,u,h,g,P,x,v,E,a,y,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,h=(r[f+3]-r[f-1])*e,g=(r[f+5]-r[f+1])*e,y=0;y<=i;y++)a=y/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,E=Math.pow(a,3)-Math.pow(a,2),l=P*r[f]+x*r[f+2]+v*c+E*u,s=P*r[f+1]+x*r[f+3]+v*h+E*g,o.push(l),o.push(s);const I=[];for(let p=0;p<o.length-1;p+=2)I.push({x:o[p],y:o[p+1]});if(n)for(let p=0;p<i+1;p++){const w=I.shift();I.push(w)}return I}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=m.Line,i=5){let o=[...e];n===m.Curve?o=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,L):n===m.Line&&o.push(o[0]);let r=-1,l=i;for(let s=0;s<o.length-1;s++){const{length:c}=M.getFootOfPerpendicular(t,o[s],o[s+1],!0);c<l&&(r=s,l=c)}return r===-1?-1:n===m.Curve?Math.floor(r/L):r}static getClosestPoint(t,e,n=m.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,h=Infinity,g=t;const P=20;let x=!1;return e.forEach(v=>{if(!x&&!!v.pointList)switch(n){case m.Line:H.findAllLine(v.pointList,s).forEach((a,y)=>{if(x)return;let{length:f,footPoint:I}=M.getFootOfPerpendicular(t,a.point1,a.point2);const p=M.getLineLength(a.point1,t),w=M.getLineLength(a.point2,t);p<i*2&&(I=a.point1,f=p,x=!0),w<i*2&&(I=a.point2,f=w,x=!0),f<h&&f<i&&(c=v.id,u=y,h=f,g=I,l=!0)});break;case m.Curve:{const E=this.createSmoothCurvePoints(v.pointList.reduce((a,y)=>[...a,y.x,y.y],[]),.5,s,P);for(let a=0;a<E.length-1;a++){const{length:y,footPoint:f}=M.getFootOfPerpendicular(t,E[a],E[a+1]);y<h&&y<i&&(c=v.id,u=Math.floor(a/(P+1)),h=y,g=f,l=!0)}}break}}),{dropFoot:g,closestEdgeIndex:u,closestPolygonID:c,hasClosed:l}}static isPointListInPolygon(t,e,n=m.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=m.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,M.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=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=_(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(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!O.getIsInScope(h,s[P],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=>d.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=d.isPolygonClosewise(e),i=d.isPolygonClosewise(t),o=d.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=j.calcDistance(t,o);l<n&&(n=l,i=r)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const o=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(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(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(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=j.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&&d.isPointListInPolygon(s,l)&&(t[o].pointList=d.composePointList(l,s),i.unshift(r))}return i.forEach(o=>{t.splice(o,1)}),t}static computeConvexHull(t){t.sort((o,r)=>o.x!==r.x?o.x-r.x:o.y-r.y);const e=(o,r,l)=>(r.x-o.x)*(l.y-o.y)-(r.y-o.y)*(l.x-o.x),n=[];for(const o of t){for(;n.length>=2&&e(n[n.length-2],n[n.length-1],o)<=0;)n.pop();n.push(o)}const i=[];for(let o=t.length-1;o>=0;o--){const r=t[o];for(;i.length>=2&&e(i[i.length-2],i[i.length-1],r)<=0;)i.pop();i.push(r)}return i.pop(),n.pop(),n.concat(i)}static createConvexHullGroup(t){const e={};return t.forEach(n=>{n.type==="line"&&(e[n.annotation.id]||(e[n.annotation.id]={points:[],convexHull:[]}),e[n.annotation.id].points.push(...n.annotation.pointList))}),Object.keys(e).forEach(n=>{e[n].convexHull=this.computeConvexHull(e[n].points)}),e}}export{d as default};
@@ -1 +1 @@
1
- import a from"../uuid.js";var p=Object.defineProperty,o=Object.getOwnPropertySymbols,m=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,f=(s,t,e)=>t in s?p(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,c=(s,t)=>{for(var e in t||(t={}))m.call(t,e)&&f(s,e,t[e]);if(o)for(var e of o(t))v.call(t,e)&&f(s,e,t[e]);return s};class y{static getTagKeyName(t,e){var r,l;if(!!e)return(l=(r=e.find(u=>u.value===t))==null?void 0:r.key)!=null?l:""}static getTagName([t="",e=""],r){if(!!r){for(const l of r)if(l.value===t){if(!l.subSelected)return console.error("\u6807\u7B7E\u89E3\u6790\u9519\u8BEF",t,e),"";for(const u of l.subSelected)if(u.value===e)return u.key}}}static getTagNameList(t,e){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((r,l)=>{const[u,n]=l;if(n&&n.length>0){const i=n.split(";"),g={keyName:this.getTagKeyName(u,e),value:i.map(d=>this.getTagName([u,d],e))};return[...r,g]}return r},[]).filter(r=>r)}static getTagnameListWithoutConfig(t){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((e,r)=>{const[l,u]=r,n=u.split(";"),i={keyName:l,value:n};return[...e,i]},[]).filter(e=>e)}static judgeResultIsInInputList(t,e,r){return!t||!e||!r?!1:r.filter(u=>{if(u.value===t&&u.subSelected){const n=e==null?void 0:e.split(";");return(u==null?void 0:u.subSelected.filter(i=>n.indexOf(i.value)>-1).length)>0}return!1}).length>0}static getDefaultResultByConfig(t){return t.reduce((e,r)=>(r.subSelected&&r.subSelected.forEach(l=>{var u;if(l.isDefault){const n=(u=e[r.value])!=null?u:"";let i=[];n.length>0&&(i=n.split(";")),i.push(l.value),e[r.value]=i.join(";")}}),e),{})}static getDefaultTagResult(t,e){const r=this.getDefaultResultByConfig(t!=null?t:[]);return e.length>0?e.map(l=>({id:a(),sourceID:l.id,result:c({},r)})):[{id:a(),sourceID:"",result:c({},r)}]}}export{y as default};
1
+ import o from"../uuid.js";var m=Object.defineProperty,f=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,c=(s,t,e)=>t in s?m(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,g=(s,t)=>{for(var e in t||(t={}))y.call(t,e)&&c(s,e,t[e]);if(f)for(var e of f(t))_.call(t,e)&&c(s,e,t[e]);return s};class h{static getTagKeyName(t,e){var r,l;if(!!e)return(l=(r=e.find(u=>u.value===t))==null?void 0:r.key)!=null?l:""}static getTagName([t="",e=""],r){if(!!r){for(const l of r)if(l.value===t){if(!l.subSelected)return console.error("\u6807\u7B7E\u89E3\u6790\u9519\u8BEF",t,e),"";for(const u of l.subSelected)if(u.value===e)return u.key}}}static getTagNameList(t,e){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((r,l)=>{var u;const[i,n]=l;if(n&&n.length>0){const d=n.split(";"),a=(u=this.getTagKeyName(i,e))!=null?u:"",p=d.map(v=>this.getTagName([i,v],e));if(a.trim()!=="")return[...r,{keyName:a,value:p}]}return r},[]).filter(r=>r)}static getTagnameListWithoutConfig(t){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((e,r)=>{const[l,u]=r,i=u.split(";"),n={keyName:l,value:i};return[...e,n]},[]).filter(e=>e)}static judgeResultIsInInputList(t,e,r){return!t||!e||!r?!1:r.filter(u=>{if(u.value===t&&u.subSelected){const i=e==null?void 0:e.split(";");return(u==null?void 0:u.subSelected.filter(n=>i.indexOf(n.value)>-1).length)>0}return!1}).length>0}static getDefaultResultByConfig(t){return t.reduce((e,r)=>(r.subSelected&&r.subSelected.forEach(l=>{var u;if(l.isDefault){const i=(u=e[r.value])!=null?u:"";let n=[];i.length>0&&(n=i.split(";")),n.push(l.value),e[r.value]=n.join(";")}}),e),{})}static getDefaultTagResult(t,e){const r=this.getDefaultResultByConfig(t!=null?t:[]);return e.length>0?e.map(l=>({id:o(),sourceID:l.id,result:g({},r)})):[{id:o(),sourceID:"",result:g({},r)}]}}export{h as default};
@@ -1 +1 @@
1
- import{ELineTypes as g,SEGMENT_NUMBER as E}from"../../constant/tool.js";var C=Object.defineProperty,I=Object.defineProperties,L=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,P=(e,t,l)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,b=(e,t)=>{for(var l in t||(t={}))N.call(t,l)&&P(e,l,t[l]);if(O)for(var l of O(t))S.call(t,l)&&P(e,l,t[l]);return e},D=(e,t)=>I(e,L(t));function v(e,t=.5,l=!1,s=16){if(e.length<4)return e;const h=[],r=e.slice(0);let f,u,n,y,p,d,w,i,M,m,o,c,a;for(l?(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])),a=2;a<r.length-4;a+=2)for(n=(r[a+2]-r[a-2])*t,y=(r[a+4]-r[a-0])*t,p=(r[a+3]-r[a-1])*t,d=(r[a+5]-r[a+1])*t,c=0;c<=s;c++)o=c/s,w=2*Math.pow(o,3)-3*Math.pow(o,2)+1,i=-(2*Math.pow(o,3))+3*Math.pow(o,2),M=Math.pow(o,3)-2*Math.pow(o,2)+o,m=Math.pow(o,3)-Math.pow(o,2),f=w*r[a]+i*r[a+2]+M*n+m*y,u=w*r[a+1]+i*r[a+3]+M*p+m*d,h.push(f),h.push(u);const _=[];for(let x=0;x<h.length-1;x+=2)_.push({x:h[x],y:h[x+1]});if(l)for(let x=0;x<s+1;x++){const j=_.shift();_.push(j)}return _}const R=(e,t=16)=>v(e.reduce((l,s)=>[...l,s.x,s.y],[]),.5,!1,t);function T(e,t,l=g.Line){let s=0,h,r,f,u;t=[...t],l===g.Curve&&(t=v(t.reduce((y,p)=>[...y,p.x,p.y],[]),.5,!0,E)),[f]=t;const n=t.length;for(h=1;h<=n;h++)u=t[h%n],e.x>Math.min(f.x,u.x)&&e.x<=Math.max(f.x,u.x)&&e.y<=Math.max(f.y,u.y)&&f.x!==u.x&&(r=(e.x-f.x)*(u.y-f.y)/(u.x-f.x)+f.y,(f.y===u.y||e.y<=r)&&s++),f=u;return s%2!=0}function U(e,t=1){return e.map(l=>D(b({},l),{x:l.x*t,y:l.y*t}))}export{v as createSmoothCurvePoints,R as createSmoothCurvePointsFromPointList,U as getPolygonPointUnderZoom,T as isInPolygon};
1
+ import{ELineTypes as d,SEGMENT_NUMBER as E}from"../../constant/tool.js";var b=Object.defineProperty,C=Object.defineProperties,L=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,j=(t,e,a)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a,S=(t,e)=>{for(var a in e||(e={}))N.call(e,a)&&j(t,a,e[a]);if(O)for(var a of O(e))P.call(e,a)&&j(t,a,e[a]);return t},D=(t,e)=>C(t,L(e));function v(t,e=.5,a=!1,u=16){if(t.length<4)return t;const l=[],r=t.slice(0);let _,M,o,w,h,x,i,p,s,m,n,c,f;for(a?(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(o=(r[f+2]-r[f-2])*e,w=(r[f+4]-r[f-0])*e,h=(r[f+3]-r[f-1])*e,x=(r[f+5]-r[f+1])*e,c=0;c<=u;c++)n=c/u,i=2*Math.pow(n,3)-3*Math.pow(n,2)+1,p=-(2*Math.pow(n,3))+3*Math.pow(n,2),s=Math.pow(n,3)-2*Math.pow(n,2)+n,m=Math.pow(n,3)-Math.pow(n,2),_=i*r[f]+p*r[f+2]+s*o+m*w,M=i*r[f+1]+p*r[f+3]+s*h+m*x,l.push(_),l.push(M);const g=[];for(let y=0;y<l.length-1;y+=2)g.push({x:l[y],y:l[y+1]});if(a)for(let y=0;y<u+1;y++){const I=g.shift();g.push(I)}return g}const R=(t,e=16)=>v(t.reduce((a,u)=>[...a,u.x,u.y],[]),.5,!1,e);function T(t,e,a=d.Line){let u=0,l,r;a===d.Curve&&(e=v(e.flatMap(h=>[h.x,h.y]),.5,!0,E));const[_,M,o,w]=e.reduce(([h,x,i,p],{x:s,y:m})=>[Math.min(h,s),Math.max(x,s),Math.min(i,m),Math.max(p,m)],[Infinity,-Infinity,Infinity,-Infinity]);if(t.x<_||t.x>M||t.y<o||t.y>w)return!1;l=e[e.length-1];for(let h=0;h<e.length;h++){if(r=e[h],t.y>Math.min(l.y,r.y)&&t.y<=Math.max(l.y,r.y)&&t.x<=Math.max(l.x,r.x)){const x=l.y!==r.y?(t.y-l.y)*(r.x-l.x)/(r.y-l.y)+l.x:l.x;t.x<=x&&u++}if(l=r,u%2!=0&&h>e.length/2)break}return u%2!=0}function U(t,e=1){return t.map(a=>D(S({},a),{x:a.x*e,y:a.y*e}))}export{v as createSmoothCurvePoints,R as createSmoothCurvePointsFromPointList,U as getPolygonPointUnderZoom,T as isInPolygon};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.28.0-alpha.3",
3
+ "version": "1.28.0-alpha.31",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -87,18 +87,18 @@
87
87
  "rollup": "^2.43.1",
88
88
  "rollup-plugin-esbuild": "^3.0.2",
89
89
  "rollup-plugin-svg": "^2.0.0",
90
- "rollup-plugin-web-worker-loader": "^1.6.1",
90
+ "rollup-plugin-web-worker-loader": "1.6.1",
91
91
  "tslib": "^1.10.0",
92
92
  "tslint": "^6.1.3",
93
93
  "tslint-config-prettier": "^1.18.0",
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.19.0",
97
+ "@labelbee/lb-utils": "1.20.0-alpha.8",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",
101
101
  "mathjs": "11.8.1",
102
- "three": ">=0.141.0"
102
+ "three": "0.173.0"
103
103
  }
104
104
  }