UNPKG

ractive

Version:

Next-generation DOM manipulation

2 lines 32.8 kB
(function(t){Date.now||(Date.now=function(){return+new Date}),t.createElementNS||(t.createElementNS=function(e,n){if(null!==e&&"http://www.w3.org/1999/xhtml"!==e)throw"This browser does not support namespaces other than http://www.w3.org/1999/xhtml";return t.createElement(n)}),Element.prototype.contains||(Element.prototype.contains=function(t){for(;t.parentNode;){if(t.parentNode===this)return!0;t=t.parentNode}return!1}),String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")}),window.addEventListener||function(t,e,n,i,r,o,s){t[i]=e[i]=n[i]=function(t,e){var n=this;s.unshift([n,t,e,function(t){t.currentTarget=n,t.preventDefault=function(){t.returnValue=!1},t.stopPropagation=function(){t.cancelBubble=!0},t.target=t.srcElement||n,e.call(n,t)}]),this.attachEvent("on"+t,s[0][3])},t[r]=e[r]=n[r]=function(t,e){var n,i;for(n=0,i;i=s[n];++n)if(i[0]===this&&i[1]===t&&i[2]===e)return this.detachEvent("on"+t,s.splice(n,1)[0][3])},t[o]=e[o]=n[o]=function(t){return this.fireEvent("on"+t.type,t)}}(Window.prototype,HTMLDocument.prototype,Element.prototype,"addEventListener","removeEventListener","dispatchEvent",[]),Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){var n;for(void 0===e&&(e=0),0>e&&(e+=this.length),0>e&&(e=0),n=this.length;n>e;e++)if(this.hasOwnProperty(e)&&this[e]===t)return e;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(t,e){var n,i;for(n=0,i=this.length;i>n;n+=1)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)}),Array.prototype.map||(Array.prototype.map=function(t,e){var n,i,r=[];for(n=0,i=this.length;i>n;n+=1)this.hasOwnProperty(n)&&(r[n]=t.call(e,this[n],n,this));return r}),Array.prototype.map||(Array.prototype.map=function(t,e){var n,i,r=[];for(n=0,i=this.length;i>n;n+=1)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)&&(r[r.length]=this[n]);return r})})(document),function(t){"use strict";var e,n,i,r,o,s,a,h,p,u,d,c,l,f,g,m,v,w,y,b,x,N,_,k,E={},F={},O={},L={},M="Missing Ractive.parse - cannot parse template. Either preparse or use the version that includes the parser",A=1,S=2,P=3,R=4,C=7,T=8,j={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/"};E.animate=function(t,n,i){var r,o,a,h,p;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,p=s(t),a=new g({keys:p,from:this.get(p),to:n,root:this,duration:o,easing:r,step:i.step,complete:i.complete}),N.push(a)},E.bind=function(t){var e=this._bound;-1===e.indexOf(t)&&(e[e.length]=t,t.init(this))},E.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)},E.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&&("("===n.charAt(0)||!a(h)||h.ractive&&h._ractive.setting||_(h,n,this)),this._cache[n]=h,h):void 0)};var V,I,q,D,U,B;V=function(t){if(t.keypath)D(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()},I=function(t,e){var n,i,r=t._depsMap[e];if(t.modifyArrays&&"("!==e.charAt(0)&&(n=t._cache[e],a(n)&&!n._ractive.setting&&k(n,e,t)),delete t._cache[e],r)for(i=r.length;i--;)I(t,r[i])},q=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)},D=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][i]=null),o=t._deps[e].length;o--;)if(t._deps[e][o]){s=!0;break}s||(t._deps[e]=null)},U=function(t,e,n){var i,r,o,s,a,h;if(i=t._deps[e])for(a=i.length,o=0;a>o;o+=1)if(r=i[o])for(s=r.length;s--;)r[s].update();if(!n&&(h=t._depsMap[e]))for(o=h.length;o--;)U(t,h[o])},B=function(t,e,n){var i,r,o,a,h,p;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)){p=o+"."+e;break}return p||void 0===t.get(e)||(p=e),p},E.link=function(t){var e=this;return function(n){e.set(t,n)}},function(t){var e;t.observe=function(t,n,i){var r,o=[];if("object"==typeof t){i=n;for(r in t)t.hasOwnProperty(r)&&(n=t[r],o[o.length]=e(this,r,n,i));return{cancel:function(){for(;o.length;)o.pop().cancel()}}}return e(this,t,n,i)},e=function(t,e,n,i){var r,o,s;return i=i||{},s=i.context||t,r={update:function(){var i;i=t.get(e,!0),u(i,o)||(n.call(s,i,o),o=i)},cancel:function(){D(t,e,r,0)}},i.init!==!1&&r.update(),q(t,e,r,0),r}}(E),E.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))},E.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)}}},E.render=function(t){var e=t.el?d(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 c({descriptor:this.template,root:this,owner:this,parentNode:e}),e.appendChild(this.rendered.docFrag)},function(t){var e,n;t.set=function(t,i){var r,o,a,p,u;if(this.setting||(this.setting=!0,this.fire("set",t,i),this.setting=!1),o=[],r=[],h(t))for(a in t)t.hasOwnProperty(a)&&(u=s(a),p=u.join("."),i=t[a],e(this,p,u,i,r,o));else u=s(t),p=u.join("."),e(this,p,u,i,r,o);if(r.length){for(;r.length;)U(this,r.pop());n(this)}for(;o.length;)U(this,o.pop(),!0);for(;this._def.length;)this._def.pop().update().deferred=!1},e=function(t,e,n,i,r,o){var s,a,h,p;if(p=n.slice(),s=t.get(e),s!==i){for(h=t.data;n.length>1;)a=n.shift(),h[a]||(h[a]=/^\s*[0-9]+\s*$/.test(n[0])?[]:{}),h=h[a];a=n[0],h[a]=i}else if("object"!=typeof i)return;for(I(t,e),r[r.length]=e;p.length;)p.pop(),e=p.join("."),-1===o.indexOf(e)&&(o[o.length]=e)},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}}(E),E.teardown=function(){var t;this.rendered.teardown();for(t in this._depsMap)this._depsMap.hasOwnProperty(t)&&I(this,t);for(t in this._cache)this._cache.hasOwnProperty(t)&&I(this,t);for(;this._bound.length;)this.unbind(this._bound.pop())},E.unbind=function(t){var e,n=this._bound;e=n.indexOf(t),-1!==e&&(n.splice(e,1),t.teardown(this))},E.update=function(t){return I(this,t||""),U(this,t||""),this.fire("update:"+t),this.fire("update",t),this},F.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(p){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,p.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,p.set(t.changed),i=!1)},r=function(e,r){i||(n=!0,t.set(e,r),n=!1)}),t.on("change",o),p.on("set",r),p.set(e?h(t.attributes):t.attributes)},teardown:function(e){t.off("change",o),e.off("set",r)}}},F.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)}},O.tap=function(t,e){var n,i,r,o;return r=5,o=400,n=function(t){var n,i,s,a,h,p;n=t.clientX,i=t.clientY,s=this,a=function(t){e.call(s,t),p()},h=function(t){(Math.abs(t.clientX-n)>=r||Math.abs(t.clientY-i)>=r)&&p()},p=function(){window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",a)},window.addEventListener("mousemove",h),window.addEventListener("mouseup",a),setTimeout(p,o)},t.addEventListener("mousedown",n),i=function(t){var n,i,s,a,h,p,u;1===t.touches.length&&(s=t.touches[0],n=s.clientX,i=s.clientY,a=s.identifier,p=function(t){var n;n=t.changedTouches[0],n.identifier!==a&&u(),e.call(n.target,t)},h=function(t){var e;(1!==t.touches.length||t.touches[0].identifier!==a)&&u(),e=t.touches[0],(Math.abs(e.clientX-n)>=r||Math.abs(e.clientY-i)>=r)&&u()},u=function(){window.removeEventListener("touchmove",h),window.removeEventListener("touchend",p),window.removeEventListener("touchcancel",u)},window.addEventListener("touchmove",h),window.addEventListener("touchend",p),window.addEventListener("touchcancel",u),setTimeout(u,o))},{teardown:function(){t.removeEventListener("mousedown",n),t.removeEventListener("touchstart",i)}}};var z=function(t,e){var n;for(n in e)e.hasOwnProperty(n)&&!t.hasOwnProperty(n)&&(t[n]=e[n])};i=function(t){var n,i,r,o,s,a,h,p;if(n=this,o=["el","preserveWhitespace","append","twoway","modifyArrays"],s=o.concat("data","template"),t.template)if("string"==typeof t.template){if(!e.parse)throw Error(M);a=e.parse(t.template)}else a=t.template;if(t.partials){h={};for(r in t.partials)if(t.partials.hasOwnProperty(r)){if("string"==typeof t.partials[r]){if(!e.parse)throw Error(M);p=e.parse(t.partials[r],t)}else p=t.partials[r];h[r]=p}}i=function(n){var i,r;for(!n.template&&a&&(n.template=a),n.data||(n.data={}),z(n.data,t.data),h&&(n.partials||(n.partials={}),z(n.partials,h)),i=o.length;i--;)r=o[i],!n.hasOwnProperty(r)&&t.hasOwnProperty(r)&&(n[r]=t[r]);e.call(this,n),this.init&&this.init.call(this,n)};for(r in n.prototype)n.prototype.hasOwnProperty(r)&&(i.prototype[r]=n.prototype[r]);for(r in t)if(t.hasOwnProperty(r)&&-1===s.indexOf(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 p(t)&&p(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}}};var Y={preserveWhitespace:!1,append:!1,twoway:!0,modifyArrays:!0,data:{}};e=function(t){var n,i,r,o,s;for(n in Y)Y.hasOwnProperty(n)&&!t.hasOwnProperty(n)&&(t[n]=Y[n]);if(this.el=d(t.el),this.data=t.data||{},this._subs={},this._cache={},this._deps={},this._depsMap={},this.nodes={},this._pendingResolution=[],this._def=[],this._proxies={},this._expressions=[],this._bound=[],t.bindings)if(a(t.bindings))for(r=0;t.bindings.length>r;r+=1)this.bind(t.bindings[r]);else this.bind(t.bindings);if(t.partials){this.partials={};for(n in t.partials)if(t.partials.hasOwnProperty(n)){if(i=t.partials[n],"string"==typeof i){if(!e.parse)throw Error(M);i=e.parse(i,t)}1===i.length&&"string"==typeof i[0]&&(i=i[0]),this.partials[n]=i}}if(o=t.template,"string"==typeof o){if(!e.parse)throw Error(M);if("#"===o.charAt(0)){if(s=document.getElementById(o.substring(1)),!s)throw Error("Could not find template element ("+o+")");this.template=e.parse(s.innerHTML,t)}else o=e.parse(o,t)}this.template=o&&1===o.length&&"string"==typeof o[0]?o[0]:o,this.el&&this.render({el:this.el,append:t.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},f=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.resolvers=[],this.unresolved=this.numRefs=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()},f.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]})+")",-1===this.root._expressions.indexOf(this.keypath)?(t=this.str.replace(/❖([0-9]+)/g,function(t,e){return"_"+e}),this.fn=i(t,this.numRefs||0),this.update(),this.root._expressions.push(this.keypath)):this.teardown(),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.resolved&&(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 u(t,this._lastValue)||(I(this.root,this.keypath),this.root._cache[this.keypath]=t,U(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.priority=r.priority,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(){V(this)},resolve:function(t){this.keypath=t,q(this.root,t,this,this.priority),this.update(),this.evaluator.resolve(this.ref,this.argNum,t)},update:function(){var t=this.root.get(this.keypath);u(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 f(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()),u(t,this._lastValue)||(this.render(t),this._lastValue=t)},w=function(t){this.keypath=t,q(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,p,u;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},c=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)},c.prototype={createItem:function(t){if("string"==typeof t.descriptor)return new r(t,this.docFrag);switch(t.descriptor.t){case S:return new h(t,this.docFrag);case R:return new u(t,this.docFrag);case P:return new p(t,this.docFrag);case C:return new o(t,this.docFrag);case T: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 c({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,p,u,d;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===j.html?this.node.innerHTML=i.f:(this.fragment=new c({descriptor:i.f,root:t.root,parentNode:this.node,contextStack:t.contextStack,owner:this}),this.node.appendChild(this.fragment.docFrag))),i.v)for(o in i.v)i.v.hasOwnProperty(o)&&this.addEventProxy(o,i.v[o],t.contextStack);this.attributes=[],u=[];for(h in i.a)i.a.hasOwnProperty(h)&&(p=i.a[h],s=new a({element:this,name:h,value:void 0===p?null:p,root:t.root,parentNode:this.node,contextStack:t.contextStack}),this.attributes[this.attributes.length]=s,s.isBindable&&u.push(s),s.isTwowayNameAttr?d=s:s.update());for(;u.length;)u.pop().bind(this.root.lazy);d&&(d.updateViewModel(),d.update()),e.appendChild(this.node)},o.prototype={addEventProxy:function(t,n,i){var r,o,s,a,h=this,p=this.root;"string"==typeof n?(p._proxies[n]||(p._proxies[n]=function(t){p.fire(n,t,this)}),a=p._proxies[n]):(s=new l({descriptor:n,root:this.root,owner:this,contextStack:i}),a=function(t){p.fire(""+s,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.fragment&&this.fragment.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,p,u,d,c;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=j[o],!this.namespace)))throw'Unknown namespace ("'+o+'")';if(null===n||"string"==typeof n)return 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;for(this.root=t.root,this.parentNode=t.parentNode,this.name=e,this.lcName=e.toLowerCase(),this.namespace||t.parentNode.namespaceURI!==j.html||(h=this.lcName,p=i[h]||h,void 0!==t.parentNode[p]&&(this.propertyName=p),("boolean"==typeof t.parentNode[p]||"value"===p)&&(this.useProperty=!0)),this.parentFragment=this.element.parentFragment,this.fragment=new l({descriptor:n,root:this.root,owner:this,contextStack:t.contextStack}),this.selfUpdating=!0,u=this.fragment.items.length;u--;)if(d=this.fragment.items[u],d.type!==A){if(d.type!==S){this.selfUpdating=!1;break}if(c){this.selfUpdating=!1;break}c=!0}this.root.twoway&&(s=this.element.descriptor.e.toLowerCase(),a=!("name"!==p&&"value"!==p&&"checked"!==p||"input"!==s&&"textarea"!==s&&"select"!==s)),a&&(this.isBindable=!0,"name"===p&&(this.isTwowayNameAttr=!0)),this.ready=!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!==S)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(){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.fragment&&this.fragment.teardown()},bubble:function(){this.selfUpdating?this.update():!this.deferred&&this.ready&&(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}if(t=""+this.fragment,void 0===t&&(t=""),t!==this.value){if(this.useProperty)return this.parentNode[this.propertyName]=t,this;if(this.namespace)return this.parentNode.setAttributeNS(this.namespace,this.name,t),this;this.parentNode.setAttribute(this.name,t),this.value=t}return 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(){V(this),this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},render:function(t){this.node.data=t},firstNode:function(){return this.node}},p=function(t,e){this.nodes=[],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(){if(this.root.el.contains(this.parentNode))for(;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());V(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))}},u=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},u.prototype={update:v,resolve:w,evaluate:y,teardown:function(){this.unrender(),V(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 c(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 S:return new e(r);case P:return new n(r);case R:return new i(r);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.owner.bubble()},teardown:function(){var t,e;for(t=this.items.length,e=0;t>e;e+=1)this.items[e].teardown()},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(){V(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(),V(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)},u=function(t,e){return null===t&&null===e?!0:"object"==typeof t||"object"==typeof e?!1:t===e },p=function(t){return!isNaN(parseFloat(t))&&isFinite(t)},h=function(t){return"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t},d=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=E,e.adaptors=F,e.eventDefinitions=O,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);