UNPKG

ractive

Version:

Next-generation DOM manipulation

1 lines 28.6 kB
(function(t){"use strict";var e,i;(function(){var t;return e=function(i){var n,r,s;if(i)for(r in i)i.hasOwnProperty(r)&&(this[r]=i[r]);n={preserveWhitespace:!1,append:!1,twoway:!0,modifiers:{},modifyArrays:!0,data:{}};for(r in n)n.hasOwnProperty(r)&&void 0===this[r]&&(this[r]=n[r]);if(i&&i.formatters&&(this.modifiers=i.formatters,"undefined"!=typeof console&&console.warn("The 'formatters' option is deprecated as of v0.2.2 and will be removed in a future version - use 'modifiers' instead (same thing, more accurate name)")),void 0!==this.el&&(this.el=t(this.el)),this._subs={},this._cache={},this._cacheMap={},this._observers={},this._pendingResolution=[],this._defAttrs=[],this.partials)for(r in this.partials)if(this.partials.hasOwnProperty(r)){if(s=this.partials[r],"string"==typeof s){if(!e.compile)throw Error('Missing Ractive.compile - cannot compile partial "'+r+'". Either precompile or use the version that includes the compiler');s=e.compile(s,this)}1===s.length&&"string"==typeof s[0]&&(s=s[0]),this.partials[r]=s}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,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({descriptor:this.template,root:this,parentNode:n}),n.appendChild(this.rendered.docFrag)},teardown:function(){var t;this.rendered.teardown();for(t in this._cacheMap)this._cacheMap.hasOwnProperty(t)&&this._clearCache(t);for(t in this._cache)this._cache.hasOwnProperty(t)&&this._clearCache(t)},set:function(t,e){for(i.isObject(t)?this._setMultiple(t):this._setSingle(t,e);this._defAttrs.length;)this._defAttrs.pop().update().deferred=!1},_setSingle:function(t,e){var n,r,s,o,a,h;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]=/^\s*[0-9]+\s*$/.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),a=this._pendingResolution.length;a--;)h=this._pendingResolution.splice(a,1)[0],this._resolveRef(h)||(this._pendingResolution[this._pendingResolution.length]=h)},_setMultiple:function(t){var e;for(e in t)t.hasOwnProperty(e)&&this._setSingle(e,t[e])},_clearCache:function(t){var e,n=this._cacheMap[t];if(this.modifyArrays&&(e=this._cache[t],i.isArray(e)&&!e._ractive.setting&&i.removeKeypath(e,t,this)),delete this._cache[t],n)for(;n.length;)this._clearCache(n.pop())},get:function(t){var e,n,r,s,o,a,h,c;if(i.isArray(t))e=t.slice(),n=e.join(".");else{if(this._cache.hasOwnProperty(t))return this._cache[t];e=i.splitKeypath(t),n=e.join(".")}if(this._cache.hasOwnProperty(n))return this._cache[n];if(r=e.pop(),a=e.length?this.get(e):this.data,s=/^⭆(.+)⭅$/.exec(r))c=i.getModifiersFromString(s[1]),h=this._modify(a,c);else{if("object"!=typeof a||!a.hasOwnProperty(r))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.modifyArrays&&(!i.isArray(h)||h.ractive&&h._ractive.setting||i.addKeypath(h,n,this)),this._cache[n]=h,h},update:function(t){return this._clearCache(t),this._notifyObservers(t),this.fire("update:"+t),this.fire("update",t),this},link:function(t){var e=this;return function(i){e.set(t,i)}},_registerMustache:function(t){var e,i,n;return t.parentFragment&&t.parentFragment.indexRefs.hasOwnProperty(t.descriptor.r)?(n=t.parentFragment.indexRefs[t.descriptor.r],i=t.descriptor.m?this._modify(n,t.descriptor.m):n,t.update(i),void 0):(e=this._resolveRef(t),e||(t.descriptor.m&&t.update(this._modify(void 0,t.descriptor.m)),this._pendingResolution[this._pendingResolution.length]=t),void 0)},_resolveRef:function(t){var e,n,r,s,o,a,h,c;if(e=t.descriptor.r,n=t.contextStack,"."===e)c=n[n.length-1];else{for(r=i.splitKeypath(e),s=r.pop(),n=n.concat();n.length;)if(o=n.pop(),a=i.splitKeypath(o),h=this.get(a.concat(r)),"object"==typeof h&&h.hasOwnProperty(s)){c=o+"."+e;break}c||void 0===this.get(e)||(c=e)}return c?(t.keypath=t.descriptor.m?c+"."+i.stringifyModifiers(t.descriptor.m):c,t.keys=i.splitKeypath(t.keypath),t.observerRefs=this._observe(t),t.update(this.get(t.keypath)),!0):!1},_cancelKeypathResolution:function(t){var e=this._pendingResolution.indexOf(t);-1!==e&&this._pendingResolution.splice(e,1)},_modify: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.d,a=s.g||[],h=this.modifiers[o]||e.modifiers[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.keys))},_observe:function(t){var e,n,r=this,s=[],o=t.descriptor.p||0;for(e=function(e){var i;i=r._observers[e]=r._observers[e]||[],i=i[o]=i[o]||[],i[i.length]=t,s[s.length]={keypath:e,priority:o,mustache:t}},n=i.splitKeypath(t.keypath);n.length>1;)e(n.join(".")),n.pop();return e(n[0]),s},_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.mustache){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})(),function(){var t={},e={};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 i,n,r,s,o,a,h,c;if(e[t])return e[t].concat();if(i=/⭆.+⭅/.test(t),!/\\\./.test(t)&&!i)return e[t]=t.replace(/\[\s*([0-9]+)\s*\]/g,".$1").split("."),e[t].concat();for(a=[],h=t,i&&(n=[],h=h.replace(/⭆(.+)⭅/g,function(t,e){return n[n.length]=e,"⭆x⭅"})),o=0;h.length;){if(s=h.indexOf(".",o),-1===s)c=h,h="";else{if("\\"===h.charAt(s-1)&&"\\"!==h.charAt(s-2)){o=s+1;continue}c=h.substr(0,s),o=0}/\[/.test(c)?a=a.concat(c.replace(/\[\s*([0-9]+)\s*\]/g,".$1").split(".")):a[a.length]=c,h=h.substring(s+1)}if(i)for(r=a.length;r--;)"⭆x⭅"===a[r]&&(a[r]="⭆"+n.pop()+"⭅");return e[t]=a,a.concat()},getModifiersFromString: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?{d:t,g:[]}:{d:t.substr(0,e),g:JSON.parse(t.substring(e))}}),t[e]=i,i)},stringifyModifiers:function(t){var e=t.map(function(t){return t.g&&t.g.length?t.d+JSON.stringify(t.g):t.d});return"⭆"+e.join("⤋")+"⭅"},eventDefns:{}}}(),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.descriptor=t.descriptor,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.descriptor.t,this.root._registerMustache(this),!this.keypath&&this.descriptor.n&&this.update(this.descriptor.m?this.root._modify(!1,this.descriptor.m):!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.descriptor?t.descriptor.length:0,i=0;e>i;i+=1)n.descriptor=t.descriptor[i],n.index=i,this.items[this.items.length]=this.createItem(n)},t.sectionUpdate=function(e){var i,n,r,s,o;if(i={descriptor:this.descriptor.f,root:this.root,parentNode:this.parentNode,parent:this},this.parentNode&&(i.anchor=this.parentFragment.findNextNode(this)),n=t.isArray(e),n&&0===e.length&&(r=!0),this.descriptor.n){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}else 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.descriptor.i&&(i.indexRef=this.descriptor.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)}}(i),function(t){t.on=function(t,e){var i,n,r=this;if("object"==typeof t){i=[];for(n in t)t.hasOwnProperty(n)&&(i[i.length]=this.on(n,t[n]));return{cancel:function(){for(;i.length;)i.pop().cancel()}}}return this._subs[t]?this._subs[t].push(e):this._subs[t]=[e],{cancel:function(){r.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,e){t.defineEvent=function(t,i){e.eventDefns[t]=i},t.defineEvent("tap",function(t,e){var i,n,r,s;return r=5,s=400,i=function(t){var i,n,o,a,h;i=t.clientX,n=t.clientY,o=function(t){e(t),h()},a=function(t){(Math.abs(t.clientX-i)>=r||Math.abs(t.clientY-n)>=r)&&h()},h=function(){window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",o)},window.addEventListener("mousemove",a),window.addEventListener("mouseup",o),setTimeout(h,s)},t.addEventListener("mousedown",i),n=function(t){var i,n,o,a,h,c,p;1===t.touches.length&&(o=t.touches[0],a=o.identifier,c=function(t){1!==t.changedTouches.length||t.touches[0].identifier!==a?p():e(t)},h=function(t){var e;(1!==t.touches.length||t.touches[0].identifier!==a)&&p(),e=t.touches[0],(Math.abs(e.clientX-i)>=r||Math.abs(e.clientY-n)>=r)&&p()},p=function(){window.removeEventListener("touchmove",h),window.removeEventListener("touchend",c),window.removeEventListener("touchcancel",p)},window.addEventListener("touchmove",h),window.addEventListener("touchend",c),window.addEventListener("touchcancel",p),setTimeout(p,s))},{teardown:function(){t.removeEventListener("mousedown",i),t.removeEventListener("touchstart",n)}}})}(e,i),function(t){var e,i,n,r,s,o,a,h,c,p,d;e=t.types,r={"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,i=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},t.DomFragment=function(e){return this.docFrag=n.createDocumentFragment(),"string"==typeof e.descriptor?(this.nodes=i(e.descriptor,this.docFrag),void 0):(t.Fragment.call(this,e),void 0)},t.DomFragment.prototype={createItem:function(t){if("string"==typeof t.descriptor)return new s(t,this.docFrag);switch(t.descriptor.t){case e.INTERPOLATOR:return new c(t,this.docFrag);case e.SECTION:return new d(t,this.docFrag);case e.TRIPLE:return new p(t,this.docFrag);case e.ELEMENT:return new o(t,this.docFrag);case e.PARTIAL:return new a(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}},a=function(e,i){this.fragment=new t.DomFragment({descriptor:e.root.partials[e.descriptor.r]||[],root:e.root,parentNode:e.parentNode,contextStack:e.contextStack,parent:this}),i.appendChild(this.fragment.docFrag)},a.prototype={teardown:function(){this.fragment.teardown()}},s=function(t,e){this.node=n.createTextNode(t.descriptor),this.root=t.root,this.parentNode=t.parentNode,e.appendChild(this.node)},s.prototype={teardown:function(){this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},firstNode:function(){return this.node}},o=function(e,i){var r,s,o,a,c,p,d,u;if(r=this.descriptor=e.descriptor,this.root=e.root,this.parentFragment=e.parentFragment,this.parentNode=e.parentNode,this.index=e.index,this.eventListeners=[],this.customEventListeners=[],r.a&&r.a.xmlns){if(s=r.a.xmlns,"string"!=typeof s)throw Error("Namespace attribute cannot contain mustaches")}else s=this.parentNode.namespaceURI;if(this.node=n.createElementNS(s,r.e),r.f&&("string"==typeof r.f&&this.node.namespaceURI===t.namespaces.html?this.node.innerHTML=r.f:(this.children=new t.DomFragment({descriptor:r.f,root:e.root,parentNode:this.node,contextStack:e.contextStack,parent:this}),this.node.appendChild(this.children.docFrag))),r.x)for(o in r.x)r.x.hasOwnProperty(o)&&this.addEventProxy(o,r.x[o],e.contextStack);this.attributes=[],d=[];for(c in r.a)r.a.hasOwnProperty(c)&&(p=r.a[c],a=new h({parent:this,name:c,value:void 0===p?null:p,root:e.root,parentNode:this.node,contextStack:e.contextStack}),this.attributes[this.attributes.length]=a,a.isBindable&&d.push(a),a.isTwowayNameAttr?u=a:a.update());for(;d.length;)d.pop().bind(this.root.lazy);u&&(u.updateViewModel(),u.update()),i.appendChild(this.node)},o.prototype={addEventProxy:function(e,i,n){var r,s,o,a,h=this;"string"==typeof i?a=function(t){h.root.fire(i,t,h.node)}:(o=new t.TextFragment({descriptor:i,root:this.root,parent:this,contextStack:n}),a=function(t){h.root.fire(o.getValue(),t,h.node)}),(r=t.eventDefns[e])?(s=r(this.node,a),this.customEventListeners[this.customEventListeners.length]=s):void 0!==this.node["on"+e]&&(this.eventListeners[this.eventListeners.length]={n:e,h:a},this.node.addEventListener(e,a))},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(){}},h=function(e){var i,n,s,o,a,h,c,p;if(i=e.name,n=e.value,this.parent=e.parent,s=i.indexOf(":"),-1!==s&&(o=i.substr(0,s),"xmlns"!==o&&(i=i.substring(s+1),this.namespace=t.namespaces[o],!this.namespace)))throw'Unknown namespace ("'+o+'")';return null===n||"string"==typeof n?(this.namespace?e.parentNode.setAttributeNS(this.namespace,i,n):e.parentNode.setAttribute(i,n),void 0):(this.root=e.root,this.parentNode=e.parentNode,this.name=i,this.children=[],this.namespace||e.parentNode.namespaceURI!==t.namespaces.html||(c=this.name.toLowerCase(),p=r[c]||c,void 0!==e.parentNode[p]&&(this.propertyName=p),("boolean"==typeof e.parentNode[p]||"value"===p)&&(this.useProperty=!0)),this.parentFragment=this.parent.parentFragment,this.fragment=new t.TextFragment({descriptor:n,root:this.root,parent:this,contextStack:e.contextStack}),1===this.fragment.items.length&&(this.selfUpdating=!0),this.root.twoway&&(a=this.parent.descriptor.e.toLowerCase(),h=!("name"!==p&&"value"!==p&&"checked"!==p||"input"!==a&&"textarea"!==a&&"select"!==a)),h&&(this.isBindable=!0,"name"===p&&(this.isTwowayNameAttr=!0)),this.ready=!0,this.isTwowayNameAttr||this.update(),void 0)},h.prototype={bind:function(e){var i,n,r=this,s=this.parentNode;if(!this.fragment)return!1;if(1!==this.fragment.items.length||this.fragment.items[0].type!==t.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.descriptor.r,-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.descriptor.m?r.root._modify(s.value,r.interpolator.descriptor.m):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),e||(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.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._defAttrs[this.root._defAttrs.length]=this,this.deferred=!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(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)}},c=function(e,i){this.node=n.createTextNode(""),i.appendChild(this.node),t.Mustache.call(this,e)},c.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}},p=function(e,i){this.nodes=[],this.docFrag=n.createDocumentFragment(),this.initialising=!0,t.Mustache.call(this,e),i.appendChild(this.docFrag),this.initialising=!1},p.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=i(t,this.docFrag),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}}},d=function(e,i){this.fragments=[],this.length=0,this.docFrag=n.createDocumentFragment(),this.initialising=!0,t.Mustache.call(this,e),i.appendChild(this.docFrag),this.initialising=!1},d.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(e){t.sectionUpdate.call(this,e),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},createFragment:function(e){var i=new t.DomFragment(e);return this.docFrag.appendChild(i.docFrag),i}}}(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.descriptor)return new i(t.descriptor);switch(t.descriptor.t){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),this.value=this.fragments.join(""),this.parent.bubble()},createFragment:function(e){return new t.TextFragment(e)},toString:function(){return this.fragments.join("")}}}(i),e.extend=function(t){var i,n,r;i=this,n=function(){e.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 t)if(t.hasOwnProperty(r)){if(e.prototype.hasOwnProperty(r))throw Error('Cannot override "'+r+'" method or property of Ractive prototype');n.prototype[r]=t[r]}return n.extend=i.extend,n},function(t){var e,i,n,r,s,o,a;e=Object.defineProperty?Object.defineProperty:function(t,e,i){t[e]=i.value},t.addKeypath=function(t,i,r){var s,o,a,h;t._ractive?(s=t._ractive.roots,o=t._ractive.keypathsByIndex,a=s.indexOf(r),-1===a&&(a=s.length,s[a]=r),o[a]||(o[a]=[]),h=o[a],-1===h.indexOf(i)&&(h[h.length]=i)):(e(t,"_ractive",{value:{roots:[r],keypathsByIndex:[[i]]},configurable:!0}),n(t))},t.removeKeypath=function(t,e,i){var n,s,o,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(n=t._ractive.roots,o=n.indexOf(i),-1===o)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(s=t._ractive.keypathsByIndex,a=s[o],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||n.splice(o,1),n.length||r(t)},i=function(t){var e,i,n,r,s,o;for(e=t._ractive.roots,i=t._ractive.keypathsByIndex,s=e.length;s--;)for(n=e[s],r=i[s],o=r.length;o--;)n.set(r[o],t)},s=[],a=["pop","push","reverse","shift","sort","splice","unshift"],a.forEach(function(t){var n=function(){var e=Array.prototype[t].apply(this,arguments);return this._ractive.setting=!0,i(this),this._ractive.setting=!1,e};e(s,t,{value:n})}),o={},o.__proto__?(n=function(t){t.__proto__=s},r=function(t){delete t._ractive,t.__proto__=Array.prototype}):(n=function(t){var i,n;for(i=a.length;i--;)n=a[i],e(t,n,{value:s[n]})},r=function(t){var e;for(e=a.length;e--;)delete t[a[e]];delete t._ractive,console.log("unwrapped array",t)})}(i),e.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)}},function(t,e){var i,n,r;r="undefined"!=typeof window?window:{},function(t,e,i){var n;for(n=0;t.length>n&&!i.requestAnimationFrame;++n)i.requestAnimationFrame=i[t[n]+"RequestAnimationFrame"],i.cancelAnimationFrame=i[t[n]+"CancelAnimationFrame"]||i[t[n]+"CancelRequestAnimationFrame"];i.requestAnimationFrame||(i.requestAnimationFrame=function(t){var n,r,s;return n=Date.now(),r=Math.max(0,16-(n-e)),s=i.setTimeout(function(){t(n+r)},r),e=n+r,s}),i.cancelAnimationFrame||(i.cancelAnimationFrame=function(t){i.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,c,p,d;for(o=o||{},p=n.animations.length;p--;)n.animations[p].keypath===r&&n.animations[p].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,d=e.splitKeypath(r),c=new i({keys:d,from:this.get(d),to:s,root:this,duration:h,easing:a,step:o.step,complete:o.complete}),n.push(c)}}(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);