@cos-design/weather-background 3.5.1 → 3.5.3

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/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("@cos-design/shared"),u=require("react/jsx-runtime");var d=39,f={0:`sunny`,1:`sunny`,2:`partlyCloudy`,3:`overcast`,45:`fog`,48:`fog`,51:`lightRain`,53:`lightRain`,55:`moderateRain`,56:`sleet`,57:`sleet`,61:`lightRain`,63:`moderateRain`,65:`heavyRain`,66:`sleet`,67:`sleet`,71:`lightSnow`,73:`moderateSnow`,75:`heavySnow`,77:`lightSnow`,80:`lightRain`,81:`moderateRain`,82:`heavyRain`,85:`lightSnow`,86:`heavySnow`,95:`thunderstorm`,96:`thunderstorm`,99:`thunderstorm`},p=(e,t=0)=>{let n=f[e]??`overcast`;return(n===`sunny`||n===`partlyCloudy`||n===`overcast`)&&t>=d?`gale`:n},m={weather:null,status:`idle`,error:null,current:null},h={weather:null,status:`locating`,error:null,current:null},g={weather:null,status:`fetching`,error:null,current:null},_=e=>e!=null&&Number.isFinite(e.latitude)&&Number.isFinite(e.longitude),v=(e=!0,t)=>{let n=_(t),r=n?t.latitude:null,i=n?t.longitude:null,a=e?n?g:h:m,o=`${e}:${r},${i}`,[s,l]=(0,c.useState)(a),[u,d]=(0,c.useState)(o);return u!==o&&(d(o),l(t=>e&&t.weather?{...a,weather:t.weather,current:t.current}:a)),(0,c.useEffect)(()=>{if(!e)return;let t=!1,n=new AbortController,a=async(e,r)=>{try{let i=new URLSearchParams({latitude:String(e),longitude:String(r),current:`weather_code,wind_speed_10m,is_day`}),a=await fetch(`https://api.open-meteo.com/v1/forecast?${i}`,{signal:n.signal});if(!a.ok)throw Error(`Open-Meteo 请求失败(HTTP ${a.status})`);let o=await a.json(),s=Number(o?.current?.weather_code);if(Number.isNaN(s))throw Error(`Open-Meteo 返回数据缺少 weather_code`);let c=Number(o?.current?.wind_speed_10m??0);if(t)return;l({weather:p(s,c),status:`success`,error:null,current:{weatherCode:s,windSpeed:c,isDay:o?.current?.is_day===1,latitude:e,longitude:r}})}catch(e){if(t||e instanceof DOMException&&e.name===`AbortError`)return;l({weather:null,status:`error`,error:e instanceof Error?e.message:`天气获取失败`,current:null})}};return r!=null&&i!=null?(a(r,i),()=>{t=!0,n.abort()}):typeof navigator>`u`||!navigator.geolocation?(Promise.resolve().then(()=>{t||l({weather:null,status:`error`,error:`当前环境不支持定位`,current:null})}),()=>{t=!0}):(navigator.geolocation.getCurrentPosition(({coords:e})=>{t||(l(e=>({...e,status:`fetching`})),a(e.latitude,e.longitude))},e=>{t||l({weather:null,status:`error`,error:e.message||`定位失败`,current:null})},{timeout:1e4,maximumAge:600*1e3}),()=>{t=!0,n.abort()})},[e,r,i]),s},y={weatherBackground:`cos-weatherBackground-Mnm22`,canvas:`cos-canvas-nvqMt`,loadingOverlay:`cos-loadingOverlay-O58B7`,loadingSpinner:`cos-loadingSpinner-NQ9yG`,"weather-loading-spin":`cos-weather-loading-spin-IPFWZ`},b={sunny:{sky:[`#4a9fe0`,`#c8e8fb`],sun:`full`,cloudCount:1,cloudColor:[255,255,255],cloudAlpha:.5,cloudSpread:.12,rain:null,fogBanks:0,haze:0,snowCount:0,lightning:!1},partlyCloudy:{sky:[`#5b9bd0`,`#cfe6f3`],sun:`soft`,cloudCount:5,cloudColor:[255,255,255],cloudAlpha:.85,cloudSpread:.22,rain:null,fogBanks:0,haze:0,snowCount:0,lightning:!1},overcast:{sky:[`#8a97a8`,`#c3cbd6`],sun:`none`,cloudCount:9,cloudColor:[100,116,139],cloudAlpha:.55,cloudSpread:.3,rain:null,fogBanks:0,haze:.06,snowCount:0,lightning:!1},lightRain:{sky:[`#6b7a8f`,`#9aa7b8`],sun:`none`,cloudCount:7,cloudColor:[71,85,105],cloudAlpha:.6,cloudSpread:.24,rain:{count:70,speed:7,wind:-.8,alpha:.4,splash:!1},fogBanks:0,haze:.04,snowCount:0,lightning:!1},moderateRain:{sky:[`#55637a`,`#7e8ba0`],sun:`none`,cloudCount:8,cloudColor:[51,65,85],cloudAlpha:.65,cloudSpread:.26,rain:{count:150,speed:10,wind:-1.5,alpha:.5,splash:!0},fogBanks:0,haze:.06,snowCount:0,lightning:!1},heavyRain:{sky:[`#3d4a5f`,`#5d6a80`],sun:`none`,cloudCount:9,cloudColor:[30,41,59],cloudAlpha:.7,cloudSpread:.3,rain:{count:280,speed:14,wind:-2.8,alpha:.55,splash:!0},fogBanks:0,haze:.1,snowCount:0,lightning:!1},thunderstorm:{sky:[`#252f42`,`#43506a`],sun:`none`,cloudCount:10,cloudColor:[15,23,42],cloudAlpha:.75,cloudSpread:.32,rain:{count:240,speed:13,wind:-2.2,alpha:.55,splash:!0},fogBanks:0,haze:.08,snowCount:0,lightning:!0},fog:{sky:[`#aab4bf`,`#d5dbe1`],sun:`dim`,cloudCount:3,cloudColor:[203,213,225],cloudAlpha:.4,cloudSpread:.2,rain:null,fogBanks:10,haze:.28,snowCount:0,lightning:!1},lightSnow:{sky:[`#aab8c8`,`#e2e8ef`],sun:`none`,cloudCount:5,cloudColor:[166,180,196],cloudAlpha:.45,cloudSpread:.22,rain:null,fogBanks:0,haze:.05,snowCount:70,lightning:!1},moderateSnow:{sky:[`#9fb0c4`,`#dde5ee`],sun:`none`,cloudCount:6,cloudColor:[148,163,184],cloudAlpha:.5,cloudSpread:.24,rain:null,fogBanks:0,haze:.08,snowCount:160,lightning:!1},heavySnow:{sky:[`#8495aa`,`#c7d1dc`],sun:`none`,cloudCount:9,cloudColor:[100,116,139],cloudAlpha:.62,cloudSpread:.3,rain:null,fogBanks:3,haze:.14,snowCount:300,lightning:!1},sleet:{sky:[`#78899e`,`#b8c5d2`],sun:`none`,cloudCount:8,cloudColor:[71,85,105],cloudAlpha:.6,cloudSpread:.28,rain:{count:100,speed:9,wind:-1.4,alpha:.42,splash:!0},fogBanks:0,haze:.09,snowCount:100,lightning:!1},hail:{sky:[`#46566c`,`#77889d`],sun:`none`,cloudCount:9,cloudColor:[30,41,59],cloudAlpha:.68,cloudSpread:.3,rain:{count:80,speed:11,wind:-2.5,alpha:.38,splash:!0},fogBanks:0,haze:.1,snowCount:0,lightning:!1},smog:{sky:[`#8f8b7e`,`#c5bca8`],sun:`dim`,cloudCount:3,cloudColor:[142,136,119],cloudAlpha:.35,cloudSpread:.2,rain:null,fogBanks:12,haze:.34,snowCount:0,lightning:!1},gale:{sky:[`#587087`,`#a6b5c2`],sun:`soft`,cloudCount:8,cloudColor:[203,213,225],cloudAlpha:.72,cloudSpread:.3,rain:null,fogBanks:0,haze:.04,snowCount:0,lightning:!1},snow:{sky:[`#9fb0c4`,`#dde5ee`],sun:`none`,cloudCount:6,cloudColor:[148,163,184],cloudAlpha:.5,cloudSpread:.24,rain:null,fogBanks:0,haze:.08,snowCount:160,lightning:!1}},x={sunny:{sky:[`#0b1a33`,`#27476e`],stars:110},partlyCloudy:{sky:[`#0f1f38`,`#2c4666`],stars:60},overcast:{sky:[`#181f2a`,`#333e4e`],stars:0},lightRain:{sky:[`#151b26`,`#2b3442`],stars:0},moderateRain:{sky:[`#11161f`,`#242c3a`],stars:0},heavyRain:{sky:[`#0c1017`,`#1c232e`],stars:0},thunderstorm:{sky:[`#0a0e18`,`#192132`],stars:0},fog:{sky:[`#1c222b`,`#3a434e`],stars:0},lightSnow:{sky:[`#161e2b`,`#3a4656`],stars:20},moderateSnow:{sky:[`#131a26`,`#333f4f`],stars:8},heavySnow:{sky:[`#101623`,`#2a3545`],stars:0},sleet:{sky:[`#121924`,`#2c3745`],stars:0},hail:{sky:[`#0e141d`,`#26303e`],stars:0},smog:{sky:[`#1a1812`,`#38321f`],stars:0},gale:{sky:[`#101a26`,`#2e3d4d`],stars:30},snow:{sky:[`#131a26`,`#333f4f`],stars:8}},S=([e,t,n])=>[Math.round(e*.3+18),Math.round(t*.3+24),Math.round(n*.3+42)],C=e=>{let t=Math.ceil(e*2+4),n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`),i=r.createRadialGradient(t/2,t/2,0,t/2,t/2,e+1);return i.addColorStop(0,`rgba(255, 255, 255, 1)`),i.addColorStop(.6,`rgba(255, 255, 255, 0.85)`),i.addColorStop(1,`rgba(255, 255, 255, 0)`),r.fillStyle=i,r.fillRect(0,0,t,t),n},w=e=>{let t=Math.ceil(e*2+6),n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`);r.translate(t/2,t/2),r.strokeStyle=`rgba(255, 255, 255, 0.95)`,r.lineCap=`round`,r.lineWidth=Math.max(e*.11,.7),r.shadowColor=`rgba(255, 255, 255, 0.5)`,r.shadowBlur=e*.25;let i=1+Math.floor(Math.random()*3),a=Array.from({length:i},()=>({pos:.3+Math.random()*.5,len:e*(.22+Math.random()*.34),angle:Math.PI/3*(.8+Math.random()*.45)})),o=Math.random()<.55,s=e*(.14+Math.random()*.12),c=Math.random()<.45,l=e*(.14+Math.random()*.14);for(let t=0;t<6;t++){r.save(),r.rotate(t*Math.PI/3),r.beginPath(),r.moveTo(0,0),r.lineTo(0,-e);for(let t of a){let n=-e*t.pos;r.moveTo(0,n),r.lineTo(Math.sin(t.angle)*t.len,n-Math.cos(t.angle)*t.len),r.moveTo(0,n),r.lineTo(-Math.sin(t.angle)*t.len,n-Math.cos(t.angle)*t.len)}o&&(r.moveTo(0,-e),r.lineTo(s*.7,-e-s*.5),r.moveTo(0,-e),r.lineTo(-s*.7,-e-s*.5)),r.stroke(),r.restore()}if(c){r.beginPath();for(let e=0;e<6;e++){let t=e*Math.PI/3-Math.PI/2,n=Math.cos(t)*l,i=Math.sin(t)*l;e===0?r.moveTo(n,i):r.lineTo(n,i)}r.closePath(),r.stroke()}return n},T=(e,t,n)=>{let r=1+Math.random()**1.6*4.2,i=r>=2.4;return{x:Math.random()*e,y:n??Math.random()*t,size:r,speed:.4+r*.28+Math.random()*.4,phase:Math.random()*Math.PI*2,drift:(Math.random()-.5)*.4,rotation:Math.random()*Math.PI*2,rotationSpeed:(Math.random()-.5)*.025,opacity:.55+Math.random()*.45,sprite:i?w(r*2.4):C(r)}},E=(e,t,n,r,i,a)=>{if(a<=0)return[[e,t],[n,r]];let o=(e+n)/2+(Math.random()-.5)*i,s=(t+r)/2,c=E(e,t,o,s,i*.55,a-1),l=E(o,s,n,r,i*.55,a-1);return[...c.slice(0,-1),...l]},D=({width:e=800,height:t=450,weather:n=`sunny`,night:r=!1,live:i=!1,latitude:a,longitude:o,onLiveWeather:s,loading:d=!1})=>{let f=(0,c.useRef)(null),p=v(i,a!=null&&o!=null?{latitude:a,longitude:o}:void 0),m=i&&p.weather?p.weather:n,h=i&&p.current?!p.current.isDay:r,g=d||i&&(p.status===`locating`||p.status===`fetching`),_=(0,c.useRef)(s);return(0,c.useEffect)(()=>{_.current=s}),(0,c.useEffect)(()=>{p.weather&&_.current?.(p.weather)},[p.weather]),(0,c.useEffect)(()=>{let n=f.current;if(!n)return;let r=window.devicePixelRatio||1;n.width=e*r,n.height=t*r;let i=n.getContext(`2d`);if(!i)return;i.setTransform(r,0,0,r,0,0);let a=b[m],o=x[m],s=h?o.sky:a.sky,c=h?S(a.cloudColor):a.cloudColor,u=e*.72,d=t*.26,p=Math.min(e,t)*.09,g=h?Array.from({length:o.stars},()=>({x:Math.random()*e,y:Math.random()*t*.72,r:.4+Math.random()*1.1,phase:Math.random()*Math.PI*2,speed:.015+Math.random()*.035})):[],_=[{dx:-.32,dy:.08,r:.17},{dx:.24,dy:-.22,r:.12},{dx:.04,dy:.34,r:.1},{dx:.36,dy:.24,r:.07}],v=Array.from({length:a.cloudCount},()=>{let n=.7+Math.random()*.9,r=4+Math.floor(Math.random()*3);return{x:Math.random()*(e+240)-120,y:t*.06+Math.random()*t*a.cloudSpread,scale:n,speed:.12+Math.random()*.22,puffs:Array.from({length:r},(e,t)=>({dx:(t-r/2)*26+(Math.random()-.5)*14,dy:(Math.random()-.5)*14,r:22+Math.random()*20}))}}),y=a.rain?Array.from({length:a.rain.count},()=>({x:Math.random()*(e+160)-80,y:Math.random()*t,len:8+Math.random()*10,speed:a.rain.speed*(.75+Math.random()*.5)})):[],C=[],w=Array.from({length:a.fogBanks},(n,r)=>({x:Math.random()*e,y:r/Math.max(a.fogBanks-1,1)*t*.9+t*.05,rw:e*(.25+Math.random()*.3),rh:t*(.08+Math.random()*.08),speed:(.1+Math.random()*.25)*(r%2==0?1:-1),alpha:.16+Math.random()*.14})),D=Array.from({length:a.snowCount},()=>T(e,t)),O=m===`hail`?Array.from({length:130},()=>({x:Math.random()*(e+180)-90,y:Math.random()*t,r:1.8+Math.random()*3,vx:-2.2-Math.random()*1.8,vy:8+Math.random()*5,bounces:0,opacity:.65+Math.random()*.35})):[],k=m===`gale`?Array.from({length:46},()=>({x:Math.random()*e,y:Math.random()*t,length:45+Math.random()*130,speed:8+Math.random()*10,wave:Math.random()*Math.PI*2,alpha:.12+Math.random()*.3,width:.6+Math.random()*1.2})):[],A=0,j=0,M=0,N=[],P=120+Math.random()*240,F=0,I=document.hidden,L=(0,l.bindVisibilityPause)(e=>{I=e}),R=()=>{let n=i.createLinearGradient(0,0,0,t);n.addColorStop(0,s[0]),n.addColorStop(1,s[1]),i.fillStyle=n,i.fillRect(0,0,e,t)},z=()=>{for(let e of g){let t=.35+(Math.sin(A*e.speed+e.phase)+1)*.325;i.beginPath(),i.arc(e.x,e.y,e.r,0,Math.PI*2),i.fillStyle=`rgba(226, 235, 255, ${t})`,i.fill()}},B=()=>{if(a.sun===`none`)return;let n=p*.88,r=a.sun===`dim`,o=i.createRadialGradient(u,d,0,u,d,n*(r?1.8:2.8));o.addColorStop(0,`rgba(214, 226, 245, ${r?.18:.35})`),o.addColorStop(1,`rgba(214, 226, 245, 0)`),i.fillStyle=o,i.fillRect(0,0,e,t);let s=r?.5:1,c=i.createRadialGradient(u-n*.25,d-n*.25,0,u,d,n);c.addColorStop(0,`rgba(245, 248, 252, ${s})`),c.addColorStop(1,`rgba(196, 208, 226, ${s})`),i.beginPath(),i.arc(u,d,n,0,Math.PI*2),i.fillStyle=c,i.fill();for(let e of _)i.beginPath(),i.arc(u+e.dx*n,d+e.dy*n,e.r*n,0,Math.PI*2),i.fillStyle=`rgba(170, 184, 206, ${s*.55})`,i.fill()},V=()=>{if(h){z(),B();return}if(a.sun===`none`)return;if(a.sun===`full`){let n=1+Math.sin(A*.02)*.04,r=i.createRadialGradient(u,d,0,u,d,p*3.4*n);r.addColorStop(0,`rgba(255, 236, 168, 0.9)`),r.addColorStop(.35,`rgba(255, 214, 112, 0.32)`),r.addColorStop(1,`rgba(255, 214, 112, 0)`),i.fillStyle=r,i.fillRect(0,0,e,t),i.save(),i.translate(u,d),i.rotate(A*.003);for(let e=0;e<12;e++){i.rotate(Math.PI/6);let e=i.createLinearGradient(p*1.2,0,p*2.4,0);e.addColorStop(0,`rgba(255, 230, 150, 0.5)`),e.addColorStop(1,`rgba(255, 230, 150, 0)`),i.strokeStyle=e,i.lineWidth=3,i.beginPath(),i.moveTo(p*1.2,0),i.lineTo(p*2.4,0),i.stroke()}i.restore()}if(a.sun===`soft`){let n=i.createRadialGradient(u,d,0,u,d,p*2.4);n.addColorStop(0,`rgba(255, 240, 190, 0.7)`),n.addColorStop(1,`rgba(255, 240, 190, 0)`),i.fillStyle=n,i.fillRect(0,0,e,t)}let n=a.sun===`dim`?.35:1,r=i.createRadialGradient(u-p*.2,d-p*.2,0,u,d,p);r.addColorStop(0,`rgba(255, 250, 224, ${n})`),r.addColorStop(1,`rgba(255, 214, 102, ${n})`),i.beginPath(),i.arc(u,d,p,0,Math.PI*2),i.fillStyle=r,i.fill()},H=()=>{let[t,n,r]=c;for(let o of v){o.x+=o.speed*(m===`gale`?7:1),o.x-140*o.scale>e&&(o.x=-160*o.scale);for(let e of o.puffs){let s=o.x+e.dx*o.scale,c=o.y+e.dy*o.scale,l=e.r*o.scale,u=i.createRadialGradient(s,c,0,s,c,l);u.addColorStop(0,`rgba(${t}, ${n}, ${r}, ${a.cloudAlpha})`),u.addColorStop(1,`rgba(${t}, ${n}, ${r}, 0)`),i.beginPath(),i.arc(s,c,l,0,Math.PI*2),i.fillStyle=u,i.fill()}}},U=()=>{if(!a.rain)return;let{wind:n,alpha:r,splash:o}=a.rain;i.strokeStyle=`rgba(214, 228, 240, ${r})`,i.lineWidth=1.2,i.beginPath();for(let r of y){let a=Math.hypot(n,r.speed)||1,s=n/a,c=r.speed/a;i.moveTo(r.x,r.y),i.lineTo(r.x+s*r.len,r.y+c*r.len),r.x+=n,r.y+=r.speed,r.y>t&&(o&&Math.random()<.3&&C.length<60&&C.push({x:r.x,r:1,alpha:.5}),r.y=-r.len,r.x=Math.random()*(e+160)-80)}i.stroke();for(let e=C.length-1;e>=0;e--){let n=C[e];if(n.r+=.8,n.alpha-=.035,n.alpha<=0){C.splice(e,1);continue}i.beginPath(),i.ellipse(n.x,t-3,n.r,n.r*.35,0,Math.PI,Math.PI*2),i.strokeStyle=`rgba(214, 228, 240, ${n.alpha})`,i.lineWidth=1,i.stroke()}},W=()=>{let t=m===`smog`?`168, 155, 126`:`226, 232, 238`;h&&(t=m===`smog`?`96, 88, 66`:`138, 150, 168`);for(let n of w){n.x+=n.speed,n.speed>0&&n.x-n.rw>e&&(n.x=-n.rw),n.speed<0&&n.x+n.rw<0&&(n.x=e+n.rw);let r=i.createRadialGradient(n.x,n.y,0,n.x,n.y,n.rw);r.addColorStop(0,`rgba(${t}, ${n.alpha})`),r.addColorStop(1,`rgba(${t}, 0)`),i.save(),i.translate(n.x,n.y),i.scale(1,n.rh/n.rw),i.translate(-n.x,-n.y),i.beginPath(),i.arc(n.x,n.y,n.rw,0,Math.PI*2),i.fillStyle=r,i.fill(),i.restore()}},G=()=>{for(let n of D)n.y+=n.speed,n.x+=Math.sin(A*.02+n.phase)*(.3+n.size*.08)+n.drift,n.rotation+=n.rotationSpeed,n.y-n.sprite.height>t&&(n.y=-n.sprite.height,n.x=Math.random()*e,n.phase=Math.random()*Math.PI*2,n.drift=(Math.random()-.5)*.4,n.opacity=.55+Math.random()*.45),n.x>e+20&&(n.x=-20),n.x<-20&&(n.x=e+20),i.save(),i.globalAlpha=n.opacity,i.translate(n.x,n.y),i.rotate(n.rotation),i.drawImage(n.sprite,-n.sprite.width/2,-n.sprite.height/2),i.restore()},K=()=>{if(O.length!==0)for(let n of O){let r=n.x,a=n.y;n.vy+=.16,n.x+=n.vx,n.y+=n.vy,i.beginPath(),i.moveTo(r,a),i.lineTo(n.x,n.y),i.strokeStyle=`rgba(225, 239, 250, ${n.opacity*.25})`,i.lineWidth=n.r*.65,i.stroke(),n.y+n.r>=t&&(n.bounces===0?(n.y=t-n.r,n.vy*=-.36,n.vx*=.72,n.bounces=1):(n.x=Math.random()*(e+180)-90,n.y=-10-Math.random()*t*.25,n.vx=-2.2-Math.random()*1.8,n.vy=8+Math.random()*5,n.bounces=0)),i.beginPath(),i.arc(n.x,n.y,n.r,0,Math.PI*2),i.fillStyle=`rgba(241, 248, 255, ${n.opacity})`,i.fill(),i.strokeStyle=`rgba(174, 207, 229, ${n.opacity*.75})`,i.lineWidth=.7,i.stroke(),i.beginPath(),i.arc(n.x-n.r*.3,n.y-n.r*.3,Math.max(.6,n.r*.24),0,Math.PI*2),i.fillStyle=`rgba(255, 255, 255, ${n.opacity})`,i.fill()}},q=()=>{if(k.length!==0)for(let n of k){n.x+=n.speed,n.wave+=.04,n.x-n.length>e&&(n.x=-n.length-Math.random()*e*.3,n.y=Math.random()*t);let r=Math.sin(n.wave)*8,a=n.x+n.length;if(i.beginPath(),i.moveTo(n.x,n.y),i.bezierCurveTo(n.x+n.length*.3,n.y+r,n.x+n.length*.7,n.y-r,a,n.y),i.strokeStyle=`rgba(235, 244, 250, ${n.alpha})`,i.lineWidth=n.width,i.lineCap=`round`,i.stroke(),n.length>100){let e=n.x+n.length*.58,t=n.y-r*.4;i.save(),i.translate(e,t),i.rotate(n.wave*2),i.beginPath(),i.ellipse(0,0,4,1.6,0,0,Math.PI*2),i.fillStyle=`rgba(91, 76, 52, ${n.alpha*1.6})`,i.fill(),i.restore()}}},J=()=>{if(a.lightning){if(A>=P){P=A+150+Math.random()*300,j=.5,M=9;let n=e*(.15+Math.random()*.7);N=E(n,t*.12,n+(Math.random()-.5)*e*.2,t*.92,60,6)}if(M>0){--M;let e=M/9;i.beginPath(),N.forEach(([e,t],n)=>n===0?i.moveTo(e,t):i.lineTo(e,t)),i.strokeStyle=`rgba(240, 246, 255, ${e})`,i.lineWidth=2.4,i.shadowColor=`#bcd7ff`,i.shadowBlur=16,i.stroke(),i.shadowBlur=0}j>.01&&(i.fillStyle=`rgba(226, 236, 255, ${j})`,i.fillRect(0,0,e,t),j*=.82)}},Y=()=>{if(a.haze<=0)return;let n=m===`smog`?`177, 164, 135`:`220, 226, 232`;h&&(n=m===`smog`?`82, 74, 54`:`116, 128, 145`),i.fillStyle=`rgba(${n}, ${a.haze})`,i.fillRect(0,0,e,t)},X=()=>{F=requestAnimationFrame(X),!I&&(A+=1,R(),V(),H(),W(),Y(),U(),G(),K(),q(),J())};return X(),()=>{cancelAnimationFrame(F),L()}},[h,m,t,e]),(0,u.jsxs)(`div`,{className:y.weatherBackground,style:{width:e,height:t},children:[(0,u.jsx)(`canvas`,{ref:f,className:y.canvas,style:{width:e,height:t}}),g&&(0,u.jsxs)(`div`,{className:y.loadingOverlay,children:[(0,u.jsx)(`div`,{className:y.loadingSpinner}),(0,u.jsx)(`span`,{children:`天气加载中…`})]})]})};exports.WeatherBackground=D,exports.default=D,exports.mapWmoCodeToWeatherType=p,exports.useLiveWeather=v;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("@cos-design/shared"),u=require("react/jsx-runtime");var d=39,f={0:`sunny`,1:`sunny`,2:`partlyCloudy`,3:`overcast`,45:`fog`,48:`fog`,51:`lightRain`,53:`moderateRain`,55:`moderateRain`,56:`lightRain`,57:`moderateRain`,61:`lightRain`,63:`moderateRain`,65:`heavyRain`,66:`lightRain`,67:`heavyRain`,71:`lightSnow`,73:`moderateSnow`,75:`heavySnow`,77:`lightSnow`,80:`lightRain`,81:`moderateRain`,82:`heavyRain`,85:`lightSnow`,86:`heavySnow`,95:`thunderstorm`,96:`hail`,99:`hail`},p=(e,t=0)=>{let n=f[e]??`overcast`;return(n===`sunny`||n===`partlyCloudy`||n===`overcast`)&&t>=d?`gale`:n},m={weather:null,status:`idle`,error:null,current:null},h={weather:null,status:`locating`,error:null,current:null},g={weather:null,status:`fetching`,error:null,current:null},_=e=>e!=null&&Number.isFinite(e.latitude)&&Number.isFinite(e.longitude),v=(e=!0,t)=>{let n=_(t),r=n?t.latitude:null,i=n?t.longitude:null,a=e?n?g:h:m,o=`${e}:${r},${i}`,[s,l]=(0,c.useState)(a),[u,d]=(0,c.useState)(o);return u!==o&&(d(o),l(t=>e&&t.weather?{...a,weather:t.weather,current:t.current}:a)),(0,c.useEffect)(()=>{if(!e)return;let t=!1,n=new AbortController,a=async(e,r)=>{try{let i=new URLSearchParams({latitude:String(e),longitude:String(r),current:`weather_code,wind_speed_10m,is_day`}),a=await fetch(`https://api.open-meteo.com/v1/forecast?${i}`,{signal:n.signal});if(!a.ok)throw Error(`Open-Meteo 请求失败(HTTP ${a.status})`);let o=await a.json(),s=Number(o?.current?.weather_code);if(Number.isNaN(s))throw Error(`Open-Meteo 返回数据缺少 weather_code`);let c=Number(o?.current?.wind_speed_10m??0);if(t)return;l({weather:p(s,c),status:`success`,error:null,current:{weatherCode:s,windSpeed:c,isDay:o?.current?.is_day===1,latitude:e,longitude:r}})}catch(e){if(t||e instanceof DOMException&&e.name===`AbortError`)return;l({weather:null,status:`error`,error:e instanceof Error?e.message:`天气获取失败`,current:null})}};return r!=null&&i!=null?(a(r,i),()=>{t=!0,n.abort()}):typeof navigator>`u`||!navigator.geolocation?(Promise.resolve().then(()=>{t||l({weather:null,status:`error`,error:`当前环境不支持定位`,current:null})}),()=>{t=!0}):(navigator.geolocation.getCurrentPosition(({coords:e})=>{t||(l(e=>({...e,status:`fetching`})),a(e.latitude,e.longitude))},e=>{t||l({weather:null,status:`error`,error:e.message||`定位失败`,current:null})},{timeout:1e4,maximumAge:600*1e3}),()=>{t=!0,n.abort()})},[e,r,i]),s};function y(e){let t=e.activeWeather===`gale`?7:1;for(let n of e.state.clouds)n.x+=n.speed*t,n.x-140*n.scale>e.width&&(n.x=-160*n.scale),e.ctx.drawImage(n.sprite,n.x+n.ox,n.y+n.oy)}function b(e){let t=e.fogSprite;if(!t||e.state.fogBanks.length===0)return;let{canvas:n,baseR:r}=t;for(let t of e.state.fogBanks)t.x+=t.speed,t.speed>0&&t.x-t.rw>e.width&&(t.x=-t.rw),t.speed<0&&t.x+t.rw<0&&(t.x=e.width+t.rw),e.ctx.save(),e.ctx.translate(t.x,t.y),e.ctx.scale(t.rw/r,t.rh/r),e.ctx.globalAlpha=t.alpha,e.ctx.drawImage(n,-r,-r),e.ctx.restore()}function x(e){if(e.cfg.haze<=0)return;let t=e.activeWeather===`smog`?`177, 164, 135`:`220, 226, 232`;e.activeNight&&(t=e.activeWeather===`smog`?`82, 74, 54`:`116, 128, 145`),e.ctx.fillStyle=`rgba(${t}, ${e.cfg.haze})`,e.ctx.fillRect(0,0,e.width,e.height)}function S(e,t,n,r,i,a){if(a<=0)return[[e,t],[n,r]];let o=(e+n)/2+(Math.random()-.5)*i,s=(t+r)/2,c=S(e,t,o,s,i*.55,a-1),l=S(o,s,n,r,i*.55,a-1);return[...c.slice(0,-1),...l]}function C(e){if(e.state.windStreaks.length!==0)for(let t of e.state.windStreaks){t.x+=t.speed,t.wave+=.04,t.x-t.length>e.width&&(t.x=-t.length-Math.random()*e.width*.3,t.y=Math.random()*e.height);let n=Math.sin(t.wave)*8,r=t.x+t.length;if(e.ctx.beginPath(),e.ctx.moveTo(t.x,t.y),e.ctx.bezierCurveTo(t.x+t.length*.3,t.y+n,t.x+t.length*.7,t.y-n,r,t.y),e.ctx.strokeStyle=`rgba(235, 244, 250, ${t.alpha})`,e.ctx.lineWidth=t.width,e.ctx.lineCap=`round`,e.ctx.stroke(),t.length>100){let r=t.x+t.length*.58,i=t.y-n*.4;e.ctx.save(),e.ctx.translate(r,i),e.ctx.rotate(t.wave*2),e.ctx.beginPath(),e.ctx.ellipse(0,0,4,1.6,0,0,Math.PI*2),e.ctx.fillStyle=`rgba(91, 76, 52, ${t.alpha*1.6})`,e.ctx.fill(),e.ctx.restore()}}}function w(e){if(e.cfg.lightning){if(e.state.t>=e.state.nextStrike){e.state.nextStrike=e.state.t+150+Math.random()*300,e.state.flashAlpha=.5,e.state.boltLife=9;let t=e.width*(.15+Math.random()*.7);e.state.boltPoints=S(t,e.height*.12,t+(Math.random()-.5)*e.width*.2,e.height*.92,60,6)}if(e.state.boltLife>0){--e.state.boltLife;let t=e.state.boltLife/9;e.ctx.beginPath(),e.state.boltPoints.forEach(([t,n],r)=>r===0?e.ctx.moveTo(t,n):e.ctx.lineTo(t,n)),e.ctx.strokeStyle=`rgba(240, 246, 255, ${t})`,e.ctx.lineWidth=2.4,e.ctx.shadowColor=`#bcd7ff`,e.ctx.shadowBlur=16,e.ctx.stroke(),e.ctx.shadowBlur=0}e.state.flashAlpha>.01&&(e.ctx.fillStyle=`rgba(226, 236, 255, ${e.state.flashAlpha})`,e.ctx.fillRect(0,0,e.width,e.height),e.state.flashAlpha*=.82)}}var T=3.2,E=e=>{let t=Math.ceil(e*2.8+4),n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`),i=t/2,a=t/2,o=9+Math.floor(Math.random()*5),s=Array.from({length:o},(t,n)=>{let r=n/o*Math.PI*2+(Math.random()-.5)*.22,s=e*(.72+Math.random()*.44);return{x:i+Math.cos(r)*s,y:a+Math.sin(r)*s}}),c=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2});r.beginPath();let l=c(s[s.length-1],s[0]);r.moveTo(l.x,l.y);for(let e=0;e<s.length;e++){let t=c(s[e],s[(e+1)%s.length]);r.quadraticCurveTo(s[e].x,s[e].y,t.x,t.y)}r.closePath();let u=i-e*.3,d=a-e*.34,f=r.createRadialGradient(u,d,e*.06,i,a,e*1.2);f.addColorStop(0,`rgba(255, 255, 255, 0.98)`),f.addColorStop(.42,`rgba(228, 241, 252, 0.96)`),f.addColorStop(.82,`rgba(176, 203, 224, 0.93)`),f.addColorStop(1,`rgba(130, 162, 188, 0.9)`),r.fillStyle=f,r.fill(),r.strokeStyle=`rgba(155, 190, 215, 0.62)`,r.lineWidth=Math.max(.45,e*.11),r.stroke();let p=1+Math.floor(Math.random()*2);for(let t=0;t<p;t++){let t=Math.random()*Math.PI*2,n=i+Math.cos(t)*e*(.28+Math.random()*.35),o=a+Math.sin(t)*e*(.28+Math.random()*.35);r.beginPath(),r.ellipse(n,o,e*(.14+Math.random()*.1),e*(.1+Math.random()*.08),t,0,Math.PI*2),r.fillStyle=`rgba(105, 135, 165, 0.28)`,r.fill()}if(Math.random()<.75){let t=Math.random()*Math.PI*2,n=i+Math.cos(t)*e*(.38+Math.random()*.28),o=a+Math.sin(t)*e*(.38+Math.random()*.28);r.beginPath(),r.arc(n,o,e*(.1+Math.random()*.08),0,Math.PI*2),r.fillStyle=`rgba(255, 255, 255, 0.55)`,r.fill()}return r.beginPath(),r.ellipse(i-e*.34,a-e*.36,e*.24,e*.17,-.35,0,Math.PI*2),r.fillStyle=`rgba(255, 255, 255, 0.78)`,r.fill(),n},D=(e=16)=>Array.from({length:e},()=>E(T)),O=e=>e[Math.floor(Math.random()*e.length)],k=(e,t,n,r,i=!0)=>{e.r=1.4+Math.random()**1.35*3.4,e.x=Math.random()*(t+260)-130+(Math.random()-.5)*40,e.y=i?-e.r-Math.random()*n*.55:Math.random()*n,e.vx=-1.2-Math.random()*4.8+(Math.random()-.5)*1.2,e.vy=5.5+Math.random()*11,e.bounces=0,e.opacity=.45+Math.random()*.55,e.delay=Math.floor(Math.random()*(i?110:45)),e.gravity=.11+Math.random()*.14,e.phase=Math.random()*Math.PI*2,e.gust=(Math.random()-.5)*1.4,e.maxBounces=+(Math.random()<.62),e.sprite=O(r),e.drawSize=e.r*2.8+4,e.rotation=Math.random()*Math.PI*2,e.rotationSpeed=(Math.random()-.5)*.06},A=(e,t,n)=>{let r={x:0,y:0,r:2,vx:0,vy:0,bounces:0,opacity:1,delay:0,gravity:.16,phase:0,gust:0,maxBounces:1,sprite:n[0],drawSize:9.6,rotation:0,rotationSpeed:0};return k(r,e,t,n,Math.random()<.72),r};function j(e){if(!e.cfg.rain)return;let{wind:t,alpha:n,splash:r}=e.cfg.rain;e.ctx.strokeStyle=`rgba(214, 228, 240, ${n})`,e.ctx.lineWidth=1.2,e.ctx.beginPath();for(let n of e.state.drops){let i=Math.hypot(t,n.speed)||1,a=t/i,o=n.speed/i;e.ctx.moveTo(n.x,n.y),e.ctx.lineTo(n.x+a*n.len,n.y+o*n.len),n.x+=t,n.y+=n.speed,n.y>e.height&&(r&&Math.random()<.3&&e.state.splashes.length<60&&e.state.splashes.push({x:n.x,r:1,alpha:.5}),n.y=-n.len,n.x=Math.random()*(e.width+160)-80)}e.ctx.stroke();for(let t=e.state.splashes.length-1;t>=0;t--){let n=e.state.splashes[t];if(n.r+=.8,n.alpha-=.035,n.alpha<=0){e.state.splashes.splice(t,1);continue}e.ctx.beginPath(),e.ctx.ellipse(n.x,e.height-3,n.r,n.r*.35,0,Math.PI,Math.PI*2),e.ctx.strokeStyle=`rgba(214, 228, 240, ${n.alpha})`,e.ctx.lineWidth=1,e.ctx.stroke()}}function M(e){for(let t of e.state.flakes){t.y+=t.speed,t.x+=Math.sin(e.state.t*.02+t.phase)*(.3+t.size*.08)+t.drift,t.rotation+=t.rotationSpeed,t.y-t.drawSize>e.height&&(t.y=-t.drawSize,t.x=Math.random()*e.width,t.phase=Math.random()*Math.PI*2,t.drift=(Math.random()-.5)*.4,t.opacity=.55+Math.random()*.45),t.x>e.width+20&&(t.x=-20),t.x<-20&&(t.x=e.width+20);let n=t.drawSize/2;e.ctx.save(),e.ctx.globalAlpha=t.opacity,e.ctx.translate(t.x,t.y),e.ctx.rotate(t.rotation),e.ctx.drawImage(t.sprite,-n,-n,t.drawSize,t.drawSize),e.ctx.restore()}}function N(e){if(e.state.hailstones.length===0)return;let t=e.state.hailPool;for(let n of e.state.hailstones){if(n.delay>0){--n.delay;continue}let r=n.x,i=n.y;if(n.vy+=n.gravity,n.vx+=n.gust*.004+(Math.random()-.5)*.06,n.x+=n.vx+Math.sin(e.state.t*.028+n.phase)*.35,n.y+=n.vy,e.ctx.beginPath(),e.ctx.moveTo(r,i),e.ctx.lineTo(n.x,n.y),e.ctx.strokeStyle=`rgba(225, 239, 250, ${n.opacity*.18})`,e.ctx.lineWidth=n.r*.35,e.ctx.stroke(),n.y+n.r>=e.height)if(n.bounces<n.maxBounces)n.y=e.height-n.r,n.vy*=-(.22+Math.random()*.28),n.vx=n.vx*(.55+Math.random()*.25)+(Math.random()-.5)*1.6,n.bounces+=1;else{k(n,e.width,e.height,t,!0);continue}let a=n.drawSize/2;n.rotation+=n.rotationSpeed,e.ctx.save(),e.ctx.globalAlpha=n.opacity,e.ctx.translate(n.x,n.y),e.ctx.rotate(n.rotation),e.ctx.drawImage(n.sprite,-a,-a,n.drawSize,n.drawSize),e.ctx.restore()}}function P(e){e.ctx.fillStyle=e.skyGradient,e.ctx.fillRect(0,0,e.width,e.height)}function F(e){if(e.state.stars.length!==0)for(let t of e.state.stars){let n=.35+(Math.sin(e.state.t*t.speed+t.phase)+1)*.325;e.ctx.beginPath(),e.ctx.arc(t.x,t.y,t.r,0,Math.PI*2),e.ctx.fillStyle=`rgba(226, 235, 255, ${n})`,e.ctx.fill()}}function I(e){let t=e.celestial;if(!t)return;let{ctx:n,sunX:r,sunY:i,state:a}=e,o=1+Math.sin(a.t*t.breathSpeed)*t.breathAmp,s=t.half*o,c=s*2;n.drawImage(t.canvas,r-s,i-s,c,c)}function L(e){if(e.activeNight){F(e),I(e);return}I(e)}var R={sunny:{sky:[`#4a9fe0`,`#c8e8fb`],sun:`full`,cloudCount:1,cloudColor:[255,255,255],cloudAlpha:.5,cloudSpread:.12,rain:null,fogBanks:0,haze:0,snowCount:0,lightning:!1},partlyCloudy:{sky:[`#5b9bd0`,`#cfe6f3`],sun:`soft`,cloudCount:5,cloudColor:[255,255,255],cloudAlpha:.85,cloudSpread:.22,rain:null,fogBanks:0,haze:0,snowCount:0,lightning:!1},overcast:{sky:[`#8a97a8`,`#c3cbd6`],sun:`none`,cloudCount:9,cloudColor:[100,116,139],cloudAlpha:.55,cloudSpread:.3,rain:null,fogBanks:0,haze:.06,snowCount:0,lightning:!1},lightRain:{sky:[`#6b7a8f`,`#9aa7b8`],sun:`none`,cloudCount:7,cloudColor:[71,85,105],cloudAlpha:.6,cloudSpread:.24,rain:{count:70,speed:7,wind:-.8,alpha:.4,splash:!1},fogBanks:0,haze:.04,snowCount:0,lightning:!1},moderateRain:{sky:[`#55637a`,`#7e8ba0`],sun:`none`,cloudCount:8,cloudColor:[51,65,85],cloudAlpha:.65,cloudSpread:.26,rain:{count:150,speed:10,wind:-1.5,alpha:.5,splash:!0},fogBanks:0,haze:.06,snowCount:0,lightning:!1},heavyRain:{sky:[`#3d4a5f`,`#5d6a80`],sun:`none`,cloudCount:9,cloudColor:[30,41,59],cloudAlpha:.7,cloudSpread:.3,rain:{count:280,speed:14,wind:-2.8,alpha:.55,splash:!0},fogBanks:0,haze:.1,snowCount:0,lightning:!1},thunderstorm:{sky:[`#252f42`,`#43506a`],sun:`none`,cloudCount:10,cloudColor:[15,23,42],cloudAlpha:.75,cloudSpread:.32,rain:{count:240,speed:13,wind:-2.2,alpha:.55,splash:!0},fogBanks:0,haze:.08,snowCount:0,lightning:!0},fog:{sky:[`#aab4bf`,`#d5dbe1`],sun:`dim`,cloudCount:3,cloudColor:[203,213,225],cloudAlpha:.4,cloudSpread:.2,rain:null,fogBanks:10,haze:.28,snowCount:0,lightning:!1},lightSnow:{sky:[`#aab8c8`,`#e2e8ef`],sun:`none`,cloudCount:5,cloudColor:[166,180,196],cloudAlpha:.45,cloudSpread:.22,rain:null,fogBanks:0,haze:.05,snowCount:70,lightning:!1},moderateSnow:{sky:[`#9fb0c4`,`#dde5ee`],sun:`none`,cloudCount:6,cloudColor:[148,163,184],cloudAlpha:.5,cloudSpread:.24,rain:null,fogBanks:0,haze:.08,snowCount:160,lightning:!1},heavySnow:{sky:[`#8495aa`,`#c7d1dc`],sun:`none`,cloudCount:9,cloudColor:[100,116,139],cloudAlpha:.62,cloudSpread:.3,rain:null,fogBanks:3,haze:.14,snowCount:300,lightning:!1},sleet:{sky:[`#78899e`,`#b8c5d2`],sun:`none`,cloudCount:8,cloudColor:[71,85,105],cloudAlpha:.6,cloudSpread:.28,rain:{count:100,speed:9,wind:-1.4,alpha:.42,splash:!0},fogBanks:0,haze:.09,snowCount:100,lightning:!1},hail:{sky:[`#46566c`,`#77889d`],sun:`none`,cloudCount:9,cloudColor:[30,41,59],cloudAlpha:.68,cloudSpread:.3,rain:{count:80,speed:11,wind:-2.5,alpha:.38,splash:!0},fogBanks:0,haze:.1,snowCount:0,lightning:!1},smog:{sky:[`#8f8b7e`,`#c5bca8`],sun:`dim`,cloudCount:3,cloudColor:[142,136,119],cloudAlpha:.35,cloudSpread:.2,rain:null,fogBanks:12,haze:.34,snowCount:0,lightning:!1},gale:{sky:[`#587087`,`#a6b5c2`],sun:`soft`,cloudCount:8,cloudColor:[203,213,225],cloudAlpha:.72,cloudSpread:.3,rain:null,fogBanks:0,haze:.04,snowCount:0,lightning:!1},snow:{sky:[`#9fb0c4`,`#dde5ee`],sun:`none`,cloudCount:6,cloudColor:[148,163,184],cloudAlpha:.5,cloudSpread:.24,rain:null,fogBanks:0,haze:.08,snowCount:160,lightning:!1}};R.snow=R.moderateSnow;var z={sunny:{sky:[`#0b1a33`,`#27476e`],stars:110},partlyCloudy:{sky:[`#0f1f38`,`#2c4666`],stars:60},overcast:{sky:[`#181f2a`,`#333e4e`],stars:0},lightRain:{sky:[`#151b26`,`#2b3442`],stars:0},moderateRain:{sky:[`#11161f`,`#242c3a`],stars:0},heavyRain:{sky:[`#0c1017`,`#1c232e`],stars:0},thunderstorm:{sky:[`#0a0e18`,`#192132`],stars:0},fog:{sky:[`#1c222b`,`#3a434e`],stars:0},lightSnow:{sky:[`#161e2b`,`#3a4656`],stars:20},moderateSnow:{sky:[`#131a26`,`#333f4f`],stars:8},heavySnow:{sky:[`#101623`,`#2a3545`],stars:0},sleet:{sky:[`#121924`,`#2c3745`],stars:0},hail:{sky:[`#0e141d`,`#26303e`],stars:0},smog:{sky:[`#1a1812`,`#38321f`],stars:0},gale:{sky:[`#101a26`,`#2e3d4d`],stars:30},snow:{sky:[`#131a26`,`#333f4f`],stars:8}};z.snow=z.moderateSnow;var B=([e,t,n])=>[Math.round(e*.3+18),Math.round(t*.3+24),Math.round(n*.3+42)];function V(e,t,n,r){let[i,a,o]=n,s=1/0,c=1/0,l=-1/0,u=-1/0;for(let n of t){let t=n.dx*e,r=n.dy*e,i=n.r*e;s=Math.min(s,t-i),c=Math.min(c,r-i),l=Math.max(l,t+i),u=Math.max(u,r+i)}let d=Math.floor(s-2),f=Math.floor(c-2),p=Math.ceil(l+2)-d,m=Math.ceil(u+2)-f,h=document.createElement(`canvas`);h.width=p,h.height=m;let g=h.getContext(`2d`);for(let n of t){let t=n.dx*e-d,s=n.dy*e-f,c=n.r*e,l=g.createRadialGradient(t,s,0,t,s,c);l.addColorStop(0,`rgba(${i}, ${a}, ${o}, ${r})`),l.addColorStop(1,`rgba(${i}, ${a}, ${o}, 0)`),g.beginPath(),g.arc(t,s,c,0,Math.PI*2),g.fillStyle=l,g.fill()}return{sprite:h,ox:d,oy:f}}function H(e,t,n,r,i){let a=.7+Math.random()*.9,o=4+Math.floor(Math.random()*3),s=Array.from({length:o},(e,t)=>({dx:(t-o/2)*26+(Math.random()-.5)*14,dy:(Math.random()-.5)*14,r:22+Math.random()*20})),{sprite:c,ox:l,oy:u}=V(a,s,r,i);return{x:Math.random()*(e+240)-120,y:t*.06+Math.random()*t*n,scale:a,speed:.12+Math.random()*.22,puffs:s,sprite:c,ox:l,oy:u}}function U(e,t=120){let n=t*2,r=document.createElement(`canvas`);r.width=n,r.height=n;let i=r.getContext(`2d`),a=i.createRadialGradient(t,t,0,t,t,t);return a.addColorStop(0,`rgba(${e}, 1)`),a.addColorStop(1,`rgba(${e}, 0)`),i.fillStyle=a,i.beginPath(),i.arc(t,t,t,0,Math.PI*2),i.fill(),{canvas:r,baseR:t}}function W(e,t){let n=e.sun;if(n===`none`)return null;let r=n===`full`?1:n===`soft`?.62:.32,i=t*(n===`full`?.72:n===`soft`?.62:.5),a=t*(n===`full`?7.2:n===`soft`?5.2:3.6),o=a;n===`full`&&(o=Math.max(o,1.55*t*5.5)),o=Math.ceil(o+2);let s=o*2,c=document.createElement(`canvas`);c.width=s,c.height=s;let l=c.getContext(`2d`),u=o,d=o;l.save(),l.globalCompositeOperation=`lighter`;let f=l.createRadialGradient(u,d,0,u,d,a);f.addColorStop(0,`rgba(255, 230, 170, ${.14*r})`),f.addColorStop(.22,`rgba(255, 210, 140, ${.07*r})`),f.addColorStop(.5,`rgba(255, 195, 120, ${.03*r})`),f.addColorStop(1,`rgba(255, 200, 130, 0)`),l.fillStyle=f,l.fillRect(0,0,s,s);let p=t*(n===`full`?3.4:2.6),m=l.createRadialGradient(u,d,i*.15,u,d,p);if(m.addColorStop(0,`rgba(255, 240, 200, ${.32*r})`),m.addColorStop(.4,`rgba(255, 220, 150, ${.16*r})`),m.addColorStop(.75,`rgba(255, 200, 120, ${.05*r})`),m.addColorStop(1,`rgba(255, 190, 110, 0)`),l.fillStyle=m,l.beginPath(),l.arc(u,d,p,0,Math.PI*2),l.fill(),n===`full`){l.translate(u,d),l.scale(1.55,.55);let e=l.createRadialGradient(0,0,0,0,0,t*5.5);e.addColorStop(0,`rgba(255, 225, 170, 0.08)`),e.addColorStop(.5,`rgba(255, 205, 140, 0.03)`),e.addColorStop(1,`rgba(255, 195, 130, 0)`),l.fillStyle=e,l.beginPath(),l.arc(0,0,t*5.5,0,Math.PI*2),l.fill()}l.restore();let h=i*2.05,g=l.createRadialGradient(u,d,0,u,d,h);g.addColorStop(0,`rgba(255, 245, 210, ${.7*r})`),g.addColorStop(.4,`rgba(255, 230, 170, ${.35*r})`),g.addColorStop(.75,`rgba(255, 210, 140, ${.1*r})`),g.addColorStop(1,`rgba(255, 200, 130, 0)`),l.fillStyle=g,l.beginPath(),l.arc(u,d,h,0,Math.PI*2),l.fill();let _=l.createRadialGradient(u,d,0,u,d,i);return n===`dim`?(_.addColorStop(0,`rgba(255, 240, 210, ${.5*r})`),_.addColorStop(.55,`rgba(255, 220, 170, ${.3*r})`),_.addColorStop(1,`rgba(255, 200, 140, 0)`)):(_.addColorStop(0,`rgba(255, 250, 230, ${.98*r})`),_.addColorStop(.4,`rgba(255, 240, 195, ${.92*r})`),_.addColorStop(.75,`rgba(255, 220, 150, ${.55*r})`),_.addColorStop(1,`rgba(255, 205, 130, 0)`)),l.fillStyle=_,l.beginPath(),l.arc(u,d,i,0,Math.PI*2),l.fill(),{canvas:c,half:o,breathSpeed:.018,breathAmp:.018}}function G(e,t,n){if(e.sun===`none`)return null;let r=t*.82,i=e.sun===`dim`,a=i?.45:1,o=r*(i?4.2:6.2),s=Math.ceil(Math.max(o,r*2.6,r*1.35)+2),c=s*2,l=document.createElement(`canvas`);l.width=c,l.height=c;let u=l.getContext(`2d`),d=s,f=s;u.save(),u.globalCompositeOperation=`lighter`;let p=u.createRadialGradient(d,f,0,d,f,o);p.addColorStop(0,`rgba(200, 215, 240, ${.16*a})`),p.addColorStop(.25,`rgba(170, 190, 225, ${.07*a})`),p.addColorStop(.55,`rgba(140, 165, 210, ${.025*a})`),p.addColorStop(1,`rgba(130, 155, 200, 0)`),u.fillStyle=p,u.fillRect(0,0,c,c);let m=r*2.6,h=u.createRadialGradient(d,f,r*.2,d,f,m);h.addColorStop(0,`rgba(230, 236, 248, ${.28*a})`),h.addColorStop(.45,`rgba(190, 205, 230, ${.12*a})`),h.addColorStop(1,`rgba(160, 180, 220, 0)`),u.fillStyle=h,u.beginPath(),u.arc(d,f,m,0,Math.PI*2),u.fill(),u.restore();let g=u.createRadialGradient(d-r*.28,f-r*.3,0,d,f,r);g.addColorStop(0,`rgba(236, 240, 246, ${.96*a})`),g.addColorStop(.45,`rgba(214, 220, 230, ${.94*a})`),g.addColorStop(.82,`rgba(186, 196, 212, ${.9*a})`),g.addColorStop(1,`rgba(160, 172, 192, ${.75*a})`),u.beginPath(),u.arc(d,f,r,0,Math.PI*2),u.fillStyle=g,u.fill(),u.save(),u.beginPath(),u.arc(d,f,r*.98,0,Math.PI*2),u.clip();for(let e of[{dx:-.18,dy:.12,rx:.38,ry:.28,a:.14},{dx:.22,dy:-.08,rx:.26,ry:.2,a:.11},{dx:.05,dy:.32,rx:.2,ry:.14,a:.09}]){let t=d+e.dx*r,n=f+e.dy*r,i=u.createRadialGradient(t,n,0,t,n,e.rx*r);i.addColorStop(0,`rgba(140, 152, 170, ${e.a*a})`),i.addColorStop(.65,`rgba(150, 162, 178, ${e.a*.45*a})`),i.addColorStop(1,`rgba(160, 170, 185, 0)`),u.fillStyle=i,u.beginPath(),u.ellipse(t,n,e.rx*r,e.ry*r,.35,0,Math.PI*2),u.fill()}for(let e of n){let t=d+e.dx*r,n=f+e.dy*r,i=e.r*r,o=u.createRadialGradient(t-i*.25,n-i*.3,0,t,n,i);o.addColorStop(0,`rgba(155, 168, 186, ${.22*a})`),o.addColorStop(.55,`rgba(145, 158, 176, ${.28*a})`),o.addColorStop(.85,`rgba(200, 210, 224, ${.12*a})`),o.addColorStop(1,`rgba(210, 218, 230, 0)`),u.fillStyle=o,u.beginPath(),u.arc(t,n,i,0,Math.PI*2),u.fill()}let _=u.createRadialGradient(d-r*.35,f-r*.38,0,d-r*.1,f-r*.1,r*.7);_.addColorStop(0,`rgba(255, 255, 255, ${.28*a})`),_.addColorStop(.45,`rgba(245, 248, 252, ${.08*a})`),_.addColorStop(1,`rgba(240, 244, 250, 0)`),u.fillStyle=_,u.beginPath(),u.arc(d,f,r,0,Math.PI*2),u.fill(),u.restore();let v=u.createRadialGradient(d,f,r*.72,d,f,r*1.35);return v.addColorStop(0,`rgba(210, 220, 235, 0)`),v.addColorStop(.55,`rgba(200, 212, 232, ${.1*a})`),v.addColorStop(1,`rgba(180, 195, 220, 0)`),u.fillStyle=v,u.beginPath(),u.arc(d,f,r*1.35,0,Math.PI*2),u.fill(),{canvas:l,half:s,breathSpeed:.012,breathAmp:.012}}var K=e=>{let t=Math.ceil(e*2+4),n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`),i=r.createRadialGradient(t/2,t/2,0,t/2,t/2,e+1);return i.addColorStop(0,`rgba(255, 255, 255, 1)`),i.addColorStop(.6,`rgba(255, 255, 255, 0.85)`),i.addColorStop(1,`rgba(255, 255, 255, 0)`),r.fillStyle=i,r.fillRect(0,0,t,t),n},q=e=>{let t=Math.ceil(e*2+6),n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`);r.translate(t/2,t/2),r.strokeStyle=`rgba(255, 255, 255, 0.95)`,r.lineCap=`round`,r.lineWidth=Math.max(e*.11,.7),r.shadowColor=`rgba(255, 255, 255, 0.5)`,r.shadowBlur=e*.25;let i=1+Math.floor(Math.random()*3),a=Array.from({length:i},()=>({pos:.3+Math.random()*.5,len:e*(.22+Math.random()*.34),angle:Math.PI/3*(.8+Math.random()*.45)})),o=Math.random()<.55,s=e*(.14+Math.random()*.12),c=Math.random()<.45,l=e*(.14+Math.random()*.14);for(let t=0;t<6;t++){r.save(),r.rotate(t*Math.PI/3),r.beginPath(),r.moveTo(0,0),r.lineTo(0,-e);for(let t of a){let n=-e*t.pos;r.moveTo(0,n),r.lineTo(Math.sin(t.angle)*t.len,n-Math.cos(t.angle)*t.len),r.moveTo(0,n),r.lineTo(-Math.sin(t.angle)*t.len,n-Math.cos(t.angle)*t.len)}o&&(r.moveTo(0,-e),r.lineTo(s*.7,-e-s*.5),r.moveTo(0,-e),r.lineTo(-s*.7,-e-s*.5)),r.stroke(),r.restore()}if(c){r.beginPath();for(let e=0;e<6;e++){let t=e*Math.PI/3-Math.PI/2,n=Math.cos(t)*l,i=Math.sin(t)*l;e===0?r.moveTo(n,i):r.lineTo(n,i)}r.closePath(),r.stroke()}return n},J=()=>({dots:[1.2,1.6,2,2.3].map(e=>K(e)),crystals:[2.6,3.2,3.8,4.4,5].map(e=>q(e*2.4))}),Y=e=>e[Math.floor(Math.random()*e.length)],X=(e,t,n,r)=>{let i=1+Math.random()**1.6*4.2,a=i>=2.4,o=Y(a?n.crystals:n.dots),s=a?i*4.8+6:i*2+4;return{x:Math.random()*e,y:r??Math.random()*t,size:i,speed:.4+i*.28+Math.random()*.4,phase:Math.random()*Math.PI*2,drift:(Math.random()-.5)*.4,rotation:Math.random()*Math.PI*2,rotationSpeed:(Math.random()-.5)*.025,opacity:.55+Math.random()*.45,sprite:o,drawSize:s}},ee=(e,t)=>t?e===`smog`?`96, 88, 66`:`138, 150, 168`:e===`smog`?`168, 155, 126`:`226, 232, 238`;function te(e){let{ctx:t,width:n,height:r,activeWeather:i,activeNight:a}=e,o=R[i],s=z[i],c=a?s.sky:o.sky,l=a?B(o.cloudColor):o.cloudColor,u=n*.72,d=r*.26,f=Math.min(n,r)*.09,p=t.createLinearGradient(0,0,0,r);p.addColorStop(0,c[0]),p.addColorStop(1,c[1]);let m=a?Array.from({length:s.stars},()=>({x:Math.random()*n,y:Math.random()*r*.72,r:.4+Math.random()*1.1,phase:Math.random()*Math.PI*2,speed:.015+Math.random()*.035})):[],h=[{dx:-.32,dy:.08,r:.17},{dx:.24,dy:-.22,r:.12},{dx:.04,dy:.34,r:.1},{dx:.36,dy:.24,r:.07}],g=a?G(o,f,h):W(o,f),_=Array.from({length:o.cloudCount},()=>H(n,r,o.cloudSpread,l,o.cloudAlpha)),v=o.rain?Array.from({length:o.rain.count},()=>({x:Math.random()*(n+160)-80,y:Math.random()*r,len:8+Math.random()*10,speed:o.rain.speed*(.75+Math.random()*.5)})):[],y=[],b=Array.from({length:o.fogBanks},(e,t)=>({x:Math.random()*n,y:t/Math.max(o.fogBanks-1,1)*r*.9+r*.05,rw:n*(.25+Math.random()*.3),rh:r*(.08+Math.random()*.08),speed:(.1+Math.random()*.25)*(t%2==0?1:-1),alpha:.16+Math.random()*.14})),x=o.fogBanks>0?U(ee(i,a)):null,S=o.snowCount>0?J():null,C=S==null?[]:Array.from({length:o.snowCount},()=>X(n,r,S)),w=i===`hail`?D():null,T=w==null?[]:Array.from({length:145},()=>A(n,r,w)),E=i===`gale`?Array.from({length:46},()=>({x:Math.random()*n,y:Math.random()*r,length:45+Math.random()*130,speed:8+Math.random()*10,wave:Math.random()*Math.PI*2,alpha:.12+Math.random()*.3,width:.6+Math.random()*1.2})):[],O=[],k=120+Math.random()*240;return{sky:c,cloudRgb:l,cfg:o,sunX:u,sunY:d,sunR:f,skyGradient:p,celestial:g,fogSprite:x,state:{stars:m,moonCraters:h,clouds:_,drops:v,splashes:y,fogBanks:b,flakes:C,hailstones:T,hailPool:w??[],windStreaks:E,t:0,flashAlpha:0,boltLife:0,boltPoints:O,nextStrike:k}}}function Z(e,t){t&&(e.state.t+=1),P(e),L(e),y(e),b(e),x(e),j(e),M(e),N(e),C(e),w(e)}function ne(e){let{ctx:t,width:n,height:r,activeWeather:i,activeNight:a}=e,o={ctx:t,width:n,height:r,activeWeather:i,activeNight:a,...te(e)};if(typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches)return Z(o,!1),()=>void 0;let s=0,c=document.hidden,u=(0,l.bindVisibilityPause)(e=>{c=e}),d=()=>{s=requestAnimationFrame(d),!c&&Z(o,!0)};return d(),()=>{cancelAnimationFrame(s),u()}}var Q={weatherBackground:`cos-weatherBackground-Mnm22`,canvas:`cos-canvas-nvqMt`,loadingOverlay:`cos-loadingOverlay-O58B7`,loadingSpinner:`cos-loadingSpinner-NQ9yG`,"weather-loading-spin":`cos-weather-loading-spin-IPFWZ`},$=({width:e=800,height:t=450,weather:n=`sunny`,night:r=!1,live:i=!1,latitude:a,longitude:o,onLiveWeather:s,loading:l=!1})=>{let d=(0,c.useRef)(null),f=v(i,a!=null&&o!=null?{latitude:a,longitude:o}:void 0),p=i&&f.weather?f.weather:n,m=i&&f.current?!f.current.isDay:r,h=l||i&&(f.status===`locating`||f.status===`fetching`),g=(0,c.useRef)(s);return(0,c.useEffect)(()=>{g.current=s}),(0,c.useEffect)(()=>{f.weather&&g.current?.(f.weather)},[f.weather]),(0,c.useEffect)(()=>{let n=d.current;if(!n)return;let r=window.devicePixelRatio||1;n.width=e*r,n.height=t*r;let i=n.getContext(`2d`);if(i)return i.setTransform(r,0,0,r,0,0),ne({ctx:i,width:e,height:t,activeWeather:p,activeNight:m})},[m,p,t,e]),(0,u.jsxs)(`div`,{className:Q.weatherBackground,style:{width:e,height:t},children:[(0,u.jsx)(`canvas`,{ref:d,className:Q.canvas,style:{width:e,height:t},role:`img`,"aria-label":`天气背景:${p}${m?`(夜间)`:``}`}),h&&(0,u.jsxs)(`div`,{className:Q.loadingOverlay,role:`status`,"aria-live":`polite`,children:[(0,u.jsx)(`div`,{className:Q.loadingSpinner,"aria-hidden":!0}),(0,u.jsx)(`span`,{children:`天气加载中…`})]})]})};exports.WeatherBackground=$,exports.default=$,exports.mapWmoCodeToWeatherType=p,exports.useLiveWeather=v;
package/dist/index.js CHANGED
@@ -10,15 +10,15 @@ var o = 39, s = {
10
10
  45: "fog",
11
11
  48: "fog",
12
12
  51: "lightRain",
13
- 53: "lightRain",
13
+ 53: "moderateRain",
14
14
  55: "moderateRain",
15
- 56: "sleet",
16
- 57: "sleet",
15
+ 56: "lightRain",
16
+ 57: "moderateRain",
17
17
  61: "lightRain",
18
18
  63: "moderateRain",
19
19
  65: "heavyRain",
20
- 66: "sleet",
21
- 67: "sleet",
20
+ 66: "lightRain",
21
+ 67: "heavyRain",
22
22
  71: "lightSnow",
23
23
  73: "moderateSnow",
24
24
  75: "heavySnow",
@@ -29,8 +29,8 @@ var o = 39, s = {
29
29
  85: "lightSnow",
30
30
  86: "heavySnow",
31
31
  95: "thunderstorm",
32
- 96: "thunderstorm",
33
- 99: "thunderstorm"
32
+ 96: "hail",
33
+ 99: "hail"
34
34
  }, c = (e, t = 0) => {
35
35
  let n = s[e] ?? "overcast";
36
36
  return (n === "sunny" || n === "partlyCloudy" || n === "overcast") && t >= o ? "gale" : n;
@@ -125,13 +125,192 @@ var o = 39, s = {
125
125
  a,
126
126
  o
127
127
  ]), m;
128
- }, m = {
129
- weatherBackground: "cos-weatherBackground-Mnm22",
130
- canvas: "cos-canvas-nvqMt",
131
- loadingOverlay: "cos-loadingOverlay-O58B7",
132
- loadingSpinner: "cos-loadingSpinner-NQ9yG",
133
- "weather-loading-spin": "cos-weather-loading-spin-IPFWZ"
134
- }, h = {
128
+ };
129
+ //#endregion
130
+ //#region src/components/weatherBackground/scene/draw-atmosphere.ts
131
+ function m(e) {
132
+ let t = e.activeWeather === "gale" ? 7 : 1;
133
+ for (let n of e.state.clouds) n.x += n.speed * t, n.x - 140 * n.scale > e.width && (n.x = -160 * n.scale), e.ctx.drawImage(n.sprite, n.x + n.ox, n.y + n.oy);
134
+ }
135
+ function h(e) {
136
+ let t = e.fogSprite;
137
+ if (!t || e.state.fogBanks.length === 0) return;
138
+ let { canvas: n, baseR: r } = t;
139
+ for (let t of e.state.fogBanks) t.x += t.speed, t.speed > 0 && t.x - t.rw > e.width && (t.x = -t.rw), t.speed < 0 && t.x + t.rw < 0 && (t.x = e.width + t.rw), e.ctx.save(), e.ctx.translate(t.x, t.y), e.ctx.scale(t.rw / r, t.rh / r), e.ctx.globalAlpha = t.alpha, e.ctx.drawImage(n, -r, -r), e.ctx.restore();
140
+ }
141
+ function g(e) {
142
+ if (e.cfg.haze <= 0) return;
143
+ let t = e.activeWeather === "smog" ? "177, 164, 135" : "220, 226, 232";
144
+ e.activeNight && (t = e.activeWeather === "smog" ? "82, 74, 54" : "116, 128, 145"), e.ctx.fillStyle = `rgba(${t}, ${e.cfg.haze})`, e.ctx.fillRect(0, 0, e.width, e.height);
145
+ }
146
+ //#endregion
147
+ //#region src/components/weatherBackground/lightning.ts
148
+ function _(e, t, n, r, i, a) {
149
+ if (a <= 0) return [[e, t], [n, r]];
150
+ let o = (e + n) / 2 + (Math.random() - .5) * i, s = (t + r) / 2, c = _(e, t, o, s, i * .55, a - 1), l = _(o, s, n, r, i * .55, a - 1);
151
+ return [...c.slice(0, -1), ...l];
152
+ }
153
+ //#endregion
154
+ //#region src/components/weatherBackground/scene/draw-effects.ts
155
+ function v(e) {
156
+ if (e.state.windStreaks.length !== 0) for (let t of e.state.windStreaks) {
157
+ t.x += t.speed, t.wave += .04, t.x - t.length > e.width && (t.x = -t.length - Math.random() * e.width * .3, t.y = Math.random() * e.height);
158
+ let n = Math.sin(t.wave) * 8, r = t.x + t.length;
159
+ if (e.ctx.beginPath(), e.ctx.moveTo(t.x, t.y), e.ctx.bezierCurveTo(t.x + t.length * .3, t.y + n, t.x + t.length * .7, t.y - n, r, t.y), e.ctx.strokeStyle = `rgba(235, 244, 250, ${t.alpha})`, e.ctx.lineWidth = t.width, e.ctx.lineCap = "round", e.ctx.stroke(), t.length > 100) {
160
+ let r = t.x + t.length * .58, i = t.y - n * .4;
161
+ e.ctx.save(), e.ctx.translate(r, i), e.ctx.rotate(t.wave * 2), e.ctx.beginPath(), e.ctx.ellipse(0, 0, 4, 1.6, 0, 0, Math.PI * 2), e.ctx.fillStyle = `rgba(91, 76, 52, ${t.alpha * 1.6})`, e.ctx.fill(), e.ctx.restore();
162
+ }
163
+ }
164
+ }
165
+ function y(e) {
166
+ if (e.cfg.lightning) {
167
+ if (e.state.t >= e.state.nextStrike) {
168
+ e.state.nextStrike = e.state.t + 150 + Math.random() * 300, e.state.flashAlpha = .5, e.state.boltLife = 9;
169
+ let t = e.width * (.15 + Math.random() * .7);
170
+ e.state.boltPoints = _(t, e.height * .12, t + (Math.random() - .5) * e.width * .2, e.height * .92, 60, 6);
171
+ }
172
+ if (e.state.boltLife > 0) {
173
+ --e.state.boltLife;
174
+ let t = e.state.boltLife / 9;
175
+ e.ctx.beginPath(), e.state.boltPoints.forEach(([t, n], r) => r === 0 ? e.ctx.moveTo(t, n) : e.ctx.lineTo(t, n)), e.ctx.strokeStyle = `rgba(240, 246, 255, ${t})`, e.ctx.lineWidth = 2.4, e.ctx.shadowColor = "#bcd7ff", e.ctx.shadowBlur = 16, e.ctx.stroke(), e.ctx.shadowBlur = 0;
176
+ }
177
+ e.state.flashAlpha > .01 && (e.ctx.fillStyle = `rgba(226, 236, 255, ${e.state.flashAlpha})`, e.ctx.fillRect(0, 0, e.width, e.height), e.state.flashAlpha *= .82);
178
+ }
179
+ }
180
+ //#endregion
181
+ //#region src/components/weatherBackground/sprites/hail.ts
182
+ var b = 3.2, x = (e) => {
183
+ let t = Math.ceil(e * 2.8 + 4), n = document.createElement("canvas");
184
+ n.width = t, n.height = t;
185
+ let r = n.getContext("2d"), i = t / 2, a = t / 2, o = 9 + Math.floor(Math.random() * 5), s = Array.from({ length: o }, (t, n) => {
186
+ let r = n / o * Math.PI * 2 + (Math.random() - .5) * .22, s = e * (.72 + Math.random() * .44);
187
+ return {
188
+ x: i + Math.cos(r) * s,
189
+ y: a + Math.sin(r) * s
190
+ };
191
+ }), c = (e, t) => ({
192
+ x: (e.x + t.x) / 2,
193
+ y: (e.y + t.y) / 2
194
+ });
195
+ r.beginPath();
196
+ let l = c(s[s.length - 1], s[0]);
197
+ r.moveTo(l.x, l.y);
198
+ for (let e = 0; e < s.length; e++) {
199
+ let t = c(s[e], s[(e + 1) % s.length]);
200
+ r.quadraticCurveTo(s[e].x, s[e].y, t.x, t.y);
201
+ }
202
+ r.closePath();
203
+ let u = i - e * .3, d = a - e * .34, f = r.createRadialGradient(u, d, e * .06, i, a, e * 1.2);
204
+ f.addColorStop(0, "rgba(255, 255, 255, 0.98)"), f.addColorStop(.42, "rgba(228, 241, 252, 0.96)"), f.addColorStop(.82, "rgba(176, 203, 224, 0.93)"), f.addColorStop(1, "rgba(130, 162, 188, 0.9)"), r.fillStyle = f, r.fill(), r.strokeStyle = "rgba(155, 190, 215, 0.62)", r.lineWidth = Math.max(.45, e * .11), r.stroke();
205
+ let p = 1 + Math.floor(Math.random() * 2);
206
+ for (let t = 0; t < p; t++) {
207
+ let t = Math.random() * Math.PI * 2, n = i + Math.cos(t) * e * (.28 + Math.random() * .35), o = a + Math.sin(t) * e * (.28 + Math.random() * .35);
208
+ r.beginPath(), r.ellipse(n, o, e * (.14 + Math.random() * .1), e * (.1 + Math.random() * .08), t, 0, Math.PI * 2), r.fillStyle = "rgba(105, 135, 165, 0.28)", r.fill();
209
+ }
210
+ if (Math.random() < .75) {
211
+ let t = Math.random() * Math.PI * 2, n = i + Math.cos(t) * e * (.38 + Math.random() * .28), o = a + Math.sin(t) * e * (.38 + Math.random() * .28);
212
+ r.beginPath(), r.arc(n, o, e * (.1 + Math.random() * .08), 0, Math.PI * 2), r.fillStyle = "rgba(255, 255, 255, 0.55)", r.fill();
213
+ }
214
+ return r.beginPath(), r.ellipse(i - e * .34, a - e * .36, e * .24, e * .17, -.35, 0, Math.PI * 2), r.fillStyle = "rgba(255, 255, 255, 0.78)", r.fill(), n;
215
+ }, S = (e = 16) => Array.from({ length: e }, () => x(b)), C = (e) => e[Math.floor(Math.random() * e.length)], w = (e, t, n, r, i = !0) => {
216
+ e.r = 1.4 + Math.random() ** 1.35 * 3.4, e.x = Math.random() * (t + 260) - 130 + (Math.random() - .5) * 40, e.y = i ? -e.r - Math.random() * n * .55 : Math.random() * n, e.vx = -1.2 - Math.random() * 4.8 + (Math.random() - .5) * 1.2, e.vy = 5.5 + Math.random() * 11, e.bounces = 0, e.opacity = .45 + Math.random() * .55, e.delay = Math.floor(Math.random() * (i ? 110 : 45)), e.gravity = .11 + Math.random() * .14, e.phase = Math.random() * Math.PI * 2, e.gust = (Math.random() - .5) * 1.4, e.maxBounces = +(Math.random() < .62), e.sprite = C(r), e.drawSize = e.r * 2.8 + 4, e.rotation = Math.random() * Math.PI * 2, e.rotationSpeed = (Math.random() - .5) * .06;
217
+ }, T = (e, t, n) => {
218
+ let r = {
219
+ x: 0,
220
+ y: 0,
221
+ r: 2,
222
+ vx: 0,
223
+ vy: 0,
224
+ bounces: 0,
225
+ opacity: 1,
226
+ delay: 0,
227
+ gravity: .16,
228
+ phase: 0,
229
+ gust: 0,
230
+ maxBounces: 1,
231
+ sprite: n[0],
232
+ drawSize: 9.6,
233
+ rotation: 0,
234
+ rotationSpeed: 0
235
+ };
236
+ return w(r, e, t, n, Math.random() < .72), r;
237
+ };
238
+ //#endregion
239
+ //#region src/components/weatherBackground/scene/draw-precipitation.ts
240
+ function E(e) {
241
+ if (!e.cfg.rain) return;
242
+ let { wind: t, alpha: n, splash: r } = e.cfg.rain;
243
+ e.ctx.strokeStyle = `rgba(214, 228, 240, ${n})`, e.ctx.lineWidth = 1.2, e.ctx.beginPath();
244
+ for (let n of e.state.drops) {
245
+ let i = Math.hypot(t, n.speed) || 1, a = t / i, o = n.speed / i;
246
+ e.ctx.moveTo(n.x, n.y), e.ctx.lineTo(n.x + a * n.len, n.y + o * n.len), n.x += t, n.y += n.speed, n.y > e.height && (r && Math.random() < .3 && e.state.splashes.length < 60 && e.state.splashes.push({
247
+ x: n.x,
248
+ r: 1,
249
+ alpha: .5
250
+ }), n.y = -n.len, n.x = Math.random() * (e.width + 160) - 80);
251
+ }
252
+ e.ctx.stroke();
253
+ for (let t = e.state.splashes.length - 1; t >= 0; t--) {
254
+ let n = e.state.splashes[t];
255
+ if (n.r += .8, n.alpha -= .035, n.alpha <= 0) {
256
+ e.state.splashes.splice(t, 1);
257
+ continue;
258
+ }
259
+ e.ctx.beginPath(), e.ctx.ellipse(n.x, e.height - 3, n.r, n.r * .35, 0, Math.PI, Math.PI * 2), e.ctx.strokeStyle = `rgba(214, 228, 240, ${n.alpha})`, e.ctx.lineWidth = 1, e.ctx.stroke();
260
+ }
261
+ }
262
+ function D(e) {
263
+ for (let t of e.state.flakes) {
264
+ t.y += t.speed, t.x += Math.sin(e.state.t * .02 + t.phase) * (.3 + t.size * .08) + t.drift, t.rotation += t.rotationSpeed, t.y - t.drawSize > e.height && (t.y = -t.drawSize, t.x = Math.random() * e.width, t.phase = Math.random() * Math.PI * 2, t.drift = (Math.random() - .5) * .4, t.opacity = .55 + Math.random() * .45), t.x > e.width + 20 && (t.x = -20), t.x < -20 && (t.x = e.width + 20);
265
+ let n = t.drawSize / 2;
266
+ e.ctx.save(), e.ctx.globalAlpha = t.opacity, e.ctx.translate(t.x, t.y), e.ctx.rotate(t.rotation), e.ctx.drawImage(t.sprite, -n, -n, t.drawSize, t.drawSize), e.ctx.restore();
267
+ }
268
+ }
269
+ function O(e) {
270
+ if (e.state.hailstones.length === 0) return;
271
+ let t = e.state.hailPool;
272
+ for (let n of e.state.hailstones) {
273
+ if (n.delay > 0) {
274
+ --n.delay;
275
+ continue;
276
+ }
277
+ let r = n.x, i = n.y;
278
+ if (n.vy += n.gravity, n.vx += n.gust * .004 + (Math.random() - .5) * .06, n.x += n.vx + Math.sin(e.state.t * .028 + n.phase) * .35, n.y += n.vy, e.ctx.beginPath(), e.ctx.moveTo(r, i), e.ctx.lineTo(n.x, n.y), e.ctx.strokeStyle = `rgba(225, 239, 250, ${n.opacity * .18})`, e.ctx.lineWidth = n.r * .35, e.ctx.stroke(), n.y + n.r >= e.height) if (n.bounces < n.maxBounces) n.y = e.height - n.r, n.vy *= -(.22 + Math.random() * .28), n.vx = n.vx * (.55 + Math.random() * .25) + (Math.random() - .5) * 1.6, n.bounces += 1;
279
+ else {
280
+ w(n, e.width, e.height, t, !0);
281
+ continue;
282
+ }
283
+ let a = n.drawSize / 2;
284
+ n.rotation += n.rotationSpeed, e.ctx.save(), e.ctx.globalAlpha = n.opacity, e.ctx.translate(n.x, n.y), e.ctx.rotate(n.rotation), e.ctx.drawImage(n.sprite, -a, -a, n.drawSize, n.drawSize), e.ctx.restore();
285
+ }
286
+ }
287
+ //#endregion
288
+ //#region src/components/weatherBackground/scene/draw-sky.ts
289
+ function k(e) {
290
+ e.ctx.fillStyle = e.skyGradient, e.ctx.fillRect(0, 0, e.width, e.height);
291
+ }
292
+ function A(e) {
293
+ if (e.state.stars.length !== 0) for (let t of e.state.stars) {
294
+ let n = .35 + (Math.sin(e.state.t * t.speed + t.phase) + 1) * .325;
295
+ e.ctx.beginPath(), e.ctx.arc(t.x, t.y, t.r, 0, Math.PI * 2), e.ctx.fillStyle = `rgba(226, 235, 255, ${n})`, e.ctx.fill();
296
+ }
297
+ }
298
+ function j(e) {
299
+ let t = e.celestial;
300
+ if (!t) return;
301
+ let { ctx: n, sunX: r, sunY: i, state: a } = e, o = 1 + Math.sin(a.t * t.breathSpeed) * t.breathAmp, s = t.half * o, c = s * 2;
302
+ n.drawImage(t.canvas, r - s, i - s, c, c);
303
+ }
304
+ function M(e) {
305
+ if (e.activeNight) {
306
+ A(e), j(e);
307
+ return;
308
+ }
309
+ j(e);
310
+ }
311
+ //#endregion
312
+ //#region src/components/weatherBackground/configs.ts
313
+ var N = {
135
314
  sunny: {
136
315
  sky: ["#4a9fe0", "#c8e8fb"],
137
316
  sun: "full",
@@ -440,7 +619,9 @@ var o = 39, s = {
440
619
  snowCount: 160,
441
620
  lightning: !1
442
621
  }
443
- }, g = {
622
+ };
623
+ N.snow = N.moderateSnow;
624
+ var P = {
444
625
  sunny: {
445
626
  sky: ["#0b1a33", "#27476e"],
446
627
  stars: 110
@@ -505,16 +686,150 @@ var o = 39, s = {
505
686
  sky: ["#131a26", "#333f4f"],
506
687
  stars: 8
507
688
  }
508
- }, _ = ([e, t, n]) => [
689
+ };
690
+ P.snow = P.moderateSnow;
691
+ var F = ([e, t, n]) => [
509
692
  Math.round(e * .3 + 18),
510
693
  Math.round(t * .3 + 24),
511
694
  Math.round(n * .3 + 42)
512
- ], v = (e) => {
695
+ ];
696
+ //#endregion
697
+ //#region src/components/weatherBackground/sprites/cloud.ts
698
+ function I(e, t, n, r) {
699
+ let [i, a, o] = n, s = Infinity, c = Infinity, l = -Infinity, u = -Infinity;
700
+ for (let n of t) {
701
+ let t = n.dx * e, r = n.dy * e, i = n.r * e;
702
+ s = Math.min(s, t - i), c = Math.min(c, r - i), l = Math.max(l, t + i), u = Math.max(u, r + i);
703
+ }
704
+ let d = Math.floor(s - 2), f = Math.floor(c - 2), p = Math.ceil(l + 2) - d, m = Math.ceil(u + 2) - f, h = document.createElement("canvas");
705
+ h.width = p, h.height = m;
706
+ let g = h.getContext("2d");
707
+ for (let n of t) {
708
+ let t = n.dx * e - d, s = n.dy * e - f, c = n.r * e, l = g.createRadialGradient(t, s, 0, t, s, c);
709
+ l.addColorStop(0, `rgba(${i}, ${a}, ${o}, ${r})`), l.addColorStop(1, `rgba(${i}, ${a}, ${o}, 0)`), g.beginPath(), g.arc(t, s, c, 0, Math.PI * 2), g.fillStyle = l, g.fill();
710
+ }
711
+ return {
712
+ sprite: h,
713
+ ox: d,
714
+ oy: f
715
+ };
716
+ }
717
+ function L(e, t, n, r, i) {
718
+ let a = .7 + Math.random() * .9, o = 4 + Math.floor(Math.random() * 3), s = Array.from({ length: o }, (e, t) => ({
719
+ dx: (t - o / 2) * 26 + (Math.random() - .5) * 14,
720
+ dy: (Math.random() - .5) * 14,
721
+ r: 22 + Math.random() * 20
722
+ })), { sprite: c, ox: l, oy: u } = I(a, s, r, i);
723
+ return {
724
+ x: Math.random() * (e + 240) - 120,
725
+ y: t * .06 + Math.random() * t * n,
726
+ scale: a,
727
+ speed: .12 + Math.random() * .22,
728
+ puffs: s,
729
+ sprite: c,
730
+ ox: l,
731
+ oy: u
732
+ };
733
+ }
734
+ function R(e, t = 120) {
735
+ let n = t * 2, r = document.createElement("canvas");
736
+ r.width = n, r.height = n;
737
+ let i = r.getContext("2d"), a = i.createRadialGradient(t, t, 0, t, t, t);
738
+ return a.addColorStop(0, `rgba(${e}, 1)`), a.addColorStop(1, `rgba(${e}, 0)`), i.fillStyle = a, i.beginPath(), i.arc(t, t, t, 0, Math.PI * 2), i.fill(), {
739
+ canvas: r,
740
+ baseR: t
741
+ };
742
+ }
743
+ //#endregion
744
+ //#region src/components/weatherBackground/sprites/celestial.ts
745
+ function z(e, t) {
746
+ let n = e.sun;
747
+ if (n === "none") return null;
748
+ let r = n === "full" ? 1 : n === "soft" ? .62 : .32, i = t * (n === "full" ? .72 : n === "soft" ? .62 : .5), a = t * (n === "full" ? 7.2 : n === "soft" ? 5.2 : 3.6), o = a;
749
+ n === "full" && (o = Math.max(o, 1.55 * t * 5.5)), o = Math.ceil(o + 2);
750
+ let s = o * 2, c = document.createElement("canvas");
751
+ c.width = s, c.height = s;
752
+ let l = c.getContext("2d"), u = o, d = o;
753
+ l.save(), l.globalCompositeOperation = "lighter";
754
+ let f = l.createRadialGradient(u, d, 0, u, d, a);
755
+ f.addColorStop(0, `rgba(255, 230, 170, ${.14 * r})`), f.addColorStop(.22, `rgba(255, 210, 140, ${.07 * r})`), f.addColorStop(.5, `rgba(255, 195, 120, ${.03 * r})`), f.addColorStop(1, "rgba(255, 200, 130, 0)"), l.fillStyle = f, l.fillRect(0, 0, s, s);
756
+ let p = t * (n === "full" ? 3.4 : 2.6), m = l.createRadialGradient(u, d, i * .15, u, d, p);
757
+ if (m.addColorStop(0, `rgba(255, 240, 200, ${.32 * r})`), m.addColorStop(.4, `rgba(255, 220, 150, ${.16 * r})`), m.addColorStop(.75, `rgba(255, 200, 120, ${.05 * r})`), m.addColorStop(1, "rgba(255, 190, 110, 0)"), l.fillStyle = m, l.beginPath(), l.arc(u, d, p, 0, Math.PI * 2), l.fill(), n === "full") {
758
+ l.translate(u, d), l.scale(1.55, .55);
759
+ let e = l.createRadialGradient(0, 0, 0, 0, 0, t * 5.5);
760
+ e.addColorStop(0, "rgba(255, 225, 170, 0.08)"), e.addColorStop(.5, "rgba(255, 205, 140, 0.03)"), e.addColorStop(1, "rgba(255, 195, 130, 0)"), l.fillStyle = e, l.beginPath(), l.arc(0, 0, t * 5.5, 0, Math.PI * 2), l.fill();
761
+ }
762
+ l.restore();
763
+ let h = i * 2.05, g = l.createRadialGradient(u, d, 0, u, d, h);
764
+ g.addColorStop(0, `rgba(255, 245, 210, ${.7 * r})`), g.addColorStop(.4, `rgba(255, 230, 170, ${.35 * r})`), g.addColorStop(.75, `rgba(255, 210, 140, ${.1 * r})`), g.addColorStop(1, "rgba(255, 200, 130, 0)"), l.fillStyle = g, l.beginPath(), l.arc(u, d, h, 0, Math.PI * 2), l.fill();
765
+ let _ = l.createRadialGradient(u, d, 0, u, d, i);
766
+ return n === "dim" ? (_.addColorStop(0, `rgba(255, 240, 210, ${.5 * r})`), _.addColorStop(.55, `rgba(255, 220, 170, ${.3 * r})`), _.addColorStop(1, "rgba(255, 200, 140, 0)")) : (_.addColorStop(0, `rgba(255, 250, 230, ${.98 * r})`), _.addColorStop(.4, `rgba(255, 240, 195, ${.92 * r})`), _.addColorStop(.75, `rgba(255, 220, 150, ${.55 * r})`), _.addColorStop(1, "rgba(255, 205, 130, 0)")), l.fillStyle = _, l.beginPath(), l.arc(u, d, i, 0, Math.PI * 2), l.fill(), {
767
+ canvas: c,
768
+ half: o,
769
+ breathSpeed: .018,
770
+ breathAmp: .018
771
+ };
772
+ }
773
+ function B(e, t, n) {
774
+ if (e.sun === "none") return null;
775
+ let r = t * .82, i = e.sun === "dim", a = i ? .45 : 1, o = r * (i ? 4.2 : 6.2), s = Math.ceil(Math.max(o, r * 2.6, r * 1.35) + 2), c = s * 2, l = document.createElement("canvas");
776
+ l.width = c, l.height = c;
777
+ let u = l.getContext("2d"), d = s, f = s;
778
+ u.save(), u.globalCompositeOperation = "lighter";
779
+ let p = u.createRadialGradient(d, f, 0, d, f, o);
780
+ p.addColorStop(0, `rgba(200, 215, 240, ${.16 * a})`), p.addColorStop(.25, `rgba(170, 190, 225, ${.07 * a})`), p.addColorStop(.55, `rgba(140, 165, 210, ${.025 * a})`), p.addColorStop(1, "rgba(130, 155, 200, 0)"), u.fillStyle = p, u.fillRect(0, 0, c, c);
781
+ let m = r * 2.6, h = u.createRadialGradient(d, f, r * .2, d, f, m);
782
+ h.addColorStop(0, `rgba(230, 236, 248, ${.28 * a})`), h.addColorStop(.45, `rgba(190, 205, 230, ${.12 * a})`), h.addColorStop(1, "rgba(160, 180, 220, 0)"), u.fillStyle = h, u.beginPath(), u.arc(d, f, m, 0, Math.PI * 2), u.fill(), u.restore();
783
+ let g = u.createRadialGradient(d - r * .28, f - r * .3, 0, d, f, r);
784
+ g.addColorStop(0, `rgba(236, 240, 246, ${.96 * a})`), g.addColorStop(.45, `rgba(214, 220, 230, ${.94 * a})`), g.addColorStop(.82, `rgba(186, 196, 212, ${.9 * a})`), g.addColorStop(1, `rgba(160, 172, 192, ${.75 * a})`), u.beginPath(), u.arc(d, f, r, 0, Math.PI * 2), u.fillStyle = g, u.fill(), u.save(), u.beginPath(), u.arc(d, f, r * .98, 0, Math.PI * 2), u.clip();
785
+ for (let e of [
786
+ {
787
+ dx: -.18,
788
+ dy: .12,
789
+ rx: .38,
790
+ ry: .28,
791
+ a: .14
792
+ },
793
+ {
794
+ dx: .22,
795
+ dy: -.08,
796
+ rx: .26,
797
+ ry: .2,
798
+ a: .11
799
+ },
800
+ {
801
+ dx: .05,
802
+ dy: .32,
803
+ rx: .2,
804
+ ry: .14,
805
+ a: .09
806
+ }
807
+ ]) {
808
+ let t = d + e.dx * r, n = f + e.dy * r, i = u.createRadialGradient(t, n, 0, t, n, e.rx * r);
809
+ i.addColorStop(0, `rgba(140, 152, 170, ${e.a * a})`), i.addColorStop(.65, `rgba(150, 162, 178, ${e.a * .45 * a})`), i.addColorStop(1, "rgba(160, 170, 185, 0)"), u.fillStyle = i, u.beginPath(), u.ellipse(t, n, e.rx * r, e.ry * r, .35, 0, Math.PI * 2), u.fill();
810
+ }
811
+ for (let e of n) {
812
+ let t = d + e.dx * r, n = f + e.dy * r, i = e.r * r, o = u.createRadialGradient(t - i * .25, n - i * .3, 0, t, n, i);
813
+ o.addColorStop(0, `rgba(155, 168, 186, ${.22 * a})`), o.addColorStop(.55, `rgba(145, 158, 176, ${.28 * a})`), o.addColorStop(.85, `rgba(200, 210, 224, ${.12 * a})`), o.addColorStop(1, "rgba(210, 218, 230, 0)"), u.fillStyle = o, u.beginPath(), u.arc(t, n, i, 0, Math.PI * 2), u.fill();
814
+ }
815
+ let _ = u.createRadialGradient(d - r * .35, f - r * .38, 0, d - r * .1, f - r * .1, r * .7);
816
+ _.addColorStop(0, `rgba(255, 255, 255, ${.28 * a})`), _.addColorStop(.45, `rgba(245, 248, 252, ${.08 * a})`), _.addColorStop(1, "rgba(240, 244, 250, 0)"), u.fillStyle = _, u.beginPath(), u.arc(d, f, r, 0, Math.PI * 2), u.fill(), u.restore();
817
+ let v = u.createRadialGradient(d, f, r * .72, d, f, r * 1.35);
818
+ return v.addColorStop(0, "rgba(210, 220, 235, 0)"), v.addColorStop(.55, `rgba(200, 212, 232, ${.1 * a})`), v.addColorStop(1, "rgba(180, 195, 220, 0)"), u.fillStyle = v, u.beginPath(), u.arc(d, f, r * 1.35, 0, Math.PI * 2), u.fill(), {
819
+ canvas: l,
820
+ half: s,
821
+ breathSpeed: .012,
822
+ breathAmp: .012
823
+ };
824
+ }
825
+ //#endregion
826
+ //#region src/components/weatherBackground/sprites/snow.ts
827
+ var V = (e) => {
513
828
  let t = Math.ceil(e * 2 + 4), n = document.createElement("canvas");
514
829
  n.width = t, n.height = t;
515
830
  let r = n.getContext("2d"), i = r.createRadialGradient(t / 2, t / 2, 0, t / 2, t / 2, e + 1);
516
831
  return i.addColorStop(0, "rgba(255, 255, 255, 1)"), i.addColorStop(.6, "rgba(255, 255, 255, 0.85)"), i.addColorStop(1, "rgba(255, 255, 255, 0)"), r.fillStyle = i, r.fillRect(0, 0, t, t), n;
517
- }, y = (e) => {
832
+ }, H = (e) => {
518
833
  let t = Math.ceil(e * 2 + 6), n = document.createElement("canvas");
519
834
  n.width = t, n.height = t;
520
835
  let r = n.getContext("2d");
@@ -541,249 +856,198 @@ var o = 39, s = {
541
856
  r.closePath(), r.stroke();
542
857
  }
543
858
  return n;
544
- }, b = (e, t, n) => {
545
- let r = 1 + Math.random() ** 1.6 * 4.2, i = r >= 2.4;
859
+ }, U = () => ({
860
+ dots: [
861
+ 1.2,
862
+ 1.6,
863
+ 2,
864
+ 2.3
865
+ ].map((e) => V(e)),
866
+ crystals: [
867
+ 2.6,
868
+ 3.2,
869
+ 3.8,
870
+ 4.4,
871
+ 5
872
+ ].map((e) => H(e * 2.4))
873
+ }), W = (e) => e[Math.floor(Math.random() * e.length)], G = (e, t, n, r) => {
874
+ let i = 1 + Math.random() ** 1.6 * 4.2, a = i >= 2.4, o = W(a ? n.crystals : n.dots), s = a ? i * 4.8 + 6 : i * 2 + 4;
546
875
  return {
547
876
  x: Math.random() * e,
548
- y: n ?? Math.random() * t,
549
- size: r,
550
- speed: .4 + r * .28 + Math.random() * .4,
877
+ y: r ?? Math.random() * t,
878
+ size: i,
879
+ speed: .4 + i * .28 + Math.random() * .4,
551
880
  phase: Math.random() * Math.PI * 2,
552
881
  drift: (Math.random() - .5) * .4,
553
882
  rotation: Math.random() * Math.PI * 2,
554
883
  rotationSpeed: (Math.random() - .5) * .025,
555
884
  opacity: .55 + Math.random() * .45,
556
- sprite: i ? y(r * 2.4) : v(r)
885
+ sprite: o,
886
+ drawSize: s
557
887
  };
558
- }, x = (e, t, n, r, i, a) => {
559
- if (a <= 0) return [[e, t], [n, r]];
560
- let o = (e + n) / 2 + (Math.random() - .5) * i, s = (t + r) / 2, c = x(e, t, o, s, i * .55, a - 1), l = x(o, s, n, r, i * .55, a - 1);
561
- return [...c.slice(0, -1), ...l];
562
- }, S = ({ width: n = 800, height: o = 450, weather: s = "sunny", night: c = !1, live: l = !1, latitude: u, longitude: d, onLiveWeather: f, loading: v = !1 }) => {
563
- let y = t(null), S = p(l, u != null && d != null ? {
564
- latitude: u,
565
- longitude: d
566
- } : void 0), C = l && S.weather ? S.weather : s, w = l && S.current ? !S.current.isDay : c, T = v || l && (S.status === "locating" || S.status === "fetching"), E = t(f);
888
+ }, K = (e, t) => t ? e === "smog" ? "96, 88, 66" : "138, 150, 168" : e === "smog" ? "168, 155, 126" : "226, 232, 238";
889
+ function q(e) {
890
+ let { ctx: t, width: n, height: r, activeWeather: i, activeNight: a } = e, o = N[i], s = P[i], c = a ? s.sky : o.sky, l = a ? F(o.cloudColor) : o.cloudColor, u = n * .72, d = r * .26, f = Math.min(n, r) * .09, p = t.createLinearGradient(0, 0, 0, r);
891
+ p.addColorStop(0, c[0]), p.addColorStop(1, c[1]);
892
+ let m = a ? Array.from({ length: s.stars }, () => ({
893
+ x: Math.random() * n,
894
+ y: Math.random() * r * .72,
895
+ r: .4 + Math.random() * 1.1,
896
+ phase: Math.random() * Math.PI * 2,
897
+ speed: .015 + Math.random() * .035
898
+ })) : [], h = [
899
+ {
900
+ dx: -.32,
901
+ dy: .08,
902
+ r: .17
903
+ },
904
+ {
905
+ dx: .24,
906
+ dy: -.22,
907
+ r: .12
908
+ },
909
+ {
910
+ dx: .04,
911
+ dy: .34,
912
+ r: .1
913
+ },
914
+ {
915
+ dx: .36,
916
+ dy: .24,
917
+ r: .07
918
+ }
919
+ ], g = a ? B(o, f, h) : z(o, f), _ = Array.from({ length: o.cloudCount }, () => L(n, r, o.cloudSpread, l, o.cloudAlpha)), v = o.rain ? Array.from({ length: o.rain.count }, () => ({
920
+ x: Math.random() * (n + 160) - 80,
921
+ y: Math.random() * r,
922
+ len: 8 + Math.random() * 10,
923
+ speed: o.rain.speed * (.75 + Math.random() * .5)
924
+ })) : [], y = [], b = Array.from({ length: o.fogBanks }, (e, t) => ({
925
+ x: Math.random() * n,
926
+ y: t / Math.max(o.fogBanks - 1, 1) * r * .9 + r * .05,
927
+ rw: n * (.25 + Math.random() * .3),
928
+ rh: r * (.08 + Math.random() * .08),
929
+ speed: (.1 + Math.random() * .25) * (t % 2 == 0 ? 1 : -1),
930
+ alpha: .16 + Math.random() * .14
931
+ })), x = o.fogBanks > 0 ? R(K(i, a)) : null, C = o.snowCount > 0 ? U() : null, w = C == null ? [] : Array.from({ length: o.snowCount }, () => G(n, r, C)), E = i === "hail" ? S() : null, D = E == null ? [] : Array.from({ length: 145 }, () => T(n, r, E)), O = i === "gale" ? Array.from({ length: 46 }, () => ({
932
+ x: Math.random() * n,
933
+ y: Math.random() * r,
934
+ length: 45 + Math.random() * 130,
935
+ speed: 8 + Math.random() * 10,
936
+ wave: Math.random() * Math.PI * 2,
937
+ alpha: .12 + Math.random() * .3,
938
+ width: .6 + Math.random() * 1.2
939
+ })) : [], k = [], A = 120 + Math.random() * 240;
940
+ return {
941
+ sky: c,
942
+ cloudRgb: l,
943
+ cfg: o,
944
+ sunX: u,
945
+ sunY: d,
946
+ sunR: f,
947
+ skyGradient: p,
948
+ celestial: g,
949
+ fogSprite: x,
950
+ state: {
951
+ stars: m,
952
+ moonCraters: h,
953
+ clouds: _,
954
+ drops: v,
955
+ splashes: y,
956
+ fogBanks: b,
957
+ flakes: w,
958
+ hailstones: D,
959
+ hailPool: E ?? [],
960
+ windStreaks: O,
961
+ t: 0,
962
+ flashAlpha: 0,
963
+ boltLife: 0,
964
+ boltPoints: k,
965
+ nextStrike: A
966
+ }
967
+ };
968
+ }
969
+ //#endregion
970
+ //#region src/components/weatherBackground/scene/create-weather-scene.ts
971
+ function J(e, t) {
972
+ t && (e.state.t += 1), k(e), M(e), m(e), h(e), g(e), E(e), D(e), O(e), v(e), y(e);
973
+ }
974
+ function Y(e) {
975
+ let { ctx: t, width: n, height: i, activeWeather: a, activeNight: o } = e, s = {
976
+ ctx: t,
977
+ width: n,
978
+ height: i,
979
+ activeWeather: a,
980
+ activeNight: o,
981
+ ...q(e)
982
+ };
983
+ if (typeof window < "u" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return J(s, !1), () => void 0;
984
+ let c = 0, l = document.hidden, u = r((e) => {
985
+ l = e;
986
+ }), d = () => {
987
+ c = requestAnimationFrame(d), !l && J(s, !0);
988
+ };
989
+ return d(), () => {
990
+ cancelAnimationFrame(c), u();
991
+ };
992
+ }
993
+ var X = {
994
+ weatherBackground: "cos-weatherBackground-Mnm22",
995
+ canvas: "cos-canvas-nvqMt",
996
+ loadingOverlay: "cos-loadingOverlay-O58B7",
997
+ loadingSpinner: "cos-loadingSpinner-NQ9yG",
998
+ "weather-loading-spin": "cos-weather-loading-spin-IPFWZ"
999
+ }, Z = ({ width: n = 800, height: r = 450, weather: o = "sunny", night: s = !1, live: c = !1, latitude: l, longitude: u, onLiveWeather: d, loading: f = !1 }) => {
1000
+ let m = t(null), h = p(c, l != null && u != null ? {
1001
+ latitude: l,
1002
+ longitude: u
1003
+ } : void 0), g = c && h.weather ? h.weather : o, _ = c && h.current ? !h.current.isDay : s, v = f || c && (h.status === "locating" || h.status === "fetching"), y = t(d);
567
1004
  return e(() => {
568
- E.current = f;
1005
+ y.current = d;
569
1006
  }), e(() => {
570
- S.weather && E.current?.(S.weather);
571
- }, [S.weather]), e(() => {
572
- let e = y.current;
1007
+ h.weather && y.current?.(h.weather);
1008
+ }, [h.weather]), e(() => {
1009
+ let e = m.current;
573
1010
  if (!e) return;
574
1011
  let t = window.devicePixelRatio || 1;
575
- e.width = n * t, e.height = o * t;
1012
+ e.width = n * t, e.height = r * t;
576
1013
  let i = e.getContext("2d");
577
- if (!i) return;
578
- i.setTransform(t, 0, 0, t, 0, 0);
579
- let a = h[C], s = g[C], c = w ? s.sky : a.sky, l = w ? _(a.cloudColor) : a.cloudColor, u = n * .72, d = o * .26, f = Math.min(n, o) * .09, p = w ? Array.from({ length: s.stars }, () => ({
580
- x: Math.random() * n,
581
- y: Math.random() * o * .72,
582
- r: .4 + Math.random() * 1.1,
583
- phase: Math.random() * Math.PI * 2,
584
- speed: .015 + Math.random() * .035
585
- })) : [], m = [
586
- {
587
- dx: -.32,
588
- dy: .08,
589
- r: .17
590
- },
591
- {
592
- dx: .24,
593
- dy: -.22,
594
- r: .12
595
- },
596
- {
597
- dx: .04,
598
- dy: .34,
599
- r: .1
600
- },
601
- {
602
- dx: .36,
603
- dy: .24,
604
- r: .07
605
- }
606
- ], v = Array.from({ length: a.cloudCount }, () => {
607
- let e = .7 + Math.random() * .9, t = 4 + Math.floor(Math.random() * 3);
608
- return {
609
- x: Math.random() * (n + 240) - 120,
610
- y: o * .06 + Math.random() * o * a.cloudSpread,
611
- scale: e,
612
- speed: .12 + Math.random() * .22,
613
- puffs: Array.from({ length: t }, (e, n) => ({
614
- dx: (n - t / 2) * 26 + (Math.random() - .5) * 14,
615
- dy: (Math.random() - .5) * 14,
616
- r: 22 + Math.random() * 20
617
- }))
618
- };
619
- }), S = a.rain ? Array.from({ length: a.rain.count }, () => ({
620
- x: Math.random() * (n + 160) - 80,
621
- y: Math.random() * o,
622
- len: 8 + Math.random() * 10,
623
- speed: a.rain.speed * (.75 + Math.random() * .5)
624
- })) : [], T = [], E = Array.from({ length: a.fogBanks }, (e, t) => ({
625
- x: Math.random() * n,
626
- y: t / Math.max(a.fogBanks - 1, 1) * o * .9 + o * .05,
627
- rw: n * (.25 + Math.random() * .3),
628
- rh: o * (.08 + Math.random() * .08),
629
- speed: (.1 + Math.random() * .25) * (t % 2 == 0 ? 1 : -1),
630
- alpha: .16 + Math.random() * .14
631
- })), D = Array.from({ length: a.snowCount }, () => b(n, o)), O = C === "hail" ? Array.from({ length: 130 }, () => ({
632
- x: Math.random() * (n + 180) - 90,
633
- y: Math.random() * o,
634
- r: 1.8 + Math.random() * 3,
635
- vx: -2.2 - Math.random() * 1.8,
636
- vy: 8 + Math.random() * 5,
637
- bounces: 0,
638
- opacity: .65 + Math.random() * .35
639
- })) : [], k = C === "gale" ? Array.from({ length: 46 }, () => ({
640
- x: Math.random() * n,
641
- y: Math.random() * o,
642
- length: 45 + Math.random() * 130,
643
- speed: 8 + Math.random() * 10,
644
- wave: Math.random() * Math.PI * 2,
645
- alpha: .12 + Math.random() * .3,
646
- width: .6 + Math.random() * 1.2
647
- })) : [], A = 0, j = 0, M = 0, N = [], P = 120 + Math.random() * 240, F = 0, I = document.hidden, L = r((e) => {
648
- I = e;
649
- }), R = () => {
650
- let e = i.createLinearGradient(0, 0, 0, o);
651
- e.addColorStop(0, c[0]), e.addColorStop(1, c[1]), i.fillStyle = e, i.fillRect(0, 0, n, o);
652
- }, z = () => {
653
- for (let e of p) {
654
- let t = .35 + (Math.sin(A * e.speed + e.phase) + 1) * .325;
655
- i.beginPath(), i.arc(e.x, e.y, e.r, 0, Math.PI * 2), i.fillStyle = `rgba(226, 235, 255, ${t})`, i.fill();
656
- }
657
- }, B = () => {
658
- if (a.sun === "none") return;
659
- let e = f * .88, t = a.sun === "dim", r = i.createRadialGradient(u, d, 0, u, d, e * (t ? 1.8 : 2.8));
660
- r.addColorStop(0, `rgba(214, 226, 245, ${t ? .18 : .35})`), r.addColorStop(1, "rgba(214, 226, 245, 0)"), i.fillStyle = r, i.fillRect(0, 0, n, o);
661
- let s = t ? .5 : 1, c = i.createRadialGradient(u - e * .25, d - e * .25, 0, u, d, e);
662
- c.addColorStop(0, `rgba(245, 248, 252, ${s})`), c.addColorStop(1, `rgba(196, 208, 226, ${s})`), i.beginPath(), i.arc(u, d, e, 0, Math.PI * 2), i.fillStyle = c, i.fill();
663
- for (let t of m) i.beginPath(), i.arc(u + t.dx * e, d + t.dy * e, t.r * e, 0, Math.PI * 2), i.fillStyle = `rgba(170, 184, 206, ${s * .55})`, i.fill();
664
- }, V = () => {
665
- if (w) {
666
- z(), B();
667
- return;
668
- }
669
- if (a.sun === "none") return;
670
- if (a.sun === "full") {
671
- let e = 1 + Math.sin(A * .02) * .04, t = i.createRadialGradient(u, d, 0, u, d, f * 3.4 * e);
672
- t.addColorStop(0, "rgba(255, 236, 168, 0.9)"), t.addColorStop(.35, "rgba(255, 214, 112, 0.32)"), t.addColorStop(1, "rgba(255, 214, 112, 0)"), i.fillStyle = t, i.fillRect(0, 0, n, o), i.save(), i.translate(u, d), i.rotate(A * .003);
673
- for (let e = 0; e < 12; e++) {
674
- i.rotate(Math.PI / 6);
675
- let e = i.createLinearGradient(f * 1.2, 0, f * 2.4, 0);
676
- e.addColorStop(0, "rgba(255, 230, 150, 0.5)"), e.addColorStop(1, "rgba(255, 230, 150, 0)"), i.strokeStyle = e, i.lineWidth = 3, i.beginPath(), i.moveTo(f * 1.2, 0), i.lineTo(f * 2.4, 0), i.stroke();
677
- }
678
- i.restore();
679
- }
680
- if (a.sun === "soft") {
681
- let e = i.createRadialGradient(u, d, 0, u, d, f * 2.4);
682
- e.addColorStop(0, "rgba(255, 240, 190, 0.7)"), e.addColorStop(1, "rgba(255, 240, 190, 0)"), i.fillStyle = e, i.fillRect(0, 0, n, o);
683
- }
684
- let e = a.sun === "dim" ? .35 : 1, t = i.createRadialGradient(u - f * .2, d - f * .2, 0, u, d, f);
685
- t.addColorStop(0, `rgba(255, 250, 224, ${e})`), t.addColorStop(1, `rgba(255, 214, 102, ${e})`), i.beginPath(), i.arc(u, d, f, 0, Math.PI * 2), i.fillStyle = t, i.fill();
686
- }, H = () => {
687
- let [e, t, r] = l;
688
- for (let o of v) {
689
- o.x += o.speed * (C === "gale" ? 7 : 1), o.x - 140 * o.scale > n && (o.x = -160 * o.scale);
690
- for (let n of o.puffs) {
691
- let s = o.x + n.dx * o.scale, c = o.y + n.dy * o.scale, l = n.r * o.scale, u = i.createRadialGradient(s, c, 0, s, c, l);
692
- u.addColorStop(0, `rgba(${e}, ${t}, ${r}, ${a.cloudAlpha})`), u.addColorStop(1, `rgba(${e}, ${t}, ${r}, 0)`), i.beginPath(), i.arc(s, c, l, 0, Math.PI * 2), i.fillStyle = u, i.fill();
693
- }
694
- }
695
- }, U = () => {
696
- if (!a.rain) return;
697
- let { wind: e, alpha: t, splash: r } = a.rain;
698
- i.strokeStyle = `rgba(214, 228, 240, ${t})`, i.lineWidth = 1.2, i.beginPath();
699
- for (let t of S) {
700
- let a = Math.hypot(e, t.speed) || 1, s = e / a, c = t.speed / a;
701
- i.moveTo(t.x, t.y), i.lineTo(t.x + s * t.len, t.y + c * t.len), t.x += e, t.y += t.speed, t.y > o && (r && Math.random() < .3 && T.length < 60 && T.push({
702
- x: t.x,
703
- r: 1,
704
- alpha: .5
705
- }), t.y = -t.len, t.x = Math.random() * (n + 160) - 80);
706
- }
707
- i.stroke();
708
- for (let e = T.length - 1; e >= 0; e--) {
709
- let t = T[e];
710
- if (t.r += .8, t.alpha -= .035, t.alpha <= 0) {
711
- T.splice(e, 1);
712
- continue;
713
- }
714
- i.beginPath(), i.ellipse(t.x, o - 3, t.r, t.r * .35, 0, Math.PI, Math.PI * 2), i.strokeStyle = `rgba(214, 228, 240, ${t.alpha})`, i.lineWidth = 1, i.stroke();
715
- }
716
- }, W = () => {
717
- let e = C === "smog" ? "168, 155, 126" : "226, 232, 238";
718
- w && (e = C === "smog" ? "96, 88, 66" : "138, 150, 168");
719
- for (let t of E) {
720
- t.x += t.speed, t.speed > 0 && t.x - t.rw > n && (t.x = -t.rw), t.speed < 0 && t.x + t.rw < 0 && (t.x = n + t.rw);
721
- let r = i.createRadialGradient(t.x, t.y, 0, t.x, t.y, t.rw);
722
- r.addColorStop(0, `rgba(${e}, ${t.alpha})`), r.addColorStop(1, `rgba(${e}, 0)`), i.save(), i.translate(t.x, t.y), i.scale(1, t.rh / t.rw), i.translate(-t.x, -t.y), i.beginPath(), i.arc(t.x, t.y, t.rw, 0, Math.PI * 2), i.fillStyle = r, i.fill(), i.restore();
723
- }
724
- }, G = () => {
725
- for (let e of D) e.y += e.speed, e.x += Math.sin(A * .02 + e.phase) * (.3 + e.size * .08) + e.drift, e.rotation += e.rotationSpeed, e.y - e.sprite.height > o && (e.y = -e.sprite.height, e.x = Math.random() * n, e.phase = Math.random() * Math.PI * 2, e.drift = (Math.random() - .5) * .4, e.opacity = .55 + Math.random() * .45), e.x > n + 20 && (e.x = -20), e.x < -20 && (e.x = n + 20), i.save(), i.globalAlpha = e.opacity, i.translate(e.x, e.y), i.rotate(e.rotation), i.drawImage(e.sprite, -e.sprite.width / 2, -e.sprite.height / 2), i.restore();
726
- }, K = () => {
727
- if (O.length !== 0) for (let e of O) {
728
- let t = e.x, r = e.y;
729
- e.vy += .16, e.x += e.vx, e.y += e.vy, i.beginPath(), i.moveTo(t, r), i.lineTo(e.x, e.y), i.strokeStyle = `rgba(225, 239, 250, ${e.opacity * .25})`, i.lineWidth = e.r * .65, i.stroke(), e.y + e.r >= o && (e.bounces === 0 ? (e.y = o - e.r, e.vy *= -.36, e.vx *= .72, e.bounces = 1) : (e.x = Math.random() * (n + 180) - 90, e.y = -10 - Math.random() * o * .25, e.vx = -2.2 - Math.random() * 1.8, e.vy = 8 + Math.random() * 5, e.bounces = 0)), i.beginPath(), i.arc(e.x, e.y, e.r, 0, Math.PI * 2), i.fillStyle = `rgba(241, 248, 255, ${e.opacity})`, i.fill(), i.strokeStyle = `rgba(174, 207, 229, ${e.opacity * .75})`, i.lineWidth = .7, i.stroke(), i.beginPath(), i.arc(e.x - e.r * .3, e.y - e.r * .3, Math.max(.6, e.r * .24), 0, Math.PI * 2), i.fillStyle = `rgba(255, 255, 255, ${e.opacity})`, i.fill();
730
- }
731
- }, q = () => {
732
- if (k.length !== 0) for (let e of k) {
733
- e.x += e.speed, e.wave += .04, e.x - e.length > n && (e.x = -e.length - Math.random() * n * .3, e.y = Math.random() * o);
734
- let t = Math.sin(e.wave) * 8, r = e.x + e.length;
735
- if (i.beginPath(), i.moveTo(e.x, e.y), i.bezierCurveTo(e.x + e.length * .3, e.y + t, e.x + e.length * .7, e.y - t, r, e.y), i.strokeStyle = `rgba(235, 244, 250, ${e.alpha})`, i.lineWidth = e.width, i.lineCap = "round", i.stroke(), e.length > 100) {
736
- let n = e.x + e.length * .58, r = e.y - t * .4;
737
- i.save(), i.translate(n, r), i.rotate(e.wave * 2), i.beginPath(), i.ellipse(0, 0, 4, 1.6, 0, 0, Math.PI * 2), i.fillStyle = `rgba(91, 76, 52, ${e.alpha * 1.6})`, i.fill(), i.restore();
738
- }
739
- }
740
- }, J = () => {
741
- if (a.lightning) {
742
- if (A >= P) {
743
- P = A + 150 + Math.random() * 300, j = .5, M = 9;
744
- let e = n * (.15 + Math.random() * .7);
745
- N = x(e, o * .12, e + (Math.random() - .5) * n * .2, o * .92, 60, 6);
746
- }
747
- if (M > 0) {
748
- --M;
749
- let e = M / 9;
750
- i.beginPath(), N.forEach(([e, t], n) => n === 0 ? i.moveTo(e, t) : i.lineTo(e, t)), i.strokeStyle = `rgba(240, 246, 255, ${e})`, i.lineWidth = 2.4, i.shadowColor = "#bcd7ff", i.shadowBlur = 16, i.stroke(), i.shadowBlur = 0;
751
- }
752
- j > .01 && (i.fillStyle = `rgba(226, 236, 255, ${j})`, i.fillRect(0, 0, n, o), j *= .82);
753
- }
754
- }, Y = () => {
755
- if (a.haze <= 0) return;
756
- let e = C === "smog" ? "177, 164, 135" : "220, 226, 232";
757
- w && (e = C === "smog" ? "82, 74, 54" : "116, 128, 145"), i.fillStyle = `rgba(${e}, ${a.haze})`, i.fillRect(0, 0, n, o);
758
- }, X = () => {
759
- F = requestAnimationFrame(X), !I && (A += 1, R(), V(), H(), W(), Y(), U(), G(), K(), q(), J());
760
- };
761
- return X(), () => {
762
- cancelAnimationFrame(F), L();
763
- };
1014
+ if (i) return i.setTransform(t, 0, 0, t, 0, 0), Y({
1015
+ ctx: i,
1016
+ width: n,
1017
+ height: r,
1018
+ activeWeather: g,
1019
+ activeNight: _
1020
+ });
764
1021
  }, [
765
- w,
766
- C,
767
- o,
1022
+ _,
1023
+ g,
1024
+ r,
768
1025
  n
769
1026
  ]), /* @__PURE__ */ a("div", {
770
- className: m.weatherBackground,
1027
+ className: X.weatherBackground,
771
1028
  style: {
772
1029
  width: n,
773
- height: o
1030
+ height: r
774
1031
  },
775
1032
  children: [/* @__PURE__ */ i("canvas", {
776
- ref: y,
777
- className: m.canvas,
1033
+ ref: m,
1034
+ className: X.canvas,
778
1035
  style: {
779
1036
  width: n,
780
- height: o
781
- }
782
- }), T && /* @__PURE__ */ a("div", {
783
- className: m.loadingOverlay,
784
- children: [/* @__PURE__ */ i("div", { className: m.loadingSpinner }), /* @__PURE__ */ i("span", { children: "天气加载中…" })]
1037
+ height: r
1038
+ },
1039
+ role: "img",
1040
+ "aria-label": `天气背景:${g}${_ ? "(夜间)" : ""}`
1041
+ }), v && /* @__PURE__ */ a("div", {
1042
+ className: X.loadingOverlay,
1043
+ role: "status",
1044
+ "aria-live": "polite",
1045
+ children: [/* @__PURE__ */ i("div", {
1046
+ className: X.loadingSpinner,
1047
+ "aria-hidden": !0
1048
+ }), /* @__PURE__ */ i("span", { children: "天气加载中…" })]
785
1049
  })]
786
1050
  });
787
1051
  };
788
1052
  //#endregion
789
- export { S as WeatherBackground, S as default, c as mapWmoCodeToWeatherType, p as useLiveWeather };
1053
+ export { Z as WeatherBackground, Z as default, c as mapWmoCodeToWeatherType, p as useLiveWeather };
@@ -0,0 +1,9 @@
1
+ import { WeatherConfig, WeatherType } from './types';
2
+ export declare const CONFIGS: Record<WeatherType, WeatherConfig>;
3
+ /** 夜间天空渐变与可见星星数量(云越多星越少) */
4
+ export declare const NIGHT_CONFIGS: Record<WeatherType, {
5
+ sky: [string, string];
6
+ stars: number;
7
+ }>;
8
+ /** 夜间云色:整体压暗并偏冷蓝 */
9
+ export declare const toNightCloudColor: ([r, g, b]: [number, number, number]) => [number, number, number];
@@ -1,24 +1,5 @@
1
1
  import { default as React } from 'react';
2
- export type WeatherType = 'sunny' | 'partlyCloudy' | 'overcast' | 'lightRain' | 'moderateRain' | 'heavyRain' | 'thunderstorm' | 'fog' | 'lightSnow' | 'moderateSnow' | 'heavySnow' | 'sleet' | 'hail' | 'smog' | 'gale'
3
- /** @deprecated 请使用 moderateSnow */
4
- | 'snow';
5
- export interface WeatherBackgroundProps {
6
- width?: number;
7
- height?: number;
8
- /** 天气类型:sunny 大晴天 / partlyCloudy 多云 / overcast 阴天 / lightRain 小雨 / moderateRain 中雨 / heavyRain 大雨 / thunderstorm 雷阵雨 / fog 雾 / lightSnow 小雪 / moderateSnow 中雪 / heavySnow 大雪 / sleet 雨夹雪 / hail 冰雹 / smog 霾 / gale 大风 */
9
- weather?: WeatherType;
10
- /** 夜间模式:渲染深夜天空、月亮与星空;live 模式下自动按当地实际日夜覆盖此值 */
11
- night?: boolean;
12
- /** 接入 Open-Meteo 实况:自动定位并按真实天气渲染,定位或请求失败时回退到 weather */
13
- live?: boolean;
14
- /** live 模式查询纬度(-90 ~ 90),与 longitude 同时配置时跳过浏览器定位 */
15
- latitude?: number;
16
- /** live 模式查询经度(-180 ~ 180),与 latitude 同时配置时跳过浏览器定位 */
17
- longitude?: number;
18
- /** live 模式解析出真实天气后回调 */
19
- onLiveWeather?: (weather: WeatherType) => void;
20
- /** 外部受控 loading:在当前画面上叠加加载遮罩(live 模式定位/请求期间会自动显示,无需传入) */
21
- loading?: boolean;
22
- }
2
+ import { WeatherBackgroundProps } from './types';
3
+ export type { WeatherBackgroundProps, WeatherType } from './types';
23
4
  declare const WeatherBackground: React.FC<WeatherBackgroundProps>;
24
5
  export default WeatherBackground;
@@ -0,0 +1 @@
1
+ export declare function displaceBolt(x1: number, y1: number, x2: number, y2: number, rough: number, depth: number): [number, number][];
@@ -1,6 +1,6 @@
1
1
  import { WeatherType } from './index';
2
2
  export interface OpenMeteoCurrent {
3
- /** WMO 天气码 */
3
+ /** Open-Meteo 精简天气码(WMO WW 子集,非完整 4677) */
4
4
  weatherCode: number;
5
5
  /** 10 米风速(km/h) */
6
6
  windSpeed: number;
@@ -18,7 +18,7 @@ export interface LiveWeatherState {
18
18
  /** Open-Meteo 原始实况数据 */
19
19
  current: OpenMeteoCurrent | null;
20
20
  }
21
- /** WMO 天气码 → WeatherType;无降水且风速达强风时映射为大风 */
21
+ /** Open-Meteo / WMO 精简天气码 → WeatherType;无降水且风速达强风时映射为大风 */
22
22
  export declare const mapWmoCodeToWeatherType: (code: number, windSpeedKmh?: number) => WeatherType;
23
23
  export interface LiveWeatherCoords {
24
24
  latitude: number;
@@ -0,0 +1,2 @@
1
+ import { WeatherSceneParams } from '../types';
2
+ export declare function createWeatherScene(params: WeatherSceneParams): () => void;
@@ -0,0 +1,4 @@
1
+ import { WeatherSceneRuntime } from './runtime';
2
+ export declare function drawClouds(scene: WeatherSceneRuntime): void;
3
+ export declare function drawFog(scene: WeatherSceneRuntime): void;
4
+ export declare function drawHaze(scene: WeatherSceneRuntime): void;
@@ -0,0 +1,3 @@
1
+ import { WeatherSceneRuntime } from './runtime';
2
+ export declare function drawWind(scene: WeatherSceneRuntime): void;
3
+ export declare function drawLightning(scene: WeatherSceneRuntime): void;
@@ -0,0 +1,4 @@
1
+ import { WeatherSceneRuntime } from './runtime';
2
+ export declare function drawRain(scene: WeatherSceneRuntime): void;
3
+ export declare function drawSnow(scene: WeatherSceneRuntime): void;
4
+ export declare function drawHail(scene: WeatherSceneRuntime): void;
@@ -0,0 +1,4 @@
1
+ import { WeatherSceneRuntime } from './runtime';
2
+ export declare function drawSky(scene: WeatherSceneRuntime): void;
3
+ export declare function drawStars(scene: WeatherSceneRuntime): void;
4
+ export declare function drawSun(scene: WeatherSceneRuntime): void;
@@ -0,0 +1,15 @@
1
+ import { CelestialSprite, FogSprite, SceneState, WeatherConfig, WeatherSceneParams } from '../types';
2
+ export interface WeatherSceneLayout {
3
+ sky: [string, string];
4
+ cloudRgb: [number, number, number];
5
+ cfg: WeatherConfig;
6
+ sunX: number;
7
+ sunY: number;
8
+ sunR: number;
9
+ skyGradient: CanvasGradient;
10
+ celestial: CelestialSprite | null;
11
+ fogSprite: FogSprite | null;
12
+ }
13
+ export declare function createSceneState(params: WeatherSceneParams): WeatherSceneLayout & {
14
+ state: SceneState;
15
+ };
@@ -0,0 +1,21 @@
1
+ import { CelestialSprite, FogSprite, SceneState, WeatherConfig, WeatherType } from '../types';
2
+ export interface WeatherSceneRuntime {
3
+ ctx: CanvasRenderingContext2D;
4
+ width: number;
5
+ height: number;
6
+ activeWeather: WeatherType;
7
+ activeNight: boolean;
8
+ sky: [string, string];
9
+ cloudRgb: [number, number, number];
10
+ cfg: WeatherConfig;
11
+ sunX: number;
12
+ sunY: number;
13
+ sunR: number;
14
+ /** 缓存的天空线性渐变(整场不变) */
15
+ skyGradient: CanvasGradient;
16
+ /** 预渲染的日/月贴图,白天为太阳、夜间为月亮,sun==='none' 时为 null */
17
+ celestial: CelestialSprite | null;
18
+ /** 预渲染的雾团贴图,无雾时为 null */
19
+ fogSprite: FogSprite | null;
20
+ state: SceneState;
21
+ }
@@ -0,0 +1,11 @@
1
+ import { CelestialSprite, MoonCrater, WeatherConfig } from '../types';
2
+ /**
3
+ * 预渲染太阳贴图。原本每帧要创建 6+ 个径向渐变(散射 / 光冕 / 霾 / bloom / 日轮),
4
+ * 这里一次性烘焙到离屏 canvas,主循环只需按 breath 缩放绘制。
5
+ */
6
+ export declare function makeSunSprite(cfg: WeatherConfig, sunR: number): CelestialSprite | null;
7
+ /**
8
+ * 预渲染月亮贴图(含月光散射、月轮、月海、环形山、受光高光与软边 bloom)。
9
+ * sun==='none' 时不渲染月亮(与原逻辑一致)。
10
+ */
11
+ export declare function makeMoonSprite(cfg: WeatherConfig, sunR: number, moonCraters: MoonCrater[]): CelestialSprite | null;
@@ -0,0 +1,20 @@
1
+ import { Cloud, FogSprite } from '../types';
2
+ type Puff = {
3
+ dx: number;
4
+ dy: number;
5
+ r: number;
6
+ };
7
+ /**
8
+ * 预渲染单朵云。原本每帧要为每个 puff 创建径向渐变(阴天/雷暴可达 60 个/帧),
9
+ * 云的形状与颜色整场不变、仅横向平移,这里把 puffs 烘焙成一张贴图。
10
+ */
11
+ export declare function makeCloudSprite(scale: number, puffs: Puff[], rgb: [number, number, number], alpha: number): {
12
+ sprite: HTMLCanvasElement;
13
+ ox: number;
14
+ oy: number;
15
+ };
16
+ /** 组装带贴图的云对象(供 init-state 使用) */
17
+ export declare function makeCloud(width: number, height: number, cloudSpread: number, rgb: [number, number, number], alpha: number): Cloud;
18
+ /** 柔边圆雾贴图(alpha=1),绘制时按 bank 缩放并用 globalAlpha 叠加透明度 */
19
+ export declare function makeFogSprite(rgb: string, baseR?: number): FogSprite;
20
+ export {};
@@ -0,0 +1,5 @@
1
+ import { Hailstone } from '../types';
2
+ /** 预生成共享冰雹贴图池;reset 只换贴图引用,不再分配新 canvas */
3
+ export declare const createHailSpritePool: (count?: number) => HTMLCanvasElement[];
4
+ export declare const resetHailstone: (h: Hailstone, width: number, height: number, pool: HTMLCanvasElement[], spawnAbove?: boolean) => void;
5
+ export declare const makeHailstone: (width: number, height: number, pool: HTMLCanvasElement[]) => Hailstone;
@@ -0,0 +1,8 @@
1
+ import { Flake } from '../types';
2
+ export interface FlakeSpritePool {
3
+ dots: HTMLCanvasElement[];
4
+ crystals: HTMLCanvasElement[];
5
+ }
6
+ /** 预生成少量雪花贴图供粒子复用(大雪 300 片不再各自一张 canvas) */
7
+ export declare const createFlakeSpritePool: () => FlakeSpritePool;
8
+ export declare const makeFlake: (width: number, height: number, pool: FlakeSpritePool, y?: number) => Flake;
@@ -0,0 +1,170 @@
1
+ export type WeatherType = 'sunny' | 'partlyCloudy' | 'overcast' | 'lightRain' | 'moderateRain' | 'heavyRain' | 'thunderstorm' | 'fog' | 'lightSnow' | 'moderateSnow' | 'heavySnow' | 'sleet' | 'hail' | 'smog' | 'gale'
2
+ /** @deprecated 请使用 moderateSnow */
3
+ | 'snow';
4
+ export interface WeatherBackgroundProps {
5
+ width?: number;
6
+ height?: number;
7
+ /** 天气类型:sunny 大晴天 / partlyCloudy 多云 / overcast 阴天 / lightRain 小雨 / moderateRain 中雨 / heavyRain 大雨 / thunderstorm 雷阵雨 / fog 雾 / lightSnow 小雪 / moderateSnow 中雪 / heavySnow 大雪 / sleet 雨夹雪 / hail 冰雹 / smog 霾 / gale 大风 */
8
+ weather?: WeatherType;
9
+ /** 夜间模式:渲染深夜天空、月亮与星空;live 模式下自动按当地实际日夜覆盖此值 */
10
+ night?: boolean;
11
+ /** 接入 Open-Meteo 实况:自动定位并按真实天气渲染,定位或请求失败时回退到 weather */
12
+ live?: boolean;
13
+ /** live 模式查询纬度(-90 ~ 90),与 longitude 同时配置时跳过浏览器定位 */
14
+ latitude?: number;
15
+ /** live 模式查询经度(-180 ~ 180),与 latitude 同时配置时跳过浏览器定位 */
16
+ longitude?: number;
17
+ /** live 模式解析出真实天气后回调 */
18
+ onLiveWeather?: (weather: WeatherType) => void;
19
+ /** 外部受控 loading:在当前画面上叠加加载遮罩(live 模式定位/请求期间会自动显示,无需传入) */
20
+ loading?: boolean;
21
+ }
22
+ export interface WeatherConfig {
23
+ sky: [string, string];
24
+ sun: 'full' | 'soft' | 'dim' | 'none';
25
+ cloudCount: number;
26
+ cloudColor: [number, number, number];
27
+ cloudAlpha: number;
28
+ cloudSpread: number;
29
+ rain: {
30
+ count: number;
31
+ speed: number;
32
+ wind: number;
33
+ alpha: number;
34
+ splash: boolean;
35
+ } | null;
36
+ fogBanks: number;
37
+ haze: number;
38
+ snowCount: number;
39
+ lightning: boolean;
40
+ }
41
+ export interface Star {
42
+ x: number;
43
+ y: number;
44
+ r: number;
45
+ phase: number;
46
+ speed: number;
47
+ }
48
+ export interface Cloud {
49
+ x: number;
50
+ y: number;
51
+ scale: number;
52
+ speed: number;
53
+ puffs: {
54
+ dx: number;
55
+ dy: number;
56
+ r: number;
57
+ }[];
58
+ /** 预渲染贴图(puffs 已烘焙),每帧只平移绘制 */
59
+ sprite: HTMLCanvasElement;
60
+ /** 贴图左上角相对 cloud.x/cloud.y 的偏移 */
61
+ ox: number;
62
+ oy: number;
63
+ }
64
+ export interface Drop {
65
+ x: number;
66
+ y: number;
67
+ len: number;
68
+ speed: number;
69
+ }
70
+ export interface Splash {
71
+ x: number;
72
+ r: number;
73
+ alpha: number;
74
+ }
75
+ export interface FogBank {
76
+ x: number;
77
+ y: number;
78
+ rw: number;
79
+ rh: number;
80
+ speed: number;
81
+ alpha: number;
82
+ }
83
+ export interface Flake {
84
+ x: number;
85
+ y: number;
86
+ size: number;
87
+ speed: number;
88
+ phase: number;
89
+ drift: number;
90
+ rotation: number;
91
+ rotationSpeed: number;
92
+ opacity: number;
93
+ /** 来自共享贴图池 */
94
+ sprite: HTMLCanvasElement;
95
+ /** 绘制边长(贴图按此缩放) */
96
+ drawSize: number;
97
+ }
98
+ export interface Hailstone {
99
+ x: number;
100
+ y: number;
101
+ r: number;
102
+ vx: number;
103
+ vy: number;
104
+ bounces: number;
105
+ opacity: number;
106
+ /** 帧延迟:>0 时不渲染,用于打散同时出现的批次感 */
107
+ delay: number;
108
+ gravity: number;
109
+ phase: number;
110
+ gust: number;
111
+ maxBounces: number;
112
+ /** 来自共享贴图池 */
113
+ sprite: HTMLCanvasElement;
114
+ /** 绘制边长(贴图按此缩放) */
115
+ drawSize: number;
116
+ rotation: number;
117
+ rotationSpeed: number;
118
+ }
119
+ export interface WindStreak {
120
+ x: number;
121
+ y: number;
122
+ length: number;
123
+ speed: number;
124
+ wave: number;
125
+ alpha: number;
126
+ width: number;
127
+ }
128
+ export interface MoonCrater {
129
+ dx: number;
130
+ dy: number;
131
+ r: number;
132
+ }
133
+ /** 预渲染的日/月贴图,绘制时按 breath 轻微缩放 */
134
+ export interface CelestialSprite {
135
+ canvas: HTMLCanvasElement;
136
+ /** 贴图中心到边的半长 */
137
+ half: number;
138
+ breathSpeed: number;
139
+ breathAmp: number;
140
+ }
141
+ /** 预渲染的雾团贴图(alpha=1 的柔边圆),绘制时按 bank 缩放并叠加透明度 */
142
+ export interface FogSprite {
143
+ canvas: HTMLCanvasElement;
144
+ baseR: number;
145
+ }
146
+ export interface SceneState {
147
+ stars: Star[];
148
+ moonCraters: MoonCrater[];
149
+ clouds: Cloud[];
150
+ drops: Drop[];
151
+ splashes: Splash[];
152
+ fogBanks: FogBank[];
153
+ flakes: Flake[];
154
+ hailstones: Hailstone[];
155
+ /** 冰雹共享贴图池,落地回收时复用 */
156
+ hailPool: HTMLCanvasElement[];
157
+ windStreaks: WindStreak[];
158
+ t: number;
159
+ flashAlpha: number;
160
+ boltLife: number;
161
+ boltPoints: [number, number][];
162
+ nextStrike: number;
163
+ }
164
+ export interface WeatherSceneParams {
165
+ ctx: CanvasRenderingContext2D;
166
+ width: number;
167
+ height: number;
168
+ activeWeather: WeatherType;
169
+ activeNight: boolean;
170
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cos-design/weather-background",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "description": "WeatherBackground component from cos-design",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -52,6 +52,6 @@
52
52
  "registry": "https://registry.npmjs.org"
53
53
  },
54
54
  "dependencies": {
55
- "@cos-design/shared": "3.5.1"
55
+ "@cos-design/shared": "3.5.3"
56
56
  }
57
57
  }