@labelbee/lb-annotation 1.14.0-alpha.9 → 1.15.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +2 -2
- package/dist/core/scheduler.js +1 -1
- package/dist/core/toolOperation/LineToolOperation.js +1 -1
- package/dist/core/toolOperation/Selection.js +1 -0
- package/dist/core/toolOperation/cuboidOperation.js +1 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/core/toolOperation/polygonOperation.js +1 -1
- package/dist/core/toolOperation/rectOperation.js +1 -1
- package/dist/core/toolOperation/textAttributeClass.js +9 -9
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/pointCloud/annotation.d.ts +2 -1
- package/dist/types/core/pointCloud/index.d.ts +8 -3
- package/dist/types/core/scheduler.d.ts +16 -3
- package/dist/types/core/toolOperation/LineToolOperation.d.ts +26 -36
- package/dist/types/core/toolOperation/Selection.d.ts +70 -0
- package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +2 -10
- package/dist/types/core/toolOperation/pointOperation.d.ts +10 -4
- package/dist/types/core/toolOperation/polygonOperation.d.ts +23 -14
- package/dist/types/core/toolOperation/rectOperation.d.ts +41 -10
- package/dist/types/core/toolOperation/textAttributeClass.d.ts +6 -0
- package/dist/types/utils/tool/CommonToolUtils.d.ts +2 -2
- package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +2 -2
- package/dist/types/utils/tool/PolygonUtils.d.ts +1 -1
- package/dist/utils/tool/CommonToolUtils.js +1 -1
- package/dist/utils/tool/PolygonUtils.js +1 -1
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/scheduler.js +1 -1
- package/es/core/toolOperation/LineToolOperation.js +1 -1
- package/es/core/toolOperation/Selection.js +1 -0
- package/es/core/toolOperation/cuboidOperation.js +1 -1
- package/es/core/toolOperation/pointCloud2dOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/core/toolOperation/polygonOperation.js +1 -1
- package/es/core/toolOperation/rectOperation.js +1 -1
- package/es/core/toolOperation/textAttributeClass.js +9 -9
- package/es/utils/tool/CommonToolUtils.js +1 -1
- package/es/utils/tool/PolygonUtils.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import N from"../../utils/MathUtils.js";import S from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/RectUtils.js";import{EDragStatus as L,ESortDirection as O,DEFAULT_TEXT_SHADOW as T}from"../../constant/annotation.js";import{EDragTarget as w,EOperationMode as _}from"../../constant/tool.js";import p from"../../constant/keyCode.js";import A from"../../locales/index.js";import{EMessage as P}from"../../locales/constants.js";import C from"../../utils/tool/AttributeUtils.js";import U from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import k from"../../utils/tool/DrawUtils.js";import B from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as E}from"../../utils/tool/polygonTool.js";import K from"../../utils/uuid.js";import{BasicToolOperation as V}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var F=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,j=(D,t,e)=>t in D?F(D,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):D[t]=e,x=(D,t)=>{for(var e in t||(t={}))G.call(t,e)&&j(D,e,t[e]);if(H)for(var e of H(t))J.call(t,e)&&j(D,e,t[e]);return D},m=(D,t)=>X(D,Y(t));const M=6;class W extends V{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===i);r&&(this.setSelectedID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=M,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:g}=this;if(g&&y.isInRect(i,g,r,this.zoom))return g.id}const h=o.filter(g=>y.isInRect(i,g,r,this.zoom));if(h.length===0)return"";if(h.length===1)return h[0].id;if(h.length>1)return h.map(s=>({size:s.width*s.height,id:s.id})).sort((s,f)=>s.size-f.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(C.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=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 selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);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){var e,i;const r=this.selectedRectID;t!==r&&r&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;C.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",C.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?m(x({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?S.returnClosePointIndex(this.getCoordinateUnderZoom(t),y.getRectPointList(this.selectedRect,this.zoom),M+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=y.getRectEdgeList(i,this.zoom),o=this.getCoordinateUnderZoom(t);for(let h=0;h<r.length;h++){const g=r[h],{length:s}=N.getFootOfPerpendicular(o,g.begin,g.end);s<M+10&&(e=h)}return e}getTextIconSvg(t=""){return C.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}multiMoveMouseDown(t){const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);return this.isMultiMoveMode&&i&&t.button===0?(this.dragInfo={dragStartCoord:e,dragTarget:w.Plane,startTime:+new Date,originRectList:this.rectList},this.dragStatus=L.Start,!0):!1}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0||this.multiMoveMouseDown(t))return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!(!r||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const o=w.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=L.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=w.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=L.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const o=w.Plane;this.dragInfo={dragStartCoord:e,dragTarget:o,firstRect:r,startTime:+new Date},this.dragStatus=L.Start}}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>m(x({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,o,h,g;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=L.Move,this.isMultiMoveMode){this.onDragMoveAll(s);return}if(!this.dragInfo.firstRect)return;const f=y.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:l,y:c,width:u,height:d}=f;let n=this.rectList.filter(a=>a.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case w.Plane:n=m(x({},n),{x:l+s.x,y:c+s.y,width:u,height:d});break;case w.Point:{let a=l,b=c,I=u,v=d;switch(this.hoverRectPointIndex){case 0:{a=u-s.x<0?l+u:l+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(s.x-u),v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,b=d-s.y<0?c+d:c+s.y,I=Math.abs(u+s.x),v=Math.abs(d-s.y);break}case 2:{a=u+s.x>0?l:l+u+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(u+s.x),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,b=d+s.y>0?c:c+d+s.y,I=Math.abs(s.x-u),v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v})}break;case w.Line:{let a=l,b=c,I=u,v=d;switch(this.hoverRectEdgeIndex){case 0:{b=d-s.y<0?c+d:c+s.y,v=Math.abs(s.y-d);break}case 1:{a=u+s.x>0?l:l+u+s.x,I=Math.abs(u+s.x);break}case 2:{b=d+s.y>0?c:c+d+s.y,v=d+s.y>0?d+s.y:Math.abs(d+s.y);break}case 3:{a=u-s.x<0?l+u:l+s.x,I=Math.abs(s.x-u);break}default:return}n=m(x({},n),{x:a,y:b,width:I,height:v});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(n,E(this.basicResult.pointList,this.zoom)))return;const a=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,I=this.basicResult.width*this.zoom,v=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==w.Plane&&(n.x<a-.01||n.y<b-.01||n.width>a+I-n.x+.01||n.height>b+v-n.y+.01))return;if(n.x<a&&(n.x=a),n.y<b&&(n.y=b),n.width>a+I-n.x)switch(this.dragInfo.dragTarget){case w.Plane:n.x=a+I-u;break;case w.Point:case w.Line:s.x>0&&s.y>0&&(n.width=a+I-n.x);break;default:return}if(n.height>b+v-n.y)switch(this.dragInfo.dragTarget){case w.Plane:n.y=b+v-d;break}}else if(n.x<0&&(n.x=0),n.y<0&&(n.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case w.Plane:n.x+n.width>((r=this.imgInfo)==null?void 0:r.width)&&(n.x=this.imgInfo.width-u),n.y+n.height>((o=this.imgInfo)==null?void 0:o.height)&&(n.y=this.imgInfo.height-d);break;default:if(n.x+n.width>((h=this.imgInfo)==null?void 0:h.width)+.01||n.y+n.height>((g=this.imgInfo)==null?void 0:g.height)+.01)return}}this.setRectList(this.rectList.map(a=>a.id===n.id?y.getRectUnderZoom(n,1/this.zoom):a)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=S.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if((this.selectedRectID||this.isMultiMoveMode)&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const s=this.getHoverRectPointIndex(t);if(s!==this.hoverRectPointIndex){this.hoverRectPointIndex=s,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const f=this.getHoverRectEdgeIndex(t);if(f!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=f,this.render();return}}}const h=this.getHoverRectID(t),g=this.hoverRectID;if(this.hoverRectID=h,h!==g&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:s,y:f}=this.firstClickCoord,{width:l,height:c}=this.drawingRect;if(l=Math.abs(s-o.x),c=Math.abs(f-o.y),o.x<s&&(s=o.x),o.y<f&&(f=o.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&y.isRectNotInPolygon(m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),E(this.basicResult.pointList,this.zoom)))return;o.x<0&&(l=Math.abs(this.firstClickCoord.x),s=0),o.y<0&&(c=Math.abs(this.firstClickCoord.y),f=0),this.imgInfo&&(s+l>this.imgInfo.width&&(l=Math.abs(this.imgInfo.width-s)),f+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-f)))}this.drawingRect=m(x({},this.drawingRect),{x:s,y:f,width:l,height:c}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?m(x({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),r=S.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=m(x({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:K(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",A.getMessagesByLocale(P.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=C.getTextAttribute(this.rectList.filter(h=>R.isSameSourceID(h.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=x({},r),this.firstCurrentPos=x({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",A.getMessagesByLocale(P.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,m(x({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(o=>o.id===e),{selectedRectID:r}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(r!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const o=R.getCurrentMarkerIndex(i.label,this.config.markerList);o>=0&&(this.setMarkerIndex(o),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===L.Move){this.dragInfo=void 0,this.dragStatus=L.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(this.isMultiMoveMode&&this.setOperationMode(_.General),t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case p.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case p.Z:this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deleteRect(this.selectedRectID);break;case p.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=O.ascend;t.shiftKey&&(i=O.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let h=[...r];o&&(h=[...h,o]);const g=U.getViewPort(this.canvas,this.currentPos,this.zoom);h=h.filter(f=>U.inViewPort({x:f.x,y:f.y},g));const s=R.getNextSelectedRectID(h,i,this.selectedRectID);s&&(this.setSelectedRectID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute));break}default:{if(this.config.attributeConfigurable){const i=C.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=y.getRectUnderZoom(this.drawingRect,1/e),r=S.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=y.getRectUnderZoom(i,this.zoom),this.firstClickCoord=S.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:h,attribute:g,valid:s}=e,f=o*this.zoom*.6,l=S.getOffsetCoordinate({x:i,y:r+h},this.currentPos,this.zoom),c=this.getColor(g),u=s?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new $({width:f,container:this.container,icon:this.getTextIconSvg(g),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:l.x,top:l.y+d,color:u,width:f})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=y.getRectPointList(t),o=r.length,h=this.getColor(t.attribute);r.forEach((g,s)=>{var f,l;if(e.save(),e.moveTo(g.x,g.y),e.beginPath(),this.hoverRectPointIndex===s?i=M+6:i=M,t.valid===!1?(e.strokeStyle=h==null?void 0:h.invalid.stroke,e.fillStyle=h==null?void 0:h.invalid.stroke):(e.strokeStyle=h==null?void 0:h.valid.stroke,e.fillStyle=h==null?void 0:h.valid.stroke),e.arc(g.x*this.zoom+this.currentPos.x,g.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===s){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),u=t.valid===!1?(f=c==null?void 0:c.invalid)==null?void 0:f.stroke:(l=c==null?void 0:c.valid)==null?void 0:l.stroke;e.strokeStyle=u,e.moveTo(r[s].x*this.zoom+this.currentPos.x,r[s].y*this.zoom+this.currentPos.y),e.lineTo(r[(s+1)%o].x*this.zoom+this.currentPos.x,r[(s+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,o,h,g;if(this.ctx&&t){const{ctx:s,style:f}=this,{hiddenText:l=!1}=f;s.save();const{strokeColor:c,fillColor:u,textColor:d}=this.getRenderStyle(t);s.font="lighter 14px Arial";let n="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(n=`${t.order}`),t.label&&this.hasMarkerConfig&&(n=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${B.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(n=`${n} ${C.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const a=S.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||k.drawText(this.canvas,{x:a.x,y:a.y-6},n,m(x({color:c,font:"normal normal 900 14px SourceHanSansCN-Regular"},T),{textMaxWidth:300}));const b=(g=(h=this.style)==null?void 0:h.width)!=null?g:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&k.drawRectWithFill(this.canvas,a,{color:u}),k.drawRect(this.canvas,a,{color:c,thickness:b,hiddenText:!0}),s.restore();let I=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(I=`${Math.round(t.width/this.zoom)} * ${Math.round(a.height/this.zoom)}`);const v=I.length*7;if(l||k.drawText(this.canvas,{x:a.x+a.width-v,y:a.y+a.height+15},I,x({color:d,font:"normal normal 600 14px Arial"},T)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,a.width-v);k.drawText(this.canvas,{x:a.x,y:a.y+a.height+20+z},t.textAttribute,x({color:d,font:"italic normal 900 14px Arial",textMaxWidth:Z},T))}}}renderMultiSelectedRect(){!this.isMultiMoveMode||this.rectList.forEach(t=>{this.renderDrawingRect(t),this.renderSelectedRect(t)})}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,S.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&(this.renderDrawingRect(r),this.renderSelectedRect(r),e.selectedRender&&e.selectedRender(this.canvas,S.changeRectByZoom(r,this.zoom,this.currentPos),this.getRenderStyle(r)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,S.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){switch(this.operationMode){case _.MultiMove:this.renderMultiSelectedRect();break;default:this.renderStaticRect(),this.renderCreatingRect()}}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(r=>r.id===this.selectedID?m(x({},r),{attribute:this.defaultAttribute}):r),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=m(x({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=L.Wait,this.setSelectedRectID(void 0),this.setOperationMode(_.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",A.getMessagesByLocale(P.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",A.getMessagesByLocale(P.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
|
|
1
|
+
import B from"lodash";import{distance as N}from"@turf/turf";import O from"../../utils/MathUtils.js";import w from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import{EDragStatus as y,ESortDirection as U,DEFAULT_TEXT_SHADOW as P}from"../../constant/annotation.js";import{EDragTarget as D,EOperationMode as K}from"../../constant/tool.js";import L from"../../constant/keyCode.js";import k from"../../locales/index.js";import{EMessage as M}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import E from"../../utils/tool/CanvasUtils.js";import f from"../../utils/tool/CommonToolUtils.js";import S from"../../utils/tool/DrawUtils.js";import V from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as T}from"../../utils/tool/polygonTool.js";import $ from"../../utils/uuid.js";import{BasicToolOperation as F}from"./basicToolOperation.js";import X from"./textAttributeClass.js";import Y from"./Selection.js";var G=Object.defineProperty,J=Object.defineProperties,q=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,H=(v,t,e)=>t in v?G(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,R=(v,t)=>{for(var e in t||(t={}))Q.call(t,e)&&H(v,e,t[e]);if(j)for(var e of j(t))tt.call(t,e)&&H(v,e,t[e]);return v},b=(v,t)=>J(v,q(t));const C=6;class W extends F{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const s=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===s);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const s=this.getCoordinateUnderZoom(e),r=C,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:l}=this;if(l&&I.isInRect(s,l,r,this.zoom))return l.id}const i=o.filter(l=>I.isInRect(s,l,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(n=>({size:n.width*n.height,id:n.id})).sort((n,c)=>n.size-c.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(p.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=f.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.selection=new Y(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=f.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=f.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const s=this.rectList.length;this.rectList=t,s!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,s]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),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(s=>s.id===this.selectedRectID?b(R({},s),{textAttribute:e}):s),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?w.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),C+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:s}=this,r=I.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const l=r[i],{length:n}=O.getFootOfPerpendicular(o,l.begin,l.end);n<C+10&&(e=i)}return e}getTextIconSvg(t=""){return p.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),s=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const o=D.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=D.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}}if(this.selection.isIdSelected(s)&&!this.drawingRect){const r=D.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=y.Start}}}appendOffsetRect(t,e){return b(R({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const s=t.reduce((r,o)=>r.concat(...I.getRectPointList(this.appendOffsetRect(o,e))),[]);return O.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,o,i;if(this.config.drawOutsideTarget!==!1)return!1;const l=this.getRectsBoundaries(t,e),n={y:l.top,x:l.left,height:l.bottom-l.top,width:l.right-l.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return I.isRectNotInPolygon(n,T(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const c=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(i=this.imgNode)==null?void 0:i.width};if(c)return[{x:l.left,y:l.top},{x:l.right,y:l.bottom}].some(a=>!I.isInRect(a,c))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=B.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>b(R({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=s.find(i=>i.id===r.id);return o||r}))}}onDragMoveAll(t){var e,s;!((s=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:s.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>b(R({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,s,r,o;if(!this.dragInfo)return;const i={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=y.Move,this.dragInfo.dragTarget===D.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const l=I.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:c,width:a,height:h}=l;let d=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case D.Point:{let g=n,x=c,u=a,m=h;switch(this.hoverRectPointIndex){case 0:{g=a-i.x<0?n+a:n+i.x,x=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-a),m=Math.abs(i.y-h);break}case 1:{g=a+i.x>0?n:n+a+i.x,x=h-i.y<0?c+h:c+i.y,u=Math.abs(a+i.x),m=Math.abs(h-i.y);break}case 2:{g=a+i.x>0?n:n+a+i.x,x=h+i.y>0?c:c+h+i.y,u=Math.abs(a+i.x),m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=a-i.x<0?n+a:n+i.x,x=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-a),m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}d=b(R({},d),{x:g,y:x,width:u,height:m})}break;case D.Line:{let g=n,x=c,u=a,m=h;switch(this.hoverRectEdgeIndex){case 0:{x=h-i.y<0?c+h:c+i.y,m=Math.abs(i.y-h);break}case 1:{g=a+i.x>0?n:n+a+i.x,u=Math.abs(a+i.x);break}case 2:{x=h+i.y>0?c:c+h+i.y,m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=a-i.x<0?n+a:n+i.x,u=Math.abs(i.x-a);break}default:return}d=b(R({},d),{x:g,y:x,width:u,height:m});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&I.isRectNotInPolygon(d,T(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,x=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,m=this.basicResult.height*this.zoom;if(d.x<g-.01||d.y<x-.01||d.width>g+u-d.x+.01||d.height>x+m-d.y+.01)return;if(d.x<g&&(d.x=g),d.y<x&&(d.y=x),d.width>g+u-d.x)switch(this.dragInfo.dragTarget){case D.Point:case D.Line:i.x>0&&i.y>0&&(d.width=g+u-d.x);break;default:return}if(d.height>x+m-d.y)switch(this.dragInfo.dragTarget){}}else if(d.x<0&&(d.x=0),d.y<0&&(d.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(d.x+d.width>((r=this.imgInfo)==null?void 0:r.width)+.01||d.y+d.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===d.id?I.getRectUnderZoom(d,1/this.zoom):g)),this.render()}onMouseMove(t){var e,s;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=w.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),l=this.hoverRectID;if(this.hoverRectID=i,i!==l&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:c}=this.firstClickCoord,{width:a,height:h}=this.drawingRect;if(a=Math.abs(n-o.x),h=Math.abs(c-o.y),o.x<n&&(n=o.x),o.y<c&&(c=o.y),this.config.drawOutsideTarget===!1){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&I.isRectNotInPolygon(b(R({},this.drawingRect),{x:n,y:c,width:a,height:h}),T(this.basicResult.pointList,this.zoom)))return;o.x<0&&(a=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(h=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(n+a>this.imgInfo.width&&(a=Math.abs(this.imgInfo.width-n)),c+h>this.imgInfo.height&&(h=Math.abs(this.imgInfo.height-c)))}this.drawingRect=b(R({},this.drawingRect),{x:n,y:c,width:a,height:h}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?b(R({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),r=w.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=b(R({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:$(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=f.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=b(R({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",k.getMessagesByLocale(M.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=p.getTextAttribute(this.rectList.filter(i=>f.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=b(R({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:f.getMaxOrder(this.rectList.filter(o=>f.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=R({},r),this.firstCurrentPos=R({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",k.getMessagesByLocale(M.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait,this.render();return}const s=this.getDrawingRectWithRectList();this.setRectList(s,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:s,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,s/=this.zoom,r/=this.zoom,[...this.rectList,b(R({},this.drawingRect),{x:t,y:e,width:s,height:r})]}rightMouseUp(t){var e,s;const r=this.getHoverRectID(t),o=this.rectList.find(i=>i.id===r);if(o&&this.setDefaultAttribute(o.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&N((s=this.dragInfo)==null?void 0:s.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(r,t.ctrlKey),this.hoverRectID="",(o==null?void 0:o.label)&&this.hasMarkerConfig){const i=f.getCurrentMarkerIndex(o.label,this.config.markerList);i>=0&&(this.setMarkerIndex(i),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===y.Move){this.dragInfo=void 0,this.dragStatus=y.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=f.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}onKeyDown(t){if(!f.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case L.Ctrl:this.drawingRect&&(this.drawingRect=b(R({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case L.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case L.Z:this.setIsHidden(!this.isHidden),this.render();break;case L.Delete:this.deleteSelectedRect();break;case L.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=U.ascend;t.shiftKey&&(s=U.descend);const[r,o]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const l=E.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>E.inViewPort({x:c.x,y:c.y},l));const n=f.getNextSelectedRectID(i,s,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const s=p.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){if(super.onKeyUp(t),!this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))switch(t.keyCode){case L.Ctrl:this.drawingRect&&(this.drawingRect=b(R({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let s,r;this.drawingRect&&this.firstClickCoord&&(s=I.getRectUnderZoom(this.drawingRect,1/e),r=w.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=I.getRectUnderZoom(s,this.zoom),this.firstClickCoord=w.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),s=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:s}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const s=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,o=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,o=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:s}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:s,y:r,width:o,height:i,attribute:l,valid:n}=e,c=o*this.zoom*.6,a=w.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),h=this.getColor(l),d=n?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new X({width:c,container:this.container,icon:this.getTextIconSvg(l),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:a.x,top:a.y+g,color:d,width:c})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=I.getRectPointList(t),o=r.length,i=this.getColor(t.attribute);r.forEach((l,n)=>{var c,a;if(e.save(),e.moveTo(l.x,l.y),e.beginPath(),this.hoverRectPointIndex===n?s=C+6:s=C,t.valid===!1?(e.strokeStyle=i==null?void 0:i.invalid.stroke,e.fillStyle=i==null?void 0:i.invalid.stroke):(e.strokeStyle=i==null?void 0:i.valid.stroke,e.fillStyle=i==null?void 0:i.valid.stroke),e.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const h=this.getColor(t.attribute),d=t.valid===!1?(c=h==null?void 0:h.invalid)==null?void 0:c.stroke:(a=h==null?void 0:h.valid)==null?void 0:a.stroke;e.strokeStyle=d,e.moveTo(r[n].x*this.zoom+this.currentPos.x,r[n].y*this.zoom+this.currentPos.y),e.lineTo(r[(n+1)%o].x*this.zoom+this.currentPos.x,r[(n+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,o,i,l;if(this.ctx&&t){const{ctx:n,style:c}=this,{hiddenText:a=!1}=c;n.save();const{strokeColor:h,fillColor:d,textColor:g}=this.getRenderStyle(t);n.font="lighter 14px Arial";let x="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(x=`${t.order}`),t.label&&this.hasMarkerConfig&&(x=`${f.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${V.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(x=`${x} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=w.changeRectByZoom(t,s?e:this.zoom,this.currentPos);a||S.drawText(this.canvas,{x:u.x,y:u.y-6},x,b(R({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},P),{textMaxWidth:300}));const m=(l=(i=this.style)==null?void 0:i.width)!=null?l:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&S.drawRectWithFill(this.canvas,u,{color:d}),S.drawRect(this.canvas,u,{color:h,thickness:m,hiddenText:!0}),n.restore();let A=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(A=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const _=A.length*7;if(a||S.drawText(this.canvas,{x:u.x+u.width-_,y:u.y+u.height+15},A,R({color:g,font:"normal normal 600 14px Arial"},P)),!a&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,u.width-_);S.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+z},t.textAttribute,R({color:g,font:"italic normal 900 14px Arial",textMaxWidth:Z},P))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=f.getRenderResultList(this.rectList,f.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||s==null||s.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,w.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,w.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))})}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,w.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(s=>this.selection.isIdSelected(s.id)?b(R({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=b(R({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait,this.setSelectedRectID(void 0),this.setOperationMode(K.General)}clearResult(t=!0){const e=this.rectList.filter(s=>s.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",k.getMessagesByLocale(M.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const s=this.rectList.find(r=>r.id===t);if((s==null?void 0:s.disableDelete)===!0){this.emit("messageInfo",k.getMessagesByLocale(M.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import d from"../../constant/keyCode.js";import{TEXT_ATTRIBUTE_LINE_HEIGHT as c,TEXT_ATTRIBUTE_MAX_LENGTH as u}from"../../constant/tool.js";const h=30,x=164;class
|
|
1
|
+
import{isEqual as d}from"lodash";import l from"../../constant/keyCode.js";import{TEXT_ATTRIBUTE_LINE_HEIGHT as c,TEXT_ATTRIBUTE_MAX_LENGTH as u}from"../../constant/tool.js";const h=30,x=164;class D{constructor(t){this.textKeyDown=a=>{switch(a.stopPropagation(),a.keyCode){case l.Enter:this.submitTextarea(),this.appendToContainer();break}};const{container:e,icon:i,color:r,getCurrentSelectedData:o,updateSelectedTextAttribute:n}=t,s=t.width||x;this.container=e,this.getCurrentSelectedData=o,this.updateSelectedTextAttribute=n,this._textAttributeDOM=this.initTextAttributeDOM(),this._iconDOM=this.initIconDOM(i),this._textDOM=this.initTextDOM(s,c),this._textareaDOM=this.initTextareaDOM(s,r),this.appendToContainer()}get isExit(){return this._textAttributeDOM?this.container.contains(this._textAttributeDOM):!1}get isExitTextareaDOM(){return this._textareaDOM?this.container.contains(this._textareaDOM):!1}updateIcon(t){this._iconDOM&&(this._iconDOM.innerHTML=t)}appendToContainer(){!this._textAttributeDOM||!this._textDOM||!this._iconDOM||(this.container.appendChild(this._textAttributeDOM),this._textAttributeDOM.appendChild(this._textDOM),this._textAttributeDOM.appendChild(this._iconDOM))}initTextAttributeDOM(){const t=document.createElement("div");return t.setAttribute("id","textArea"),t}initTextDOM(t,e){const i=document.createElement("span");return i.setAttribute("style",`
|
|
2
2
|
width: ${Math.max(t,h)}px;
|
|
3
|
-
line-height: ${
|
|
3
|
+
line-height: ${e}px;
|
|
4
4
|
word-break: break-all;
|
|
5
5
|
white-space: pre-line;
|
|
6
6
|
font-style: italic;
|
|
7
|
-
`),
|
|
7
|
+
`),i}initIconDOM(t){const e=document.createElement("div");return e.setAttribute("id","annotation_text"),e.innerHTML=t,e.addEventListener("mouseup",i=>{i.stopPropagation(),this.renderTextarea()}),e.addEventListener("mousedown",i=>{i.stopPropagation()}),e.addEventListener("contextmenu",i=>{i.stopPropagation()}),e.setAttribute("style",`
|
|
8
8
|
position: absolute;
|
|
9
9
|
left: -20px;
|
|
10
10
|
top: 4px;
|
|
11
11
|
cursor: pointer;
|
|
12
12
|
z-index: 10
|
|
13
|
-
`),
|
|
13
|
+
`),e}initTextareaDOM(t,e){const i=document.createElement("textarea");return i.addEventListener("click",r=>{r.stopPropagation()}),i.addEventListener("mouseup",r=>{r.stopPropagation()}),i.setAttribute("style",`
|
|
14
14
|
background-color: transparent;
|
|
15
15
|
border-radius: 5px;
|
|
16
|
-
border-color: ${
|
|
16
|
+
border-color: ${e};
|
|
17
17
|
outline: none;
|
|
18
18
|
resize: none;
|
|
19
19
|
width: ${Math.max(t,30)}px;
|
|
20
|
-
`),
|
|
20
|
+
`),i.setAttribute("maxLength",`${u}`),i}removeTextDOM(){!this._textAttributeDOM||this._textDOM&&this._textAttributeDOM.removeChild(this._textDOM)}removeIconDOM(){!this._textAttributeDOM||this._iconDOM&&this._textAttributeDOM.removeChild(this._iconDOM)}removeTextareaDOM(){var t,e;this._textareaDOM&&this._textAttributeDOM&&((t=this._textAttributeDOM)==null?void 0:t.contains(this._textareaDOM))&&((e=this._textAttributeDOM)==null||e.removeChild(this._textareaDOM))}submitTextarea(){var t;this._textareaDOM&&(this.updateSelectedTextAttribute((t=this._textareaDOM)==null?void 0:t.value),this.removeTextareaDOM(),this.clearTextAttribute())}clearTextAttribute(){this._textAttributeDOM&&this.container.contains(this._textAttributeDOM)&&this.container.removeChild(this._textAttributeDOM)}renderTextarea(){if(!this._textAttributeDOM||!this._textareaDOM)return;const t=this.getCurrentSelectedData();if(!t)return;const{width:e=x,textAttribute:i,color:r}=t;this._textareaDOM.value=`${i}`,this._textareaDOM.setAttribute("style",`
|
|
21
21
|
background-color: rgba(0,0,0,0.4);
|
|
22
22
|
border-radius: 5px;
|
|
23
23
|
border-color: ${r};
|
|
@@ -26,12 +26,12 @@ import d from"../../constant/keyCode.js";import{TEXT_ATTRIBUTE_LINE_HEIGHT as c,
|
|
|
26
26
|
font-style: italic;
|
|
27
27
|
font-weight: 900;
|
|
28
28
|
text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.6);
|
|
29
|
-
width: ${Math.max(
|
|
30
|
-
`),this._textareaDOM.setAttribute("maxLength",`${u}`),this._textAttributeDOM.appendChild(this._textareaDOM),this.removeIconDOM(),this.removeTextDOM(),this._textareaDOM.focus(),this._textareaDOM.addEventListener("keydown",this.textKeyDown)}update(t,
|
|
29
|
+
width: ${Math.max(e,h)}px;
|
|
30
|
+
`),this._textareaDOM.setAttribute("maxLength",`${u}`),this._textAttributeDOM.appendChild(this._textareaDOM),this.removeIconDOM(),this.removeTextDOM(),this._textareaDOM.focus(),this._textareaDOM.addEventListener("keydown",this.textKeyDown)}update(t,e){var i;const{left:r,top:o,color:n,width:s=x}=e,a=Math.max(s,h);(i=this._textAttributeDOM)==null||i.setAttribute("style",`
|
|
31
31
|
position: absolute;
|
|
32
32
|
width: ${a}px;
|
|
33
33
|
font-size: 14px;
|
|
34
34
|
left:${r}px;
|
|
35
35
|
top: ${o}px;
|
|
36
36
|
color: ${n};
|
|
37
|
-
`),this._textDOM&&(this._textDOM.innerHTML=`${t}`),this._textareaDOM&&(this._textareaDOM.style.width=`${a}px`,this._textareaDOM.style.borderColor=`${n}`)}changeSelected(){this.isExitTextareaDOM&&this.submitTextarea()}}export{
|
|
37
|
+
`),this._textDOM&&(this._textDOM.innerHTML=`${t}`),this._textareaDOM&&(this._textareaDOM.style.width=`${a}px`,this._textareaDOM.style.borderColor=`${n}`)}selectedIDsChanged(t,e){if(t.length===1&&e.length===1){if(d(t,e))return;this==null||this.changeSelected()}(e==null?void 0:e.length)!==1&&(this.removeTextareaDOM(),this==null||this.clearTextAttribute())}changeSelected(){this.isExitTextareaDOM&&this.submitTextarea()}}export{D as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as h}from"lodash";import{EStepType as u,ESortDirection as
|
|
1
|
+
import{isObject as h}from"lodash";import{EStepType as u,ESortDirection as c}from"../../constant/annotation.js";var v=Object.defineProperty,y=Object.defineProperties,_=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,p=(o,t,e)=>t in o?v(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,g=(o,t)=>{for(var e in t||(t={}))O.call(t,e)&&p(o,e,t[e]);if(d)for(var e of d(t))P.call(t,e)&&p(o,e,t[e]);return o},E=(o,t)=>y(o,_(t));class S{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===u.QUALITY_INSPECTION||r.type===u.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:i}=e;if(!r||!i)return!0;let n=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&i!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getNextSelectedRectID(t,e=c.ascend,r){let i=1;e===c.descend&&(i=-1);const n=t.sort((s,f)=>s.x-f.x==0?s.y-f.y:i*(s.x-f.x)),a=n.findIndex(s=>s.id===r),l=n.length;return n[(a+1)%l]}static getNextSelectedRectIDByEvent(t,e,r){const i=e.shiftKey?c.descend:c.ascend;return this.getNextSelectedRectID(t,i,r)}static getRenderResultList(t,e,r=[],i){const n=[];return[t.filter(l=>i&&i.includes(l.id)?(n.push(l),!1):!(r.length>0&&!r.includes(l==null?void 0:l.attribute)||this.isDifferSourceID(l==null?void 0:l.sourceID,e))),n]}static getSourceID(t){var e;const r="";return t&&(e=t==null?void 0:t.id)!=null?e:r}static findAllLine(t,e=!0){const r=[],i=[...t];i.length>=3&&e===!0&&i.push(g({},i[0]));for(let n=0;n<i.length;n++)i[n+1]&&r.push({point1:i[n],point2:i[n+1],pointIndex:n});return r}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],r){if((e==null?void 0:e.length)===0)return;let i=e.map((n,a)=>E(g({},n),{index:a}));if(typeof r=="number"&&r>0){const n=e[r];if(n&&t.every(a=>a.label!==n.value))return{label:n.value,index:r};i=[...i.slice(r,e.length),...i.slice(0,r)]}for(let n=0;n<i.length;n++)if(!t.some(a=>a.label===i[n].value))return{label:i[n].value,index:i[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(r=>t===r.value)}}S.jsonParser=(o,t={})=>{try{return typeof o=="string"?JSON.parse(o):h(o)?o:t}catch(e){return t}};export{S as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{polygon as S,difference as _,union as j}from"@turf/turf";import{ERotateDirection as B}from"../../constant/annotation.js";import F from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as M}from"../../constant/tool.js";import D from"./AxisUtils.js";import C from"../MathUtils.js";import z from"./LineToolUtils.js";var N=Object.defineProperty,b=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,O=(p,t,e)=>t in p?N(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,A=(p,t)=>{for(var e in t||(t={}))R.call(t,e)&&O(p,e,t[e]);if(b)for(var e of b(t))T.call(t,e)&&O(p,e,t[e]);return p};class g{static getHoverPolygonID(t,e,n=3,i=y.Line){let r="",l=Infinity;const o=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&o.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<l&&(r=s.id,l=u)})}),r}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,r,l,o)=>{const s=o[(l+1)%e];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,r,l,o,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,h)=>[...u,h.x,h.y],[]),.5,!0,20)),[o]=e;const c=e.length;for(r=1;r<=c;r++)s=e[r%c],t.x>Math.min(o.x,s.x)&&t.x<=Math.max(o.x,s.x)&&t.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(t.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||t.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=M){return this.createSmoothCurvePoints(t.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,e).map((i,r)=>{var l;const o=r/(M+1),s=Math.floor(o),c=(l=t[s])!=null?l:{};return A(s===o?A({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=M){if(t.length<4)return t;const r=[],l=t.slice(0);let o,s,c,u,h,m,v,L,P,E,a,d,f;for(n?(l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.push(t[0]),l.push(t[1])):(l.unshift(t[1]),l.unshift(t[0]),l.push(t[t.length-2]),l.push(t[t.length-1])),f=2;f<l.length-4;f+=2)for(c=(l[f+2]-l[f-2])*e,u=(l[f+4]-l[f-0])*e,h=(l[f+3]-l[f-1])*e,m=(l[f+5]-l[f+1])*e,d=0;d<=i;d++)a=d/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,L=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,E=Math.pow(a,3)-Math.pow(a,2),o=v*l[f]+L*l[f+2]+P*c+E*u,s=v*l[f+1]+L*l[f+3]+P*h+E*m,r.push(o),r.push(s);const I=[];for(let x=0;x<r.length-1;x+=2)I.push({x:r[x],y:r[x+1]});if(n)for(let x=0;x<i+1;x++){const w=I.shift();I.push(w)}return I}static getPolygonByID(t,e){return t.find(n=>n.id===e)}static getPolygonByIDs(t,e){
|
|
1
|
+
import{polygon as S,difference as _,union as j}from"@turf/turf";import{ERotateDirection as B}from"../../constant/annotation.js";import F from"./CommonToolUtils.js";import{ELineTypes as y,SEGMENT_NUMBER as M}from"../../constant/tool.js";import D from"./AxisUtils.js";import C from"../MathUtils.js";import z from"./LineToolUtils.js";var N=Object.defineProperty,b=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,O=(p,t,e)=>t in p?N(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,A=(p,t)=>{for(var e in t||(t={}))R.call(t,e)&&O(p,e,t[e]);if(b)for(var e of b(t))T.call(t,e)&&O(p,e,t[e]);return p};class g{static getHoverPolygonID(t,e,n=3,i=y.Line){let r="",l=Infinity;const o=D.axisArea(t,n);return e.forEach(s=>{s.pointList&&o.forEach(c=>{const u=this.calcPolygonSize(s.pointList);this.isInPolygon(c,s.pointList,i)&&u<l&&(r=s.id,l=u)})}),r}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,n=t.reduce((i,r,l,o)=>{const s=o[(l+1)%e];return i+r.x*s.y-s.x*r.y},0);return Math.abs(n)/2}static isInPolygon(t,e,n=y.Line){let i=0,r,l,o,s;e=[...e],n===y.Curve&&(e=this.createSmoothCurvePoints(e.reduce((u,h)=>[...u,h.x,h.y],[]),.5,!0,20)),[o]=e;const c=e.length;for(r=1;r<=c;r++)s=e[r%c],t.x>Math.min(o.x,s.x)&&t.x<=Math.max(o.x,s.x)&&t.y<=Math.max(o.y,s.y)&&o.x!==s.x&&(l=(t.x-o.x)*(s.y-o.y)/(s.x-o.x)+o.y,(o.y===s.y||t.y<=l)&&i++),o=s;return i%2!=0}static createSmoothCurvePointsFromPointList(t,e=M){return this.createSmoothCurvePoints(t.reduce((i,r)=>[...i,r.x,r.y],[]),.5,!1,e).map((i,r)=>{var l;const o=r/(M+1),s=Math.floor(o),c=(l=t[s])!=null?l:{};return A(s===o?A({},c):{specialEdge:c.specialEdge},i)})}static createSmoothCurvePoints(t,e=.5,n=!1,i=M){if(t.length<4)return t;const r=[],l=t.slice(0);let o,s,c,u,h,m,v,L,P,E,a,d,f;for(n?(l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.unshift(t[t.length-1]),l.unshift(t[t.length-2]),l.push(t[0]),l.push(t[1])):(l.unshift(t[1]),l.unshift(t[0]),l.push(t[t.length-2]),l.push(t[t.length-1])),f=2;f<l.length-4;f+=2)for(c=(l[f+2]-l[f-2])*e,u=(l[f+4]-l[f-0])*e,h=(l[f+3]-l[f-1])*e,m=(l[f+5]-l[f+1])*e,d=0;d<=i;d++)a=d/i,v=2*Math.pow(a,3)-3*Math.pow(a,2)+1,L=-(2*Math.pow(a,3))+3*Math.pow(a,2),P=Math.pow(a,3)-2*Math.pow(a,2)+a,E=Math.pow(a,3)-Math.pow(a,2),o=v*l[f]+L*l[f+2]+P*c+E*u,s=v*l[f+1]+L*l[f+3]+P*h+E*m,r.push(o),r.push(s);const I=[];for(let x=0;x<r.length-1;x+=2)I.push({x:r[x],y:r[x+1]});if(n)for(let x=0;x<i+1;x++){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=y.Line,i=3){let r=[...e];n===y.Curve?r=this.createSmoothCurvePoints(e.reduce((s,c)=>[...s,c.x,c.y],[]),.5,!0,M):n===y.Line&&r.push(r[0]);let l=-1,o=i;for(let s=0;s<r.length-1;s++){const{length:c}=C.getFootOfPerpendicular(t,r[s],r[s+1]);c<o&&(l=s,o=c)}return l===-1?-1:n===y.Curve?Math.floor(l/M):l}static getClosestPoint(t,e,n=y.Line,i=3,r){var l;let o=!1;const s=(l=r==null?void 0:r.isClose)!=null?l:!0;let c="",u=-1,h=Infinity,m=t;const v=20;let L=!1;return e.forEach(P=>{if(!L&&!!P.pointList)switch(n){case y.Line:F.findAllLine(P.pointList,s).forEach((a,d)=>{if(L)return;let{length:f,footPoint:I}=C.getFootOfPerpendicular(t,a.point1,a.point2);const x=C.getLineLength(a.point1,t),w=C.getLineLength(a.point2,t);x<i*2&&(I=a.point1,f=x,L=!0),w<i*2&&(I=a.point2,f=w,L=!0),f<h&&f<i&&(c=P.id,u=d,h=f,m=I,o=!0)});break;case y.Curve:{const E=this.createSmoothCurvePoints(P.pointList.reduce((a,d)=>[...a,d.x,d.y],[]),.5,s,v);for(let a=0;a<E.length-1;a++){const{length:d,footPoint:f}=C.getFootOfPerpendicular(t,E[a],E[a+1]);d<h&&d<i&&(c=P.id,u=Math.floor(a/(v+1)),h=d,m=f,o=!0)}}break}}),{dropFoot:m,closestEdgeIndex:u,closestPolygonID:c,hasClosed:o}}static isPointListInPolygon(t,e,n=y.Line){return t.every(i=>this.isInPolygon(i,e,n))}static isPointListOutSidePolygon(t,e,n=y.Line){return t.some(i=>!this.isInPolygon(i,e,n))}static getPolygonArea(t){let e=0;for(let n=0,i=t.length;n<i;n++){const r=t[n].x,l=t[n===t.length-1?0:n+1].y,o=t[n===t.length-1?0:n+1].x,s=t[n].y;e+=r*l*.5,e-=o*s*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,n){let i=1;return t===B.Anticlockwise&&(i=-1),i*=e,C.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 r=S([[...g.concatBeginAndEnd(t.map(o=>[o.x,o.y]))]]);return e.forEach(o=>{const s=S([[...g.concatBeginAndEnd(o.pointList.map(u=>[u.x,u.y]))]]),c=_(r,s);c&&(r=c)}),((i=(n=r==null?void 0:r.geometry)==null?void 0:n.coordinates.map(o=>{var s;return((s=r==null?void 0:r.geometry)==null?void 0:s.type)==="MultiPolygon"?o[0].reduce(g.deletePolygonLastPoint,[]):o.reduce(g.deletePolygonLastPoint,[])}))!=null?i:[]).reduce((o,s)=>{const c=s.length,u=s.filter((h,m)=>{const v=(m+1)%c;return!D.getIsInScope(h,s[v],1)});return u.length<3?o:[...o,u]},[])}catch(r){console.error(r)}}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=>g.isPointListInPolygon(t,n.pointList))}static clipPolygonFromWrapPolygon(t,e){const n=g.isPolygonClosewise(e),i=g.isPolygonClosewise(t),r=g.getClosePointDistanceFromPolygon(t[0],e),l=e[r];let o=[...e.slice(0,r),l,...t,t[0],...e.slice(r,e.length)];return n===i&&(o=[...e.slice(0,r),l,t[0],...t.reverse(),...e.slice(r,e.length)]),o}static isPolygonClosewise(t){const e=t.length;let n,i,r,l=0,o;if(e<3)return 0;for(n=0;n<e;n++)i=(n+1)%e,r=(n+2)%e,o=(t[i].x-t[n].x)*(t[r].y-t[i].y),o-=(t[i].y-t[n].y)*(t[r].x-t[i].x),o<0?l--:o>0&&l++;return l>0?1:l<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let n=Number.MAX_SAFE_INTEGER,i=-1;return e.forEach((r,l)=>{const o=z.calcDistance(t,r);o<n&&(n=o,i=l)}),i}static combinePolygonWithPolygon(t,e){var n,i;try{const r=S([[...g.concatBeginAndEnd(t.pointList.map(u=>[u.x,u.y]))]]),l=S([[...g.concatBeginAndEnd(e.pointList.map(u=>[u.x,u.y]))]]),o=j(r,l),s=[],c=t;if(((i=(n=o==null?void 0:o.geometry)==null?void 0:n.coordinates)==null?void 0:i.length)===1){s.push(e.id);const u=o==null?void 0:o.geometry.coordinates.map(h=>{var m;return((m=o==null?void 0:o.geometry)==null?void 0:m.type)==="MultiPolygon"?h[0].reduce(g.deletePolygonLastPoint,[]):h.reduce(g.deletePolygonLastPoint,[])})[0];c.pointList=u}return{newPolygon:c,unionList:s}}catch(r){console.error(r)}}}export{g as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0-alpha.1",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"typescript": "^4.2.3"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@labelbee/lb-utils": "1.7.
|
|
97
|
+
"@labelbee/lb-utils": "1.7.1-alpha.1",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|