vanilla-beans
Version:
Thin layer on top of HTML and DOM API, dramatically simplify development of SPA using Vanilla Js.
1 lines • 6.04 kB
JavaScript
var vanillaBeansFactory;!function(){"use strict";var n={d:function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:function(n,e){return Object.prototype.hasOwnProperty.call(n,e)}},e={};n.d(e,{default:function(){return u}});var t="beans-";const r={AS:t+"as",TAG:t+"tagname",USE:t+"usetag",REF:t+"ref",BDY:t+"body",SDW:t+"shadow",STL:t+"style",IMP:t+"import",NS:t};function o(n){return{or:function(e){var t;try{t=n()}catch(n){}return void 0===t?e:t}}}function a(n){return n&&n.toUpperCase()}var i={},s={};function u(n){if(!c(n+=""))throw new Error("Module "+n+" not found");return{with:function(e){return{create:function(t,r){return d(null,t,r,void 0,e,n)}}}}}u.document=window.document,u.put=function(n){if(!c(n.src))return i[n.src]=n,u;console.warn('Module "%s" already exists',n.src)};var c=u.has=function(n){return!!i[n]};function d(n,e,t,c,f,b,m){if(n=t&&t.xmlns||n,!e)throw new Error("Tag should not be empty");t=t||{},c=c||[];var B,D=u.document,N=l(b,a(e));if(N&&N.create)return N.create(n,e,t,c,f,b,m);if(N&&N.bean){var g=h(h({},N.bean.a),t),w={};!function(n,e,t,r,o,a){h(n,v,!0,!0),e&&e.init&&e.init.apply&&e.init.apply(n,[t,r,o,u.document,S(a)])}(B=d(n,N.bean.t,g,N.bean.c,f,N.src,w),N.bean,f,u(b),w,b)}else{var U=t[r.USE]||e,C=t[r.SDW],E=t[r.STL];B=n&&D.createElementNS(n,U)||D.createElement(U);try{var T=C&&B.attachShadow(function(n){var e={mode:"open",clonable:!1,delegatesFocus:!1,serializable:!1,slotAssignment:"named"},t=["mode","slotAssignment"];return n.split(";").forEach((function(n){var r=n.replace(/\s+/g,"").split("=");e[r[0]]=o((function(){return t.indexOf(r[0])<0?"true"===r[1]:r[1]})).or(e[r[1]])})),e}(C));T&&p(B,"_SDW",T,!0,!0),B._BODY=C&&T||B,C&&E&&function(n,e,t){var o=[];e.forEach((function(e){if(e){var u=i[t].imports[e];if(u&&"css"===u.type){var c=i[u.src]||{};if(void 0===c.evaluated)try{var d=new CSSStyleSheet;d.replace(c.style),c.evaluated=d}catch(n){c.evaluated=!1}if(c.evaluated)return void o.push(c.evaluated);var f={};f[r.STL]=e,n.appendChild(s[a(r.STL)].create(null,"",f,[],{},t))}else console.error("CSSModule %s was not found in %s",e,t)}})),n.adoptedStyleSheets=o}(B._BODY,a(E).replace(/\s+/g,"").split(";"),b)}catch(n){console.error(n)}!function(n,e){if(e&&n&&n.setAttribute)for(var t in e)o=t,a=r.NS,o.substring(0,a.length)===a||n.setAttribute(t,e[t]);var o,a}(B,t),h(B,v,!0,!1)}return y(n,B,c,f,b,m=m||{}),B}function f(n,e){return(n.a||{})[e]}function l(n,e){if(s[e])return s[e];var t=o((function(){return i[n].beans[e]})).or();if(t)return{src:n,tag:e,bean:t};var r=e.split("."),a=o((function(){return i[n].imports[r[0]].src})).or(),u=r.slice(1).join(".");return(t=o((function(){return i[a].beans[u]})).or())?{src:a,tag:u,bean:t}:void 0}function h(n,e,t,r){for(var o in n=n||{},e=e||{})t&&void 0!==n[o]||p(n,o,e[o],r);return n}function p(n,e,t,r,o){void 0!==t&&Object.defineProperty(n,e,{value:t,writable:!r,configurable:!r,enumerable:!o})}var v={beanMount:function(n,e){this.beanUnmount();var t=n&&(n._BODY||n._SDW||n);if(t&&t.appendChild)return e&&t.insertBefore(this,e)||0===e&&t.insertBefore(this,t.firstChild)||t.appendChild(this),m(this)&&b(this,(function(n){n.onBeanMount&&n.onBeanMount()})),this},beanUnmount:function(){return m(this)&&b(this,(function(n){n.onBeanUnmount&&n.onBeanUnmount()})),this.parentNode&&this.parentNode.removeChild(this),this},beanStart:function(){b(this,(function(n){n.onBeanStart&&n.onBeanStart()}))},beanStop:function(){b(this,(function(n){n.onBeanStop&&n.onBeanStop()}))},beanUpdate:function(n,e,t){this.onBeanUpdate&&this.onBeanUpdate(n,e,t)},beanDestroy:function(){for(var n=this._SDW||this;n.childNodes&&n.childNodes.length>0;)n.childNodes[0].beanDestroy&&n.childNodes[0].beanDestroy()||(n.childNodes[0].beanDestroy=v.beanDestroy)&&n.childNodes[0].beanDestroy();return this.onBeanStop&&this.onBeanStop(),this.onBeanUnmount&&this.onBeanUnmount(),this.onBeanDestroy&&this.onBeanDestroy(),this.parentNode&&this.parentNode.removeChild(this),!0}};function b(n,e){if(e(n),(n=n._SDW||n).childNodes)for(var t=0;t<n.childNodes.length;t++)b(n.childNodes[t],e)}function m(n){if(void 0!==n.isConnected)return n.isConnected;for(var e=n;e.parentNode;){if(e.parentNode===u.document.documentElement)return!0;e=e.parentNode}return!1}function S(n){return function(e){try{return i[i[n].imports[a(e)].src].evaluated}catch(t){throw new Error('CJSModule "'+e+'" was not found in "'+n+'"')}}}function y(n,e,t,o,a,i){var s=u.document,c=e._BODY||e,l=c;return t.forEach((function(t){if(t)if(t.t){var u=d(n,t.t,t.a,t.c,o,a,i),h=f(t,r.REF);h&&p(i,h,u,!0),l=void 0!==f(t,r.BDY)&&u||l,c.appendChild(u)}else(e._BODY||e).appendChild(s.createTextNode(t))})),e._BODY=l,c.childNodes}s[a(r.STL)]={create:function(n,e,t,s,c,d,f){var l=u.document.createElement("style"),h=o((function(){return i[d].imports[a(t[r.STL]).split(";")[0]]})).or();if(!h||"css"!==h.type)return console.error("CSSModule %s was not found in %s",t[r.STL],d),l;var p=i[h.src]&&i[h.src].style||"";return l.textContent=p,l}},s[a(r.NS)+"ITERATOR"]={create:function(n,e,t,r,o,i,s){r=r&&r.filter((function(n,e){return!!l(i,a(n.t))||(console.warn('Bean "%s" is not defined in "%s", template[%d] will be ignored',n.t,i,e),!1)}));var u=d(n,"div",t,[],o,i);return p(u,"beanUpdate",(function(e,t,a){e=this.transformBeanData?this.transformBeanData(e,t,a):e,e=Array.isArray(e)?e:[];for(var s=this.children,u=0;u<e.length||u<s.length;)if(u<s.length&&u<e.length)s[u].beanUpdate(e[u],t,u),u++;else if(u>=e.length)s[u].beanDestroy();else{var c=r[u%r.length],f=d(n,c.t,c.a,c.c,o,i);f.beanUpdate(e[u],t,u),f.beanMount(this),u++}}),!0),h(u,v,!0,!0),u}},s[a(r.NS)+"FRAGMENT"]={create:function(n,e,t,r,o,a,i){var s=new DocumentFragment;return y(n,s,r,o,a,i=i||{}),p(s,"beanUpdate",v.beanUpdate),s}},s[a(r.NS)+"TEXT"]={create:function(n,e,t,r,a,i,s){var c=u.document.createTextNode(o((function(){return r.join("")})).or(""));return p(c,"beanUpdate",(function(n,e,t){n=this.transformBeanData?this.transformBeanData(n,e,t):n,this.textContent=n}),!0),h(c,v,!0,!0),c}},vanillaBeansFactory=e.default}();