dicomweb-proxy
Version:
A proxy to translate between dicomweb and dimse
3 lines • 6.9 kB
JavaScript
/*! For license information please see histogram-worker.bundle.61c0dfaa28db555020a6.js.LICENSE.txt */
(()=>{var e,n,t={57153:(e,n,t)=>{"use strict";const r=Symbol("Comlink.proxy"),a=Symbol("Comlink.endpoint"),i=Symbol("Comlink.releaseProxy"),o=Symbol("Comlink.finalizer"),s=Symbol("Comlink.thrown"),c=e=>"object"==typeof e&&null!==e||"function"==typeof e,u={canHandle:e=>c(e)&&e[r],serialize(e){const{port1:n,port2:t}=new MessageChannel;return f(e,n),[t,[t]]},deserialize(e){return e.start(),b(e,[],n);var n}},l=new Map([["proxy",u],["throw",{canHandle:e=>c(e)&&s in e,serialize({value:e}){let n;return n=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[n,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function f(e,n=globalThis,t=["*"]){n.addEventListener("message",(function a(i){if(!i||!i.data)return;if(!function(e,n){for(const t of e){if(n===t||"*"===t)return!0;if(t instanceof RegExp&&t.test(n))return!0}return!1}(t,i.origin))return void console.warn(`Invalid origin '${i.origin}' for comlink proxy`);const{id:c,type:u,path:l}=Object.assign({path:[]},i.data),m=(i.data.argumentList||[]).map(E);let d;try{const n=l.slice(0,-1).reduce(((e,n)=>e[n]),e),t=l.reduce(((e,n)=>e[n]),e);switch(u){case"GET":d=t;break;case"SET":n[l.slice(-1)[0]]=E(i.data.value),d=!0;break;case"APPLY":d=t.apply(n,m);break;case"CONSTRUCT":d=function(e){return Object.assign(e,{[r]:!0})}(new t(...m));break;case"ENDPOINT":{const{port1:n,port2:t}=new MessageChannel;f(e,t),d=function(e,n){return y.set(e,n),e}(n,[n])}break;case"RELEASE":d=void 0;break;default:return}}catch(e){d={value:e,[s]:0}}Promise.resolve(d).catch((e=>({value:e,[s]:0}))).then((t=>{const[r,i]=w(t);n.postMessage(Object.assign(Object.assign({},r),{id:c}),i),"RELEASE"===u&&(n.removeEventListener("message",a),p(n),o in e&&"function"==typeof e[o]&&e[o]())})).catch((e=>{const[t,r]=w({value:new TypeError("Unserializable return value"),[s]:0});n.postMessage(Object.assign(Object.assign({},t),{id:c}),r)}))})),n.start&&n.start()}function p(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function m(e){if(e)throw new Error("Proxy has been released and is not useable")}function d(e){return x(e,{type:"RELEASE"}).then((()=>{p(e)}))}const g=new WeakMap,h="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const n=(g.get(e)||0)-1;g.set(e,n),0===n&&d(e)}));function b(e,n=[],t=function(){}){let r=!1;const o=new Proxy(t,{get(t,a){if(m(r),a===i)return()=>{!function(e){h&&h.unregister(e)}(o),d(e),r=!0};if("then"===a){if(0===n.length)return{then:()=>o};const t=x(e,{type:"GET",path:n.map((e=>e.toString()))}).then(E);return t.then.bind(t)}return b(e,[...n,a])},set(t,a,i){m(r);const[o,s]=w(i);return x(e,{type:"SET",path:[...n,a].map((e=>e.toString())),value:o},s).then(E)},apply(t,i,o){m(r);const s=n[n.length-1];if(s===a)return x(e,{type:"ENDPOINT"}).then(E);if("bind"===s)return b(e,n.slice(0,-1));const[c,u]=v(o);return x(e,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:c},u).then(E)},construct(t,a){m(r);const[i,o]=v(a);return x(e,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:i},o).then(E)}});return function(e,n){const t=(g.get(n)||0)+1;g.set(n,t),h&&h.register(e,n,e)}(o,e),o}function v(e){const n=e.map(w);return[n.map((e=>e[0])),(t=n.map((e=>e[1])),Array.prototype.concat.apply([],t))];var t}const y=new WeakMap;function w(e){for(const[n,t]of l)if(t.canHandle(e)){const[r,a]=t.serialize(e);return[{type:"HANDLER",name:n,value:r},a]}return[{type:"RAW",value:e},y.get(e)||[]]}function E(e){switch(e.type){case"HANDLER":return l.get(e.name).deserialize(e.value);case"RAW":return e.value}}function x(e,n,t){return new Promise((r=>{const a=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");e.addEventListener("message",(function n(t){t.data&&t.data.id&&t.data.id===a&&(e.removeEventListener("message",n),r(t.data))})),e.start&&e.start(),e.postMessage(Object.assign({id:a},n),t)}))}var O=t(58498),S=t(42008);f({getRange:({dimensions:e,origin:n,direction:t,spacing:r,scalarData:a})=>{const i=O.Ay.newInstance();i.setDimensions(e),i.setOrigin(n),i.setDirection(t),i.setSpacing(r);const o=S.Ay.newInstance({name:"Pixels",numberOfComponents:1,values:a});i.getPointData().setScalars(o),i.modified();return i.computeHistogram(i.getBounds())},calcHistogram:({data:e,options:n})=>{void 0===n&&(n={});const t={numBins:n.numBins||256,range:{min:0,max:0},bins:new Int32Array(1),maxBin:0,maxBinValue:0};let r=n.min,a=n.max;if(void 0===r||void 0===a){let n=1/0,t=-1/0,i=e.length;for(;i--;){const r=e[i];r<n&&(n=r),r>t&&(t=r)}r=n,a=t}t.range={min:r,max:a};const i=new Int32Array(t.numBins),o=t.numBins/(a-r);for(let n=0;n<e.length;n++){const t=e[n];if(t<r)continue;if(t>a)continue;i[Math.floor((t-r)*o)]+=1}t.bins=i,t.maxBin=0,t.maxBinValue=0;for(let e=0;e<t.numBins;e++)t.bins[e]>t.maxBinValue&&(t.maxBin=e,t.maxBinValue=t.bins[e]);return t}})},89288:()=>{}},r={};function a(e){var n=r[e];if(void 0!==n)return n.exports;var i=r[e]={id:e,loaded:!1,exports:{}};return t[e].call(i.exports,i,i.exports,a),i.loaded=!0,i.exports}a.m=t,a.x=()=>{var e=a.O(void 0,[573,9742],(()=>a(57153)));return e=a.O(e)},a.amdD=function(){throw new Error("define cannot be used indirect")},a.amdO={},e=[],a.O=(n,t,r,i)=>{if(!t){var o=1/0;for(l=0;l<e.length;l++){t=e[l][0],r=e[l][1],i=e[l][2];for(var s=!0,c=0;c<t.length;c++)(!1&i||o>=i)&&Object.keys(a.O).every((e=>a.O[e](t[c])))?t.splice(c--,1):(s=!1,i<o&&(o=i));if(s){e.splice(l--,1);var u=r();void 0!==u&&(n=u)}}return n}i=i||0;for(var l=e.length;l>0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[t,r,i]},a.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return a.d(n,{a:n}),n},a.d=(e,n)=>{for(var t in n)a.o(n,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce(((n,t)=>(a.f[t](e,n),n)),[])),a.u=e=>e+".bundle."+{573:"e9182fe16a8f12c93a19",9742:"8aca46da38bdee7b0b56"}[e]+".js",a.miniCssF=e=>{},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),a.p="/",(()=>{var e={3054:1,3694:1,572:1};a.f.i=(n,t)=>{e[n]||importScripts(a.p+a.u(n))};var n=self.webpackChunk=self.webpackChunk||[],t=n.push.bind(n);n.push=n=>{var r=n[0],i=n[1],o=n[2];for(var s in i)a.o(i,s)&&(a.m[s]=i[s]);for(o&&o(a);r.length;)e[r.pop()]=1;t(n)}})(),n=a.x,a.x=()=>Promise.all([a.e(573),a.e(9742)]).then(n);a.x()})();
//# sourceMappingURL=histogram-worker.bundle.61c0dfaa28db555020a6.js.map