x-weather
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,1 +0,1 @@ | ||
import{g as convertTemperature,h as dateTime,j as isObjectEmpty,a as loadComponent,i as unixEpochToDate,b as classCallCheck,c as createClass,d as inherits,e as possibleConstructorReturn,f as toConsumableArray}from"./utilities-aabd0479.js";function _CustomElement(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(_CustomElement.prototype,HTMLElement.prototype),Object.setPrototypeOf(_CustomElement,HTMLElement);var template="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",XForecast=function(t){function e(){classCallCheck(this,e);var t=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),n=document.createElement("div");return n.innerHTML=template,t.attachShadow({mode:"open"}).appendChild(n),t}return inherits(e,_CustomElement),createClass(e,[{key:"connectedCallback",value:function(){var t=this;this.refresh().then(function(e){t.render(e),t.currentForecast=e})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&"scale"===t&&this.render(this.currentForecast)}},{key:"_buildDateContainer",value:function(t){var e=this,n=document.createElement("div");if(n.setAttribute("data-x-forecast-date-container",""),t&&!isObjectEmpty(t)){var a=dateTime(new Date).Y("-").m("-").d("").getResults();t.forEach(function(t){var o=t.dt,r=t.temp,i=(t.pressure,t.humidity,t.weather,t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),s=document.createElement("u"),c=unixEpochToDate(o),l=dateTime(c).Y("-").m("-").d().getResults(),u="F"===e.scale?convertTemperature(r.day,"cToF"):r.day,d="F"===e.scale?convertTemperature(r.night,"cToF"):r.night;if(l===a)s.textContent="Today:";else{var p=dateTime(c).date.toLocaleString("en-US",{weekday:"long"}),h=dateTime(c).m("/").d().getResults();s.textContent=p+" ("+h+"):"}var m=document.createElement("li");m.appendChild(s),i.appendChild(m);var f=document.createElement("li");f.textContent="Day: "+Number.parseFloat(u).toFixed(2)+"°"+e.scale,i.appendChild(f);var v=document.createElement("li");v.textContent="Night: "+Number.parseFloat(d).toFixed(2)+"°"+e.scale,i.appendChild(v),n.appendChild(i)})}return n}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t){var e=this.shadowRoot.querySelector("[data-x-forecast]"),n=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");e.replaceChild(this._buildDateContainer(t),n)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),e}(),load=function(){return loadComponent({customElements:customElements,tagName:"x-forecast",element:XForecast})};export default XForecast;export{load}; | ||
import{g as convertTemperature,h as dateTime,j as isObjectEmpty,a as loadComponent,i as unixEpochToDate,b as classCallCheck,c as createClass,d as inherits,e as possibleConstructorReturn,f as toConsumableArray}from"./utilities-aabd0479.js";function _CustomElement(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(_CustomElement.prototype,HTMLElement.prototype),Object.setPrototypeOf(_CustomElement,HTMLElement);var template="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",XForecast=function(t){function e(){classCallCheck(this,e);var t=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),n=document.createElement("div");return n.innerHTML=template,t.attachShadow({mode:"open"}).appendChild(n),t}return inherits(e,_CustomElement),createClass(e,[{key:"connectedCallback",value:function(){var t=this;this.refresh().then(function(e){t.render(e,t.days),t.currentForecast=e})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&null!==this.days&&("days"!==t&&"scale"!==t||this.render(this.currentForecast,this.days))}},{key:"_buildDayOfWeek",value:function(t){var e=t.dt,n=t.today,a=document.createElement("u"),r=unixEpochToDate(e);if(dateTime(r).Y("-").m("-").d().getResults()===n)a.textContent="Today:";else{var i=dateTime(r).date.toLocaleString("en-US",{weekday:"long"}),o=dateTime(r).m("/").d().getResults();a.textContent=i+" ("+o+"):"}var s=document.createElement("li");return s.appendChild(a),s}},{key:"_buildWeatherIcon",value:function(t){var e=t.description,n="https://openweathermap.org/img/w/"+t.icon+".png",a=document.createElement("img");a.setAttribute("src",n),a.setAttribute("alt",e);var r=document.createElement("li");return r.appendChild(a),r}},{key:"_buildTimeOfDayForecast",value:function(t){var e=t.timeOfDayTemp,n=t.type,a="F"===this.scale?convertTemperature(e,"cToF"):e,r=document.createElement("li");return r.textContent=n+": "+Number.parseFloat(a).toFixed(2)+"°"+this.scale,r}},{key:"_buildDateContainer",value:function(t,e){var n=this,a=document.createElement("div");if(a.setAttribute("data-x-forecast-date-container",""),t&&!isObjectEmpty(t)){var r=dateTime(new Date).Y("-").m("-").d("").getResults();t.length>e&&(t.length=e),t.forEach(function(t){var e=t.dt,i=t.temp,o=(t.pressure,t.humidity,t.weather),s=(t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),c=n._buildDayOfWeek({dt:e,today:r});s.appendChild(c);var u=n._buildWeatherIcon(o[0]);s.appendChild(u);var d=n._buildTimeOfDayForecast({timeOfDayTemp:i.day,type:"Day"});s.appendChild(d);var l=n._buildTimeOfDayForecast({timeOfDayTemp:i.night,type:"Night"});s.appendChild(l),a.appendChild(s)})}return a}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t,e){var n=this.shadowRoot.querySelector("[data-x-forecast]"),a=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");n.replaceChild(this._buildDateContainer(t,e),a)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"days",get:function(){return this.getAttribute("days")},set:function(t){this.setAttribute("days",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["days","scale"]}}]),e}(),load=function(){return loadComponent({customElements:customElements,tagName:"x-forecast",element:XForecast})};export default XForecast;export{load}; |
@@ -1,1 +0,1 @@ | ||
System.register(["./utilities-efc14eb9.js"],function(n,t){"use strict";var y,g,a,r,b,i,o,s,c;return{setters:[function(t){y=t.g,g=t.h,a=t.j,r=t.a,b=t.i,i=t.b,o=t.c,s=t.d,c=t.e,t.f}],execute:function(){function e(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(e.prototype,HTMLElement.prototype),Object.setPrototypeOf(e,HTMLElement);var t=function(t){function n(){i(this,n);var t=c(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return s(n,e),o(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&"scale"===t&&this.render(this.currentForecast)}},{key:"_buildDateContainer",value:function(t){var f=this,m=document.createElement("div");if(m.setAttribute("data-x-forecast-date-container",""),t&&!a(t)){var v=g(new Date).Y("-").m("-").d("").getResults();t.forEach(function(t){var e=t.dt,n=t.temp,a=(t.pressure,t.humidity,t.weather,t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),r=document.createElement("u"),i=b(e),o=g(i).Y("-").m("-").d().getResults(),s="F"===f.scale?y(n.day,"cToF"):n.day,c="F"===f.scale?y(n.night,"cToF"):n.night;if(o===v)r.textContent="Today:";else{var u=g(i).date.toLocaleString("en-US",{weekday:"long"}),d=g(i).m("/").d().getResults();r.textContent=u+" ("+d+"):"}var l=document.createElement("li");l.appendChild(r),a.appendChild(l);var h=document.createElement("li");h.textContent="Day: "+Number.parseFloat(s).toFixed(2)+"°"+f.scale,a.appendChild(h);var p=document.createElement("li");p.textContent="Night: "+Number.parseFloat(c).toFixed(2)+"°"+f.scale,a.appendChild(p),m.appendChild(a)})}return m}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t){var e=this.shadowRoot.querySelector("[data-x-forecast]"),n=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");e.replaceChild(this._buildDateContainer(t),n)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}();n("load",function(){return r({customElements:customElements,tagName:"x-forecast",element:t})});n("default",t)}}}); | ||
System.register(["./utilities-efc14eb9.js"],function(n,t){"use strict";var r,c,a,i,u,o,s,d,l;return{setters:[function(t){r=t.g,c=t.h,a=t.j,i=t.a,u=t.i,o=t.b,s=t.c,d=t.d,l=t.e,t.f}],execute:function(){function e(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(e.prototype,HTMLElement.prototype),Object.setPrototypeOf(e,HTMLElement);var t=function(t){function n(){o(this,n);var t=l(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return d(n,e),s(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t,e.days),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&null!==this.days&&("days"!==t&&"scale"!==t||this.render(this.currentForecast,this.days))}},{key:"_buildDayOfWeek",value:function(t){var e=t.dt,n=t.today,a=document.createElement("u"),i=u(e);if(c(i).Y("-").m("-").d().getResults()===n)a.textContent="Today:";else{var r=c(i).date.toLocaleString("en-US",{weekday:"long"}),o=c(i).m("/").d().getResults();a.textContent=r+" ("+o+"):"}var s=document.createElement("li");return s.appendChild(a),s}},{key:"_buildWeatherIcon",value:function(t){var e=t.description,n="https://openweathermap.org/img/w/"+t.icon+".png",a=document.createElement("img");a.setAttribute("src",n),a.setAttribute("alt",e);var i=document.createElement("li");return i.appendChild(a),i}},{key:"_buildTimeOfDayForecast",value:function(t){var e=t.timeOfDayTemp,n=t.type,a="F"===this.scale?r(e,"cToF"):e,i=document.createElement("li");return i.textContent=n+": "+Number.parseFloat(a).toFixed(2)+"°"+this.scale,i}},{key:"_buildDateContainer",value:function(t,e){var u=this,d=document.createElement("div");if(d.setAttribute("data-x-forecast-date-container",""),t&&!a(t)){var l=c(new Date).Y("-").m("-").d("").getResults();t.length>e&&(t.length=e),t.forEach(function(t){var e=t.dt,n=t.temp,a=(t.pressure,t.humidity,t.weather),i=(t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),r=u._buildDayOfWeek({dt:e,today:l});i.appendChild(r);var o=u._buildWeatherIcon(a[0]);i.appendChild(o);var s=u._buildTimeOfDayForecast({timeOfDayTemp:n.day,type:"Day"});i.appendChild(s);var c=u._buildTimeOfDayForecast({timeOfDayTemp:n.night,type:"Night"});i.appendChild(c),d.appendChild(i)})}return d}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t,e){var n=this.shadowRoot.querySelector("[data-x-forecast]"),a=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");n.replaceChild(this._buildDateContainer(t,e),a)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"days",get:function(){return this.getAttribute("days")},set:function(t){this.setAttribute("days",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["days","scale"]}}]),n}();n("load",function(){return i({customElements:customElements,tagName:"x-forecast",element:t})});n("default",t)}}}); |
@@ -1,1 +0,1 @@ | ||
var Main=function(){"use strict";var r=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e=function(){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}}(),i=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},a=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},g=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"cToF",n=function(t){return t+273.15},r=function(t){return t-273.15},i=function(t){return 1.8*t+32},a=function(t){return 5*(t-32)/9};return{cToK:n,kToC:r,cToF:i,fToC:a,kToF:function(t){return i(r(t))},fToK:function(t){return n(a(t))}}[e](t)},t=function(t){var e=t.customElements,n=t.tagName,r=t.element,i=function(t){var e=t.customElements,n=t.tagName,r=t.element;e.define(n,r)};window.customElements?i({customElements:e,tagName:n,element:r}):document.addEventListener("WebComponentsReady",function(){i({customElements:e,tagName:n,element:r})})},v=function(t){return new Date(1e3*t)},b=function(t){return{date:t,results:"",getResults:function(){return this.results},getTimeStamp:function(){return this.date.getTime()},Y:function(t){return this.results+=this.date.getFullYear(),this.sep(t)&&(this.results+=t),this},m:function(t){return this.results+=this.pad(this.date.getMonth()+1),this.sep(t)&&(this.results+=t),this},d:function(t){return this.results+=this.pad(this.date.getDate()),this.sep(t)&&(this.results+=t),this},H:function(t){return this.results+=this.pad(this.date.getHours()),this.sep(t)&&(this.results+=t),this},M:function(t){return this.results+=this.pad(this.date.getMinutes()),this.sep(t)&&(this.results+=t),this},S:function(t){return this.results+=this.pad(this.date.getSeconds()),this.sep(t)&&(this.results+=t),this},pad:function(t){return t<10?"0"+t:t},sep:function(t){return!!t}}},n=function(t){function n(){r(this,n);var t=a(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-current] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-current] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-current] ul > li {\n padding: 0.5rem 0 0 0;\n }\n\n div[data-x-current] #time {\n display: none;\n }\n\n div[data-x-current] #alternateScale {\n cursor: pointer;\n border-bottom: 1px dotted;\n }\n </style>\n\n <div data-x-current>\n <h3>Current</h3>\n <ul>\n <li id="time"></li>\n <li><img alt="" id="icon"></img></li>\n <li>\n <span id="temperature"></span>°<span id="primaryScale"></span> / <span><a id="alternateScale"></a></span>\n </li>\n </ul>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,t),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentWeather=t,e.primaryScale=e.shadowRoot.querySelector("#primaryScale"),e.alternateScale=e.shadowRoot.querySelector("#alternateScale"),e.primaryScale.textContent=e.scale,e.alternateScale.textContent="C"===e.scale?"F":"C",e.alternateScale.onclick=function(){e.scale=e.alternateScale.textContent;var t=e.parentElement.querySelector("x-forecast");t&&t.setAttribute("scale",e.primaryScale.textContent)}})}},{key:"attributeChangedCallback",value:function(t,e,n){"scale"===t&&e!==n&&this.alternateScale&&this.primaryScale&&("C"===n&&(this.alternateScale.textContent="F",this.primaryScale.textContent=n),"F"===n&&(this.alternateScale.textContent="C",this.primaryScale.textContent=n),this.render(this.currentWeather))}},{key:"_getCurrentWeather",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.coord;var e=t.weather,n=(t.base,t.main),r=(t.visibility,t.wind,t.clouds,t.dt);t.sys,t.id,t.name,t.cod;return{iconAlt:e[0].description,iconSrc:e[0].icon,temperature:{kelvin:n.temp,celsius:g(n.temp,"kToC"),fahrenheit:g(n.temp,"kToF")},timestamp:r}})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/weather?q="+r+"&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getCurrentWeather(t)}},{key:"render",value:function(t){var e=t.iconAlt,n=t.iconSrc,r=t.temperature,i=t.timestamp;this.temperature=Number.parseFloat(r["C"===this.scale?"celsius":"fahrenheit"]).toFixed(2),this.iconAlt=e,this.iconSrc="https://openweathermap.org/img/w/"+n+".png",this.timestamp=i}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"iconAlt",set:function(t){this.shadowRoot.querySelector("#icon").setAttribute("alt",t)}},{key:"iconSrc",set:function(t){this.shadowRoot.querySelector("#icon").src=t}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}},{key:"temperature",set:function(t){this.setAttribute("temperature",t),this.shadowRoot.querySelector("#temperature").textContent=t}},{key:"timestamp",set:function(t){this.shadowRoot.querySelector("#time").textContent=b(v(t)).H(":").M(":").S().getResults()}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}(HTMLElement),o=function(t){function n(){r(this,n);var t=a(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,t),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&"scale"===t&&this.render(this.currentForecast)}},{key:"_buildDateContainer",value:function(t){var e,f=this,m=document.createElement("div");if(m.setAttribute("data-x-forecast-date-container",""),t&&(e=t,0!==Object.keys(e).length||e.constructor!==Object)){var y=b(new Date).Y("-").m("-").d("").getResults();t.forEach(function(t){var e=t.dt,n=t.temp,r=(t.pressure,t.humidity,t.weather,t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),i=document.createElement("u"),a=v(e),o=b(a).Y("-").m("-").d().getResults(),s="F"===f.scale?g(n.day,"cToF"):n.day,c="F"===f.scale?g(n.night,"cToF"):n.night;if(o===y)i.textContent="Today:";else{var u=b(a).date.toLocaleString("en-US",{weekday:"long"}),l=b(a).m("/").d().getResults();i.textContent=u+" ("+l+"):"}var h=document.createElement("li");h.appendChild(i),r.appendChild(h);var d=document.createElement("li");d.textContent="Day: "+Number.parseFloat(s).toFixed(2)+"°"+f.scale,r.appendChild(d);var p=document.createElement("li");p.textContent="Night: "+Number.parseFloat(c).toFixed(2)+"°"+f.scale,r.appendChild(p),m.appendChild(r)})}return m}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+r+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t){var e=this.shadowRoot.querySelector("[data-x-forecast]"),n=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");e.replaceChild(this._buildDateContainer(t),n)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}(HTMLElement),s=function(t){function n(){r(this,n);var t=a(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-weather] #location {\n border: 0;\n font-style: italic;\n margin: 0 0 0 2.5%;\n padding: 0 2.5% 0 0;\n width: 95%;\n }\n </style>\n\n <div data-x-weather>\n <div><input id="location"></input></div>\n\n <slot></slot>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,t),e(n,[{key:"connectedCallback",value:function(){var e=this;this._upgradeProperty("appid"),this._upgradeProperty("host"),this._upgradeProperty("location"),this.xCurrent=this.querySelector("x-current"),this.xForecast=this.querySelector("x-forecast"),this._renderLocation(this.location);var t=this.shadowRoot.querySelector("#location");t.addEventListener("change",function(){e.location=t.value,e.xCurrent.refresh().then(function(t){e.xCurrent.render(t),e.xCurrent.currentWeather=t}),e.xForecast.refresh().then(function(t){e.xForecast.render(t),e.xForecast.currentForecast=t})})}},{key:"attributeChangedCallback",value:function(t,e,n){(e!==n&&"appid"===t||"host"===t||"location"===t)&&("location"===t&&this._renderLocation(this.location),this.xCurrent&&this.xCurrent.setAttribute(t,n),this.xForecast&&this.xForecast.setAttribute(t,n))}},{key:"_renderLocation",value:function(t){this.shadowRoot.querySelector("#location").value=t}},{key:"_upgradeProperty",value:function(t){if(this.hasOwnProperty(t)){var e=this[t];delete this[t],this[t]=e}}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}}],[{key:"observedAttributes",get:function(){return["appid","host","location"]}}]),n}(HTMLElement);return t({customElements:customElements,tagName:"x-current",element:n}),t({customElements:customElements,tagName:"x-forecast",element:o}),t({customElements:customElements,tagName:"x-weather",element:s}),{XCurrent:n,XForecast:o,XWeather:s}}(); | ||
var Main=function(){"use strict";var r=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e=function(){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}}(),i=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},a=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},o=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"cToF",n=function(t){return t+273.15},r=function(t){return t-273.15},i=function(t){return 1.8*t+32},a=function(t){return 5*(t-32)/9};return{cToK:n,kToC:r,cToF:i,fToC:a,kToF:function(t){return i(r(t))},fToK:function(t){return n(a(t))}}[e](t)},t=function(t){var e=t.customElements,n=t.tagName,r=t.element,i=function(t){var e=t.customElements,n=t.tagName,r=t.element;e.define(n,r)};window.customElements?i({customElements:e,tagName:n,element:r}):document.addEventListener("WebComponentsReady",function(){i({customElements:e,tagName:n,element:r})})},u=function(t){return new Date(1e3*t)},d=function(t){return{date:t,results:"",getResults:function(){return this.results},getTimeStamp:function(){return this.date.getTime()},Y:function(t){return this.results+=this.date.getFullYear(),this.sep(t)&&(this.results+=t),this},m:function(t){return this.results+=this.pad(this.date.getMonth()+1),this.sep(t)&&(this.results+=t),this},d:function(t){return this.results+=this.pad(this.date.getDate()),this.sep(t)&&(this.results+=t),this},H:function(t){return this.results+=this.pad(this.date.getHours()),this.sep(t)&&(this.results+=t),this},M:function(t){return this.results+=this.pad(this.date.getMinutes()),this.sep(t)&&(this.results+=t),this},S:function(t){return this.results+=this.pad(this.date.getSeconds()),this.sep(t)&&(this.results+=t),this},pad:function(t){return t<10?"0"+t:t},sep:function(t){return!!t}}},n=function(t){function n(){r(this,n);var t=a(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-current] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-current] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-current] ul > li {\n padding: 0.5rem 0 0 0;\n }\n\n div[data-x-current] #time {\n display: none;\n }\n\n div[data-x-current] #alternateScale {\n cursor: pointer;\n border-bottom: 1px dotted;\n }\n </style>\n\n <div data-x-current>\n <h3>Current</h3>\n <ul>\n <li id="time"></li>\n <li><img alt="" id="icon"></img></li>\n <li>\n <span id="temperature"></span>°<span id="primaryScale"></span> / <span><a id="alternateScale"></a></span>\n </li>\n </ul>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,t),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentWeather=t,e.primaryScale=e.shadowRoot.querySelector("#primaryScale"),e.alternateScale=e.shadowRoot.querySelector("#alternateScale"),e.primaryScale.textContent=e.scale,e.alternateScale.textContent="C"===e.scale?"F":"C",e.alternateScale.onclick=function(){e.scale=e.alternateScale.textContent;var t=e.parentElement.querySelector("x-forecast");t&&t.setAttribute("scale",e.primaryScale.textContent)}})}},{key:"attributeChangedCallback",value:function(t,e,n){"scale"===t&&e!==n&&this.alternateScale&&this.primaryScale&&("C"===n&&(this.alternateScale.textContent="F",this.primaryScale.textContent=n),"F"===n&&(this.alternateScale.textContent="C",this.primaryScale.textContent=n),this.render(this.currentWeather))}},{key:"_getCurrentWeather",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.coord;var e=t.weather,n=(t.base,t.main),r=(t.visibility,t.wind,t.clouds,t.dt);t.sys,t.id,t.name,t.cod;return{iconAlt:e[0].description,iconSrc:e[0].icon,temperature:{kelvin:n.temp,celsius:o(n.temp,"kToC"),fahrenheit:o(n.temp,"kToF")},timestamp:r}})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/weather?q="+r+"&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getCurrentWeather(t)}},{key:"render",value:function(t){var e=t.iconAlt,n=t.iconSrc,r=t.temperature,i=t.timestamp;this.temperature=Number.parseFloat(r["C"===this.scale?"celsius":"fahrenheit"]).toFixed(2),this.iconAlt=e,this.iconSrc="https://openweathermap.org/img/w/"+n+".png",this.timestamp=i}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"iconAlt",set:function(t){this.shadowRoot.querySelector("#icon").setAttribute("alt",t)}},{key:"iconSrc",set:function(t){this.shadowRoot.querySelector("#icon").src=t}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}},{key:"temperature",set:function(t){this.setAttribute("temperature",t),this.shadowRoot.querySelector("#temperature").textContent=t}},{key:"timestamp",set:function(t){this.shadowRoot.querySelector("#time").textContent=d(u(t)).H(":").M(":").S().getResults()}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}(HTMLElement),s=function(t){function n(){r(this,n);var t=a(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,t),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t,e.days),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&null!==this.days&&("days"!==t&&"scale"!==t||this.render(this.currentForecast,this.days))}},{key:"_buildDayOfWeek",value:function(t){var e=t.dt,n=t.today,r=document.createElement("u"),i=u(e);if(d(i).Y("-").m("-").d().getResults()===n)r.textContent="Today:";else{var a=d(i).date.toLocaleString("en-US",{weekday:"long"}),o=d(i).m("/").d().getResults();r.textContent=a+" ("+o+"):"}var s=document.createElement("li");return s.appendChild(r),s}},{key:"_buildWeatherIcon",value:function(t){var e=t.description,n="https://openweathermap.org/img/w/"+t.icon+".png",r=document.createElement("img");r.setAttribute("src",n),r.setAttribute("alt",e);var i=document.createElement("li");return i.appendChild(r),i}},{key:"_buildTimeOfDayForecast",value:function(t){var e=t.timeOfDayTemp,n=t.type,r="F"===this.scale?o(e,"cToF"):e,i=document.createElement("li");return i.textContent=n+": "+Number.parseFloat(r).toFixed(2)+"°"+this.scale,i}},{key:"_buildDateContainer",value:function(t,e){var n,c=this,l=document.createElement("div");if(l.setAttribute("data-x-forecast-date-container",""),t&&(n=t,0!==Object.keys(n).length||n.constructor!==Object)){var h=d(new Date).Y("-").m("-").d("").getResults();t.length>e&&(t.length=e),t.forEach(function(t){var e=t.dt,n=t.temp,r=(t.pressure,t.humidity,t.weather),i=(t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),a=c._buildDayOfWeek({dt:e,today:h});i.appendChild(a);var o=c._buildWeatherIcon(r[0]);i.appendChild(o);var s=c._buildTimeOfDayForecast({timeOfDayTemp:n.day,type:"Day"});i.appendChild(s);var u=c._buildTimeOfDayForecast({timeOfDayTemp:n.night,type:"Night"});i.appendChild(u),l.appendChild(i)})}return l}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+r+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t,e){var n=this.shadowRoot.querySelector("[data-x-forecast]"),r=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");n.replaceChild(this._buildDateContainer(t,e),r)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"days",get:function(){return this.getAttribute("days")},set:function(t){this.setAttribute("days",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["days","scale"]}}]),n}(HTMLElement),c=function(t){function n(){r(this,n);var t=a(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-weather] #location {\n border: 0;\n font-style: italic;\n margin: 0 0 0 2.5%;\n padding: 0 2.5% 0 0;\n width: 95%;\n }\n </style>\n\n <div data-x-weather>\n <div><input id="location"></input></div>\n\n <slot></slot>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,t),e(n,[{key:"connectedCallback",value:function(){var e=this;this._upgradeProperty("appid"),this._upgradeProperty("host"),this._upgradeProperty("location"),this.xCurrent=this.querySelector("x-current"),this.xForecast=this.querySelector("x-forecast"),this._renderLocation(this.location);var t=this.shadowRoot.querySelector("#location");t.addEventListener("change",function(){e.location=t.value,e.xCurrent.refresh().then(function(t){e.xCurrent.render(t),e.xCurrent.currentWeather=t}),e.xForecast.refresh().then(function(t){e.xForecast.render(t),e.xForecast.currentForecast=t})})}},{key:"attributeChangedCallback",value:function(t,e,n){(e!==n&&"appid"===t||"host"===t||"location"===t)&&("location"===t&&this._renderLocation(this.location),this.xCurrent&&this.xCurrent.setAttribute(t,n),this.xForecast&&this.xForecast.setAttribute(t,n))}},{key:"_renderLocation",value:function(t){this.shadowRoot.querySelector("#location").value=t}},{key:"_upgradeProperty",value:function(t){if(this.hasOwnProperty(t)){var e=this[t];delete this[t],this[t]=e}}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}}],[{key:"observedAttributes",get:function(){return["appid","host","location"]}}]),n}(HTMLElement);return t({customElements:customElements,tagName:"x-current",element:n}),t({customElements:customElements,tagName:"x-forecast",element:s}),t({customElements:customElements,tagName:"x-weather",element:c}),{XCurrent:n,XForecast:s,XWeather:c}}(); |
@@ -1,1 +0,1 @@ | ||
System.register(["./utilities-efc14eb9.js"],function(e,t){"use strict";var g,y,a,n,b,i,r,o,s;return{setters:[function(t){g=t.g,y=t.h,a=t.j,n=t.a,b=t.i,i=t.b,r=t.c,o=t.d,s=t.e,t.f}],execute:function(){var t=function(t){function n(){i(this,n);var t=s(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return o(n,t),r(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&"scale"===t&&this.render(this.currentForecast)}},{key:"_buildDateContainer",value:function(t){var p=this,m=document.createElement("div");if(m.setAttribute("data-x-forecast-date-container",""),t&&!a(t)){var v=y(new Date).Y("-").m("-").d("").getResults();t.forEach(function(t){var e=t.dt,n=t.temp,a=(t.pressure,t.humidity,t.weather,t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),i=document.createElement("u"),r=b(e),o=y(r).Y("-").m("-").d().getResults(),s="F"===p.scale?g(n.day,"cToF"):n.day,c="F"===p.scale?g(n.night,"cToF"):n.night;if(o===v)i.textContent="Today:";else{var u=y(r).date.toLocaleString("en-US",{weekday:"long"}),d=y(r).m("/").d().getResults();i.textContent=u+" ("+d+"):"}var l=document.createElement("li");l.appendChild(i),a.appendChild(l);var h=document.createElement("li");h.textContent="Day: "+Number.parseFloat(s).toFixed(2)+"°"+p.scale,a.appendChild(h);var f=document.createElement("li");f.textContent="Night: "+Number.parseFloat(c).toFixed(2)+"°"+p.scale,a.appendChild(f),m.appendChild(a)})}return m}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t){var e=this.shadowRoot.querySelector("[data-x-forecast]"),n=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");e.replaceChild(this._buildDateContainer(t),n)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}(HTMLElement);e("load",function(){return n({customElements:customElements,tagName:"x-forecast",element:t})});e("default",t)}}}); | ||
System.register(["./utilities-efc14eb9.js"],function(e,t){"use strict";var r,c,a,n,u,i,o,s,d;return{setters:[function(t){r=t.g,c=t.h,a=t.j,n=t.a,u=t.i,i=t.b,o=t.c,s=t.d,d=t.e,t.f}],execute:function(){var t=function(t){function n(){i(this,n);var t=d(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return s(n,t),o(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t,e.days),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&null!==this.days&&("days"!==t&&"scale"!==t||this.render(this.currentForecast,this.days))}},{key:"_buildDayOfWeek",value:function(t){var e=t.dt,n=t.today,a=document.createElement("u"),i=u(e);if(c(i).Y("-").m("-").d().getResults()===n)a.textContent="Today:";else{var r=c(i).date.toLocaleString("en-US",{weekday:"long"}),o=c(i).m("/").d().getResults();a.textContent=r+" ("+o+"):"}var s=document.createElement("li");return s.appendChild(a),s}},{key:"_buildWeatherIcon",value:function(t){var e=t.description,n="https://openweathermap.org/img/w/"+t.icon+".png",a=document.createElement("img");a.setAttribute("src",n),a.setAttribute("alt",e);var i=document.createElement("li");return i.appendChild(a),i}},{key:"_buildTimeOfDayForecast",value:function(t){var e=t.timeOfDayTemp,n=t.type,a="F"===this.scale?r(e,"cToF"):e,i=document.createElement("li");return i.textContent=n+": "+Number.parseFloat(a).toFixed(2)+"°"+this.scale,i}},{key:"_buildDateContainer",value:function(t,e){var u=this,d=document.createElement("div");if(d.setAttribute("data-x-forecast-date-container",""),t&&!a(t)){var l=c(new Date).Y("-").m("-").d("").getResults();t.length>e&&(t.length=e),t.forEach(function(t){var e=t.dt,n=t.temp,a=(t.pressure,t.humidity,t.weather),i=(t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),r=u._buildDayOfWeek({dt:e,today:l});i.appendChild(r);var o=u._buildWeatherIcon(a[0]);i.appendChild(o);var s=u._buildTimeOfDayForecast({timeOfDayTemp:n.day,type:"Day"});i.appendChild(s);var c=u._buildTimeOfDayForecast({timeOfDayTemp:n.night,type:"Night"});i.appendChild(c),d.appendChild(i)})}return d}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t,e){var n=this.shadowRoot.querySelector("[data-x-forecast]"),a=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");n.replaceChild(this._buildDateContainer(t,e),a)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"days",get:function(){return this.getAttribute("days")},set:function(t){this.setAttribute("days",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["days","scale"]}}]),n}(HTMLElement);e("load",function(){return n({customElements:customElements,tagName:"x-forecast",element:t})});e("default",t)}}}); |
@@ -1,1 +0,1 @@ | ||
import{g as convertTemperature,h as dateTime,j as isObjectEmpty,a as loadComponent,i as unixEpochToDate,b as classCallCheck,c as createClass,d as inherits,e as possibleConstructorReturn,f as toConsumableArray}from"./utilities-aabd0479.js";function _CustomElement(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(_CustomElement.prototype,HTMLElement.prototype),Object.setPrototypeOf(_CustomElement,HTMLElement);var template="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",XForecast=function(t){function e(){classCallCheck(this,e);var t=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),n=document.createElement("div");return n.innerHTML=template,t.attachShadow({mode:"open"}).appendChild(n),t}return inherits(e,_CustomElement),createClass(e,[{key:"connectedCallback",value:function(){var t=this;this.refresh().then(function(e){t.render(e),t.currentForecast=e})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&"scale"===t&&this.render(this.currentForecast)}},{key:"_buildDateContainer",value:function(t){var e=this,n=document.createElement("div");if(n.setAttribute("data-x-forecast-date-container",""),t&&!isObjectEmpty(t)){var a=dateTime(new Date).Y("-").m("-").d("").getResults();t.forEach(function(t){var o=t.dt,r=t.temp,i=(t.pressure,t.humidity,t.weather,t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),s=document.createElement("u"),c=unixEpochToDate(o),l=dateTime(c).Y("-").m("-").d().getResults(),u="F"===e.scale?convertTemperature(r.day,"cToF"):r.day,d="F"===e.scale?convertTemperature(r.night,"cToF"):r.night;if(l===a)s.textContent="Today:";else{var p=dateTime(c).date.toLocaleString("en-US",{weekday:"long"}),h=dateTime(c).m("/").d().getResults();s.textContent=p+" ("+h+"):"}var m=document.createElement("li");m.appendChild(s),i.appendChild(m);var f=document.createElement("li");f.textContent="Day: "+Number.parseFloat(u).toFixed(2)+"°"+e.scale,i.appendChild(f);var v=document.createElement("li");v.textContent="Night: "+Number.parseFloat(d).toFixed(2)+"°"+e.scale,i.appendChild(v),n.appendChild(i)})}return n}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t){var e=this.shadowRoot.querySelector("[data-x-forecast]"),n=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");e.replaceChild(this._buildDateContainer(t),n)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),e}(),load=function(){return loadComponent({customElements:customElements,tagName:"x-forecast",element:XForecast})};export default XForecast;export{load}; | ||
import{g as convertTemperature,h as dateTime,j as isObjectEmpty,a as loadComponent,i as unixEpochToDate,b as classCallCheck,c as createClass,d as inherits,e as possibleConstructorReturn,f as toConsumableArray}from"./utilities-aabd0479.js";function _CustomElement(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(_CustomElement.prototype,HTMLElement.prototype),Object.setPrototypeOf(_CustomElement,HTMLElement);var template="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",XForecast=function(t){function e(){classCallCheck(this,e);var t=possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),n=document.createElement("div");return n.innerHTML=template,t.attachShadow({mode:"open"}).appendChild(n),t}return inherits(e,_CustomElement),createClass(e,[{key:"connectedCallback",value:function(){var t=this;this.refresh().then(function(e){t.render(e,t.days),t.currentForecast=e})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&null!==this.days&&("days"!==t&&"scale"!==t||this.render(this.currentForecast,this.days))}},{key:"_buildDayOfWeek",value:function(t){var e=t.dt,n=t.today,a=document.createElement("u"),r=unixEpochToDate(e);if(dateTime(r).Y("-").m("-").d().getResults()===n)a.textContent="Today:";else{var i=dateTime(r).date.toLocaleString("en-US",{weekday:"long"}),o=dateTime(r).m("/").d().getResults();a.textContent=i+" ("+o+"):"}var s=document.createElement("li");return s.appendChild(a),s}},{key:"_buildWeatherIcon",value:function(t){var e=t.description,n="https://openweathermap.org/img/w/"+t.icon+".png",a=document.createElement("img");a.setAttribute("src",n),a.setAttribute("alt",e);var r=document.createElement("li");return r.appendChild(a),r}},{key:"_buildTimeOfDayForecast",value:function(t){var e=t.timeOfDayTemp,n=t.type,a="F"===this.scale?convertTemperature(e,"cToF"):e,r=document.createElement("li");return r.textContent=n+": "+Number.parseFloat(a).toFixed(2)+"°"+this.scale,r}},{key:"_buildDateContainer",value:function(t,e){var n=this,a=document.createElement("div");if(a.setAttribute("data-x-forecast-date-container",""),t&&!isObjectEmpty(t)){var r=dateTime(new Date).Y("-").m("-").d("").getResults();t.length>e&&(t.length=e),t.forEach(function(t){var e=t.dt,i=t.temp,o=(t.pressure,t.humidity,t.weather),s=(t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),c=n._buildDayOfWeek({dt:e,today:r});s.appendChild(c);var u=n._buildWeatherIcon(o[0]);s.appendChild(u);var d=n._buildTimeOfDayForecast({timeOfDayTemp:i.day,type:"Day"});s.appendChild(d);var l=n._buildTimeOfDayForecast({timeOfDayTemp:i.night,type:"Night"});s.appendChild(l),a.appendChild(s)})}return a}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,a=t.location;if(e&&n&&a)return this._serviceHandler({appid:e,host:n,location:a}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,a=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+a+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t,e){var n=this.shadowRoot.querySelector("[data-x-forecast]"),a=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");n.replaceChild(this._buildDateContainer(t,e),a)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"days",get:function(){return this.getAttribute("days")},set:function(t){this.setAttribute("days",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["days","scale"]}}]),e}(),load=function(){return loadComponent({customElements:customElements,tagName:"x-forecast",element:XForecast})};export default XForecast;export{load}; |
@@ -1,1 +0,1 @@ | ||
var Main=function(){"use strict";var r=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e=function(){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}}(),i=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},g=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"cToF",n=function(t){return t+273.15},r=function(t){return t-273.15},i=function(t){return 1.8*t+32},o=function(t){return 5*(t-32)/9};return{cToK:n,kToC:r,cToF:i,fToC:o,kToF:function(t){return i(r(t))},fToK:function(t){return n(o(t))}}[e](t)},t=function(t){var e=t.customElements,n=t.tagName,r=t.element,i=function(t){var e=t.customElements,n=t.tagName,r=t.element;e.define(n,r)};window.customElements?i({customElements:e,tagName:n,element:r}):document.addEventListener("WebComponentsReady",function(){i({customElements:e,tagName:n,element:r})})},v=function(t){return new Date(1e3*t)},b=function(t){return{date:t,results:"",getResults:function(){return this.results},getTimeStamp:function(){return this.date.getTime()},Y:function(t){return this.results+=this.date.getFullYear(),this.sep(t)&&(this.results+=t),this},m:function(t){return this.results+=this.pad(this.date.getMonth()+1),this.sep(t)&&(this.results+=t),this},d:function(t){return this.results+=this.pad(this.date.getDate()),this.sep(t)&&(this.results+=t),this},H:function(t){return this.results+=this.pad(this.date.getHours()),this.sep(t)&&(this.results+=t),this},M:function(t){return this.results+=this.pad(this.date.getMinutes()),this.sep(t)&&(this.results+=t),this},S:function(t){return this.results+=this.pad(this.date.getSeconds()),this.sep(t)&&(this.results+=t),this},pad:function(t){return t<10?"0"+t:t},sep:function(t){return!!t}}};function a(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(a.prototype,HTMLElement.prototype),Object.setPrototypeOf(a,HTMLElement);var n=function(t){function n(){r(this,n);var t=o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-current] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-current] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-current] ul > li {\n padding: 0.5rem 0 0 0;\n }\n\n div[data-x-current] #time {\n display: none;\n }\n\n div[data-x-current] #alternateScale {\n cursor: pointer;\n border-bottom: 1px dotted;\n }\n </style>\n\n <div data-x-current>\n <h3>Current</h3>\n <ul>\n <li id="time"></li>\n <li><img alt="" id="icon"></img></li>\n <li>\n <span id="temperature"></span>°<span id="primaryScale"></span> / <span><a id="alternateScale"></a></span>\n </li>\n </ul>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,a),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentWeather=t,e.primaryScale=e.shadowRoot.querySelector("#primaryScale"),e.alternateScale=e.shadowRoot.querySelector("#alternateScale"),e.primaryScale.textContent=e.scale,e.alternateScale.textContent="C"===e.scale?"F":"C",e.alternateScale.onclick=function(){e.scale=e.alternateScale.textContent;var t=e.parentElement.querySelector("x-forecast");t&&t.setAttribute("scale",e.primaryScale.textContent)}})}},{key:"attributeChangedCallback",value:function(t,e,n){"scale"===t&&e!==n&&this.alternateScale&&this.primaryScale&&("C"===n&&(this.alternateScale.textContent="F",this.primaryScale.textContent=n),"F"===n&&(this.alternateScale.textContent="C",this.primaryScale.textContent=n),this.render(this.currentWeather))}},{key:"_getCurrentWeather",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.coord;var e=t.weather,n=(t.base,t.main),r=(t.visibility,t.wind,t.clouds,t.dt);t.sys,t.id,t.name,t.cod;return{iconAlt:e[0].description,iconSrc:e[0].icon,temperature:{kelvin:n.temp,celsius:g(n.temp,"kToC"),fahrenheit:g(n.temp,"kToF")},timestamp:r}})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/weather?q="+r+"&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getCurrentWeather(t)}},{key:"render",value:function(t){var e=t.iconAlt,n=t.iconSrc,r=t.temperature,i=t.timestamp;this.temperature=Number.parseFloat(r["C"===this.scale?"celsius":"fahrenheit"]).toFixed(2),this.iconAlt=e,this.iconSrc="https://openweathermap.org/img/w/"+n+".png",this.timestamp=i}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"iconAlt",set:function(t){this.shadowRoot.querySelector("#icon").setAttribute("alt",t)}},{key:"iconSrc",set:function(t){this.shadowRoot.querySelector("#icon").src=t}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}},{key:"temperature",set:function(t){this.setAttribute("temperature",t),this.shadowRoot.querySelector("#temperature").textContent=t}},{key:"timestamp",set:function(t){this.shadowRoot.querySelector("#time").textContent=b(v(t)).H(":").M(":").S().getResults()}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}();function s(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(s.prototype,HTMLElement.prototype),Object.setPrototypeOf(s,HTMLElement);var c=function(t){function n(){r(this,n);var t=o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,s),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&"scale"===t&&this.render(this.currentForecast)}},{key:"_buildDateContainer",value:function(t){var e,f=this,m=document.createElement("div");if(m.setAttribute("data-x-forecast-date-container",""),t&&(e=t,0!==Object.keys(e).length||e.constructor!==Object)){var y=b(new Date).Y("-").m("-").d("").getResults();t.forEach(function(t){var e=t.dt,n=t.temp,r=(t.pressure,t.humidity,t.weather,t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),i=document.createElement("u"),o=v(e),a=b(o).Y("-").m("-").d().getResults(),s="F"===f.scale?g(n.day,"cToF"):n.day,c="F"===f.scale?g(n.night,"cToF"):n.night;if(a===y)i.textContent="Today:";else{var u=b(o).date.toLocaleString("en-US",{weekday:"long"}),l=b(o).m("/").d().getResults();i.textContent=u+" ("+l+"):"}var h=document.createElement("li");h.appendChild(i),r.appendChild(h);var d=document.createElement("li");d.textContent="Day: "+Number.parseFloat(s).toFixed(2)+"°"+f.scale,r.appendChild(d);var p=document.createElement("li");p.textContent="Night: "+Number.parseFloat(c).toFixed(2)+"°"+f.scale,r.appendChild(p),m.appendChild(r)})}return m}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+r+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t){var e=this.shadowRoot.querySelector("[data-x-forecast]"),n=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");e.replaceChild(this._buildDateContainer(t),n)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}();function u(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(u.prototype,HTMLElement.prototype),Object.setPrototypeOf(u,HTMLElement);var l=function(t){function n(){r(this,n);var t=o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-weather] #location {\n border: 0;\n font-style: italic;\n margin: 0 0 0 2.5%;\n padding: 0 2.5% 0 0;\n width: 95%;\n }\n </style>\n\n <div data-x-weather>\n <div><input id="location"></input></div>\n\n <slot></slot>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,u),e(n,[{key:"connectedCallback",value:function(){var e=this;this._upgradeProperty("appid"),this._upgradeProperty("host"),this._upgradeProperty("location"),this.xCurrent=this.querySelector("x-current"),this.xForecast=this.querySelector("x-forecast"),this._renderLocation(this.location);var t=this.shadowRoot.querySelector("#location");t.addEventListener("change",function(){e.location=t.value,e.xCurrent.refresh().then(function(t){e.xCurrent.render(t),e.xCurrent.currentWeather=t}),e.xForecast.refresh().then(function(t){e.xForecast.render(t),e.xForecast.currentForecast=t})})}},{key:"attributeChangedCallback",value:function(t,e,n){(e!==n&&"appid"===t||"host"===t||"location"===t)&&("location"===t&&this._renderLocation(this.location),this.xCurrent&&this.xCurrent.setAttribute(t,n),this.xForecast&&this.xForecast.setAttribute(t,n))}},{key:"_renderLocation",value:function(t){this.shadowRoot.querySelector("#location").value=t}},{key:"_upgradeProperty",value:function(t){if(this.hasOwnProperty(t)){var e=this[t];delete this[t],this[t]=e}}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}}],[{key:"observedAttributes",get:function(){return["appid","host","location"]}}]),n}();return t({customElements:customElements,tagName:"x-current",element:n}),t({customElements:customElements,tagName:"x-forecast",element:c}),t({customElements:customElements,tagName:"x-weather",element:l}),{XCurrent:n,XForecast:c,XWeather:l}}(); | ||
var Main=function(){"use strict";var r=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},e=function(){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}}(),i=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},a=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"cToF",n=function(t){return t+273.15},r=function(t){return t-273.15},i=function(t){return 1.8*t+32},o=function(t){return 5*(t-32)/9};return{cToK:n,kToC:r,cToF:i,fToC:o,kToF:function(t){return i(r(t))},fToK:function(t){return n(o(t))}}[e](t)},t=function(t){var e=t.customElements,n=t.tagName,r=t.element,i=function(t){var e=t.customElements,n=t.tagName,r=t.element;e.define(n,r)};window.customElements?i({customElements:e,tagName:n,element:r}):document.addEventListener("WebComponentsReady",function(){i({customElements:e,tagName:n,element:r})})},c=function(t){return new Date(1e3*t)},d=function(t){return{date:t,results:"",getResults:function(){return this.results},getTimeStamp:function(){return this.date.getTime()},Y:function(t){return this.results+=this.date.getFullYear(),this.sep(t)&&(this.results+=t),this},m:function(t){return this.results+=this.pad(this.date.getMonth()+1),this.sep(t)&&(this.results+=t),this},d:function(t){return this.results+=this.pad(this.date.getDate()),this.sep(t)&&(this.results+=t),this},H:function(t){return this.results+=this.pad(this.date.getHours()),this.sep(t)&&(this.results+=t),this},M:function(t){return this.results+=this.pad(this.date.getMinutes()),this.sep(t)&&(this.results+=t),this},S:function(t){return this.results+=this.pad(this.date.getSeconds()),this.sep(t)&&(this.results+=t),this},pad:function(t){return t<10?"0"+t:t},sep:function(t){return!!t}}};function s(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(s.prototype,HTMLElement.prototype),Object.setPrototypeOf(s,HTMLElement);var n=function(t){function n(){r(this,n);var t=o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-current] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-current] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-current] ul > li {\n padding: 0.5rem 0 0 0;\n }\n\n div[data-x-current] #time {\n display: none;\n }\n\n div[data-x-current] #alternateScale {\n cursor: pointer;\n border-bottom: 1px dotted;\n }\n </style>\n\n <div data-x-current>\n <h3>Current</h3>\n <ul>\n <li id="time"></li>\n <li><img alt="" id="icon"></img></li>\n <li>\n <span id="temperature"></span>°<span id="primaryScale"></span> / <span><a id="alternateScale"></a></span>\n </li>\n </ul>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,s),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t),e.currentWeather=t,e.primaryScale=e.shadowRoot.querySelector("#primaryScale"),e.alternateScale=e.shadowRoot.querySelector("#alternateScale"),e.primaryScale.textContent=e.scale,e.alternateScale.textContent="C"===e.scale?"F":"C",e.alternateScale.onclick=function(){e.scale=e.alternateScale.textContent;var t=e.parentElement.querySelector("x-forecast");t&&t.setAttribute("scale",e.primaryScale.textContent)}})}},{key:"attributeChangedCallback",value:function(t,e,n){"scale"===t&&e!==n&&this.alternateScale&&this.primaryScale&&("C"===n&&(this.alternateScale.textContent="F",this.primaryScale.textContent=n),"F"===n&&(this.alternateScale.textContent="C",this.primaryScale.textContent=n),this.render(this.currentWeather))}},{key:"_getCurrentWeather",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.coord;var e=t.weather,n=(t.base,t.main),r=(t.visibility,t.wind,t.clouds,t.dt);t.sys,t.id,t.name,t.cod;return{iconAlt:e[0].description,iconSrc:e[0].icon,temperature:{kelvin:n.temp,celsius:a(n.temp,"kToC"),fahrenheit:a(n.temp,"kToF")},timestamp:r}})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/weather?q="+r+"&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getCurrentWeather(t)}},{key:"render",value:function(t){var e=t.iconAlt,n=t.iconSrc,r=t.temperature,i=t.timestamp;this.temperature=Number.parseFloat(r["C"===this.scale?"celsius":"fahrenheit"]).toFixed(2),this.iconAlt=e,this.iconSrc="https://openweathermap.org/img/w/"+n+".png",this.timestamp=i}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"iconAlt",set:function(t){this.shadowRoot.querySelector("#icon").setAttribute("alt",t)}},{key:"iconSrc",set:function(t){this.shadowRoot.querySelector("#icon").src=t}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}},{key:"temperature",set:function(t){this.setAttribute("temperature",t),this.shadowRoot.querySelector("#temperature").textContent=t}},{key:"timestamp",set:function(t){this.shadowRoot.querySelector("#time").textContent=d(c(t)).H(":").M(":").S().getResults()}}],[{key:"observedAttributes",get:function(){return["scale"]}}]),n}();function u(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(u.prototype,HTMLElement.prototype),Object.setPrototypeOf(u,HTMLElement);var l=function(t){function n(){r(this,n);var t=o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML="\n <style>\n :host {\n display: block;\n }\n\n div[data-x-forecast] h3 {\n padding-left: 0.5rem;\n }\n\n div[data-x-forecast] ul {\n list-style-type: none;\n padding: 0 0 1rem 1.5rem;\n }\n\n div[data-x-forecast] ul > li {\n padding: 0.5rem 0 0 0;\n }\n </style>\n\n <div data-x-forecast>\n <h3>Forecast</h3>\n\n <div data-x-forecast-date-container>\n <div/>\n",t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,u),e(n,[{key:"connectedCallback",value:function(){var e=this;this.refresh().then(function(t){e.render(t,e.days),e.currentForecast=t})}},{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&null!==this.days&&("days"!==t&&"scale"!==t||this.render(this.currentForecast,this.days))}},{key:"_buildDayOfWeek",value:function(t){var e=t.dt,n=t.today,r=document.createElement("u"),i=c(e);if(d(i).Y("-").m("-").d().getResults()===n)r.textContent="Today:";else{var o=d(i).date.toLocaleString("en-US",{weekday:"long"}),a=d(i).m("/").d().getResults();r.textContent=o+" ("+a+"):"}var s=document.createElement("li");return s.appendChild(r),s}},{key:"_buildWeatherIcon",value:function(t){var e=t.description,n="https://openweathermap.org/img/w/"+t.icon+".png",r=document.createElement("img");r.setAttribute("src",n),r.setAttribute("alt",e);var i=document.createElement("li");return i.appendChild(r),i}},{key:"_buildTimeOfDayForecast",value:function(t){var e=t.timeOfDayTemp,n=t.type,r="F"===this.scale?a(e,"cToF"):e,i=document.createElement("li");return i.textContent=n+": "+Number.parseFloat(r).toFixed(2)+"°"+this.scale,i}},{key:"_buildDateContainer",value:function(t,e){var n,u=this,l=document.createElement("div");if(l.setAttribute("data-x-forecast-date-container",""),t&&(n=t,0!==Object.keys(n).length||n.constructor!==Object)){var h=d(new Date).Y("-").m("-").d("").getResults();t.length>e&&(t.length=e),t.forEach(function(t){var e=t.dt,n=t.temp,r=(t.pressure,t.humidity,t.weather),i=(t.speed,t.deg,t.clouds,t.rain,document.createElement("ul")),o=u._buildDayOfWeek({dt:e,today:h});i.appendChild(o);var a=u._buildWeatherIcon(r[0]);i.appendChild(a);var s=u._buildTimeOfDayForecast({timeOfDayTemp:n.day,type:"Day"});i.appendChild(s);var c=u._buildTimeOfDayForecast({timeOfDayTemp:n.night,type:"Night"});i.appendChild(c),l.appendChild(i)})}return l}},{key:"_getForecast",value:function(t){var e=t.appid,n=t.host,r=t.location;if(e&&n&&r)return this._serviceHandler({appid:e,host:n,location:r}).then(function(t){t.city,t.cod,t.message,t.cnt;return t.list})}},{key:"_serviceHandler",value:function(t){var e=t.appid,n=t.host,r=t.location;return fetch("https://"+n+"/data/2.5/forecast/daily?q="+r+"&mode=json&units=metric&cnt=14&appid="+e,{method:"GET"}).then(function(t){if(t.ok)return t.json()})}},{key:"refresh",value:function(){var t={appid:this.parentElement.getAttribute("appid"),host:this.parentElement.getAttribute("host"),location:this.parentElement.getAttribute("location")};return this._getForecast(t)}},{key:"render",value:function(t,e){var n=this.shadowRoot.querySelector("[data-x-forecast]"),r=this.shadowRoot.querySelector("[data-x-forecast] > [data-x-forecast-date-container]");n.replaceChild(this._buildDateContainer(t,e),r)}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"days",get:function(){return this.getAttribute("days")},set:function(t){this.setAttribute("days",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}},{key:"scale",get:function(){return this.getAttribute("scale")},set:function(t){this.setAttribute("scale",t)}}],[{key:"observedAttributes",get:function(){return["days","scale"]}}]),n}();function h(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}Object.setPrototypeOf(h.prototype,HTMLElement.prototype),Object.setPrototypeOf(h,HTMLElement);var p=function(t){function n(){r(this,n);var t=o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this)),e=document.createElement("div");return e.innerHTML='\n <style>\n :host {\n display: block;\n }\n\n div[data-x-weather] #location {\n border: 0;\n font-style: italic;\n margin: 0 0 0 2.5%;\n padding: 0 2.5% 0 0;\n width: 95%;\n }\n </style>\n\n <div data-x-weather>\n <div><input id="location"></input></div>\n\n <slot></slot>\n </div>\n',t.attachShadow({mode:"open"}).appendChild(e),t}return i(n,h),e(n,[{key:"connectedCallback",value:function(){var e=this;this._upgradeProperty("appid"),this._upgradeProperty("host"),this._upgradeProperty("location"),this.xCurrent=this.querySelector("x-current"),this.xForecast=this.querySelector("x-forecast"),this._renderLocation(this.location);var t=this.shadowRoot.querySelector("#location");t.addEventListener("change",function(){e.location=t.value,e.xCurrent.refresh().then(function(t){e.xCurrent.render(t),e.xCurrent.currentWeather=t}),e.xForecast.refresh().then(function(t){e.xForecast.render(t),e.xForecast.currentForecast=t})})}},{key:"attributeChangedCallback",value:function(t,e,n){(e!==n&&"appid"===t||"host"===t||"location"===t)&&("location"===t&&this._renderLocation(this.location),this.xCurrent&&this.xCurrent.setAttribute(t,n),this.xForecast&&this.xForecast.setAttribute(t,n))}},{key:"_renderLocation",value:function(t){this.shadowRoot.querySelector("#location").value=t}},{key:"_upgradeProperty",value:function(t){if(this.hasOwnProperty(t)){var e=this[t];delete this[t],this[t]=e}}},{key:"appid",get:function(){return this.getAttribute("appid")},set:function(t){this.setAttribute("appid",t)}},{key:"host",get:function(){return this.getAttribute("host")},set:function(t){this.setAttribute("host",t)}},{key:"location",get:function(){return this.getAttribute("location")},set:function(t){this.setAttribute("location",t)}}],[{key:"observedAttributes",get:function(){return["appid","host","location"]}}]),n}();return t({customElements:customElements,tagName:"x-current",element:n}),t({customElements:customElements,tagName:"x-forecast",element:l}),t({customElements:customElements,tagName:"x-weather",element:p}),{XCurrent:n,XForecast:l,XWeather:p}}(); |
{ | ||
"name": "x-weather", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A collection of web components implementing portions of the OpenWeatherMap API.", | ||
@@ -21,11 +21,11 @@ "files": [ | ||
"browser-sync": "npx browser-sync start --server --serveStatic ./dist/ --files ./dist/** ./src/**", | ||
"build-custom-elements-shady-dom-esm": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.custom.elements.shady.dom-esm.js && npm run copy-custom-elements-shady-dom-esm", | ||
"build-custom-elements-shady-dom-systemjs": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.custom.elements.shady.dom-systemjs.js && npm run copy-custom-elements-shady-dom-systemjs", | ||
"build-ie11-systemjs": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.ie11-systemjs.js && npm run copy-ie11-systemjs", | ||
"build-ie11-iife": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.ie11-iife.js && npm run copy-ie11-iife", | ||
"build-ie11-iife-ssr": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.ie11-iife-ssr.js", | ||
"build-no-polyfills-esm": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.no.polyfills-esm.js && npm run copy-no-polyfills-esm", | ||
"build-no-polyfills-iife": "npx rimraf ./dist && mkdirp ./dist && npx rollup --config ./config/rollup.config.no.polyfills-iife.js && npm run copy-no-polyfills-iife", | ||
"build-custom-elements-shady-dom-esm": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.custom.elements.shady.dom-esm.js && npm run copy-custom-elements-shady-dom-esm", | ||
"build-custom-elements-shady-dom-systemjs": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.custom.elements.shady.dom-systemjs.js && npm run copy-custom-elements-shady-dom-systemjs", | ||
"build-ie11-systemjs": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.ie11-systemjs.js && npm run copy-ie11-systemjs", | ||
"build-ie11-iife": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.ie11-iife.js && npm run copy-ie11-iife", | ||
"build-ie11-iife-ssr": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.ie11-iife-ssr.js", | ||
"build-no-polyfills-esm": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.no.polyfills-esm.js && npm run copy-no-polyfills-esm", | ||
"build-no-polyfills-iife": "npx rimraf ./dist && npx mkdirp ./dist && npx rollup --config ./config/rollup.config.no.polyfills-iife.js && npm run copy-no-polyfills-iife", | ||
"build": "npm run bootstrap && npm run build-ie11-iife", | ||
"bundle-modules": "npx rimraf ./bundle && mkdirp ./bundle && npx rimraf ./dist ./lib && npm run build-ie11-systemjs && npx ncp ./dist ./bundle/build-ie11-systemjs && npx rimraf ./dist && npm run build-ie11-iife && npx ncp ./dist ./bundle/build-ie11-iife && npx rimraf ./dist && npm run build-no-polyfills-esm && npx ncp ./dist ./bundle/build-no-polyfills-esm && npx rimraf ./dist && npm run build-no-polyfills-iife && npx ncp ./dist ./bundle/build-no-polyfills-iife && npx rimraf ./dist && npm run build-custom-elements-shady-dom-esm && npx ncp ./dist ./bundle/build-custom-elements-shady-dom-esm && npx rimraf ./dist && npm run build-custom-elements-shady-dom-systemjs && npx ncp ./dist ./bundle/build-custom-elements-shady-dom-systemjs && npx rimraf ./dist && npx ncp ./bundle ./dist && npx rimraf ./bundle && npx ncp ./dist ./lib", | ||
"bundle-modules": "npx rimraf ./bundle && npx mkdirp ./bundle && npx rimraf ./dist ./lib && npm run build-ie11-systemjs && npx ncp ./dist ./bundle/build-ie11-systemjs && npx rimraf ./dist && npm run build-ie11-iife && npx ncp ./dist ./bundle/build-ie11-iife && npx rimraf ./dist && npm run build-no-polyfills-esm && npx ncp ./dist ./bundle/build-no-polyfills-esm && npx rimraf ./dist && npm run build-no-polyfills-iife && npx ncp ./dist ./bundle/build-no-polyfills-iife && npx rimraf ./dist && npm run build-custom-elements-shady-dom-esm && npx ncp ./dist ./bundle/build-custom-elements-shady-dom-esm && npx rimraf ./dist && npm run build-custom-elements-shady-dom-systemjs && npx ncp ./dist ./bundle/build-custom-elements-shady-dom-systemjs && npx rimraf ./dist && npx ncp ./bundle ./dist && npx rimraf ./bundle && npx ncp ./dist ./lib", | ||
"copy-custom-elements-shady-dom-esm": "npx ncp src/index.custom.elements.shady.dom-esm.html dist/index.html && npx ncp assets/favicon.ico dist/", | ||
@@ -32,0 +32,0 @@ "copy-custom-elements-shady-dom-systemjs": "npx ncp src/index.custom.elements.shady.dom-systemjs.html dist/index.html && npx ncp assets/favicon.ico dist/", |
@@ -58,3 +58,3 @@ x-weather | ||
<x-current scale="F"></x-current> | ||
<x-forecast scale="F"></x-forecast> | ||
<x-forecast days="2" scale="F"></x-forecast> | ||
</x-weather> | ||
@@ -61,0 +61,0 @@ ``` |
@@ -166,3 +166,3 @@ import { convertTemperature, dateTime, loadComponent, unixEpochToDate } from '../utilities.js' | ||
if (appid && host && location) { | ||
// this is a main API call, and ultimately should trigger an attribute change | ||
return this._serviceHandler({ appid, host, location }).then(result => { | ||
@@ -169,0 +169,0 @@ const { coord, weather, base, main, visibility, wind, clouds, dt, sys, id, name, cod } = result // eslint-disable-line no-unused-vars |
@@ -42,4 +42,4 @@ import { convertTemperature, dateTime, isObjectEmpty, loadComponent, unixEpochToDate } from '../utilities.js' | ||
connectedCallback() { | ||
this.refresh().then(currentForecast => { | ||
this.render(currentForecast) | ||
this.refresh().then((currentForecast) => { | ||
this.render(currentForecast, this.days) | ||
@@ -52,10 +52,18 @@ // set this as a class property to be used later | ||
attributeChangedCallback(attrName, oldVal, newVal) { | ||
// handle the scale attribute change | ||
if (oldVal !== newVal && attrName === 'scale' ) { | ||
this.render(this.currentForecast) | ||
// handle the scale and days attribute change | ||
if (oldVal === newVal) { | ||
return | ||
} | ||
if (this.days === null) { | ||
return | ||
} | ||
if (attrName === 'days' || attrName === 'scale') { | ||
this.render(this.currentForecast, this.days) | ||
} | ||
} | ||
static get observedAttributes() { | ||
return [ 'scale' ] | ||
return [ 'days', 'scale' ] | ||
} | ||
@@ -71,2 +79,10 @@ | ||
get days() { | ||
return this.getAttribute('days') | ||
} | ||
set days(days) { | ||
this.setAttribute('days', days) | ||
} | ||
get host() { | ||
@@ -96,3 +112,45 @@ return this.getAttribute('host') | ||
_buildDateContainer(forecast) { | ||
_buildDayOfWeek({ dt, today }) { | ||
const dayOfWeek = document.createElement('u') | ||
const timestamp = unixEpochToDate(dt) | ||
const current = dateTime(timestamp).Y('-').m('-').d().getResults() | ||
if (current === today) { | ||
dayOfWeek.textContent = 'Today:' | ||
} else { | ||
const weekDay = dateTime(timestamp)['date'].toLocaleString('en-US', { weekday: 'long'} ) | ||
const ddMM = dateTime(timestamp).m('/').d().getResults() | ||
dayOfWeek.textContent = `${weekDay} (${ddMM}):` | ||
} | ||
const dayOfWeekItem = document.createElement('li') | ||
dayOfWeekItem.appendChild(dayOfWeek) | ||
return dayOfWeekItem | ||
} | ||
_buildWeatherIcon({ description, icon }) { | ||
const iconAlt = description | ||
const iconSrc = `https://openweathermap.org/img/w/${icon}.png` | ||
const weatherImg = document.createElement('img') | ||
weatherImg.setAttribute('src', iconSrc) | ||
weatherImg.setAttribute('alt', iconAlt) | ||
const weatherIcon = document.createElement('li') | ||
weatherIcon.appendChild(weatherImg) | ||
return weatherIcon | ||
} | ||
_buildTimeOfDayForecast({ timeOfDayTemp, type }) { | ||
const temp = this.scale === 'F' ? convertTemperature(timeOfDayTemp, 'cToF') : timeOfDayTemp | ||
const dayListItem = document.createElement('li') | ||
dayListItem.textContent = `${type}: ${Number.parseFloat(temp).toFixed(2)}°${this.scale}` | ||
return dayListItem | ||
} | ||
_buildDateContainer(forecast, days) { | ||
const dateContainer = document.createElement('div') | ||
@@ -105,2 +163,8 @@ dateContainer.setAttribute('data-x-forecast-date-container', '') | ||
// shorten the forecast to the requested number of days, https://mzl.la/2JDIuy6 | ||
// if the attribute is changed to be smaller | ||
if (forecast.length > days) { | ||
forecast.length = days; | ||
} | ||
forecast.forEach(props => { | ||
@@ -110,32 +174,13 @@ const { dt, temp, pressure, humidity, weather, speed, deg, clouds, rain } = props // eslint-disable-line no-unused-vars | ||
const dateItem = document.createElement('ul') | ||
const dayOfWeek = document.createElement('u') | ||
const timestamp = unixEpochToDate(dt) | ||
const current = dateTime(timestamp).Y('-').m('-').d().getResults() | ||
const day = this.scale === 'F' ? convertTemperature(temp.day, 'cToF') : temp.day | ||
const night = this.scale === 'F' ? convertTemperature(temp.night, 'cToF') : temp.night | ||
if (current === today) { | ||
dayOfWeek.textContent = 'Today:' | ||
} else { | ||
const weekDay = dateTime(timestamp)['date'].toLocaleString('en-US', { weekday: 'long'} ) | ||
const ddMM = dateTime(timestamp).m('/').d().getResults() | ||
dayOfWeek.textContent = `${weekDay} (${ddMM}):` | ||
} | ||
const dayOfWeekItem = document.createElement('li') | ||
dayOfWeekItem.appendChild(dayOfWeek) | ||
const dayOfWeekItem = this._buildDayOfWeek({ dt, today }) | ||
dateItem.appendChild(dayOfWeekItem) | ||
const dayListItem = document.createElement('li') | ||
dayListItem.textContent = `Day: ${Number.parseFloat(day).toFixed(2)}°${this.scale}` | ||
const weatherIcon = this._buildWeatherIcon(weather[0]) | ||
dateItem.appendChild(weatherIcon) | ||
const dayListItem = this._buildTimeOfDayForecast({ timeOfDayTemp: temp.day, type: 'Day' }) | ||
dateItem.appendChild(dayListItem) | ||
const nightListItem = document.createElement('li') | ||
nightListItem.textContent = `Night: ${Number.parseFloat(night).toFixed(2)}°${this.scale}` | ||
const nightListItem = this._buildTimeOfDayForecast({ timeOfDayTemp: temp.night, type: 'Night' }) | ||
dateItem.appendChild(nightListItem) | ||
@@ -155,3 +200,2 @@ | ||
// set the class property "forecast" to result.list | ||
return list | ||
@@ -185,7 +229,7 @@ }) | ||
render(res) { | ||
render(res, days) { | ||
const forecastDayNode = this.shadowRoot.querySelector('[data-x-forecast]') | ||
const dateContainerNode = this.shadowRoot.querySelector('[data-x-forecast] > [data-x-forecast-date-container]') | ||
forecastDayNode.replaceChild(this._buildDateContainer(res), dateContainerNode) | ||
forecastDayNode.replaceChild(this._buildDateContainer(res, days), dateContainerNode) | ||
} | ||
@@ -192,0 +236,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
153330
1262