Source: just.min.js

/**
 * @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 Full suite for browser environments. Includes core utilities, {@link just.View} & {@link just.Router}.
 * @version 1.2.0
 */
!function(t){"function"==typeof define&&define.amd?define("just",[],t):"object"==typeof module&&module.exports?module.exports=t():this.just=t()}.call(this,function(){"use strict";function o(t,e,n,r){var i,o,a=Object.prototype.hasOwnProperty,u=Object(t);for(i in u)a.call(u,i)&&(o=u[i],n=e.call(r,n,o,i,u));return n}function h(t){var e,n,r,i,o;if(null==t)throw new TypeError("can't convert "+t+" to object");for(e=Object(t),n=1,r=arguments.length;n<r;n++)for(o in i=Object(arguments[n]))S.call(i,o)&&(e[o]=i[o]);return e}function i(t,e,n){n=h({},n||{}),n=("just"+t+" is deprecated"+(n.since?" since "+n.since:"")+". "+(n.message||"")).trim();if("warning"===e)console.warn(n);else{if("error"===e)throw new Error(n);console.error(n)}}function t(t,e,n,r){var i=h({override:!0,mutate:!1},r),o=Array.isArray(e)?e:[e],r=i.mutate?t:h({},t),a=r,u=!1,e=o[o.length-1];return o.slice(0,-1).forEach(function(t,e){var n=a[t];if(!(n instanceof Object)){if("undefined"!=typeof n&&null!==n&&!i.override)throw new TypeError(t+" is not an object.");u=!0,a[t]=n={}}a=n}),t=e in a&&!u,n?n.call(r,a,e,t,o):a[e]}function l(e,t){return[].slice.call(arguments,1).some(function(t){return[t,e].some(function(t){return null==t})?t===e:t.constructor===e.constructor})}function e(t){if(!(this instanceof e))return new e(t);r(this,{element:t})}function d(n,t,e){var r=h({ignoreDefaultKeys:!1,checkLooks:!0,checkDeepLooks:!0,ignoreNull:!1},e);return r.ignoreNull&&null===t&&void 0!==n?n:r.checkLooks?l(n,t)?(l(n,{})&&r.checkDeepLooks&&m(t,function(t,e){"undefined"!=typeof n[e]?n[e]=d(n[e],t,r):r.ignoreDefaultKeys||(n[e]=t)}),n):t:typeof n==typeof t?n:t}function r(t,e){return m(e,function(t,e){n(this,e,t)},t),t}function n(t,e,n){var r=Object(n),i=o(r,function(t,e,n){return t.concat(n)},[]);return(!i.length||i.some(function(t){return-1===this.indexOf(t)},["value","writable","get","set","configurable","enumerable"]))&&(r={value:n}),Object.defineProperty(t,e,r),t}function m(t,e,n,r){var i,o=Object(t),a=h({addNonOwned:!1},r),u=!1;if("function"!=typeof e)throw new TypeError(e+" is not a function.");for(i in o){if(u)break;(a.addNonOwned||{}.hasOwnProperty.call(o,i))&&(u=Boolean(e.call(n,o[i],i,o)))}return u}function f(t,e){return[].slice.call((e||document).querySelectorAll(t))}function a(t,e,n,r){var i=t,o=0;if(!(t instanceof Node))throw new TypeError(t+" is not a Node.");for(n instanceof Node||(n=document.documentElement);i;){if((0<o||r)&&e.call(i,o,n))return i;if(i===n)return null;i=i.parentNode,o++}return null}function u(t){return!m(t,function(){return!0})}function s(){return Boolean("ontouchstart"in document.body||0<window.navigator.maxTouchPoints||0<window.navigator.msMaxTouchPoints||"DocumentTouch"in window&&document instanceof DocumentTouch)}function c(t,e,n,r){function i(t){return y(this,["load","error"],i),n.call(this,t)}var o=Object("object"==typeof e?e:null),a=/link/i.test(t)?"href":"src",u="string"==typeof e?o[a]=e:o[a],s=v(u).origin!==window.location.origin,c=!("crossOrigin"in o)&&-1!==["video","img","script","link"].indexOf(t),l=/link/i.test(t),e=!("rel"in o),a=f(t+"["+a+'="'+(u||"")+'"]')[0]||null,o=T(t,o);if("string"!=typeof u||""===u.trim())throw new TypeError(u+" is not valid url.");return n&&g(o,["load","error"],i),s&&c&&(o.crossOrigin="anonymous"),l&&e&&(o.rel="stylesheet"),"function"==typeof r?r.call(o,a,u):a||((r=r||document.head).appendChild(o),o)}function p(t,e){if(!(this instanceof p))return new p(t,e);r(this,{consent:Boolean(t),isExplicit:d(e,"undefined"!=typeof t)})}function g(t,e,n,r){var i=r||!1,r=[];return"string"==typeof t&&(t=f(t)),Array.isArray(e)||(e=[e]),(t=!Array.isArray(t)?[t]:t).forEach(function(t){"addEventListener"in Object(t)&&(e.forEach(function(t){this.addEventListener(t,n,i)},t),this.push(t))},r),r}function y(t,e,n,r){var i=r||!1;Array.isArray(t)||(t=[t]),Array.isArray(e)||(e=[e]),t.forEach(function(t){e.forEach(function(t){this.removeEventListener(t,n,i)},t)})}function v(t){var e,n,r={},i=window.location;return t=t||i.href,/^blob:/i.test(t)?h(n=v(t.replace(/^blob:/i,"")),{protocol:"blob:",href:"blob:"+n.href,host:"",hostname:"",port:"",pathname:n.origin+n.pathname}):(/^(:)?\/\//.test(t)?t="//"===(t=t.replace(/^:/,""))?i.origin:i.protocol+t:/^(\?|#|\/)/.test(t)?t=i.origin+t:/:\/\//.test(t)||(t=i.protocol+"//"+t),t=(i=((n=(t||"").split(/(\?.*#?|#.*\??).*/))[1]||"").split("#"))[1]||"",r.search=i[0]||"",r.hash=t&&"#"+t,t=((i=(n[0]||"").split("://"))[1]||"").split(/(\/.*)/),r.username="",r.password="",/@/.test(t[0])&&(n=(e=t[0].split("@"))[0].split(":"),r.username=n[0]||"",r.password=n[1]||"",t[0]=e[1]),r.host=t[0]||"",r.pathname=t[1]||"",t=r.host.split(/:([0-9]+)/),r.hostname=t[0]||"",r.port="undefined"!=typeof t[1]?t[1]:"",r.protocol=i[0]+":",r.origin=r.protocol+"//"+r.host,r.href=(e?r.protocol+"//"+r.username+":"+r.password+"@"+r.host:r.origin)+r.pathname+r.search+r.hash,r)}function b(t){var e;if("object"==typeof t)return t;try{e=JSON.parse(t)}catch(t){e=null}return e}function w(t){return/(?:^\{|\}$)/.test(String(t).trim())&&b(t)||{}}function E(t){var e={};if(i(".toObjectLiteral()","warning",{since:"1.0.0-rc.22"}),l(t,{},null))return h({},t);if(!l(t,[]))throw new TypeError(t+" must be either null, an object literal or an Array.");return t.forEach(function(t){var e,n;if(l(t,[]))e=t[0],n=t[1],this[e]=n;else{if(!l(t,{}))throw new TypeError(t+" must be either an object literal or an Array.");h(this,t)}},e),e}function j(e){"loading"===document.readyState?g(document,"DOMContentLoaded",function t(){y(document,"DOMContentLoaded",t),e()}):setTimeout(e)}function T(t,e){t=document.createElement(t);return h(t,e),t}function A(t,r,e){var i="json"in Object(e)?e.json:/\.json$/i.test(t),n=d(e,{json:i,data:null,method:"GET",async:!0,user:null,pwd:null,headers:h({"X-Requested-With":"XMLHttpRequest"},i?{"Content-Type":"application/json"}:null),props:h({},i?{responseType:"json"}:null),send:function(t){return this.send(t)}},{ignoreNull:!0}),o=n.data,a=n.method,u=n.async,s=n.user,c=n.pwd,l=n.props,f=n.headers,p=new XMLHttpRequest;return/GET/i.test(a)&&o&&(t=A.appendData(t,o),o=null),p.open(a,t,u,s,c),m(f,function(t,e){this.setRequestHeader(e,t)},p),h(p,l),p.onreadystatechange=function(t){var e,n;this.readyState===XMLHttpRequest.DONE&&(this.onreadystatechange=null,n=this.status,e="response"in this?this.response:this.responseText,n=(n<200||400<=n)&&0!==n?new Error("Bad status: "+n):null,i&&"object"!=typeof e&&(e=b(e)),r&&r.call(this,n,e))},n.send.call(p,o,e)}function O(t,e){Object.defineProperty(N,t,{value:e})}var N={};O("register",O),O("reduce",o);var S=Object.prototype.hasOwnProperty;O("assign",h),O("deprecate",i),O("access",t),O("prop",t),r(l,{throwable:function(t,e){var n=[].slice.call(arguments),r=this;if(i(".check.throwable()","warning",{since:"1.0.0-rc.24"}),!l.apply(this,n))throw r instanceof String||(r=t+" must be like one of the following values: "+n.slice(1).map(function(t){return t+""}).join(", ")),new TypeError(r);return t}}),O("check",l),O("is",l),r(e,{apply:function(t,e,n){var n="number"==typeof n?[n]:[].slice.call(n),r=t.classList;if(!/(?:add|remove)/.test(e))return r[e](n[0],n[1]);n.forEach(function(t){r[e](t)})}}),r(e.prototype,{add:function(){return e.apply(this.element,"add",arguments),this},remove:function(){return e.apply(this.element,"remove",arguments),this},toggle:function(){return e.apply(this.element,"toggle",arguments),this},replace:function(){return e.apply(this.element,"replace",arguments),this},contains:function(){return e.apply(this.element,"contains",arguments)},item:function(){return e.apply(this.element,"item",arguments)}}),O("ClassList",e),O("defaults",d),O("from",d),O("defineProperties",r),O("defProps",r),O("defineProperty",n),O("defProp",n),O("eachProperty",m),O("eachProp",m),O("findElements",f),O("el",f),O("getRemoteParent",a),O("parent",a),O("isEmptyObject",u),O("emptyObj",u),O("isTouchSupported",s),O("supportsTouch",s),O("isWindow",function(t){return i(".isWindow()","warning",{since:"1.0.0-rc.24"}),Boolean(t===window||t instanceof Object&&t.document&&t.setInterval)}),O("loadElement",c),O("load",c),r(p,{DNT:{get:function(){var t=","+[navigator.doNotTrack,navigator.msDoNotTrack,window.doNotTrack]+",";return!!/,(yes|1),/i.test(t)||!/,(no|0),/i.test(t)&&void 0}},cookieExists:function(t){return new RegExp("; "+t+"(=|;)").test("; "+document.cookie+";")},getCookie:function(t){return!/=/.test(t)&&p.cookieExists(t)?("; "+document.cookie).split("; "+t+"=").pop().split(";")[0]:null}}),r(p.prototype,{setCookie:function(t,e,n){function r(t,e){i+=t+("undefined"!=typeof e?"="+e:"")+"; "}var i="",n=d(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(t,e),m(n,function(t,e){r(e,t)}),document.cookie=i.trim(),!0)},removeCookie:function(t,e){e=d(e,{expires:new Date(0)});return!p.cookieExists(t)||this.setCookie(t,"",e)},isStorageAvailable:function(t,e,n){var r,e=d(e,"_"),n=d(n,"_");if(!this.consent)return!1;if(/cookie/i.test(t))return this.setCookie(e,n)&&p.getCookie(e)===n&&this.removeCookie(e);try{(r=window[t]).setItem(e,n),r.removeItem(e)}catch(t){try{r.removeItem(e)}catch(t){return!1}return!1}return!0}}),O("LocalStorage",p),O("addEventListener",g),O("on",g),O("removeEventListener",y),O("off",y),O("parseUrl",v),O("parseJSON",b),O("stringToJSON",w),O("toJSON",b),O("toObjectLiteral",E),O("toObj",E),O("onDocumentReady",j),O("createElement",T),O("create",T),r(A,{appendData:function(t,e){t=v(t),e=A.dataToUrl(e),e=((/\?.+/.test(t.search)?t.search+"&":"?")+e).replace(/[?&]$/,"");return[t.origin,t.pathname,e,t.hash].join("")},dataToUrl:function(t){var e=Object(t);if("object"!=typeof t)throw new TypeError(t+" is not an object.");return o(e,function(t,e,n){e=encodeURIComponent(n)+"="+encodeURIComponent(e);return t.concat(e)},[]).join("&")}}),O("request",A),O("ajax",A);var L,D,C,k,x=(D={},r(H,{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:V,load:_,configure:function(t){return h(H,t),H},clear:function(){return H.globals={},H.nonScripts={},H.urls={},H.handleError=J,H.clearModules(),H},clearModules:function(){return D={},this},clearModule:function(t){return delete D[t],this},handleError:{value:J,writable:!0},init:function(){return H.configure({urls:H.findUrlsInDocument("data-just-Define")}),m(H.urls,function(t,e){H.load(e)}),H},findUrlsInDocument:function(t,e){var n={};return f("*["+t+"]",e).forEach(function(n){h(this,w((n.getAttribute(t)+"").replace(/\[([^\]]+)\]/gi,function(t,e){return n.getAttribute(e)})))},n),n}}),r(H.prototype,{load:function(){return _.apply(null,[].slice.call(arguments)),this}}),H);function I(t,e){var n=e[t];return t in e&&!V(t)&&(new H(t,[],n),!0)}function R(t,e){return!V(t)&&(t in H.urls&&!e?_(t):t in H.nonScripts?I(t,H.nonScripts):t in H.globals&&I(t,H.globals))}function _(n,r){function i(t){var e="error"===Object(t).type;if(y(this,["load","error"],i),e||R(n,!0),"function"==typeof r)return r.call(this,t);e&&H.handleError.call(null,new Error("Error loading "+o))}var t=H.urls[n],e=Object(t),o="object"==typeof t?e.src||e.href:"string"==typeof t?t:n,a=(v(o).pathname.match(/\.(.+)$/)||["js"])[0],u="tagName"in e?e.tagName:!("src"in e)&&("href"in e||/css$/i.test(a))?"link":"script",e="object"==typeof t?(delete t.tagName,t):null;return n in H.urls||(H.urls[n]=o),o!==n&&(a=n,V(t=o)||new H(t,[a],function(t){return t})),c(u,e||o,i,function(t){return"script"===u||n in H.nonScripts||(H.nonScripts[n]=this),t?(g(t,["load","error"],i),!1):(document.head.appendChild(this),!0)})}function P(t){return t.map(function(t){return R(t=t),D[t]||null})}function M(t){return Object(t).state===H.STATE_CALLED}function U(t,e){return Object(e).id===t}function $(e){var n,t,r=e.handler,i=e.dependencies;if(!M(e)&&(e.state=H.STATE_NON_CALLED,t=i.every(function(t){return t&&t.state!==H.STATE_DEFINED}),i.every(M)||t&&((t=e)&&t.dependencies.some(U.bind(null,t.id))||(t=e)&&t.dependencies.some(function(t){return t&&t.dependencies.some(U.bind(null,this.id))},t)))){i=i.map(function(t){return t.exports}),e.state=H.STATE_CALLING;try{e.exports=r.apply(e,i)}catch(t){n=H.handleError.call(e,t)}return e.state=H.STATE_CALLED,"boolean"!=typeof n||n}}function B(t){return"string"==typeof t&&""!==t.trim()}function V(t){return t in D}function q(t){return null===t||"undefined"==typeof t}function H(t,e,n){if(!arguments.length||"function"!=typeof n&&[t,e].every(q))throw new TypeError("Not enough arguments.");if(2===arguments.length?(n=arguments[1],Array.isArray(arguments[0])?(e=arguments[0],t=void 0):e=void 0):1===arguments.length&&"function"==typeof arguments[0]&&(n=arguments[0],e=t=void 0),!B(t)){if(!q(t))throw new TypeError("The given id ("+t+") is invalid.");t=Math.random().toString()}if(q(e)?e=[]:Array.isArray(e)||(e=[e]),e.some(function(t){return!B(t)}))throw new TypeError("If present, the ids for the dependencies must be valid ids.");if(!(this instanceof H))return new H(t,e,n);r(D[t]=this,{id:t,handler:"function"==typeof n?n:function(){return n},dependencyIDs:e,dependencies:{get:function(){return P(this.dependencyIDs)}},state:{value:H.STATE_DEFINED,writable:!0},exports:{value:"function"==typeof n?this:n,writable:!0}}),clearTimeout(L),L=setTimeout(function e(){m(D,function(t){if($(t))return e(),!0})})}function J(t){throw t}function G(){h(this,{routes:{}})}function F(t,e){return t instanceof RegExp?t.test(e):t===e}function X(t,n){m(t.path,function(t,e){return function(t,e,n,r){var i=r.detail,o=Object(i),a=Object(o.route),u=t.handler,s=t.options,c=C[n],l=s.ignore,o=s.only,s=s.actions,f=a.action,s=s.some(function(t){return F(t,f)});if(F(e,c)&&o.call(t)&&!l.call(t)&&s)return a.by&&"init"!==a.action||(a.by=n),!u.call(t,r,i)}(this,t,e,n)},t)}function W(t,n){var i,e,o,u=[];if(t)return"string"!=typeof t?t:(i="(",e=")","function"!=typeof(o=function(t,e){var o,a,e=e.enclosed;return null!==e?(o=n,a={},e=b("["+(","+e+",").replace(/,\s*([\w.-]+)\s*(?=,)/gi,function(t,e,n){e=/^\d/.test(e)?parseFloat(e):"this"===e?e:W(e,o);return","+("object"==typeof e&&null!==e||"string"==typeof e&&"this"!==e?JSON.stringify(e):e)}).replace(/^,|,$/g,"").replace(/(\b)(undefined|this)(\b)/g,function(t,e,n,r){var i=Math.random()+"";return a[i]="this"===n?o[n]:void 0,e+JSON.stringify(i)+r})+"]").map(function(t,e){return t in a?a[t]:t}),u.push(e),t):t.split(".").reduce(function(t,e){var n=Object(t),r=e.trim(),e=r in n?n[r]:r in String.prototype?String.prototype[r]:"object"==typeof t&&null!==t&&"undefined"!=typeof r&&"undefined"!==r?b(r):void 0,t=e;return"function"==typeof e&&(r=e,e=u.pop(),t=r.apply(n,e)),t},n)})&&(o=function(t){return t}),t.split(e).reduce(function(t,e){var n=t+e,r=n.lastIndexOf(i),t=null,e=n;return-1<r&&(t=n.slice(r+1),e=n.slice(0,r)),o(e,{enclosed:t,index:r})},""))}function K(t){var e=Object(t).attributes,e="string"==typeof e?e:"data-var";h(this,d(t,{id:null,element:null,data:{},attributes:{var:e,html:e+"-html",attr:e+"-attr",if:e+"-if",alias:e+"-as",for:e+"-for",on:e+"-on"}},{ignoreNull:!0}),{previousData:null}),this.original=h({},this)}return j(x.init),O("Define",x),O("Def",x),O("Router",(C=window.location,k=window.history,r(G,{changeState:function(t,e){var n=C.origin,r=v(e).origin===n,n=e.replace(n,"");if(!r)return!1;try{t in k?k[t](null,"",n):C.hash="#!"+n}catch(t){return!1}return!0},replaceState:function(t){return G.changeState("replaceState",t)},pushState:function(t){return G.changeState("pushState",t)}}),r(G.prototype,{trigger:function(o,a,u){return m(this.routes,function(t,e){var n=t.options.event,r=n.target,i=n.name,n=n.init;if("init"===o){if(t.init)return!1;t.init=!0}(u=d(u,n,{ignoreNull:!0})).detail.data=a,h(u.detail.route,{by:"action",action:o}),i=new CustomEvent(i,u),r.dispatchEvent(i)}),this},route:function(t,e,n,r){var i=d(r,{ignore:function(){},only:function(){return!0},actions:[/.+/],event:{name:"just:Router:route:"+t,target:document,init:{detail:{data:null,route:{by:null,action:null}}}}},{ignoreNull:!0}),o=i.event,a=o.name,u=o.init,s=u.detail.data,r=o.target,o=l(e,{})?e:{pathname:e},c=function(t){"popstate"===t.type&&(t.detail={data:null,route:{by:null,action:t.type}}),X(this,t)}.bind(i={id:t,path:o,originalPath:e,handler:n,options:i,init:!1});return this.routes[t]=i,g(r,a,c),g(window,"popstate",function(t){setTimeout(function(){c.call(this,t)}.bind(this),0)}),this.trigger("init",s,u),this},change:function(t,e,n,r){return G.changeState(t,e)&&this.trigger(t,n,r),this},push:function(t,e,n){return this.change("pushState",t,e,n)},replace:function(t,e,n){return this.change("replaceState",t,e,n)}}),G)),O("View",(r(K,{INIT_ATTRIBUTE_NAME:"data-just-View",globals:{},init:function(t){var r=d(t,{listeners:{}}).listeners,i=K.INIT_ATTRIBUTE_NAME,t=f("["+i+"]"),o=h({},K.globals,r);return t.map(function(t){var e=t.getAttribute(i),n=h({this:t},o),n=K.replaceVars(e,n,null),n=new K(w(n)).attachListeners(r);return t.view=n})},attachListeners:function(t,r,e){var e=t.getAttribute(e),i={};return e&&m(w(e),function(t,e){var n=t.split("."),t=n.pop(),n=n.join("."),t=(n?W(n,r):r)[t];g(this,e,t),i[e]=t},t),i},resolveConditional:function(t,e){var n=/^!/.test(t),r=(t+"").replace("!",""),t=r,e=!!/^true$/.test(r)||W(t,e);return e=n?!e:e},resolveConditionals:function(t,n){var r,e=Object(t);return"string"==typeof t?r=K.resolveConditional(t,n):(m(e,function(t,e){if(K.resolveConditional(e,n))return r=t}),r)},replaceVars:function(t,r,i){return String("object"==typeof t?K.resolveConditionals(t,r):t).replace(/(\$\{[^(]+\()([^)]+)(\)\})/g,function(t,e,n,r){return e+encodeURI(n)+r}).replace(/\$\{([^}]+)\}/g,function(t,e){var n=W(decodeURI(e),r),e=decodeURI(t),t="undefined"!=typeof i?i:e,e="undefined"!=typeof n;return e?e&&"string"!=typeof n&&"number"!=typeof n&&null!==n?JSON.stringify(n):n:t})},updateVars:function(t,e,n,r){r=d(r,function(t,e){return t.textContent=e,!0}),n=t.getAttribute(n);return!!n&&("this"in(e=Object(e))||(e.this=t),e=K.replaceVars(n,e),Boolean(e!==n&&r(t,e)))},updateHtmlVars:function(t,e,n){return K.updateVars(t,e,n,function(t,e){return t.innerHTML=e,!0})},updateConditionals:function(t,e,n){n=t.getAttribute(n);return!(!t.parentNode||!n)&&((e=K.resolveConditionals(n,e))?t.removeAttribute("hidden"):t.setAttribute("hidden",""),Boolean(e))},updateAttributes:function(t,n,e){e=t.getAttribute(e);return!!e&&(m(w(e),function(t,e){t=K.replaceVars(t,n);/^(?:null|undefined)$/.test(t)||this.setAttribute(e,t)},t),!0)},getAliases:function(t,n,e){t=t.getAttribute(e),e={};return t&&m(w(t),function(t,e){this[e]=W(t,n)},e),e},updateLoops:function(s,c,l){var f,p,t,e=(s.getAttribute(l)||"").split(/\s*,\s*/),n=e[0],d=(e[1]||"").split(" ").reduce(function(t,e){var n=e.split("="),e=n[0],n=n[1];return t[e]=!/false/.test(n),t},{cache:!0}).cache;return/(\S+)\s+in\s+(\S+)(?:\s+as\s+(\S+))?/i.test(n)&&(f=RegExp.$1,t=RegExp.$2,p=RegExp.$3||l+"-"+f,t=W(t,c)||[],Array.isArray(t))?function(n){for(var t,e,r=(s.view?s.view.original.element:s).parentNode,i=n.length,o=[].slice.call(r.children),a=h({},c),u=o.reduce(function(t,e){e=e.view;return e&&e.element!==s&&t.push(e),t},[]);d?u.length>i:0<u.length;){e=u.pop().element;try{e.parentNode.removeChild(e)}catch(t){console.error(t)}}for(;u.length<i;)(t=new K({element:s,attributes:p}).create().append(r)).element.removeAttribute(l),t.element.view=t,u.push(t);return u.map(function(t,e){return a[f]=n[e],a.this=t.element,a.loop={index:e,array:n,length:i,left:i-e},t.update(a)})}(t):null}}),r(K.prototype,{getElement:function(){return this.element||document.getElementById(this.id)},getData:function(t){var e=this.getElement(),n=K.globals,r=this.data,i=this.attributes.alias;return f("["+i+"]",e).concat(e).reduce(function(t,e){return h(t,K.getAliases(e,t,i))},h({},n,r,t))},getUpdatables:function(t){var e=this.attributes;return f(["["+e.var+"]","["+e.html+"]","["+e.if+"]","["+e.attr+"]","["+e.for+"]"].join(","),t)},create:function(){var t,e=this.getElement();if(!(e instanceof Node))throw new TypeError("You must provide a valid Node using #id or #template.");return e=(t=e.cloneNode(!0)).id,t.classList.remove("template"),e&&t.classList.add(e),t.removeAttribute("hidden"),t.removeAttribute("id"),this.element=t,this},update:function(t,e){var n=this.getElement(),r=this.getData(t),i=this.attributes,o=i.if,a=i.attr,u=i.html,s=i.var,c=i.for;return n&&(this.previousData=t,this.getUpdatables(n).concat(n).forEach(function(t){"function"==typeof e&&e(t)||(K.updateConditionals(t,r,o),K.updateAttributes(t,r,a),K.updateHtmlVars(t,r,u),K.updateVars(t,r,s),K.updateLoops(t,r,c))})),this},refresh:function(t,e){t=h({},this.previousData,t);return this.update(t,e),this},insert:function(t,e){var n=this.getElement(),r=e||Object(this.id?document.getElementById(this.id):this.element).parentNode,e=Object(t);if(!(r instanceof Node))throw new TypeError("Please provide a container.");return"before"===t||"before"in e?r.insertBefore(n,e.before||r.firstChild):r.appendChild(n),this},append:function(t){return this.insert("after",t)},prepend:function(t){return this.insert("before",t)},reset:function(){return h(this,this.original),this},attachListeners:function(t){var e=this.getElement(),n=this.attributes.on,t=this.getData(t);return K.attachListeners(e,t,n),this}}),K)),O("version","1.2.0"),O("just",N),N});