/** * @license * BSD 3-Clause License * * Copyright (c) 2019, Alexis Puga Ruíz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * @preserve © 2019-2022 {@link https://github.com/AlexisPuga|Alexis Puga} and {@link https://github.com/justjs/just/contributors|contributors}. {@link https://github.com/justjs/just|JustJs} is released under the {@link https://github.com/justjs/just/blob/master/LICENSE|BSD-3-Clause License}. * @file Core utilities for browser environments. * @version 1.2.0 */ !function(e){"function"==typeof define&&define.amd?define("just",[],e):"object"==typeof module&&module.exports?module.exports=e():this.just=e()}.call(this,function(){"use strict";function i(e,t,n,r){var o,i,c=Object.prototype.hasOwnProperty,s=Object(e);for(o in s)c.call(s,o)&&(i=s[o],n=t.call(r,n,i,o,s));return n}function d(e){var t,n,r,o,i;if(null==e)throw new TypeError("can't convert "+e+" to object");for(t=Object(e),n=1,r=arguments.length;n<r;n++)for(i in o=Object(arguments[n]))k.call(o,i)&&(t[i]=o[i]);return t}function o(e,t,n){n=d({},n||{}),n=("just"+e+" is deprecated"+(n.since?" since "+n.since:"")+". "+(n.message||"")).trim();if("warning"===t)console.warn(n);else{if("error"===t)throw new Error(n);console.error(n)}}function e(e,t,n,r){var o=d({override:!0,mutate:!1},r),i=Array.isArray(t)?t:[t],r=o.mutate?e:d({},e),c=r,s=!1,t=i[i.length-1];return i.slice(0,-1).forEach(function(e,t){var n=c[e];if(!(n instanceof Object)){if("undefined"!=typeof n&&null!==n&&!o.override)throw new TypeError(e+" is not an object.");s=!0,c[e]=n={}}c=n}),e=t in c&&!s,n?n.call(r,c,t,e,i):c[t]}function c(t,e){return[].slice.call(arguments,1).some(function(e){return[e,t].some(function(e){return null==e})?e===t:e.constructor===t.constructor})}function t(e){if(!(this instanceof t))return new t(e);r(this,{element:e})}function h(n,e,t){var r=d({ignoreDefaultKeys:!1,checkLooks:!0,checkDeepLooks:!0,ignoreNull:!1},t);return r.ignoreNull&&null===e&&void 0!==n?n:r.checkLooks?c(n,e)?(c(n,{})&&r.checkDeepLooks&&y(e,function(e,t){"undefined"!=typeof n[t]?n[t]=h(n[t],e,r):r.ignoreDefaultKeys||(n[t]=e)}),n):e:typeof n==typeof e?n:e}function r(e,t){return y(t,function(e,t){n(this,t,e)},e),e}function n(e,t,n){var r=Object(n),o=i(r,function(e,t,n){return e.concat(n)},[]);return(!o.length||o.some(function(e){return-1===this.indexOf(e)},["value","writable","get","set","configurable","enumerable"]))&&(r={value:n}),Object.defineProperty(e,t,r),e}function y(e,t,n,r){var o,i=Object(e),c=d({addNonOwned:!1},r),s=!1;if("function"!=typeof t)throw new TypeError(t+" is not a function.");for(o in i){if(s)break;(c.addNonOwned||{}.hasOwnProperty.call(i,o))&&(s=Boolean(t.call(n,i[o],o,i)))}return s}function f(e,t){return[].slice.call((t||document).querySelectorAll(e))}function s(e,t,n,r){var o=e,i=0;if(!(e instanceof Node))throw new TypeError(e+" is not a Node.");for(n instanceof Node||(n=document.documentElement);o;){if((0<i||r)&&t.call(o,i,n))return o;if(o===n)return null;o=o.parentNode,i++}return null}function u(e){return!y(e,function(){return!0})}function a(){return Boolean("ontouchstart"in document.body||0<window.navigator.maxTouchPoints||0<window.navigator.msMaxTouchPoints||"DocumentTouch"in window&&document instanceof DocumentTouch)}function l(e,t,n,r){function o(e){return w(this,["load","error"],o),n.call(this,e)}var i=Object("object"==typeof t?t:null),c=/link/i.test(e)?"href":"src",s="string"==typeof t?i[c]=t:i[c],u=v(s).origin!==window.location.origin,a=!("crossOrigin"in i)&&-1!==["video","img","script","link"].indexOf(e),l=/link/i.test(e),t=!("rel"in i),c=f(e+"["+c+'="'+(s||"")+'"]')[0]||null,i=j(e,i);if("string"!=typeof s||""===s.trim())throw new TypeError(s+" is not valid url.");return n&&m(i,["load","error"],o),u&&a&&(i.crossOrigin="anonymous"),l&&t&&(i.rel="stylesheet"),"function"==typeof r?r.call(i,c,s):c||((r=r||document.head).appendChild(i),i)}function p(e,t){if(!(this instanceof p))return new p(e,t);r(this,{consent:Boolean(e),isExplicit:h(t,"undefined"!=typeof e)})}function m(e,t,n,r){var o=r||!1,r=[];return"string"==typeof e&&(e=f(e)),Array.isArray(t)||(t=[t]),(e=!Array.isArray(e)?[e]:e).forEach(function(e){"addEventListener"in Object(e)&&(t.forEach(function(e){this.addEventListener(e,n,o)},e),this.push(e))},r),r}function w(e,t,n,r){var o=r||!1;Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]),e.forEach(function(e){t.forEach(function(e){this.removeEventListener(e,n,o)},e)})}function v(e){var t,n,r={},o=window.location;return e=e||o.href,/^blob:/i.test(e)?d(n=v(e.replace(/^blob:/i,"")),{protocol:"blob:",href:"blob:"+n.href,host:"",hostname:"",port:"",pathname:n.origin+n.pathname}):(/^(:)?\/\//.test(e)?e="//"===(e=e.replace(/^:/,""))?o.origin:o.protocol+e:/^(\?|#|\/)/.test(e)?e=o.origin+e:/:\/\//.test(e)||(e=o.protocol+"//"+e),e=(o=((n=(e||"").split(/(\?.*#?|#.*\??).*/))[1]||"").split("#"))[1]||"",r.search=o[0]||"",r.hash=e&&"#"+e,e=((o=(n[0]||"").split("://"))[1]||"").split(/(\/.*)/),r.username="",r.password="",/@/.test(e[0])&&(n=(t=e[0].split("@"))[0].split(":"),r.username=n[0]||"",r.password=n[1]||"",e[0]=t[1]),r.host=e[0]||"",r.pathname=e[1]||"",e=r.host.split(/:([0-9]+)/),r.hostname=e[0]||"",r.port="undefined"!=typeof e[1]?e[1]:"",r.protocol=o[0]+":",r.origin=r.protocol+"//"+r.host,r.href=(t?r.protocol+"//"+r.username+":"+r.password+"@"+r.host:r.origin)+r.pathname+r.search+r.hash,r)}function g(e){var t;if("object"==typeof e)return e;try{t=JSON.parse(e)}catch(e){t=null}return t}function b(e){return/(?:^\{|\}$)/.test(String(e).trim())&&g(e)||{}}function E(e){var t={};if(o(".toObjectLiteral()","warning",{since:"1.0.0-rc.22"}),c(e,{},null))return d({},e);if(!c(e,[]))throw new TypeError(e+" must be either null, an object literal or an Array.");return e.forEach(function(e){var t,n;if(c(e,[]))t=e[0],n=e[1],this[t]=n;else{if(!c(e,{}))throw new TypeError(e+" must be either an object literal or an Array.");d(this,e)}},t),t}function T(t){"loading"===document.readyState?m(document,"DOMContentLoaded",function e(){w(document,"DOMContentLoaded",e),t()}):setTimeout(t)}function j(e,t){e=document.createElement(e);return d(e,t),e}function O(e,r,t){var o="json"in Object(t)?t.json:/\.json$/i.test(e),n=h(t,{json:o,data:null,method:"GET",async:!0,user:null,pwd:null,headers:d({"X-Requested-With":"XMLHttpRequest"},o?{"Content-Type":"application/json"}:null),props:d({},o?{responseType:"json"}:null),send:function(e){return this.send(e)}},{ignoreNull:!0}),i=n.data,c=n.method,s=n.async,u=n.user,a=n.pwd,l=n.props,f=n.headers,p=new XMLHttpRequest;return/GET/i.test(c)&&i&&(e=O.appendData(e,i),i=null),p.open(c,e,s,u,a),y(f,function(e,t){this.setRequestHeader(t,e)},p),d(p,l),p.onreadystatechange=function(e){var t,n;this.readyState===XMLHttpRequest.DONE&&(this.onreadystatechange=null,n=this.status,t="response"in this?this.response:this.responseText,n=(n<200||400<=n)&&0!==n?new Error("Bad status: "+n):null,o&&"object"!=typeof t&&(t=g(t)),r&&r.call(this,n,t))},n.send.call(p,i,t)}function A(e,t){Object.defineProperty(D,e,{value:t})}var D={};A("register",A),A("reduce",i);var k=Object.prototype.hasOwnProperty;A("assign",d),A("deprecate",o),A("access",e),A("prop",e),r(c,{throwable:function(e,t){var n=[].slice.call(arguments),r=this;if(o(".check.throwable()","warning",{since:"1.0.0-rc.24"}),!c.apply(this,n))throw r instanceof String||(r=e+" must be like one of the following values: "+n.slice(1).map(function(e){return e+""}).join(", ")),new TypeError(r);return e}}),A("check",c),A("is",c),r(t,{apply:function(e,t,n){var n="number"==typeof n?[n]:[].slice.call(n),r=e.classList;if(!/(?:add|remove)/.test(t))return r[t](n[0],n[1]);n.forEach(function(e){r[t](e)})}}),r(t.prototype,{add:function(){return t.apply(this.element,"add",arguments),this},remove:function(){return t.apply(this.element,"remove",arguments),this},toggle:function(){return t.apply(this.element,"toggle",arguments),this},replace:function(){return t.apply(this.element,"replace",arguments),this},contains:function(){return t.apply(this.element,"contains",arguments)},item:function(){return t.apply(this.element,"item",arguments)}}),A("ClassList",t),A("defaults",h),A("from",h),A("defineProperties",r),A("defProps",r),A("defineProperty",n),A("defProp",n),A("eachProperty",y),A("eachProp",y),A("findElements",f),A("el",f),A("getRemoteParent",s),A("parent",s),A("isEmptyObject",u),A("emptyObj",u),A("isTouchSupported",a),A("supportsTouch",a),A("isWindow",function(e){return o(".isWindow()","warning",{since:"1.0.0-rc.24"}),Boolean(e===window||e instanceof Object&&e.document&&e.setInterval)}),A("loadElement",l),A("load",l),r(p,{DNT:{get:function(){var e=","+[navigator.doNotTrack,navigator.msDoNotTrack,window.doNotTrack]+",";return!!/,(yes|1),/i.test(e)||!/,(no|0),/i.test(e)&&void 0}},cookieExists:function(e){return new RegExp("; "+e+"(=|;)").test("; "+document.cookie+";")},getCookie:function(e){return!/=/.test(e)&&p.cookieExists(e)?("; "+document.cookie).split("; "+e+"=").pop().split(";")[0]:null}}),r(p.prototype,{setCookie:function(e,t,n){function r(e,t){o+=e+("undefined"!=typeof t?"="+t:"")+"; "}var o="",n=h(n,{secure:"https:"===location.protocol});return!!this.consent&&(n.secure&&r("secure"),delete n.secure,n.expires&&(n.expires=new Date(n.expires).toGMTString()),r(e,t),y(n,function(e,t){r(t,e)}),document.cookie=o.trim(),!0)},removeCookie:function(e,t){t=h(t,{expires:new Date(0)});return!p.cookieExists(e)||this.setCookie(e,"",t)},isStorageAvailable:function(e,t,n){var r,t=h(t,"_"),n=h(n,"_");if(!this.consent)return!1;if(/cookie/i.test(e))return this.setCookie(t,n)&&p.getCookie(t)===n&&this.removeCookie(t);try{(r=window[e]).setItem(t,n),r.removeItem(t)}catch(e){try{r.removeItem(t)}catch(e){return!1}return!1}return!0}}),A("LocalStorage",p),A("addEventListener",m),A("on",m),A("removeEventListener",w),A("off",w),A("parseUrl",v),A("parseJSON",g),A("stringToJSON",b),A("toJSON",g),A("toObjectLiteral",E),A("toObj",E),A("onDocumentReady",T),A("createElement",j),A("create",j),r(O,{appendData:function(e,t){e=v(e),t=O.dataToUrl(t),t=((/\?.+/.test(e.search)?e.search+"&":"?")+t).replace(/[?&]$/,"");return[e.origin,e.pathname,t,e.hash].join("")},dataToUrl:function(e){var t=Object(e);if("object"!=typeof e)throw new TypeError(e+" is not an object.");return i(t,function(e,t,n){t=encodeURIComponent(n)+"="+encodeURIComponent(t);return e.concat(t)},[]).join("&")}}),A("request",O),A("ajax",O);var L,N,S=(N={},r(G,{STATE_DEFINED:-1,STATE_NON_CALLED:0,STATE_CALLING:1,STATE_CALLED:2,urls:{value:{},writable:!0},nonScripts:{value:{},writable:!0},globals:{value:{},writable:!0},isDefined:U,load:I,configure:function(e){return d(G,e),G},clear:function(){return G.globals={},G.nonScripts={},G.urls={},G.handleError=$,G.clearModules(),G},clearModules:function(){return N={},this},clearModule:function(e){return delete N[e],this},handleError:{value:$,writable:!0},init:function(){return G.configure({urls:G.findUrlsInDocument("data-just-Define")}),y(G.urls,function(e,t){G.load(t)}),G},findUrlsInDocument:function(e,t){var n={};return f("*["+e+"]",t).forEach(function(n){d(this,b((n.getAttribute(e)+"").replace(/\[([^\]]+)\]/gi,function(e,t){return n.getAttribute(t)})))},n),n}}),r(G.prototype,{load:function(){return I.apply(null,[].slice.call(arguments)),this}}),G);function C(e,t){var n=t[e];return e in t&&!U(e)&&(new G(e,[],n),!0)}function x(e,t){return!U(e)&&(e in G.urls&&!t?I(e):e in G.nonScripts?C(e,G.nonScripts):e in G.globals&&C(e,G.globals))}function I(n,r){function o(e){var t="error"===Object(e).type;if(w(this,["load","error"],o),t||x(n,!0),"function"==typeof r)return r.call(this,e);t&&G.handleError.call(null,new Error("Error loading "+i))}var e=G.urls[n],t=Object(e),i="object"==typeof e?t.src||t.href:"string"==typeof e?e:n,c=(v(i).pathname.match(/\.(.+)$/)||["js"])[0],s="tagName"in t?t.tagName:!("src"in t)&&("href"in t||/css$/i.test(c))?"link":"script",t="object"==typeof e?(delete e.tagName,e):null;return n in G.urls||(G.urls[n]=i),i!==n&&(c=n,U(e=i)||new G(e,[c],function(e){return e})),l(s,t||i,o,function(e){return"script"===s||n in G.nonScripts||(G.nonScripts[n]=this),e?(m(e,["load","error"],o),!1):(document.head.appendChild(this),!0)})}function P(e){return e.map(function(e){return x(e=e),N[e]||null})}function _(e){return Object(e).state===G.STATE_CALLED}function M(e,t){return Object(t).id===e}function R(t){var n,e,r=t.handler,o=t.dependencies;if(!_(t)&&(t.state=G.STATE_NON_CALLED,e=o.every(function(e){return e&&e.state!==G.STATE_DEFINED}),o.every(_)||e&&((e=t)&&e.dependencies.some(M.bind(null,e.id))||(e=t)&&e.dependencies.some(function(e){return e&&e.dependencies.some(M.bind(null,this.id))},e)))){o=o.map(function(e){return e.exports}),t.state=G.STATE_CALLING;try{t.exports=r.apply(t,o)}catch(e){n=G.handleError.call(t,e)}return t.state=G.STATE_CALLED,"boolean"!=typeof n||n}}function q(e){return"string"==typeof e&&""!==e.trim()}function U(e){return e in N}function B(e){return null===e||"undefined"==typeof e}function G(e,t,n){if(!arguments.length||"function"!=typeof n&&[e,t].every(B))throw new TypeError("Not enough arguments.");if(2===arguments.length?(n=arguments[1],Array.isArray(arguments[0])?(t=arguments[0],e=void 0):t=void 0):1===arguments.length&&"function"==typeof arguments[0]&&(n=arguments[0],t=e=void 0),!q(e)){if(!B(e))throw new TypeError("The given id ("+e+") is invalid.");e=Math.random().toString()}if(B(t)?t=[]:Array.isArray(t)||(t=[t]),t.some(function(e){return!q(e)}))throw new TypeError("If present, the ids for the dependencies must be valid ids.");if(!(this instanceof G))return new G(e,t,n);r(N[e]=this,{id:e,handler:"function"==typeof n?n:function(){return n},dependencyIDs:t,dependencies:{get:function(){return P(this.dependencyIDs)}},state:{value:G.STATE_DEFINED,writable:!0},exports:{value:"function"==typeof n?this:n,writable:!0}}),clearTimeout(L),L=setTimeout(function t(){y(N,function(e){if(R(e))return t(),!0})})}function $(e){throw e}return T(S.init),A("Define",S),A("Def",S),A("version","1.2.0"),A("just",D),D});