@lunit/insight-viewer
Advanced tools
Comparing version 5.0.1-alpha.2 to 5.1.0-alpha.0
@@ -1,2 +0,2 @@ | ||
import e,{useState as n,useEffect as r,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 f}from"react-resize-detector";import d from"cornerstone-core";import{tap as v,filter as p,switchMap as m,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 n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}var I,P=new u,V=new u,E=new u,S=function(e){return E.next({loaded:e.loaded,total:e.total})};function D(e){var n=e.loadedCount,r=e.totalCount,t=e.progress;return n===r?100:Math.floor((100*n+(null!=t?t:0))*(1/r))}var q={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function W(t){var o=t.Progress,i=n({progress:void 0,hidden:!0}),a=i[0],u=a.progress,l=a.hidden,s=i[1];return r(function(){var e=!1,n=P.asObservable(),r=E.asObservable(),t=0,o=1,i=0;return I=c(n,r).subscribe(function(n){"number"==typeof n?i=n:(t=n.loaded,o=n.total),e||s(function(e){return C({},e,{progress:D({loadedCount:t,totalCount:o,progress:i})})})}),function(){e=!0,I.unsubscribe()}},[]),r(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:q,"data-cy-loading":l?"":"loading"},!l&&e.createElement(o,{progress:null!=u?u:0}))}var j={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function k(e){if(!e)return j;var n=e.translation,r=e.voi;return{scale:e.scale,invert:e.invert,hflip:e.hflip,vflip:e.vflip,x:n.x,y:n.y,windowWidth:r.windowWidth,windowCenter:r.windowCenter}}function Y(e,n){var r,t,o,i,a,u,c,l;return void 0===n&&(n={}),C({},e,{scale:null!=(r=n.scale)?r:e.scale,invert:null!=(t=n.invert)?t:e.invert,hflip:null!=(o=n.hflip)?o:e.hflip,vflip:null!=(i=n.vflip)?i:e.vflip,translation:{x:null!=(a=n.x)?a:e.translation.x,y:null!=(u=n.y)?u:e.translation.y},voi:{windowWidth:null!=(c=n.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(l=n.windowCenter)?l:e.voi.windowCenter}})}function z(){return d}function R(e,n){return d.loadImage(e,n)}function _(e){return d.getViewport(e)}function O(e,n){return d.setViewport(e,n)}var X={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},M=o(function(n,r){var o=n.Progress,i=n.children,a=function(e){var n=e,r=null==n?void 0:n.current,o=t(function(){if(r)return function(e){d.resize(e)}(r)},[r]);return{resizeRef:f({targetRef:n,onResize:o,skipOnMount:!1}).ref}}(r);return e.createElement("div",{ref:a.resizeRef,style:X,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},o&&e.createElement(W,{Progress:o}),e.createElement("canvas",{className:"cornerstone-canvas"}),i)}),L=e.memo(M);function T(e){e.preventDefault()}M.displayName="Forwarded",L.displayName="ViewerWrapper";var B,N,A,F,G={pan:function(e,n){return{x:e.translation.x+n.x/e.scale,y:e.translation.y+n.y/e.scale}},adjust:function(e,n){return{windowWidth:e.voi.windowWidth+n.x/e.scale,windowCenter:e.voi.windowCenter+n.y/e.scale}}};function H(n){var t,o=n.image,a=n.Progress,u=n.viewport,c=n.interaction,s=n.onViewportChange,f=n.children,h=i(null),y=i(u),b=function(){var e=i();return r(function(){return F=V.asObservable().subscribe(function(n){e.current=n}),function(){F.unsubscribe()}},[]),e}();return r(function(){if(t)return function(e){d.enable(e)}(t),function(){!function(e){d.disable(e)}(t)}},[t=h.current]),function(e){var n=e.element,t=e.image,o=e.viewportRef,a=e.onViewportChange,u=i(0);r(function(){var e;if(t&&n){u.current+=1;var r=function(e,n,r){var t=d.getDefaultViewportForImage(e,n),o=r?Y(t,r):t;return d.displayImage(e,n,o),{viewport:o,defaultViewport:t,image:n}}(n,t,1===u.current?null==o||null==(e=o.current)?void 0:e._default:null==o?void 0:o.current),i=r.viewport;V.next(r.defaultViewport),a&&a(k(i))}},[n,t,o,a])}({element:h.current,image:o,viewportRef:y,onViewportChange:s}),function(e){var n=e.element,t=e.viewport,o=e.initialViewport,i=e.onViewportChange;r(function(){if(n&&t){var e,r=(null==t?void 0:t._reset)&&o,a=r?o:_(n);a&&(O(n,Y(a,t)),r&&i&&i(C({},k(o),null!=(e=null==t?void 0:t._reset)?e:{})))}},[n,t,o,i])}({element:h.current,viewport:u,initialViewport:null==b?void 0:b.current,onViewportChange:s}),function(e){var n=e.element,t=e.interaction,o=e.viewport,i=e.onViewportChange;!function(e){var n=e.element,t=e.interaction;r(function(){if(n){var e=l(n,"wheel");return A=e.pipe(p(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(){A.unsubscribe()}}},[t,n,e.onViewportChange])}({element:n,interaction:t,onViewportChange:i}),function(e){var n=e.element,t=e.interaction,o=e.onViewportChange;r(function(){if(t&&n&&(null==n||n.removeEventListener("contextmenu",T),t.primaryDrag||t.secondaryDrag)){var e,r=l(n,"mousedown"),i=l(document,"mousemove"),a=l(document,"mouseup");return B=r.pipe(v(function(n){var r=n.button;0===r&&(e="primaryDrag"),2===r&&(e="secondaryDrag")}),p(function(){return void 0!==e}),v(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",T))}),m(function(e){var n=e.pageX,r=e.pageY;return i.pipe(g(function(e){e.preventDefault();var t=e.pageX-n,o=e.pageY-r;return n=e.pageX,r=e.pageY,{x:t,y:o}}),w(a))})).subscribe(function(r){var i=_(n);i&&e&&function(e){var n,r,t=e.element,o=e.dragged,i=e.viewport,a=e.onViewportChange,u=e.interaction[e.dragType];switch(typeof u){case"string":(n=u)&&(a?a(function(e){var r;return C({},e,null==(r=G[n])?void 0:r.call(G,i,o))}):O(t,Y(i,null==(r=G[n])?void 0:r.call(G,i,o))));break;case"function":u({viewport:i,delta:o})}}({interaction:t,dragType:e,element:n,viewport:i,dragged:r,onViewportChange:o})}),function(){B.unsubscribe()}}},[n,t,o])}({element:n,interaction:t,onViewportChange:i}),function(e){var n=e.element,t=e.interaction,o=e.viewport;r(function(){if(t&&n&&(null==n||n.removeEventListener("contextmenu",T),t.primaryClick||t.secondaryClick)){var e,r=l(n,"mousedown");if(t)return N=r.pipe(v(function(n){var r=n.button;0===r&&(e="primaryClick"),2===r&&(e="secondaryClick")}),p(function(){return void 0!==e}),v(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",T))}),g(function(e){return{clientX:e.clientX,clientY:e.clientY,currentTarget:e.currentTarget}})).subscribe(function(r){var i,a=r.clientX,u=r.clientY,c=r.currentTarget.getBoundingClientRect(),l=function(e,n){var r;if(n)return{x:n.x,y:n.y};var t=(null!=(r=_(e))?r:{}).translation,o=(t=void 0===t?{}:t).x,i=t.y;return{x:void 0===o?0:o,y:void 0===i?0:i}}(n,o);e&&(null==(i=t[e])||i.call(t,-l.x+a-c.left,-l.y+u-c.top))}),function(){N.unsubscribe()}}},[n,t,o])}({element:n,interaction:t,viewport:o})}({element:h.current,interaction:c,viewport:u,onViewportChange:s}),r(function(){y.current=u},[u]),e.createElement(L,{ref:h,Progress:a},f)}var J={onError:function(e){b.error(e)},Progress:void 0,requestInterceptor:function(e){}},K={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0},Q=function(e){try{var n,r,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=(n=e)[1],(r=n[0]).external.cornerstone=z(),r.external.dicomParser=t,!0})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(n){return e(n),!1}))}catch(e){return Promise.reject(e)}},U=function(e){try{return Promise.resolve(function(e,n){try{var r=Promise.resolve(import("cornerstone-web-image-loader")).then(function(e){return e.external.cornerstone=z(),!0})}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(n){return e(n),!1}))}catch(e){return Promise.reject(e)}};function Z(e,r){void 0===e&&(e="Dicom");var t=n(!1),o=t[0],i=t[1],a="Dicom"===e?Q:U;return function(){try{var e=function(){if(!o)return Promise.resolve(a(r)).then(function(e){i(e)})}();e&&e.then&&e.then(function(){})}catch(e){Promise.reject(e)}}(),o}function $(e){var n,r,t=new Error(e instanceof Error?e.message:e.error.message);return e instanceof Error||(t.status=null==e||null==(n=e.error)||null==(r=n.response)?void 0:r.status),t}var ee=function(e){return function(n){try{var r=x.create({hooks:{beforeRequest:[function(n){e(n)}]},onDownloadProgress:function(e){try{return n=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),P.next(n),Promise.resolve()}catch(e){return Promise.reject(e)}var n}});return Promise.resolve(r.get(n)).then(function(e){return e.arrayBuffer()})}catch(e){return Promise.reject(e)}}},ne=function(e,n){return R(e,{loader:ee(n)})};function re(e){var n=e.stateMap,r=e.value;return r===e.size?n.set(r-1,"success"):n.set(r-1,"success").set(r,"loading")}var te=function(e){var t=e.type,o=e.requestInterceptor,i=e.onError,a=function(e){var t,o,i=e.images,a=e.onError,u=e.requestInterceptor,c=e.type,l=n({images:[],loadingStates:(t=i.length,o=Array(t).fill("initial"),new Map(o.map(function(e,n){return[n,e]}))),_currentIndex:-1}),f=l[0],d=f.images,v=f.loadingStates,p=l[1],m=Z(c,a);return r(function(){0!==i.length&&m&&(p(function(e){return C({},e,{loadingStates:e.loadingStates.set(0,"loading")})}),function(e){var n=e.images,r=e.requestInterceptor,t=e.getLoadImage,o=void 0===t?ne:t,i=0;return S({loaded:i,total:n.length}),s(n).pipe(h(function(e){return o(e,r)}),g(function(e){return S({loaded:i+=1,total:n.length}),{image:e,loaded:i}}),y(function(e){throw $(e)}))}({images:i,requestInterceptor:u}).subscribe({next:function(e){var n=e.image,r=e.loaded;p(function(e){return{images:[].concat(e.images,[n]),loadingStates:re({size:i.length,stateMap:e.loadingStates,value:r}),_currentIndex:r-1}})},error:function(e){a(e),p(function(e){return C({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")})})}}))},[i,a,u,m]),{images:d,loadingStates:Array.from(v.values())}}({images:e.imageIds,onError:void 0===i?J.onError:i,requestInterceptor:void 0===o?J.requestInterceptor:o,type:void 0===t?"Dicom":t}),u=a.images;return{loadingStates:a.loadingStates,images:void 0===u?[]:u}};function oe(e){var r=n(C({},e?C({},K,{_default:e}):K)),t=r[0],o=r[1];return{viewport:t,setViewport:o,resetViewport:function(){o(C({},t,{_reset:e}))},initialized:t.scale!==K.scale}}function ie(){var e,r=n(((e={}).primaryDrag=void 0,e.secondaryDrag=void 0,e.primaryClick=void 0,e.secondaryClick=void 0,e.mouseWheel=void 0,e));return{interaction:r[0],setInteraction:r[1]}}function ae(e,n){var r=n.payload;switch(n.type){case"loading":return C({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:r};case"fail":return C({},e,{loadingState:"fail"});default:return e}}var ue={loadingState:"initial",image:void 0};function ce(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var le=function(e){var n=e.imageId,r=e.requestInterceptor;try{return Promise.resolve(ce(function(){return Promise.resolve(R(n,{loader:ee(r)}))},function(e){throw $(e)}))}catch(e){return Promise.reject(e)}},se=function(e){var n=e.imageId,t=e.type,o=void 0===t?"Dicom":t,i=e.requestInterceptor,u=void 0===i?J.requestInterceptor:i,c=e.onError,l=void 0===c?J.onError:c,s=a(ae,ue),f=s[0],d=s[1],v=f.loadingState,p=f.image,m=Z(o,l);return r(function(){m&&(d({type:"loading"}),function(e){var n=e.imageId,r=e.requestInterceptor,t=e.onError,o=e.getImage,i=void 0===o?le:o;try{return Promise.resolve(ce(function(){return Promise.resolve(i({imageId:n,requestInterceptor:r}))},function(e){throw t(e),e}))}catch(e){return Promise.reject(e)}}({imageId:n,requestInterceptor:u,onError:l}).then(function(e){d({type:"success",payload:e})}).catch(function(){return d({type:"fail"})}))},[m,n,u,l]),{image:p,loadingState:v}},fe=function(e){var r=e.initial,t=e.max,o=n(void 0===r?0:r),i=o[0],a=o[1];return{frame:i,setFrame:function(e){var n;(n="number"==typeof e?e:e(i))<0||n>t||a(e)}}};export{H as default,fe as useFrame,se as useImage,ie as useInteraction,te as useMultipleImages,oe as useViewport}; | ||
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}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("react"),t=require("rxjs"),r=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 t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var s=u(e),l=u(n),f=u(i),d=u(a);function v(){return(v=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)}var p,m=new t.Subject,g=new t.Subject,w=new t.Subject,h=function(e){return w.next({loaded:e.loaded,total:e.total})};function y(e){var t=e.loadedCount,r=e.totalCount,n=e.progress;return t===r?100:Math.floor((100*t+(null!=n?n:0))*(1/r))}var b={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function x(r){var n=r.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,r=m.asObservable(),n=w.asObservable(),o=0,i=1,a=0;return p=t.merge(r,n).subscribe(function(t){"number"==typeof t?a=t:(o=t.loaded,i=t.total),e||c(function(e){return v({},e,{progress:y({loadedCount:o,totalCount:i,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]),s.default.createElement("div",{style:b,"data-cy-loading":u?"":"loading"},!u&&s.default.createElement(n,{progress:null!=a?a:0}))}var E={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function C(e){if(!e)return E;var t=e.translation,r=e.voi;return{scale:e.scale,invert:e.invert,hflip:e.hflip,vflip:e.vflip,x:t.x,y:t.y,windowWidth:r.windowWidth,windowCenter:r.windowCenter}}function P(e,t){var r,n,o,i,a,u,c,s;return void 0===t&&(t={}),v({},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!=(u=t.y)?u:e.translation.y},voi:{windowWidth:null!=(c=t.windowWidth)?c:e.voi.windowWidth,windowCenter:null!=(s=t.windowCenter)?s:e.voi.windowCenter}})}function I(){return l.default}function S(e,t){return l.default.loadImage(e,t)}function q(e){return l.default.getViewport(e)}function V(e,t){return l.default.setViewport(e,t)}var j={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},D=e.forwardRef(function(t,n){var o=t.Progress,i=t.children,a=function(t){var n=t,o=null==n?void 0:n.current,i=e.useCallback(function(){if(o)return function(e){l.default.resize(e)}(o)},[o]);return{resizeRef:r.useResizeDetector({targetRef:n,onResize:i,skipOnMount:!1}).ref}}(n);return s.default.createElement("div",{ref:a.resizeRef,style:j,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},o&&s.default.createElement(x,{Progress:o}),s.default.createElement("canvas",{className:"cornerstone-canvas"}),i)}),R=s.default.memo(D);function k(e){e.preventDefault()}D.displayName="Forwarded",R.displayName="ViewerWrapper";var W,O,M,_,z={pan:function(e,t){return{x:e.translation.x+t.x/e.scale,y:e.translation.y+t.y/e.scale}},adjust:function(e,t){return{windowWidth:e.voi.windowWidth+t.x/e.scale,windowCenter:e.voi.windowCenter+t.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},L=function(e){try{var t,r,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=(t=e)[1],(r=t[0]).external.cornerstone=I(),r.external.dicomParser=n,!0})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(t){return e(t),!1}))}catch(e){return Promise.reject(e)}},T=function(e){try{return Promise.resolve(function(e,t){try{var r=Promise.resolve(Promise.resolve().then(function(){return c(require("cornerstone-web-image-loader"))})).then(function(e){return e.external.cornerstone=I(),!0})}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(t){return e(t),!1}))}catch(e){return Promise.reject(e)}};function B(t,r){void 0===t&&(t="Dicom");var n=e.useState(!1),o=n[0],i=n[1],a="Dicom"===t?L:T;return function(){try{var e=function(){if(!o)return Promise.resolve(a(r)).then(function(e){i(e)})}();e&&e.then&&e.then(function(){})}catch(e){Promise.reject(e)}}(),o}function F(e){var t,r,n=new Error(e instanceof Error?e.message:e.error.message);return e instanceof Error||(n.status=null==e||null==(t=e.error)||null==(r=t.response)?void 0:r.status),n}var N=function(e){return function(t){try{var r=d.default.create({hooks:{beforeRequest:[function(t){e(t)}]},onDownloadProgress:function(e){try{return t=0===e.percent&&0===e.totalBytes&&e.transferredBytes>0?100:Math.round(100*e.percent),m.next(t),Promise.resolve()}catch(e){return Promise.reject(e)}var t}});return Promise.resolve(r.get(t)).then(function(e){return e.arrayBuffer()})}catch(e){return Promise.reject(e)}}},A=function(e,t){return S(e,{loader:N(t)})};function U(e){var t=e.stateMap,r=e.value;return r===e.size?t.set(r-1,"success"):t.set(r-1,"success").set(r,"loading")}function G(e,t){var r=t.payload;switch(t.type){case"loading":return v({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:r};case"fail":return v({},e,{loadingState:"fail"});default:return e}}var H={loadingState:"initial",image:void 0};function J(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var K=function(e){var t=e.imageId,r=e.requestInterceptor;try{return Promise.resolve(J(function(){return Promise.resolve(S(t,{loader:N(r)}))},function(e){throw F(e)}))}catch(e){return Promise.reject(e)}};exports.default=function(r){var n,i=r.image,a=r.Progress,u=r.viewport,c=r.interaction,f=r.onViewportChange,d=r.children,p=e.useRef(null),m=e.useRef(u),w=function(){var t=e.useRef();return e.useEffect(function(){return _=g.asObservable().subscribe(function(e){t.current=e}),function(){_.unsubscribe()}},[]),t}();return e.useEffect(function(){if(n)return function(e){l.default.enable(e)}(n),function(){!function(e){l.default.disable(e)}(n)}},[n=p.current]),function(t){var r=t.element,n=t.image,o=t.viewportRef,i=t.onViewportChange,a=e.useRef(0);e.useEffect(function(){var e;if(n&&r){a.current+=1;var t=function(e,t,r){var n=l.default.getDefaultViewportForImage(e,t),o=r?P(n,r):n;return l.default.displayImage(e,t,o),{viewport:o,defaultViewport:n,image:t}}(r,n,1===a.current?null==o||null==(e=o.current)?void 0:e._default:null==o?void 0:o.current),u=t.viewport;g.next(t.defaultViewport),i&&i(C(u))}},[r,n,o,i])}({element:p.current,image:i,viewportRef:m,onViewportChange:f}),function(t){var r=t.element,n=t.viewport,o=t.initialViewport,i=t.onViewportChange;e.useEffect(function(){if(r&&n){var e,t=(null==n?void 0:n._reset)&&o,a=t?o:q(r);a&&(V(r,P(a,n)),t&&i&&i(v({},C(o),null!=(e=null==n?void 0:n._reset)?e:{})))}},[r,n,o,i])}({element:p.current,viewport:u,initialViewport:null==w?void 0:w.current,onViewportChange:f}),function(r){var n=r.element,i=r.interaction,a=r.viewport,u=r.onViewportChange;!function(r){var n=r.element,i=r.interaction;e.useEffect(function(){if(n){var e=t.fromEvent(n,"wheel");return M=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(){M.unsubscribe()}}},[i,n,r.onViewportChange])}({element:n,interaction:i,onViewportChange:u}),function(r){var n=r.element,i=r.interaction,a=r.onViewportChange;e.useEffect(function(){if(i&&n&&(null==n||n.removeEventListener("contextmenu",k),i.primaryDrag||i.secondaryDrag)){var e,r=t.fromEvent(n,"mousedown"),u=t.fromEvent(document,"mousemove"),c=t.fromEvent(document,"mouseup");return W=r.pipe(o.tap(function(t){var r=t.button;0===r&&(e="primaryDrag"),2===r&&(e="secondaryDrag")}),o.filter(function(){return void 0!==e}),o.tap(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",k))}),o.switchMap(function(e){var t=e.pageX,r=e.pageY;return u.pipe(o.map(function(e){e.preventDefault();var n=e.pageX-t,o=e.pageY-r;return t=e.pageX,r=e.pageY,{x:n,y:o}}),o.takeUntil(c))})).subscribe(function(t){var r=q(n);r&&e&&function(e){var t,r,n=e.element,o=e.dragged,i=e.viewport,a=e.onViewportChange,u=e.interaction[e.dragType];switch(typeof u){case"string":(t=u)&&(a?a(function(e){var r;return v({},e,null==(r=z[t])?void 0:r.call(z,i,o))}):V(n,P(i,null==(r=z[t])?void 0:r.call(z,i,o))));break;case"function":u({viewport:i,delta:o})}}({interaction:i,dragType:e,element:n,viewport:r,dragged:t,onViewportChange:a})}),function(){W.unsubscribe()}}},[n,i,a])}({element:n,interaction:i,onViewportChange:u}),function(r){var n=r.element,i=r.interaction,a=r.viewport;e.useEffect(function(){if(i&&n&&(null==n||n.removeEventListener("contextmenu",k),i.primaryClick||i.secondaryClick)){var e,r=t.fromEvent(n,"mousedown");if(i)return O=r.pipe(o.tap(function(t){var r=t.button;0===r&&(e="primaryClick"),2===r&&(e="secondaryClick")}),o.filter(function(){return void 0!==e}),o.tap(function(e){2===e.button&&(null==n||n.addEventListener("contextmenu",k))}),o.map(function(e){return{clientX:e.clientX,clientY:e.clientY,currentTarget:e.currentTarget}})).subscribe(function(t){var r,o=t.clientX,u=t.clientY,c=t.currentTarget.getBoundingClientRect(),s=function(e,t){var r;if(t)return{x:t.x,y:t.y};var n=(null!=(r=q(e))?r:{}).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==(r=i[e])||r.call(i,-s.x+o-c.left,-s.y+u-c.top))}),function(){O.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]),s.default.createElement(R,{ref:p,Progress:a},d)},exports.useFrame=function(t){var r=t.initial,n=t.max,o=e.useState(void 0===r?0:r),i=o[0],a=o[1];return{frame:i,setFrame:function(e){var t;(t="number"==typeof e?e:e(i))<0||t>n||a(e)}}},exports.useImage=function(t){var r=t.imageId,n=t.type,o=void 0===n?"Dicom":n,i=t.requestInterceptor,a=void 0===i?Y.requestInterceptor:i,u=t.onError,c=void 0===u?Y.onError:u,s=e.useReducer(G,H),l=s[0],f=s[1],d=l.loadingState,v=l.image,p=B(o,c);return e.useEffect(function(){p&&(f({type:"loading"}),function(e){var t=e.imageId,r=e.requestInterceptor,n=e.onError,o=e.getImage,i=void 0===o?K:o;try{return Promise.resolve(J(function(){return Promise.resolve(i({imageId:t,requestInterceptor:r}))},function(e){throw n(e),e}))}catch(e){return Promise.reject(e)}}({imageId:r,requestInterceptor:a,onError:c}).then(function(e){f({type:"success",payload:e})}).catch(function(){return f({type:"fail"})}))},[p,r,a,c]),{image:v,loadingState:d}},exports.useInteraction=function(){var t,r=e.useState(((t={}).primaryDrag=void 0,t.secondaryDrag=void 0,t.primaryClick=void 0,t.secondaryClick=void 0,t.mouseWheel=void 0,t));return{interaction:r[0],setInteraction:r[1]}},exports.useMultipleImages=function(r){var n=r.type,i=r.requestInterceptor,a=r.onError,u=function(r){var n,i,a=r.images,u=r.onError,c=r.requestInterceptor,s=r.type,l=e.useState({images:[],loadingStates:(n=a.length,i=Array(n).fill("initial"),new Map(i.map(function(e,t){return[t,e]}))),_currentIndex:-1}),f=l[0],d=f.images,p=f.loadingStates,m=l[1],g=B(s,u);return e.useEffect(function(){0!==a.length&&g&&(m(function(e){return v({},e,{loadingStates:e.loadingStates.set(0,"loading")})}),function(e){var r=e.images,n=e.requestInterceptor,i=e.getLoadImage,a=void 0===i?A:i,u=0;return h({loaded:u,total:r.length}),t.from(r).pipe(o.concatMap(function(e){return a(e,n)}),o.map(function(e){return h({loaded:u+=1,total:r.length}),{image:e,loaded:u}}),o.catchError(function(e){throw F(e)}))}({images:a,requestInterceptor:c}).subscribe({next:function(e){var t=e.image,r=e.loaded;m(function(e){return{images:[].concat(e.images,[t]),loadingStates:U({size:a.length,stateMap:e.loadingStates,value:r}),_currentIndex:r-1}})},error:function(e){u(e),m(function(e){return v({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")})})}}))},[a,u,c,g]),{images:d,loadingStates:Array.from(p.values())}}({images:r.imageIds,onError:void 0===a?Y.onError:a,requestInterceptor:void 0===i?Y.requestInterceptor:i,type:void 0===n?"Dicom":n}),c=u.images;return{loadingStates:u.loadingStates,images:void 0===c?[]:c}},exports.useViewport=function(t){var r=e.useState(v({},t?v({},X,{_default:t}):X)),n=r[0],o=r[1];return{viewport:n,setViewport:o,resetViewport:function(){o(v({},n,{_reset:t}))},initialized:n.scale!==X.scale}}; | ||
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}}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{useState as t,useEffect as n,useCallback as r,forwardRef as o,useRef as i,useReducer as a}from"react";import{Subject as s,merge as l,fromEvent as c,from as u}from"rxjs";import{useResizeDetector as d}from"react-resize-detector";import p from"cornerstone-core";import{tap as g,filter as m,switchMap as f,map as w,takeUntil as v,concatMap as y,catchError as h}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 n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const I=new s,V=new s,E=new s,S=({loaded:e,total:t})=>E.next({loaded:e,total:t});function D({loadedCount:e,totalCount:t,progress:n}){return e===t?100:Math.floor((100*e+(null!=n?n:0))*(1/t))}let W;const k={position:"absolute",top:"50%",width:"100%",transform:"translateY(-50%)",textAlign:"center"};function q({Progress:r}){const[{progress:o,hidden:i},a]=t({progress:void 0,hidden:!0});return n(()=>{let e=!1;const t=I.asObservable(),n=E.asObservable();let r=0,o=1,i=0;return W=l(t,n).subscribe(t=>{"number"==typeof t?i=t:(r=t.loaded,o=t.total),e||a(e=>C({},e,{progress:D({loadedCount:r,totalCount:o,progress:i})}))}),()=>{e=!0,W.unsubscribe()}},[]),n(()=>{100===o&&a(e=>C({},e,{hidden:!0})),0===o&&a(e=>C({},e,{hidden:!1}))},[o]),e.createElement("div",{style:k,"data-cy-loading":i?"":"loading"},!i&&e.createElement(r,{progress:null!=o?o:0}))}const P={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};function Y(e){if(!e)return P;const{scale:t,invert:n,hflip:r,vflip:o,translation:i,voi:a}=e;return{scale:t,invert:n,hflip:r,vflip:o,x:i.x,y:i.y,windowWidth:a.windowWidth,windowCenter:a.windowCenter}}function z(e,t={}){var n,r,o,i,a,s,l,c;return C({},e,{scale:null!=(n=t.scale)?n:e.scale,invert:null!=(r=t.invert)?r: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!=(l=t.windowWidth)?l:e.voi.windowWidth,windowCenter:null!=(c=t.windowCenter)?c:e.voi.windowCenter}})}function R(){return p}function _(e,t){return p.loadImage(e,t)}function O(e){return p.getViewport(e)}function X(e,t){return p.setViewport(e,t)}const M={position:"relative",width:"100%",height:"100%",backgroundColor:"#000",userSelect:"none"},j=o(({Progress:t,children:n},o)=>{const{resizeRef:i}=function(e){const t=e,n=null==t?void 0:t.current,o=r(()=>{if(n)return function(e){p.resize(e)}(n)},[n]),{ref:i}=d({targetRef:t,onResize:o,skipOnMount:!1});return{resizeRef:i}}(o);return e.createElement("div",{ref:i,style:M,className:"cornerstone-canvas-wrapper","data-cy":"cornerstone-canvas-wrapper"},t&&e.createElement(q,{Progress:t}),e.createElement("canvas",{className:"cornerstone-canvas"}),n)}),L=e.memo(j);function T(e){e.preventDefault()}j.displayName="Forwarded",L.displayName="ViewerWrapper";const B={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 N,A,F,G;function H({image:t,Progress:r,viewport:o,interaction:a,onViewportChange:s,children:l}){const u=i(null),d=i(o),y=function(){const e=i();return n(()=>(G=V.asObservable().subscribe(t=>{e.current=t}),()=>{G.unsubscribe()}),[]),e}();return n(()=>{if(h)return function(e){p.enable(e)}(h),()=>{!function(e){p.disable(e)}(h)}},[h=u.current]),function({element:e,image:t,viewportRef:r,onViewportChange:o}){const a=i(0);n(()=>{var n;if(!t||!e)return;a.current+=1;const{viewport:i,defaultViewport:s}=function(e,t,n){const r=p.getDefaultViewportForImage(e,t),o=n?z(r,n):r;return p.displayImage(e,t,o),{viewport:o,defaultViewport:r,image:t}}(e,t,1===a.current?null==r||null==(n=r.current)?void 0:n._default:null==r?void 0:r.current);V.next(s),o&&o(Y(i))},[e,t,r,o])}({element:u.current,image:t,viewportRef:d,onViewportChange:s}),function({element:e,viewport:t,initialViewport:r,onViewportChange:o}){n(()=>{if(!e||!t)return;const n=(null==t?void 0:t._reset)&&r,i=n?r:O(e);var a;i&&(X(e,z(i,t)),n&&o&&o(C({},Y(r),null!=(a=null==t?void 0:t._reset)?a:{})))},[e,t,r,o])}({element:u.current,viewport:o,initialViewport:null==y?void 0:y.current,onViewportChange:s}),function({element:e,interaction:t,viewport:r,onViewportChange:o}){!function({element:e,interaction:t,onViewportChange:r}){n(()=>{if(!e)return;const n=c(e,"wheel");return F=n.pipe(m(({deltaY:e})=>0!==e),g(e=>{e.preventDefault()})).subscribe(({deltaX:e,deltaY:n})=>{null!=t&&t.mouseWheel&&(null==t||t.mouseWheel(e,n))}),()=>{F.unsubscribe()}},[t,e,r])}({element:e,interaction:t,onViewportChange:o}),function({element:e,interaction:t,onViewportChange:r}){n(()=>{if(!t||!e)return;if(null==e||e.removeEventListener("contextmenu",T),!t.primaryDrag&&!t.secondaryDrag)return;const n=c(e,"mousedown"),o=c(document,"mousemove"),i=c(document,"mouseup");let a;return N=n.pipe(g(({button:e})=>{0===e&&(a="primaryDrag"),2===e&&(a="secondaryDrag")}),m(()=>void 0!==a),g(({button:t})=>{2===t&&(null==e||e.addEventListener("contextmenu",T))}),f(e=>{let t=e.pageX,n=e.pageY;return o.pipe(w(e=>{e.preventDefault();const r=e.pageX-t,o=e.pageY-n;return t=e.pageX,n=e.pageY,{x:r,y:o}}),v(i))})).subscribe(n=>{const o=O(e);o&&a&&function({element:e,interaction:t,dragType:n,dragged:r,viewport:o,onViewportChange:i}){const a=t[n];switch(typeof a){case"string":(s=a)&&(i?i(e=>{var t;return C({},e,null==(t=B[s])?void 0:t.call(B,o,r))}):X(e,z(o,null==(l=B[s])?void 0:l.call(B,o,r))));break;case"function":a({viewport:o,delta:r})}var s,l}({interaction:t,dragType:a,element:e,viewport:o,dragged:n,onViewportChange:r})}),()=>{N.unsubscribe()}},[e,t,r])}({element:e,interaction:t,onViewportChange:o}),function({element:e,interaction:t,viewport:r}){n(()=>{if(!t||!e)return;if(null==e||e.removeEventListener("contextmenu",T),!t.primaryClick&&!t.secondaryClick)return;const n=c(e,"mousedown");let o;return t?(A=n.pipe(g(({button:e})=>{0===e&&(o="primaryClick"),2===e&&(o="secondaryClick")}),m(()=>void 0!==o),g(({button:t})=>{2===t&&(null==e||e.addEventListener("contextmenu",T))}),w(({clientX:e,clientY:t,currentTarget:n})=>({clientX:e,clientY:t,currentTarget:n}))).subscribe(({clientX:n,clientY:i,currentTarget:a})=>{var s;const l=a.getBoundingClientRect(),{x:c,y:u}=function(e,t){var n;if(t){const{x:e,y:n}=t;return{x:e,y:n}}const{translation:{x:r=0,y:o=0}={}}=null!=(n=O(e))?n:{};return{x:r,y:o}}(e,r);o&&(null==(s=t[o])||s.call(t,-c+n-l.left,-u+i-l.top))}),()=>{A.unsubscribe()}):void 0},[e,t,r])}({element:e,interaction:t,viewport:r})}({element:u.current,interaction:a,viewport:o,onViewportChange:s}),n(()=>{d.current=o},[o]),e.createElement(L,{ref:u,Progress:r},l);var h}const J=function(e){b.error(e)},K=e=>{},Q={scale:0,invert:!1,hflip:!1,vflip:!1,x:0,y:0,windowWidth:0,windowCenter:0};async function U(e){try{const[e,t]=await Promise.all([import("cornerstone-wado-image-loader"),import("dicom-parser")]);return e.external.cornerstone=R(),e.external.dicomParser=t,!0}catch(t){return e(t),!1}}async function Z(e){try{return(await import("cornerstone-web-image-loader")).external.cornerstone=R(),!0}catch(t){return e(t),!1}}function $(e="Dicom",n){const[r,o]=t(!1),i="Dicom"===e?U:Z;return async function(){r||o(await i(n))}(),r}function ee(e){var t,n;const r=new Error(e instanceof Error?e.message:e.error.message);return e instanceof Error||(r.status=null==e||null==(t=e.error)||null==(n=t.response)?void 0:n.status),r}const te=e=>async t=>{const n=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),I.next(t)}});return(await n.get(t)).arrayBuffer()},ne=(e,t)=>_(e,{loader:te(t)});function re(e){const t=Array(e).fill("initial");return new Map(t.map((e,t)=>[t,e]))}function oe({size:e,stateMap:t,value:n}){return n===e?t.set(n-1,"success"):t.set(n-1,"success").set(n,"loading")}const ie=({imageIds:e,type:r="Dicom",requestInterceptor:o=K,onError:i=J})=>{const{loadingStates:a,images:s=[]}=(({images:e,onError:r,requestInterceptor:o,type:i})=>{const[{images:a,loadingStates:s},l]=t({images:[],loadingStates:re(e.length),_currentIndex:-1}),c=$(i,r);return n(()=>{0!==e.length&&c&&(l(e=>C({},e,{loadingStates:e.loadingStates.set(0,"loading")})),(({images:e,requestInterceptor:t,getLoadImage:n=ne})=>{let r=0;return S({loaded:r,total:e.length}),u(e).pipe(y(e=>n(e,t)),w(t=>(r+=1,S({loaded:r,total:e.length}),{image:t,loaded:r})),h(e=>{throw ee(e)}))})({images:e,requestInterceptor:o}).subscribe({next:({image:t,loaded:n})=>{l(r=>({images:[...r.images,t],loadingStates:oe({size:e.length,stateMap:r.loadingStates,value:n}),_currentIndex:n-1}))},error:e=>{r(e),l(e=>C({},e,{loadingStates:e.loadingStates.set(e._currentIndex+1,"fail")}))}}))},[e,r,o,c]),{images:a,loadingStates:Array.from(s.values())}})({images:e,onError:i,requestInterceptor:o,type:r});return{loadingStates:a,images:s}};function ae(e){const[n,r]=t(C({},e?C({},Q,{_default:e}):Q));return{viewport:n,setViewport:r,resetViewport:function(){r(C({},n,{_reset:e}))},initialized:n.scale!==Q.scale}}function se(){const[e,n]=t({primaryDrag:void 0,secondaryDrag:void 0,primaryClick:void 0,secondaryClick:void 0,mouseWheel:void 0});return{interaction:e,setInteraction:n}}function le(e,t){const{type:n,payload:r}=t;switch(n){case"loading":return C({},e,{loadingState:"loading"});case"success":return{loadingState:"success",image:r};case"fail":return C({},e,{loadingState:"fail"});default:return e}}const ce={loadingState:"initial",image:void 0},ue=async({imageId:e,requestInterceptor:t})=>{try{return await _(e,{loader:te(t)})}catch(e){throw ee(e)}},de=({imageId:e,type:t="Dicom",requestInterceptor:r=K,onError:o=J})=>{const[i,s]=a(le,ce),{loadingState:l,image:c}=i,u=$(t,o);return n(()=>{u&&(s({type:"loading"}),(async({imageId:e,requestInterceptor:t,onError:n,getImage:r=ue})=>{try{return await r({imageId:e,requestInterceptor:t})}catch(e){throw n(e),e}})({imageId:e,requestInterceptor:r,onError:o}).then(e=>{s({type:"success",payload:e})}).catch(()=>s({type:"fail"})))},[u,e,r,o]),{image:c,loadingState:l}},pe=({initial:e=0,max:n})=>{const[r,o]=t(e);return{frame:r,setFrame:function(e){let t=0;t="number"==typeof e?e:e(r),t<0||t>n||o(e)}}};export{H as default,pe as useFrame,de as useImage,se as useInteraction,ie as useMultipleImages,ae 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}).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}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -0,4 +1,9 @@ | ||
export declare const IMAGE_LOADER_SCHEME: { | ||
readonly WADO: "wadouri"; | ||
readonly DICOMFILE: "dicomfile"; | ||
readonly WEB: "web"; | ||
}; | ||
export declare const LOADER_TYPE: { | ||
readonly Dicom: "Dicom"; | ||
readonly Web: "Web"; | ||
readonly DICOM: "dicom"; | ||
readonly WEB: "web"; | ||
}; | ||
@@ -5,0 +10,0 @@ export declare const CONFIG: { |
@@ -1,8 +0,5 @@ | ||
import { LoadingState, LoaderType } from '../../types'; | ||
import { LoadingState, ImageId, HTTP } from '../../types'; | ||
import { CornerstoneImage } from '../../utils/cornerstoneHelper'; | ||
import { Props } from './types'; | ||
interface UseImage { | ||
({ imageId, type, requestInterceptor, onError, }: Props & { | ||
type?: LoaderType; | ||
}): { | ||
(props: Partial<HTTP> & ImageId): { | ||
loadingState: LoadingState; | ||
@@ -13,4 +10,3 @@ image: CornerstoneImage | undefined; | ||
/** | ||
* @param imageId The image url to load. | ||
* @param type The image type to load. 'Dicom'(default) | 'Web'. | ||
* @param rest wadouri | dicomfile | web | ||
* @param requestInterceptor The callback is called before a request is sent. | ||
@@ -17,0 +13,0 @@ * It use ky.js beforeRequest hook. |
@@ -5,6 +5,7 @@ /** | ||
import { CornerstoneImage } from '../../utils/cornerstoneHelper'; | ||
import { Props, GetImage } from './types'; | ||
import { ImageLoaderScheme } from '../../types'; | ||
import { Props } from './types'; | ||
interface LoadImage { | ||
({ imageId, requestInterceptor, onError, getImage, }: Required<Props> & { | ||
getImage?: GetImage; | ||
({ imageId, imageScheme, requestInterceptor, onError, }: Required<Props> & { | ||
imageScheme: ImageLoaderScheme; | ||
}): Promise<CornerstoneImage>; | ||
@@ -15,3 +16,2 @@ } | ||
* @param requestInterceptor The callback is called before a request is sent. It use ky.js beforeRequest hook. | ||
* @param getImage | ||
* @returns Promise<CornerstoneImage>. | ||
@@ -18,0 +18,0 @@ * @throws If image fetching fails. |
@@ -1,2 +0,2 @@ | ||
import { HTTP, RequestInterceptor } from '../../types'; | ||
import { HTTP, RequestInterceptor, ImageLoaderScheme } from '../../types'; | ||
import { CornerstoneImage } from '../../utils/cornerstoneHelper'; | ||
@@ -6,7 +6,7 @@ export declare type Props = { | ||
} & Partial<HTTP>; | ||
export declare type DefaultGetImage = (arg: { | ||
export declare type GetImage = (arg: { | ||
imageId: string; | ||
imageScheme: ImageLoaderScheme; | ||
requestInterceptor: RequestInterceptor; | ||
}) => Promise<CornerstoneImage>; | ||
export declare type GetImage = DefaultGetImage | (() => Promise<CornerstoneImage>); | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,8 +0,8 @@ | ||
import { ImagesLoadState, Props } from './types'; | ||
import { HTTP, ImageId } from '../../types'; | ||
import { ImagesLoadState } from './types'; | ||
interface UseMultiframeImages { | ||
({ imageIds, onError, requestInterceptor, type }: Props): ImagesLoadState; | ||
(props: Partial<HTTP> & ImageId): ImagesLoadState; | ||
} | ||
/** | ||
* @param imageIds The images urls to load. | ||
* @param type The image type to load. 'Dicom'(default) | 'Web'. | ||
* @param rest wadouri | dicomfile | web | ||
* @param requestInterceptor The callback is called before a request is sent. | ||
@@ -9,0 +9,0 @@ * It uses ky.js beforeRequest hook. |
@@ -5,13 +5,9 @@ /** | ||
import { Observable } from 'rxjs'; | ||
import { CornerstoneImage } from '../../utils/cornerstoneHelper'; | ||
import { RequestInterceptor } from '../../types'; | ||
import { RequestInterceptor, ImageLoaderScheme } from '../../types'; | ||
import { Loaded } from './types'; | ||
interface GetLoadImage { | ||
(image: string, requestInterceptor: RequestInterceptor): Promise<CornerstoneImage>; | ||
} | ||
interface LoadImages { | ||
({ images, requestInterceptor, getLoadImage, }: { | ||
({ images, imageScheme, requestInterceptor, }: { | ||
images: string[]; | ||
imageScheme: ImageLoaderScheme; | ||
requestInterceptor: RequestInterceptor; | ||
getLoadImage?: GetLoadImage; | ||
}): Observable<Loaded>; | ||
@@ -22,3 +18,2 @@ } | ||
* @param requestInterceptor The callback is called before a request is sent. It use ky.js beforeRequest hook. | ||
* @param getLoadImage | ||
* @returns Observable<{ image, loaded }>. image is cornerstone image. loaded is the numbe of loaded images. | ||
@@ -25,0 +20,0 @@ * @throws If image fetching fails. |
@@ -1,8 +0,5 @@ | ||
import { HTTP, LoaderType } from '../../types'; | ||
import { HTTP, ImageId } from '../../types'; | ||
import { ImagesLoadState } from './types'; | ||
interface UseLoadImages { | ||
({ images, onError, requestInterceptor, type, }: HTTP & { | ||
images: string[]; | ||
type?: LoaderType; | ||
}): ImagesLoadState; | ||
({ onError, requestInterceptor, ...rest }: HTTP & ImageId): ImagesLoadState; | ||
} | ||
@@ -9,0 +6,0 @@ /** |
@@ -10,2 +10,3 @@ export { InsightViewer as default } from './Viewer'; | ||
export type { DragEvent, Click, Drag, Wheel, } from './hooks/useInteraction/types'; | ||
export { useDicomFile } from './hooks/useDicomFile'; | ||
//# sourceMappingURL=index.d.ts.map |
import { Dispatch, SetStateAction } from 'react'; | ||
import { LOADING_STATE, LOADER_TYPE } from '../const'; | ||
import { LOADING_STATE, LOADER_TYPE, IMAGE_LOADER_SCHEME } from '../const'; | ||
export declare type WithChildren<T = Record<string, unknown>> = T & { | ||
@@ -36,2 +36,16 @@ children?: React.ReactNode; | ||
export declare type LoaderType = typeof LOADER_TYPE[keyof typeof LOADER_TYPE]; | ||
export declare type ImageLoaderScheme = typeof IMAGE_LOADER_SCHEME[keyof typeof IMAGE_LOADER_SCHEME]; | ||
export declare type ImageId = { | ||
[IMAGE_LOADER_SCHEME.WADO]: string | string[]; | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]?: never; | ||
[IMAGE_LOADER_SCHEME.WEB]?: never; | ||
} | { | ||
[IMAGE_LOADER_SCHEME.WADO]?: never; | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]: string | string[]; | ||
[IMAGE_LOADER_SCHEME.WEB]?: never; | ||
} | { | ||
[IMAGE_LOADER_SCHEME.WADO]?: never; | ||
[IMAGE_LOADER_SCHEME.DICOMFILE]?: never; | ||
[IMAGE_LOADER_SCHEME.WEB]: string | string[]; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
import { Viewport } from '../../types'; | ||
export declare const DefaultViewport: Viewport; | ||
export declare const ERROR_UNKNOWN = "error unknown"; | ||
//# sourceMappingURL=const.d.ts.map |
@@ -15,4 +15,4 @@ import { ViewerError } from '../../types'; | ||
} | ||
export declare function formatError(e: Error | HTTPError): ViewerError; | ||
export declare function normalizeError(e: Error | HTTPError | unknown): ViewerError; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
/// <reference types="src/@types/cornerstone-wado-image-loader" /> | ||
/// <reference types="src/@types/dicom-parser" /> | ||
import { OnError } from '../../types'; | ||
export default function setWadoImageLoader(onError: OnError): Promise<boolean>; | ||
export declare type CornerstoneWadoImageLoader = typeof import('cornerstone-wado-image-loader'); | ||
export default function setWadoImageLoader(onError: OnError): Promise<CornerstoneWadoImageLoader | undefined>; | ||
//# sourceMappingURL=setWadoImageLoader.d.ts.map |
/// <reference types="src/@types/cornerstone-web-image-loader" /> | ||
import { OnError } from '../../types'; | ||
export default function setWebImageLoader(onError: OnError): Promise<boolean>; | ||
export declare type CornerstoneWebImageLoader = typeof import('cornerstone-web-image-loader'); | ||
export default function setWebImageLoader(onError: OnError): Promise<CornerstoneWebImageLoader | undefined>; | ||
//# sourceMappingURL=setWebImageLoader.d.ts.map |
{ | ||
"name": "@lunit/insight-viewer", | ||
"version": "5.0.1-alpha.2", | ||
"version": "5.1.0-alpha.0", | ||
"description": "cornerstone 라이브러리를 기반으로 Dicom Image를 다루기 위한 여러 Component들을 제공한다.", | ||
@@ -63,3 +63,3 @@ "source": "src/index.ts", | ||
}, | ||
"gitHead": "7a448b36fbcecfa4dc59ac1d146bd2511f82489a" | ||
"gitHead": "4e00e0f17fdcc0e91805b2a5cbe59795bf2a6d23" | ||
} |
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
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
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
295289
139
754
1