UNPKG

moon-phase-widget

Version:
1 lines 9.64 kB
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MoonPhaseWidget=t():n.MoonPhaseWidget=t()}(window,(function(){return function(n){var t={};function e(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return n[o].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=n,e.c=t,e.d=function(n,t,o){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:o})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e.t=function(n,t){if(1&t&&(n=e(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var o=Object.create(null);if(e.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var i in n)e.d(o,i,function(t){return n[t]}.bind(null,i));return o},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=6)}([function(n,t,e){"use strict";const o=window.localStorage||{},i={ip:"104.131.241.248",city:"Gramercy Park",region:"New York",country:"US",loc:"40.7402,-73.9996",org:"AS14061 DigitalOcean, LLC",postal:"10011",timezone:"America/New_York",readme:"https://ipinfo.io/missingauth"};t.a=async function(){let n=function(){const n="localStorageTest";try{return o.setItem(n,n),o.removeItem(n),!0}catch(n){return!1}}(),t=n&&JSON.parse(o.getItem("mph-widget-geodata"));if(t)return t;try{const n=await fetch("https://ipinfo.io/json");n.ok&&(t=await n.json())}catch(n){console.warn(n)}t=t||i;const[e,r]=t.loc.split(",");return Object.assign(t,{latitude:parseFloat(e),longitude:parseFloat(r)}),n&&o.setItem("mph-widget-geodata",JSON.stringify(t)),t}},function(n,t,e){"use strict";t.a=function(n,t){return`\n<div class="mph-widget">\n <div class="mph-widget-body">\n <div class="mph-col">\n <div class="mph-row">\n <div class="current-date">${n.dateFmt}</div>\n </div>\n <div class="mph-row">\n <div class="current-place">${t.city}, ${t.country}</div>\n </div>\n <div class="mph-row">\n <div class="moon-phase-ico">\n <img src="${n.phaseIco}" />\n </div>\n </div>\n </div>\n <div class="mph-col">\n <div class="mph-row">\n <div class="phase-name">${n.phase}</div>\n </div>\n <div class="mph-row">\n <div class="zodiac-name">Moon in <strong>${n.zodiac}</strong></div>\n </div>\n <div class="mph-row">\n <div>Set: </div>\n <div class="moon-time">${n.set}</div>\n </div>\n <div class="mph-row">\n <div>Rise: </div>\n <div class="moon-time">${n.rise}</div>\n </div>\n </div>\n </div>\n <div class="mph-row mph-link">\n <a href="${n.link}" target="_blank">${n.linkLabel}</a>\n </div>\n</div>\n `}},function(n,t,e){"use strict";var o=e(0),i=e(1);t.a=class{constructor(n="moon-phase-widget",t=o.a,e=i.a){this.containerId=n,this.el=document.getElementById(n),this.getGeoDataFn=t,this.renderFn=e,this.mount().catch(n=>console.log(n))}async mount(){const n=await this.getGeoDataFn(),t=await this.getMoonPhaseData(n.latitude,n.longitude);this.el.innerHTML=this.renderFn(t,n),this.loadBackgroundColor()}async getMoonPhaseData(n,t){const e=await fetch("https://moonorganizer.com/api/public/moon-phase",{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:JSON.stringify({latitude:n,longitude:t,date:new Date})});return await e.json()}loadBackgroundColor(){const n=this.el.dataset.color;n&&this.el.firstElementChild&&(this.el.firstElementChild.style.backgroundColor=n)}}},function(n,t,e){"use strict";n.exports=function(n){var t=[];return t.toString=function(){return this.map((function(t){var e=function(n,t){var e=n[1]||"",o=n[3];if(!o)return e;if(t&&"function"==typeof btoa){var i=(a=o,s=btoa(unescape(encodeURIComponent(JSON.stringify(a)))),c="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(s),"/*# ".concat(c," */")),r=o.sources.map((function(n){return"/*# sourceURL=".concat(o.sourceRoot).concat(n," */")}));return[e].concat(r).concat([i]).join("\n")}var a,s,c;return[e].join("\n")}(t,n);return t[2]?"@media ".concat(t[2],"{").concat(e,"}"):e})).join("")},t.i=function(n,e){"string"==typeof n&&(n=[[null,n,""]]);for(var o={},i=0;i<this.length;i++){var r=this[i][0];null!=r&&(o[r]=!0)}for(var a=0;a<n.length;a++){var s=n[a];null!=s[0]&&o[s[0]]||(e&&!s[2]?s[2]=e:e&&(s[2]="(".concat(s[2],") and (").concat(e,")")),t.push(s))}},t}},function(n,t,e){"use strict";var o,i={},r=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},a=function(){var n={};return function(t){if(void 0===n[t]){var e=document.querySelector(t);if(window.HTMLIFrameElement&&e instanceof window.HTMLIFrameElement)try{e=e.contentDocument.head}catch(n){e=null}n[t]=e}return n[t]}}();function s(n,t){for(var e=[],o={},i=0;i<n.length;i++){var r=n[i],a=t.base?r[0]+t.base:r[0],s={css:r[1],media:r[2],sourceMap:r[3]};o[a]?o[a].parts.push(s):e.push(o[a]={id:a,parts:[s]})}return e}function c(n,t){for(var e=0;e<n.length;e++){var o=n[e],r=i[o.id],a=0;if(r){for(r.refs++;a<r.parts.length;a++)r.parts[a](o.parts[a]);for(;a<o.parts.length;a++)r.parts.push(v(o.parts[a],t))}else{for(var s=[];a<o.parts.length;a++)s.push(v(o.parts[a],t));i[o.id]={id:o.id,refs:1,parts:s}}}}function l(n){var t=document.createElement("style");if(void 0===n.attributes.nonce){var o=e.nc;o&&(n.attributes.nonce=o)}if(Object.keys(n.attributes).forEach((function(e){t.setAttribute(e,n.attributes[e])})),"function"==typeof n.insert)n.insert(t);else{var i=a(n.insert||"head");if(!i)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");i.appendChild(t)}return t}var d,u=(d=[],function(n,t){return d[n]=t,d.filter(Boolean).join("\n")});function p(n,t,e,o){var i=e?"":o.css;if(n.styleSheet)n.styleSheet.cssText=u(t,i);else{var r=document.createTextNode(i),a=n.childNodes;a[t]&&n.removeChild(a[t]),a.length?n.insertBefore(r,a[t]):n.appendChild(r)}}function f(n,t,e){var o=e.css,i=e.media,r=e.sourceMap;if(i&&n.setAttribute("media",i),r&&btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),n.styleSheet)n.styleSheet.cssText=o;else{for(;n.firstChild;)n.removeChild(n.firstChild);n.appendChild(document.createTextNode(o))}}var h=null,m=0;function v(n,t){var e,o,i;if(t.singleton){var r=m++;e=h||(h=l(t)),o=p.bind(null,e,r,!1),i=p.bind(null,e,r,!0)}else e=l(t),o=f.bind(null,e,t),i=function(){!function(n){if(null===n.parentNode)return!1;n.parentNode.removeChild(n)}(e)};return o(n),function(t){if(t){if(t.css===n.css&&t.media===n.media&&t.sourceMap===n.sourceMap)return;o(n=t)}else i()}}n.exports=function(n,t){(t=t||{}).attributes="object"==typeof t.attributes?t.attributes:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=r());var e=s(n,t);return c(e,t),function(n){for(var o=[],r=0;r<e.length;r++){var a=e[r],l=i[a.id];l&&(l.refs--,o.push(l))}n&&c(s(n,t),t);for(var d=0;d<o.length;d++){var u=o[d];if(0===u.refs){for(var p=0;p<u.parts.length;p++)u.parts[p]();delete i[u.id]}}}}},,function(n,t,e){"use strict";e.r(t);e(7);new(e(2).a)},function(n,t,e){var o=e(8);"string"==typeof o&&(o=[[n.i,o,""]]);var i={insert:"head",singleton:!1};e(4)(o,i);o.locals&&(n.exports=o.locals)},function(n,t,e){(n.exports=e(3)(!1)).push([n.i,'.mph-widget {\n width: 250px;\n min-height: 400px;\n height: auto;\n word-break: break-all;\n position: relative;\n display: inline-flex;\n flex-direction: column;\n text-align: center;\n border-radius: 15px;\n box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);\n font-family: Helvetica, sans-serif;\n color: #212121;\n font-weight: 400;\n font-size: 16px;\n line-height: normal;\n}\n\n[data-style="small"] .mph-widget {\n font-size: 12px;\n width: 160px;\n min-height: 300px;\n height: auto;\n}\n\n[data-style="horizontal"] .mph-widget {\n font-size: 12px;\n width: 320px;\n min-height: 100px;\n height: auto;\n}\n\n.mph-widget-body {\n display: flex;\n flex-direction: column;\n}\n\n[data-style="horizontal"] .mph-widget-body {\n display: flex;\n flex-direction: row;\n}\n\n.mph-row {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n justify-content: center;\n margin: 7px 0;\n}\n\n.mph-col {\n display: flex;\n flex-direction: column;\n}\n\n[data-style="horizontal"] .mph-col {\n width: 500%;\n}\n\n.mph-widget .moon-phase-ico {\n width: 50%;\n}\n\n.mph-widget .moon-phase-ico img {\n width: 100%;\n}\n\n.mph-row.mph-link {\n margin-top: auto;\n}\n\n.moon-time {\n margin-left: 5px;\n}\n\n.mph-row .current-date {\n margin-top: 10px;\n font-weight: bold;\n font-size: 1.125em;\n}\n\n[data-style="small"] .mph-row .current-date {\n font-size: 1em;\n}\n\n.phase-name{\n font-weight: bold;\n font-size: 1.125em;\n}\n\n[data-style="horizontal"] .phase-name{\n margin-top: 10px;\n}\n\n.mph-link a {\n text-decoration: underline;\n}\n\n.mph-link a:link,\n.mph-link a:visited {\n color: #212121;\n text-decoration: underline;\n}\n\n.mph-link a:hover,\n.mph-link a:active {\n color: #0000EE;\n text-decoration: underline;\n}',""])}])}));