@labelbee/lb-annotation 1.19.0 → 1.20.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.
Files changed (34) hide show
  1. package/dist/core/pointCloud/index.js +2 -2
  2. package/dist/core/pointCloud/matrix.js +1 -1
  3. package/dist/core/pointCloud/segmentation.js +1 -1
  4. package/dist/core/pointCloud/selector/rectSelector.js +1 -0
  5. package/dist/core/pointCloud/store/index.js +1 -1
  6. package/dist/core/toolOperation/ViewOperation.js +1 -1
  7. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/types/core/pointCloud/index.d.ts +3 -2
  10. package/dist/types/core/pointCloud/matrix.d.ts +25 -3
  11. package/dist/types/core/pointCloud/segmentation.d.ts +5 -2
  12. package/dist/types/core/pointCloud/selector/rectSelector.d.ts +8 -0
  13. package/dist/types/core/pointCloud/store/index.d.ts +10 -0
  14. package/dist/types/core/toolOperation/ViewOperation.d.ts +11 -3
  15. package/dist/types/core/toolOperation/basicToolOperation.d.ts +4 -0
  16. package/dist/types/utils/ImgUtils.d.ts +12 -0
  17. package/dist/types/utils/color.d.ts +5 -0
  18. package/dist/types/utils/tool/CanvasUtils.d.ts +4 -0
  19. package/dist/types/utils/tool/DrawUtils.d.ts +15 -0
  20. package/dist/utils/ImgUtils.js +1 -1
  21. package/dist/utils/tool/CanvasUtils.js +1 -1
  22. package/dist/utils/tool/DrawUtils.js +3 -3
  23. package/es/core/pointCloud/index.js +2 -2
  24. package/es/core/pointCloud/matrix.js +1 -1
  25. package/es/core/pointCloud/segmentation.js +1 -1
  26. package/es/core/pointCloud/selector/rectSelector.js +1 -0
  27. package/es/core/pointCloud/store/index.js +1 -1
  28. package/es/core/toolOperation/ViewOperation.js +1 -1
  29. package/es/core/toolOperation/basicToolOperation.js +1 -1
  30. package/es/index.js +1 -1
  31. package/es/utils/ImgUtils.js +1 -1
  32. package/es/utils/tool/CanvasUtils.js +1 -1
  33. package/es/utils/tool/DrawUtils.js +3 -3
  34. package/package.json +2 -2
@@ -1 +1 @@
1
- import{ImgPosUtils as w,toolStyleConverter as z}from"@labelbee/lb-utils";import{isNumber as S}from"lodash";import{EOperationMode as y,EToolName as I}from"../../constant/tool.js";import M from"../../utils/MathUtils.js";import P,{CoordinateUtils as N}from"../../utils/tool/AxisUtils.js";import j from"../../utils/tool/CanvasUtils.js";import L from"../../utils/tool/CommonToolUtils.js";import T from"../../utils/tool/LineToolUtils.js";import{EGrowthMode as K,EDragStatus as W,ELang as F}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{styleString as G,BASE_ICON as H}from"../../constant/style.js";import R from"../../locales/index.js";import{EMessage as k}from"../../locales/constants.js";import V from"../../utils/ActionsHistory.js";import E from"../../utils/tool/AttributeUtils.js";import Y from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import X from"../../utils/tool/RenderDomUtils.js";import B from"../../utils/tool/ZoomUtils.js";import $ from"./eventListener.js";var q=Object.defineProperty,J=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,O=(d,t,i)=>t in d?q(d,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[t]=i,_=(d,t)=>{for(var i in t||(t={}))tt.call(t,i)&&O(d,i,t[i]);if(U)for(var i of U(t))it.call(t,i)&&O(d,i,t[i]);return d},Z=(d,t)=>J(d,Q(t)),et=(d,t,i)=>new Promise((e,s)=>{var o=n=>{try{r(i.next(n))}catch(a){s(a)}},h=n=>{try{r(i.throw(n))}catch(a){s(a)}},r=n=>n.done?e(n.value):Promise.resolve(n.value).then(o,h);r((i=i.apply(d,t)).next())});const st={min:.2,max:1e3,ratio:.4};class ot extends ${constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.operationMode=y.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=st,this.initImgPos=()=>et(this,null,function*(){var l,c;if(!this.imgNode)return;const u=(l=this._imgAttribute)==null?void 0:l.zoomRatio,m=(c=this._imgAttribute)==null?void 0:c.isOriginalSize,{currentPos:f,imgInfo:b,zoom:v}=w.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(b),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,b)}),this.getCurrentPos=l=>{const{_firstClickCoordinate:c,currentPosStorage:u}=this;try{let m;return c&&u?m={y:u.y+l.y-c.y,x:u.x+l.x-c.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(l,c,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&c===-1)return;const b=B.wheelChangePos(f,l,c,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!b)return;const{currentPos:v,ratio:A,zoom:D,imgInfo:x}=b;this.setZoom(D),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(x),this.zoomInfo.ratio=A,this.emit("renderZoom",D,v,x)},this.zoomChanged=(l,c=K.Linear)=>{const u=B.zoomChanged(this.zoom,l,c);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=l=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,l),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var i,e,s,o,h,r,n,a,C;this.container=t.container,this.config=L.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(e=(i=t.imgNode)==null?void 0:i.width)!=null?e:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(h=t.forbidOperation)!=null?h:!1,this.forbidBasicResultRender=(r=t.forbidBasicResultRender)!=null?r:!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 V,this.style=(n=t.style)!=null?n:L.jsonParser(G),this._imgAttribute=(a=t.imgAttribute)!=null?a:{},this.isHidden=!1,this.dragStatus=W.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=F.Zh,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 Y(this.container,200),this.coordUtils=new N(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 H[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===y.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===y.MultiMove&&this.setOperationMode(y.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}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 j.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 s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,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,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),i&&(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,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}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(_({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:s}=w.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=Z(_({},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 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 E.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}}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:s,imgInfo:o,dependToolName:h}=this;if(t&&e&&h){let r=t;switch(h){case I.Polygon:case I.Line:{if(t.pointList){const a=M.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=w.getBasicRecPos(e,r,i,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(Z(_({},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 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||!S(i==null?void 0:i.x)||!S(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||T.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===p.Alt&&t.preventDefault(),t.keyCode){case p.Space:this.isSpaceKey=!0;break;case p.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case p.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),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(e,o),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;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.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=L.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",R.getMessagesByLocale(k.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",R.getMessagesByLocale(k.NoRotateNotice,this.lang)),!1;const t=M.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return z.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,o,h,r,n,a;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const c=E.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(m=>m.value===t))==null?void 0:r.color)?(a=(n=z.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[c]:""}const{color:C,lineColor:l}=this.style;return C&&l?l[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=X.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 I.Rect:{g.drawRect(this.basicCanvas,P.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case I.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,P.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case I.Line:{g.drawLineWithPointList(this.basicCanvas,P.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})}}export{ot as BasicToolOperation};
1
+ import{ImgPosUtils as P,toolStyleConverter as S}from"@labelbee/lb-utils";import{isNumber as M}from"lodash";import{EOperationMode as p,EToolName as y}from"../../constant/tool.js";import R from"../../utils/MathUtils.js";import L,{CoordinateUtils as j}from"../../utils/tool/AxisUtils.js";import T from"../../utils/tool/CanvasUtils.js";import _ from"../../utils/tool/CommonToolUtils.js";import K from"../../utils/tool/LineToolUtils.js";import{EGrowthMode as W,EDragStatus as F,ELang as G}from"../../constant/annotation.js";import w from"../../constant/keyCode.js";import{styleString as H,BASE_ICON as V}from"../../constant/style.js";import k from"../../locales/index.js";import{EMessage as E}from"../../locales/constants.js";import Y from"../../utils/ActionsHistory.js";import B from"../../utils/tool/AttributeUtils.js";import X from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import $ from"../../utils/tool/RenderDomUtils.js";import U from"../../utils/tool/ZoomUtils.js";import q from"./eventListener.js";var J=Object.defineProperty,Q=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,Z=(c,t,i)=>t in c?J(c,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[t]=i,D=(c,t)=>{for(var i in t||(t={}))it.call(t,i)&&Z(c,i,t[i]);if(O)for(var i of O(t))et.call(t,i)&&Z(c,i,t[i]);return c},A=(c,t)=>Q(c,tt(t)),st=(c,t,i)=>new Promise((e,s)=>{var o=n=>{try{r(i.next(n))}catch(a){s(a)}},h=n=>{try{r(i.throw(n))}catch(a){s(a)}},r=n=>n.done?e(n.value):Promise.resolve(n.value).then(o,h);r((i=i.apply(c,t)).next())});const ot={min:.2,max:1e3,ratio:.4};class nt extends q{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=p.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=ot,this.initImgPos=()=>st(this,null,function*(){var l,d;if(!this.imgNode)return;const u=(l=this._imgAttribute)==null?void 0:l.zoomRatio,m=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:f,imgInfo:I,zoom:v}=P.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(I),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,I)}),this.getCurrentPos=l=>{const{_firstClickCoordinate:d,currentPosStorage:u}=this;try{let m;return d&&u?m={y:u.y+l.y-d.y,x:u.x+l.x-d.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(l,d,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const I=U.wheelChangePos(f,l,d,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!I)return;const{currentPos:v,ratio:N,zoom:x,imgInfo:z}=I;this.setZoom(x),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(z),this.zoomInfo.ratio=N,this.emit("renderZoom",x,v,z)},this.zoomChanged=(l,d=W.Linear)=>{const u=U.zoomChanged(this.zoom,l,d);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=l=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,l),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(g.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(),g.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,s,o,h,r,n,a,C,b;this.container=t.container,this.config=_.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:(s=(e=t.imgNode)==null?void 0:e.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 Y,this.style=(a=t.style)!=null?a:_.jsonParser(H),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=F.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=G.Zh,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 X(this.container,200),this.coordUtils=new j(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 V[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===p.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===p.MultiMove&&this.setOperationMode(p.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}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 T.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 s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,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,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),i&&(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,(e=this.ctx)==null||e.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,i={}){this.imgNode=t,this.setBasicImgInfo(D({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:s}=P.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=A(D({},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 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 B.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}}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:s,imgInfo:o,dependToolName:h}=this;if(t&&e&&h){let r=t;switch(h){case y.Polygon:case y.Line:{if(t.pointList){const a=R.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=P.getBasicRecPos(e,r,i,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(A(D({},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 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||!M(i==null?void 0:i.x)||!M(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||K.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===w.Alt&&t.preventDefault(),t.keyCode){case w.Space:this.isSpaceKey=!0,t.preventDefault();break;case w.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case w.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),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(e,o),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;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.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=_.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",k.getMessagesByLocale(E.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",k.getMessagesByLocale(E.NoRotateNotice,this.lang)),!1;const t=R.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return S.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,o,h,r,n,a;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const l=B.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(u=>u.value===t))==null?void 0:r.color)?(a=(n=S.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[l]:""}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=$.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 y.Rect:{g.drawRect(this.basicCanvas,L.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,L.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{g.drawLineWithPointList(this.basicCanvas,L.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})}}export{nt as BasicToolOperation};
package/es/index.js CHANGED
@@ -1 +1 @@
1
- export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isInImage,lidar2image,mergeHighlightList,point2dTo3D,point3DLidar2Image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
1
+ export{RectOperation}from"./core/toolOperation/rectOperation.js";export{default as TagOperation}from"./core/toolOperation/tagOperation.js";export{default as PointOperation}from"./core/toolOperation/pointOperation.js";export{default as LineToolOperation}from"./core/toolOperation/LineToolOperation.js";export{default as TextToolOperation}from"./core/toolOperation/TextToolOperation.js";export{default as PolygonOperation}from"./core/toolOperation/polygonOperation.js";export{default as MeasureOperation}from"./core/toolOperation/measureOperation.js";export{default as PointCloud2DRectOperation}from"./core/toolOperation/pointCloud2DRectOperation.js";export{BasicToolOperation}from"./core/toolOperation/basicToolOperation.js";export{default as ViewOperation}from"./core/toolOperation/ViewOperation.js";export{default as ScribbleTool}from"./core/toolOperation/ScribbleTool.js";export{default as PointCloud2dOperation}from"./core/toolOperation/pointCloud2dOperation.js";import*as t from"./constant/annotation.js";export{t as cAnnotation};import*as e from"./constant/annotationTask.js";export{e as cAnnotationTask};import*as r from"./constant/keyCode.js";export{r as cKeyCode};import*as a from"./constant/style.js";export{a as cStyle};import*as i from"./constant/tool.js";export{i as cTool};export{CLIENT_TOOL_HEAD_TYPE,CLIENT_TOOL_NAME,DEFAULT_FONT,DEFAULT_TEXT_MAX_WIDTH,EAnnotationMode,EAudioToolName,EAuditStatus,ECheckModel,EDependPattern,EDragTarget,EDrawPointPattern,EFilterToolOperation,ELineColor,ELineTypes,EOperationMode,EPageOperator,EPointCloudName,EPolygonPattern,ERectPattern,EScribblePattern,ESelectedType,ETextType,EThumbnailOption,EToolName,EToolType,EVideoToolName,OPERATION_LIST,SEGMENT_NUMBER,TEXT_ATTRIBUTE_LINE_HEIGHT,TEXT_ATTRIBUTE_MAX_LENGTH,TEXT_TYPE,TOOL_NAME,TOOL_NAME_EN,edgeAdsorptionScope,editStepWidth}from"./constant/tool.js";export{default as TagUtils}from"./utils/tool/TagUtils.js";export{default as uuid}from"./utils/uuid.js";import o from"./utils/tool/EnhanceCommonToolUtils.js";export{default as MarkerUtils}from"./utils/tool/MarkerUtils.js";export{default as RectUtils}from"./utils/tool/RectUtils.js";export{default as AxisUtils}from"./utils/tool/AxisUtils.js";export{default as DrawUtils}from"./utils/tool/DrawUtils.js";export{default as ImgUtils}from"./utils/ImgUtils.js";export{default as MathUtils}from"./utils/MathUtils.js";export{default as AttributeUtils}from"./utils/tool/AttributeUtils.js";export{default as ActionsHistory}from"./utils/ActionsHistory.js";export{default as EventBus}from"./utils/EventBus.js";export{default as DblClickEventListener}from"./utils/tool/DblClickEventListener.js";export{default as AnnotationEngine}from"./core/index.js";export{default as UnitUtils}from"./utils/tool/UnitUtils.js";export{default as StyleUtils}from"./utils/tool/StyleUtils.js";export{CanvasScheduler}from"./newCore/CanvasScheduler.js";export{PointCloud}from"./core/pointCloud/index.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isInImage,lidar2image,mergeHighlightList,point2dTo3D,point3DLidar2Image,pointCloudLidar2image,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./core/pointCloud/matrix.js";export{PointCloudAnnotation}from"./core/pointCloud/annotation.js";const s=o,l=o;export{s as CommonToolUtils,l as toolUtils};
@@ -1 +1 @@
1
- class r{static load(o){return new Promise((s,n)=>{const e=new Image;e.crossOrigin="anonymous",o.startsWith("file")?e.src=encodeURI(o):e.src=o,e.onload=()=>{s(e)},e.onerror=()=>{n(e)}})}}export{r as default};
1
+ class l{static load(t){return new Promise((e,o)=>{const n=new Image;n.crossOrigin="anonymous",t.startsWith("file")?n.src=encodeURI(t):n.src=t,n.onload=()=>{e(n)},n.onerror=()=>{o(n)}})}}const m=(r,t,e,o)=>{if(!r)return"";const n=r.width/2,a=r.height/2,d=n-t/2,i=a-e/2,s=document.createElement("canvas");s.width=t*o,s.height=e*o;const c=s.getContext("2d");return c==null||c.drawImage(r,d,i,t,e,0,0,t*o,e*o),s.toDataURL()};export{m as cropAndEnlarge,l as default};
@@ -1 +1 @@
1
- import l from"../MathUtils.js";class a{static getMousePositionOnCanvasFromEvent(i,t){if(t&&i){const n=t.getBoundingClientRect();return{x:i.clientX-n.left,y:i.clientY-n.top}}return null}static getClientRect(i){if(i){const t=i.getBoundingClientRect();return{x:t.left,y:t.top,width:t.width,height:t.height}}return null}static getSize(i){if(i){const t=i.getBoundingClientRect();return{width:t.width,height:t.height}}return null}static inViewPort(i,t){return i?l.isInRange(i.x,[t.left,t.right])&&l.isInRange(i.y,[t.top,t.bottom]):!1}}a.getViewPort=(e,i,t)=>{const{width:n,height:o}=e,{x:g,y:c}=i,r=(0-c)/t,s=(0-g)/t,h=r+o/t,u=s+n/t;return{top:r,bottom:h,left:s,right:u}},a.getPixelRatio=e=>{if(!e||!window)return 1;const i=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/i};export{a as default};
1
+ import g from"../MathUtils.js";class c{static getMousePositionOnCanvasFromEvent(i,t){if(t&&i){const n=t.getBoundingClientRect();return{x:i.clientX-n.left,y:i.clientY-n.top}}return null}static getClientRect(i){if(i){const t=i.getBoundingClientRect();return{x:t.left,y:t.top,width:t.width,height:t.height}}return null}static getSize(i){if(i){const t=i.getBoundingClientRect();return{width:t.width,height:t.height}}return null}static inViewPort(i,t){return i?g.isInRange(i.x,[t.left,t.right])&&g.isInRange(i.y,[t.top,t.bottom]):!1}static createCanvas(i){const t=document.createElement("canvas"),{width:n,height:a}=i;t.width=n,t.height=a;const s=t.getContext("2d");return{canvas:t,ctx:s}}}c.getViewPort=(e,i,t)=>{const{width:n,height:a}=e,{x:s,y:l}=i,o=(0-l)/t,r=(0-s)/t,h=o+a/t,u=r+n/t;return{top:o,bottom:h,left:r,right:u}},c.getPixelRatio=e=>{if(!e||!window)return 1;const i=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/i};export{c as default};
@@ -1,3 +1,3 @@
1
- import{ELineTypes as P,SEGMENT_NUMBER as p,DEFAULT_FONT as O}from"../../constant/tool.js";import b from"./PolygonUtils.js";import T from"./UnitUtils.js";import S from"./AxisUtils.js";import{getCuboidAllSideLine as D,getPointListsByDirection as W,getCuboidTextAttributeOffset as F}from"./CuboidUtils.js";import M from"./AttributeUtils.js";var U=Object.defineProperty,I=Object.defineProperties,R=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,k=(r,t,i)=>t in r?U(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))$.call(t,i)&&k(r,i,t[i]);if(v)for(var i of v(t))L.call(t,i)&&k(r,i,t[i]);return r},A=(r,t)=>I(r,R(t));const j=1,B={x:0,y:0},X=0,u="",x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=u,thickness:s=1,lineCap:a="round",lineDash:d}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=a,d&&o.setLineDash(d),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=u,thickness:l=1,lineCap:s="round",hiddenText:a=!1,lineDash:d}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)&&e.setLineDash(d),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),a===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,w=0,y=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+w},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=u}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,a)=>`${s}${a.keyName}: ${a.value.join(" \u3001 ")}
2
- `,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=u,thickness:l=1,lineCap:s="round",lineType:a=P.Line,lineDash:d,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)?e.setLineDash(d):e.setLineDash([])})(),a===P.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=b.createSmoothCurvePointsFromPointList([...t],p),n!==void 0&&n>-1&&(t=t.slice((p+1)*n,(p+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),c.forEach(h=>{const g=t[h.i1],C=t[h.i2];e.beginPath(),e.moveTo(g.x,g.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const w=4,y=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,w+y,o),this.drawSpecialPoint(r,h,w,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:a=1,color:d=u,fill:n=u}=e,f=T.deg2rad(l),c=T.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=d,o.fillStyle=n,o.lineWidth=a,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=u}=e;o.save();const s=T.deg2rad(0),a=T.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,a,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const a=i*1.5,d=a*Math.sqrt(3)/2,n=a/2;o.moveTo(l,s-a),o.lineTo(l-d,s+n),o.lineTo(l+d,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=P.Line}=i;return e===!0&&(t=[...t,t[0]]),o===P.Curve&&(t=b.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,A(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=u,lineType:l=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===P.Curve&&(t=b.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...a]=t;return e.moveTo(s.x,s.y),a.forEach(d=>{e.lineTo(d.x,d.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:a,lineType:d}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:a,lineType:d});return this.drawPolygonWithFill(r,t,{color:o,lineType:d}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=u,font:s=O,shadowColor:a="",shadowBlur:d=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:w=0,offsetY:y=0,textAlign:h="start",lineHeight:g}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=a,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=d,this.wrapText(r,`${i}`,t.x+w,t.y+y,c,g),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=t.split(`
3
- `);for(let d=0;d<a.length;d++){const n=a[d].split("");let f="";for(let c=0;c<n.length;c++){const w=f+n[c],h=s.measureText(w).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=n[c],e+=l):f=w}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=u,thickness:l=1,lineCap:s="round",theta:a=30,headLen:d=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+a)*Math.PI/180,c=(n-a)*Math.PI/180,w=d*Math.cos(f),y=d*Math.sin(f),h=d*Math.cos(c),g=d*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+w,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+g),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:a,fillColor:d}=i,n={color:s,thickness:a};if(e){const c=S.transformPlain2PointList(e);x.drawPolygon(r,c,A(m({},n),{isClose:!0}));const w=D(t);w==null||w.forEach(y=>{x.drawLine(r,y.p1,y.p2,m({},n))})}const f=S.transformPlain2PointList(l);if(o&&e&&l){const c=W({direction:o,frontPoints:l,backPoints:e});c&&x.drawPolygonWithFill(r,c,{color:d})}x.drawPolygon(r,f,A(m({},n),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:a,selectedID:d,headerText:n,bottomText:f}=e,{backPoints:c,frontPoints:w,textAttribute:y}=t,h=w.br.x-w.bl.x;x.drawCuboid(r,t,i);let g="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.attribute&&(g=`${g} ${M.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!a&&c&&g&&x.drawText(r,{x:c.tl.x,y:c.tl.y-5},n!=null?n:g,{color:o,textMaxWidth:300});const C=F({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!a&&y&&t.id!==d){const E=Math.max(20,h*.8);x.drawText(r,{x:C.left,y:C.top},f!=null?f:y,{color:l,textMaxWidth:E})}}};let _=x;_.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=j,currentPos:l=B,rotate:s=X,imgAttribute:a}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(a){const{contrast:d,saturation:n,brightness:f}=a;e.filter=`saturate(${n+100}%) contrast(${d+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{_ as default};
1
+ import O from"color-rgba";import{MathUtils as S}from"@labelbee/lb-utils";import{ELineTypes as P,SEGMENT_NUMBER as p,DEFAULT_FONT as M}from"../../constant/tool.js";import b from"./PolygonUtils.js";import T from"./UnitUtils.js";import v from"./AxisUtils.js";import{getCuboidAllSideLine as W,getPointListsByDirection as U,getCuboidTextAttributeOffset as F}from"./CuboidUtils.js";import I from"./AttributeUtils.js";var R=Object.defineProperty,$=Object.defineProperties,L=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,_=(r,t,i)=>t in r?R(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))j.call(t,i)&&_(r,i,t[i]);if(k)for(var i of k(t))B.call(t,i)&&_(r,i,t[i]);return r},A=(r,t)=>$(r,L(t));const z=1,X={x:0,y:0},Y=0,x="",y=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=x,thickness:s=1,lineCap:a="round",lineDash:c}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=a,c&&o.setLineDash(c),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=x,thickness:l=1,lineCap:s="round",hiddenText:a=!1,lineDash:c}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(c)&&e.setLineDash(c),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),a===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const d=`${~~t.width} * ${~~t.height}`.length*7,g=0,w=Math.max(20,t.width-d);this.drawText(r,{x:t.x,y:t.y+t.height+20+g},t.textAttribute,{textMaxWidth:w})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=x}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,a)=>`${s}${a.keyName}: ${a.value.join(" \u3001 ")}
2
+ `,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=x,thickness:l=1,lineCap:s="round",lineType:a=P.Line,lineDash:c,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(c)?e.setLineDash(c):e.setLineDash([])})(),a===P.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=b.createSmoothCurvePointsFromPointList([...t],p),n!==void 0&&n>-1&&(t=t.slice((p+1)*n,(p+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const d=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&d.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),d.forEach(h=>{const u=t[h.i1],C=t[h.i2];e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const g=4,w=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,g+w,o),this.drawSpecialPoint(r,h,g,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:a=1,color:c=x,fill:n=x}=e,f=T.deg2rad(l),d=T.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=c,o.fillStyle=n,o.lineWidth=a,o.arc(t.x,t.y,i,f,d,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=x}=e;o.save();const s=T.deg2rad(0),a=T.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,a,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const a=i*1.5,c=a*Math.sqrt(3)/2,n=a/2;o.moveTo(l,s-a),o.lineTo(l-c,s+n),o.lineTo(l+c,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=P.Line}=i;return e===!0&&(t=[...t,t[0]]),o===P.Curve&&(t=b.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,A(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=x,lineType:l=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===P.Curve&&(t=b.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...a]=t;return e.moveTo(s.x,s.y),a.forEach(c=>{e.lineTo(c.x,c.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:a,lineType:c}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:a,lineType:c});return this.drawPolygonWithFill(r,t,{color:o,lineType:c}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=x,font:s=M,shadowColor:a="",shadowBlur:c=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:d=164,offsetX:g=0,offsetY:w=0,textAlign:h="start",lineHeight:u}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=a,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=c,this.wrapText(r,`${i}`,t.x+g,t.y+w,d,u),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=t.split(`
3
+ `);for(let c=0;c<a.length;c++){const n=a[c].split("");let f="";for(let d=0;d<n.length;d++){const g=f+n[d],h=s.measureText(g).width;o||(o=300),h>o&&d>0?(s.fillText(f,i,e),f=n[d],e+=l):f=g}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=x,thickness:l=1,lineCap:s="round",theta:a=30,headLen:c=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+a)*Math.PI/180,d=(n-a)*Math.PI/180,g=c*Math.cos(f),w=c*Math.sin(f),h=c*Math.cos(d),u=c*Math.sin(d);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+g,i.y+w),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+u),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:a,fillColor:c}=i,n={color:s,thickness:a};if(e){const d=v.transformPlain2PointList(e);y.drawPolygon(r,d,A(m({},n),{isClose:!0}));const g=W(t);g==null||g.forEach(w=>{y.drawLine(r,w.p1,w.p2,m({},n))})}const f=v.transformPlain2PointList(l);if(o&&e&&l){const d=U({direction:o,frontPoints:l,backPoints:e});d&&y.drawPolygonWithFill(r,d,{color:c})}y.drawPolygon(r,f,A(m({},n),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:a,selectedID:c,headerText:n,bottomText:f}=e,{backPoints:d,frontPoints:g,textAttribute:w}=t,h=g.br.x-g.bl.x;y.drawCuboid(r,t,i);let u="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(u=`${t.order}`),t.attribute&&(u=`${u} ${I.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!a&&d&&u&&y.drawText(r,{x:d.tl.x,y:d.tl.y-5},n!=null?n:u,{color:o,textMaxWidth:300});const C=F({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!a&&w&&t.id!==c){const E=Math.max(20,h*.8);y.drawText(r,{x:C.left,y:C.top},f!=null?f:w,{color:l,textMaxWidth:E})}}static drawPixel({canvas:r,points:t,size:i}){const e=r.getContext("2d"),{width:o,height:l}=i,s=e.getImageData(0,0,o,l),a=(d,g)=>{const[w,h,u,C]=O(g);s.data[d]=w,s.data[d+1]=h,s.data[d+2]=u,s.data[d+3]=Math.floor(255*C)},c=Math.max(o,l),n=Math.floor(Math.pow(S.calculateThousandsPlace(c),2)),f=S.generateCoordinates(n);return t.forEach(d=>{for(const[g,w]of f){const h=(d.y+w)*(s.width*4)+(d.x+g)*4;a(h,d.color)}}),e.putImageData(s,0,0),{canvas:r}}};let D=y;D.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=z,currentPos:l=X,rotate:s=Y,imgAttribute:a}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(a){const{contrast:c,saturation:n,brightness:f}=a;e.filter=`saturate(${n+100}%) contrast(${c+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{D as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.19.0",
3
+ "version": "1.20.0-alpha.1",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.12.0",
97
+ "@labelbee/lb-utils": "1.13.0-alpha.1",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",