@lunit/insight-viewer
Advanced tools
Comparing version 5.1.0-alpha.4 to 5.1.0-alpha.5
@@ -1,2 +0,2 @@ | ||
import e,{useState as r,useEffect as n,useCallback as t,forwardRef as o,useRef as i,useReducer as a}from"react";import{Subject as u,merge as c,fromEvent as l,from as s}from"rxjs";import{useResizeDetector as d}from"react-resize-detector";import f from"cornerstone-core";import{tap as v,filter as m,switchMap as p,map as g,takeUntil as w,concatMap as h,catchError as y}from"rxjs/operators";import b from"consola";import x from"ky";function C(){return(C=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function P(e,r){if(null==e)return{};var n,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)r.indexOf(n=i[t])>=0||(o[n]=e[n]);return o}var I,E=new u,S=new u,V=new u,q=function(e){return V.next({loaded:e.loaded,total:e.total})};function j(e){var r=e.loadedCount,n=e.totalCount,t=e.progress;return r===n?100:Math.floor((100*r+(null!=t?t:0))*(1/n))}var k={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function W(t){var o=t.Progress,i=r({progress:void 0,hidden:!0}),a=i[0],u=a.progress,l=a.hidden,s=i[1];return n(function(){var e=!1,r=E.asObservable(),n=V.asObservable(),t=0,o=1,i=0;return I=c(r,n).subscribe(function(r){"number"==typeof r?i=r:(t=r.loaded,o=r.total),e||s(function(e){return C({},e,{progress:j({loadedCount:t,totalCount:o,progress:i})})})}),function(){e=!0,I.unsubscribe()}},[]),n(function(){100===u&&s(function(e){return C({},e,{hidden:!0})}),0===u&&s(function(e){return C({},e,{hidden:!1})})},[u]),e.createElement("div",{style:k,"data-cy-loading":l?"":"loading"},!l&&e.createElement(o,{progress:null!=u?u:0}))}var D={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function A(e){if(!e)return D;var r=e.translation,n=e.voi;return{scale:e.scale,invert:e.invert,hflip:e.hflip,vflip:e.vflip,x:r.x,y:r.y,windowWidth:n.windowWidth,windowCenter:n.windowCenter}}function O(e,r){var n,t,o,i,a,u,c,l;return void 0===r&&(r={}),C({},e,{scale:null!=(n=r.scale)?n:e.scale,invert:null!=(t=r.invert)?t:e.invert,hflip:null!=(o=r.hflip)?o:e.hflip,vflip:null!=(i=r.vflip)?i:e.vflip,translation:{x:null!=(a=r.x)?a:e.translation.x,y:null!=(u=r.y)?u:e.translation.y},voi:{windowWidth:null!=(c=r.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=r.windowCenter)?l:e.voi.windowCenter}})}function Y(){return f}function z(e,r){return f.loadImage(e,r)}function R(e){return f.getViewport(e)}function _(e,r){return f.setViewport(e,r)}var M={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},X=o(function(r,n){var o=r.Progress,i=r.children,a=function(e){var r=e,n=null==r?void 0:r.current,o=t(function(){if(n)return function(e){f.resize(e)}(n)},[n]);return{resizeRef:d({targetRef:r,onResize:o,skipOnMount:!1}).ref}}(n);return e.createElement("div",{ref:a.resizeRef,style:M,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},o&&e.createElement(W,{Progress:o}),e.createElement("canvas",{className:"cornerstone-canvas"}),i)}),T=e.memo(X);function B(e){e.preventDefault()}X.displayName="Forwarded",T.displayName="ViewerWrapper";var F,L,N,G,H={pan:function(e,r){return{x:e.translation.x+r.x/e.scale,y:e.translation.y+r.y/e.scale}},adjust:function(e,r){return{windowWidth:e.voi.windowWidth+r.x/e.scale,windowCenter:e.voi.windowCenter+r.y/e.scale}}};function J(r){var t,o=r.image,a=r.Progress,u=r.viewport,c=r.interaction,s=r.onViewportChange,d=r.children,h=i(null),y=i(u),b=function(){var e=i();return n(function(){return G=S.asObservable().subscribe(function(r){e.current=r}),function(){G.unsubscribe()}},[]),e}();return n(function(){if(t)return function(e){f.enable(e)}(t),function(){!function(e){f.disable(e)}(t)}},[t=h.current]),function(e){var r=e.element,t=e.image,o=e.viewportRef,a=e.onViewportChange,u=i(0);n(function(){var e;if(t&&r){u.current+=1;var n=function(e,r,n){var t=f.getDefaultViewportForImage(e,r),o=n?O(t,n):t;return f.displayImage(e,r,o),{viewport:o,defaultViewport:t,image:r}}(r,t,1===u.current?null==o||null==(e=o.current)?void 0:e._default:null==o?void 0:o.current),i=n.viewport;S.next(n.defaultViewport),a&&a(A(i))}},[r,t,o,a])}({element:h.current,image:o,viewportRef:y,onViewportChange:s}),function(e){var r=e.element,t=e.viewport,o=e.initialViewport,i=e.onViewportChange;n(function(){if(r&&t){var e,n=(null==t?void 0:t._reset)&&o,a=n?o:R(r);a&&(_(r,O(a,t)),n&&i&&i(C({},A(o),null!=(e=null==t?void 0:t._reset)?e:{})))}},[r,t,o,i])}({element:h.current,viewport:u,initialViewport:null==b?void 0:b.current,onViewportChange:s}),function(e){var r=e.element,t=e.interaction,o=e.viewport,i=e.onViewportChange;!function(e){var r=e.element,t=e.interaction;n(function(){if(r){var e=l(r,"wheel");return N=e.pipe(m(function(e){return 0!==e.deltaY}),v(function(e){e.preventDefault()})).subscribe(function(e){null!=t&&t.mouseWheel&&(null==t||t.mouseWheel(e.deltaX,e.deltaY))}),function(){N.unsubscribe()}}},[t,r,e.onViewportChange])}({element:r,interaction:t,onViewportChange:i}),function(e){var r=e.element,t=e.interaction,o=e.onViewportChange;n(function(){if(t&&r&&(null==r||r.removeEventListener("contextmenu",B),t.primaryDrag||t.secondaryDrag)){var e,n=l(r,"mousedown"),i=l(document,"mousemove"),a=l(document,"mouseup");return F=n.pipe(v(function(r){var n=r.button;0===n&&(e="primaryDrag"),2===n&&(e="secondaryDrag")}),m(function(){return void 0!==e}),v(function(e){2===e.button&&(null==r||r.addEventListener("contextmenu",B))}),p(function(e){var r=e.pageX,n=e.pageY;return i.pipe(g(function(e){e.preventDefault();var t=e.pageX-r,o=e.pageY-n;return r=e.pageX,n=e.pageY,{x:t,y:o}}),w(a))})).subscribe(function(n){var i=R(r);i&&e&&function(e){var r,n,t=e.element,o=e.dragged,i=e.viewport,a=e.onViewportChange,u=e.interaction[e.dragType];switch(typeof u){case"string":(r=u)&&(a?a(function(e){var n;return C({},e,null==(n=H[r])?void 0:n.call(H,i,o))}):_(t,O(i,null==(n=H[r])?void 0:n.call(H,i,o))));break;case"function":u({viewport:i,delta:o})}}({interaction:t,dragType:e,element:r,viewport:i,dragged:n,onViewportChange:o})}),function(){F.unsubscribe()}}},[r,t,o])}({element:r,interaction:t,onViewportChange:i}),function(e){var r=e.element,t=e.interaction,o=e.viewport;n(function(){if(t&&r&&(null==r||r.removeEventListener("contextmenu",B),t.primaryClick||t.secondaryClick)){var e,n=l(r,"mousedown");if(t)return L=n.pipe(v(function(r){var n=r.button;0===n&&(e="primaryClick"),2===n&&(e="secondaryClick")}),m(function(){return void 0!==e}),v(function(e){2===e.button&&(null==r||r.addEventListener("contextmenu",B))}),g(function(e){return{clientX:e.clientX,clientY:e.clientY,currentTarget:e.currentTarget}})).subscribe(function(n){var i,a=n.clientX,u=n.clientY,c=n.currentTarget.getBoundingClientRect(),l=function(e,r){var n;if(r)return{x:r.x,y:r.y};var t=(null!=(n=R(e))?n:{}).translation,o=(t=void 0===t?{}:t).x,i=t.y;return{x:void 0===o?0:o,y:void 0===i?0:i}}(r,o);e&&(null==(i=t[e])||i.call(t,-l.x+a-c.left,-l.y+u-c.top))}),function(){L.unsubscribe()}}},[r,t,o])}({element:r,interaction:t,viewport:o})}({element:h.current,interaction:c,viewport:u,onViewportChange:s}),n(function(){y.current=u},[u]),e.createElement(T,{ref:h,Progress:a},d)}var K={onError:function(e){b.error(e)},Progress:void 0,requestInterceptor:function(e){}},Q={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function U(e){if(function(e){return e instanceof Error}(e))return e;if(function(e){var r;return void 0!==(null==e?void 0:e.error)&&void 0!==(null==e||null==(r=e.error)?void 0:r.message)}(e)){var r,n,t=new Error(e.error.message);return t.status=null==e||null==(r=e.error)||null==(n=r.response)?void 0:n.status,t}return new Error("error unknown")}var Z=function(e){try{var r,n,t;return Promise.resolve(function(e,o){try{var i=Promise.resolve(Promise.all([import("cornerstone-wado-image-loader"),import("dicom-parser")])).then(function(e){return t=(r=e)[1],(n=r[0]).external.cornerstone=Y(),n.external.dicomParser=t,n})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(r){e(U(r))}))}catch(e){return Promise.reject(e)}},$=function(e){try{var r;return Promise.resolve(function(e,n){try{var t=Promise.resolve(import("cornerstone-web-image-loader")).then(function(e){return(r=e).external.cornerstone=Y(),r})}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(0,function(r){e(U(r))}))}catch(e){return Promise.reject(e)}};function ee(e,n){var t=r(!1),o=t[0],i=t[1],a="dicom"==(e.web?"web":"dicom")?Z:$;return function(){try{var e=function(){if(!o)return Promise.resolve(a(n)).then(function(e){i(!!e)})}();e&&e.then&&e.then(function(){})}catch(e){Promise.reject(e)}}(),o}var re=function(e){return function(r){try{var n=x.create({hooks:{beforeRequest:[function(r){e(r)}]},onDownloadProgress:function(e){try{return r=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),E.next(r),Promise.resolve()}catch(e){return Promise.reject(e)}var r}});return Promise.resolve(n.get(r)).then(function(e){return e.arrayBuffer()})}catch(e){return Promise.reject(e)}}};function ne(e){var r=e.stateMap,n=e.value;return n===e.size?r.set(n-1,"success"):r.set(n-1,"success").set(n,"loading")}function te(e){return void 0===e?[]:Array.isArray(e)?e:[e]}var oe=["onError","requestInterceptor"],ie=["requestInterceptor","onError"],ae=function(e){var t=e.requestInterceptor,o=void 0===t?K.requestInterceptor:t,i=e.onError,a=void 0===i?K.onError:i,u=function(e){var t,o,i,a=e.onError,u=e.requestInterceptor,c=P(e,oe),l=(t=c).wadouri?{ids:te(t.wadouri),scheme:"wadouri"}:t.dicomfile?{ids:te(t.dicomfile),scheme:"dicomfile"}:t.web?{ids:te(t.web),scheme:"web"}:{ids:[],scheme:void 0},d=l.ids,f=l.scheme,v=r({images:[],loadingStates:(o=Array.isArray(d)?d.length:0,i=Array(o).fill("initial"),new Map(i.map(function(e,r){return[r,e]}))),_currentIndex:-1}),m=v[0],p=m.images,w=m.loadingStates,b=v[1],x=ee(c,a);return n(function(){d&&0!==d.length&&f&&x&&(b(function(e){return C({},e,{loadingStates:e.loadingStates.set(0,"loading")})}),function(e){var r=e.images,n=e.imageScheme,t=e.requestInterceptor,o=0;return q({loaded:o,total:r.length}),s(r).pipe(h(function(e){return function(e,r,n){return z(e,{loader:"dicomfile"===r?void 0:re(n)})}(e,n,t)}),g(function(e){return q({loaded:o+=1,total:r.length}),{image:e,loaded:o}}),y(function(e){throw U(e)}))}({images:d,imageScheme:f,requestInterceptor:u}).subscribe({next:function(e){var r=e.image,n=e.loaded;b(function(e){return{images:[].concat(e.images,[r]),loadingStates:ne({size:d.length,stateMap:e.loadingStates,value:n}),_currentIndex:n-1}})},error:function(e){a(e),b(function(e){return C({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")})})}}))},[d,f,a,u,x]),{images:p,loadingStates:Array.from(w.values())}}(C({},P(e,ie),{onError:a,requestInterceptor:o})),c=u.images;return{loadingStates:u.loadingStates,images:void 0===c?[]:c}};function ue(e){var n=r(C({},e?C({},Q,{_default:e}):Q)),t=n[0],o=n[1];return{viewport:t,setViewport:o,resetViewport:function(){o(C({},t,{_reset:e}))},initialized:t.scale!==Q.scale}}function ce(){var e,n=r(((e={}).primaryDrag=void 0,e.secondaryDrag=void 0,e.primaryClick=void 0,e.secondaryClick=void 0,e.mouseWheel=void 0,e));return{interaction:n[0],setInteraction:n[1]}}function le(e,r){var n=r.payload;switch(r.type){case"loading":return C({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:n};case"fail":return C({},e,{loadingState:"fail"});default:return e}}var se={loadingState:"initial",image:void 0};function de(e){if(void 0!==e)return Array.isArray(e)?e[0]:e}var fe=["requestInterceptor","onError"],ve=function(e){var r=e.requestInterceptor,t=void 0===r?K.requestInterceptor:r,o=e.onError,i=void 0===o?K.onError:o,u=P(e,fe),c=function(e){return e.wadouri?{id:de(e.wadouri),scheme:"wadouri"}:e.dicomfile?{id:de(e.dicomfile),scheme:"dicomfile"}:e.web?{id:de(e.web),scheme:"web"}:{id:void 0,scheme:void 0}}(u),l=c.id,s=c.scheme,d=a(le,se),f=d[0],v=f.loadingState,m=f.image,p=d[1],g=ee(u,i);return n(function(){g&&l&&s&&(p({type:"loading"}),function(e){var r=e.imageId,n=e.imageScheme,t=e.requestInterceptor,o=e.onError;try{return Promise.resolve(function(e,o){try{var i=Promise.resolve(function(e){var r=e.imageId,n=e.imageScheme,t=e.requestInterceptor;try{return Promise.resolve(function(e,o){try{var i=Promise.resolve(z(r,{loader:"dicomfile"===n?void 0:re(t)}))}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){throw U(e)}))}catch(e){return Promise.reject(e)}}({imageId:r,imageScheme:n,requestInterceptor:t}))}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){throw o(U(e)),e}))}catch(e){return Promise.reject(e)}}({imageId:l,imageScheme:s,requestInterceptor:t,onError:i}).then(function(e){p({type:"success",payload:e})}).catch(function(){return p({type:"fail"})}))},[g,l,s,t,i]),{image:m,loadingState:v}},me=function(e){var n=e.initial,t=e.max,o=r(void 0===n?0:n),i=o[0],a=o[1];return{frame:i,setFrame:function(e){var r;(r="number"==typeof e?e:e(i))<0||r>t||a(e)}}};function pe(){var e=r(""),n=e[1];return{imageId:e[0],handleFileChange:function(e){(function(e){return function(){try{return Promise.resolve(Z(K.onError)).then(function(r){var n;return null!=(n=null==r?void 0:r.wadouri.fileManager.add(e))?n:""})}catch(e){return Promise.reject(e)}}()})(e).then(function(e){n(null!=e?e:"")})}}}export{J as default,pe as useDicomFile,me as useFrame,ve as useImage,ce as useInteraction,ae as useMultipleImages,ue as useViewport}; | ||
import e,{useState as r,useEffect as n,useCallback as t,forwardRef as i,useRef as o,useReducer as a}from"react";import{Subject as u,merge as c,fromEvent as l,from as s}from"rxjs";import{useResizeDetector as d}from"react-resize-detector";import f from"cornerstone-core";import{tap as v,filter as m,switchMap as p,map as g,takeUntil as w,concatMap as h,catchError as y}from"rxjs/operators";import b from"consola";import x from"ky";function C(){return C=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},C.apply(this,arguments)}function I(e,r){if(null==e)return{};var n,t,i={},o=Object.keys(e);for(t=0;t<o.length;t++)r.indexOf(n=o[t])>=0||(i[n]=e[n]);return i}var P,E=new u,S=new u,V=new u,q=function(e){return V.next({loaded:e.loaded,total:e.total})};function j(e){var r=e.loadedCount,n=e.totalCount,t=e.progress;return r===n?100:Math.floor((100*r+(null!=t?t:0))*(1/n))}var k={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function W(t){var i=t.Progress,o=r({progress:void 0,hidden:!0}),a=o[0],u=a.progress,l=a.hidden,s=o[1];return n(function(){var e=!1,r=E.asObservable(),n=V.asObservable(),t=0,i=1,o=0;return P=c(r,n).subscribe(function(r){"number"==typeof r?o=r:(t=r.loaded,i=r.total),e||s(function(e){return C({},e,{progress:j({loadedCount:t,totalCount:i,progress:o})})})}),function(){e=!0,P.unsubscribe()}},[]),n(function(){100===u&&s(function(e){return C({},e,{hidden:!0})}),0===u&&s(function(e){return C({},e,{hidden:!1})})},[u]),e.createElement("div",{style:k,"data-cy-loading":l?"":"loading"},!l&&e.createElement(i,{progress:null!=u?u:0}))}var D={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function A(e){if(!e)return D;var r=e.translation,n=e.voi;return{scale:e.scale,invert:e.invert,hflip:e.hflip,vflip:e.vflip,x:r.x,y:r.y,windowWidth:n.windowWidth,windowCenter:n.windowCenter}}function O(e,r){var n,t,i,o,a,u,c,l;return void 0===r&&(r={}),C({},e,{scale:null!=(n=r.scale)?n:e.scale,invert:null!=(t=r.invert)?t:e.invert,hflip:null!=(i=r.hflip)?i:e.hflip,vflip:null!=(o=r.vflip)?o:e.vflip,translation:{x:null!=(a=r.x)?a:e.translation.x,y:null!=(u=r.y)?u:e.translation.y},voi:{windowWidth:null!=(c=r.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=r.windowCenter)?l:e.voi.windowCenter}})}function Y(){return f}function z(e,r){return f.loadImage(e,r)}function R(e){return f.getViewport(e)}function _(e,r){return f.setViewport(e,r)}var M={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},X=i(function(r,n){var i=r.Progress,o=r.children,a=function(e){var r=e,n=null==r?void 0:r.current,i=t(function(){if(n)return function(e){f.resize(e)}(n)},[n]);return{resizeRef:d({targetRef:r,onResize:i,skipOnMount:!1}).ref}}(n);return e.createElement("div",{ref:a.resizeRef,style:M,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},i&&e.createElement(W,{Progress:i}),e.createElement("canvas",{className:"cornerstone-canvas"}),o)}),B=e.memo(X);function T(e){e.preventDefault()}X.displayName="Forwarded",B.displayName="ViewerWrapper";var F,L,N,G,H={pan:function(e,r){return{x:e.translation.x+r.x/e.scale,y:e.translation.y+r.y/e.scale}},adjust:function(e,r){return{windowWidth:e.voi.windowWidth+r.x/e.scale,windowCenter:e.voi.windowCenter+r.y/e.scale}}};function J(r){var t,i=r.image,a=r.Progress,u=r.viewport,c=r.interaction,s=r.onViewportChange,d=r.children,h=o(null),y=o(u),b=function(){var e=o();return n(function(){return G=S.asObservable().subscribe(function(r){e.current=r}),function(){G.unsubscribe()}},[]),e}();return n(function(){if(t)return function(e){f.enable(e)}(t),function(){!function(e){f.disable(e)}(t)}},[t=h.current]),function(e){var r=e.element,t=e.image,i=e.viewportRef,a=e.onViewportChange,u=o(0);n(function(){var e;if(t&&r){u.current+=1;var n=function(e,r,n){var t=f.getDefaultViewportForImage(e,r),i=n?O(t,n):t;return f.displayImage(e,r,i),{viewport:i,defaultViewport:t,image:r}}(r,t,1===u.current?null==i||null==(e=i.current)?void 0:e._default:null==i?void 0:i.current),o=n.viewport;S.next(n.defaultViewport),a&&a(A(o))}},[r,t,i,a])}({element:h.current,image:i,viewportRef:y,onViewportChange:s}),function(e){var r=e.element,t=e.viewport,i=e.initialViewport,o=e.onViewportChange;n(function(){if(r&&t){var e,n=(null==t?void 0:t._reset)&&i,a=n?i:R(r);a&&(_(r,O(a,t)),n&&o&&o(C({},A(i),null!=(e=null==t?void 0:t._reset)?e:{})))}},[r,t,i,o])}({element:h.current,viewport:u,initialViewport:null==b?void 0:b.current,onViewportChange:s}),function(e){var r=e.element,t=e.interaction,i=e.viewport,o=e.onViewportChange;!function(e){var r=e.element,t=e.interaction;n(function(){if(r){var e=l(r,"wheel");return N=e.pipe(m(function(e){return 0!==e.deltaY}),v(function(e){e.preventDefault()})).subscribe(function(e){null!=t&&t.mouseWheel&&(null==t||t.mouseWheel(e.deltaX,e.deltaY))}),function(){N.unsubscribe()}}},[t,r,e.onViewportChange])}({element:r,interaction:t,onViewportChange:o}),function(e){var r=e.element,t=e.interaction,i=e.onViewportChange;n(function(){if(t&&r&&(null==r||r.removeEventListener("contextmenu",T),t.primaryDrag||t.secondaryDrag)){var e,n=l(r,"mousedown"),o=l(document,"mousemove"),a=l(document,"mouseup");return F=n.pipe(v(function(r){var n=r.button;0===n&&(e="primaryDrag"),2===n&&(e="secondaryDrag")}),m(function(){return void 0!==e}),v(function(e){2===e.button&&(null==r||r.addEventListener("contextmenu",T))}),p(function(e){var r=e.pageX,n=e.pageY;return o.pipe(g(function(e){e.preventDefault();var t=e.pageX-r,i=e.pageY-n;return r=e.pageX,n=e.pageY,{x:t,y:i}}),w(a))})).subscribe(function(n){var o=R(r);o&&e&&function(e){var r,n,t=e.element,i=e.dragged,o=e.viewport,a=e.onViewportChange,u=e.interaction[e.dragType];switch(typeof u){case"string":(r=u)&&(a?a(function(e){var n;return C({},e,null==(n=H[r])?void 0:n.call(H,o,i))}):_(t,O(o,null==(n=H[r])?void 0:n.call(H,o,i))));break;case"function":u({viewport:o,delta:i})}}({interaction:t,dragType:e,element:r,viewport:o,dragged:n,onViewportChange:i})}),function(){F.unsubscribe()}}},[r,t,i])}({element:r,interaction:t,onViewportChange:o}),function(e){var r=e.element,t=e.interaction,i=e.viewport;n(function(){if(t&&r&&(null==r||r.removeEventListener("contextmenu",T),t.primaryClick||t.secondaryClick)){var e,n=l(r,"mousedown");if(t)return L=n.pipe(v(function(r){var n=r.button;0===n&&(e="primaryClick"),2===n&&(e="secondaryClick")}),m(function(){return void 0!==e}),v(function(e){2===e.button&&(null==r||r.addEventListener("contextmenu",T))}),g(function(e){return{clientX:e.clientX,clientY:e.clientY,currentTarget:e.currentTarget}})).subscribe(function(n){var o,a=n.clientX,u=n.clientY,c=n.currentTarget.getBoundingClientRect(),l=function(e,r){var n;if(r)return{x:r.x,y:r.y};var t=(null!=(n=R(e))?n:{}).translation,i=(t=void 0===t?{}:t).x,o=t.y;return{x:void 0===i?0:i,y:void 0===o?0:o}}(r,i);e&&(null==(o=t[e])||o.call(t,-l.x+a-c.left,-l.y+u-c.top))}),function(){L.unsubscribe()}}},[r,t,i])}({element:r,interaction:t,viewport:i})}({element:h.current,interaction:c,viewport:u,onViewportChange:s}),n(function(){y.current=u},[u]),e.createElement(B,{ref:h,Progress:a},d)}var K={onError:function(e){b.error(e)},Progress:void 0,requestInterceptor:function(e){}},Q={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function U(e){if(function(e){return e instanceof Error}(e))return e;if(function(e){var r;return void 0!==(null==e?void 0:e.error)&&void 0!==(null==e||null==(r=e.error)?void 0:r.message)}(e)){var r,n,t=new Error(e.error.message);return t.status=null==e||null==(r=e.error)||null==(n=r.response)?void 0:n.status,t}return new Error("error unknown")}var Z=function(e){try{var r,n,t;return Promise.resolve(function(e,i){try{var o=Promise.resolve(Promise.all([import("cornerstone-wado-image-loader"),import("dicom-parser")])).then(function(e){return t=(r=e)[1],(n=r[0]).external.cornerstone=Y(),n.external.dicomParser=t,n})}catch(e){return i(e)}return o&&o.then?o.then(void 0,i):o}(0,function(r){e(U(r))}))}catch(e){return Promise.reject(e)}},$=function(e){try{var r;return Promise.resolve(function(e,n){try{var t=Promise.resolve(import("cornerstone-web-image-loader")).then(function(e){return(r=e).external.cornerstone=Y(),r})}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(0,function(r){e(U(r))}))}catch(e){return Promise.reject(e)}};function ee(e,n){var t=r(!1),i=t[0],o=t[1],a="dicom"==(e.web?"web":"dicom")?Z:$;return function(){try{var e=function(){if(!i)return Promise.resolve(a(n)).then(function(e){o(!!e)})}();e&&e.then&&e.then(function(){})}catch(e){Promise.reject(e)}}(),i}var re=function(e){return function(r){try{var n=x.create({hooks:{beforeRequest:[function(r){e(r)}]},onDownloadProgress:function(e){try{return r=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),E.next(r),Promise.resolve()}catch(e){return Promise.reject(e)}var r}});return Promise.resolve(n.get(r)).then(function(e){return e.arrayBuffer()})}catch(e){return Promise.reject(e)}}};function ne(e){var r=e.stateMap,n=e.value;return n===e.size?r.set(n-1,"success"):r.set(n-1,"success").set(n,"loading")}function te(e){return void 0===e?[]:Array.isArray(e)?e:[e]}var ie=["onError","requestInterceptor"],oe=["requestInterceptor","onError"],ae=function(e){var t=e.requestInterceptor,i=void 0===t?K.requestInterceptor:t,o=e.onError,a=void 0===o?K.onError:o,u=function(e){var t,i,o,a=e.onError,u=e.requestInterceptor,c=I(e,ie),l=(t=c).wadouri?{ids:te(t.wadouri),scheme:"wadouri"}:t.dicomfile?{ids:te(t.dicomfile),scheme:"dicomfile"}:t.web?{ids:te(t.web),scheme:"web"}:{ids:[],scheme:void 0},d=l.ids,f=l.scheme,v=r({images:[],loadingStates:(i=Array.isArray(d)?d.length:0,o=Array(i).fill("initial"),new Map(o.map(function(e,r){return[r,e]}))),_currentIndex:-1}),m=v[0],p=m.images,w=m.loadingStates,b=v[1],x=ee(c,a);return n(function(){d&&0!==d.length&&f&&x&&(b(function(e){return C({},e,{loadingStates:e.loadingStates.set(0,"loading")})}),function(e){var r=e.images,n=e.imageScheme,t=e.requestInterceptor,i=0;return q({loaded:i,total:r.length}),s(r).pipe(h(function(e){return function(e,r,n){return z(e,{loader:"dicomfile"===r?void 0:re(n)})}(e,n,t)}),g(function(e){return q({loaded:i+=1,total:r.length}),{image:e,loaded:i}}),y(function(e){throw U(e)}))}({images:d,imageScheme:f,requestInterceptor:u}).subscribe({next:function(e){var r=e.image,n=e.loaded;b(function(e){return{images:[].concat(e.images,[r]),loadingStates:ne({size:d.length,stateMap:e.loadingStates,value:n}),_currentIndex:n-1}})},error:function(e){a(e),b(function(e){return C({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")})})}}))},[d,f,a,u,x]),{images:p,loadingStates:Array.from(w.values())}}(C({},I(e,oe),{onError:a,requestInterceptor:i})),c=u.images;return{loadingStates:u.loadingStates,images:void 0===c?[]:c}};function ue(e){var n=r(C({},e?C({},Q,{_default:e}):Q)),t=n[0],i=n[1];return{viewport:t,setViewport:i,resetViewport:function(){i(C({},t,{_reset:e}))},initialized:t.scale!==Q.scale}}function ce(){var e,n=r(((e={}).primaryDrag=void 0,e.secondaryDrag=void 0,e.primaryClick=void 0,e.secondaryClick=void 0,e.mouseWheel=void 0,e));return{interaction:n[0],setInteraction:n[1]}}function le(e,r){var n=r.payload;switch(r.type){case"loading":return C({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:n};case"fail":return C({},e,{loadingState:"fail"});default:return e}}var se={loadingState:"initial",image:void 0};function de(e){if(void 0!==e)return Array.isArray(e)?e[0]:e}var fe=["requestInterceptor","onError"],ve=function(e){var r=e.requestInterceptor,t=void 0===r?K.requestInterceptor:r,i=e.onError,o=void 0===i?K.onError:i,u=I(e,fe),c=function(e){return e.wadouri?{id:de(e.wadouri),scheme:"wadouri"}:e.dicomfile?{id:de(e.dicomfile),scheme:"dicomfile"}:e.web?{id:de(e.web),scheme:"web"}:{id:void 0,scheme:void 0}}(u),l=c.id,s=c.scheme,d=a(le,se),f=d[0],v=f.loadingState,m=f.image,p=d[1],g=ee(u,o);return n(function(){g&&l&&s&&(p({type:"loading"}),function(e){var r=e.imageId,n=e.imageScheme,t=e.requestInterceptor,i=e.onError;try{return Promise.resolve(function(e,i){try{var o=Promise.resolve(function(e){var r=e.imageId,n=e.imageScheme,t=e.requestInterceptor;try{return Promise.resolve(function(e,i){try{var o=Promise.resolve(z(r,{loader:"dicomfile"===n?void 0:re(t)}))}catch(e){return i(e)}return o&&o.then?o.then(void 0,i):o}(0,function(e){throw U(e)}))}catch(e){return Promise.reject(e)}}({imageId:r,imageScheme:n,requestInterceptor:t}))}catch(e){return i(e)}return o&&o.then?o.then(void 0,i):o}(0,function(e){throw i(U(e)),e}))}catch(e){return Promise.reject(e)}}({imageId:l,imageScheme:s,requestInterceptor:t,onError:o}).then(function(e){p({type:"success",payload:e})}).catch(function(){return p({type:"fail"})}))},[g,l,s,t,o]),{image:m,loadingState:v}},me=function(e){var n=e.initial,t=e.max,i=r(void 0===n?0:n),o=i[0],a=i[1];return{frame:o,setFrame:function(e){var r;(r="number"==typeof e?e:e(o))<0||r>t||a(e)}}};function pe(){var e=r({imageId:"",file:void 0}),n=e[0],t=n.file,i=e[1];return{imageId:n.imageId,setImageIdByFile:function(e){(function(e){return function(){try{return Promise.resolve(Z(K.onError)).then(function(r){var n;return null!=(n=null==r?void 0:r.wadouri.fileManager.add(e))?n:""})}catch(e){return Promise.reject(e)}}()})(e).then(function(e){i({imageId:e,file:t})})},file:t}}export{J as default,pe as useDicomFile,me as useFrame,ve as useImage,ce as useInteraction,ae as useMultipleImages,ue as useViewport}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("react"),r=require("rxjs"),t=require("react-resize-detector"),n=require("cornerstone-core"),o=require("rxjs/operators"),i=require("consola"),a=require("ky");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var l=u(e),s=u(n),f=u(i),d=u(a);function v(){return(v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function p(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r.indexOf(t=i[n])>=0||(o[t]=e[t]);return o}var m,g=new r.Subject,w=new r.Subject,h=new r.Subject,y=function(e){return h.next({loaded:e.loaded,total:e.total})};function b(e){var r=e.loadedCount,t=e.totalCount,n=e.progress;return r===t?100:Math.floor((100*r+(null!=n?n:0))*(1/t))}var E={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function x(t){var n=t.Progress,o=e.useState({progress:void 0,hidden:!0}),i=o[0],a=i.progress,u=i.hidden,c=o[1];return e.useEffect(function(){var e=!1,t=g.asObservable(),n=h.asObservable(),o=0,i=1,a=0;return m=r.merge(t,n).subscribe(function(r){"number"==typeof r?a=r:(o=r.loaded,i=r.total),e||c(function(e){return v({},e,{progress:b({loadedCount:o,totalCount:i,progress:a})})})}),function(){e=!0,m.unsubscribe()}},[]),e.useEffect(function(){100===a&&c(function(e){return v({},e,{hidden:!0})}),0===a&&c(function(e){return v({},e,{hidden:!1})})},[a]),l.default.createElement("div",{style:E,"data-cy-loading":u?"":"loading"},!u&&l.default.createElement(n,{progress:null!=a?a:0}))}var C={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function P(e){if(!e)return C;var r=e.translation,t=e.voi;return{scale:e.scale,invert:e.invert,hflip:e.hflip,vflip:e.vflip,x:r.x,y:r.y,windowWidth:t.windowWidth,windowCenter:t.windowCenter}}function S(e,r){var t,n,o,i,a,u,c,l;return void 0===r&&(r={}),v({},e,{scale:null!=(t=r.scale)?t:e.scale,invert:null!=(n=r.invert)?n:e.invert,hflip:null!=(o=r.hflip)?o:e.hflip,vflip:null!=(i=r.vflip)?i:e.vflip,translation:{x:null!=(a=r.x)?a:e.translation.x,y:null!=(u=r.y)?u:e.translation.y},voi:{windowWidth:null!=(c=r.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=r.windowCenter)?l:e.voi.windowCenter}})}function I(){return s.default}function q(e,r){return s.default.loadImage(e,r)}function V(e){return s.default.getViewport(e)}function j(e,r){return s.default.setViewport(e,r)}var k={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},R=e.forwardRef(function(r,n){var o=r.Progress,i=r.children,a=function(r){var n=r,o=null==n?void 0:n.current,i=e.useCallback(function(){if(o)return function(e){s.default.resize(e)}(o)},[o]);return{resizeRef:t.useResizeDetector({targetRef:n,onResize:i,skipOnMount:!1}).ref}}(n);return l.default.createElement("div",{ref:a.resizeRef,style:k,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},o&&l.default.createElement(x,{Progress:o}),l.default.createElement("canvas",{className:"cornerstone-canvas"}),i)}),D=l.default.memo(R);function O(e){e.preventDefault()}R.displayName="Forwarded",D.displayName="ViewerWrapper";var W,M,_,z,A={pan:function(e,r){return{x:e.translation.x+r.x/e.scale,y:e.translation.y+r.y/e.scale}},adjust:function(e,r){return{windowWidth:e.voi.windowWidth+r.x/e.scale,windowCenter:e.voi.windowCenter+r.y/e.scale}}},Y={onError:function(e){f.default.error(e)},Progress:void 0,requestInterceptor:function(e){}},X={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function F(e){if(function(e){return e instanceof Error}(e))return e;if(function(e){var r;return void 0!==(null==e?void 0:e.error)&&void 0!==(null==e||null==(r=e.error)?void 0:r.message)}(e)){var r,t,n=new Error(e.error.message);return n.status=null==e||null==(r=e.error)||null==(t=r.response)?void 0:t.status,n}return new Error("error unknown")}var T=function(e){try{var r,t,n;return Promise.resolve(function(e,o){try{var i=Promise.resolve(Promise.all([Promise.resolve().then(function(){return c(require("cornerstone-wado-image-loader"))}),Promise.resolve().then(function(){return c(require("dicom-parser"))})])).then(function(e){return n=(r=e)[1],(t=r[0]).external.cornerstone=I(),t.external.dicomParser=n,t})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(r){e(F(r))}))}catch(e){return Promise.reject(e)}},B=function(e){try{var r;return Promise.resolve(function(e,t){try{var n=Promise.resolve(Promise.resolve().then(function(){return c(require("cornerstone-web-image-loader"))})).then(function(e){return(r=e).external.cornerstone=I(),r})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(r){e(F(r))}))}catch(e){return Promise.reject(e)}};function L(r,t){var n=e.useState(!1),o=n[0],i=n[1],a="dicom"==(r.web?"web":"dicom")?T:B;return function(){try{var e=function(){if(!o)return Promise.resolve(a(t)).then(function(e){i(!!e)})}();e&&e.then&&e.then(function(){})}catch(e){Promise.reject(e)}}(),o}var N=function(e){return function(r){try{var t=d.default.create({hooks:{beforeRequest:[function(r){e(r)}]},onDownloadProgress:function(e){try{return r=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),g.next(r),Promise.resolve()}catch(e){return Promise.reject(e)}var r}});return Promise.resolve(t.get(r)).then(function(e){return e.arrayBuffer()})}catch(e){return Promise.reject(e)}}};function U(e){var r=e.stateMap,t=e.value;return t===e.size?r.set(t-1,"success"):r.set(t-1,"success").set(t,"loading")}function G(e){return void 0===e?[]:Array.isArray(e)?e:[e]}var H=["onError","requestInterceptor"],J=["requestInterceptor","onError"];function K(e,r){var t=r.payload;switch(r.type){case"loading":return v({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:t};case"fail":return v({},e,{loadingState:"fail"});default:return e}}var Q={loadingState:"initial",image:void 0};function Z(e){if(void 0!==e)return Array.isArray(e)?e[0]:e}var $=["requestInterceptor","onError"];exports.default=function(t){var n,i=t.image,a=t.Progress,u=t.viewport,c=t.interaction,f=t.onViewportChange,d=t.children,p=e.useRef(null),m=e.useRef(u),g=function(){var r=e.useRef();return e.useEffect(function(){return z=w.asObservable().subscribe(function(e){r.current=e}),function(){z.unsubscribe()}},[]),r}();return e.useEffect(function(){if(n)return function(e){s.default.enable(e)}(n),function(){!function(e){s.default.disable(e)}(n)}},[n=p.current]),function(r){var t=r.element,n=r.image,o=r.viewportRef,i=r.onViewportChange,a=e.useRef(0);e.useEffect(function(){var e;if(n&&t){a.current+=1;var r=function(e,r,t){var n=s.default.getDefaultViewportForImage(e,r),o=t?S(n,t):n;return s.default.displayImage(e,r,o),{viewport:o,defaultViewport:n,image:r}}(t,n,1===a.current?null==o||null==(e=o.current)?void 0:e._default:null==o?void 0:o.current),u=r.viewport;w.next(r.defaultViewport),i&&i(P(u))}},[t,n,o,i])}({element:p.current,image:i,viewportRef:m,onViewportChange:f}),function(r){var t=r.element,n=r.viewport,o=r.initialViewport,i=r.onViewportChange;e.useEffect(function(){if(t&&n){var e,r=(null==n?void 0:n._reset)&&o,a=r?o:V(t);a&&(j(t,S(a,n)),r&&i&&i(v({},P(o),null!=(e=null==n?void 0:n._reset)?e:{})))}},[t,n,o,i])}({element:p.current,viewport:u,initialViewport:null==g?void 0:g.current,onViewportChange:f}),function(t){var n=t.element,i=t.interaction,a=t.viewport,u=t.onViewportChange;!function(t){var n=t.element,i=t.interaction;e.useEffect(function(){if(n){var e=r.fromEvent(n,"wheel");return _=e.pipe(o.filter(function(e){return 0!==e.deltaY}),o.tap(function(e){e.preventDefault()})).subscribe(function(e){null!=i&&i.mouseWheel&&(null==i||i.mouseWheel(e.deltaX,e.deltaY))}),function(){_.unsubscribe()}}},[i,n,t.onViewportChange])}({element:n,interaction:i,onViewportChange:u}),function(t){var n=t.element,i=t.interaction,a=t.onViewportChange;e.useEffect(function(){if(i&&n&&(null==n||n.removeEventListener("contextmenu",O),i.primaryDrag||i.secondaryDrag)){var e,t=r.fromEvent(n,"mousedown"),u=r.fromEvent(document,"mousemove"),c=r.fromEvent(document,"mouseup");return W=t.pipe(o.tap(function(r){var t=r.button;0===t&&(e="primaryDrag"),2===t&&(e="secondaryDrag")}),o.filter(function(){return void 0!==e}),o.tap(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",O))}),o.switchMap(function(e){var r=e.pageX,t=e.pageY;return u.pipe(o.map(function(e){e.preventDefault();var n=e.pageX-r,o=e.pageY-t;return r=e.pageX,t=e.pageY,{x:n,y:o}}),o.takeUntil(c))})).subscribe(function(r){var t=V(n);t&&e&&function(e){var r,t,n=e.element,o=e.dragged,i=e.viewport,a=e.onViewportChange,u=e.interaction[e.dragType];switch(typeof u){case"string":(r=u)&&(a?a(function(e){var t;return v({},e,null==(t=A[r])?void 0:t.call(A,i,o))}):j(n,S(i,null==(t=A[r])?void 0:t.call(A,i,o))));break;case"function":u({viewport:i,delta:o})}}({interaction:i,dragType:e,element:n,viewport:t,dragged:r,onViewportChange:a})}),function(){W.unsubscribe()}}},[n,i,a])}({element:n,interaction:i,onViewportChange:u}),function(t){var n=t.element,i=t.interaction,a=t.viewport;e.useEffect(function(){if(i&&n&&(null==n||n.removeEventListener("contextmenu",O),i.primaryClick||i.secondaryClick)){var e,t=r.fromEvent(n,"mousedown");if(i)return M=t.pipe(o.tap(function(r){var t=r.button;0===t&&(e="primaryClick"),2===t&&(e="secondaryClick")}),o.filter(function(){return void 0!==e}),o.tap(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",O))}),o.map(function(e){return{clientX:e.clientX,clientY:e.clientY,currentTarget:e.currentTarget}})).subscribe(function(r){var t,o=r.clientX,u=r.clientY,c=r.currentTarget.getBoundingClientRect(),l=function(e,r){var t;if(r)return{x:r.x,y:r.y};var n=(null!=(t=V(e))?t:{}).translation,o=(n=void 0===n?{}:n).x,i=n.y;return{x:void 0===o?0:o,y:void 0===i?0:i}}(n,a);e&&(null==(t=i[e])||t.call(i,-l.x+o-c.left,-l.y+u-c.top))}),function(){M.unsubscribe()}}},[n,i,a])}({element:n,interaction:i,viewport:a})}({element:p.current,interaction:c,viewport:u,onViewportChange:f}),e.useEffect(function(){m.current=u},[u]),l.default.createElement(D,{ref:p,Progress:a},d)},exports.useDicomFile=function(){var r=e.useState(""),t=r[1];return{imageId:r[0],handleFileChange:function(e){(function(e){return function(){try{return Promise.resolve(T(Y.onError)).then(function(r){var t;return null!=(t=null==r?void 0:r.wadouri.fileManager.add(e))?t:""})}catch(e){return Promise.reject(e)}}()})(e).then(function(e){t(null!=e?e:"")})}}},exports.useFrame=function(r){var t=r.initial,n=r.max,o=e.useState(void 0===t?0:t),i=o[0],a=o[1];return{frame:i,setFrame:function(e){var r;(r="number"==typeof e?e:e(i))<0||r>n||a(e)}}},exports.useImage=function(r){var t=r.requestInterceptor,n=void 0===t?Y.requestInterceptor:t,o=r.onError,i=void 0===o?Y.onError:o,a=p(r,$),u=function(e){return e.wadouri?{id:Z(e.wadouri),scheme:"wadouri"}:e.dicomfile?{id:Z(e.dicomfile),scheme:"dicomfile"}:e.web?{id:Z(e.web),scheme:"web"}:{id:void 0,scheme:void 0}}(a),c=u.id,l=u.scheme,s=e.useReducer(K,Q),f=s[0],d=f.loadingState,v=f.image,m=s[1],g=L(a,i);return e.useEffect(function(){g&&c&&l&&(m({type:"loading"}),function(e){var r=e.imageId,t=e.imageScheme,n=e.requestInterceptor,o=e.onError;try{return Promise.resolve(function(e,o){try{var i=Promise.resolve(function(e){var r=e.imageId,t=e.imageScheme,n=e.requestInterceptor;try{return Promise.resolve(function(e,o){try{var i=Promise.resolve(q(r,{loader:"dicomfile"===t?void 0:N(n)}))}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){throw F(e)}))}catch(e){return Promise.reject(e)}}({imageId:r,imageScheme:t,requestInterceptor:n}))}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){throw o(F(e)),e}))}catch(e){return Promise.reject(e)}}({imageId:c,imageScheme:l,requestInterceptor:n,onError:i}).then(function(e){m({type:"success",payload:e})}).catch(function(){return m({type:"fail"})}))},[g,c,l,n,i]),{image:v,loadingState:d}},exports.useInteraction=function(){var r,t=e.useState(((r={}).primaryDrag=void 0,r.secondaryDrag=void 0,r.primaryClick=void 0,r.secondaryClick=void 0,r.mouseWheel=void 0,r));return{interaction:t[0],setInteraction:t[1]}},exports.useMultipleImages=function(t){var n=t.requestInterceptor,i=void 0===n?Y.requestInterceptor:n,a=t.onError,u=void 0===a?Y.onError:a,c=function(t){var n,i,a,u=t.onError,c=t.requestInterceptor,l=p(t,H),s=(n=l).wadouri?{ids:G(n.wadouri),scheme:"wadouri"}:n.dicomfile?{ids:G(n.dicomfile),scheme:"dicomfile"}:n.web?{ids:G(n.web),scheme:"web"}:{ids:[],scheme:void 0},f=s.ids,d=s.scheme,m=e.useState({images:[],loadingStates:(i=Array.isArray(f)?f.length:0,a=Array(i).fill("initial"),new Map(a.map(function(e,r){return[r,e]}))),_currentIndex:-1}),g=m[0],w=g.images,h=g.loadingStates,b=m[1],E=L(l,u);return e.useEffect(function(){f&&0!==f.length&&d&&E&&(b(function(e){return v({},e,{loadingStates:e.loadingStates.set(0,"loading")})}),function(e){var t=e.images,n=e.imageScheme,i=e.requestInterceptor,a=0;return y({loaded:a,total:t.length}),r.from(t).pipe(o.concatMap(function(e){return function(e,r,t){return q(e,{loader:"dicomfile"===r?void 0:N(t)})}(e,n,i)}),o.map(function(e){return y({loaded:a+=1,total:t.length}),{image:e,loaded:a}}),o.catchError(function(e){throw F(e)}))}({images:f,imageScheme:d,requestInterceptor:c}).subscribe({next:function(e){var r=e.image,t=e.loaded;b(function(e){return{images:[].concat(e.images,[r]),loadingStates:U({size:f.length,stateMap:e.loadingStates,value:t}),_currentIndex:t-1}})},error:function(e){u(e),b(function(e){return v({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")})})}}))},[f,d,u,c,E]),{images:w,loadingStates:Array.from(h.values())}}(v({},p(t,J),{onError:u,requestInterceptor:i})),l=c.images;return{loadingStates:c.loadingStates,images:void 0===l?[]:l}},exports.useViewport=function(r){var t=e.useState(v({},r?v({},X,{_default:r}):X)),n=t[0],o=t[1];return{viewport:n,setViewport:o,resetViewport:function(){o(v({},n,{_reset:r}))},initialized:n.scale!==X.scale}}; | ||
var e=require("react"),r=require("rxjs"),t=require("react-resize-detector"),n=require("cornerstone-core"),i=require("rxjs/operators"),o=require("consola"),a=require("ky");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var l=u(e),s=u(n),f=u(o),d=u(a);function v(){return v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},v.apply(this,arguments)}function m(e,r){if(null==e)return{};var t,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)r.indexOf(t=o[n])>=0||(i[t]=e[t]);return i}var p,g=new r.Subject,w=new r.Subject,h=new r.Subject,y=function(e){return h.next({loaded:e.loaded,total:e.total})};function b(e){var r=e.loadedCount,t=e.totalCount,n=e.progress;return r===t?100:Math.floor((100*r+(null!=n?n:0))*(1/t))}var E={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function x(t){var n=t.Progress,i=e.useState({progress:void 0,hidden:!0}),o=i[0],a=o.progress,u=o.hidden,c=i[1];return e.useEffect(function(){var e=!1,t=g.asObservable(),n=h.asObservable(),i=0,o=1,a=0;return p=r.merge(t,n).subscribe(function(r){"number"==typeof r?a=r:(i=r.loaded,o=r.total),e||c(function(e){return v({},e,{progress:b({loadedCount:i,totalCount:o,progress:a})})})}),function(){e=!0,p.unsubscribe()}},[]),e.useEffect(function(){100===a&&c(function(e){return v({},e,{hidden:!0})}),0===a&&c(function(e){return v({},e,{hidden:!1})})},[a]),l.default.createElement("div",{style:E,"data-cy-loading":u?"":"loading"},!u&&l.default.createElement(n,{progress:null!=a?a:0}))}var I={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function C(e){if(!e)return I;var r=e.translation,t=e.voi;return{scale:e.scale,invert:e.invert,hflip:e.hflip,vflip:e.vflip,x:r.x,y:r.y,windowWidth:t.windowWidth,windowCenter:t.windowCenter}}function P(e,r){var t,n,i,o,a,u,c,l;return void 0===r&&(r={}),v({},e,{scale:null!=(t=r.scale)?t:e.scale,invert:null!=(n=r.invert)?n:e.invert,hflip:null!=(i=r.hflip)?i:e.hflip,vflip:null!=(o=r.vflip)?o:e.vflip,translation:{x:null!=(a=r.x)?a:e.translation.x,y:null!=(u=r.y)?u:e.translation.y},voi:{windowWidth:null!=(c=r.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=r.windowCenter)?l:e.voi.windowCenter}})}function S(){return s.default}function q(e,r){return s.default.loadImage(e,r)}function V(e){return s.default.getViewport(e)}function j(e,r){return s.default.setViewport(e,r)}var k={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},R=e.forwardRef(function(r,n){var i=r.Progress,o=r.children,a=function(r){var n=r,i=null==n?void 0:n.current,o=e.useCallback(function(){if(i)return function(e){s.default.resize(e)}(i)},[i]);return{resizeRef:t.useResizeDetector({targetRef:n,onResize:o,skipOnMount:!1}).ref}}(n);return l.default.createElement("div",{ref:a.resizeRef,style:k,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},i&&l.default.createElement(x,{Progress:i}),l.default.createElement("canvas",{className:"cornerstone-canvas"}),o)}),D=l.default.memo(R);function O(e){e.preventDefault()}R.displayName="Forwarded",D.displayName="ViewerWrapper";var W,M,_,z,A={pan:function(e,r){return{x:e.translation.x+r.x/e.scale,y:e.translation.y+r.y/e.scale}},adjust:function(e,r){return{windowWidth:e.voi.windowWidth+r.x/e.scale,windowCenter:e.voi.windowCenter+r.y/e.scale}}},Y={onError:function(e){f.default.error(e)},Progress:void 0,requestInterceptor:function(e){}},X={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function F(e){if(function(e){return e instanceof Error}(e))return e;if(function(e){var r;return void 0!==(null==e?void 0:e.error)&&void 0!==(null==e||null==(r=e.error)?void 0:r.message)}(e)){var r,t,n=new Error(e.error.message);return n.status=null==e||null==(r=e.error)||null==(t=r.response)?void 0:t.status,n}return new Error("error unknown")}var B=function(e){try{var r,t,n;return Promise.resolve(function(e,i){try{var o=Promise.resolve(Promise.all([Promise.resolve().then(function(){return c(require("cornerstone-wado-image-loader"))}),Promise.resolve().then(function(){return c(require("dicom-parser"))})])).then(function(e){return n=(r=e)[1],(t=r[0]).external.cornerstone=S(),t.external.dicomParser=n,t})}catch(e){return i(e)}return o&&o.then?o.then(void 0,i):o}(0,function(r){e(F(r))}))}catch(e){return Promise.reject(e)}},T=function(e){try{var r;return Promise.resolve(function(e,t){try{var n=Promise.resolve(Promise.resolve().then(function(){return c(require("cornerstone-web-image-loader"))})).then(function(e){return(r=e).external.cornerstone=S(),r})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(r){e(F(r))}))}catch(e){return Promise.reject(e)}};function L(r,t){var n=e.useState(!1),i=n[0],o=n[1],a="dicom"==(r.web?"web":"dicom")?B:T;return function(){try{var e=function(){if(!i)return Promise.resolve(a(t)).then(function(e){o(!!e)})}();e&&e.then&&e.then(function(){})}catch(e){Promise.reject(e)}}(),i}var N=function(e){return function(r){try{var t=d.default.create({hooks:{beforeRequest:[function(r){e(r)}]},onDownloadProgress:function(e){try{return r=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),g.next(r),Promise.resolve()}catch(e){return Promise.reject(e)}var r}});return Promise.resolve(t.get(r)).then(function(e){return e.arrayBuffer()})}catch(e){return Promise.reject(e)}}};function U(e){var r=e.stateMap,t=e.value;return t===e.size?r.set(t-1,"success"):r.set(t-1,"success").set(t,"loading")}function G(e){return void 0===e?[]:Array.isArray(e)?e:[e]}var H=["onError","requestInterceptor"],J=["requestInterceptor","onError"];function K(e,r){var t=r.payload;switch(r.type){case"loading":return v({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:t};case"fail":return v({},e,{loadingState:"fail"});default:return e}}var Q={loadingState:"initial",image:void 0};function Z(e){if(void 0!==e)return Array.isArray(e)?e[0]:e}var $=["requestInterceptor","onError"];exports.default=function(t){var n,o=t.image,a=t.Progress,u=t.viewport,c=t.interaction,f=t.onViewportChange,d=t.children,m=e.useRef(null),p=e.useRef(u),g=function(){var r=e.useRef();return e.useEffect(function(){return z=w.asObservable().subscribe(function(e){r.current=e}),function(){z.unsubscribe()}},[]),r}();return e.useEffect(function(){if(n)return function(e){s.default.enable(e)}(n),function(){!function(e){s.default.disable(e)}(n)}},[n=m.current]),function(r){var t=r.element,n=r.image,i=r.viewportRef,o=r.onViewportChange,a=e.useRef(0);e.useEffect(function(){var e;if(n&&t){a.current+=1;var r=function(e,r,t){var n=s.default.getDefaultViewportForImage(e,r),i=t?P(n,t):n;return s.default.displayImage(e,r,i),{viewport:i,defaultViewport:n,image:r}}(t,n,1===a.current?null==i||null==(e=i.current)?void 0:e._default:null==i?void 0:i.current),u=r.viewport;w.next(r.defaultViewport),o&&o(C(u))}},[t,n,i,o])}({element:m.current,image:o,viewportRef:p,onViewportChange:f}),function(r){var t=r.element,n=r.viewport,i=r.initialViewport,o=r.onViewportChange;e.useEffect(function(){if(t&&n){var e,r=(null==n?void 0:n._reset)&&i,a=r?i:V(t);a&&(j(t,P(a,n)),r&&o&&o(v({},C(i),null!=(e=null==n?void 0:n._reset)?e:{})))}},[t,n,i,o])}({element:m.current,viewport:u,initialViewport:null==g?void 0:g.current,onViewportChange:f}),function(t){var n=t.element,o=t.interaction,a=t.viewport,u=t.onViewportChange;!function(t){var n=t.element,o=t.interaction;e.useEffect(function(){if(n){var e=r.fromEvent(n,"wheel");return _=e.pipe(i.filter(function(e){return 0!==e.deltaY}),i.tap(function(e){e.preventDefault()})).subscribe(function(e){null!=o&&o.mouseWheel&&(null==o||o.mouseWheel(e.deltaX,e.deltaY))}),function(){_.unsubscribe()}}},[o,n,t.onViewportChange])}({element:n,interaction:o,onViewportChange:u}),function(t){var n=t.element,o=t.interaction,a=t.onViewportChange;e.useEffect(function(){if(o&&n&&(null==n||n.removeEventListener("contextmenu",O),o.primaryDrag||o.secondaryDrag)){var e,t=r.fromEvent(n,"mousedown"),u=r.fromEvent(document,"mousemove"),c=r.fromEvent(document,"mouseup");return W=t.pipe(i.tap(function(r){var t=r.button;0===t&&(e="primaryDrag"),2===t&&(e="secondaryDrag")}),i.filter(function(){return void 0!==e}),i.tap(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",O))}),i.switchMap(function(e){var r=e.pageX,t=e.pageY;return u.pipe(i.map(function(e){e.preventDefault();var n=e.pageX-r,i=e.pageY-t;return r=e.pageX,t=e.pageY,{x:n,y:i}}),i.takeUntil(c))})).subscribe(function(r){var t=V(n);t&&e&&function(e){var r,t,n=e.element,i=e.dragged,o=e.viewport,a=e.onViewportChange,u=e.interaction[e.dragType];switch(typeof u){case"string":(r=u)&&(a?a(function(e){var t;return v({},e,null==(t=A[r])?void 0:t.call(A,o,i))}):j(n,P(o,null==(t=A[r])?void 0:t.call(A,o,i))));break;case"function":u({viewport:o,delta:i})}}({interaction:o,dragType:e,element:n,viewport:t,dragged:r,onViewportChange:a})}),function(){W.unsubscribe()}}},[n,o,a])}({element:n,interaction:o,onViewportChange:u}),function(t){var n=t.element,o=t.interaction,a=t.viewport;e.useEffect(function(){if(o&&n&&(null==n||n.removeEventListener("contextmenu",O),o.primaryClick||o.secondaryClick)){var e,t=r.fromEvent(n,"mousedown");if(o)return M=t.pipe(i.tap(function(r){var t=r.button;0===t&&(e="primaryClick"),2===t&&(e="secondaryClick")}),i.filter(function(){return void 0!==e}),i.tap(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",O))}),i.map(function(e){return{clientX:e.clientX,clientY:e.clientY,currentTarget:e.currentTarget}})).subscribe(function(r){var t,i=r.clientX,u=r.clientY,c=r.currentTarget.getBoundingClientRect(),l=function(e,r){var t;if(r)return{x:r.x,y:r.y};var n=(null!=(t=V(e))?t:{}).translation,i=(n=void 0===n?{}:n).x,o=n.y;return{x:void 0===i?0:i,y:void 0===o?0:o}}(n,a);e&&(null==(t=o[e])||t.call(o,-l.x+i-c.left,-l.y+u-c.top))}),function(){M.unsubscribe()}}},[n,o,a])}({element:n,interaction:o,viewport:a})}({element:m.current,interaction:c,viewport:u,onViewportChange:f}),e.useEffect(function(){p.current=u},[u]),l.default.createElement(D,{ref:m,Progress:a},d)},exports.useDicomFile=function(){var r=e.useState({imageId:"",file:void 0}),t=r[0],n=t.file,i=r[1];return{imageId:t.imageId,setImageIdByFile:function(e){(function(e){return function(){try{return Promise.resolve(B(Y.onError)).then(function(r){var t;return null!=(t=null==r?void 0:r.wadouri.fileManager.add(e))?t:""})}catch(e){return Promise.reject(e)}}()})(e).then(function(e){i({imageId:e,file:n})})},file:n}},exports.useFrame=function(r){var t=r.initial,n=r.max,i=e.useState(void 0===t?0:t),o=i[0],a=i[1];return{frame:o,setFrame:function(e){var r;(r="number"==typeof e?e:e(o))<0||r>n||a(e)}}},exports.useImage=function(r){var t=r.requestInterceptor,n=void 0===t?Y.requestInterceptor:t,i=r.onError,o=void 0===i?Y.onError:i,a=m(r,$),u=function(e){return e.wadouri?{id:Z(e.wadouri),scheme:"wadouri"}:e.dicomfile?{id:Z(e.dicomfile),scheme:"dicomfile"}:e.web?{id:Z(e.web),scheme:"web"}:{id:void 0,scheme:void 0}}(a),c=u.id,l=u.scheme,s=e.useReducer(K,Q),f=s[0],d=f.loadingState,v=f.image,p=s[1],g=L(a,o);return e.useEffect(function(){g&&c&&l&&(p({type:"loading"}),function(e){var r=e.imageId,t=e.imageScheme,n=e.requestInterceptor,i=e.onError;try{return Promise.resolve(function(e,i){try{var o=Promise.resolve(function(e){var r=e.imageId,t=e.imageScheme,n=e.requestInterceptor;try{return Promise.resolve(function(e,i){try{var o=Promise.resolve(q(r,{loader:"dicomfile"===t?void 0:N(n)}))}catch(e){return i(e)}return o&&o.then?o.then(void 0,i):o}(0,function(e){throw F(e)}))}catch(e){return Promise.reject(e)}}({imageId:r,imageScheme:t,requestInterceptor:n}))}catch(e){return i(e)}return o&&o.then?o.then(void 0,i):o}(0,function(e){throw i(F(e)),e}))}catch(e){return Promise.reject(e)}}({imageId:c,imageScheme:l,requestInterceptor:n,onError:o}).then(function(e){p({type:"success",payload:e})}).catch(function(){return p({type:"fail"})}))},[g,c,l,n,o]),{image:v,loadingState:d}},exports.useInteraction=function(){var r,t=e.useState(((r={}).primaryDrag=void 0,r.secondaryDrag=void 0,r.primaryClick=void 0,r.secondaryClick=void 0,r.mouseWheel=void 0,r));return{interaction:t[0],setInteraction:t[1]}},exports.useMultipleImages=function(t){var n=t.requestInterceptor,o=void 0===n?Y.requestInterceptor:n,a=t.onError,u=void 0===a?Y.onError:a,c=function(t){var n,o,a,u=t.onError,c=t.requestInterceptor,l=m(t,H),s=(n=l).wadouri?{ids:G(n.wadouri),scheme:"wadouri"}:n.dicomfile?{ids:G(n.dicomfile),scheme:"dicomfile"}:n.web?{ids:G(n.web),scheme:"web"}:{ids:[],scheme:void 0},f=s.ids,d=s.scheme,p=e.useState({images:[],loadingStates:(o=Array.isArray(f)?f.length:0,a=Array(o).fill("initial"),new Map(a.map(function(e,r){return[r,e]}))),_currentIndex:-1}),g=p[0],w=g.images,h=g.loadingStates,b=p[1],E=L(l,u);return e.useEffect(function(){f&&0!==f.length&&d&&E&&(b(function(e){return v({},e,{loadingStates:e.loadingStates.set(0,"loading")})}),function(e){var t=e.images,n=e.imageScheme,o=e.requestInterceptor,a=0;return y({loaded:a,total:t.length}),r.from(t).pipe(i.concatMap(function(e){return function(e,r,t){return q(e,{loader:"dicomfile"===r?void 0:N(t)})}(e,n,o)}),i.map(function(e){return y({loaded:a+=1,total:t.length}),{image:e,loaded:a}}),i.catchError(function(e){throw F(e)}))}({images:f,imageScheme:d,requestInterceptor:c}).subscribe({next:function(e){var r=e.image,t=e.loaded;b(function(e){return{images:[].concat(e.images,[r]),loadingStates:U({size:f.length,stateMap:e.loadingStates,value:t}),_currentIndex:t-1}})},error:function(e){u(e),b(function(e){return v({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")})})}}))},[f,d,u,c,E]),{images:w,loadingStates:Array.from(h.values())}}(v({},m(t,J),{onError:u,requestInterceptor:o})),l=c.images;return{loadingStates:c.loadingStates,images:void 0===l?[]:l}},exports.useViewport=function(r){var t=e.useState(v({},r?v({},X,{_default:r}):X)),n=t[0],i=t[1];return{viewport:n,setViewport:i,resetViewport:function(){i(v({},n,{_reset:r}))},initialized:n.scale!==X.scale}}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{useState as t,useEffect as r,useCallback as n,forwardRef as o,useRef as i,useReducer as a}from"react";import{Subject as s,merge as c,fromEvent as l,from as u}from"rxjs";import{useResizeDetector as d}from"react-resize-detector";import p from"cornerstone-core";import{tap as m,filter as f,switchMap as g,map as w,takeUntil as v,concatMap as h,catchError as y}from"rxjs/operators";import b from"consola";import x from"ky";function C(){return(C=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function I(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}const E=new s,S=new s,V=new s,q=({loaded:e,total:t})=>V.next({loaded:e,total:t});function k({loadedCount:e,totalCount:t,progress:r}){return e===t?100:Math.floor((100*e+(null!=r?r:0))*(1/t))}let W;const D={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function P({Progress:n}){const[{progress:o,hidden:i},a]=t({progress:void 0,hidden:!0});return r(()=>{let e=!1;const t=E.asObservable(),r=V.asObservable();let n=0,o=1,i=0;return W=c(t,r).subscribe(t=>{"number"==typeof t?i=t:(n=t.loaded,o=t.total),e||a(e=>C({},e,{progress:k({loadedCount:n,totalCount:o,progress:i})}))}),()=>{e=!0,W.unsubscribe()}},[]),r(()=>{100===o&&a(e=>C({},e,{hidden:!0})),0===o&&a(e=>C({},e,{hidden:!1}))},[o]),e.createElement("div",{style:D,"data-cy-loading":i?"":"loading"},!i&&e.createElement(n,{progress:null!=o?o:0}))}const A={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function O(e){if(!e)return A;const{scale:t,invert:r,hflip:n,vflip:o,translation:i,voi:a}=e;return{scale:t,invert:r,hflip:n,vflip:o,x:i.x,y:i.y,windowWidth:a.windowWidth,windowCenter:a.windowCenter}}function Y(e,t={}){var r,n,o,i,a,s,c,l;return C({},e,{scale:null!=(r=t.scale)?r:e.scale,invert:null!=(n=t.invert)?n:e.invert,hflip:null!=(o=t.hflip)?o:e.hflip,vflip:null!=(i=t.vflip)?i:e.vflip,translation:{x:null!=(a=t.x)?a:e.translation.x,y:null!=(s=t.y)?s:e.translation.y},voi:{windowWidth:null!=(c=t.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=t.windowCenter)?l:e.voi.windowCenter}})}function z(){return p}function R(e,t){return p.loadImage(e,t)}function _(e){return p.getViewport(e)}function M(e,t){return p.setViewport(e,t)}const X={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},j=o(({Progress:t,children:r},o)=>{const{resizeRef:i}=function(e){const t=e,r=null==t?void 0:t.current,o=n(()=>{if(r)return function(e){p.resize(e)}(r)},[r]),{ref:i}=d({targetRef:t,onResize:o,skipOnMount:!1});return{resizeRef:i}}(o);return e.createElement("div",{ref:i,style:X,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},t&&e.createElement(P,{Progress:t}),e.createElement("canvas",{className:"cornerstone-canvas"}),r)}),T=e.memo(j);function B(e){e.preventDefault()}j.displayName="Forwarded",T.displayName="ViewerWrapper";const F={pan:(e,t)=>({x:e.translation.x+t.x/e.scale,y:e.translation.y+t.y/e.scale}),adjust:(e,t)=>({windowWidth:e.voi.windowWidth+t.x/e.scale,windowCenter:e.voi.windowCenter+t.y/e.scale})};let L,N,G,H;function J({image:t,Progress:n,viewport:o,interaction:a,onViewportChange:s,children:c}){const u=i(null),d=i(o),h=function(){const e=i();return r(()=>(H=S.asObservable().subscribe(t=>{e.current=t}),()=>{H.unsubscribe()}),[]),e}();return r(()=>{if(y)return function(e){p.enable(e)}(y),()=>{!function(e){p.disable(e)}(y)}},[y=u.current]),function({element:e,image:t,viewportRef:n,onViewportChange:o}){const a=i(0);r(()=>{var r;if(!t||!e)return;a.current+=1;const{viewport:i,defaultViewport:s}=function(e,t,r){const n=p.getDefaultViewportForImage(e,t),o=r?Y(n,r):n;return p.displayImage(e,t,o),{viewport:o,defaultViewport:n,image:t}}(e,t,1===a.current?null==n||null==(r=n.current)?void 0:r._default:null==n?void 0:n.current);S.next(s),o&&o(O(i))},[e,t,n,o])}({element:u.current,image:t,viewportRef:d,onViewportChange:s}),function({element:e,viewport:t,initialViewport:n,onViewportChange:o}){r(()=>{if(!e||!t)return;const r=(null==t?void 0:t._reset)&&n,i=r?n:_(e);var a;i&&(M(e,Y(i,t)),r&&o&&o(C({},O(n),null!=(a=null==t?void 0:t._reset)?a:{})))},[e,t,n,o])}({element:u.current,viewport:o,initialViewport:null==h?void 0:h.current,onViewportChange:s}),function({element:e,interaction:t,viewport:n,onViewportChange:o}){!function({element:e,interaction:t,onViewportChange:n}){r(()=>{if(!e)return;const r=l(e,"wheel");return G=r.pipe(f(({deltaY:e})=>0!==e),m(e=>{e.preventDefault()})).subscribe(({deltaX:e,deltaY:r})=>{null!=t&&t.mouseWheel&&(null==t||t.mouseWheel(e,r))}),()=>{G.unsubscribe()}},[t,e,n])}({element:e,interaction:t,onViewportChange:o}),function({element:e,interaction:t,onViewportChange:n}){r(()=>{if(!t||!e)return;if(null==e||e.removeEventListener("contextmenu",B),!t.primaryDrag&&!t.secondaryDrag)return;const r=l(e,"mousedown"),o=l(document,"mousemove"),i=l(document,"mouseup");let a;return L=r.pipe(m(({button:e})=>{0===e&&(a="primaryDrag"),2===e&&(a="secondaryDrag")}),f(()=>void 0!==a),m(({button:t})=>{2===t&&(null==e||e.addEventListener("contextmenu",B))}),g(e=>{let t=e.pageX,r=e.pageY;return o.pipe(w(e=>{e.preventDefault();const n=e.pageX-t,o=e.pageY-r;return t=e.pageX,r=e.pageY,{x:n,y:o}}),v(i))})).subscribe(r=>{const o=_(e);o&&a&&function({element:e,interaction:t,dragType:r,dragged:n,viewport:o,onViewportChange:i}){const a=t[r];switch(typeof a){case"string":(s=a)&&(i?i(e=>{var t;return C({},e,null==(t=F[s])?void 0:t.call(F,o,n))}):M(e,Y(o,null==(c=F[s])?void 0:c.call(F,o,n))));break;case"function":a({viewport:o,delta:n})}var s,c}({interaction:t,dragType:a,element:e,viewport:o,dragged:r,onViewportChange:n})}),()=>{L.unsubscribe()}},[e,t,n])}({element:e,interaction:t,onViewportChange:o}),function({element:e,interaction:t,viewport:n}){r(()=>{if(!t||!e)return;if(null==e||e.removeEventListener("contextmenu",B),!t.primaryClick&&!t.secondaryClick)return;const r=l(e,"mousedown");let o;return t?(N=r.pipe(m(({button:e})=>{0===e&&(o="primaryClick"),2===e&&(o="secondaryClick")}),f(()=>void 0!==o),m(({button:t})=>{2===t&&(null==e||e.addEventListener("contextmenu",B))}),w(({clientX:e,clientY:t,currentTarget:r})=>({clientX:e,clientY:t,currentTarget:r}))).subscribe(({clientX:r,clientY:i,currentTarget:a})=>{var s;const c=a.getBoundingClientRect(),{x:l,y:u}=function(e,t){var r;if(t){const{x:e,y:r}=t;return{x:e,y:r}}const{translation:{x:n=0,y:o=0}={}}=null!=(r=_(e))?r:{};return{x:n,y:o}}(e,n);o&&(null==(s=t[o])||s.call(t,-l+r-c.left,-u+i-c.top))}),()=>{N.unsubscribe()}):void 0},[e,t,n])}({element:e,interaction:t,viewport:n})}({element:u.current,interaction:a,viewport:o,onViewportChange:s}),r(()=>{d.current=o},[o]),e.createElement(T,{ref:u,Progress:n},c);var y}const K={onError:function(e){b.error(e)},Progress:void 0,requestInterceptor:e=>{}},Q={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function U(e){if(function(e){return e instanceof Error}(e))return e;if(function(e){var t;return void 0!==(null==e?void 0:e.error)&&void 0!==(null==e||null==(t=e.error)?void 0:t.message)}(e)){var t,r;const n=new Error(e.error.message);return n.status=null==e||null==(t=e.error)||null==(r=t.response)?void 0:r.status,n}return new Error("error unknown")}async function Z(e){try{const[e,t]=await Promise.all([import("cornerstone-wado-image-loader"),import("dicom-parser")]);return e.external.cornerstone=z(),e.external.dicomParser=t,e}catch(t){return void e(U(t))}}async function $(e){try{const e=await import("cornerstone-web-image-loader");return e.external.cornerstone=z(),e}catch(t){return void e(U(t))}}function ee(e,r){const[n,o]=t(!1),i="dicom"==(e.web?"web":"dicom")?Z:$;return async function(){if(!n){const e=await i(r);o(!!e)}}(),n}const te=e=>async t=>{const r=x.create({hooks:{beforeRequest:[t=>{e(t)}]},onDownloadProgress:async e=>{var t;t=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),E.next(t)}});return(await r.get(t)).arrayBuffer()};function re(e){const t=Array(e).fill("initial");return new Map(t.map((e,t)=>[t,e]))}function ne({size:e,stateMap:t,value:r}){return r===e?t.set(r-1,"success"):t.set(r-1,"success").set(r,"loading")}function oe(e){return void 0===e?[]:Array.isArray(e)?e:[e]}const ie=["onError","requestInterceptor"],ae=["requestInterceptor","onError"],se=e=>{let{requestInterceptor:n=K.requestInterceptor,onError:o=K.onError}=e,i=I(e,ae);const{loadingStates:a,images:s=[]}=(e=>{let{onError:n,requestInterceptor:o}=e,i=I(e,ie);const{ids:a,scheme:s}=(c=i).wadouri?{ids:oe(c.wadouri),scheme:"wadouri"}:c.dicomfile?{ids:oe(c.dicomfile),scheme:"dicomfile"}:c.web?{ids:oe(c.web),scheme:"web"}:{ids:[],scheme:void 0};var c;const[{images:l,loadingStates:d},p]=t({images:[],loadingStates:re(Array.isArray(a)?a.length:0),_currentIndex:-1}),m=ee(i,n);return r(()=>{a&&0!==a.length&&s&&m&&(p(e=>C({},e,{loadingStates:e.loadingStates.set(0,"loading")})),(({images:e,imageScheme:t,requestInterceptor:r})=>{let n=0;return q({loaded:n,total:e.length}),u(e).pipe(h(e=>((e,t,r)=>R(e,{loader:"dicomfile"===t?void 0:te(r)}))(e,t,r)),w(t=>(n+=1,q({loaded:n,total:e.length}),{image:t,loaded:n})),y(e=>{throw U(e)}))})({images:a,imageScheme:s,requestInterceptor:o}).subscribe({next:({image:e,loaded:t})=>{p(r=>({images:[...r.images,e],loadingStates:ne({size:a.length,stateMap:r.loadingStates,value:t}),_currentIndex:t-1}))},error:e=>{n(e),p(e=>C({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")}))}}))},[a,s,n,o,m]),{images:l,loadingStates:Array.from(d.values())}})(C({},i,{onError:o,requestInterceptor:n}));return{loadingStates:a,images:s}};function ce(e){const[r,n]=t(C({},e?C({},Q,{_default:e}):Q));return{viewport:r,setViewport:n,resetViewport:function(){n(C({},r,{_reset:e}))},initialized:r.scale!==Q.scale}}function le(){const[e,r]=t({primaryDrag:void 0,secondaryDrag:void 0,primaryClick:void 0,secondaryClick:void 0,mouseWheel:void 0});return{interaction:e,setInteraction:r}}function ue(e,t){const{type:r,payload:n}=t;switch(r){case"loading":return C({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:n};case"fail":return C({},e,{loadingState:"fail"});default:return e}}const de={loadingState:"initial",image:void 0};function pe(e){if(void 0!==e)return Array.isArray(e)?e[0]:e}const me=["requestInterceptor","onError"],fe=e=>{let{requestInterceptor:t=K.requestInterceptor,onError:n=K.onError}=e,o=I(e,me);const{id:i,scheme:s}=function(e){return e.wadouri?{id:pe(e.wadouri),scheme:"wadouri"}:e.dicomfile?{id:pe(e.dicomfile),scheme:"dicomfile"}:e.web?{id:pe(e.web),scheme:"web"}:{id:void 0,scheme:void 0}}(o),[{loadingState:c,image:l},u]=a(ue,de),d=ee(o,n);return r(()=>{d&&i&&s&&(u({type:"loading"}),(async({imageId:e,imageScheme:t,requestInterceptor:r,onError:n})=>{try{return await(async({imageId:e,imageScheme:t,requestInterceptor:r})=>{try{return await R(e,{loader:"dicomfile"===t?void 0:te(r)})}catch(e){throw U(e)}})({imageId:e,imageScheme:t,requestInterceptor:r})}catch(e){throw n(U(e)),e}})({imageId:i,imageScheme:s,requestInterceptor:t,onError:n}).then(e=>{u({type:"success",payload:e})}).catch(()=>u({type:"fail"})))},[d,i,s,t,n]),{image:l,loadingState:c}},ge=({initial:e=0,max:r})=>{const[n,o]=t(e);return{frame:n,setFrame:function(e){let t=0;t="number"==typeof e?e:e(n),t<0||t>r||o(e)}}};function we(){const[e,r]=t("");return{imageId:e,handleFileChange:function(e){(function(e){return async function(){var t;const r=await Z(K.onError);return null!=(t=null==r?void 0:r.wadouri.fileManager.add(e))?t:""}()})(e).then(e=>{r(null!=e?e:"")})}}}export{J as default,we as useDicomFile,ge as useFrame,fe as useImage,le as useInteraction,se as useMultipleImages,ce as useViewport}; | ||
import e,{useState as t,useEffect as r,useCallback as n,forwardRef as o,useRef as i,useReducer as a}from"react";import{Subject as s,merge as c,fromEvent as l,from as u}from"rxjs";import{useResizeDetector as d}from"react-resize-detector";import p from"cornerstone-core";import{tap as m,filter as f,switchMap as g,map as w,takeUntil as v,concatMap as h,catchError as y}from"rxjs/operators";import b from"consola";import x from"ky";function C(){return C=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},C.apply(this,arguments)}function I(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}const E=new s,S=new s,V=new s,q=({loaded:e,total:t})=>V.next({loaded:e,total:t});function k({loadedCount:e,totalCount:t,progress:r}){return e===t?100:Math.floor((100*e+(null!=r?r:0))*(1/t))}let W;const D={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function P({Progress:n}){const[{progress:o,hidden:i},a]=t({progress:void 0,hidden:!0});return r(()=>{let e=!1;const t=E.asObservable(),r=V.asObservable();let n=0,o=1,i=0;return W=c(t,r).subscribe(t=>{"number"==typeof t?i=t:(n=t.loaded,o=t.total),e||a(e=>C({},e,{progress:k({loadedCount:n,totalCount:o,progress:i})}))}),()=>{e=!0,W.unsubscribe()}},[]),r(()=>{100===o&&a(e=>C({},e,{hidden:!0})),0===o&&a(e=>C({},e,{hidden:!1}))},[o]),e.createElement("div",{style:D,"data-cy-loading":i?"":"loading"},!i&&e.createElement(n,{progress:null!=o?o:0}))}const A={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function O(e){if(!e)return A;const{scale:t,invert:r,hflip:n,vflip:o,translation:i,voi:a}=e;return{scale:t,invert:r,hflip:n,vflip:o,x:i.x,y:i.y,windowWidth:a.windowWidth,windowCenter:a.windowCenter}}function Y(e,t={}){var r,n,o,i,a,s,c,l;return C({},e,{scale:null!=(r=t.scale)?r:e.scale,invert:null!=(n=t.invert)?n:e.invert,hflip:null!=(o=t.hflip)?o:e.hflip,vflip:null!=(i=t.vflip)?i:e.vflip,translation:{x:null!=(a=t.x)?a:e.translation.x,y:null!=(s=t.y)?s:e.translation.y},voi:{windowWidth:null!=(c=t.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=t.windowCenter)?l:e.voi.windowCenter}})}function z(){return p}function R(e,t){return p.loadImage(e,t)}function _(e){return p.getViewport(e)}function M(e,t){return p.setViewport(e,t)}const X={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},j=o(({Progress:t,children:r},o)=>{const{resizeRef:i}=function(e){const t=e,r=null==t?void 0:t.current,o=n(()=>{if(r)return function(e){p.resize(e)}(r)},[r]),{ref:i}=d({targetRef:t,onResize:o,skipOnMount:!1});return{resizeRef:i}}(o);return e.createElement("div",{ref:i,style:X,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},t&&e.createElement(P,{Progress:t}),e.createElement("canvas",{className:"cornerstone-canvas"}),r)}),B=e.memo(j);function T(e){e.preventDefault()}j.displayName="Forwarded",B.displayName="ViewerWrapper";const F={pan:(e,t)=>({x:e.translation.x+t.x/e.scale,y:e.translation.y+t.y/e.scale}),adjust:(e,t)=>({windowWidth:e.voi.windowWidth+t.x/e.scale,windowCenter:e.voi.windowCenter+t.y/e.scale})};let L,N,G,H;function J({image:t,Progress:n,viewport:o,interaction:a,onViewportChange:s,children:c}){const u=i(null),d=i(o),h=function(){const e=i();return r(()=>(H=S.asObservable().subscribe(t=>{e.current=t}),()=>{H.unsubscribe()}),[]),e}();return r(()=>{if(y)return function(e){p.enable(e)}(y),()=>{!function(e){p.disable(e)}(y)}},[y=u.current]),function({element:e,image:t,viewportRef:n,onViewportChange:o}){const a=i(0);r(()=>{var r;if(!t||!e)return;a.current+=1;const{viewport:i,defaultViewport:s}=function(e,t,r){const n=p.getDefaultViewportForImage(e,t),o=r?Y(n,r):n;return p.displayImage(e,t,o),{viewport:o,defaultViewport:n,image:t}}(e,t,1===a.current?null==n||null==(r=n.current)?void 0:r._default:null==n?void 0:n.current);S.next(s),o&&o(O(i))},[e,t,n,o])}({element:u.current,image:t,viewportRef:d,onViewportChange:s}),function({element:e,viewport:t,initialViewport:n,onViewportChange:o}){r(()=>{if(!e||!t)return;const r=(null==t?void 0:t._reset)&&n,i=r?n:_(e);var a;i&&(M(e,Y(i,t)),r&&o&&o(C({},O(n),null!=(a=null==t?void 0:t._reset)?a:{})))},[e,t,n,o])}({element:u.current,viewport:o,initialViewport:null==h?void 0:h.current,onViewportChange:s}),function({element:e,interaction:t,viewport:n,onViewportChange:o}){!function({element:e,interaction:t,onViewportChange:n}){r(()=>{if(!e)return;const r=l(e,"wheel");return G=r.pipe(f(({deltaY:e})=>0!==e),m(e=>{e.preventDefault()})).subscribe(({deltaX:e,deltaY:r})=>{null!=t&&t.mouseWheel&&(null==t||t.mouseWheel(e,r))}),()=>{G.unsubscribe()}},[t,e,n])}({element:e,interaction:t,onViewportChange:o}),function({element:e,interaction:t,onViewportChange:n}){r(()=>{if(!t||!e)return;if(null==e||e.removeEventListener("contextmenu",T),!t.primaryDrag&&!t.secondaryDrag)return;const r=l(e,"mousedown"),o=l(document,"mousemove"),i=l(document,"mouseup");let a;return L=r.pipe(m(({button:e})=>{0===e&&(a="primaryDrag"),2===e&&(a="secondaryDrag")}),f(()=>void 0!==a),m(({button:t})=>{2===t&&(null==e||e.addEventListener("contextmenu",T))}),g(e=>{let t=e.pageX,r=e.pageY;return o.pipe(w(e=>{e.preventDefault();const n=e.pageX-t,o=e.pageY-r;return t=e.pageX,r=e.pageY,{x:n,y:o}}),v(i))})).subscribe(r=>{const o=_(e);o&&a&&function({element:e,interaction:t,dragType:r,dragged:n,viewport:o,onViewportChange:i}){const a=t[r];switch(typeof a){case"string":(s=a)&&(i?i(e=>{var t;return C({},e,null==(t=F[s])?void 0:t.call(F,o,n))}):M(e,Y(o,null==(c=F[s])?void 0:c.call(F,o,n))));break;case"function":a({viewport:o,delta:n})}var s,c}({interaction:t,dragType:a,element:e,viewport:o,dragged:r,onViewportChange:n})}),()=>{L.unsubscribe()}},[e,t,n])}({element:e,interaction:t,onViewportChange:o}),function({element:e,interaction:t,viewport:n}){r(()=>{if(!t||!e)return;if(null==e||e.removeEventListener("contextmenu",T),!t.primaryClick&&!t.secondaryClick)return;const r=l(e,"mousedown");let o;return t?(N=r.pipe(m(({button:e})=>{0===e&&(o="primaryClick"),2===e&&(o="secondaryClick")}),f(()=>void 0!==o),m(({button:t})=>{2===t&&(null==e||e.addEventListener("contextmenu",T))}),w(({clientX:e,clientY:t,currentTarget:r})=>({clientX:e,clientY:t,currentTarget:r}))).subscribe(({clientX:r,clientY:i,currentTarget:a})=>{var s;const c=a.getBoundingClientRect(),{x:l,y:u}=function(e,t){var r;if(t){const{x:e,y:r}=t;return{x:e,y:r}}const{translation:{x:n=0,y:o=0}={}}=null!=(r=_(e))?r:{};return{x:n,y:o}}(e,n);o&&(null==(s=t[o])||s.call(t,-l+r-c.left,-u+i-c.top))}),()=>{N.unsubscribe()}):void 0},[e,t,n])}({element:e,interaction:t,viewport:n})}({element:u.current,interaction:a,viewport:o,onViewportChange:s}),r(()=>{d.current=o},[o]),e.createElement(B,{ref:u,Progress:n},c);var y}const K={onError:function(e){b.error(e)},Progress:void 0,requestInterceptor:e=>{}},Q={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function U(e){if(function(e){return e instanceof Error}(e))return e;if(function(e){var t;return void 0!==(null==e?void 0:e.error)&&void 0!==(null==e||null==(t=e.error)?void 0:t.message)}(e)){var t,r;const n=new Error(e.error.message);return n.status=null==e||null==(t=e.error)||null==(r=t.response)?void 0:r.status,n}return new Error("error unknown")}async function Z(e){try{const[e,t]=await Promise.all([import("cornerstone-wado-image-loader"),import("dicom-parser")]);return e.external.cornerstone=z(),e.external.dicomParser=t,e}catch(t){return void e(U(t))}}async function $(e){try{const e=await import("cornerstone-web-image-loader");return e.external.cornerstone=z(),e}catch(t){return void e(U(t))}}function ee(e,r){const[n,o]=t(!1),i="dicom"==(e.web?"web":"dicom")?Z:$;return async function(){if(!n){const e=await i(r);o(!!e)}}(),n}const te=e=>async t=>{const r=x.create({hooks:{beforeRequest:[t=>{e(t)}]},onDownloadProgress:async e=>{var t;t=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),E.next(t)}});return(await r.get(t)).arrayBuffer()};function re(e){const t=Array(e).fill("initial");return new Map(t.map((e,t)=>[t,e]))}function ne({size:e,stateMap:t,value:r}){return r===e?t.set(r-1,"success"):t.set(r-1,"success").set(r,"loading")}function oe(e){return void 0===e?[]:Array.isArray(e)?e:[e]}const ie=["onError","requestInterceptor"],ae=["requestInterceptor","onError"],se=e=>{let{requestInterceptor:n=K.requestInterceptor,onError:o=K.onError}=e,i=I(e,ae);const{loadingStates:a,images:s=[]}=(e=>{let{onError:n,requestInterceptor:o}=e,i=I(e,ie);const{ids:a,scheme:s}=(c=i).wadouri?{ids:oe(c.wadouri),scheme:"wadouri"}:c.dicomfile?{ids:oe(c.dicomfile),scheme:"dicomfile"}:c.web?{ids:oe(c.web),scheme:"web"}:{ids:[],scheme:void 0};var c;const[{images:l,loadingStates:d},p]=t({images:[],loadingStates:re(Array.isArray(a)?a.length:0),_currentIndex:-1}),m=ee(i,n);return r(()=>{a&&0!==a.length&&s&&m&&(p(e=>C({},e,{loadingStates:e.loadingStates.set(0,"loading")})),(({images:e,imageScheme:t,requestInterceptor:r})=>{let n=0;return q({loaded:n,total:e.length}),u(e).pipe(h(e=>((e,t,r)=>R(e,{loader:"dicomfile"===t?void 0:te(r)}))(e,t,r)),w(t=>(n+=1,q({loaded:n,total:e.length}),{image:t,loaded:n})),y(e=>{throw U(e)}))})({images:a,imageScheme:s,requestInterceptor:o}).subscribe({next:({image:e,loaded:t})=>{p(r=>({images:[...r.images,e],loadingStates:ne({size:a.length,stateMap:r.loadingStates,value:t}),_currentIndex:t-1}))},error:e=>{n(e),p(e=>C({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")}))}}))},[a,s,n,o,m]),{images:l,loadingStates:Array.from(d.values())}})(C({},i,{onError:o,requestInterceptor:n}));return{loadingStates:a,images:s}};function ce(e){const[r,n]=t(C({},e?C({},Q,{_default:e}):Q));return{viewport:r,setViewport:n,resetViewport:function(){n(C({},r,{_reset:e}))},initialized:r.scale!==Q.scale}}function le(){const[e,r]=t({primaryDrag:void 0,secondaryDrag:void 0,primaryClick:void 0,secondaryClick:void 0,mouseWheel:void 0});return{interaction:e,setInteraction:r}}function ue(e,t){const{type:r,payload:n}=t;switch(r){case"loading":return C({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:n};case"fail":return C({},e,{loadingState:"fail"});default:return e}}const de={loadingState:"initial",image:void 0};function pe(e){if(void 0!==e)return Array.isArray(e)?e[0]:e}const me=["requestInterceptor","onError"],fe=e=>{let{requestInterceptor:t=K.requestInterceptor,onError:n=K.onError}=e,o=I(e,me);const{id:i,scheme:s}=function(e){return e.wadouri?{id:pe(e.wadouri),scheme:"wadouri"}:e.dicomfile?{id:pe(e.dicomfile),scheme:"dicomfile"}:e.web?{id:pe(e.web),scheme:"web"}:{id:void 0,scheme:void 0}}(o),[{loadingState:c,image:l},u]=a(ue,de),d=ee(o,n);return r(()=>{d&&i&&s&&(u({type:"loading"}),(async({imageId:e,imageScheme:t,requestInterceptor:r,onError:n})=>{try{return await(async({imageId:e,imageScheme:t,requestInterceptor:r})=>{try{return await R(e,{loader:"dicomfile"===t?void 0:te(r)})}catch(e){throw U(e)}})({imageId:e,imageScheme:t,requestInterceptor:r})}catch(e){throw n(U(e)),e}})({imageId:i,imageScheme:s,requestInterceptor:t,onError:n}).then(e=>{u({type:"success",payload:e})}).catch(()=>u({type:"fail"})))},[d,i,s,t,n]),{image:l,loadingState:c}},ge=({initial:e=0,max:r})=>{const[n,o]=t(e);return{frame:n,setFrame:function(e){let t=0;t="number"==typeof e?e:e(n),t<0||t>r||o(e)}}};function we(){const[{imageId:e,file:r},n]=t({imageId:"",file:void 0});return{imageId:e,setImageIdByFile:function(e){(function(e){return async function(){var t;const r=await Z(K.onError);return null!=(t=null==r?void 0:r.wadouri.fileManager.add(e))?t:""}()})(e).then(e=>{n({imageId:e,file:r})})},file:r}}export{J as default,we as useDicomFile,ge as useFrame,fe as useImage,le as useInteraction,se as useMultipleImages,ce as useViewport}; | ||
//# sourceMappingURL=index.modern.js.map |
export declare function useDicomFile(): { | ||
imageId: string; | ||
handleFileChange: (file: File) => void; | ||
setImageIdByFile: (file: File) => void; | ||
file: File | undefined; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -38,3 +38,3 @@ import { Dispatch, SetStateAction } from 'react'; | ||
export declare type ImageId = { | ||
[IMAGE_LOADER_SCHEME.WADO]: string | string[]; | ||
[IMAGE_LOADER_SCHEME.WADO]: string | string[] | undefined; | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]?: never; | ||
@@ -44,3 +44,3 @@ [IMAGE_LOADER_SCHEME.WEB]?: never; | ||
[IMAGE_LOADER_SCHEME.WADO]?: never; | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]: string | string[]; | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]: string | string[] | undefined; | ||
[IMAGE_LOADER_SCHEME.WEB]?: never; | ||
@@ -50,4 +50,4 @@ } | { | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]?: never; | ||
[IMAGE_LOADER_SCHEME.WEB]: string | string[]; | ||
[IMAGE_LOADER_SCHEME.WEB]: string | string[] | undefined; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@lunit/insight-viewer", | ||
"version": "5.1.0-alpha.4", | ||
"version": "5.1.0-alpha.5", | ||
"description": "cornerstone 라이브러리를 기반으로 Dicom Image를 다루기 위한 여러 Component들을 제공한다.", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296246
756