UNPKG

lost-sia

Version:

Single Image Annotation Tool

2 lines (1 loc) 1.24 kB
import{jsxs as C,jsx as x}from"react/jsx-runtime";import{useState as r,useRef as H,useEffect as f}from"react";import m from"../../../utils/transform.js";import R from"./DaviIcon.js";const j=10,a=15,I=3,k=({annotationCoordinates:u,canLabel:y,color:L,labels:b,selectedLabelIds:h=[],isSelected:E,svgScale:t,style:p,onLabelIconClicked:P})=>{const[c,w]=r({x:0,y:0}),e={x:c.x+7/t,y:c.y-10/t},[d,D]=r(0),[z,A]=r(0),[l,B]=r(0),[T,F]=r(""),s=H(null);f(()=>{F(W())},[h]),f(()=>{const i=m.getTopPoint(u),o=m.getMostLeftPoints(i),n=o.length>0?o[0]:{x:0,y:0};w(n);const _=Math.ceil(j/t);B(_),A(a/t)},[t]),f(()=>{if(s===void 0)return;const n=(s.current.getBoundingClientRect().width+I)/t;D(n)},[s,T,l]);const W=()=>{const o=b.filter(n=>h.includes(n.id)).map(n=>n.name).join(", ");return o.length?o:"no label"};return C("g",{children:[E&&y&&x(R,{x:e.x-33/t,y:e.y-30/t,color:L,size:60/t,onClick:()=>P(c)}),x("rect",{x:e.x,y:e.y-6/(t*1.2),width:d,height:z,rx:5/t,opacity:"0.5",style:p}),x("text",{x:e.x+1/t,y:e.y+6/t,fill:"white",textAnchor:"start",alignmentBaseline:"central",ref:s,fontSize:`${l}pt`,children:T}),x("rect",{x:e.x,y:e.y-6/(t*1.2),width:d,height:a,rx:5/t,opacity:"0.01",style:p,onContextMenu:i=>i.preventDefault()})]})};export{k as default};