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

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.
@@ -1 +1 @@
1
- "use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),defaultConfig=require("../../constant/defaultConfig.js"),polygonOperation=require("./polygonOperation.js"),basicToolOperation=require("./basicToolOperation.js");function _interopDefaultLegacy(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const a=(d=this.polygonList.find(u=>u.id===this.hoverID))==null?void 0:d.attribute;a&&a!==this.defaultAttribute&&this.emit("syncAttribute",a)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var d;if(o){const a=this.getPointCloudLineColor(o),u=AxisUtils.default.changePointListByZoom(o.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,u,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(u),(o==null?void 0:o.trackID)&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(a=>{if(this.selectedIDs.includes(a.id)){const u=o.find(c=>c.id===a.id);u&&d.push({newPolygon:a,originPolygon:u})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,s,l,r,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=CommonToolUtils.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(l=t.checkMode)!=null?l:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=__spreadProps(__spreadValues({},defaultConfig.polygonConfig),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(r=this.pointCloudConfig)==null?void 0:r.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=CommonToolUtils.jsonParser(t);this.pointCloudConfig=i,this.config=__spreadProps(__spreadValues({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=___default.default.cloneDeep(this.selectedPolygons),l=[];(i=this.selectedPolygons)==null||i.forEach((r,h)=>{r.pointList=r.pointList.map(o=>{var d,a;const{x:u,y:c}=o;return __spreadProps(__spreadValues({},o),{x:u+((d=t.x)!=null?d:0),y:c+((a=t.y)!=null?a:0)})}),l.push({originPolygon:s[h],newPolygon:r})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",l),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?lbUtils.INVALID_COLOR:lbUtils.toolStyleConverter.getColorFromConfig({attribute:t.attribute},__spreadProps(__spreadValues({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,l;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const r=this.getPointCloudLineColor(e),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:o?r:"transparent",strokeColor:r,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(l=this.config)==null?void 0:l.lineType}),(e==null?void 0:e.trackID)&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){const e=AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),i=e[e.length-1],s=t==null?void 0:t.trackID;DrawUtils.drawText(this.canvas,i,`${s}`,__spreadValues({textAlign:"center",color:"white"},annotation.DEFAULT_TEXT_OFFSET))}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),l=this.currentPolygonListByPattern.map(r=>__spreadProps(__spreadValues({},r),{pointList:AxisUtils.default.changePointListByZoom(r.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,l,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var l,r,h,o;return __spreadProps(__spreadValues({},s),{x:(r=(l=s.pointList[0])==null?void 0:l.x)!=null?r:0,y:(o=(h=s.pointList[0])==null?void 0:h.y)!=null?o:0})}),i=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const s=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(s,s),(i=this.basicCtx)==null||i.scale(s,s),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(basicToolOperation.BasicToolOperation.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:annotation.EDragTarget.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}}module.exports=PointCloud2dOperation;
1
+ "use strict";var _=require("lodash"),lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),defaultConfig=require("../../constant/defaultConfig.js"),polygonOperation=require("./polygonOperation.js"),basicToolOperation=require("./basicToolOperation.js");function _interopDefaultLegacy(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const a=(d=this.polygonList.find(u=>u.id===this.hoverID))==null?void 0:d.attribute;a&&a!==this.defaultAttribute&&this.emit("syncAttribute",a)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var d;if(o){const a=this.getPointCloudLineColor(o),u=AxisUtils.default.changePointListByZoom(o.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,u,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(u),_.isNumber(o==null?void 0:o.trackID)&&(o==null?void 0:o.trackID)>=0&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const d=[];this.polygonList.forEach(a=>{if(this.selectedIDs.includes(a.id)){const u=o.find(c=>c.id===a.id);u&&d.push({newPolygon:a,originPolygon:u})}}),this.emit("updatePolygonByDrag",d)}}};var e,i,s,l,r,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=CommonToolUtils.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(l=t.checkMode)!=null?l:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=__spreadProps(__spreadValues({},defaultConfig.polygonConfig),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(r=this.pointCloudConfig)==null?void 0:r.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=CommonToolUtils.jsonParser(t);this.pointCloudConfig=i,this.config=__spreadProps(__spreadValues({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=___default.default.cloneDeep(this.selectedPolygons),l=[];(i=this.selectedPolygons)==null||i.forEach((r,h)=>{r.pointList=r.pointList.map(o=>{var d,a;const{x:u,y:c}=o;return __spreadProps(__spreadValues({},o),{x:u+((d=t.x)!=null?d:0),y:c+((a=t.y)!=null?a:0)})}),l.push({originPolygon:s[h],newPolygon:r})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",l),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?lbUtils.INVALID_COLOR:lbUtils.toolStyleConverter.getColorFromConfig({attribute:t.attribute},__spreadProps(__spreadValues({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,l;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const r=this.getPointCloudLineColor(e),h=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);DrawUtils.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:o?r:"transparent",strokeColor:r,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(l=this.config)==null?void 0:l.lineType}),_.isNumber(e==null?void 0:e.trackID)&&(e==null?void 0:e.trackID)>=0&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){const e=AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),i=e[e.length-1],s=t==null?void 0:t.trackID;DrawUtils.drawText(this.canvas,i,`${s}`,__spreadValues({textAlign:"center",color:"white"},annotation.DEFAULT_TEXT_OFFSET))}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),l=this.currentPolygonListByPattern.map(r=>__spreadProps(__spreadValues({},r),{pointList:AxisUtils.default.changePointListByZoom(r.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,l,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var l,r,h,o;return __spreadProps(__spreadValues({},s),{x:(r=(l=s.pointList[0])==null?void 0:l.x)!=null?r:0,y:(o=(h=s.pointList[0])==null?void 0:h.y)!=null?o:0})}),i=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const s=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(s,s),(i=this.basicCtx)==null||i.scale(s,s),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(basicToolOperation.BasicToolOperation.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:annotation.EDragTarget.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}}module.exports=PointCloud2dOperation;
@@ -1 +1 @@
1
- import I from"lodash";import{INVALID_COLOR as b,toolStyleConverter as _}from"@labelbee/lb-utils";import{ESortDirection as C,EDragTarget as w,DEFAULT_TEXT_OFFSET as S}from"../../constant/annotation.js";import{EPolygonPattern as D}from"../../constant/tool.js";import f from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import L from"../../utils/tool/PolygonUtils.js";import{polygonConfig as A}from"../../constant/defaultConfig.js";import x from"./polygonOperation.js";import{BasicToolOperation as T}from"./basicToolOperation.js";var O=Object.defineProperty,k=Object.defineProperties,B=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,m=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,u=(d,t)=>{for(var e in t||(t={}))R.call(t,e)&&m(d,e,t[e]);if(v)for(var e of v(t))U.call(t,e)&&m(d,e,t[e]);return d},g=(d,t)=>k(d,B(t));class j extends x{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=s=>{var a;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,s.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const l=(a=this.polygonList.find(c=>c.id===this.hoverID))==null?void 0:a.attribute;l&&l!==this.defaultAttribute&&this.emit("syncAttribute",l)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=s=>{var a;if(s){const l=this.getPointCloudLineColor(s),c=f.changePointListByZoom(s.pointList,this.zoom,this.currentPos);P.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:l,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(a=this.config)==null?void 0:a.lineType}),s.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(c),(s==null?void 0:s.trackID)&&this.renderdrawTrackID(s))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:s}=this.dragInfo;if(this.selectedIDs.length>0){const a=[];this.polygonList.forEach(l=>{if(this.selectedIDs.includes(l.id)){const c=s.find(p=>p.id===l.id);c&&a.push({newPolygon:l,originPolygon:c})}}),this.emit("updatePolygonByDrag",a)}}};var e,i,o,r,n,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=y.jsonParser(t.config))!=null?o:{},this.hideAttributes=[],this.checkMode=(r=t.checkMode)!=null?r:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},A),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=y.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return L.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const o=I.cloneDeep(this.selectedPolygons),r=[];(i=this.selectedPolygons)==null||i.forEach((n,h)=>{n.pointList=n.pointList.map(s=>{var a,l;const{x:c,y:p}=s;return g(u({},s),{x:c+((a=t.x)!=null?a:0),y:p+((l=t.y)!=null?l:0)})}),r.push({originPolygon:o[h],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",r),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?b:_.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,o,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),h=f.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),s=this.highlightAttributeList.includes(e.attribute);P.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:s?n:"transparent",strokeColor:n,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),(e==null?void 0:e.trackID)&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){const e=f.changePointListByZoom(t.pointList,this.zoom,this.currentPos),i=e[e.length-1],o=t==null?void 0:t.trackID;P.drawText(this.canvas,i,`${o}`,u({textAlign:"center",color:"white"},S))}renderRectPolygonDirection(t){t.length<2||P.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===D.Rect?t.isRect===!0:this.pattern===D.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:f.changePointListByZoom(n.pointList,this.zoom)}));return L.getHoverPolygonID(i,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=C.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(o=>{var r,n,h,s;return g(u({},o),{x:(n=(r=o.pointList[0])==null?void 0:r.x)!=null?n:0,y:(s=(h=o.pointList[0])==null?void 0:h.y)!=null?s:0})}),i=y.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const o=this.selectedID;t!==o&&o&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(T.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:w.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}}export{j as default};
1
+ import b,{isNumber as D}from"lodash";import{INVALID_COLOR as _,toolStyleConverter as C}from"@labelbee/lb-utils";import{ESortDirection as w,EDragTarget as S,DEFAULT_TEXT_OFFSET as A}from"../../constant/annotation.js";import{EPolygonPattern as v}from"../../constant/tool.js";import f from"../../utils/tool/AxisUtils.js";import y from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import L from"../../utils/tool/PolygonUtils.js";import{polygonConfig as x}from"../../constant/defaultConfig.js";import T from"./polygonOperation.js";import{BasicToolOperation as O}from"./basicToolOperation.js";var k=Object.defineProperty,B=Object.defineProperties,R=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,I=(d,t,e)=>t in d?k(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,u=(d,t)=>{for(var e in t||(t={}))U.call(t,e)&&I(d,e,t[e]);if(m)for(var e of m(t))j.call(t,e)&&I(d,e,t[e]);return d},g=(d,t)=>B(d,R(t));class M extends T{constructor(t){super(t);this.highlightAttributeList=[],this.rightMouseUp=o=>{var a;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.selection.setSelectedIDs(this.hoverID,o.ctrlKey),this.emit("setSelectedIDs",this.selection.selectedIDs);const l=(a=this.polygonList.find(c=>c.id===this.hoverID))==null?void 0:a.attribute;l&&l!==this.defaultAttribute&&this.emit("syncAttribute",l)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=o=>{var a;if(o){const l=this.getPointCloudLineColor(o),c=f.changePointListByZoom(o.pointList,this.zoom,this.currentPos);P.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:l,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(a=this.config)==null?void 0:a.lineType}),o.isRect===!0&&this.showDirectionLine===!0&&(this.renderRectPolygonDirection(c),D(o==null?void 0:o.trackID)&&(o==null?void 0:o.trackID)>=0&&this.renderdrawTrackID(o))}},this.emitUpdatePolygonByDrag=()=>{if(this.dragInfo){const{originPolygonList:o}=this.dragInfo;if(this.selectedIDs.length>0){const a=[];this.polygonList.forEach(l=>{if(this.selectedIDs.includes(l.id)){const c=o.find(p=>p.id===l.id);c&&a.push({newPolygon:l,originPolygon:c})}}),this.emit("updatePolygonByDrag",a)}}};var e,i,s,r,n,h;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(s=y.jsonParser(t.config))!=null?s:{},this.hideAttributes=[],this.checkMode=(r=t.checkMode)!=null?r:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=g(u({},x),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(h=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?h:[]})}get getSelectedIDs(){return this.selectedIDs}get enableDrag(){return Boolean(this.selectedIDs.length>0&&this.dragInfo)}get visiblePolygonList(){return this.polygonList.filter(t=>!this.hideAttributes.includes(t.attribute))}setHiddenAttributes(t){this.hideAttributes=t}setConfig(t){var e;const i=y.jsonParser(t);this.pointCloudConfig=i,this.config=g(u({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygons(t?[t]:void 0)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selection.hardSetSelectedIDs(t),this.selectedIDs.length<2&&this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selection.setSelectedIDs(),this.emit("deleteSelectedIDs")}get selectedPolygons(){return L.getPolygonByIDs(this.polygonList,this.selectedIDs)}updateSelectedPolygonsPoints(t){var e,i;if(this.selectedPolygons&&((e=this.selectedPolygons)==null?void 0:e.length)>0){const s=b.cloneDeep(this.selectedPolygons),r=[];(i=this.selectedPolygons)==null||i.forEach((n,h)=>{n.pointList=n.pointList.map(o=>{var a,l;const{x:c,y:p}=o;return g(u({},o),{x:c+((a=t.x)!=null?a:0),y:p+((l=t.y)!=null?l:0)})}),r.push({originPolygon:s[h],newPolygon:n})}),this.emit("updateResult"),this.emit("updatePolygonByDrag",r),this.render(),this.history.pushHistory(this.polygonList)}}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t){return t.valid===!1?_:C.getColorFromConfig({attribute:t.attribute},g(u({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.visiblePolygonList)==null||t.forEach(e=>{var i,s,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const n=this.getPointCloudLineColor(e),h=f.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos),o=this.highlightAttributeList.includes(e.attribute);P.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:o?n:"transparent",strokeColor:n,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),D(e==null?void 0:e.trackID)&&(e==null?void 0:e.trackID)>=0&&this.renderdrawTrackID(e),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderdrawTrackID(t){const e=f.changePointListByZoom(t.pointList,this.zoom,this.currentPos),i=e[e.length-1],s=t==null?void 0:t.trackID;P.drawText(this.canvas,i,`${s}`,u({textAlign:"center",color:"white"},A))}renderRectPolygonDirection(t){t.length<2||P.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===v.Rect?t.isRect===!0:this.pattern===v.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(n=>g(u({},n),{pointList:f.changePointListByZoom(n.pointList,this.zoom)}));return L.getHoverPolygonID(i,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=w.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var r,n,h,o;return g(u({},s),{x:(n=(r=s.pointList[0])==null?void 0:r.x)!=null?n:0,y:(o=(h=s.pointList[0])==null?void 0:h.y)!=null?o:0})}),i=y.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}updateTextAttribute(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute()}setSelectedID(t){this.updateTextAttribute(t),this.selection.setSelectedIDs(t),this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const s=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(s,s),(i=this.basicCtx)==null||i.scale(s,s),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1,i){if(e){super.setPolygonValidAndRender(t,i);return}this.emit("validUpdate",t)}onMouseDown(t){if(O.prototype.onMouseDown.call(this,t)||this.forbidMouseOperation||t.ctrlKey===!0||t.button!==0)return;if(this.selectedIDs.length<2)return super.onMouseDown(t);const e=this.getCoordinateUnderZoom(t);this.dragInfo={dragStartCoord:e,dragTarget:S.Plane,initPointList:[],changePointIndex:[0],originPolygon:this.selectedPolygon,dragPrevCoord:e,originPolygonList:this.polygonList,selectedPolygons:this.selectedPolygons}}setResultAndSelectedID(t,e){this.setPolygonList(t),this.setSelectedIDs([e])}setHighlightAttribute(t){this.highlightAttributeList=[t],this.render()}}export{M as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.28.0-alpha.2",
3
+ "version": "1.28.0-alpha.3",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",