@labelbee/lb-annotation 1.23.0 → 1.24.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.
@@ -0,0 +1 @@
1
+ "use strict";var _rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory=require("./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js"),WorkerFactory=_rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory.createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7b25tZXNzYWdlPWZ1bmN0aW9uKGkpe2NvbnN0e3BvaW50czpzfT1pLmRhdGEsZT1uZXcgTWFwO2ZvcihsZXQgdD0wO3Q8cy5sZW5ndGg7dCs9Myl7Y29uc3Qgbz1zW3RdLGM9c1t0KzFdLGE9c1t0KzJdLG49YCR7TWF0aC5jZWlsKG8pfUAke01hdGguY2VpbChjKX1AJHtNYXRoLmNlaWwoYSl9YDtlLmhhcyhuKXx8ZS5zZXQobixbXSksZS5nZXQobikucHVzaCh7eDpvLHk6Yyx6OmF9KX10aGlzLnBvc3RNZXNzYWdlKHtpbmRleE1hcDplfSl9fSkoKTsKCg==",null,!1);module.exports=WorkerFactory;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var PCDLoader=require("./PCDLoader.js");class PointCloudCache{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=t=>new Promise((i,n)=>{const s=this.pointsMap.get(t),o=this.colorMap.get(t);if(s&&o){i({points:s,color:o});return}if(this.cacheList.length>this.MAX_SIZE){const e=this.cacheList.shift();e&&this.pointsMap.delete(e.src)}this.cacheList.push({src:t}),this.pcdLoader.load(t,e=>{const a=e.geometry.attributes.position.array,r=e.geometry.attributes.color.array;this.pointsMap.set(t,a),this.colorMap.set(t,r),i({points:a,color:r})},()=>{},e=>{n(e)})}),this.pcdLoader=new PCDLoader.PCDLoader,this.pointsMap=new Map,this.colorMap=new Map,this.cache2DHighlightIndex=new Map}static getInstance(){return this.instance==null&&(this.instance=new PointCloudCache),this.instance}updateColor(t,i){this.colorMap.set(t,i)}clearCache2DHighlightIndex(){this.cache2DHighlightIndex.clear()}}exports.PointCloudCache=PointCloudCache;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var generateIndexWorker=require("../../_virtual/generateIndexWorker.js"),PCDLoader=require("./PCDLoader.js"),__async=(h,e,s)=>new Promise((o,n)=>{var r=t=>{try{a(s.next(t))}catch(c){n(c)}},i=t=>{try{a(s.throw(t))}catch(c){n(c)}},a=t=>t.done?o(t.value):Promise.resolve(t.value).then(r,i);a((s=s.apply(h,e)).next())});class PointCloudCache{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=e=>new Promise((s,o)=>{const n=this.pointsMap.get(e),r=this.colorMap.get(e);if(n&&r){s({points:n,color:r});return}if(this.cacheList.length>this.MAX_SIZE){const i=this.cacheList.shift();i&&this.pointsMap.delete(i.src)}this.cacheList.push({src:e}),this.pcdLoader.load(e,i=>{const a=i.geometry.attributes.position.array,t=i.geometry.attributes.color.array;this.pointsMap.set(e,a),this.colorMap.set(e,t),s({points:a,color:t})},()=>{},i=>{o(i)})}),this.loadIndexMap=(e,s)=>__async(this,null,function*(){const o=this.cacheIndexMap.get(e);return new Promise(n=>{if(o)return n(o);if(window.Worker){const r=new generateIndexWorker({type:"module"});r.postMessage({points:s}),r.onmessage=i=>{const{indexMap:a}=i.data;if(this.cacheIndexMap.set(e,a),this.cacheIndexMap.size>this.MAX_SIZE){const t=Array.from(this.cacheIndexMap.keys())[0];this.cacheIndexMap.delete(t)}n(a),r.terminate()}}})}),this.pcdLoader=new PCDLoader.PCDLoader,this.pointsMap=new Map,this.colorMap=new Map,this.cacheIndexMap=new Map,this.cache2DHighlightIndex=new Map}static getInstance(){return this.instance==null&&(this.instance=new PointCloudCache),this.instance}updateColor(e,s){this.colorMap.set(e,s)}clearCache2DHighlightIndex(){this.cache2DHighlightIndex.clear()}}exports.PointCloudCache=PointCloudCache;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(f){if(f&&f.__esModule)return f;var t=Object.create(null);return f&&Object.keys(f).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return f[e]}})}}),t.default=f,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t)),__async=(f,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(n){r(n)}},a=l=>{try{o(e.throw(l))}catch(n){r(n)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);o((e=e.apply(f,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:o,checkMode:l}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=n,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),w=new THREE__namespace.MeshBasicMaterial({color:c}),b=new THREE__namespace.Mesh(x,w);b.position.set(g.x,g.y,g.z),y.add(b),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:h}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,h)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:g,rotation:y}=n,x=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(m,p,g),b=new THREE__namespace.MeshBasicMaterial({color:"blue"}),C=new THREE__namespace.Mesh(w,b),P=new THREE__namespace.BoxHelper(C,c),M=this.generateBoxArrow(n),v=this.generateBoxTrackID(n);v&&x.add(v),x.add(P),x.add(M),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${d}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),ImgUtils=require("../../utils/ImgUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(f){if(f&&f.__esModule)return f;var t=Object.create(null);return f&&Object.keys(f).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return f[e]}})}}),t.default=f,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t)),__async=(f,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(n){r(n)}},h=l=>{try{o(e.throw(l))}catch(n){r(n)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,h);o((e=e.apply(f,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:l}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var a;const d=(a=n.id)!=null?a:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=n,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),w=new THREE__namespace.MeshBasicMaterial({color:c}),C=new THREE__namespace.Mesh(x,w);C.position.set(g.x,g.y,g.z),y.add(C),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:a}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,a)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var a;const d=(a=n.id)!=null?a:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:g,rotation:y}=n,x=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(m,p,g),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),b=new THREE__namespace.Mesh(w,C),P=new THREE__namespace.BoxHelper(b,c),M=this.generateBoxArrow(n),v=this.generateBoxTrackID(n);v&&x.add(v),x.add(P),x.add(M),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${d}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,4 @@
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,d=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,a){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,a),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:a}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:a,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.filterPreResult=(n,c,a)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(m=>{const p=a.map(g=>{const y=MathUtils.default.calculatePointsInsideBox({indexMap:u,polygon:matrix.getCuboidFromPointCloudBox(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),x=y>=c.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},g),{valid:x,count:y})});m(p)})}),this.loadPCDFileByBox=(n,c,a)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=a!=null?a:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const b=new THREE__namespace.Points(C.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),a=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,a,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const a=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(a);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const a=this.scene.getObjectByName(this.pointCloudObjectName);if(!a)return;const d=a.material.uniforms.pointSize.value;n?a.material.uniforms.pointSize.value=Math.min(d*1.2,10):a.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(a.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),a.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,a=-100,d=500/c;return{left:h,right:o,top:l,bottom:n,near:c,far:a,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const a={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(a),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:a}=c.data,d=new THREE__namespace.BufferAttribute(a,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==a.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,a),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(a),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:l,depth:n,rotation:c}=i,{fill:a}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:a,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,h);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:a,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((a,d)=>a.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:a})=>a>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((a,d)=>a.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((a,d)=>a.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,a)=>{const d=r[a+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[a]||u<i[a].distance)&&(i[a]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((l,n)=>{const c=r[n],a=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,a],p2:s[n+1].point,line2:[a,d]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,a=0,d=[],u=[];const m=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,a=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:a,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:a,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2},a={x:e-h/2,y:i+s/2,z:r-o/2};return[l,n,c,a]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r-o/2},a={x:e-h/2,y:i-s/2,z:r+o/2};return[l,n,c,a]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i-s/2,z:r+o/2},a={x:e-h/2,y:i+s/2,z:r+o/2};return[l,n,c,a]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(a=>new THREE__namespace.Vector3(a.x,a.y,a.z)).map(a=>a.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),a=this.containerWidth/(h*2),d=this.containerHeight/(h*2);return{point2d:c,zoom:Math.min(a,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[l,n,c,a]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(a).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const l=r.getZ(o);s.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),tool=require("../../constant/tool.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),MathUtils=require("../../utils/MathUtils.js"),basicToolOperation=require("./basicToolOperation.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js");function _interopDefaultLegacy(a){return a&&typeof a=="object"&&"default"in a?a:{default:a}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(a,e,t)=>e in a?__defProp(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,__spreadValues=(a,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(a,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(a,t,e[t]);return a},__spreadProps=(a,e)=>__defProps(a,__getOwnPropDescs(e)),EStatus;(function(a){a[a.Create=0]="Create",a[a.Active=1]="Active",a[a.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends basicToolOperation.BasicToolOperation{constructor(e){super(e);this.drawActivatedLine=(t,i,s)=>{const n=this.isCreate?___default.default.cloneDeep([{pointList:this.activeLine,order:this.nextOrder(),attribute:this.defaultAttribute,valid:this.isLineValid}]):___default.default.cloneDeep(this.selectedLines),o=this.isActiveLineValid();n.forEach(r=>{if((r==null?void 0:r.pointList)&&(r.pointList=r.pointList.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l)))),!r.pointList)return;const h=this.getLineColorByAttribute({attribute:r.attribute,valid:r.valid});return this.selectedLines.length>0&&(this.drawLineLength(r.pointList,h),this.renderActiveArea(MathUtils.default.calcViewportBoundaries(r.pointList,this.isCurve,SEGMENT_NUMBER))),this.drawLine(r.pointList,t,h,!0,!0),r.pointList[0]&&this.drawLineNumber(r.pointList[0],r.order,h,"",this.defaultAttribute,o),t&&this.isCreate&&this.arc(t,POINT_RADIUS,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,h),r})},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.selectedID){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>LineToolUtils.default.calcDistance(this.coordUtils.getRenderCoord(o),t)<=POINT_ACTIVE_RADIUS);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,t)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.updatedLine={id:"",valid:!1,order:0},this.toolName="lineTool",this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,i,s,n=!0,o=!1,r)=>{const h=polygonTool.createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=s.color,n&&(t.lineWidth=s.lineWidth),o&&LineToolUtils.default.setReferenceCtx(t),i.forEach(({specialEdge:l},d)=>{const u=h.splice(0,SEGMENT_NUMBER+1);t.save(),t.beginPath(),r===d&&(t.lineWidth=4),u.forEach(({x:c,y:f},v)=>{const L=v>0?"lineTo":"moveTo";l&&LineToolUtils.default.setSpecialEdgeStyle(t),t[L](c,f)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,i,s,n=!1,o=!1)=>{const r=i?t.concat(i):t,h={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.default.drawCurveLine(this.ctx,r,h,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(r,h,o),n&&t.forEach(l=>{var d,u;const c=l.id,f=c&&[this.hoverPointID,(d=this.selectedPoint)==null?void 0:d.id].includes(c)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(l,f,s),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(c)||this.arc(l,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(t,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.default.setReferenceCtx(n),t.forEach((o,r)=>{if(n.beginPath(),r>0){const h=t[r-1];n.save(),(h==null?void 0:h.specialEdge)&&LineToolUtils.default.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===r&&(n.lineWidth=4),n.moveTo(h.x,h.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const t=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(i=>{if(!this.selection.isIdSelected(i.id)&&i.pointList){i.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:s,label:n}=i,o=s,r=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,r,!1),this.drawLineNumber(i.pointList[0],o,r,n,i.attribute,i.valid),i.id!==this.textEditingID&&(this.drawLineTextAttribute(i.pointList[1],r,i==null?void 0:i.textAttribute),this.drawLineLength(i.pointList,r))}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!1),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+t,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(t,i))},this.getSelectedLinesArea=()=>MathUtils.default.calcViewportBoundaries(this.selectedLines.reduce((t,i)=>(i==null?void 0:i.pointList)?t.concat(...i==null?void 0:i.pointList):t,[])),this.moveLineInRectRange=(t,i,s,n)=>{if(this.selectedLines.length===0)return;const{top:o,left:r,right:h,bottom:l}=this.getSelectedLinesArea(),d=[r,h].map(g=>___default.default.isNumber(g)?g+t:0),u=[o,l].map(g=>___default.default.isNumber(g)?g+i:0),c=r>=0&&h&&MathUtils.default.isInRange(d,s),f=o>=0&&l&&MathUtils.default.isInRange(u,n),v=c?t:0,L=f?i:0;this.lineDragging=!0,this.moveActiveArea(v,L)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;if(LineToolUtils.default.lineLengthSum(this.activeLine||[])<this.minLength)return this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinLengthLimitErrorNotice,this.lang)}${this.minLength}`),!0;this.stopLineCreating(!0);return}const i=this.findHoverLine(this.getCoordinate(t));this.setSelectedLineID(i==null?void 0:i.id,t.ctrlKey),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedIDs.length>0){const t=this.lineList.find(s=>s.id===this.selectedIDs[0]),i=t==null?void 0:t.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=t=>{const i=this.getCoordinate(t),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(t,i);if(this.isCreate||this.isNone){this.setCreateStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreateStatusAndAddPoint(n);return}if(t.shiftKey){this.updateLineSegmentSpecial(i);return}this.coordsInsideActiveArea&&t.ctrlKey&&this.setInvalidLine(this.selectedID),this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,!this.selection.triggerKeyboardEvent(t,this.setLineList)){if(t.keyCode===keyCode.Esc){this.stopLineCreating(!1);return}if(this.selectedLine){if(t.key==="Delete"){this.deleteLine();return}if(t.key==="f"){this.setInvalidLine(this.selectedID);return}if(t.key===" "){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)}},this.onRightDblClick=t=>{super.onRightDblClick(t);const i=this.getCoordinate(t);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const i=t.length!==this.lineListLen;this.lineList=t,i&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(e.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.selection=new Selection(this),this.dependToolConfig={lineType:tool.ELineTypes.Line},this.historyDisabled=!1}get selectedLines(){return this.lineList.filter(e=>this.selection.isIdSelected(e.id))}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLine(){return this.lineList.find(e=>e.id===this.selectedID)}get isCreate(){return this.status===0}get isActive(){return this.selectedLines.length>0}get isNone(){return!this.isCreate&&this.selectedIDs.length===0}get isCurve(){return this.config.lineType===tool.ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===tool.ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===tool.EToolName.Polygon}get isDependRect(){return this.dependToolName===tool.EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(e=>this.attributeLockList.includes((e==null?void 0:e.attribute)||"")):this.lineList}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get enableOutOfTarget(){return this.config.enableOutOfTarget||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var e;return(e=this.config.showOrder)!=null?e:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get minLength(){var e;return((e=this.config)==null?void 0:e.minLength)||0}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const e=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var i;return(i=t==null?void 0:t.pointList)==null?void 0:i.some(s=>CanvasUtils.inViewPort(s,e))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var e,t;return(t=(e=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(e,t=!1){if(e!==this.status){if(t){let i="";this.textCheckType===tool.ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.default.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=e,this.lineStatusChanged()}}isInBasicPolygon(e){var t,i;return polygonTool.isInPolygon(e,((t=this.basicResult)==null?void 0:t.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:e}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===tool.ELineTypes.Curve?polygonTool.createSmoothCurvePoints(e.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):e}getNextCoordByRenderCoord(e){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(e))}getNextCoordByAbsCoord(e){var t;const i=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(e,i):e}pointInLine(e,t,i){return e.filter(s=>s).length<2?!1:e.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(e[n-1]),r=this.coordUtils.getRenderCoord(s);return LineToolUtils.default.isInLine(t,o,r,i)})}arc(e,t=POINT_RADIUS,i){var s,n,o,r,h,l;if(this.ctx){const{x:d,y:u}=e;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(o=this.ctx)==null||o.arc(d,u,t,0,360),(r=this.ctx)==null||r.closePath(),(h=this.ctx)==null||h.fill(),(l=this.ctx)==null||l.restore()}}renderActiveArea({top:e,left:t,right:i,bottom:s}){this.ctx&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(t,e,i-t,s-e),this.ctx.stroke(),this.ctx.restore())}addLinePoint(e){var t,i,s,n;this.arc(e),(t=this.activeLine)==null||t.push(__spreadProps(__spreadValues({},e),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreateStatusAndAddPoint(e,t=!1){this.updateStatus(0,t),this.addLinePoint(e)}isActiveLineValid(){var e;return this.selectedID?(e=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:e.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(e,t=!1){return StyleUtils.getStrokeAndFill(this.getColor(e.attribute),e.valid,{isSelected:t}).stroke}drawLineNumber(e,t=1,i,s="",n,o=!0){var r,h,l;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let d=this.showOrder?t.toString():`${s}`;if(this.attributeConfigurable){const u=n?(l=(h=(r=this.attributeList)==null?void 0:r.find(c=>c.value===n))==null?void 0:h.key)!=null?l:n:"";d=[d,`${!o&&u?"\u65E0\u6548":""}${u}`].filter(c=>c).join("_")}this.drawText(e,d,i)}}drawLineTextAttribute(e,t,i){if(e&&i)return this.drawText(e,i,t,200)}drawLineLength(e,t){var i;if(((i=this.config)==null?void 0:i.showLineLength)&&e){const s=e.reduce((o,r,h)=>h<=0||!e[h-1].actual||!r.actual?o:o+LineToolUtils.default.calcDistance(e[h-1].actual,r.actual),0),n=e[e.length-1];this.drawText(n,`l = ${s.toFixed(2)}`,t)}}drawText(e,t,i,s){var n,o;this.ctx&&((n=this.ctx)==null||n.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=i,this.ctx.strokeStyle=i,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,s?DrawUtils.wrapText(this.canvas,t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y,s):this.ctx.fillText(t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y),(o=this.ctx)==null||o.restore())}moveActiveArea(e,t){this.selectedLines.length>0&&(this.selectedLines.forEach(i=>{var s;(s=i.pointList)==null||s.forEach(n=>Object.assign(n,{x:n.x+e,y:n.y+t}))}),this.render()),this.emit("dataUpdated",this.lineList,this.selectedIDs)}findHoveredPoint(e){if(!!this.activeLine)return this.activeLine.find(t=>{const i=this.coordUtils.getRenderCoord(t);return LineToolUtils.default.calcDistance(i,e)<=POINT_ACTIVE_RADIUS})}findHoverLine(e){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,r)=>{if(r===0)return!1;const h=this.coordUtils.getRenderCoord(o),l=this.coordUtils.getRenderCoord(s[r-1]);return LineToolUtils.default.isInLine(e,h,l,n)})})}getAdsorptionPoint(e){let t,i,s;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const r=this.findNearestPoint(n,e);if(r){if(r.minDistance===0){t=r.point;return}(i===void 0||r.minDistance<i)&&(t=r.point,i=r.minDistance)}}),s||t}findNearestPoint(e,t,i=7){let s;const n=i;for(let o=1;o<=e.length-1;o++){const r=this.coordUtils.getRenderCoord(e[o]),h=this.coordUtils.getRenderCoord(e[o-1]),{length:l,footPoint:d}=MathUtils.default.getFootOfPerpendicular(t,r,h),u=LineToolUtils.default.calcTwoPointDistance(r,t),c=LineToolUtils.default.calcTwoPointDistance(h,t);if(u<=i*2){s=r,i=0;break}if(c<=i*2){s=h,i=0;break}l<i&&(s=d,i=l)}return s?{point:s,minDistance:n}:void 0}getPointList(e){return this.isCurve?polygonTool.createSmoothCurvePointsFromPointList(e,SEGMENT_NUMBER):e}moveSelectedLine(e){const t=(e.x-this.prevAxis.x)/this.zoom,i=(e.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,i);return}if(this.isDependPolygon){this.moveLineInPolygon(t,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:r,width:h,height:l}=this.basicResult;s=[o,o+h],n=[r,r+l]}this.moveLineInRectRange(t,i,s,n)}moveSelectPoint(e){if(!this.selectedPoint)return;const t=e.x-this.prevAxis.x,i=e.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(e,t){var i;const s=!!e.shiftKey,n=e.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return LineToolUtils.default.getVHPoint(o,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(t):t}getNextPoint(e,t){const i=this.getCoordByConfig(e,t)||t;return this.enableOutOfTarget?this.coordUtils.getAbsCoord(i):this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(e){const t=this.getCoordinate(e),i=e.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(e,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!e.altKey)){const s=this.getAdsorptionPoint(t);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(e){if(super.onMouseMove(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);this.mouseMoveHandler(e),this.prevAxis=t}setActiveLine(e){this.activeLine=e?___default.default.cloneDeep(e):void 0}historyChanged(e){if(this.historyDisabled)return;const t=`${e}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const i=this.actionsHistory&&this.actionsHistory[e]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[t]){const i=this.history[e](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(e){if(this.isDependPolygon)return this.isInBasicPolygon(e);if(this.isDependRect){const{x:t,y:i,width:s,height:n}=this.basicResult,o=[t,t+s],r=[i,i+n];return MathUtils.default.isInRange(e.x,o)&&MathUtils.default.isInRange(e.y,r)}return MathUtils.default.isInRange(e.x,[0,this.imageSize.width])&&MathUtils.default.isInRange(e.y,[0,this.imageSize.height])}getPointInsertIndex(e,t){if(e&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,r=this.isCurve?i.slice((n-1)*(SEGMENT_NUMBER+1),n*(SEGMENT_NUMBER+1)):[o,s];return this.pointInLine(r,e,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var e;return this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(e){const t=this.getPointInsertIndex(e,2)-1;if(t>-1){const i=this.activeLine[t];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var e;const t=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&i&&(this.activeLine.splice(t,0,__spreadProps(__spreadValues({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList),this.render(),this.cursor=void 0)}isCoordOnSelectedArea(e){return this.selectedLines.some(t=>LineToolUtils.default.inArea(MathUtils.default.calcViewportBoundaries(t.pointList),this.coordUtils.getAbsCoord(e)))}onMouseDown(e){if(super.onMouseDown(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);if(this.isMousedown=!0,this.prevAxis=t,e.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.selectedLines.length>0?this.isCoordOnSelectedArea(t):!1,this.lineDragging=!1}lineHasChanged(){const e=this.lineList.find(t=>t.id===this.selectedID);return e?JSON.stringify(e.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const e=this.lineList.find(t=>t.id===this.selectedID);e&&(e.pointList=___default.default.cloneDeep(this.activeLine),this.updatedLine=e,this.emit("dataUpdated",this.lineList))}onMouseUp(e){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(e)||this.forbidMouseOperation||!this.imgInfo){t();return}e.which===1&&this.onLeftClick(e),e.which===3&&this.onRightClick(e),t()}isTextValid(e){return AttributeUtils.default.textAttributeValidate(this.textCheckType,this.customFormat,e)}createLineData(){const e=uuid(),t={pointList:___default.default.cloneDeep(this.activeLine),id:e,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(e=!0){var t,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let r;if(e){if(this.selectedID){const h=this.lineList.find(l=>l.id===this.selectedID);r=this.selectedID,h&&(h.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();r=h.id,this.setLineList([...this.lineList,h]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?(this.activeLine=[],this.setSelectedLineID(r,!1,!1)):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.render()}setNoneStatus(e=!0){e&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(e,t){this.isShift=t!=null?t:e.keyCode===keyCode.Shift}continueToEdit(){var e,t;((e=this.selectedLine)==null?void 0:e.pointList)&&(this.updateStatus(0),this.cursor=void 0,this.setActiveLine(this.selectedLine.pointList),(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render())}setInvalidLineOnCreating(e){if(this.selectedID&&e.keyCode!==keyCode.Ctrl||!this.isCreate)return;const t=!e.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(e){if(super.onKeyDown(e),this.setKeyDownStatus(e),e.keyCode===keyCode.Z&&!e.ctrlKey&&this.toggleIsHide(),e.keyCode===keyCode.Shift&&this.render(),e.keyCode===keyCode.Tab){e.preventDefault(),this.selectToNextLine(e);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(e),this.config.attributeConfigurable){const t=AttributeUtils.default.getAttributeByKeycode(e.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(e){const t=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,r;return __spreadProps(__spreadValues({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(r=(o=i.pointList[0])==null?void 0:o.y)!=null?r:0})}),e,this.selectedID);t&&this.selection.setSelectedIDs(t.id)}keyboardEventWhileLineCreating(e){!this.isCreate||(e.keyCode===keyCode.Ctrl&&this.setInvalidLineOnCreating(e),[keyCode.Shift,keyCode.Alt].includes(e.keyCode)&&this.renderNextPoint(e,this.prevAxis))}renderNextPoint(e,t){const i=this.coordUtils.getRenderCoord(this.getNextPoint(e,t));this.render(i)}deleteSelectedLine(e){var t;if(this.selectedLine){const i=MathUtils.default.calcViewportBoundaries((t=this.selectedLine)==null?void 0:t.pointList,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.default.inArea(i,this.coordUtils.getAbsCoord(e))&&this.deleteLine()}}deleteSelectedLinePoint(e){var t;this.pointsWithinRange(this.activeLine.length-1)&&e&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==e)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var e;this.lineList=this.lineList.filter(t=>!this.selection.isIdSelected(t.id)),(e=this.history)==null||e.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(e,t,i=!0){var s;const n=this.lineList.find(o=>o.id===e);n&&(n.valid=t!==void 0?t:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),this.emit("dataUpdated",this.lineList),i&&this.render())}empty(){var e,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(e=this.actionsHistory)==null||e.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(e){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedIDs.length>0&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(e){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",e),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",e))}setLineAttribute(e,t){this.selectedIDs.length>0&&(this.lineList.forEach(i=>{this.selection.isIdSelected(i.id)&&(i[e]=t)}),this.render())}updateAttribute(e){this.emit("updateAttribute",e)}updateLineAttributes(e){var t;if(this.attributeConfigurable&&e){const i=(e==null?void 0:e.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&e){const i=(e==null?void 0:e.textAttribute)||"";this.updateTextAttribute(i)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(e){if(this.selectedID){const t=this.lineList.find(i=>i.id===this.selectedID);t&&(t.textAttribute=e)}this.emit("updateText",e)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(e){this.textEditingID=e,this.render()}updateAttrWhileIDChanged(e){if(e){const t=this.lineList.find(i=>i.id===e);t&&this.setDefaultAttribute(t.attribute)}}setSelectedLineID(e,t=!1,i=!0){this.selection.setSelectedIDs(e,t),this.status=1,i&&e&&this.updateAttrWhileIDChanged(this.selectedID),this.selectedLine&&this.setActiveLine(this.selectedLine.pointList),this.selectedIDs.length===0&&this.setActiveLine([]),this.emit("dataUpdated",this.lineList,this.selectedIDs)}attributeLockListChange(e){this.attributeLockList=e,this.render()}setResult(e){this.setLineList(e),this.render()}setConfig(e){super.setConfig(e)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(e=""){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.changeStyle(this.defaultAttribute),this.setLineAttribute("attribute",e),this.selectedIDs.length>0&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var e,t;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,r=(t=(e=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:"";return{color:o,textAttribute:r}}renderTextAttribute(){var e,t,i,s;if(!this.ctx||!this.selectedLine||this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<2)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:r,y:h}=this.selectedLine.pointList[1],l=this.coordUtils.getRenderCoord({x:r,y:h}),d=this.getColor(o),u=n?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke,c=(i=(t=this.lineList.find(f=>f.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({container:this.container,icon:this.getTextIconSvg(o),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${c}`,{left:l.x,top:l.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(e=""){return AttributeUtils.default.getTextIconSvg(e,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(e){if(this._textAttributeInstance&&e&&this.selectedID){let t=e;!AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",t)&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}exports.INNER_POINT_RADIUS=INNER_POINT_RADIUS,exports.LINE_ORDER_OFFSET=LINE_ORDER_OFFSET,exports.POINT_ACTIVE_RADIUS=POINT_ACTIVE_RADIUS,exports.POINT_RADIUS=POINT_RADIUS,exports.SEGMENT_NUMBER=SEGMENT_NUMBER,exports.default=LineToolOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),tool=require("../../constant/tool.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),MathUtils=require("../../utils/MathUtils.js"),basicToolOperation=require("./basicToolOperation.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js");function _interopDefaultLegacy(a){return a&&typeof a=="object"&&"default"in a?a:{default:a}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(a,e,t)=>e in a?__defProp(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,__spreadValues=(a,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(a,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(a,t,e[t]);return a},__spreadProps=(a,e)=>__defProps(a,__getOwnPropDescs(e)),EStatus;(function(a){a[a.Create=0]="Create",a[a.Active=1]="Active",a[a.None=2]="None"})(EStatus||(EStatus={}));const SEGMENT_NUMBER=16,LINE_ORDER_OFFSET={x:0,y:20},POINT_RADIUS=3,POINT_ACTIVE_RADIUS=5,INNER_POINT_RADIUS=2;class LineToolOperation extends basicToolOperation.BasicToolOperation{constructor(e){super(e);this.drawActivatedLine=(t,i,s)=>{const n=this.isCreate?___default.default.cloneDeep([{pointList:this.activeLine,order:this.nextOrder(),attribute:this.defaultAttribute,valid:this.isLineValid}]):___default.default.cloneDeep(this.selectedLines),o=this.isActiveLineValid();n.forEach(r=>{if((r==null?void 0:r.pointList)&&(r.pointList=r.pointList.map(l=>Object.assign(l,{actual:{x:l.x,y:l.y}},this.coordUtils.getRenderCoord(l)))),!r.pointList)return;const h=this.getLineColorByAttribute({attribute:r.attribute,valid:r.valid});return this.selectedLines.length>0&&(this.drawLineLength(r.pointList,h),this.renderActiveArea(MathUtils.default.calcViewportBoundaries(r.pointList,this.isCurve,SEGMENT_NUMBER))),this.drawLine(r.pointList,t,h,!0,!0),r.pointList[0]&&this.drawLineNumber(r.pointList[0],r.order,h,"",this.defaultAttribute,o),t&&this.isCreate&&this.arc(t,POINT_RADIUS,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,POINT_ACTIVE_RADIUS,h),r})},this.drawHoverPoint=t=>{if(!this.isMousedown&&t&&this.selectedID){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>LineToolUtils.default.calcDistance(this.coordUtils.getRenderCoord(o),t)<=POINT_ACTIVE_RADIUS);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,t)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.updatedLine={id:"",valid:!1,order:0},this.toolName="lineTool",this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(t,i,s,n=!0,o=!1,r)=>{const h=polygonTool.createSmoothCurvePointsFromPointList(i,SEGMENT_NUMBER);t.save(),t.lineCap="round",t.lineJoin="round",t.strokeStyle=s.color,n&&(t.lineWidth=s.lineWidth),o&&LineToolUtils.default.setReferenceCtx(t),i.forEach(({specialEdge:l},d)=>{const u=h.splice(0,SEGMENT_NUMBER+1);t.save(),t.beginPath(),r===d&&(t.lineWidth=4),u.forEach(({x:c,y:f},v)=>{const L=v>0?"lineTo":"moveTo";l&&LineToolUtils.default.setSpecialEdgeStyle(t),t[L](c,f)}),t.stroke(),t.restore()}),t.restore()},this.drawLine=(t,i,s,n=!1,o=!1)=>{const r=i?t.concat(i):t,h={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?LineToolUtils.default.drawCurveLine(this.ctx,r,h,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(r,h,o),n&&t.forEach(l=>{var d,u;const c=l.id,f=c&&[this.hoverPointID,(d=this.selectedPoint)==null?void 0:d.id].includes(c)?POINT_ACTIVE_RADIUS:POINT_RADIUS;this.arc(l,f,s),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(c)||this.arc(l,INNER_POINT_RADIUS,"white")})},this.drawStraightLine=(t,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&LineToolUtils.default.setReferenceCtx(n),t.forEach((o,r)=>{if(n.beginPath(),r>0){const h=t[r-1];n.save(),(h==null?void 0:h.specialEdge)&&LineToolUtils.default.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===r&&(n.lineWidth=4),n.moveTo(h.x,h.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const t=___default.default.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;t.forEach(i=>{if(!this.selection.isIdSelected(i.id)&&i.pointList){i.pointList.map(h=>Object.assign(h,{actual:{x:h.x,y:h.y}},this.coordUtils.getRenderCoord(h)));const{order:s,label:n}=i,o=s,r=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,r,!1),this.drawLineNumber(i.pointList[0],o,r,n,i.attribute,i.valid),i.id!==this.textEditingID&&(this.drawLineTextAttribute(i.pointList[1],r,i==null?void 0:i.textAttribute),this.drawLineLength(i.pointList,r))}})}catch(t){console.error(t,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=t=>{super.render(),this.drawLines(),this.drawActivatedLine(t,void 0,!1),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(t,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+t,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(t,i))},this.getSelectedLinesArea=()=>MathUtils.default.calcViewportBoundaries(this.selectedLines.reduce((t,i)=>(i==null?void 0:i.pointList)?t.concat(...i==null?void 0:i.pointList):t,[])),this.moveLineInRectRange=(t,i,s,n)=>{if(this.selectedLines.length===0)return;const{top:o,left:r,right:h,bottom:l}=this.getSelectedLinesArea(),d=[r,h].map(g=>___default.default.isNumber(g)?g+t:0),u=[o,l].map(g=>___default.default.isNumber(g)?g+i:0),c=r>=0&&h&&MathUtils.default.isInRange(d,s),f=o>=0&&l&&MathUtils.default.isInRange(u,n),v=c?t:0,L=f?i:0;this.lineDragging=!0,this.moveActiveArea(v,L)},this.onRightClick=t=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;if(LineToolUtils.default.lineLengthSum(this.activeLine||[])<this.minLength)return this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.MinLengthLimitErrorNotice,this.lang)}${this.minLength}`),!0;this.stopLineCreating(!0);return}const i=this.findHoverLine(this.getCoordinate(t));this.setSelectedLineID(i==null?void 0:i.id,t.ctrlKey),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedIDs.length>0){const t=this.lineList.find(s=>s.id===this.selectedIDs[0]),i=t==null?void 0:t.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=t=>{const i=this.getCoordinate(t),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&t.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(t,i);if(this.isCreate||this.isNone){this.setCreateStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreateStatusAndAddPoint(n);return}if(t.shiftKey){this.updateLineSegmentSpecial(i);return}this.coordsInsideActiveArea&&t.ctrlKey&&this.setInvalidLine(this.selectedID),this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=t=>{if(super.onKeyUp(t),this.isShift=!1,this.hoverLineSegmentIndex=-1,!this.selection.triggerKeyboardEvent(t,this.setLineList)){if(t.keyCode===keyCode.Esc){this.stopLineCreating(!1);return}if(this.selectedLine){if(t.key==="Delete"){this.deleteLine();return}if(t.key==="f"){this.setInvalidLine(this.selectedID);return}if(t.key===" "){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(t)}},this.onRightDblClick=t=>{super.onRightDblClick(t);const i=this.getCoordinate(t);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=t=>{this.isReference=t},this.pointsWithinRange=t=>!(this.lowerLimitPointNum&&t<this.lowerLimitPointNum||this.upperLimitPointNum&&t>this.upperLimitPointNum),this.setLineList=t=>{const i=t.length!==this.lineListLen;this.lineList=t,i&&this.emit("updatePageNumber")},this.textChange=t=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(t),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(e.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ActionsHistory,this.selection=new Selection(this),this.dependToolConfig={lineType:tool.ELineTypes.Line},this.historyDisabled=!1}get selectedLines(){return this.lineList.filter(e=>this.selection.isIdSelected(e.id))}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLine(){return this.lineList.find(e=>e.id===this.selectedID)}get isCreate(){return this.status===0}get isActive(){return this.selectedLines.length>0}get isNone(){return!this.isCreate&&this.selectedIDs.length===0}get isCurve(){return this.config.lineType===tool.ELineTypes.Curve}get isMultipleColor(){return this.config.lineColor===tool.ELineColor.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===tool.EToolName.Polygon}get isDependRect(){return this.dependToolName===tool.EToolName.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(e=>this.attributeLockList.includes((e==null?void 0:e.attribute)||"")):this.lineList}get selectedIDs(){return this.selection.selectedIDs}get selectedID(){return this.selection.selectedID}get enableOutOfTarget(){return this.config.enableOutOfTarget||this.config.outOfTarget||this.config.drawOutsideTarget}get showOrder(){var e;return(e=this.config.showOrder)!=null?e:this.config.isShowOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get minLength(){var e;return((e=this.config)==null?void 0:e.minLength)||0}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const e=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(t=>{var i;return(i=t==null?void 0:t.pointList)==null?void 0:i.some(s=>CanvasUtils.inViewPort(s,e))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var e,t;return(t=(e=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:""}get currentPageResult(){return this.lineList}updateStatus(e,t=!1){if(e!==this.status){if(t){let i="";this.textCheckType===tool.ETextType.Order&&this.isTextConfigurable&&(i=AttributeUtils.default.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=e,this.lineStatusChanged()}}isInBasicPolygon(e){var t,i;return polygonTool.isInPolygon(e,((t=this.basicResult)==null?void 0:t.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:e}=this.basicResult,{lineType:t}=this.dependToolConfig;return t===tool.ELineTypes.Curve?polygonTool.createSmoothCurvePoints(e.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):e}getNextCoordByRenderCoord(e){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(e))}getNextCoordByAbsCoord(e){var t;const i=(t=this.activeLine)==null?void 0:t.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(e,i):e}pointInLine(e,t,i){return e.filter(s=>s).length<2?!1:e.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(e[n-1]),r=this.coordUtils.getRenderCoord(s);return LineToolUtils.default.isInLine(t,o,r,i)})}arc(e,t=POINT_RADIUS,i){var s,n,o,r,h,l;if(this.ctx){const{x:d,y:u}=e;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(o=this.ctx)==null||o.arc(d,u,t,0,360),(r=this.ctx)==null||r.closePath(),(h=this.ctx)==null||h.fill(),(l=this.ctx)==null||l.restore()}}renderActiveArea({top:e,left:t,right:i,bottom:s}){this.ctx&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(t,e,i-t,s-e),this.ctx.stroke(),this.ctx.restore())}addLinePoint(e){var t,i,s,n;this.arc(e),(t=this.activeLine)==null||t.push(__spreadProps(__spreadValues({},e),{id:uuid()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreateStatusAndAddPoint(e,t=!1){this.updateStatus(0,t),this.addLinePoint(e)}isActiveLineValid(){var e;return this.selectedID?(e=this.lineList.find(t=>t.id===this.selectedID))==null?void 0:e.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(e,t=!1){return StyleUtils.getStrokeAndFill(this.getColor(e.attribute),e.valid,{isSelected:t}).stroke}drawLineNumber(e,t=1,i,s="",n,o=!0){var r,h,l;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let d=this.showOrder?t.toString():`${s}`;if(this.attributeConfigurable){const u=n?(l=(h=(r=this.attributeList)==null?void 0:r.find(c=>c.value===n))==null?void 0:h.key)!=null?l:n:"";d=[d,`${!o&&u?"\u65E0\u6548":""}${u}`].filter(c=>c).join("_")}this.drawText(e,d,i)}}drawLineTextAttribute(e,t,i){if(e&&i)return this.drawText(e,i,t,200)}drawLineLength(e,t){var i;if(((i=this.config)==null?void 0:i.showLineLength)&&e){const s=e.reduce((o,r,h)=>h<=0||!e[h-1].actual||!r.actual?o:o+LineToolUtils.default.calcDistance(e[h-1].actual,r.actual),0),n=e[e.length-1];this.drawText(n,`l = ${s.toFixed(2)}`,t)}}drawText(e,t,i,s){var n,o;this.ctx&&((n=this.ctx)==null||n.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=i,this.ctx.strokeStyle=i,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,s?DrawUtils.wrapText(this.canvas,t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y,s):this.ctx.fillText(t,e.x-LINE_ORDER_OFFSET.x,e.y-LINE_ORDER_OFFSET.y),(o=this.ctx)==null||o.restore())}moveActiveArea(e,t){this.selectedLines.length>0&&(this.selectedLines.forEach(i=>{var s;(s=i.pointList)==null||s.forEach(n=>Object.assign(n,{x:n.x+e,y:n.y+t}))}),this.render()),this.emit("dataUpdated",this.lineList,this.selectedIDs)}findHoveredPoint(e){if(!!this.activeLine)return this.activeLine.find(t=>{const i=this.coordUtils.getRenderCoord(t);return LineToolUtils.default.calcDistance(i,e)<=POINT_ACTIVE_RADIUS})}findHoverLine(e){return ___default.default.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,r)=>{if(r===0)return!1;const h=this.coordUtils.getRenderCoord(o),l=this.coordUtils.getRenderCoord(s[r-1]);return LineToolUtils.default.isInLine(e,h,l,n)})})}getAdsorptionPoint(e){let t,i,s;return ___default.default.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const r=this.findNearestPoint(n,e);if(r){if(r.minDistance===0){t=r.point;return}(i===void 0||r.minDistance<i)&&(t=r.point,i=r.minDistance)}}),s||t}findNearestPoint(e,t,i=7){let s;const n=i;for(let o=1;o<=e.length-1;o++){const r=this.coordUtils.getRenderCoord(e[o]),h=this.coordUtils.getRenderCoord(e[o-1]),{length:l,footPoint:d}=MathUtils.default.getFootOfPerpendicular(t,r,h),u=LineToolUtils.default.calcTwoPointDistance(r,t),c=LineToolUtils.default.calcTwoPointDistance(h,t);if(u<=i*2){s=r,i=0;break}if(c<=i*2){s=h,i=0;break}l<i&&(s=d,i=l)}return s?{point:s,minDistance:n}:void 0}getPointList(e){return this.isCurve?polygonTool.createSmoothCurvePointsFromPointList(e,SEGMENT_NUMBER):e}moveSelectedLine(e){const t=(e.x-this.prevAxis.x)/this.zoom,i=(e.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(t,i);return}if(this.isDependPolygon){this.moveLineInPolygon(t,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:r,width:h,height:l}=this.basicResult;s=[o,o+h],n=[r,r+l]}this.moveLineInRectRange(t,i,s,n)}moveSelectPoint(e){if(!this.selectedPoint)return;const t=e.x-this.prevAxis.x,i=e.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+t/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(e,t){var i;const s=!!e.shiftKey,n=e.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return LineToolUtils.default.getVHPoint(o,t,this.coordUtils.getAbsCoord(t),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(t):t}getNextPoint(e,t){const i=this.getCoordByConfig(e,t)||t;return this.enableOutOfTarget?this.coordUtils.getAbsCoord(i):this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(e){const t=this.getCoordinate(e),i=e.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(e,t);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!e.altKey)){const s=this.getAdsorptionPoint(t);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(t);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(t),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(t),this.render()}}onMouseMove(e){if(super.onMouseMove(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);this.mouseMoveHandler(e),this.prevAxis=t}setActiveLine(e){this.activeLine=e?___default.default.cloneDeep(e):void 0}historyChanged(e){if(this.historyDisabled)return;const t=`${e}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[t]){const i=this.actionsHistory&&this.actionsHistory[e]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[t]){const i=this.history[e](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(e){if(this.isDependPolygon)return this.isInBasicPolygon(e);if(this.isDependRect){const{x:t,y:i,width:s,height:n}=this.basicResult,o=[t,t+s],r=[i,i+n];return MathUtils.default.isInRange(e.x,o)&&MathUtils.default.isInRange(e.y,r)}return MathUtils.default.isInRange(e.x,[0,this.imageSize.width])&&MathUtils.default.isInRange(e.y,[0,this.imageSize.height])}getPointInsertIndex(e,t){if(e&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,r=this.isCurve?i.slice((n-1)*(SEGMENT_NUMBER+1),n*(SEGMENT_NUMBER+1)):[o,s];return this.pointInLine(r,e,t||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var e;return this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(e){const t=this.getPointInsertIndex(e,2)-1;if(t>-1){const i=this.activeLine[t];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var e;const t=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&t>-1&&i&&(this.activeLine.splice(t,0,__spreadProps(__spreadValues({},this.coordUtils.getAbsCoord(this.cursor)),{id:uuid()})),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList),this.render(),this.cursor=void 0)}isCoordOnSelectedArea(e){return this.selectedLines.some(t=>LineToolUtils.default.inArea(MathUtils.default.calcViewportBoundaries(t.pointList),this.coordUtils.getAbsCoord(e)))}onMouseDown(e){if(super.onMouseDown(e)||this.forbidMouseOperation||!this.imgInfo)return;const t=this.getCoordinate(e);if(this.isMousedown=!0,this.prevAxis=t,e.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(t),this.coordsInsideActiveArea=this.selectedLines.length>0?this.isCoordOnSelectedArea(t):!1,this.lineDragging=!1}lineHasChanged(){const e=this.lineList.find(t=>t.id===this.selectedID);return e?JSON.stringify(e.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const e=this.lineList.find(t=>t.id===this.selectedID);e&&(e.pointList=___default.default.cloneDeep(this.activeLine),this.updatedLine=e,this.emit("dataUpdated",this.lineList))}onMouseUp(e){const t=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(e)||this.forbidMouseOperation||!this.imgInfo){t();return}e.which===1&&this.onLeftClick(e),e.which===3&&this.onRightClick(e),t()}isTextValid(e){return AttributeUtils.default.textAttributeValidate(this.textCheckType,this.customFormat,e)}createLineData(){const e=uuid(),t={pointList:___default.default.cloneDeep(this.activeLine),id:e,valid:this.isLineValid,order:this.nextOrder()};return t.attribute=this.defaultAttribute,t}stopLineCreating(e=!0){var t,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let r;if(e){if(this.selectedID){const h=this.lineList.find(l=>l.id===this.selectedID);r=this.selectedID,h&&(h.pointList=___default.default.cloneWith(this.activeLine),___default.default.isEqual(h.pointList,(t=this.history)==null?void 0:t.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const h=this.createLineData();r=h.id,this.setLineList([...this.lineList,h]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?(this.activeLine=[],this.setSelectedLineID(r,!1,!1)):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.render()}setNoneStatus(e=!0){e&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(e,t){this.isShift=t!=null?t:e.keyCode===keyCode.Shift}continueToEdit(){var e,t;((e=this.selectedLine)==null?void 0:e.pointList)&&(this.updateStatus(0),this.cursor=void 0,this.setActiveLine(this.selectedLine.pointList),(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render())}setInvalidLineOnCreating(e){if(this.selectedID&&e.keyCode!==keyCode.Ctrl||!this.isCreate)return;const t=!e.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,t,!1):this.isLineValid=t}onKeyDown(e){if(super.onKeyDown(e),this.setKeyDownStatus(e),e.keyCode===keyCode.Z&&!e.ctrlKey&&this.toggleIsHide(),e.keyCode===keyCode.Shift&&this.render(),e.keyCode===keyCode.Tab){e.preventDefault(),this.selectToNextLine(e);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(e),this.config.attributeConfigurable){const t=AttributeUtils.default.getAttributeByKeycode(e.keyCode,this.config.attributeList);t!==void 0&&this.setDefaultAttribute(t)}}selectToNextLine(e){const t=CommonToolUtils.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,r;return __spreadProps(__spreadValues({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(r=(o=i.pointList[0])==null?void 0:o.y)!=null?r:0})}),e,this.selectedID);t&&this.selection.setSelectedIDs(t.id)}keyboardEventWhileLineCreating(e){!this.isCreate||(e.keyCode===keyCode.Ctrl&&this.setInvalidLineOnCreating(e),[keyCode.Shift,keyCode.Alt].includes(e.keyCode)&&this.renderNextPoint(e,this.prevAxis))}renderNextPoint(e,t){const i=this.coordUtils.getRenderCoord(this.getNextPoint(e,t));this.render(i)}deleteSelectedLine(e){var t;if(this.selectedLine){const i=MathUtils.default.calcViewportBoundaries((t=this.selectedLine)==null?void 0:t.pointList,this.isCurve,SEGMENT_NUMBER,this.zoom);LineToolUtils.default.inArea(i,this.coordUtils.getAbsCoord(e))&&this.deleteLine()}}deleteSelectedLinePoint(e){var t;this.pointsWithinRange(this.activeLine.length-1)&&e&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==e)),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var e;this.lineList=this.lineList.filter(t=>!this.selection.isIdSelected(t.id)),(e=this.history)==null||e.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(e,t,i=!0){var s;const n=this.lineList.find(o=>o.id===e);n&&(n.valid=t!==void 0?t:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),this.emit("dataUpdated",this.lineList),i&&this.render())}empty(){var e,t;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(e=this.actionsHistory)==null||e.empty(),(t=this.history)==null||t.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(e){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.setLineAttribute("attribute",e),this.selectedIDs.length>0&&((t=this.history)==null||t.pushHistory(this.lineList)))}setTextAttribute(e){var t;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",e),(t=this.history)==null||t.applyAttribute(this.selectedID,"textAttribute",e))}setLineAttribute(e,t){this.selectedIDs.length>0&&(this.lineList.forEach(i=>{this.selection.isIdSelected(i.id)&&(i[e]=t)}),this.render())}updateAttribute(e){this.emit("updateAttribute",e)}updateLineAttributes(e){var t;if(this.attributeConfigurable&&e){const i=(e==null?void 0:e.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&e){const i=(e==null?void 0:e.textAttribute)||"";this.updateTextAttribute(i)}(t=this.history)==null||t.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(e){if(this.selectedID){const t=this.lineList.find(i=>i.id===this.selectedID);t&&(t.textAttribute=e)}this.emit("updateText",e)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(e){this.textEditingID=e,this.render()}updateAttrWhileIDChanged(e){if(e){const t=this.lineList.find(i=>i.id===e);t&&this.setDefaultAttribute(t.attribute)}}setSelectedLineID(e,t=!1,i=!0){this.selection.setSelectedIDs(e,t),this.status=1,i&&e&&this.updateAttrWhileIDChanged(this.selectedID),this.selectedLine&&this.setActiveLine(this.selectedLine.pointList),this.selectedIDs.length===0&&this.setActiveLine([]),this.emit("dataUpdated",this.lineList,this.selectedIDs)}attributeLockListChange(e){this.attributeLockList=e,this.render()}setResult(e){this.setLineList(e),this.render()}setConfig(e){super.setConfig(e)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(e=""){var t;this.attributeConfigurable&&(this.defaultAttribute=e,this.changeStyle(this.defaultAttribute),this.setLineAttribute("attribute",e),this.selectedIDs.length>0&&((t=this.history)==null||t.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var e,t;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,r=(t=(e=this.lineList.find(h=>h.id===this.selectedID))==null?void 0:e.textAttribute)!=null?t:"";return{color:o,textAttribute:r}}renderTextAttribute(){var e,t,i,s;if(!this.ctx||!this.selectedLine||this.activeLine&&((e=this.activeLine)==null?void 0:e.length)<2)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:r,y:h}=this.selectedLine.pointList[1],l=this.coordUtils.getRenderCoord({x:r,y:h}),d=this.getColor(o),u=n?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke,c=(i=(t=this.lineList.find(f=>f.id===this.selectedID))==null?void 0:t.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({container:this.container,icon:this.getTextIconSvg(o),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${c}`,{left:l.x,top:l.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(e=""){return AttributeUtils.default.getTextIconSvg(e,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(e){if(this._textAttributeInstance&&e!==void 0&&this.selectedID){let t=e;!AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",t)&&t!==""&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),t=""),this.setTextAttribute(t),this.emit("updateTextAttribute"),this.render()}}}exports.INNER_POINT_RADIUS=INNER_POINT_RADIUS,exports.LINE_ORDER_OFFSET=LINE_ORDER_OFFSET,exports.POINT_ACTIVE_RADIUS=POINT_ACTIVE_RADIUS,exports.POINT_RADIUS=POINT_RADIUS,exports.SEGMENT_NUMBER=SEGMENT_NUMBER,exports.default=LineToolOperation;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),tool=require("../../constant/tool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),basicToolOperation=require("./basicToolOperation.js");const DEFAULT_PEN_SIZE=20,DEFAULT_COLOR="white";class ScribbleTool extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.toolName=tool.EToolName.ScribbleTool,this.action=tool.EScribblePattern.Scribble,this.getOriginCoordinate=i=>AxisUtils.default.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[tool.EScribblePattern.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[tool.EScribblePattern.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case tool.EScribblePattern.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=DEFAULT_PEN_SIZE,((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===tool.EScribblePattern.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:DEFAULT_COLOR}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=lbUtils.ImgConversionUtils.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){lbUtils.ImgConversionUtils.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e}onScribbleMove(t){if(t.buttons===1&&this.cacheContext&&this.startPoint){const e=this.getOriginCoordinate(t);this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke()}}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){DrawUtils.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){DrawUtils.drawCircle(this.canvas,this.coord,t,{color:"black"})}render(){if(super.render(),!this.ctx||!this.cacheCanvas||(this.ctx.save(),this.ctx.globalAlpha=.5,DrawUtils.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===tool.EScribblePattern.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}module.exports=ScribbleTool;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),tool=require("../../constant/tool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),keyCode=require("../../constant/keyCode.js"),basicToolOperation=require("./basicToolOperation.js");const DEFAULT_PEN_SIZE=20,DEFAULT_COLOR="white";class ScribbleTool extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.toolName=tool.EToolName.ScribbleTool,this.action=tool.EScribblePattern.Scribble,this.getOriginCoordinate=i=>AxisUtils.default.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[tool.EScribblePattern.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[tool.EScribblePattern.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case tool.EScribblePattern.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=DEFAULT_PEN_SIZE,this.isHidden=!1,this.pointList=[],((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===tool.EScribblePattern.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:DEFAULT_COLOR}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t,this.render()}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=lbUtils.ImgConversionUtils.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){lbUtils.ImgConversionUtils.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i),e===keyCode.Z&&!t.ctrlKey&&this.toggleIsHide(),t.ctrlKey&&this.action===tool.EScribblePattern.Scribble&&(this.lineActive=!0,this.render())}onKeyUp(t){super.onKeyUp(t),t.keyCode===keyCode.Ctrl&&(this.lineActive=!1,this.pointList=[],this.render())}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e,this.lineActive&&this.scribbleOnImgByLine(e)}scribbleOnImgByLine(t){const e=this.cacheContext;!e||(this.pointList.push(t),this.pointList.length>1&&this.pointList.forEach((i,s)=>{if(e.beginPath(),s>0){const o=this.pointList[s-1];e.save(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke(),e.restore()}}))}onScribbleMove(t){const e=this.getOriginCoordinate(t);if(this.lineActive){this.prePoint=e;return}t.buttons===1&&this.cacheContext&&this.startPoint&&(this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke())}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){DrawUtils.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){DrawUtils.drawCircle(this.canvas,this.coord,t,{color:"black"})}drawLineSegment(){if(this.prePoint&&this.pointList.length>0){const i=[this.pointList[this.pointList.length-1]].concat(this.prePoint).map(s=>this.getCoordinateUnderZoomByRotateFromImgPoint(s));this.drawStraightLine(i,{color:this.color,lineWidth:this.penSize,globalAlpha:.5})}}render(){if(super.render(),!this.ctx||!this.cacheCanvas||this.isHidden||(this.lineActive&&(this.renderCursorLine(this.color),this.drawLineSegment()),this.ctx.save(),this.ctx.globalAlpha=.5,DrawUtils.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===tool.EScribblePattern.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}module.exports=ScribbleTool;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t)),__async=(c,t,e)=>new Promise((i,s)=>{var o=n=>{try{r(e.next(n))}catch(a){s(a)}},h=n=>{try{r(e.throw(n))}catch(a){s(a)}},r=n=>n.done?i(n.value):Promise.resolve(n.value).then(o,h);r((e=e.apply(c,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var d,l;if(!this.imgNode)return;const u=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(l=this._imgAttribute)==null?void 0:l.isOriginalSize,{currentPos:m,imgInfo:b,zoom:f}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(b),this.setZoom(f),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",f,m,b)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:l,currentPosStorage:u}=this;try{let g;return l&&u?g={y:u.y+d.y-l.y,x:u.x+d.x-l.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,l,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&l===-1)return;const b=ZoomUtils.wheelChangePos(m,d,l,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!b)return;const{currentPos:f,ratio:w,zoom:y,imgInfo:P}=b;this.setZoom(y),this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,f,P)},this.zoomChanged=(d,l=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,d,l);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var e,i,s,o,h,r,n,a,v,C,I;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(e=t.staticMode)!=null?e:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(i=t.imgNode)==null?void 0:i.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(a=t.style)!=null?a:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(v=t.imgAttribute)!=null?v:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const e=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(e)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(r))),this.canvas=r,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,e=this.size){var i;if(!t||!e)return;const{min:s}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:e,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(i=this._imgAttribute)==null?void 0:i.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const e=this.canvas.getBoundingClientRect();return{x:(t.clientX-e.left-this.currentPos.x)/this.zoom,y:(t.clientY-e.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var e;return AttributeUtils.default.getTextIconSvg(t,(e=this.config)==null?void 0:e.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&i&&h){let r=t;switch(h){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const a=MathUtils.default.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=lbUtils.ImgPosUtils.getBasicRecPos(i,r,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*n.innerZoom,height:o.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:e,style:this.style})}getLineColor(t=""){var e,i,s,o,h,r,n,a;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(l=>l.value===t))==null?void 0:r.color)?(a=(n=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:v,lineColor:C}=this.style;return v&&C?C[v]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(u,t,i)=>t in u?__defProp(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,__spreadValues=(u,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(u,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(u,i,t[i]);return u},__spreadProps=(u,t)=>__defProps(u,__getOwnPropDescs(t)),__async=(u,t,i)=>new Promise((e,o)=>{var r=n=>{try{a(i.next(n))}catch(l){o(l)}},c=n=>{try{a(i.throw(n))}catch(l){o(l)}},a=n=>n.done?e(n.value):Promise.resolve(n.value).then(r,c);a((i=i.apply(u,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var d,h;if(!this.imgNode)return;const s=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(h=this._imgAttribute)==null?void 0:h.isOriginalSize,{currentPos:m,imgInfo:f,zoom:v}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,s,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(f),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,m,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:h,currentPosStorage:s}=this;try{let g;return h&&s?g={y:s.y+d.y-h.y,x:s.x+d.x-h.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,h,s)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&h===-1)return;const f=ZoomUtils.wheelChangePos(m,d,h,g,{zoom:s||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:v,ratio:w,zoom:y,imgInfo:P}=f;this.setZoom(y),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,v,P)},this.zoomChanged=(d,h=annotation.EGrowthMode.Linear)=>{const s=ZoomUtils.zoomChanged(this.zoom,d,h);this.wheelChangePos(this.getGetCenterCoordinate(),s>this.zoom?1:-1,s),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,h)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=h.color,s.lineWidth=h.lineWidth,s.globalAlpha=h.globalAlpha,d.forEach((g,m)=>{if(s.beginPath(),m>0){const f=d[m-1];s.save(),s.moveTo(f.x,f.y),s.lineTo(g.x,g.y),s.stroke(),s.restore()}}),s.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,o,r,c,a,n,l,C,b,I;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(o=(e=t.imgNode)==null?void 0:e.width)!=null?o:0,height:(c=(r=t.imgNode)==null?void 0:r.height)!=null?c:0,valid:!0,rotate:0},this.forbidOperation=(a=t.forbidOperation)!=null?a:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(l=t.style)!=null?l:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const o=this.pixelRatio;t.style.position="absolute",t.width=i.width*o,t.height=i.height*o,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,o;const r=this.pixelRatio,c=document.createElement("canvas");this.updateCanvasBasicStyle(c,t,0),this.basicCanvas=c;const a=document.createElement("canvas");this.updateCanvasBasicStyle(a,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(a,this.container.childNodes[0]),this.container.insertBefore(c,this.container.childNodes[0])):(this.container.appendChild(c),this.container.appendChild(a))),this.canvas=a,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(r,r),(o=this.basicCtx)==null||o.scale(r,r),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:o}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:o})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return AttributeUtils.default.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:o,imgInfo:r,dependToolName:c}=this;if(t&&e&&c){let a=t;switch(c){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const l=MathUtils.default.calcViewportBoundaries(t.pointList);a={x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top}}break}}const n=lbUtils.ImgPosUtils.getBasicRecPos(e,a,i,void 0,o==null?void 0:o.zoomRatio,o==null?void 0:o.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/this.innerZoom*n.innerZoom,height:r.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!_.isNumber(i==null?void 0:i.x)||!_.isNumber(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),o=t.deltaY||t.wheelDelta;let r=0;o>0&&this.zoom>this.zoomInfo.min&&(r=-1),o<0&&this.zoom<this.zoomInfo.max&&(r=1),this.wheelChangePos(e,r),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),DrawUtils.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,o,r,c,a,n,l;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(o=(e=this.config)==null?void 0:e.attributeList)!=null?o:[])+1;return((a=(c=(r=this.config)==null?void 0:r.attributeList)==null?void 0:c.find(h=>h.value===t))==null?void 0:a.color)?(l=(n=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:l.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
@@ -26,7 +26,7 @@ export default class AnnotationEngine {
26
26
  constructor(props: IProps);
27
27
  /**
28
28
  * 同步各种基础类型信息
29
- * 1. imgNode (TODO,后续是否将 imgNode 放置在内部管理)
29
+ * 1. imgNode
30
30
  * 2. size
31
31
  * 3. config
32
32
  * 4. style
@@ -4,11 +4,17 @@
4
4
  * @author Ron <ron.f.luo@gmail.com>
5
5
  */
6
6
  import { PCDLoader } from './PCDLoader';
7
+ export type TIndexMap = Map<string, {
8
+ x: number;
9
+ y: number;
10
+ z: number;
11
+ }[]>;
7
12
  export declare class PointCloudCache {
8
13
  pcdLoader: PCDLoader;
9
14
  MAX_SIZE: number;
10
15
  private pointsMap;
11
16
  private colorMap;
17
+ private cacheIndexMap;
12
18
  private cacheList;
13
19
  private static instance;
14
20
  cache2DHighlightIndex: Map<string, number[]>;
@@ -28,4 +34,12 @@ export declare class PointCloudCache {
28
34
  * Clear all cache2dHighlightIndex.
29
35
  */
30
36
  clearCache2DHighlightIndex(): void;
37
+ /**
38
+ * Loads index map from cache or generates it in a worker.
39
+ *
40
+ * @param src The path to the source image.
41
+ * @param points The points of the source image.
42
+ * @returns A promise that resolves to the index map.
43
+ */
44
+ loadIndexMap: (src: string, points: Float32Array) => Promise<unknown>;
31
45
  }
@@ -247,6 +247,7 @@ export declare class PointCloud extends EventListener {
247
247
  }>;
248
248
  points: ArrayLike<number>;
249
249
  }) => Promise<number[]>;
250
+ filterPreResult: (src: string, config: any, boxParamsList: IPointCloudBox[]) => Promise<unknown>;
250
251
  /**
251
252
  * It needs to be updated after load PointCloud's data.
252
253
  * @param boxParams
@@ -7,12 +7,6 @@ import * as THREE from 'three';
7
7
  import { EPointCloudSegmentCoverMode, EPointCloudSegmentFocusMode, EPointCloudSegmentMode, IPointCloudConfig, IPointCloudSegmentation } from '@labelbee/lb-utils';
8
8
  import { IPointCloudDelegate } from '..';
9
9
  export type ThreePoints = THREE.Points<THREE.BufferGeometry, THREE.PointsMaterial>;
10
- /**
11
- * TODO:
12
- * Need to think about store:
13
- * 1. The definition of points in IPointCloudSegmentation is Float32Array ?
14
- * 2. CloudData store the status ?
15
- */
16
10
  declare class PointCloudStore {
17
11
  canvas2d: HTMLCanvasElement | null;
18
12
  private container;
@@ -57,14 +57,12 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
57
57
  */
58
58
  createOperation(tool?: EToolName, imgNode?: HTMLImageElement, config?: Object): any;
59
59
  /**
60
- * Notice & TODO. Temporary additions
61
- * Just to switch last two canvas。
62
- *
63
- * It will be deleted later.
60
+ * Just to switch last two canvas
61
+ * @returns
64
62
  */
65
63
  switchLastTwoCanvas(): PolygonOperation | RectOperation | undefined;
66
64
  /**
67
- * Notice & TODO. Temporary additions
65
+ * Notice & TODO. Temporary Resolution
68
66
  * Just to set data to toolInstance.
69
67
  * @returns
70
68
  */
@@ -6,11 +6,15 @@ declare class ScribbleTool extends BasicToolOperation {
6
6
  toolName: EToolName;
7
7
  defaultAttributeInfo?: IInputList;
8
8
  config: IScribbleConfig;
9
+ isHidden: boolean;
9
10
  private action;
10
11
  private cacheCanvas?;
11
12
  private cacheContext?;
12
13
  private penSize;
13
14
  private startPoint?;
15
+ private prePoint?;
16
+ private pointList;
17
+ private lineActive?;
14
18
  constructor(props: IProps);
15
19
  get cursorErase(): string;
16
20
  get defaultCursor(): string;
@@ -36,6 +40,8 @@ declare class ScribbleTool extends BasicToolOperation {
36
40
  }>): void;
37
41
  setResult(data: IScribbleData[]): void;
38
42
  onKeyDown(e: KeyboardEvent): boolean | void;
43
+ onKeyUp(e: KeyboardEvent): void;
44
+ toggleIsHide(): void;
39
45
  eventBinding(): void;
40
46
  onMouseDown: (e: MouseEvent) => undefined;
41
47
  onMouseMove: (e: MouseEvent) => undefined;
@@ -46,6 +52,7 @@ declare class ScribbleTool extends BasicToolOperation {
46
52
  clearStatusAfterLeave(): void;
47
53
  onMouseLeave(): void;
48
54
  onScribbleStart(e: MouseEvent): void;
55
+ scribbleOnImgByLine(endPoint: ICoordinate): void;
49
56
  onScribbleMove(e: MouseEvent): void;
50
57
  onScribbleEnd(): void;
51
58
  eraseArc(e: MouseEvent): void;
@@ -57,6 +64,7 @@ declare class ScribbleTool extends BasicToolOperation {
57
64
  clearResult(): void;
58
65
  renderPoint(radius: number): void;
59
66
  renderBorderPoint(radius: number): void;
67
+ drawLineSegment(): void;
60
68
  render(): void;
61
69
  /** 撤销 */
62
70
  undo(): void;
@@ -42,7 +42,7 @@ export default class ViewOperation extends BasicToolOperation {
42
42
  rotate: number;
43
43
  }>): void;
44
44
  /**
45
- * TODO: New Pattern.
45
+ * Temporary: New Pattern
46
46
  *
47
47
  * 1. crop the canvas.
48
48
  */