PreUpVer/dist/js/preupver.min.js

3 lines
12 KiB
JavaScript

/*! PreUpVer v1.0.0 | https://git.vdm.dev/Llewellyn/PreUpVer | (c) 2014 - 2023 Llewellyn van der Merwe | MIT License */
!function(t){"function"==typeof define&&define.amd?define(t):t()}((function(){"use strict";function t(){t=function(){return r};var e,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(e){l=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=e&&e.prototype instanceof g?e:g,a=Object.create(o.prototype),c=new T(n||[]);return i(a,"_invoke",{value:_(t,r,c)}),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var p="suspendedStart",v="suspendedYield",d="executing",y="completed",w={};function g(){}function m(){}function b(){}var E={};l(E,c,(function(){return this}));var x=Object.getPrototypeOf,k=x&&x(x(I([])));k&&k!==n&&o.call(k,c)&&(E=k);var L=b.prototype=g.prototype=Object.create(E);function O(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&o.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new e((function(e,n){r(t,o,e,n)}))}return n=n?n.then(i,i):i()}})}function _(t,r,n){var o=p;return function(i,a){if(o===d)throw new Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:e,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=j(c,n);if(u){if(u===w)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=h(t,r,n);if("normal"===s.type){if(o=n.done?y:v,s.arg===w)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function j(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,j(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),w;var i=h(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,w;var a=i.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,w):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,w)}function N(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(N,this),this.reset(!0)}function I(t){if(t||""===t){var r=t[c];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(o.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return m.prototype=b,i(L,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:m,configurable:!0}),m.displayName=l(b,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,s,"GeneratorFunction")),t.prototype=Object.create(L),t},r.awrap=function(t){return{__await:t}},O(S.prototype),l(S.prototype,u,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new S(f(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(L),l(L,s,"Generator"),l(L,c,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=I,T.prototype={constructor:T,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(P),!t)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),s=o.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,w):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),w},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),w}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:I(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),w}},r}function e(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function i(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function a(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function c(t,e){return function(t,e){if(e.get)return e.get.call(t);return e.value}(t,s(t,e,"get"))}function u(t,e,r){return function(t,e,r){if(e.set)e.set.call(t,r);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=r}}(t,s(t,e,"set"),r),r}function s(t,e,r){if(!e.has(t))throw new TypeError("attempted to "+r+" private field on non-instance");return e.get(t)}function l(t,e,r){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return r}function f(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function h(t,e,r){f(t,e),e.set(t,r)}function p(t,e){f(t,e),e.add(t)}var v,d,y,w=function(){function e(){n(this,e)}var o;return i(e,null,[{key:"set",value:function(t,e){var r={data:e,timestamp:Date.now()};try{localStorage.setItem(t,JSON.stringify(r))}catch(t){throw console.error("Error storing data in local storage:",t),t}}},{key:"get",value:(o=r(t().mark((function r(n){var o,i,a;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,!(o=localStorage.getItem(n))){t.next=6;break}if(i=JSON.parse(o),a=i.data,!(i.timestamp>Date.now()-e.ONE_DAY_IN_MILLISECONDS)){t.next=6;break}return t.abrupt("return",a);case 6:return t.abrupt("return",null);case 9:throw t.prev=9,t.t0=t.catch(0),console.error("Error parsing or retrieving data from local storage:",t.t0),t.t0;case 13:case"end":return t.stop()}}),r,null,[[0,9]])}))),function(t){return o.apply(this,arguments)})}]),e}();v=w,y=864e5,(d=a(d="ONE_DAY_IN_MILLISECONDS"))in v?Object.defineProperty(v,d,{value:y,enumerable:!0,configurable:!0,writable:!0}):v[d]=y;var g=function(){function e(){n(this,e)}var o;return i(e,[{key:"get",value:(o=r(t().mark((function e(r,n){var o,i,a;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,w.get(n);case 3:if(null===(o=t.sent)){t.next=6;break}return t.abrupt("return",o);case 6:return t.next=8,fetch(r);case 8:if((i=t.sent).ok){t.next=11;break}throw new Error("".concat(i.status," - ").concat(i.statusText||"Failed to fetch data"));case 11:return t.next=13,i.json();case 13:return a=t.sent,t.next=16,w.set(n,a);case 16:return t.abrupt("return",a);case 19:throw t.prev=19,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),new Error(t.t0.message||"Error fetching data");case 23:case"end":return t.stop()}}),e,null,[[0,19]])}))),function(t,e){return o.apply(this,arguments)})}]),e}(),m=new WeakMap,b=new WeakMap,E=new WeakMap,x=new WeakMap,k=new WeakMap,L=function(){function t(e){if(n(this,t),h(this,m,{writable:!0,value:void 0}),h(this,b,{writable:!0,value:void 0}),h(this,E,{writable:!0,value:void 0}),h(this,x,{writable:!0,value:void 0}),h(this,k,{writable:!0,value:void 0}),!(e instanceof HTMLElement))throw new Error("triggerElement must be an instance of HTMLElement.");u(this,m,e),u(this,k,e.id),u(this,b,e.dataset.apiUrl),u(this,E,e.dataset.description),u(this,x,e.dataset.url)}return i(t,[{key:"id",get:function(){return c(this,k)}},{key:"api",get:function(){return c(this,b)}},{key:"description",get:function(){return c(this,E)}},{key:"libUrl",get:function(){return c(this,x)}},{key:"element",get:function(){return c(this,m)}}]),t}(),O=new WeakMap,S=new WeakMap,_=new WeakSet,j=new WeakSet,N=new WeakSet,P=new WeakSet,T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new g;n(this,e),p(this,P),p(this,N),p(this,j),p(this,_),h(this,O,{writable:!0,value:void 0}),h(this,S,{writable:!0,value:void 0}),u(this,O,t)}var o;return i(e,[{key:"load",value:(o=r(t().mark((function e(r){return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(l(this,_,I).call(this,r)){t.next=2;break}return t.abrupt("return");case 2:return l(this,N,D).call(this,r),t.next=5,l(this,j,M).call(this);case 5:case"end":return t.stop()}}),e,this)}))),function(t){return o.apply(this,arguments)})}]),e}();function I(t){return!!t.id||(console.error("Element missing ID:",t),!1)}function M(){return W.apply(this,arguments)}function W(){return(W=r(t().mark((function e(){var r;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,c(this,O).get(c(this,S).api,c(this,S).id);case 3:(r=t.sent)&&l(this,P,G).call(this,r),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),console.error("Error loading preupver:",t.t0);case 10:case"end":return t.stop()}}),e,this,[[0,7]])})))).apply(this,arguments)}function D(t){u(this,S,new L(t))}function G(t){var e=t[0].name,r=document.getElementById(c(this,S).id);if(!r)throw new Error("Pre tag not found.");r.innerHTML="&lt;!-- ".concat(c(this,S).description," --&gt;\n&lt;script src&#x3D;&quot;").concat(c(this,S).libUrl.replace("${version}",e),"&quot;&gt;&lt;/script&gt;")}document.addEventListener("DOMContentLoaded",(function(t){try{!function(t){document.querySelectorAll(".preupver").forEach((function(e){new T(t).load(e).catch((function(t){console.error("Loading error for element ".concat(e,":"),t)}))}))}(new g)}catch(t){console.error("Error initializing PreUp loaders:",t)}}))}));