UNPKG

ractive

Version:

Next-generation DOM manipulation

1 lines 24.9 kB
(function(t){"use strict";var e;(function(){var t;return e=function(i){var n,r;if(i)for(r in i)i.hasOwnProperty(r)&&(this[r]=i[r]);n={preserveWhitespace:!1,append:!1,twoway:!0,formatters:{},modifyArrays:!0};for(r in n)n.hasOwnProperty(r)&&void 0===this[r]&&(this[r]=n[r]);if(void 0!==this.el&&(this.el=t(this.el)),this._subs={},this._cache={},this._cacheMap={},this.observers={},this.pendingResolution=[],this.deferredAttributes=[],this.data&&this.set(this.data),this.partials)for(r in this.partials)if(this.partials.hasOwnProperty(r)&&"string"==typeof this.partials[r]){if(!e.compile)throw Error('Missing Ractive.compile - cannot compile partial "'+r+'". Either precompile or use the version that includes the compiler');this.partials[r]=e.compile(this.partials[r],this)}if("string"==typeof this.template){if(!e.compile)throw Error("Missing Ractive.compile - cannot compile template. Either precompile or use the version that includes the compiler");this.template=e.compile(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,callback:this.callback,append:this.append})},e.prototype={render:function(e){var n=e.el?t(e.el):this.el;if(!n)throw Error("You must specify a DOM element to render to");e.append||(n.innerHTML=""),e.callback&&(this.callback=e.callback),this.rendered=new i.DomFragment({model:this.template,root:this,parentNode:n}),n.appendChild(this.rendered.docFrag)},teardown:function(){this.rendered.teardown()},set:function(t,e){for(i.isObject(t)?this._setMultiple(t):this._setSingle(t,e);this.deferredAttributes.length;)this.deferredAttributes.pop().update().updateDeferred=!1},_setSingle:function(t,e){var n,r,s,o,a,h,p;for(n=i.isArray(t)?t.slice():i.splitKeypath(t),o=n.join("."),this._clearCache(o),s=this.data;n.length>1;)r=n.shift(),s[r]||(s[r]=/^[0-9]+$/.test(n[0])?[]:{}),s=s[r];for(r=n[0],s[r]=e,this.setting||(this.setting=!0,this.fire("set",o,e),this.fire("set:"+o,e),this.setting=!1),this._notifyObservers(o,e),a=this.pendingResolution.length;a--;)p=this.pendingResolution.splice(a,1)[0],h=this.resolveRef(p.view.model.ref,p.view.contextStack),h?p.callback(h.keypath,h.value):this.registerUnresolvedKeypath(p)},_setMultiple:function(t){var e;for(e in t)t.hasOwnProperty(e)&&this._setSingle(e,t[e])},_clearCache:function(t){var e=this._cacheMap[t];if(delete this._cache[t],e)for(;e.length;)this._clearCache(e.pop())},get:function(t){var e,n,r,s,o,a,h,p;if(i.isArray(t))e=t.slice(),n=e.join(".");else{if(t in this._cache)return this._cache[t];e=i.splitKeypath(t),n=e.join(".")}if(n in this._cache)return this._cache[n];if(e.length>1?(r=e.pop(),a=this.get(e)):(r=e.pop(),a=this.data),s=/^⭆(.+)⭅$/.exec(r))p=i.getFormattersFromString(s[1]),h=this._format(a,p);else{if("object"!=typeof a)return;h=a[r]}return e.length&&(o=e.join("."),this._cacheMap[o]||(this._cacheMap[o]=[]),this._cacheMap[o].push(n)),"function"==typeof h&&(h=h()),this._cache[n]=h,h},update:function(){throw Error("not implemented yet!")},link:function(t){var e=this;return function(i){e.set(t,i)}},registerView:function(t){var e,n,r,s,o=this;return t.parentFragment&&t.parentFragment.indexRefs.hasOwnProperty(t.model.ref)?(s=t.parentFragment.indexRefs[t.model.ref],r=t.model.fmtrs?this._format(s,t.model.fmtrs):s,t.update(r),void 0):(n=function(e){t.keypath=t.model.fmtrs?e+"."+i.stringifyFormatters(t.model.fmtrs):e,t.observerRefs=o.observe(t.model.p||0,t),t.update(o.get(t.keypath))},e=this.resolveRef(t.model.ref,t.contextStack),e?n(e.keypath,e.value):(t.model.fmtrs&&t.update(this._format(void 0,t.model.fmtrs)),this.registerUnresolvedKeypath({view:t,callback:n})),void 0)},resolveRef:function(t,e){var i,n,r;if("."===t)return n=e[e.length-1],r=this.get(n),{keypath:n,value:r};for(e=e.concat();e.length;)if(i=e.pop(),n=i+"."+t,r=this.get(n),void 0!==r)return{keypath:n,value:r};return r=this.get(t),void 0!==r?{keypath:t,value:r}:void 0},registerUnresolvedKeypath:function(t){this.pendingResolution[this.pendingResolution.length]=t},_format:function(t,i){var n,r,s,o,a,h;if(!i)return t;for(r=i.length,n=0;r>n;n+=1)s=i[n],o=s.name,a=s.args||[],h=this.formatters[o]||e.formatters[o],h&&(t=h.apply(this,[t].concat(a)));return t},_notifyObservers:function(t){var e,i,n,r,s=this,o=this.observers[t]||[];for(e=0;o.length>e;e+=1)if(n=o[e])for(i=0;n.length>i;i+=1)r=n[i],r.update(s.get(r.keypath))},observe:function(t,e){var n,r,s=this,o=e.keypath,a=[];if(!o)return void 0;for(n=function(i){var n;n=s.observers[i]=s.observers[i]||[],n=n[t]=n[t]||[],n[n.length]=e,a[a.length]={keypath:i,priority:t,view:e}},r=i.splitKeypath(e.keypath);r.length>1;)n(r.join(".")),r.pop();return n(r[0]),a},unobserve:function(t){var e,i,n,r,s;if(e=this.observers[t.keypath],e&&(i=e[t.priority])){if(i.indexOf)n=i.indexOf(t.observer);else for(r=0,s=i.length;s>r;r+=1)if(i[r]===t.view){n=r;break}-1!==n&&(i.splice(n,1),0===i.length&&delete e[t.priority],0===e.length&&delete this.observers[t.keypath])}},unobserveAll:function(t){for(;t.length;)this.unobserve(t.shift())}},t=function(t){var e,i;if("undefined"!=typeof window){if(i=window.document,!t)throw Error("No container element specified");if(t.tagName)return t;if("string"==typeof t&&(e=i.getElementById(t),!e&&i.querySelector&&(e=i.querySelector(t)),e.tagName))return e;if(t[0]&&t[0].tagName)return t[0];throw Error("Could not find container element")}},e})();var i;(function(){var t={};i={isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},isObject:function(t){return"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t},isNumeric:function(t){return!isNaN(parseFloat(t))&&isFinite(t)},splitKeypath:function(t){var e,i,n,r,s,o,a,h,p,d;if(!(e=/\\\./.test(t))&&!(i=/⭆.+⭅/.test(t)))return t.replace(/\[\s*([0-9]+)\s*\]/g,".$1").split(".");for(h=[],p=t,i&&(n=[],p=p.replace(/⭆(.+)⭅/g,function(t,e){return n[n.length]=e,"⭆x⭅"})),a=0;p.length;){if(o=p.indexOf(".",a),-1===o)d=p,p="";else{if("\\"===p.charAt(o-1)&&"\\"!==p.charAt(o-2)){a=o+1;continue}d=p.substr(0,o),a=0}/\[/.test(d)?h=h.concat(d.replace(/\[\s*([0-9]+)\s*\]/g,".$1").split(".")):h[h.length]=d,p=p.substring(o+1)}if(i)for(s=function(){return"⭆"+n.pop()+"⭅"},r=h.length;r--;)"⭆x⭅"===h[r]&&(h[r]="⭆"+n.pop()+"⭅");return h},getFormattersFromString:function(e){var i,n;return t[e]?t[e]:(n=e.split("⤋"),i=n.map(function(t){var e;return e=t.indexOf("["),-1===e?{name:t,args:[]}:{name:t.substr(0,e),args:JSON.parse(t.substring(e))}}),t[e]=i,i)},stringifyFormatters:function(t){var e=t.map(function(t){return t.args&&t.args.length?t.name+JSON.stringify(t.args):t.name});return"⭆"+e.join("⤋")+"⭅"}}})(),i.types={TEXT:1,INTERPOLATOR:2,TRIPLE:3,SECTION:4,INVERTED:5,CLOSING:6,ELEMENT:7,PARTIAL:8,COMMENT:9,DELIMCHANGE:10,MUSTACHE:11,TAG:12,ATTR_VALUE_TOKEN:13},function(t){t._Mustache=function(t){this.root=t.root,this.model=t.model,this.parent=t.parent,this.parentFragment=t.parentFragment,this.contextStack=t.contextStack||[],this.index=t.index||0,(t.parentNode||t.anchor)&&(this.parentNode=t.parentNode,this.anchor=t.anchor),this.type=t.model.type,this.root.registerView(this),!this.keypath&&this.model.inv&&this.update(!1)},t._Fragment=function(t){var e,i,n,r,s;if(this.parent=t.parent,this.index=t.index,this.items=[],this.indexRefs={},this.parent&&this.parent.parentFragment){r=this.parent.parentFragment.indexRefs;for(s in r)r.hasOwnProperty(s)&&(this.indexRefs[s]=r[s])}for(t.indexRef&&(this.indexRefs[t.indexRef]=t.index),n={root:t.root,parentFragment:this,parent:this,parentNode:t.parentNode,contextStack:t.contextStack},e=t.model?t.model.length:0,i=0;e>i;i+=1)n.model=t.model[i],n.index=i,this.items[this.items.length]=this.createItem(n)},t._sectionUpdate=function(e){var i,n,r,s,o;if(i={model:this.model.frag,root:this.root,parentNode:this.parentNode,parent:this},this.parentNode&&(i.anchor=this.parentFragment.findNextNode(this)),n=t.isArray(e),n&&this.root.modifyArrays&&t.modifyArray(e,this.keypath,this.root),n&&0===e.length&&(r=!0),this.model.inv){if(e&&!r)this.length&&(this.unrender(),this.length=0);else if(!this.length)return i.contextStack=this.contextStack,i.index=0,this.fragments[0]=this.createFragment(i),this.length=1,void 0;return this.postUpdate&&this.postUpdate(),void 0}if(n){if(e.length<this.length)for(o=this.fragments.splice(e.length,this.length-e.length);o.length;)o.pop().teardown();else if(e.length>this.length)for(s=this.length;e.length>s;s+=1)i.contextStack=this.contextStack.concat(this.keypath+"."+s),i.index=s,this.model.i&&(i.indexRef=this.model.i),this.fragments[s]=this.createFragment(i);this.length=e.length}else t.isObject(e)?this.length||(i.contextStack=this.contextStack.concat(this.keypath),i.index=0,this.fragments[0]=this.createFragment(i),this.length=1):e&&!r?this.length||(i.contextStack=this.contextStack,i.index=0,this.fragments[0]=this.createFragment(i),this.length=1):this.length&&(this.unrender(),this.length=0);this.postUpdate&&this.postUpdate()}}(i),function(t){t.on=function(t,e){var i=this;return this._subs[t]?this._subs[t].push(e):this._subs[t]=[e],{cancel:function(){i.off(t,e)}}},t.off=function(t,e){var i,n;e||(t?this._subs[t]=[]:this._subs={}),i=this._subs[t],i&&(n=i.indexOf(e),-1!==n&&i.splice(n,1))},t.fire=function(t){var e,i,n,r=this._subs[t];if(r)for(e=Array.prototype.slice.call(arguments,1),i=0,n=r.length;n>i;i+=1)r[i].apply(this,e)}}(e.prototype),function(t){t.formatters={equals:function(t,e){return t===e},greaterThan:function(t,e){return t>e},greaterThanEquals:function(t,e){return t>=e},lessThan:function(t,e){return e>t},lessThanEquals:function(t,e){return e>=t}}}(e),function(t,e){var i,n,r,s,o,a,h,p,d,c,l;i=e.types,s={"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"},r="undefined"!=typeof window?window.document:null,n=function(t,e){var i,n=[];for(i=r.createElement("div"),i.innerHTML=t;i.firstChild;)n[n.length]=i.firstChild,e.appendChild(i.firstChild);return n},e.DomFragment=function(t){return this.docFrag=r.createDocumentFragment(),"string"==typeof t.model?(this.nodes=n(t.model,this.docFrag),void 0):(e._Fragment.call(this,t),void 0)},e.DomFragment.prototype={createItem:function(t){if("string"==typeof t.model)return new o(t,this.docFrag);switch(t.model.type){case i.INTERPOLATOR:return new d(t,this.docFrag);case i.SECTION:return new l(t,this.docFrag);case i.TRIPLE:return new c(t,this.docFrag);case i.ELEMENT:return new a(t,this.docFrag);case i.PARTIAL:return new h(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}},h=function(t,i){this.fragment=new e.DomFragment({model:t.root.partials[t.model.ref]||[],root:t.root,parentNode:t.parentNode,contextStack:t.contextStack,parent:this}),i.appendChild(this.fragment.docFrag)},h.prototype={teardown:function(){this.fragment.teardown()}},o=function(t,e){this.node=r.createTextNode(t.model),this.root=t.root,this.parentNode=t.parentNode,e.appendChild(this.node)},o.prototype={teardown:function(){this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},firstNode:function(){return this.node}},a=function(t,i){var n,s,o,a,h,d,c;if(n=this.model=t.model,this.root=t.root,this.parentFragment=t.parentFragment,this.parentNode=t.parentNode,this.index=t.index,n.attrs&&n.attrs.xmlns){if(s=n.attrs.xmlns,"string"!=typeof s)throw"Namespace attribute cannot contain mustaches"}else s=this.parentNode.namespaceURI;this.node=r.createElementNS(s,n.tag),n.frag&&("string"==typeof n.frag?this.node.innerHTML=n.frag:(this.children=new e.DomFragment({model:n.frag,root:t.root,parentNode:this.node,contextStack:t.contextStack,parent:this}),this.node.appendChild(this.children.docFrag))),this.attributes=[],d=[];for(a in n.attrs)n.attrs.hasOwnProperty(a)&&(h=n.attrs[a],o=new p({parent:this,name:a,value:void 0===h?null:h,root:t.root,parentNode:this.node,contextStack:t.contextStack}),this.attributes[this.attributes.length]=o,o.isBindable&&d.push(o),o.isTwowayNameAttr?c=o:o.update());for(;d.length;)d.pop().bind(this.root.lazy);c&&(c.updateViewModel(),c.update()),i.appendChild(this.node)},a.prototype={teardown:function(){for(this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node),this.children&&this.children.teardown();this.attributes.length;)this.attributes.pop().teardown()},firstNode:function(){return this.node}},p=function(t){var i,n,r,o,a,h,p,d;if(i=t.name,n=t.value,this.parent=t.parent,r=i.indexOf(":"),-1!==r&&(o=i.substr(0,r),"xmlns"!==o&&(i=i.substring(r+1),this.namespace=e.namespaces[o],!this.namespace)))throw'Unknown namespace ("'+o+'")';return null===n||"string"==typeof n?(this.namespace?t.parentNode.setAttributeNS(this.namespace,i,n):t.parentNode.setAttribute(i,n),void 0):(this.root=t.root,this.parentNode=t.parentNode,this.name=i,this.children=[],this.namespace||t.parentNode.namespaceURI!==e.namespaces.html||(p=this.name.toLowerCase(),d=s[p]?s[p]:p,void 0!==t.parentNode[d]&&(this.propertyName=d),("boolean"==typeof t.parentNode[d]||"value"===d)&&(this.useProperty=!0)),this.parentFragment=this.parent.parentFragment,this.fragment=new e.TextFragment({model:n,root:this.root,parent:this,contextStack:t.contextStack}),1===this.fragment.items.length&&(this.selfUpdating=!0),this.root.twoway&&(a=this.parent.model.tag.toLowerCase(),h=!("name"!==d&&"value"!==d&&"checked"!==d||"input"!==a&&"textarea"!==a&&"select"!==a)),h&&(this.isBindable=!0,"name"===d&&(this.isTwowayNameAttr=!0)),this.ready=!0,this.isTwowayNameAttr||this.update(),void 0)},p.prototype={bind:function(t){var i,n,r=this,s=this.parentNode;if(!this.fragment)return!1;if(1!==this.fragment.items.length||this.fragment.items[0].type!==e.types.INTERPOLATOR)throw"Not a valid two-way data binding candidate - must be a single interpolator";this.interpolator=this.fragment.items[0],i=this.interpolator.keypath||this.interpolator.model.ref,-1!==(n=i.indexOf(".⭆"))&&(i=i.substr(0,n)),"checkbox"===s.type||"radio"===s.type?"name"===this.propertyName?(s.name="{{"+i+"}}",this.updateViewModel=function(){s.checked&&r.root.set(i,s.value)}):"checked"===this.propertyName&&(this.updateViewModel=function(){r.root.set(i,s.checked)}):this.updateViewModel=function(){var t;t=r.interpolator.model.fmtrs?r.root._format(s.value,r.interpolator.model.fmtrs):s.value,"0"===t?t=0:""!==t&&(t=+t||t),r.root.set(i,t)},this.updateViewModel&&(this.twoway=!0,s.addEventListener("change",this.updateViewModel),s.addEventListener("click",this.updateViewModel),s.addEventListener("blur",this.updateViewModel),t||(s.addEventListener("keyup",this.updateViewModel),s.addEventListener("keydown",this.updateViewModel),s.addEventListener("keypress",this.updateViewModel),s.addEventListener("input",this.updateViewModel)))},teardown:function(){if(this.updateViewModel&&(this.node.removeEventListener("change",this.updateViewModel),this.node.removeEventListener("click",this.updateViewModel),this.node.removeEventListener("blur",this.updateViewModel),this.node.removeEventListener("keyup",this.updateViewModel),this.node.removeEventListener("keydown",this.updateViewModel),this.node.removeEventListener("keypress",this.updateViewModel),this.node.removeEventListener("input",this.updateViewModel)),this.children)for(;this.children.length;)this.children.pop().teardown()},bubble:function(){this.selfUpdating?this.update():this.updateDeferred||(this.root.deferredAttributes[this.root.deferredAttributes.length]=this,this.updateDeferred=!0)},update:function(){var t,e;if(!this.ready)return this;if(this.twoway){if(e=this.name.toLowerCase(),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(r.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)}},d=function(t,i){this.node=r.createTextNode(""),i.appendChild(this.node),e._Mustache.call(this,t)},d.prototype={teardown:function(){this.observerRefs?this.root.unobserveAll(this.observerRefs):this.root.cancelKeypathResolution(this),this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},update:function(t){t!==this.text&&(this.text=t,this.node.data=t)},firstNode:function(){return this.node}},c=function(t,i){this.nodes=[],this.docFrag=r.createDocumentFragment(),this.initialising=!0,e._Mustache.call(this,t),i.appendChild(this.docFrag),this.initialising=!1},c.prototype={teardown:function(){if(this.root.el.contains(this.parentNode))for(;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());this.observerRefs?this.root.unobserveAll(this.observerRefs):this.root.cancelKeypathResolution(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},update:function(t){if(t!==this.html){for(this.html=t;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());this.nodes=n(t,this.docFrag),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}}},l=function(t,i){this.fragments=[],this.length=0,this.docFrag=r.createDocumentFragment(),this.initialising=!0,e._Mustache.call(this,t),i.appendChild(this.docFrag),this.initialising=!1},l.prototype={teardown:function(){this.unrender(),this.observerRefs?this.root.unobserveAll(this.observerRefs):this.root.cancelKeypathResolution(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()},update:function(t){e._sectionUpdate.call(this,t),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},createFragment:function(t){var i=new e.DomFragment(t);return this.docFrag.appendChild(i.docFrag),i}}}(e,i),function(t){var e,i,n,r,s;e=t.types,t.TextFragment=function(e){t._Fragment.call(this,e)},t.TextFragment.prototype={createItem:function(t){if("string"==typeof t.model)return new i(t.model);switch(t.model.type){case e.INTERPOLATOR:return new n(t);case e.TRIPLE:return new r(t);case e.SECTION:return new s(t);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.value=this.getValue(),this.parent.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("")}},i=function(t){this.text=t},i.prototype={toString:function(){return this.text},teardown:function(){}},n=function(e){t._Mustache.call(this,e)},n.prototype={update:function(t){this.value=t,this.parent.bubble()},teardown:function(){this.observerRefs?this.root.unobserveAll(this.observerRefs):this.root.cancelKeypathResolution(this)},toString:function(){return void 0===this.value?"":this.value}},r=n,s=function(e){this.fragments=[],this.length=0,t._Mustache.call(this,e)},s.prototype={teardown:function(){this.unrender(),this.observerRefs?this.root.unobserveAll(this.observerRefs):this.root.cancelKeypathResolution(this)},unrender:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parent.bubble()},update:function(e){t._sectionUpdate.call(this,e)},createFragment:function(e){return new t.TextFragment(e)},postUpdate:function(){this.value=this.fragments.join(""),this.parent.bubble()},toString:function(){return this.fragments.join("")}}}(i),function(t){t.extend=function(e){var i,n,r;i=this,n=function(){t.apply(this,arguments),this.init&&this.init.apply(this,arguments)};for(r in i.prototype)i.prototype.hasOwnProperty(r)&&(n.prototype[r]=i.prototype[r]);for(r in e)if(e.hasOwnProperty(r)){if(t.prototype.hasOwnProperty(r))throw Error('Cannot override "'+r+'" method or property of Ractive prototype');n.prototype[r]=e[r]}return n.extend=i.extend,n}}(e),function(t){var e;t.modifyArray=function(t,i,n){var r,s,o,a;t._ractive?(r=t._ractive.roots,s=t._ractive.keypathsByIndex,o=r.indexOf(n),-1===o&&(o=r.length,r[o]=n),a=s[o],-1===a.indexOf(i)&&(a[a.length]=i)):(t._ractive={roots:[n],keypathsByIndex:[[i]]},e(t))},e=function(t){var e=function(t){var e,i;e=t._ractive.roots,i=t._ractive.keypathsByIndex,e.forEach(function(e,n){var r=i[n];r.forEach(function(i){e.set(i,t)})})};["pop","push","reverse","shift","sort","splice","unshift"].forEach(function(i){t[i]=function(){var n=Array.prototype[i].apply(this,arguments);return e(t),n}})}}(i),function(t){t.easing={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)}}}(e),function(t,e){var i,n,r;r="undefined"!=typeof window?window:{},function(t,e){var i;for(i=0;t.length>i&&!r.requestAnimationFrame;++i)r.requestAnimationFrame=r[t[i]+"RequestAnimationFrame"],r.cancelAnimationFrame=r[t[i]+"CancelAnimationFrame"]||r[t[i]+"CancelRequestAnimationFrame"];r.requestAnimationFrame||(r.requestAnimationFrame=function(t){var i,n,s;return i=Date.now(),n=Math.max(0,16-(i-e)),s=r.setTimeout(function(){t(i+n)},n),e=i+n,s}),r.cancelAnimationFrame||(r.cancelAnimationFrame=function(t){r.clearTimeout(t)})}(["ms","moz","webkit","o"],0,r),n={animations:[],tick:function(){var t,e;for(t=0;this.animations.length>t;t+=1)e=this.animations[t],e.tick()||this.animations.splice(t--,1);this.animations.length?r.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())}},i=function(e){var i;this.startTime=Date.now();for(i in e)e.hasOwnProperty(i)&&(this[i]=e[i]);this.interpolator=t.interpolate(this.from,this.to),this.running=!0},i.prototype={tick:function(){var t,e,i,n;return this.running?(n=Date.now(),t=n-this.startTime,t>=this.duration?(this.root.set(this.keys,this.to),this.complete&&this.complete(1),this.running=!1,!1):(e=this.easing?this.easing(t/this.duration):t/this.duration,i=this.interpolator(e),this.root.set(this.keys,i),this.step&&this.step(e,i),!0)):!1},stop:function(){this.running=!1}},t.prototype.animate=function(r,s,o){var a,h,p,d,c;for(o=o||{},d=n.animations.length;d--;)n.animations[d].keypath===r&&n.animations[d].stop();o.easing&&(a="function"==typeof o.easing?o.easing:this.easing&&this.easing[o.easing]?this.easing[o.easing]:t.easing[o.easing],"function"!=typeof a&&(a=null)),h=void 0===o.duration?400:o.duration,c=e.splitKeypath(r),p=new i({keys:c,from:this.get(c),to:s,root:this,duration:h,easing:a,step:o.step,complete:o.complete}),n.push(p)}}(e,i),function(t,e){t.interpolate=function(i,n){if(e.isNumeric(i)&&e.isNumeric(n))return t.interpolators.number(+i,+n);if(e.isArray(i)&&e.isArray(n))return t.interpolators.array(i,n);if(e.isObject(i)&&e.isObject(n))return t.interpolators.object(i,n);throw Error("Could not interpolate values")},t.interpolators={number:function(t,e){var i=e-t;return i?function(e){return t+e*i}:function(){return t}},array:function(e,i){var n,r,s,o;for(n=[],r=[],o=s=Math.min(e.length,i.length);o--;)r[o]=t.interpolate(e[o],i[o]);for(o=s;e.length>o;o+=1)n[o]=e[o];for(o=s;i.length>o;o+=1)n[o]=i[o];return function(t){for(var e=s;e--;)n[e]=r[e](t);return n}},object:function(e,i){var n,r,s,o,a=[];s={},r={};for(o in e)e.hasOwnProperty(o)&&(i.hasOwnProperty(o)?(a[a.length]=o,r[o]=t.interpolate(e[o],i[o])):s[o]=e[o]);for(o in i)i.hasOwnProperty(o)&&!e.hasOwnProperty(o)&&(s[o]=i[o]);return n=a.length,function(t){for(var e,i=n;i--;)e=a[i],s[e]=r[e](t);return s}}}}(e,i),i.namespaces={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/"},"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):t.Ractive=e})(this);