@cos-design/weather-background 3.5.1
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/LICENSE +22 -0
- package/dist/index.cjs +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +789 -0
- package/dist/packages/shared/src/index.d.ts +3 -0
- package/dist/packages/weatherBackground/src/index.d.ts +5 -0
- package/dist/src/components/weatherBackground/index.d.ts +24 -0
- package/dist/src/components/weatherBackground/live-weather.d.ts +32 -0
- package/dist/src/vite-env.d.ts +39 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present jiaxiantao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +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;
|
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cos-weatherBackground-Mnm22{border-radius:12px;position:relative;overflow:hidden}.cos-canvas-nvqMt{display:block}.cos-loadingOverlay-O58B7{-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);color:#ffffffe0;pointer-events:none;background:#0c121c52;flex-direction:column;justify-content:center;align-items:center;gap:10px;font-size:13px;display:flex;position:absolute;inset:0}.cos-loadingSpinner-NQ9yG{border:3px solid #ffffff40;border-top-color:#ffffffeb;border-radius:50%;width:28px;height:28px;animation:.8s linear infinite cos-weather-loading-spin-IPFWZ}@keyframes cos-weather-loading-spin-IPFWZ{to{transform:rotate(360deg)}}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default } from './src/components/weatherBackground/index';
|
|
2
|
+
export { default as WeatherBackground } from './src/components/weatherBackground/index';
|
|
3
|
+
export type * from './src/components/weatherBackground/index';
|
|
4
|
+
export { mapWmoCodeToWeatherType, useLiveWeather } from './src/components/weatherBackground/live-weather';
|
|
5
|
+
export type { LiveWeatherCoords, LiveWeatherState, LiveWeatherStatus, OpenMeteoCurrent } from './src/components/weatherBackground/live-weather';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
import { useEffect as e, useRef as t, useState as n } from "react";
|
|
2
|
+
import { bindVisibilityPause as r } from "@cos-design/shared";
|
|
3
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
4
|
+
import './index.css';//#region src/components/weatherBackground/live-weather.ts
|
|
5
|
+
var o = 39, s = {
|
|
6
|
+
0: "sunny",
|
|
7
|
+
1: "sunny",
|
|
8
|
+
2: "partlyCloudy",
|
|
9
|
+
3: "overcast",
|
|
10
|
+
45: "fog",
|
|
11
|
+
48: "fog",
|
|
12
|
+
51: "lightRain",
|
|
13
|
+
53: "lightRain",
|
|
14
|
+
55: "moderateRain",
|
|
15
|
+
56: "sleet",
|
|
16
|
+
57: "sleet",
|
|
17
|
+
61: "lightRain",
|
|
18
|
+
63: "moderateRain",
|
|
19
|
+
65: "heavyRain",
|
|
20
|
+
66: "sleet",
|
|
21
|
+
67: "sleet",
|
|
22
|
+
71: "lightSnow",
|
|
23
|
+
73: "moderateSnow",
|
|
24
|
+
75: "heavySnow",
|
|
25
|
+
77: "lightSnow",
|
|
26
|
+
80: "lightRain",
|
|
27
|
+
81: "moderateRain",
|
|
28
|
+
82: "heavyRain",
|
|
29
|
+
85: "lightSnow",
|
|
30
|
+
86: "heavySnow",
|
|
31
|
+
95: "thunderstorm",
|
|
32
|
+
96: "thunderstorm",
|
|
33
|
+
99: "thunderstorm"
|
|
34
|
+
}, c = (e, t = 0) => {
|
|
35
|
+
let n = s[e] ?? "overcast";
|
|
36
|
+
return (n === "sunny" || n === "partlyCloudy" || n === "overcast") && t >= o ? "gale" : n;
|
|
37
|
+
}, l = {
|
|
38
|
+
weather: null,
|
|
39
|
+
status: "idle",
|
|
40
|
+
error: null,
|
|
41
|
+
current: null
|
|
42
|
+
}, u = {
|
|
43
|
+
weather: null,
|
|
44
|
+
status: "locating",
|
|
45
|
+
error: null,
|
|
46
|
+
current: null
|
|
47
|
+
}, d = {
|
|
48
|
+
weather: null,
|
|
49
|
+
status: "fetching",
|
|
50
|
+
error: null,
|
|
51
|
+
current: null
|
|
52
|
+
}, f = (e) => e != null && Number.isFinite(e.latitude) && Number.isFinite(e.longitude), p = (t = !0, r) => {
|
|
53
|
+
let i = f(r), a = i ? r.latitude : null, o = i ? r.longitude : null, s = t ? i ? d : u : l, p = `${t}:${a},${o}`, [m, h] = n(s), [g, _] = n(p);
|
|
54
|
+
return g !== p && (_(p), h((e) => t && e.weather ? {
|
|
55
|
+
...s,
|
|
56
|
+
weather: e.weather,
|
|
57
|
+
current: e.current
|
|
58
|
+
} : s)), e(() => {
|
|
59
|
+
if (!t) return;
|
|
60
|
+
let e = !1, n = new AbortController(), r = async (t, r) => {
|
|
61
|
+
try {
|
|
62
|
+
let i = new URLSearchParams({
|
|
63
|
+
latitude: String(t),
|
|
64
|
+
longitude: String(r),
|
|
65
|
+
current: "weather_code,wind_speed_10m,is_day"
|
|
66
|
+
}), a = await fetch(`https://api.open-meteo.com/v1/forecast?${i}`, { signal: n.signal });
|
|
67
|
+
if (!a.ok) throw Error(`Open-Meteo 请求失败(HTTP ${a.status})`);
|
|
68
|
+
let o = await a.json(), s = Number(o?.current?.weather_code);
|
|
69
|
+
if (Number.isNaN(s)) throw Error("Open-Meteo 返回数据缺少 weather_code");
|
|
70
|
+
let l = Number(o?.current?.wind_speed_10m ?? 0);
|
|
71
|
+
if (e) return;
|
|
72
|
+
h({
|
|
73
|
+
weather: c(s, l),
|
|
74
|
+
status: "success",
|
|
75
|
+
error: null,
|
|
76
|
+
current: {
|
|
77
|
+
weatherCode: s,
|
|
78
|
+
windSpeed: l,
|
|
79
|
+
isDay: o?.current?.is_day === 1,
|
|
80
|
+
latitude: t,
|
|
81
|
+
longitude: r
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
} catch (t) {
|
|
85
|
+
if (e || t instanceof DOMException && t.name === "AbortError") return;
|
|
86
|
+
h({
|
|
87
|
+
weather: null,
|
|
88
|
+
status: "error",
|
|
89
|
+
error: t instanceof Error ? t.message : "天气获取失败",
|
|
90
|
+
current: null
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return a != null && o != null ? (r(a, o), () => {
|
|
95
|
+
e = !0, n.abort();
|
|
96
|
+
}) : typeof navigator > "u" || !navigator.geolocation ? (Promise.resolve().then(() => {
|
|
97
|
+
e || h({
|
|
98
|
+
weather: null,
|
|
99
|
+
status: "error",
|
|
100
|
+
error: "当前环境不支持定位",
|
|
101
|
+
current: null
|
|
102
|
+
});
|
|
103
|
+
}), () => {
|
|
104
|
+
e = !0;
|
|
105
|
+
}) : (navigator.geolocation.getCurrentPosition(({ coords: t }) => {
|
|
106
|
+
e || (h((e) => ({
|
|
107
|
+
...e,
|
|
108
|
+
status: "fetching"
|
|
109
|
+
})), r(t.latitude, t.longitude));
|
|
110
|
+
}, (t) => {
|
|
111
|
+
e || h({
|
|
112
|
+
weather: null,
|
|
113
|
+
status: "error",
|
|
114
|
+
error: t.message || "定位失败",
|
|
115
|
+
current: null
|
|
116
|
+
});
|
|
117
|
+
}, {
|
|
118
|
+
timeout: 1e4,
|
|
119
|
+
maximumAge: 600 * 1e3
|
|
120
|
+
}), () => {
|
|
121
|
+
e = !0, n.abort();
|
|
122
|
+
});
|
|
123
|
+
}, [
|
|
124
|
+
t,
|
|
125
|
+
a,
|
|
126
|
+
o
|
|
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 = {
|
|
135
|
+
sunny: {
|
|
136
|
+
sky: ["#4a9fe0", "#c8e8fb"],
|
|
137
|
+
sun: "full",
|
|
138
|
+
cloudCount: 1,
|
|
139
|
+
cloudColor: [
|
|
140
|
+
255,
|
|
141
|
+
255,
|
|
142
|
+
255
|
|
143
|
+
],
|
|
144
|
+
cloudAlpha: .5,
|
|
145
|
+
cloudSpread: .12,
|
|
146
|
+
rain: null,
|
|
147
|
+
fogBanks: 0,
|
|
148
|
+
haze: 0,
|
|
149
|
+
snowCount: 0,
|
|
150
|
+
lightning: !1
|
|
151
|
+
},
|
|
152
|
+
partlyCloudy: {
|
|
153
|
+
sky: ["#5b9bd0", "#cfe6f3"],
|
|
154
|
+
sun: "soft",
|
|
155
|
+
cloudCount: 5,
|
|
156
|
+
cloudColor: [
|
|
157
|
+
255,
|
|
158
|
+
255,
|
|
159
|
+
255
|
|
160
|
+
],
|
|
161
|
+
cloudAlpha: .85,
|
|
162
|
+
cloudSpread: .22,
|
|
163
|
+
rain: null,
|
|
164
|
+
fogBanks: 0,
|
|
165
|
+
haze: 0,
|
|
166
|
+
snowCount: 0,
|
|
167
|
+
lightning: !1
|
|
168
|
+
},
|
|
169
|
+
overcast: {
|
|
170
|
+
sky: ["#8a97a8", "#c3cbd6"],
|
|
171
|
+
sun: "none",
|
|
172
|
+
cloudCount: 9,
|
|
173
|
+
cloudColor: [
|
|
174
|
+
100,
|
|
175
|
+
116,
|
|
176
|
+
139
|
|
177
|
+
],
|
|
178
|
+
cloudAlpha: .55,
|
|
179
|
+
cloudSpread: .3,
|
|
180
|
+
rain: null,
|
|
181
|
+
fogBanks: 0,
|
|
182
|
+
haze: .06,
|
|
183
|
+
snowCount: 0,
|
|
184
|
+
lightning: !1
|
|
185
|
+
},
|
|
186
|
+
lightRain: {
|
|
187
|
+
sky: ["#6b7a8f", "#9aa7b8"],
|
|
188
|
+
sun: "none",
|
|
189
|
+
cloudCount: 7,
|
|
190
|
+
cloudColor: [
|
|
191
|
+
71,
|
|
192
|
+
85,
|
|
193
|
+
105
|
|
194
|
+
],
|
|
195
|
+
cloudAlpha: .6,
|
|
196
|
+
cloudSpread: .24,
|
|
197
|
+
rain: {
|
|
198
|
+
count: 70,
|
|
199
|
+
speed: 7,
|
|
200
|
+
wind: -.8,
|
|
201
|
+
alpha: .4,
|
|
202
|
+
splash: !1
|
|
203
|
+
},
|
|
204
|
+
fogBanks: 0,
|
|
205
|
+
haze: .04,
|
|
206
|
+
snowCount: 0,
|
|
207
|
+
lightning: !1
|
|
208
|
+
},
|
|
209
|
+
moderateRain: {
|
|
210
|
+
sky: ["#55637a", "#7e8ba0"],
|
|
211
|
+
sun: "none",
|
|
212
|
+
cloudCount: 8,
|
|
213
|
+
cloudColor: [
|
|
214
|
+
51,
|
|
215
|
+
65,
|
|
216
|
+
85
|
|
217
|
+
],
|
|
218
|
+
cloudAlpha: .65,
|
|
219
|
+
cloudSpread: .26,
|
|
220
|
+
rain: {
|
|
221
|
+
count: 150,
|
|
222
|
+
speed: 10,
|
|
223
|
+
wind: -1.5,
|
|
224
|
+
alpha: .5,
|
|
225
|
+
splash: !0
|
|
226
|
+
},
|
|
227
|
+
fogBanks: 0,
|
|
228
|
+
haze: .06,
|
|
229
|
+
snowCount: 0,
|
|
230
|
+
lightning: !1
|
|
231
|
+
},
|
|
232
|
+
heavyRain: {
|
|
233
|
+
sky: ["#3d4a5f", "#5d6a80"],
|
|
234
|
+
sun: "none",
|
|
235
|
+
cloudCount: 9,
|
|
236
|
+
cloudColor: [
|
|
237
|
+
30,
|
|
238
|
+
41,
|
|
239
|
+
59
|
|
240
|
+
],
|
|
241
|
+
cloudAlpha: .7,
|
|
242
|
+
cloudSpread: .3,
|
|
243
|
+
rain: {
|
|
244
|
+
count: 280,
|
|
245
|
+
speed: 14,
|
|
246
|
+
wind: -2.8,
|
|
247
|
+
alpha: .55,
|
|
248
|
+
splash: !0
|
|
249
|
+
},
|
|
250
|
+
fogBanks: 0,
|
|
251
|
+
haze: .1,
|
|
252
|
+
snowCount: 0,
|
|
253
|
+
lightning: !1
|
|
254
|
+
},
|
|
255
|
+
thunderstorm: {
|
|
256
|
+
sky: ["#252f42", "#43506a"],
|
|
257
|
+
sun: "none",
|
|
258
|
+
cloudCount: 10,
|
|
259
|
+
cloudColor: [
|
|
260
|
+
15,
|
|
261
|
+
23,
|
|
262
|
+
42
|
|
263
|
+
],
|
|
264
|
+
cloudAlpha: .75,
|
|
265
|
+
cloudSpread: .32,
|
|
266
|
+
rain: {
|
|
267
|
+
count: 240,
|
|
268
|
+
speed: 13,
|
|
269
|
+
wind: -2.2,
|
|
270
|
+
alpha: .55,
|
|
271
|
+
splash: !0
|
|
272
|
+
},
|
|
273
|
+
fogBanks: 0,
|
|
274
|
+
haze: .08,
|
|
275
|
+
snowCount: 0,
|
|
276
|
+
lightning: !0
|
|
277
|
+
},
|
|
278
|
+
fog: {
|
|
279
|
+
sky: ["#aab4bf", "#d5dbe1"],
|
|
280
|
+
sun: "dim",
|
|
281
|
+
cloudCount: 3,
|
|
282
|
+
cloudColor: [
|
|
283
|
+
203,
|
|
284
|
+
213,
|
|
285
|
+
225
|
|
286
|
+
],
|
|
287
|
+
cloudAlpha: .4,
|
|
288
|
+
cloudSpread: .2,
|
|
289
|
+
rain: null,
|
|
290
|
+
fogBanks: 10,
|
|
291
|
+
haze: .28,
|
|
292
|
+
snowCount: 0,
|
|
293
|
+
lightning: !1
|
|
294
|
+
},
|
|
295
|
+
lightSnow: {
|
|
296
|
+
sky: ["#aab8c8", "#e2e8ef"],
|
|
297
|
+
sun: "none",
|
|
298
|
+
cloudCount: 5,
|
|
299
|
+
cloudColor: [
|
|
300
|
+
166,
|
|
301
|
+
180,
|
|
302
|
+
196
|
|
303
|
+
],
|
|
304
|
+
cloudAlpha: .45,
|
|
305
|
+
cloudSpread: .22,
|
|
306
|
+
rain: null,
|
|
307
|
+
fogBanks: 0,
|
|
308
|
+
haze: .05,
|
|
309
|
+
snowCount: 70,
|
|
310
|
+
lightning: !1
|
|
311
|
+
},
|
|
312
|
+
moderateSnow: {
|
|
313
|
+
sky: ["#9fb0c4", "#dde5ee"],
|
|
314
|
+
sun: "none",
|
|
315
|
+
cloudCount: 6,
|
|
316
|
+
cloudColor: [
|
|
317
|
+
148,
|
|
318
|
+
163,
|
|
319
|
+
184
|
|
320
|
+
],
|
|
321
|
+
cloudAlpha: .5,
|
|
322
|
+
cloudSpread: .24,
|
|
323
|
+
rain: null,
|
|
324
|
+
fogBanks: 0,
|
|
325
|
+
haze: .08,
|
|
326
|
+
snowCount: 160,
|
|
327
|
+
lightning: !1
|
|
328
|
+
},
|
|
329
|
+
heavySnow: {
|
|
330
|
+
sky: ["#8495aa", "#c7d1dc"],
|
|
331
|
+
sun: "none",
|
|
332
|
+
cloudCount: 9,
|
|
333
|
+
cloudColor: [
|
|
334
|
+
100,
|
|
335
|
+
116,
|
|
336
|
+
139
|
|
337
|
+
],
|
|
338
|
+
cloudAlpha: .62,
|
|
339
|
+
cloudSpread: .3,
|
|
340
|
+
rain: null,
|
|
341
|
+
fogBanks: 3,
|
|
342
|
+
haze: .14,
|
|
343
|
+
snowCount: 300,
|
|
344
|
+
lightning: !1
|
|
345
|
+
},
|
|
346
|
+
sleet: {
|
|
347
|
+
sky: ["#78899e", "#b8c5d2"],
|
|
348
|
+
sun: "none",
|
|
349
|
+
cloudCount: 8,
|
|
350
|
+
cloudColor: [
|
|
351
|
+
71,
|
|
352
|
+
85,
|
|
353
|
+
105
|
|
354
|
+
],
|
|
355
|
+
cloudAlpha: .6,
|
|
356
|
+
cloudSpread: .28,
|
|
357
|
+
rain: {
|
|
358
|
+
count: 100,
|
|
359
|
+
speed: 9,
|
|
360
|
+
wind: -1.4,
|
|
361
|
+
alpha: .42,
|
|
362
|
+
splash: !0
|
|
363
|
+
},
|
|
364
|
+
fogBanks: 0,
|
|
365
|
+
haze: .09,
|
|
366
|
+
snowCount: 100,
|
|
367
|
+
lightning: !1
|
|
368
|
+
},
|
|
369
|
+
hail: {
|
|
370
|
+
sky: ["#46566c", "#77889d"],
|
|
371
|
+
sun: "none",
|
|
372
|
+
cloudCount: 9,
|
|
373
|
+
cloudColor: [
|
|
374
|
+
30,
|
|
375
|
+
41,
|
|
376
|
+
59
|
|
377
|
+
],
|
|
378
|
+
cloudAlpha: .68,
|
|
379
|
+
cloudSpread: .3,
|
|
380
|
+
rain: {
|
|
381
|
+
count: 80,
|
|
382
|
+
speed: 11,
|
|
383
|
+
wind: -2.5,
|
|
384
|
+
alpha: .38,
|
|
385
|
+
splash: !0
|
|
386
|
+
},
|
|
387
|
+
fogBanks: 0,
|
|
388
|
+
haze: .1,
|
|
389
|
+
snowCount: 0,
|
|
390
|
+
lightning: !1
|
|
391
|
+
},
|
|
392
|
+
smog: {
|
|
393
|
+
sky: ["#8f8b7e", "#c5bca8"],
|
|
394
|
+
sun: "dim",
|
|
395
|
+
cloudCount: 3,
|
|
396
|
+
cloudColor: [
|
|
397
|
+
142,
|
|
398
|
+
136,
|
|
399
|
+
119
|
|
400
|
+
],
|
|
401
|
+
cloudAlpha: .35,
|
|
402
|
+
cloudSpread: .2,
|
|
403
|
+
rain: null,
|
|
404
|
+
fogBanks: 12,
|
|
405
|
+
haze: .34,
|
|
406
|
+
snowCount: 0,
|
|
407
|
+
lightning: !1
|
|
408
|
+
},
|
|
409
|
+
gale: {
|
|
410
|
+
sky: ["#587087", "#a6b5c2"],
|
|
411
|
+
sun: "soft",
|
|
412
|
+
cloudCount: 8,
|
|
413
|
+
cloudColor: [
|
|
414
|
+
203,
|
|
415
|
+
213,
|
|
416
|
+
225
|
|
417
|
+
],
|
|
418
|
+
cloudAlpha: .72,
|
|
419
|
+
cloudSpread: .3,
|
|
420
|
+
rain: null,
|
|
421
|
+
fogBanks: 0,
|
|
422
|
+
haze: .04,
|
|
423
|
+
snowCount: 0,
|
|
424
|
+
lightning: !1
|
|
425
|
+
},
|
|
426
|
+
snow: {
|
|
427
|
+
sky: ["#9fb0c4", "#dde5ee"],
|
|
428
|
+
sun: "none",
|
|
429
|
+
cloudCount: 6,
|
|
430
|
+
cloudColor: [
|
|
431
|
+
148,
|
|
432
|
+
163,
|
|
433
|
+
184
|
|
434
|
+
],
|
|
435
|
+
cloudAlpha: .5,
|
|
436
|
+
cloudSpread: .24,
|
|
437
|
+
rain: null,
|
|
438
|
+
fogBanks: 0,
|
|
439
|
+
haze: .08,
|
|
440
|
+
snowCount: 160,
|
|
441
|
+
lightning: !1
|
|
442
|
+
}
|
|
443
|
+
}, g = {
|
|
444
|
+
sunny: {
|
|
445
|
+
sky: ["#0b1a33", "#27476e"],
|
|
446
|
+
stars: 110
|
|
447
|
+
},
|
|
448
|
+
partlyCloudy: {
|
|
449
|
+
sky: ["#0f1f38", "#2c4666"],
|
|
450
|
+
stars: 60
|
|
451
|
+
},
|
|
452
|
+
overcast: {
|
|
453
|
+
sky: ["#181f2a", "#333e4e"],
|
|
454
|
+
stars: 0
|
|
455
|
+
},
|
|
456
|
+
lightRain: {
|
|
457
|
+
sky: ["#151b26", "#2b3442"],
|
|
458
|
+
stars: 0
|
|
459
|
+
},
|
|
460
|
+
moderateRain: {
|
|
461
|
+
sky: ["#11161f", "#242c3a"],
|
|
462
|
+
stars: 0
|
|
463
|
+
},
|
|
464
|
+
heavyRain: {
|
|
465
|
+
sky: ["#0c1017", "#1c232e"],
|
|
466
|
+
stars: 0
|
|
467
|
+
},
|
|
468
|
+
thunderstorm: {
|
|
469
|
+
sky: ["#0a0e18", "#192132"],
|
|
470
|
+
stars: 0
|
|
471
|
+
},
|
|
472
|
+
fog: {
|
|
473
|
+
sky: ["#1c222b", "#3a434e"],
|
|
474
|
+
stars: 0
|
|
475
|
+
},
|
|
476
|
+
lightSnow: {
|
|
477
|
+
sky: ["#161e2b", "#3a4656"],
|
|
478
|
+
stars: 20
|
|
479
|
+
},
|
|
480
|
+
moderateSnow: {
|
|
481
|
+
sky: ["#131a26", "#333f4f"],
|
|
482
|
+
stars: 8
|
|
483
|
+
},
|
|
484
|
+
heavySnow: {
|
|
485
|
+
sky: ["#101623", "#2a3545"],
|
|
486
|
+
stars: 0
|
|
487
|
+
},
|
|
488
|
+
sleet: {
|
|
489
|
+
sky: ["#121924", "#2c3745"],
|
|
490
|
+
stars: 0
|
|
491
|
+
},
|
|
492
|
+
hail: {
|
|
493
|
+
sky: ["#0e141d", "#26303e"],
|
|
494
|
+
stars: 0
|
|
495
|
+
},
|
|
496
|
+
smog: {
|
|
497
|
+
sky: ["#1a1812", "#38321f"],
|
|
498
|
+
stars: 0
|
|
499
|
+
},
|
|
500
|
+
gale: {
|
|
501
|
+
sky: ["#101a26", "#2e3d4d"],
|
|
502
|
+
stars: 30
|
|
503
|
+
},
|
|
504
|
+
snow: {
|
|
505
|
+
sky: ["#131a26", "#333f4f"],
|
|
506
|
+
stars: 8
|
|
507
|
+
}
|
|
508
|
+
}, _ = ([e, t, n]) => [
|
|
509
|
+
Math.round(e * .3 + 18),
|
|
510
|
+
Math.round(t * .3 + 24),
|
|
511
|
+
Math.round(n * .3 + 42)
|
|
512
|
+
], v = (e) => {
|
|
513
|
+
let t = Math.ceil(e * 2 + 4), n = document.createElement("canvas");
|
|
514
|
+
n.width = t, n.height = t;
|
|
515
|
+
let r = n.getContext("2d"), i = r.createRadialGradient(t / 2, t / 2, 0, t / 2, t / 2, e + 1);
|
|
516
|
+
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) => {
|
|
518
|
+
let t = Math.ceil(e * 2 + 6), n = document.createElement("canvas");
|
|
519
|
+
n.width = t, n.height = t;
|
|
520
|
+
let r = n.getContext("2d");
|
|
521
|
+
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;
|
|
522
|
+
let i = 1 + Math.floor(Math.random() * 3), a = Array.from({ length: i }, () => ({
|
|
523
|
+
pos: .3 + Math.random() * .5,
|
|
524
|
+
len: e * (.22 + Math.random() * .34),
|
|
525
|
+
angle: Math.PI / 3 * (.8 + Math.random() * .45)
|
|
526
|
+
})), o = Math.random() < .55, s = e * (.14 + Math.random() * .12), c = Math.random() < .45, l = e * (.14 + Math.random() * .14);
|
|
527
|
+
for (let t = 0; t < 6; t++) {
|
|
528
|
+
r.save(), r.rotate(t * Math.PI / 3), r.beginPath(), r.moveTo(0, 0), r.lineTo(0, -e);
|
|
529
|
+
for (let t of a) {
|
|
530
|
+
let n = -e * t.pos;
|
|
531
|
+
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);
|
|
532
|
+
}
|
|
533
|
+
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();
|
|
534
|
+
}
|
|
535
|
+
if (c) {
|
|
536
|
+
r.beginPath();
|
|
537
|
+
for (let e = 0; e < 6; e++) {
|
|
538
|
+
let t = e * Math.PI / 3 - Math.PI / 2, n = Math.cos(t) * l, i = Math.sin(t) * l;
|
|
539
|
+
e === 0 ? r.moveTo(n, i) : r.lineTo(n, i);
|
|
540
|
+
}
|
|
541
|
+
r.closePath(), r.stroke();
|
|
542
|
+
}
|
|
543
|
+
return n;
|
|
544
|
+
}, b = (e, t, n) => {
|
|
545
|
+
let r = 1 + Math.random() ** 1.6 * 4.2, i = r >= 2.4;
|
|
546
|
+
return {
|
|
547
|
+
x: Math.random() * e,
|
|
548
|
+
y: n ?? Math.random() * t,
|
|
549
|
+
size: r,
|
|
550
|
+
speed: .4 + r * .28 + Math.random() * .4,
|
|
551
|
+
phase: Math.random() * Math.PI * 2,
|
|
552
|
+
drift: (Math.random() - .5) * .4,
|
|
553
|
+
rotation: Math.random() * Math.PI * 2,
|
|
554
|
+
rotationSpeed: (Math.random() - .5) * .025,
|
|
555
|
+
opacity: .55 + Math.random() * .45,
|
|
556
|
+
sprite: i ? y(r * 2.4) : v(r)
|
|
557
|
+
};
|
|
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);
|
|
567
|
+
return e(() => {
|
|
568
|
+
E.current = f;
|
|
569
|
+
}), e(() => {
|
|
570
|
+
S.weather && E.current?.(S.weather);
|
|
571
|
+
}, [S.weather]), e(() => {
|
|
572
|
+
let e = y.current;
|
|
573
|
+
if (!e) return;
|
|
574
|
+
let t = window.devicePixelRatio || 1;
|
|
575
|
+
e.width = n * t, e.height = o * t;
|
|
576
|
+
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
|
+
};
|
|
764
|
+
}, [
|
|
765
|
+
w,
|
|
766
|
+
C,
|
|
767
|
+
o,
|
|
768
|
+
n
|
|
769
|
+
]), /* @__PURE__ */ a("div", {
|
|
770
|
+
className: m.weatherBackground,
|
|
771
|
+
style: {
|
|
772
|
+
width: n,
|
|
773
|
+
height: o
|
|
774
|
+
},
|
|
775
|
+
children: [/* @__PURE__ */ i("canvas", {
|
|
776
|
+
ref: y,
|
|
777
|
+
className: m.canvas,
|
|
778
|
+
style: {
|
|
779
|
+
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: "天气加载中…" })]
|
|
785
|
+
})]
|
|
786
|
+
});
|
|
787
|
+
};
|
|
788
|
+
//#endregion
|
|
789
|
+
export { S as WeatherBackground, S as default, c as mapWmoCodeToWeatherType, p as useLiveWeather };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default } from '../../../src/components/weatherBackground';
|
|
2
|
+
export { default as WeatherBackground } from '../../../src/components/weatherBackground';
|
|
3
|
+
export type * from '../../../src/components/weatherBackground';
|
|
4
|
+
export { mapWmoCodeToWeatherType, useLiveWeather } from '../../../src/components/weatherBackground/live-weather';
|
|
5
|
+
export type { LiveWeatherCoords, LiveWeatherState, LiveWeatherStatus, OpenMeteoCurrent } from '../../../src/components/weatherBackground/live-weather';
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
23
|
+
declare const WeatherBackground: React.FC<WeatherBackgroundProps>;
|
|
24
|
+
export default WeatherBackground;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WeatherType } from './index';
|
|
2
|
+
export interface OpenMeteoCurrent {
|
|
3
|
+
/** WMO 天气码 */
|
|
4
|
+
weatherCode: number;
|
|
5
|
+
/** 10 米风速(km/h) */
|
|
6
|
+
windSpeed: number;
|
|
7
|
+
/** 是否白天 */
|
|
8
|
+
isDay: boolean;
|
|
9
|
+
latitude: number;
|
|
10
|
+
longitude: number;
|
|
11
|
+
}
|
|
12
|
+
export type LiveWeatherStatus = 'idle' | 'locating' | 'fetching' | 'success' | 'error';
|
|
13
|
+
export interface LiveWeatherState {
|
|
14
|
+
/** 映射后的组件天气类型,成功前为 null */
|
|
15
|
+
weather: WeatherType | null;
|
|
16
|
+
status: LiveWeatherStatus;
|
|
17
|
+
error: string | null;
|
|
18
|
+
/** Open-Meteo 原始实况数据 */
|
|
19
|
+
current: OpenMeteoCurrent | null;
|
|
20
|
+
}
|
|
21
|
+
/** WMO 天气码 → WeatherType;无降水且风速达强风时映射为大风 */
|
|
22
|
+
export declare const mapWmoCodeToWeatherType: (code: number, windSpeedKmh?: number) => WeatherType;
|
|
23
|
+
export interface LiveWeatherCoords {
|
|
24
|
+
latitude: number;
|
|
25
|
+
longitude: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Open-Meteo 实况天气。
|
|
29
|
+
* 传入 coords 时直接按该经纬度查询;未传时使用浏览器定位(需 HTTPS 与用户授权)。
|
|
30
|
+
* 失败时 status 为 error,调用方自行回退。
|
|
31
|
+
*/
|
|
32
|
+
export declare const useLiveWeather: (enabled?: boolean, coords?: LiveWeatherCoords) => LiveWeatherState;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module '*.module.less' {
|
|
4
|
+
const classes: { readonly [key: string]: string };
|
|
5
|
+
export default classes;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module '*.less' {
|
|
9
|
+
const classes: { readonly [key: string]: string };
|
|
10
|
+
export default classes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module '*.png' {
|
|
14
|
+
const src: string;
|
|
15
|
+
export default src;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module '*.jpg' {
|
|
19
|
+
const src: string;
|
|
20
|
+
export default src;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module '*.mp4' {
|
|
24
|
+
const src: string;
|
|
25
|
+
export default src;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '*.mp3' {
|
|
29
|
+
const src: string;
|
|
30
|
+
export default src;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare module '*.svg' {
|
|
34
|
+
import type { FC, SVGProps } from 'react';
|
|
35
|
+
|
|
36
|
+
export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
|
|
37
|
+
const src: string;
|
|
38
|
+
export default src;
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cos-design/weather-background",
|
|
3
|
+
"version": "3.5.1",
|
|
4
|
+
"description": "WeatherBackground component from cos-design",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css",
|
|
27
|
+
"**/*.less"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"cos-design",
|
|
31
|
+
"react",
|
|
32
|
+
"weatherBackground",
|
|
33
|
+
"WeatherBackground"
|
|
34
|
+
],
|
|
35
|
+
"homepage": "https://jiaxiantao.github.io/cos-design/",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/jiaxiantao/cos-design/issues"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/jiaxiantao/cos-design.git",
|
|
42
|
+
"directory": "packages/weatherBackground"
|
|
43
|
+
},
|
|
44
|
+
"author": "jiaxiantao <jiaxiantao@souche.com>",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": ">=18.0.0",
|
|
48
|
+
"react-dom": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@cos-design/shared": "3.5.1"
|
|
56
|
+
}
|
|
57
|
+
}
|