gralobe 1.0.8 → 1.0.9
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/dist/gralobe.js +10 -3
- package/dist/gralobe.js.map +1 -1
- package/dist/gralobe.umd.cjs +2 -2
- package/dist/gralobe.umd.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/gralobe.umd.cjs
CHANGED
|
@@ -490,7 +490,7 @@
|
|
|
490
490
|
padding-bottom: 6px;
|
|
491
491
|
border-bottom: 1px solid rgba(100, 150, 200, 0.2);
|
|
492
492
|
}
|
|
493
|
-
`,document.head.appendChild(e)}show(e){const t=this.container.querySelector(".legend-title"),i=this.container.querySelector(".legend-gradient"),n=this.container.querySelector(".legend-min"),r=this.container.querySelector(".legend-max"),s=this.container.querySelector(".legend-description");t.textContent=e.name,s.textContent=e.description;const[o,l,h]=e.colorScale;i.style.background=`linear-gradient(to right, ${o}, ${l}, ${h})`;const c=e.format??Vi(e.unit);n.textContent=c(e.domain[0]),r.textContent=c(e.domain[1]),this.container.classList.add("visible"),this.visible=!0}hide(){this.container.classList.remove("visible"),this.visible=!1}isVisible(){return this.visible}getContainer(){return this.container}dispose(){this.container.remove()}}var Aa={trailer:59};function mr(a=256){let e=0,t=new Uint8Array(a);return{get buffer(){return t.buffer},reset(){e=0},bytesView(){return t.subarray(0,e)},bytes(){return t.slice(0,e)},writeByte(n){i(e+1),t[e]=n,e++},writeBytes(n,r=0,s=n.length){i(e+s);for(let o=0;o<s;o++)t[e++]=n[o+r]},writeBytesView(n,r=0,s=n.byteLength){i(e+s),t.set(n.subarray(r,r+s),e),e+=s}};function i(n){var r=t.length;if(r>=n)return;var s=1024*1024;n=Math.max(n,r*(r<s?2:1.125)>>>0),r!=0&&(n=Math.max(n,256));let o=t;t=new Uint8Array(n),e>0&&t.set(o.subarray(0,e),0)}}var Gi=12,gr=5003,Sa=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function Ta(a,e,t,i,n=mr(512),r=new Uint8Array(256),s=new Int32Array(gr),o=new Int32Array(gr)){let l=s.length,h=Math.max(2,i);r.fill(0),o.fill(0),s.fill(-1);let c=0,u=0,p=h+1,m=p,f=!1,d=m,g=(1<<d)-1,_=1<<p-1,y=_+1,x=_+2,v=0,b=t[0],C=0;for(let w=l;w<65536;w*=2)++C;C=8-C,n.writeByte(h),P(_);let E=t.length;for(let w=1;w<E;w++)e:{let T=t[w],O=(T<<Gi)+b,S=T<<C^b;if(s[S]===O){b=o[S];break e}let R=S===0?1:l-S;for(;s[S]>=0;)if(S-=R,S<0&&(S+=l),s[S]===O){b=o[S];break e}P(b),b=T,x<1<<Gi?(o[S]=x++,s[S]=O):(s.fill(-1),x=_+2,f=!0,P(_))}return P(b),P(y),n.writeByte(0),n.bytesView();function P(w){for(c&=Sa[u],u>0?c|=w<<u:c=w,u+=d;u>=8;)r[v++]=c&255,v>=254&&(n.writeByte(v),n.writeBytesView(r,0,v),v=0),c>>=8,u-=8;if((x>g||f)&&(f?(d=m,g=(1<<d)-1,f=!1):(++d,g=d===Gi?1<<d:(1<<d)-1)),w==y){for(;u>0;)r[v++]=c&255,v>=254&&(n.writeByte(v),n.writeBytesView(r,0,v),v=0),c>>=8,u-=8;v>0&&(n.writeByte(v),n.writeBytesView(r,0,v),v=0)}}}var Da=Ta;function _r(a,e,t){return a<<8&63488|e<<2&992|t>>3}function yr(a,e,t,i){return a>>4|e&240|(t&240)<<4|(i&240)<<8}function xr(a,e,t){return a>>4<<8|e&240|t>>4}function Yt(a,e,t){return a<e?e:a>t?t:a}function Ht(a){return a*a}function br(a,e,t){var i=0,n=1e100;let r=a[e],s=r.cnt;r.ac;let o=r.rc,l=r.gc,h=r.bc;for(var c=r.fw;c!=0;c=a[c].fw){let p=a[c],m=p.cnt,f=s*m/(s+m);if(!(f>=n)){var u=0;u+=f*Ht(p.rc-o),!(u>=n)&&(u+=f*Ht(p.gc-l),!(u>=n)&&(u+=f*Ht(p.bc-h),!(u>=n)&&(n=u,i=c)))}}r.err=n,r.nn=i}function ji(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function Ma(a,e){let t=e==="rgb444"?4096:65536,i=new Array(t),n=a.length;if(e==="rgba4444")for(let r=0;r<n;++r){let s=a[r],o=s>>24&255,l=s>>16&255,h=s>>8&255,c=s&255,u=yr(c,h,l,o),p=u in i?i[u]:i[u]=ji();p.rc+=c,p.gc+=h,p.bc+=l,p.ac+=o,p.cnt++}else if(e==="rgb444")for(let r=0;r<n;++r){let s=a[r],o=s>>16&255,l=s>>8&255,h=s&255,c=xr(h,l,o),u=c in i?i[c]:i[c]=ji();u.rc+=h,u.gc+=l,u.bc+=o,u.cnt++}else for(let r=0;r<n;++r){let s=a[r],o=s>>16&255,l=s>>8&255,h=s&255,c=_r(h,l,o),u=c in i?i[c]:i[c]=ji();u.rc+=h,u.gc+=l,u.bc+=o,u.cnt++}return i}function Oa(a,e,t={}){let{format:i="rgb565",clearAlpha:n=!0,clearAlphaColor:r=0,clearAlphaThreshold:s=0,oneBitAlpha:o=!1}=t;if(!a||!a.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(a instanceof Uint8Array)&&!(a instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");let l=new Uint32Array(a.buffer),h=t.useSqrt!==!1,c=i==="rgba4444",u=Ma(l,i),p=u.length,m=p-1,f=new Uint32Array(p+1);for(var d=0,g=0;g<p;++g){let I=u[g];if(I!=null){var _=1/I.cnt;c&&(I.ac*=_),I.rc*=_,I.gc*=_,I.bc*=_,u[d++]=I}}Ht(e)/d<.022&&(h=!1);for(var g=0;g<d-1;++g)u[g].fw=g+1,u[g+1].bk=g,h&&(u[g].cnt=Math.sqrt(u[g].cnt));h&&(u[g].cnt=Math.sqrt(u[g].cnt));var y,x,v;for(g=0;g<d;++g){br(u,g);var b=u[g].err;for(x=++f[0];x>1&&(v=x>>1,!(u[y=f[v]].err<=b));x=v)f[x]=y;f[x]=g}var C=d-e;for(g=0;g<C;){for(var E;;){var P=f[1];if(E=u[P],E.tm>=E.mtm&&u[E.nn].mtm<=E.tm)break;E.mtm==m?P=f[1]=f[f[0]--]:(br(u,P),E.tm=g);var b=u[P].err;for(x=1;(v=x+x)<=f[0]&&(v<f[0]&&u[f[v]].err>u[f[v+1]].err&&v++,!(b<=u[y=f[v]].err));x=v)f[x]=y;f[x]=P}var w=u[E.nn],T=E.cnt,O=w.cnt,_=1/(T+O);c&&(E.ac=_*(T*E.ac+O*w.ac)),E.rc=_*(T*E.rc+O*w.rc),E.gc=_*(T*E.gc+O*w.gc),E.bc=_*(T*E.bc+O*w.bc),E.cnt+=w.cnt,E.mtm=++g,u[w.bk].fw=w.fw,u[w.fw].bk=w.bk,w.mtm=m}let S=[];var R=0;for(g=0;;++R){let I=Yt(Math.round(u[g].rc),0,255),G=Yt(Math.round(u[g].gc),0,255),z=Yt(Math.round(u[g].bc),0,255),F=255;c&&(F=Yt(Math.round(u[g].ac),0,255),o&&(F=F<=(typeof o=="number"?o:127)?0:255),n&&F<=s&&(I=G=z=r,F=0));let se=c?[I,G,z,F]:[I,G,z];if(Ra(S,se)||S.push(se),(g=u[g].fw)==0)break}return S}function Ra(a,e){for(let t=0;t<a.length;t++){let i=a[t],n=i[0]===e[0]&&i[1]===e[1]&&i[2]===e[2],r=i.length>=4&&e.length>=4?i[3]===e[3]:!0;if(n&&r)return!0}return!1}function Ia(a,e,t="rgb565"){if(!a||!a.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(a instanceof Uint8Array)&&!(a instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");if(e.length>256)throw new Error("applyPalette() only works with 256 colors or less");let i=new Uint32Array(a.buffer),n=i.length,r=t==="rgb444"?4096:65536,s=new Uint8Array(n),o=new Array(r);if(t==="rgba4444")for(let l=0;l<n;l++){let h=i[l],c=h>>24&255,u=h>>16&255,p=h>>8&255,m=h&255,f=yr(m,p,u,c),d=f in o?o[f]:o[f]=La(m,p,u,c,e);s[l]=d}else{let l=t==="rgb444"?xr:_r;for(let h=0;h<n;h++){let c=i[h],u=c>>16&255,p=c>>8&255,m=c&255,f=l(m,p,u),d=f in o?o[f]:o[f]=ka(m,p,u,e);s[h]=d}}return s}function La(a,e,t,i,n){let r=0,s=1e100;for(let o=0;o<n.length;o++){let l=n[o],h=l[3],c=He(h-i);if(c>s)continue;let u=l[0];if(c+=He(u-a),c>s)continue;let p=l[1];if(c+=He(p-e),c>s)continue;let m=l[2];c+=He(m-t),!(c>s)&&(s=c,r=o)}return r}function ka(a,e,t,i){let n=0,r=1e100;for(let s=0;s<i.length;s++){let o=i[s],l=o[0],h=He(l-a);if(h>r)continue;let c=o[1];if(h+=He(c-e),h>r)continue;let u=o[2];h+=He(u-t),!(h>r)&&(r=h,n=s)}return n}function He(a){return a*a}function Ua(a={}){let{initialCapacity:e=4096,auto:t=!0}=a,i=mr(e),n=5003,r=new Uint8Array(256),s=new Int32Array(n),o=new Int32Array(n),l=!1;return{reset(){i.reset(),l=!1},finish(){i.writeByte(Aa.trailer)},bytes(){return i.bytes()},bytesView(){return i.bytesView()},get buffer(){return i.buffer},get stream(){return i},writeHeader:h,writeFrame(c,u,p,m={}){let{transparent:f=!1,transparentIndex:d=0,delay:g=0,palette:_=null,repeat:y=0,colorDepth:x=8,dispose:v=-1}=m,b=!1;if(t?l||(b=!0,h(),l=!0):b=!!m.first,u=Math.max(0,Math.floor(u)),p=Math.max(0,Math.floor(p)),b){if(!_)throw new Error("First frame must include a { palette } option");Na(i,u,p,_,x),vr(i,_),y>=0&&za(i,y)}let C=Math.round(g/10);Fa(i,v,C,f,d);let E=!!_&&!b;$a(i,u,p,E?_:null),E&&vr(i,_),Ba(i,c,u,p,x,r,s,o)}};function h(){Er(i,"GIF89a")}}function Fa(a,e,t,i,n){a.writeByte(33),a.writeByte(249),a.writeByte(4),n<0&&(n=0,i=!1);var r,s;i?(r=1,s=2):(r=0,s=0),e>=0&&(s=e&7),s<<=2,a.writeByte(0|s|0|r),ke(a,t),a.writeByte(n||0),a.writeByte(0)}function Na(a,e,t,i,n=8){let r=1,s=0,o=Yi(i.length)-1,l=r<<7|n-1<<4|s<<3|o;ke(a,e),ke(a,t),a.writeBytes([l,0,0])}function za(a,e){a.writeByte(33),a.writeByte(255),a.writeByte(11),Er(a,"NETSCAPE2.0"),a.writeByte(3),a.writeByte(1),ke(a,e),a.writeByte(0)}function vr(a,e){let t=1<<Yi(e.length);for(let i=0;i<t;i++){let n=[0,0,0];i<e.length&&(n=e[i]),a.writeByte(n[0]),a.writeByte(n[1]),a.writeByte(n[2])}}function $a(a,e,t,i){if(a.writeByte(44),ke(a,0),ke(a,0),ke(a,e),ke(a,t),i){let n=0,r=0,s=Yi(i.length)-1;a.writeByte(128|n|r|0|s)}else a.writeByte(0)}function Ba(a,e,t,i,n=8,r,s,o){Da(t,i,e,n,a,r,s,o)}function ke(a,e){a.writeByte(e&255),a.writeByte(e>>8&255)}function Er(a,e){for(var t=0;t<e.length;t++)a.writeByte(e.charCodeAt(t))}function Yi(a){return Math.max(Math.ceil(Math.log2(a)),1)}class Va{renderer;scene;camera;isRecording=!1;frames=[];mediaRecorder=null;recordedChunks=[];captureCanvas;captureCtx;compositeCanvas;compositeCtx;gifWidth=480;gifHeight=270;legendElement=null;countryLabels=null;constructor(e,t,i){this.renderer=e,this.scene=t,this.camera=i,this.captureCanvas=document.createElement("canvas"),this.captureCtx=this.captureCanvas.getContext("2d",{willReadFrequently:!0}),this.compositeCanvas=document.createElement("canvas"),this.compositeCtx=this.compositeCanvas.getContext("2d")}setLegendElement(e){this.legendElement=e}setCountryLabels(e){this.countryLabels=e}drawCountryLabelsOnCanvas(e,t,i){if(this.countryLabels)try{this.countryLabels.getVisibleLabelsForCanvas(this.camera,t,i).forEach(r=>{e.save(),e.globalAlpha=r.opacity,e.font="bold 12px Arial, sans-serif",e.textAlign="center",e.textBaseline="middle",e.strokeStyle="rgba(0, 0, 0, 0.8)",e.lineWidth=3,e.strokeText(r.text,r.x,r.y),e.fillStyle="#ffffff",e.fillText(r.text,r.x,r.y),e.restore()})}catch(n){console.warn("Failed to draw country labels:",n)}}drawOverlaysOnCanvas(e,t,i){this.drawCountryLabelsOnCanvas(e,t,i),this.drawLegendOnCanvas(e,t,i)}drawLegendOnCanvas(e,t,i){try{if(!this.legendElement||!this.legendElement.classList.contains("visible"))return;const n=this.legendElement,r=n.querySelector(".legend-title"),s=n.querySelector(".legend-gradient"),o=n.querySelector(".legend-min"),l=n.querySelector(".legend-max"),h=n.querySelector(".legend-description");if(!r||!s)return;const c=280,u=100,p=20,m=t-c-p,f=i-u-p,d=12;e.fillStyle="rgba(0, 10, 20, 0.9)",e.strokeStyle="rgba(100, 170, 255, 0.5)",e.lineWidth=2,e.beginPath(),e.roundRect?e.roundRect(m,f,c,u,d):e.rect(m,f,c,u),e.fill(),e.stroke(),e.fillStyle="#44aaff",e.font="bold 18px Arial, sans-serif",e.fillText(r.textContent||"",m+16,f+28);const g=m+16,_=f+40,y=c-32,x=20,v=s.style.background||"";let b=[];const C=v.match(/rgba?\([^)]+\)/g);if(C&&C.length>=2)b=C;else{const E=v.match(/#[0-9a-fA-F]{3,8}/g);E&&E.length>=2&&(b=E)}if(b.length>=2){const E=e.createLinearGradient(g,0,g+y,0);E.addColorStop(0,b[0]),b.length>=3?(E.addColorStop(.5,b[1]),E.addColorStop(1,b[2])):E.addColorStop(1,b[1]),e.fillStyle=E,e.beginPath(),e.roundRect?e.roundRect(g,_,y,x,4):e.rect(g,_,y,x),e.fill()}else{const E=e.createLinearGradient(g,0,g+y,0);E.addColorStop(0,"#cc6600"),E.addColorStop(.5,"#ffaa44"),E.addColorStop(1,"#ffeecc"),e.fillStyle=E,e.beginPath(),e.roundRect?e.roundRect(g,_,y,x,4):e.rect(g,_,y,x),e.fill(),console.log("Legend gradient style:",v)}if(e.fillStyle="#cccccc",e.font="14px Arial, sans-serif",o&&e.fillText(o.textContent||"",g,f+78),l){const E=l.textContent||"",P=e.measureText(E).width;e.fillText(E,g+y-P,f+78)}h&&h.textContent&&(e.fillStyle="#888888",e.font="italic 12px Arial, sans-serif",e.fillText(h.textContent,g,f+95))}catch(n){console.warn("Failed to draw legend on canvas:",n)}}screenshot(e={}){const{width:t=1920,height:i=1080}=e,n=this.renderer.domElement.width,r=this.renderer.domElement.height;this.renderer.setSize(t,i),this.camera.aspect=t/i,this.camera.updateProjectionMatrix(),this.renderer.render(this.scene,this.camera),this.compositeCanvas.width=t,this.compositeCanvas.height=i,this.compositeCtx.drawImage(this.renderer.domElement,0,0),this.drawOverlaysOnCanvas(this.compositeCtx,t,i);const s=this.compositeCanvas.toDataURL("image/png");this.renderer.setSize(n,r),this.camera.aspect=n/r,this.camera.updateProjectionMatrix(),this.downloadFile(s,`globe-${Date.now()}.png`)}startVideoRecording(e={}){return new Promise(t=>{if(this.isRecording){t();return}const i=this.renderer.domElement;this.compositeCanvas.width=i.width,this.compositeCanvas.height=i.height,this.compositeCtx.drawImage(i,0,0),this.drawOverlaysOnCanvas(this.compositeCtx,this.compositeCanvas.width,this.compositeCanvas.height);const n=this.compositeCanvas.captureStream(60),r=[{mime:"video/mp4;codecs=avc1",ext:"mp4"},{mime:"video/mp4",ext:"mp4"},{mime:"video/webm;codecs=h264",ext:"webm"},{mime:"video/webm;codecs=vp9",ext:"webm"},{mime:"video/webm;codecs=vp8",ext:"webm"},{mime:"video/webm",ext:"webm"}];let s="video/webm",o="webm";for(const{mime:h,ext:c}of r)if(MediaRecorder.isTypeSupported(h)){s=h,o=c,console.log(`Video recording using: ${h}`);break}this.mediaRecorder=new MediaRecorder(n,{mimeType:s,videoBitsPerSecond:8e6}),this.recordedChunks=[];const l=o;this.mediaRecorder.ondataavailable=h=>{h.data.size>0&&this.recordedChunks.push(h.data)},this.mediaRecorder.onstop=()=>{const h=s.split(";")[0],c=new Blob(this.recordedChunks,{type:h}),u=URL.createObjectURL(c);this.downloadFile(u,`globe-${Date.now()}.${l}`),URL.revokeObjectURL(u)},this.mediaRecorder.onstart=()=>{this.isRecording=!0,setTimeout(()=>t(),50)},this.mediaRecorder.start(100)})}updateVideoFrame(){if(!this.isRecording||!this.mediaRecorder)return;const e=this.compositeCanvas.width,t=this.compositeCanvas.height;this.compositeCtx.drawImage(this.renderer.domElement,0,0,e,t),this.drawOverlaysOnCanvas(this.compositeCtx,e,t)}stopVideoRecording(){!this.isRecording||!this.mediaRecorder||(this.mediaRecorder.stop(),this.isRecording=!1)}startGifCapture(e={}){if(this.isRecording)return;this.frames=[],this.isRecording=!0;const{width:t=480,height:i=270}=e;this.gifWidth=t,this.gifHeight=i,this.captureCanvas.width=t,this.captureCanvas.height=i}captureGifFrame(){if(!this.isRecording)return;const e=this.renderer.domElement,t=this.gifWidth,i=this.gifHeight;this.captureCtx.drawImage(e,0,0,t,i),this.drawOverlaysOnCanvas(this.captureCtx,t,i);const n=this.captureCtx.getImageData(0,0,t,i);this.frames.push({data:new Uint8ClampedArray(n.data),width:t,height:i})}async stopGifCapture(e={}){if(!this.isRecording)return;if(this.isRecording=!1,this.frames.length===0){console.warn("No frames captured for GIF");return}const{fps:t=20,filename:i}=e,n=Math.round(1e3/t);console.log(`Generating GIF with ${this.frames.length} frames at ${t} fps...`);try{const r=this.frames[0],s=r.width,o=r.height,l=Oa(r.data,256),h=Ua();for(let f=0;f<this.frames.length;f++){const d=this.frames[f],g=Ia(d.data,l);h.writeFrame(g,s,o,{palette:f===0?l:void 0,delay:n,repeat:f===0?0:void 0}),f%10===0&&await new Promise(_=>setTimeout(_,0))}h.finish();const c=h.bytes(),u=new Blob([c],{type:"image/gif"}),p=URL.createObjectURL(u),m=i||`globe-${Date.now()}.gif`;this.downloadFile(p,m),setTimeout(()=>URL.revokeObjectURL(p),1e3),console.log(`GIF saved: ${m} (${this.frames.length} frames, ${(u.size/1024).toFixed(1)}KB)`)}catch(r){console.error("Failed to generate GIF:",r)}this.frames=[]}getIsRecording(){return this.isRecording}getFrameCount(){return this.frames.length}downloadFile(e,t){const i=document.createElement("a");i.href=e,i.download=t,i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}class Ga extends A.Object3D{constructor(e=document.createElement("div")){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.center=new A.Vector2(.5,.5),this.addEventListener("removed",function(){this.traverse(function(t){t.element&&t.element instanceof t.element.ownerDocument.defaultView.Element&&t.element.parentNode!==null&&t.element.remove()})})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this.center=e.center,this}}const lt=new A.Vector3,wr=new A.Matrix4,Cr=new A.Matrix4,Pr=new A.Vector3,Ar=new A.Vector3;class ja{constructor(e={}){const t=this;let i,n,r,s;const o={objects:new WeakMap},l=e.element!==void 0?e.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l,this.sortObjects=!0,this.getSize=function(){return{width:i,height:n}},this.render=function(f,d){f.matrixWorldAutoUpdate===!0&&f.updateMatrixWorld(),d.parent===null&&d.matrixWorldAutoUpdate===!0&&d.updateMatrixWorld(),wr.copy(d.matrixWorldInverse),Cr.multiplyMatrices(d.projectionMatrix,wr),c(f,f,d),this.sortObjects&&m(f)},this.setSize=function(f,d){i=f,n=d,r=i/2,s=n/2,l.style.width=f+"px",l.style.height=d+"px"};function h(f){f.isCSS2DObject&&(f.element.style.display="none");for(let d=0,g=f.children.length;d<g;d++)h(f.children[d])}function c(f,d,g){if(f.visible===!1){h(f);return}if(f.isCSS2DObject){lt.setFromMatrixPosition(f.matrixWorld),lt.applyMatrix4(Cr);const _=lt.z>=-1&<.z<=1&&f.layers.test(g.layers)===!0,y=f.element;y.style.display=_===!0?"":"none",_===!0&&(f.onBeforeRender(t,d,g),y.style.transform="translate("+-100*f.center.x+"%,"+-100*f.center.y+"%)translate("+(lt.x*r+r)+"px,"+(-lt.y*s+s)+"px)",y.parentNode!==l&&l.appendChild(y),f.onAfterRender(t,d,g));const x={distanceToCameraSquared:u(g,f)};o.objects.set(f,x)}for(let _=0,y=f.children.length;_<y;_++)c(f.children[_],d,g)}function u(f,d){return Pr.setFromMatrixPosition(f.matrixWorld),Ar.setFromMatrixPosition(d.matrixWorld),Pr.distanceToSquared(Ar)}function p(f){const d=[];return f.traverseVisible(function(g){g.isCSS2DObject&&d.push(g)}),d}function m(f){const d=p(f).sort(function(_,y){if(_.renderOrder!==y.renderOrder)return y.renderOrder-_.renderOrder;const x=o.objects.get(_).distanceToCameraSquared,v=o.objects.get(y).distanceToCameraSquared;return x-v}),g=d.length;for(let _=0,y=d.length;_<y;_++)d[_].element.style.zIndex=g-_}}}const Ya={CN:[35,105],IN:[22,78],US:[39,-98],ID:[-2,118],PK:[30,70],BR:[-10,-55],NG:[9,8],BD:[24,90],RU:[60,100],MX:[23,-102],JP:[36,138],ET:[9,38.5],PH:[12,122],EG:[27,30],VN:[16,108],DE:[51,10],TR:[39,35],IR:[32,53],TH:[15,101],GB:[54,-2],FR:[46,2],IT:[42.5,12.5],ZA:[-29,24],TZ:[-6,35],KE:[0,38],KR:[36,128],CO:[4,-72],ES:[40,-4],AR:[-34,-64],UG:[1,32],DZ:[28,3],UA:[49,32],IQ:[33,44],PL:[52,20],CA:[56,-106],MA:[32,-5],SA:[24,45],PE:[-10,-76],AU:[-25,134],MY:[4,109.5],GH:[8,-1],NP:[28,84],VE:[7,-66],MG:[-19,47],CM:[6,12],NL:[52.5,5.5],CL:[-34,-71],SE:[62,15],NO:[64,10],SG:[1.3,103.8],NZ:[-42,174],IE:[53,-8],IL:[31,35],AE:[24,54],CH:[47,8],AT:[47.5,14.5],PT:[39.5,-8],GR:[39,22],CZ:[49.8,15.5],BE:[50.8,4],HU:[47,20],FI:[64,26],DK:[56,10],IS:[65,-18],CD:[-3,22],SD:[16,30],AO:[-12.5,18.5],MZ:[-18,35],CI:[7.5,-5.5],NE:[17,10],BF:[12,-1.5],ML:[17,-4],SN:[14.5,-14.5],ZM:[-15,28],ZW:[-19,29.5],RW:[-2,30],AF:[33,65],MM:[21,96],KP:[40,127],MN:[46,105],LK:[7.8,80.8],KZ:[48,67],UZ:[41,64],CU:[22,-79.5],EC:[-1.5,-78.5],GT:[15.5,-90.3],BO:[-17,-65],HN:[15,-86.5],PY:[-23,-58],UY:[-33,-56],CR:[10,-84],PA:[9,-80]},Ha=new Set(["CN","IN","US","BR","RU","JP","DE","GB","FR","AU","CA","MX","ID","SA","ZA","EG","NG","AR","IT","ES","KR","TR","PL","NL","CH","SE","NO","PK","BD","VN"]),Za=new Set(["CN","IN","US","BR","RU","AU","CA"]),Ka=new Set(["RU","CA","US","CN","BR","AU"]),Xa=new Set(["IN","AR","KZ","DZ","CD","SA","MX","ID","SD","LY","IR","MN","PE","TD","NE","AO","ML","ZA","CO","ET","BO","MR","EG","TZ","NG","VE","PK","TR","CL","MM"]),Wa=new Set(["AF","UA","MG","MZ","FR","ES","TH","CM","PG","JP","DE","VN","MY","CI","PL","IT","PH","EC","BF","NZ","GB","GH","RO","LA","GY","OM","BY","KH","SN","UG","NO","SE","FI","MR","ZM","ZW","NP","MA","IQ","BD"]);class qa{labelRenderer;labels=[];labelGroup;currentStyle="none";sphereRadius;currentMorph=0;globe=null;camera=null;constructor(e,t){this.sphereRadius=t,this.labelRenderer=new ja,this.labelRenderer.setSize(window.innerWidth,window.innerHeight),this.labelRenderer.domElement.style.position="absolute",this.labelRenderer.domElement.style.top="0",this.labelRenderer.domElement.style.left="0",this.labelRenderer.domElement.style.pointerEvents="none",e.appendChild(this.labelRenderer.domElement),this.labelGroup=new D.Group,this.injectStyles(),this.createLabels()}injectStyles(){const e=document.createElement("style");e.textContent=`
|
|
493
|
+
`,document.head.appendChild(e)}show(e){const t=this.container.querySelector(".legend-title"),i=this.container.querySelector(".legend-gradient"),n=this.container.querySelector(".legend-min"),r=this.container.querySelector(".legend-max"),s=this.container.querySelector(".legend-description");t.textContent=e.name,s.textContent=e.description;const[o,l,h]=e.colorScale;i.style.background=`linear-gradient(to right, ${o}, ${l}, ${h})`;const c=e.format??Vi(e.unit);n.textContent=c(e.domain[0]),r.textContent=c(e.domain[1]),this.container.classList.add("visible"),this.visible=!0}hide(){this.container.classList.remove("visible"),this.visible=!1}isVisible(){return this.visible}getContainer(){return this.container}dispose(){this.container.remove()}}var Aa={trailer:59};function mr(a=256){let e=0,t=new Uint8Array(a);return{get buffer(){return t.buffer},reset(){e=0},bytesView(){return t.subarray(0,e)},bytes(){return t.slice(0,e)},writeByte(n){i(e+1),t[e]=n,e++},writeBytes(n,r=0,s=n.length){i(e+s);for(let o=0;o<s;o++)t[e++]=n[o+r]},writeBytesView(n,r=0,s=n.byteLength){i(e+s),t.set(n.subarray(r,r+s),e),e+=s}};function i(n){var r=t.length;if(r>=n)return;var s=1024*1024;n=Math.max(n,r*(r<s?2:1.125)>>>0),r!=0&&(n=Math.max(n,256));let o=t;t=new Uint8Array(n),e>0&&t.set(o.subarray(0,e),0)}}var Gi=12,gr=5003,Sa=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function Ta(a,e,t,i,n=mr(512),r=new Uint8Array(256),s=new Int32Array(gr),o=new Int32Array(gr)){let l=s.length,h=Math.max(2,i);r.fill(0),o.fill(0),s.fill(-1);let c=0,u=0,p=h+1,m=p,f=!1,d=m,g=(1<<d)-1,_=1<<p-1,y=_+1,x=_+2,v=0,b=t[0],C=0;for(let w=l;w<65536;w*=2)++C;C=8-C,n.writeByte(h),P(_);let E=t.length;for(let w=1;w<E;w++)e:{let T=t[w],O=(T<<Gi)+b,S=T<<C^b;if(s[S]===O){b=o[S];break e}let R=S===0?1:l-S;for(;s[S]>=0;)if(S-=R,S<0&&(S+=l),s[S]===O){b=o[S];break e}P(b),b=T,x<1<<Gi?(o[S]=x++,s[S]=O):(s.fill(-1),x=_+2,f=!0,P(_))}return P(b),P(y),n.writeByte(0),n.bytesView();function P(w){for(c&=Sa[u],u>0?c|=w<<u:c=w,u+=d;u>=8;)r[v++]=c&255,v>=254&&(n.writeByte(v),n.writeBytesView(r,0,v),v=0),c>>=8,u-=8;if((x>g||f)&&(f?(d=m,g=(1<<d)-1,f=!1):(++d,g=d===Gi?1<<d:(1<<d)-1)),w==y){for(;u>0;)r[v++]=c&255,v>=254&&(n.writeByte(v),n.writeBytesView(r,0,v),v=0),c>>=8,u-=8;v>0&&(n.writeByte(v),n.writeBytesView(r,0,v),v=0)}}}var Da=Ta;function _r(a,e,t){return a<<8&63488|e<<2&992|t>>3}function yr(a,e,t,i){return a>>4|e&240|(t&240)<<4|(i&240)<<8}function xr(a,e,t){return a>>4<<8|e&240|t>>4}function Yt(a,e,t){return a<e?e:a>t?t:a}function Ht(a){return a*a}function br(a,e,t){var i=0,n=1e100;let r=a[e],s=r.cnt;r.ac;let o=r.rc,l=r.gc,h=r.bc;for(var c=r.fw;c!=0;c=a[c].fw){let p=a[c],m=p.cnt,f=s*m/(s+m);if(!(f>=n)){var u=0;u+=f*Ht(p.rc-o),!(u>=n)&&(u+=f*Ht(p.gc-l),!(u>=n)&&(u+=f*Ht(p.bc-h),!(u>=n)&&(n=u,i=c)))}}r.err=n,r.nn=i}function ji(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function Ma(a,e){let t=e==="rgb444"?4096:65536,i=new Array(t),n=a.length;if(e==="rgba4444")for(let r=0;r<n;++r){let s=a[r],o=s>>24&255,l=s>>16&255,h=s>>8&255,c=s&255,u=yr(c,h,l,o),p=u in i?i[u]:i[u]=ji();p.rc+=c,p.gc+=h,p.bc+=l,p.ac+=o,p.cnt++}else if(e==="rgb444")for(let r=0;r<n;++r){let s=a[r],o=s>>16&255,l=s>>8&255,h=s&255,c=xr(h,l,o),u=c in i?i[c]:i[c]=ji();u.rc+=h,u.gc+=l,u.bc+=o,u.cnt++}else for(let r=0;r<n;++r){let s=a[r],o=s>>16&255,l=s>>8&255,h=s&255,c=_r(h,l,o),u=c in i?i[c]:i[c]=ji();u.rc+=h,u.gc+=l,u.bc+=o,u.cnt++}return i}function Oa(a,e,t={}){let{format:i="rgb565",clearAlpha:n=!0,clearAlphaColor:r=0,clearAlphaThreshold:s=0,oneBitAlpha:o=!1}=t;if(!a||!a.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(a instanceof Uint8Array)&&!(a instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");let l=new Uint32Array(a.buffer),h=t.useSqrt!==!1,c=i==="rgba4444",u=Ma(l,i),p=u.length,m=p-1,f=new Uint32Array(p+1);for(var d=0,g=0;g<p;++g){let I=u[g];if(I!=null){var _=1/I.cnt;c&&(I.ac*=_),I.rc*=_,I.gc*=_,I.bc*=_,u[d++]=I}}Ht(e)/d<.022&&(h=!1);for(var g=0;g<d-1;++g)u[g].fw=g+1,u[g+1].bk=g,h&&(u[g].cnt=Math.sqrt(u[g].cnt));h&&(u[g].cnt=Math.sqrt(u[g].cnt));var y,x,v;for(g=0;g<d;++g){br(u,g);var b=u[g].err;for(x=++f[0];x>1&&(v=x>>1,!(u[y=f[v]].err<=b));x=v)f[x]=y;f[x]=g}var C=d-e;for(g=0;g<C;){for(var E;;){var P=f[1];if(E=u[P],E.tm>=E.mtm&&u[E.nn].mtm<=E.tm)break;E.mtm==m?P=f[1]=f[f[0]--]:(br(u,P),E.tm=g);var b=u[P].err;for(x=1;(v=x+x)<=f[0]&&(v<f[0]&&u[f[v]].err>u[f[v+1]].err&&v++,!(b<=u[y=f[v]].err));x=v)f[x]=y;f[x]=P}var w=u[E.nn],T=E.cnt,O=w.cnt,_=1/(T+O);c&&(E.ac=_*(T*E.ac+O*w.ac)),E.rc=_*(T*E.rc+O*w.rc),E.gc=_*(T*E.gc+O*w.gc),E.bc=_*(T*E.bc+O*w.bc),E.cnt+=w.cnt,E.mtm=++g,u[w.bk].fw=w.fw,u[w.fw].bk=w.bk,w.mtm=m}let S=[];var R=0;for(g=0;;++R){let I=Yt(Math.round(u[g].rc),0,255),G=Yt(Math.round(u[g].gc),0,255),z=Yt(Math.round(u[g].bc),0,255),F=255;c&&(F=Yt(Math.round(u[g].ac),0,255),o&&(F=F<=(typeof o=="number"?o:127)?0:255),n&&F<=s&&(I=G=z=r,F=0));let se=c?[I,G,z,F]:[I,G,z];if(Ra(S,se)||S.push(se),(g=u[g].fw)==0)break}return S}function Ra(a,e){for(let t=0;t<a.length;t++){let i=a[t],n=i[0]===e[0]&&i[1]===e[1]&&i[2]===e[2],r=i.length>=4&&e.length>=4?i[3]===e[3]:!0;if(n&&r)return!0}return!1}function Ia(a,e,t="rgb565"){if(!a||!a.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(a instanceof Uint8Array)&&!(a instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");if(e.length>256)throw new Error("applyPalette() only works with 256 colors or less");let i=new Uint32Array(a.buffer),n=i.length,r=t==="rgb444"?4096:65536,s=new Uint8Array(n),o=new Array(r);if(t==="rgba4444")for(let l=0;l<n;l++){let h=i[l],c=h>>24&255,u=h>>16&255,p=h>>8&255,m=h&255,f=yr(m,p,u,c),d=f in o?o[f]:o[f]=La(m,p,u,c,e);s[l]=d}else{let l=t==="rgb444"?xr:_r;for(let h=0;h<n;h++){let c=i[h],u=c>>16&255,p=c>>8&255,m=c&255,f=l(m,p,u),d=f in o?o[f]:o[f]=ka(m,p,u,e);s[h]=d}}return s}function La(a,e,t,i,n){let r=0,s=1e100;for(let o=0;o<n.length;o++){let l=n[o],h=l[3],c=He(h-i);if(c>s)continue;let u=l[0];if(c+=He(u-a),c>s)continue;let p=l[1];if(c+=He(p-e),c>s)continue;let m=l[2];c+=He(m-t),!(c>s)&&(s=c,r=o)}return r}function ka(a,e,t,i){let n=0,r=1e100;for(let s=0;s<i.length;s++){let o=i[s],l=o[0],h=He(l-a);if(h>r)continue;let c=o[1];if(h+=He(c-e),h>r)continue;let u=o[2];h+=He(u-t),!(h>r)&&(r=h,n=s)}return n}function He(a){return a*a}function Ua(a={}){let{initialCapacity:e=4096,auto:t=!0}=a,i=mr(e),n=5003,r=new Uint8Array(256),s=new Int32Array(n),o=new Int32Array(n),l=!1;return{reset(){i.reset(),l=!1},finish(){i.writeByte(Aa.trailer)},bytes(){return i.bytes()},bytesView(){return i.bytesView()},get buffer(){return i.buffer},get stream(){return i},writeHeader:h,writeFrame(c,u,p,m={}){let{transparent:f=!1,transparentIndex:d=0,delay:g=0,palette:_=null,repeat:y=0,colorDepth:x=8,dispose:v=-1}=m,b=!1;if(t?l||(b=!0,h(),l=!0):b=!!m.first,u=Math.max(0,Math.floor(u)),p=Math.max(0,Math.floor(p)),b){if(!_)throw new Error("First frame must include a { palette } option");Na(i,u,p,_,x),vr(i,_),y>=0&&za(i,y)}let C=Math.round(g/10);Fa(i,v,C,f,d);let E=!!_&&!b;$a(i,u,p,E?_:null),E&&vr(i,_),Ba(i,c,u,p,x,r,s,o)}};function h(){Er(i,"GIF89a")}}function Fa(a,e,t,i,n){a.writeByte(33),a.writeByte(249),a.writeByte(4),n<0&&(n=0,i=!1);var r,s;i?(r=1,s=2):(r=0,s=0),e>=0&&(s=e&7),s<<=2,a.writeByte(0|s|0|r),ke(a,t),a.writeByte(n||0),a.writeByte(0)}function Na(a,e,t,i,n=8){let r=1,s=0,o=Yi(i.length)-1,l=r<<7|n-1<<4|s<<3|o;ke(a,e),ke(a,t),a.writeBytes([l,0,0])}function za(a,e){a.writeByte(33),a.writeByte(255),a.writeByte(11),Er(a,"NETSCAPE2.0"),a.writeByte(3),a.writeByte(1),ke(a,e),a.writeByte(0)}function vr(a,e){let t=1<<Yi(e.length);for(let i=0;i<t;i++){let n=[0,0,0];i<e.length&&(n=e[i]),a.writeByte(n[0]),a.writeByte(n[1]),a.writeByte(n[2])}}function $a(a,e,t,i){if(a.writeByte(44),ke(a,0),ke(a,0),ke(a,e),ke(a,t),i){let n=0,r=0,s=Yi(i.length)-1;a.writeByte(128|n|r|0|s)}else a.writeByte(0)}function Ba(a,e,t,i,n=8,r,s,o){Da(t,i,e,n,a,r,s,o)}function ke(a,e){a.writeByte(e&255),a.writeByte(e>>8&255)}function Er(a,e){for(var t=0;t<e.length;t++)a.writeByte(e.charCodeAt(t))}function Yi(a){return Math.max(Math.ceil(Math.log2(a)),1)}class Va{renderer;scene;camera;isRecording=!1;frames=[];mediaRecorder=null;recordedChunks=[];captureCanvas;captureCtx;compositeCanvas;compositeCtx;gifWidth=480;gifHeight=270;legendElement=null;countryLabels=null;constructor(e,t,i){this.renderer=e,this.scene=t,this.camera=i,this.captureCanvas=document.createElement("canvas"),this.captureCtx=this.captureCanvas.getContext("2d",{willReadFrequently:!0}),this.compositeCanvas=document.createElement("canvas"),this.compositeCtx=this.compositeCanvas.getContext("2d")}setLegendElement(e){this.legendElement=e}setCountryLabels(e){this.countryLabels=e}drawCountryLabelsOnCanvas(e,t,i){if(this.countryLabels)try{this.countryLabels.getVisibleLabelsForCanvas(this.camera,t,i).forEach(r=>{e.save(),e.globalAlpha=r.opacity,e.font="bold 12px Arial, sans-serif",e.textAlign="center",e.textBaseline="middle",e.strokeStyle="rgba(0, 0, 0, 0.8)",e.lineWidth=3,e.strokeText(r.text,r.x,r.y),e.fillStyle="#ffffff",e.fillText(r.text,r.x,r.y),e.restore()})}catch(n){console.warn("Failed to draw country labels:",n)}}drawOverlaysOnCanvas(e,t,i){this.drawCountryLabelsOnCanvas(e,t,i),this.drawLegendOnCanvas(e,t,i)}drawLegendOnCanvas(e,t,i){try{if(!this.legendElement||!this.legendElement.classList.contains("visible"))return;const n=this.legendElement,r=n.querySelector(".legend-title"),s=n.querySelector(".legend-gradient"),o=n.querySelector(".legend-min"),l=n.querySelector(".legend-max"),h=n.querySelector(".legend-description");if(!r||!s)return;const c=280,u=100,p=20,m=t-c-p,f=i-u-p,d=12;e.fillStyle="rgba(0, 10, 20, 0.9)",e.strokeStyle="rgba(100, 170, 255, 0.5)",e.lineWidth=2,e.beginPath(),e.roundRect?e.roundRect(m,f,c,u,d):e.rect(m,f,c,u),e.fill(),e.stroke(),e.fillStyle="#44aaff",e.font="bold 18px Arial, sans-serif",e.fillText(r.textContent||"",m+16,f+28);const g=m+16,_=f+40,y=c-32,x=20,v=s.style.background||"";let b=[];const C=v.match(/rgba?\([^)]+\)/g);if(C&&C.length>=2)b=C;else{const E=v.match(/#[0-9a-fA-F]{3,8}/g);E&&E.length>=2&&(b=E)}if(b.length>=2){const E=e.createLinearGradient(g,0,g+y,0);E.addColorStop(0,b[0]),b.length>=3?(E.addColorStop(.5,b[1]),E.addColorStop(1,b[2])):E.addColorStop(1,b[1]),e.fillStyle=E,e.beginPath(),e.roundRect?e.roundRect(g,_,y,x,4):e.rect(g,_,y,x),e.fill()}else{const E=e.createLinearGradient(g,0,g+y,0);E.addColorStop(0,"#cc6600"),E.addColorStop(.5,"#ffaa44"),E.addColorStop(1,"#ffeecc"),e.fillStyle=E,e.beginPath(),e.roundRect?e.roundRect(g,_,y,x,4):e.rect(g,_,y,x),e.fill(),console.log("Legend gradient style:",v)}if(e.fillStyle="#cccccc",e.font="14px Arial, sans-serif",o&&e.fillText(o.textContent||"",g,f+78),l){const E=l.textContent||"",P=e.measureText(E).width;e.fillText(E,g+y-P,f+78)}h&&h.textContent&&(e.fillStyle="#888888",e.font="italic 12px Arial, sans-serif",e.fillText(h.textContent,g,f+95))}catch(n){console.warn("Failed to draw legend on canvas:",n)}}screenshot(e={}){const{width:t=1920,height:i=1080}=e,n=this.renderer.domElement.width,r=this.renderer.domElement.height;this.renderer.setSize(t,i),this.camera.aspect=t/i,this.camera.updateProjectionMatrix(),this.renderer.render(this.scene,this.camera),this.compositeCanvas.width=t,this.compositeCanvas.height=i,this.compositeCtx.drawImage(this.renderer.domElement,0,0),this.drawOverlaysOnCanvas(this.compositeCtx,t,i);const s=this.compositeCanvas.toDataURL("image/png");this.renderer.setSize(n,r),this.camera.aspect=n/r,this.camera.updateProjectionMatrix(),this.downloadFile(s,`globe-${Date.now()}.png`)}startVideoRecording(e={}){return new Promise(t=>{if(this.isRecording){t();return}const i=this.renderer.domElement;this.compositeCanvas.width=i.width,this.compositeCanvas.height=i.height,this.compositeCtx.drawImage(i,0,0),this.drawOverlaysOnCanvas(this.compositeCtx,this.compositeCanvas.width,this.compositeCanvas.height);const n=this.compositeCanvas.captureStream(60),r=[{mime:"video/mp4;codecs=avc1",ext:"mp4"},{mime:"video/mp4",ext:"mp4"},{mime:"video/webm;codecs=h264",ext:"webm"},{mime:"video/webm;codecs=vp9",ext:"webm"},{mime:"video/webm;codecs=vp8",ext:"webm"},{mime:"video/webm",ext:"webm"}];let s="video/webm",o="webm";for(const{mime:h,ext:c}of r)if(MediaRecorder.isTypeSupported(h)){s=h,o=c,console.log(`Video recording using: ${h}`);break}this.mediaRecorder=new MediaRecorder(n,{mimeType:s,videoBitsPerSecond:8e6}),this.recordedChunks=[];const l=o;this.mediaRecorder.ondataavailable=h=>{h.data.size>0&&this.recordedChunks.push(h.data)},this.mediaRecorder.onstop=()=>{const h=s.split(";")[0],c=new Blob(this.recordedChunks,{type:h}),u=URL.createObjectURL(c);this.downloadFile(u,`globe-${Date.now()}.${l}`),URL.revokeObjectURL(u)},this.mediaRecorder.onstart=()=>{this.isRecording=!0,setTimeout(()=>t(),50)},this.mediaRecorder.start(100)})}updateVideoFrame(){if(!this.isRecording||!this.mediaRecorder)return;const e=this.compositeCanvas.width,t=this.compositeCanvas.height;this.compositeCtx.drawImage(this.renderer.domElement,0,0,e,t),this.drawOverlaysOnCanvas(this.compositeCtx,e,t)}stopVideoRecording(){!this.isRecording||!this.mediaRecorder||(this.mediaRecorder.stop(),this.isRecording=!1)}startGifCapture(e={}){if(this.isRecording)return;this.frames=[],this.isRecording=!0;const{width:t=480,height:i=270}=e;this.gifWidth=t,this.gifHeight=i,this.captureCanvas.width=t,this.captureCanvas.height=i}captureGifFrame(){if(!this.isRecording)return;const e=this.renderer.domElement,t=this.gifWidth,i=this.gifHeight;this.captureCtx.drawImage(e,0,0,t,i),this.drawOverlaysOnCanvas(this.captureCtx,t,i);const n=this.captureCtx.getImageData(0,0,t,i);this.frames.push({data:new Uint8ClampedArray(n.data),width:t,height:i})}async stopGifCapture(e={}){if(!this.isRecording)return;if(this.isRecording=!1,this.frames.length===0){console.warn("No frames captured for GIF");return}const{fps:t=20,filename:i}=e,n=Math.round(1e3/t);console.log(`Generating GIF with ${this.frames.length} frames at ${t} fps...`);try{const r=this.frames[0],s=r.width,o=r.height,l=Oa(r.data,256),h=Ua();for(let f=0;f<this.frames.length;f++){const d=this.frames[f],g=Ia(d.data,l);h.writeFrame(g,s,o,{palette:f===0?l:void 0,delay:n,repeat:f===0?0:void 0}),f%10===0&&await new Promise(_=>setTimeout(_,0))}h.finish();const c=h.bytes(),u=new Blob([c],{type:"image/gif"}),p=URL.createObjectURL(u),m=i||`globe-${Date.now()}.gif`;this.downloadFile(p,m),setTimeout(()=>URL.revokeObjectURL(p),1e3),console.log(`GIF saved: ${m} (${this.frames.length} frames, ${(u.size/1024).toFixed(1)}KB)`)}catch(r){console.error("Failed to generate GIF:",r)}this.frames=[]}getIsRecording(){return this.isRecording}getFrameCount(){return this.frames.length}downloadFile(e,t){const i=document.createElement("a");i.href=e,i.download=t,i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}class Ga extends A.Object3D{constructor(e=document.createElement("div")){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.center=new A.Vector2(.5,.5),this.addEventListener("removed",function(){this.traverse(function(t){t.element&&t.element instanceof t.element.ownerDocument.defaultView.Element&&t.element.parentNode!==null&&t.element.remove()})})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this.center=e.center,this}}const lt=new A.Vector3,wr=new A.Matrix4,Cr=new A.Matrix4,Pr=new A.Vector3,Ar=new A.Vector3;class ja{constructor(e={}){const t=this;let i,n,r,s;const o={objects:new WeakMap},l=e.element!==void 0?e.element:document.createElement("div");l.style.overflow="hidden",this.domElement=l,this.sortObjects=!0,this.getSize=function(){return{width:i,height:n}},this.render=function(f,d){f.matrixWorldAutoUpdate===!0&&f.updateMatrixWorld(),d.parent===null&&d.matrixWorldAutoUpdate===!0&&d.updateMatrixWorld(),wr.copy(d.matrixWorldInverse),Cr.multiplyMatrices(d.projectionMatrix,wr),c(f,f,d),this.sortObjects&&m(f)},this.setSize=function(f,d){i=f,n=d,r=i/2,s=n/2,l.style.width=f+"px",l.style.height=d+"px"};function h(f){f.isCSS2DObject&&(f.element.style.display="none");for(let d=0,g=f.children.length;d<g;d++)h(f.children[d])}function c(f,d,g){if(f.visible===!1){h(f);return}if(f.isCSS2DObject){lt.setFromMatrixPosition(f.matrixWorld),lt.applyMatrix4(Cr);const _=lt.z>=-1&<.z<=1&&f.layers.test(g.layers)===!0,y=f.element;y.style.display=_===!0?"":"none",_===!0&&(f.onBeforeRender(t,d,g),y.style.transform="translate("+-100*f.center.x+"%,"+-100*f.center.y+"%)translate("+(lt.x*r+r)+"px,"+(-lt.y*s+s)+"px)",y.parentNode!==l&&l.appendChild(y),f.onAfterRender(t,d,g));const x={distanceToCameraSquared:u(g,f)};o.objects.set(f,x)}for(let _=0,y=f.children.length;_<y;_++)c(f.children[_],d,g)}function u(f,d){return Pr.setFromMatrixPosition(f.matrixWorld),Ar.setFromMatrixPosition(d.matrixWorld),Pr.distanceToSquared(Ar)}function p(f){const d=[];return f.traverseVisible(function(g){g.isCSS2DObject&&d.push(g)}),d}function m(f){const d=p(f).sort(function(_,y){if(_.renderOrder!==y.renderOrder)return y.renderOrder-_.renderOrder;const x=o.objects.get(_).distanceToCameraSquared,v=o.objects.get(y).distanceToCameraSquared;return x-v}),g=d.length;for(let _=0,y=d.length;_<y;_++)d[_].element.style.zIndex=g-_}}}const Ya={CN:[35,105],IN:[22,78],US:[39,-98],ID:[-2,118],PK:[30,70],BR:[-10,-55],NG:[9,8],BD:[24,90],RU:[60,100],MX:[23,-102],JP:[36,138],ET:[9,38.5],PH:[12,122],EG:[27,30],VN:[16,108],DE:[51,10],TR:[39,35],IR:[32,53],TH:[15,101],GB:[54,-2],FR:[46,2],IT:[42.5,12.5],ZA:[-29,24],TZ:[-6,35],KE:[0,38],KR:[36,128],CO:[4,-72],ES:[40,-4],AR:[-34,-64],UG:[1,32],DZ:[28,3],UA:[49,32],IQ:[33,44],PL:[52,20],CA:[56,-106],MA:[32,-5],SA:[24,45],PE:[-10,-76],AU:[-25,134],MY:[4,109.5],GH:[8,-1],NP:[28,84],VE:[7,-66],MG:[-19,47],CM:[6,12],NL:[52.5,5.5],CL:[-34,-71],SE:[62,15],NO:[64,10],SG:[1.3,103.8],NZ:[-42,174],IE:[53,-8],IL:[31,35],AE:[24,54],CH:[47,8],AT:[47.5,14.5],PT:[39.5,-8],GR:[39,22],CZ:[49.8,15.5],BE:[50.8,4],HU:[47,20],FI:[64,26],DK:[56,10],IS:[65,-18],CD:[-3,22],SD:[16,30],AO:[-12.5,18.5],MZ:[-18,35],CI:[7.5,-5.5],NE:[17,10],BF:[12,-1.5],ML:[17,-4],SN:[14.5,-14.5],ZM:[-15,28],ZW:[-19,29.5],RW:[-2,30],AF:[33,65],MM:[21,96],KP:[40,127],MN:[46,105],LK:[7.8,80.8],KZ:[48,67],UZ:[41,64],CU:[22,-79.5],EC:[-1.5,-78.5],GT:[15.5,-90.3],BO:[-17,-65],HN:[15,-86.5],PY:[-23,-58],UY:[-33,-56],CR:[10,-84],PA:[9,-80]},Ha=new Set(["CN","IN","US","BR","RU","JP","DE","GB","FR","AU","CA","MX","ID","SA","ZA","EG","NG","AR","IT","ES","KR","TR","PL","NL","CH","SE","NO","PK","BD","VN"]),Za=new Set(["CN","IN","US","BR","RU","AU","CA"]),Ka=new Set(["RU","CA","US","CN","BR","AU"]),Xa=new Set(["IN","AR","KZ","DZ","CD","SA","MX","ID","SD","LY","IR","MN","PE","TD","NE","AO","ML","ZA","CO","ET","BO","MR","EG","TZ","NG","VE","PK","TR","CL","MM"]),Wa=new Set(["AF","UA","MG","MZ","FR","ES","TH","CM","PG","JP","DE","VN","MY","CI","PL","IT","PH","EC","BF","NZ","GB","GH","RO","LA","GY","OM","BY","KH","SN","UG","NO","SE","FI","MR","ZM","ZW","NP","MA","IQ","BD"]);class qa{labelRenderer;labels=[];labelGroup;currentStyle="none";sphereRadius;currentMorph=0;globe=null;camera=null;constructor(e,t){this.sphereRadius=t,this.labelRenderer=new ja;const i=e.clientWidth||800,n=e.clientHeight||600;this.labelRenderer.setSize(i,n),this.labelRenderer.domElement.style.position="absolute",this.labelRenderer.domElement.style.top="0",this.labelRenderer.domElement.style.left="0",this.labelRenderer.domElement.style.pointerEvents="none",e.appendChild(this.labelRenderer.domElement),this.labelGroup=new D.Group,this.injectStyles(),this.createLabels()}injectStyles(){const e=document.createElement("style");e.textContent=`
|
|
494
494
|
.country-label {
|
|
495
495
|
font-family: system-ui, -apple-system, sans-serif;
|
|
496
496
|
font-weight: 400;
|
|
@@ -1014,5 +1014,5 @@ void main() {
|
|
|
1014
1014
|
|
|
1015
1015
|
gl_FragColor = vec4(1.0, 1.0, 1.0, alpha * vOpacity * 0.9);
|
|
1016
1016
|
}
|
|
1017
|
-
`,Sr={satellite:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_atmos_2048.jpg",natural:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_day_4096.jpg",dark:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",light:"https://raw.githubusercontent.com/turban/webgl-earth/master/images/2_no_clouds_4k.jpg",night:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",topographic:"https://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.topo.200407.3x5400x2700.jpg"},Tr={texture:"satellite",labels:"all",statistic:"lifeExpectancy",autoRotate:!1,initialView:"globe",showControls:!1,showLegend:!0,effects:{atmosphereIntensity:0,atmosphere:!1,clouds:!1,starTwinkle:!0},extrudeHeight:!1};class ro{container;config;scene;camera;renderer;controls;globe=null;material=null;atmosphere=null;stars=null;gui=null;choropleth=null;legend=null;exporter=null;countryLabels=null;textureLoader=new D.TextureLoader;dataTexture=null;morph=0;currentStatistic=null;animationId=null;isDestroyed=!1;constructor(e,t={}){if(typeof e=="string"){const i=document.querySelector(e);if(!i)throw new Error(`Container not found: ${e}`);this.container=i}else this.container=e;this.config={...Tr,...t,effects:{...Tr.effects,...t.effects}},this.init()}async init(){const e=this.config.width||this.container.clientWidth||800,t=this.config.height||this.container.clientHeight||600;this.scene=new D.Scene,this.scene.background=new D.Color(2066),this.camera=new D.PerspectiveCamera(50,e/t,1,1e3),this.camera.position.set(0,0,this.config.initialView==="flat"?350:150),this.renderer=new D.WebGLRenderer({antialias:!0}),this.renderer.setSize(e,t),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.container.appendChild(this.renderer.domElement),this.controls=new Rr(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.minDistance=80,this.controls.maxDistance=400,this.choropleth=new wa,this.config.showLegend&&(this.legend=new Pa),await this.createGlobe(),this.createStars(),this.config.effects.atmosphere&&this.createAtmosphere(),this.countryLabels=new qa(this.container,Ze),this.scene.add(this.countryLabels.getGroup()),this.globe&&this.countryLabels.setGlobe(this.globe),this.countryLabels.setCamera(this.camera),this.countryLabels.setStyle(this.config.labels),this.exporter=new Va(this.renderer,this.scene,this.camera),this.config.showControls&&this.createGUI(),await this.choropleth.waitForLoad(),this.setStatistic(this.config.statistic),this.morph=this.config.initialView==="globe"?1:0,this.material&&(this.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),window.addEventListener("resize",this.handleResize),window.addEventListener("keydown",this.handleKeydown),this.animate()}async createGlobe(){const e=await this.textureLoader.loadAsync(Sr[this.config.texture]);e.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),e.minFilter=D.LinearMipmapLinearFilter,e.magFilter=D.LinearFilter;const t=document.createElement("canvas");t.width=2048,t.height=1024,this.dataTexture=new D.CanvasTexture(t);const i=new D.PlaneGeometry(Math.PI*2*Ze,Math.PI*Ze,256,128);this.material=new D.ShaderMaterial({vertexShader:Qa,fragmentShader:Ja,uniforms:{uMorph:{value:0},uTime:{value:0},uParchment:{value:0},uExtremeParchment:{value:0},uTransitionEffect:{value:0},uTexture:{value:e},uDataTexture:{value:this.dataTexture},uCloudTexture:{value:null},uNightTexture:{value:null},uDataOpacity:{value:0},uDataOverlay:{value:0},uExtrudeHeight:{value:this.config.extrudeHeight?1:0},uSunDir:{value:new D.Vector3(1,.5,1).normalize()},uClouds:{value:this.config.effects.clouds?1:0},uCloudSpeed:{value:this.config.effects.cloudSpeed||1},uCloudOpacity:{value:this.config.effects.cloudOpacity||.6},uAtmosphereIntensity:{value:this.config.effects.atmosphereIntensity||0},uAurora:{value:this.config.effects.aurora?1:0},uAuroraIntensity:{value:1},uCityLights:{value:this.config.effects.cityLights?1:0},uCityLightsIntensity:{value:1},uOceanSpecular:{value:this.config.effects.oceanSpecular?1:0},uSpecularIntensity:{value:1},uSunGlow:{value:0},uGridLines:{value:this.config.effects.gridLines?1:0},uGridOpacity:{value:this.config.effects.gridOpacity||.5},uScanEffect:{value:0},uScanSpeed:{value:1},uHologram:{value:this.config.effects.hologramMode?1:0},uHologramColor:{value:new D.Color(65535)},uVintage:{value:this.config.effects.vintageMode?1:0},uThermal:{value:this.config.effects.thermalMode?1:0},uBlueprint:{value:this.config.effects.blueprintMode?1:0},uGlowPulse:{value:this.config.effects.glowPulse?1:0},uGlowColor:{value:new D.Color(4491519)}},side:D.DoubleSide}),this.globe=new D.Mesh(i,this.material),this.scene.add(this.globe)}createAtmosphere(){const e=new D.PlaneGeometry(Math.PI*2*Ze*1.15,Math.PI*Ze*1.15,128,64),t=new D.ShaderMaterial({vertexShader:eo,fragmentShader:to,uniforms:{uMorph:{value:0}},side:D.BackSide,transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.atmosphere=new D.Mesh(e,t),this.scene.add(this.atmosphere)}createStars(){const t=new D.BufferGeometry,i=new Float32Array(3e3*3),n=new Float32Array(3e3),r=new Float32Array(3e3);for(let o=0;o<3e3;o++){const l=300+Math.random()*300,h=Math.random()*Math.PI*2,c=Math.acos(2*Math.random()-1);i[o*3]=l*Math.sin(c)*Math.cos(h),i[o*3+1]=l*Math.sin(c)*Math.sin(h),i[o*3+2]=l*Math.cos(c),n[o]=.5+Math.random()*1.5,r[o]=Math.random()*Math.PI*2}t.setAttribute("position",new D.BufferAttribute(i,3)),t.setAttribute("aSize",new D.BufferAttribute(n,1)),t.setAttribute("aPhase",new D.BufferAttribute(r,1));const s=new D.ShaderMaterial({vertexShader:io,fragmentShader:no,uniforms:{uTime:{value:0},uTwinkle:{value:this.config.effects.starTwinkle?1:0}},transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.stars=new D.Points(t,s),this.scene.add(this.stars)}createGUI(){this.gui=new zi({title:"Globe Controls",width:300});const e=this.gui.addFolder("View");e.add({toGlobe:()=>this.toGlobe()},"toGlobe").name("→ Globe"),e.add({toFlat:()=>this.toFlat()},"toFlat").name("→ Flat Map"),e.add({morph:this.morph},"morph",0,1).name("Morph").onChange(r=>this.setMorph(r)),e.open();const t=this.gui.addFolder("Statistics"),i=Object.keys(Zt);t.add({stat:this.config.statistic},"stat",i).name("Statistic").onChange(r=>this.setStatistic(r)),t.open();const n=["none","minimal","major","all"];this.gui.add({labels:this.config.labels},"labels",n).name("Labels").onChange(r=>this.setLabels(r)),this.gui.add(this.config,"autoRotate").name("Auto Rotate")}handleResize=()=>{if(this.isDestroyed)return;const e=this.config.width||this.container.clientWidth,t=this.config.height||this.container.clientHeight;this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t),this.countryLabels?.resize(e,t)};handleKeydown=e=>{this.isDestroyed||(e.key==="g"||e.key==="G")&&(this.morph>.5?this.toFlat():this.toGlobe())};animate=()=>{if(this.isDestroyed)return;this.animationId=requestAnimationFrame(this.animate);const e=performance.now()*.001;this.material&&(this.material.uniforms.uTime.value=e),this.stars&&(this.stars.material.uniforms.uTime.value=e),this.controls.update(),this.config.autoRotate&&this.globe&&(this.globe.rotation.y+=.002*this.morph),this.countryLabels?.update(),this.renderer.render(this.scene,this.camera),this.countryLabels?.render(this.scene,this.camera)};toGlobe(){wt.to(this,{morph:1,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("globe",this.morph)}}),wt.to(this.camera.position,{z:150,duration:2.5,ease:"power2.inOut"})}toFlat(){wt.to(this,{morph:0,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("flat",this.morph)}}),wt.to(this.camera.position,{z:350,duration:2.5,ease:"power2.inOut"})}setMorph(e){this.morph=Math.max(0,Math.min(1,e)),this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph)}getMorph(){return this.morph}setStatistic(e){if(typeof e=="string"){if(!Zt[e]){console.warn(`Unknown statistic: ${e}`);return}this.currentStatistic=e;const i=ba.find(n=>n.id===e);if(i&&this.choropleth){const n=this.choropleth.renderTexture(i);if(this.material&&n){const r=new D.CanvasTexture(n);r.needsUpdate=!0,this.material.uniforms.uDataTexture.value=r,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&i&&this.legend.show(i)}else{const t=e;if(this.currentStatistic=t.definition.id,this.choropleth){const i=this.choropleth.renderCustomTexture(t.values,t.definition.colorScale,t.definition.domain);if(this.material&&i){const n=new D.CanvasTexture(i);n.needsUpdate=!0,this.material.uniforms.uDataTexture.value=n,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&this.legend.show(t.definition)}}setLabels(e){this.countryLabels?.setStyle(e)}async setTexture(e){const t=Sr[e];if(!(!t||!this.material))try{const i=await this.textureLoader.loadAsync(t);i.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),i.minFilter=D.LinearMipmapLinearFilter,i.magFilter=D.LinearFilter,this.material.uniforms.uTexture.value=i}catch(i){console.error("Failed to load texture:",e,i)}}setAutoRotate(e){this.config.autoRotate=e}screenshot(e){this.exporter?.screenshot(e)}async recordGif(e){if(!this.exporter)return;const t=e?.duration||5,i=e?.fps||20,n=t*i;this.exporter.startGifCapture(e);for(let r=0;r<n;r++)this.exporter.captureGifFrame(),await new Promise(s=>setTimeout(s,1e3/i));await this.exporter.stopGifCapture(e)}async recordVideo(e){if(!this.exporter)return;const t=e?.duration||5;await this.exporter.startVideoRecording(e),await new Promise(i=>setTimeout(i,t*1e3)),this.exporter.stopVideoRecording()}setEffects(e){Object.assign(this.config.effects,e),this.material&&(e.atmosphere!==void 0&&(e.atmosphere&&!this.atmosphere?this.createAtmosphere():!e.atmosphere&&this.atmosphere&&(this.scene.remove(this.atmosphere),this.atmosphere.geometry.dispose(),this.atmosphere.material.dispose(),this.atmosphere=null)),e.clouds!==void 0&&(this.material.uniforms.uClouds.value=e.clouds?1:0),e.cloudSpeed!==void 0&&(this.material.uniforms.uCloudSpeed.value=e.cloudSpeed),e.cloudOpacity!==void 0&&(this.material.uniforms.uCloudOpacity.value=e.cloudOpacity),e.atmosphereIntensity!==void 0&&(this.material.uniforms.uAtmosphereIntensity.value=e.atmosphereIntensity),e.gridLines!==void 0&&(this.material.uniforms.uGridLines.value=e.gridLines?1:0),e.gridOpacity!==void 0&&(this.material.uniforms.uGridOpacity.value=e.gridOpacity),e.glowPulse!==void 0&&(this.material.uniforms.uGlowPulse.value=e.glowPulse?1:0),e.starTwinkle!==void 0&&this.stars&&(this.stars.material.uniforms.uTwinkle.value=e.starTwinkle?1:0))}resize(e,t){this.config.width=e,this.config.height=t,this.handleResize()}destroy(){this.isDestroyed=!0,this.animationId&&cancelAnimationFrame(this.animationId),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),this.gui?.destroy(),this.legend?.dispose(),this.countryLabels?.dispose(),this.globe?.geometry.dispose(),this.globe?.material?.dispose(),this.atmosphere?.geometry.dispose(),this.atmosphere?.material?.dispose(),this.stars?.geometry.dispose(),this.stars?.material?.dispose(),this.renderer.dispose(),this.container.removeChild(this.renderer.domElement)}}ae.BUILT_IN_STATISTICS=Zt,ae.GlobeViz=ro,ae.WORLD_STATISTICS=$i,ae.createFormatter=Vi,ae.formatValue=Ca,ae.normalizeCountryValues=fr,ae.toNumericCode=Bi,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"})}));
|
|
1017
|
+
`,Sr={satellite:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_atmos_2048.jpg",natural:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_day_4096.jpg",dark:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",light:"https://raw.githubusercontent.com/turban/webgl-earth/master/images/2_no_clouds_4k.jpg",night:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",topographic:"https://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.topo.200407.3x5400x2700.jpg"},Tr={texture:"satellite",labels:"all",statistic:"lifeExpectancy",autoRotate:!1,initialView:"globe",showControls:!1,showLegend:!0,effects:{atmosphereIntensity:0,atmosphere:!1,clouds:!1,starTwinkle:!0},extrudeHeight:!1};class ro{container;config;scene;camera;renderer;controls;globe=null;material=null;atmosphere=null;stars=null;gui=null;choropleth=null;legend=null;exporter=null;countryLabels=null;textureLoader=new D.TextureLoader;dataTexture=null;morph=0;currentStatistic=null;animationId=null;isDestroyed=!1;ready;resolveReady;constructor(e,t={}){if(typeof e=="string"){const i=document.querySelector(e);if(!i)throw new Error(`Container not found: ${e}`);this.container=i}else this.container=e;this.config={...Tr,...t,effects:{...Tr.effects,...t.effects}},this.ready=new Promise(i=>{this.resolveReady=i}),this.init()}async init(){const e=this.config.width||this.container.clientWidth||800,t=this.config.height||this.container.clientHeight||600;this.scene=new D.Scene,this.scene.background=new D.Color(2066),this.camera=new D.PerspectiveCamera(50,e/t,1,1e3),this.camera.position.set(0,0,this.config.initialView==="flat"?350:150),this.renderer=new D.WebGLRenderer({antialias:!0}),this.renderer.setSize(e,t),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.container.appendChild(this.renderer.domElement),this.controls=new Rr(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.minDistance=80,this.controls.maxDistance=400,this.choropleth=new wa,this.config.showLegend&&(this.legend=new Pa),await this.createGlobe(),this.createStars(),this.config.effects.atmosphere&&this.createAtmosphere(),this.countryLabels=new qa(this.container,Ze),this.scene.add(this.countryLabels.getGroup()),this.globe&&this.countryLabels.setGlobe(this.globe),this.countryLabels.setCamera(this.camera),this.countryLabels.setStyle(this.config.labels),this.exporter=new Va(this.renderer,this.scene,this.camera),this.config.showControls&&this.createGUI(),await this.choropleth.waitForLoad(),this.setStatistic(this.config.statistic),this.morph=this.config.initialView==="globe"?1:0,this.material&&(this.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),window.addEventListener("resize",this.handleResize),window.addEventListener("keydown",this.handleKeydown),this.animate(),this.resolveReady()}async createGlobe(){const e=await this.textureLoader.loadAsync(Sr[this.config.texture]);e.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),e.minFilter=D.LinearMipmapLinearFilter,e.magFilter=D.LinearFilter;const t=document.createElement("canvas");t.width=2048,t.height=1024,this.dataTexture=new D.CanvasTexture(t);const i=new D.PlaneGeometry(Math.PI*2*Ze,Math.PI*Ze,256,128);this.material=new D.ShaderMaterial({vertexShader:Qa,fragmentShader:Ja,uniforms:{uMorph:{value:0},uTime:{value:0},uParchment:{value:0},uExtremeParchment:{value:0},uTransitionEffect:{value:0},uTexture:{value:e},uDataTexture:{value:this.dataTexture},uCloudTexture:{value:null},uNightTexture:{value:null},uDataOpacity:{value:0},uDataOverlay:{value:0},uExtrudeHeight:{value:this.config.extrudeHeight?1:0},uSunDir:{value:new D.Vector3(1,.5,1).normalize()},uClouds:{value:this.config.effects.clouds?1:0},uCloudSpeed:{value:this.config.effects.cloudSpeed||1},uCloudOpacity:{value:this.config.effects.cloudOpacity||.6},uAtmosphereIntensity:{value:this.config.effects.atmosphereIntensity||0},uAurora:{value:this.config.effects.aurora?1:0},uAuroraIntensity:{value:1},uCityLights:{value:this.config.effects.cityLights?1:0},uCityLightsIntensity:{value:1},uOceanSpecular:{value:this.config.effects.oceanSpecular?1:0},uSpecularIntensity:{value:1},uSunGlow:{value:0},uGridLines:{value:this.config.effects.gridLines?1:0},uGridOpacity:{value:this.config.effects.gridOpacity||.5},uScanEffect:{value:0},uScanSpeed:{value:1},uHologram:{value:this.config.effects.hologramMode?1:0},uHologramColor:{value:new D.Color(65535)},uVintage:{value:this.config.effects.vintageMode?1:0},uThermal:{value:this.config.effects.thermalMode?1:0},uBlueprint:{value:this.config.effects.blueprintMode?1:0},uGlowPulse:{value:this.config.effects.glowPulse?1:0},uGlowColor:{value:new D.Color(4491519)}},side:D.DoubleSide}),this.globe=new D.Mesh(i,this.material),this.scene.add(this.globe)}createAtmosphere(){const e=new D.PlaneGeometry(Math.PI*2*Ze*1.15,Math.PI*Ze*1.15,128,64),t=new D.ShaderMaterial({vertexShader:eo,fragmentShader:to,uniforms:{uMorph:{value:0}},side:D.BackSide,transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.atmosphere=new D.Mesh(e,t),this.scene.add(this.atmosphere)}createStars(){const t=new D.BufferGeometry,i=new Float32Array(3e3*3),n=new Float32Array(3e3),r=new Float32Array(3e3);for(let o=0;o<3e3;o++){const l=300+Math.random()*300,h=Math.random()*Math.PI*2,c=Math.acos(2*Math.random()-1);i[o*3]=l*Math.sin(c)*Math.cos(h),i[o*3+1]=l*Math.sin(c)*Math.sin(h),i[o*3+2]=l*Math.cos(c),n[o]=.5+Math.random()*1.5,r[o]=Math.random()*Math.PI*2}t.setAttribute("position",new D.BufferAttribute(i,3)),t.setAttribute("aSize",new D.BufferAttribute(n,1)),t.setAttribute("aPhase",new D.BufferAttribute(r,1));const s=new D.ShaderMaterial({vertexShader:io,fragmentShader:no,uniforms:{uTime:{value:0},uTwinkle:{value:this.config.effects.starTwinkle?1:0}},transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.stars=new D.Points(t,s),this.scene.add(this.stars)}createGUI(){this.gui=new zi({title:"Globe Controls",width:300});const e=this.gui.addFolder("View");e.add({toGlobe:()=>this.toGlobe()},"toGlobe").name("→ Globe"),e.add({toFlat:()=>this.toFlat()},"toFlat").name("→ Flat Map"),e.add({morph:this.morph},"morph",0,1).name("Morph").onChange(r=>this.setMorph(r)),e.open();const t=this.gui.addFolder("Statistics"),i=Object.keys(Zt);t.add({stat:this.config.statistic},"stat",i).name("Statistic").onChange(r=>this.setStatistic(r)),t.open();const n=["none","minimal","major","all"];this.gui.add({labels:this.config.labels},"labels",n).name("Labels").onChange(r=>this.setLabels(r)),this.gui.add(this.config,"autoRotate").name("Auto Rotate")}handleResize=()=>{if(this.isDestroyed)return;const e=this.config.width||this.container.clientWidth,t=this.config.height||this.container.clientHeight;this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t),this.countryLabels?.resize(e,t)};handleKeydown=e=>{this.isDestroyed||(e.key==="g"||e.key==="G")&&(this.morph>.5?this.toFlat():this.toGlobe())};animate=()=>{if(this.isDestroyed)return;this.animationId=requestAnimationFrame(this.animate);const e=performance.now()*.001;this.material&&(this.material.uniforms.uTime.value=e),this.stars&&(this.stars.material.uniforms.uTime.value=e),this.controls.update(),this.config.autoRotate&&this.globe&&(this.globe.rotation.y+=.002*this.morph),this.countryLabels?.update(),this.renderer.render(this.scene,this.camera),this.countryLabels?.render(this.scene,this.camera)};toGlobe(){wt.to(this,{morph:1,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("globe",this.morph)}}),wt.to(this.camera.position,{z:150,duration:2.5,ease:"power2.inOut"})}toFlat(){wt.to(this,{morph:0,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("flat",this.morph)}}),wt.to(this.camera.position,{z:350,duration:2.5,ease:"power2.inOut"})}setMorph(e){this.morph=Math.max(0,Math.min(1,e)),this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph)}getMorph(){return this.morph}setStatistic(e){if(typeof e=="string"){if(!Zt[e]){console.warn(`Unknown statistic: ${e}`);return}this.currentStatistic=e;const i=ba.find(n=>n.id===e);if(i&&this.choropleth){const n=this.choropleth.renderTexture(i);if(this.material&&n){const r=new D.CanvasTexture(n);r.needsUpdate=!0,this.material.uniforms.uDataTexture.value=r,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&i&&this.legend.show(i)}else{const t=e;if(this.currentStatistic=t.definition.id,this.choropleth){const i=this.choropleth.renderCustomTexture(t.values,t.definition.colorScale,t.definition.domain);if(this.material&&i){const n=new D.CanvasTexture(i);n.needsUpdate=!0,this.material.uniforms.uDataTexture.value=n,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&this.legend.show(t.definition)}}setLabels(e){this.countryLabels?.setStyle(e)}async setTexture(e){const t=Sr[e];if(!(!t||!this.material))try{const i=await this.textureLoader.loadAsync(t);i.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),i.minFilter=D.LinearMipmapLinearFilter,i.magFilter=D.LinearFilter,this.material.uniforms.uTexture.value=i}catch(i){console.error("Failed to load texture:",e,i)}}setAutoRotate(e){this.config.autoRotate=e}screenshot(e){this.exporter?.screenshot(e)}async recordGif(e){if(!this.exporter)return;const t=e?.duration||5,i=e?.fps||20,n=t*i;this.exporter.startGifCapture(e);for(let r=0;r<n;r++)this.exporter.captureGifFrame(),await new Promise(s=>setTimeout(s,1e3/i));await this.exporter.stopGifCapture(e)}async recordVideo(e){if(!this.exporter)return;const t=e?.duration||5;await this.exporter.startVideoRecording(e),await new Promise(i=>setTimeout(i,t*1e3)),this.exporter.stopVideoRecording()}setEffects(e){Object.assign(this.config.effects,e),this.material&&(e.atmosphere!==void 0&&(e.atmosphere&&!this.atmosphere?this.createAtmosphere():!e.atmosphere&&this.atmosphere&&(this.scene.remove(this.atmosphere),this.atmosphere.geometry.dispose(),this.atmosphere.material.dispose(),this.atmosphere=null)),e.clouds!==void 0&&(this.material.uniforms.uClouds.value=e.clouds?1:0),e.cloudSpeed!==void 0&&(this.material.uniforms.uCloudSpeed.value=e.cloudSpeed),e.cloudOpacity!==void 0&&(this.material.uniforms.uCloudOpacity.value=e.cloudOpacity),e.atmosphereIntensity!==void 0&&(this.material.uniforms.uAtmosphereIntensity.value=e.atmosphereIntensity),e.gridLines!==void 0&&(this.material.uniforms.uGridLines.value=e.gridLines?1:0),e.gridOpacity!==void 0&&(this.material.uniforms.uGridOpacity.value=e.gridOpacity),e.glowPulse!==void 0&&(this.material.uniforms.uGlowPulse.value=e.glowPulse?1:0),e.starTwinkle!==void 0&&this.stars&&(this.stars.material.uniforms.uTwinkle.value=e.starTwinkle?1:0))}resize(e,t){this.config.width=e,this.config.height=t,this.handleResize()}destroy(){this.isDestroyed=!0,this.animationId&&cancelAnimationFrame(this.animationId),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),this.gui?.destroy(),this.legend?.dispose(),this.countryLabels?.dispose(),this.globe?.geometry.dispose(),this.globe?.material?.dispose(),this.atmosphere?.geometry.dispose(),this.atmosphere?.material?.dispose(),this.stars?.geometry.dispose(),this.stars?.material?.dispose(),this.renderer.dispose(),this.container.removeChild(this.renderer.domElement)}}ae.BUILT_IN_STATISTICS=Zt,ae.GlobeViz=ro,ae.WORLD_STATISTICS=$i,ae.createFormatter=Vi,ae.formatValue=Ca,ae.normalizeCountryValues=fr,ae.toNumericCode=Bi,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"})}));
|
|
1018
1018
|
//# sourceMappingURL=gralobe.umd.cjs.map
|