radi
Version:
**Radi** is a tiny javascript framework.
69 lines (68 loc) • 33.3 kB
JavaScript
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(c,h,n){c!=Array.prototype&&c!=Object.prototype&&(c[h]=n.value)};$jscomp.getGlobal=function(c){return"undefined"!=typeof window&&window===c?c:"undefined"!=typeof global&&null!=global?global:c};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var c=0;return function(h){return $jscomp.SYMBOL_PREFIX+(h||"")+c++}}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var c=$jscomp.global.Symbol.iterator;c||(c=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[c]&&$jscomp.defineProperty(Array.prototype,c,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(c){var h=0;return $jscomp.iteratorPrototype(function(){return h<c.length?{done:!1,value:c[h++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(c){$jscomp.initSymbolIterator();c={next:c};c[$jscomp.global.Symbol.iterator]=function(){return this};return c};$jscomp.makeIterator=function(c){$jscomp.initSymbolIterator();var h=c[Symbol.iterator];return h?h.call(c):$jscomp.arrayIterator(c)};$jscomp.arrayFromIterator=function(c){for(var h,n=[];!(h=c.next()).done;)n.push(h.value);return n};$jscomp.arrayFromIterable=function(c){return c instanceof Array?c:$jscomp.arrayFromIterator($jscomp.makeIterator(c))};
$jscomp.iteratorFromArray=function(c,h){$jscomp.initSymbolIterator();c instanceof String&&(c+="");var n=0,l={next:function(){if(n<c.length){var f=n++;return{value:h(f,c[f]),done:!1}}l.next=function(){return{done:!0,value:void 0}};return l.next()}};l[Symbol.iterator]=function(){return l};return l};
$jscomp.polyfill=function(c,h,n,l){if(h){n=$jscomp.global;c=c.split(".");for(l=0;l<c.length-1;l++){var f=c[l];f in n||(n[f]={});n=n[f]}c=c[c.length-1];l=n[c];h=h(l);h!=l&&null!=h&&$jscomp.defineProperty(n,c,{configurable:!0,writable:!0,value:h})}};$jscomp.polyfill("Array.prototype.keys",function(c){return c?c:function(){return $jscomp.iteratorFromArray(this,function(c){return c})}},"es6","es3");
$jscomp.polyfill("Number.isNaN",function(c){return c?c:function(c){return"number"===typeof c&&isNaN(c)}},"es6","es3");$jscomp.FORCE_POLYFILL_PROMISE=!1;
$jscomp.polyfill("Promise",function(c){function h(){this.batch_=null}function n(c){return c instanceof f?c:new f(function(r,f){r(c)})}if(c&&!$jscomp.FORCE_POLYFILL_PROMISE)return c;h.prototype.asyncExecute=function(c){null==this.batch_&&(this.batch_=[],this.asyncExecuteBatch_());this.batch_.push(c);return this};h.prototype.asyncExecuteBatch_=function(){var c=this;this.asyncExecuteFunction(function(){c.executeBatch_()})};var l=$jscomp.global.setTimeout;h.prototype.asyncExecuteFunction=function(c){l(c,
0)};h.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var c=this.batch_;this.batch_=[];for(var f=0;f<c.length;++f){var h=c[f];delete c[f];try{h()}catch(m){this.asyncThrow_(m)}}}this.batch_=null};h.prototype.asyncThrow_=function(c){this.asyncExecuteFunction(function(){throw c;})};var f=function(c){this.state_=0;this.result_=void 0;this.onSettledCallbacks_=[];var f=this.createResolveAndReject_();try{c(f.resolve,f.reject)}catch(u){f.reject(u)}};f.prototype.createResolveAndReject_=
function(){function c(c){return function(r){h||(h=!0,c.call(f,r))}}var f=this,h=!1;return{resolve:c(this.resolveTo_),reject:c(this.reject_)}};f.prototype.resolveTo_=function(c){if(c===this)this.reject_(new TypeError("A Promise cannot resolve to itself"));else if(c instanceof f)this.settleSameAsPromise_(c);else{a:switch(typeof c){case "object":var h=null!=c;break a;case "function":h=!0;break a;default:h=!1}h?this.resolveToNonPromiseObj_(c):this.fulfill_(c)}};f.prototype.resolveToNonPromiseObj_=function(c){var f=
void 0;try{f=c.then}catch(u){this.reject_(u);return}"function"==typeof f?this.settleSameAsThenable_(f,c):this.fulfill_(c)};f.prototype.reject_=function(c){this.settle_(2,c)};f.prototype.fulfill_=function(c){this.settle_(1,c)};f.prototype.settle_=function(c,f){if(0!=this.state_)throw Error("Cannot settle("+c+", "+f|"): Promise already settled in state"+this.state_);this.state_=c;this.result_=f;this.executeOnSettledCallbacks_()};f.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var c=
this.onSettledCallbacks_,f=0;f<c.length;++f)c[f].call(),c[f]=null;this.onSettledCallbacks_=null}};var E=new h;f.prototype.settleSameAsPromise_=function(c){var f=this.createResolveAndReject_();c.callWhenSettled_(f.resolve,f.reject)};f.prototype.settleSameAsThenable_=function(c,f){var h=this.createResolveAndReject_();try{c.call(f,h.resolve,h.reject)}catch(m){h.reject(m)}};f.prototype.then=function(c,h){function n(c,f){return"function"==typeof c?function(f){try{m(c(f))}catch(A){l(A)}}:f}var m,l,r=new f(function(c,
f){m=c;l=f});this.callWhenSettled_(n(c,m),n(h,l));return r};f.prototype.catch=function(c){return this.then(void 0,c)};f.prototype.callWhenSettled_=function(c,f){function h(){switch(m.state_){case 1:c(m.result_);break;case 2:f(m.result_);break;default:throw Error("Unexpected state: "+m.state_);}}var m=this;null==this.onSettledCallbacks_?E.asyncExecute(h):this.onSettledCallbacks_.push(function(){E.asyncExecute(h)})};f.resolve=n;f.reject=function(c){return new f(function(f,h){h(c)})};f.race=function(c){return new f(function(f,
h){for(var m=$jscomp.makeIterator(c),l=m.next();!l.done;l=m.next())n(l.value).callWhenSettled_(f,h)})};f.all=function(c){var h=$jscomp.makeIterator(c),l=h.next();return l.done?n([]):new f(function(c,f){function m(f){return function(h){r[f]=h;u--;0==u&&c(r)}}var r=[],u=0;do r.push(void 0),u++,n(l.value).callWhenSettled_(m(r.length-1),f),l=h.next();while(!l.done)})};return f},"es6","es3");$jscomp.owns=function(c,h){return Object.prototype.hasOwnProperty.call(c,h)};
$jscomp.assign="function"==typeof Object.assign?Object.assign:function(c,h){for(var n=1;n<arguments.length;n++){var l=arguments[n];if(l)for(var f in l)$jscomp.owns(l,f)&&(c[f]=l[f])}return c};$jscomp.polyfill("Object.assign",function(c){return c||$jscomp.assign},"es6","es3");$jscomp.polyfill("Object.values",function(c){return c?c:function(c){var h=[],l;for(l in c)$jscomp.owns(c,l)&&h.push(c[l]);return h}},"es8","es3");
(function(c,h){"object"===typeof exports&&"undefined"!==typeof module?module.exports=h():"function"===typeof define&&define.amd?define(h):c.Radi=h()})(this,function(){var c={},h={},n={},l={},f=function b(a){return a.reduce(function(a,e){return a.concat(Array.isArray(e)?b(e):e)},[])},E=function(){for(var a="",b=0;32>b;b++){var d=16*Math.random()|0;if(8===b||12===b||16===b||20===b)a+="-";a+=(12===b?4:16===b?d&3|8:d).toString(16)}return a},r=function(){this.store={}};r.prototype.addListener=function(a,
b,d){"undefined"===typeof this.store[a]&&this.createItemWrapper(a);this.store[a].listeners[d]=(this.store[a].listeners[d]||[]).filter(function(a){return a.attached});this.store[a].listeners[d].push(b);return b};r.prototype.removeListeners=function(){for(var a=Object.keys(this.store),b=0;b<a.length;b++)this.store[a[b]].listeners={},this.store[a[b]].value=null};r.prototype.setState=function(a){for(var b=$jscomp.makeIterator(Object.keys(a)),d=b.next();!d.done;d=b.next())d=d.value,"undefined"===typeof this.store[d]&&
this.createItemWrapper(d),this.store[d].value=a[d],this.triggerListeners(d);return a};r.prototype.createItemWrapper=function(a){return this.store[a]={listeners:{},value:null}};r.prototype.triggerListeners=function(a){var b=this.store[a];if(b){a=Object.keys(b.listeners).sort().map(function(a){return b.listeners[a].map(function(a){return a})});for(var d=0;d<a.length;d++)for(var e=a[d].length-1;0<=e;e--)a[d][e].attached&&a[d][e].handleUpdate(b.value)}};var G=function(a){if("object"!==typeof a||null===
a)return a;if(Array.isArray(a))return a.map(G);var b={},d;for(d in a)a.hasOwnProperty(d)&&(b[d]=G(a[d]));return b},u=function(a){return"undefined"===typeof process||"production"===process.env.NODE_ENV||"test"===process.env.NODE_ENV?!1:a&&a()},m=function(a,b){for(var d=[],e=1;e<arguments.length;++e)d[e-1]=arguments[e];this.component=a;this.key=d[0];this.path=d.slice(1,d.length);this.depth=0;this.attached=!0;this.processValue=function(a){return a};this.changeListener=function(){};this.addedListeners=
[]};m.prototype.init=function(){this.value=this.getValue(this.component.state[this.key]);this.component.addListener(this.key,this,this.depth);this.handleUpdate(this.component.state[this.key]);return this};m.prototype.unlink=function(){this.value instanceof Node||this.value instanceof m&&this.value.deattach()};m.prototype.clone=function(a,b){var d={},e;for(e in a)d[e]=a[e];for(var c in b)d[c]=b[c];return d};m.prototype.setPartialState=function(a,b,d){var e={};return a.length?(e[a[0]]=1<a.length?this.setPartialState(a.slice(1),
b,d[a[0]]):b,this.clone(d,e)):b};m.prototype.updateValue=function(a){var b={};return this.component.setState((b[this.key]=this.setPartialState(this.path,a,this.component.state[this.key]),b))};m.prototype.extractListeners=function(a){var b=this;if(a instanceof m){var d={depth:a.depth,attached:!0,processValue:function(a){return a},handleUpdate:function(){b.component&&b.handleUpdate(b.getValue(b.component.state[b.key]));d.attached=!1},changeListener:function(){}};this.addedListeners.push(d);a.component.addListener(a.key,
d,a.depth);var e=a.processValue(a.getValue(a.component.state[a.key]));a.deattach();return this.extractListeners(e)}return a};m.prototype.handleUpdate=function(a){a=this.processValue(this.getValue(a));if(a instanceof m){for(var b=0;b<this.addedListeners.length;b++)this.addedListeners[b].attached=!1;this.addedListeners=[];this.value=this.extractListeners(a)}else this.unlink(),this.value=a;this.changeListener(this.value)};m.prototype.getValue=function(a){for(var b=0;b<this.path.length;)a=null===a||!a[this.path[b]]&&
"number"!==typeof a[this.path[b]]?null:a[this.path[b]],b+=1;return a};m.prototype.applyDepth=function(a){this.depth=a;return this};m.prototype.onValueChange=function(a){this.changeListener=a;this.changeListener(this.value)};m.prototype.process=function(a){this.processValue=a;return this};m.prototype.deattach=function(){this.component=null;this.attached=!1;this.path=this.childPath=this.key=null;this.unlink();this.value=null;this.changeListener=function(){};this.processValue=function(){}};var H=document.createEvent("Event");
H.initEvent("mount",!0,!0);var O=document.createEvent("Event");O.initEvent("load",!0,!0);var y=function(a,b,d){"function"===typeof a.dispatchEvent&&a.dispatchEvent(O);if(d&&b)return b.parentNode&&(b.parentNode.insertBefore(a,b),"function"===typeof a.dispatchEvent&&a.dispatchEvent(H)),a;b.appendChild(a);"function"===typeof a.dispatchEvent&&a.dispatchEvent(H);return a},N=function(a){return a.$redirect&&a.$redirect[a.$redirect.length-1]?N(a.$redirect[a.$redirect.length-1]):a},I=function(a,b,d){void 0===
d&&(d=0);a&&(a.$redirect&&0<a.$redirect.length?I(N(a),b,d+1):a.children&&0<a.children.length&&(a.html&&1===a.html.length?B(a.children,a.html[0],1!==a.html[0].nodeType,a.$isSvg,a.$depth):B(a.children,a.$pointer,!0,a.$isSvg,a.$depth)))},A=function(a){return document.createTextNode("object"===typeof a?JSON.stringify(a):a)},B=function(a,b,d,e,c){void 0===d&&(d=!1);void 0===e&&(e=!1);void 0===c&&(c=0);b="string"===typeof b?document.getElementById(b):b;var g=f([a]).map(t);a=function(a){var k=g[a];k instanceof
Node?y(k,b,d):k&&"function"===typeof k.render&&(k.$pointer=A(""),y(k.$pointer,b,d),g[a].render(function(a){if(!1===k.$pointer)return!1;for(var e=0;e<a.length;e++)k.$pointer?y(a[e],k.$pointer,!0):y(a[e],b,d);I(k,k.$isSvg,c+1)},k,c,e))};for(var p=0;p<g.length;p++)a(p);return g},U=function(a,b){if("string"===typeof a||"number"===typeof a)return"template"!==a?b||"svg"===a?document.createElementNS("http://www.w3.org/2000/svg",a):document.createElement(a):document.createDocumentFragment();console.warn("[Radi.js] Warn: Creating a JSX element whose query is not of type string, automatically converting query to string.");
return document.createElement(a.toString())},C=function(a,b,d,e,c){void 0===e&&(e=0);a=f([a]).map(t);for(var g=0;g<a.length;g++)(a[g]instanceof v||a[g].isStructure)&&!a[g].html&&(0>=b.children.length&&(b.$redirect?b.$redirect.push(a[g]):b.$redirect=[a[g]]),!b.$redirect&&a[g].children&&(b.children=b.children.concat(a[g].children)),"function"===typeof a[g].render&&a[g].render(function(a){d(a)},a[g],e+1,c))},V=function(a){return"number"!==typeof a||Number.isNaN(a)?a:a+"px"},J=function(a,b,d){void 0===
b&&(b={});void 0===d&&(d={});if(!a.html||!a.html[0])return b;var e=a.html[0];if(b instanceof m){if("undefined"!==typeof a.$styleListeners.general)return e.style;a.$styleListeners.general=b;a.$styleListeners.general.applyDepth(a.depth).init();a.$styleListeners.general.onValueChange(function(b){J(a,b,{})});return e.style}if("string"===typeof b)return e.style=b,e.style;var c=Object.keys(d).filter(function(a){return"undefined"===typeof b[a]}),g=function(g){!b.hasOwnProperty(g)||"undefined"!==typeof d&&
d[g]===b[g]||(b[g]||"number"===typeof b[g]?b[g]instanceof m?"undefined"===typeof a.$styleListeners[g]&&(a.$styleListeners[g]=b[g],a.$styleListeners[g].applyDepth(a.depth).init(),a.$styleListeners[g].onValueChange(function(b){var e={};J(a,(e[g]=b,e),{})}),b[g]=a.$styleListeners[g].value):e.style[g]=V(b[g]):e.style[g]=null)},p;for(p in b)g(p);for(g=0;g<c.length;g++)e.style[c[g]]=null;return e.style},W=function(a){return Array.isArray(a)?a.filter(function(a){return a}).join(" "):a},D=function(a,b,d){void 0===
b&&(b={});void 0===d&&(d={});var e=b||{},c=d||{};if(!a.html||!a.html[0])return a;var g=a.html[0];if(!(g instanceof Node&&3!==g.nodeType))return a;b=Object.keys(c).filter(function(a){return"undefined"===typeof e[a]});d=function(b){if(e.hasOwnProperty(b)&&("undefined"===typeof c||c[b]!==e[b]))if("checked"===b&&(g.checked=e[b]),e[b]||"number"===typeof e[b]||"string"===typeof e[b])if(e[b]instanceof m){if("undefined"===typeof a.$attrListeners[b]){a.$attrListeners[b]=e[b];e[b].applyDepth(a.depth).init();
if("model"===b.toLowerCase()||"checked"===b.toLowerCase())"radio"===g.getAttribute("type")?(g.addEventListener("input",function(d){a.$attrListeners[b].updateValue(d.target.checked&&d.target.value||d.target.checked)},!1),a.$attrListeners[b].onValueChange(function(b){D(a,{checked:g.value===b&&!!b},{})})):"checkbox"===g.getAttribute("type")?(g.addEventListener("input",function(d){a.$attrListeners[b].updateValue(!!d.target.checked)},!1),a.$attrListeners[b].onValueChange(function(b){D(a,{checked:!!b},
{})})):g.addEventListener("input",function(d){a.$attrListeners[b].updateValue(d.target.value)},!1);if(!/(checkbox|radio)/.test(g.getAttribute("type")))a.$attrListeners[b].onValueChange(function(d){var e={};D(a,(e[b]=d,e),{})});e[b]=a.$attrListeners[b].value}}else{if("value"===b||"model"===b)g.value=e[b];if("undefined"!==typeof n[b]){var d=n[b].allowedTags;if(!d||d&&0<d.length&&0<=d.indexOf(g.localName))if("function"===typeof n[b].caller&&n[b].caller(g,e[b]),!n[b].addToElement)return}if("style"===
b.toLowerCase())"object"===typeof e[b]?J(a,e[b],c&&c.style||{}):g.style=e[b];else if("class"===b.toLowerCase()||"classname"===b.toLowerCase())g.setAttribute("class",W(e[b]));else if("loadfocus"===b.toLowerCase())g.addEventListener("mount",function(){g.focus()},!1);else if("html"===b.toLowerCase())g.innerHTML=e[b];else if("on"===b.substring(0,2).toLowerCase()&&"function"===typeof e[b]){var p=e[b];"onsubmit"===b.substring(0,8).toLowerCase()?g[b]=function(b){e.prevent&&b.preventDefault();for(var d=[],
g=$jscomp.makeIterator(b.target.elements||[]),c=g.next();!c.done;c=g.next())if(c=c.value,""!==c.name&&"radio"!==c.type&&"checkbox"!==c.type||c.checked)c={name:c.name,el:c,type:c.type,default:c.defaultValue,value:c.value,set:function(b){a&&a.el&&a.el.value&&(a.el.value=b)},reset:function(b){a&&a.el&&a.el.value&&(a.el.value=b,a.el.defaultValue=b)}},d.push(c),d[c.name]||Object.defineProperty(d,c.name,{value:c});return p(b,d)}:g[b]=function(a,b){for(var d=[],c=1;c<arguments.length;++c)d[c-1]=arguments[c];
return p.apply(null,[].concat([a],$jscomp.arrayFromIterable(d)))}}else g.setAttribute(b,e[b])}else g.removeAttribute(b)};for(var p in e)d(p);for(p=0;p<b.length;p++)g.removeAttribute(b[p]);a.props=e;return a},v=function(a,b,d,c){void 0===b&&(b={});void 0===c&&(c=0);this.query=a;this.props=Boolean!==b?b:{};K(a)||a instanceof q?(this.$compChildren=f(d||[]).map(t),this.children=[]):(this.children=f(d||[]).map(t),this.$compChildren=[]);this.html=null;this.$attrListeners=[];this.$styleListeners=[];this.$redirect=
this.$listener=this.$component=this.$pointer=null;this.$destroyed=!1;this.$isSvg="svg"===a;this.$depth=c};v.prototype.mount=function(){this.$destroyed=!1;this.$component instanceof q&&this.$component.mount();if("function"===typeof this.onMount)this.onMount()};v.prototype.destroy=function(a){void 0===a&&(a=!0);if(this.$destroyed)return!1;for(var b in this.$styleListeners)this.$styleListeners[b]&&"function"===typeof this.$styleListeners[b].deattach&&this.$styleListeners[b].deattach();for(var d in this.$attrListeners)this.$attrListeners[d]&&
"function"===typeof this.$attrListeners[d].deattach&&this.$attrListeners[d].deattach();if(this.$redirect)for(b=0;b<this.$redirect.length;b++)"function"===typeof this.$redirect[b].destroy&&this.$redirect[b].destroy();if(a&&this.children)for(a=0;a<this.children.length;a++)"function"===typeof this.children[a].destroy&&this.children[a].destroy();if(this.html){var c=this.html;a=function(a){if(c[a].parentNode){var b=function(){return c[a].parentNode.removeChild(c[a])};"function"===typeof c[a].beforedestroy?
c[a].beforedestroy(b):b()}};for(b=0;b<this.html.length;b++)a(b)}this.$component instanceof q&&this.$component.destroy();this.$listener instanceof m&&this.$listener.deattach();this.$pointer&&this.$pointer.parentNode&&this.$pointer.parentNode.removeChild(this.$pointer);if("function"===typeof this.onDestroy)this.onDestroy();this.$component=this.$redirect=this.$pointer=null;this.render=function(){};this.html=null;return this.$destroyed=!0};v.prototype.render=function(a,b,d,c){var e=this;void 0===d&&(d=
0);void 0===c&&(c=!1);this.$depth=Math.max(this.$depth,d);this.$isSvg=c||b&&b.$isSvg||"svg"===this.query;return"#text"===this.query?(this.html=[A(this.props)],a(this.html)):"string"===typeof this.query||"number"===typeof this.query?(this.html=[U(this.query,this.$isSvg)],D(this,this.props,{}),a(this.html)):this.query instanceof m?(this.$listener||(this.$listener=this.query.applyDepth(this.$depth).init(),this.mount()),this.query.onValueChange(function(c){if(e.html){var d=e.html[0];e.$redirect=e.$pointer?
x(e.$redirect,c,e.$pointer,!0,e.$isSvg,e.$depth+1):x(e.$redirect,c,d,!0,e.$isSvg,e.$depth+1)}else C(c,b||e,function(b){e.html=b;a(b)},e.$depth+1,e.$isSvg)})):this.query instanceof Promise||"LazyPromise"===this.query.constructor.name?this.query.then(function(c){C(c.default||c,b||e,function(b){e.html=b;a(b)},e.$depth,e.$isSvg)}):this.query instanceof q&&"function"===typeof this.query.render?(this.$component=this.query,C(this.$component.render(),b||this,function(b){e.html=b;a(b);e.mount()},this.$depth,
this.$isSvg)):K(this.query)?(this.$component||(this.$component=(new this.query(this.$compChildren)).setProps(this.props)),"function"===typeof this.$component.render&&(C(this.$component.render(),b||this,function(b){e.html=b;a(b)},this.$depth,this.$isSvg),this.mount()),null):"function"===typeof this.query?C(this.query(this.props),b||this,function(b){e.html=b;a(b)},this.$depth,this.$isSvg):a(A(this.query))};v.prototype.isStructure=function(){return!0};var x=function(a,b,c,e,h,g){void 0===e&&(e=!1);void 0===
h&&(h=!1);void 0===g&&(g=0);var d=f([a]),k=f([b]).map(t);a=Math.max(d.length,k.length);b=function(a){if("undefined"===typeof d[a])B(k[a],c,e,h,g);else if("undefined"===typeof k[a])"function"===typeof d[a].destroy&&d[a].destroy();else if(k[a].$depth=g,(d[a]instanceof v||d[a].isStructure)&&(k[a]instanceof v||k[a].isStructure)&&d[a]!==k[a])if(d[a].html&&"#text"===d[a].query&&"#text"===k[a].query){for(var b=0;b<d[a].html.length;b++)d[a].props!==k[a].props&&(d[a].html[b].textContent=d[a].props=k[a].props);
k[a].html=d[a].html;d[a].html=null;d[a].$pointer&&(k[a].$pointer&&k[a].$pointer.parentNode&&k[a].$pointer.parentNode.removeChild(k[a].$pointer),k[a].$pointer=d[a].$pointer,d[a].$pointer=null);d[a].destroy()}else if(d[a].html&&"string"===typeof d[a].query&&"string"===typeof k[a].query&&d[a].query===k[a].query)k[a].html=d[a].html,d[a].html=null,d[a].$pointer&&(k[a].$pointer&&k[a].$pointer.parentNode&&k[a].$pointer.parentNode.removeChild(k[a].$pointer),k[a].$pointer=d[a].$pointer,d[a].$pointer=null),
D(k[a],k[a].props,d[a].props),k[a].html[0]&&k[a].children&&0<k[a].children.length&&(k[a].children=x(d[a].children,k[a].children,k[a].html[0],!1,k[a].$isSvg,k[a].$depth+1)),d[a].destroy();else{var f=d[a],p=k[a];p.$pointer=A("");y(p.$pointer,c,e);p.render(function(b){f.$pointer&&(p.$pointer&&p.$pointer.parentNode&&p.$pointer.parentNode.removeChild(p.$pointer),p.$pointer=f.$pointer,f.$pointer=null);for(var d=0;d<b.length;d++)f.html&&!f.html[a]||!f.html?y(b[d],p.$pointer,!0):y(b[d],f.html[a],!0);I(p,
h,g+1);f.destroy(!1)},p,g,h)}};for(var l=0;l<a;l++)b(l);return k},P=function(a){return a.charAt(0).toUpperCase()+a.substr(1)},q=function(a,b){var d=this;this.addNonEnumerableProperties({$id:E(),$name:this.constructor.name,$config:"function"===typeof this.config?this.config():{listen:!0},__$events:{},__$privateStore:new r});if("function"!==typeof this.on||"function"===typeof this.on&&"object"===typeof this.on())throw Error("[Radi.js] Using `on.eventName()` is deprecated. Please use `onEventName()`.");
this.children=[];for(var e in c)if(this[e]&&"function"===typeof this[e].on)this[e].on("update",function(){return d.setState()});this.state="function"===typeof this.state?this.state():this.state||{};u(function(){return Object.freeze(d.state)});a&&this.setChildren(a);b&&this.setProps(b)};q.prototype.render=function(){return"function"!==typeof this.view?null:this.html=this.view()};q.prototype.setProps=function(a){var b={},d=this,c=function(c){if("function"===typeof a[c]&&"on"===c.substr(0,2))d.on(c.substring(2,
c.length),a[c]);else a[c]instanceof m?(b[c]=a[c].init().value,a[c].changeListener=function(a){var b={};d.setState((b[c]=a,b))}):b[c]=a[c]},f;for(f in a)c(f);this.setState(b);return this};q.prototype.setChildren=function(a){var b=this;this.children=a;this.setState();for(a=0;a<this.children.length;a++)if("function"===typeof this.children[a].on)this.children[a].on("update",function(){return b.setState()});return this};q.prototype.addNonEnumerableProperties=function(a){for(var b in a)"undefined"===typeof this[b]&&
Object.defineProperty(this,b,{value:a[b]})};q.prototype.addListener=function(a,b,d){this.__$privateStore.addListener(a,b,d)};q.prototype.mount=function(){this.trigger("mount")};q.prototype.destroy=function(){this.html=null;this.trigger("destroy");this.__$privateStore.removeListeners()};q.prototype.when=function(){throw Error("[Radi.js] Using `.when('Event')` is deprecated. Use `.on('Event')` instead.");};q.prototype.on=function(a,b){"undefined"===typeof this.__$events[a]&&(this.__$events[a]=[]);this.__$events[a].push(b);
return b};q.prototype.trigger=function(a,b){for(var d=[],c=1;c<arguments.length;++c)d[c-1]=arguments[c];c=this["on"+P(a)];"function"===typeof c&&c.call.apply(c,[].concat([this],$jscomp.arrayFromIterable(d)));if("undefined"!==typeof this.__$events[a])for(var f in this.__$events[a])this.__$events[a][f].call.apply(this.__$events[a][f],[].concat([this],$jscomp.arrayFromIterable(d)))};q.prototype.setState=function(a,b){var c=this;if("object"===typeof a){var e=this.state;u(function(){return e=G(c.state)});
this.state=Object.assign(e,a);u(function(){return Object.freeze(c.state)});this.$config.listen&&this.__$privateStore.setState(a)}!this.$config.listen&&"function"===typeof this.view&&this.html&&(this.html=x(this.html,this.view()));"string"===typeof b&&"function"===typeof this[b]&&this.trigger("after"+P(b),a);this.trigger("update");return a};q.isComponent=function(){return!0};var K=function(a){return a&&(a.prototype instanceof q||a.isComponent)?!0:!1},t=function(a){return Array.isArray(a)?a.map(t):
"string"===typeof a||"number"===typeof a?z("#text",a):a&&"boolean"!==typeof a?a instanceof m||K(a)||a instanceof q||"function"===typeof a||a instanceof Promise||"LazyPromise"===a.constructor.name?z(a):a:z("#text","")},z=function(a,b,c){for(var d=[],h=2;h<arguments.length;++h)d[h-2]=arguments[h];if("undefined"!==typeof l[a])return l[a].onmount(b||{},d&&f([d]).map(t)||[],t,function(b){return l[a].saved=b})||null;if("await"===a){var g=null;b.src&&b.src instanceof Promise&&b.src.then(function(a){a=t("function"===
typeof b.transform?b.transform(a):a);g=g?x(g,a,g.html[0].parentNode):a}).catch(function(a){a=t("function"===typeof b.error?b.error(a):b.error);g=g?x(g,a,g.html[0].parentNode):a});g||(g=t(b.placeholder));return g}return"template"===a?new v("section",b,f([d]).map(t)):new v(a,b,f([d]).map(t))},L=function(a,b){for(var c=[],e=1;e<arguments.length;++e)c[e-1]=arguments[e];return new (Function.prototype.bind.apply(m,[null].concat([a],$jscomp.arrayFromIterable(c))))},Q=function(a,b){a="$".concat(a);b=new b;
b.mount();q.prototype[a]=b;return c[a]=b},X=function(a){var b=function(){};a=new window.Blob(["self.onmessage \x3d function(e) {\n self.postMessage(("+a.toString()+")(e.data));\n }"],{type:"text/javascript"});a=window.URL.createObjectURL(a);var c=new window.Worker(a);c.onmessage=function(a){b(a.data,null)};c.onerror=function(a){b(null,a.data)};return function(a){return new Promise(function(d,e){b=function(a,b){return b?e(a):d(a)};c.postMessage(a)})}},R=function(a,b,c){return l[a]={name:a,onmount:b||
function(){},ondestroy:c||function(){},saved:null}},S=function(a,b,c){void 0===c&&(c={});return n[a]={name:a,caller:b,allowedTags:c.allowedTags||null,addToElement:c.addToElement}},Y=function(){Object.values(h).forEach(function(a){if("function"===typeof a.onMount)a.onMount(a)})},T=function(a,b,c,e){c=c[b];if("function"!==typeof c)console.warn("[Radi.js] Animation `"+b+"` for node `"+a.nodeName.toLowerCase+"` should be function");else return c(a,e)};S("animation",function(a,b){T(a,"in",b,function(){});
a.beforedestroy=function(c){return T(a,"out",b,c)}});var w=function(a){function b(){a.apply(this,arguments)}a&&(b.__proto__=a);b.prototype=Object.create(a&&a.prototype);b.prototype.constructor=b;b.prototype.state=function(){return{registry:{}}};b.prototype.register=function(a,b){if("undefined"!==typeof this.state.registry[a])console.warn('[Radi.js] Warn: Modal with name "'+a+'" is already registerd!');else{var c={};this.setState({registry:Object.assign({},this.state.registry,(c[a]={status:!1,element:b},
c))},"register")}};b.prototype.exists=function(a){return"undefined"===typeof this.state.registry[a]?(console.warn('[Radi.js] Warn: Modal with name "'+a+'" is not registerd!'),!1):!0};b.prototype.open=function(a){if(this.exists(a)&&!this.state.registry[a].status){var b={};return this.setState({registry:Object.assign({},this.state.registry,(b[a]={status:!0,element:this.state.registry[a].element},b))},"open")}};b.prototype.close=function(a){if(this.exists(a)&&this.state.registry[a].status){var b={};
return this.setState({registry:Object.assign({},this.state.registry,(b[a]={status:!1,element:this.state.registry[a].element},b))},"close")}};b.prototype.closeAll=function(){var a=this,b=Object.keys(this.state.registry).reduce(function(b,c){var d={};return Object.assign(b,(d[c]={status:!1,element:a.state.registry[c].element},d))},{});return this.setState({registry:b},"closeAll")};return b}(q),M=Q("modal",w);R("modal",function(a,b,c){var d=a.name||"default";M.register(d,null);"undefined"===typeof a.name&&
console.warn("[Radi.js] Warn: Every \x3cmodal\x3e tag needs to have `name` attribute!");var f=B(L(M,"registry",d).process(function(a){return a.status&&z("div",{class:"radi-modal",name:d},z("div",{class:"radi-modal-backdrop",onclick:function(){return M.close(d)}}),z.apply(null,[].concat(["div",{class:"radi-modal-content"}],$jscomp.arrayFromIterable(b.slice()))))}),document.body);a=c(null);a.onDestroy=function(){for(var a=0;a<f.length;a++)"function"===typeof f[a].destroy&&f[a].destroy()};return a},
function(){});var Z=function(a){var b={};a=$jscomp.makeIterator(a.elements||[]);for(var c=a.next();!c.done;c=a.next())if(c=c.value,""!==c.name&&"radio"!==c.type&&"checkbox"!==c.type||c.checked)b[c.name]=c.value;return b},aa=function(a){var b=null;a=$jscomp.makeIterator(a);for(var c=a.next();!c.done;c=a.next())c=c.value,c.submitButton&&(b=c);return b};w=function(a){this.value=a;this.rules=[]};w.prototype.register=function(a){var b=this,c=a.validate,e=a.error,f=this.rules.push({type:a.type,validate:function(a){return a&&
c(a)},error:e||"Invalid field"});this.error=function(a){b.rules[f-1].error=a||e;return b};return this};w.prototype.check=function(a){var b=this;"undefined"!==typeof a&&(this.value=a);return this.rules.reduce(function(a,c){return"string"===typeof a?a:!c.validate(b.value)&&c.error||a},!0)};w.prototype.required=function(){return this.register({type:"required",validate:function(a){return""!==a},error:"Field is required"})};w.prototype.min=function(a){return this.register({type:"min",validate:function(b){return b.length>=
a},error:"Min char length is "+a})};w.prototype.max=function(a){return this.register({type:"max",validate:function(b){return b.length<a},error:"Max char length is "+a})};w.prototype.email=function(){return this.register({type:"email",validate:function(a){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)},error:"Email is not valid"})};var F={version:"0.4.2",activeComponents:h,r:z,listen:L,l:L,worker:function(a,b,c){var d=X(c.value);c.value=function(a){for(var b=[],c=0;c<arguments.length;++c)b[c-0]=arguments[c];
var e=this;d.apply(null,[].concat($jscomp.arrayFromIterable(b))).then(function(a){e.setState.call(e,a)})};return c},Component:q,component:q,action:function(a,b,c){var d=c.value;return{configurable:!0,value:function(a){for(var c=[],e=0;e<arguments.length;++e)c[e-0]=arguments[e];return this.setState.call(this,d.call.apply(d,[].concat([this],$jscomp.arrayFromIterable(c))),b)}}},subscribe:function(a,b){return function(c,e,f){var d=f.value,h=function(){};if("function"!==typeof d)throw Error("@subscribe decorator can only be applied to methods not: "+
typeof d);var k=!1;a[b]=function(a){for(var b=[],c=0;c<arguments.length;++c)b[c-0]=arguments[c];return h.apply(null,[].concat($jscomp.arrayFromIterable(b)))};return{configurable:!0,get:function(){if(k||this===c.prototype||this.hasOwnProperty(e)||"function"!==typeof d)return d;h=d.bind(this);k=!0;Object.defineProperty(this,e,{configurable:!0,get:function(){return h},set:function(a){d=a;delete this[e]}});k=!1;return h},set:function(a){d=a}}}},customTag:R,customAttribute:S,headless:Q,update:x,patch:x,
mount:B,freeze:function(){},unfreeze:function(){Y()},Validator:w,plugin:function(a,b){for(var c=[],e=1;e<arguments.length;++e)c[e-1]=arguments[e];return a.apply(null,[].concat([F],$jscomp.arrayFromIterable(c)))}};F.plugin(function(a){var b=function(a){function b(){a.apply(this,arguments)}a&&(b.__proto__=a);b.prototype=Object.create(a&&a.prototype);b.prototype.constructor=b;b.prototype.state=function(){return{}};b.prototype.add=function(a,b){var c={};c=this.setState((c[a]=b,c));this.trigger("update:"+
a,b);return c};b.prototype.remove=function(a){return this.add(a,[])};return b}(a.Component),c=a.headless("errors",b);a.customTag("errors",function(b,d,g,f){var e=g(null);c.on("update:"+b.name,function(c){c=!c||0>=c.length?g(null):g(b.onrender(c||[]));e=a.patch(e,c,e.html[0].parentNode)[0]});return e},function(){});a.customAttribute("error",function(a,b){a.onerror=function(a){return c.add(b,a)};a.onvalid=function(){return c.remove(b)}},{allowedTags:["form"],addToElement:!1});a.customAttribute("validate-submit",
function(a,b){a.submitButton=!0},{allowedTags:["button"]});a.customAttribute("validate",function(a,b){var c=a.form,d=null,e=function(b){c||(c=a.form);if(c&&"function"===typeof c.onvalidate){d=aa(c.elements);b=Z(c);var e=c.onvalidate(c),f=c.touched||[];if(e){if("object"===typeof e){var g=[],h;for(h in e)if(e.hasOwnProperty(h)&&"function"===typeof e[h]){var k=e[h](b[h]);"string"===typeof k&&0>f.indexOf(h)?g.push({field:h,reason:null}):"string"===typeof k&&g.push({field:h,reason:k||null})}if(0<g.length){d&&
(d.disabled=!0);if("function"===typeof c.onerror)c.onerror(g.filter(function(a){return a.reason}));return}}d&&(d.disabled=!1);if(c&&"function"===typeof c.onvalid)c.onvalid();return}}d&&(d.disabled=!0);if(c&&"function"===typeof c.onerror)c.onerror(null)};a.addEventListener("change",function(b){if(c){var d=a.name;"undefined"===typeof c.touched&&(c.touched=[]);0>c.touched.indexOf(d)&&(c.touched.push(a.name),e(b))}});a.addEventListener("input",e);return!0},{allowedTags:["input","textarea","select"]})});
window&&(window.Radi=F);return F});