cod-dicomweb-server 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +96 -0
- package/dist/16.js +1 -1
- package/dist/170.js +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/types/classes/CodDicomWebServer.d.ts +1 -1
- package/package.json +4 -3
package/LICENSE
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Cod DicomWeb Server
|
|
2
|
+
|
|
3
|
+
A wadors server proxy that get data from a Cloud Optimized Dicom format.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Testing](#testing)
|
|
10
|
+
- [Contributing](#contributing)
|
|
11
|
+
- [License](#license)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To install this utility, follow these steps:
|
|
16
|
+
|
|
17
|
+
1. **Clone the repository**:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/gradienthealth/cod-dicomweb-server.git
|
|
21
|
+
cd cod-dicomweb-server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
2. **Install dependencies**:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
3. **Build the code**:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yarn build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Make sure you have [Node.js](https://nodejs.org/) installed on your machine.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
1. **Open the Target repo in the code editor where this package needs to use and add the package**:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
yarn add cod-dicomweb-server
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
2. **Use the methods of the package in any file in the target repo**:
|
|
47
|
+
|
|
48
|
+
```javaScript
|
|
49
|
+
import { CodDicomWebServer, FetchType } from 'cod-dicomweb-server';
|
|
50
|
+
|
|
51
|
+
const server = new CodDicomWebServer();
|
|
52
|
+
const wadorsUrl = "https://storage.googleapis.com/gradienthealth_cod_dicomweb_public_benchmark/v1/dicomweb/studies/1.2.826.0.1.3680043.8.498.25373200666081576206661715880670310913/series/1.2.826.0.1.3680043.8.498.17065113110917795618106606234460323040/instances/1.3.6.1.4.1.14519.5.2.1.7009.2403.109731662822930985185381565631/frames/1";
|
|
53
|
+
const headers = {};
|
|
54
|
+
|
|
55
|
+
const result = await server.fetchCod( wadorsUrl, headers, { useSharedArrayBuffer: true, fetchType: FetchType.BYTES_OPTIMIZED, });
|
|
56
|
+
|
|
57
|
+
console.log(result);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Testing
|
|
61
|
+
|
|
62
|
+
You need to install all the dependencies and build the code to run the tests.
|
|
63
|
+
|
|
64
|
+
### Running Tests
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
yarn test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Test Coverage
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
yarn coverage
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Benchmark tests
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
yarn benchmark
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- The benchmark output will be displayed in the browser's debugger console.
|
|
83
|
+
|
|
84
|
+
## Contributing
|
|
85
|
+
|
|
86
|
+
Contributions are welcome! Please follow these steps:
|
|
87
|
+
|
|
88
|
+
1. Fork the repository.
|
|
89
|
+
2. Create a new branch ( `git checkout -b feature/YourFeature` ).
|
|
90
|
+
3. Make your changes and commit them ( `git commit -m 'Add some feature'` ).
|
|
91
|
+
4. Push to the branch ( `git push origin feature/YourFeature` ).
|
|
92
|
+
5. Open a Pull Request.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/16.js
CHANGED
package/dist/170.js
CHANGED
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
*
|
|
3
|
-
* cod-dicomweb-server v1.2.
|
|
3
|
+
* cod-dicomweb-server v1.2.2
|
|
4
4
|
* git+https://github.com/gradienthealth/cod-dicomweb-server.git
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Adithyan Dinesh and project contributors.
|
|
@@ -17,5 +17,5 @@ e.exports=function(e){return r=[function(t,r){t.exports=e},function(e,t,r){"use
|
|
|
17
17
|
* Copyright 2019 Google LLC
|
|
18
18
|
* SPDX-License-Identifier: Apache-2.0
|
|
19
19
|
*/
|
|
20
|
-
const c=Symbol("Comlink.proxy"),u=Symbol("Comlink.endpoint"),f=Symbol("Comlink.releaseProxy"),l=Symbol("Comlink.finalizer"),d=Symbol("Comlink.thrown"),h=e=>"object"==typeof e&&null!==e||"function"==typeof e,p=new Map([["proxy",{canHandle:e=>h(e)&&e[c],serialize(e){const{port1:t,port2:r}=new MessageChannel;return m(e,t),[r,[r]]},deserialize:e=>(e.start(),g(e))}],["throw",{canHandle:e=>h(e)&&d in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function m(e,t=globalThis,r=["*"]){t.addEventListener("message",(function n(a){if(!a||!a.data)return;if(!function(e,t){for(const r of e){if(t===r||"*"===r)return!0;if(r instanceof RegExp&&r.test(t))return!0}return!1}(r,a.origin))return void console.warn(`Invalid origin '${a.origin}' for comlink proxy`);const{id:i,type:o,path:s}=Object.assign({path:[]},a.data),u=(a.data.argumentList||[]).map(O);let f;try{const t=s.slice(0,-1).reduce(((e,t)=>e[t]),e),r=s.reduce(((e,t)=>e[t]),e);switch(o){case"GET":f=r;break;case"SET":t[s.slice(-1)[0]]=O(a.data.value),f=!0;break;case"APPLY":f=r.apply(t,u);break;case"CONSTRUCT":f=function(e){return Object.assign(e,{[c]:!0})}(new r(...u));break;case"ENDPOINT":{const{port1:t,port2:r}=new MessageChannel;m(e,r),f=function(e,t){return S.set(e,t),e}(t,[t])}break;case"RELEASE":f=void 0;break;default:return}}catch(e){f={value:e,[d]:0}}Promise.resolve(f).catch((e=>({value:e,[d]:0}))).then((r=>{const[a,s]=A(r);t.postMessage(Object.assign(Object.assign({},a),{id:i}),s),"RELEASE"===o&&(t.removeEventListener("message",n),y(t),l in e&&"function"==typeof e[l]&&e[l]())})).catch((e=>{const[r,n]=A({value:new TypeError("Unserializable return value"),[d]:0});t.postMessage(Object.assign(Object.assign({},r),{id:i}),n)}))})),t.start&&t.start()}function y(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function g(e,t){const r=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const n=r.get(t.id);if(n)try{n(t)}finally{r.delete(t.id)}})),x(e,r,[],t)}function v(e){if(e)throw new Error("Proxy has been released and is not useable")}function b(e){return k(e,new Map,{type:"RELEASE"}).then((()=>{y(e)}))}const w=new WeakMap,E="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(w.get(e)||0)-1;w.set(e,t),0===t&&b(e)}));function x(e,t,r=[],n=function(){}){let a=!1;const i=new Proxy(n,{get(n,o){if(v(a),o===f)return()=>{!function(e){E&&E.unregister(e)}(i),b(e),t.clear(),a=!0};if("then"===o){if(0===r.length)return{then:()=>i};const n=k(e,t,{type:"GET",path:r.map((e=>e.toString()))}).then(O);return n.then.bind(n)}return x(e,t,[...r,o])},set(n,i,o){v(a);const[s,c]=A(o);return k(e,t,{type:"SET",path:[...r,i].map((e=>e.toString())),value:s},c).then(O)},apply(n,i,o){v(a);const s=r[r.length-1];if(s===u)return k(e,t,{type:"ENDPOINT"}).then(O);if("bind"===s)return x(e,t,r.slice(0,-1));const[c,f]=P(o);return k(e,t,{type:"APPLY",path:r.map((e=>e.toString())),argumentList:c},f).then(O)},construct(n,i){v(a);const[o,s]=P(i);return k(e,t,{type:"CONSTRUCT",path:r.map((e=>e.toString())),argumentList:o},s).then(O)}});return function(e,t){const r=(w.get(t)||0)+1;w.set(t,r),E&&E.register(e,t,e)}(i,e),i}function P(e){const t=e.map(A);return[t.map((e=>e[0])),(r=t.map((e=>e[1])),Array.prototype.concat.apply([],r))];var r}const S=new WeakMap;function A(e){for(const[t,r]of p)if(r.canHandle(e)){const[n,a]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},a]}return[{type:"RAW",value:e},S.get(e)||[]]}function O(e){switch(e.type){case"HANDLER":return p.get(e.name).deserialize(e.value);case"RAW":return e.value}}function k(e,t,r,n){return new Promise((a=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,a),e.start&&e.start(),e.postMessage(Object.assign({id:i},r),n)}))}function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function I(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */I=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new F(n||[]);return a(o,"_invoke",{value:O(e,r,s)}),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",y={};function g(){}function v(){}function b(){}var w={};u(w,o,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(U([])));x&&x!==r&&n.call(x,o)&&(w=x);var P=b.prototype=g.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(a,i,o,s){var c=l(e[a],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==T(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function O(t,r,n){var a=d;return function(i,o){if(a===p)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=k(s,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=p;var u=l(t,r,n);if("normal"===u.type){if(a=n.done?m:h,u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function k(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function D(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function F(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(D,this),this.reset(!0)}function U(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(T(t)+" is not iterable")}return v.prototype=b,a(P,"constructor",{value:b,configurable:!0}),a(b,"constructor",{value:v,configurable:!0}),v.displayName=u(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,u(e,c,"GeneratorFunction")),e.prototype=Object.create(P),e},t.awrap=function(e){return{__await:e}},S(A.prototype),u(A.prototype,s,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new A(f(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(P),u(P,c,"Generator"),u(P,o,(function(){return this})),u(P,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=U,F.prototype={constructor:F,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;L(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:U(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function D(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function L(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,F(n.key),n)}}function F(e){var t=function(e,t){if("object"!=T(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=T(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==T(t)?t:t+""}var U=new(function(){return e=function e(){var t,r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t=this,n={},(r=F(r="workerRegistry"))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n},t=[{key:"registerWorker",value:function(e,t){try{var r=t();if(!r)throw new Error("WorkerFn of worker ".concat(e," is not creating a worker"));this.workerRegistry[e]={instance:g(r),nativeWorker:r}}catch(e){console.warn(e)}}},{key:"executeTask",value:(n=I().mark((function e(t,r,n){var a,i;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=null===(a=this.workerRegistry[t])||void 0===a?void 0:a.instance){e.next=3;break}throw new Error("Worker ".concat(t," not registered"));case 3:return e.prev=3,e.next=6,i[r](n);case 6:return e.abrupt("return",e.sent);case 9:throw e.prev=9,e.t0=e.catch(3),console.error('Error executing task "'.concat(r,'" on worker "').concat(t,'":'),e.t0),new Error('Task "'.concat(r,'" failed: ').concat(e.t0.message));case 13:case"end":return e.stop()}}),e,this,[[3,9]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,a){var i=n.apply(e,t);function o(e){D(i,r,a,o,s,"next",e)}function s(e){D(i,r,a,o,s,"throw",e)}o(void 0)}))},function(e,t,r){return a.apply(this,arguments)})},{key:"addEventListener",value:function(e,t,r){var n=this.workerRegistry[e];n?n.nativeWorker.addEventListener(t,r):console.error("Worker type '".concat(e,"' is not registered."))}},{key:"removeEventListener",value:function(e,t,r){var n=this.workerRegistry[e];n?n.nativeWorker.removeEventListener(t,r):console.error("Worker type '".concat(e,"' is not registered."))}}],t&&L(e.prototype,t),r&&L(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,a}());function N(){return U}function j(e){return j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},j(e)}function _(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,i,o,s=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(s.push(n.value),s.length!==t);c=!0);}catch(e){u=!0,a=e}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw a}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return M(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?M(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function B(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,q(n.key),n)}}function R(e,t,r){return(t=q(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function q(e){var t=function(e,t){if("object"!=j(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=j(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==j(t)?t:t+""}const C=function(){return e=function e(t){var r=t.fileStreamingWorkerName;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),R(this,"files",{}),R(this,"fileStreamingWorkerName",void 0),this.fileStreamingWorkerName=r},(t=[{key:"set",value:function(e,t){this.files[e]=t}},{key:"get",value:function(e,t){return!this.files[e]||t&&this.files[e].position<=t.endByte?null:t?this.files[e].data.slice(t.startByte,t.endByte):this.files[e].data}},{key:"setPosition",value:function(e,t){this.files[e]&&(this.files[e].position=t)}},{key:"getPosition",value:function(e){var t;return null===(t=this.files[e])||void 0===t?void 0:t.position}},{key:"append",value:function(e,t,r){this.files[e]&&r&&(this.files[e].data.set(t,r-t.length),this.setPosition(e,r))}},{key:"getTotalSize",value:function(){return Object.entries(this.files).reduce((function(e,t){var r=_(t,2),n=r[0],a=r[1].position;return n.includes("?bytes=")?e:e+a}),0)}},{key:"remove",value:function(e){var t=this.getPosition(e);delete this.files[e],e.includes("?bytes=")||N().executeTask(this.fileStreamingWorkerName,"decreaseFetchedSize",t)}},{key:"purge",value:function(){var e=this.getTotalSize();this.files={},N().executeTask(this.fileStreamingWorkerName,"decreaseFetchedSize",e)}}])&&B(e.prototype,t),r&&B(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();var W="https://storage.googleapis.com",G=[".tar",".zip"],z="/dicomweb/",H="filePartial",J="fileStreaming",Y=1e4;const V={Enums:e,url:t,worker:a};function Z(e,t){if(e.includes(V.url.URL_VALIDATION_STRING)){var r,n=e.split(t+"/")[1],a=n.split("/studies")[0],i=a.split("/"),s=i[0],c=i.slice(1).join("/"),u=n.split(a+"/")[1].split("/"),f=u[1],l=u[3],d="",h=1;switch(!0){case u.includes("thumbnail"):r=o.THUMBNAIL;break;case u.includes("metadata"):u.includes("instances")?(d=u[5],r=o.INSTANCE_METADATA):r=o.SERIES_METADATA;break;case u.includes("frames"):d=u[5],h=+u[7],r=o.FRAME;break;default:throw new Error("Invalid type of request")}return{type:r,bucketName:s,bucketPrefix:c,studyInstanceUID:f,seriesInstanceUID:l,sopInstanceUID:d,frameNumber:h}}}function $(e,t,r,n){var a;if(!e||null===(a=e.cod)||void 0===a||!a.instances)throw new Error("Invalid seriesMetadata provided.");if(null==r)throw new Error("Frame index is required.");var i,o=n.domain,s=n.bucketName,c=n.bucketPrefix;if(e.thumbnail){var u=e.thumbnail.uri;i="".concat(o,"/").concat(u.split("gs://")[1])}var f=Object.values(e.cod.instances).find((function(e){var r;return(null===(r=e.metadata["00080018"])||void 0===r||null===(r=r.Value)||void 0===r?void 0:r[0])===t}));if(!f)return{thumbnailUrl:i};var l,d,h=f.url,p=f.uri,m=f.headers,y=f.offset_tables,g=function(e,t,r,n){var a=e,i=V.url.FILE_EXTENSIONS.find((function(t){return e.includes(t)}));if(i){a=e.split(i)[0]+i}var o=a.split("studies/")[1];return a="".concat(t,"/").concat(r,"/").concat(n?n+"/":"","studies/").concat(o),a}(h||p,o,s,c),v=y.CustomOffsetTable,b=y.CustomOffsetTableLengths,w=!1;null!=v&&v.length&&null!=b&&b.length&&(d=(l=v[r])+b[r],w=!0);var E=m.start_byte,x=m.end_byte;return{url:g,startByte:void 0!==l?E+l:E,endByte:void 0!==d?E+d:x,thumbnailUrl:i,isMultiframe:w}}function K(e){var t=e.domain,r=void 0===t?V.url.DOMAIN:t,n=e.bucketName,a=e.bucketPrefix,i=e.studyInstanceUID,o=e.seriesInstanceUID;if(n&&a&&i&&o)return"".concat(r,"/").concat(n,"/").concat(a,"/studies/").concat(i,"/series/").concat(o,"/metadata.json")}function Q(e){return Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Q(e)}function X(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */X=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new D(n||[]);return a(o,"_invoke",{value:O(e,r,s)}),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",y={};function g(){}function v(){}function b(){}var w={};u(w,o,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(L([])));x&&x!==r&&n.call(x,o)&&(w=x);var P=b.prototype=g.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(a,i,o,s){var c=l(e[a],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==Q(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function O(t,r,n){var a=d;return function(i,o){if(a===p)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=k(s,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=p;var u=l(t,r,n);if("normal"===u.type){if(a=n.done?m:h,u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function k(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function L(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(Q(t)+" is not iterable")}return v.prototype=b,a(P,"constructor",{value:b,configurable:!0}),a(b,"constructor",{value:v,configurable:!0}),v.displayName=u(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,u(e,c,"GeneratorFunction")),e.prototype=Object.create(P),e},t.awrap=function(e){return{__await:e}},S(A.prototype),u(A.prototype,s,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new A(f(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(P),u(P,c,"Generator"),u(P,o,(function(){return this})),u(P,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=L,D.prototype={constructor:D,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function ee(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function te(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,re(n.key),n)}}function re(e){var t=function(e,t){if("object"!=Q(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Q(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Q(t)?t:t+""}const ne=function(){return e=function e(){var t,r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t=this,n={},(r=re(r="metadata"))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n},t=[{key:"getMetadataFromCache",value:function(e){return this.metadata[e]}},{key:"getMetadata",value:(n=X().mark((function e(t,r){var n,a,i,o;return X().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=K(t)){e.next=3;break}throw new Error("Error creating metadata json url");case 3:if(!(a=this.getMetadataFromCache(n))){e.next=6;break}return e.abrupt("return",a);case 6:return e.prev=6,e.next=9,fetch(n,{headers:r});case 9:if((i=e.sent).ok){e.next=12;break}throw new Error("Failed to fetch metadata: ".concat(i.statusText));case 12:return e.next=14,i.json();case 14:return o=e.sent,this.metadata[n]=o,e.abrupt("return",o);case 19:throw e.prev=19,e.t0=e.catch(6),console.error(e.t0),e.t0;case 23:case"end":return e.stop()}}),e,this,[[6,19]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,a){var i=n.apply(e,t);function o(e){ee(i,r,a,o,s,"next",e)}function s(e){ee(i,r,a,o,s,"throw",e)}o(void 0)}))},function(e,t){return a.apply(this,arguments)})}],t&&te(e.prototype,t),r&&te(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,a}();function ae(e){return ae="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ae(e)}function ie(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ie=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new D(n||[]);return a(o,"_invoke",{value:O(e,r,s)}),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",y={};function g(){}function v(){}function b(){}var w={};u(w,o,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(L([])));x&&x!==r&&n.call(x,o)&&(w=x);var P=b.prototype=g.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(a,i,o,s){var c=l(e[a],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==ae(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function O(t,r,n){var a=d;return function(i,o){if(a===p)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=k(s,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=p;var u=l(t,r,n);if("normal"===u.type){if(a=n.done?m:h,u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function k(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function L(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(ae(t)+" is not iterable")}return v.prototype=b,a(P,"constructor",{value:b,configurable:!0}),a(b,"constructor",{value:v,configurable:!0}),v.displayName=u(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,u(e,c,"GeneratorFunction")),e.prototype=Object.create(P),e},t.awrap=function(e){return{__await:e}},S(A.prototype),u(A.prototype,s,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new A(f(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(P),u(P,c,"Generator"),u(P,o,(function(){return this})),u(P,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=L,D.prototype={constructor:D,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function oe(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function se(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function o(e){oe(i,n,a,o,s,"next",e)}function s(e){oe(i,n,a,o,s,"throw",e)}o(void 0)}))}}function ce(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,fe(n.key),n)}}function ue(e,t,r){return(t=fe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function fe(e){var t=function(e,t){if("object"!=ae(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ae(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ae(t)?t:t+""}var le=function(){return e=function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),ue(this,"filePromises",{}),ue(this,"options",{maxWorkerFetchSize:1/0,domain:V.url.DOMAIN}),ue(this,"fileManager",void 0),ue(this,"metadataManager",void 0),ue(this,"seriesUidFileUrls",{}),ue(this,"setOptions",(function(e){Object.keys(e).forEach((function(r){void 0!==e[r]&&(t.options[r]=e[r])}))})),ue(this,"getOptions",(function(){return t.options}));var a=n.maxWorkerFetchSize,i=n.domain;this.options.maxWorkerFetchSize=a||this.options.maxWorkerFetchSize,this.options.domain=i||this.options.domain;var o=V.worker.FILE_STREAMING_WORKER_NAME,s=V.worker.FILE_PARTIAL_WORKER_NAME;this.fileManager=new C({fileStreamingWorkerName:o}),this.metadataManager=new ne,function(e,t){var n=e.fileStreamingWorkerName,a=e.filePartialWorkerName,i=N();i.registerWorker(n,(function(){return new Worker(new URL(r.p+r.u(170),r.b),{name:n})})),i.executeTask(n,"setMaxFetchSize",t),i.registerWorker(a,(function(){return new Worker(new URL(r.p+r.u(16),r.b),{name:a})}))}({fileStreamingWorkerName:o,filePartialWorkerName:s},this.options.maxWorkerFetchSize)},t=[{key:"addFileUrl",value:function(e,t){this.seriesUidFileUrls[e]?this.seriesUidFileUrls[e].push(t):this.seriesUidFileUrls[e]=[t]}},{key:"fetchCod",value:(c=se(ie().mark((function e(t,r){var n,a,c,u,f,l,d,h,p,m,y,g,v,b,w,E,x,P,S,A,O,k,T,I=this,D=arguments;return ie().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=D.length>2&&void 0!==D[2]?D[2]:{},c=(a=D.length>3&&void 0!==D[3]?D[3]:{}).useSharedArrayBuffer,u=void 0!==c&&c,f=a.fetchType,l=void 0===f?V.Enums.FetchType.API_OPTIMIZED:f,e.prev=2,t){e.next=5;break}throw new Error("Url not provided");case 5:if(!(d=Z(t,this.options.domain))){e.next=31;break}return h=d.type,p=d.bucketName,m=d.bucketPrefix,y=d.studyInstanceUID,g=d.seriesInstanceUID,v=d.sopInstanceUID,b=d.frameNumber,e.next=10,this.metadataManager.getMetadata({domain:this.options.domain,bucketName:p,bucketPrefix:m,studyInstanceUID:y,seriesInstanceUID:g},n);case 10:if(w=e.sent){e.next=13;break}throw new Error("Metadata not found for ".concat(t));case 13:E=$(w,v,b-1,{domain:this.options.domain,bucketName:p,bucketPrefix:m}),x=E.url,P=E.startByte,S=E.endByte,A=E.thumbnailUrl,O=E.isMultiframe,e.t0=h,e.next=e.t0===o.THUMBNAIL?17:e.t0===o.FRAME?21:e.t0===o.SERIES_METADATA||e.t0===o.INSTANCE_METADATA?27:28;break;case 17:if(A){e.next=19;break}throw new Error("Thumbnail not found for ".concat(t));case 19:return this.addFileUrl(g,A),e.abrupt("return",this.fetchFile(A,n,{useSharedArrayBuffer:u}));case 21:if(x){e.next=23;break}throw new Error("Url not found for frame");case 23:return k=x,l===i.BYTES_OPTIMIZED&&(k="".concat(x,"?bytes=").concat(P,"-").concat(S)),this.addFileUrl(g,x),e.abrupt("return",this.fetchFile(k,n,{offsets:{startByte:P,endByte:S},useSharedArrayBuffer:u,fetchType:l}).then((function(e){if(null==e||!e.byteLength)throw new Error("File Arraybuffer is not found");if(O)return e;var t=(0,s.parseDicom)(new Uint8Array(e)).elements.x7fe00010,r=t.dataOffset,n=t.length;if(t.hadUndefinedLength&&t.fragments){var a=t.fragments[0];r=a.position,n=a.length}else r+=8;return e.slice(r,r+n)})));case 27:return e.abrupt("return",this.parseMetadata(w,h,v));case 28:throw new Error("Unsupported request type: ".concat(h));case 29:e.next=32;break;case 31:return e.abrupt("return",new Promise((function(e,r){return I.fetchFile(t,n,{useSharedArrayBuffer:u}).then((function(r){if(r instanceof ArrayBuffer)try{var n=(0,s.parseDicom)(new Uint8Array(r)).string("0020000e");n&&I.addFileUrl(n,t)}catch(e){console.warn("CodDicomWebServer.ts: There is some issue parsing the file.",e)}e(r)})).catch((function(e){return r(e)}))})));case 32:e.next=39;break;case 34:throw e.prev=34,e.t1=e.catch(2),T=new Error("CodDicomWebServer.ts: ".concat(e.t1.message||"An error occured when fetching the COD")),console.error(T),T;case 39:case"end":return e.stop()}}),e,this,[[2,34]])}))),function(e,t){return c.apply(this,arguments)})},{key:"fetchFile",value:(a=se(ie().mark((function e(t,r){var n,a,o,s,c,u,f,l,d,h,p,m,y,g,v,b,w=this,E=arguments;return ie().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=(n=E.length>2&&void 0!==E[2]?E[2]:{}).offsets,o=n.useSharedArrayBuffer,s=void 0!==o&&o,c=n.fetchType,u=void 0===c?V.Enums.FetchType.API_OPTIMIZED:c,f=u===i.BYTES_OPTIMIZED,!(l=this.fileManager.get(t,f?void 0:a))){e.next=5;break}return e.abrupt("return",new Promise((function(e,t){try{e(l.buffer)}catch(e){t(e)}})));case 5:return d=this.getOptions(),h=d.maxWorkerFetchSize,p=N(),m=V.worker,y=m.FILE_STREAMING_WORKER_NAME,g=m.FILE_PARTIAL_WORKER_NAME,v=m.THRESHOLD,this.filePromises[t]?b=this.filePromises[t]:(b=new Promise((function(e,n){if(w.fileManager.getTotalSize()+v>h)throw new Error("CodDicomWebServer.ts: Maximum size(".concat(h,") for fetching files reached"));var i=V.Enums.FetchType;if(u===i.API_OPTIMIZED){var o=function(e){if(e instanceof ErrorEvent)throw n(e.error),e.error;var r=e.data,a=r.url,i=r.position,s=r.fileArraybuffer;a===t&&s&&(w.fileManager.set(a,{data:s,position:i}),p.removeEventListener(y,"message",o))};p.addEventListener(y,"message",o),p.executeTask(y,"stream",{url:t,headers:r,useSharedArrayBuffer:s}).then((function(){e()})).catch((function(e){p.removeEventListener(y,"message",o),n(e)})).then((function(){return delete w.filePromises[t]}))}else if(u===i.BYTES_OPTIMIZED&&a){var c=a.startByte,f=a.endByte;r.Range="bytes=".concat(c,"-").concat(f-1);var l=t.split("?bytes=")[0];p.executeTask(g,"partial",{url:l,headers:r,useSharedArrayBuffer:s}).then((function(r){r?(w.fileManager.set(t,{data:new Uint8Array(r),position:r.byteLength}),e()):n(new Error("File - ".concat(l," not found")))})).catch((function(e){n(e)})).then((function(){return delete w.filePromises[t]}))}else n(new Error("CodDicomWebServer.ts: Offsets is needed in bytes optimized fetching"))})),this.filePromises[t]=b),e.abrupt("return",new Promise((function(e,r){var n=!1,i=function(i){if(i instanceof ErrorEvent)throw r(i.message),i.error;var o=i.data,s=o.url,c=o.position,u=o.chunk;if(o.isAppending&&(u?w.fileManager.append(s,u,c):w.fileManager.setPosition(s,c)),!n&&s===t&&a&&c>a.endByte)try{var f=w.fileManager.get(s,a);n=!0,e(null==f?void 0:f.buffer)}catch(e){r(e)}};a&&!f&&p.addEventListener(y,"message",i),b.then((function(){if(!n){var r=w.fileManager.get(t,f?void 0:a);n=!0,e(null==r?void 0:r.buffer)}})).catch((function(e){r(e)})).then((function(){p.removeEventListener(y,"message",i)}))})));case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"delete",value:function(e){var t=this,r=this.seriesUidFileUrls[e];r&&r.forEach((function(e){t.fileManager.remove(e)})),delete this.seriesUidFileUrls[e]}},{key:"deleteAll",value:function(){var e=this;Object.values(this.seriesUidFileUrls).forEach((function(t){t.forEach((function(t){e.fileManager.remove(t)}))})),this.seriesUidFileUrls={}}},{key:"parseMetadata",value:function(e,t,r){var n;return t===o.INSTANCE_METADATA?null===(n=Object.values(e.cod.instances).find((function(e){var t;return(null===(t=e.metadata["00080018"])||void 0===t||null===(t=t.Value)||void 0===t?void 0:t[0])===r})))||void 0===n?void 0:n.metadata:Object.values(e.cod.instances).map((function(e){return e.metadata}))}}],t&&ce(e.prototype,t),n&&ce(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,a,c}();const de=le,he={FetchType:i,CodDicomWebServer:le}})(),n})()));
|
|
20
|
+
const c=Symbol("Comlink.proxy"),u=Symbol("Comlink.endpoint"),f=Symbol("Comlink.releaseProxy"),l=Symbol("Comlink.finalizer"),d=Symbol("Comlink.thrown"),h=e=>"object"==typeof e&&null!==e||"function"==typeof e,p=new Map([["proxy",{canHandle:e=>h(e)&&e[c],serialize(e){const{port1:t,port2:r}=new MessageChannel;return m(e,t),[r,[r]]},deserialize:e=>(e.start(),g(e))}],["throw",{canHandle:e=>h(e)&&d in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function m(e,t=globalThis,r=["*"]){t.addEventListener("message",(function n(a){if(!a||!a.data)return;if(!function(e,t){for(const r of e){if(t===r||"*"===r)return!0;if(r instanceof RegExp&&r.test(t))return!0}return!1}(r,a.origin))return void console.warn(`Invalid origin '${a.origin}' for comlink proxy`);const{id:i,type:o,path:s}=Object.assign({path:[]},a.data),u=(a.data.argumentList||[]).map(O);let f;try{const t=s.slice(0,-1).reduce(((e,t)=>e[t]),e),r=s.reduce(((e,t)=>e[t]),e);switch(o){case"GET":f=r;break;case"SET":t[s.slice(-1)[0]]=O(a.data.value),f=!0;break;case"APPLY":f=r.apply(t,u);break;case"CONSTRUCT":f=function(e){return Object.assign(e,{[c]:!0})}(new r(...u));break;case"ENDPOINT":{const{port1:t,port2:r}=new MessageChannel;m(e,r),f=function(e,t){return S.set(e,t),e}(t,[t])}break;case"RELEASE":f=void 0;break;default:return}}catch(e){f={value:e,[d]:0}}Promise.resolve(f).catch((e=>({value:e,[d]:0}))).then((r=>{const[a,s]=A(r);t.postMessage(Object.assign(Object.assign({},a),{id:i}),s),"RELEASE"===o&&(t.removeEventListener("message",n),y(t),l in e&&"function"==typeof e[l]&&e[l]())})).catch((e=>{const[r,n]=A({value:new TypeError("Unserializable return value"),[d]:0});t.postMessage(Object.assign(Object.assign({},r),{id:i}),n)}))})),t.start&&t.start()}function y(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function g(e,t){const r=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const n=r.get(t.id);if(n)try{n(t)}finally{r.delete(t.id)}})),x(e,r,[],t)}function v(e){if(e)throw new Error("Proxy has been released and is not useable")}function b(e){return k(e,new Map,{type:"RELEASE"}).then((()=>{y(e)}))}const w=new WeakMap,E="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(w.get(e)||0)-1;w.set(e,t),0===t&&b(e)}));function x(e,t,r=[],n=function(){}){let a=!1;const i=new Proxy(n,{get(n,o){if(v(a),o===f)return()=>{!function(e){E&&E.unregister(e)}(i),b(e),t.clear(),a=!0};if("then"===o){if(0===r.length)return{then:()=>i};const n=k(e,t,{type:"GET",path:r.map((e=>e.toString()))}).then(O);return n.then.bind(n)}return x(e,t,[...r,o])},set(n,i,o){v(a);const[s,c]=A(o);return k(e,t,{type:"SET",path:[...r,i].map((e=>e.toString())),value:s},c).then(O)},apply(n,i,o){v(a);const s=r[r.length-1];if(s===u)return k(e,t,{type:"ENDPOINT"}).then(O);if("bind"===s)return x(e,t,r.slice(0,-1));const[c,f]=P(o);return k(e,t,{type:"APPLY",path:r.map((e=>e.toString())),argumentList:c},f).then(O)},construct(n,i){v(a);const[o,s]=P(i);return k(e,t,{type:"CONSTRUCT",path:r.map((e=>e.toString())),argumentList:o},s).then(O)}});return function(e,t){const r=(w.get(t)||0)+1;w.set(t,r),E&&E.register(e,t,e)}(i,e),i}function P(e){const t=e.map(A);return[t.map((e=>e[0])),(r=t.map((e=>e[1])),Array.prototype.concat.apply([],r))];var r}const S=new WeakMap;function A(e){for(const[t,r]of p)if(r.canHandle(e)){const[n,a]=r.serialize(e);return[{type:"HANDLER",name:t,value:n},a]}return[{type:"RAW",value:e},S.get(e)||[]]}function O(e){switch(e.type){case"HANDLER":return p.get(e.name).deserialize(e.value);case"RAW":return e.value}}function k(e,t,r,n){return new Promise((a=>{const i=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(i,a),e.start&&e.start(),e.postMessage(Object.assign({id:i},r),n)}))}function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function I(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */I=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new F(n||[]);return a(o,"_invoke",{value:O(e,r,s)}),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",y={};function g(){}function v(){}function b(){}var w={};u(w,o,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(U([])));x&&x!==r&&n.call(x,o)&&(w=x);var P=b.prototype=g.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(a,i,o,s){var c=l(e[a],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==T(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function O(t,r,n){var a=d;return function(i,o){if(a===p)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=k(s,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=p;var u=l(t,r,n);if("normal"===u.type){if(a=n.done?m:h,u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function k(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function D(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function F(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(D,this),this.reset(!0)}function U(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(T(t)+" is not iterable")}return v.prototype=b,a(P,"constructor",{value:b,configurable:!0}),a(b,"constructor",{value:v,configurable:!0}),v.displayName=u(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,u(e,c,"GeneratorFunction")),e.prototype=Object.create(P),e},t.awrap=function(e){return{__await:e}},S(A.prototype),u(A.prototype,s,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new A(f(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(P),u(P,c,"Generator"),u(P,o,(function(){return this})),u(P,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=U,F.prototype={constructor:F,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;L(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:U(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function D(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function L(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,F(n.key),n)}}function F(e){var t=function(e,t){if("object"!=T(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=T(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==T(t)?t:t+""}var U=new(function(){return e=function e(){var t,r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t=this,n={},(r=F(r="workerRegistry"))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n},t=[{key:"registerWorker",value:function(e,t){try{var r=t();if(!r)throw new Error("WorkerFn of worker ".concat(e," is not creating a worker"));this.workerRegistry[e]={instance:g(r),nativeWorker:r}}catch(e){console.warn(e)}}},{key:"executeTask",value:(n=I().mark((function e(t,r,n){var a,i;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=null===(a=this.workerRegistry[t])||void 0===a?void 0:a.instance){e.next=3;break}throw new Error("Worker ".concat(t," not registered"));case 3:return e.prev=3,e.next=6,i[r](n);case 6:return e.abrupt("return",e.sent);case 9:throw e.prev=9,e.t0=e.catch(3),console.error('Error executing task "'.concat(r,'" on worker "').concat(t,'":'),e.t0),new Error('Task "'.concat(r,'" failed: ').concat(e.t0.message));case 13:case"end":return e.stop()}}),e,this,[[3,9]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,a){var i=n.apply(e,t);function o(e){D(i,r,a,o,s,"next",e)}function s(e){D(i,r,a,o,s,"throw",e)}o(void 0)}))},function(e,t,r){return a.apply(this,arguments)})},{key:"addEventListener",value:function(e,t,r){var n=this.workerRegistry[e];n?n.nativeWorker.addEventListener(t,r):console.error("Worker type '".concat(e,"' is not registered."))}},{key:"removeEventListener",value:function(e,t,r){var n=this.workerRegistry[e];n?n.nativeWorker.removeEventListener(t,r):console.error("Worker type '".concat(e,"' is not registered."))}}],t&&L(e.prototype,t),r&&L(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,a}());function N(){return U}function j(e){return j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},j(e)}function _(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,i,o,s=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(s.push(n.value),s.length!==t);c=!0);}catch(e){u=!0,a=e}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw a}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return M(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?M(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function B(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,q(n.key),n)}}function R(e,t,r){return(t=q(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function q(e){var t=function(e,t){if("object"!=j(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=j(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==j(t)?t:t+""}const C=function(){return e=function e(t){var r=t.fileStreamingWorkerName;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),R(this,"files",{}),R(this,"fileStreamingWorkerName",void 0),this.fileStreamingWorkerName=r},(t=[{key:"set",value:function(e,t){this.files[e]=t}},{key:"get",value:function(e,t){return!this.files[e]||t&&this.files[e].position<=t.endByte?null:t?this.files[e].data.slice(t.startByte,t.endByte):this.files[e].data}},{key:"setPosition",value:function(e,t){this.files[e]&&(this.files[e].position=t)}},{key:"getPosition",value:function(e){var t;return null===(t=this.files[e])||void 0===t?void 0:t.position}},{key:"append",value:function(e,t,r){this.files[e]&&r&&(this.files[e].data.set(t,r-t.length),this.setPosition(e,r))}},{key:"getTotalSize",value:function(){return Object.entries(this.files).reduce((function(e,t){var r=_(t,2),n=r[0],a=r[1].position;return n.includes("?bytes=")?e:e+a}),0)}},{key:"remove",value:function(e){var t=this.getPosition(e);delete this.files[e],e.includes("?bytes=")||N().executeTask(this.fileStreamingWorkerName,"decreaseFetchedSize",t)}},{key:"purge",value:function(){var e=this.getTotalSize();this.files={},N().executeTask(this.fileStreamingWorkerName,"decreaseFetchedSize",e)}}])&&B(e.prototype,t),r&&B(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();var W="https://storage.googleapis.com",G=[".tar",".zip"],z="/dicomweb/",H="filePartial",J="fileStreaming",Y=1e4;const V={Enums:e,url:t,worker:a};function Z(e,t){if(e.includes(V.url.URL_VALIDATION_STRING)){var r,n=e.split(t+"/")[1],a=n.split("/studies")[0],i=a.split("/"),s=i[0],c=i.slice(1).join("/"),u=n.split(a+"/")[1].split("/"),f=u[1],l=u[3],d="",h=1;switch(!0){case u.includes("thumbnail"):r=o.THUMBNAIL;break;case u.includes("metadata"):u.includes("instances")?(d=u[5],r=o.INSTANCE_METADATA):r=o.SERIES_METADATA;break;case u.includes("frames"):d=u[5],h=+u[7],r=o.FRAME;break;default:throw new Error("Invalid type of request")}return{type:r,bucketName:s,bucketPrefix:c,studyInstanceUID:f,seriesInstanceUID:l,sopInstanceUID:d,frameNumber:h}}}function $(e,t,r,n){var a;if(!e||null===(a=e.cod)||void 0===a||!a.instances)throw new Error("Invalid seriesMetadata provided.");if(null==r)throw new Error("Frame index is required.");var i,o=n.domain,s=n.bucketName,c=n.bucketPrefix;if(e.thumbnail){var u=e.thumbnail.uri;i="".concat(o,"/").concat(u.split("gs://")[1])}var f=Object.values(e.cod.instances).find((function(e){var r;return(null===(r=e.metadata["00080018"])||void 0===r||null===(r=r.Value)||void 0===r?void 0:r[0])===t}));if(!f)return{thumbnailUrl:i};var l,d,h=f.url,p=f.uri,m=f.headers,y=f.offset_tables,g=function(e,t,r,n){var a=e,i=V.url.FILE_EXTENSIONS.find((function(t){return e.includes(t)}));if(i){a=e.split(i)[0]+i}var o=a.split("studies/")[1];return a="".concat(t,"/").concat(r,"/").concat(n?n+"/":"","studies/").concat(o),a}(h||p,o,s,c),v=y.CustomOffsetTable,b=y.CustomOffsetTableLengths,w=!1;null!=v&&v.length&&null!=b&&b.length&&(d=(l=v[r])+b[r],w=!0);var E=m.start_byte,x=m.end_byte;return{url:g,startByte:void 0!==l?E+l:E,endByte:void 0!==d?E+d:x,thumbnailUrl:i,isMultiframe:w}}function K(e){var t=e.domain,r=void 0===t?V.url.DOMAIN:t,n=e.bucketName,a=e.bucketPrefix,i=e.studyInstanceUID,o=e.seriesInstanceUID;if(n&&a&&i&&o)return"".concat(r,"/").concat(n,"/").concat(a,"/studies/").concat(i,"/series/").concat(o,"/metadata.json")}function Q(e){return Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Q(e)}function X(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */X=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new D(n||[]);return a(o,"_invoke",{value:O(e,r,s)}),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",y={};function g(){}function v(){}function b(){}var w={};u(w,o,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(L([])));x&&x!==r&&n.call(x,o)&&(w=x);var P=b.prototype=g.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(a,i,o,s){var c=l(e[a],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==Q(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function O(t,r,n){var a=d;return function(i,o){if(a===p)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=k(s,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=p;var u=l(t,r,n);if("normal"===u.type){if(a=n.done?m:h,u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function k(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function L(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(Q(t)+" is not iterable")}return v.prototype=b,a(P,"constructor",{value:b,configurable:!0}),a(b,"constructor",{value:v,configurable:!0}),v.displayName=u(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,u(e,c,"GeneratorFunction")),e.prototype=Object.create(P),e},t.awrap=function(e){return{__await:e}},S(A.prototype),u(A.prototype,s,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new A(f(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(P),u(P,c,"Generator"),u(P,o,(function(){return this})),u(P,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=L,D.prototype={constructor:D,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function ee(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function te(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,re(n.key),n)}}function re(e){var t=function(e,t){if("object"!=Q(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Q(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Q(t)?t:t+""}const ne=function(){return e=function e(){var t,r,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),t=this,n={},(r=re(r="metadata"))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n},t=[{key:"getMetadataFromCache",value:function(e){return this.metadata[e]}},{key:"getMetadata",value:(n=X().mark((function e(t,r){var n,a,i,o;return X().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=K(t)){e.next=3;break}throw new Error("Error creating metadata json url");case 3:if(!(a=this.getMetadataFromCache(n))){e.next=6;break}return e.abrupt("return",a);case 6:return e.prev=6,e.next=9,fetch(n,{headers:r});case 9:if((i=e.sent).ok){e.next=12;break}throw new Error("Failed to fetch metadata: ".concat(i.statusText));case 12:return e.next=14,i.json();case 14:return o=e.sent,this.metadata[n]=o,e.abrupt("return",o);case 19:throw e.prev=19,e.t0=e.catch(6),console.error(e.t0),e.t0;case 23:case"end":return e.stop()}}),e,this,[[6,19]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,a){var i=n.apply(e,t);function o(e){ee(i,r,a,o,s,"next",e)}function s(e){ee(i,r,a,o,s,"throw",e)}o(void 0)}))},function(e,t){return a.apply(this,arguments)})}],t&&te(e.prototype,t),r&&te(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,a}();function ae(e){return ae="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ae(e)}function ie(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ie=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,o=Object.create(i.prototype),s=new D(n||[]);return a(o,"_invoke",{value:O(e,r,s)}),o}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",y={};function g(){}function v(){}function b(){}var w={};u(w,o,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(L([])));x&&x!==r&&n.call(x,o)&&(w=x);var P=b.prototype=g.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(a,i,o,s){var c=l(e[a],e,i);if("throw"!==c.type){var u=c.arg,f=u.value;return f&&"object"==ae(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(f).then((function(e){u.value=e,o(u)}),(function(e){return r("throw",e,o,s)}))}s(c.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function O(t,r,n){var a=d;return function(i,o){if(a===p)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=k(s,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=p;var u=l(t,r,n);if("normal"===u.type){if(a=n.done?m:h,u.arg===y)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function k(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=l(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function L(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(ae(t)+" is not iterable")}return v.prototype=b,a(P,"constructor",{value:b,configurable:!0}),a(b,"constructor",{value:v,configurable:!0}),v.displayName=u(b,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,u(e,c,"GeneratorFunction")),e.prototype=Object.create(P),e},t.awrap=function(e){return{__await:e}},S(A.prototype),u(A.prototype,s,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new A(f(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(P),u(P,c,"Generator"),u(P,o,(function(){return this})),u(P,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=L,D.prototype={constructor:D,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}function oe(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function se(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function o(e){oe(i,n,a,o,s,"next",e)}function s(e){oe(i,n,a,o,s,"throw",e)}o(void 0)}))}}function ce(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,fe(n.key),n)}}function ue(e,t,r){return(t=fe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function fe(e){var t=function(e,t){if("object"!=ae(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ae(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ae(t)?t:t+""}var le=function(){return e=function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),ue(this,"filePromises",{}),ue(this,"options",{maxWorkerFetchSize:1/0,domain:V.url.DOMAIN}),ue(this,"fileManager",void 0),ue(this,"metadataManager",void 0),ue(this,"seriesUidFileUrls",{}),ue(this,"setOptions",(function(e){Object.keys(e).forEach((function(r){void 0!==e[r]&&(t.options[r]=e[r])}))})),ue(this,"getOptions",(function(){return t.options}));var a=n.maxWorkerFetchSize,i=n.domain;this.options.maxWorkerFetchSize=a||this.options.maxWorkerFetchSize,this.options.domain=i||this.options.domain;var o=V.worker.FILE_STREAMING_WORKER_NAME,s=V.worker.FILE_PARTIAL_WORKER_NAME;this.fileManager=new C({fileStreamingWorkerName:o}),this.metadataManager=new ne,function(e,t){var n=e.fileStreamingWorkerName,a=e.filePartialWorkerName,i=N();i.registerWorker(n,(function(){return new Worker(new URL(r.p+r.u(170),r.b),{name:n})})),i.executeTask(n,"setMaxFetchSize",t),i.registerWorker(a,(function(){return new Worker(new URL(r.p+r.u(16),r.b),{name:a})}))}({fileStreamingWorkerName:o,filePartialWorkerName:s},this.options.maxWorkerFetchSize)},t=[{key:"addFileUrl",value:function(e,t){this.seriesUidFileUrls[e]?this.seriesUidFileUrls[e].push(t):this.seriesUidFileUrls[e]=[t]}},{key:"fetchCod",value:(c=se(ie().mark((function e(t){var r,n,a,c,u,f,l,d,h,p,m,y,g,v,b,w,E,x,P,S,A,O,k,T=this,I=arguments;return ie().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=I.length>1&&void 0!==I[1]?I[1]:{},a=(n=I.length>2&&void 0!==I[2]?I[2]:{}).useSharedArrayBuffer,c=void 0!==a&&a,u=n.fetchType,f=void 0===u?V.Enums.FetchType.API_OPTIMIZED:u,e.prev=2,t){e.next=5;break}throw new Error("Url not provided");case 5:if(!(l=Z(t,this.options.domain))){e.next=31;break}return d=l.type,h=l.bucketName,p=l.bucketPrefix,m=l.studyInstanceUID,y=l.seriesInstanceUID,g=l.sopInstanceUID,v=l.frameNumber,e.next=10,this.metadataManager.getMetadata({domain:this.options.domain,bucketName:h,bucketPrefix:p,studyInstanceUID:m,seriesInstanceUID:y},r);case 10:if(b=e.sent){e.next=13;break}throw new Error("Metadata not found for ".concat(t));case 13:w=$(b,g,v-1,{domain:this.options.domain,bucketName:h,bucketPrefix:p}),E=w.url,x=w.startByte,P=w.endByte,S=w.thumbnailUrl,A=w.isMultiframe,e.t0=d,e.next=e.t0===o.THUMBNAIL?17:e.t0===o.FRAME?21:e.t0===o.SERIES_METADATA||e.t0===o.INSTANCE_METADATA?27:28;break;case 17:if(S){e.next=19;break}throw new Error("Thumbnail not found for ".concat(t));case 19:return this.addFileUrl(y,S),e.abrupt("return",this.fetchFile(S,r,{useSharedArrayBuffer:c}));case 21:if(E){e.next=23;break}throw new Error("Url not found for frame");case 23:return O=E,f===i.BYTES_OPTIMIZED&&(O="".concat(E,"?bytes=").concat(x,"-").concat(P)),this.addFileUrl(y,E),e.abrupt("return",this.fetchFile(O,r,{offsets:{startByte:x,endByte:P},useSharedArrayBuffer:c,fetchType:f}).then((function(e){if(null==e||!e.byteLength)throw new Error("File Arraybuffer is not found");if(A)return e;var t=(0,s.parseDicom)(new Uint8Array(e)).elements.x7fe00010,r=t.dataOffset,n=t.length;if(t.hadUndefinedLength&&t.fragments){var a=t.fragments[0];r=a.position,n=a.length}else r+=8;return e.slice(r,r+n)})));case 27:return e.abrupt("return",this.parseMetadata(b,d,g));case 28:throw new Error("Unsupported request type: ".concat(d));case 29:e.next=32;break;case 31:return e.abrupt("return",new Promise((function(e,n){return T.fetchFile(t,r,{useSharedArrayBuffer:c}).then((function(r){if(r instanceof ArrayBuffer)try{var n=(0,s.parseDicom)(new Uint8Array(r)).string("0020000e");n&&T.addFileUrl(n,t)}catch(e){console.warn("CodDicomWebServer.ts: There is some issue parsing the file.",e)}e(r)})).catch((function(e){return n(e)}))})));case 32:e.next=39;break;case 34:throw e.prev=34,e.t1=e.catch(2),k=new Error("CodDicomWebServer.ts: ".concat(e.t1.message||"An error occured when fetching the COD")),console.error(k),k;case 39:case"end":return e.stop()}}),e,this,[[2,34]])}))),function(e){return c.apply(this,arguments)})},{key:"fetchFile",value:(a=se(ie().mark((function e(t,r){var n,a,o,s,c,u,f,l,d,h,p,m,y,g,v,b,w=this,E=arguments;return ie().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=(n=E.length>2&&void 0!==E[2]?E[2]:{}).offsets,o=n.useSharedArrayBuffer,s=void 0!==o&&o,c=n.fetchType,u=void 0===c?V.Enums.FetchType.API_OPTIMIZED:c,f=u===i.BYTES_OPTIMIZED,!(l=this.fileManager.get(t,f?void 0:a))){e.next=5;break}return e.abrupt("return",new Promise((function(e,t){try{e(l.buffer)}catch(e){t(e)}})));case 5:return d=this.getOptions(),h=d.maxWorkerFetchSize,p=N(),m=V.worker,y=m.FILE_STREAMING_WORKER_NAME,g=m.FILE_PARTIAL_WORKER_NAME,v=m.THRESHOLD,this.filePromises[t]?b=this.filePromises[t]:(b=new Promise((function(e,n){if(w.fileManager.getTotalSize()+v>h)throw new Error("CodDicomWebServer.ts: Maximum size(".concat(h,") for fetching files reached"));var i=V.Enums.FetchType;if(u===i.API_OPTIMIZED){var o=function(e){if(e instanceof ErrorEvent)throw n(e.error),e.error;var r=e.data,a=r.url,i=r.position,s=r.fileArraybuffer;a===t&&s&&(w.fileManager.set(a,{data:s,position:i}),p.removeEventListener(y,"message",o))};p.addEventListener(y,"message",o),p.executeTask(y,"stream",{url:t,headers:r,useSharedArrayBuffer:s}).then((function(){e()})).catch((function(e){p.removeEventListener(y,"message",o),n(e)})).then((function(){return delete w.filePromises[t]}))}else if(u===i.BYTES_OPTIMIZED&&a){var c=a.startByte,f=a.endByte;r.Range="bytes=".concat(c,"-").concat(f-1);var l=t.split("?bytes=")[0];p.executeTask(g,"partial",{url:l,headers:r,useSharedArrayBuffer:s}).then((function(r){r?(w.fileManager.set(t,{data:new Uint8Array(r),position:r.byteLength}),e()):n(new Error("File - ".concat(l," not found")))})).catch((function(e){n(e)})).then((function(){return delete w.filePromises[t]}))}else n(new Error("CodDicomWebServer.ts: Offsets is needed in bytes optimized fetching"))})),this.filePromises[t]=b),e.abrupt("return",new Promise((function(e,r){var n=!1,i=function(i){if(i instanceof ErrorEvent)throw r(i.message),i.error;var o=i.data,s=o.url,c=o.position,u=o.chunk;if(o.isAppending&&(u?w.fileManager.append(s,u,c):w.fileManager.setPosition(s,c)),!n&&s===t&&a&&c>a.endByte)try{var f=w.fileManager.get(s,a);n=!0,e(null==f?void 0:f.buffer)}catch(e){r(e)}};a&&!f&&p.addEventListener(y,"message",i),b.then((function(){if(!n){var r=w.fileManager.get(t,f?void 0:a);n=!0,e(null==r?void 0:r.buffer)}})).catch((function(e){r(e)})).then((function(){p.removeEventListener(y,"message",i)}))})));case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"delete",value:function(e){var t=this,r=this.seriesUidFileUrls[e];r&&r.forEach((function(e){t.fileManager.remove(e)})),delete this.seriesUidFileUrls[e]}},{key:"deleteAll",value:function(){var e=this;Object.values(this.seriesUidFileUrls).forEach((function(t){t.forEach((function(t){e.fileManager.remove(t)}))})),this.seriesUidFileUrls={}}},{key:"parseMetadata",value:function(e,t,r){var n;return t===o.INSTANCE_METADATA?null===(n=Object.values(e.cod.instances).find((function(e){var t;return(null===(t=e.metadata["00080018"])||void 0===t||null===(t=t.Value)||void 0===t?void 0:t[0])===r})))||void 0===n?void 0:n.metadata:Object.values(e.cod.instances).map((function(e){return e.metadata}))}}],t&&ce(e.prototype,t),n&&ce(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,a,c}();const de=le,he={FetchType:i,CodDicomWebServer:le}})(),n})()));
|
|
21
21
|
//# sourceMappingURL=main.js.map
|