UNPKG

ractive

Version:

Next-generation DOM manipulation

1 lines 29.7 kB
(function(t){"use strict";var e,n,i,r,o,s,a,h,d,p,c,u,f,l,g,m,v,w,y,b,x,N,_,k,F={},E={},M={},L={},O=2,S=3,R=4,P=7,V=8,A={html:"http://www.w3.org/1999/xhtml",mathml:"http://www.w3.org/1998/Math/MathML",svg:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};F.animate=function(t,n,i){var r,o,a,h,d;for(i=i||{},h=N.animations.length;h--;)N.animations[h].keypath===t&&N.animations[h].stop();i.easing&&(r="function"==typeof i.easing?i.easing:this.easing&&this.easing[i.easing]?this.easing[i.easing]:e.easing[i.easing],"function"!=typeof r&&(r=null)),o=void 0===i.duration?400:i.duration,d=s(t),a=new g({keys:d,from:this.get(d),to:n,root:this,duration:o,easing:r,step:i.step,complete:i.complete}),N.push(a)},F.bind=function(t){var e=this._bound;-1===e.indexOf(t)&&(e[e.length]=t,t.init(this))},F.fire=function(t){var e,n,i,r=this._subs[t];if(r)for(e=Array.prototype.slice.call(arguments,1),n=0,i=r.length;i>n;n+=1)r[n].apply(this,e)},F.get=function(t){var e,n,i,r,o,h;if(!t)return this.data;if(a(t))e=t.slice(),n=e.join(".");else{if(this._cache.hasOwnProperty(t))return this._cache[t];e=s(t),n=e.join(".")}return this._cache.hasOwnProperty(n)?this._cache[n]:(i=e.pop(),o=e.length?this.get(e):this.data,"object"==typeof o&&o.hasOwnProperty(i)?(h=o[i],r=e.join("."),this._depsMap[r]||(this._depsMap[r]=[]),-1===this._depsMap[r].indexOf(n)&&this._depsMap[r].push(n),this.modifyArrays&&(!a(h)||h.ractive&&h._ractive.setting||_(h,n,this)),this._cache[n]=h,h):void 0)};var C,j,T,I,q,B;C=function(t){if(t.keypath)I(t.root,t.keypath,t,t.priority||0);else{var e=t.root._pendingResolution.indexOf(t);-1!==e&&t.root._pendingResolution.splice(e,1)}t.evaluator&&t.evaluator.teardown()},j=function(t,e){var n,i,r=t._depsMap[e];if(t.modifyArrays&&(n=t._cache[e],a(n)&&!n._ractive.setting&&k(n,e,t)),delete t._cache[e],r)for(i=r.length;i--;)j(t,r[i])},T=function(t,e,n,i){var r;return t._deps[e]||(t._deps[e]=[]),r=t._deps[e],r[i]?(r=r[i],-1===r.indexOf(n)&&(r[r.length]=n),void 0):(r[i]=[n],void 0)},I=function(t,e,n,i){var r,o,s;for(r=t._deps[e][i],r.splice(r.indexOf(n),1),r.length||t._deps[e].splice(i,1),o=t._deps[e].length;o--;)if(t._deps[e][o]){s=!0;break}s||delete t._deps[e]},q=function(t,e){var n,i,r,o,s,a;if(n=t._deps[e])for(s=n.length,r=0;s>r;r+=1)if(i=n[r])for(o=i.length;o--;)i[o].update();if(a=t._depsMap[e])for(r=a.length;r--;)q(t,a[r])},B=function(t,e,n){var i,r,o,a,h,d;if("."===e)return n[n.length-1];for(i=s(e),r=i.pop(),n=n.concat();n.length;)if(o=n.pop(),a=s(o),h=t.get(a.concat(i)),"object"==typeof h&&h.hasOwnProperty(r)){d=o+"."+e;break}return d||void 0===t.get(e)||(d=e),d},F.link=function(t){var e=this;return function(n){e.set(t,n)}},F.off=function(t,e){var n,i;e||(t?this._subs[t]=[]:this._subs={}),n=this._subs[t],n&&(i=n.indexOf(e),-1!==i&&n.splice(i,1))},F.on=function(t,e){var n,i,r=this;if("object"==typeof t){n=[];for(i in t)t.hasOwnProperty(i)&&(n[n.length]=this.on(i,t[i]));return{cancel:function(){for(;n.length;)n.pop().cancel()}}}return this._subs[t]?this._subs[t].push(e):this._subs[t]=[e],{cancel:function(){r.off(t,e)}}},F.render=function(t){var e=t.el?c(t.el):this.el;if(!e)throw Error("You must specify a DOM element to render to");t.append||(e.innerHTML=""),t.callback&&(this.callback=t.callback),this.rendered=new u({descriptor:this.template,root:this,owner:this,parentNode:e}),e.appendChild(this.rendered.docFrag)},function(t){var e,n;e=function(t,e,i,r,o){var s,a,h;if(s=t.get(e),s!==r){for(h=t.data;i.length>1;)a=i.shift(),h[a]||(h[a]=/^\s*[0-9]+\s*$/.test(i[0])?[]:{}),h=h[a];a=i[0],h[a]=r}else if("object"!=typeof r)return;j(t,e),o?o[o.length]=e:(q(t,e),n(t)),t.setting||(t.setting=!0,t.fire("set",e,r),t.fire("set:"+e,r),t.setting=!1)},n=function(t){var e,n,i;for(e=t._pendingResolution.length;e--;)n=t._pendingResolution.splice(e,1)[0],(i=B(t,n.ref,n.contextStack))?n.resolve(i):t._pendingResolution[t._pendingResolution.length]=n},t.set=function(t,i){var r,o,a,d;if(h(t)){r=[];for(o in t)t.hasOwnProperty(o)&&(d=s(o),a=d.join("."),i=t[o],e(this,a,d,i,r));if(r.length){for(;r.length;)q(this,r.pop());n(this)}}else d=s(t),a=d.join("."),e(this,a,d,i);for(;this._def.length;)this._def.pop().update().deferred=!1}}(F),F.teardown=function(){var t;this.rendered.teardown();for(t in this._depsMap)this._depsMap.hasOwnProperty(t)&&j(this,t);for(t in this._cache)this._cache.hasOwnProperty(t)&&j(this,t);for(;this._bound.length;)this.unbind(this._bound.pop())},F.unbind=function(t){var e,n=this._bound;e=n.indexOf(t),-1!==e&&(n.splice(e,1),t.teardown(this))},F.update=function(t){return j(this,t||""),q(this,t||""),this.fire("update:"+t),this.fire("update",t),this},E.backbone=function(t,e){var n,i,r,o,s,a,h;return e&&(e+=".",s=RegExp("^"+e.replace(/\./g,"\\.")),a=e.length),{init:function(d){e?(h=function(t){var n,i;i={};for(n in t)t.hasOwnProperty(n)&&(i[e+n]=t[n]);return i},o=function(t){n||(i=!0,d.set(h(t.changed)),i=!1)},r=function(e,r){i||s.test(e)&&(n=!0,t.set(e.substring(a),r),n=!1)}):(o=function(t){n||(i=!0,d.set(t.changed),i=!1)},r=function(e,r){i||(n=!0,t.set(e,r),n=!1)}),t.on("change",o),d.on("set",r),d.set(e?h(t.attributes):t.attributes)},teardown:function(e){t.off("change",o),e.off("set",r)}}},E.statesman=function(t,e){var n,i,r,o;return e=e?e+".":"",{init:function(e){o=function(t,r){n||(i=!0,e.set(t,r),i=!1)},r=function(e,r){i||(n=!0,t.set(e,r),n=!1)},t.on("set",o),e.on("set",r),e.set(t.get())},teardown:function(e){t.off("change",o),e.off("set",r)}}},n={linear:function(t){return t},easeIn:function(t){return Math.pow(t,3)},easeOut:function(t){return Math.pow(t-1,3)+1},easeInOut:function(t){return 1>(t/=.5)?.5*Math.pow(t,3):.5*(Math.pow(t-2,3)+2)}},M.tap=function(t,e){var n,i,r,o;return r=5,o=400,n=function(t){var n,i,s,a,h,d;n=t.clientX,i=t.clientY,s=this,a=function(t){e.call(s,t),d()},h=function(t){(Math.abs(t.clientX-n)>=r||Math.abs(t.clientY-i)>=r)&&d()},d=function(){window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",a)},window.addEventListener("mousemove",h),window.addEventListener("mouseup",a),setTimeout(d,o)},t.addEventListener("mousedown",n),i=function(t){var n,i,s,a,h,d,p;1===t.touches.length&&(s=t.touches[0],n=s.clientX,i=s.clientY,a=s.identifier,d=function(t){var n;n=t.changedTouches[0],n.identifier!==a&&p(),e.call(n.target,t)},h=function(t){var e;(1!==t.touches.length||t.touches[0].identifier!==a)&&p(),e=t.touches[0],(Math.abs(e.clientX-n)>=r||Math.abs(e.clientY-i)>=r)&&p()},p=function(){window.removeEventListener("touchmove",h),window.removeEventListener("touchend",d),window.removeEventListener("touchcancel",p)},window.addEventListener("touchmove",h),window.addEventListener("touchend",d),window.addEventListener("touchcancel",p),setTimeout(p,o))},{teardown:function(){t.removeEventListener("mousedown",n),t.removeEventListener("touchstart",i)}}},i=function(t){var n,i,r;n=this,i=function(){e.apply(this,arguments),this.init&&this.init.apply(this,arguments)};for(r in n.prototype)n.prototype.hasOwnProperty(r)&&(i.prototype[r]=n.prototype[r]);for(r in t)if(t.hasOwnProperty(r)){if(e.prototype.hasOwnProperty(r))throw Error('Cannot override "'+r+'" method or property of Ractive prototype');i.prototype[r]=t[r]}return i.extend=n.extend,i},r=function(t,n){return d(t)&&d(n)?e.interpolators.number(+t,+n):a(t)&&a(n)?e.interpolators.array(t,n):h(t)&&h(n)?e.interpolators.object(t,n):function(){return n}},o={number:function(t,e){var n=e-t;return n?function(e){return t+e*n}:function(){return t}},array:function(t,n){var i,r,o,s;for(i=[],r=[],s=o=Math.min(t.length,n.length);s--;)r[s]=e.interpolate(t[s],n[s]);for(s=o;t.length>s;s+=1)i[s]=t[s];for(s=o;n.length>s;s+=1)i[s]=n[s];return function(t){for(var e=o;e--;)i[e]=r[e](t);return i}},object:function(t,n){var i,r,o,s,a=[];o={},r={};for(s in t)t.hasOwnProperty(s)&&(n.hasOwnProperty(s)?(a[a.length]=s,r[s]=e.interpolate(t[s],n[s])):o[s]=t[s]);for(s in n)n.hasOwnProperty(s)&&!t.hasOwnProperty(s)&&(o[s]=n[s]);return i=a.length,function(t){for(var e,n=i;n--;)e=a[n],o[e]=r[e](t);return o}}},e=function(t){var n,i,r,o;if(t)for(i in t)t.hasOwnProperty(i)&&(this[i]=t[i]);n={preserveWhitespace:!1,append:!1,twoway:!0,modifyArrays:!0,data:{}};for(i in n)n.hasOwnProperty(i)&&void 0===this[i]&&(this[i]=n[i]);if(void 0!==this.el&&(this.el=c(this.el)),this._subs={},this._cache={},this._deps={},this._depsMap={},this.nodes={},this._observers={},this._pendingResolution=[],this._def=[],this._proxies={},this._bound=[],this.bindings)if(a(this.bindings))for(o=0;this.bindings.length>o;o+=1)this.bind(this.bindings[o]);else this.bind(this.bindings);if(this.partials)for(i in this.partials)if(this.partials.hasOwnProperty(i)){if(r=this.partials[i],"string"==typeof r){if(!e.parse)throw Error('Missing Ractive.parse - cannot parse partial "'+i+'". Either preparse or use the version that includes the parser');r=e.parse(r,this)}1===r.length&&"string"==typeof r[0]&&(r=r[0]),this.partials[i]=r}if("string"==typeof this.template){if(!e.parse)throw Error("Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser");this.template=e.parse(this.template,this)}this.template&&1===this.template.length&&"string"==typeof this.template[0]&&(this.template=this.template[0]),this.el&&this.render({el:this.el,append:this.append})},g=function(t){var n;this.startTime=Date.now();for(n in t)t.hasOwnProperty(n)&&(this[n]=t[n]);this.interpolator=e.interpolate(this.from,this.to),this.running=!0},g.prototype={tick:function(){var t,e,n,i;return this.running?(i=Date.now(),t=i-this.startTime,t>=this.duration?(this.root.set(this.keys,this.to),this.step&&this.step(1,this.to),this.complete&&this.complete(1,this.to),this.running=!1,!1):(e=this.easing?this.easing(t/this.duration):t/this.duration,n=this.interpolator(e),this.root.set(this.keys,n),this.step&&this.step(e,n),!0)):!1},stop:function(){this.running=!1}},N={animations:[],tick:function(){var e,n;for(e=0;this.animations.length>e;e+=1)n=this.animations[e],n.tick()||this.animations.splice(e--,1);this.animations.length?t.requestAnimationFrame(this.boundTick):this.running=!1},boundTick:function(){N.tick()},push:function(t){this.animations[this.animations.length]=t,this.running||(this.running=!0,this.tick())}},function(t,e,n){var i;for(i=0;t.length>i&&!n.requestAnimationFrame;++i)n.requestAnimationFrame=n[t[i]+"RequestAnimationFrame"],n.cancelAnimationFrame=n[t[i]+"CancelAnimationFrame"]||n[t[i]+"CancelRequestAnimationFrame"];n.requestAnimationFrame||(n.requestAnimationFrame=function(t){var i,r,o;return i=Date.now(),r=Math.max(0,16-(i-e)),o=n.setTimeout(function(){t(i+r)},r),e=i+r,o}),n.cancelAnimationFrame||(n.cancelAnimationFrame=function(t){n.clearTimeout(t)})}(["ms","moz","webkit","o"],0,t),function(){var t,e,n,i,r,o,s;t=Object.defineProperty?Object.defineProperty:function(t,e,n){t[e]=n.value},_=function(e,i,r){var o,s,a,h;e._ractive?(o=e._ractive.roots,s=e._ractive.keypathsByIndex,a=o.indexOf(r),-1===a&&(a=o.length,o[a]=r),s[a]||(s[a]=[]),h=s[a],-1===h.indexOf(i)&&(h[h.length]=i)):(t(e,"_ractive",{value:{roots:[r],keypathsByIndex:[[i]]},configurable:!0}),n(e))},k=function(t,e,n){var r,o,s,a,h;if(!t._ractive)throw Error("Attempted to remove keypath from non-wrapped array. This error is unexpected - please send a bug report to @rich_harris");if(r=t._ractive.roots,s=r.indexOf(n),-1===s)throw Error("Ractive instance was not listed as a dependent of this array. This error is unexpected - please send a bug report to @rich_harris");if(o=t._ractive.keypathsByIndex,a=o[s],h=a.indexOf(e),-1===h)throw Error("Attempted to unlink non-linked keypath from array. This error is unexpected - please send a bug report to @rich_harris");a.splice(h,1),a.length||r.splice(s,1),r.length||i(t)},e=function(t){var e,n,i,r,o,s;for(e=t._ractive.roots,n=t._ractive.keypathsByIndex,o=e.length;o--;)for(i=e[o],r=n[o],s=r.length;s--;)i.set(r[s],t)},r=[],s=["pop","push","reverse","shift","sort","splice","unshift"],s.forEach(function(n){var i=function(){var t=Array.prototype[n].apply(this,arguments);return this._ractive.setting=!0,e(this),this._ractive.setting=!1,t};t(r,n,{value:i})}),o={},o.__proto__?(n=function(t){t.__proto__=r},i=function(t){delete t._ractive,t.__proto__=Array.prototype}):(n=function(e){var n,i;for(n=s.length;n--;)i=s[n],t(e,i,{value:r[i]})},i=function(t){var e;for(e=s.length;e--;)delete t[s[e]];delete t._ractive})}(),function(t,e){var n,i;i=function(t,n){var i,r;if(e[t])return e[t];for(r=[];n--;)r[n]="_"+n;return i=Function(r.join(","),"return("+t+")"),e[t]=i,i},l=function(t,e,i,r,o){var s;if(this.root=t,this.mustache=e,this.priority=e.priority,this.str=o.s,this.keypaths=[],this.override=[],this.values=[],o.r){for(this.unresolved=o.r.length,this.refs=o.r.slice(),this.resolvers=[],s=o.r.length;s--;)r&&r.hasOwnProperty(o.r[s])?(this.values[s]=this.override[s]=r[o.r[s]],this.unresolved-=1):this.resolvers[this.resolvers.length]=new n(t,o.r[s],i,s,this);1>=this.resolvers.length&&(this.selfUpdating=!0),this.unresolved||this.resolved||this.init()}else this.init()},l.prototype={init:function(){var t,e=this;this.resolved=!0,this.keypath="("+this.str.replace(/❖([0-9]+)/g,function(t,n){return e.override.hasOwnProperty(n)?e.override[n]:e.keypaths[n]})+")",t=this.str.replace(/❖([0-9]+)/g,function(t,e){return"_"+e}),this.fn=i(t,this.refs?this.refs.length:0),this.update(),this.mustache.resolve(this.keypath)},teardown:function(){if(this.resolvers)for(;this.resolvers.length;)this.resolvers.pop().teardown()},resolve:function(t,e,n){this.keypaths[e]=n,this.unresolved-=1,this.unresolved||this.init()},bubble:function(){this.selfUpdating?this.update():this.deferred||(this.root._def[this.root._def.length]=this,this.deferred=!0)},update:function(){var t;if(!this.resolved)return this;try{t=this.getter()}catch(e){if(this.root.debug)throw e;t=void 0}return p(t,this._lastValue)||(this.root._cache[this.keypath]=t,q(this.root,this.keypath),this._lastValue=t),this},getter:function(){return this.fn.apply(null,this.values)}},n=function(t,e,n,i,r){var o;this.ref=e,this.root=t,this.evaluator=r,this.argNum=i,o=B(t,e,n),o?this.resolve(o):(this.contextStack=n,t._pendingResolution[t._pendingResolution.length]=this)},n.prototype={teardown:function(){C(this)},resolve:function(t){this.keypath=t,T(this.root,t,this,this.evaluator.priority),this.update(),this.evaluator.resolve(this.ref,this.argNum,t)},update:function(){var t=this.root.get(this.keypath);p(t,this._lastValue)||(this.evaluator.values[this.argNum]=t,this.evaluator.bubble(),this._lastValue=t)}}}({},{}),b=function(t,e){var n,i,r,o,s;if(t.owner=e.owner,t.owner.type===R&&(t.index=e.index),t.owner.parentFragment&&(o=t.owner.parentFragment.indexRefs)){t.indexRefs={};for(s in o)o.hasOwnProperty(s)&&(t.indexRefs[s]=o[s])}for(e.indexRef&&(t.indexRefs||(t.indexRefs={}),t.indexRefs[e.indexRef]=e.index),t.items=[],r={root:e.root,parentFragment:t,parentNode:e.parentNode,contextStack:e.contextStack},n=e.descriptor?e.descriptor.length:0,i=0;n>i;i+=1)r.descriptor=e.descriptor[i],r.index=i,t.items[t.items.length]=t.createItem(r)},m=function(t,e){var n,i;t.root=e.root,t.descriptor=e.descriptor,t.parentFragment=e.parentFragment,t.contextStack=e.contextStack||[],t.index=e.index||0,t.priority=e.descriptor.p||0,(e.parentNode||e.anchor)&&(t.parentNode=e.parentNode,t.anchor=e.anchor),t.type=e.descriptor.t,e.descriptor.r&&(t.parentFragment.indexRefs&&t.parentFragment.indexRefs.hasOwnProperty(e.descriptor.r)?(i=t.parentFragment.indexRefs[e.descriptor.r],t.render(i)):(n=B(t.root,e.descriptor.r,t.contextStack),n?t.resolve(n):(t.ref=e.descriptor.r,t.root._pendingResolution[t.root._pendingResolution.length]=t,t.descriptor.n&&t.render(!1)))),e.descriptor.x&&(t.evaluator=new l(t.root,t,t.contextStack,t.parentFragment.indexRefs,e.descriptor.x))},v=function(){var t;this.keypath?t=this.root.get(this.keypath,!0):this.expression&&(t=this.evaluate()),p(t,this._lastValue)||(this.render(t),this._lastValue=t)},w=function(t){this.keypath=t,T(this.root,t,this,this.priority),this.update()},y=function(){var t,e;for(t=[],e=this.refs.length;e--;)t[e]=this.root.get(this.refs[e]);return this.evaluator.apply(null,t)},x=function(t,e){var n,i,r,o,s;if(n={descriptor:t.descriptor.f,root:t.root,parentNode:t.parentNode,owner:t},i=a(e),i&&0===e.length&&(r=!0),t.descriptor.n){if(e&&!r)t.length&&(t.unrender(),t.length=0);else if(!t.length)return n.contextStack=t.contextStack,n.index=0,t.fragments[0]=t.createFragment(n),t.length=1,void 0}else if(i){if(e.length<t.length)for(s=t.fragments.splice(e.length,t.length-e.length);s.length;)s.pop().teardown();else if(e.length>t.length)for(o=t.length;e.length>o;o+=1)n.contextStack=t.contextStack.concat(t.keypath+"."+o),n.index=o,t.descriptor.i&&(n.indexRef=t.descriptor.i),t.fragments[o]=t.createFragment(n);t.length=e.length}else h(e)?t.length||(n.contextStack=t.contextStack.concat(t.keypath),n.index=0,t.fragments[0]=t.createFragment(n),t.length=1):e&&!r?t.length||(n.contextStack=t.contextStack,n.index=0,t.fragments[0]=t.createFragment(n),t.length=1):t.length&&(t.unrender(),t.length=0)},function(){var t,n,i,r,o,s,a,h,d,p;i={"accept-charset":"acceptCharset",accesskey:"accessKey",bgcolor:"bgColor","class":"className",codebase:"codeBase",colspan:"colSpan",contenteditable:"contentEditable",datetime:"dateTime",dirname:"dirName","for":"htmlFor","http-equiv":"httpEquiv",ismap:"isMap",maxlength:"maxLength",novalidate:"noValidate",pubdate:"pubDate",readonly:"readOnly",rowspan:"rowSpan",tabindex:"tabIndex",usemap:"useMap"},n="undefined"!=typeof window?window.document:null,t=function(t,e){var i,r=[];for(i=n.createElement("div"),i.innerHTML=t;i.firstChild;)r[r.length]=i.firstChild,e.appendChild(i.firstChild);return r},u=function(e){return this.docFrag=n.createDocumentFragment(),"string"==typeof e.descriptor?(this.nodes=t(e.descriptor,this.docFrag),void 0):(b(this,e),void 0)},u.prototype={createItem:function(t){if("string"==typeof t.descriptor)return new r(t,this.docFrag);switch(t.descriptor.t){case O:return new h(t,this.docFrag);case R:return new p(t,this.docFrag);case S:return new d(t,this.docFrag);case P:return new o(t,this.docFrag);case V:return new s(t,this.docFrag);default:throw"WTF? not sure what happened here..."}},teardown:function(){var t;if(this.nodes)for(;this.nodes.length;)t=this.nodes.pop(),t.parentNode.removeChild(t);else for(;this.items.length;)this.items.pop().teardown()},firstNode:function(){return this.items[0]?this.items[0].firstNode():null},findNextNode:function(t){var e=t.index;return this.items[e+1]?this.items[e+1].firstNode():null}},s=function(t,e){this.parentFragment=t.parentFragment,this.fragment=new u({descriptor:t.root.partials[t.descriptor.r]||[],root:t.root,parentNode:t.parentNode,contextStack:t.contextStack,owner:this}),e.appendChild(this.fragment.docFrag)},s.prototype={teardown:function(){this.fragment.teardown()}},r=function(t,e){this.node=n.createTextNode(t.descriptor),this.root=t.root,this.parentNode=t.parentNode,e.appendChild(this.node)},r.prototype={teardown:function(){this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},firstNode:function(){return this.node}},o=function(t,e){var i,r,o,s,h,d,p,c;if(i=this.descriptor=t.descriptor,this.root=t.root,this.parentFragment=t.parentFragment,this.parentNode=t.parentNode,this.index=t.index,this.eventListeners=[],this.customEventListeners=[],i.a&&i.a.xmlns){if(r=i.a.xmlns,"string"!=typeof r)throw Error("Namespace attribute cannot contain mustaches")}else r=this.parentNode.namespaceURI;if(this.node=n.createElementNS(r,i.e),i.f&&("string"==typeof i.f&&this.node.namespaceURI===A.html?this.node.innerHTML=i.f:(this.children=new u({descriptor:i.f,root:t.root,parentNode:this.node,contextStack:t.contextStack,owner:this}),this.node.appendChild(this.children.docFrag))),i.v)for(o in i.v)i.v.hasOwnProperty(o)&&this.addEventProxy(o,i.v[o],t.contextStack);this.attributes=[],p=[];for(h in i.a)i.a.hasOwnProperty(h)&&(d=i.a[h],s=new a({element:this,name:h,value:void 0===d?null:d,root:t.root,parentNode:this.node,contextStack:t.contextStack}),this.attributes[this.attributes.length]=s,s.isBindable&&p.push(s),s.isTwowayNameAttr?c=s:s.update());for(;p.length;)p.pop().bind(this.root.lazy);c&&(c.updateViewModel(),c.update()),e.appendChild(this.node)},o.prototype={addEventProxy:function(t,n,i){var r,o,s,a,h=this,d=this.root;"string"==typeof n?(d._proxies[n]||(d._proxies[n]=function(t){d.fire(n,t,this)}),a=d._proxies[n]):(s=new f({descriptor:n,root:this.root,owner:this,contextStack:i}),a=function(t){d.fire(s.getValue(),t,h.node)}),(r=e.eventDefinitions[t])?(o=r(this.node,a),this.customEventListeners[this.customEventListeners.length]=o):void 0!==this.node["on"+t]?(this.eventListeners[this.eventListeners.length]={n:t,h:a},this.node.addEventListener(t,a)):console&&console.warn&&console.warn("Invalid event handler ("+t+")")},teardown:function(){var t;for(this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node),this.children&&this.children.teardown();this.attributes.length;)this.attributes.pop().teardown();for(;this.eventListeners.length;)t=this.eventListeners.pop(),this.node.removeEventListener(t.n,t.h);for(;this.customEventListeners.length;)this.customEventListeners.pop().teardown()},firstNode:function(){return this.node},bubble:function(){}},a=function(t){var e,n,r,o,s,a,h,d;if(e=t.name,n=t.value,this.element=t.element,r=e.indexOf(":"),-1!==r&&(o=e.substr(0,r),"xmlns"!==o&&(e=e.substring(r+1),this.namespace=A[o],!this.namespace)))throw'Unknown namespace ("'+o+'")';return null===n||"string"==typeof n?(this.namespace?t.parentNode.setAttributeNS(this.namespace,e,n):t.parentNode.setAttribute(e,n),"id"===e.toLowerCase()&&(t.root.nodes[n]=t.parentNode),void 0):(this.root=t.root,this.parentNode=t.parentNode,this.name=e,this.lcName=e.toLowerCase(),this.children=[],this.namespace||t.parentNode.namespaceURI!==A.html||(h=this.lcName,d=i[h]||h,void 0!==t.parentNode[d]&&(this.propertyName=d),("boolean"==typeof t.parentNode[d]||"value"===d)&&(this.useProperty=!0)),this.parentFragment=this.element.parentFragment,this.fragment=new f({descriptor:n,root:this.root,owner:this,contextStack:t.contextStack}),1===this.fragment.items.length&&(this.selfUpdating=!0),this.root.twoway&&(s=this.element.descriptor.e.toLowerCase(),a=!("name"!==d&&"value"!==d&&"checked"!==d||"input"!==s&&"textarea"!==s&&"select"!==s)),a&&(this.isBindable=!0,"name"===d&&(this.isTwowayNameAttr=!0)),this.ready=!0,this.isTwowayNameAttr||this.update(),void 0)},a.prototype={bind:function(t){var e,n,i,r,o,s=this,a=this.parentNode;if(!this.fragment)return!1;if(1!==this.fragment.items.length||this.fragment.items[0].type!==O)throw"Not a valid two-way data binding candidate - must be a single interpolator";if(this.interpolator=this.fragment.items[0],e=this.interpolator.keypath||this.interpolator.descriptor.r,"SELECT"===a.tagName&&"value"===this.propertyName)for(n=a.getElementsByTagName("option"),o=n.length,r=0;o>r;r+=1)if(i=n[r],i.hasAttribute("selected")){this.root.set(e,i.value);break}"checkbox"===a.type||"radio"===a.type?"name"===this.propertyName?(a.name="{{"+e+"}}",this.updateViewModel=function(){a.checked&&s.root.set(e,a.value)}):"checked"===this.propertyName&&(this.updateViewModel=function(){s.root.set(e,a.checked)}):this.updateViewModel=function(){var t;t=a.value,"0"===t?t=0:""!==t&&(t=+t||t),s.root.set(e,t)},this.updateViewModel&&(this.twoway=!0,a.addEventListener("change",this.updateViewModel),a.addEventListener("click",this.updateViewModel),a.addEventListener("blur",this.updateViewModel),t||(a.addEventListener("keyup",this.updateViewModel),a.addEventListener("keydown",this.updateViewModel),a.addEventListener("keypress",this.updateViewModel),a.addEventListener("input",this.updateViewModel)))},teardown:function(){if(this.updateViewModel&&(this.parentNode.removeEventListener("change",this.updateViewModel),this.parentNode.removeEventListener("click",this.updateViewModel),this.parentNode.removeEventListener("blur",this.updateViewModel),this.parentNode.removeEventListener("keyup",this.updateViewModel),this.parentNode.removeEventListener("keydown",this.updateViewModel),this.parentNode.removeEventListener("keypress",this.updateViewModel),this.parentNode.removeEventListener("input",this.updateViewModel)),this.children)for(;this.children.length;)this.children.pop().teardown()},bubble:function(){this.selfUpdating?this.update():this.deferred||(this.root._def[this.root._def.length]=this,this.deferred=!0)},update:function(){var t,e;if(!this.ready)return this;if("id"===this.lcName&&(void 0!==this.id&&delete this.root.nodes[this.id],this.root.nodes[this.id]=this.parentNode),this.twoway){if(e=this.lcName,this.value=this.interpolator.value,"name"===e&&("checkbox"===this.parentNode.type||"radio"===this.parentNode.type))return this.parentNode.checked=this.value===this.parentNode.value?!0:!1,this;if(n.activeElement===this.parentNode)return this}return t=this.fragment.getValue(),void 0===t&&(t=""),this.useProperty?(this.parentNode[this.propertyName]=t,this):this.namespace?(this.parentNode.setAttributeNS(this.namespace,this.name,t),this):(this.parentNode.setAttribute(this.name,t),this)}},h=function(t,e){this.node=n.createTextNode(""),e.appendChild(this.node),m(this,t),this.cond&&!this.keypath&&this.update(!1)},h.prototype={update:v,resolve:w,evaluate:y,teardown:function(){C(this),this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},render:function(t){this.node.data=t},firstNode:function(){return this.node}},d=function(t,e){this.nodes=[],this.docFrag=n.createDocumentFragment(),this.initialising=!0,m(this,t),e.appendChild(this.docFrag),this.initialising=!1},d.prototype={update:v,resolve:w,evaluate:y,teardown:function(){if(this.root.el.contains(this.parentNode))for(;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());C(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},render:function(e){for(;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());this.nodes=t(e,this.docFrag),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}},p=function(t,e){this.fragments=[],this.length=0,this.docFrag=n.createDocumentFragment(),this.initialising=!0,m(this,t),e.appendChild(this.docFrag),this.initialising=!1},p.prototype={update:v,resolve:w,evaluate:y,teardown:function(){this.unrender(),C(this)},firstNode:function(){return this.fragments[0]?this.fragments[0].firstNode():this.parentFragment.findNextNode(this)},findNextNode:function(t){return this.fragments[t.index+1]?this.fragments[t.index+1].firstNode():this.parentFragment.findNextNode(this)},unrender:function(){for(;this.fragments.length;)this.fragments.shift().teardown()},render:function(t){x(this,t),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},createFragment:function(t){var e=new u(t);return this.docFrag.appendChild(e.docFrag),e}}}(),function(){var t,e,n,i;r=function r(t){b(this,t)},r.prototype={createItem:function(r){if("string"==typeof r.descriptor)return new t(r.descriptor);switch(r.descriptor.t){case O:return new e(r);case S:return new n(r);case R:return new i(r);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.value=this.getValue(),this.owner.bubble()},teardown:function(){var t,e;for(t=this.items.length,e=0;t>e;e+=1)this.items[e].teardown()},getValue:function(){var t;return 1===this.items.length&&(t=this.items[0].value,void 0!==t)?t:""+this},toString:function(){return this.items.join("")}},t=function(t){this.text=t},t.prototype={toString:function(){return this.text},teardown:function(){}},e=function(t){m(this,t),this.cond&&!this.keypath&&this.update(!1)},e.prototype={update:v,resolve:w,evaluate:y,render:function(t){this.value=t,this.parentFragment.bubble()},teardown:function(){C(this)},toString:function(){return void 0===this.value?"":this.value}},n=e,i=function(t){this.fragments=[],this.length=0,m(this,t)},i.prototype={update:v,resolve:w,evaluate:y,teardown:function(){this.unrender(),C(this)},unrender:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parentFragment.bubble()},render:function(t){x(this,t),this.parentFragment.bubble()},createFragment:function(t){return new r(t)},toString:function(){return this.fragments.join("")}}}(),s=function(t){var e,n,i,r,o;if(L[t])return L[t].concat();for(i=[],r=t,n=0;r.length;){if(e=r.indexOf(".",n),-1===e)o=r,r="";else{if("\\"===r.charAt(e-1)&&"\\"!==r.charAt(e-2)){n=e+1;continue}o=r.substr(0,e),n=0}/\[/.test(o)?i=i.concat(o.replace(/\[\s*([0-9]+)\s*\]/g,".$1").split(".")):i[i.length]=o,r=r.substring(e+1)}return L[t]=i,i.concat()},a=function(t){return"[object Array]"===Object.prototype.toString.call(t)},p=function(t,e){return null===t&&null===e?!0:"object"==typeof t||"object"==typeof e?!1:t===e},d=function(t){return!isNaN(parseFloat(t))&&isFinite(t)},h=function(t){return"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t},c=function(t){var e,n;if("undefined"!=typeof window){if(n=window.document,!t)throw Error("No container element specified");if(t.tagName)return t;if("string"==typeof t&&(e=n.getElementById(t),!e&&n.querySelector&&(e=n.querySelector(t)),e.tagName))return e;if(t[0]&&t[0].tagName)return t[0];throw Error("Could not find container element")}},e.prototype=F,e.adaptors=E,e.eventDefinitions=M,e.easing=n,e.extend=i,e.interpolate=r,e.interpolators=o,e.parse=parse,"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):t.Ractive=e})(this);