UNPKG

ractive

Version:

Next-generation DOM manipulation

1 lines 16.5 kB
(function(t){"use strict";var e=e||{};(function(t){var e,i,r,s,n,a,o,h,u,l,c,f,d,p;t.compile=function(e,r){var s,n;return r=r||{},t.delimiters=r.delimiters||["{{","}}"],t.tripleDelimiters=r.tripleDelimiters||["{{{","}}}"],s=t.tokenize(e),n=i(s),n.toJson()},l=t.types,c=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],f=["a","abbr","acronym","address","applet","area","b","base","basefont","bdo","big","blockquote","body","br","button","caption","center","cite","code","col","colgroup","dd","del","dfn","dir","div","dl","dt","em","fieldset","font","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","hr","html","i","iframe","img","input","ins","isindex","kbd","label","legend","li","link","map","menu","meta","noframes","noscript","object","ol","optgroup","option","p","param","pre","q","s","samp","script","select","small","span","strike","strong","style","sub","sup","table","tbody","td","textarea","tfoot","th","thead","title","tr","tt","u","ul","var","article","aside","audio","bdi","canvas","command","data","datagrid","datalist","details","embed","eventsource","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","ruby","rp","rt","section","source","summary","time","track","video","wbr"],d=["li","dd","rt","rp","optgroup","option","tbody","tfoot","tr","td","th"],p={li:["li"],dt:["dt","dd"],dd:["dt","dd"],p:["address","article","aside","blockquote","dir","div","dl","fieldset","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","menu","nav","ol","p","pre","section","table","ul"],rt:["rt","rp"],rp:["rp","rt"],optgroup:["optgroup"],option:["option","optgroup"],thead:["tbody","tfoot"],tbody:["tbody","tfoot"],tr:["tr"],td:["td","th"],th:["td","th"]},u=function(t){var e,i,r,s;if(s=t.indexOf("["),-1!==s){e=t.substr(0,s),i=t.substring(s+1,t.length-1);try{r=JSON.parse(i)}catch(n){throw"Could not parse arguments ("+i+") using JSON.parse"}return{name:e,args:r}}return{name:t}},h={quot:34,amp:38,apos:39,lt:60,gt:62,nbsp:160,iexcl:161,cent:162,pound:163,curren:164,yen:165,brvbar:166,sect:167,uml:168,copy:169,ordf:170,laquo:171,not:172,shy:173,reg:174,macr:175,deg:176,plusmn:177,sup2:178,sup3:179,acute:180,micro:181,para:182,middot:183,cedil:184,sup1:185,ordm:186,raquo:187,frac14:188,frac12:189,frac34:190,iquest:191,Agrave:192,Aacute:193,Acirc:194,Atilde:195,Auml:196,Aring:197,AElig:198,Ccedil:199,Egrave:200,Eacute:201,Ecirc:202,Euml:203,Igrave:204,Iacute:205,Icirc:206,Iuml:207,ETH:208,Ntilde:209,Ograve:210,Oacute:211,Ocirc:212,Otilde:213,Ouml:214,times:215,Oslash:216,Ugrave:217,Uacute:218,Ucirc:219,Uuml:220,Yacute:221,THORN:222,szlig:223,agrave:224,aacute:225,acirc:226,atilde:227,auml:228,aring:229,aelig:230,ccedil:231,egrave:232,eacute:233,ecirc:234,euml:235,igrave:236,iacute:237,icirc:238,iuml:239,eth:240,ntilde:241,ograve:242,oacute:243,ocirc:244,otilde:245,ouml:246,divide:247,oslash:248,ugrave:249,uacute:250,ucirc:251,uuml:252,yacute:253,thorn:254,yuml:255,OElig:338,oelig:339,Scaron:352,scaron:353,Yuml:376,fnof:402,circ:710,tilde:732,Alpha:913,Beta:914,Gamma:915,Delta:916,Epsilon:917,Zeta:918,Eta:919,Theta:920,Iota:921,Kappa:922,Lambda:923,Mu:924,Nu:925,Xi:926,Omicron:927,Pi:928,Rho:929,Sigma:931,Tau:932,Upsilon:933,Phi:934,Chi:935,Psi:936,Omega:937,alpha:945,beta:946,gamma:947,delta:948,epsilon:949,zeta:950,eta:951,theta:952,iota:953,kappa:954,lambda:955,mu:956,nu:957,xi:958,omicron:959,pi:960,rho:961,sigmaf:962,sigma:963,tau:964,upsilon:965,phi:966,chi:967,psi:968,omega:969,thetasym:977,upsih:978,piv:982,ensp:8194,emsp:8195,thinsp:8201,zwnj:8204,zwj:8205,lrm:8206,rlm:8207,ndash:8211,mdash:8212,lsquo:8216,rsquo:8217,sbquo:8218,ldquo:8220,rdquo:8221,bdquo:8222,dagger:8224,Dagger:8225,bull:8226,hellip:8230,permil:8240,prime:8242,Prime:8243,lsaquo:8249,rsaquo:8250,oline:8254,frasl:8260,euro:8364,image:8465,weierp:8472,real:8476,trade:8482,alefsym:8501,larr:8592,uarr:8593,rarr:8594,darr:8595,harr:8596,crarr:8629,lArr:8656,uArr:8657,rArr:8658,dArr:8659,hArr:8660,forall:8704,part:8706,exist:8707,empty:8709,nabla:8711,isin:8712,notin:8713,ni:8715,prod:8719,sum:8721,minus:8722,lowast:8727,radic:8730,prop:8733,infin:8734,ang:8736,and:8743,or:8744,cap:8745,cup:8746,"int":8747,there4:8756,sim:8764,cong:8773,asymp:8776,ne:8800,equiv:8801,le:8804,ge:8805,sub:8834,sup:8835,nsub:8836,sube:8838,supe:8839,oplus:8853,otimes:8855,perp:8869,sdot:8901,lceil:8968,rceil:8969,lfloor:8970,rfloor:8971,lang:9001,rang:9002,loz:9674,spades:9824,clubs:9827,hearts:9829,diams:9830},o=function(t){var e;return e=t.replace(/&([a-zA-Z]+);/,function(t,e){return h[e]?String.fromCharCode(h[e]):t}),e=e.replace(/&#x([0-9]+);/,function(t,e){return String.fromCharCode(parseInt(e,16))}),e=e.replace(/&#([0-9]+);/,function(t,e){return String.fromCharCode(e)})},r=function(t){this.text=t.value},r.prototype={toJson:function(){return this.decoded||(this.decoded=o(this.text))},toString:function(){return this.text},decodeCharacterReferences:function(){}},s=function(t,r){var s,n,a,o;if(this.type=l.ELEMENT,this.tag=t.tag,this.parentFragment=r,this.parentElement=r.parentElement,s=t.attributes.items,a=s.length){for(n=[],o=0;a>o;o+=1)n[o]={name:s[o].name.value,value:i(s[o].value.tokens,this.parentFragment.priority+1)};this.attributes=n}t.isSelfClosingTag||-1!==c.indexOf(t.tag.toLowerCase())||(this.fragment=new e(this,r.priority+1))},s.prototype={read:function(t){return this.fragment&&this.fragment.read(t)},toJson:function(t){var e,i,r,s,n;if(e={type:l.ELEMENT,tag:this.tag},this.attributes)for(e.attrs={},n=0;this.attributes.length>n;n+=1)i=this.attributes[n].name,s=""+this.attributes[n].value,r=s!==!1?s:this.attributes[n].value.toJson(),e.attrs[i]=r;return this.fragment&&this.fragment.items.length&&(e.frag=this.fragment.toJson(t)),e},toString:function(){var t,e,i,r,s,n,a;if(-1===f.indexOf(this.tag.toLowerCase()))return!1;if(n=this.fragment?""+this.fragment:"",n===!1)return!1;if(a=-1!==c.indexOf(this.tag.toLowerCase()),t="<"+this.tag,this.attributes)for(e=0,i=this.attributes.length;i>e;e+=1){if(-1!==this.attributes[e].name.indexOf(":"))return!1;if(r=" "+this.attributes[e].name,s=""+this.attributes[e].value,s===!1)return!1;""!==s&&(r+="=",r+=/[\s"'=<>`]/.test(s)?'"'+s.replace(/"/g,"&quot;")+'"':s),t+=r}return this.isSelfClosing&&!a?t+="/>":(t+=">",a?t:(t+=n,t+="</"+this.tag+">"))}},n=function(t,i){this.type=l.SECTION,this.parentFragment=i,this.ref=t.ref,this.inverted=t.type===l.INVERTED,this.formatters=t.formatters,this.i=t.i,this.fragment=new e(this,i.priority+1)},n.prototype={read:function(t){return this.fragment.read(t)},toJson:function(t){var e;return e={type:l.SECTION,ref:this.ref,frag:this.fragment.toJson(t)},this.formatters&&this.formatters.length&&(e.fmtrs=this.formatters.map(u)),this.inverted&&(e.inv=!0),this.priority&&(e.p=this.parentFragment.priority),this.i&&(e.i=this.i),e},toString:function(){return!1}},a=function(t,e){this.type=t.type,this.priority=e,this.ref=t.ref,this.formatters=t.formatters},a.prototype={toJson:function(){var t={type:this.type,ref:this.ref};return this.formatters&&(t.fmtrs=this.formatters.map(u)),this.priority&&(t.p=this.priority),t},toString:function(){return!1}},e=function(t,e){this.owner=t,this.items=[],t&&(this.parentElement=t.type===l.ELEMENT?t:t.parentElement),this.priority=e},e.prototype={read:function(t){if(this.sealed)return!1;if(this.isImplicitlyClosedBy(t))return this.seal(),!1;if(this.currentChild){if(this.currentChild.read(t))return!0;this.currentChild=null}return this.isExplicitlyClosedBy(t)?(this.seal(),!0):t.type===l.CLOSING||t.type===l.DELIMCHANGE||t.type===l.COMMENT?!1:t.type===l.SECTION||t.type===l.INVERTED?(this.currentChild=new n(t,this),this.items[this.items.length]=this.currentChild,!0):t.type===l.TAG?(this.currentChild=new s(t,this),this.items[this.items.length]=this.currentChild,!0):t.type===l.TEXT||t.type===l.ATTR_VALUE_TOKEN?(this.items[this.items.length]=new r(t),!0):(this.items[this.items.length]=new a(t,this.priority),!0)},isClosedBy:function(t){return this.isImplicitlyClosedBy(t)||this.isExplicitlyClosedBy(t)},isImplicitlyClosedBy:function(t){var e,i,r,s,n;return t.tag&&this.owner&&this.owner.type===l.ELEMENT?(s=this.owner.tag.toLowerCase(),n=t.tag.toLowerCase(),i=this.owner,r=i.parentElement||null,e=p[s],e&&!t.isClosingTag&&-1!==e.indexOf(n)?!0:-1!==d.indexOf(s)&&r&&r.fragment.isClosedBy(t)?!0:"p"===s&&r&&"a"===r.tag.toLowerCase()&&r.fragment.isClosedBy(t)?!0:void 0):!1},isExplicitlyClosedBy:function(t){return this.owner?this.owner.type===l.SECTION&&t.type===l.CLOSING&&t.ref===this.owner.ref?!0:this.owner.type===l.ELEMENT&&this.owner&&t.isClosingTag&&t.tag.toLowerCase()===this.owner.tag.toLowerCase()?!0:void 0:!1},toJson:function(t){var e,i,r,s=[];if(!t&&(r=""+this,r!==!1))return r;for(e=0,i=this.items.length;i>e;e+=1)s[e]=this.items[e].toJson(t);return s},toString:function(){var t,e,i,r="";for(t=0,e=this.items.length;e>t;t+=1){if(i=""+this.items[t],i===!1)return!1;r+=i}return r},seal:function(){this.sealed=!0}},i=function(t,i){for(var r,s=new e(null,i||0);t.length;)r=t.shift(),s.read(r);return s}})(e),function(t){var e,i,r,s,n,a,o,h,u,l,c,f,d,p,m,g,y,v,T;t.tokenize=function(t){var e=s.fromString(r(t));return e.tokens},s=function(){this.tokens=[],this.buffer=new n},s.prototype={read:function(t){var i,r;if(this.currentToken&&this.currentToken.type===e.TAG&&this.currentToken.read(t))return!0;if(this.buffer.read(t))return!0;if(i=this.buffer.convert())return this.currentToken&&this.currentToken.seal(),this.currentToken=this.tokens[this.tokens.length]=i,!0;if(r=this.buffer.release(),this.currentToken){for(;r.length;){for(;r.length&&this.currentToken.read(r.charAt(0));)r=r.substring(1);r.length&&("<"===r.charAt(0)?(this.currentToken=new u,this.currentToken.read("<")):(this.currentToken=new a,this.currentToken.read(r.charAt(0))),this.tokens[this.tokens.length]=this.currentToken,r=r.substring(1))}return!0}return this.currentToken="<"===t?new u:new a,this.currentToken.read(t),this.tokens[this.tokens.length]=this.currentToken,!0},end:function(){this.buffer.isEmpty()||(this.tokens[this.tokens.length]=this.buffer.convert())}},s.fromString=function(t){var e,i,r;for(e=new s,i=0,r=t.length;r>i;)e.read(t.charAt(i)),i+=1;return e.end(),e},n=function(){this.value=""},n.prototype={read:function(e){var i;return this.value+=e,i=this.isPartialMatchOf(t.delimiters[0])||this.isPartialMatchOf(t.tripleDelimiters[0])},convert:function(){var e,i,r,s,n,a;if(i=t.delimiters[0],r=t.tripleDelimiters[0],e=this.value,n=function(){return 0===e.indexOf(r)?new h:void 0},a=function(){return 0===e.indexOf(i)?new o:void 0},s=r.length>i.length?n()||a():a()||n()){for(;this.value.length;)s.read(this.value.charAt(0)),this.value=this.value.substring(1);return s}return!1},release:function(){var t=this.value;return this.value="",t},isEmpty:function(){return!this.value.length},isPartialMatchOf:function(t){return 0===t.indexOf(this.value)}},a=function(){this.type=e.TEXT,this.value=""},a.prototype={read:function(t){return this.sealed?!1:"<"===t?!1:(this.value+=t,!0)},seal:function(){this.sealed=!0}},o=function(){this.value="",this.openingDelimiter=t.delimiters[0],this.closingDelimiter=t.delimiters[1]},h=function(){this.value="",this.openingDelimiter=t.tripleDelimiters[0],this.closingDelimiter=t.tripleDelimiters[1],this.type=e.TRIPLE},o.prototype=h.prototype={read:function(t){return this.sealed?!1:(this.value+=t,this.value.substr(-this.closingDelimiter.length)===this.closingDelimiter&&this.seal(),!0)},seal:function(){var t,i,r,s,n;this.sealed||(t=this.value.replace(this.openingDelimiter,"").replace(this.closingDelimiter,"").trim(),"="===t.charAt(0)&&(this.changeDelimiters(t),this.type=e.DELIMCHANGE),this.type||(i=t.charAt(0),c[i]?(this.type=c[i],t=t.substring(1).trim()):this.type=e.INTERPOLATOR),this.type===e.SECTION&&(s=/:\s*([a-zA-Z_$][a-zA-Z0-9_$]*)$/,n=s.exec(t),n&&(this.i=n[1],t=t.substr(0,t.length-n[0].length))),r=t.split("|"),this.ref=r.shift().trim(),r.length&&(this.formatters=r.map(function(t){return t.trim()})),this.sealed=!0)},changeDelimiters:function(i){var r,s;s=/\=([^\s=]+)\s+([^\s=]+)=/.exec(i),r=this.type===e.TRIPLE?t.tripleDelimiters:t.delimiters,r[0]=s[1],r[1]=s[2]}},u=function(){this.type=e.TAG,this.openingBracket=new f,this.closingTagSolidus=new m,this.tagName=new d,this.attributes=new p,this.selfClosingSolidus=new m,this.closingBracket=new g},u.prototype={read:function(t){var e;return this.sealed?!1:(e=this.openingBracket.read(t)||this.closingTagSolidus.read(t)||this.tagName.read(t)||this.attributes.read(t)||this.selfClosingSolidus.read(t)||this.closingBracket.read(t))?(this.closingBracket.sealed&&this.seal(),!0):(this.seal(),!1)},seal:function(){this.tag=this.tagName.value,this.closingTagSolidus.value&&(this.isClosingTag=!0),this.selfClosingSolidus.value&&(this.isSelfClosingTag=!0),this.sealed=!0}},f=function(){},f.prototype={read:function(t){if(this.sealed)return!1;if("<"===t)return this.value="<",this.seal(),!0;throw'Expected "<", saw "'+t+'"'},seal:function(){this.sealed=!0}},d=function(){},d.prototype={read:function(t){return this.sealed?!1:!this.value&&/[a-zA-Z]/.test(t)?(this.value=t,!0):/[a-zA-Z0-9\-]/.test(t)?(this.value+=t,!0):(this.seal(),!1)},seal:function(){this.sealed=!0}},p=function(){this.items=[]},p.prototype={read:function(t){return this.sealed?!1:this.nextItem&&this.nextItem.read(t)?!0:i.test(t)?!0:(this.nextItem=new y,this.nextItem.read(t)?(this.items[this.items.length]=this.nextItem,!0):(this.seal(),!1))},seal:function(){this.sealed=!0}},y=function(){this.name=new v,this.value=new T},y.prototype={read:function(t){return this.sealed?!1:this.name.read(t)?!0:this.name.value?this.value.read(t)?!0:(this.seal(),!1):(this.seal(),!1)},seal:function(){this.sealed=!0}},v=function(){},v.prototype={read:function(t){return this.sealed?!1:this.value?/[_:a-zA-Z0-9\.\-]/.test(t)?(this.value+=t,!0):(this.seal(),!1):/[a-zA-Z_:]/.test(t)?(this.value=t,!0):(this.seal(),!1)},seal:function(){this.sealed=!0}},T=function(){this.tokens=[],this.buffer=new n,this.expected=!1},T.prototype={read:function(t){var e,r;if(this.sealed)return!1;if(!this.expected)return i.test(t)?!0:"="===t?(this.expected=!0,!0):!1;if(!this.tokens.length&&!this.quoteMark){if(i.test(t))return!0;if('"'===t||"'"===t)return this.quoteMark=t,!0}if(this.buffer.read(t))return!0;if(e=this.buffer.convert())return this.currentToken&&this.currentToken.seal(),this.currentToken=this.tokens[this.tokens.length]=e,!0;if(r=this.buffer.release(),this.currentToken){for(;r.length;){for(;r.length&&r.charAt(0)!==this.quoteMark&&this.currentToken.read(r.charAt(0));)r=r.substring(1);if(r.length&&r.charAt(0)!==this.quoteMark&&(this.currentToken=new l(this.quoteMark),this.currentToken.read(r.charAt(0)),this.tokens[this.tokens.length]=this.currentToken,r=r.substring(1)),r.charAt(0)===this.quoteMark)return this.currentToken.seal(),this.seal(),!0}return!0}return this.currentToken=new l(this.quoteMark),this.currentToken.read(t),this.tokens[this.tokens.length]=this.currentToken,this.currentToken.sealed&&this.seal(),!0},seal:function(){this.sealed=!0}},l=function(t){this.type=e.ATTR_VALUE_TOKEN,this.quoteMark=t||"",this.value=""},l.prototype={read:function(t){return this.sealed?!1:t===this.quoteMark?(this.seal(),!0):this.quoteMark?(this.value+=t,!0):/[\s"'=<>`]/.test(t)?(this.seal(),!1):(this.value+=t,!0)},seal:function(){this.sealed=!0}},m=function(){},m.prototype={read:function(t){return this.sealed?!1:"/"===t?(this.value="/",this.seal(),!0):(this.seal(),!1)},seal:function(){this.sealed=!0}},g=function(){},g.prototype={read:function(t){if(this.sealed)return!1;if(">"===t)return this.value=">",this.seal(),!0;throw'Expected ">", received "'+t+'"'},seal:function(){this.sealed=!0}},r=function(t){var e,i,r;for(r="";t.length;){if(e=t.indexOf("<!--"),i=t.indexOf("-->"),-1===e&&-1===i){r+=t;break}if(-1!==e&&-1===i)throw"Illegal HTML - expected closing comment sequence ('-->')";if(-1!==i&&-1===e||e>i)throw"Illegal HTML - unexpected closing comment sequence ('-->')";r+=t.substr(0,e),t=t.substring(i+3)}return r},e=t.types,i=/\s/,c={"#":e.SECTION,"^":e.INVERTED,"/":e.CLOSING,">":e.PARTIAL,"!":e.COMMENT,"&":e.INTERPOLATOR}}(e),e.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},"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):t.Anglebars=e})(this);