UNPKG

lost-sia

Version:

Single Image Annotation Tool

2 lines (1 loc) 3.83 kB
import{jsx as l,jsxs as q}from"react/jsx-runtime";import{useRef as cn,useState as s,useEffect as u}from"react";import{CSpinner as z}from"@coreui/react";import fn from"./Canvas/Canvas.js";import un from"./models/AnnotationTool.js";import In from"./Toolbar/Toolbar.js";import mn from"./models/AnnotationMode.js";import hn from"./models/AnnotationStatus.js";const yn=({additionalButtons:H,allowedTools:S,polygonOperationResult:c={annotationsToDelete:[],polygonsToCreate:[]},annotationSettings:x,uiConfig:g,defaultAnnotationTool:w,defaultLabelId:M,image:I,isLoading:y=!1,isPolygonSelectionMode:b=!1,initialAnnotations:_=[],initialImageLabelIds:C=[],initialIsImageJunk:V=!1,possibleLabels:k,onAnnoCreated:G=(f,m)=>{},onAnnoCreationFinished:K=(f,m)=>{},onAnnoChanged:Q=(f,m)=>{},onAnnoDeleted:E=(f,m)=>{},onImageLabelsChanged:X=()=>{},onIsImageJunk:Y=()=>{},onNotification:Z=f=>{},onSelectAnnotation:$=f=>{}})=>{const m=cn(null),[D,p]=s(),[i,r]=s([]),[j,R]=s(),[O,nn]=s(),[d,h]=s(),[N,B]=s(w!==void 0?w:un.Point),[en,Sn]=s({height:"100%"}),[tn,F]=s(C),[J,L]=s(),[T,on]=s(!1),[U,P]=s([]),v=n=>{const e=i.findIndex(a=>a.internalId===n),t=[...i],o=t.splice(e,1)[0];r(t),h(void 0),E(o,t)},sn=()=>{d!==void 0&&v(d.internalId)},an=()=>{let n=0;const e=_.map(t=>({...t,internalId:n++,mode:mn.VIEW,selectedNode:1,status:t.status,annoTime:t.annoTime!==void 0?t.annoTime:0}));P([...Array(n).keys()]),r(e)},rn=()=>{let n=0;for(;U.includes(n);)n++;const e=[...U];return e.push(n),P(e),n},dn=n=>{const e=[...i],t=e.findIndex(A=>A.internalId===(d==null?void 0:d.internalId));if(t===-1)return;const o=e.splice(t,1)[0];E(o,e);const a=[...e];a.push(n),r(a),h(n)},W=n=>{L(n),Y(n)};u(()=>{I===void 0&&(r([]),h(void 0))},[I]),u(()=>{L(V),!(I!==void 0||_.length===0)&&an()},[_]),u(()=>{F(C)},[C]),u(()=>{const e={...{canCreate:!0,canEdit:!0,canHaveMultipleLabels:!1,canLabel:!0,minimalArea:250},...x};R(e)},[x]),u(()=>{const e={...{nodeRadius:4,strokeWidth:4,imageCentered:!1},...g};nn(e)},[g]),u(()=>{const n={bbox:!0,point:!0,line:!0,junk:!0,polygon:!0};if(S===void 0)return p(n);p(S)},[S]);const ln={position:"fixed",top:0,left:0,zIndex:6e3,backgroundColor:"#ffff",width:"100%",height:"100%",padding:15};return D===void 0?l("div",{className:"d-flex justify-content-center",children:l(z,{color:"primary",style:{width:"5rem",height:"5rem"}})}):q("div",{style:{...T?ln:{},width:"100%",height:"100%"},children:[l("div",{ref:m,style:{marginBottom:10},children:l(In,{annotationSettings:j,allowedTools:D,additionalButtons:H,isDisabled:y,isFullscreen:T,isImageJunk:J,imageLabelIds:tn,possibleLabels:k,selectedTool:N,onImageLabelsChanged:n=>{F(n),X(n)},onSetIsFullscreen:on,onSetIsImageJunk:W,onSetSelectedTool:B,onShouldDeleteSelectedAnnotation:sn})}),q("div",{style:en,children:[y&&l("div",{className:"d-flex justify-content-center",children:l(z,{color:"primary",style:{width:"5rem",height:"5rem",marginTop:200}})}),I&&i&&l(fn,{annotations:i,annotationSettings:j,defaultLabelId:M,image:I,isFullscreen:T,isImageJunk:J,isPolygonSelectionMode:b,selectedAnnotation:d,selectedAnnoTool:N,polygonOperationResult:c,possibleLabels:k,uiConfig:O,onAnnoCreated:n=>{const e=[...i];e.push(n),r(e),h(n),G(n,e)},onAnnoChanged:n=>{const e=i.findIndex(o=>o.internalId===n.internalId);if(e===-1)return;const t=[...i];t[e]=n,r(t),Q(n,t)},onAnnoCreationFinished:(n,e)=>{const t=[...i];if(b&&(c==null?void 0:c.annotationsToDelete)!==void 0&&(c.annotationsToDelete.push(d),c.annotationsToDelete.forEach(o=>{v(o.internalId);const a=t.findIndex(A=>A.internalId===o.internalId);t.splice(a,1)})),e)t.push(n);else{const o=i.findIndex(a=>a.internalId===n.internalId);t[o]=n}r(t),n.status=hn.CREATED,K(n,t)},onAnnoEditing:dn,onSetIsImageJunk:W,onNotification:Z,onRequestNewAnnoId:rn,onSelectAnnotation:n=>{h(n),$(n)},onSetSelectedTool:B,onShouldDeleteAnno:v})]})]})};export{yn as default};