@labelbee/lb-annotation 1.18.0-alpha.8 → 1.18.0

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";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,o)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,__spreadValues=(n,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(n,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(n,o,t[o]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:o,pcdPath:s,extraProps:P,config:m,checkMode:v,toolName:u,proxyMode:I}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(d=>__spreadValues({i:d},lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size)));return __spreadProps(__spreadValues({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(tool.EToolName.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:d}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:d,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return __spreadProps(__spreadValues({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(d=>lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return __spreadProps(__spreadValues({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const L=lbUtils.PointCloudUtils.getDefaultOrthographicParams(t),O=createEmptyImage(t),c=new Image;c.src=O;const h=new scheduler.ToolScheduler({container:o,size:t,toolName:u,proxyMode:I}),f=new CanvasScheduler.CanvasScheduler({container:o}),g=new index.PointCloud({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:L});s&&g.loadPCDFile(s),f.createCanvas(g.renderer.domElement);const C={size:t,config:JSON.stringify(__spreadProps(__spreadValues({},m),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:c,checkMode:v};P&&Object.assign(C,P);let p=[];scheduler.HybridToolUtils.isSingleTool(u)?p=[u]:p=u,p.forEach((a,l)=>{let i;if(a===tool.EToolName.PointCloudPolygon){const e=h.createOperation(a,c,C);e.eventBinding(),e.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=h.createOperation(a,c,__spreadProps(__spreadValues({},C),{textConfigurable:!1}));l===p.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=g,this.canvasScheduler=f,this.toolScheduler=h,this.config=m}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=__spreadProps(__spreadValues({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(lbUtils.PointCloudUtils.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=createEmptyImage(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),s=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=lbUtils.PointCloudUtils.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__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));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:s,extraProps:P,config:m,checkMode:I,toolName:u,proxyMode:v}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var o;const r=(o=i.pointList)==null?void 0:o.map(d=>__spreadValues({i:d},lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size)));return __spreadProps(__spreadValues({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(tool.EToolName.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(o=>{var r;const{polygon2d:d}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(o);return{id:o.id,sourceID:"",pointList:d,isRect:!0,valid:(r=o.valid)!=null?r:!0,attribute:o.attribute,trackID:o==null?void 0:o.trackID}});l&&(i=i.concat(l.map(o=>{var r;return __spreadProps(__spreadValues({},o),{pointList:(r=o==null?void 0:o.pointList)==null?void 0:r.map(d=>lbUtils.PointCloudUtils.transferWorld2Canvas(d,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var o;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return __spreadProps(__spreadValues({},r),{id:i.id,sourceID:"",valid:(o=i.valid)!=null?o:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const L=lbUtils.PointCloudUtils.getDefaultOrthographicParams(t),O=createEmptyImage(t),c=new Image;c.src=O;const h=new scheduler.ToolScheduler({container:e,size:t,toolName:u,proxyMode:v}),f=new CanvasScheduler.CanvasScheduler({container:e}),g=new index.PointCloud({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:L});s&&g.loadPCDFile(s),f.createCanvas(g.renderer.domElement);const C={size:t,config:JSON.stringify(__spreadProps(__spreadValues({},m),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:c,checkMode:I};P&&Object.assign(C,P);let p=[];scheduler.HybridToolUtils.isSingleTool(u)?p=[u]:p=u,p.forEach((a,l)=>{let i;if(a===tool.EToolName.PointCloudPolygon){const o=h.createOperation(a,c,C);o.eventBinding(),o.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=o,this.toolInstance.eventBinding(),this.pointCloud2dOperation=o}else i=h.createOperation(a,c,__spreadProps(__spreadValues({},C),{textConfigurable:!1}));l===p.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=g,this.canvasScheduler=f,this.toolScheduler=h,this.config=m}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=__spreadProps(__spreadValues({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(lbUtils.PointCloudUtils.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const e=createEmptyImage(t),s=new Image;s.src=e,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const e=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),s=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(e,s)}addLineListOnTopView(t){const e=lbUtils.PointCloudUtils.getLineListFromResultList(t);this.updateLineList(e)}addPointListOnTopView(t){const e=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(e)}updateData(t,e,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(e),this.addLineListOnTopView(e),this.addPointListOnTopView(e))}switchToCanvas(t){const e=this.toolScheduler.switchToCanvas(t);return e?(this.toolInstance.eventUnbinding(),e.eventBinding(),this.toolInstance=e,e):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(i,t,o)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,__spreadValues=(i,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(i,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(i,o,t[o]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},arraySwap=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},_HybridToolUtils=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=i=>_HybridToolUtils.isHybridTool(i)?i[i.length-1]:i;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=__spreadProps(__spreadValues({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const s=this.toolOperationList.length+1;return e.style.zIndex=`${s}`,e}getEmptyImage(t,o){const e=createEmptyImage({width:t,height:o}),s=new Image;return s.src=e,s}createOperation(t,o,e){var s;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let n;if(!t)n=new basicToolOperation.BasicToolOperation(h),r.style.zIndex="0",n.init();else{const p=EnhanceCommonToolUtils.getCurrentOperation(t);if(!p)return;n=new p(h)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.on("dragMove",({currentPos:p,zoom:d,imgInfo:u})=>{this.syncPosition(p,d,u,n)}),n.on("renderZoom",(p,d,u)=>{p&&d&&this.syncPosition(d,p,u,n)}),t?(this.container.appendChild(r),this.toolOperationList.push(n),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),n):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(n),this.toolOperationDom.unshift(r),n)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,s=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!s))return s.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=arraySwap(this.toolOperationList,o,e),this.toolOperationDom=arraySwap(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,s,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const n=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${n}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(s=this.toolOperationList[r]).clearCursorLine)==null||a.call(s),this.toolOperationList[r].render(),this.toolOperationList=arraySwap(this.toolOperationList,r,l),this.toolOperationDom=arraySwap(this.toolOperationDom,r,l),this.toolOperationNameList=arraySwap(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}exports.HybridToolUtils=HybridToolUtils,exports.ToolScheduler=ToolScheduler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(i,t,o)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,__spreadValues=(i,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(i,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(i,o,t[o]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},arraySwap=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},_HybridToolUtils=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=i=>_HybridToolUtils.isHybridTool(i)?i[i.length-1]:i;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=__spreadProps(__spreadValues({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){t.width&&t.height&&this.toolOperationDom.forEach(o=>{o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}),this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=createEmptyImage({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let s;if(!t)s=new basicToolOperation.BasicToolOperation(h),r.style.zIndex="0",s.init();else{const p=EnhanceCommonToolUtils.getCurrentOperation(t);if(!p)return;s=new p(h)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:d,imgInfo:u})=>{this.syncPosition(p,d,u,s)}),s.on("renderZoom",(p,d,u)=>{p&&d&&this.syncPosition(d,p,u,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=arraySwap(this.toolOperationList,o,e),this.toolOperationDom=arraySwap(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const s=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=arraySwap(this.toolOperationList,r,l),this.toolOperationDom=arraySwap(this.toolOperationDom,r,l),this.toolOperationNameList=arraySwap(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}exports.HybridToolUtils=HybridToolUtils,exports.ToolScheduler=ToolScheduler;
@@ -1 +1 @@
1
- import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:s,extraProps:L,config:O,checkMode:_,toolName:h,proxyMode:b}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(u=>c({i:u},d.transferWorld2Canvas(u,this.toolInstance.size)));return p(c({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(C.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:u,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(u=>d.transferWorld2Canvas(u,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(c({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l)};const D=d.getDefaultOrthographicParams(t),T=S(t),g=new Image;g.src=T;const f=new B({container:o,size:t,toolName:h,proxyMode:b}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});s&&P.loadPCDFile(s),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:_};L&&Object.assign(I,L);let m=[];E.isSingleTool(h)?m=[h]:m=h,m.forEach((a,l)=>{let i;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=f.createOperation(a,g,p(c({},I),{textConfigurable:!1}));l===m.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=f,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(d.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=S(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),s=d.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{J as PointCloudAnnotation};
1
+ import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as C,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},p=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class J{constructor({size:t,container:o,pcdPath:s,extraProps:L,config:O,checkMode:_,toolName:h,proxyMode:b}){this.updateLineList=a=>{const l=(a!=null?a:[]).map(i=>{var e;const r=(e=i.pointList)==null?void 0:e.map(u=>c({i:u},d.transferWorld2Canvas(u,this.toolInstance.size)));return p(c({},i),{pointList:r})});this.toolScheduler.updateDataByToolName(C.Line,l)},this.updatePolygonList=(a,l)=>{let i=a.map(e=>{var r;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:u,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute,trackID:e==null?void 0:e.trackID}});l&&(i=i.concat(l.map(e=>{var r;return p(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(u=>d.transferWorld2Canvas(u,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(C.PointCloudPolygon,i)},this.updatePointList=a=>{const l=a==null?void 0:a.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return p(c({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(C.Point,l)};const D=d.getDefaultOrthographicParams(t),T=S(t),g=new Image;g.src=T;const f=new B({container:o,size:t,toolName:h,proxyMode:b}),v=new A({container:o}),P=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});s&&P.loadPCDFile(s),v.createCanvas(P.renderer.domElement);const I={size:t,config:JSON.stringify(p(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:g,checkMode:_};L&&Object.assign(I,L);let m=[];E.isSingleTool(h)?m=[h]:m=h,m.forEach((a,l)=>{let i;if(a===C.PointCloudPolygon){const e=f.createOperation(a,g,I);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=f.createOperation(a,g,p(c({},I),{textConfigurable:!1}));l===m.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=P,this.canvasScheduler=v,this.toolScheduler=f,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}updateAttributeList(t){this.config=p(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(t)}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.toolScheduler.setSize(t),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(d.getDefaultOrthographicParams(t)),this.pointCloudInstance.render();const o=S(t),s=new Image;s.src=o,s.onload=()=>{this.toolInstance.setImgNode(s),this.toolInstance.initImgPos()}}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),s=d.getPolygonListFromResultList(t);this.updatePolygonList(o,s)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,s){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,s==null?void 0:s.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(this.toolInstance.eventUnbinding(),o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{J as PointCloudAnnotation};
@@ -1 +1 @@
1
- import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as D}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";var I=Object.defineProperty,M=Object.defineProperties,_=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?I(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,E=(i,t)=>{for(var o in t||(t={}))x.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))b.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>M(i,_(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(E({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let s;if(!t)s=new w(h),r.style.zIndex="0",s.init();else{const p=D(t);if(!p)return;s=new p(h)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,s)}),s.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const s=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,l),this.toolOperationDom=d(this.toolOperationDom,r,l),this.toolOperationNameList=d(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
1
+ import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as w}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as D}from"./toolOperation/basicToolOperation.js";var x=Object.defineProperty,I=Object.defineProperties,M=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?x(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,b=(i,t)=>{for(var o in t||(t={}))_.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))E.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>I(i,M(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(b({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){t.width&&t.height&&this.toolOperationDom.forEach(o=>{o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}),this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:h}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,h),l={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(l,e);let s;if(!t)s=new D(l),r.style.zIndex="0",s.init();else{const p=w(t);if(!p)return;s=new p(l)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,s)}),s.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,a;const h=this.toolOperationNameList.indexOf(t);if(h<0||this.toolOperationList.length<1||h>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,c=this.toolOperationDom[h],l=this.toolOperationDom[r];if(!c||!l)return;const s=l.style.zIndex;return l.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,h),this.toolOperationDom=d(this.toolOperationDom,r,h),this.toolOperationNameList=d(this.toolOperationNameList,r,h),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.18.0-alpha.8",
3
+ "version": "1.18.0",
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.10.0-alpha.4",
97
+ "@labelbee/lb-utils": "1.10.0",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",