@labelbee/lb-annotation 1.24.0-alpha.5 → 1.24.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),basicToolOperation=require("./basicToolOperation.js");class TextToolOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var s;e[n.key]=(s=n.default)!=null?s:""}),{value:e,id:uuid(),sourceID:i!=null?i:CommonToolUtils.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),i={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),s=document.createElement("div"),o=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),s.innerText=`${e.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(s),n.appendChild(o),t.appendChild(n)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===keyCode.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}module.exports=TextToolOperation;
1
+ "use strict";var uuid=require("../../utils/uuid.js"),keyCode=require("../../constant/keyCode.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),basicToolOperation=require("./basicToolOperation.js");class TextToolOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var o;e[n.key]=(o=n.default)!=null?o:""}),{value:e,id:uuid(),sourceID:i!=null?i:CommonToolUtils.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config)}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}toggleShowText(t){this.toggleTextContainerVisible(t)}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}init(){super.init(),this.initTextDisplayContainer()}initTextDisplayContainer(){const t=document.createElement("div"),i={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),o=document.createElement("div"),s=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),o.innerText=`${e.key}:`,s.innerText="",s.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(o),n.appendChild(s),t.appendChild(n)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===keyCode.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}module.exports=TextToolOperation;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t)),__async=(v,t,e)=>new Promise((i,o)=>{var r=a=>{try{s(e.next(a))}catch(n){o(n)}},c=a=>{try{s(e.throw(a))}catch(n){o(n)}},s=a=>a.done?i(a.value):Promise.resolve(a.value).then(r,c);s((e=e.apply(v,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=i=>{var o,r;const c=this.getCoordinateUnderZoom(i),s=AxisUtils.default.changePointByZoom(c,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",n=Number.MAX_SAFE_INTEGER;for(let h=0;h<this.annotations.length;h++){const l=this.annotations[h];switch(l.type){case"rect":{const d=l.annotation;if(RectUtils.isInRect(c,d,newScope,this.zoom)){const u=d.width*d.height;u<n&&(a=d.id,n=u)}break}case"polygon":{const d=l.annotation;if(PolygonUtils.isInPolygon(s,d.pointList)){const u=PolygonUtils.getPolygonArea(d.pointList);u<n&&(a=d.id,n=u)}break}}}return a};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:c}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(s=>{this.connectionPoints=s.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:s.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,c=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/c*o.innerZoom,height:r.height/c*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=tool.ELineTypes.Line}=s,n=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos),h=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:a,strokeColor:r.stroke});let l=[];if(s.showKeyPoint?l=DrawUtils.drawPolygonWithKeyPoint(this.canvas,n,h):l=DrawUtils.drawPolygon(this.canvas,n,h),(s==null?void 0:s.showDirection)===!0&&((o=s==null?void 0:s.pointList)==null?void 0:o.length)>=2){let g=n[0],y=MathUtils.default.getLineCenterPoint([n[0],n[1]]);if(a===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);g=l[f],y=l[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,y,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,n[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:u,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(n[0]),u,c),p){const g=n[n.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,c)}}renderPolygon(t){var e,i,o,r,c;if(t.type!=="polygon")return;const{style:s,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:h=tool.ELineTypes.Line}=n,l=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||s.fill){const f=rgba__default.default((r=(o=s==null?void 0:s.fill)!=null?o:s==null?void 0:s.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,l,{color:m,lineType:h})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},s),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:s.stroke});let u=[];if(n.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,l,d):u=DrawUtils.drawPolygon(this.canvas,l,d),(n==null?void 0:n.showDirection)===!0&&((c=n==null?void 0:n.pointList)==null?void 0:c.length)>=2){let f=l[0],m=MathUtils.default.getLineCenterPoint([l[0],l[1]]);if(h===tool.ELineTypes.Curve){const P=Math.floor(tool.SEGMENT_NUMBER/2);f=u[P],m=u[P+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:s.stroke,thickness:s.thickness}),DrawUtils.drawCircle(this.canvas,l[0],s.thickness+6,{color:s.stroke,thickness:s.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(g&&DrawUtils.drawText(this.canvas,this.appendOffset(l[0]),g,a),y){const f=l[l.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,c=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),s=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,a=o.stroke,n=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:l}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,n,{strokeColor:a,fillColor:s,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:h,bottomText:l})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},c=___default.default.pick(i,["stroke","thickness"]);o.forEach((s,a)=>{const n=__spreadValues(__spreadProps(__spreadValues({},c),{id:`${t.annotation.id}-${a}`,pointList:s.pointList}),r);switch(s.type){case"line":this.renderLine({type:"line",annotation:n});break;case"polygon":this.renderPolygon({type:"polygon",annotation:n});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:s,canvas:a}=CanvasUtils.createCanvas(c),n=typeof t.pixelSize=="number"?t.pixelSize:13;s&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:a,points:i,size:c,defaultRGBA:t.defaultRGBA,pixelSize:n}),DrawUtils.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,c,s;const a=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:l=!1,isReference:d,hiddenRectSize:u=!1}=h,{zoom:p}=this,g=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:y,y:f,width:m,height:P}=g;if(h.id===this.mouseHoverID||a.fill){const x=rgba__default.default((o=(i=a==null?void 0:a.fill)!=null?i:a==null?void 0:a.stroke)!=null?o:DEFAULT_STROKE_COLOR),b=`rgba(${x[0]}, ${x[1]}, ${x[2]},${x[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,g,{color:b})}DrawUtils.drawRect(this.canvas,g,__spreadValues(__spreadProps(__spreadValues({},a),{hiddenText:!0}),this.getReferenceOptions(d)));const{headerText:w,bottomText:S}=this.getRenderText(h,h==null?void 0:h.hiddenText);w&&DrawUtils.drawText(this.canvas,{x:y,y:f-6},w,__spreadValues({textMaxWidth:300},n));const T=`${Math.round(m/p)} * ${Math.round(P/p)}`,I=T.length*7;if(!l&&!u&&DrawUtils.drawText(this.canvas,{x:y+m-I,y:f+P+15},T,n),S){const x=20,b=Math.max(20,m-I);DrawUtils.drawText(this.canvas,{x:y,y:f+P+x},h.textAttribute,__spreadValues({textMaxWidth:b},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,l=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),d=(r=a.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,l,d,a);const{headerText:u,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:l.x+d/2,y:l.y-d-4},u,__spreadValues({textAlign:"center"},n)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:l.x+d,y:l.y+d+24}),p,n);break}case"text":{const h=e.annotation,{text:l,x:d,y:u,textMaxWidth:p,color:g="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:m=tool.DEFAULT_FONT,position:P}=h,w=10,S=10,T=AxisUtils.default.changePointByZoom({x:d,y:u},this.zoom,this.currentPos),{width:I,height:x,fontHeight:b=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,m,f);if(P==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:I+S*2,height:x+w*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:T.x+S,y:T.y+b+w},l,{color:g,lineHeight:f,font:m,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t)),__async=(v,t,e)=>new Promise((i,o)=>{var r=a=>{try{s(e.next(a))}catch(n){o(n)}},c=a=>{try{s(e.throw(a))}catch(n){o(n)}},s=a=>a.done?i(a.value):Promise.resolve(a.value).then(r,c);s((e=e.apply(v,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=i=>{var o,r;const c=this.getCoordinateUnderZoom(i),s=AxisUtils.default.changePointByZoom(c,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",n=Number.MAX_SAFE_INTEGER;for(let h=0;h<this.annotations.length;h++){const l=this.annotations[h];switch(l.type){case"rect":{const d=l.annotation;if(RectUtils.isInRect(c,d,newScope,this.zoom)){const f=d.width*d.height;f<n&&(a=d.id,n=f)}break}case"polygon":{const d=l.annotation;if(PolygonUtils.isInPolygon(s,d.pointList)){const f=PolygonUtils.getPolygonArea(d.pointList);f<n&&(a=d.id,n=f)}break}}}return a};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:c}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(s=>{this.connectionPoints=s.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:s.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,c=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/c*o.innerZoom,height:r.height/c*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=tool.ELineTypes.Line}=s,n=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos),h=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:a,strokeColor:r.stroke});let l=[];if(s.showKeyPoint?l=DrawUtils.drawPolygonWithKeyPoint(this.canvas,n,h):l=DrawUtils.drawPolygon(this.canvas,n,h),(s==null?void 0:s.showDirection)===!0&&((o=s==null?void 0:s.pointList)==null?void 0:o.length)>=2){let g=n[0],y=MathUtils.default.getLineCenterPoint([n[0],n[1]]);if(a===tool.ELineTypes.Curve){const u=Math.floor(tool.SEGMENT_NUMBER/2);g=l[u],y=l[u+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,y,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,n[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(f&&DrawUtils.drawText(this.canvas,this.appendOffset(n[0]),f,c),p){const g=n[n.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,c)}}renderPolygon(t){var e,i,o,r,c;if(t.type!=="polygon")return;const{style:s,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:h=tool.ELineTypes.Line}=n,l=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||s.fill){const u=rgba__default.default((r=(o=s==null?void 0:s.fill)!=null?o:s==null?void 0:s.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${u[0]}, ${u[1]}, ${u[2]},${u[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,l,{color:m,lineType:h})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},s),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:s.stroke});let f=[];if(n.showKeyPoint?f=DrawUtils.drawPolygonWithKeyPoint(this.canvas,l,d):f=DrawUtils.drawPolygon(this.canvas,l,d),(n==null?void 0:n.showDirection)===!0&&((c=n==null?void 0:n.pointList)==null?void 0:c.length)>=2){let u=l[0],m=MathUtils.default.getLineCenterPoint([l[0],l[1]]);if(h===tool.ELineTypes.Curve){const P=Math.floor(tool.SEGMENT_NUMBER/2);u=f[P],m=f[P+1]}DrawUtils.drawArrowByCanvas(this.canvas,u,m,{color:s.stroke,thickness:s.thickness}),DrawUtils.drawCircle(this.canvas,l[0],s.thickness+6,{color:s.stroke,thickness:s.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(g&&DrawUtils.drawText(this.canvas,this.appendOffset(l[0]),g,a),y){const u=l[l.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:u.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:u.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,c=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),s=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,a=o.stroke,n=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:l}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,n,{strokeColor:a,fillColor:s,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:h,bottomText:l})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},c=___default.default.pick(i,["stroke","thickness"]);o.forEach((s,a)=>{const n=__spreadValues(__spreadProps(__spreadValues({},c),{id:`${t.annotation.id}-${a}`,pointList:s.pointList}),r);switch(s.type){case"line":this.renderLine({type:"line",annotation:n});break;case"polygon":this.renderPolygon({type:"polygon",annotation:n});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:s,canvas:a}=CanvasUtils.createCanvas(c),n=typeof t.pixelSize=="number"?t.pixelSize:13;s&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:a,points:i,size:c,defaultRGBA:t.defaultRGBA,pixelSize:n}),DrawUtils.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,c,s;const a=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:l=!1,isReference:d,hiddenRectSize:f=!1}=h,{zoom:p}=this,g=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:y,y:u,width:m,height:P}=g,x=rgba__default.default((o=(i=a==null?void 0:a.fill)!=null?i:a==null?void 0:a.stroke)!=null?o:DEFAULT_STROKE_COLOR),w=`rgba(${x[0]}, ${x[1]}, ${x[2]},${x[3]*.8})`;(h.id===this.mouseHoverID||a.fill)&&DrawUtils.drawRectWithFill(this.canvas,g,{color:w}),DrawUtils.drawRect(this.canvas,g,__spreadValues(__spreadProps(__spreadValues({},a),{hiddenText:!0}),this.getReferenceOptions(d))),(h==null?void 0:h.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:w,position:{x:y-16,y:u-16}});const{headerText:T,bottomText:I}=this.getRenderText(h,h==null?void 0:h.hiddenText);T&&DrawUtils.drawText(this.canvas,{x:y,y:u-6},T,__spreadValues({textMaxWidth:300},n));const b=`${Math.round(m/p)} * ${Math.round(P/p)}`,S=b.length*7;if(!l&&!f&&DrawUtils.drawText(this.canvas,{x:y+m-S,y:u+P+15},b,n),I){const k=20,C=Math.max(20,m-S);DrawUtils.drawText(this.canvas,{x:y,y:u+P+k},h.textAttribute,__spreadValues({textMaxWidth:C},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,l=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),d=(r=a.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,l,d,a);const{headerText:f,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);f&&DrawUtils.drawText(this.canvas,{x:l.x+d/2,y:l.y-d-4},f,__spreadValues({textAlign:"center"},n)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:l.x+d,y:l.y+d+24}),p,n);break}case"text":{const h=e.annotation,{text:l,x:d,y:f,textMaxWidth:p,color:g="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:u=25,font:m=tool.DEFAULT_FONT,position:P}=h,x=10,w=10,T=AxisUtils.default.changePointByZoom({x:d,y:f},this.zoom,this.currentPos),{width:I,height:b,fontHeight:S=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,m,u);if(P==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:I+w*2,height:b+x*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:T.x+w,y:T.y+S+x},l,{color:g,lineHeight:u,font:m,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(R){return R&&typeof R=="object"&&"default"in R?R:{default:R}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(R,t,e)=>t in R?__defProp(R,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):R[t]=e,__spreadValues=(R,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(R,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(R,e,t[e]);return R},__spreadProps=(R,t)=>__defProps(R,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const s=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===s);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const s=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:h}=this;if(h&&RectUtils.isInRect(s,h,r,this.zoom))return h.id}const i=o.filter(h=>RectUtils.isInRect(s,h,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(n=>({size:n.width*n.height,id:n.id})).sort((n,c)=>n.size-c.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.selection=new Selection(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const s=this.rectList.length;this.rectList=t,s!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,s]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(s=>s.id===this.selectedRectID?__spreadProps(__spreadValues({},s),{textAttribute:e}):s),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:s}=this,r=RectUtils.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const h=r[i],{length:n}=MathUtils.default.getFootOfPerpendicular(o,h.begin,h.end);n<scope+10&&(e=i)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),s=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const o=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(s)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const s=t.reduce((r,o)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(o,e))),[]);return MathUtils.default.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,o,i;if(this.drawOutSideTarget!==!1)return!1;const h=this.getRectsBoundaries(t,e),n={y:h.top,x:h.left,height:h.bottom-h.top,width:h.right-h.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(n,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const c=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(i=this.imgNode)==null?void 0:i.width};if(c)return[{x:h.left,y:h.top},{x:h.right,y:h.bottom}].some(d=>!RectUtils.isInRect(d,c))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=s.find(i=>i.id===r.id);return o||r}))}}onDragMoveAll(t){var e,s;!((s=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:s.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,s,r,o;if(!this.dragInfo)return;const i={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const h=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:c,width:d,height:a}=h;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let g=n,f=c,u=d,x=a;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?n+d:n+i.x,f=a-i.y<0?c+a:c+i.y,u=Math.abs(i.x-d),x=Math.abs(i.y-a);break}case 1:{g=d+i.x>0?n:n+d+i.x,f=a-i.y<0?c+a:c+i.y,u=Math.abs(d+i.x),x=Math.abs(a-i.y);break}case 2:{g=d+i.x>0?n:n+d+i.x,f=a+i.y>0?c:c+a+i.y,u=Math.abs(d+i.x),x=a+i.y>0?a+i.y:Math.abs(a+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,f=a+i.y>0?c:c+a+i.y,u=Math.abs(i.x-d),x=a+i.y>0?a+i.y:Math.abs(a+i.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:x})}break;case tool.EDragTarget.Line:{let g=n,f=c,u=d,x=a;switch(this.hoverRectEdgeIndex){case 0:{f=a-i.y<0?c+a:c+i.y,x=Math.abs(i.y-a);break}case 1:{g=d+i.x>0?n:n+d+i.x,u=Math.abs(d+i.x);break}case 2:{f=a+i.y>0?c:c+a+i.y,x=a+i.y>0?a+i.y:Math.abs(a+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,u=Math.abs(i.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:x});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(l,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,f=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,x=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<f-.01||l.width>g+u-l.x+.01||l.height>f+x-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<f&&(l.y=f),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>f+x-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?RectUtils.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){var e,s;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),h=this.hoverRectID;if(this.hoverRectID=i,i!==h&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:c}=this.firstClickCoord,{width:d,height:a}=this.drawingRect;if(d=Math.abs(n-o.x),a=Math.abs(c-o.y),o.x<n&&(n=o.x),o.y<c&&(c=o.y),this.drawOutSideTarget===!1){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:c,width:d,height:a}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;o.x<0&&(d=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(a=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(n+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-n)),c+a>this.imgInfo.height&&(a=Math.abs(this.imgInfo.height-c)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:c,width:d,height:a}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=__spreadProps(__spreadValues({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.rectList.filter(i=>CommonToolUtils.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},r),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.render();return}const s=this.getDrawingRectWithRectList();this.setRectList(s,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:s,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,s/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:s,height:r})]}rightMouseUp(t){var e,s,r;const o=this.getHoverRectID(t),i=this.rectList.find(h=>h.id===o);if(this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((s=this.dragInfo)==null?void 0:s.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(o,t.ctrlKey),i&&((r=this.selectedIDs)==null?void 0:r.length)===1&&this.setDefaultAttribute(i.attribute),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const h=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);h>=0&&(this.setMarkerIndex(h),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect();break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=annotation.ESortDirection.ascend;t.shiftKey&&(s=annotation.ESortDirection.descend);const[r,o]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const h=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>CanvasUtils.inViewPort({x:c.x,y:c.y},h));const n=CommonToolUtils.getNextSelectedRectID(i,s,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const s=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let s,r;this.drawingRect&&this.firstClickCoord&&(s=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(s,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),s=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:s}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const s=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,o=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,o=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:s}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:s,y:r,width:o,height:i,attribute:h,valid:n}=e,c=o*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),a=this.getColor(h),l=n?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:c,container:this.container,icon:this.getTextIconSvg(h),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+g,color:l,width:c})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=RectUtils.getRectPointList(t),o=r.length,i=this.getColor(t.attribute);r.forEach((h,n)=>{var c,d;if(e.save(),e.moveTo(h.x,h.y),e.beginPath(),this.hoverRectPointIndex===n?s=scope+6:s=scope,t.valid===!1?(e.strokeStyle=i==null?void 0:i.invalid.stroke,e.fillStyle=i==null?void 0:i.invalid.stroke):(e.strokeStyle=i==null?void 0:i.valid.stroke,e.fillStyle=i==null?void 0:i.valid.stroke),e.arc(h.x*this.zoom+this.currentPos.x,h.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const a=this.getColor(t.attribute),l=t.valid===!1?(c=a==null?void 0:a.invalid)==null?void 0:c.stroke:(d=a==null?void 0:a.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[n].x*this.zoom+this.currentPos.x,r[n].y*this.zoom+this.currentPos.y),e.lineTo(r[(n+1)%o].x*this.zoom+this.currentPos.x,r[(n+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,o,i,h;if(this.ctx&&t){const{ctx:n,style:c}=this,{hiddenText:d=!1}=c;n.save();const{strokeColor:a,fillColor:l,textColor:g}=this.getRenderStyle(t);n.font="lighter 14px Arial";let f="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=AxisUtils.default.changeRectByZoom(t,s?e:this.zoom,this.currentPos);d||DrawUtils.drawText(this.canvas,{x:u.x,y:u.y-6},f,__spreadProps(__spreadValues({color:a,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300}));const x=(h=(i=this.style)==null?void 0:i.width)!=null?h:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,u,{color:l}),DrawUtils.drawRect(this.canvas,u,{color:a,thickness:x,hiddenText:!0}),n.restore();let b=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(b=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const v=b.length*7;if(d||DrawUtils.drawText(this.canvas,{x:u.x+u.width-v,y:u.y+u.height+15},b,__spreadValues({color:g,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!d&&t.textAttribute&&t.id!==this.selectedRectID){const I=0,w=Math.max(20,u.width-v);DrawUtils.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+I},t.textAttribute,__spreadValues({color:g,font:"italic normal 900 14px Arial",textMaxWidth:w},annotation.DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||s==null||s.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))})}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(s=>this.selection.isIdSelected(s.id)?__spreadProps(__spreadValues({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(s=>s.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const s=this.rectList.find(r=>r.id===t);if((s==null?void 0:s.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}exports.RectOperation=RectOperation,exports.default=RectOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(R){return R&&typeof R=="object"&&"default"in R?R:{default:R}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(R,t,e)=>t in R?__defProp(R,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):R[t]=e,__spreadValues=(R,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(R,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(R,e,t[e]);return R},__spreadProps=(R,t)=>__defProps(R,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.highlightVisible=!1,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const s=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===s);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const s=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(s,a,r,this.zoom))return a.id}const i=o.filter(a=>RectUtils.isInRect(s,a,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(n=>({size:n.width*n.height,id:n.id})).sort((n,c)=>n.size-c.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.selection=new Selection(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const s=this.rectList.length;this.rectList=t,s!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,s]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(s=>s.id===this.selectedRectID?__spreadProps(__spreadValues({},s),{textAttribute:e}):s),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:s}=this,r=RectUtils.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const a=r[i],{length:n}=MathUtils.default.getFootOfPerpendicular(o,a.begin,a.end);n<scope+10&&(e=i)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),s=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const o=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(s)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const s=t.reduce((r,o)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(o,e))),[]);return MathUtils.default.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,o,i;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),n={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(n,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const c=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(i=this.imgNode)==null?void 0:i.width};if(c)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,c))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=s.find(i=>i.id===r.id);return o||r}))}}onDragMoveAll(t){var e,s;!((s=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:s.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,s,r,o;if(!this.dragInfo)return;const i={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:c,width:d,height:h}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let g=n,f=c,u=d,b=h;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?n+d:n+i.x,f=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-d),b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,f=h-i.y<0?c+h:c+i.y,u=Math.abs(d+i.x),b=Math.abs(h-i.y);break}case 2:{g=d+i.x>0?n:n+d+i.x,f=h+i.y>0?c:c+h+i.y,u=Math.abs(d+i.x),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,f=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-d),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:b})}break;case tool.EDragTarget.Line:{let g=n,f=c,u=d,b=h;switch(this.hoverRectEdgeIndex){case 0:{f=h-i.y<0?c+h:c+i.y,b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,u=Math.abs(d+i.x);break}case 2:{f=h+i.y>0?c:c+h+i.y,b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,u=Math.abs(i.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:g,y:f,width:u,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(l,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,f=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<f-.01||l.width>g+u-l.x+.01||l.height>f+b-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<f&&(l.y=f),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>f+b-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?RectUtils.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){var e,s;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=i,i!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:c}=this.firstClickCoord,{width:d,height:h}=this.drawingRect;if(d=Math.abs(n-o.x),h=Math.abs(c-o.y),o.x<n&&(n=o.x),o.y<c&&(c=o.y),this.drawOutSideTarget===!1){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:c,width:d,height:h}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;o.x<0&&(d=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(h=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(n+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-n)),c+h>this.imgInfo.height&&(h=Math.abs(this.imgInfo.height-c)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:n,y:c,width:d,height:h}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=__spreadProps(__spreadValues({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=AttributeUtils.default.getTextAttribute(this.rectList.filter(i=>CommonToolUtils.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},r),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.render();return}const s=this.getDrawingRectWithRectList();this.setRectList(s,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:s,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,s/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:s,height:r})]}rightMouseUp(t){var e,s,r;const o=this.getHoverRectID(t),i=this.rectList.find(a=>a.id===o);if(this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((s=this.dragInfo)==null?void 0:s.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(o,t.ctrlKey),i&&((r=this.selectedIDs)==null?void 0:r.length)===1&&this.setDefaultAttribute(i.attribute),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const a=CommonToolUtils.getCurrentMarkerIndex(i.label,this.config.markerList);a>=0&&(this.setMarkerIndex(a),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect();break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=annotation.ESortDirection.ascend;t.shiftKey&&(s=annotation.ESortDirection.descend);const[r,o]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>CanvasUtils.inViewPort({x:c.x,y:c.y},a));const n=CommonToolUtils.getNextSelectedRectID(i,s,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const s=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let s,r;this.drawingRect&&this.firstClickCoord&&(s=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(s,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),s=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:s}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const s=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,o=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,o=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:s}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:s,y:r,width:o,height:i,attribute:a,valid:n}=e,c=o*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),h=this.getColor(a),l=n?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:c,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+g,color:l,width:c})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=RectUtils.getRectPointList(t),o=r.length,i=this.getColor(t.attribute);r.forEach((a,n)=>{var c,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===n?s=scope+6:s=scope,t.valid===!1?(e.strokeStyle=i==null?void 0:i.invalid.stroke,e.fillStyle=i==null?void 0:i.invalid.stroke):(e.strokeStyle=i==null?void 0:i.valid.stroke,e.fillStyle=i==null?void 0:i.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const h=this.getColor(t.attribute),l=t.valid===!1?(c=h==null?void 0:h.invalid)==null?void 0:c.stroke:(d=h==null?void 0:h.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[n].x*this.zoom+this.currentPos.x,r[n].y*this.zoom+this.currentPos.y),e.lineTo(r[(n+1)%o].x*this.zoom+this.currentPos.x,r[(n+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,o,i,a;if(this.ctx&&t){const{ctx:n,style:c}=this,{hiddenText:d=!1}=c;n.save();const{strokeColor:h,fillColor:l,textColor:g}=this.getRenderStyle(t);n.font="lighter 14px Arial";let f="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=AxisUtils.default.changeRectByZoom(t,s?e:this.zoom,this.currentPos);d||DrawUtils.drawText(this.canvas,{x:u.x,y:u.y-6},f,__spreadProps(__spreadValues({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:h,position:{x:u.x-5,y:u.y-16}});const b=(a=(i=this.style)==null?void 0:i.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,u,{color:l}),DrawUtils.drawRect(this.canvas,u,{color:h,thickness:b,hiddenText:!0}),n.restore();let x=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(x=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const v=x.length*7;if(d||DrawUtils.drawText(this.canvas,{x:u.x+u.width-v,y:u.y+u.height+15},x,__spreadValues({color:g,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!d&&t.textAttribute&&t.id!==this.selectedRectID){const I=0,w=Math.max(20,u.width-v);DrawUtils.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+I},t.textAttribute,__spreadValues({color:g,font:"italic normal 900 14px Arial",textMaxWidth:w},annotation.DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||s==null||s.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))})}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(s=>this.selection.isIdSelected(s.id)?__spreadProps(__spreadValues({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(s=>s.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const s=this.rectList.find(r=>r.id===t);if((s==null?void 0:s.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}exports.RectOperation=RectOperation,exports.default=RectOperation;
@@ -23,6 +23,7 @@ declare class TextToolOperation extends BasicToolOperation {
23
23
  */
24
24
  getInitResultList: (dataSourceStep: number, basicResultList: any[]) => ITextResult[];
25
25
  updateTextValue(k: string, v: string): void;
26
+ toggleShowText(show: boolean): void;
26
27
  /**
27
28
  *
28
29
  * @param key
@@ -30,6 +31,7 @@ declare class TextToolOperation extends BasicToolOperation {
30
31
  */
31
32
  renderText(key: string, value: string): void;
32
33
  getTextDomID(key: string): string;
34
+ init(): void;
33
35
  /** 初始化文本渲染元素 */
34
36
  initTextDisplayContainer(): void;
35
37
  exportData(): any[];
@@ -19,6 +19,7 @@ declare class RectOperation extends BasicToolOperation {
19
19
  private _drawOutSideTarget;
20
20
  private selection;
21
21
  private dragInfo?;
22
+ private highlightVisible;
22
23
  constructor(props: IRectOperationProps);
23
24
  setResult(rectList: IRect[]): void;
24
25
  destroy(): void;
@@ -96,6 +97,7 @@ declare class RectOperation extends BasicToolOperation {
96
97
  attribute: string;
97
98
  textAttribute: string;
98
99
  disableDelete?: boolean | undefined;
100
+ isHighlight?: boolean | undefined;
99
101
  label?: string | undefined;
100
102
  };
101
103
  getRectsBoundaries(rects: IRect[], offset: ICoordinate): {
@@ -123,6 +125,7 @@ declare class RectOperation extends BasicToolOperation {
123
125
  onDragMoveAll(offset: ICoordinate): void;
124
126
  onDragMove(coordinate: ICoordinate): void;
125
127
  onMouseMove(e: MouseEvent): undefined;
128
+ setHighlightVisible(highlightVisible: boolean): void;
126
129
  setAttributeLockList(attributeLockList: string[]): void;
127
130
  setBasicResult(basicResult: any): void;
128
131
  setRectValidAndRender(id: string): void;
@@ -33,6 +33,7 @@ export default class AxisUtils {
33
33
  attribute: string;
34
34
  textAttribute: string;
35
35
  disableDelete?: boolean | undefined;
36
+ isHighlight?: boolean | undefined;
36
37
  label?: string | undefined;
37
38
  };
38
39
  /**
@@ -68,7 +68,7 @@ export default class CommonToolUtils {
68
68
  * @param selectedIDs 是否含有选中逻辑
69
69
  * @returns
70
70
  */
71
- static getRenderResultList<T = any>(resultList: any[], sourceID: string, attributeLockList?: string[], selectedIDs?: string[]): [T[], T[]];
71
+ static getRenderResultList<T = any>(resultList: any[], sourceID: string, attributeLockList?: string[], selectedIDs?: string[], highlightVisible?: boolean): [T[], T[]];
72
72
  /**
73
73
  * 获取当前依赖情况下的 sourceID 提取
74
74
  */
@@ -15,6 +15,15 @@ export interface IDrawTextConfig {
15
15
  textAlign: 'start' | 'center' | 'end' | 'left' | 'right';
16
16
  lineHeight: number;
17
17
  }
18
+ interface IDrawHighlightFlagParams {
19
+ canvas: HTMLCanvasElement;
20
+ color: string;
21
+ position: {
22
+ x: number;
23
+ y: number;
24
+ };
25
+ scale?: number;
26
+ }
18
27
  export default class DrawUtils {
19
28
  static drawImg: (canvas: HTMLCanvasElement, imgNode: HTMLImageElement | HTMLCanvasElement, options?: Partial<IOffsetCanvasPosition & {
20
29
  imgAttribute: IImageAttribute;
@@ -210,4 +219,14 @@ export default class DrawUtils {
210
219
  }): {
211
220
  canvas: HTMLCanvasElement;
212
221
  };
222
+ /**
223
+ * Draws a highlight flag.
224
+ * @param {IDrawHighlightFlagParams} params - The parameters for drawing the highlight flag.
225
+ * @param {Canvas} params.canvas - The canvas on which to draw the highlight flag.
226
+ * @param {Object} params.position - The position at which to draw the highlight flag.
227
+ * @param {string} params.color - The color of the highlight flag.
228
+ * @param {number} [params.scale=0.1] - The scale of the highlight flag.
229
+ */
230
+ static drawHighlightFlag(params: IDrawHighlightFlagParams): void;
213
231
  }
232
+ export {};
@@ -57,6 +57,7 @@ export default class RectUtils {
57
57
  attribute: string;
58
58
  textAttribute: string;
59
59
  disableDelete?: boolean | undefined;
60
+ isHighlight?: boolean | undefined;
60
61
  label?: string | undefined;
61
62
  };
62
63
  /**
@@ -1 +1 @@
1
- "use strict";var _=require("lodash"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));class CommonToolUtils{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===annotation.EStepType.QUALITY_INSPECTION||r.type===annotation.EStepType.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getCurrentStepToolAndConfig(t,e){const r=this.getStepInfo(t,e);if(r){const n=this.getCurrentStepInfo(t,e);return __spreadProps(__spreadValues({},r),{tool:n.tool,config:n.config})}return!1}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:n}=e;if(!r||!n)return!0;let i=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&n!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(i=!1),i}static isMoveKey(t){return[keyCode.Left,keyCode.Right,keyCode.Down,keyCode.Up,keyCode.Space].includes(t)}static getNextSelectedRectID(t,e=annotation.ESortDirection.ascend,r){let n=1;e===annotation.ESortDirection.descend&&(n=-1);const i=t.sort((l,c)=>l.x-c.x==0?l.y-c.y:n*(l.x-c.x)),a=i.findIndex(l=>l.id===r),s=i.length;return i[(a+1)%s]}static getNextSelectedRectIDByEvent(t,e,r){const n=e.shiftKey?annotation.ESortDirection.descend:annotation.ESortDirection.ascend;return this.getNextSelectedRectID(t,n,r)}static getRenderResultList(t,e,r=[],n){const i=[];return[t.filter(s=>n&&n.includes(s.id)?(i.push(s),!1):!(r.length>0&&!r.includes(s==null?void 0:s.attribute)||this.isDifferSourceID(s==null?void 0:s.sourceID,e))),i]}static getSourceID(t){var e;const r="";return t&&(e=t==null?void 0:t.id)!=null?e:r}static findAllLine(t,e=!0){const r=[],n=[...t];n.length>=3&&e===!0&&n.push(__spreadValues({},n[0]));for(let i=0;i<n.length;i++)n[i+1]&&r.push({point1:n[i],point2:n[i+1],pointIndex:i});return r}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],r){if((e==null?void 0:e.length)===0)return;let n=e.map((i,a)=>__spreadProps(__spreadValues({},i),{index:a}));if(typeof r=="number"&&r>0){const i=e[r];if(i&&t.every(a=>a.label!==i.value))return{label:i.value,index:r};n=[...n.slice(r,e.length),...n.slice(0,r)]}for(let i=0;i<n.length;i++)if(!t.some(a=>a.label===n[i].value))return{label:n[i].value,index:n[i].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(r=>t===r.value)}}CommonToolUtils.jsonParser=(o,t={})=>{try{return typeof o=="string"?JSON.parse(o):_.isObject(o)?o:t}catch(e){return t}},module.exports=CommonToolUtils;
1
+ "use strict";var _=require("lodash"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));class CommonToolUtils{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===annotation.EStepType.QUALITY_INSPECTION||r.type===annotation.EStepType.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getCurrentStepToolAndConfig(t,e){const r=this.getStepInfo(t,e);if(r){const n=this.getCurrentStepInfo(t,e);return __spreadProps(__spreadValues({},r),{tool:n.tool,config:n.config})}return!1}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:n}=e;if(!r||!n)return!0;let i=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&n!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(i=!1),i}static isMoveKey(t){return[keyCode.Left,keyCode.Right,keyCode.Down,keyCode.Up,keyCode.Space].includes(t)}static getNextSelectedRectID(t,e=annotation.ESortDirection.ascend,r){let n=1;e===annotation.ESortDirection.descend&&(n=-1);const i=t.sort((a,l)=>a.x-l.x==0?a.y-l.y:n*(a.x-l.x)),s=i.findIndex(a=>a.id===r),c=i.length;return i[(s+1)%c]}static getNextSelectedRectIDByEvent(t,e,r){const n=e.shiftKey?annotation.ESortDirection.descend:annotation.ESortDirection.ascend;return this.getNextSelectedRectID(t,n,r)}static getRenderResultList(t,e,r=[],n,i=!1){const s=[];return[t.filter(a=>n&&n.includes(a.id)?(s.push(a),!1):i?a==null?void 0:a.isHighlight:!(r.length>0&&!r.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),s]}static getSourceID(t){var e;const r="";return t&&(e=t==null?void 0:t.id)!=null?e:r}static findAllLine(t,e=!0){const r=[],n=[...t];n.length>=3&&e===!0&&n.push(__spreadValues({},n[0]));for(let i=0;i<n.length;i++)n[i+1]&&r.push({point1:n[i],point2:n[i+1],pointIndex:i});return r}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],r){if((e==null?void 0:e.length)===0)return;let n=e.map((i,s)=>__spreadProps(__spreadValues({},i),{index:s}));if(typeof r=="number"&&r>0){const i=e[r];if(i&&t.every(s=>s.label!==i.value))return{label:i.value,index:r};n=[...n.slice(r,e.length),...n.slice(0,r)]}for(let i=0;i<n.length;i++)if(!t.some(s=>s.label===n[i].value))return{label:n[i].value,index:n[i].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(r=>t===r.value)}}CommonToolUtils.jsonParser=(o,t={})=>{try{return typeof o=="string"?JSON.parse(o):_.isObject(o)?o:t}catch(e){return t}},module.exports=CommonToolUtils;
@@ -1,3 +1,3 @@
1
- "use strict";var rgba=require("color-rgba"),lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,thickness:s=1,lineCap:d="round",lineDash:n}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=d,n&&o.setLineDash(n),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=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",hiddenText:d=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),d===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,y=0,g=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+y},t.textAttribute,{textMaxWidth:g})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR}=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,d)=>`${s}${d.keyName}: ${d.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=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",lineType:d=tool.ELineTypes.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),d===tool.ELineTypes.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=PolygonUtils.createSmoothCurvePointsFromPointList([...t],tool.SEGMENT_NUMBER),a!==void 0&&a>-1&&(t=t.slice((tool.SEGMENT_NUMBER+1)*a,(tool.SEGMENT_NUMBER+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+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 u=t[h.i1],w=t[h.i2];e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(w.x,w.y),e.stroke()}),e.restore();const y=4,g=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,y+g,o),this.drawSpecialPoint(r,h,y,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:d=1,color:n=DEFAULT_COLOR,fill:a=DEFAULT_COLOR}=e,f=UnitUtils.deg2rad(l),c=UnitUtils.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=d,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR}=e;o.save();const s=UnitUtils.deg2rad(0),d=UnitUtils.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,d,!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 d=i*1.5,n=d*Math.sqrt(3)/2,a=d/2;o.moveTo(l,s-d),o.lineTo(l-n,s+a),o.lineTo(l+n,s+a),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=tool.ELineTypes.Line}=i;return e===!0&&(t=[...t,t[0]]),o===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,__spreadProps(__spreadValues({},i),{lineType:tool.ELineTypes.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,lineType:l=tool.ELineTypes.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...d]=t;return e.moveTo(s.x,s.y),d.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:d,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:d,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}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=DEFAULT_COLOR,font:s=tool.DEFAULT_FONT,shadowColor:d="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:y=0,offsetY:g=0,textAlign:h="start",lineHeight:u}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=d,o.shadowOffsetX=a,o.shadowOffsetY=f,o.shadowBlur=n,this.wrapText(r,`${i}`,t.x+y,t.y+g,c,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 d=t.split(`
3
- `);for(let n=0;n<d.length;n++){const a=d[n].split("");let f="";for(let c=0;c<a.length;c++){const y=f+a[c],h=s.measureText(y).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=a[c],e+=l):f=y}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",theta:d=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(a+d)*Math.PI/180,c=(a-d)*Math.PI/180,y=n*Math.cos(f),g=n*Math.sin(f),h=n*Math.cos(c),u=n*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+y,i.y+g),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:d,fillColor:n}=i,a={color:s,thickness:d};if(e){const c=AxisUtils.default.transformPlain2PointList(e);_DrawUtils.drawPolygon(r,c,__spreadProps(__spreadValues({},a),{isClose:!0}));const y=CuboidUtils.getCuboidAllSideLine(t);y==null||y.forEach(g=>{_DrawUtils.drawLine(r,g.p1,g.p2,__spreadValues({},a))})}const f=AxisUtils.default.transformPlain2PointList(l);if(o&&e&&l){const c=CuboidUtils.getPointListsByDirection({direction:o,frontPoints:l,backPoints:e});c&&_DrawUtils.drawPolygonWithFill(r,c,{color:n})}_DrawUtils.drawPolygon(r,f,__spreadProps(__spreadValues({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:d,selectedID:n,headerText:a,bottomText:f}=e,{backPoints:c,frontPoints:y,textAttribute:g}=t,h=y.br.x-y.bl.x;_DrawUtils.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} ${AttributeUtils.default.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!d&&c&&u&&_DrawUtils.drawText(r,{x:c.tl.x,y:c.tl.y-5},a!=null?a:u,{color:o,textMaxWidth:300});const w=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!d&&g&&t.id!==n){const x=Math.max(20,h*.8);_DrawUtils.drawText(r,{x:w.left,y:w.top},f!=null?f:g,{color:l,textMaxWidth:x})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const l=r.getContext("2d"),{width:s,height:d}=i,n=l.getImageData(0,0,s,d),[a,f,c,y]=rgba__default.default(e!=null?e:lbUtils.NULL_COLOR),g=u=>{n.data[u]=a,n.data[u+1]=f,n.data[u+2]=c,n.data[u+3]=Math.floor(255*y)},h=lbUtils.MathUtils.generateCoordinates(o);return t.forEach(u=>{for(const[w,x]of h){const C=(u.y+x)*(n.width*4)+(u.x+w)*4;g(C)}}),l.putImageData(n,0,0),{canvas:r}}};let DrawUtils=_DrawUtils;DrawUtils.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=DEFAULT_ZOOM,currentPos:l=DEFAULT_CURRENT_POS,rotate:s=DEFAULT_ROTATE,imgAttribute:d}=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(d){const{contrast:n,saturation:a,brightness:f}=d;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()},module.exports=DrawUtils;
1
+ "use strict";var rgba=require("color-rgba"),lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js");function _interopDefaultLegacy(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",HIGHLIGHT_ICON_SVG_PATHS=[{d:"M0.423514 10.1595C-0.362666 7.22543 1.37854 4.20957 4.3126 3.42339C7.24666 2.63721 10.2625 4.37842 11.0487 7.31248L49.8716 152.201C50.6577 155.135 48.9165 158.151 45.9825 158.937C43.0484 159.724 40.0325 157.982 39.2464 155.048L0.423514 10.1595Z"},{d:"M14.0774 9.47294C28.5 -16.5001 91.5 25.5001 113.138 0.529419L131.773 70.076C112 96.9999 50.5 54 32.7124 79.0196L14.0774 9.47294Z"}],_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:s=DEFAULT_COLOR,thickness:l=1,lineCap:c="round",lineDash:n}=e;o.save(),o.strokeStyle=s,o.lineWidth=l,o.lineCap=c,n&&o.setLineDash(n),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=DEFAULT_COLOR,thickness:s=1,lineCap:l="round",hiddenText:c=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),c===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const h=`${~~t.width} * ${~~t.height}`.length*7,u=0,y=Math.max(20,t.width-h);this.drawText(r,{x:t.x,y:t.y+t.height+20+u},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR}=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 s=document.createElement("div");return s.innerHTML=(i=t.reduce((l,c)=>`${l}${c.keyName}: ${c.value.join(" \u3001 ")}
2
+ `,""))!=null?i:"",s.setAttribute("id","tagToolTag"),e==null||e.appendChild(s),s}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:s=1,lineCap:l="round",lineType:c=tool.ELineTypes.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),c===tool.ELineTypes.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=PolygonUtils.createSmoothCurvePointsFromPointList([...t],tool.SEGMENT_NUMBER),a!==void 0&&a>-1&&(t=t.slice((tool.SEGMENT_NUMBER+1)*a,(tool.SEGMENT_NUMBER+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+2));const h=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let f=0;f<t.length-1;f++)t[f].specialEdge&&h.push({i1:f,i2:f+1}),e.lineTo(t[f+1].x,t[f+1].y);e.stroke(),e.save(),e.lineWidth=s*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),h.forEach(f=>{const g=t[f.i1],w=t[f.i2];e.beginPath(),e.moveTo(g.x,g.y),e.lineTo(w.x,w.y),e.stroke()}),e.restore();const u=4,y=2;return t.forEach(f=>{f.specialPoint&&(this.drawSpecialPoint(r,f,u+y,o),this.drawSpecialPoint(r,f,u,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:s=0,endAngleDeg:l=360,thickness:c=1,color:n=DEFAULT_COLOR,fill:a=DEFAULT_COLOR}=e,d=UnitUtils.deg2rad(s),h=UnitUtils.deg2rad(l);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=c,o.arc(t.x,t.y,i,d,h,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:s=DEFAULT_COLOR}=e;o.save();const l=UnitUtils.deg2rad(0),c=UnitUtils.deg2rad(360);o.fillStyle=s,o.beginPath(),o.arc(t.x,t.y,i,l,c,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:s,y:l}=t;o.save(),o.beginPath(),o.fillStyle=e;const c=i*1.5,n=c*Math.sqrt(3)/2,a=c/2;o.moveTo(s,l-c),o.lineTo(s-n,l+a),o.lineTo(s+n,l+a),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=tool.ELineTypes.Line}=i;return e===!0&&(t=[...t,t[0]]),o===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,__spreadProps(__spreadValues({},i),{lineType:tool.ELineTypes.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,lineType:s=tool.ELineTypes.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),s===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t,t[0]]));const[l,...c]=t;return e.moveTo(l.x,l.y),c.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:s,lineCap:l,isClose:c,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:s,lineCap:l,isClose:c,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygon(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygonWithFillAndLine(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:s=DEFAULT_COLOR,font:l=tool.DEFAULT_FONT,shadowColor:c="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:d=0,textMaxWidth:h=164,offsetX:u=0,offsetY:y=0,textAlign:f="start",lineHeight:g}=e;o.save(),o.textAlign=f,o.fillStyle=s!=null?s:"white",o.font=l,o.shadowColor=c,o.shadowOffsetX=a,o.shadowOffsetY=d,o.shadowBlur=n,this.wrapText(r,`${i}`,t.x+u,t.y+y,h,g),o.restore()}static wrapText(r,t,i,e,o,s){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const l=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
3
+ `);for(let n=0;n<c.length;n++){const a=c[n].split("");let d="";for(let h=0;h<a.length;h++){const u=d+a[h],f=l.measureText(u).width;o||(o=300),f>o&&h>0?(l.fillText(d,i,e),d=a[h],e+=s):d=u}l.fillText(d,i,e),e+=s}}static drawArrow(r,t,i,e={}){const{color:o=DEFAULT_COLOR,thickness:s=1,lineCap:l="round",theta:c=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,d=(a+c)*Math.PI/180,h=(a-c)*Math.PI/180,u=n*Math.cos(d),y=n*Math.sin(d),f=n*Math.cos(h),g=n*Math.sin(h);r.save(),r.strokeStyle=o,r.lineWidth=s,r.lineCap=l,r.beginPath(),r.moveTo(i.x+u,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+f,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:s}=t,{strokeColor:l,thickness:c,fillColor:n}=i,a={color:l,thickness:c};if(e){const h=AxisUtils.default.transformPlain2PointList(e);_DrawUtils.drawPolygon(r,h,__spreadProps(__spreadValues({},a),{isClose:!0}));const u=CuboidUtils.getCuboidAllSideLine(t);u==null||u.forEach(y=>{_DrawUtils.drawLine(r,y.p1,y.p2,__spreadValues({},a))})}const d=AxisUtils.default.transformPlain2PointList(s);if(o&&e&&s){const h=CuboidUtils.getPointListsByDirection({direction:o,frontPoints:s,backPoints:e});h&&_DrawUtils.drawPolygonWithFill(r,h,{color:n})}_DrawUtils.drawPolygon(r,d,__spreadProps(__spreadValues({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,s=o,{config:l,hiddenText:c,selectedID:n,headerText:a,bottomText:d}=e,{backPoints:h,frontPoints:u,textAttribute:y}=t,f=u.br.x-u.bl.x;_DrawUtils.drawCuboid(r,t,i);let g="";(l==null?void 0:l.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.attribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,l==null?void 0:l.attributeList)}`),!c&&h&&g&&_DrawUtils.drawText(r,{x:h.tl.x,y:h.tl.y-5},a!=null?a:g,{color:o,textMaxWidth:300});const w=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!c&&y&&t.id!==n){const x=Math.max(20,f*.8);_DrawUtils.drawText(r,{x:w.left,y:w.top},d!=null?d:y,{color:s,textMaxWidth:x})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const s=r.getContext("2d"),{width:l,height:c}=i,n=s.getImageData(0,0,l,c),[a,d,h,u]=rgba__default.default(e!=null?e:lbUtils.NULL_COLOR),y=g=>{n.data[g]=a,n.data[g+1]=d,n.data[g+2]=h,n.data[g+3]=Math.floor(255*u)},f=lbUtils.MathUtils.generateCoordinates(o);return t.forEach(g=>{for(const[w,x]of f){const C=(g.y+x)*(n.width*4)+(g.x+w)*4;y(C)}}),s.putImageData(n,0,0),{canvas:r}}static drawHighlightFlag(r){const{canvas:t,position:i,color:e,scale:o=.1}=r,s=t.getContext("2d");if(!!s)for(const l of HIGHLIGHT_ICON_SVG_PATHS){s.beginPath();const c=l.d.split(/(?=[CLMZclmz])/);for(const n of c){const d=n.slice(1).split(" ").map(Number).map((h,u)=>u%2==0?h*o+i.x:h*o+i.y);switch(n[0]){case"M":s.moveTo(d[0],d[1]);break;case"C":s.bezierCurveTo(d[0],d[1],d[2],d[3],d[4],d[5]);break;case"L":s.lineTo(d[0],d[1]);break;case"Z":s.closePath();break}}s.fillStyle=e,s.fill()}}};let DrawUtils=_DrawUtils;DrawUtils.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=DEFAULT_ZOOM,currentPos:s=DEFAULT_CURRENT_POS,rotate:l=DEFAULT_ROTATE,imgAttribute:c}=i;switch(e.save(),l){case 0:e.translate(s.x,s.y);break;case 90:e.translate(s.x+t.height*o,s.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(s.x+t.width*o,s.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(s.x,s.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(s.x,s.y);break}if(c){const{contrast:n,saturation:a,brightness:d}=c;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${d+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()},module.exports=DrawUtils;
@@ -1 +1 @@
1
- import a from"../../utils/uuid.js";import r from"../../constant/keyCode.js";import l from"../../utils/tool/CommonToolUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";class d extends u{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var o;e[n.key]=(o=n.default)!=null?o:""}),{value:e,id:a(),sourceID:i!=null?i:l.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),i={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),o=document.createElement("div"),s=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),o.innerText=`${e.key}:`,s.innerText="",s.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(o),n.appendChild(s),t.appendChild(n)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===r.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}export{d as default};
1
+ import r from"../../utils/uuid.js";import a from"../../constant/keyCode.js";import l from"../../utils/tool/CommonToolUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";class d extends u{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var o;e[n.key]=(o=n.default)!=null?o:""}),{value:e,id:r(),sourceID:i!=null?i:l.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config)}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}toggleShowText(t){this.toggleTextContainerVisible(t)}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}init(){super.init(),this.initTextDisplayContainer()}initTextDisplayContainer(){const t=document.createElement("div"),i={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),o=document.createElement("div"),s=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),o.innerText=`${e.key}:`,s.innerText="",s.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(o),n.appendChild(s),t.appendChild(n)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===a.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}export{d as default};
@@ -1 +1 @@
1
- import{ImgPosUtils as N}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import z from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as O,DEFAULT_FONT as j,SEGMENT_NUMBER as U}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as L,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import V,{cropAndEnlarge as G}from"../../utils/ImgUtils.js";import K from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as X}from"./basicToolOperation.js";import{pointCloudLidar2image as q}from"../pointCloud/matrix.js";var Y=Object.defineProperty,J=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,tt=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,F=(v,t,e)=>t in v?Y(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,m=(v,t)=>{for(var e in t||(t={}))tt.call(t,e)&&F(v,e,t[e]);if($)for(var e of $(t))et.call(t,e)&&F(v,e,t[e]);return v},_=(v,t)=>J(v,Q(t)),ot=(v,t,e)=>new Promise((o,i)=>{var r=a=>{try{s(e.next(a))}catch(n){i(n)}},c=a=>{try{s(e.throw(a))}catch(n){i(n)}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((e=e.apply(v,t)).next())});const it=3,nt=3,A="#6371FF";class st extends X{constructor(t){super(_(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),s=T.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",n=Number.MAX_SAFE_INTEGER;for(let d=0;d<this.annotations.length;d++){const l=this.annotations[d];switch(l.type){case"rect":{const u=l.annotation;if(Z.isInRect(c,u,it,this.zoom)){const f=u.width*u.height;f<n&&(a=u.id,n=f)}break}case"polygon":{const u=l.annotation;if(z.isInPolygon(s,u.pointList)){const f=z.getPolygonArea(u.pointList);f<n&&(a=u.id,n=f)}break}}}return a};var e;this.style=(e=t.style)!=null?e:{stroke:A,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=C.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(s=>{this.connectionPoints=s.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:s.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const o=G(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);V.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){return ot(this,null,function*(){if(!E.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,o=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const i=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:o}),this.staticImgNode=i}})}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=m(m({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return _(m({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=N.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(_(m({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=T.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=O.Line}=s,n=T.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos),d=_(m(m({},r),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:a,strokeColor:r.stroke});let l=[];if(s.showKeyPoint?l=h.drawPolygonWithKeyPoint(this.canvas,n,d):l=h.drawPolygon(this.canvas,n,d),(s==null?void 0:s.showDirection)===!0&&((i=s==null?void 0:s.pointList)==null?void 0:i.length)>=2){let p=n[0],P=C.getLineCenterPoint([n[0],n[1]]);if(a===O.Curve){const g=Math.floor(U/2);p=l[g],P=l[g+1]}h.drawArrowByCanvas(this.canvas,p,P,{color:r.stroke,thickness:r.thickness}),h.drawCircle(this.canvas,n[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(n[0]),f,c),y){const p=n[n.length-1];h.drawText(this.canvas,this.appendOffset({x:p.x+L.x,y:p.y+L.y}),y,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:s,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:d=O.Line}=n,l=T.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||s.fill){const g=M((r=(i=s==null?void 0:s.fill)!=null?i:s==null?void 0:s.stroke)!=null?r:A),x=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;h.drawPolygonWithFill(this.canvas,l,{color:x,lineType:d})}const u=_(m(_(m({},s),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:d,strokeColor:s.stroke});let f=[];if(n.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,l,u):f=h.drawPolygon(this.canvas,l,u),(n==null?void 0:n.showDirection)===!0&&((c=n==null?void 0:n.pointList)==null?void 0:c.length)>=2){let g=l[0],x=C.getLineCenterPoint([l[0],l[1]]);if(d===O.Curve){const w=Math.floor(U/2);g=f[w],x=f[w+1]}h.drawArrowByCanvas(this.canvas,g,x,{color:s.stroke,thickness:s.thickness}),h.drawCircle(this.canvas,l[0],s.thickness+6,{color:s.stroke,thickness:s.thickness})}const{headerText:p,bottomText:P}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(p&&h.drawText(this.canvas,this.appendOffset(l[0]),p,a),P){const g=l[l.length-1];h.drawText(this.canvas,this.appendOffset({x:g.x+L.x,y:g.y+L.y}),P,a)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:A),s=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,a=i.stroke,n=T.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:l}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,n,{strokeColor:a,fillColor:s,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:l})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=q(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},c=E.pick(o,["stroke","thickness"]);i.forEach((s,a)=>{const n=m(_(m({},c),{id:`${t.annotation.id}-${a}`,pointList:s.pointList}),r);switch(s.type){case"line":this.renderLine({type:"line",annotation:n});break;case"polygon":this.renderPolygon({type:"polygon",annotation:n});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const o=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(o.length>0)){console.warn("Empty pixelPoints");return}const i=this.imgNode.src+o.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){h.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:s,canvas:a}=K.createCanvas(c),n=typeof t.pixelSize=="number"?t.pixelSize:13;s&&(o==null?void 0:o.length)>0&&(h.drawPixel({canvas:a,points:o,size:c,defaultRGBA:t.defaultRGBA,pixelSize:n}),h.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,c,s;const a=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const d=e.annotation,{hiddenText:l=!1,isReference:u,hiddenRectSize:f=!1}=d,{zoom:y}=this,p=T.changeRectByZoom(d,this.zoom,this.currentPos),{x:P,y:g,width:x,height:w}=p;if(d.id===this.mouseHoverID||a.fill){const b=M((i=(o=a==null?void 0:a.fill)!=null?o:a==null?void 0:a.stroke)!=null?i:A),k=`rgba(${b[0]}, ${b[1]}, ${b[2]},${b[3]*.8})`;h.drawRectWithFill(this.canvas,p,{color:k})}h.drawRect(this.canvas,p,m(_(m({},a),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:I,bottomText:D}=this.getRenderText(d,d==null?void 0:d.hiddenText);I&&h.drawText(this.canvas,{x:P,y:g-6},I,m({textMaxWidth:300},n));const S=`${Math.round(x/y)} * ${Math.round(w/y)}`,R=S.length*7;if(!l&&!f&&h.drawText(this.canvas,{x:P+x-R,y:g+w+15},S,n),D){const b=20,k=Math.max(20,x-R);h.drawText(this.canvas,{x:P,y:g+w+b},d.textAttribute,m({textMaxWidth:k},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const d=e.annotation,l=T.changePointByZoom(d,this.zoom,this.currentPos),u=(r=a.radius)!=null?r:nt;h.drawCircle(this.canvas,l,u,a);const{headerText:f,bottomText:y}=this.getRenderText(d,d==null?void 0:d.hiddenText);f&&h.drawText(this.canvas,{x:l.x+u/2,y:l.y-u-4},f,m({textAlign:"center"},n)),y&&h.drawText(this.canvas,this.appendOffset({x:l.x+u,y:l.y+u+24}),y,n);break}case"text":{const d=e.annotation,{text:l,x:u,y:f,textMaxWidth:y,color:p="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:x=j,position:w}=d,I=10,D=10,S=T.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:R,height:b,fontHeight:k=0}=C.getTextArea(this.canvas,d.text,y,x,g);if(w==="rt")break;h.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:R+D*2,height:b+I*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),h.drawText(this.canvas,{x:S.x+D,y:S.y+k+I},l,{color:p,lineHeight:g,font:x,textMaxWidth:y});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{st as default};
1
+ import{ImgPosUtils as H}from"@labelbee/lb-utils";import E from"lodash";import M from"color-rgba";import d from"../../utils/tool/DrawUtils.js";import b from"../../utils/tool/AxisUtils.js";import W from"../../utils/tool/RectUtils.js";import z from"../../utils/tool/PolygonUtils.js";import k from"../../utils/MathUtils.js";import j from"../../utils/tool/RenderDomClass.js";import{ELineTypes as R,DEFAULT_FONT as V,SEGMENT_NUMBER as U}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as O,DEFAULT_TEXT_SHADOW as G}from"../../constant/annotation.js";import K,{cropAndEnlarge as X}from"../../utils/ImgUtils.js";import q from"../../utils/tool/CanvasUtils.js";import{BasicToolOperation as Y}from"./basicToolOperation.js";import{pointCloudLidar2image as J}from"../pointCloud/matrix.js";var Q=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,F=(v,t,e)=>t in v?Q(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,m=(v,t)=>{for(var e in t||(t={}))ot.call(t,e)&&F(v,e,t[e]);if($)for(var e of $(t))it.call(t,e)&&F(v,e,t[e]);return v},T=(v,t)=>tt(v,et(t)),nt=(v,t,e)=>new Promise((o,i)=>{var r=a=>{try{s(e.next(a))}catch(n){i(n)}},c=a=>{try{s(e.throw(a))}catch(n){i(n)}},s=a=>a.done?o(a.value):Promise.resolve(a.value).then(r,c);s((e=e.apply(v,t)).next())});const st=3,rt=3,L="#6371FF";class at extends Y{constructor(t){super(T(m({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),s=b.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let a="",n=Number.MAX_SAFE_INTEGER;for(let h=0;h<this.annotations.length;h++){const l=this.annotations[h];switch(l.type){case"rect":{const u=l.annotation;if(W.isInRect(c,u,st,this.zoom)){const g=u.width*u.height;g<n&&(a=u.id,n=g)}break}case"polygon":{const u=l.annotation;if(z.isInPolygon(s,u.pointList)){const g=z.getPolygonArea(u.pointList);g<n&&(a=u.id,n=g)}break}}}return a};var e;this.style=(e=t.style)!=null?e:{stroke:L,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new j({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=k.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(s=>{this.connectionPoints=s.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({connectionPoints:s.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const o=X(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);K.load(o).then(i=>{this.staticImgNode=i,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){return nt(this,null,function*(){if(!E.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,o=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const i=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:o}),this.staticImgNode=i}})}getSpecificStyle(t){const e=E.pick(t,["stroke","thickness","fill","radius"]),o=m(m({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return T(m({},G),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.offsetY}}getRenderText(t,e=!1){let o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=k.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=H.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(T(m({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=b.changePointByZoom(t,this.zoom,this.currentPos);d.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),d.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=2))return;const{lineType:a=R.Line}=s,n=b.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos),h=T(m(m({},r),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:a,strokeColor:r.stroke});let l=[];if(s.showKeyPoint?l=d.drawPolygonWithKeyPoint(this.canvas,n,h):l=d.drawPolygon(this.canvas,n,h),(s==null?void 0:s.showDirection)===!0&&((i=s==null?void 0:s.pointList)==null?void 0:i.length)>=2){let p=n[0],P=k.getLineCenterPoint([n[0],n[1]]);if(a===R.Curve){const f=Math.floor(U/2);p=l[f],P=l[f+1]}d.drawArrowByCanvas(this.canvas,p,P,{color:r.stroke,thickness:r.thickness}),d.drawCircle(this.canvas,n[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(g&&d.drawText(this.canvas,this.appendOffset(n[0]),g,c),y){const p=n[n.length-1];d.drawText(this.canvas,this.appendOffset({x:p.x+O.x,y:p.y+O.y}),y,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:s,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=3))return;const{lineType:h=R.Line}=n,l=b.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);if(n.id===this.mouseHoverID||s.fill){const f=M((r=(i=s==null?void 0:s.fill)!=null?i:s==null?void 0:s.stroke)!=null?r:L),x=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;d.drawPolygonWithFill(this.canvas,l,{color:x,lineType:h})}const u=T(m(T(m({},s),{isClose:!0}),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:s.stroke});let g=[];if(n.showKeyPoint?g=d.drawPolygonWithKeyPoint(this.canvas,l,u):g=d.drawPolygon(this.canvas,l,u),(n==null?void 0:n.showDirection)===!0&&((c=n==null?void 0:n.pointList)==null?void 0:c.length)>=2){let f=l[0],x=k.getLineCenterPoint([l[0],l[1]]);if(h===R.Curve){const w=Math.floor(U/2);f=g[w],x=g[w+1]}d.drawArrowByCanvas(this.canvas,f,x,{color:s.stroke,thickness:s.thickness}),d.drawCircle(this.canvas,l[0],s.thickness+6,{color:s.stroke,thickness:s.thickness})}const{headerText:p,bottomText:P}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(p&&d.drawText(this.canvas,this.appendOffset(l[0]),p,a),P){const f=l[l.length-1];d.drawText(this.canvas,this.appendOffset({x:f.x+O.x,y:f.y+O.y}),P,a)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=M((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:L),s=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,a=i.stroke,n=b.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:h,bottomText:l}=this.getRenderText(r,r==null?void 0:r.hiddenText);d.drawCuboidWithText(this.canvas,n,{strokeColor:a,fillColor:s,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:h,bottomText:l})}renderBox3d(t){var e;if(t.type!=="box3d")return;const o=t.annotation,{transferViewData:i}=(e=J(o,o.calib))!=null?e:{};if(!i)return;const r={fill:"transparent"},c=E.pick(o,["stroke","thickness"]);i.forEach((s,a)=>{const n=m(T(m({},c),{id:`${t.annotation.id}-${a}`,pointList:s.pointList}),r);switch(s.type){case"line":this.renderLine({type:"line",annotation:n});break;case"polygon":this.renderPolygon({type:"polygon",annotation:n});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const o=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(o.length>0)){console.warn("Empty pixelPoints");return}const i=this.imgNode.src+o.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[i];if(r){d.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const c={width:this.imgNode.width,height:this.imgNode.height},{ctx:s,canvas:a}=q.createCanvas(c),n=typeof t.pixelSize=="number"?t.pixelSize:13;s&&(o==null?void 0:o.length)>0&&(d.drawPixel({canvas:a,points:o,size:c,defaultRGBA:t.defaultRGBA,pixelSize:n}),d.drawImg(this.canvas,a,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[i]:a})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var o,i,r,c,s;const a=this.getSpecificStyle(e.annotation),n=this.getFontStyle(e.annotation,a);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:l=!1,isReference:u,hiddenRectSize:g=!1}=h,{zoom:y}=this,p=b.changeRectByZoom(h,this.zoom,this.currentPos),{x:P,y:f,width:x,height:w}=p,_=M((i=(o=a==null?void 0:a.fill)!=null?o:a==null?void 0:a.stroke)!=null?i:L),I=`rgba(${_[0]}, ${_[1]}, ${_[2]},${_[3]*.8})`;(h.id===this.mouseHoverID||a.fill)&&d.drawRectWithFill(this.canvas,p,{color:I}),d.drawRect(this.canvas,p,m(T(m({},a),{hiddenText:!0}),this.getReferenceOptions(u))),(h==null?void 0:h.isHighlight)&&d.drawHighlightFlag({canvas:this.canvas,color:I,position:{x:P-16,y:f-16}});const{headerText:S,bottomText:A}=this.getRenderText(h,h==null?void 0:h.hiddenText);S&&d.drawText(this.canvas,{x:P,y:f-6},S,m({textMaxWidth:300},n));const C=`${Math.round(x/y)} * ${Math.round(w/y)}`,D=C.length*7;if(!l&&!g&&d.drawText(this.canvas,{x:P+x-D,y:f+w+15},C,n),A){const N=20,Z=Math.max(20,x-D);d.drawText(this.canvas,{x:P,y:f+w+N},h.textAttribute,m({textMaxWidth:Z},n))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,l=b.changePointByZoom(h,this.zoom,this.currentPos),u=(r=a.radius)!=null?r:rt;d.drawCircle(this.canvas,l,u,a);const{headerText:g,bottomText:y}=this.getRenderText(h,h==null?void 0:h.hiddenText);g&&d.drawText(this.canvas,{x:l.x+u/2,y:l.y-u-4},g,m({textAlign:"center"},n)),y&&d.drawText(this.canvas,this.appendOffset({x:l.x+u,y:l.y+u+24}),y,n);break}case"text":{const h=e.annotation,{text:l,x:u,y:g,textMaxWidth:y,color:p="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:x=V,position:w}=h,_=10,I=10,S=b.changePointByZoom({x:u,y:g},this.zoom,this.currentPos),{width:A,height:C,fontHeight:D=0}=k.getTextArea(this.canvas,h.text,y,x,f);if(w==="rt")break;d.drawRectWithFill(this.canvas,{x:S.x,y:S.y,width:A+I*2,height:C+_*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),d.drawText(this.canvas,{x:S.x+I,y:S.y+D+_},l,{color:p,lineHeight:f,font:x,textMaxWidth:y});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}export{at as default};
@@ -1 +1 @@
1
- import B from"lodash";import{distance as N}from"@turf/turf";import O from"../../utils/MathUtils.js";import w from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import{EDragStatus as y,ESortDirection as U,DEFAULT_TEXT_SHADOW as T}from"../../constant/annotation.js";import{EDragTarget as D,EOperationMode as K}from"../../constant/tool.js";import S from"../../constant/keyCode.js";import k from"../../locales/index.js";import{EMessage as M}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import E from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import L from"../../utils/tool/DrawUtils.js";import V from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as P}from"../../utils/tool/polygonTool.js";import $ from"../../utils/uuid.js";import{BasicToolOperation as F}from"./basicToolOperation.js";import X from"./textAttributeClass.js";import Y from"./Selection.js";var G=Object.defineProperty,J=Object.defineProperties,q=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,H=(v,t,e)=>t in v?G(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,f=(v,t)=>{for(var e in t||(t={}))Q.call(t,e)&&H(v,e,t[e]);if(j)for(var e of j(t))tt.call(t,e)&&H(v,e,t[e]);return v},m=(v,t)=>J(v,q(t));const C=6;class W extends F{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const s=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===s);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const s=this.getCoordinateUnderZoom(e),r=C,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&I.isInRect(s,a,r,this.zoom))return a.id}const i=o.filter(a=>I.isInRect(s,a,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(n=>({size:n.width*n.height,id:n.id})).sort((n,c)=>n.size-c.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(p.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.selection=new Y(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const s=this.rectList.length;this.rectList=t,s!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,s]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;p.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",p.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(s=>s.id===this.selectedRectID?m(f({},s),{textAttribute:e}):s),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?w.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),C+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:s}=this,r=I.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const a=r[i],{length:n}=O.getFootOfPerpendicular(o,a.begin,a.end);n<C+10&&(e=i)}return e}getTextIconSvg(t=""){return p.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),s=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const o=D.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=D.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}}if(this.selection.isIdSelected(s)&&!this.drawingRect){const r=D.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=y.Start}}}appendOffsetRect(t,e){return m(f({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const s=t.reduce((r,o)=>r.concat(...I.getRectPointList(this.appendOffsetRect(o,e))),[]);return O.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,o,i;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),n={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return I.isRectNotInPolygon(n,P(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const c=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(i=this.imgNode)==null?void 0:i.width};if(c)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!I.isInRect(d,c))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=B.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>m(f({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=s.find(i=>i.id===r.id);return o||r}))}}onDragMoveAll(t){var e,s;!((s=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:s.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>m(f({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,s,r,o;if(!this.dragInfo)return;const i={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=y.Move,this.dragInfo.dragTarget===D.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const a=I.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:c,width:d,height:h}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case D.Point:{let g=n,x=c,u=d,b=h;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?n+d:n+i.x,x=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-d),b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,x=h-i.y<0?c+h:c+i.y,u=Math.abs(d+i.x),b=Math.abs(h-i.y);break}case 2:{g=d+i.x>0?n:n+d+i.x,x=h+i.y>0?c:c+h+i.y,u=Math.abs(d+i.x),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,x=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-d),b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}l=m(f({},l),{x:g,y:x,width:u,height:b})}break;case D.Line:{let g=n,x=c,u=d,b=h;switch(this.hoverRectEdgeIndex){case 0:{x=h-i.y<0?c+h:c+i.y,b=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,u=Math.abs(d+i.x);break}case 2:{x=h+i.y>0?c:c+h+i.y,b=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,u=Math.abs(i.x-d);break}default:return}l=m(f({},l),{x:g,y:x,width:u,height:b});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&I.isRectNotInPolygon(l,P(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,x=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<x-.01||l.width>g+u-l.x+.01||l.height>x+b-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<x&&(l.y=x),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case D.Point:case D.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>x+b-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?I.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){var e,s;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=w.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=i,i!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:c}=this.firstClickCoord,{width:d,height:h}=this.drawingRect;if(d=Math.abs(n-o.x),h=Math.abs(c-o.y),o.x<n&&(n=o.x),o.y<c&&(c=o.y),this.drawOutSideTarget===!1){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&I.isRectNotInPolygon(m(f({},this.drawingRect),{x:n,y:c,width:d,height:h}),P(this.basicResult.pointList,this.zoom)))return;o.x<0&&(d=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(h=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(n+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-n)),c+h>this.imgInfo.height&&(h=Math.abs(this.imgInfo.height-c)))}this.drawingRect=m(f({},this.drawingRect),{x:n,y:c,width:d,height:h}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?m(f({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),r=w.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=m(f({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:$(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=m(f({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",k.getMessagesByLocale(M.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=p.getTextAttribute(this.rectList.filter(i=>R.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=m(f({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=f({},r),this.firstCurrentPos=f({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",k.getMessagesByLocale(M.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait,this.render();return}const s=this.getDrawingRectWithRectList();this.setRectList(s,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:s,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,s/=this.zoom,r/=this.zoom,[...this.rectList,m(f({},this.drawingRect),{x:t,y:e,width:s,height:r})]}rightMouseUp(t){var e,s,r;const o=this.getHoverRectID(t),i=this.rectList.find(a=>a.id===o);if(this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&N((s=this.dragInfo)==null?void 0:s.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(o,t.ctrlKey),i&&((r=this.selectedIDs)==null?void 0:r.length)===1&&this.setDefaultAttribute(i.attribute),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const a=R.getCurrentMarkerIndex(i.label,this.config.markerList);a>=0&&(this.setMarkerIndex(a),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",f({},this.selectedRect))}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===y.Move){this.dragInfo=void 0,this.dragStatus=y.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case S.Ctrl:this.drawingRect&&(this.drawingRect=m(f({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case S.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case S.Z:this.setIsHidden(!this.isHidden),this.render();break;case S.Delete:this.deleteSelectedRect();break;case S.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=U.ascend;t.shiftKey&&(s=U.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const a=E.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>E.inViewPort({x:c.x,y:c.y},a));const n=R.getNextSelectedRectID(i,s,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const s=p.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case S.Ctrl:this.drawingRect&&(this.drawingRect=m(f({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let s,r;this.drawingRect&&this.firstClickCoord&&(s=I.getRectUnderZoom(this.drawingRect,1/e),r=w.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=I.getRectUnderZoom(s,this.zoom),this.firstClickCoord=w.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),s=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:s}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const s=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,o=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,o=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:s}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:s,y:r,width:o,height:i,attribute:a,valid:n}=e,c=o*this.zoom*.6,d=w.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),h=this.getColor(a),l=n?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new X({width:c,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+g,color:l,width:c})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=I.getRectPointList(t),o=r.length,i=this.getColor(t.attribute);r.forEach((a,n)=>{var c,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===n?s=C+6:s=C,t.valid===!1?(e.strokeStyle=i==null?void 0:i.invalid.stroke,e.fillStyle=i==null?void 0:i.invalid.stroke):(e.strokeStyle=i==null?void 0:i.valid.stroke,e.fillStyle=i==null?void 0:i.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const h=this.getColor(t.attribute),l=t.valid===!1?(c=h==null?void 0:h.invalid)==null?void 0:c.stroke:(d=h==null?void 0:h.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[n].x*this.zoom+this.currentPos.x,r[n].y*this.zoom+this.currentPos.y),e.lineTo(r[(n+1)%o].x*this.zoom+this.currentPos.x,r[(n+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,o,i,a;if(this.ctx&&t){const{ctx:n,style:c}=this,{hiddenText:d=!1}=c;n.save();const{strokeColor:h,fillColor:l,textColor:g}=this.getRenderStyle(t);n.font="lighter 14px Arial";let x="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(x=`${t.order}`),t.label&&this.hasMarkerConfig&&(x=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${V.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(x=`${x} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=w.changeRectByZoom(t,s?e:this.zoom,this.currentPos);d||L.drawText(this.canvas,{x:u.x,y:u.y-6},x,m(f({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},T),{textMaxWidth:300}));const b=(a=(i=this.style)==null?void 0:i.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&L.drawRectWithFill(this.canvas,u,{color:l}),L.drawRect(this.canvas,u,{color:h,thickness:b,hiddenText:!0}),n.restore();let A=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(A=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const _=A.length*7;if(d||L.drawText(this.canvas,{x:u.x+u.width-_,y:u.y+u.height+15},A,f({color:g,font:"normal normal 600 14px Arial"},T)),!d&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,u.width-_);L.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+z},t.textAttribute,f({color:g,font:"italic normal 900 14px Arial",textMaxWidth:Z},T))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);this.isHidden||s==null||s.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,w.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,w.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))})}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,w.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(s=>this.selection.isIdSelected(s.id)?m(f({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=m(f({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait,this.setSelectedRectID(void 0),this.setOperationMode(K.General)}clearResult(t=!0){const e=this.rectList.filter(s=>s.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",k.getMessagesByLocale(M.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const s=this.rectList.find(r=>r.id===t);if((s==null?void 0:s.disableDelete)===!0){this.emit("messageInfo",k.getMessagesByLocale(M.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
1
+ import B from"lodash";import{distance as N}from"@turf/turf";import O from"../../utils/MathUtils.js";import w from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/RectUtils.js";import{EDragStatus as y,ESortDirection as U,DEFAULT_TEXT_SHADOW as T}from"../../constant/annotation.js";import{EDragTarget as D,EOperationMode as V}from"../../constant/tool.js";import S from"../../constant/keyCode.js";import k from"../../locales/index.js";import{EMessage as A}from"../../locales/constants.js";import p from"../../utils/tool/AttributeUtils.js";import E from"../../utils/tool/CanvasUtils.js";import R from"../../utils/tool/CommonToolUtils.js";import L from"../../utils/tool/DrawUtils.js";import K from"../../utils/tool/MarkerUtils.js";import{getPolygonPointUnderZoom as P}from"../../utils/tool/polygonTool.js";import $ from"../../utils/uuid.js";import{BasicToolOperation as F}from"./basicToolOperation.js";import X from"./textAttributeClass.js";import Y from"./Selection.js";var G=Object.defineProperty,J=Object.defineProperties,q=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,j=(v,t,e)=>t in v?G(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,f=(v,t)=>{for(var e in t||(t={}))Q.call(t,e)&&j(v,e,t[e]);if(H)for(var e of H(t))tt.call(t,e)&&j(v,e,t[e]);return v},x=(v,t)=>J(v,q(t));const C=6;class W extends F{constructor(t){super(t);this.highlightVisible=!1,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const s=this.config.markerList[e].value,r=this.currentPageResult.find(o=>o.label===s);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const s=this.getCoordinateUnderZoom(e),r=C,{currentShowList:o}=this;if(o.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&I.isInRect(s,a,r,this.zoom))return a.id}const i=o.filter(a=>I.isInRect(s,a,r,this.zoom));if(i.length===0)return"";if(i.length===1)return i[0].id;if(i.length>1)return i.map(n=>({size:n.width*n.height,id:n.id})).sort((n,c)=>n.size-c.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(p.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=R.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.selection=new Y(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=R.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=R.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const s=this.rectList.length;this.rectList=t,s!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,s]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),s&&t.push(...s),t}get currentPageResult(){const[t]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=R.getRenderResultList(t,R.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;p.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",p.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(s=>s.id===this.selectedRectID?x(f({},s),{textAttribute:e}):s),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?w.returnClosePointIndex(this.getCoordinateUnderZoom(t),I.getRectPointList(this.selectedRect,this.zoom),C+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:s}=this,r=I.getRectEdgeList(s,this.zoom),o=this.getCoordinateUnderZoom(t);for(let i=0;i<r.length;i++){const a=r[i],{length:n}=O.getFootOfPerpendicular(o,a.begin,a.end);n<C+10&&(e=i)}return e}getTextIconSvg(t=""){return p.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),s=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(o=>o.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const o=D.Point;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const o=D.Line;this.dragInfo={dragStartCoord:e,dragTarget:o,startTime:+new Date,firstRect:r},this.dragStatus=y.Start;return}}if(this.selection.isIdSelected(s)&&!this.drawingRect){const r=D.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=y.Start}}}appendOffsetRect(t,e){return x(f({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const s=t.reduce((r,o)=>r.concat(...I.getRectPointList(this.appendOffsetRect(o,e))),[]);return O.calcViewportBoundaries(s)}isRectsOutOfTarget(t,e){var s,r,o,i;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),n={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(s=this.basicResult)==null?void 0:s.pointList)==null?void 0:r.length)>0)return I.isRectNotInPolygon(n,P(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const c=this.basicResult?this.basicResult:{x:0,y:0,height:(o=this.imgNode)==null?void 0:o.height,width:(i=this.imgNode)==null?void 0:i.width};if(c)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!I.isInRect(d,c))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let s=B.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(s,t))return;s=this.dragInfo.originRectList.map(r=>x(f({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const o=s.find(i=>i.id===r.id);return o||r}))}}onDragMoveAll(t){var e,s;!((s=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:s.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>x(f({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,s,r,o;if(!this.dragInfo)return;const i={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=y.Move,this.dragInfo.dragTarget===D.Plane){this.moveRects(i);return}if(!this.dragInfo.firstRect)return;const a=I.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:n,y:c,width:d,height:h}=a;let l=this.rectList.filter(g=>g.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case D.Point:{let g=n,b=c,u=d,m=h;switch(this.hoverRectPointIndex){case 0:{g=d-i.x<0?n+d:n+i.x,b=h-i.y<0?c+h:c+i.y,u=Math.abs(i.x-d),m=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,b=h-i.y<0?c+h:c+i.y,u=Math.abs(d+i.x),m=Math.abs(h-i.y);break}case 2:{g=d+i.x>0?n:n+d+i.x,b=h+i.y>0?c:c+h+i.y,u=Math.abs(d+i.x),m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,b=h+i.y>0?c:c+h+i.y,u=Math.abs(i.x-d),m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}default:return}l=x(f({},l),{x:g,y:b,width:u,height:m})}break;case D.Line:{let g=n,b=c,u=d,m=h;switch(this.hoverRectEdgeIndex){case 0:{b=h-i.y<0?c+h:c+i.y,m=Math.abs(i.y-h);break}case 1:{g=d+i.x>0?n:n+d+i.x,u=Math.abs(d+i.x);break}case 2:{b=h+i.y>0?c:c+h+i.y,m=h+i.y>0?h+i.y:Math.abs(h+i.y);break}case 3:{g=d-i.x<0?n+d:n+i.x,u=Math.abs(i.x-d);break}default:return}l=x(f({},l),{x:g,y:b,width:u,height:m});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&I.isRectNotInPolygon(l,P(this.basicResult.pointList,this.zoom)))return;const g=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,u=this.basicResult.width*this.zoom,m=this.basicResult.height*this.zoom;if(l.x<g-.01||l.y<b-.01||l.width>g+u-l.x+.01||l.height>b+m-l.y+.01)return;if(l.x<g&&(l.x=g),l.y<b&&(l.y=b),l.width>g+u-l.x)switch(this.dragInfo.dragTarget){case D.Point:case D.Line:i.x>0&&i.y>0&&(l.width=g+u-l.x);break;default:return}if(l.height>b+m-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((o=this.imgInfo)==null?void 0:o.height)+.01)return}}this.setRectList(this.rectList.map(g=>g.id===l.id?I.getRectUnderZoom(l,1/this.zoom):g)),this.render()}onMouseMove(t){var e,s;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),o=w.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(o);return}if(this.selectedRectID){const n=this.getHoverRectPointIndex(t);if(n!==this.hoverRectPointIndex){this.hoverRectPointIndex=n,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const c=this.getHoverRectEdgeIndex(t);if(c!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=c,this.render();return}}}const i=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=i,i!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:n,y:c}=this.firstClickCoord,{width:d,height:h}=this.drawingRect;if(d=Math.abs(n-o.x),h=Math.abs(c-o.y),o.x<n&&(n=o.x),o.y<c&&(c=o.y),this.drawOutSideTarget===!1){if(((s=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:s.length)>0&&I.isRectNotInPolygon(x(f({},this.drawingRect),{x:n,y:c,width:d,height:h}),P(this.basicResult.pointList,this.zoom)))return;o.x<0&&(d=Math.abs(this.firstClickCoord.x),n=0),o.y<0&&(h=Math.abs(this.firstClickCoord.y),c=0),this.imgInfo&&(n+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-n)),c+h>this.imgInfo.height&&(h=Math.abs(this.imgInfo.height-c)))}this.drawingRect=x(f({},this.drawingRect),{x:n,y:c,width:d,height:h}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?x(f({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),r=w.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(r.x<0&&(r.x=0),r.y<0&&(r.y=0)),this.drawingRect=x(f({},r),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:$(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const o=R.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(o)this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{label:o.label})),this.markerIndex=o.index,this.emit("markIndexChange");else{this.emit("messageInfo",k.getMessagesByLocale(A.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let o="";o=p.getTextAttribute(this.rectList.filter(i=>R.isSameSourceID(i.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{textAttribute:o}))}if(Object.assign(this.drawingRect,{order:R.getMaxOrder(this.rectList.filter(o=>R.isSameSourceID(o.sourceID,e)))+1}),this.firstClickCoord=f({},r),this.firstCurrentPos=f({},this.currentPos),this.dataInjectionAtCreation){const o=this.dataInjectionAtCreation(this.drawingRect);o&&Object.assign(this.drawingRect,o)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",k.getMessagesByLocale(A.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait,this.render();return}const s=this.getDrawingRectWithRectList();this.setRectList(s,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:s,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,s/=this.zoom,r/=this.zoom,[...this.rectList,x(f({},this.drawingRect),{x:t,y:e,width:s,height:r})]}rightMouseUp(t){var e,s,r;const o=this.getHoverRectID(t),i=this.rectList.find(a=>a.id===o);if(this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&N((s=this.dragInfo)==null?void 0:s.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(o,t.ctrlKey),i&&((r=this.selectedIDs)==null?void 0:r.length)===1&&this.setDefaultAttribute(i.attribute),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const a=R.getCurrentMarkerIndex(i.label,this.config.markerList);a>=0&&(this.setMarkerIndex(a),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",f({},this.selectedRect))}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===y.Move){this.dragInfo=void 0,this.dragStatus=y.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=R.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect()}deleteSelectedRect(){this.selectedRects.forEach(t=>{this.deleteRect(t.id)})}onKeyDown(t){if(!R.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case S.Ctrl:this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case S.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case S.Z:this.setIsHidden(!this.isHidden),this.render();break;case S.Delete:this.deleteSelectedRect();break;case S.Tab:{if(t.preventDefault(),this.drawingRect)return;let s=U.ascend;t.shiftKey&&(s=U.descend);const[r,o]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let i=[...r];o&&(i=[...i,...o]);const a=E.getViewPort(this.canvas,this.currentPos,this.zoom);i=i.filter(c=>E.inViewPort({x:c.x,y:c.y},a));const n=R.getNextSelectedRectID(i,s,this.selectedRectID);n&&(this.setSelectedRectID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute));break}default:{if(this.config.attributeConfigurable){const s=p.getAttributeByKeycode(e,this.config.attributeList);s!==void 0&&this.setDefaultAttribute(s)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case S.Ctrl:this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let s,r;this.drawingRect&&this.firstClickCoord&&(s=I.getRectUnderZoom(this.drawingRect,1/e),r=w.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),s&&r&&(this.drawingRect=I.getRectUnderZoom(s,this.zoom),this.firstClickCoord=w.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),s=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:s}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const s=this.getColor(t.attribute);let r,o;return t.valid===!1?(r=s==null?void 0:s.invalid.stroke,o=s==null?void 0:s.invalid.fill):(r=s==null?void 0:s.valid.stroke,o=s==null?void 0:s.valid.fill),{strokeColor:r,fillColor:o,textColor:r,toolColor:s}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:s,y:r,width:o,height:i,attribute:a,valid:n}=e,c=o*this.zoom*.6,d=w.getOffsetCoordinate({x:s,y:r+i},this.currentPos,this.zoom),h=this.getColor(a),l=n?h==null?void 0:h.valid.stroke:h==null?void 0:h.invalid.stroke,g=4;this._textAttributeInstance||(this._textAttributeInstance=new X({width:c,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+g,color:l,width:c})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let s=10;const r=I.getRectPointList(t),o=r.length,i=this.getColor(t.attribute);r.forEach((a,n)=>{var c,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===n?s=C+6:s=C,t.valid===!1?(e.strokeStyle=i==null?void 0:i.invalid.stroke,e.fillStyle=i==null?void 0:i.invalid.stroke):(e.strokeStyle=i==null?void 0:i.valid.stroke,e.fillStyle=i==null?void 0:i.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===n){e.beginPath(),e.lineWidth=10;const h=this.getColor(t.attribute),l=t.valid===!1?(c=h==null?void 0:h.invalid)==null?void 0:c.stroke:(d=h==null?void 0:h.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[n].x*this.zoom+this.currentPos.x,r[n].y*this.zoom+this.currentPos.y),e.lineTo(r[(n+1)%o].x*this.zoom+this.currentPos.x,r[(n+1)%o].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,s=!1){var r,o,i,a;if(this.ctx&&t){const{ctx:n,style:c}=this,{hiddenText:d=!1}=c;n.save();const{strokeColor:h,fillColor:l,textColor:g}=this.getRenderStyle(t);n.font="lighter 14px Arial";let b="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(b=`${t.order}`),t.label&&this.hasMarkerConfig&&(b=`${R.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${K.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(b=`${b} ${p.getAttributeShowText(t.attribute,(o=this.config)==null?void 0:o.attributeList)}`);const u=w.changeRectByZoom(t,s?e:this.zoom,this.currentPos);d||L.drawText(this.canvas,{x:u.x,y:u.y-6},b,x(f({color:h,font:"normal normal 900 14px SourceHanSansCN-Regular"},T),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&L.drawHighlightFlag({canvas:this.canvas,color:h,position:{x:u.x-5,y:u.y-16}});const m=(a=(i=this.style)==null?void 0:i.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID||this.isMultiMoveMode)&&L.drawRectWithFill(this.canvas,u,{color:l}),L.drawRect(this.canvas,u,{color:h,thickness:m,hiddenText:!0}),n.restore();let M=`${Math.round(t.width)} * ${Math.round(t.height)}`;s===!0&&(M=`${Math.round(t.width/this.zoom)} * ${Math.round(u.height/this.zoom)}`);const _=M.length*7;if(d||L.drawText(this.canvas,{x:u.x+u.width-_,y:u.y+u.height+15},M,f({color:g,font:"normal normal 600 14px Arial"},T)),!d&&t.textAttribute&&t.id!==this.selectedRectID){const z=0,Z=Math.max(20,u.width-_);L.drawText(this.canvas,{x:u.x,y:u.y+u.height+20+z},t.textAttribute,f({color:g,font:"italic normal 900 14px Arial",textMaxWidth:Z},T))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[s,r]=R.getRenderResultList(this.rectList,R.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||s==null||s.forEach(o=>{this.renderDrawingRect(o),e.staticRender&&e.staticRender(this.canvas,w.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))}),r&&r.forEach(o=>{this.renderDrawingRect(o),this.renderSelectedRect(o),e.selectedRender&&e.selectedRender(this.canvas,w.changeRectByZoom(o,this.zoom,this.currentPos),this.getRenderStyle(o))})}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,w.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(s=>this.selection.isIdSelected(s.id)?x(f({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=x(f({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=y.Wait,this.setSelectedRectID(void 0),this.setOperationMode(V.General)}clearResult(t=!0){const e=this.rectList.filter(s=>s.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",k.getMessagesByLocale(A.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const s=this.rectList.find(r=>r.id===t);if((s==null?void 0:s.disableDelete)===!0){this.emit("messageInfo",k.getMessagesByLocale(A.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}export{W as RectOperation,W as default};
@@ -1 +1 @@
1
- import{isObject as y}from"lodash";import{EStepType as p,ESortDirection as c}from"../../constant/annotation.js";import f from"../../constant/keyCode.js";var _=Object.defineProperty,O=Object.defineProperties,I=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,S=(o,t,e)=>t in o?_(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,d=(o,t)=>{for(var e in t||(t={}))P.call(t,e)&&S(o,e,t[e]);if(g)for(var e of g(t))E.call(t,e)&&S(o,e,t[e]);return o},h=(o,t)=>O(o,I(t));class v{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===p.QUALITY_INSPECTION||r.type===p.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getCurrentStepToolAndConfig(t,e){const r=this.getStepInfo(t,e);if(r){const n=this.getCurrentStepInfo(t,e);return h(d({},r),{tool:n.tool,config:n.config})}return!1}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:n}=e;if(!r||!n)return!0;let i=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&n!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(i=!1),i}static isMoveKey(t){return[f.Left,f.Right,f.Down,f.Up,f.Space].includes(t)}static getNextSelectedRectID(t,e=c.ascend,r){let n=1;e===c.descend&&(n=-1);const i=t.sort((l,u)=>l.x-u.x==0?l.y-u.y:n*(l.x-u.x)),a=i.findIndex(l=>l.id===r),s=i.length;return i[(a+1)%s]}static getNextSelectedRectIDByEvent(t,e,r){const n=e.shiftKey?c.descend:c.ascend;return this.getNextSelectedRectID(t,n,r)}static getRenderResultList(t,e,r=[],n){const i=[];return[t.filter(s=>n&&n.includes(s.id)?(i.push(s),!1):!(r.length>0&&!r.includes(s==null?void 0:s.attribute)||this.isDifferSourceID(s==null?void 0:s.sourceID,e))),i]}static getSourceID(t){var e;const r="";return t&&(e=t==null?void 0:t.id)!=null?e:r}static findAllLine(t,e=!0){const r=[],n=[...t];n.length>=3&&e===!0&&n.push(d({},n[0]));for(let i=0;i<n.length;i++)n[i+1]&&r.push({point1:n[i],point2:n[i+1],pointIndex:i});return r}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],r){if((e==null?void 0:e.length)===0)return;let n=e.map((i,a)=>h(d({},i),{index:a}));if(typeof r=="number"&&r>0){const i=e[r];if(i&&t.every(a=>a.label!==i.value))return{label:i.value,index:r};n=[...n.slice(r,e.length),...n.slice(0,r)]}for(let i=0;i<n.length;i++)if(!t.some(a=>a.label===n[i].value))return{label:n[i].value,index:n[i].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(r=>t===r.value)}}v.jsonParser=(o,t={})=>{try{return typeof o=="string"?JSON.parse(o):y(o)?o:t}catch(e){return t}};export{v as default};
1
+ import{isObject as y}from"lodash";import{EStepType as p,ESortDirection as f}from"../../constant/annotation.js";import s from"../../constant/keyCode.js";var _=Object.defineProperty,O=Object.defineProperties,I=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,S=(o,t,e)=>t in o?_(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,u=(o,t)=>{for(var e in t||(t={}))P.call(t,e)&&S(o,e,t[e]);if(g)for(var e of g(t))E.call(t,e)&&S(o,e,t[e]);return o},h=(o,t)=>O(o,I(t));class v{static getStepInfo(t,e){return e==null?void 0:e.filter(r=>r.step===t)[0]}static getCurrentStepInfo(t,e){const r=this.getStepInfo(t,e);return r&&(r.type===p.QUALITY_INSPECTION||r.type===p.MANUAL_CORRECTION)?this.getCurrentStepInfo(r.dataSourceStep,e):r}static getCurrentStepToolAndConfig(t,e){const r=this.getStepInfo(t,e);if(r){const n=this.getCurrentStepInfo(t,e);return h(u({},r),{tool:n.tool,config:n.config})}return!1}static getMaxOrder(t){let e=0;return t.forEach(r=>{r.order&&r.order>e&&(e=r.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:r,type:n}=e;if(!r||!n)return!0;let i=!0;return(e.isContentEditable||r==="TEXTAREA"||(r==="INPUT"&&n!=="radio"||r==="TEXTAREA")&&!e.readOnly)&&(i=!1),i}static isMoveKey(t){return[s.Left,s.Right,s.Down,s.Up,s.Space].includes(t)}static getNextSelectedRectID(t,e=f.ascend,r){let n=1;e===f.descend&&(n=-1);const i=t.sort((a,c)=>a.x-c.x==0?a.y-c.y:n*(a.x-c.x)),l=i.findIndex(a=>a.id===r),d=i.length;return i[(l+1)%d]}static getNextSelectedRectIDByEvent(t,e,r){const n=e.shiftKey?f.descend:f.ascend;return this.getNextSelectedRectID(t,n,r)}static getRenderResultList(t,e,r=[],n,i=!1){const l=[];return[t.filter(a=>n&&n.includes(a.id)?(l.push(a),!1):i?a==null?void 0:a.isHighlight:!(r.length>0&&!r.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),l]}static getSourceID(t){var e;const r="";return t&&(e=t==null?void 0:t.id)!=null?e:r}static findAllLine(t,e=!0){const r=[],n=[...t];n.length>=3&&e===!0&&n.push(u({},n[0]));for(let i=0;i<n.length;i++)n[i+1]&&r.push({point1:n[i],point2:n[i+1],pointIndex:i});return r}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],r){if((e==null?void 0:e.length)===0)return;let n=e.map((i,l)=>h(u({},i),{index:l}));if(typeof r=="number"&&r>0){const i=e[r];if(i&&t.every(l=>l.label!==i.value))return{label:i.value,index:r};n=[...n.slice(r,e.length),...n.slice(0,r)]}for(let i=0;i<n.length;i++)if(!t.some(l=>l.label===n[i].value))return{label:n[i].value,index:n[i].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(r=>t===r.value)}}v.jsonParser=(o,t={})=>{try{return typeof o=="string"?JSON.parse(o):y(o)?o:t}catch(e){return t}};export{v as default};
@@ -1,3 +1,3 @@
1
- import E from"color-rgba";import{NULL_COLOR as W,MathUtils as M}from"@labelbee/lb-utils";import{ELineTypes as P,SEGMENT_NUMBER as b,DEFAULT_FONT as U}from"../../constant/tool.js";import A from"./PolygonUtils.js";import T from"./UnitUtils.js";import v from"./AxisUtils.js";import{getCuboidAllSideLine as F,getPointListsByDirection as I,getCuboidTextAttributeOffset as R}from"./CuboidUtils.js";import L from"./AttributeUtils.js";var $=Object.defineProperty,j=Object.defineProperties,B=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,k=(r,t,i)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))N.call(t,i)&&k(r,i,t[i]);if(_)for(var i of _(t))X.call(t,i)&&k(r,i,t[i]);return r},S=(r,t)=>j(r,B(t));const Y=1,z={x:0,y:0},H=0,u="",x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=u,thickness:s=1,lineCap:d="round",lineDash:n}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=d,n&&o.setLineDash(n),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:d=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),d===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),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,d)=>`${s}${d.keyName}: ${d.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:d=P.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),d===P.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=A.createSmoothCurvePointsFromPointList([...t],b),a!==void 0&&a>-1&&(t=t.slice((b+1)*a,(b+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+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:d=1,color:n=u,fill:a=u}=e,f=T.deg2rad(l),c=T.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=d,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),a&&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),d=T.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,d,!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 d=i*1.5,n=d*Math.sqrt(3)/2,a=d/2;o.moveTo(l,s-d),o.lineTo(l-n,s+a),o.lineTo(l+n,s+a),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=A.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,S(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=A.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...d]=t;return e.moveTo(s.x,s.y),d.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:d,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:d,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}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=U,shadowColor:d="",shadowBlur:n=0,shadowOffsetX:a=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=d,o.shadowOffsetX=a,o.shadowOffsetY=f,o.shadowBlur=n,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 d=t.split(`
3
- `);for(let n=0;n<d.length;n++){const a=d[n].split("");let f="";for(let c=0;c<a.length;c++){const w=f+a[c],h=s.measureText(w).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=a[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:d=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(a+d)*Math.PI/180,c=(a-d)*Math.PI/180,w=n*Math.cos(f),y=n*Math.sin(f),h=n*Math.cos(c),g=n*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:d,fillColor:n}=i,a={color:s,thickness:d};if(e){const c=v.transformPlain2PointList(e);x.drawPolygon(r,c,S(m({},a),{isClose:!0}));const w=F(t);w==null||w.forEach(y=>{x.drawLine(r,y.p1,y.p2,m({},a))})}const f=v.transformPlain2PointList(l);if(o&&e&&l){const c=I({direction:o,frontPoints:l,backPoints:e});c&&x.drawPolygonWithFill(r,c,{color:n})}x.drawPolygon(r,f,S(m({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:d,selectedID:n,headerText:a,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} ${L.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!d&&c&&g&&x.drawText(r,{x:c.tl.x,y:c.tl.y-5},a!=null?a:g,{color:o,textMaxWidth:300});const C=R({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!d&&y&&t.id!==n){const p=Math.max(20,h*.8);x.drawText(r,{x:C.left,y:C.top},f!=null?f:y,{color:l,textMaxWidth:p})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const l=r.getContext("2d"),{width:s,height:d}=i,n=l.getImageData(0,0,s,d),[a,f,c,w]=E(e!=null?e:W),y=g=>{n.data[g]=a,n.data[g+1]=f,n.data[g+2]=c,n.data[g+3]=Math.floor(255*w)},h=M.generateCoordinates(o);return t.forEach(g=>{for(const[C,p]of h){const D=(g.y+p)*(n.width*4)+(g.x+C)*4;y(D)}}),l.putImageData(n,0,0),{canvas:r}}};let O=x;O.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=Y,currentPos:l=z,rotate:s=H,imgAttribute:d}=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(d){const{contrast:n,saturation:a,brightness:f}=d;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{O as default};
1
+ import E from"color-rgba";import{NULL_COLOR as M,MathUtils as W}from"@labelbee/lb-utils";import{ELineTypes as P,SEGMENT_NUMBER as b,DEFAULT_FONT as U}from"../../constant/tool.js";import A from"./PolygonUtils.js";import T from"./UnitUtils.js";import k from"./AxisUtils.js";import{getCuboidAllSideLine as F,getPointListsByDirection as L,getCuboidTextAttributeOffset as I}from"./CuboidUtils.js";import R from"./AttributeUtils.js";var $=Object.defineProperty,j=Object.defineProperties,B=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,_=(r,t,i)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,m=(r,t)=>{for(var i in t||(t={}))H.call(t,i)&&_(r,i,t[i]);if(v)for(var i of v(t))N.call(t,i)&&_(r,i,t[i]);return r},S=(r,t)=>j(r,B(t));const z=1,X={x:0,y:0},Y=0,y="",Z=[{d:"M0.423514 10.1595C-0.362666 7.22543 1.37854 4.20957 4.3126 3.42339C7.24666 2.63721 10.2625 4.37842 11.0487 7.31248L49.8716 152.201C50.6577 155.135 48.9165 158.151 45.9825 158.937C43.0484 159.724 40.0325 157.982 39.2464 155.048L0.423514 10.1595Z"},{d:"M14.0774 9.47294C28.5 -16.5001 91.5 25.5001 113.138 0.529419L131.773 70.076C112 96.9999 50.5 54 32.7124 79.0196L14.0774 9.47294Z"}],x=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:s=y,thickness:l=1,lineCap:c="round",lineDash:n}=e;o.save(),o.strokeStyle=s,o.lineWidth=l,o.lineCap=c,n&&o.setLineDash(n),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=y,thickness:s=1,lineCap:l="round",hiddenText:c=!1,lineDash:n}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)&&e.setLineDash(n),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),c===!1){let a="";if(t.attribute&&(a=`${a} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},a),t.textAttribute){const h=`${~~t.width} * ${~~t.height}`.length*7,g=0,u=Math.max(20,t.width-h);this.drawText(r,{x:t.x,y:t.y+t.height+20+g},t.textAttribute,{textMaxWidth:u})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=y}=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 s=document.createElement("div");return s.innerHTML=(i=t.reduce((l,c)=>`${l}${c.keyName}: ${c.value.join(" \u3001 ")}
2
+ `,""))!=null?i:"",s.setAttribute("id","tagToolTag"),e==null||e.appendChild(s),s}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=y,thickness:s=1,lineCap:l="round",lineType:c=P.Line,lineDash:n,hoverEdgeIndex:a}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=s,e.lineCap=l,Array.isArray(n)?e.setLineDash(n):e.setLineDash([])})(),c===P.Curve?(a!==void 0&&a>-1&&t.push(t[0]),t=A.createSmoothCurvePointsFromPointList([...t],b),a!==void 0&&a>-1&&(t=t.slice((b+1)*a,(b+1)*(a+1)))):a!==void 0&&a>-1&&(t=[...t,t[0]],t=t.slice(a,a+2));const h=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let f=0;f<t.length-1;f++)t[f].specialEdge&&h.push({i1:f,i2:f+1}),e.lineTo(t[f+1].x,t[f+1].y);e.stroke(),e.save(),e.lineWidth=s*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),h.forEach(f=>{const w=t[f.i1],C=t[f.i2];e.beginPath(),e.moveTo(w.x,w.y),e.lineTo(C.x,C.y),e.stroke()}),e.restore();const g=4,u=2;return t.forEach(f=>{f.specialPoint&&(this.drawSpecialPoint(r,f,g+u,o),this.drawSpecialPoint(r,f,g,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:s=0,endAngleDeg:l=360,thickness:c=1,color:n=y,fill:a=y}=e,d=T.deg2rad(s),h=T.deg2rad(l);o.save(),o.beginPath(),o.strokeStyle=n,o.fillStyle=a,o.lineWidth=c,o.arc(t.x,t.y,i,d,h,!1),o.stroke(),a&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:s=y}=e;o.save();const l=T.deg2rad(0),c=T.deg2rad(360);o.fillStyle=s,o.beginPath(),o.arc(t.x,t.y,i,l,c,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:s,y:l}=t;o.save(),o.beginPath(),o.fillStyle=e;const c=i*1.5,n=c*Math.sqrt(3)/2,a=c/2;o.moveTo(s,l-c),o.lineTo(s-n,l+a),o.lineTo(s+n,l+a),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=A.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,S(m({},i),{lineType:P.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=y,lineType:s=P.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),s===P.Curve&&(t=A.createSmoothCurvePointsFromPointList([...t,t[0]]));const[l,...c]=t;return e.moveTo(l.x,l.y),c.forEach(n=>{e.lineTo(n.x,n.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:s,lineCap:l,isClose:c,lineType:n}=i,a=this.drawPolygon(r,t,{color:e,thickness:s,lineCap:l,isClose:c,lineType:n});return this.drawPolygonWithFill(r,t,{color:o,lineType:n}),a}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygon(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,s=this.drawPolygonWithFillAndLine(r,t,i);return s.forEach(l=>{this.drawCircleWithFill(r,l,4,{color:o}),this.drawCircleWithFill(r,l,3,{color:e})}),s}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:s=y,font:l=U,shadowColor:c="",shadowBlur:n=0,shadowOffsetX:a=0,shadowOffsetY:d=0,textMaxWidth:h=164,offsetX:g=0,offsetY:u=0,textAlign:f="start",lineHeight:w}=e;o.save(),o.textAlign=f,o.fillStyle=s!=null?s:"white",o.font=l,o.shadowColor=c,o.shadowOffsetX=a,o.shadowOffsetY=d,o.shadowBlur=n,this.wrapText(r,`${i}`,t.x+g,t.y+u,h,w),o.restore()}static wrapText(r,t,i,e,o,s){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const l=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const c=t.split(`
3
+ `);for(let n=0;n<c.length;n++){const a=c[n].split("");let d="";for(let h=0;h<a.length;h++){const g=d+a[h],f=l.measureText(g).width;o||(o=300),f>o&&h>0?(l.fillText(d,i,e),d=a[h],e+=s):d=g}l.fillText(d,i,e),e+=s}}static drawArrow(r,t,i,e={}){const{color:o=y,thickness:s=1,lineCap:l="round",theta:c=30,headLen:n=10}=e,a=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,d=(a+c)*Math.PI/180,h=(a-c)*Math.PI/180,g=n*Math.cos(d),u=n*Math.sin(d),f=n*Math.cos(h),w=n*Math.sin(h);r.save(),r.strokeStyle=o,r.lineWidth=s,r.lineCap=l,r.beginPath(),r.moveTo(i.x+g,i.y+u),r.lineTo(i.x,i.y),r.lineTo(i.x+f,i.y+w),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:s}=t,{strokeColor:l,thickness:c,fillColor:n}=i,a={color:l,thickness:c};if(e){const h=k.transformPlain2PointList(e);x.drawPolygon(r,h,S(m({},a),{isClose:!0}));const g=F(t);g==null||g.forEach(u=>{x.drawLine(r,u.p1,u.p2,m({},a))})}const d=k.transformPlain2PointList(s);if(o&&e&&s){const h=L({direction:o,frontPoints:s,backPoints:e});h&&x.drawPolygonWithFill(r,h,{color:n})}x.drawPolygon(r,d,S(m({},a),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,s=o,{config:l,hiddenText:c,selectedID:n,headerText:a,bottomText:d}=e,{backPoints:h,frontPoints:g,textAttribute:u}=t,f=g.br.x-g.bl.x;x.drawCuboid(r,t,i);let w="";(l==null?void 0:l.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(w=`${t.order}`),t.attribute&&(w=`${w} ${R.getAttributeShowText(t.attribute,l==null?void 0:l.attributeList)}`),!c&&h&&w&&x.drawText(r,{x:h.tl.x,y:h.tl.y-5},a!=null?a:w,{color:o,textMaxWidth:300});const C=I({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!c&&u&&t.id!==n){const p=Math.max(20,f*.8);x.drawText(r,{x:C.left,y:C.top},d!=null?d:u,{color:s,textMaxWidth:p})}}static drawPixel({canvas:r,points:t,size:i,defaultRGBA:e,pixelSize:o=13}){const s=r.getContext("2d"),{width:l,height:c}=i,n=s.getImageData(0,0,l,c),[a,d,h,g]=E(e!=null?e:M),u=w=>{n.data[w]=a,n.data[w+1]=d,n.data[w+2]=h,n.data[w+3]=Math.floor(255*g)},f=W.generateCoordinates(o);return t.forEach(w=>{for(const[C,p]of f){const D=(w.y+p)*(n.width*4)+(w.x+C)*4;u(D)}}),s.putImageData(n,0,0),{canvas:r}}static drawHighlightFlag(r){const{canvas:t,position:i,color:e,scale:o=.1}=r,s=t.getContext("2d");if(!!s)for(const l of Z){s.beginPath();const c=l.d.split(/(?=[CLMZclmz])/);for(const n of c){const d=n.slice(1).split(" ").map(Number).map((h,g)=>g%2==0?h*o+i.x:h*o+i.y);switch(n[0]){case"M":s.moveTo(d[0],d[1]);break;case"C":s.bezierCurveTo(d[0],d[1],d[2],d[3],d[4],d[5]);break;case"L":s.lineTo(d[0],d[1]);break;case"Z":s.closePath();break}}s.fillStyle=e,s.fill()}}};let O=x;O.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=z,currentPos:s=X,rotate:l=Y,imgAttribute:c}=i;switch(e.save(),l){case 0:e.translate(s.x,s.y);break;case 90:e.translate(s.x+t.height*o,s.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(s.x+t.width*o,s.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(s.x,s.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(s.x,s.y);break}if(c){const{contrast:n,saturation:a,brightness:d}=c;e.filter=`saturate(${a+100}%) contrast(${n+100}%) brightness(${d+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()};export{O as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.24.0-alpha.5",
3
+ "version": "1.24.0-alpha.6",
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.16.0-alpha.2",
97
+ "@labelbee/lb-utils": "1.16.0-alpha.3",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",