UNPKG

dwv

Version:
1 lines 609 kB
import{default as e}from"konva";import{default as t}from"magic-wand-tool";import{default as n}from"jszip";var i={m:{},d:function(e,t){for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},u:function(e){return"assets/workers/"+{112:"jpegloss.worker",201:"resampling.worker",326:"rle.worker",391:"labeling.worker",557:"jpeg2000.worker",968:"jpegbaseline.worker"}[e]+".min.js"},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}};(function(){var e;if("string"==typeof import.meta.url&&(e=import.meta.url),!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=e})(),i.b="undefined"!=typeof document&&document.baseURI||self.location.href;class o{#e;constructor(e){if(!e||void 0===e)throw new Error("Cannot create index with no values.");if(0===e.length)throw new Error("Cannot create index with empty values.");if(!e.every((function(e){return!isNaN(e)})))throw new Error("Cannot create index with non number values.");this.#e=e}get(e){return this.#e[e]}length(){return this.#e.length}toString(){return"("+this.#e.toString()+")"}getValues(){return this.#e.slice()}canCompare(e){return!!e&&this.length()===e.length()}equals(e){if(!this.canCompare(e))return!1;for(let t=0,n=this.length();t<n;++t)if(this.get(t)!==e.get(t))return!1;return!0}compare(e){if(!this.canCompare(e))return null;const t=[];for(let n=0,i=this.length();n<i;++n)this.get(n)!==e.get(n)&&t.push(n);return t}add(e){if(!this.canCompare(e))return null;const t=[];for(let n=0,i=this.length();n<i;++n)t.push(this.get(n)+e.get(n));return new o(t)}#t(e,t){const n=this.#e.slice();return e<n.length?n[e]+=t:console.warn("Cannot add to given dimension: ",e,n.length),new o(n)}next(e){return this.#t(e,1)}previous(e){return this.#t(e,-1)}getWithNew2D(e,t){const n=[e,t];for(let e=2,t=this.length();e<t;++e)n.push(this.get(e));return new o(n)}}class r{#n;#i;#o;#r;constructor(e,t){if(this.#n=e,this.#i=e.isID(),this.#o=Math.pow(2,t),!this.#i){this.#r=new Float32Array(this.#o);for(let e=0;e<this.#o;++e)this.#r[e]=this.#n.apply(e)}}getRSI(){return this.#n}getLength(){return this.#o}getValue(e){return this.#i?e:this.#r[e]}}class a{#a;#s;#r;#l=0;#c=!0;constructor(e,t,n){if(this.#a=e,t){const e=this.#a.getLength();this.#l=e/2}else this.#l=0;this.#c=n}getVoiLut(){return this.#s}getModalityLut(){return this.#a}setVoiLut(e){if(this.#s=e,this.#s.setSignedOffset(this.#a.getRSI().getSlope()*this.#l),this.#c){const e=this.#a.getLength();this.#r=new Uint8ClampedArray(e);for(let t=0;t<e;++t)this.#r[t]=this.#s.apply(this.#a.getValue(t))}}getValue(e){return this.#c?this.#r[e+this.#l]:Math.floor(this.#s.apply(e+this.#l))}}function s(e){const t=[];for(let n=0;n<256;++n)t.push(e(n));return t}function l(e){return e}function c(e){return 255-e}class u{red;green;blue;constructor(e,t,n){this.red=e,this.green=t,this.blue=n}}const d={plain:{red:s(l),green:s(l),blue:s(l)},invPlain:{red:s(c),green:s(c),blue:s(c)},rainbow:{blue:[0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,255,247,239,231,223,215,207,199,191,183,175,167,159,151,143,135,127,119,111,103,95,87,79,71,63,55,47,39,31,23,15,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,251,249,247,245,243,241,239,237,235,233,231,229,227,225,223,221,219,217,215,213,211,209,207,205,203,201,199,197,195,193,192,189,186,183,180,177,174,171,168,165,162,159,156,153,150,147,144,141,138,135,132,129,126,123,120,117,114,111,108,105,102,99,96,93,90,87,84,81,78,75,72,69,66,63,60,57,54,51,48,45,42,39,36,33,30,27,24,21,18,15,12,9,6,3],red:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,62,60,58,56,54,52,50,48,46,44,42,40,38,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]},hot:{red:s((function(e){const t=3*e;return t>255?255:t})),green:s((function(e){const t=256/3;let n=0;return e>=t&&(n=3*(e-t),n>255)?255:n})),blue:s((function(e){const t=256/3;let n=0;return e>=2*t&&(n=3*(e-2*t),n>255)?255:n}))},hot_iron:{red:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,255],blue:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,255]},pet:{red:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243,245,247,249,251,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,128,126,124,122,120,118,116,114,112,110,108,106,104,102,100,98,96,94,92,90,88,86,84,82,80,78,76,74,72,70,68,66,64,63,61,59,57,55,53,51,49,47,45,43,41,39,37,35,33,31,29,27,25,23,21,19,17,15,13,11,9,7,5,3,1,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,255],blue:[0,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243,245,247,249,251,253,255,252,248,244,240,236,232,228,224,220,216,212,208,204,200,196,192,188,184,180,176,172,168,164,160,156,152,148,144,140,136,132,128,124,120,116,112,108,104,100,96,92,88,84,80,76,72,68,64,60,56,52,48,44,40,36,32,28,24,20,16,12,8,4,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,85,89,93,97,101,105,109,113,117,121,125,129,133,137,141,145,149,153,157,161,165,170,174,178,182,186,190,194,198,202,206,210,214,218,222,226,230,234,238,242,246,250,255]},hot_metal_blue:{red:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,6,9,12,15,18,21,24,26,29,32,35,38,41,44,47,50,52,55,57,59,62,64,66,69,71,74,76,78,81,83,85,88,90,93,96,99,102,105,108,111,114,116,119,122,125,128,131,134,137,140,143,146,149,152,155,158,161,164,166,169,172,175,178,181,184,187,190,194,198,201,205,209,213,217,221,224,228,232,236,240,244,247,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,6,8,9,11,13,15,17,19,21,23,24,26,28,30,32,34,36,38,40,41,43,45,47,49,51,53,55,56,58,60,62,64,66,68,70,72,73,75,77,79,81,83,85,87,88,90,92,94,96,98,100,102,104,105,107,109,111,113,115,117,119,120,122,124,126,128,130,132,134,136,137,139,141,143,145,147,149,151,152,154,156,158,160,162,164,166,168,169,171,173,175,177,179,181,183,184,186,188,190,192,194,196,198,200,201,203,205,207,209,211,213,215,216,218,220,222,224,226,228,229,231,233,235,237,239,240,242,244,246,248,250,251,253,255],blue:[0,2,4,6,8,10,12,14,16,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,184,186,188,190,192,194,196,198,200,197,194,191,188,185,182,179,176,174,171,168,165,162,159,156,153,150,144,138,132,126,121,115,109,103,97,91,85,79,74,68,62,56,50,47,44,41,38,35,32,29,26,24,21,18,15,12,9,6,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,6,9,12,15,18,21,24,26,29,32,35,38,41,44,47,50,53,56,59,62,65,68,71,74,76,79,82,85,88,91,94,97,100,103,106,109,112,115,118,121,124,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,176,179,182,185,188,191,194,197,200,203,206,210,213,216,219,223,226,229,232,236,239,242,245,249,252,255]},pet_20step:{red:[0,0,0,0,0,0,0,0,0,0,0,0,0,96,96,96,96,96,96,96,96,96,96,96,96,96,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,96,96,96,96,96,96,96,96,96,96,96,96,96,112,112,112,112,112,112,112,112,112,112,112,112,112,128,128,128,128,128,128,128,128,128,128,128,128,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,64,64,64,64,64,64,64,64,64,64,64,64,224,224,224,224,224,224,224,224,224,224,224,224,224,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192,192,192,192,192,176,176,176,176,176,176,176,176,176,176,176,176,176,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],green:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,96,96,96,96,96,96,96,96,96,96,96,96,96,112,112,112,112,112,112,112,112,112,112,112,112,112,128,128,128,128,128,128,128,128,128,128,128,128,96,96,96,96,96,96,96,96,96,96,96,96,96,144,144,144,144,144,144,144,144,144,144,144,144,144,192,192,192,192,192,192,192,192,192,192,192,192,192,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,224,208,208,208,208,208,208,208,208,208,208,208,208,208,176,176,176,176,176,176,176,176,176,176,176,176,176,144,144,144,144,144,144,144,144,144,144,144,144,96,96,96,96,96,96,96,96,96,96,96,96,96,48,48,48,48,48,48,48,48,48,48,48,48,48,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255],blue:[0,0,0,0,0,0,0,0,0,0,0,0,0,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,112,112,112,112,112,112,112,112,112,112,112,112,128,128,128,128,128,128,128,128,128,128,128,128,128,176,176,176,176,176,176,176,176,176,176,176,176,176,192,192,192,192,192,192,192,192,192,192,192,192,192,224,224,224,224,224,224,224,224,224,224,224,224,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,80,80,80,80,80,80,80,80,80,80,80,80,80,64,64,64,64,64,64,64,64,64,64,64,64,80,80,80,80,80,80,80,80,80,80,80,80,80,96,96,96,96,96,96,96,96,96,96,96,96,96,64,64,64,64,64,64,64,64,64,64,64,64,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255]}},h={levels:{TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4},level:3,trace:function(e){this.level<=this.levels.TRACE&&console.trace(e)},debug:function(e){this.level<=this.levels.DEBUG&&console.debug(e)},info:function(e){this.level<=this.levels.INFO&&console.info(e)},warn:function(e){this.level<=this.levels.WARN&&console.warn(e)},error:function(e){this.level<=this.levels.ERROR&&console.error(e)}},g={linear:"LINEAR",linear_exact:"LINEAR_EXACT",sigmoid:"SIGMOID"};class S{#u;#d;#h=0;#g=255;#S;#m;constructor(e,t,n){void 0===n&&(n=!1);let i=e,o=t;n||(i-=.5,o-=1),this.#u=i-o/2,this.#d=i+o/2,this.#S=(this.#g-this.#h)/o,this.#m=(-i/o+.5)*(this.#g-this.#h)+this.#h}getY(e){let t;return t=e<=this.#u?this.#h:e>this.#d?this.#g:e*this.#S+this.#m,t}}class m{#h=0;#g=255;#p;#f;constructor(e,t){this.#p=e,this.#f=t}getY(e){return(this.#g-this.#h)/(1+Math.exp(-4*(e-this.#p)/this.#f))+this.#h}}class p{#v;#D=0;#y;#C=g.linear;constructor(e,t){if(this.#v=e,void 0!==t){const e=[];for(const t in g)e.push(g[t]);e.includes(t)?this.#C=t:h.debug("Unknown VOI LUT function: "+t)}this.#I()}getWindowLevel(){return this.#v}#I(){const e=this.#v.center,t=this.#v.width,n=e+this.#D;this.#C===g.linear_exact?this.#y=new S(n,t,!0):this.#C===g.sigmoid?this.#y=new m(n,t):this.#y=new S(n,t)}setSignedOffset(e){this.#D=e,this.#I()}apply(e){return this.#y.getY(e)}}class f{center;width;constructor(e,t){this.center=e,this.width=t}}function v(e,t){return null!=e&&null!=t&&e.center===t.center&&e.width===t.width}function D(e,t,n){if(void 0===e)return;let i=e.center;i=Math.min(i,t.max),i=Math.max(i,t.min);let o=1;void 0===n||n!==g.linear_exact&&n!==g.sigmoid||(o=0);let r=e.width;return r=Math.max(r,o),r=Math.min(r,t.max-t.min),new f(i,r)}class y{r;g;b;constructor(e,t,n){this.r=e,this.g=t,this.b=n}}function C(e,t){return null!==e&&null!==t&&void 0!==e&&void 0!==t&&e.r===t.r&&e.g===t.g&&e.b===t.b}function I(e){return{r:parseInt(e.substring(1,3),16),g:parseInt(e.substring(3,5),16),b:parseInt(e.substring(5,7),16)}}function T(e){return"#"+((1<<24)+(e.r<<16)+(e.g<<8)+e.b).toString(16).slice(1)}function w(e){return{l:655.35*e.l,a:257*e.a+32896,b:257*e.b+32896}}const L={x:95.0489,y:100,z:108.884};function P(e){return function(e){function t(e){let t=null;return t=e>.008856452?Math.pow(e,.333333333):7.787037037*e+.137931034,t}const n=L,i=t(e.y/n.y);return{l:116*i-16,a:500*(t(e.x/n.x)-i),b:200*(i-t(e.z/n.z))}}(function(e){function t(e){let t=null;return t=e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),t}const n=t(e.r/255),i=t(e.g/255),o=t(e.b/255);return{x:100*(.4124*n+.3576*i+.1805*o),y:100*(.2126*n+.7152*i+.0722*o),z:100*(.0193*n+.1192*i+.9505*o)}}(e))}function O(e){const t={Yellow:"#ffff00",Red:"#ff0000",White:"#ffffff",Green:"#008000",Blue:"#0000ff",Lime:"#00ff00",Fuchsia:"#ff00ff",Black:"#000000"};let n="#ffff00";return void 0!==t[e]&&(n=t[e]),n}const b={wlPresets:void 0,labelTexts:void 0,privateBValueRules:void 0,openRoiDialog:void 0,getVolumeIdTagValue:void 0,getPostLoadVolumeIdTagValue:void 0,getTagPixelUnit:void 0},A={CT:{mediastinum:new f(40,400),lung:new f(-500,1500),bone:new f(500,2e3),brain:new f(40,80),head:new f(90,350)}};class x{create(e,t){const n=new Z(t);"MONOCHROME1"===t.getPhotometricInterpretation()&&n.setColourMap("invPlain");let i={};void 0!==t.getMeta().windowPresets&&(i=t.getMeta().windowPresets),i.minmax={name:"minmax"};const o=t.getMeta().Modality;let r;r=void 0!==b.wlPresets&&void 0!==b.wlPresets[o]?b.wlPresets[o]:A[o];for(const e in r){const t=r[e];i[e]={wl:[new f(t.center,t.width)],name:e}}return n.setWindowPresets(i),n}}class R{#T;#w;#L;constructor(e,t,n){this.#T=e,this.#w=t,this.#L=n}getX(){return this.#T}getY(){return this.#w}getZ(){return this.#L}equals(e){return null!==e&&this.#T===e.getX()&&this.#w===e.getY()&&this.#L===e.getZ()}toString(){return"("+this.#T+", "+this.#w+", "+this.#L+")"}norm(){return Math.sqrt(this.#T*this.#T+this.#w*this.#w+this.#L*this.#L)}crossProduct(e){return new R(this.#w*e.getZ()-e.getY()*this.#L,this.#L*e.getX()-e.getZ()*this.#T,this.#T*e.getY()-e.getX()*this.#w)}dotProduct(e){return this.#T*e.getX()+this.#w*e.getY()+this.#L*e.getZ()}isCodirectional(e){return this.dotProduct(e)>0}}class F{#T;#w;constructor(e,t){this.#T=e,this.#w=t}getX(){return this.#T}getY(){return this.#w}getValues(){return[this.#T,this.#w]}getCentroid(){return this}equals(e){return null!=e&&this.#T===e.getX()&&this.#w===e.getY()}toString(){return"("+this.#T+", "+this.#w+")"}getDistance(e){const t=this.#T-e.getX(),n=this.#w-e.getY();return Math.sqrt(t*t+n*n)}}class E{#T;#w;#L;constructor(e,t,n){this.#T=e,this.#w=t,this.#L=n}getX(){return this.#T}getY(){return this.#w}getZ(){return this.#L}getValues(){return[this.#T,this.#w,this.#L]}equals(e){return null!==e&&this.#T===e.getX()&&this.#w===e.getY()&&this.#L===e.getZ()}isSimilar(e,t){return null!==e&&U(this.#T,e.getX(),t)&&U(this.#w,e.getY(),t)&&U(this.#L,e.getZ(),t)}toString(){return"("+this.#T+", "+this.#w+", "+this.#L+")"}getDistance(e){return Math.sqrt(this.#P(e))}#P(e){const t=this.#T-e.getX(),n=this.#w-e.getY(),i=this.#L-e.getZ();return t*t+n*n+i*i}getClosest(e){let t=0,n=this.#P(e[t]);for(let i=0;i<e.length;++i){const o=this.#P(e[i]);o<n&&(t=i,n=o)}return t}minus(e){return new R(this.#T-e.getX(),this.#w-e.getY(),this.#L-e.getZ())}}class q{#e;constructor(e){if(!e||void 0===e)throw new Error("Cannot create point with no values.");if(0===e.length)throw new Error("Cannot create point with empty values.");if(!e.every((function(e){return!isNaN(e)})))throw new Error("Cannot create point with non number values.");this.#e=e}get(e){return this.#e[e]}length(){return this.#e.length}toString(){return"("+this.#e.toString()+")"}getValues(){return this.#e.slice()}canCompare(e){return!!e&&this.length()===e.length()}equals(e){if(!this.canCompare(e))return!1;for(let t=0,n=this.length();t<n;++t)if(this.get(t)!==e.get(t))return!1;return!0}compare(e){if(!this.canCompare(e))return null;const t=[];for(let n=0,i=this.length();n<i;++n)this.get(n)!==e.get(n)&&t.push(n);return t}get3D(){return new E(this.get(0),this.get(1),this.get(2))}add(e){if(!this.canCompare(e))return null;const t=[],n=this.getValues(),i=e.getValues();for(let e=0;e<n.length;++e)t.push(n[e]+i[e]);return new q(t)}mergeWith3D(e){const t=this.getValues();return t[0]=e.getX(),t[1]=e.getY(),t[2]=e.getZ(),new q(t)}}Number.EPSILON;const M=1e-4;function U(e,t,n){return void 0===n&&(n=Number.EPSILON),Math.abs(e-t)<n}class Q{#e;#O;constructor(e){this.#e=e}get(e,t){return this.#e[3*e+t]}getInverse(){return void 0===this.#O&&(this.#O=function(e){const t=e.get(0,0),n=e.get(0,1),i=e.get(0,2),o=e.get(1,0),r=e.get(1,1),a=e.get(1,2),s=e.get(2,0),l=e.get(2,1),c=e.get(2,2),u=r*c-a*l,d=a*s-o*c,g=o*l-r*s;let S=t*u+n*d+i*g;if(0!==S)return S=1/S,new Q([S*u,S*(i*l-n*c),S*(n*a-i*r),S*d,S*(t*c-i*s),S*(i*o-t*a),S*g,S*(n*s-t*l),S*(t*r-n*o)]);h.warn("Cannot invert 3*3 matrix with zero determinant.")}(this)),this.#O}equals(e){for(let t=0;t<3;++t)for(let n=0;n<3;++n)if(this.get(t,n)!==e.get(t,n))return!1;return!0}isSimilar(e,t){for(let n=0;n<3;++n)for(let i=0;i<3;++i)if(!U(this.get(n,i),e.get(n,i),t))return!1;return!0}toString(){let e="[";for(let t=0;t<3;++t){0!==t&&(e+=", \n ");for(let n=0;n<3;++n)0!==n&&(e+=", "),e+=this.get(t,n)}return e+="]",e}multiply(e){const t=[];for(let n=0;n<3;++n)for(let i=0;i<3;++i){let o=0;for(let t=0;t<3;++t)o+=this.get(n,t)*e.get(t,i);t.push(o)}return new Q(t)}getAbs(){const e=[];for(let t=0;t<3;++t)for(let n=0;n<3;++n)e.push(Math.abs(this.get(t,n)));return new Q(e)}multiplyArray3D(e){if(3!==e.length)throw new Error("Cannot multiply 3x3 matrix with non 3D array: "+e.length);const t=e[0],n=e[1],i=e[2],o=new Array(3);return o[0]=this.#e[0]*t+this.#e[1]*n+this.#e[2]*i,o[1]=this.#e[3]*t+this.#e[4]*n+this.#e[5]*i,o[2]=this.#e[6]*t+this.#e[7]*n+this.#e[8]*i,o}multiplyTypedArray3D(e,t){const n=e[0],i=e[1],o=e[2];t[0]=this.#e[0]*n+this.#e[1]*i+this.#e[2]*o,t[1]=this.#e[3]*n+this.#e[4]*i+this.#e[5]*o,t[2]=this.#e[6]*n+this.#e[7]*i+this.#e[8]*o}multiplyVector3D(e){const t=this.multiplyArray3D([e.getX(),e.getY(),e.getZ()]);return new R(t[0],t[1],t[2])}multiplyPoint3D(e){const t=this.multiplyArray3D([e.getX(),e.getY(),e.getZ()]);return new E(t[0],t[1],t[2])}multiplyIndex3D(e){const t=this.multiplyArray3D(e.getValues());return new o(t)}getRowAbsMax(e){const t=[Math.abs(this.get(e,0)),Math.abs(this.get(e,1)),Math.abs(this.get(e,2))],n=Math.max.apply(null,t),i=t.indexOf(n);return{value:this.get(e,i),index:i}}getColAbsMax(e){const t=[Math.abs(this.get(0,e)),Math.abs(this.get(1,e)),Math.abs(this.get(2,e))],n=Math.max.apply(null,t),i=t.indexOf(n);return{value:this.get(i,e),index:i}}asOneAndZeros(){const e=[];for(let t=0;t<3;++t){const n=this.getRowAbsMax(t),i=n.value>0?1:-1;for(let t=0;t<3;++t)t===n.index?e.push(1*i):e.push(0)}return new Q(e)}getThirdColMajorDirection(){return this.getColAbsMax(2).index}getValues(){return this.#e.slice()}}function V(){return new Q([1,0,0,0,1,0,0,0,1])}function N(e){return e.equals(V())}function B(e,t,n,i,o,r,a,s){void 0===a&&(a=!1),void 0===s&&(s=!1);let l=t;a?(r*=-1,s?l-=(o-1)*i:i*=-1):s&&(l+=(o-1)*i,i*=-1);const c=r-o*i;let u=0,d=0;return{next:function(){if(u<n){const t={value:e(l),done:!1,index:l};return l+=i,++u,++d,d===o&&(d=0,l+=c),t}return{done:!0,index:l}}}}function G(e){const t=[];let n=e.next();for(;!n.done;)t.push(n.value),n=e.next();return t}function k(e,t,n,i){const r=e.getGeometry().getSize();let a=2;i&&void 0!==i&&(a=i.getColAbsMax(2).index);const s=t.getValues(),l=new o(s.map((function(e,t){return t===a||t>2?e:0})));let c=r.indexToOffset(l);void 0===n&&(n=!1);let u=null;u=n?function(t){return e.getRescaledValueAtOffset(t)}:function(t){return e.getValueAtOffset(t)};const d=r.get(0),h=r.get(1),g=r.get(2);let S=r.getDimSize(2);const m=e.getNumberOfComponents(),p=1===e.getPlanarConfiguration(),f=function(e,t,n,i,o,r,a,s){return 1===m?B(e,t,n,i,o,r,a,s):3===m?function(e,t,n,i,o,r,a,s,l){const c=[];return l?(c.push(B(e,t,n,i,o,r,a,s)),c.push(B(e,t+n*i,n,i,o,r,a,s)),c.push(B(e,t+2*n*i,n,i,o,r,a,s))):(i*=3,r*=3,c.push(B(e,t,n,i,o,r,a,s)),c.push(B(e,t+1,n,i,o,r,a,s)),c.push(B(e,t+2,n,i,o,r,a,s))),{next:function(){const e=c[0].next(),t=c[1].next(),n=c[2].next();return e.done?{done:!0,index:n.index}:{value:[e.value,t.value,n.value],done:!1,index:[e.index,t.index,n.index]}}}}(e,3*t,n,i,o,r,a,s,p):void 0};let v=null;if(i&&void 0!==i){const e=i.getColAbsMax(0),t=i.getColAbsMax(2),n=!1,o=!1;let r=null;if(2===t.index)r=d*h,v=0===e.index?f(u,c,r,1,d,d,n,o):f(u,c,r,d,h,1,n,o);else if(0===t.index)r=g*h,v=1===e.index?f(u,c,r,d,h,S,n,o):f(u,c,r,S,g,d,n,o);else{if(1!==t.index)throw new Error("Unknown direction: "+t.index);r=g*d,v=0===e.index?f(u,c,r,1,d,S,n,o):f(u,c,r,S,g,1,n,o)}}else if(1===e.getNumberOfComponents())v=function(e,t,n,i){void 0===i&&(i=1);let o=t;return{next:function(){if(o<n){const t={value:e(o),done:!1,index:o};return o+=i,t}return{done:!0,index:n}}}}(u,c,c+S);else{if(3!==e.getNumberOfComponents())throw new Error("Unsupported number of components: "+e.getNumberOfComponents());c*=3,S*=3,v=function(e,t,n,i,o){void 0===i&&(i=1),void 0===o&&(o=!1);let r=t,a=1;o?a=(n-t)/3:i*=3;let s=r+a,l=r+2*a;return{next:function(){if(r<n){const t={value:[e(r),e(s),e(l)],done:!1,index:[r,s,l]};return r+=i,s+=i,l+=i,t}return{done:!0,index:[n]}}}}(u,c,c+S,1,p)}return v}function H(e,t){let n=0,i=0;return{next:function(){if(n<t){i+1<e.length&&n>=e[i+1].index&&++i;const t={value:e[i].value,done:!1,index:n};return++n,t}return{done:!0,index:t}}}}class z{#b={};add(e,t){void 0===this.#b[e]&&(this.#b[e]=[]),this.#b[e].push(t)}remove(e,t){if(void 0===this.#b[e])return;let n=0;for(let i=0;i<this.#b[e].length;++i)this.#b[e][i]===t&&(++n,this.#b[e].splice(i,1));0===n&&h.debug("No callback found on remove listener for type "+e)}fireEvent=e=>{if(void 0===this.#b[e.type])return;const t=this.#b[e.type].slice();for(let n=0;n<t.length;++n)t[n](e)}}class W{#S;#m;constructor(e,t){this.#S=e,this.#m=t}getSlope(){return this.#S}getIntercept(){return this.#m}apply(e){return e*this.#S+this.#m}equals(e){return null!=e&&this.getSlope()===e.getSlope()&&this.getIntercept()===e.getIntercept()}isID(){return 1===this.getSlope()&&0===this.getIntercept()}}class Y{#A=[];#x(e){return this.#A.indexOf(e)}isHidden(e){return-1!==this.#x(e)}addToHidden(e){this.isHidden(e)?h.warn("Not hidding segment, it is allready in the hidden list: "+e):this.#A.push(e)}removeFromHidden(e){const t=this.#x(e);-1!==t?this.#A.splice(t,1):h.warn("Cannot remove segment, it is not in the hidden list: "+e)}}const X=["wlchange","wlpresetadd","colourmapchange","positionchange","opacitychange","alphafuncchange","maskviewchange"];function j(e,t){return(new x).create(e,t)}class Z{#R;#F;#E;#q={minmax:{name:"minmax"}};#M;#U;#Q="plain";#V;#N;#B=.33;#G=1;#k;#H=function(e,t){return 255};#z=(e,t)=>0===e||this.#W.isHidden(e)?0:0!==this.getContourThickness()&&this.#R.getContourDistance(t,this.getOrientation())<=this.getContourThickness()?255:255*this.getFillOpacity();#W;#Y=new z;constructor(e){this.setImage(e)}getImage(){return this.#R}setImage(e){this.#R=e,void 0===this.getCurrentPosition()&&this.setCurrentIndex(this.#X(),!0),this.isMask()?(this.#W=new Y,this.#k=this.#z):(this.#k=this.#H,this.#R.addEventListener("appendframe",(()=>{const e=this.getCurrentIndex();if(3===e.length()){const t=e.getValues();t.push(0),this.setCurrentIndex(new o(t),!0)}})))}isMask(){return"SEG"===this.#R.getMeta().Modality}setMaskViewHelper(e){this.#W=e,this.#j({type:"alphafuncchange"})}getOrientation(){return this.#N}setOrientation(e){this.#N=e}getFillOpacity(){return this.#B}setFillOpacity(e){this.#B=e>1?1:e<0?0:e,this.#j({type:"maskviewchange",value:[this.#B,this.#G]})}getContourThickness(){return this.#G}setContourThickness(e){this.#G=e<0?0:e>10?10:e,this.#j({type:"maskviewchange",value:[this.#B,this.#G]})}#X(){const e=this.#R.getGeometry().getSize(),t=new Array(e.length());return t.fill(0),t[0]=Math.floor(e.get(0)/2),t[1]=Math.floor(e.get(1)/2),t[2]=Math.floor(e.get(2)/2),e.normaliseIndex(new o(t))}getPlaybackMilliseconds(e){return e||(e=10),Math.round(1e3/e)}getAlphaFunction(){return this.#k}setAlphaFunction(e){this.#k=e,this.#j({type:"alphafuncchange"})}#Z(){if(void 0!==this.#M&&void 0!==this.#q[this.#M]&&void 0!==this.#q[this.#M].perslice&&!0===this.#q[this.#M].perslice&&!this.#R.isResampled()){const e=this.getCurrentIndex();if(void 0===e)throw new Error("Cannot get window lut with no current index");const t=this.#R.getSecondaryOffset(e),n=this.#q[this.#M].wl[t];void 0!==n&&this.setWindowLevel(n,this.#M,!0)}if(void 0===this.#U&&this.setWindowLevelPresetById(0,!0),void 0===this.#E||this.#R.isConstantRSI()!==this.#E){let e,t;this.#E=this.#R.isConstantRSI(),this.#E?(e=this.#R.getRescaleSlopeAndIntercept(),t=!0):(e=new W(1,0),t=!1);const n=new r(e,this.#R.getMeta().BitsStored);this.#F=new a(n,1===this.#R.getMeta().PixelRepresentation,t)}const e=this.#F.getVoiLut();let t;if(void 0!==e&&(t=e.getWindowLevel()),void 0===e||!v(this.#U,t)){const e=new p(this.#U,this.#R.getMeta().VOILUTFunction);this.#F.setVoiLut(e)}return this.#F}getWindowPresets(){return this.#q}getWindowPresetsNames(){return Object.keys(this.#q)}setWindowPresets(e){this.#q=e}addWindowPresets(e){const t=Object.keys(e);let n=null;for(let i=0;i<t.length;++i)if(n=t[i],void 0!==this.#q[n]){if(void 0!==this.#q[n].perslice&&!0===this.#q[n].perslice)throw new Error("Cannot add perslice preset");this.#q[n]=e[n]}else this.#q[n]=e[n],this.#j({type:"wlpresetadd",name:n})}getCurrentWindowPresetName(){return this.#M}getColourMap(){return this.#Q}#_(){return d[this.#Q]}setColourMap(e){if(!d[e])throw new Error("Unknown colour map: '"+e+"'");this.#Q=e,this.#j({type:"colourmapchange",value:[e]})}getCurrentPosition(){return this.#V}getCurrentIndex(){const e=this.getCurrentPosition();if(void 0!==e)return this.getImage().getGeometry().worldToIndex(e)}getCurrentImageUid(){return this.#R.getImageUid(this.getCurrentIndex())}getOriginForImageUid(e){return this.#R.getOriginForImageUid(e)}includesImageUid(e){return this.#R.includesImageUid(e)}isPositionInBounds(e){void 0===e&&(e=this.#V);const t=this.#R.getGeometry(),n=t.worldToIndex(e),i=[this.getScrollDimIndex()];return 4===n.length()&&i.push(3),t.isIndexInBounds(n,i)}getOrigin(e){const t=this.#R.getGeometry();let n=0;return void 0!==e&&(n=t.worldToIndex(e).get(2)),t.getOrigins()[n]}setCurrentIndex(e,t){const n=this.#R.getGeometry().indexToWorld(e);return this.setCurrentPosition(n,t)}setCurrentPosition(e,t){void 0===t&&(t=!1);const n=this.#R.getGeometry(),i=n.getSize().normalisePoint(e,this.#V),o=n.worldToIndex(i),r=[this.getScrollDimIndex()];if(4===o.length()&&r.push(3),!n.isIndexInBounds(o,r))return this.#V=i,t||this.#j({type:"positionchange",value:[o.getValues(),e.getValues()],valid:!1}),!1;let a=[];const s=this.getCurrentIndex();if(void 0!==s)if(s.canCompare(o))a=s.compare(o);else{const e=Math.min(s.length(),o.length());for(let t=0;t<e;++t)s.get(t)!==o.get(t)&&a.push(t);const t=Math.max(s.length(),o.length());for(let n=e;n<t;++n)a.push(n)}else for(let e=0;e<o.length();++e)a.push(e);if(this.#V=i,!t){const t={type:"positionchange",value:[o.getValues(),e.getValues()],diffDims:a,data:{imageUid:this.#R.getImageUid(o)}};if(this.#R.canQuantify()){const e=this.#R.getRescaledValueAtIndex(o);t.value.push(e)}this.#j(t)}return!0}setWindowLevel(e,t,n){if(void 0===t&&(t="manual"),"manual"!==t&&void 0===this.#q[t])throw new Error("Unknown window level preset: '"+t+"'");void 0===n&&(n=!1);const i=D(e,this.#R.getRescaledDataRange(),this.#R.getMeta().VOILUTFunction),o=!v(i,this.#U),r=this.#M!==t;(o||r)&&(this.#U=i,this.#M=t,"manual"===t&&(void 0!==this.#q[t]?this.#q[t].wl[0]=i:this.addWindowPresets({manual:{wl:[i],name:"manual"}})),this.#j({type:"wlchange",value:[i.center,i.width,t],wc:i.center,ww:i.width,skipGenerate:n}))}getWindowLevel(){return this.#Z().getVoiLut().getWindowLevel()}setWindowLevelPreset(e,t){const n=this.getWindowPresets()[e];if(void 0===n)throw new Error("Unknown window level preset: '"+e+"'");"minmax"===e&&void 0===n.wl&&(n.wl=[this.getWindowLevelMinMax()]);let i=n.wl[0];if(void 0!==n.perslice&&!0===n.perslice&&!this.#R.isResampled()){const e=this.#R.getSecondaryOffset(this.getCurrentIndex());i=n.wl[e]}void 0!==i&&this.setWindowLevel(i,e,t)}setWindowLevelPresetById(e,t){const n=Object.keys(this.getWindowPresets());this.setWindowLevelPreset(n[e],t)}addEventListener(e,t){this.#Y.add(e,t)}removeEventListener(e,t){this.#Y.remove(e,t)}#j=e=>{this.#Y.fireEvent(e)};getWindowLevelMinMax(){const e=this.getImage().getRescaledDataRange(),t=e.max-e.min,n=e.min+t/2;return D(new f(n,t),e,this.#R.getMeta().VOILUTFunction)}setWindowLevelMinMax(){const e=this.getWindowLevelMinMax();this.setWindowLevel(e,"minmax")}generateImageData(e,t){if(void 0===t&&void 0===(t=this.getCurrentIndex()))throw new Error("Cannot generate image data with no current index");const n=this.getImage(),i=!n.isConstantRSI(),o=k(n,t,i,this.getOrientation()),r=n.getPhotometricInterpretation();switch(r){case"MONOCHROME1":case"MONOCHROME2":!function(e,t,n,i,o){let r=0,a=0,s=t.next();for(;!s.done;)a=i.getValue(s.value),e.data[r]=o.red[a],e.data[r+1]=o.green[a],e.data[r+2]=o.blue[a],e.data[r+3]=n(s.value,s.index),r+=4,s=t.next()}(e,o,this.getAlphaFunction(),this.#Z(),this.#_());break;case"PALETTE COLOR":!function(e,t,n,i,o){const r=function(e){return e>>8};o&&h.info("Scaling 16bits data to 8bits.");let a=0,s=0,l=t.next();for(;!l.done;)s=l.value,o?(e.data[a]=r(i.red[s]),e.data[a+1]=r(i.green[s]),e.data[a+2]=r(i.blue[s])):(e.data[a]=i.red[s],e.data[a+1]=i.green[s],e.data[a+2]=i.blue[s]),e.data[a+3]=n(s,l.index),a+=4,l=t.next()}(e,o,this.getAlphaFunction(),n.getPaletteColourMap(),16===n.getMeta().BitsStored);break;case"RGB":!function(e,t,n){let i=0,o=t.next();for(;!o.done;)e.data[i]=o.value[0],e.data[i+1]=o.value[1],e.data[i+2]=o.value[2],e.data[i+3]=n(o.value,o.index),i+=4,o=t.next()}(e,o,this.getAlphaFunction());break;case"YBR_FULL":!function(e,t,n){let i=0,o=null,r=t.next();for(;!r.done;)a=r.value[0],s=r.value[1],o={r:a+1.402*((l=r.value[2])-128),g:a-.34414*(s-128)-.71414*(l-128),b:a+1.772*(s-128)},e.data[i]=o.r,e.data[i+1]=o.g,e.data[i+2]=o.b,e.data[i+3]=n(r.value,r.index),i+=4,r=t.next();var a,s,l}(e,o,this.getAlphaFunction());break;default:throw new Error("Unsupported photometric interpretation: "+r)}}getScrollDimIndex(){let e=2;const t=this.getOrientation();return void 0!==t&&(e=t.getThirdColMajorDirection()),e}isAquisitionOrientation(){return N(this.#N)}}const _={t(e){let t=e;const n=e.split(".");return 2===n.length&&"unit"===n[0]&&(t={mm:"mm",cm2:"cm²",ml:"ml",degree:"°",pixel:"pixels"}[n[1]]),t}};function K(e,t,n){if(null==e||null==t)return!1;const i=n>0?0|n:0;return e.substring(i,i+t.length)===t}function J(e,t){return null!=e&&null!=t&&e.substring(e.length-t.length)===t}function $(e){const t=[];if(null==e)return t;const n=/{(\w+)}/g;let i=n.exec(e);for(;i;)t.push(i[1]),i=n.exec(e);return t}function ee(e){let t=null;if(null!=e&&"."!==e[0]){const n=e.toLowerCase().split(".");1!==n.length&&(t=n.pop(),/[a-z]/.test(t)&&!t.includes("/")||(t=null))}return t}function te(e){const t=new Uint8Array(e.length);for(let n=0,i=e.length;n<i;n++)t[n]=e.charCodeAt(n);return t}function ne(e,t){const n=Math.pow(10,t),i=.01/n;return Math.round(e*n+i)/n}function ie(e,t){if(void 0===t){t=[];for(let n=0;n<e.length;++n)t.push(n)}for(let n=0;n<t.length;++n)if(t[n]>=e.length)throw new Error("Non valid dimension for toStringId");let n="";for(let i=0;i<t.length;++i)0!==i&&(n+="_"),n+="#"+t[i]+"-"+e[t[i]];return n}function oe(e,t,n){let i=e.map(((e,i)=>function(e,t,n){return void 0===e?t:void 0===t?e:n(e,t)}(e,t[i],n)));return t.length>e.length&&(i=i.concat(t.slice(e.length))),i}function re(e,t){return null!==e&&null!==t&&void 0!==e&&void 0!==t&&ae(e.slice().sort(),t.slice().sort())}function ae(e,t){return null!==e&&null!==t&&void 0!==e&&void 0!==t&&e.length===t.length&&e.every((function(e,n){return e===t[n]}))}function se(e){return String.fromCharCode.apply(String,e)}function le(e,t,n,i){(void 0===n||n<0||n>=e.length)&&(n=0),(void 0===i||i<=n||i>e.length)&&(i=e.length);for(let o=n;o<i;++o)if(t(e[o],o,e))return o}function ce(e){return function(t,n,i){for(let t=0;t<e.length;++t)if(i[n+t]!==e[t])return!1;return!0}}function ue(e,t){const n="\r\n";let i=0;const o=[];for(let r=0;r<e.length;++r){let a="";0!==r&&(a+=n),a+="--"+t+n;const s=Object.keys(e[r]);for(let t=0;t<s.length;++t){const i=s[t];"data"!==i&&(a+=i+": "+e[r][i]+n)}a+=n;const l=te(a);o.push(l),i+=l.byteLength+e[r].data.byteLength}const r=te("\r\n--"+t+"--"+n),a=new Uint8Array(i+r.byteLength);let s=0;for(let t=0;t<e.length;++t)a.set(o[t],s),s+=o[t].byteLength,a.set(new Uint8Array(e[t].data),s),s+=e[t].data.byteLength;return a.set(r,s),a}const de={"0000":{"0000":["UL","1","CommandGroupLength"],"0001":["UL","1","CommandLengthToEnd"],"0002":["UI","1","AffectedSOPClassUID"],"0003":["UI","1","RequestedSOPClassUID"],"0010":["SH","1","CommandRecognitionCode"],"0100":["US","1","CommandField"],"0110":["US","1","MessageID"],"0120":["US","1","MessageIDBeingRespondedTo"],"0200":["AE","1","Initiator"],"0300":["AE","1","Receiver"],"0400":["AE","1","FindLocation"],"0600":["AE","1","MoveDestination"],"0700":["US","1","Priority"],"0800":["US","1","CommandDataSetType"],"0850":["US","1","NumberOfMatches"],"0860":["US","1","ResponseSequenceNumber"],"0900":["US","1","Status"],"0901":["AT","1-n","OffendingElement"],"0902":["LO","1","ErrorComment"],"0903":["US","1","ErrorID"],1e3:["UI","1","AffectedSOPInstanceUID"],1001:["UI","1","RequestedSOPInstanceUID"],1002:["US","1","EventTypeID"],1005:["AT","1-n","AttributeIdentifierList"],1008:["US","1","ActionTypeID"],1020:["US","1","NumberOfRemainingSuboperations"],1021:["US","1","NumberOfCompletedSuboperations"],1022:["US","1","NumberOfFailedSuboperations"],1023:["US","1","NumberOfWarningSuboperations"],1030:["AE","1","MoveOriginatorApplicationEntityTitle"],1031:["US","1","MoveOriginatorMessageID"],4e3:["LT","1","DialogReceiver"],4010:["LT","1","TerminalType"],5010:["SH","1","MessageSetID"],5020:["SH","1","EndMessageID"],5110:["LT","1","DisplayFormat"],5120:["LT","1","PagePositionID"],5130:["CS","1","TextFormatID"],5140:["CS","1","NormalReverse"],5150:["CS","1","AddGrayScale"],5160:["CS","1","Borders"],5170:["IS","1","Copies"],5180:["CS","1","CommandMagnificationType"],5190:["CS","1","Erase"],"51A0":["CS","1","Print"],"51B0":["US","1-n","Overlays"]},"0002":{"0000":["UL","1","FileMetaInformationGroupLength"],"0001":["OB","1","FileMetaInformationVersion"],"0002":["UI","1","MediaStorageSOPClassUID"],"0003":["UI","1","MediaStorageSOPInstanceUID"],"0010":["UI","1","TransferSyntaxUID"],"0012":["UI","1","ImplementationClassUID"],"0013":["SH","1","ImplementationVersionName"],"0016":["AE","1","SourceApplicationEntityTitle"],"0017":["AE","1","SendingApplicationEntityTitle"],"0018":["AE","1","ReceivingApplicationEntityTitle"],"0026":["UR","1","SourcePresentationAddress"],"0027":["UR","1","SendingPresentationAddress"],"0028":["UR","1","ReceivingPresentationAddress"],"0031":["OB","1","RTVMetaInformationVersion"],"0032":["UI","1","RTVCommunicationSOPClassUID"],"0033":["UI","1","RTVCommunicationSOPInstanceUID"],"0035":["OB","1","RTVSourceIdentifier"],"0036":["OB","1","RTVFlowIdentifier"],"0037":["UL","1","RTVFlowRTPSamplingRate"],"0038":["FD","1","RTVFlowActualFrameDuration"],"0100":["UI","1","PrivateInformationCreatorUID"],"0102":["OB","1","PrivateInformation"]},"0004":{"0000":["UL","1","GenericGroupLength"],1130:["CS","1","FileSetID"],1141:["CS","1-8","FileSetDescriptorFileID"],1142:["CS","1","SpecificCharacterSetOfFileSetDescriptorFile"],1200:["UL","1","OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity"],1202:["UL","1","OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity"],1212:["US","1","FileSetConsistencyFlag"],1220:["SQ","1","DirectoryRecordSequence"],1400:["UL","1","OffsetOfTheNextDirectoryRecord"],1410:["US","1","RecordInUseFlag"],1420:["UL","1","OffsetOfReferencedLowerLevelDirectoryEntity"],1430:["CS","1","DirectoryRecordType"],1432:["UI","1","PrivateRecordUID"],1500:["CS","1-8","ReferencedFileID"],1504:["UL","1","MRDRDirectoryRecordOffset"],1510:["UI","1","ReferencedSOPClassUIDInFile"],1511:["UI","1","ReferencedSOPInstanceUIDInFile"],1512:["UI","1","ReferencedTransferSyntaxUIDInFile"],"151A":["UI","1-n","ReferencedRelatedGeneralSOPClassUIDInFile"],1600:["UL","1","NumberOfReferences"]},"0008":{"0000":["UL","1","GenericGroupLength"],"0001":["UL","1","LengthToEnd"],"0005":["CS","1-n","SpecificCharacterSet"],"0006":["SQ","1","LanguageCodeSequence"],"0008":["CS","2-n","ImageType"],"0010":["SH","1","RecognitionCode"],"0012":["DA","1","InstanceCreationDate"],"0013":["TM","1","InstanceCreationTime"],"0014":["UI","1","InstanceCreatorUID"],"0015":["DT","1","InstanceCoercionDateTime"],"0016":["UI","1","SOPClassUID"],"0018":["UI","1","SOPInstanceUID"],"001A":["UI","1-n","RelatedGeneralSOPClassUID"],"001B":["UI","1","OriginalSpecializedSOPClassUID"],"0020":["DA","1","StudyDate"],"0021":["DA","1","SeriesDate"],"0022":["DA","1","AcquisitionDate"],"0023":["DA","1","ContentDate"],"0024":["DA","1","OverlayDate"],"0025":["DA","1","CurveDate"],"002A":["DT","1","AcquisitionDateTime"],"0030":["TM","1","StudyTime"],"0031":["TM","1","SeriesTime"],"0032":["TM","1","AcquisitionTime"],"0033":["TM","1","ContentTime"],"0034":["TM","1","OverlayTime"],"0035":["TM","1","CurveTime"],"0040":["US","1","DataSetType"],"0041":["LO","1","DataSetSubtype"],"0042":["CS","1","NuclearMedicineSeriesType"],"0050":["SH","1","AccessionNumber"],"0051":["SQ","1","IssuerOfAccessionNumberSequence"],"0052":["CS","1","QueryRetrieveLevel"],"0053":["CS","1","QueryRetrieveView"],"0054":["AE","1-n","RetrieveAETitle"],"0055":["AE","1","StationAETitle"],"0056":["CS","1","InstanceAvailability"],"0058":["UI","1-n","FailedSOPInstanceUIDList"],"0060":["CS","1","Modality"],"0061":["CS","1-n","ModalitiesInStudy"],"0062":["UI","1-n","SOPClassesInStudy"],"0063":["SQ","1","AnatomicRegionsInStudyCodeSequence"],"0064":["CS","1","ConversionType"],"0068":["CS","1","PresentationIntentType"],"0070":["LO","1","Manufacturer"],"0080":["LO","1","InstitutionName"],"0081":["ST","1","InstitutionAddress"],"0082":["SQ","1","InstitutionCodeSequence"],"0090":["PN","1","ReferringPhysicianName"],"0092":["ST","1","ReferringPhysicianAddress"],"0094":["SH","1-n","ReferringPhysicianTelephoneNumbers"],"0096":["SQ","1","ReferringPhysicianIdentificationSequence"],"009C":["PN","1-n","ConsultingPhysicianName"],"009D":["SQ","1","ConsultingPhysicianIdentificationSequence"],"0100":["SH","1","CodeValue"],"0101":["LO","1","ExtendedCodeValue"],"0102":["SH","1","CodingSchemeDesignator"],"0103":["SH","1","CodingSchemeVersion"],"0104":["LO","1","CodeMeaning"],"0105":["CS","1","MappingResource"],"0106":["DT","1","ContextGroupVersion"],"0107":["DT","1","ContextGroupLocalVersion"],"0108":["LT","1","ExtendedCodeMeaning"],"0109":["SQ","1","CodingSchemeResourcesSequence"],"010A":["CS","1","CodingSchemeURLType"],"010B":["CS","1","ContextGroupExtensionFlag"],"010C":["UI","1","CodingSchemeUID"],"010D":["UI","1","ContextGroupExtensionCreatorUID"],"010E":["UR","1","CodingSchemeURL"],"010F":["CS","1","ContextIdentifier"],"0110":["SQ","1","CodingSchemeIdentificationSequence"],"0112":["LO","1","CodingSchemeRegistry"],"0114":["ST","1","CodingSchemeExternalID"],"0115":["ST","1","CodingSchemeName"],"0116":["ST","1","CodingSchemeResponsibleOrganization"],"0117":["UI","1","ContextUID"],"0118":["UI","1","MappingResourceUID"],"0119":["UC","1","LongCodeValue"],"0120":["UR","1","URNCodeValue"],"0121":["SQ","1","EquivalentCodeSequence"],"0122":["LO","1","MappingResourceName"],"0123":["SQ","1","ContextGroupIdentificationSequence"],"0124":["SQ","1","MappingResourceIdentificationSequence"],"0201":["SH","1","TimezoneOffsetFromUTC"],"0202":["","",""],"0220":["SQ","1","ResponsibleGroupCodeSequence"],"0221":["CS","1","EquipmentModality"],"0222":["LO","1","ManufacturerRelatedModelGroup"],"0300":["SQ","1","PrivateDataElementCharacteristicsSequence"],"0301":["US","1","PrivateGroupReference"],"0302":["LO","1","PrivateCreatorReference"],"0303":["CS","1","BlockIdentifyingInformationStatus"],"0304":["US","1-n","NonidentifyingPrivateElements"],"0305":["SQ","1","DeidentificationActionSequence"],"0306":["US","1-n","IdentifyingPrivateElements"],"0307":["CS","1","DeidentificationAction"],"0308":["US","1","PrivateDataElement"],"0309":["UL","1-3","PrivateDataElementValueMultiplicity"],"030A":["CS","1","PrivateDataElementValueRepresentation"],"030B":["UL","1-2","PrivateDataElementNumberOfItems"],"030C":["UC","1","PrivateDataElementName"],"030D":["UC","1","PrivateDataElementKeyword"],"030E":["UT","1","PrivateDataElementDescription"],"030F":["UT","1","PrivateDataElementEncoding"],"0310":["SQ","1","PrivateDataElementDefinitionSequence"],1e3:["AE","1","NetworkID"],1010:["SH","1","StationName"],1030:["LO","1","StudyDescription"],1032:["SQ","1","ProcedureCodeSequence"],"103E":["LO","1","SeriesDescription"],"103F":["SQ","1","SeriesDescriptionCodeSequence"],1040:["LO","1","InstitutionalDepartmentName"],1041:["SQ","1","InstitutionalDepartmentTypeCodeSequence"],1048:["PN","1-n","PhysiciansOfRecord"],1049:["SQ","1","PhysiciansOfRecordIdentificationSequence"],1050:["PN","1-n","PerformingPhysicianName"],1052:["SQ","1","PerformingPhysicianIdentificationSequence"],1060:["PN","1-n","NameOfPhysiciansReadingStudy"],1062:["SQ","1","PhysiciansReadingStudyIdentificationSequence"],1070:["PN","1-n","OperatorsName"],1072:["SQ","1","OperatorIdentificationSequence"],1080:["LO","1-n","AdmittingDiagnosesDescription"],1084:["SQ","1","AdmittingDiagnosesCodeSequence"],1090:["LO","1","ManufacturerModelName"],1100:["SQ","1","ReferencedResultsSequence"],1110:["SQ","1","ReferencedStudySequence"],1111:["SQ","1","ReferencedPerformedProcedureStepSequence"],1115:["SQ","1","ReferencedSeriesSequence"],1120:["SQ","1","ReferencedPatientSequence"],1125:["SQ","1","ReferencedVisitSequence"],1130:["SQ","1","ReferencedOverlaySequence"],1134:["SQ","1","ReferencedStereometricInstanceSequence"],"113A":["SQ","1","ReferencedWaveformSequence"],1140:["SQ","1","ReferencedImageSequence"],1145:["SQ","1","ReferencedCurveSequence"],"114A":["SQ","1","ReferencedInstanceSequence"],"114B":["SQ","1","ReferencedRealWorldValueMappingInstanceSequence"],1150:["UI","1","ReferencedSOPClassUID"],1155:["UI","1","ReferencedSOPInstanceUID"],1156:["SQ","1","DefinitionSourceSequence"],"115A":["UI","1-n","SOPClassesSupported"],1160:["IS","1-n","ReferencedFrameNumber"],1161:["UL","1-n","SimpleFrameList"],1162:["UL","3-3n","CalculatedFrameList"],1163:["FD","2","TimeRange"],1164:["SQ","1","FrameExtractionSequence"],1167:["UI","1","MultiFrameSourceSOPInstanceUID"],1190:["UR","1","RetrieveURL"],1195:["UI","1","TransactionUID"],1196:["US","1","WarningReason"],1197:["US","1","FailureReason"],1198:["SQ","1","FailedSOPSequence"],1199:["SQ","1","ReferencedSOPSequence"],"119A":["SQ","1","OtherFailuresSequence"],1200:["SQ","1","StudiesContainingOtherReferencedInstancesSequence"],1250:["SQ","1","RelatedSeriesSequence"],2110:["CS","1","LossyImageCompressionRetired"],2111:["ST","1","DerivationDescription"],2112:["SQ","1","SourceImageSequence"],2120:["SH","1","StageName"],2122:["IS","1","StageNumber"],2124:["IS","1","NumberOfStages"],2127:["SH","1","ViewName"],2128:["IS","1","ViewNumber"],2129:["IS","1","NumberOfEventTimers"],"212A":["IS","1","NumberOfViewsInStage"],2130:["DS","1-n","EventElapsedTimes"],2132:["LO","1-n","EventTimerNames"],2133:["SQ","1","EventTimerSequence"],2134:["FD","1","EventTimeOffset"],2135:["SQ","1","EventCodeSequence"],2142:["IS","1","StartTrim"],2143:["IS","1","StopTrim"],2144:["IS","1","RecommendedDisplayFrameRate"],2200:["CS","1","TransducerPosition"],2204:["CS","1","TransducerOrientation"],2208:["CS","1","AnatomicStructure"],2218:["SQ","1","AnatomicRegionSequence"],2220:["SQ","1","AnatomicRegionModifierSequence"],2228:["SQ","1","PrimaryAnatomicStructureSequence"],2229:["SQ","1","AnatomicStructureSpaceOrRegionSequence"],2230:["SQ","1","PrimaryAnatomicStructureModifierSequence"],2240:["SQ","1","TransducerPositionSequence"],2242:["SQ","1","TransducerPositionModifierSequence"],2244:["SQ","1","TransducerOrientationSequence"],2246:["SQ","1","TransducerOrientationModifierSequence"],2251:["SQ","1","AnatomicStructureSpaceOrRegionCodeSequenceTrial"],2253:["SQ","1","AnatomicPortalOfEntranceCodeSequenceTrial"],2255:["SQ","1","AnatomicApproachDirectionCodeSequenceTrial"],2256:["ST","1","AnatomicPerspectiveDescriptionTrial"],2257:["SQ","1","AnatomicPerspectiveCodeSequenceTrial"