jskick
Version:
Short syntax html data binding + templating solution using javascript, a variation of rivetsjs and tinybind.
3 lines (2 loc) • 23.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).kick=e()}(this,function(){"use strict";var a=["templateDelimiters","rootInterface","preloadData","handler"],o="components",c=["binders","formatters",o,"adapters"],b=/^'.*'$|^".*"$/,v=" \n\r\t".split("");function n(t){var e=0,n=t;return b.test(t)?n=t.slice(1,-1):"true"===t?n=!0:"false"===t?n=!1:"null"===t?n=null:"undefined"===t?n=void 0:isNaN(t)?e=1:n=Number(t),{type:e,value:n}}function h(t,e){for(var n,i=t.length,r=0,s=0,a=e[0],o=e[1];s<i;){if((r=t.indexOf(a,s))<0){n&&n.push({type:0,value:t.slice(s)});break}if(n=n||[],0<r&&s<r&&n.push({type:0,value:t.slice(s,r)}),s=r+a.length,(r=t.indexOf(o,s))<0){var c=t.slice(s-o.length),h=n[n.length-1];h&&0===h.type?h.value+=c:n.push({type:0,value:c});break}var u=t.slice(s,r).trim();n.push({type:1,value:u}),s=r+o.length}return n}function i(t){return function i(t){var e=new RegExp("([a-zA-Z0-9_$]+)\\((.*)\\)","g"),n={_:[]};if(b.test(t))return n._.push({k:t,t:"l"}),n;var r=e.exec(t);if(!r||r.length<3)return n;var s,a,o,c,h,u,l,f,d=(s=r[2],a=[],o=(s+=",").split(""),h=c=0,f=l=u="",o.forEach(function(t){switch(!0){case"'"===t:case'"'===t:l.length&&l===t?(u+=l+f+l,a[h]={s:f},l=f="",h++):l=t;break;case!l.length&&-1!==v.indexOf(t):break;case!l.length&&"("===t:u+=t,c++;break;case!l.length&&")"===t:u+=t,c--;break;case!l.length&&","===t:0!==c?u+=t:(a[h]={e:u},u="",h++);break;default:l.length?f+=t:u+=t}}),a),p={_:[]};return d.forEach(function(t){if(t.e)if(-1==t.e.indexOf("("))p._.push({k:t.e,t:"p"});else{var e,n=i(t.e);for(e in n)p._.push(n[e][0])}}),n._.push({k:r[1],t:"f",_:p._}),n}(t)._[0]||null}var s,u,r,m={binders:{},formatters:{},components:{},adapters:{},parseTemplate:h,parseType:n,templateDelimiters:["{{","}}"],binderMap:{"^":"^click","^^":"^dblclick","^_":"^contextmenu","^@":"^change","^+":"^focus","^-":"^blur","@":"@value","@x":"@checked","@-x":"@unchecked",":":":text","::":":html",$:":html","+":":show","-":":hide","~":":disabled","~~":":enabled","-~":":enabled"},varBinderMap:{".&":":class-&","-.&":"-:class-&","..&":":style-&","-..&":"-:style-&",":&":":attr-&","-:&":"-:attr-&"},rootInterface:".",preloadData:!0,handler:function(t,e,n){var i=n.parseFormatterArguments(n.fnArgs,0,e,n.view.models),r=this.name.split(" "),s=r[r.length-1];if(s&&""!==s){var a,o=n.model;(a=o[s]).call.apply(a,[o].concat([].concat(i)))}else this.call.apply(this,[t].concat([].concat(i)))},fallbackBinder:function(t,e){if(null!=e){var n=this.type,i=customElements.get(t.localName);if(":"===n.substr(0,1)&&(n=n.substr(1)),i&&i.properties&&void 0!==i.properties[n])t[i.properties[n]]=e;else t.setAttribute(n,e)}else t.removeAttribute(this.type)},configure:function(t){var i=this;t&&Object.keys(t).forEach(function(e){var n=t[e];-1<c.indexOf(e)?Object.keys(n).forEach(function(t){i[e][t]=n[t]}):i[e]=n})},router:{}};function l(t){return"object"==typeof t&&null!==t}function f(t,e,n){this.keypath=e,this.callback=n,this.objectPath=[],this.parse(),this.obj=this.getRootObject(t),l(this.target=this.realize())&&this.set(!0,this.key,this.target,this.callback)}f.updateOptions=function(t){s=t.adapters,u=Object.keys(s),r=t.rootInterface},f.tokenize=function(t,e){var n,i,r=[],s={i:e,path:""};for(n=0;n<t.length;n++)i=t.charAt(n),~u.indexOf(i)?(r.push(s),s={i:i,path:""}):s.path+=i;return r.push(s),r},f.prototype.parse=function(){var t,e;u.length||function(t){throw new Error("[Observer] "+t)}("Must define at least one adapter interface."),t=~u.indexOf(this.keypath[0])?(e=this.keypath[0],this.keypath.substr(1)):(e=r,this.keypath),this.tokens=f.tokenize(t,e),this.key=this.tokens.pop()},f.prototype.realize=function(){for(var t,e,n=this.obj,i=-1,r=0;r<this.tokens.length;r++)e=this.tokens[r],l(n)?(void 0!==this.objectPath[r]?n!==(t=this.objectPath[r])&&(this.set(!1,e,t,this),this.set(!0,e,n,this),this.objectPath[r]=n):(this.set(!0,e,n,this),this.objectPath[r]=n),n=this.get(e,n)):(-1===i&&(i=r),(t=this.objectPath[r])&&this.set(!1,e,t,this));return-1!==i&&this.objectPath.splice(i),n},f.prototype.sync=function(){var t,e,n;(t=this.realize())!==this.target?(l(this.target)&&this.set(!1,this.key,this.target,this.callback),l(t)&&this.set(!0,this.key,t,this.callback),e=this.value(),this.target=t,((n=this.value())!==e||n instanceof Function)&&this.callback.sync()):t instanceof Array&&this.callback.sync()},f.prototype.value=function(){if(l(this.target))return this.get(this.key,this.target)},f.prototype.setValue=function(t){l(this.target)&&s[this.key.i].set(this.target,this.key.path,t)},f.prototype.get=function(t,e){return s[t.i].get(e,t.path)},f.prototype.set=function(t,e,n,i){var r=t?"observe":"unobserve";s[e.i][r](n,e.path,i)},f.prototype.unobserve=function(){for(var t,e,n=0;n<this.tokens.length;n++)e=this.tokens[n],(t=this.objectPath[n])&&this.set(!1,e,t,this);l(this.target)&&this.set(!1,this.key,this.target,this.callback)},f.prototype.getRootObject=function(t){var e,n;if(!t.$parent)return t;for(e=this.tokens.length?this.tokens[0].path:this.key.path,n=t;n.$parent&&void 0===n[e];)n=n.$parent;return n};function d(t,e){var n=!1;if(3===e.nodeType){var i=h(e.data,m.templateDelimiters);if(i){for(var r=0;r<i.length;r++){var s=i[r],a=document.createTextNode(s.value);e.parentNode.insertBefore(a,e),1===s.type&&t.buildBinding(a,null,s.value,x,null)}e.parentNode.removeChild(e)}n=!0}else 1===e.nodeType&&(n=t.traverse(e));if(!n)for(var o=0;o<e.childNodes.length;o++)d(t,e.childNodes[o])}function p(t,e){var n=t.binder&&t.binder.priority||0;return(e.binder&&e.binder.priority||0)-n}function y(t){return t.trim()}function k(t,e,n){T?$(t).off(e,n):t.removeEventListener(e,n)}function g(t){return null!=t?t.toString():void 0}var _=/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g,w=/\s+/,O=/\(.*\)/,E=function(){function t(t,e,n,i,r,s,a){this.view=t,this.el=e,this.type=n,this.keypath=i,this.binder=r,this.arg=s,this.formatters=a,this.formatterObservers={},this.model=void 0,this.fnArgs=[],this.subscribers=[],this.locked=!1,this.listeners={}}var e=t.prototype;return e.observe=function(t,e){return new f(t,e,this)},e.parseTarget=function(){if(this.keypath){var t=n(this.keypath);if(0===t.type)this.value=t.value;else{if(O.test(this.keypath)){var e=i(this.keypath);e&&(this.keypath=e.k,this.fnArgs=e._.map(function(t){return t.k}))}this.observer=this.observe(this.view.models,this.keypath),this.model=this.observer.target}}else this.value=void 0},e.parseFormatterArguments=function(t,s,a,o){var c=this;return t.map(n).map(function(t,e){var n=t.type,i=t.value;if(0===n)return i;if("$ev"===i||"$event"===i)return a;if("$vm"===i||"$scope"===i)return o;if("$el"===i)return c.el;c.formatterObservers[s]||(c.formatterObservers[s]={});var r=c.formatterObservers[s][e];return r||(r=c.observe(c.view.models,i),c.formatterObservers[s][e]=r),r.value()})},e.formattedValue=function(t){var o=this;return this.formatters.reduce(function(t,e,n){var i=e.match(_),r=i.shift(),s=o.view.options.formatters[r],a=o.parseFormatterArguments(i,n,null,o.view.models);return s&&s.read instanceof Function?t=s.read.apply(s,[t].concat(a)):s instanceof Function&&(t=s.apply(void 0,[t].concat(a))),t},t)},e.eventHandler=function(t){var e=this,n=e.view.options.handler,i=t,r=this.type,s=this.el;if("^"===r.substr(0,1)&&(r=r.substr(1)),!s.constructor||!s.constructor.properties||void 0===s.constructor.properties[r])return function(t){i&&n.call(i,this,t,e)};s[s.constructor.properties[r]]=i},e.set=function(t){if(t instanceof Function&&!this.binder.function){var e=this.parseFormatterArguments(this.fnArgs,0,null,this.view.models);t=this.formattedValue(t.call.apply(t,[this.model].concat([].concat(e))))}else t=this.formattedValue(t);var n=this.binder.routine||this.binder;n instanceof Function&&(n.call(this,this.el,t),this.callSubscribers(t))},e.sync=function(){this.observer?(this.model=this.observer.target,this.set(this.observer.value())):this.set(this.value)},e.publish=function(){var o=this;if(this.observer){var t=this.formatters.reduceRight(function(t,e,n){var i=e.split(w),r=i.shift(),s=o.view.options.formatters[r],a=o.parseFormatterArguments(i,n,null,o.view.models);return s&&s.publish&&(t=s.publish.apply(s,[t].concat(a))),t},this.getValue(this.el));this.observer.setValue(t)}},e.bind=function(){this.parseTarget(),this.binder.hasOwnProperty("bind")&&this.binder.bind.call(this,this.el),this.view.options.preloadData&&this.sync()},e.unbind=function(){var n=this;this.binder.unbind&&this.binder.unbind.call(this,this.el),this.observer&&this.observer.unobserve(),Object.keys(this.formatterObservers).forEach(function(t){var e=n.formatterObservers[t];Object.keys(e).forEach(function(t){e[t].unobserve()})}),this.formatterObservers={}},e.update=function(t){void 0===t&&(t={}),this.observer&&(this.model=this.observer.target),this.binder.update&&this.binder.update.call(this,t)},e.getValue=function(t){return this.binder&&this.binder.getValue?this.binder.getValue.call(this,t):(n=[],"checkbox"===(e=t).type?e.checked:"select-multiple"===e.type?(e.options.forEach(function(t){t.selected&&n.push(t.value)}),n):e.value);var e,n},e.subscribe=function(t){var e=this.subscribers.push(t)-1;return{remove:function(){delete this.subscribers[e]}}},e.callSubscribers=function(e){this.subscribers.forEach(function(t){t(e)})},e.lock=function(t){return void 0===t?this.locked:(!0!==this.locked||!0!==t)&&(this.locked=t)},e.kins=function(){var e=this;return this.view.bindings.filter(function(t){return t.el===e.el})},e.kin=function(t){var e=m.binderMap[t]||t;return this.kins().find(function(t){return t.type===e})},t}(),x={routine:function(t,e){t.data=null!=e?e:""}},j=/((?:'[^']*')*(?:(?:[^\|']*(?:'[^']*')+[^\|']*)+|[^\|]+))|^$/g,N="@:^.-+?!*#$~".split(""),A=function(){function t(t,e,n){t.jquery||t instanceof Array?this.els=t:this.els=[t],this.models=e,this.options=n,this.build()}var e=t.prototype;return e.buildBinding=function(t,e,n,i,r){var s=n.match(j).map(y),a=s.shift();if(""===r&&"*"===e){var o=new RegExp(/^(.+)\s+in\s+(.[^|\s]+)(.*)$/gm).exec(a);o&&2<o.length&&(r=o[1]||r,a=o[2]||a)}this.bindings.push(new E(this,t,e,a,i,r,s))},e.build=function(){this.bindings=[];var t,e,n=this.els;for(t=0,e=n.length;t<e;t++)d(this,n[t]);this.bindings.sort(p)},e.traverse=function(t){for(var e,n,i,r,s="SCRIPT"===t.nodeName||"STYLE"===t.nodeName,a=t.attributes,o=[],c=this.options.varBinders,h=0,u=a.length;h<u;h++){var l=a[h];if(this.startWithBinder(l.name)){if(e=m.binderMap[l.name]||l.name,r=void 0,!(n=this.options.binders[e]))for(var f=0;f<c.length;f++)if(i=c[f],e.slice(0,i.length-1)===i.slice(0,-1)){n=this.options.binders[i],r=e.slice(i.length-1);break}if((n=n||m.fallbackBinder).block)return this.buildBinding(t,e,l.value,n,r),t.removeAttribute(l.name),!0;o.push({attr:l,binder:n,type:e,arg:r})}}for(var d=0;d<o.length;d++){var p=o[d];this.buildBinding(t,p.type,p.attr.value,p.binder,p.arg),t.removeAttribute(p.attr.name)}return m.components[e]&&!t._bound&&(this.bindings.push(new ComponentBinding(this,t,e)),s=!0),s},e.bind=function(){this.bindings.forEach(function(t){t.bind()})},e.unbind=function(){this.bindings.forEach(function(t){t.unbind()})},e.sync=function(){this.bindings.forEach(function(t){t.sync()})},e.publish=function(){this.bindings.forEach(function(t){t.binder&&t.binder.publishes&&t.publish()})},e.update=function(e){var n=this;void 0===e&&(e={}),Object.keys(e).forEach(function(t){n.models[t]=e[t]}),this.bindings.forEach(function(t){t.update&&t.update(e)})},e.startWithBinder=function(t){var e=t.substr(0,1);return N.some(function(t){return t===e})},t}(),T=!!window.jQuery;function C(t,e,n){var i=t.el.cloneNode(!0),r=new A(i,e,t.view.options);return r.bind(),t.marker.parentNode.insertBefore(i,n),r}var t={"^&":{function:!0,priority:1e3,unbind:function(t){this.handler&&k(t,this.arg,this.handler)},routine:function(t,e){var n,i,r;this.handler&&k(t,this.arg,this.handler),this.handler=this.eventHandler(e),n=t,i=this.arg,r=this.handler,T?$(n).on(i,r):n.addEventListener(i,r)}},"*&":{block:!0,priority:4e3,bind:function(t){this.marker?this.iterated.forEach(function(t){t.bind()}):(this.marker=document.createComment(" kick: "+this.type+" "),this.iterated=[],t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t))},unbind:function(){this.iterated&&this.iterated.forEach(function(t){t.unbind()})},routine:function(t,e){var c=this,h=this.arg||"$item";e=e||[];var u=t.getAttribute("#index")||t.getAttribute("index-property")||"$index";e.forEach(function(t,e){var n={$parent:c.view.models};n[u]=e,n[h]=t;var i=c.iterated[e];if(i)if(i.models[h]!==t){for(var r,s,a=e+1;a<c.iterated.length;a++)if((s=c.iterated[a]).models[h]===t){r=a;break}void 0!==r?(c.iterated.splice(r,1),c.marker.parentNode.insertBefore(s.els[0],i.els[0]),s.models[u]=e):s=C(c,n,i.els[0]),c.iterated.splice(e,0,s)}else i.models[u]=e;else{var o=c.marker;c.iterated.length&&(o=c.iterated[c.iterated.length-1].els[0]),i=C(c,n,o.nextSibling),c.iterated.push(i)}}),this.iterated.length>e.length&&function(t,e){for(var n=0;n<t;n++)e()}(this.iterated.length-e.length,function(){var t=c.iterated.pop();t.unbind(),c.marker.parentNode.removeChild(t.els[0])}),"OPTION"===t.nodeName&&this.view.bindings.forEach(function(t){t.el===c.marker.parentNode&&"value"===t.type&&t.sync()})},update:function(e){var n=this,i={};Object.keys(e).forEach(function(t){t!==n.arg&&(i[t]=e[t])}),this.iterated.forEach(function(t){t.update(i)})}},"-..&":function(t,e){var n=this.arg;e&&(t.style[n]="")},"..&":function(t,e){var n=this.arg;t.style[n]=e||""},"-.&":function(t,e){var n=" "+t.className+" ";e===-1<n.indexOf(" "+this.arg+" ")&&(t.className=e?n.replace(" "+this.arg+" "," ").trim():t.className+" "+this.arg)},".&":function(t,e){var n=" "+t.className+" ",i=this.arg;null!=i&&""!==i||(i=e),!e==-1<n.indexOf(" "+i+" ")&&(t.className=e?t.className+" "+i:n.replace(" "+i+" "," ").trim())},":text":function(t,e){t.textContent=null!=e?e:""},":html":function(t,e){t.innerHTML=null!=e?e:""},":show":function(t,e){t.style.display=e?"":"none"},":hide":function(t,e){t.style.display=e?"none":""},":enabled":function(t,e){t.disabled=!e},":disabled":function(t,e){t.disabled=!!e},"@checked":{publishes:!0,priority:2e3,bind:function(t){var e=this;this.callback||(this.callback=function(){e.publish()}),t.addEventListener("change",this.callback)},unbind:function(t){t.removeEventListener("change",this.callback)},routine:function(t,e){"radio"===t.type?t.checked=g(t.value)===g(e):t.checked=!!e}},"@unchecked":{publishes:!0,priority:2e3,bind:function(t){var e=this;this.callback||(this.callback=function(){e.publish()}),t.addEventListener("change",this.callback)},unbind:function(t){t.removeEventListener("change",this.callback)},routine:function(t,e){"radio"===t.type?t.checked=!(g(t.value)===g(e)):t.checked=!e}},"@value":{publishes:!0,priority:3e3,bind:function(t){if(this.isRadio="INPUT"===t.tagName&&"radio"===t.type,!this.isRadio){this.event=t.getAttribute("event-name")||("SELECT"===t.tagName?"change":"input");var e=this;this.callback||(this.callback=function(){e.publish()}),t.addEventListener(this.event,this.callback)}},unbind:function(t){this.isRadio||t.removeEventListener(this.event,this.callback)},routine:function(t,e){if(this.isRadio)t.setAttribute("value",e);else if("select-multiple"===t.type){if(e instanceof Array)for(var n=0;n<t.length;n++){var i=t[n];i.selected=-1<e.indexOf(i.value)}}else g(e)!==g(t.value)&&(t.value=null!=e?e:"")}},"?":{block:!0,priority:4e3,bind:function(t){this.marker?!1===this.bound&&this.nested&&this.nested.bind():(this.marker=document.createComment(" kick: "+this.type+" "+this.keypath+" "),this.attached=!1,t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)),this.bound=!0},unbind:function(){this.nested&&(this.nested.unbind(),this.bound=!1)},routine:function(t,e){!!e!==this.attached&&(e?(this.nested||(this.nested=new A(t,this.view.models,this.view.options),this.nested.bind()),this.marker.parentNode.insertBefore(t,this.marker.nextSibling),this.attached=!0):(t.parentNode.removeChild(t),this.attached=!1))},update:function(t){this.nested&&this.nested.update(t)}},"-?":{block:!0,priority:4001,bind:function(t){this.marker?!1===this.bound&&this.nested&&this.nested.bind():(this.marker=document.createComment(" kick: "+this.type+" "+this.keypath+" "),this.attached=!1,t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)),this.bound=!0},unbind:function(){this.nested&&(this.nested.unbind(),this.bound=!1)},routine:function(t,e){!!e===this.attached&&(e?(t.parentNode.removeChild(t),this.attached=!1):(this.nested||(this.nested=new A(t,this.view.models,this.view.options),this.nested.bind()),this.marker.parentNode.insertBefore(t,this.marker.nextSibling),this.attached=!0))},update:function(t){this.nested&&this.nested.update(t)}},":&":function(t,e){null!=e?t.setAttribute(this.arg,e):t.removeAttribute(this.arg)},"-:&":function(t,e){null!=e&&t.removeAttribute(this.arg)}},M=["push","pop","shift","unshift","sort","reverse","splice"],e={counter:0,weakmap:{},weakReference:function(t){if(!t.hasOwnProperty("__rv")){var e=this.counter++;Object.defineProperty(t,"__rv",{value:e})}return this.weakmap[t.__rv]||(this.weakmap[t.__rv]={callbacks:{}}),this.weakmap[t.__rv]},cleanupWeakReference:function(t,e){Object.keys(t.callbacks).length||t.pointers&&Object.keys(t.pointers).length||delete this.weakmap[e]},stubFunction:function(r,t){var s=r[t],a=this.weakReference(r),o=this.weakmap;r[t]=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i=s.apply(r,e);return Object.keys(a.pointers).forEach(function(t){var e=a.pointers[t];o[t]&&o[t].callbacks[e]instanceof Array&&o[t].callbacks[e].forEach(function(t){t.sync()})}),i}},observeMutations:function(e,t,n){var i=this;if(e instanceof Array){var r=this.weakReference(e);r.pointers||(r.pointers={},M.forEach(function(t){i.stubFunction(e,t)})),r.pointers[t]||(r.pointers[t]=[]),-1===r.pointers[t].indexOf(n)&&r.pointers[t].push(n)}},unobserveMutations:function(t,e,n){if(t instanceof Array&&null!=t.__rv){var i=this.weakmap[t.__rv];if(i){var r=i.pointers[e];if(r){var s=r.indexOf(n);-1<s&&r.splice(s,1),r.length||delete i.pointers[e],this.cleanupWeakReference(i,t.__rv)}}}},observe:function(i,r,t){var s,a=this,e=this.weakReference(i).callbacks;if(!e[r]){e[r]=[];var n=Object.getOwnPropertyDescriptor(i,r);n&&(n.get||n.set||!n.configurable)||(s=i[r],Object.defineProperty(i,r,{enumerable:!0,get:function(){return s},set:function(t){if(t!==s){a.unobserveMutations(s,i.__rv,r),s=t;var e=a.weakmap[i.__rv];if(e){var n=e.callbacks[r];n&&n.forEach(function(t){t.sync()}),a.observeMutations(t,i.__rv,r)}}}}))}-1===e[r].indexOf(t)&&e[r].push(t),this.observeMutations(i[r],i.__rv,r)},unobserve:function(t,e,n){var i=this.weakmap[t.__rv];if(i){var r=i.callbacks[e];if(r){var s=r.indexOf(n);-1<s&&(r.splice(s,1),r.length||(delete i.callbacks[e],this.unobserveMutations(t[e],t.__rv,e))),this.cleanupWeakReference(i,t.__rv)}}},get:function(t,e){return t[e]},set:function(t,e,n){t[e]=n}};function R(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function B(t){return(B=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function L(t,e){return(L=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function P(t,e,n){return(P=function(){if("undefined"!=typeof Reflect&&Reflect.construct&&!Reflect.construct.sham){if("function"==typeof Proxy)return 1;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),1}catch(t){return}}}()?Reflect.construct:function(t,e,n){var i=[null];i.push.apply(i,e);var r=new(Function.bind.apply(t,i));return n&&L(r,n.prototype),r}).apply(null,arguments)}function F(t){var i="function"==typeof Map?new Map:void 0;return(F=function(t){if(null===t||(e=t,-1===Function.toString.call(e).indexOf("[native code]")))return t;var e;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(t))return i.get(t);i.set(t,n)}function n(){return P(t,arguments,B(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),L(n,t)})(t)}var S=function(s){var t,e;e=s,(t=o).prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e,o.setObservedAttributes=function(t){var e=t.template,n=t.tag;if(!e||!n)throw new Error("No template or tag declared for "+this.name);t.__templateEl=document.createElement("template"),t.__templateEl.innerHTML=e;var i=t.__propAttributeMap={},r=[],s=t.properties;return s&&Object.keys(s).forEach(function(t){var e=s[t],n="string"==typeof e?e:t;i[n]=t,r.push(n)}),r};var n,i,r,a=o.prototype;function o(){for(var t,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];var r=t=s.call.apply(s,[this].concat(n))||this;return t.onInit(),r||function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}return a.connectedCallback=function(){var t=this.constructor.__templateEl.content.cloneNode(!0);for(this.__kickView=m.bind(t,this);this.firstChild;)this.removeChild(this.firstChild);this.__kickView.sync(),this.appendChild(t),this.__kickView.sync(),this.afterInit()},a.disconnectedCallback=function(){this.beforeExit(),this.__kickView.unbind()},a.attributeChangedCallback=function(t,e,n){e!==n&&(this[this.constructor.__propAttributeMap[t]]=n)},n=o,r=[{key:"observedAttributes",get:function(){return this.setObservedAttributes(this)}}],(i=null)&&R(n.prototype,i),r&&R(n,r),a.onInit=function(){},a.afterInit=function(){},a.beforeExit=function(){},o}(F(HTMLElement));return m.binders=t,m.formatters={watch:function(t){return t},not:function(t){return!t},negate:function(t){return!t}},m.adapters["."]=e,m.Component=S,m.bind=function(t,e,n){var i=(t=t||"[kick-app]").nodeType&&0<t.nodeType?t:document.querySelector(t);m.includeFile(i),i=t.nodeType&&0<t.nodeType?t:document.querySelector(t);var r={};e=e||{},n=n||{},c.forEach(function(e){r[e]=Object.create(null),n[e]&&Object.keys(n[e]).forEach(function(t){r[e][t]=n[e][t]}),Object.keys(m[e]).forEach(function(t){r[e][t]||(r[e][t]=m[e][t])})}),r[o]&&Object.keys(r[o]).forEach(function(t){var e=r[o][t];e.tag&&!customElements.get(e.tag)&&customElements.define(e.tag,e)}),a.forEach(function(t){var e=n[t];r[t]=null!=e?e:m[t]}),r.varBinders=Object.keys(r.binders).filter(function(t){return 0<t.indexOf("&")}),f.updateOptions(r);var s=new A(i,e,r);return s.bind(),s},m.init=function(t,e,n){void 0===n&&(n={}),null==e&&(e=document.createElement("div"));var i=(t=m.components[t]).template.call(m,e);if(i instanceof HTMLElement){for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(i)}else e.innerHTML=i;var r=t.initialize.call(m,e,n),s=new A(e,r);return s.bind(),s},m.formatters.negate=m.formatters.not=function(t){return!t},m.formatters.call=function(t){for(var e=arguments.length,n=new Array(1<e?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];if(n.length){var r=n[0];return n=Array.prototype.slice.call(n,1),r.call.apply(r,[t].concat(n))}},m.loadFile=function(e,t){try{var n=new XMLHttpRequest;n.onreadystatechange=function(){4==this.readyState&&(200==this.status?"KICKER"===e.tagName?e.outerHTML=this.responseText:(e.removeAttribute(":file"),e.innerHTML=this.responseText,m.includeFile(e)):404==this.status?e.innerHTML="\x3c!-- "+this.responseURL+" not found. --\x3e":e.innerHTML="\x3c!-- "+this.responseText+" --\x3e")},n.open("GET",t,!1),n.send()}catch(t){e.innerHTML="\x3c!-- Unable to connect to server --\x3e"}},m.includeFile=function(t){var e,n,i,r;if(t.getElementsByTagName)e=t.getElementsByTagName("*");else{if(!t.children.length)return;e=t.children}for(n=0;n<e.length;n++)(r=(i=e[n]).getAttribute(":file"))&&m.loadFile(i,r)},m});
//# sourceMappingURL=kick.min.js.map