3 lines
68 KiB
JavaScript
3 lines
68 KiB
JavaScript
|
var t=function(){function t(t){this.id=t,this.adjacentVertexIds=new Set,this.color=void 0}return t.prototype.appendVertex=function(t){void 0!==t&&this.adjacentVertexIds.add(t)},t}(),e=function(){function t(t){var e=this;this.vertices=t,this.vertexLookup=new Map,this.vertices.forEach((function(t){e.vertexLookup.set(t.id,t)}))}return t.prototype.connectVertices=function(t,e){void 0!==t&&void 0!==e&&t!==e&&(this.vertexLookup.has(t)&&this.vertexLookup.get(t).appendVertex(e),this.vertexLookup.has(e)&&this.vertexLookup.get(e).appendVertex(t))},t.prototype.colorAllVertices=function(){var t=this;this.vertices.sort((function(t,e){return e.adjacentVertexIds.size-t.adjacentVertexIds.size})),this.vertices.forEach((function(e){if(e.adjacentVertexIds.size<=0)e.color=0;else{var i=t.getAdjacentVertices(e).filter((function(t){return void 0!==t.color})).map((function(t){return t.color}));e.color=t.lowestColor(i)}}))},t.prototype.getAdjacentVertices=function(t){var e=this;return Array.from(t.adjacentVertexIds).map((function(t){return e.getById(t)})).filter((function(t){return void 0!==t}))},t.prototype.getById=function(t){return this.vertices.find((function(e){return e.id===t}))},t.prototype.lowestColor=function(t){if(t.length<=0)return 0;for(var e=0;e<t.length+1;e++)if(!t.includes(e))return e},t}();function i(t,e,i){if(i||2===arguments.length)for(var a,n=0,o=e.length;n<o;n++)!a&&n in e||(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))}var a=function(){function a(t,e){var i=Math.floor(30/e);this.stepFunction=function(t){return t+i};var a=this.preprocessLayers(t);if(void 0!==a){var n=this.createPixelToSegmentMapping(a);this.areaGraph=this.buildGraph(n),this.areaGraph.colorAllVertices()}}return a.prototype.getColor=function(t){if(void 0===this.areaGraph)return 0;var e=this.areaGraph.getById(t);return e&&void 0!==e.color?e.color:0},a.prototype.preprocessLayers=function(t){var e=[],i={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0},n=t.filter((function(t){return"segment"===t.type}));if(!(n.length<=0))return n.forEach((function(t){for(var n=[],o=0;o<t.pixels.length-1;o+=2){var s={x:t.pixels[o],y:t.pixels[o+1]};a.setBoundaries(i,s),n.push(s)}void 0!==t.metaData.segmentId&&e.push({segmentId:t.metaData.segmentId,name:t.metaData.name,pixels:n})})),{boundaries:i,segments:e}},a.setBoundaries=function(t,e){e.x<t.minX&&(t.minX=e.x),e.y<t.minY&&(t.minY=e.y),e.x>t.maxX&&(t.maxX=e.x),e.y>t.maxY&&(t.maxY=e.y)},a.prototype.createPixelToSegmentMapping=function(t){var e,a,n=(e=t.boundaries.maxX+1,a=t.boundaries.maxY+1,i([],new Array(e),!0).map((function(t){return i([],new Array(a),!0)}))),o=[];return t.segments.forEach((function(t){o.push(t.segmentId),t.pixels.forEach((function(e){n[e.x][e.y]=t.segmentId}))})),{map:n,segmentIds:o,boundaries:t.boundaries}},a.prototype.buildGraph=function(i){var a=i.segmentIds.map((function(e){return new t(e)})),n=new e(a);return this.traverseMap(i.boundaries,i.map,(function(t,e,i,a){var o=a[t][e];return n.connectVertices(i,o),void 0!==o?o:i})),n},a.prototype.traverseMap=function(t,e,i){for(var a=t.minY;a<=t.maxY;a=this.stepFunction(a))for(var n=void 0,o=t.minX;o<=t.maxX;o=this.stepFunction(o))n=i(o,a,n,e);for(o=t.minX;o<=t.maxX;o=this.stepFunction(o)){var s=void 0;for(a=t.minY;a<=t.maxY;a=this.stepFunction(a))s=i(o,a,s,e)}},a}();
|
||
|
/*! pako 2.0.4 https://github.com/nodeca/pako @license (MIT AND Zlib) */function n(t){let e=t.length;for(;--e>=0;)t[e]=0}const o=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),s=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),r=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),l=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),h=new Array(576);n(h);const d=new Array(60);n(d);const c=new Array(512);n(c);const _=new Array(256);n(_);const f=new Array(29);n(f);const u=new Array(30);function p(t,e,i,a,n){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=a,this.max_length=n,this.has_stree=t&&t.length}let g,m,w;function b(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}n(u);const y=t=>t<256?c[t]:c[256+(t>>>7)],v=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},x=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<<t.bi_valid&65535,v(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=i)},k=(t,e,i)=>{x(t,i[2*e],i[2*e+1])},E=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},C=(t,e,i)=>{const a=new Array(16);let n,o,s=0;for(n=1;n<=15;n++)a[n]=s=s+i[n-1]<<1;for(o=0;o<=e;o++){let e=t[2*o+1];0!==e&&(t[2*o]=E(a[e]++,e))}},A=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},z=t=>{t.bi_valid>8?v(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},S=(t,e,i,a)=>{const n=2*e,o=2*i;return t[n]<t[o]||t[n]===t[o]&&a[e]<=a[i]},R=(t,e,i)=>{const a=t.heap[i];let n=i<<1;for(;n<=t.heap_len&&(n<t.heap_len&&S(e,t.heap[n+1],t.heap[n],t.depth)&&n++,!S(e,a,t.heap[n],t.depth));)t.heap[i]=t.heap[n],i=n,n<<=1;t.heap[i]=a},M=(t,e,i)=>{let a,n,r,l,h=0;if(0!==t.last_lit)do{a=t.pending_buf[t.d_buf+2*h]<<8|t.pending_buf[t.d_buf+2*h+1],n=t.pending_buf[t.l_buf+h],h++,0===a?k(t,n,e):(r=_[n],k(t,r+256+1,e),l=o[r],0!==l&&(n-=f[r],x(t,n,l)),a--,r=y(a),k(t,r,i),l=s[r],0!==l&&(a-=u[r],x(t,a,l)))}while(h<t.last_lit);k(t,256,e)},I=(t,e)=>{const i=e.dyn_tree,a=e.stat_desc.static_tree,n=e.stat_desc.has_stree,o=e.stat_desc.elems;let s,r,l,h=-1;for(t.heap_len=0,t.heap_max=573,s=0;s<o;s++)0!==i[2*s]?(t.heap[++t.heap_len]=h=s,t.depth[s]=0):i[2*s+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=h<2?++h:0,i[2*l]=1,t.depth[l]=0,t.opt_len--,n&&(t.static_len-=a[2*l+1]);for(e.max_code=h,s=t.heap_len>>1;s>=1;s--)R(t,i,s);l=o;do{s=t.heap[1],t.heap[1]=t.heap[t.heap_len--],R(t,i,1),r=t.heap[1],t.heap[--t.heap_max]=s,t.heap[--t.heap_max]=r,i[2*l]=i[2*s]+i[2*r],t.depth[l]=(t.depth[s]>=t.depth[r]?t.depth[s]:t.depth[r])+1,i[2*s+1]=i[2*r+1]=l,t.heap[1]=l++,R(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,a=e.max_code,n=e.stat_desc.static_tree,o=e.stat_desc.has_stree,s=e.stat_desc.extra_bits,r=e.stat_desc.extra_base,l=e.stat_desc.max_length;let h,d,c,_,f,u,p=0;for(_=0;_<=15;_++)t.bl_count[_]=0;for(i[2*t.heap[t.heap_max]+1]=0,h=t.heap_max+1;h<573;h++)d=t.heap[h],_=i[2*i[2*d+1]+1]+1,_>l&&(_=l,p++),i[2*d+1]=_,d>a||(t.bl_count[_]++,f=0,d>=r&&(f=s[d-r]),u=i[2*d],t.opt_len+=u*(_+f),o&&(t.static_len+=u*(n[2*d+1]+f)));if(0!==p){do{for(_=l-1;0===t.bl_count[_];)_--;t.bl_count[_]--,t.bl_count[_+1]+=2,t.bl_count[l]--,p-=2}while(p>0);for(_=l;0!==_;_--)for(d=t.bl_count[_];0!==d;)c=t.heap[--h],c>a||(i[2*c+1]!==_&&(t.opt_len+=(_-i[2*c+1])*i[2*c],i[2*c+1]=_),d--)}})(t,e),C(i,h,t.bl_count)},D=(t,e,i)=>{let a,n,o=-1,s=e[1],r=0,l=7,h=4;for(0===s&&(l=138,h=3),e[2*(i+1)+1]=65535,a=0;a<=i;a++)n=s,s=e[2*(a+1)+1],++r<l&&n===s||(r<h?t.bl_tree[2*n]+=r:0!==n?(n!==o&&t.bl_tree[2*n]++,t.bl_tree[32]++):r<=10?t.bl_tree[34]++:t.bl_tree[36]++,r=0,o=n,0===s?(l=138,h=3):n===s?(l=6,h=3):(l=7,h=4))},U=(t,e,i)=>{let a,n,o=-1,s=e[1],r=0,l=7,h=4;for(0===s&&(l=138,h=3),a=0;a<=i;a++)if(n=s,s=e[2*(a+1)+1],!(++r<l&&n===s)){if(r<h)do{k(t,n,t.bl_tree)}while(0!=--r);else 0!==n?(n!==o&&(k(t,n,t.bl_tree),r--),k(t,16,t.bl_tree),x(t,r-3,2)):r<=10?(
|